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, [email protected]
5 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 1992-2021 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>
34#include <kiid.h>
35#include "hotkeys_basic.h"
36
37class EDA_ITEM;
38class wxSingleInstanceChecker;
39class ACTION_TOOLBAR;
40class COLOR_SETTINGS;
41class TOOL_MENU;
43class wxFindReplaceData;
44class SEARCH_PANE;
45
46namespace KIGFX
47{
48 class GAL_DISPLAY_OPTIONS;
49 class RENDER_SETTINGS;
50}
51
52using KIGFX::COLOR4D;
54
55#define LIB_EDIT_FRAME_NAME wxT( "LibeditFrame" )
56#define SCH_EDIT_FRAME_NAME wxT( "SchematicFrame" )
57#define PL_EDITOR_FRAME_NAME wxT( "PlEditorFrame" )
58#define FOOTPRINT_WIZARD_FRAME_NAME wxT( "FootprintWizard" )
59#define FOOTPRINT_EDIT_FRAME_NAME wxT( "ModEditFrame" )
60#define FOOTPRINT_VIEWER_FRAME_NAME wxT( "ModViewFrame" )
61#define FOOTPRINT_VIEWER_FRAME_NAME_MODAL wxT( "ModViewFrameModal" )
62#define PCB_EDIT_FRAME_NAME wxT( "PcbFrame" )
63
64
72{
73public:
74 EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle,
75 const wxPoint& aPos, const wxSize& aSize, long aStyle,
76 const wxString& aFrameName, const EDA_IU_SCALE& aIuScale );
77
79
88 bool LockFile( const wxString& aFileName );
89
93 void ReleaseFile();
94
99
104
106 wxArrayString& GetFindHistoryList() { return m_findStringHistoryList; }
107
108 virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) = 0;
109 virtual const PAGE_INFO& GetPageSettings() const = 0;
110
115 virtual const wxSize GetPageSizeIU() const = 0;
116
120 bool GetShowPolarCoords() const { return m_polarCoords; }
121 void SetShowPolarCoords( bool aShow ) { m_polarCoords = aShow; }
122
123 void ToggleUserUnits() override;
124
131 void GetUnitPair( EDA_UNITS& aPrimaryUnit, EDA_UNITS& aSecondaryUnits );
132
139 virtual const VECTOR2I& GetGridOrigin() const = 0;
140 virtual void SetGridOrigin( const VECTOR2I& aPosition ) = 0;
141
148 VECTOR2I GetNearestGridPosition( const VECTOR2I& aPosition ) const;
149
159 VECTOR2I GetNearestHalfGridPosition( const VECTOR2I& aPosition ) const;
160
161 virtual const TITLE_BLOCK& GetTitleBlock() const = 0;
162 virtual void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) = 0;
163
164 // the background color of the draw canvas:
165 // Virtual because some frames can have a specific way to get/set the bg color
166 virtual COLOR4D GetDrawBgColor() const { return m_drawBgColor; }
167 virtual void SetDrawBgColor( const COLOR4D& aColor) { m_drawBgColor= aColor ; }
168
170 virtual COLOR_SETTINGS* GetColorSettings( bool aForceRefresh = false ) const;
171
181 bool LibraryFileBrowser( bool doOpen, wxFileName& aFilename, const wxString& wildcard,
182 const wxString& ext, bool isDirectory = false, bool aIsGlobal = false,
183 const wxString& aGlobalPath = wxEmptyString );
184
185 void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
186
187 virtual wxString GetScreenDesc() const;
188
194 virtual BASE_SCREEN* GetScreen() const { return m_currentScreen; }
195
196 void EraseMsgBox();
197
198 void ReCreateMenuBar() override { }
199 virtual void ReCreateHToolbar() = 0;
200 virtual void ReCreateVToolbar() = 0;
201 virtual void ReCreateOptToolbar() = 0;
202 virtual void ReCreateAuxiliaryToolbar() { }
203
207 virtual void UpdateToolbarControlSizes() { }
208
209 /*
210 * These 4 functions provide a basic way to show/hide grid and /get/set grid color.
211 *
212 * These parameters are saved in KiCad config for each main frame.
213 */
214 bool IsGridVisible() const;
215 virtual void SetGridVisibility( bool aVisible );
216
217 virtual COLOR4D GetGridColor() { return m_gridColor; }
218 virtual void SetGridColor( const COLOR4D& aColor ) { m_gridColor = aColor; }
219
229 void OnSelectGrid( wxCommandEvent& event );
230
231 void OnGridSettings( wxCommandEvent& event );
232
237 void UpdateGridSelectBox();
238
242 void OnUpdateSelectGrid( wxUpdateUIEvent& aEvent );
243
247 void OnUpdateSelectZoom( wxUpdateUIEvent& aEvent );
248
253 void UpdateZoomSelectBox();
254
258 const wxString GetZoomLevelIndicator() const;
259
267 virtual void OnSelectZoom( wxCommandEvent& event );
268
272 virtual void OnSize( wxSizeEvent& event ) override;
273
274 void OnMove( wxMoveEvent& aEvent ) override;
275
279 virtual void HardRedraw();
280
285 virtual void Zoom_Automatique( bool aWarpPointer );
286
295 void FocusOnLocation( const VECTOR2I& aPos );
296
301 void AddStandardSubMenus( TOOL_MENU& aMenu );
302
312 void PrintDrawingSheet( const RENDER_SETTINGS* aSettings, BASE_SCREEN* aScreen,
313 const std::map<wxString, wxString>* aProperties, double aMils2Iu,
314 const wxString& aFilename, const wxString& aSheetLayer = wxEmptyString );
315
316 void DisplayToolMsg( const wxString& msg ) override;
317
318 void DisplayConstraintsMsg( const wxString& msg );
319
325 virtual void OnPageSettingsChange() {}
326
334 void UpdateStatusBar() override;
335
339 void DisplayUnitsMsg();
340
344 virtual void DisplayGridMsg();
345
346 void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
347 void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
348
359 void AppendMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding = 6 );
360
364 virtual void ClearMsgPanel();
365
371 void SetMsgPanel( const std::vector< MSG_PANEL_ITEM >& aList );
372 void SetMsgPanel( EDA_ITEM* aItem );
373
381 void SetMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding = 6 );
382
386 virtual void UpdateMsgPanel();
387
391 virtual EDA_ITEM* GetItem( const KIID& aId ) const { return nullptr; }
392
398 virtual void PrintPage( const RENDER_SETTINGS* aSettings );
399
403 virtual void ActivateGalCanvas();
404
408 virtual void SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType );
409
415 virtual EDA_DRAW_PANEL_GAL* GetCanvas() const { return m_canvas; }
416 void SetCanvas( EDA_DRAW_PANEL_GAL* aPanel ) { m_canvas = aPanel; }
417
418 wxWindow* GetToolCanvas() const override { return GetCanvas(); }
419
424
425 void RefreshCanvas() override
426 {
427 GetCanvas()->Refresh();
428 }
429
442 virtual const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const;
443
447 void RecreateToolbars();
448
452 void ShowChangedLanguage() override;
453
454 DECLARE_EVENT_TABLE()
455
456protected:
457 virtual void SetScreen( BASE_SCREEN* aScreen ) { m_currentScreen = aScreen; }
458
459 void unitsChangeRefresh() override;
460
461 void setupUnits( APP_SETTINGS_BASE* aCfg );
462
463 std::vector<wxWindow*> findDialogs();
464
468 void resolveCanvasType();
469
474
479
483 virtual void handleActivateEvent( wxActivateEvent& aEvent );
484 void onActivate( wxActivateEvent& aEvent );
485
486
487 wxSocketServer* m_socketServer;
488 std::vector<wxSocketBase*> m_sockets;
489
491 std::unique_ptr<wxSingleInstanceChecker> m_file_checker;
492
493 COLOR4D m_gridColor; // Grid color
494 COLOR4D m_drawBgColor; // The background color of the draw canvas; BLACK for
495 // Pcbnew, BLACK or WHITE for Eeschema
496 int m_undoRedoCountMax; // Default Undo/Redo command Max depth, to be handed
497 // to screens
498 bool m_polarCoords; // For those frames that support polar coordinates
499
500 bool m_showBorderAndTitleBlock; // Show the drawing sheet (border & title block).
501 long m_firstRunDialogSetting; // Show first run dialog on startup
502
505
507 ACTION_TOOLBAR* m_auxiliaryToolBar; // Additional tools under main toolbar
508 ACTION_TOOLBAR* m_drawToolBar; // Drawing tools (typically on right edge of window)
509 ACTION_TOOLBAR* m_optionsToolBar; // Options (typically on left edge of window)
510
511 std::unique_ptr<EDA_SEARCH_DATA> m_findReplaceData;
514
517
520
523
524private:
527
530};
531
532#endif // DRAW_FRAME_H_
Define the structure of a toolbar with buttons that invoke ACTIONs.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:110
Handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:41
Color settings are a bit different than most of the settings objects in that there can be more than o...
The base class for create windows for drawing purpose.
virtual const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const
Returns bbox of document with option to not include some items.
wxArrayString m_replaceStringHistoryList
virtual void ClearMsgPanel()
Clear all messages from the message panel.
virtual void UpdateToolbarControlSizes()
Update the sizes of any controls in the toolbars of the frame.
virtual void ReCreateOptToolbar()=0
EDA_DRAW_PANEL_GAL * m_canvas
This the frame's interface to setting GAL display options.
virtual void ActivateGalCanvas()
Use to start up the GAL drawing canvas.
virtual void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)=0
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
virtual const TITLE_BLOCK & GetTitleBlock() const =0
virtual void PrintPage(const RENDER_SETTINGS *aSettings)
Print the page pointed by current screen, set by the calling print function.
void onActivate(wxActivateEvent &aEvent)
COLOR_SETTINGS * m_colorSettings
wxChoice * m_gridSelectBox
void AddStandardSubMenus(TOOL_MENU &aMenu)
Construct a "basic" menu for a tool, containing only items that apply to all tools (e....
void ReleaseFile()
Release the current file marked in use.
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
void ScriptingConsoleEnableDisable()
Toggles the scripting console visibility.
void OnSelectGrid(wxCommandEvent &event)
Command event handler for selecting grid sizes.
void DisplayToolMsg(const wxString &msg) override
bool IsScriptingConsoleVisible()
Gets the current visibility of the scripting console window.
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...
void OnUpdateSelectZoom(wxUpdateUIEvent &aEvent)
Update the checked item in the zoom wxchoice.
virtual const PAGE_INFO & GetPageSettings() const =0
void DisplayUnitsMsg()
Display current unit pane in the status bar.
void setupUnits(APP_SETTINGS_BASE *aCfg)
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void RefreshCanvas() override
virtual COLOR4D GetGridColor()
ACTION_TOOLBAR * m_optionsToolBar
void UpdateGridSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
bool LockFile(const wxString &aFileName)
Mark a schematic file as being in use.
virtual void HardRedraw()
Rebuild the GAL and redraws the screen.
virtual void SetGridOrigin(const VECTOR2I &aPosition)=0
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false, bool aIsGlobal=false, const wxString &aGlobalPath=wxEmptyString)
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void UpdateZoomSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)=0
virtual void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Changes the current rendering backend.
virtual void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
long m_firstRunDialogSetting
const wxString GetZoomLevelIndicator() const
Return a human readable value for display in dialogs.
virtual void OnSelectZoom(wxCommandEvent &event)
Set the zoom factor when selected by the zoom list box in the main tool bar.
void resolveCanvasType()
Determines the Canvas type to load (with prompt if required) and initializes m_canvasType.
virtual void ReCreateHToolbar()=0
std::vector< wxSocketBase * > m_sockets
interprocess communication
void GetUnitPair(EDA_UNITS &aPrimaryUnit, EDA_UNITS &aSecondaryUnits)
Get the pair or units in current use.
BASE_SCREEN * m_currentScreen
current used SCREEN
virtual wxString GetScreenDesc() const
VECTOR2I GetNearestGridPosition(const VECTOR2I &aPosition) const
Return the nearest aGridSize location to aPosition.
EDA_MSG_PANEL * m_messagePanel
void SetCanvas(EDA_DRAW_PANEL_GAL *aPanel)
virtual const VECTOR2I & GetGridOrigin() const =0
Return the absolute coordinates of the origin of the snap grid.
virtual void ReCreateAuxiliaryToolbar()
void SetShowPolarCoords(bool aShow)
void FocusOnLocation(const VECTOR2I &aPos)
Useful to focus on a particular location, in find functions.
virtual void SetScreen(BASE_SCREEN *aScreen)
void RecreateToolbars()
Rebuild all toolbars, and update the checked state of check tools.
bool saveCanvasTypeSetting(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Stores the canvas type in the application settings.
EDA_DRAW_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, const EDA_IU_SCALE &aIuScale)
ACTION_TOOLBAR * m_mainToolBar
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.
std::unique_ptr< wxSingleInstanceChecker > m_file_checker
COLOR4D m_drawBgColor
virtual void SetGridVisibility(bool aVisible)
virtual void handleActivateEvent(wxActivateEvent &aEvent)
Handle a window activation event.
void ReCreateMenuBar() override
Recreates the menu bar.
virtual void SetDrawBgColor(const COLOR4D &aColor)
virtual void UpdateMsgPanel()
Redraw the message panel.
virtual COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const
Returns a pointer to the active color theme settings.
void ToggleUserUnits() override
void UpdateStatusBar() override
Update the status bar information.
void OnGridSettings(wxCommandEvent &event)
wxArrayString & GetFindHistoryList()
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
virtual EDA_ITEM * GetItem(const KIID &aId) const
Fetch an item by KIID.
void PrintDrawingSheet(const RENDER_SETTINGS *aSettings, BASE_SCREEN *aScreen, const std::map< wxString, wxString > *aProperties, double aMils2Iu, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Prints the drawing-sheet (frame and title block).
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual void OnPageSettingsChange()
Called when modifying the page settings.
wxSocketServer * m_socketServer
ACTION_TOOLBAR * m_drawToolBar
SEARCH_PANE * m_searchPane
The current canvas type.
EDA_SEARCH_DATA & GetFindReplaceData()
virtual COLOR4D GetDrawBgColor() const
virtual void ReCreateVToolbar()=0
void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
void OnMove(wxMoveEvent &aEvent) override
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
bool IsGridVisible() const
std::vector< wxWindow * > findDialogs()
virtual void DisplayGridMsg()
Display current grid size in the status bar.
EDA_DRAW_PANEL_GAL::GAL_TYPE loadCanvasTypeSetting()
Returns the canvas type stored in the application settings.
virtual void SetGridColor(const COLOR4D &aColor)
wxArrayString m_findStringHistoryList
wxChoice * m_zoomSelectBox
wxWindow * GetToolCanvas() const override
Canvas access.
std::unique_ptr< EDA_SEARCH_DATA > m_findReplaceData
void DisplayConstraintsMsg(const wxString &msg)
void AppendMsgPanel(const wxString &aTextUpper, const wxString &aTextLower, int aPadding=6)
Append a message to the message panel.
bool m_showBorderAndTitleBlock
VECTOR2I GetNearestHalfGridPosition(const VECTOR2I &aPosition) const
Return the nearest aGridSize / 2 location to aPosition.
void OnUpdateSelectGrid(wxUpdateUIEvent &aEvent)
Update the checked item in the grid wxchoice.
ACTION_TOOLBAR * m_auxiliaryToolBar
bool GetShowPolarCoords() const
For those frames that support polar coordinates.
KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
A panel to display various information messages.
Definition: msgpanel.h:101
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Definition: kiid.h:48
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:66
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:273
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:41
Manage a CONDITIONAL_MENU and some number of CONTEXT_MENUs as sub-menus.
Definition: tool_menu.h:43
Base window classes and related definitions.
EDA_UNITS
Definition: eda_units.h:43
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:33
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:266