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>
29 #include <class_board.h>
30 #include <view/view.h>
31 #include "footprint_info_impl.h"
32 #include <project.h>
33 #include <tools/pcb_actions.h>
34 
35 PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
36  FRAME_T aFrameType, const wxString& aTitle,
37  const wxPoint& aPos, const wxSize& aSize, long aStyle,
38  const wxString& aFrameName ) :
39  PCB_BASE_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
40  m_rotationAngle( 900 ), m_undoRedoBlocked( false )
41 {
42  if( !GFootprintList.GetCount() )
43  {
44  wxTextFile footprintInfoCache( Prj().GetProjectPath() + "fp-info-cache" );
45  GFootprintList.ReadCacheFromFile( &footprintInfoCache );
46  }
47 }
48 
50 {
51  wxTextFile footprintInfoCache( Prj().GetProjectPath() + "fp-info-cache" );
52  GFootprintList.WriteCacheToFile( &footprintInfoCache );
53 }
54 
55 
56 void PCB_BASE_EDIT_FRAME::SetRotationAngle( int aRotationAngle )
57 {
58  wxCHECK2_MSG( aRotationAngle > 0 && aRotationAngle <= 900, aRotationAngle = 900,
59  wxT( "Invalid rotation angle, defaulting to 90." ) );
60 
61  m_rotationAngle = aRotationAngle;
62 }
63 
64 
66 {
68 
69  // No matter what, reenable undo/redo on switching to the legacy canvas
70  if( !aEnable )
71  UndoRedoBlock( false );
72  else
73  static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->SyncLayersVisibility( m_Pcb );
74 }
75 
76 
78 {
79  bool new_board = ( aBoard != m_Pcb );
80 
81  if( new_board )
82  {
83  if( m_toolManager )
85 
86  GetGalCanvas()->GetView()->Clear();
87  }
88 
89  PCB_BASE_FRAME::SetBoard( aBoard );
90 
92 
93  // update the tool manager with the new board and its view.
94  if( m_toolManager )
95  {
96  PCB_DRAW_PANEL_GAL* drawPanel = static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() );
97 
98  drawPanel->DisplayBoard( aBoard );
99  drawPanel->UseColorScheme( &Settings().Colors() );
100  m_toolManager->SetEnvironment( aBoard, drawPanel->GetView(),
101  drawPanel->GetViewControls(), this );
102 
103  if( new_board )
105  }
106 }
107 
108 
110 {
112 
114 
115  if( m_toolManager )
117 }
118 
119 
TOOL_MANAGER * m_toolManager
Definition: draw_frame.h:125
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 ...
const wxPoint & GetGridOrigin() const
Definition: class_board.h:356
Model changes (required full reload)
Definition: tool_base.h:83
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
Class BOARD to handle a board.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
static TOOL_ACTION updateUnits
Definition: pcb_actions.h:368
void UndoRedoBlock(bool aBlock=true)
Function UndoRedoBlock Enables/disable undo and redo operations.
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
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 ...
void UseGalCanvas(bool aEnable) override
>
virtual void UseGalCanvas(bool aEnable) override
>
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: pcbnew.cpp:338
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
unsigned GetCount() const
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, wxWindow *aFrame)
Sets the work environment (model, view, view controls and the parent window).
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:1108
PCB_GENERAL_SETTINGS & Settings()
virtual void ReCreateAuxiliaryToolbar()
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Function ResetTools() Resets all tools (i.e.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
void UseColorScheme(const COLORS_DESIGN_SETTINGS *aSettings)
Function UseColorScheme Applies layer color settings.
int m_rotationAngle
User defined rotation angle (in tenths of a degree).
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
virtual void SetBoard(BOARD *aBoard) override
>
void ReadCacheFromFile(wxTextFile *aFile) override
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel...
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:928
void SetRotationAngle(int aRotationAngle)
Function SetRotationAngle() Sets the angle used for rotate operations.
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...