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-2023 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
25#include <confirm.h>
26#include <pcb_edit_frame.h>
27#include <project.h>
28#include <tool/tool_manager.h>
31
32#include <board.h>
35
38
39
40bool PCB_EDIT_FRAME::Clear_Pcb( bool doAskAboutUnsavedChanges, bool aFinal )
41{
42 if( GetBoard() == nullptr )
43 return false;
44
45 if( doAskAboutUnsavedChanges && !GetBoard()->IsEmpty() )
46 {
47 if( !IsOK( this, _( "Current Board will be lost and this operation cannot be undone. "
48 "Continue?" ) ) )
49 {
50 return false;
51 }
52 }
53
54 // Release the lock file, if exists
56
57 // Clear undo and redo lists because we want a full deletion
59 GetScreen()->SetContentModified( false );
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() );
86
87 Zoom_Automatique( false );
88 }
89 else if( m_isClosing )
90 {
91 if( m_toolManager )
93
94 // Clear the view so we don't attempt redraws (particularly of the RATSNEST_VIEW_ITEM,
95 // which causes all manner of grief).
96 GetCanvas()->GetView()->Clear();
97 }
98
99 return true;
100}
101
102
103bool FOOTPRINT_EDIT_FRAME::Clear_Pcb( bool doAskAboutUnsavedChanges )
104{
105 if( GetBoard() == nullptr )
106 return false;
107
108 bool is_last_fp_from_brd = IsCurrentFPFromBoard();
109
110 if( doAskAboutUnsavedChanges && IsContentModified() )
111 {
112 wxSafeYield( this, true ); // Allow frame to come to front before showing warning.
113
115 this, _( "The current footprint has been modified. Save changes?" ),
116 [&]() -> bool
117 {
118 return SaveFootprint( GetBoard()->Footprints().front() );
119 } ) )
120 {
121 return false;
122 }
123 }
124
125 if( is_last_fp_from_brd )
126 m_boardFootprintUuids.clear();
127
128 // Clear undo and redo lists because we want a full deletion
130 GetScreen()->SetContentModified( false );
131
132 if( !m_isClosing )
133 {
134 SetBoard( new BOARD );
135
137 GetBoard()->GetDesignSettings() = cfg->m_DesignSettings;
138
140
141 // This board will only be used to hold a footprint for editing
142 GetBoard()->SetBoardUse( BOARD_USE::FPHOLDER );
143
144 // clear filename, to avoid overwriting an old file
145 GetBoard()->SetFileName( wxEmptyString );
146
148 }
149 else
150 {
151 if( m_toolManager )
153
154 // Clear the view so we don't attempt redraws
155 GetCanvas()->GetView()->Clear();
156 }
157
158
159 return true;
160}
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:276
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition: board.h:288
void SetFileName(const wxString &aFileName)
Definition: board.h:311
void SetEnabledLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition: board.cpp:709
void SynchronizeNetsAndNetClasses(bool aResetTrackAndViaSizes)
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1813
void ResetNetHighLight()
Reset all high light data to the init state.
Definition: board.cpp:2396
void SetVisibleLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
Definition: board.cpp:721
void SetCopperLayerCount(int aCount)
Definition: board.cpp:671
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:806
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
bool m_isClosing
Set by NonUserClose() to indicate that the user did not request the current close.
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.
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 doAskAboutUnsavedChanges)
Delete all and reinitialize the current board.
Definition: initpcb.cpp:103
FOOTPRINT_EDITOR_SETTINGS * GetSettings()
void Clear()
Remove all items from the view.
Definition: view.cpp:1121
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:573
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_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
BOARD * GetBoard() const
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
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.
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...
bool Clear_Pcb(bool doAskAboutUnsavedChanges, bool aFinal=false)
Delete all and reinitialize the current board.
Definition: initpcb.cpp:40
void ReCreateAuxiliaryToolbar() override
void UpdateTitle()
Set the main window title bar text.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:167
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition: tool_base.h:80
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:360
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:240
This file is part of the common library.
#define _(s)