KiCad PCB EDA Suite
gerbview_frame.h
Go to the documentation of this file.
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-2019 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 
22 #ifndef WX_GERBER_STRUCT_H
23 #define WX_GERBER_STRUCT_H
24 
25 
26 #include <pgm_base.h>
27 #include <config_params.h>
28 #include <eda_draw_frame.h>
30 #include <gerbview.h>
31 #include <convert_to_biu.h>
32 #include <gbr_layout.h>
33 #include <gbr_screen.h>
34 #include <page_info.h>
35 #include <gbr_display_options.h>
36 #include <colors_design_settings.h>
37 
39 
40 #define NO_AVAILABLE_LAYERS UNDEFINED_LAYER
41 
45 class GERBER_DRAW_ITEM;
46 class GERBER_FILE_IMAGE;
48 class REPORTER;
49 
50 
56 #define GERBVIEW_FRAME_NAME wxT( "GerberFrame" )
57 
58 class GERBVIEW_FRAME : public EDA_DRAW_FRAME // PCB_BASE_FRAME
59 {
61  wxPoint m_grid_origin;
62  PAGE_INFO m_paper; // used only to show paper limits to screen
63 
64 public:
66 
73  void SetLayout( GBR_LAYOUT* aLayout )
74  {
75  delete m_gerberLayout;
76  m_gerberLayout = aLayout;
77  }
78 
80  {
81  wxASSERT( m_gerberLayout );
82  return m_gerberLayout;
83  }
84 
89  {
90  return m_gerberLayout->GetImagesList();
91  }
92 
93  GERBER_FILE_IMAGE* GetGbrImage( int aIdx ) const;
94 
95  unsigned ImagesMaxCount() const;
96 
97 
98  void SetPageSettings( const PAGE_INFO& aPageSettings ) override;
99  const PAGE_INFO& GetPageSettings() const override;
100  const wxSize GetPageSizeIU() const override;
101 
102  const wxPoint& GetAuxOrigin() const override;
103  void SetAuxOrigin( const wxPoint& aPoint ) override;
104 
105  const wxPoint& GetGridOrigin() const override { return m_grid_origin; }
106  void SetGridOrigin( const wxPoint& aPoint ) override { m_grid_origin = aPoint; }
107 
108  const TITLE_BLOCK& GetTitleBlock() const override;
109  void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override;
110 
126  int SelectPCBLayer( int aDefaultLayer, int aOpperLayerCount, bool aNullLayer = false );
127 
129  virtual void SetGridColor( COLOR4D aColor ) override;
130 
131  const BOX2I GetDocumentExtents() const override
132  {
133  wxASSERT( m_gerberLayout );
134  return m_gerberLayout->ViewBBox();
135  }
136 
137 protected:
139 
143 
144  wxString m_lastFileName; // The last filename chosen to be proposed to the user
145 
146 public:
147  wxChoice* m_SelComponentBox; // a choice box to display and highlight component graphic items
148  wxChoice* m_SelNetnameBox; // a choice box to display and highlight netlist graphic items
149  wxChoice* m_SelAperAttributesBox; // a choice box to display aperture attributes and highlight items
150  GBR_LAYER_BOX_SELECTOR* m_SelLayerBox; // The combobox to select the current active graphic layer
151  // (which is drawn on top on the other layers
152  DCODE_SELECTION_BOX* m_DCodeSelector; // a list box to select the dcode Id to highlight.
153  wxTextCtrl* m_TextInfo; // a wxTextCtrl used to display some info about
154  // gerber data (format..)
155 
157 
158 private:
159  // list of PARAM_CFG_xxx to read/write parameters saved in config
161 
162  int m_displayMode; // Gerber images ("layers" in Gerbview) can be drawn:
163  // - in fast mode (write mode) but if there are negative
164  // items only the last image is correctly drawn (no
165  // problem to see only one image or when no negative items)
166  // - in "exact" mode (but slower) in write mode:
167  // last image covers previous images
168  // - in "exact" mode (also slower) in OR mode
169  // (transparency mode)
170  // m_displayMode = 0, 1 or 2
171 
173 
177  void updateDCodeSelectBox();
178  void updateGridSelectBox();
179  void updateZoomSelectBox();
180  void unitsChangeRefresh() override; // See class EDA_DRAW_FRAME
181 
182  // The Tool Framework initalization
183  void setupTools();
184 
187 
196  bool loadListOfGerberAndDrillFiles( const wxString& aPath,
197  const wxArrayString& aFilenameList,
198  const std::vector<int>* aFileType = nullptr );
199 
200 public:
201  GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent );
202  ~GERBVIEW_FRAME();
203 
204  void OnCloseWindow( wxCloseEvent& Event );
205 
206  bool OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl ) override;
207 
208  // Virtual basic functions:
209  void ReCreateHToolbar() override;
210  void ReCreateAuxiliaryToolbar() override;
211 
218  void ReCreateVToolbar() override;
219 
223  void ReCreateOptToolbar() override;
224 
225  void ReCreateMenuBar() override;
226  void OnUpdateSelectZoom( wxUpdateUIEvent& aEvent );
227  double BestZoom() override;
228  void UpdateStatusBar() override;
229 
236  const wxString GetZoomLevelIndicator() const override;
237 
244  int GetDisplayMode() { return m_displayMode; }
245 
252  void SetDisplayMode( int aMode ) { m_displayMode = aMode; }
253 
261  bool IsElementVisible( int aLayerID ) const;
262 
270  void SetElementVisibility( int aLayerID, bool aNewState );
271 
277  void SetGridVisibility( bool aVisible ) override;
278 
284  LSET GetVisibleLayers() const;
285 
291  void SetVisibleLayers( LSET aLayerMask );
292 
299  bool IsLayerVisible( int aLayer ) const;
300 
305  COLOR4D GetVisibleElementColor( int aLayerID );
306 
307  void SetVisibleElementColor( int aLayerID, COLOR4D aColor );
308 
313  COLOR4D GetLayerColor( int aLayer ) const;
314 
319  void SetLayerColor( int aLayer, COLOR4D aColor );
320 
328 
334  void ReFillLayerWidget();
335 
341  void SetActiveLayer( int aLayer, bool doLayerWidgetUpdate = true );
342 
347  int GetActiveLayer();
348 
356  int getNextAvailableLayer( int aLayer = 0 ) const;
357 
358  bool hasAvailableLayers() const
359  {
361  }
362 
371  void syncLayerWidget();
372 
381  void syncLayerBox( bool aRebuildLayerBox = false );
382 
392  void UpdateTitleAndInfo();
393 
399  void DisplayGridMsg();
400 
411 
412  void LoadSettings( wxConfigBase* aCfg ) override;
413  void SaveSettings( wxConfigBase* aCfg ) override;
414 
415  void OnToggleShowLayerManager( wxCommandEvent& aEvent );
416 
417  void ShowChangedLanguage() override;
418 
419  void Process_Special_Functions( wxCommandEvent& event );
420 
422  void OnSelectHighlightChoice( wxCommandEvent& event );
423 
429  void OnSelectActiveDCode( wxCommandEvent& event );
430 
437  void OnSelectActiveLayer( wxCommandEvent& event );
438 
444  void OnShowGerberSourceFile( wxCommandEvent& event );
445 
452  void OnSelectDisplayMode( wxCommandEvent& event );
453 
458  void OnQuit( wxCommandEvent& event );
459 
460  GERBER_DRAW_ITEM* Locate( const wxPoint& aPosition, int typeloc );
461 
462  void OnUpdateDrawMode( wxUpdateUIEvent& aEvent );
463  void OnUpdateSelectDCode( wxUpdateUIEvent& aEvent );
464  void OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent );
465 
466  void Files_io( wxCommandEvent& event );
467 
473  void OnGbrFileHistory( wxCommandEvent& event );
474 
480  void OnDrlFileHistory( wxCommandEvent& event );
481 
487  void OnZipFileHistory( wxCommandEvent& event );
488 
493  void OnJobFileHistory( wxCommandEvent& event );
494 
501  bool unarchiveFiles( const wxString& aFullFileName, REPORTER* aReporter = nullptr );
502 
511  bool LoadGerberFiles( const wxString& aFileName );
512  bool Read_GERBER_File( const wxString& GERBER_FullFileName );
513 
522  bool LoadExcellonFiles( const wxString& aFileName );
523  bool Read_EXCELLON_File( const wxString& aFullFileName );
524 
533  bool LoadZipArchiveFile( const wxString& aFileName );
534 
535 
543  bool LoadGerberJobFile( const wxString& aFileName );
544 
545 
549  void Liste_D_Codes();
550 
551  // PCB handling
552  bool Clear_DrawLayers( bool query );
553  void Erase_Current_DrawLayer( bool query );
554 
556 
561  void UpdateDisplayOptions( const GBR_DISPLAY_OPTIONS& aOptions );
562 
563  // Conversion function
564  void ExportDataInPcbnewFormat( wxCommandEvent& event );
565 
566  /* SaveCopyInUndoList() virtual
567  * currently: do nothing in GerbView.
568  */
570  UNDO_REDO_T aTypeCommand = UR_UNSPECIFIED,
571  const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) { }
572 
582  void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
583  UNDO_REDO_T aTypeCommand,
584  const wxPoint& aTransformPoint = wxPoint( 0, 0 ) )
585  {
586  // currently: do nothing in GerbView.
587  }
588 
590  void ActivateGalCanvas() override;
591 
595  void InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) override;
596 
600  void CommonSettingsChanged( bool aEnvVarsChanged ) override;
601 
602  void SyncToolbars() override;
603 
604  DECLARE_EVENT_TABLE()
605 };
606 
607 #endif /* WX_GERBER_STRUCT_H */
Class GBR_DISPLAY_OPTIONS is a helper class to handle display options (filling modes and afew other o...
Class GBR_LAYOUT holds list of GERBER_DRAW_ITEM currently loaded.
Definition: gbr_layout.h:53
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock) override
void OnSelectHighlightChoice(wxCommandEvent &event)
Handles the changing of the highlighted component/net/attribute.
Class CLASS_GBR_LAYOUT to handle info to draw loaded Gerber images and page frame reference.
A list of parameters type.
wxString m_lastFileName
void SetVisibleElementColor(int aLayerID, COLOR4D aColor)
void SortLayersByX2Attributes()
bool Clear_DrawLayers(bool query)
const wxSize GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
void OnUpdateSelectDCode(wxUpdateUIEvent &aEvent)
void Files_io(wxCommandEvent &event)
void UpdateStatusBar() override
Update the status bar information.
COLOR4D GetNegativeItemsColor()
Function GetNegativeItemsColor.
Handle colors used to draw all items or layers.
void OnToggleShowLayerManager(wxCommandEvent &aEvent)
const BOX2I GetDocumentExtents() const override
void syncLayerBox(bool aRebuildLayerBox=false)
Function syncLayerBox updates the currently "selected" layer within m_SelLayerBox The currently activ...
int GetDisplayMode()
Function GetDisplayMode.
void SetAuxOrigin(const wxPoint &aPoint) override
COLOR4D GetVisibleElementColor(int aLayerID)
Function GetVisibleElementColor returns the color of a gerber visible element.
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
const wxPoint & GetAuxOrigin() const override
Return the origin of the axis used for plotting and various exports.
void OnQuit(wxCommandEvent &event)
Function OnQuit called on request of application quit.
FILE_HISTORY m_jobFileHistory
void SetPageSettings(const PAGE_INFO &aPageSettings) override
const TITLE_BLOCK & GetTitleBlock() const override
GERBER_LAYER_WIDGET * m_LayersManager
UNDO_REDO_T
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl) override
Function OpenProjectFiles is abstract, and opens a project or set of files given by aFileList.
bool Read_GERBER_File(const wxString &GERBER_FullFileName)
Definition: readgerb.cpp:40
Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters ...
void SetActiveLayer(int aLayer, bool doLayerWidgetUpdate=true)
Function SetActiveLayer will change the currently active layer to aLayer and also update the GERBER_L...
void OnGbrFileHistory(wxCommandEvent &event)
Function OnGbrFileHistory deletes the current data and loads a Gerber file selected from history list...
bool loadListOfGerberAndDrillFiles(const wxString &aPath, const wxArrayString &aFilenameList, const std::vector< int > *aFileType=nullptr)
Loads a list of Gerber and NC drill files and updates the view based on them.
GBR_LAYER_BOX_SELECTOR * m_SelLayerBox
void SaveCopyInUndoList(GERBER_DRAW_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand=UR_UNSPECIFIED, const wxPoint &aTransformPoint=wxPoint(0, 0))
The common library.
void OnUpdateLayerSelectBox(wxUpdateUIEvent &aEvent)
void updateNetnameListSelectBox()
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
void Erase_Current_DrawLayer(bool query)
The base class for create windows for drawing purpose.
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
int GetActiveLayer()
Function SetActiveLayer returns the active layer.
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot,...
Definition: title_block.h:40
void OnSelectActiveDCode(wxCommandEvent &event)
Function OnSelectActiveDCode Selects the active DCode for the current active layer.
wxChoice * m_SelNetnameBox
void SaveSettings(wxConfigBase *aCfg) override
Saves common frame parameters to a configuration data file.
void ActivateGalCanvas() override
void SetGridVisibility(bool aVisible) override
Function SetGridVisibility(), virtual from EDA_DRAW_FRAME It may be overloaded by derived classes.
GERBVIEW_FRAME(KIWAY *aKiway, wxWindow *aParent)
void OnSelectDisplayMode(wxCommandEvent &event)
Function OnSelectDisplayMode called on a display mode selection Mode selection can be fast display,...
void ReCreateHToolbar() override
bool LoadGerberJobFile(const wxString &aFileName)
Load a Gerber job file, and load gerber files found in job files.
void SetGridOrigin(const wxPoint &aPoint) override
FILE_HISTORY m_zipFileHistory
void updateComponentListSelectBox()
bool hasAvailableLayers() const
COLORS_DESIGN_SETTINGS g_ColorsSettings
void UpdateDisplayOptions(const GBR_DISPLAY_OPTIONS &aOptions)
Updates the display options and refreshes the view as needed.
Class LSET is a set of PCB_LAYER_IDs.
unsigned ImagesMaxCount() const
The max number of file images.
bool unarchiveFiles(const wxString &aFullFileName, REPORTER *aReporter=nullptr)
Extracts gerber and drill files from the zip archive, and load them.
PAGE_INFO m_paper
void ReCreateAuxiliaryToolbar() override
void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
void ReCreateVToolbar() override
Function ReCreateVToolbar creates or updates the right vertical toolbar.
PARAM_CFG_ARRAY m_configSettings
#define NO_AVAILABLE_LAYERS
bool LoadGerberFiles(const wxString &aFileName)
function LoadGerberFiles Load a photoplot (Gerber) file or many files.
void InstallPreferences(PAGED_DIALOG *aParent, PANEL_HOTKEYS_EDITOR *aHotkeysPanel) override
Allows Gerbview to install its preferences panels into the preferences dialog.
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
GERBER_FILE_IMAGE * GetGbrImage(int aIdx) const
bool LoadZipArchiveFile(const wxString &aFileName)
function LoadZipArchiveFileLoadZipArchiveFile Load a zipped archive file.
COLORS_DESIGN_SETTINGS * m_colorsSettings
GBR_DISPLAY_OPTIONS m_DisplayOptions
void applyDisplaySettingsToGAL()
Updates the GAL with display settings changes.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
double BestZoom() override
Return the zoom level which displays the full page on screen.
bool IsElementVisible(int aLayerID) const
Function IsElementVisible tests whether a given element category is visible.
GBR_LAYOUT * m_gerberLayout
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
const wxPoint & GetGridOrigin() const override
Return the absolute coordinates of the origin of the snap grid.
Class GERBER_LAYER_WIDGET is here to implement the abtract functions of LAYER_WIDGET so they may be t...
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
void LoadSettings(wxConfigBase *aCfg) override
Load common frame parameters from a configuration file.
void OnCloseWindow(wxCloseEvent &Event)
FILE_HISTORY m_drillFileHistory
void OnShowGerberSourceFile(wxCommandEvent &event)
Function OnShowGerberSourceFile Call the preferred editor to show (and edit) the gerber source file l...
GERBER_DRAW_ITEM * Locate(const wxPoint &aPosition, int typeloc)
Definition: locate.cpp:43
void Process_Special_Functions(wxCommandEvent &event)
void OnUpdateSelectZoom(wxUpdateUIEvent &aEvent)
GBR_LAYOUT * GetGerberLayout() const
wxTextCtrl * m_TextInfo
DCODE_SELECTION_BOX * m_DCodeSelector
void ExportDataInPcbnewFormat(wxCommandEvent &event)
const PAGE_INFO & GetPageSettings() const override
void OnJobFileHistory(wxCommandEvent &event)
deletes the current data and load a gerber job file selected from the history list.
void updateAperAttributesSelectBox()
wxChoice * m_SelAperAttributesBox
see class PGM_BASE
Board layer functions and definitions.
void SyncToolbars() override
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
PARAM_CFG_ARRAY & GetConfigurationSettings(void)
Function GetConfigurationSettings Populates the GerbView applications settings list.
void OnUpdateDrawMode(wxUpdateUIEvent &aEvent)
void SaveCopyInUndoList(const PICKED_ITEMS_LIST &aItemsList, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0))
Function SaveCopyInUndoList (overloaded).
COLOR4D GetLayerColor(int aLayer) const
Function GetLayerColor gets a layer color for any valid layer.
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Definition: gbr_layout.cpp:44
void DisplayGridMsg()
Function DisplayGridMsg()
void SetLayerColor(int aLayer, COLOR4D aColor)
Function SetLayerColor changes a layer color for any valid layer.
virtual void SetGridColor(COLOR4D aColor) override
wxPoint m_grid_origin
void syncLayerWidget()
Function syncLayerWidget updates the currently "selected" layer within the GERBER_LAYER_WIDGET.
Class COLORS_DESIGN_SETTINGS is a list of color settings for designs in Pcbnew.
wxChoice * m_SelComponentBox
void OnDrlFileHistory(wxCommandEvent &event)
Function OnDrlFileHistory deletes the current data and load a drill file in Excellon format selected ...
bool LoadExcellonFiles(const wxString &aFileName)
function LoadExcellonFiles Load a drill (EXCELLON) file or many files.
void OnZipFileHistory(wxCommandEvent &event)
Function OnZipFileHistory deletes the current data and load a zip archive file selected from the hist...
void SetVisibleLayers(LSET aLayerMask)
Function SetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
bool m_show_layer_manager_tools
void ReCreateMenuBar() override
Recreates the menu bar.
int getNextAvailableLayer(int aLayer=0) const
Function getNextAvailableLayer finds the next empty layer starting at aLayer and returns it to the ca...
virtual const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
void SetLayout(GBR_LAYOUT *aLayout)
Function SetLayout sets the m_gerberLayout member in such as way as to ensure deleting any previous G...
bool IsLayerVisible(int aLayer) const
Function IsLayerVisible tests whether a given layer is visible.
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data.
void Liste_D_Codes()
Set Size Items (Lines, Flashes) from DCodes List.
void SetElementVisibility(int aLayerID, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
void CommonSettingsChanged(bool aEnvVarsChanged) override
Called after the preferences dialog is run.
void ReFillLayerWidget()
Function ReFillLayerWidget changes out all the layers in m_Layers and may be called upon loading new ...
void OnSelectActiveLayer(wxCommandEvent &event)
Function OnSelectActiveLayer Selects the active layer:
void UpdateTitleAndInfo()
Function UpdateTitleAndInfo displays the short filename (if exists) of the selected layer on the capt...
void SetDisplayMode(int aMode)
Function SetDisplayMode.
int SelectPCBLayer(int aDefaultLayer, int aOpperLayerCount, bool aNullLayer=false)
Install the dialog box for layer selection.
const wxString GetZoomLevelIndicator() const override
Function GetZoomLevelIndicator returns a human readable value which can be displayed as zoom level in...
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
bool Read_EXCELLON_File(const wxString &aFullFileName)
void ReCreateOptToolbar() override
Create or update the left vertical toolbar (option toolbar.