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 <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, _( "Current Board will be lost and this operation cannot be undone. "
50  "Continue?" ) ) )
51  {
52  return false;
53  }
54  }
55 
56  // Release the lock file, if exists
57  ReleaseFile();
58 
59  // Clear undo and redo lists because we want a full deletion
61  GetScreen()->ClrModify();
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 
69  // clear filename, to avoid overwriting an old file
70  GetBoard()->SetFileName( wxEmptyString );
71 
73 
75 
76  // Enable all layers (SetCopperLayerCount() will adjust the copper layers enabled)
77  GetBoard()->SetEnabledLayers( LSET().set() );
78 
79  // Default copper layers count set to 2: double layer board
81 
82  // Update display (some options depend on the board setup)
83  GetBoard()->SetVisibleLayers( LSET().set() );
87  UpdateTitle();
88 
89  Zoom_Automatique( false );
90  }
91 
92  return true;
93 }
94 
95 
97 {
98  if( GetBoard() == NULL )
99  return false;
100 
101  bool is_last_fp_from_brd = IsCurrentFPFromBoard();
102 
103  if( aQuery && IsContentModified() )
104  {
105  wxSafeYield( this, true ); // Allow frame to come to front before showing warning.
106 
108  this, _( "The current footprint has been modified. Save changes?" ),
109  [&]() -> bool
110  {
111  return SaveFootprint( GetBoard()->Footprints().front() );
112  } ) )
113  {
114  return false;
115  }
116  }
117 
118  if( is_last_fp_from_brd )
119  m_boardFootprintUuids.clear();
120 
121  // Clear undo and redo lists because we want a full deletion
123  GetScreen()->ClrModify();
124 
125  BOARD* board = new BOARD;
126 
129  SetBoard( board );
130 
131  // This board will only be used to hold a footprint for editing
133 
134  // clear filename, to avoid overwriting an old file
135  GetBoard()->SetFileName( wxEmptyString );
136 
138 
139  return true;
140 }
void UpdateTitle()
Set the main window title bar text.
std::map< KIID, KIID > m_boardFootprintUuids
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:207
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Returns the BOARD_DESIGN_SETTINGS for the open project.
This file is part of the common library.
APPEARANCE_CONTROLS * m_appearancePanel
void SetCopperLayerCount(int aCount)
Definition: board.cpp:441
void ReCreateLayerBox(bool aForceResizeToolbar=true)
Recreate the layer box by clearing the old list and building a new one from the new layer names and c...
void ReleaseFile()
Release the current file marked in use.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
bool IsContentModified() override
Get if any footprints or libraries have been modified but not saved.
void InitDataPoints(const wxSize &aPageSizeInternalUnits)
Definition: base_screen.cpp:47
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1434
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:96
LSET is a set of PCB_LAYER_IDs.
void ResetNetHighLight()
Reset all high light data to the init state.
Definition: board.cpp:2044
#define NULL
void SetVisibleLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
Definition: board.cpp:473
void SetFileName(const wxString &aFileName)
Definition: board.h:298
void SetBoard(BOARD *aBoard) override
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetBoard(BOARD *aBoard) override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
void ClrModify()
Definition: base_screen.h:60
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 SaveFootprint(FOOTPRINT *aFootprint)
Save in an existing library a given footprint.
bool Clear_Pcb(bool aQuery, bool aFinal=false)
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:296
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
void SetEnabledLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings Changes the bit-mask of ena...
Definition: board.cpp:467
void ReCreateAuxiliaryToolbar() override
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition: board.h:262