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 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 <pcbnew_settings.h>
30 #include <pgm_base.h>
31 #include <board.h>
32 #include "footprint_info_impl.h"
33 #include <project.h>
36 #include <tools/pcb_actions.h>
40 #include <dimension.h>
42 
43 
44 PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
45  FRAME_T aFrameType, const wxString& aTitle,
46  const wxPoint& aPos, const wxSize& aSize, long aStyle,
47  const wxString& aFrameName ) :
48  PCB_BASE_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
49  m_rotationAngle( 900 ), m_undoRedoBlocked( false ),
50  m_selectionFilterPanel( nullptr ),
51  m_appearancePanel( nullptr )
52 {
53 }
54 
55 
57 {
58  GetCanvas()->GetView()->Clear();
59 }
60 
61 
63 {
65  wxFileName projectName( Prj().GetProjectFullName() );
66 
67  if( mgr->IsProjectOpen() && wxFileName::IsDirWritable( projectName.GetPath() )
68  && projectName.Exists() )
69  {
70  GFootprintList.WriteCacheToFile( Prj().GetProjectPath() + "fp-info-cache" );
71  }
72 
73  // Close the project if we are standalone, so it gets cleaned up properly
74  if( mgr->IsProjectOpen() && Kiface().IsSingle() )
75  mgr->UnloadProject( &Prj(), false );
76 }
77 
78 
79 bool PCB_BASE_EDIT_FRAME::TryBefore( wxEvent& aEvent )
80 {
81  static bool s_switcherShown = false;
82 
83  if( !s_switcherShown && wxGetKeyState( WXK_RAW_CONTROL ) && wxGetKeyState( WXK_TAB ) )
84  {
85  if( m_appearancePanel && this->IsActive() )
86  {
87  const wxArrayString& mru = m_appearancePanel->GetLayerPresetsMRU();
88  EDA_VIEW_SWITCHER switcher( this, mru );
89 
90  s_switcherShown = true;
91  switcher.ShowModal();
92  s_switcherShown = false;
93 
94  int idx = switcher.GetSelection();
95 
96  if( idx >= 0 && idx < (int) mru.size() )
98 
99  return true;
100  }
101  }
102 
103  return PCB_BASE_FRAME::TryBefore( aEvent );
104 }
105 
106 
107 void PCB_BASE_EDIT_FRAME::SetRotationAngle( int aRotationAngle )
108 {
109  wxCHECK2_MSG( aRotationAngle > 0 && aRotationAngle <= 900, aRotationAngle = 900,
110  wxT( "Invalid rotation angle, defaulting to 90." ) );
111 
112  m_rotationAngle = aRotationAngle;
113 }
114 
115 
117 {
119 
121 }
122 
123 
125 {
126  bool new_board = ( aBoard != m_pcb );
127 
128  if( new_board )
129  {
130  if( m_toolManager )
132 
133  GetCanvas()->GetView()->Clear();
134  GetCanvas()->GetView()->InitPreview();
135  }
136 
137  PCB_BASE_FRAME::SetBoard( aBoard );
138 
140 
141  if( new_board )
142  {
143  BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings();
144  bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
145  }
146 
147  // update the tool manager with the new board and its view.
148  if( m_toolManager )
149  {
150  GetCanvas()->DisplayBoard( aBoard );
151 
152  GetCanvas()->UpdateColors();
153  m_toolManager->SetEnvironment( aBoard, GetCanvas()->GetView(),
154  GetCanvas()->GetViewControls(), config(), this );
155 
156  if( new_board )
158  }
159 }
160 
161 
163 {
165 
166  if( BOARD* board = GetBoard() )
167  {
168  EDA_UNITS units = GetUserUnits();
169  KIGFX::VIEW* view = GetCanvas()->GetView();
170 
171  INSPECTOR_FUNC inspector =
172  [units, view]( EDA_ITEM* aItem, void* aTestData )
173  {
174  DIMENSION_BASE* dimension = static_cast<DIMENSION_BASE*>( aItem );
175 
176  if( dimension->GetUnitsMode() == DIM_UNITS_MODE::AUTOMATIC )
177  {
178  dimension->SetUnits( units );
179  dimension->Update();
180  view->Update( dimension );
181  }
182 
184  };
185 
186  board->Visit( inspector, nullptr, GENERAL_COLLECTOR::Dimensions );
187  }
188 
190 }
191 
192 
194 {
196 
197  // Update the grid checkbox in the layer widget
198  if( m_appearancePanel )
200 }
201 
202 
204 {
205  if( m_appearancePanel )
206  m_appearancePanel->SetObjectVisible( aLayer, aVisible );
207 }
208 
209 
211 {
212  return Pgm().GetSettingsManager().GetColorSettings( GetPcbNewSettings()->m_ColorTheme );
213 }
214 
215 
217 {
218  if( !GetBoard() )
219  return wxEmptyString;
220 
221  wxFileName fn = GetBoard()->GetFileName();
222  fn.SetExt( DesignRulesFileExtension );
223  return Prj().AbsolutePath( fn.GetFullName() );
224 }
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.
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
AUI panel for controlling layer and object visibility and appearance.
DIM_UNITS_MODE GetUnitsMode() const
Definition: dimension.cpp:150
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:1545
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:584
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:291
void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
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.
void doCloseWindow() override
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: pcbnew.cpp:331
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: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:1083
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.
int m_rotationAngle
User defined rotation angle (in tenths of a degree).
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:189
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
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149
virtual void ReCreateAuxiliaryToolbar()
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:1508
COLOR_SETTINGS * GetColorSettings() const override
Helper to retrieve the current color settings.
Container for design settings for a BOARD object.