KiCad PCB EDA Suite
initpcb.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2007-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 #include <confirm.h>
30 #include <pcb_edit_frame.h>
31 #include <project.h>
32 #include <project/net_settings.h>
33 #include <project/project_file.h>
34 
35 #include <class_board.h>
36 
37 #include <pcbnew.h>
38 #include <footprint_edit_frame.h>
40 
41 
42 bool PCB_EDIT_FRAME::Clear_Pcb( bool aQuery, bool aFinal )
43 {
44  if( GetBoard() == NULL )
45  return false;
46 
47  if( aQuery && !GetBoard()->IsEmpty() )
48  {
49  if( !IsOK( this,
50  _( "Current Board will be lost and this operation cannot be undone. Continue?" ) ) )
51  return false;
52  }
53 
54  // Release the lock file, if exists
55  ReleaseFile();
56 
57  // Clear undo and redo lists because we want a full deletion
59  GetScreen()->ClrModify();
60 
61  if( !aFinal )
62  {
63  // delete the old BOARD and create a new BOARD so that the default
64  // layer names are put into the BOARD.
65  SetBoard( new BOARD() );
66 
67  // clear filename, to avoid overwriting an old file
68  GetBoard()->SetFileName( wxEmptyString );
69 
71 
73 
74  // Enable all layers (SetCopperLayerCount() will adjust the copper layers enabled)
75  GetBoard()->SetEnabledLayers( LSET().set() );
76 
77  // Default copper layers count set to 2: double layer board
79 
80  // Update display (some options depend on the board setup)
81  GetBoard()->SetVisibleLayers( LSET().set() );
85  UpdateTitle();
86 
87  Zoom_Automatique( false );
88  }
89 
90  return true;
91 }
92 
93 
95 {
96  if( GetBoard() == NULL )
97  return false;
98 
99  if( aQuery && IsContentModified() )
100  {
101  wxSafeYield( this, true ); // Allow frame to come to front before showing warning.
102 
103  if( !HandleUnsavedChanges( this, _( "The current footprint has been modified. "
104  "Save changes?" ),
105  [&]() -> bool { return SaveFootprint( GetBoard()->Modules().front() ); } ) )
106  {
107  return false;
108  }
109  }
110 
111  // Clear undo and redo lists because we want a full deletion
113  GetScreen()->ClrModify();
114 
115  BOARD* board = new BOARD;
116 
119  SetBoard( board );
120 
121  // This board will only be used to hold a footprint for editing
123 
124  // clear filename, to avoid overwriting an old file
125  GetBoard()->SetFileName( wxEmptyString );
126 
128 
129  Zoom_Automatique( false );
130 
131  return true;
132 }
void UpdateTitle()
Function UpdateTitle sets the main window title bar text.
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
Definition: confirm.cpp:202
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Returns the BOARD_DESIGN_SETTINGS for the open project Overloaded in FOOTPRINT_EDIT_FRAME.
This file is part of the common library.
APPEARANCE_CONTROLS * m_appearancePanel
AUI panel for controlling layer and object visibility and appearance.
void SetCopperLayerCount(int aCount)
void ReCreateLayerBox(bool aForceResizeToolbar=true)
Re create the layer Box by clearing the old list, and building le new one, from the new layers names ...
void ReleaseFile()
Release the current file marked in use.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: class_board.h:557
bool IsContentModified() override
Get if any footprints or libraries have been modified but not saved.
void OnBoardChanged()
Updates the panel contents from the application and board models
void InitDataPoints(const wxSize &aPageSizeInternalUnits)
Definition: base_screen.cpp:48
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
virtual void Zoom_Automatique(bool aWarpPointer)
Redraw the screen with best zoom level and the best centering that shows all the page or the board.
bool Clear_Pcb(bool aQuery)
Delete all and reinitialize the current board.
Definition: initpcb.cpp:94
LSET is a set of PCB_LAYER_IDs.
void ResetNetHighLight()
Reset all high light data to the init state.
#define NULL
void SetVisibleLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
void SetFileName(const wxString &aFileName)
Definition: class_board.h:277
void SetBoard(BOARD *aBoard) override
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetBoard(BOARD *aBoard) override
bool SaveFootprint(MODULE *aModule)
Save in an existing library a given footprint.
void ClrModify()
Definition: base_screen.h:100
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
const wxSize GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
BOARD * GetBoard() const
bool Clear_Pcb(bool aQuery, bool aFinal=false)
Function Clear_Pcb delete all and reinitialize the current board.
Definition: initpcb.cpp:42
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:284
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
void SetEnabledLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings Changes the bit-mask of ena...
void ReCreateAuxiliaryToolbar() override
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition: class_board.h:258