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 <maciej.suminski@cern.ch>
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_i.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 <dimension.h>
35 #include <footprint_info_impl.h>
36 #include <project.h>
43 
44 
45 PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
46  FRAME_T aFrameType, const wxString& aTitle,
47  const wxPoint& aPos, const wxSize& aSize, long aStyle,
48  const wxString& aFrameName ) :
49  PCB_BASE_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
50  m_rotationAngle( 900 ), m_undoRedoBlocked( false ),
51  m_selectionFilterPanel( nullptr ),
52  m_appearancePanel( nullptr )
53 {
54  Bind( wxEVT_IDLE,
55  [this]( wxIdleEvent& aEvent )
56  {
57  // Handle cursor adjustments. While we can get motion and key events through
58  // wxWidgets, we can't get modifier-key-up events.
59  if( m_toolManager )
60  {
62 
63  if( selTool )
64  selTool->OnIdle( aEvent );
65  }
66  } );
67 }
68 
69 
71 {
72  GetCanvas()->GetView()->Clear();
73 }
74 
75 
77 {
79  wxFileName projectName( Prj().GetProjectFullName() );
80 
81  if( mgr->IsProjectOpen() && wxFileName::IsDirWritable( projectName.GetPath() )
82  && projectName.Exists() )
83  {
84  GFootprintList.WriteCacheToFile( Prj().GetProjectPath() + "fp-info-cache" );
85  }
86 
87  // Close the project if we are standalone, so it gets cleaned up properly
88  if( mgr->IsProjectOpen() && Kiface().IsSingle() )
89  mgr->UnloadProject( &Prj(), false );
90 }
91 
92 
93 bool PCB_BASE_EDIT_FRAME::TryBefore( wxEvent& aEvent )
94 {
95  static bool s_switcherShown = false;
96 
97  if( !s_switcherShown && wxGetKeyState( WXK_RAW_CONTROL ) && wxGetKeyState( WXK_TAB ) )
98  {
99  if( m_appearancePanel && this->IsActive() )
100  {
101  const wxArrayString& mru = m_appearancePanel->GetLayerPresetsMRU();
102  EDA_VIEW_SWITCHER switcher( this, mru );
103 
104  s_switcherShown = true;
105  switcher.ShowModal();
106  s_switcherShown = false;
107 
108  int idx = switcher.GetSelection();
109 
110  if( idx >= 0 && idx < (int) mru.size() )
111  m_appearancePanel->ApplyLayerPreset( mru[idx] );
112 
113  return true;
114  }
115  }
116 
117  return PCB_BASE_FRAME::TryBefore( aEvent );
118 }
119 
120 
121 void PCB_BASE_EDIT_FRAME::SetRotationAngle( int aRotationAngle )
122 {
123  wxCHECK2_MSG( aRotationAngle > 0 && aRotationAngle <= 900, aRotationAngle = 900,
124  wxT( "Invalid rotation angle, defaulting to 90." ) );
125 
126  m_rotationAngle = aRotationAngle;
127 }
128 
129 
131 {
133 
135 }
136 
137 
139 {
140  bool new_board = ( aBoard != m_pcb );
141 
142  if( new_board )
143  {
144  if( m_toolManager )
146 
147  GetCanvas()->GetView()->Clear();
148  GetCanvas()->GetView()->InitPreview();
149  }
150 
151  PCB_BASE_FRAME::SetBoard( aBoard );
152 
154 
155  if( new_board )
156  {
157  BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings();
158  bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
159  }
160 
161  // update the tool manager with the new board and its view.
162  if( m_toolManager )
163  {
164  GetCanvas()->DisplayBoard( aBoard );
165 
166  GetCanvas()->UpdateColors();
167  m_toolManager->SetEnvironment( aBoard, GetCanvas()->GetView(),
168  GetCanvas()->GetViewControls(), config(), this );
169 
170  if( new_board )
172  }
173 }
174 
175 
177 {
179 
180  if( BOARD* board = GetBoard() )
181  {
182  EDA_UNITS units = GetUserUnits();
183  KIGFX::VIEW* view = GetCanvas()->GetView();
184 
185  INSPECTOR_FUNC inspector =
186  [units, view]( EDA_ITEM* aItem, void* aTestData )
187  {
188  DIMENSION_BASE* dimension = static_cast<DIMENSION_BASE*>( aItem );
189 
190  if( dimension->GetUnitsMode() == DIM_UNITS_MODE::AUTOMATIC )
191  {
192  dimension->SetUnits( units );
193  dimension->Update();
194  view->Update( dimension );
195  }
196 
198  };
199 
200  board->Visit( inspector, nullptr, GENERAL_COLLECTOR::Dimensions );
201  }
202 
204 }
205 
206 
208 {
210 
211  // Update the grid checkbox in the layer widget
212  if( m_appearancePanel )
214 }
215 
216 
218 {
219  if( m_appearancePanel )
220  m_appearancePanel->SetObjectVisible( aLayer, aVisible );
221 }
222 
223 
225 {
226  return Pgm().GetSettingsManager().GetColorSettings( GetPcbNewSettings()->m_ColorTheme );
227 }
228 
229 
231 {
232  if( !GetBoard() )
233  return wxEmptyString;
234 
235  wxFileName fn = GetBoard()->GetFileName();
236  fn.SetExt( DesignRulesFileExtension );
237  return Prj().AbsolutePath( fn.GetFullName() );
238 }
239 
240 
241 void PCB_BASE_EDIT_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
242 {
244 
245  // The text in the collapsible pane headers need to be updated
246  if( m_appearancePanel )
248 }
249 
250 
252 {
253  if( m_appearancePanel )
255 }
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:81
APPEARANCE_CONTROLS * m_appearancePanel
DIM_UNITS_MODE GetUnitsMode() const
Definition: dimension.cpp:150
void handleActivateEvent(wxActivateEvent &aEvent) override
Handle a window activation event.
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.
const std::string DesignRulesFileExtension
void InitPreview()
Definition: view.cpp:1540
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
void SetUnits(EDA_UNITS aUnits)
Definition: dimension.cpp:144
const wxArrayString & GetLayerPresetsMRU()
void Update()
Updates the dimension's cached text and geometry.
Definition: dimension.h:146
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:300
void OnIdle(wxIdleEvent &aEvent)
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:271
void doCloseWindow() override
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: pcbnew.cpp:339
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.
bool IsSingle() const
Is this KIFACE_I running under single_top?
Definition: kiface_i.h:104
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:70
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:1091
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
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:157
see class PGM_BASE
static const KICAD_T Dimensions[]
A scan list for dimensions.
Definition: collectors.h:309
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:150
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:67
Abstract dimension API.
Definition: dimension.h:95
void SetRotationAngle(int aRotationAngle)
Set the angle used for rotate operations.
virtual void SetGridVisibility(bool aVisible)
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:1503
COLOR_SETTINGS * GetColorSettings() const override
Helper to retrieve the current color settings.
Container for design settings for a BOARD object.