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() + wxT( "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( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
100  {
101  if( !s_switcherShown && wxGetKeyState( WXK_RAW_CONTROL ) && wxGetKeyState( WXK_TAB ) )
102  {
103  if( m_appearancePanel && this->IsActive() )
104  {
105  const wxArrayString& mru = m_appearancePanel->GetLayerPresetsMRU();
106  EDA_VIEW_SWITCHER switcher( this, mru );
107 
108  s_switcherShown = true;
109  switcher.ShowModal();
110  s_switcherShown = false;
111 
112  int idx = switcher.GetSelection();
113 
114  if( idx >= 0 && idx < (int) mru.size() )
115  m_appearancePanel->ApplyLayerPreset( mru[idx] );
116 
117  return true;
118  }
119  }
120  }
121 
122  return PCB_BASE_FRAME::TryBefore( aEvent );
123 }
124 
125 
126 void PCB_BASE_EDIT_FRAME::SetRotationAngle( int aRotationAngle )
127 {
128  wxCHECK2_MSG( aRotationAngle > 0 && aRotationAngle <= 900, aRotationAngle = 900,
129  wxT( "Invalid rotation angle, defaulting to 90." ) );
130 
131  m_rotationAngle = aRotationAngle;
132 }
133 
134 
136 {
138 
140 }
141 
142 
144 {
145  bool new_board = ( aBoard != m_pcb );
146 
147  if( new_board )
148  {
149  if( m_toolManager )
151 
152  GetCanvas()->GetView()->Clear();
153  GetCanvas()->GetView()->InitPreview();
154  }
155 
156  PCB_BASE_FRAME::SetBoard( aBoard, aReporter );
157 
159 
160  if( new_board )
161  {
162  BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings();
163  bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
164  }
165 
166  // update the tool manager with the new board and its view.
167  if( m_toolManager )
168  {
169  GetCanvas()->DisplayBoard( aBoard, aReporter );
170 
171  GetCanvas()->UpdateColors();
172  m_toolManager->SetEnvironment( aBoard, GetCanvas()->GetView(),
173  GetCanvas()->GetViewControls(), config(), this );
174 
175  if( new_board )
177  }
178 }
179 
180 
182 {
184 
185  if( BOARD* board = GetBoard() )
186  {
187  EDA_UNITS units = GetUserUnits();
188  KIGFX::VIEW* view = GetCanvas()->GetView();
189 
190  INSPECTOR_FUNC inspector =
191  [units, view]( EDA_ITEM* aItem, void* aTestData )
192  {
193  PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( aItem );
194 
195  if( dimension->GetUnitsMode() == DIM_UNITS_MODE::AUTOMATIC )
196  {
197  dimension->SetUnits( units );
198  dimension->Update();
199  view->Update( dimension );
200  }
201 
203  };
204 
205  board->Visit( inspector, nullptr, GENERAL_COLLECTOR::Dimensions );
206  }
207 
209 }
210 
211 
213 {
215 
216  // Update the grid checkbox in the layer widget
217  if( m_appearancePanel )
219 }
220 
221 
223 {
224  if( m_appearancePanel )
225  m_appearancePanel->SetObjectVisible( aLayer, aVisible );
226 }
227 
228 
230 {
231  return Pgm().GetSettingsManager().GetColorSettings( GetPcbNewSettings()->m_ColorTheme );
232 }
233 
234 
236 {
237  if( !GetBoard() )
238  return wxEmptyString;
239 
240  wxFileName fn = GetBoard()->GetFileName();
241  fn.SetExt( DesignRulesFileExtension );
242  return Prj().AbsolutePath( fn.GetFullName() );
243 }
244 
245 
246 void PCB_BASE_EDIT_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
247 {
249 
250  // The text in the collapsible pane headers need to be updated
251  if( m_appearancePanel )
253 }
254 
255 
257 {
258  if( m_appearancePanel )
260 }
void DisplayBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Add all items from the current board to the VIEW, so they can be displayed by GAL.
void SetUnits(EDA_UNITS aUnits)
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 ...
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.
A progress reporter interface for use in multi-threaded environments.
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:32
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.
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:196
const std::string DesignRulesFileExtension
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: cvpcb.cpp:140
void InitPreview()
Definition: view.cpp:1607
Abstract dimension API.
Definition: pcb_dimension.h:95
const wxArrayString & GetLayerPresetsMRU()
const wxPoint & GetGridOrigin()
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:229
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:621
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:68
void Clear()
Remove all items from the view.
Definition: view.cpp:1100
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.
virtual void SetBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
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:191
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).
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:99
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:1570
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.