KiCad PCB EDA Suite
pcb_base_edit_frame.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) 2014 CERN
5  * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Maciej Suminski <[email protected]>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <kiface_base.h>
27 #include <pcb_base_edit_frame.h>
28 #include <tool/tool_manager.h>
29 #include <tools/pcb_actions.h>
31 #include <pcbnew_settings.h>
32 #include <pgm_base.h>
33 #include <board.h>
34 #include <board_design_settings.h>
35 #include <pcb_dimension.h>
36 #include <footprint_info_impl.h>
37 #include <project.h>
44 #include <collectors.h>
45 
46 
47 PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
48  FRAME_T aFrameType, const wxString& aTitle,
49  const wxPoint& aPos, const wxSize& aSize, long aStyle,
50  const wxString& aFrameName ) :
51  PCB_BASE_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
52  m_rotationAngle( 900 ), m_undoRedoBlocked( false ),
53  m_selectionFilterPanel( nullptr ),
54  m_appearancePanel( nullptr )
55 {
56  Bind( wxEVT_IDLE,
57  [this]( wxIdleEvent& aEvent )
58  {
59  // Handle cursor adjustments. While we can get motion and key events through
60  // wxWidgets, we can't get modifier-key-up events.
61  if( m_toolManager )
62  {
64 
65  if( selTool )
66  selTool->OnIdle( aEvent );
67  }
68  } );
69 }
70 
71 
73 {
74  GetCanvas()->GetView()->Clear();
75 }
76 
77 
79 {
81  wxFileName projectName( Prj().GetProjectFullName() );
82 
83  if( mgr->IsProjectOpen() && wxFileName::IsDirWritable( projectName.GetPath() )
84  && projectName.Exists() )
85  {
86  GFootprintList.WriteCacheToFile( Prj().GetProjectPath() + "fp-info-cache" );
87  }
88 
89  // Close the project if we are standalone, so it gets cleaned up properly
90  if( mgr->IsProjectOpen() && Kiface().IsSingle() )
91  mgr->UnloadProject( &Prj(), false );
92 }
93 
94 
95 bool PCB_BASE_EDIT_FRAME::TryBefore( wxEvent& aEvent )
96 {
97  static bool s_switcherShown = false;
98 
99  if( !s_switcherShown && wxGetKeyState( WXK_RAW_CONTROL ) && wxGetKeyState( WXK_TAB ) )
100  {
101  if( m_appearancePanel && this->IsActive() )
102  {
103  const wxArrayString& mru = m_appearancePanel->GetLayerPresetsMRU();
104  EDA_VIEW_SWITCHER switcher( this, mru );
105 
106  s_switcherShown = true;
107  switcher.ShowModal();
108  s_switcherShown = false;
109 
110  int idx = switcher.GetSelection();
111 
112  if( idx >= 0 && idx < (int) mru.size() )
113  m_appearancePanel->ApplyLayerPreset( mru[idx] );
114 
115  return true;
116  }
117  }
118 
119  return PCB_BASE_FRAME::TryBefore( aEvent );
120 }
121 
122 
123 void PCB_BASE_EDIT_FRAME::SetRotationAngle( int aRotationAngle )
124 {
125  wxCHECK2_MSG( aRotationAngle > 0 && aRotationAngle <= 900, aRotationAngle = 900,
126  wxT( "Invalid rotation angle, defaulting to 90." ) );
127 
128  m_rotationAngle = aRotationAngle;
129 }
130 
131 
133 {
135 
137 }
138 
139 
141 {
142  bool new_board = ( aBoard != m_pcb );
143 
144  if( new_board )
145  {
146  if( m_toolManager )
148 
149  GetCanvas()->GetView()->Clear();
150  GetCanvas()->GetView()->InitPreview();
151  }
152 
153  PCB_BASE_FRAME::SetBoard( aBoard );
154 
156 
157  if( new_board )
158  {
159  BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings();
160  bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
161  }
162 
163  // update the tool manager with the new board and its view.
164  if( m_toolManager )
165  {
166  GetCanvas()->DisplayBoard( aBoard );
167 
168  GetCanvas()->UpdateColors();
169  m_toolManager->SetEnvironment( aBoard, GetCanvas()->GetView(),
170  GetCanvas()->GetViewControls(), config(), this );
171 
172  if( new_board )
174  }
175 }
176 
177 
179 {
181 
182  if( BOARD* board = GetBoard() )
183  {
184  EDA_UNITS units = GetUserUnits();
185  KIGFX::VIEW* view = GetCanvas()->GetView();
186 
187  INSPECTOR_FUNC inspector =
188  [units, view]( EDA_ITEM* aItem, void* aTestData )
189  {
190  PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( aItem );
191 
192  if( dimension->GetUnitsMode() == DIM_UNITS_MODE::AUTOMATIC )
193  {
194  dimension->SetUnits( units );
195  dimension->Update();
196  view->Update( dimension );
197  }
198 
200  };
201 
202  board->Visit( inspector, nullptr, GENERAL_COLLECTOR::Dimensions );
203  }
204 
206 }
207 
208 
210 {
212 
213  // Update the grid checkbox in the layer widget
214  if( m_appearancePanel )
216 }
217 
218 
220 {
221  if( m_appearancePanel )
222  m_appearancePanel->SetObjectVisible( aLayer, aVisible );
223 }
224 
225 
227 {
228  return Pgm().GetSettingsManager().GetColorSettings( GetPcbNewSettings()->m_ColorTheme );
229 }
230 
231 
233 {
234  if( !GetBoard() )
235  return wxEmptyString;
236 
237  wxFileName fn = GetBoard()->GetFileName();
238  fn.SetExt( DesignRulesFileExtension );
239  return Prj().AbsolutePath( fn.GetFullName() );
240 }
241 
242 
243 void PCB_BASE_EDIT_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
244 {
246 
247  // The text in the collapsible pane headers need to be updated
248  if( m_appearancePanel )
250 }
251 
252 
254 {
255  if( m_appearancePanel )
257 }
void SetUnits(EDA_UNITS aUnits)
virtual void SetBoard(BOARD *aBoard)
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
PCB_BASE_EDIT_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName)
void SetObjectVisible(GAL_LAYER_ID aLayer, bool aVisible=true)
virtual void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
wxPoint m_GridOrigin
origin for grid offsets
void ActivateGalCanvas() override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
void ApplyLayerPreset(const wxString &aPresetName)
SETTINGS_MANAGER * GetSettingsManager() const
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual void handleActivateEvent(wxActivateEvent &aEvent)
Handle a window activation event.
wxString GetDesignRulesPath()
Return the absolute path to the design rules file for the currently-loaded board.
Model changes (required full reload)
Definition: tool_base.h:80
APPEARANCE_CONTROLS * m_appearancePanel
void handleActivateEvent(wxActivateEvent &aEvent) override
Handle a window activation event.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:32
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition: layer_ids.h:185
const std::string DesignRulesFileExtension
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: cvpcb.cpp:140
void InitPreview()
Definition: view.cpp:1549
Abstract dimension API.
Definition: pcb_dimension.h:95
const wxArrayString & GetLayerPresetsMRU()
void SetGridOrigin(const VECTOR2D &aGridOrigin)
Set the origin point for the grid.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
const wxString & GetFileName() const
Definition: board.h:228
void OnIdle(wxIdleEvent &aEvent)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
virtual void OnLayerAlphaChanged()
Notify the frame that the layer Alpha is being changed.
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
Definition: project.cpp:269
void doCloseWindow() override
DIM_UNITS_MODE GetUnitsMode() const
bool TryBefore(wxEvent &aEvent) override
bool IsProjectOpen() const
Helper for checking if we have a project open TODO: This should be deprecated along with Prj() once w...
virtual void ActivateGalCanvas() override
Use to start up the GAL drawing canvas.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
std::function< SEARCH_RESULT(EDA_ITEM *aItem, void *aTestData) > INSPECTOR_FUNC
Used to inspect and possibly collect the (search) results of iterating over a list or tree of KICAD_T...
Definition: eda_item.h:69
void DisplayBoard(BOARD *aBoard)
Add all items from the current board to the VIEW, so they can be displayed by GAL.
void Clear()
Remove all items from the view.
Definition: view.cpp:1104
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Definition of file extensions used in Kicad.
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
void SyncLayersVisibility(const BOARD *aBoard)
Update "visibility" property of each layer of a given BOARD.
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void UpdateColors()
Update the color settings in the painter and GAL.
EDA_UNITS
Definition: eda_units.h:38
int GetSelection() const
void SetGridVisibility(bool aVisible) override
Override this function in the PCB_BASE_EDIT_FRAME to refill the layer widget.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:158
see class PGM_BASE
static const KICAD_T Dimensions[]
A scan list for dimensions.
Definition: collectors.h:308
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
virtual void SetBoard(BOARD *aBoard) override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
PCBNEW_SETTINGS * GetPcbNewSettings() const
The selection tool: currently supports:
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
virtual void ReCreateAuxiliaryToolbar()
void RefreshCollapsiblePanes()
Function to force a redraw of the collapsible panes in this control.
Color settings are a bit different than most of the settings objects in that there can be more than o...
void WriteCacheToFile(const wxString &aFilePath) override
BOARD * GetBoard() const
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
void SetRotationAngle(int aRotationAngle)
Set the angle used for rotate operations.
virtual void SetGridVisibility(bool aVisible)
bool IsSingle() const
Is this KIFACE running under single_top?
Definition: kiface_base.h:104
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
void SetObjectVisible(GAL_LAYER_ID aLayer, bool isVisible=true)
Update the manual layer alpha overrides.
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1512
COLOR_SETTINGS * GetColorSettings() const override
Helper to retrieve the current color settings.
Container for design settings for a BOARD object.
void Update()
Update the dimension's cached text and geometry.