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 <fctsys.h>
30 #include <confirm.h>
31 #include <pcb_edit_frame.h>
32 
33 #include <class_board.h>
34 
35 #include <pcbnew.h>
36 #include <footprint_edit_frame.h>
37 
38 
39 bool PCB_EDIT_FRAME::Clear_Pcb( bool aQuery )
40 {
41  if( GetBoard() == NULL )
42  return false;
43 
44  if( aQuery && !GetBoard()->IsEmpty() )
45  {
46  if( !IsOK( this,
47  _( "Current Board will be lost and this operation cannot be undone. Continue ?" ) ) )
48  return false;
49  }
50 
51  // Clear undo and redo lists because we want a full deletion
53  GetScreen()->ClrModify();
54 
55  // Items visibility flags will be set because a new board will be created.
56  // Grid and ratsnest can be left to their previous state
57  bool showGrid = IsElementVisible( LAYER_GRID );
58  bool showRats = IsElementVisible( LAYER_RATSNEST );
59 
60  // delete the old BOARD and create a new BOARD so that the default
61  // layer names are put into the BOARD.
62  SetBoard( new BOARD() );
63  SetElementVisibility( LAYER_GRID, showGrid );
65 
66  SetCurItem( NULL );
67 
68  // clear filename, to avoid overwriting an old file
69  GetBoard()->SetFileName( wxEmptyString );
70 
72 
74 
75  // Enable all layers (SetCopperLayerCount() will adjust the copper layers enabled)
76  GetBoard()->SetEnabledLayers( LSET().set() );
77 
78  // Default copper layers count set to 2: double layer board
80 
81  // Update display (some options depend on the board setup)
82  GetBoard()->SetVisibleLayers( LSET().set() );
86  UpdateTitle();
87 
88  Zoom_Automatique( false );
89 
90  return true;
91 }
92 
93 
95 {
96  if( GetBoard() == NULL )
97  return false;
98 
99  if( aQuery && GetScreen()->IsModify() && !GetBoard()->IsEmpty() )
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. Save changes?" ),
104  [&]()->bool { return SaveFootprint( GetBoard()->m_Modules ); } ) )
105  {
106  return false;
107  }
108  }
109 
110  // Clear undo and redo lists because we want a full deletion
112  GetScreen()->ClrModify();
113 
114  BOARD* board = new BOARD;
115 
116  // Transfer current design settings
117  if( GetBoard() )
119 
121  SetBoard( board );
122 
123  SetCurItem( NULL );
124 
125  // clear filename, to avoid overwriting an old file
126  GetBoard()->SetFileName( wxEmptyString );
127 
129 
130  Zoom_Automatique( false );
131 
132  return true;
133 }
void UpdateTitle()
Function UpdateTitle sets the main window title bar text.
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Function HandleUnsavedChanges displays a dialog with Save, Cancel and Discard Changes buttons...
Definition: confirm.cpp:213
void SetElementVisibility(GAL_LAYER_ID aElement, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
This file is part of the common library.
Class BOARD to handle a board.
bool Clear_Pcb(bool aQuery)
Function Clear_Pcb delete all and reinitialize the current board.
Definition: initpcb.cpp:39
void ResetHighLight()
Function ResetHighLight Reset all high light data to the init state.
Definition: class_board.h:362
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
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 ...
BOARD * GetBoard() const
Definition of class FOOTPRINT_EDIT_FRAME.
void InitDataPoints(const wxSize &aPageSizeInternalUnits)
Definition: base_screen.cpp:72
void SynchronizeNetsAndNetClasses()
Function SynchronizeNetsAndNetClasses copies NETCLASS info to each NET, based on NET membership in a ...
Definition: netclass.cpp:160
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 IsElementVisible(GAL_LAYER_ID aElement) const
Function IsElementVisible tests whether a given element category is visible.
bool Clear_Pcb(bool aQuery)
Delete all and reinitialize the current board.
Definition: initpcb.cpp:94
Class LSET is a set of PCB_LAYER_IDs.
void SetVisibleLayers(LSET aLayerMask)
Function SetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aDesignSettings)
Function SetDesignSettings.
Definition: class_board.h:548
void SetFileName(const wxString &aFileName)
Definition: class_board.h:235
void SetBoard(BOARD *aBoard) override
>
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
void ClrModify()
Definition: base_screen.h:325
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...
void ReFillLayerWidget()
Function ReFillLayerWidget changes out all the layers in m_Layers and may be called upon loading a ne...
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:295
void SetEnabledLayers(LSET aLayerMask)
Function SetEnabledLayers is a proxy function that calls the correspondent function in m_BoardSetting...
void ReCreateAuxiliaryToolbar() override