KiCad PCB EDA Suite
eda_draw_frame.h
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) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
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 #ifndef DRAW_FRAME_H_
27 #define DRAW_FRAME_H_
28 
29 #include <eda_base_frame.h>
30 #include <kiway_player.h>
32 #include <gal/color4d.h>
33 #include <class_draw_panel_gal.h>
34 #include <origin_transforms.h>
35 #include "hotkeys_basic.h"
36 
37 class wxSingleInstanceChecker;
38 class ACTION_TOOLBAR;
39 class COLOR_SETTINGS;
40 class TOOL_MENU;
41 class APP_SETTINGS_BASE;
42 class wxFindReplaceData;
43 
44 namespace KIGFX
45 {
46  class GAL_DISPLAY_OPTIONS;
47  class RENDER_SETTINGS;
48 }
49 
50 using KIGFX::COLOR4D;
52 
53 #define LIB_EDIT_FRAME_NAME wxT( "LibeditFrame" )
54 #define SCH_EDIT_FRAME_NAME wxT( "SchematicFrame" )
55 #define PL_EDITOR_FRAME_NAME wxT( "PlEditorFrame" )
56 #define FOOTPRINT_WIZARD_FRAME_NAME wxT( "FootprintWizard" )
57 #define FOOTPRINT_EDIT_FRAME_NAME wxT( "ModEditFrame" )
58 #define FOOTPRINT_VIEWER_FRAME_NAME wxT( "ModViewFrame" )
59 #define FOOTPRINT_VIEWER_FRAME_NAME_MODAL wxT( "ModViewFrameModal" )
60 #define PCB_EDIT_FRAME_NAME wxT( "PcbFrame" )
61 
62 
70 {
71 public:
72  EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle,
73  const wxPoint& aPos, const wxSize& aSize, long aStyle,
74  const wxString& aFrameName );
75 
77 
86  bool LockFile( const wxString& aFileName );
87 
91  void ReleaseFile();
92 
93  wxFindReplaceData& GetFindReplaceData() { return *m_findReplaceData; }
94  wxArrayString& GetFindHistoryList() { return m_findStringHistoryList; }
95 
96  virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) = 0;
97  virtual const PAGE_INFO& GetPageSettings() const = 0;
98 
103  virtual const wxSize GetPageSizeIU() const = 0;
104 
108  bool GetShowPolarCoords() const { return m_polarCoords; }
109  void SetShowPolarCoords( bool aShow ) { m_polarCoords = aShow; }
110 
111  void ToggleUserUnits() override;
112 
119  void GetUnitPair( EDA_UNITS& aPrimaryUnit, EDA_UNITS& aSecondaryUnits );
120 
127  virtual const wxPoint& GetGridOrigin() const = 0;
128  virtual void SetGridOrigin( const wxPoint& aPosition ) = 0;
129 
136  wxPoint GetNearestGridPosition( const wxPoint& aPosition ) const;
137 
147  wxPoint GetNearestHalfGridPosition( const wxPoint& aPosition ) const;
148 
153  { return m_originTransforms; }
154 
155 
156  virtual const TITLE_BLOCK& GetTitleBlock() const = 0;
157  virtual void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) = 0;
158 
159  // the background color of the draw canvas:
160  // Virtual because some frames can have a specific way to get/set the bg color
161  virtual COLOR4D GetDrawBgColor() const { return m_drawBgColor; }
162  virtual void SetDrawBgColor( COLOR4D aColor) { m_drawBgColor= aColor ; }
163 
165  virtual COLOR_SETTINGS* GetColorSettings() const;
166 
167  bool ShowPageLimits() const { return m_showPageLimits; }
168  void SetShowPageLimits( bool aShow ) { m_showPageLimits = aShow; }
169 
179  bool LibraryFileBrowser( bool doOpen, wxFileName& aFilename, const wxString& wildcard,
180  const wxString& ext, bool isDirectory = false, bool aIsGlobal = false,
181  const wxString& aGlobalPath = wxEmptyString );
182 
183  void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
184 
185  virtual wxString GetScreenDesc() const;
186 
192  virtual BASE_SCREEN* GetScreen() const { return m_currentScreen; }
193 
200  virtual void ExecuteRemoteCommand( const char* cmdline ){}
201 
202  void EraseMsgBox();
203 
204  void ReCreateMenuBar() override { }
205  virtual void ReCreateHToolbar() = 0;
206  virtual void ReCreateVToolbar() = 0;
207  virtual void ReCreateOptToolbar() = 0;
208  virtual void ReCreateAuxiliaryToolbar() { }
209 
210  /*
211  * These 4 functions provide a basic way to show/hide grid and /get/set grid color.
212  *
213  * These parameters are saved in KiCad config for each main frame.
214  */
215  bool IsGridVisible() const;
216  virtual void SetGridVisibility( bool aVisible );
217 
218  virtual COLOR4D GetGridColor() { return m_gridColor; }
219  virtual void SetGridColor( COLOR4D aColor ) { m_gridColor = aColor; }
220 
230  void OnSelectGrid( wxCommandEvent& event );
231 
232  void OnGridSettings( wxCommandEvent& event );
233 
238  void UpdateGridSelectBox();
239 
243  void OnUpdateSelectGrid( wxUpdateUIEvent& aEvent );
244 
249  void UpdateZoomSelectBox();
250 
254  void OnUpdateSelectZoom( wxUpdateUIEvent& aEvent );
255 
259  const wxString GetZoomLevelIndicator() const;
260 
268  virtual void OnSelectZoom( wxCommandEvent& event );
269 
273  virtual void OnSize( wxSizeEvent& event );
274 
275  void OnMove( wxMoveEvent& aEvent ) override;
276 
280  virtual void HardRedraw();
281 
286  virtual void Zoom_Automatique( bool aWarpPointer );
287 
296  void FocusOnLocation( const wxPoint& aPos );
297 
302  void AddStandardSubMenus( TOOL_MENU& aMenu );
303 
312  void PrintDrawingSheet( const RENDER_SETTINGS* aSettings, BASE_SCREEN* aScreen,
313  double aMils2Iu, const wxString& aFilename,
314  const wxString& aSheetLayer = wxEmptyString );
315 
316  void DisplayToolMsg( const wxString& msg ) override;
317 
323  virtual void OnPageSettingsChange() {}
324 
332  void UpdateStatusBar() override;
333 
337  void DisplayUnitsMsg();
338 
342  virtual void DisplayGridMsg();
343 
344  /* interprocess communication */
345  void CreateServer( int service, bool local = true );
346  void OnSockRequest( wxSocketEvent& evt );
347  void OnSockRequestServer( wxSocketEvent& evt );
348 
349  void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
350  void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
351 
362  void AppendMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding = 6 );
363 
367  virtual void ClearMsgPanel();
368 
374  void SetMsgPanel( const std::vector< MSG_PANEL_ITEM >& aList );
375  void SetMsgPanel( EDA_ITEM* aItem );
376 
384  void SetMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding = 6 );
385 
389  virtual void UpdateMsgPanel();
390 
394  virtual EDA_ITEM* GetItem( const KIID& aId ) { return nullptr; }
395 
401  virtual void PrintPage( const RENDER_SETTINGS* aSettings );
402 
406  virtual void ActivateGalCanvas();
407 
411  virtual void SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType );
412 
418  virtual EDA_DRAW_PANEL_GAL* GetCanvas() const { return m_canvas; }
419  void SetCanvas( EDA_DRAW_PANEL_GAL* aPanel ) { m_canvas = aPanel; }
420 
421  wxWindow* GetToolCanvas() const override { return GetCanvas(); }
422 
427 
428  void RefreshCanvas() override
429  {
430  GetCanvas()->Refresh();
431  }
432 
446  virtual const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const;
447 
451  void RecreateToolbars();
452 
453  DECLARE_EVENT_TABLE()
454 
455 protected:
456  virtual void SetScreen( BASE_SCREEN* aScreen ) { m_currentScreen = aScreen; }
457 
458  void unitsChangeRefresh() override;
459 
460  void setupUnits( APP_SETTINGS_BASE* aCfg );
461 
465  void resolveCanvasType();
466 
471 
476 
477  wxSocketServer* m_socketServer;
478  std::vector<wxSocketBase*> m_sockets;
479 
481  std::unique_ptr<wxSingleInstanceChecker> m_file_checker;
482 
483  bool m_showPageLimits; // True to display the page limits
484  COLOR4D m_gridColor; // Grid color
485  COLOR4D m_drawBgColor; // The background color of the draw canvas; BLACK for
486  // Pcbnew, BLACK or WHITE for Eeschema
487  int m_undoRedoCountMax; // Default Undo/Redo command Max depth, to be handed
488  // to screens
489  bool m_polarCoords; // For those frames that support polar coordinates
490 
491  bool m_showBorderAndTitleBlock; // Show the worksheet (border and title block).
492  long m_firstRunDialogSetting; // Show first run dialog on startup
493 
494  wxChoice* m_gridSelectBox;
495  wxChoice* m_zoomSelectBox;
496 
498  ACTION_TOOLBAR* m_auxiliaryToolBar; // Additional tools under main toolbar
499  ACTION_TOOLBAR* m_drawToolBar; // Drawing tools (typically on right edge of window)
500  ACTION_TOOLBAR* m_optionsToolBar; // Options (typically on left edge of window)
501 
502  wxFindReplaceData* m_findReplaceData;
503  wxArrayString m_findStringHistoryList;
505 
508 
510 
513 
514 private:
517 
520 
523 };
524 
525 #endif // DRAW_FRAME_H_
void ReCreateMenuBar() override
Recreates the menu bar.
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)=0
virtual void ReCreateVToolbar()=0
void AddStandardSubMenus(TOOL_MENU &aMenu)
Construct a "basic" menu for a tool, containing only items that apply to all tools (e....
virtual EDA_ITEM * GetItem(const KIID &aId)
Fetch an item by KIID.
Define the structure of a toolbar with buttons that invoke ACTIONs.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:61
virtual const TITLE_BLOCK & GetTitleBlock() const =0
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
ACTION_TOOLBAR * m_auxiliaryToolBar
virtual void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)=0
ACTION_TOOLBAR * m_optionsToolBar
void OnSockRequestServer(wxSocketEvent &evt)
Definition: eda_dde.cpp:102
virtual void SetScreen(BASE_SCREEN *aScreen)
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:32
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
void SetShowPolarCoords(bool aShow)
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false, bool aIsGlobal=false, const wxString &aGlobalPath=wxEmptyString)
Manage a CONDITIONAL_MENU and some number of CONTEXT_MENUs as sub-menus.
Definition: tool_menu.h:42
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
std::vector< wxSocketBase * > m_sockets
interprocess communication
virtual void SetDrawBgColor(COLOR4D aColor)
void OnMove(wxMoveEvent &aEvent) override
void RecreateToolbars()
Rebuild all toolbars, and update the checked state of check tools.
wxArrayString m_findStringHistoryList
void resolveCanvasType()
Determines the Canvas type to load (with prompt if required) and initializes m_canvasType.
void ReleaseFile()
Release the current file marked in use.
void RefreshCanvas() override
virtual ORIGIN_TRANSFORMS & GetOriginTransforms()
Return a reference to the default ORIGIN_TRANSFORMS object.
wxPoint GetNearestHalfGridPosition(const wxPoint &aPosition) const
Return the nearest aGridSize / 2 location to aPosition.
void UpdateZoomSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
ACTION_TOOLBAR * m_mainToolBar
virtual void SetGridColor(COLOR4D aColor)
wxPoint GetNearestGridPosition(const wxPoint &aPosition) const
Return the nearest aGridSize location to aPosition.
EDA_MSG_PANEL is a panel to display various information messages.
Definition: msgpanel.h:104
The base class for create windows for drawing purpose.
COLOR4D m_drawBgColor
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:40
wxChoice * m_gridSelectBox
std::unique_ptr< wxSingleInstanceChecker > m_file_checker
virtual const wxSize GetPageSizeIU() const =0
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
wxFindReplaceData & GetFindReplaceData()
bool ShowPageLimits() const
virtual void ExecuteRemoteCommand(const char *cmdline)
Execute a remote command sent via socket (to port KICAD_PCB_PORT_SERVICE_NUMBER, currently 4242).
void DisplayUnitsMsg()
Display current unit pane in the status bar.
EDA_DRAW_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName)
EDA_DRAW_PANEL_GAL * m_canvas
This the frame's interface to setting GAL display options.
void UpdateGridSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
virtual const PAGE_INFO & GetPageSettings() const =0
virtual void Zoom_Automatique(bool aWarpPointer)
Redraw the screen with best zoom level and the best centering that shows all the page or the board.
Definition: kiid.h:44
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
BASE_SCREEN * m_currentScreen
current used SCREEN
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
wxArrayString m_replaceStringHistoryList
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
bool IsGridVisible() const
EDA_MSG_PANEL * m_messagePanel
void OnUpdateSelectGrid(wxUpdateUIEvent &aEvent)
Update the checked item in the grid combobox.
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
bool m_showBorderAndTitleBlock
Handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:40
wxChoice * m_zoomSelectBox
virtual void PrintPage(const RENDER_SETTINGS *aSettings)
Print the page pointed by current screen, set by the calling print function.
Base window classes and related definitions.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
virtual void OnSize(wxSizeEvent &event)
Recalculate the size of toolbars and display panel when the frame size changes.
virtual const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const
Returns bbox of document with option to not include some items.
virtual void ActivateGalCanvas()
Use to start up the GAL drawing canvas.
void PrintDrawingSheet(const RENDER_SETTINGS *aSettings, BASE_SCREEN *aScreen, double aMils2Iu, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Prints the drawing-sheet (frame and title block).
virtual const wxPoint & GetGridOrigin() const =0
Return the absolute coordinates of the origin of the snap grid.
virtual COLOR4D GetGridColor()
virtual void ClearMsgPanel()
Clear all messages from the message panel.
virtual void ReCreateOptToolbar()=0
virtual void HardRedraw()
Rebuild the GAL and redraws the screen.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
COLOR_SETTINGS * m_colorSettings
The current canvas type.
const wxString GetZoomLevelIndicator() const
Return a human readable value for display in dialogs.
wxSocketServer * m_socketServer
EDA_UNITS
Definition: eda_units.h:38
void SetCanvas(EDA_DRAW_PANEL_GAL *aPanel)
EDA_DRAW_PANEL_GAL::GAL_TYPE loadCanvasTypeSetting()
Returns the canvas type stored in the application settings.
void OnSockRequest(wxSocketEvent &evt)
Definition: eda_dde.cpp:70
virtual void OnPageSettingsChange()
Called when modifying the page settings.
virtual void ReCreateHToolbar()=0
void OnSelectGrid(wxCommandEvent &event)
Command event handler for selecting grid sizes.
bool GetShowPolarCoords() const
For those frames that support polar coordinates.
virtual void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Changes the current rendering backend.
A class to perform either relative or absolute display origin transforms for a single axis of a point...
KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions
Default display origin transforms object.
void setupUnits(APP_SETTINGS_BASE *aCfg)
wxArrayString & GetFindHistoryList()
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149
virtual void ReCreateAuxiliaryToolbar()
wxFindReplaceData * m_findReplaceData
ORIGIN_TRANSFORMS m_originTransforms
Color settings are a bit different than most of the settings objects in that there can be more than o...
virtual COLOR4D GetDrawBgColor() const
void OnGridSettings(wxCommandEvent &event)
void UpdateStatusBar() override
Update the status bar information.
void CreateServer(int service, bool local=true)
Definition: eda_dde.cpp:48
virtual COLOR_SETTINGS * GetColorSettings() const
Returns a pointer to the active color theme settings.
void SetShowPageLimits(bool aShow)
void OnUpdateSelectZoom(wxUpdateUIEvent &aEvent)
Update the checked item in the zoom combobox.
bool saveCanvasTypeSetting(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Stores the canvas type in the application settings.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
virtual void SetGridOrigin(const wxPoint &aPosition)=0
virtual void DisplayGridMsg()
Display current grid size in the status bar.
void FocusOnLocation(const wxPoint &aPos)
Useful to focus on a particular location, in find functions.
void ToggleUserUnits() override
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual void SetGridVisibility(bool aVisible)
void GetUnitPair(EDA_UNITS &aPrimaryUnit, EDA_UNITS &aSecondaryUnits)
Get the pair or units in current use.
long m_firstRunDialogSetting
wxWindow * GetToolCanvas() const override
Canvas access.
virtual void OnSelectZoom(wxCommandEvent &event)
Set the zoom factor when selected by the zoom list box in the main tool bar.
bool LockFile(const wxString &aFileName)
Mark a schematic file as being in use.
void DisplayToolMsg(const wxString &msg) override
virtual void UpdateMsgPanel()
Redraw the message panel.
void AppendMsgPanel(const wxString &aTextUpper, const wxString &aTextLower, int aPadding=6)
Append a message to the message panel.
virtual wxString GetScreenDesc() const
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98
ACTION_TOOLBAR * m_drawToolBar