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.

853 lines
29 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) 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. * @file eda_base_frame.h
  27. * @brief Base window classes and related definitions.
  28. */
  29. #ifndef EDA_BASE_FRAME_H_
  30. #define EDA_BASE_FRAME_H_
  31. #include <vector>
  32. #include <wx/aui/aui.h>
  33. #include <layer_ids.h>
  34. #include <frame_type.h>
  35. #include <hotkeys_basic.h>
  36. #include <kiway_holder.h>
  37. #include <tool/tools_holder.h>
  38. #include <widgets/ui_common.h>
  39. #include <widgets/infobar.h>
  40. #include <undo_redo_container.h>
  41. #include <eda_units.h>
  42. // Option for main frames
  43. #define KICAD_DEFAULT_DRAWFRAME_STYLE wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS
  44. #define VIEWER3D_FRAMENAME wxT( "Viewer3DFrameName" )
  45. #define QUALIFIED_VIEWER3D_FRAMENAME( parent ) \
  46. ( wxString( VIEWER3D_FRAMENAME ) + wxT( ":" ) + parent->GetName() )
  47. #define KICAD_MANAGER_FRAME_NAME wxT( "KicadFrame" )
  48. class wxChoice;
  49. class wxEvent;
  50. class wxFileName;
  51. class EDA_ITEM;
  52. class EDA_RECT;
  53. class EDA_DRAW_PANEL_GAL;
  54. class EDA_MSG_PANEL;
  55. class BASE_SCREEN;
  56. class PARAM_CFG;
  57. class PAGE_INFO;
  58. class PLOTTER;
  59. class TITLE_BLOCK;
  60. class MSG_PANEL_ITEM;
  61. class TOOL_MANAGER;
  62. class TOOL_DISPATCHER;
  63. class ACTIONS;
  64. class PAGED_DIALOG;
  65. class DIALOG_EDIT_LIBRARY_TABLES;
  66. class PANEL_HOTKEYS_EDITOR;
  67. class FILE_HISTORY;
  68. class SETTINGS_MANAGER;
  69. class SEARCH_STACK;
  70. class APP_SETTINGS_BASE;
  71. struct WINDOW_SETTINGS;
  72. struct WINDOW_STATE;
  73. #define DEFAULT_MAX_UNDO_ITEMS 0
  74. #define ABS_MAX_UNDO_ITEMS (INT_MAX / 2)
  75. /// This is the handler functor for the update UI events
  76. typedef std::function< void( wxUpdateUIEvent& ) > UIUpdateHandler;
  77. wxDECLARE_EVENT( UNITS_CHANGED, wxCommandEvent );
  78. /**
  79. * The base frame for deriving all KiCad main window classes.
  80. *
  81. * This class is not intended to be used directly. It provides support for automatic calls
  82. * to SaveSettings() function. SaveSettings() for a derived class can choose to do nothing,
  83. * or rely on basic SaveSettings() support in this base class to do most of the work by
  84. * calling it from the derived class's SaveSettings(). This class is not a #KIWAY_PLAYER
  85. * because #KICAD_MANAGER_FRAME is derived from it and that class is not a player.
  86. */
  87. class EDA_BASE_FRAME : public wxFrame, public TOOLS_HOLDER, public KIWAY_HOLDER
  88. {
  89. public:
  90. /**
  91. * Specifies whether we are interacting with the undo or redo stacks
  92. */
  93. enum UNDO_REDO_LIST
  94. {
  95. UNDO_LIST,
  96. REDO_LIST
  97. };
  98. EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle,
  99. const wxPoint& aPos, const wxSize& aSize, long aStyle,
  100. const wxString& aFrameName, KIWAY* aKiway );
  101. EDA_BASE_FRAME( FRAME_T aFrameType, KIWAY* aKiway );
  102. ~EDA_BASE_FRAME();
  103. /**
  104. * Return the user units currently in use.
  105. */
  106. EDA_UNITS GetUserUnits() const
  107. {
  108. return m_userUnits;
  109. }
  110. void SetUserUnits( EDA_UNITS aUnits )
  111. {
  112. m_userUnits = aUnits;
  113. }
  114. void ChangeUserUnits( EDA_UNITS aUnits );
  115. virtual void ToggleUserUnits() { }
  116. SETTINGS_MANAGER* GetSettingsManager() const { return m_settingsManager; }
  117. virtual SEVERITY GetSeverity( int aErrorCode ) const { return RPT_SEVERITY_UNDEFINED; }
  118. /**
  119. * Override the default process event handler to implement the auto save feature.
  120. *
  121. * @warning If you override this function in a derived class, make sure you call down to
  122. * this or the auto save feature will be disabled.
  123. */
  124. bool ProcessEvent( wxEvent& aEvent ) override;
  125. /**
  126. * Capture the key event before it is sent to the GUI.
  127. *
  128. * The basic frame does not capture this event. Editor frames should override this event
  129. * function to capture and filter these keys when they are used as hotkeys, and skip it if
  130. * the key is not used as hotkey (otherwise the key events will be not sent to menus).
  131. */
  132. virtual void OnCharHook( wxKeyEvent& aKeyEvent );
  133. /**
  134. * The #TOOL_DISPATCHER needs these to work around some issues in wxWidgets where the menu
  135. * events aren't captured by the menus themselves.
  136. */
  137. void OnMenuEvent( wxMenuEvent& event );
  138. /**
  139. * Register a UI update handler for the control with ID @c aID
  140. *
  141. * @param aID is the control ID to register the handler for
  142. * @param aConditions are the UI conditions to use for the control states
  143. */
  144. virtual void RegisterUIUpdateHandler( int aID, const ACTION_CONDITIONS& aConditions ) override;
  145. /**
  146. * Unregister a UI handler for a given ID that was registered using @c RegisterUIUpdateHandler
  147. *
  148. * @param aID is the control ID to unregister the handler for
  149. */
  150. virtual void UnregisterUIUpdateHandler( int aID ) override;
  151. /**
  152. * Handle events generated when the UI is trying to figure out the current state of the
  153. * UI controls related to #TOOL_ACTIONS (e.g. enabled, checked, etc.).
  154. *
  155. * @param aEvent is the wxUpdateUIEvent to be processed.
  156. * @param aFrame is the frame to get the selection from
  157. * @param aCond are the #UI SELECTION_CONDITIONS used
  158. */
  159. static void HandleUpdateUIEvent( wxUpdateUIEvent& aEvent, EDA_BASE_FRAME* aFrame,
  160. ACTION_CONDITIONS aCond );
  161. virtual void OnMove( wxMoveEvent& aEvent )
  162. {
  163. aEvent.Skip();
  164. }
  165. virtual void OnSize( wxSizeEvent& aEvent );
  166. void OnMaximize( wxMaximizeEvent& aEvent );
  167. void SetAutoSaveInterval( int aInterval );
  168. int GetAutoSaveInterval() const { return m_autoSaveInterval; }
  169. bool IsType( FRAME_T aType ) const { return m_ident == aType; }
  170. FRAME_T GetFrameType() const { return m_ident; }
  171. /**
  172. * Return a #SEARCH_STACK pertaining to entire program.
  173. *
  174. * This is overloaded in #KICAD_MANAGER_FRAME
  175. */
  176. virtual const SEARCH_STACK& sys_search();
  177. virtual wxString help_name();
  178. void OnKicadAbout( wxCommandEvent& event );
  179. /**
  180. * Displays the preferences and settings of all opened editors paged dialog
  181. */
  182. void OnPreferences( wxCommandEvent& event );
  183. void PrintMsg( const wxString& text );
  184. void CreateInfoBar();
  185. void FinishAUIInitialization();
  186. /**
  187. * @return the #WX_INFOBAR that can be displayed on the top of the canvas.
  188. */
  189. WX_INFOBAR* GetInfoBar() { return m_infoBar; }
  190. /**
  191. * Show the #WX_INFOBAR displayed on the top of the canvas with a message and an error
  192. * icon on the left of the infobar, and an optional closebox to the right.
  193. *
  194. * The infobar will be closed after a timeout.
  195. *
  196. * @param aErrorMsg is the message to display.
  197. * @param aShowCloseButton true to show a close button on the right of the #WX_INFOBAR.
  198. */
  199. void ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton = false,
  200. WX_INFOBAR::MESSAGE_TYPE aType = WX_INFOBAR::MESSAGE_TYPE::GENERIC );
  201. /**
  202. * Show the #WX_INFOBAR displayed on the top of the canvas with a message and an error
  203. * icon on the left of the infobar, and an optional closebox to the right.
  204. *
  205. * The infobar will be closed after a timeout.
  206. *
  207. * This version accepts a callback which will be called when the infobar is dismissed
  208. * (either as a result of user action or a timeout). This can be useful when the caller
  209. * wants to make other decorations in the canvas to highlight the error.
  210. *
  211. * @param aErrorMsg is the message to display.
  212. * @param aShowCloseButton true to show a close button on the right of the #WX_INFOBAR.
  213. * @param aCallback a callback to be called when the infobar is dismissed.
  214. */
  215. void ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
  216. std::function<void(void)> aCallback );
  217. /**
  218. * Show the #WX_INFOBAR displayed on the top of the canvas with a message and a warning
  219. * icon on the left of the infobar.
  220. *
  221. * The infobar will be closed after a timeout.
  222. *
  223. * @param aErrorMsg is the message to display.
  224. * @param aShowCloseButton true to show a close button on the right of the #WX_INFOBAR.
  225. */
  226. void ShowInfoBarWarning( const wxString& aWarningMsg, bool aShowCloseButton = false );
  227. /**
  228. * Show the #WX_INFOBAR displayed on the top of the canvas with a message and an info
  229. * icon on the left of the infobar.
  230. *
  231. * The infobar will be closed after a timeout.
  232. *
  233. * @param aErrorMsg is the message to display.
  234. * @param aShowCloseButton true to show a close button on the right of the #WX_INFOBAR.
  235. */
  236. void ShowInfoBarMsg( const wxString& aMsg, bool aShowCloseButton = false );
  237. /**
  238. * Returns the settings object used in SaveSettings(), and is overloaded in
  239. * #KICAD_MANAGER_FRAME.
  240. */
  241. virtual APP_SETTINGS_BASE* config() const;
  242. /**
  243. * Allow a frame to load its preference panels (if any) into the preferences dialog.
  244. *
  245. * @param aParent a paged dialog into which the preference panels should be installed.
  246. */
  247. virtual void InstallPreferences( PAGED_DIALOG* , PANEL_HOTKEYS_EDITOR* ) { }
  248. void LoadWindowState( const wxString& aFileName );
  249. /**
  250. * Load window settings from the given settings object.
  251. *
  252. * Normally called by #LoadSettings() unless the window in question is a child window
  253. * that* stores its settings somewhere other than #APP_SETTINGS_BASE::m_Window.
  254. */
  255. void LoadWindowSettings( const WINDOW_SETTINGS* aCfg );
  256. /**
  257. * Save window settings to the given settings object.
  258. *
  259. * Normally called by #SaveSettings unless the window in question is a child window that
  260. * stores its settings somewhere other than #APP_SETTINGS_BASE::m_Window.
  261. */
  262. void SaveWindowSettings( WINDOW_SETTINGS* aCfg );
  263. /**
  264. * Load common frame parameters from a configuration file.
  265. *
  266. * Don't forget to call the base method or your frames won't remember their positions
  267. * and sizes.
  268. */
  269. virtual void LoadSettings( APP_SETTINGS_BASE* aCfg );
  270. /**
  271. * Save common frame parameters to a configuration data file.
  272. *
  273. * Don't forget to call the base class's SaveSettings() from your derived
  274. * #SaveSettings() otherwise the frames won't remember their positions and sizes.
  275. */
  276. virtual void SaveSettings( APP_SETTINGS_BASE* aCfg );
  277. /**
  278. * Return a pointer to the window settings for this frame.
  279. *
  280. * By default, points to aCfg->m_Window for top-level frames.
  281. *
  282. * @param aCfg is this frame's config object
  283. */
  284. virtual WINDOW_SETTINGS* GetWindowSettings( APP_SETTINGS_BASE* aCfg );
  285. /**
  286. * Load frame state info from a configuration file
  287. */
  288. virtual void LoadWindowState( const WINDOW_STATE& aState );
  289. /**
  290. * Get the configuration base name.
  291. *
  292. * This is usually the name of the frame set by CTOR, except for frames shown in
  293. * multiple modes in which case the m_configName must be set to the base name so
  294. * that a single configuration can be used.
  295. *
  296. * @return a base name prefix used in Load/Save settings to build the full name of keys
  297. * used in configuration.
  298. */
  299. wxString ConfigBaseName() override
  300. {
  301. wxString baseCfgName = m_configName.IsEmpty() ? GetName() : m_configName;
  302. return baseCfgName;
  303. }
  304. /**
  305. * Save changes to the project settings to the project (.pro) file.
  306. *
  307. * The method is virtual so you can override it to call the suitable save method.
  308. * The base method does nothing.
  309. *
  310. * @param aAskForSave true to open a dialog before saving the settings.
  311. */
  312. virtual void SaveProjectSettings() {};
  313. /**
  314. * Prompt the user for a hotkey file to read, and read it.
  315. *
  316. * @param aActionMap current hotkey map (over which the imported hotkeys will be applied).
  317. * @param aDefaultShortname a default short name (extension not needed) like
  318. * Eeschema, KiCad...
  319. */
  320. void ImportHotkeyConfigFromFile( std::map<std::string, TOOL_ACTION*> aActionMap,
  321. const wxString& aDefaultShortname );
  322. /**
  323. * Fetches the file name from the file history list.
  324. *
  325. * This removes the selected file, if this file does not exist. The menu is also updated,
  326. * if #FILE_HISTORY::UseMenu was called at initialization time.
  327. *
  328. * @param cmdId The command ID associated with the \a aFileHistory object.
  329. * @param type Please document me!
  330. * @param aFileHistory The FILE_HISTORY in use. If null, the main application file
  331. * history is used
  332. * @return a wxString containing the selected filename
  333. */
  334. wxString GetFileFromHistory( int cmdId, const wxString& type,
  335. FILE_HISTORY* aFileHistory = nullptr );
  336. /**
  337. * Removes all files from the file history.
  338. *
  339. * @param aFileHistory The FILE_HISTORY in use. If null, the main application file
  340. * history is used
  341. */
  342. void ClearFileHistory( FILE_HISTORY* aFileHistory = nullptr );
  343. /**
  344. * Update the list of recently opened files.
  345. *
  346. * The menu is also updated, if FILE_HISTORY::UseMenu was called at init time.
  347. *
  348. * @param FullFileName The full file name including the path.
  349. * @param aFileHistory The FILE_HISTORY in use. If NULL, the main application file
  350. * history is used.
  351. */
  352. void UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory = nullptr );
  353. /**
  354. * Get the frame's main file history.
  355. *
  356. * @return the main file history
  357. */
  358. FILE_HISTORY& GetFileHistory()
  359. {
  360. return *m_fileHistory;
  361. }
  362. void SetMruPath( const wxString& aPath ) { m_mruPath = aPath; }
  363. wxString GetMruPath() const { return m_mruPath; }
  364. /**
  365. * Get the full filename + path of the currently opened file in the frame.
  366. *
  367. * If no file is open, an empty string is returned.
  368. *
  369. * @return the filename and full path to the open file
  370. */
  371. virtual wxString GetCurrentFileName() const { return wxEmptyString; }
  372. /**
  373. * Recreates the menu bar.
  374. *
  375. * Needed when the language or icons are changed
  376. */
  377. virtual void ReCreateMenuBar();
  378. /**
  379. * Adds the standard KiCad help menu to the menubar.
  380. */
  381. void AddStandardHelpMenu( wxMenuBar* aMenuBar );
  382. /**
  383. * Checks if \a aFileName can be written.
  384. *
  385. * The function performs a number of tests on \a aFileName to verify that it can be saved.
  386. * If \a aFileName defines a path with no file name, them the path is tested for user write
  387. * permission. If \a aFileName defines a file name that does not exist in the path, the
  388. * path is tested for user write permission. If \a aFileName defines a file that already
  389. * exits, the file name is tested for user write permissions.
  390. *>
  391. * @note The file name path must be set or an assertion will be raised on debug builds and
  392. * return false on release builds.
  393. * @param aFileName The full path and/or file name of the file to test.
  394. * @param aVerbose If true will show an error dialog if the file is not writable
  395. * @return False if \a aFileName cannot be written.
  396. */
  397. bool IsWritable( const wxFileName& aFileName, bool aVerbose = true );
  398. /**
  399. * Check if an auto save file exists for \a aFileName and takes the appropriate action
  400. * depending on the user input.
  401. *
  402. * If an auto save file exists for \a aFileName, the user is prompted if they wish to
  403. * replace file \a aFileName with the auto saved file. If the user chooses to replace the
  404. * file, the backup file of \a aFileName is removed, \a aFileName is renamed to the backup
  405. * file name, and the auto save file is renamed to \a aFileName. If user chooses to keep
  406. * the existing version of \a aFileName, the auto save file is removed.
  407. *
  408. * @param aFileName A wxFileName object containing the file name to check.
  409. */
  410. virtual void CheckForAutoSaveFile( const wxFileName& aFileName );
  411. /**
  412. * Update the status bar information.
  413. *
  414. * The status bar can draw itself. This is not a drawing function per se, but rather
  415. * updates lines of text held by the components within the status bar which is owned
  416. * by the wxFrame.
  417. */
  418. virtual void UpdateStatusBar() { }
  419. /**
  420. * Redraw the menus and what not in current language.
  421. */
  422. void ShowChangedLanguage() override;
  423. /**
  424. * Notification event that some of the common (suite-wide) settings have changed.
  425. * Update menus, toolbars, local variables, etc.
  426. */
  427. void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
  428. /**
  429. * Process light/dark theme change.
  430. */
  431. virtual void ThemeChanged();
  432. /**
  433. * Notification event that the project has changed.
  434. */
  435. virtual void ProjectChanged() {}
  436. const wxString& GetAboutTitle() const { return m_aboutTitle; }
  437. /**
  438. * Get if the contents of the frame have been modified since the last save.
  439. *
  440. * @return true if the contents of the frame have not been saved
  441. */
  442. virtual bool IsContentModified() const;
  443. /**
  444. * Get the undecorated window size that can be used for restoring the window size.
  445. *
  446. * This is needed for GTK, since the normal wxWidgets GetSize() call will return
  447. * a window size that includes the window decorations added by the window manager.
  448. *
  449. * @return the undecorated window size
  450. */
  451. wxSize GetWindowSize();
  452. /**
  453. * Remove the \a aItemCount of old commands from \a aList and delete commands, pickers
  454. * and picked items if needed.
  455. *
  456. * Because picked items must be deleted only if they are not in use, this is a virtual
  457. * pure function that must be created for #SCH_SCREEN and #PCB_SCREEN. Commands are
  458. * deleted from the older to the last.
  459. *
  460. * @param aList = the #UNDO_REDO_CONTAINER of commands.
  461. * @param aItemCount number of old commands to delete. -1 to remove all old commands
  462. * this will empty the list of commands.
  463. */
  464. virtual void ClearUndoORRedoList( UNDO_REDO_LIST aList, int aItemCount = -1 )
  465. { }
  466. /**
  467. * Clear the undo and redo list using #ClearUndoORRedoList()
  468. *
  469. * Picked items are deleted by ClearUndoORRedoList() according to their status.
  470. */
  471. virtual void ClearUndoRedoList();
  472. /**
  473. * Add a command to undo in the undo list.
  474. *
  475. * Delete the very old commands when the max count of undo commands is reached.
  476. */
  477. virtual void PushCommandToUndoList( PICKED_ITEMS_LIST* aItem );
  478. /**
  479. * Add a command to redo in the redo list.
  480. *
  481. * Delete the very old commands when the max count of redo commands is reached.
  482. */
  483. virtual void PushCommandToRedoList( PICKED_ITEMS_LIST* aItem );
  484. /**
  485. * Return the last command to undo and remove it from list, nothing is deleted.
  486. */
  487. virtual PICKED_ITEMS_LIST* PopCommandFromUndoList();
  488. /**
  489. * Return the last command to undo and remove it from list, nothing is deleted.
  490. */
  491. virtual PICKED_ITEMS_LIST* PopCommandFromRedoList();
  492. virtual int GetUndoCommandCount() const { return m_undoList.m_CommandsList.size(); }
  493. virtual int GetRedoCommandCount() const { return m_redoList.m_CommandsList.size(); }
  494. int GetMaxUndoItems() const { return m_undoRedoCountMax; }
  495. bool NonUserClose( bool aForce )
  496. {
  497. m_isNonUserClose = true;
  498. return Close( aForce );
  499. }
  500. /**
  501. * Update the UI in response to a change in the system colors.
  502. */
  503. virtual void HandleSystemColorChange();
  504. protected:
  505. ///< Default style flags used for wxAUI toolbars.
  506. static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND;
  507. /**
  508. * @return the string to prepend to a file name for automatic save.
  509. */
  510. static wxString GetAutoSaveFilePrefix()
  511. {
  512. return wxT( "_autosave-" );
  513. }
  514. /**
  515. * Handle the auto save timer event.
  516. */
  517. void onAutoSaveTimer( wxTimerEvent& aEvent );
  518. /**
  519. * Return the auto save status of the application.
  520. *
  521. * Override this function if your derived frame supports automatic file saving.
  522. */
  523. virtual bool isAutoSaveRequired() const { return false; }
  524. /**
  525. * This should be overridden by the derived class to handle the auto save feature.
  526. *
  527. * @return true if the auto save was successful otherwise false.
  528. */
  529. virtual bool doAutoSave();
  530. virtual bool canCloseWindow( wxCloseEvent& aCloseEvent ) { return true; }
  531. virtual void doCloseWindow() { }
  532. void onSystemColorChange( wxSysColourChangedEvent& aEvent );
  533. /**
  534. * Called when when the units setting has changed to allow for any derived classes
  535. * to handle refreshing and controls that have units based measurements in them.
  536. *
  537. * The default version only updates the status bar. Don't forget to call the default
  538. * in your derived class or the status bar will not get updated properly.
  539. */
  540. virtual void unitsChangeRefresh() { }
  541. /**
  542. * Setup the UI conditions for the various actions and their controls in this frame.
  543. */
  544. virtual void setupUIConditions();
  545. /**
  546. * Sets the common key-pair for exiting the application (Ctrl-Q) and ties it
  547. * to the wxID_EXIT event id.
  548. *
  549. * This is useful in sub-applications to pass the event up to a non-owning window.
  550. */
  551. void initExitKey();
  552. void ensureWindowIsOnScreen();
  553. DECLARE_EVENT_TABLE()
  554. private:
  555. /**
  556. * (with its unexpected name so it does not collide with the real OnWindowClose()
  557. * function provided in derived classes) is called just before a window
  558. * closing, and is used to call a derivation specific SaveSettings().
  559. *
  560. * #SaveSettings() is called for all derived wxFrames in this base class overload.
  561. * Calling it from a destructor is deprecated since the wxFrame's position is not
  562. * available in the destructor on linux. In other words, you should not need to
  563. * call #SaveSettings() anywhere, except in this one function found only in this class.
  564. */
  565. void windowClosing( wxCloseEvent& event );
  566. /**
  567. * Collect common initialization functions used in all CTORs
  568. */
  569. void commonInit( FRAME_T aFrameType );
  570. wxWindow* findQuasiModalDialog();
  571. /**
  572. * Return true if the frame is shown in our modal mode and false if the frame is
  573. * shown as an usual frame.
  574. *
  575. * In modal mode, the caller that created the frame is responsible to Destroy()
  576. * this frame after closing.
  577. */
  578. virtual bool IsModal() const { return false; }
  579. #ifdef _WIN32
  580. /**
  581. * Windows specific override of the wxWidgets message handler for a window
  582. */
  583. WXLRESULT MSWWindowProc( WXUINT message, WXWPARAM wParam, WXLPARAM lParam ) override;
  584. #endif
  585. protected:
  586. FRAME_T m_ident; // Id Type (pcb, schematic, library..)
  587. wxPoint m_framePos;
  588. wxSize m_frameSize;
  589. bool m_maximizeByDefault;
  590. int m_displayIndex;
  591. // These contain the frame size and position for when it is not maximized
  592. wxPoint m_normalFramePos;
  593. wxSize m_normalFrameSize;
  594. wxString m_aboutTitle; // Name of program displayed in About.
  595. wxAuiManager m_auimgr;
  596. wxString m_perspective; // wxAuiManager perspective.
  597. WX_INFOBAR* m_infoBar; // Infobar for the frame
  598. wxString m_configName; // Prefix used to identify some params (frame size...)
  599. // and to name some config files (legacy hotkey files)
  600. SETTINGS_MANAGER* m_settingsManager;
  601. FILE_HISTORY* m_fileHistory; // The frame's recently opened file list
  602. bool m_hasAutoSave;
  603. bool m_autoSaveState;
  604. int m_autoSaveInterval; // The auto save interval time in seconds.
  605. wxTimer* m_autoSaveTimer;
  606. int m_undoRedoCountMax; // undo/Redo command Max depth
  607. UNDO_REDO_CONTAINER m_undoList; // Objects list for the undo command (old data)
  608. UNDO_REDO_CONTAINER m_redoList; // Objects list for the redo command (old data)
  609. wxString m_mruPath; // Most recently used path.
  610. EDA_UNITS m_userUnits;
  611. ///< Map containing the UI update handlers registered with wx for each action.
  612. std::map<int, UIUpdateHandler> m_uiUpdateMap;
  613. ///< Set by the close window event handler after frames are asked if they can close.
  614. ///< Allows other functions when called to know our state is cleanup.
  615. bool m_isClosing;
  616. ///< Set by #NonUserClose() to indicate that the user did not request the current close.
  617. bool m_isNonUserClose;
  618. };
  619. /**
  620. * Specialization of the wxAuiPaneInfo class for KiCad panels.
  621. *
  622. * Documentation for wxAui is poor at this time. The following notes spring from errors made in
  623. * previous KiCad implementations:
  624. *
  625. * wxAuiPaneInfo.ToolbarPane() and .Defaults() are used to clear and then prepare the objects so
  626. * only use them once at the beginning of configuration..
  627. *
  628. * Panels are organized in layers, from 0 (close to the center) and increasing outward. Note
  629. * that for ToolbarPanes, layer 0 considered a special default value, and ToolbarPanes on
  630. * layer 0 are pushed to layer 10 automatically. Use Layer 1 for the inner layer as a work-
  631. * around.
  632. *
  633. * Each panel has rows, starting at 0. Each row has positions starting at 0. Each item in a panel
  634. * can have its row and position set.
  635. *
  636. * Eventually panels will be movable. Each initialization function sets up the panel for this,
  637. * then after a //==// break has additional calls to anchor toolbars in a way that matches
  638. * present functionality.
  639. */
  640. class EDA_PANE : public wxAuiPaneInfo
  641. {
  642. public:
  643. EDA_PANE()
  644. {
  645. Gripper( false );
  646. CloseButton( false );
  647. PaneBorder( false );
  648. }
  649. /**
  650. * Turn *this to a horizontal toolbar for KiCad.
  651. */
  652. EDA_PANE& HToolbar()
  653. {
  654. SetFlag( optionToolbar, true );
  655. CaptionVisible( false );
  656. TopDockable().BottomDockable();
  657. DockFixed( true );
  658. Movable( false );
  659. Resizable( true ); // expand to fit available space
  660. return *this;
  661. }
  662. /**
  663. * Turn *this into a vertical toolbar for KiCad.
  664. */
  665. EDA_PANE& VToolbar()
  666. {
  667. SetFlag( optionToolbar, true );
  668. CaptionVisible( false );
  669. LeftDockable().RightDockable();
  670. DockFixed( true );
  671. Movable( false );
  672. Resizable( true ); // expand to fit available space
  673. return *this;
  674. }
  675. /**
  676. * Turn *this into a captioned palette suitable for a symbol tree, layers manager, etc.
  677. */
  678. EDA_PANE& Palette()
  679. {
  680. CaptionVisible( true );
  681. PaneBorder( true );
  682. return *this;
  683. }
  684. /**
  685. * Turn *this into an undecorated pane suitable for a drawing canvas.
  686. */
  687. EDA_PANE& Canvas()
  688. {
  689. CaptionVisible( false );
  690. Layer( 0 );
  691. PaneBorder( true );
  692. Resizable( true ); // expand to fit available space
  693. return *this;
  694. }
  695. /**
  696. * Turn *this into a messages pane for KiCad.
  697. */
  698. EDA_PANE& Messages()
  699. {
  700. CaptionVisible( false );
  701. BottomDockable( true );
  702. DockFixed( true );
  703. Movable( false );
  704. Resizable( true ); // expand to fit available space
  705. return *this;
  706. }
  707. /**
  708. * Turn *this into a infobar for KiCad.
  709. */
  710. EDA_PANE& InfoBar()
  711. {
  712. CaptionVisible( false );
  713. Movable( false );
  714. Resizable( true );
  715. PaneBorder( false );
  716. DockFixed( true );
  717. return *this;
  718. }
  719. };
  720. #endif // EDA_BASE_FRAME_H_