KiCad PCB EDA Suite
modview_frame.cpp File Reference
#include <fctsys.h>
#include <pgm_base.h>
#include <kiway.h>
#include <class_drawpanel.h>
#include <pcb_draw_panel_gal.h>
#include <wxPcbStruct.h>
#include <3d_viewer/eda_3d_viewer.h>
#include <dialog_helpers.h>
#include <msgpanel.h>
#include <fp_lib_table.h>
#include <lib_id.h>
#include <confirm.h>
#include <bitmaps.h>
#include <class_board.h>
#include <class_module.h>
#include <pcbnew.h>
#include <pcbnew_id.h>
#include <modview_frame.h>
#include <footprint_info.h>
#include <hotkeys.h>
#include <wildcards_and_files_ext.h>
#include <pcbnew_config.h>
#include <tool/tool_manager.h>
#include <tool/tool_dispatcher.h>
#include <tool/common_tools.h>
#include "tools/pcbnew_control.h"
#include "tools/pcb_actions.h"
#include <functional>
#include <memory>

Go to the source code of this file.

Macros

#define NEXT_PART   1
 
#define NEW_PART   0
 
#define PREVIOUS_PART   -1
 
#define MODAL_MODE_EXTRASTYLE   wxFRAME_FLOAT_ON_PARENT
 
#define FOOTPRINT_VIEWER_FRAME_NAME   "ModViewFrame"
 
#define FOOTPRINT_VIEWER_FRAME_NAME_MODAL   "ModViewFrameModal"
 

Functions

 EVT_TOOL (ID_MODVIEW_SELECT_LIB, FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary) EVT_TOOL(ID_MODVIEW_SELECT_PART
 
FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint EVT_TOOL (ID_MODVIEW_NEXT, FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList) EVT_TOOL(ID_MODVIEW_PREVIOUS
 
FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList EVT_TOOL (ID_MODVIEW_FOOTPRINT_EXPORT_TO_BOARD, FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint) FOOTPRINT_VIEWER_FRAME
 

Macro Definition Documentation

#define FOOTPRINT_VIEWER_FRAME_NAME   "ModViewFrame"

Referenced by EVT_TOOL().

#define FOOTPRINT_VIEWER_FRAME_NAME_MODAL   "ModViewFrameModal"
#define MODAL_MODE_EXTRASTYLE   wxFRAME_FLOAT_ON_PARENT
#define NEW_PART   0

Definition at line 68 of file modview_frame.cpp.

#define NEXT_PART   1
#define PREVIOUS_PART   -1

Function Documentation

Definition at line 97 of file modview_frame.cpp.

References BOARD::Add(), KIWAY_PLAYER::Destroy(), PCB_DRAW_PANEL_GAL::DisplayBoard(), FOOTPRINT_VIEWER_FRAME_NAME, FRAME_PCB, FRAME_PCB_MODULE_VIEWER, FRAME_PCB_MODULE_VIEWER_MODAL, g_Module_Viewer_Hokeys_Descr, EDA_DRAW_PANEL_GAL::GetBackend(), GetBoard(), BOARD_DESIGN_SETTINGS::GetDefault(), BOARD::GetDesignSettings(), EDA_DRAW_FRAME::GetGalCanvas(), EDA_DRAW_FRAME::GetGalDisplayOptions(), EDA_DRAW_PANEL_GAL::GetView(), EDA_DRAW_PANEL_GAL::GetViewControls(), ID_POPUP_GRID_LEVEL_1000, EDA_PANEINFO::InfoToolbarPane(), EDA_DRAW_FRAME::IsGalCanvasActive(), KiBitmap(), Kiway, PCAD2KICAD::Left, EDA_PANEINFO::MessageToolbarPane(), KIWAY::Player(), TOOL_MANAGER::SetEnvironment(), EDA_DRAW_PANEL_GAL::SetEventDispatcher(), LIB_ID::SetLibNickname(), BOARD::SetVisibleAlls(), and TO_UTF8.

131  :
132  PCB_BASE_FRAME( aKiway, aParent, aFrameType, _( "Footprint Library Browser" ),
133  wxDefaultPosition, wxDefaultSize,
134  aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ?
135  aParent ?
137  : KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP
139  aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ?
142 {
143  wxASSERT( aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ||
144  aFrameType == FRAME_PCB_MODULE_VIEWER );
145 
146  if( aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL )
147  SetModal( true );
148 
149  // Force the frame name used in config. the footprint viewer frame has a name
150  // depending on aFrameType (needed to identify the frame by wxWidgets),
151  // but only one configuration is preferable.
152  m_configFrameName = FOOTPRINT_VIEWER_FRAME_NAME;
153 
154  m_showAxis = true; // true to draw axis.
155 
156  // Give an icon
157  wxIcon icon;
158  icon.CopyFromBitmap( KiBitmap( modview_icon_xpm ) );
159  SetIcon( icon );
160 
161  m_hotkeysDescrList = g_Module_Viewer_Hokeys_Descr;
162 
163  m_libList = new wxListBox( this, ID_MODVIEW_LIB_LIST,
164  wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL );
165 
166  m_footprintList = new wxListBox( this, ID_MODVIEW_FOOTPRINT_LIST,
167  wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL );
168 
169  SetBoard( new BOARD() );
170  // In viewer, the default net clearance is not known (it depends on the actual board).
171  // So we do not show the default clearance, by setting it to 0
172  // The footprint or pad specific clearance will be shown
173  GetBoard()->GetDesignSettings().GetDefault()->SetClearance(0);
174 
175  // Ensure all layers and items are visible:
177  SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
178 
179  GetScreen()->m_Center = true; // Center coordinate origins on screen.
180  LoadSettings( config() );
181 
182  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
183 
184  GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
185 
186  // Menu bar is not mandatory: uncomment/comment the next line
187  // to add/remove the menubar
188  ReCreateMenuBar();
189  ReCreateHToolbar();
190  ReCreateVToolbar();
191 
192  ReCreateLibraryList();
193  UpdateTitle();
194 
195  // See for an existing board editor frame opened
196  // (we need it just to know some settings )
197  // TODO: find a better way to retrieve these settings)
198  bool isBordEditorRunning = Kiway().Player( FRAME_PCB, false ) != nullptr;
199  PCB_BASE_FRAME* pcbEditorFrame = static_cast<PCB_BASE_FRAME*>( Kiway().Player( FRAME_PCB, true ) );
200 
201  // Create GAL canvas
202  PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
203  pcbEditorFrame->GetGalDisplayOptions(),
204  pcbEditorFrame->GetGalCanvas()->GetBackend() );
205  SetGalCanvas( drawPanel );
206  bool switchToGalCanvas = pcbEditorFrame->IsGalCanvasActive();
207 
208  // delete pcbEditorFrame if it was not yet in use:
209  if( !isBordEditorRunning )
210  pcbEditorFrame->Destroy();
211 
212  // Create the manager and dispatcher & route draw panel events to the dispatcher
213  m_toolManager = new TOOL_MANAGER;
214  m_toolManager->SetEnvironment( GetBoard(), drawPanel->GetView(),
215  drawPanel->GetViewControls(), this );
216  m_actions = new PCB_ACTIONS();
217  m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions );
218  drawPanel->SetEventDispatcher( m_toolDispatcher );
219 
220  m_toolManager->RegisterTool( new PCBNEW_CONTROL );
221  m_toolManager->RegisterTool( new COMMON_TOOLS );
222  m_toolManager->InitTools();
223 
224  // If a footprint was previously loaded, reload it
225  if( getCurNickname().size() && getCurFootprintName().size() )
226  {
227  LIB_ID id;
228 
229  id.SetLibNickname( TO_UTF8( getCurNickname() ) );
230  id.SetLibItemName( TO_UTF8( getCurFootprintName() ) );
231  GetBoard()->Add( loadFootprint( id ) );
232  }
233 
234  drawPanel->DisplayBoard( m_Pcb );
235  updateView();
236 
237  m_auimgr.SetManagedWindow( this );
238 
239  wxSize minsize(100,-1); // Min size of list boxes
240 
241  // Main toolbar is initially docked at the top of the main window and dockable on any side.
242  // The close button is disable because the footprint viewer has no main menu to re-enable it.
243  // The tool bar will only be dockable on the top or bottom of the main frame window. This is
244  // most likely due to the fact that the other windows are not dockable and are preventing the
245  // tool bar from docking on the right and left.
246  wxAuiPaneInfo toolbarPaneInfo;
247  toolbarPaneInfo.Name( "m_mainToolBar" ).ToolbarPane().Top().CloseButton( false );
248 
249  EDA_PANEINFO info;
250  info.InfoToolbarPane();
251 
252  EDA_PANEINFO mesg;
253  mesg.MessageToolbarPane();
254 
255  // Manage main toolbar, top pane
256  m_auimgr.AddPane( m_mainToolBar, toolbarPaneInfo );
257 
258  // Manage the list of libraries, left pane.
259  m_auimgr.AddPane( m_libList,
260  wxAuiPaneInfo( info ).Name( "m_libList" )
261  .Left().Row( 1 ).MinSize( minsize ) );
262 
263  // Manage the list of footprints, center pane.
264  m_auimgr.AddPane( m_footprintList,
265  wxAuiPaneInfo( info ).Name( "m_footprintList" )
266  .Left().Row( 2 ).MinSize( minsize ) );
267 
268  // Manage the draw panel, right pane.
269  m_auimgr.AddPane( m_canvas,
270  wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
271  m_auimgr.AddPane( (wxWindow*) GetGalCanvas(),
272  wxAuiPaneInfo().Name( "DrawFrameGal" ).CentrePane().Hide() );
273 
274  // Manage the message panel, bottom pane.
275  m_auimgr.AddPane( m_messagePanel,
276  wxAuiPaneInfo( mesg ).Name( "MsgPanel" ).Bottom() );
277 
278  if( !m_perspective.IsEmpty() )
279  {
280  // Restore last saved sizes, pos and other params
281  // However m_mainToolBar size cannot be set to its last saved size
282  // because the actual size change depending on the way modview was called:
283  // the tool to export the current footprint exist or not.
284  // and the saved size is not always OK
285  // the trick is to get the default toolbar size, and set the size after
286  // calling LoadPerspective
287  wxSize tbsize = m_mainToolBar->GetSize();
288  m_auimgr.LoadPerspective( m_perspective, false );
289  m_auimgr.GetPane( m_mainToolBar ).BestSize( tbsize );
290  }
291 
292  // after changing something to the aui manager,
293  // call Update()() to reflect the changes
294  m_auimgr.Update();
295 
296  // Now Drawpanel is sized, we can use BestZoom to show the component (if any)
297 #ifdef USE_WX_GRAPHICS_CONTEXT
298  GetScreen()->SetZoom( BestZoom() );
299 #else
300  Zoom_Automatique( false );
301 #endif
302 
303  UseGalCanvas( switchToGalCanvas );
304 
305  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
306  {
307  Raise(); // On some window managers, this is needed
308  Show( true );
309  }
310 }
#define KICAD_DEFAULT_DRAWFRAME_STYLE
Definition: wxstruct.h:55
void DisplayBoard(const BOARD *aBoard)
Function DisplayBoard adds all items from the current board to the VIEW, so they can be displayed by ...
NETCLASSPTR GetDefault() const
Function GetDefault.
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Function GetGalDisplayOptions Returns a reference to the gal rendering options used by GAL for render...
Definition: draw_frame.h:838
GAL_TYPE GetBackend() const
Function GetBackend Returns the type of backend currently used by GAL canvas.
#define MODAL_MODE_EXTRASTYLE
void SetVisibleAlls()
Function SetVisibleAlls changes the bit-mask of visible element categories and layers.
#define FOOTPRINT_VIEWER_FRAME_NAME_MODAL
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
Class LIB_ID.
Definition: lib_id.h:56
Specialization of the wxAuiPaneInfo class for KiCad panels.
Definition: wxstruct.h:466
Class PCBNEW_CONTROL.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
Class TOOL_MANAGER.
Definition: tool_manager.h:49
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, KIWAY_PLAYER *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:302
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 Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:533
#define FOOTPRINT_VIEWER_FRAME_NAME
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:809
EDA_PANEINFO & InfoToolbarPane()
Function InfoToolbarPane Change *this to a information panel for for KiCad.
Definition: wxstruct.h:540
Class COMMON_TOOLS.
Definition: common_tools.h:38
Class TOOL_DISPATCHER.
BOARD * GetBoard()
int SetLibNickname(const UTF8 &aNickname)
Function SetLibNickname.
Definition: lib_id.cpp:219
EDA_PANEINFO & MessageToolbarPane()
Function MessageToolbarPane Change *this to a message pane for KiCad.
Definition: wxstruct.h:512
Class PCB_ACTIONS.
Definition: pcb_actions.h:42
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Function SetEventDispatcher() Sets a dispatcher that processes events and forwards them to tools...
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
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
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:817
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
KIWAY Kiway
struct EDA_HOTKEY_CONFIG g_Module_Viewer_Hokeys_Descr[]