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-2019 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>
31 #include <climits>
33 #include <gal/color4d.h>
34 #include <class_draw_panel_gal.h>
35 #include <wx/fdrepdlg.h>
36 #include "hotkeys_basic.h"
37 
38 class wxSingleInstanceChecker;
39 class ACTION_TOOLBAR;
40 class TOOL_MENU;
41 
42 using KIGFX::COLOR4D;
43 
44 namespace KIGFX
45 {
46  class GAL_DISPLAY_OPTIONS;
47 }
48 
49 #define DEFAULT_MAX_UNDO_ITEMS 0
50 #define ABS_MAX_UNDO_ITEMS (INT_MAX / 2)
51 #define LIB_EDIT_FRAME_NAME wxT( "LibeditFrame" )
52 #define SCH_EDIT_FRAME_NAME wxT( "SchematicFrame" )
53 #define PL_EDITOR_FRAME_NAME wxT( "PlEditorFrame" )
54 #define FOOTPRINT_WIZARD_FRAME_NAME wxT( "FootprintWizard" )
55 #define FOOTPRINT_EDIT_FRAME_NAME wxT( "ModEditFrame" )
56 #define FOOTPRINT_VIEWER_FRAME_NAME wxT( "ModViewFrame" )
57 #define FOOTPRINT_VIEWER_FRAME_NAME_MODAL wxT( "ModViewFrameModal" )
58 #define PCB_EDIT_FRAME_NAME wxT( "PcbFrame" )
59 
60 
63 
65 #define UserUnitsEntryKeyword "Units"
66 #define ShowGridEntryKeyword "ShowGrid"
68 #define GridColorEntryKeyword "GridColor"
70 #define LastGridSizeIdKeyword "_LastGridSize"
72 
75 #define CanvasTypeKeyBase "canvas_type"
76 
78 
84 {
87 
90 
91 protected:
92  wxSocketServer* m_socketServer;
93  std::vector<wxSocketBase*> m_sockets;
94 
95  std::unique_ptr<wxSingleInstanceChecker> m_file_checker;
96 
97  int m_LastGridSizeId; // The command id offset (>= 0) of the last selected
98  // grid 0 is for the grid corresponding to a
99  // wxCommand ID = ID_POPUP_GRID_LEVEL_1000.
100  bool m_drawGrid; // Hide/Show grid
101  bool m_showPageLimits; // True to display the page limits
102  COLOR4D m_gridColor; // Grid color
103  COLOR4D m_drawBgColor; // The background color of the draw canvas; BLACK for
104  // Pcbnew, BLACK or WHITE for eeschema
105  double m_zoomLevelCoeff; // A suitable value to convert the internal zoom
106  // scaling factor to a zoom level value which rougly
107  // gives 1.0 when the board/schematic is at scale = 1
108  int m_UndoRedoCountMax; // Default Undo/Redo command Max depth, to be handed
109  // to screens
110  bool m_PolarCoords; // For those frames that support polar coordinates
111 
113 
114  bool m_showBorderAndTitleBlock; // Show the worksheet (border and title block).
115  long m_firstRunDialogSetting; // Show first run dialog on startup
116 
117  wxChoice* m_gridSelectBox;
118  wxChoice* m_zoomSelectBox;
119 
121  ACTION_TOOLBAR* m_auxiliaryToolBar; // Additional tools under main toolbar
122  ACTION_TOOLBAR* m_drawToolBar; // Drawing tools (typically on right edge of window)
123  ACTION_TOOLBAR* m_optionsToolBar; // Options (typically on left edge of window)
124 
125  wxFindReplaceData* m_findReplaceData;
126  wxArrayString m_findStringHistoryList;
128 
131 
134 
135  virtual void SetScreen( BASE_SCREEN* aScreen ) { m_currentScreen = aScreen; }
136 
137  double bestZoom( double sizeX, double sizeY, double scaleFactor, wxPoint centre );
138 
139  void unitsChangeRefresh() override;
140 
141  void CommonSettingsChanged( bool aEnvVarsChanged ) override;
142 
148  void InitExitKey();
149 
159  bool LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
160  const wxString& wildcard, const wxString& ext,
161  bool isDirectory = false );
162 
167 
172  virtual wxString GetCanvasTypeKey() { return CanvasTypeKeyBase; }
173 
174 public:
175  EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
176  FRAME_T aFrameType,
177  const wxString& aTitle,
178  const wxPoint& aPos, const wxSize& aSize,
179  long aStyle,
180  const wxString& aFrameName );
181 
182  ~EDA_DRAW_FRAME();
183 
190  bool LockFile( const wxString& aFileName );
191 
195  void ReleaseFile();
196 
197  wxFindReplaceData& GetFindReplaceData() { return *m_findReplaceData; }
198  wxArrayString& GetFindHistoryList() { return m_findStringHistoryList; }
199 
200  virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) = 0;
201  virtual const PAGE_INFO& GetPageSettings() const = 0;
202 
207  virtual const wxSize GetPageSizeIU() const = 0;
208 
212  bool GetShowPolarCoords() const { return m_PolarCoords; }
213  void SetShowPolarCoords( bool aShow ) { m_PolarCoords = aShow; }
214 
218  virtual const wxPoint& GetAuxOrigin() const = 0;
219  virtual void SetAuxOrigin( const wxPoint& aPosition ) = 0;
220 
226  virtual const wxPoint& GetGridOrigin() const = 0;
227  virtual void SetGridOrigin( const wxPoint& aPosition ) = 0;
228 
229  int GetLastGridSizeId() const { return m_LastGridSizeId; }
230  void SetLastGridSizeId( int aId ) { m_LastGridSizeId = aId; }
231 
238  wxPoint GetNearestGridPosition( const wxPoint& aPosition ) const;
239 
240  virtual const TITLE_BLOCK& GetTitleBlock() const = 0;
241  virtual void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) = 0;
242 
243  // the background color of the draw canvas:
244  // Virtual because some frames can have a specific way to get/set the bg color
248  virtual COLOR4D GetDrawBgColor() const { return m_drawBgColor; }
249 
253  virtual void SetDrawBgColor( COLOR4D aColor) { m_drawBgColor= aColor ; }
254 
255  bool ShowPageLimits() const { return m_showPageLimits; }
256  void SetShowPageLimits( bool aShow ) { m_showPageLimits = aShow; }
257 
258  virtual wxString GetScreenDesc() const;
259 
265  virtual BASE_SCREEN* GetScreen() const { return m_currentScreen; }
266 
276  virtual void ExecuteRemoteCommand( const char* cmdline ){}
277 
286  virtual const wxString GetZoomLevelIndicator() const;
287 
291  inline double GetZoomLevelCoeff() const { return m_zoomLevelCoeff; }
292 
293  void EraseMsgBox();
294 
295  void ReCreateMenuBar() override { }
296  virtual void ReCreateHToolbar() = 0;
297  virtual void ReCreateVToolbar() = 0;
298  virtual void ReCreateOptToolbar() = 0;
299  virtual void ReCreateAuxiliaryToolbar() { }
300 
301  /*
302  * These 4 functions provide a basic way to show/hide grid and /get/set grid color.
303  * These parameters are saved in KiCad config for each main frame.
304  */
305  virtual bool IsGridVisible() const { return m_drawGrid; }
306  virtual void SetGridVisibility( bool aVisible ) { m_drawGrid = aVisible; }
307 
308  virtual COLOR4D GetGridColor() { return m_gridColor; }
309  virtual void SetGridColor( COLOR4D aColor ) { m_gridColor = aColor; }
310 
321  virtual void OnSelectGrid( wxCommandEvent& event );
322 
323  virtual void OnGridSettings( wxCommandEvent& event ) { };
324 
332  virtual void OnSelectZoom( wxCommandEvent& event );
333 
334  // Update user interface event handlers shared by all applications derived from
335  // EDA_DRAW_FRAME.
336  void OnUpdateSelectGrid( wxUpdateUIEvent& aEvent );
337 
341  virtual void OnSize( wxSizeEvent& event );
342 
346  virtual void HardRedraw();
347 
352  virtual void Zoom_Automatique( bool aWarpPointer );
353 
355  virtual double BestZoom() = 0;
356 
364  void FocusOnLocation( const wxPoint& aPos, bool aCenterView = false );
365 
369  double GetZoom();
370 
377  void AddStandardSubMenus( TOOL_MENU& aMenu );
378 
389  void PrintWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth, double aScale,
390  const wxString &aFilename, const wxString &aSheetLayer = wxEmptyString,
391  COLOR4D aColor = COLOR4D::UNSPECIFIED );
392 
393  void DisplayToolMsg( const wxString& msg ) override;
394 
400  virtual void OnPageSettingsChange() {}
401 
409  void UpdateStatusBar() override;
410 
414  void DisplayUnitsMsg();
415 
419  void DisplayGridMsg();
420 
421  /* interprocess communication */
422  void CreateServer( int service, bool local = true );
423  void OnSockRequest( wxSocketEvent& evt );
424  void OnSockRequestServer( wxSocketEvent& evt );
425 
426  void LoadSettings( wxConfigBase* aCfg ) override;
427 
428  void SaveSettings( wxConfigBase* aCfg ) override;
429 
442  void AppendMsgPanel( const wxString& textUpper, const wxString& textLower,
443  COLOR4D color, int pad = 6 );
444 
448  virtual void ClearMsgPanel();
449 
455  void SetMsgPanel( const std::vector< MSG_PANEL_ITEM >& aList );
456 
457  void SetMsgPanel( EDA_ITEM* aItem );
458 
462  virtual void UpdateMsgPanel();
463 
469  virtual void PrintPage( wxDC* aDC );
470 
475 
479  virtual void ActivateGalCanvas();
480 
484  virtual void SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType );
485 
491  virtual EDA_DRAW_PANEL_GAL* GetCanvas() const { return m_canvas; }
492  void SetCanvas( EDA_DRAW_PANEL_GAL* aPanel ) { m_canvas = aPanel; }
493 
499  virtual void* GetDisplayOptions() { return NULL; }
500 
505 
506  void RefreshCanvas() override
507  {
508  GetCanvas()->Refresh();
509  }
510 
511  virtual const BOX2I GetDocumentExtents() const;
512 
516  void RecreateToolbars();
517 };
518 
519 #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)
Function CreateBasicMenu.
Class ACTION_TOOLBAR.
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:59
void PrintWorkSheet(wxDC *aDC, BASE_SCREEN *aScreen, int aLineWidth, double aScale, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString, COLOR4D aColor=COLOR4D::UNSPECIFIED)
Prints the page layout with the frame and the basic inscriptions.
virtual void PrintPage(wxDC *aDC)
Print the page pointed by current screen, set by the calling print function.
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.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
int GetLastGridSizeId() const
ACTION_TOOLBAR * m_auxiliaryToolBar
TOOL_DISPATCHER * m_toolDispatcher
virtual void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)=0
ACTION_TOOLBAR * m_optionsToolBar
void OnSockRequestServer(wxSocketEvent &evt)
Definition: eda_dde.cpp:103
virtual void SetScreen(BASE_SCREEN *aScreen)
double bestZoom(double sizeX, double sizeY, double scaleFactor, wxPoint centre)
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
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
The current canvas type.
virtual double BestZoom()=0
Return the zoom level which displays the full page on screen.
virtual void OnGridSettings(wxCommandEvent &event)
virtual bool IsGridVisible() const
void SetShowPolarCoords(bool aShow)
int color
Definition: DXF_plotter.cpp:62
Class TOOL_MENU.
Definition: tool_menu.h:47
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 RecreateToolbars()
Rebuild all toolbars, and update the checked state of ckeck tools.
wxArrayString m_findStringHistoryList
void ReleaseFile()
Release the current file marked in use.
void RefreshCanvas() override
Notification to refresh the drawing canvas (if any).
EDA_DRAW_PANEL_GAL::GAL_TYPE LoadCanvasTypeSetting()
Returns the canvas type stored in the application settings.
virtual wxString GetCanvasTypeKey()
ACTION_TOOLBAR * m_mainToolBar
virtual void SetGridColor(COLOR4D aColor)
wxPoint GetNearestGridPosition(const wxPoint &aPosition) const
Return the nearest aGridSize location to aPosition.
class EDA_MSG_PANEL is a panel to display various information messages.
Definition: msgpanel.h:111
#define CanvasTypeKeyBase
The key to store the canvas type in config.
The base class for create windows for drawing purpose.
COLOR4D m_drawBgColor
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot,...
Definition: title_block.h:40
wxChoice * m_gridSelectBox
std::unique_ptr< wxSingleInstanceChecker > m_file_checker
prevents opening same file multiple times.
void SaveSettings(wxConfigBase *aCfg) override
Saves common frame parameters to a configuration data file.
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 send via a socket to the application, port KICAD_PCB_PORT_SERVICE_NUMBER (cu...
void DisplayUnitsMsg()
Display current unit pane on 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
GAL display options - this is the frame's interface to setting GAL display options.
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.
BASE_SCREEN * m_currentScreen
current used SCREEN
double GetZoomLevelCoeff() const
Return the coefficient to convert internal display scale factor to zoom level.
wxArrayString m_replaceStringHistoryList
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
EDA_MSG_PANEL * m_messagePanel
void OnUpdateSelectGrid(wxUpdateUIEvent &aEvent)
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
bool m_showBorderAndTitleBlock
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:74
wxChoice * m_zoomSelectBox
Base window classes and related definitions.
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false)
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
virtual void OnSize(wxSizeEvent &event)
Recalculate the size of toolbars and display panel when the frame size changes.
virtual void ActivateGalCanvas()
Use to start up the GAL drawing canvas.
void InitExitKey()
Sets the common key-pair for exiting the application (Ctrl-Q) and ties it to the wxID_EXIT event id.
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
void LoadSettings(wxConfigBase *aCfg) override
Load common frame parameters from a configuration file.
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...
Class TOOL_DISPATCHER.
virtual const wxString GetZoomLevelIndicator() const
Return a human readable value which can be displayed as zoom level indicator in dialogs.
virtual const wxPoint & GetAuxOrigin() const =0
Return the origin of the axis used for plotting and various exports.
wxSocketServer * m_socketServer
void SetCanvas(EDA_DRAW_PANEL_GAL *aPanel)
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
void OnSockRequest(wxSocketEvent &evt)
Definition: eda_dde.cpp:71
virtual void SetAuxOrigin(const wxPoint &aPosition)=0
virtual void OnPageSettingsChange()
Called when modifying the page settings.
double m_zoomLevelCoeff
virtual void ReCreateHToolbar()=0
void FocusOnLocation(const wxPoint &aPos, bool aCenterView=false)
Useful to focus on a particular location, in find functions Move the graphic cursor (crosshair cursor...
virtual 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.
KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions
wxArrayString & GetFindHistoryList()
void SetLastGridSizeId(int aId)
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
virtual void ReCreateAuxiliaryToolbar()
wxFindReplaceData * m_findReplaceData
void CommonSettingsChanged(bool aEnvVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
virtual COLOR4D GetDrawBgColor() const
virtual void SetGridVisibility(bool aVisible)
void UpdateStatusBar() override
Update the status bar information.
void CreateServer(int service, bool local=true)
Definition: eda_dde.cpp:49
void SetShowPageLimits(bool aShow)
bool saveCanvasTypeSetting(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Stores the canvas type in the application settings.
virtual void SetGridOrigin(const wxPoint &aPosition)=0
void DisplayGridMsg()
Display current grid pane on the status bar.
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual void * GetDisplayOptions()
A way to pass info to draw functions.
long m_firstRunDialogSetting
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.
virtual wxString GetScreenDesc() const
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
ACTION_TOOLBAR * m_drawToolBar
virtual const BOX2I GetDocumentExtents() const