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.

439 lines
15 KiB

16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
14 years ago
16 years ago
16 years ago
16 years ago
16 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
16 years ago
16 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
14 years ago
14 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file pcb_base_frame.h
  27. * @brief Classes used in Pcbnew, CvPcb and GerbView.
  28. */
  29. #ifndef PCB_BASE_FRAME_H
  30. #define PCB_BASE_FRAME_H
  31. #include <base_struct.h>
  32. #include <class_board.h>
  33. #include <eda_draw_frame.h>
  34. #include <eda_text.h> // EDA_DRAW_MODE_T
  35. #include <lib_id.h>
  36. #include <pcb_display_options.h>
  37. #include <pcb_draw_panel_gal.h>
  38. #include <pcb_origin_transforms.h>
  39. #include <pcb_screen.h>
  40. #include <richio.h>
  41. #include <vector>
  42. /* Forward declarations of classes. */
  43. class APP_SETTINGS_BASE;
  44. class BOARD;
  45. class BOARD_CONNECTED_ITEM;
  46. class COLOR_SETTINGS;
  47. class MODULE;
  48. class TRACK;
  49. class D_PAD;
  50. class TEXTE_MODULE;
  51. class EDA_3D_VIEWER;
  52. class GENERAL_COLLECTOR;
  53. class GENERAL_COLLECTORS_GUIDE;
  54. class BOARD_DESIGN_SETTINGS;
  55. class ZONE_SETTINGS;
  56. class PCB_PLOT_PARAMS;
  57. class FP_LIB_TABLE;
  58. class PCBNEW_SETTINGS;
  59. class FOOTPRINT_EDITOR_SETTINGS;
  60. struct MAGNETIC_SETTINGS;
  61. wxDECLARE_EVENT( BOARD_CHANGED, wxCommandEvent );
  62. /**
  63. * PCB_BASE_FRAME
  64. * basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
  65. */
  66. class PCB_BASE_FRAME : public EDA_DRAW_FRAME
  67. {
  68. protected:
  69. BOARD* m_pcb;
  70. PCB_DISPLAY_OPTIONS m_displayOptions;
  71. PCB_ORIGIN_TRANSFORMS m_originTransforms;
  72. PCBNEW_SETTINGS* m_settings; // No ownership, just a shortcut
  73. virtual void unitsChangeRefresh() override;
  74. /**
  75. * Function loadFootprint
  76. * attempts to load \a aFootprintId from the footprint library table.
  77. *
  78. * @param aFootprintId is the #LIB_ID of component footprint to load.
  79. * @return the #MODULE if found or NULL if \a aFootprintId not found in any of the
  80. * libraries in the table returned from #Prj().PcbFootprintLibs().
  81. * @throw IO_ERROR if an I/O error occurs or a #PARSE_ERROR if a file parsing error
  82. * occurs while reading footprint library files.
  83. */
  84. MODULE* loadFootprint( const LIB_ID& aFootprintId );
  85. public:
  86. PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
  87. const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
  88. long aStyle, const wxString& aFrameName );
  89. ~PCB_BASE_FRAME();
  90. /**
  91. * @return a reference to the child 3D viewer frame, when exists, or NULL
  92. */
  93. EDA_3D_VIEWER* Get3DViewerFrame();
  94. /**
  95. * Update the 3D view, if the viewer is opened by this frame
  96. * @param aTitle = the new title of the 3D frame, or nullptr
  97. * to do not change the frame title
  98. * @return false if the 3D view cannot be updated (because the
  99. * owner of the viewer is not this frame)
  100. */
  101. virtual void Update3DView( bool aForceReload, const wxString* aTitle = nullptr );
  102. /**
  103. * Request a redraw of 3D-Viewer canvas
  104. */
  105. void Redraw3Dview();
  106. /**
  107. * Function LoadFootprint
  108. * attempts to load \a aFootprintId from the footprint library table.
  109. *
  110. * @param aFootprintId is the #LIB_ID of component footprint to load.
  111. * @return the #MODULE if found or NULL if \a aFootprintId not found in any of the
  112. * libraries in table returned from #Prj().PcbFootprintLibs().
  113. */
  114. MODULE* LoadFootprint( const LIB_ID& aFootprintId );
  115. /**
  116. * Function GetBoardBoundingBox
  117. * calculates the bounding box containing all board items (or board edge segments).
  118. * @param aBoardEdgesOnly is true if we are interested in board edge segments only.
  119. * @return EDA_RECT - the board's bounding box
  120. */
  121. EDA_RECT GetBoardBoundingBox( bool aBoardEdgesOnly = false ) const;
  122. const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override
  123. {
  124. /* "Zoom to Fit" calls this with "aIncludeAllVisible" as true. Since that
  125. * feature always ignored the page and border, this function returns a bbox
  126. * without them as well when passed true. This technically is not all things
  127. * visible, but it keeps behavior consistent.
  128. *
  129. * When passed false, this function returns a bbox of just the board edge.
  130. * This allows things like fabrication text or anything else outside the board
  131. * edge to be ignored, and just zooms up to the board itself.
  132. *
  133. * Calling "GetBoardBoundingBox(true)" when edge cuts are turned off will return bbox of
  134. * entire page and border, so we make sure to do "GetBoardBoundingBox(false)" instead.
  135. */
  136. if( aIncludeAllVisible || ( !aIncludeAllVisible && !m_pcb->IsLayerVisible( Edge_Cuts ) ) )
  137. return GetBoardBoundingBox( false );
  138. else
  139. return GetBoardBoundingBox( true );
  140. }
  141. virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) override;
  142. const PAGE_INFO& GetPageSettings() const override;
  143. const wxSize GetPageSizeIU() const override;
  144. const wxPoint& GetGridOrigin() const override;
  145. void SetGridOrigin( const wxPoint& aPoint ) override;
  146. const wxPoint& GetAuxOrigin() const;
  147. const wxPoint GetUserOrigin() const;
  148. /**
  149. * Return a reference to the default ORIGIN_TRANSFORMS object
  150. */
  151. ORIGIN_TRANSFORMS& GetOriginTransforms() override;
  152. const TITLE_BLOCK& GetTitleBlock() const override;
  153. void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override;
  154. /**
  155. * Returns the BOARD_DESIGN_SETTINGS for the open project
  156. * Overloaded in FOOTPRINT_EDIT_FRAME.
  157. */
  158. virtual BOARD_DESIGN_SETTINGS& GetDesignSettings() const;
  159. /**
  160. * Helper to retrieve the current color settings
  161. * @return a pointer to the active COLOR_SETTINGS
  162. */
  163. virtual COLOR_SETTINGS* GetColorSettings() override
  164. {
  165. wxFAIL_MSG( "Color settings requested for a PCB_BASE_FRAME that does not override!" );
  166. return nullptr;
  167. }
  168. PCBNEW_SETTINGS& Settings() { return *m_settings; }
  169. void SetDrawBgColor( COLOR4D aColor ) override;
  170. /**
  171. * Function GetDisplayOptions
  172. * Display options control the way tracks, vias, outlines and other things are shown
  173. * (for instance solid or sketch mode)
  174. */
  175. const PCB_DISPLAY_OPTIONS& GetDisplayOptions() const { return m_displayOptions; }
  176. void SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions );
  177. const ZONE_SETTINGS& GetZoneSettings() const;
  178. void SetZoneSettings( const ZONE_SETTINGS& aSettings );
  179. /**
  180. * Function GetPlotSettings
  181. * returns the PCB_PLOT_PARAMS for the BOARD owned by this frame.
  182. * Overloaded in FOOTPRINT_EDIT_FRAME.
  183. */
  184. virtual const PCB_PLOT_PARAMS& GetPlotSettings() const;
  185. virtual void SetPlotSettings( const PCB_PLOT_PARAMS& aSettings );
  186. /**
  187. * Function SetBoard
  188. * sets the m_Pcb member in such as way as to ensure deleting any previous
  189. * BOARD.
  190. * @param aBoard The BOARD to put into the frame.
  191. */
  192. virtual void SetBoard( BOARD* aBoard );
  193. BOARD* GetBoard() const
  194. {
  195. wxASSERT( m_pcb );
  196. return m_pcb;
  197. }
  198. /**
  199. * Function GetModel()
  200. * @return the primary data model.
  201. */
  202. virtual BOARD_ITEM_CONTAINER* GetModel() const = 0;
  203. EDA_ITEM* GetItem( const KIID& aId ) override;
  204. void FocusOnItem( BOARD_ITEM* aItem );
  205. // General
  206. virtual void ReCreateOptToolbar() override { }
  207. virtual void ShowChangedLanguage() override;
  208. virtual void ReCreateMenuBar() override;
  209. virtual void UpdateStatusBar() override;
  210. PCB_SCREEN* GetScreen() const override { return (PCB_SCREEN*) EDA_DRAW_FRAME::GetScreen(); }
  211. /**
  212. * Shows the 3D view frame.
  213. * If it does not exist, it is created.
  214. * If it exists, it is bring to the foreground
  215. */
  216. EDA_3D_VIEWER* CreateAndShow3D_Frame();
  217. /**
  218. * Function GetCollectorsGuide
  219. * @return GENERAL_COLLECTORS_GUIDE - that considers the global configuration options.
  220. */
  221. GENERAL_COLLECTORS_GUIDE GetCollectorsGuide();
  222. /**
  223. * Function SelectLibrary
  224. * puts up a dialog and allows the user to pick a library, for unspecified use.
  225. *
  226. * @param aNicknameExisting is the current choice to highlight
  227. * @return wxString - the library or wxEmptyString on abort.
  228. */
  229. wxString SelectLibrary( const wxString& aNicknameExisting );
  230. /**
  231. * Function GetFootprintFromBoardByReference
  232. * @return a reference to the footprint found by its refence on the curent board. The
  233. * reference is entered by the user from a dialog (by awxTextCtlr, or a list of
  234. * available references)
  235. */
  236. MODULE* GetFootprintFromBoardByReference();
  237. /**
  238. * Function OnModify
  239. * Must be called after a change in order to set the "modify" flag of the current screen
  240. * and update the date in frame reference.
  241. * Do not forget to call this basic OnModify function to update info in derived OnModify
  242. * functions.
  243. */
  244. virtual void OnModify();
  245. // Modules (footprints)
  246. /**
  247. * Function CreateNewModule
  248. * Creates a new module or footprint, at position 0,0
  249. * The new module contains only 2 texts: a reference and a value:
  250. * Reference = REF**
  251. * Value = "VAL**" or Footprint name in lib
  252. * Note: they are dummy texts, which will be replaced by the actual texts
  253. * when the fooprint is placed on a board and a netlist is read
  254. * @param aModuleName = name of the new footprint in library
  255. * @return a reference to the new module
  256. */
  257. MODULE* CreateNewModule( const wxString& aModuleName );
  258. /**
  259. * Function PlaceModule
  260. * places \a aModule at the current cursor position and updates module coordinates
  261. * with the new position.
  262. *
  263. * @param aModule A MODULE object point of the module to be placed.
  264. * @param aRecreateRatsnest A bool true redraws the module rats nest.
  265. */
  266. void PlaceModule( MODULE* aModule, bool aRecreateRatsnest = true );
  267. void InstallPadOptionsFrame( D_PAD* pad );
  268. /**
  269. * Function SelectFootprintFromLibTree
  270. * opens a dialog to select a footprint.
  271. *
  272. * @param aPreslect = if valid, the LIB_ID to select (otherwise the global history is used)
  273. */
  274. MODULE* SelectFootprintFromLibTree( LIB_ID aPreselect = LIB_ID() );
  275. /**
  276. * Adds the given module to the board.
  277. * @param module
  278. * @param aDC (can be NULL ) = the current Device Context, to draw the new footprint
  279. */
  280. virtual void AddModuleToBoard( MODULE* module );
  281. /**
  282. * Function SelectFootprintFromLibBrowser
  283. * launches the footprint viewer to select the name of a footprint to load.
  284. *
  285. * @return the selected footprint name or an empty string if no selection was made.
  286. */
  287. wxString SelectFootprintFromLibBrowser();
  288. /**
  289. * Function Compile_Ratsnest
  290. * Create the entire board ratsnest.
  291. * Must be called after a board change (changes for
  292. * pads, footprints or a read netlist ).
  293. * @param aDC = the current device context (can be NULL)
  294. * @param aDisplayStatus : if true, display the computation results
  295. */
  296. void Compile_Ratsnest( bool aDisplayStatus );
  297. /* Functions relative to Undo/redo commands: */
  298. /**
  299. * Function SaveCopyInUndoList (virtual pure)
  300. * Creates a new entry in undo list of commands.
  301. * add a picker to handle aItemToCopy
  302. * @param aItemToCopy = the board item modified by the command to undo
  303. * @param aTypeCommand = command type (see enum UNDO_REDO)
  304. * @param aTransformPoint = the reference point of the transformation, for
  305. * commands like move
  306. */
  307. virtual void SaveCopyInUndoList( EDA_ITEM* aItemToCopy, UNDO_REDO aTypeCommand,
  308. const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) = 0;
  309. /**
  310. * Function SaveCopyInUndoList (virtual pure, overloaded).
  311. * Creates a new entry in undo list of commands.
  312. * add a list of pickers to handle a list of items
  313. * @param aItemsList = the list of items modified by the command to undo
  314. * @param aTypeCommand = command type (see enum UNDO_REDO)
  315. * @param aTransformPoint = the reference point of the transformation,
  316. * for commands like move
  317. */
  318. virtual void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, UNDO_REDO aTypeCommand,
  319. const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) = 0;
  320. /** Install the dialog box for layer selection
  321. * @param aDefaultLayer = Preselection (NB_PCB_LAYERS for "(Deselect)" layer)
  322. * @param aNotAllowedLayersMask = a layer mask for not allowed layers
  323. * (= 0 to show all layers in use)
  324. * @param aDlgPosition = position of dialog ( defualt = centered)
  325. * @return the selected layer id
  326. */
  327. PCB_LAYER_ID SelectLayer( PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask = LSET(),
  328. wxPoint aDlgPosition = wxDefaultPosition );
  329. virtual void SwitchLayer( wxDC* DC, PCB_LAYER_ID layer );
  330. virtual void SetActiveLayer( PCB_LAYER_ID aLayer )
  331. {
  332. GetScreen()->m_Active_Layer = aLayer;
  333. }
  334. virtual PCB_LAYER_ID GetActiveLayer() const
  335. {
  336. return GetScreen()->m_Active_Layer;
  337. }
  338. int GetSeverity( int aErrorCode ) const override;
  339. virtual void OnDisplayOptionsChanged() {}
  340. void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
  341. void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
  342. PCBNEW_SETTINGS* GetPcbNewSettings();
  343. FOOTPRINT_EDITOR_SETTINGS* GetFootprintEditorSettings();
  344. virtual MAGNETIC_SETTINGS* GetMagneticItemsSettings();
  345. void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
  346. virtual void OnUpdateLayerAlpha( wxUpdateUIEvent& aEvent ) {}
  347. /**
  348. * Function DisplayGridMsg()
  349. *
  350. * Display the current grid pane on the status bar.
  351. */
  352. void DisplayGridMsg() override;
  353. PCB_DRAW_PANEL_GAL* GetCanvas() const override;
  354. ///> @copydoc EDA_DRAW_FRAME::UseGalCanvas
  355. virtual void ActivateGalCanvas() override;
  356. /**
  357. * Does nothing. Should be overriden in derived classes which support autozoom.
  358. */
  359. virtual void SetAutoZoom( bool aAutoZoom ) {}
  360. /**
  361. * Always returns false. Should be overriden in derived classes which support autozoom.
  362. */
  363. virtual bool GetAutoZoom() { return false; }
  364. };
  365. #endif // PCB_BASE_FRAME_H