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  void unitsChangeRefresh() override;
138 
139  void CommonSettingsChanged( bool aEnvVarsChanged ) override;
140 
146  void InitExitKey();
147 
157  bool LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
158  const wxString& wildcard, const wxString& ext,
159  bool isDirectory = false );
160 
165 
170  virtual wxString GetCanvasTypeKey() { return CanvasTypeKeyBase; }
171 
172 public:
173  EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
174  FRAME_T aFrameType,
175  const wxString& aTitle,
176  const wxPoint& aPos, const wxSize& aSize,
177  long aStyle,
178  const wxString& aFrameName );
179 
180  ~EDA_DRAW_FRAME();
181 
188  bool LockFile( const wxString& aFileName );
189 
193  void ReleaseFile();
194 
195  wxFindReplaceData& GetFindReplaceData() { return *m_findReplaceData; }
196  wxArrayString& GetFindHistoryList() { return m_findStringHistoryList; }
197 
198  virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) = 0;
199  virtual const PAGE_INFO& GetPageSettings() const = 0;
200 
205  virtual const wxSize GetPageSizeIU() const = 0;
206 
210  bool GetShowPolarCoords() const { return m_PolarCoords; }
211  void SetShowPolarCoords( bool aShow ) { m_PolarCoords = aShow; }
212 
216  virtual const wxPoint& GetAuxOrigin() const = 0;
217  virtual void SetAuxOrigin( const wxPoint& aPosition ) = 0;
218 
224  virtual const wxPoint& GetGridOrigin() const = 0;
225  virtual void SetGridOrigin( const wxPoint& aPosition ) = 0;
226 
227  int GetLastGridSizeId() const { return m_LastGridSizeId; }
228  void SetLastGridSizeId( int aId ) { m_LastGridSizeId = aId; }
229 
236  wxPoint GetNearestGridPosition( const wxPoint& aPosition ) const;
237 
238  virtual const TITLE_BLOCK& GetTitleBlock() const = 0;
239  virtual void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) = 0;
240 
241  // the background color of the draw canvas:
242  // Virtual because some frames can have a specific way to get/set the bg color
246  virtual COLOR4D GetDrawBgColor() const { return m_drawBgColor; }
247 
251  virtual void SetDrawBgColor( COLOR4D aColor) { m_drawBgColor= aColor ; }
252 
253  bool ShowPageLimits() const { return m_showPageLimits; }
254  void SetShowPageLimits( bool aShow ) { m_showPageLimits = aShow; }
255 
256  virtual wxString GetScreenDesc() const;
257 
263  virtual BASE_SCREEN* GetScreen() const { return m_currentScreen; }
264 
274  virtual void ExecuteRemoteCommand( const char* cmdline ){}
275 
284  virtual const wxString GetZoomLevelIndicator() const;
285 
289  inline double GetZoomLevelCoeff() const { return m_zoomLevelCoeff; }
290 
291  void EraseMsgBox();
292 
293  void ReCreateMenuBar() override { }
294  virtual void ReCreateHToolbar() = 0;
295  virtual void ReCreateVToolbar() = 0;
296  virtual void ReCreateOptToolbar() = 0;
297  virtual void ReCreateAuxiliaryToolbar() { }
298 
299  /*
300  * These 4 functions provide a basic way to show/hide grid and /get/set grid color.
301  * These parameters are saved in KiCad config for each main frame.
302  */
303  virtual bool IsGridVisible() const { return m_drawGrid; }
304  virtual void SetGridVisibility( bool aVisible ) { m_drawGrid = aVisible; }
305 
306  virtual COLOR4D GetGridColor() { return m_gridColor; }
307  virtual void SetGridColor( COLOR4D aColor ) { m_gridColor = aColor; }
308 
319  virtual void OnSelectGrid( wxCommandEvent& event );
320 
321  virtual void OnGridSettings( wxCommandEvent& event ) { };
322 
330  virtual void OnSelectZoom( wxCommandEvent& event );
331 
332  // Update user interface event handlers shared by all applications derived from
333  // EDA_DRAW_FRAME.
334  void OnUpdateSelectGrid( wxUpdateUIEvent& aEvent );
335 
339  virtual void OnSize( wxSizeEvent& event );
340 
344  virtual void HardRedraw();
345 
350  virtual void Zoom_Automatique( bool aWarpPointer );
351 
359  void FocusOnLocation( const wxPoint& aPos, bool aCenterView = false );
360 
364  double GetZoom();
365 
372  void AddStandardSubMenus( TOOL_MENU& aMenu );
373 
384  void PrintWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth, double aScale,
385  const wxString &aFilename, const wxString &aSheetLayer = wxEmptyString,
386  COLOR4D aColor = COLOR4D::UNSPECIFIED );
387 
388  void DisplayToolMsg( const wxString& msg ) override;
389 
395  virtual void OnPageSettingsChange() {}
396 
404  void UpdateStatusBar() override;
405 
409  void DisplayUnitsMsg();
410 
414  void DisplayGridMsg();
415 
416  /* interprocess communication */
417  void CreateServer( int service, bool local = true );
418  void OnSockRequest( wxSocketEvent& evt );
419  void OnSockRequestServer( wxSocketEvent& evt );
420 
421  void LoadSettings( wxConfigBase* aCfg ) override;
422 
423  void SaveSettings( wxConfigBase* aCfg ) override;
424 
437  void AppendMsgPanel( const wxString& textUpper, const wxString& textLower,
438  COLOR4D color, int pad = 6 );
439 
443  virtual void ClearMsgPanel();
444 
450  void SetMsgPanel( const std::vector< MSG_PANEL_ITEM >& aList );
451 
452  void SetMsgPanel( EDA_ITEM* aItem );
453 
457  virtual void UpdateMsgPanel();
458 
464  virtual void PrintPage( wxDC* aDC );
465 
470 
474  virtual void ActivateGalCanvas();
475 
479  virtual void SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType );
480 
486  virtual EDA_DRAW_PANEL_GAL* GetCanvas() const { return m_canvas; }
487  void SetCanvas( EDA_DRAW_PANEL_GAL* aPanel ) { m_canvas = aPanel; }
488 
493 
494  void RefreshCanvas() override
495  {
496  GetCanvas()->Refresh();
497  }
498 
499  virtual const BOX2I GetDocumentExtents() const;
500 
504  void RecreateToolbars();
505 };
506 
507 #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:58
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)
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 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:274
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.
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