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, bool aFinal )
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  // Release the lock file, if exists
52  ReleaseFile();
53 
54  // Clear undo and redo lists because we want a full deletion
56  GetScreen()->ClrModify();
57 
58  // Items visibility flags will be set because a new board will be created.
59  // Grid and ratsnest can be left to their previous state
60  bool showGrid = IsElementVisible( LAYER_GRID );
61  bool showRats = m_DisplayOptions.m_ShowGlobalRatsnest;
62 
63  if( !aFinal )
64  {
65  // delete the old BOARD and create a new BOARD so that the default
66  // layer names are put into the BOARD.
67  SetBoard( new BOARD() );
68  SetElementVisibility( LAYER_GRID, showGrid );
70 
71  // clear filename, to avoid overwriting an old file
72  GetBoard()->SetFileName( wxEmptyString );
73 
75 
77 
78  // Enable all layers (SetCopperLayerCount() will adjust the copper layers enabled)
79  GetBoard()->SetEnabledLayers( LSET().set() );
80 
81  // Default copper layers count set to 2: double layer board
83 
84  // Update display (some options depend on the board setup)
85  GetBoard()->SetVisibleLayers( LSET().set() );
89  UpdateTitle();
90 
91  Zoom_Automatique( false );
92  }
93 
94  return true;
95 }
96 
97 
99 {
100  if( GetBoard() == NULL )
101  return false;
102 
103  if( aQuery && GetScreen()->IsModify() && !GetBoard()->IsEmpty() )
104  {
105  wxSafeYield( this, true ); // Allow frame to come to front before showing warning.
106 
107  if( !HandleUnsavedChanges( this, _( "The current footprint has been modified. "
108  "Save changes?" ),
109  [&]() -> bool { return SaveFootprint( GetBoard()->Modules().front() ); } ) )
110  {
111  return false;
112  }
113  }
114 
115  // Clear undo and redo lists because we want a full deletion
117  GetScreen()->ClrModify();
118 
119  BOARD* board = new BOARD;
120 
121  // Transfer current design settings
122  if( GetBoard() )
124 
126  SetBoard( board );
127 
128  // clear filename, to avoid overwriting an old file
129  GetBoard()->SetFileName( wxEmptyString );
130 
132 
133  Zoom_Automatique( false );
134 
135  return true;
136 }
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:201
void SetElementVisibility(GAL_LAYER_ID aElement, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame.
This file is part of the common library.
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.
void InitDataPoints(const wxSize &aPageSizeInternalUnits)
Definition: base_screen.cpp:63
void SynchronizeNetsAndNetClasses()
Function SynchronizeNetsAndNetClasses copies NETCLASS info to each NET, based on NET membership in a ...
Definition: netclass.cpp:155
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:98
Class LSET is a set of PCB_LAYER_IDs.
void ResetNetHighLight()
Function ResetNetHighLight Reset all high light data to the init state.
Definition: class_board.h:376
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...
void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aDesignSettings)
Function SetDesignSettings.
Definition: class_board.h:550
void SetFileName(const wxString &aFileName)
Definition: class_board.h:223
#define _(s)
PCB_DISPLAY_OPTIONS m_DisplayOptions
void SetBoard(BOARD *aBoard) override
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:161
virtual void SetBoard(BOARD *aBoard) override
bool SaveFootprint(MODULE *aModule)
Save in an existing library a given footprint.
void ClrModify()
Definition: base_screen.h:225
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 IsElementVisible(GAL_LAYER_ID aElement) const
Function IsElementVisible tests whether a given element category is visible.
void ReFillLayerWidget()
Function ReFillLayerWidget changes out all the layers in m_Layers and may be called upon loading a ne...
bool Clear_Pcb(bool aQuery, bool aFinal=false)
Function Clear_Pcb delete all and reinitialize the current board.
Definition: initpcb.cpp:39
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:281
void SetEnabledLayers(LSET aLayerMask)
Function SetEnabledLayers is a proxy function that calls the correspondent function in m_BoardSetting...
void ReCreateAuxiliaryToolbar() override