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>
30 #include <class_board.h>
31 #include <view/view.h>
32 #include "footprint_info_impl.h"
33 #include <project.h>
35 #include <tools/pcb_actions.h>
36 
37 PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
38  FRAME_T aFrameType, const wxString& aTitle,
39  const wxPoint& aPos, const wxSize& aSize, long aStyle,
40  const wxString& aFrameName ) :
41  PCB_BASE_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
42  m_rotationAngle( 900 ), m_undoRedoBlocked( false ),
43  m_Layers( nullptr )
44 {
45  if( !GFootprintList.GetCount() )
46  {
47  wxTextFile footprintInfoCache( Prj().GetProjectPath() + "fp-info-cache" );
48  GFootprintList.ReadCacheFromFile( &footprintInfoCache );
49  }
50 }
51 
53 {
54  if( wxFileName::IsDirWritable( Prj().GetProjectPath() ) )
55  {
56  wxTextFile footprintInfoCache( Prj().GetProjectPath() + "fp-info-cache" );
57  GFootprintList.WriteCacheToFile( &footprintInfoCache );
58  }
59 
60  GetCanvas()->GetView()->Clear();
61 }
62 
63 
64 void PCB_BASE_EDIT_FRAME::SetRotationAngle( int aRotationAngle )
65 {
66  wxCHECK2_MSG( aRotationAngle > 0 && aRotationAngle <= 900, aRotationAngle = 900,
67  wxT( "Invalid rotation angle, defaulting to 90." ) );
68 
69  m_rotationAngle = aRotationAngle;
70 }
71 
72 
74 {
76 
78 }
79 
80 
82 {
83  bool new_board = ( aBoard != m_Pcb );
84 
85  if( new_board )
86  {
87  if( m_toolManager )
89 
90  GetCanvas()->GetView()->Clear();
91  }
92 
93  PCB_BASE_FRAME::SetBoard( aBoard );
94 
95  GetCanvas()->GetGAL()->SetGridOrigin( VECTOR2D( aBoard->GetGridOrigin() ) );
96 
97  // update the tool manager with the new board and its view.
98  if( m_toolManager )
99  {
100  GetCanvas()->DisplayBoard( aBoard );
101 
102  GetCanvas()->UpdateColors();
103  m_toolManager->SetEnvironment( aBoard, GetCanvas()->GetView(),
104  GetCanvas()->GetViewControls(), this );
105 
106  if( new_board )
108  }
109 }
110 
111 
113 {
115 
117 
118  if( m_toolManager )
120 }
121 
122 
124 {
126 
127  // Update the grid checkbox in the layer widget
128  if( m_Layers )
129  m_Layers->SetRenderState( LAYER_GRID, aVisible );
130 
131  // TODO (ISM): Remove this by changing toolbars to use the EVT_UPDATE_UI to get the state
132  SyncToolbars();
133 }
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 ...
void ActivateGalCanvas() override
Model changes (required full reload)
Definition: tool_base.h:81
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.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:139
static TOOL_ACTION updateUnits
Definition: pcb_actions.h:407
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
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.
const wxPoint & GetGridOrigin() const
Definition: class_board.h:342
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()
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
virtual void SetBoard(BOARD *aBoard) override
virtual void SetGridVisibility(bool aVisible) override
Function SetGridVisibility() Turn the display of the canvas grid on/off.
void ReadCacheFromFile(wxTextFile *aFile) override
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, EDA_BASE_FRAME *aFrame)
Sets the work environment (model, view, view controls and the parent window).
virtual void ReCreateAuxiliaryToolbar()
TOOL_MANAGER * m_toolManager
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.
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.