KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2021 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>
34
35#include <board.h>
37
38#include <pcbnew.h>
41
42
43bool PCB_EDIT_FRAME::Clear_Pcb( bool aQuery, bool aFinal )
44{
45 if( GetBoard() == nullptr )
46 return false;
47
48 if( aQuery && !GetBoard()->IsEmpty() )
49 {
50 if( !IsOK( this, _( "Current Board will be lost and this operation cannot be undone. "
51 "Continue?" ) ) )
52 {
53 return false;
54 }
55 }
56
57 // Release the lock file, if exists
59
60 // Clear undo and redo lists because we want a full deletion
62 GetScreen()->SetContentModified( false );
63
64 if( !aFinal )
65 {
66 // delete the old BOARD and create a new BOARD so that the default
67 // layer names are put into the BOARD.
68 SetBoard( new BOARD() );
69
70 // clear filename, to avoid overwriting an old file
71 GetBoard()->SetFileName( wxEmptyString );
72
74
76
77 // Enable all layers (SetCopperLayerCount() will adjust the copper layers enabled)
78 GetBoard()->SetEnabledLayers( LSET().set() );
79
80 // Default copper layers count set to 2: double layer board
82
83 // Update display (some options depend on the board setup)
84 GetBoard()->SetVisibleLayers( LSET().set() );
89
90 Zoom_Automatique( false );
91 }
92
93 return true;
94}
95
96
98{
99 if( GetBoard() == nullptr )
100 return false;
101
102 bool is_last_fp_from_brd = IsCurrentFPFromBoard();
103
104 if( aQuery && IsContentModified() )
105 {
106 wxSafeYield( this, true ); // Allow frame to come to front before showing warning.
107
109 this, _( "The current footprint has been modified. Save changes?" ),
110 [&]() -> bool
111 {
112 return SaveFootprint( GetBoard()->Footprints().front() );
113 } ) )
114 {
115 return false;
116 }
117 }
118
119 if( is_last_fp_from_brd )
120 m_boardFootprintUuids.clear();
121
122 // Clear undo and redo lists because we want a full deletion
124 GetScreen()->SetContentModified( false );
125
126 BOARD* board = new BOARD;
127
129 board->SynchronizeNetsAndNetClasses( true );
130 SetBoard( board );
131
132 // This board will only be used to hold a footprint for editing
133 GetBoard()->SetBoardUse( BOARD_USE::FPHOLDER );
134
135 // clear filename, to avoid overwriting an old file
136 GetBoard()->SetFileName( wxEmptyString );
137
139
140 return true;
141}
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
void InitDataPoints(const VECTOR2I &aPageSizeInternalUnits)
Definition: base_screen.cpp:46
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:270
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition: board.h:282
void SetFileName(const wxString &aFileName)
Definition: board.h:305
void SetEnabledLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition: board.cpp:631
void SynchronizeNetsAndNetClasses(bool aResetTrackAndViaSizes)
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1601
void ResetNetHighLight()
Reset all high light data to the init state.
Definition: board.cpp:2139
void SetVisibleLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
Definition: board.cpp:643
void SetCopperLayerCount(int aCount)
Definition: board.cpp:593
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:728
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
void ReleaseFile()
Release the current file marked in use.
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.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Returns the BOARD_DESIGN_SETTINGS for the open project.
bool SaveFootprint(FOOTPRINT *aFootprint)
Save in an existing library a given footprint.
std::map< KIID, KIID > m_boardFootprintUuids
bool IsContentModified() const override
Get if any footprints or libraries have been modified but not saved.
bool Clear_Pcb(bool aQuery)
Delete all and reinitialize the current board.
Definition: initpcb.cpp:97
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:536
virtual void SetBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr) override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
APPEARANCE_CONTROLS * m_appearancePanel
const VECTOR2I GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
BOARD * GetBoard() const
void SetBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr) override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
bool Clear_Pcb(bool aQuery, bool aFinal=false)
Delete all and reinitialize the current board.
Definition: initpcb.cpp:43
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 ReCreateAuxiliaryToolbar() override
void UpdateTitle()
Set the main window title bar text.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:363
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:243
This file is part of the common library.
#define _(s)