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.

565 lines
20 KiB

* 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
8 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2013 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 modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation, either version 3 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef WX_GERBER_STRUCT_H
  22. #define WX_GERBER_STRUCT_H
  23. #include <filehistory.h>
  24. #include <config_params.h>
  25. #include <eda_draw_frame.h>
  26. #include <layer_ids.h>
  27. #include <gerbview.h>
  28. #include <convert_to_biu.h>
  29. #include <gbr_layout.h>
  30. #include <page_info.h>
  31. #include <gbr_display_options.h>
  32. #define NO_AVAILABLE_LAYERS UNDEFINED_LAYER
  33. class DCODE_SELECTION_BOX;
  34. class GERBER_LAYER_WIDGET;
  35. class GBR_LAYER_BOX_SELECTOR;
  36. class GERBER_DRAW_ITEM;
  37. class GERBER_FILE_IMAGE;
  38. class GERBER_FILE_IMAGE_LIST;
  39. class GERBVIEW_SETTINGS;
  40. class REPORTER;
  41. class SELECTION;
  42. class wxStaticText;
  43. /**
  44. * The main window used in GerbView.
  45. */
  46. #define GERBVIEW_FRAME_NAME wxT( "GerberFrame" )
  47. class GERBVIEW_FRAME : public EDA_DRAW_FRAME
  48. {
  49. public:
  50. GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent );
  51. ~GERBVIEW_FRAME();
  52. void doCloseWindow() override;
  53. bool OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl ) override;
  54. /**
  55. * Load a list of Gerber and NC drill files and updates the view based on them.
  56. *
  57. * @param aPath is the base path for the filenames if they are relative
  58. * @param aFilenameList is a list of filenames to load
  59. * @param aFileType is a list of type of files to load (0 = Gerber, 1 = NC drill, 2 Autodetect)
  60. * Successfully autodetected files will have their type changed
  61. * @return true if every file loaded successfully
  62. */
  63. bool LoadListOfGerberAndDrillFiles( const wxString& aPath, const wxArrayString& aFilenameList,
  64. std::vector<int>* aFileType );
  65. // Virtual basic functions:
  66. void ReCreateHToolbar() override;
  67. void ReCreateAuxiliaryToolbar() override;
  68. /**
  69. * Create or update the right vertical toolbar.
  70. */
  71. void ReCreateVToolbar() override;
  72. /**
  73. * Create or update the left vertical toolbar (option toolbar)
  74. */
  75. void ReCreateOptToolbar() override;
  76. void ReCreateMenuBar() override;
  77. void UpdateStatusBar() override;
  78. void UpdateToolbarControlSizes() override;
  79. GERBVIEW_SETTINGS* gvconfig() const;
  80. /// Updates the GAL with display settings changes
  81. void ApplyDisplaySettingsToGAL();
  82. /**
  83. * @return 0 for fast mode (not fully compatible with negative objects)
  84. * 1 for exact mode, write mode
  85. * 2 for exact mode, OR mode (transparency mode)
  86. */
  87. int GetDisplayMode() { return m_displayMode; }
  88. /**
  89. * @param aMode = 0 for fast mode
  90. * 1 for exact mode, write mode
  91. * 2 for exact mode, OR mode (transparency mode)
  92. */
  93. void SetDisplayMode( int aMode ) { m_displayMode = aMode; }
  94. /**
  95. * Test whether a given element category is visible. Keep this as an inline function.
  96. *
  97. * @param aLayerID is an item id from the enum GERBVIEW_LAYER_ID
  98. * @return bool - true if the element is visible.
  99. */
  100. bool IsElementVisible( int aLayerID ) const;
  101. /**
  102. * Change the visibility of an element category.
  103. *
  104. * @param aItemIdVisible is an item id from the enum GERBVIEW_LAYER_ID
  105. * @param aNewState = The new visibility state of the element category
  106. * (see enum PCB)
  107. */
  108. void SetElementVisibility( int aLayerID, bool aNewState );
  109. /**
  110. * @param aVisible true if the grid must be shown.
  111. */
  112. void SetGridVisibility( bool aVisible ) override;
  113. /**
  114. * A proxy function that calls the correspondent function in m_BoardSettings.
  115. *
  116. * @return #LSET of the visible layers
  117. */
  118. LSET GetVisibleLayers() const;
  119. /**
  120. * A proxy function that calls the correspondent function in m_BoardSettings.
  121. *
  122. * @param aLayerMask The new set of visible layers
  123. */
  124. void SetVisibleLayers( LSET aLayerMask );
  125. /**
  126. * Test whether a given layer is visible.
  127. *
  128. * @param aLayer The layer to be tested (still 0-31!)
  129. * @return true if the layer is visible.
  130. */
  131. bool IsLayerVisible( int aLayer ) const;
  132. /**
  133. * Return the color of a gerber visible element.
  134. */
  135. COLOR4D GetVisibleElementColor( int aLayerID );
  136. void SetVisibleElementColor( int aLayerID, const COLOR4D& aColor );
  137. COLOR4D GetLayerColor( int aLayer ) const;
  138. void SetLayerColor( int aLayer, const COLOR4D& aColor );
  139. /**
  140. * This is usually the background color, but can be another color in order to see
  141. * negative objects.
  142. *
  143. * @return the color of negative items.
  144. */
  145. COLOR4D GetNegativeItemsColor();
  146. /**
  147. * Change out all the layers in m_Layers; called upon loading new gerber files.
  148. */
  149. void ReFillLayerWidget();
  150. /**
  151. * change the currently active layer to \a aLayer and update the #GERBER_LAYER_WIDGET.
  152. */
  153. void SetActiveLayer( int aLayer, bool doLayerWidgetUpdate = true );
  154. /**
  155. * Return the active layer.
  156. */
  157. int GetActiveLayer() const { return m_activeLayer; }
  158. /**
  159. * Find the next empty layer.
  160. *
  161. * If no empty layers are found, #NO_AVAILABLE_LAYERS is return.
  162. *
  163. * @return The first empty layer found or #NO_AVAILABLE_LAYERS.
  164. */
  165. int getNextAvailableLayer() const;
  166. /**
  167. * Update the currently "selected" layer within the #GERBER_LAYER_WIDGET.
  168. * The currently active layer is defined by the return value of GetActiveLayer().
  169. * <p>
  170. * This function cannot be inline without including layer_widget.h in here and we do not
  171. * want to do that.
  172. */
  173. void syncLayerWidget();
  174. /**
  175. * Update the currently "selected" layer within m_SelLayerBox.
  176. * The currently active layer, as defined by the return value of GetActiveLayer().
  177. *
  178. * @param aRebuildLayerBox true to rebuild the layer box of false to just update the selection.
  179. */
  180. void syncLayerBox( bool aRebuildLayerBox = false );
  181. /**
  182. * Display the short filename (if exists) of the selected layer on the caption of the main
  183. * GerbView window and some other parameters.
  184. *
  185. * - Name of the layer (found in the gerber file: LN &ltname&gt command) in the status bar
  186. * - Name of the Image (found in the gerber file: IN &ltname&gt command) in the status bar
  187. * and other data in toolbar
  188. */
  189. void UpdateTitleAndInfo();
  190. /**
  191. * Display the current grid pane on the status bar.
  192. */
  193. void DisplayGridMsg() override;
  194. void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
  195. void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
  196. void ToggleLayerManager();
  197. void ShowChangedLanguage() override;
  198. /// Handles the changing of the highlighted component/net/attribute
  199. void OnSelectHighlightChoice( wxCommandEvent& event );
  200. /**
  201. * Select the active DCode for the current active layer.
  202. * Items using this DCode are highlighted.
  203. */
  204. void OnSelectActiveDCode( wxCommandEvent& event );
  205. /**
  206. * Select the active layer:
  207. * - if a file is loaded, it is loaded in this layer
  208. * - this layer is displayed on top of other layers
  209. */
  210. void OnSelectActiveLayer( wxCommandEvent& event );
  211. /**
  212. * Called on a display mode selection.
  213. *
  214. * Mode selection can be fast display or exact mode with stacked images or with transparency.
  215. */
  216. void OnSelectDisplayMode( wxCommandEvent& event );
  217. /**
  218. * Called on request of application quit.
  219. */
  220. void OnQuit( wxCommandEvent& event );
  221. void OnUpdateDrawMode( wxUpdateUIEvent& aEvent );
  222. void OnUpdateSelectDCode( wxUpdateUIEvent& aEvent );
  223. void OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent );
  224. /**
  225. * Delete the current data and loads a Gerber file selected from history list on current layer.
  226. */
  227. void OnGbrFileHistory( wxCommandEvent& event );
  228. /**
  229. * Delete the current data and load a drill file in Excellon format selected from
  230. * history list on current layer.
  231. */
  232. void OnDrlFileHistory( wxCommandEvent& event );
  233. /**
  234. * Delete the current data and load a zip archive file selected from the
  235. * history list. The archive is expected containing a set of gerber and drill file
  236. */
  237. void OnZipFileHistory( wxCommandEvent& event );
  238. /**
  239. * Delete the current data and load a gerber job file selected from the history list.
  240. */
  241. void OnJobFileHistory( wxCommandEvent& event );
  242. /**
  243. * Extract gerber and drill files from the zip archive, and load them.
  244. *
  245. * @param aFullFileName is the full filename of the zip archive
  246. * @param aReporter a REPORTER to collect warning and error messages
  247. * @return true if OK, false if a file cannot be readable
  248. */
  249. bool unarchiveFiles( const wxString& aFullFileName, REPORTER* aReporter = nullptr );
  250. /**
  251. * Load a given file or selected file(s), if the filename is empty.
  252. *
  253. * @param aFileName - file name with full path to open or empty string.
  254. * if empty string: a dialog will be opened to select one or
  255. * a set of files
  256. * @return true if file was opened successfully.
  257. */
  258. bool LoadAutodetectedFiles( const wxString& aFileName );
  259. /**
  260. * Load a given Gerber file or selected file(s), if the filename is empty.
  261. *
  262. * @param aFileName - file name with full path to open or empty string.
  263. * if empty string: a dialog will be opened to select one or
  264. * a set of files
  265. * @return true if file was opened successfully.
  266. */
  267. bool LoadGerberFiles( const wxString& aFileName );
  268. bool Read_GERBER_File( const wxString& GERBER_FullFileName );
  269. /**
  270. * Load a drill (EXCELLON) file or many files.
  271. *
  272. * @param aFileName - void string or file name with full path to open or empty string to
  273. * open a new file. In this case one one file is loaded
  274. * if empty string: user will be prompted for filename(s)
  275. * @return true if file was opened successfully.
  276. */
  277. bool LoadExcellonFiles( const wxString& aFileName );
  278. bool Read_EXCELLON_File( const wxString& aFullFileName );
  279. /**
  280. * Load a zipped archive file.
  281. *
  282. * @param aFileName - void string or file name with full path to open or empty string to
  283. * open a new file.
  284. * if empty string: user will be prompted for filename(s)
  285. * @return true if file was opened successfully.
  286. */
  287. bool LoadZipArchiveFile( const wxString& aFileName );
  288. /**
  289. * Load a Gerber job file, and load gerber files found in job files.
  290. *
  291. * @param aFileName - void string or file name with full path to open or empty string to
  292. * open a new file.
  293. * if empty string: user will be prompted for filename(s)
  294. * @return true if file(s) was opened successfully.
  295. */
  296. bool LoadGerberJobFile( const wxString& aFileName );
  297. // PCB handling
  298. bool Clear_DrawLayers( bool query );
  299. void Erase_Current_DrawLayer( bool query );
  300. void SortLayersByFileExtension();
  301. void SortLayersByX2Attributes();
  302. /**
  303. * Takes a layer remapping and reorders the layers.
  304. *
  305. * @param remapping A map of old layer number -> new layer number mapping.
  306. * Generally sourced from the SortImagesBy* functions.
  307. */
  308. void RemapLayers( std::unordered_map<int, int> remapping );
  309. /**
  310. * Update each layers' differential option. Needed when diff mode changes or the active layer
  311. * changes (due to changing rendering order) which matters for diff mode but not otherwise.
  312. */
  313. void UpdateDiffLayers();
  314. /*
  315. * Do nothing in GerbView.
  316. */
  317. void SaveCopyInUndoList( GERBER_DRAW_ITEM* aItemToCopy,
  318. UNDO_REDO aTypeCommand = UNDO_REDO::UNSPECIFIED ) { }
  319. /**
  320. * Create a new entry in undo list of commands and add a list of pickers to handle a list
  321. * of items.
  322. *
  323. * @param aItemsList = the list of items modified by the command to undo
  324. * @param aTypeCommand = command type (see enum UNDO_REDO)
  325. * @param aTransformPoint = the reference point of the transformation,
  326. * for commands like move
  327. */
  328. void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
  329. UNDO_REDO aTypeCommand )
  330. {
  331. // currently: do nothing in GerbView.
  332. }
  333. ///< @copydoc EDA_DRAW_FRAME::ActivateGalCanvas
  334. void ActivateGalCanvas() override;
  335. /**
  336. * Called after the preferences dialog is run.
  337. */
  338. void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
  339. SELECTION& GetCurrentSelection() override;
  340. /**
  341. * Set the m_gerberLayout member in such as way as to ensure deleting any previous
  342. * GBR_LAYOUT.
  343. * @param aLayout The GBR_LAYOUT to put into the frame.
  344. */
  345. void SetLayout( GBR_LAYOUT* aLayout )
  346. {
  347. delete m_gerberLayout;
  348. m_gerberLayout = aLayout;
  349. }
  350. GBR_LAYOUT* GetGerberLayout() const
  351. {
  352. wxASSERT( m_gerberLayout );
  353. return m_gerberLayout;
  354. }
  355. /**
  356. * Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data
  357. */
  358. GERBER_FILE_IMAGE_LIST* GetImagesList() const
  359. {
  360. return m_gerberLayout->GetImagesList();
  361. }
  362. GERBER_FILE_IMAGE* GetGbrImage( int aIdx ) const;
  363. unsigned ImagesMaxCount() const; ///< The max number of file images
  364. void SetPageSettings( const PAGE_INFO& aPageSettings ) override;
  365. const PAGE_INFO& GetPageSettings() const override;
  366. const wxSize GetPageSizeIU() const override;
  367. const VECTOR2I& GetGridOrigin() const override { return m_grid_origin; }
  368. void SetGridOrigin( const VECTOR2I& aPoint ) override { m_grid_origin = aPoint; }
  369. const TITLE_BLOCK& GetTitleBlock() const override;
  370. void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override;
  371. /**
  372. * Show the dialog box for layer selection.
  373. *
  374. * Providing the option to also display a "(Deselect)" radiobutton makes the
  375. * GerbView's "Export to Pcbnew" command) more "user friendly",
  376. * by permitting any layer to be "deselected" immediately after its
  377. * corresponding radiobutton has been clicked on. (It would otherwise be
  378. * necessary to first cancel the "Select Layer:" dialog box (invoked after a
  379. * different radiobutton is clicked on) prior to then clicking on the "Deselect"
  380. * button provided within the "Layer selection:" dialog box).
  381. *
  382. * @param aDefaultLayer = Preselection (NB_PCB_LAYERS for "(Deselect)" layer)
  383. * @param aCopperLayerCount = number of copper layers
  384. * @param aGerberName = Name of Gerber file to select KiCad layer for
  385. * @return new layer value (NB_PCB_LAYERS when "(Deselect)" radiobutton selected),
  386. * or -1 if canceled
  387. */
  388. int SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount, const wxString& aGerberName );
  389. /**
  390. * @return the color of the grid
  391. */
  392. COLOR4D GetGridColor() override;
  393. ///< @copydoc EDA_DRAW_FRAME::SetGridColor()
  394. virtual void SetGridColor( const COLOR4D& aColor ) override;
  395. const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override
  396. {
  397. wxASSERT( m_gerberLayout );
  398. return m_gerberLayout->ViewBBox();
  399. }
  400. DECLARE_EVENT_TABLE()
  401. protected:
  402. void setupUIConditions() override;
  403. private:
  404. void updateComponentListSelectBox();
  405. void updateNetnameListSelectBox();
  406. void updateAperAttributesSelectBox();
  407. void updateDCodeSelectBox();
  408. void unitsChangeRefresh() override; // See class EDA_DRAW_FRAME
  409. void OnClearJobFileHistory( wxCommandEvent& aEvent );
  410. void OnClearZipFileHistory( wxCommandEvent& aEvent );
  411. void OnClearDrlFileHistory( wxCommandEvent& aEvent );
  412. void OnClearGbrFileHistory( wxCommandEvent& aEvent );
  413. /**
  414. * Loads the file provided or shows a dialog to get the file(s) from the user.
  415. *
  416. * @param aFileName Name of the file to open. Shows a dialog if not specified.
  417. * @param dialogFiletypes File extensions to pass to the dialog if necessary
  418. * @param dialogTitle Dialog title to use if necessary
  419. * @param filetype Type of file for parsing, 0 = gerber, 1 = drill, 2 = autodetect
  420. *
  421. * @return true if success opening all files, false otherwise
  422. */
  423. bool LoadFileOrShowDialog( const wxString& aFileName, const wxString& dialogFiletypes,
  424. const wxString& dialogTitle, const int filetype );
  425. // The Tool Framework initialization
  426. void setupTools();
  427. public:
  428. wxChoice* m_SelComponentBox; // a choice box to display and highlight component
  429. // graphic items
  430. wxChoice* m_SelNetnameBox; // a choice box to display and highlight netlist
  431. // graphic items
  432. wxChoice* m_SelAperAttributesBox; // a choice box to display aperture attributes and
  433. // highlight items
  434. GBR_LAYER_BOX_SELECTOR* m_SelLayerBox; // The combobox to select the current active
  435. // graphic layer
  436. // (which is drawn on top on the other layers
  437. DCODE_SELECTION_BOX* m_DCodeSelector; // a list box to select the dcode Id to highlight.
  438. wxTextCtrl* m_TextInfo; // a wxTextCtrl used to display some info about
  439. // gerber data (format..)
  440. protected:
  441. GERBER_LAYER_WIDGET* m_LayersManager;
  442. FILE_HISTORY m_zipFileHistory;
  443. FILE_HISTORY m_drillFileHistory;
  444. FILE_HISTORY m_jobFileHistory;
  445. wxString m_lastFileName; // The last filename chosen to be proposed to the
  446. // user.
  447. private:
  448. int m_displayMode; // Gerber images ("layers" in Gerbview) can be drawn:
  449. // - in fast mode (write mode) but if there are negative
  450. // items only the last image is correctly drawn (no
  451. // problem to see only one image or when no negative items)
  452. // - in "exact" mode (but slower) in write mode:
  453. // last image covers previous images
  454. // - in "exact" mode (also slower) in OR mode
  455. // (transparency mode)
  456. // m_displayMode = 0, 1 or 2
  457. bool m_show_layer_manager_tools;
  458. GBR_LAYOUT* m_gerberLayout;
  459. int m_activeLayer;
  460. VECTOR2I m_grid_origin;
  461. PAGE_INFO m_paper; // used only to show paper limits to screen
  462. wxStaticText* m_cmpText; // a message on the auxiliary toolbar,
  463. // relative to the m_SelComponentBox
  464. wxStaticText* m_netText; // a message on the auxiliary toolbar,
  465. // relative to the m_SelNetnameBox
  466. wxStaticText* m_apertText; // a message on the auxiliary toolbar,
  467. // relative to the m_SelAperAttributesBox
  468. wxStaticText* m_dcodeText; // a message on the auxiliary toolbar,
  469. // relative to the m_DCodeSelector
  470. };
  471. #endif /* WX_GERBER_STRUCT_H */