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.

1093 lines
38 KiB

18 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
15 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2011 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 wxstruct.h
  27. * @brief Base window classes and related definitions.
  28. */
  29. #ifndef WXSTRUCT_H_
  30. #define WXSTRUCT_H_
  31. #include <vector>
  32. #include <wx/socket.h>
  33. #include <wx/log.h>
  34. #include <wx/config.h>
  35. #include <wx/wxhtml.h>
  36. #include <wx/laywin.h>
  37. #include <wx/aui/aui.h>
  38. #include <wx/docview.h>
  39. #include <colors.h>
  40. #include <fctsys.h>
  41. #include <common.h>
  42. #include <layers_id_colors_and_visibility.h>
  43. #ifdef USE_WX_OVERLAY
  44. #include <wx/overlay.h>
  45. #endif
  46. // Option for dialog boxes
  47. #define DIALOG_STYLE wxDEFAULT_DIALOG_STYLE | wxFRAME_FLOAT_ON_PARENT | MAYBE_RESIZE_BORDER
  48. #define KICAD_DEFAULT_DRAWFRAME_STYLE wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS
  49. // Readability helper definitions for creating backup files.
  50. #define CREATE_BACKUP_FILE true
  51. #define NO_BACKUP_FILE false
  52. class EDA_ITEM;
  53. class EDA_RECT;
  54. class EDA_DRAW_PANEL;
  55. class EDA_MSG_PANEL;
  56. class BASE_SCREEN;
  57. class PARAM_CFG_BASE;
  58. class PAGE_INFO;
  59. class PLOTTER;
  60. class TITLE_BLOCK;
  61. class MSG_PANEL_ITEM;
  62. enum id_librarytype {
  63. LIBRARY_TYPE_EESCHEMA,
  64. LIBRARY_TYPE_PCBNEW,
  65. LIBRARY_TYPE_DOC,
  66. LIBRARY_TYPE_SYMBOL
  67. };
  68. enum ID_DRAWFRAME_TYPE
  69. {
  70. NOT_INIT_FRAME_TYPE = 0,
  71. SCHEMATIC_FRAME_TYPE,
  72. LIBEDITOR_FRAME_TYPE,
  73. VIEWER_FRAME_TYPE,
  74. PCB_FRAME_TYPE,
  75. MODULE_EDITOR_FRAME_TYPE,
  76. MODULE_VIEWER_FRAME_TYPE,
  77. FOOTPRINT_WIZARD_FRAME_TYPE,
  78. CVPCB_FRAME_TYPE,
  79. CVPCB_DISPLAY_FRAME_TYPE,
  80. GERBER_FRAME_TYPE,
  81. TEXT_EDITOR_FRAME_TYPE,
  82. DISPLAY3D_FRAME_TYPE,
  83. KICAD_MAIN_FRAME_TYPE,
  84. PL_EDITOR_FRAME_TYPE
  85. };
  86. /// Custom trace mask to enable and disable auto save tracing.
  87. extern const wxChar* traceAutoSave;
  88. /**
  89. * Class EDA_BASE_FRAME
  90. * is the base frame for deriving all KiCad main window classes. This class is not
  91. * intended to be used directly.
  92. */
  93. class EDA_BASE_FRAME : public wxFrame
  94. {
  95. protected:
  96. ID_DRAWFRAME_TYPE m_Ident; ///< Id Type (pcb, schematic, library..)
  97. wxPoint m_FramePos;
  98. wxSize m_FrameSize;
  99. wxAuiToolBar* m_mainToolBar; ///< Standard horizontal Toolbar
  100. bool m_FrameIsActive;
  101. wxString m_FrameName; ///< name used for writing and reading setup
  102. ///< It is "SchematicFrame", "PcbFrame" ....
  103. wxString m_AboutTitle; ///< Name of program displayed in About.
  104. wxAuiManager m_auimgr;
  105. /// Flag to indicate if this frame supports auto save.
  106. bool m_hasAutoSave;
  107. /// Flag to indicate the last auto save state.
  108. bool m_autoSaveState;
  109. /// The auto save interval time in seconds.
  110. int m_autoSaveInterval;
  111. /// The timer used to implement the auto save feature;
  112. wxTimer* m_autoSaveTimer;
  113. /**
  114. * Function onAutoSaveTimer
  115. * handles the auto save timer event.
  116. */
  117. void onAutoSaveTimer( wxTimerEvent& aEvent );
  118. /**
  119. * Function autoSaveRequired
  120. * returns the auto save status of the application. Override this function if
  121. * your derived frame supports automatic file saving.
  122. */
  123. virtual bool isAutoSaveRequired() const { return false; }
  124. /**
  125. * Function doAutoSave
  126. * should be overridden by the derived class to handle the auto save feature.
  127. *
  128. * @return true if the auto save was successful otherwise false.
  129. */
  130. virtual bool doAutoSave();
  131. public:
  132. EDA_BASE_FRAME( wxWindow* aParent, ID_DRAWFRAME_TYPE aFrameType,
  133. const wxString& aTitle,
  134. const wxPoint& aPos, const wxSize& aSize,
  135. long aStyle,
  136. const wxString & aFrameName );
  137. ~EDA_BASE_FRAME();
  138. /**
  139. * Function ProcessEvent
  140. * overrides the default process event handler to implement the auto save feature.
  141. *
  142. * @warning If you override this function in a derived class, make sure you call
  143. * down to this or the auto save feature will be disabled.
  144. */
  145. virtual bool ProcessEvent( wxEvent& aEvent );
  146. void SetAutoSaveInterval( int aInterval ) { m_autoSaveInterval = aInterval; }
  147. int GetAutoSaveInterval() const { return m_autoSaveInterval; }
  148. wxString GetName() const { return m_FrameName; }
  149. bool IsActive() const { return m_FrameIsActive; }
  150. bool IsType( ID_DRAWFRAME_TYPE aType ) const { return m_Ident == aType; }
  151. void GetKicadHelp( wxCommandEvent& event );
  152. void GetKicadAbout( wxCommandEvent& event );
  153. /**
  154. * Function CopyVersionInfoToClipboard
  155. * copies the version information to the clipboard for bug reporting purposes.
  156. */
  157. void CopyVersionInfoToClipboard( wxCommandEvent& event );
  158. void PrintMsg( const wxString& text );
  159. /**
  160. * Append the copy version information to clipboard help menu entry to \a aMenu.
  161. *
  162. * @param aMenu - The menu to append.
  163. */
  164. void AddHelpVersionInfoMenuEntry( wxMenu* aMenu );
  165. /**
  166. * Load common frame parameters from configuration.
  167. *
  168. * The method is virtual so you can override it to load frame specific
  169. * parameters. Don't forget to call the base method or your frames won't
  170. * remember their positions and sizes.
  171. */
  172. virtual void LoadSettings();
  173. /**
  174. * Save common frame parameters from configuration.
  175. *
  176. * The method is virtual so you can override it to save frame specific
  177. * parameters. Don't forget to call the base method or your frames won't
  178. * remember their positions and sizes.
  179. */
  180. virtual void SaveSettings();
  181. /**
  182. * Function SaveProjectSettings
  183. * saves changes to the project settings to the project (.pro) file.
  184. * The method is virtual so you can override it to call the suitable save method.
  185. * The base method do nothing
  186. * @param aAskForSave = true to open a dialog before saving the settings
  187. */
  188. virtual void SaveProjectSettings( bool aAskForSave ) {};
  189. /**
  190. * Function OnSelectPreferredEditor
  191. * Open a dialog to select the editor that will used in KiCad
  192. * to edit or display files (reports ... )
  193. * The full filename editor is saved in configuration (global params)
  194. */
  195. virtual void OnSelectPreferredEditor( wxCommandEvent& event );
  196. // Read/Save and Import/export hotkeys config
  197. /**
  198. * Function ReadHotkeyConfig
  199. * Read configuration data and fill the current hotkey list with hotkeys
  200. * @param aDescList = current hotkey list descr. to initialize.
  201. */
  202. int ReadHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList );
  203. /**
  204. * Function WriteHotkeyConfig
  205. * Store the current hotkey list
  206. * It is stored using the standard wxConfig mechanism or a file.
  207. *
  208. * @param aDescList = pointer to the current hotkey list.
  209. * @param aFullFileName = a wxString pointer to a full file name.
  210. * if NULL, use the standard wxConfig mechanism (default)
  211. * the output format is: shortcut "key" "function"
  212. * lines starting with # are comments
  213. */
  214. int WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList, wxString* aFullFileName = NULL);
  215. /**
  216. * Function ReadHotkeyConfigFile
  217. * Read an old configuration file (&ltfile&gt.key) and fill the current hotkey list
  218. * with hotkeys
  219. * @param aFilename = file name to read.
  220. * @param aDescList = current hotkey list descr. to initialize.
  221. */
  222. int ReadHotkeyConfigFile( const wxString& aFilename, struct EDA_HOTKEY_CONFIG* aDescList );
  223. /**
  224. * Function ImportHotkeyConfigFromFile
  225. * Prompt the user for an old hotkey file to read, and read it.
  226. * @param aDescList = current hotkey list descr. to initialize.
  227. */
  228. void ImportHotkeyConfigFromFile( struct EDA_HOTKEY_CONFIG* aDescList );
  229. /**
  230. * Function ExportHotkeyConfigToFile
  231. * Prompt the user for an old hotkey file to read, and read it.
  232. * @param aDescList = current hotkey list descr. to initialize.
  233. */
  234. void ExportHotkeyConfigToFile( struct EDA_HOTKEY_CONFIG* aDescList );
  235. /**
  236. * Function SetLanguage
  237. * called on a language menu selection
  238. * when using a derived function, do not forget to call this one
  239. */
  240. virtual void SetLanguage( wxCommandEvent& event );
  241. /**
  242. * Function GetFileFromHistory
  243. * fetches the file name from the file history list.
  244. * and removes the selected file, if this file does not exists
  245. * Note also the menu is updated, if wxFileHistory::UseMenu
  246. * was called at init time
  247. * @param cmdId The command ID associated with the \a aFileHistory object.
  248. * @param type Please document me!
  249. * @param aFileHistory The wxFileHistory in use. If null, the main application file
  250. * history is used
  251. * @return a wxString containing the selected filename
  252. */
  253. wxString GetFileFromHistory( int cmdId, const wxString& type,
  254. wxFileHistory* aFileHistory = NULL );
  255. /**
  256. * Function UpdateFileHistory
  257. * Updates the list of recently opened files.
  258. * Note also the menu is updated, if wxFileHistory::UseMenu
  259. * was called at init time
  260. * @param FullFileName The full file name including the path.
  261. * @param aFileHistory The wxFileHistory in use.
  262. * If NULL, the main application file history is used.
  263. */
  264. void UpdateFileHistory( const wxString& FullFileName, wxFileHistory * aFileHistory = NULL );
  265. /**
  266. * Function ReCreateMenuBar
  267. * Creates recreates the menu bar.
  268. * Needed when the language is changed
  269. */
  270. virtual void ReCreateMenuBar();
  271. /**
  272. * Function IsWritable
  273. * checks if \a aFileName can be written.
  274. * <p>
  275. * The function performs a number of tests on \a aFileName to verify that it
  276. * can be saved. If \a aFileName defines a path with no file name, them the
  277. * path is tested for user write permission. If \a aFileName defines a file
  278. * name that does not exist in the path, the path is tested for user write
  279. * permission. If \a aFileName defines a file that already exits, the file
  280. * name is tested for user write permissions.
  281. * </p>
  282. *
  283. * @note The file name path must be set or an assertion will be raised on debug
  284. * builds and return false on release builds.
  285. * @param aFileName The full path and/or file name of the file to test.
  286. * @return False if \a aFileName cannot be written.
  287. */
  288. bool IsWritable( const wxFileName& aFileName );
  289. /**
  290. * Function CheckForAutoSaveFile
  291. * checks if an auto save file exists for \a aFileName and takes the appropriate
  292. * action depending on the user input.
  293. * <p>
  294. * If an auto save file exists for \a aFileName, the user is prompted if they wish
  295. * to replace file \a aFileName with the auto saved file. If the user chooses to
  296. * replace the file, the backup file of \a aFileName is removed, \a aFileName is
  297. * renamed to the backup file name, and the auto save file is renamed to \a aFileName.
  298. * If user chooses to keep the existing version of \a aFileName, the auto save file
  299. * is removed.
  300. * </p>
  301. * @param aFileName A wxFileName object containing the file name to check.
  302. * @param aBackupFileExtension A wxString object containing the backup file extension
  303. * used to create the backup file name.
  304. */
  305. void CheckForAutoSaveFile( const wxFileName& aFileName, const wxString& aBackupFileExtension );
  306. /**
  307. * Function SetModalMode
  308. * Disable or enable all other windows, to emulate a dialog behavior
  309. * Useful when the frame is used to show and selec items
  310. * (see FOOTPRINT_VIEWER_FRAME and LIB_VIEW_FRAME)
  311. *
  312. * @param aModal = true to disable all other opened windows (i.e.
  313. * this windows is in dialog mode
  314. * = false to enable other windows
  315. * This function is analog to MakeModal( aModal ), deprecated since wxWidgets 2.9.4
  316. */
  317. void SetModalMode( bool aModal );
  318. };
  319. /**
  320. * Class EDA_DRAW_FRAME
  321. * is the base class for create windows for drawing purpose. The Eeschema, Pcbnew and
  322. * GerbView main windows are just a few examples of classes derived from EDA_DRAW_FRAME.
  323. */
  324. class EDA_DRAW_FRAME : public EDA_BASE_FRAME
  325. {
  326. /// Let the #EDA_DRAW_PANEL object have access to the protected data since
  327. /// it is closely tied to the #EDA_DRAW_FRAME.
  328. friend class EDA_DRAW_PANEL;
  329. ///< Id of active button on the vertical toolbar.
  330. int m_toolId;
  331. BASE_SCREEN* m_currentScreen; ///< current used SCREEN
  332. bool m_snapToGrid; ///< Indicates if cursor should be snapped to grid.
  333. protected:
  334. EDA_HOTKEY_CONFIG* m_HotkeysZoomAndGridList;
  335. int m_LastGridSizeId;
  336. bool m_DrawGrid; // hide/Show grid
  337. EDA_COLOR_T m_GridColor; // Grid color
  338. /// The area to draw on.
  339. EDA_DRAW_PANEL* m_canvas;
  340. /// Tool ID of previously active draw tool bar button.
  341. int m_lastDrawToolId;
  342. /// The shape of the KiCad cursor. The default value (0) is the normal cross
  343. /// hair cursor. Set to non-zero value to draw the full screen cursor.
  344. /// @note This is not the system mouse cursor.
  345. int m_cursorShape;
  346. /// True shows the X and Y axis indicators.
  347. bool m_showAxis;
  348. /// True shows the grid axis indicators.
  349. bool m_showGridAxis;
  350. /// True shows the origin axis used to indicate the coordinate offset for
  351. /// drill, gerber, and component position files.
  352. bool m_showOriginAxis;
  353. /// True shows the drawing border and title block.
  354. bool m_showBorderAndTitleBlock;
  355. /// Choice box to choose the grid size.
  356. wxComboBox* m_gridSelectBox;
  357. /// Choice box to choose the zoom value.
  358. wxComboBox* m_zoomSelectBox;
  359. /// The tool bar that contains the buttons for quick access to the application draw
  360. /// tools. It typically is located on the right side of the main window.
  361. wxAuiToolBar* m_drawToolBar;
  362. /// The options tool bar typcially located on the left edge of the main window.
  363. wxAuiToolBar* m_optionsToolBar;
  364. /// Panel used to display information at the bottom of the main window.
  365. EDA_MSG_PANEL* m_messagePanel;
  366. int m_MsgFrameHeight;
  367. #ifdef USE_WX_OVERLAY
  368. // MAC Uses overlay to workaround the wxINVERT and wxXOR miss
  369. wxOverlay m_overlay;
  370. #endif
  371. protected:
  372. void SetScreen( BASE_SCREEN* aScreen ) { m_currentScreen = aScreen; }
  373. /**
  374. * Function unitsChangeRefresh
  375. * is called when when the units setting has changed to allow for any derived classes
  376. * to handle refreshing and controls that have units based measurements in them. The
  377. * default version only updates the status bar. Don't forget to call the default
  378. * in your derived class or the status bar will not get updated properly.
  379. */
  380. virtual void unitsChangeRefresh();
  381. public:
  382. EDA_DRAW_FRAME( wxWindow* aParent,
  383. ID_DRAWFRAME_TYPE aFrameType,
  384. const wxString& aTitle,
  385. const wxPoint& aPos, const wxSize& aSize,
  386. long aStyle,
  387. const wxString & aFrameName );
  388. ~EDA_DRAW_FRAME();
  389. virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) = 0;
  390. virtual const PAGE_INFO& GetPageSettings() const = 0;
  391. /**
  392. * Function GetPageSizeIU
  393. * works off of GetPageSettings() to return the size of the paper page in
  394. * the internal units of this particular view.
  395. */
  396. virtual const wxSize GetPageSizeIU() const = 0;
  397. /**
  398. * Function GetAuxOrigin
  399. * returns the origin of the axis used for plotting and various exports.
  400. */
  401. virtual const wxPoint& GetAuxOrigin() const = 0;
  402. virtual void SetAuxOrigin( const wxPoint& aPosition ) = 0;
  403. /**
  404. * Function GetGridOrigin
  405. * returns the absolute coordinates of the origin of the snap grid. This is
  406. * treated as a relative offset, and snapping will occur at multiples of the grid
  407. * size relative to this point.
  408. */
  409. virtual const wxPoint& GetGridOrigin() const = 0;
  410. virtual void SetGridOrigin( const wxPoint& aPosition ) = 0;
  411. //-----<BASE_SCREEN API moved here>------------------------------------------
  412. /**
  413. * Function GetCrossHairPosition
  414. * return the current cross hair position in logical (drawing) coordinates.
  415. * @param aInvertY Inverts the Y axis position.
  416. * @return The cross hair position in drawing coordinates.
  417. */
  418. wxPoint GetCrossHairPosition( bool aInvertY = false ) const;
  419. /**
  420. * Function SetCrossHairPosition
  421. * sets the screen cross hair position to \a aPosition in logical (drawing) units.
  422. * @param aPosition The new cross hair position.
  423. * @param aSnapToGrid Sets the cross hair position to the nearest grid position to
  424. * \a aPosition.
  425. *
  426. */
  427. void SetCrossHairPosition( const wxPoint& aPosition, bool aSnapToGrid = true );
  428. /**
  429. * Function GetCursorPosition
  430. * returns the current cursor position in logical (drawing) units.
  431. * @param aOnGrid Returns the nearest grid position at the current cursor position.
  432. * @param aGridSize Custom grid size instead of the current grid size. Only valid
  433. * if \a aOnGrid is true.
  434. * @return The current cursor position.
  435. */
  436. wxPoint GetCursorPosition( bool aOnGrid, wxRealPoint* aGridSize = NULL ) const;
  437. /**
  438. * Function GetNearestGridPosition
  439. * returns the nearest \a aGridSize location to \a aPosition.
  440. * @param aPosition The position to check.
  441. * @param aGridSize The grid size to locate to if provided. If NULL then the current
  442. * grid size is used.
  443. * @return The nearst grid position.
  444. */
  445. wxPoint GetNearestGridPosition( const wxPoint& aPosition, wxRealPoint* aGridSize = NULL ) const;
  446. /**
  447. * Function GetCursorScreenPosition
  448. * returns the cross hair position in device (display) units.b
  449. * @return The current cross hair position.
  450. */
  451. wxPoint GetCrossHairScreenPosition() const;
  452. void SetMousePosition( const wxPoint& aPosition );
  453. /**
  454. * Function RefPos
  455. * Return the reference position, coming from either the mouse position
  456. * or the cursor position.
  457. *
  458. * @param useMouse If true, return mouse position, else cursor's.
  459. *
  460. * @return wxPoint - The reference point, either the mouse position or
  461. * the cursor position.
  462. */
  463. wxPoint RefPos( bool useMouse ) const;
  464. const wxPoint& GetScrollCenterPosition() const;
  465. void SetScrollCenterPosition( const wxPoint& aPoint );
  466. //-----</BASE_SCREEN API moved here>-----------------------------------------
  467. virtual const TITLE_BLOCK& GetTitleBlock() const = 0;
  468. virtual void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) = 0;
  469. int GetCursorShape() const { return m_cursorShape; }
  470. void SetCursorShape( int aCursorShape ) { m_cursorShape = aCursorShape; }
  471. bool GetShowBorderAndTitleBlock() const { return m_showBorderAndTitleBlock; }
  472. void SetShowBorderAndTitleBlock( bool aShow ) { m_showBorderAndTitleBlock = aShow; }
  473. EDA_DRAW_PANEL* GetCanvas() { return m_canvas; }
  474. virtual wxString GetScreenDesc();
  475. /**
  476. * Function GetScreen
  477. * returns a pointer to a BASE_SCREEN or one of its
  478. * derivatives. It is overloaded by derived classes to return
  479. * SCH_SCREEN or PCB_SCREEN.
  480. */
  481. virtual BASE_SCREEN* GetScreen() const { return m_currentScreen; }
  482. void OnMenuOpen( wxMenuEvent& event );
  483. void OnMouseEvent( wxMouseEvent& event );
  484. /** function SkipNextLeftButtonReleaseEvent
  485. * after calling this function, if the left mouse button
  486. * is down, the next left mouse button release event will be ignored.
  487. * It is is usefull for instance when closing a dialog on a mouse click,
  488. * to skip the next mouse left button release event
  489. * by the parent window, because the mouse button
  490. * clicked on the dialog is often released in the parent frame,
  491. * and therefore creates a left button released mouse event
  492. * which can be unwanted in some cases
  493. */
  494. void SkipNextLeftButtonReleaseEvent();
  495. virtual void OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
  496. EDA_ITEM* aItem = NULL );
  497. /**
  498. * Function AddMenuZoomAndGrid (virtual)
  499. * Add standard zoom commands and submenu zoom and grid selection to a popup menu
  500. * uses zoom hotkeys info base to add hotkeys info to menu commands
  501. * @param aMasterMenu = the menu to populate.
  502. */
  503. virtual void AddMenuZoomAndGrid( wxMenu* aMasterMenu );
  504. void EraseMsgBox();
  505. void Process_PageSettings( wxCommandEvent& event );
  506. /**
  507. * Function SetLanguage
  508. * called on a language menu selection
  509. * when using a derived function, do not forget to call this one
  510. */
  511. virtual void SetLanguage( wxCommandEvent& event );
  512. virtual void ReCreateHToolbar() = 0;
  513. virtual void ReCreateVToolbar() = 0;
  514. virtual void ReCreateMenuBar();
  515. virtual void ReCreateAuxiliaryToolbar();
  516. /**
  517. * Function SetToolID
  518. * sets the tool command ID to \a aId and sets the cursor to \a aCursor. The
  519. * command ID must be greater or equal ::ID_NO_TOOL_SELECTED. If the command
  520. * ID is less than ::ID_NO_TOOL_SELECTED, the tool command ID is set to
  521. * ::ID_NO_TOOL_SELECTED. On debug builds, an assertion will be raised when
  522. * \a aId is invalid.
  523. * @param aId New tool command ID if greater than or equal to ::ID_NO_TOOL_SELECTED.
  524. If less than zero, the current tool command ID is retained.
  525. * @param aCursor Sets the cursor shape if greater than or equal to zero.
  526. * @param aToolMsg The tool message to set in the status bar.
  527. */
  528. virtual void SetToolID( int aId, int aCursor, const wxString& aToolMsg );
  529. int GetToolId() const { return m_toolId; }
  530. /* These 4 functions provide a basic way to show/hide grid
  531. * and /get/set grid color.
  532. * These parameters are saved in KiCad config for each main frame
  533. */
  534. /**
  535. * Function IsGridVisible() , virtual
  536. * @return true if the grid must be shown
  537. */
  538. virtual bool IsGridVisible() const
  539. {
  540. return m_DrawGrid;
  541. }
  542. /**
  543. * Function SetGridVisibility() , virtual
  544. * It may be overloaded by derived classes
  545. * @param aVisible = true if the grid must be shown
  546. */
  547. virtual void SetGridVisibility( bool aVisible )
  548. {
  549. m_DrawGrid = aVisible;
  550. }
  551. /**
  552. * Function GetGridColor() , virtual
  553. * @return the color of the grid
  554. */
  555. virtual EDA_COLOR_T GetGridColor() const
  556. {
  557. return m_GridColor;
  558. }
  559. /**
  560. * Function SetGridColor() , virtual
  561. * @param aColor = the new color of the grid
  562. */
  563. virtual void SetGridColor( EDA_COLOR_T aColor )
  564. {
  565. m_GridColor = aColor;
  566. }
  567. /**
  568. * Function GetGridPosition
  569. * returns the nearest grid position to \a aPosition if a screen is defined and snap to
  570. * grid is enabled. Otherwise, the original positions is returned.
  571. * @see m_snapToGrid and m_BaseScreen members.
  572. * @param aPosition The position to test.
  573. * @return The wxPoint of the appropriate cursor position.
  574. */
  575. wxPoint GetGridPosition( const wxPoint& aPosition ) const;
  576. /**
  577. * Command event handler for selecting grid sizes.
  578. *
  579. * All commands that set the grid size should eventually end up here.
  580. * This is where the application setting is saved. If you override
  581. * this method, make sure you call down to the base class.
  582. *
  583. * @param event - Command event passed by selecting grid size from the
  584. * grid size combobox on the toolbar.
  585. */
  586. virtual void OnSelectGrid( wxCommandEvent& event );
  587. /**
  588. * Functions OnSelectZoom
  589. * sets the zoom factor when selected by the zoom list box in the main tool bar.
  590. * @note List position 0 is fit to page
  591. * List position >= 1 = zoom (1 to zoom max)
  592. * Last list position is custom zoom not in zoom list.
  593. */
  594. virtual void OnSelectZoom( wxCommandEvent& event );
  595. // Command event handlers shared by all applications derived from EDA_DRAW_FRAME.
  596. void OnToggleGridState( wxCommandEvent& aEvent );
  597. void OnSelectUnits( wxCommandEvent& aEvent );
  598. void OnToggleCrossHairStyle( wxCommandEvent& aEvent );
  599. // Update user interface event handlers shared by all applications derived from
  600. // EDA_DRAW_FRAME.
  601. void OnUpdateUndo( wxUpdateUIEvent& aEvent );
  602. void OnUpdateRedo( wxUpdateUIEvent& aEvent );
  603. void OnUpdateGrid( wxUpdateUIEvent& aEvent );
  604. void OnUpdateUnits( wxUpdateUIEvent& aEvent );
  605. void OnUpdateCrossHairStyle( wxUpdateUIEvent& aEvent );
  606. /**
  607. * Function GeneralControl
  608. * performs application specific control using \a aDC at \a aPosition in logical units.
  609. * <p>
  610. * Override this function for application specific control. This function gets
  611. * called on every mouse and key event.
  612. *</p>
  613. * @param aDC A device context.
  614. * @param aPosition The current cursor position in logical (drawing) units.
  615. * @param aHotKey A key event used for application specific control if not zero.
  616. */
  617. virtual void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ) { }
  618. /**
  619. * Function OnSize
  620. * recalculates the size of toolbars and display panel when the frame size changes.
  621. */
  622. virtual void OnSize( wxSizeEvent& event );
  623. void OnEraseBackground( wxEraseEvent& SizeEvent );
  624. virtual void OnZoom( wxCommandEvent& event );
  625. /**
  626. * Function RedrawScreen
  627. * redraws the entire screen area by updating the scroll bars and mouse pointer in
  628. * order to have \a aCenterPoint at the center of the screen.
  629. * @param aCenterPoint The position in logical units to center the scroll bars.
  630. * @param aWarpPointer Moves the mouse cursor to \a aCenterPoint if true.
  631. */
  632. void RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer );
  633. /**
  634. * Function RedrawScreen2
  635. * puts the crosshair back to the screen position it had before zooming
  636. * @param posBefore screen position of the crosshair before zooming
  637. */
  638. void RedrawScreen2( const wxPoint& posBefore );
  639. /**
  640. * Function Zoom_Automatique
  641. * redraws the screen with best zoom level and the best centering
  642. * that shows all the page or the board
  643. */
  644. void Zoom_Automatique( bool aWarpPointer );
  645. /* Set the zoom level to show the area Rect */
  646. void Window_Zoom( EDA_RECT& Rect );
  647. /** Return the zoom level which displays the full page on screen */
  648. virtual double BestZoom() = 0;
  649. /**
  650. * Function GetZoom
  651. * @return The current zoom level.
  652. */
  653. double GetZoom();
  654. /**
  655. * Function DrawWorkSheet
  656. * Draws on screen the page layout with the frame and the basic inscriptions.
  657. * @param aDC The device context.
  658. * @param aScreen screen to draw
  659. * @param aLineWidth The pen width to use to draw the layout.
  660. * @param aScale The mils to Iu conversion factor.
  661. * @param aFilename The filename to display in basic inscriptions.
  662. */
  663. void DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWidth,
  664. double aScale, const wxString &aFilename );
  665. void DisplayToolMsg( const wxString& msg );
  666. virtual void RedrawActiveWindow( wxDC* DC, bool EraseBg ) = 0;
  667. virtual void OnLeftClick( wxDC* DC, const wxPoint& MousePos ) = 0;
  668. virtual void OnLeftDClick( wxDC* DC, const wxPoint& MousePos );
  669. virtual bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) = 0;
  670. virtual void ToolOnRightClick( wxCommandEvent& event );
  671. void AdjustScrollBars( const wxPoint& aCenterPosition );
  672. /**
  673. * Function OnActivate (virtual)
  674. * is called when activating the frame.
  675. * In derived classes with a overriding OnActivate function,
  676. * do not forget to call this EDA_DRAW_FRAME::OnActivate( event ) basic function.
  677. */
  678. virtual void OnActivate( wxActivateEvent& event );
  679. /**
  680. * Function UpdateStatusBar
  681. * updates the status bar information.
  682. *
  683. * The base method updates the absolute and relative coordinates and the
  684. * zoom information. If you override this virtual method, make sure to call
  685. * this subclassed method. The status bar can draw itself. This is not
  686. * a drawing function per se, but rather updates lines of text held by
  687. * the components within the status bar which is owned by the wxFrame.
  688. * <p>
  689. * On a MAC, be careful about calling this function when there is an
  690. * existing wxDC in existence on a sibling window.
  691. */
  692. virtual void UpdateStatusBar();
  693. /**
  694. * Function DisplayUnitsMsg
  695. * displays current unit pane on the status bar.
  696. */
  697. void DisplayUnitsMsg();
  698. /* Handlers for block commands */
  699. virtual void InitBlockPasteInfos();
  700. /**
  701. * Function HandleBlockBegin
  702. * initializes the block command including the command type, initial position,
  703. * and other variables.
  704. */
  705. virtual bool HandleBlockBegin( wxDC* aDC, int aKey, const wxPoint& aPosition );
  706. /**
  707. * Function ReturnBlockCommand
  708. * Returns the block command code (BLOCK_MOVE, BLOCK_COPY...) corresponding to the
  709. * keys pressed (ALT, SHIFT, SHIFT ALT ..) when block command is started by dragging
  710. * the mouse.
  711. *
  712. * @param aKey = the key modifiers (Alt, Shift ...)
  713. * @return the block command id (BLOCK_MOVE, BLOCK_COPY...)
  714. */
  715. virtual int ReturnBlockCommand( int aKey );
  716. /**
  717. * Function HandleBlockPlace( )
  718. * Called after HandleBlockEnd, when a block command needs to be
  719. * executed after the block is moved to its new place
  720. * (bloc move, drag, copy .. )
  721. * Parameters must be initialized in GetScreen()->m_BlockLocate
  722. */
  723. virtual void HandleBlockPlace( wxDC* DC );
  724. /**
  725. * Function HandleBlockEnd( )
  726. * Handle the "end" of a block command,
  727. * i.e. is called at the end of the definition of the area of a block.
  728. * depending on the current block command, this command is executed
  729. * or parameters are initialized to prepare a call to HandleBlockPlace
  730. * in GetScreen()->m_BlockLocate
  731. * @return false if no item selected, or command finished,
  732. * true if some items found and HandleBlockPlace must be called later
  733. */
  734. virtual bool HandleBlockEnd( wxDC* DC );
  735. /**
  736. * Function CopyToClipboard
  737. * copies the current page or the current block to the clipboard.
  738. */
  739. void CopyToClipboard( wxCommandEvent& event );
  740. /* interprocess communication */
  741. void OnSockRequest( wxSocketEvent& evt );
  742. void OnSockRequestServer( wxSocketEvent& evt );
  743. /**
  744. * Function LoadSettings
  745. * loads the draw frame specific configuration settings.
  746. *
  747. * Don't forget to call this base method from any derived classes or the
  748. * settings common to the draw frame will not get loaded.
  749. */
  750. virtual void LoadSettings();
  751. /**
  752. * Funxtion SaveSettings
  753. * saves the draw frame specific configuration settings.
  754. *
  755. * Don't forget to call this base method from any derived classes or the
  756. * settings common to the draw frame will not get saved.
  757. */
  758. virtual void SaveSettings();
  759. /**
  760. * Append a message to the message panel.
  761. *
  762. * This helper method checks to make sure the message panel exists in
  763. * the frame and appends a message to it using the message panel
  764. * AppendMessage() method.
  765. *
  766. * @param textUpper - The message upper text.
  767. * @param textLower - The message lower text.
  768. * @param color - A color ID from the KiCad color list (see colors.h).
  769. * @param pad - Number of spaces to pad between messages (default = 4).
  770. */
  771. void AppendMsgPanel( const wxString& textUpper, const wxString& textLower,
  772. EDA_COLOR_T color, int pad = 6 );
  773. /**
  774. * Clear all messages from the message panel.
  775. */
  776. void ClearMsgPanel( void );
  777. /**
  778. * Function SetMsgPanel
  779. * clears the message panel and populates it with the contents of \a aList.
  780. *
  781. * @param aList is the list of #MSG_PANEL_ITEM objects to fill the message panel.
  782. */
  783. void SetMsgPanel( const std::vector< MSG_PANEL_ITEM >& aList );
  784. void SetMsgPanel( EDA_ITEM* aItem );
  785. /**
  786. * Function PrintPage
  787. * used to print a page
  788. * Print the page pointed by current screen, set by the calling print function
  789. * @param aDC = wxDC given by the calling print function
  790. * @param aPrintMask = not used here
  791. * @param aPrintMirrorMode = not used here (Set when printing in mirror mode)
  792. * @param aData = a pointer on an auxiliary data (not always used, NULL if not used)
  793. */
  794. virtual void PrintPage( wxDC* aDC, LAYER_MSK aPrintMask, bool aPrintMirrorMode, void* aData = NULL );
  795. /**
  796. * Function CoordinateToString
  797. * is a helper to convert the \a integer coordinate \a aValue to a string in inches or mm
  798. * according to the current user units setting.
  799. * @param aValue The coordinate to convert.
  800. * @param aConvertToMils Convert inch values to mils if true. This setting has no effect if
  801. * the current user unit is millimeters.
  802. * @return The converted string for display in user interface elements.
  803. */
  804. wxString CoordinateToString( int aValue, bool aConvertToMils = false ) const;
  805. /**
  806. * Function LengthDoubleToString
  807. * is a helper to convert the \a double value \a aValue to a string in inches or mm
  808. * according to the current user units setting.
  809. * @param aValue The coordinate to convert.
  810. * @param aConvertToMils Convert inch values to mils if true. This setting has no effect if
  811. * the current user unit is millimeters.
  812. * @return The converted string for display in user interface elements.
  813. */
  814. wxString LengthDoubleToString( double aValue, bool aConvertToMils = false ) const;
  815. DECLARE_EVENT_TABLE()
  816. };
  817. /**
  818. * Specialization of the wxAuiPaneInfo class for KiCad panels.
  819. *
  820. * Documentation for wxAui is poor at this time. The following notes spring from errors made in
  821. * previous KiCad implementations:
  822. *
  823. * wxAuiPaneInfo.ToolbarPane() and .Defaults() are used to clear and then prepare the objects so
  824. * only use them once at the beginning of configuration..
  825. *
  826. * Panels are organized in layers, from 0 (close to the center) and increasing outward. Note
  827. * that for ToolbarPanes, layer 0 considered a special default value, and ToolbarPanes on
  828. * layer 0 are pushed to layer 10 automatically. Use Layer 1 for the inner layer as a work-
  829. * around.
  830. *
  831. * Each panel has rows, starting at 0. Each row has positions starting at 0. Each item in a panel
  832. * can have it's row and position set.
  833. *
  834. * Eventually panels will be movable. Each initialization function sets up the panel for this,
  835. * then after a //==// break has additional calls to anchor toolbars in a way that matches
  836. * present functionality.
  837. */
  838. class EDA_PANEINFO : public wxAuiPaneInfo
  839. {
  840. public:
  841. /**
  842. * Function HorizontalToolbarPane
  843. * Change *this to a horizontal toolbar for KiCad.
  844. */
  845. EDA_PANEINFO& HorizontalToolbarPane()
  846. {
  847. ToolbarPane();
  848. CloseButton( false );
  849. LeftDockable( false );
  850. RightDockable( false );
  851. //==================== Remove calls below here for movable toolbars //
  852. Gripper( false );
  853. DockFixed( true );
  854. Movable( false );
  855. Resizable( true );
  856. return *this;
  857. }
  858. /**
  859. * Function VerticalToolbarPane
  860. * Change *this to a vertical toolbar for KiCad.
  861. */
  862. EDA_PANEINFO& VerticalToolbarPane()
  863. {
  864. ToolbarPane();
  865. CloseButton( false );
  866. TopDockable( false );
  867. BottomDockable( false );
  868. //==================== Remove calls below here for movable toolbars //
  869. Gripper( false );
  870. DockFixed( true );
  871. Movable( false );
  872. Resizable( true );
  873. return *this;
  874. }
  875. /**
  876. * Function MessageToolbarPane
  877. * Change *this to a message pane for KiCad.
  878. *
  879. */
  880. EDA_PANEINFO& MessageToolbarPane()
  881. {
  882. Gripper( false );
  883. DockFixed( true );
  884. Movable( false );
  885. Floatable( false );
  886. CloseButton( false );
  887. CaptionVisible( false );
  888. return *this;
  889. }
  890. /**
  891. * Function LayersToolbarPane
  892. * Change *this to a layers toolbar for KiCad.
  893. */
  894. EDA_PANEINFO& LayersToolbarPane()
  895. {
  896. CloseButton( false );
  897. return *this;
  898. }
  899. /**
  900. * Function InfoToolbarPane
  901. * Change *this to a information panel for for KiCad.
  902. *
  903. * Info panes are used for vertical display of information next to the center pane.
  904. * Used in CvPcb and the library viewer primarily.
  905. */
  906. EDA_PANEINFO& InfoToolbarPane()
  907. {
  908. Gripper( false );
  909. CloseButton( false );
  910. CaptionVisible( false );
  911. return *this;
  912. }
  913. /**
  914. * Function ScriptingToolbarPane
  915. * Change *this to a scripting toolbar for KiCad.
  916. */
  917. EDA_PANEINFO& ScriptingToolbarPane()
  918. {
  919. CloseButton( false );
  920. Floatable( true );
  921. Resizable( true );
  922. return *this;
  923. }
  924. };
  925. #endif // WXSTRUCT_H_