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  * @author Maciej Suminski <maciej.suminski@cern.ch>
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 <pcb_base_edit_frame.h>
26 #include <tool/tool_manager.h>
27 #include <pcb_draw_panel_gal.h>
28 #include <pcb_layer_widget.h>
29 #include <pcbnew_settings.h>
30 #include <pgm_base.h>
32 #include <class_board.h>
33 #include <view/view.h>
34 #include "footprint_info_impl.h"
35 #include <project.h>
38 #include <tools/pcb_actions.h>
40 
41 PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
42  FRAME_T aFrameType, const wxString& aTitle,
43  const wxPoint& aPos, const wxSize& aSize, long aStyle,
44  const wxString& aFrameName ) :
45  PCB_BASE_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
46  m_rotationAngle( 900 ), m_undoRedoBlocked( false ),
47  m_Layers( nullptr ),
48  m_selectionFilterPanel( nullptr )
49 {
50  if( !GFootprintList.GetCount() )
51  {
52  wxTextFile footprintInfoCache( Prj().GetProjectPath() + "fp-info-cache" );
53  GFootprintList.ReadCacheFromFile( &footprintInfoCache );
54  }
55 }
56 
58 {
59  if( wxFileName::IsDirWritable( Prj().GetProjectPath() ) )
60  {
61  wxTextFile footprintInfoCache( Prj().GetProjectPath() + "fp-info-cache" );
62  GFootprintList.WriteCacheToFile( &footprintInfoCache );
63  }
64 
65  GetCanvas()->GetView()->Clear();
66 }
67 
68 
69 void PCB_BASE_EDIT_FRAME::SetRotationAngle( int aRotationAngle )
70 {
71  wxCHECK2_MSG( aRotationAngle > 0 && aRotationAngle <= 900, aRotationAngle = 900,
72  wxT( "Invalid rotation angle, defaulting to 90." ) );
73 
74  m_rotationAngle = aRotationAngle;
75 }
76 
77 
79 {
81 
83 }
84 
85 
87 {
88  bool new_board = ( aBoard != m_Pcb );
89 
90  if( new_board )
91  {
92  if( m_toolManager )
94 
95  GetCanvas()->GetView()->Clear();
96  }
97 
98  PCB_BASE_FRAME::SetBoard( aBoard );
99 
101 
102  // update the tool manager with the new board and its view.
103  if( m_toolManager )
104  {
105  GetCanvas()->DisplayBoard( aBoard );
106 
107  GetCanvas()->UpdateColors();
108  m_toolManager->SetEnvironment( aBoard, GetCanvas()->GetView(),
109  GetCanvas()->GetViewControls(), config(), this );
110 
111  if( new_board )
113  }
114 }
115 
116 
118 {
120 
122 }
123 
124 
126 {
128 
129  // Update the grid checkbox in the layer widget
130  if( m_Layers )
131  m_Layers->SetRenderState( LAYER_GRID, aVisible );
132 
133  // TODO (ISM): Remove this by changing toolbars to use the EVT_UPDATE_UI to get the state
134  SyncToolbars();
135 }
136 
137 
139 {
140  return Pgm().GetSettingsManager().GetColorSettings( GetPcbNewSettings()->m_ColorTheme );
141 }
void WriteCacheToFile(wxTextFile *aFile) override
virtual void SetBoard(BOARD *aBoard)
Function SetBoard sets 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)
virtual void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
wxPoint m_GridOrigin
origin for grid offsets
void ActivateGalCanvas() override
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
Model changes (required full reload)
Definition: tool_base.h:82
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:551
PCBNEW_SETTINGS * GetPcbNewSettings()
void SetGridOrigin(const VECTOR2D &aGridOrigin)
Set the origin point for the grid.
void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
virtual void SyncToolbars()
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
unsigned GetCount() const
virtual void ActivateGalCanvas() override
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
COLOR_SETTINGS * GetColorSettings() override
Helper to retrieve the current color settings.
void DisplayBoard(BOARD *aBoard)
Function DisplayBoard adds all items from the current board to the VIEW, so they can be displayed by ...
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:1111
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
PCB_LAYER_WIDGET * m_Layers
Layer manager. It is the responsibility of the child frames to instantiate this.
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Function ResetTools() Resets all tools (i.e.
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
void SyncLayersVisibility(const BOARD *aBoard)
Function SyncLayersVisibility Updates "visibility" property of each layer of a given BOARD.
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
void UpdateColors()
Updates the color settings in the painter and GAL.
int m_rotationAngle
User defined rotation angle (in tenths of a degree).
void SetGridVisibility(bool aVisible) override
Function SetGridVisibility()
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
see class PGM_BASE
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Sets the work environment (model, view, view controls and the parent window).
virtual void SetBoard(BOARD *aBoard) override
void ReadCacheFromFile(wxTextFile *aFile) override
virtual void ReCreateAuxiliaryToolbar()
Color settings are a bit different than most of the settings objects in that there can be more than o...
void SetRenderState(int aId, bool isSet)
Function SetRenderState sets the state of the checkbox associated with aId within the Render tab grou...
void SetRotationAngle(int aRotationAngle)
Function SetRotationAngle() Sets the angle used for rotate operations.
virtual void SetGridVisibility(bool aVisible)
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.