You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

954 lines
33 KiB

18 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009-2015 Jean-Pierre Charras, jp.charras wanadoo.fr
  5. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 2023 CERN (www.cern.ch)
  7. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. /**
  27. * @file eda_base_frame.h
  28. * @brief Base window classes and related definitions.
  29. */
  30. #ifndef EDA_BASE_FRAME_H_
  31. #define EDA_BASE_FRAME_H_
  32. #include <map>
  33. #include <optional>
  34. #include <vector>
  35. #include <wx/aui/aui.h>
  36. #include <layer_ids.h>
  37. #include <frame_type.h>
  38. #include <hotkeys_basic.h>
  39. #include <kiway_holder.h>
  40. #include <tool/action_toolbar.h>
  41. #include <tool/tools_holder.h>
  42. #include <widgets/ui_common.h>
  43. #include <widgets/wx_infobar.h>
  44. #include <undo_redo_container.h>
  45. #include <units_provider.h>
  46. #include <origin_transforms.h>
  47. #include <ui_events.h>
  48. // Option for main frames
  49. #define KICAD_DEFAULT_DRAWFRAME_STYLE wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS
  50. #define VIEWER3D_FRAMENAME wxT( "Viewer3DFrameName" )
  51. #define QUALIFIED_VIEWER3D_FRAMENAME( parent ) \
  52. ( wxString( VIEWER3D_FRAMENAME ) + wxT( ":" ) + parent->GetName() )
  53. #define KICAD_MANAGER_FRAME_NAME wxT( "KicadFrame" )
  54. class wxChoice;
  55. class wxEvent;
  56. class wxFileName;
  57. class EDA_ITEM;
  58. class EDA_DRAW_PANEL_GAL;
  59. class EDA_MSG_PANEL;
  60. class BASE_SCREEN;
  61. class PAGE_INFO;
  62. class PLOTTER;
  63. class TITLE_BLOCK;
  64. class MSG_PANEL_ITEM;
  65. class TOOL_MANAGER;
  66. class TOOL_DISPATCHER;
  67. class ACTIONS;
  68. class PAGED_DIALOG;
  69. class DIALOG_EDIT_LIBRARY_TABLES;
  70. class PANEL_HOTKEYS_EDITOR;
  71. class FILE_HISTORY;
  72. class SETTINGS_MANAGER;
  73. class SEARCH_STACK;
  74. class APP_SETTINGS_BASE;
  75. class APPEARANCE_CONTROLS_3D;
  76. struct WINDOW_SETTINGS;
  77. struct WINDOW_STATE;
  78. class ACTION_MENU;
  79. class TOOL_INTERACTIVE;
  80. class TOOLBAR_SETTINGS;
  81. #define DEFAULT_MAX_UNDO_ITEMS 0
  82. #define ABS_MAX_UNDO_ITEMS (INT_MAX / 2)
  83. /// This is the handler functor for the update UI events
  84. typedef std::function< void( wxUpdateUIEvent& ) > UIUpdateHandler;
  85. /**
  86. * The base frame for deriving all KiCad main window classes.
  87. *
  88. * This class is not intended to be used directly. It provides support for automatic calls
  89. * to SaveSettings() function. SaveSettings() for a derived class can choose to do nothing,
  90. * or rely on basic SaveSettings() support in this base class to do most of the work by
  91. * calling it from the derived class's SaveSettings(). This class is not a #KIWAY_PLAYER
  92. * because #KICAD_MANAGER_FRAME is derived from it and that class is not a player.
  93. */
  94. class EDA_BASE_FRAME : public wxFrame, public TOOLS_HOLDER, public KIWAY_HOLDER,
  95. public UNITS_PROVIDER
  96. {
  97. public:
  98. /**
  99. * Specify whether we are interacting with the undo or redo stacks.
  100. */
  101. enum UNDO_REDO_LIST
  102. {
  103. UNDO_LIST,
  104. REDO_LIST
  105. };
  106. EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle,
  107. const wxPoint& aPos, const wxSize& aSize, long aStyle,
  108. const wxString& aFrameName, KIWAY* aKiway, const EDA_IU_SCALE& aIuScale );
  109. ~EDA_BASE_FRAME();
  110. void ChangeUserUnits( EDA_UNITS aUnits );
  111. virtual void ToggleUserUnits() { }
  112. /**
  113. * Return a reference to the default ORIGIN_TRANSFORMS object
  114. */
  115. ORIGIN_TRANSFORMS& GetOriginTransforms() override
  116. {
  117. return m_originTransforms;
  118. }
  119. SETTINGS_MANAGER* GetSettingsManager() const { return m_settingsManager; }
  120. virtual SEVERITY GetSeverity( int aErrorCode ) const { return RPT_SEVERITY_UNDEFINED; }
  121. /**
  122. * Override the default process event handler to implement the auto save feature.
  123. *
  124. * @warning If you override this function in a derived class, make sure you call down to
  125. * this or the auto save feature will be disabled.
  126. */
  127. bool ProcessEvent( wxEvent& aEvent ) override;
  128. /**
  129. * Capture the key event before it is sent to the GUI.
  130. *
  131. * The basic frame does not capture this event. Editor frames should override this event
  132. * function to capture and filter these keys when they are used as hotkeys, and skip it if
  133. * the key is not used as hotkey (otherwise the key events will be not sent to menus).
  134. */
  135. virtual void OnCharHook( wxKeyEvent& aKeyEvent );
  136. /**
  137. * The #TOOL_DISPATCHER needs these to work around some issues in wxWidgets where the menu
  138. * events aren't captured by the menus themselves.
  139. */
  140. void OnMenuEvent( wxMenuEvent& event );
  141. /**
  142. * Register a UI update handler for the control with ID @c aID
  143. *
  144. * @param aID is the control ID to register the handler for
  145. * @param aConditions are the UI conditions to use for the control states
  146. */
  147. virtual void RegisterUIUpdateHandler( int aID, const ACTION_CONDITIONS& aConditions ) override;
  148. /**
  149. * Unregister a UI handler for a given ID that was registered using @c RegisterUIUpdateHandler
  150. *
  151. * @param aID is the control ID to unregister the handler for
  152. */
  153. virtual void UnregisterUIUpdateHandler( int aID ) override;
  154. /**
  155. * Handle events generated when the UI is trying to figure out the current state of the
  156. * UI controls related to #TOOL_ACTIONS (e.g. enabled, checked, etc.).
  157. *
  158. * @param aEvent is the wxUpdateUIEvent to be processed.
  159. * @param aFrame is the frame to get the selection from
  160. * @param aCond are the #UI SELECTION_CONDITIONS used
  161. */
  162. static void HandleUpdateUIEvent( wxUpdateUIEvent& aEvent, EDA_BASE_FRAME* aFrame,
  163. ACTION_CONDITIONS aCond );
  164. virtual void OnMove( wxMoveEvent& aEvent )
  165. {
  166. aEvent.Skip();
  167. }
  168. virtual void OnSize( wxSizeEvent& aEvent );
  169. void OnMaximize( wxMaximizeEvent& aEvent );
  170. int GetAutoSaveInterval() const;
  171. bool IsType( FRAME_T aType ) const { return m_ident == aType; }
  172. FRAME_T GetFrameType() const { return m_ident; }
  173. /**
  174. * Return a #SEARCH_STACK pertaining to entire program.
  175. *
  176. * This is overloaded in #KICAD_MANAGER_FRAME
  177. */
  178. virtual const SEARCH_STACK& sys_search();
  179. virtual wxString help_name();
  180. // Event handlers for menu events generated by the macOS application menu
  181. void OnKicadAbout( wxCommandEvent& event );
  182. void OnPreferences( wxCommandEvent& event );
  183. /**
  184. * Display the preferences and settings of all opened editors paged dialog, starting with
  185. * a particular page
  186. */
  187. void ShowPreferences( wxString aStartPage, wxString aStartParentPage );
  188. void PrintMsg( const wxString& text );
  189. void CreateInfoBar();
  190. void FinishAUIInitialization();
  191. /**
  192. * @return the #WX_INFOBAR that can be displayed on the top of the canvas.
  193. */
  194. WX_INFOBAR* GetInfoBar() { return m_infoBar; }
  195. /**
  196. * Show the #WX_INFOBAR displayed on the top of the canvas with a message and an error
  197. * icon on the left of the infobar, and an optional closebox to the right.
  198. *
  199. * The infobar will be closed after a timeout.
  200. *
  201. * @param aErrorMsg is the message to display.
  202. * @param aShowCloseButton true to show a close button on the right of the #WX_INFOBAR.
  203. */
  204. void ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton = false,
  205. WX_INFOBAR::MESSAGE_TYPE aType = WX_INFOBAR::MESSAGE_TYPE::GENERIC );
  206. /**
  207. * Show the #WX_INFOBAR displayed on the top of the canvas with a message and an error
  208. * icon on the left of the infobar, and an optional closebox to the right.
  209. *
  210. * The infobar will be closed after a timeout.
  211. *
  212. * This version accepts a callback which will be called when the infobar is dismissed
  213. * (either as a result of user action or a timeout). This can be useful when the caller
  214. * wants to make other decorations in the canvas to highlight the error.
  215. *
  216. * @param aErrorMsg is the message to display.
  217. * @param aShowCloseButton true to show a close button on the right of the #WX_INFOBAR.
  218. * @param aCallback a callback to be called when the infobar is dismissed.
  219. */
  220. void ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
  221. std::function<void(void)> aCallback );
  222. /**
  223. * Show the #WX_INFOBAR displayed on the top of the canvas with a message and a warning
  224. * icon on the left of the infobar.
  225. *
  226. * The infobar will be closed after a timeout.
  227. *
  228. * @param aErrorMsg is the message to display.
  229. * @param aShowCloseButton true to show a close button on the right of the #WX_INFOBAR.
  230. */
  231. void ShowInfoBarWarning( const wxString& aWarningMsg, bool aShowCloseButton = false );
  232. /**
  233. * Show the #WX_INFOBAR displayed on the top of the canvas with a message and an info
  234. * icon on the left of the infobar.
  235. *
  236. * The infobar will be closed after a timeout.
  237. *
  238. * @param aErrorMsg is the message to display.
  239. * @param aShowCloseButton true to show a close button on the right of the #WX_INFOBAR.
  240. */
  241. void ShowInfoBarMsg( const wxString& aMsg, bool aShowCloseButton = false );
  242. /**
  243. * Return the settings object used in SaveSettings(), and is overloaded in
  244. * #KICAD_MANAGER_FRAME.
  245. */
  246. virtual APP_SETTINGS_BASE* config() const;
  247. void LoadWindowState( const wxString& aFileName );
  248. /**
  249. * Load window settings from the given settings object.
  250. *
  251. * Normally called by #LoadSettings() unless the window in question is a child window
  252. * that* stores its settings somewhere other than #APP_SETTINGS_BASE::m_Window.
  253. */
  254. void LoadWindowSettings( const WINDOW_SETTINGS* aCfg );
  255. /**
  256. * Save window settings to the given settings object.
  257. *
  258. * Normally called by #SaveSettings unless the window in question is a child window that
  259. * stores its settings somewhere other than #APP_SETTINGS_BASE::m_Window.
  260. */
  261. void SaveWindowSettings( WINDOW_SETTINGS* aCfg );
  262. /**
  263. * Load common frame parameters from a configuration file.
  264. *
  265. * Don't forget to call the base method or your frames won't remember their positions
  266. * and sizes.
  267. */
  268. virtual void LoadSettings( APP_SETTINGS_BASE* aCfg );
  269. /**
  270. * Save common frame parameters to a configuration data file.
  271. *
  272. * Don't forget to call the base class's SaveSettings() from your derived
  273. * #SaveSettings() otherwise the frames won't remember their positions and sizes.
  274. */
  275. virtual void SaveSettings( APP_SETTINGS_BASE* aCfg );
  276. /**
  277. * Return a pointer to the window settings for this frame.
  278. *
  279. * By default, points to aCfg->m_Window for top-level frames.
  280. *
  281. * @param aCfg is this frame's config object
  282. */
  283. virtual WINDOW_SETTINGS* GetWindowSettings( APP_SETTINGS_BASE* aCfg );
  284. /**
  285. * Load frame state info from a configuration file.
  286. */
  287. virtual void LoadWindowState( const WINDOW_STATE& aState );
  288. /**
  289. * Get the configuration base name.
  290. *
  291. * This is usually the name of the frame set by CTOR, except for frames shown in
  292. * multiple modes in which case the m_configName must be set to the base name so
  293. * that a single configuration can be used.
  294. *
  295. * @return a base name prefix used in Load/Save settings to build the full name of keys
  296. * used in configuration.
  297. */
  298. wxString ConfigBaseName() override
  299. {
  300. wxString baseCfgName = m_configName.IsEmpty() ? GetName() : m_configName;
  301. return baseCfgName;
  302. }
  303. /**
  304. * Save changes to the project local settings.
  305. *
  306. * These settings are used to save/restore the view state for a specific project, and
  307. * should never contain design data. This method is normally called automatically at
  308. * various points in the workflow so that the user's most recent display settings are
  309. * automatically persisted.
  310. *
  311. * The method is virtual so you can override it to call the suitable save method.
  312. * The base method does nothing.
  313. */
  314. virtual void SaveProjectLocalSettings() {};
  315. /**
  316. * Prompt the user for a hotkey file to read, and read it.
  317. *
  318. * @param aActionMap current hotkey map (over which the imported hotkeys will be applied).
  319. * @param aDefaultShortname a default short name (extension not needed) like
  320. * Eeschema, KiCad...
  321. */
  322. void ImportHotkeyConfigFromFile( std::map<std::string, TOOL_ACTION*> aActionMap,
  323. const wxString& aDefaultShortname );
  324. /**
  325. * Fetch the file name from the file history list.
  326. *
  327. * This removes the selected file, if this file does not exist. The menu is also updated,
  328. * if #FILE_HISTORY::UseMenu was called at initialization time.
  329. *
  330. * @param cmdId The command ID associated with the \a aFileHistory object.
  331. * @param type Please document me!
  332. * @param aFileHistory The FILE_HISTORY in use. If null, the main application file
  333. * history is used
  334. * @return a wxString containing the selected filename
  335. */
  336. wxString GetFileFromHistory( int cmdId, const wxString& type,
  337. FILE_HISTORY* aFileHistory = nullptr );
  338. /**
  339. * Remove all files from the file history.
  340. *
  341. * @param aFileHistory The FILE_HISTORY in use. If null, the main application file
  342. * history is used
  343. */
  344. void ClearFileHistory( FILE_HISTORY* aFileHistory = nullptr );
  345. /**
  346. * Update the list of recently opened files.
  347. *
  348. * The menu is also updated, if FILE_HISTORY::UseMenu was called at init time.
  349. *
  350. * @param FullFileName The full file name including the path.
  351. * @param aFileHistory The FILE_HISTORY in use. If NULL, the main application file
  352. * history is used.
  353. */
  354. void UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory = nullptr );
  355. /**
  356. * Get the frame's main file history.
  357. *
  358. * @return the main file history
  359. */
  360. FILE_HISTORY& GetFileHistory()
  361. {
  362. return *m_fileHistory;
  363. }
  364. void SetMruPath( const wxString& aPath ) { m_mruPath = aPath; }
  365. wxString GetMruPath() const { return m_mruPath; }
  366. /**
  367. * Get the full filename + path of the currently opened file in the frame.
  368. *
  369. * If no file is open, an empty string is returned.
  370. *
  371. * @return the filename and full path to the open file
  372. */
  373. virtual wxString GetCurrentFileName() const { return wxEmptyString; }
  374. virtual void RecreateToolbars();
  375. /**
  376. * Update toolbars if desired toolbar icon changed.
  377. */
  378. void OnToolbarSizeChanged();
  379. /**
  380. * Update the sizes of any controls in the toolbars of the frame.
  381. */
  382. virtual void UpdateToolbarControlSizes();
  383. /**
  384. * Register a creation factory for toolbar controls that are present in this frame.
  385. *
  386. * The factory function takes a single argument of type `ACTION_TOOLBAR*`, which is the toolbar
  387. * to add the controls to.
  388. *
  389. * @param aControlDesc is the control descriptor
  390. * @param aControlFactory A functor that creates the custom controls and then adds them to the toolbar
  391. */
  392. void RegisterCustomToolbarControlFactory( const ACTION_TOOLBAR_CONTROL& aControlDesc,
  393. const ACTION_TOOLBAR_CONTROL_FACTORY& aControlFactory );
  394. /**
  395. *
  396. */
  397. ACTION_TOOLBAR_CONTROL_FACTORY* GetCustomToolbarControlFactory( const std::string& aName );
  398. /**
  399. * Recreate the menu bar.
  400. *
  401. * Needed when the language or icons are changed
  402. */
  403. void ReCreateMenuBar();
  404. void SetMenuBar( wxMenuBar *menu_bar ) override;
  405. /**
  406. * Add the standard KiCad help menu to the menubar.
  407. */
  408. void AddStandardHelpMenu( wxMenuBar* aMenuBar );
  409. /**
  410. * Check if \a aFileName can be written.
  411. *
  412. * The function performs a number of tests on \a aFileName to verify that it can be saved.
  413. * If \a aFileName defines a path with no file name, them the path is tested for user write
  414. * permission. If \a aFileName defines a file name that does not exist in the path, the
  415. * path is tested for user write permission. If \a aFileName defines a file that already
  416. * exits, the file name is tested for user write permissions.
  417. *>
  418. * @note The file name path must be set or an assertion will be raised on debug builds and
  419. * return false on release builds.
  420. * @param aFileName The full path and/or file name of the file to test.
  421. * @param aVerbose If true will show an error dialog if the file is not writable
  422. * @return False if \a aFileName cannot be written.
  423. */
  424. bool IsWritable( const wxFileName& aFileName, bool aVerbose = true );
  425. /**
  426. * Check if an auto save file exists for \a aFileName and takes the appropriate action
  427. * depending on the user input.
  428. *
  429. * If an auto save file exists for \a aFileName, the user is prompted if they wish to
  430. * replace file \a aFileName with the auto saved file. If the user chooses to replace the
  431. * file, the backup file of \a aFileName is removed, \a aFileName is renamed to the backup
  432. * file name, and the auto save file is renamed to \a aFileName. If user chooses to keep
  433. * the existing version of \a aFileName, the auto save file is removed.
  434. *
  435. * @param aFileName A wxFileName object containing the file name to check.
  436. */
  437. virtual void CheckForAutoSaveFile( const wxFileName& aFileName );
  438. virtual void DeleteAutoSaveFile( const wxFileName& aFileName );
  439. /**
  440. * Update the status bar information.
  441. *
  442. * The status bar can draw itself. This is not a drawing function per se, but rather
  443. * updates lines of text held by the components within the status bar which is owned
  444. * by the wxFrame.
  445. */
  446. virtual void UpdateStatusBar() { }
  447. /**
  448. * Redraw the menus and what not in current language.
  449. */
  450. void ShowChangedLanguage() override;
  451. /**
  452. * Notification event that some of the common (suite-wide) settings have changed.
  453. * Update menus, toolbars, local variables, etc.
  454. */
  455. void CommonSettingsChanged( int aFlags ) override;
  456. /**
  457. * Process light/dark theme change.
  458. */
  459. virtual void ThemeChanged();
  460. /**
  461. * Notification event that the project has changed.
  462. */
  463. virtual void ProjectChanged() {}
  464. const wxString& GetAboutTitle() const { return wxGetTranslation( m_aboutTitle ); }
  465. const wxString& GetUntranslatedAboutTitle() const { return m_aboutTitle; }
  466. /**
  467. * Get if the contents of the frame have been modified since the last save.
  468. *
  469. * @return true if the contents of the frame have not been saved
  470. */
  471. virtual bool IsContentModified() const;
  472. /**
  473. * Get the undecorated window size that can be used for restoring the window size.
  474. *
  475. * This is needed for GTK, since the normal wxWidgets GetSize() call will return
  476. * a window size that includes the window decorations added by the window manager.
  477. *
  478. * @return the undecorated window size
  479. */
  480. wxSize GetWindowSize();
  481. /**
  482. * Remove the \a aItemCount of old commands from \a aList and delete commands, pickers
  483. * and picked items if needed.
  484. *
  485. * Because picked items must be deleted only if they are not in use, this is a virtual
  486. * pure function that must be created for #SCH_SCREEN and #PCB_SCREEN. Commands are
  487. * deleted from the older to the last.
  488. *
  489. * @param aList = the #UNDO_REDO_CONTAINER of commands.
  490. * @param aItemCount number of old commands to delete. -1 to remove all old commands
  491. * this will empty the list of commands.
  492. */
  493. virtual void ClearUndoORRedoList( UNDO_REDO_LIST aList, int aItemCount = -1 )
  494. { }
  495. /**
  496. * Clear the undo and redo list using #ClearUndoORRedoList()
  497. *
  498. * Picked items are deleted by ClearUndoORRedoList() according to their status.
  499. */
  500. virtual void ClearUndoRedoList();
  501. /**
  502. * Add a command to undo in the undo list.
  503. *
  504. * Delete the very old commands when the max count of undo commands is reached.
  505. */
  506. virtual void PushCommandToUndoList( PICKED_ITEMS_LIST* aItem );
  507. /**
  508. * Add a command to redo in the redo list.
  509. *
  510. * Delete the very old commands when the max count of redo commands is reached.
  511. */
  512. virtual void PushCommandToRedoList( PICKED_ITEMS_LIST* aItem );
  513. /**
  514. * Return the last command to undo and remove it from list, nothing is deleted.
  515. */
  516. virtual PICKED_ITEMS_LIST* PopCommandFromUndoList();
  517. /**
  518. * Return the last command to undo and remove it from list, nothing is deleted.
  519. */
  520. virtual PICKED_ITEMS_LIST* PopCommandFromRedoList();
  521. virtual int GetUndoCommandCount() const { return m_undoList.m_CommandsList.size(); }
  522. virtual int GetRedoCommandCount() const { return m_redoList.m_CommandsList.size(); }
  523. virtual wxString GetUndoActionDescription() const;
  524. virtual wxString GetRedoActionDescription() const;
  525. int GetMaxUndoItems() const { return m_undoRedoCountMax; }
  526. /**
  527. * Must be called after a model change in order to set the "modify" flag and do other
  528. * frame-specific processing.
  529. */
  530. virtual void OnModify();
  531. bool NonUserClose( bool aForce )
  532. {
  533. m_isNonUserClose = true;
  534. return Close( aForce );
  535. }
  536. /**
  537. * Update the UI in response to a change in the system colors.
  538. */
  539. virtual void HandleSystemColorChange();
  540. /**
  541. * Check if this frame is ready to accept API commands.
  542. *
  543. * A frame might not accept commands if a long-running process is underway, a dialog is open,
  544. * the user is interacting with a tool, etc.
  545. */
  546. virtual bool CanAcceptApiCommands() { return IsEnabled(); }
  547. protected:
  548. /// Default style flags used for wxAUI toolbars.
  549. static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND;
  550. virtual void doReCreateMenuBar() {}
  551. virtual void configureToolbars();
  552. /**
  553. * Handle the auto save timer event.
  554. */
  555. void onAutoSaveTimer( wxTimerEvent& aEvent );
  556. /**
  557. * Handle a window iconize event.
  558. *
  559. * @param aEvent is the data for the event.
  560. */
  561. virtual void handleIconizeEvent( wxIconizeEvent& aEvent ) {}
  562. void onIconize( wxIconizeEvent& aEvent );
  563. /**
  564. * Return the auto save status of the application.
  565. *
  566. * Override this function if your derived frame supports automatic file saving.
  567. */
  568. virtual bool isAutoSaveRequired() const { return m_autoSaveRequired; }
  569. /**
  570. * This should be overridden by the derived class to handle the auto save feature.
  571. *
  572. * @return true if the auto save was successful otherwise false.
  573. */
  574. virtual bool doAutoSave();
  575. virtual bool canCloseWindow( wxCloseEvent& aCloseEvent ) { return true; }
  576. virtual void doCloseWindow() { }
  577. void onSystemColorChange( wxSysColourChangedEvent& aEvent );
  578. /**
  579. * Called when when the units setting has changed to allow for any derived classes
  580. * to handle refreshing and controls that have units based measurements in them.
  581. *
  582. * The default version only updates the status bar. Don't forget to call the default
  583. * in your derived class or the status bar will not get updated properly.
  584. */
  585. virtual void unitsChangeRefresh() { }
  586. /**
  587. * Setup the UI conditions for the various actions and their controls in this frame.
  588. */
  589. virtual void setupUIConditions();
  590. /**
  591. * Set the common key-pair for exiting the application (Ctrl-Q) and ties it
  592. * to the wxID_EXIT event id.
  593. *
  594. * This is useful in sub-applications to pass the event up to a non-owning window.
  595. */
  596. void initExitKey();
  597. void ensureWindowIsOnScreen();
  598. /**
  599. * Save any design-related project settings associated with this frame.
  600. *
  601. * This method should only be called as the result of direct user action, for example from an
  602. * explicit "Save Project" command or as a consequence of saving a design document.
  603. */
  604. virtual void saveProjectSettings() {}
  605. /**
  606. * Handle event fired when a file is dropped to the window.
  607. *
  608. * In this base class, stores the path of files accepted.
  609. * Calls DoWithAcceptedFiles() to execute actions on files.
  610. */
  611. virtual void OnDropFiles( wxDropFilesEvent& aEvent );
  612. /**
  613. * Create a menu list for language choice, and add it as submenu to \a MasterMenu.
  614. *
  615. * @param aMasterMenu is the main menu.
  616. * @param aControlTool is the tool to associate with the menu.
  617. */
  618. void AddMenuLanguageList( ACTION_MENU* aMasterMenu, TOOL_INTERACTIVE* aControlTool );
  619. /**
  620. * Execute action on accepted dropped file.
  621. *
  622. * Called in OnDropFiles() and should be populated with
  623. * the action to execute in inherited classes.
  624. */
  625. virtual void DoWithAcceptedFiles();
  626. std::vector<wxFileName> m_AcceptedFiles;
  627. DECLARE_EVENT_TABLE()
  628. private:
  629. /**
  630. * (with its unexpected name so it does not collide with the real OnWindowClose()
  631. * function provided in derived classes) is called just before a window
  632. * closing, and is used to call a derivation specific SaveSettings().
  633. *
  634. * #SaveSettings() is called for all derived wxFrames in this base class overload.
  635. * Calling it from a destructor is deprecated since the wxFrame's position is not
  636. * available in the destructor on linux. In other words, you should not need to
  637. * call #SaveSettings() anywhere, except in this one function found only in this class.
  638. */
  639. void windowClosing( wxCloseEvent& event );
  640. /**
  641. * Collect common initialization functions used in all CTORs
  642. */
  643. void commonInit( FRAME_T aFrameType );
  644. wxWindow* findQuasiModalDialog();
  645. /**
  646. * Return true if the frame is shown in our modal mode and false if the frame is
  647. * shown as an usual frame.
  648. *
  649. * In modal mode, the caller that created the frame is responsible to Destroy()
  650. * this frame after closing.
  651. */
  652. virtual bool IsModal() const { return false; }
  653. #ifdef __WXMSW__
  654. /**
  655. * Windows specific override of the wxWidgets message handler for a window.
  656. */
  657. WXLRESULT MSWWindowProc( WXUINT message, WXWPARAM wParam, WXLPARAM lParam ) override;
  658. #endif
  659. protected:
  660. FRAME_T m_ident; // Id Type (pcb, schematic, library..)
  661. wxPoint m_framePos;
  662. wxSize m_frameSize;
  663. bool m_maximizeByDefault;
  664. int m_displayIndex;
  665. // These contain the frame size and position for when it is not maximized
  666. wxPoint m_normalFramePos;
  667. wxSize m_normalFrameSize;
  668. wxString m_aboutTitle; // Name of program displayed in About.
  669. wxAuiManager m_auimgr;
  670. wxString m_perspective; // wxAuiManager perspective.
  671. WX_INFOBAR* m_infoBar; // Infobar for the frame
  672. APPEARANCE_CONTROLS_3D* m_appearancePanel;
  673. wxString m_configName; // Prefix used to identify some params (frame
  674. // size) and to name some config files (legacy
  675. // hotkey files)
  676. SETTINGS_MANAGER* m_settingsManager;
  677. FILE_HISTORY* m_fileHistory; // The frame's recently opened file list
  678. bool m_supportsAutoSave;
  679. bool m_autoSavePending;
  680. bool m_autoSaveRequired;
  681. wxTimer* m_autoSaveTimer;
  682. int m_undoRedoCountMax; // undo/Redo command Max depth
  683. UNDO_REDO_CONTAINER m_undoList; // Objects list for the undo command (old data)
  684. UNDO_REDO_CONTAINER m_redoList; // Objects list for the redo command (old data)
  685. wxString m_mruPath; // Most recently used path.
  686. ORIGIN_TRANSFORMS m_originTransforms; // Default display origin transforms object.
  687. /// Map containing the UI update handlers registered with wx for each action.
  688. std::map<int, UIUpdateHandler> m_uiUpdateMap;
  689. /// Set by the close window event handler after frames are asked if they can close.
  690. /// Allows other functions when called to know our state is cleanup.
  691. bool m_isClosing;
  692. /// Set by #NonUserClose() to indicate that the user did not request the current close.
  693. bool m_isNonUserClose;
  694. /**
  695. * Associate file extensions with action to execute.
  696. */
  697. std::map<const wxString, TOOL_ACTION*> m_acceptedExts;
  698. // Toolbar Settings - this is not owned by the frame
  699. TOOLBAR_SETTINGS* m_toolbarSettings;
  700. // Toolbar UI elements
  701. ACTION_TOOLBAR* m_tbTopMain;
  702. ACTION_TOOLBAR* m_tbTopAux; // Additional tools under main toolbar
  703. ACTION_TOOLBAR* m_tbRight; // Drawing tools (typically on right edge of window)
  704. ACTION_TOOLBAR* m_tbLeft; // Options (typically on left edge of window)
  705. std::map<std::string, ACTION_TOOLBAR_CONTROL_FACTORY> m_toolbarControlFactories;
  706. };
  707. /**
  708. * Specialization of the wxAuiPaneInfo class for KiCad panels.
  709. *
  710. * Documentation for wxAui is poor at this time. The following notes spring from errors made in
  711. * previous KiCad implementations:
  712. *
  713. * wxAuiPaneInfo.ToolbarPane() and .Defaults() are used to clear and then prepare the objects so
  714. * only use them once at the beginning of configuration..
  715. *
  716. * Panels are organized in layers, from 0 (close to the center) and increasing outward. Note
  717. * that for ToolbarPanes, layer 0 considered a special default value, and ToolbarPanes on
  718. * layer 0 are pushed to layer 10 automatically. Use Layer 1 for the inner layer as a work-
  719. * around.
  720. *
  721. * Each panel has rows, starting at 0. Each row has positions starting at 0. Each item in a panel
  722. * can have its row and position set.
  723. *
  724. * Eventually panels will be movable. Each initialization function sets up the panel for this,
  725. * then after a //==// break has additional calls to anchor toolbars in a way that matches
  726. * present functionality.
  727. */
  728. class EDA_PANE : public wxAuiPaneInfo
  729. {
  730. public:
  731. EDA_PANE()
  732. {
  733. Gripper( false );
  734. CloseButton( false );
  735. PaneBorder( false );
  736. }
  737. /**
  738. * Turn *this to a horizontal toolbar for KiCad.
  739. */
  740. EDA_PANE& HToolbar()
  741. {
  742. SetFlag( optionToolbar, true );
  743. CaptionVisible( false );
  744. TopDockable().BottomDockable();
  745. DockFixed( true );
  746. Movable( false );
  747. Resizable( true ); // expand to fit available space
  748. return *this;
  749. }
  750. /**
  751. * Turn *this into a vertical toolbar for KiCad.
  752. */
  753. EDA_PANE& VToolbar()
  754. {
  755. SetFlag( optionToolbar, true );
  756. CaptionVisible( false );
  757. LeftDockable().RightDockable();
  758. DockFixed( true );
  759. Movable( false );
  760. Resizable( true ); // expand to fit available space
  761. return *this;
  762. }
  763. /**
  764. * Turn *this into a captioned palette suitable for a symbol tree, layers manager, etc.
  765. */
  766. EDA_PANE& Palette()
  767. {
  768. CaptionVisible( true );
  769. PaneBorder( true );
  770. return *this;
  771. }
  772. /**
  773. * Turn *this into an undecorated pane suitable for a drawing canvas.
  774. */
  775. EDA_PANE& Canvas()
  776. {
  777. CaptionVisible( false );
  778. Layer( 0 );
  779. PaneBorder( true );
  780. Resizable( true ); // expand to fit available space
  781. return *this;
  782. }
  783. /**
  784. * Turn *this into a messages pane for KiCad.
  785. */
  786. EDA_PANE& Messages()
  787. {
  788. CaptionVisible( false );
  789. BottomDockable( true );
  790. DockFixed( true );
  791. Movable( false );
  792. Resizable( true ); // expand to fit available space
  793. return *this;
  794. }
  795. /**
  796. * Turn *this into a infobar for KiCad.
  797. */
  798. EDA_PANE& InfoBar()
  799. {
  800. CaptionVisible( false );
  801. Movable( false );
  802. Resizable( true );
  803. PaneBorder( false );
  804. DockFixed( true );
  805. return *this;
  806. }
  807. };
  808. #endif // EDA_BASE_FRAME_H_