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 #include <filehistory.h>
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 <page_info.h>
34 #include <gbr_display_options.h>
35 #include <undo_redo_container.h>
36 
37 #define NO_AVAILABLE_LAYERS UNDEFINED_LAYER
38 
42 class GERBER_DRAW_ITEM;
43 class GERBER_FILE_IMAGE;
45 class REPORTER;
46 class SELECTION;
47 
48 
54 #define GERBVIEW_FRAME_NAME wxT( "GerberFrame" )
55 
56 class GERBVIEW_FRAME : public EDA_DRAW_FRAME // PCB_BASE_FRAME
57 {
61  PAGE_INFO m_paper; // used only to show paper limits to screen
63  wxStaticText* m_cmpText; // a message on the auxiliary toolbar,
64  // relative to the m_SelComponentBox
65  wxStaticText* m_netText; // a message on the auxiliary toolbar,
66  // relative to the m_SelNetnameBox
67  wxStaticText* m_apertText; // a message on the auxiliary toolbar,
68  // relative to the m_SelAperAttributesBox
69  wxStaticText* m_dcodeText; // a message on the auxiliary toolbar,
70  // relative to the m_DCodeSelector
71 
72 public:
74  void SetDisplayOptions( const GBR_DISPLAY_OPTIONS& aOptions ) { m_DisplayOptions = aOptions; }
75 
82  void SetLayout( GBR_LAYOUT* aLayout )
83  {
84  delete m_gerberLayout;
85  m_gerberLayout = aLayout;
86  }
87 
89  {
90  wxASSERT( m_gerberLayout );
91  return m_gerberLayout;
92  }
93 
98  {
99  return m_gerberLayout->GetImagesList();
100  }
101 
102  GERBER_FILE_IMAGE* GetGbrImage( int aIdx ) const;
103 
104  unsigned ImagesMaxCount() const;
105 
106 
107  void SetPageSettings( const PAGE_INFO& aPageSettings ) override;
108  const PAGE_INFO& GetPageSettings() const override;
109  const wxSize GetPageSizeIU() const override;
110 
111  const wxPoint& GetGridOrigin() const override { return m_grid_origin; }
112  void SetGridOrigin( const wxPoint& aPoint ) override { m_grid_origin = aPoint; }
113 
114  const TITLE_BLOCK& GetTitleBlock() const override;
115  void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override;
116 
132  int SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount, wxString aGerberName );
133 
137  COLOR4D GetGridColor() override;
138 
140  virtual void SetGridColor( COLOR4D aColor ) override;
141 
142  const BOX2I GetDocumentExtents() const override
143  {
144  wxASSERT( m_gerberLayout );
145  return m_gerberLayout->ViewBBox();
146  }
147 
148 protected:
150 
154 
155  wxString m_lastFileName; // The last filename chosen to be proposed to the user
156 
157  void setupUIConditions() override;
158 
159 public:
160  wxChoice* m_SelComponentBox; // a choice box to display and highlight component graphic items
161  wxChoice* m_SelNetnameBox; // a choice box to display and highlight netlist graphic items
162  wxChoice* m_SelAperAttributesBox; // a choice box to display aperture attributes and highlight items
163  GBR_LAYER_BOX_SELECTOR* m_SelLayerBox; // The combobox to select the current active graphic layer
164  // (which is drawn on top on the other layers
165  DCODE_SELECTION_BOX* m_DCodeSelector; // a list box to select the dcode Id to highlight.
166  wxTextCtrl* m_TextInfo; // a wxTextCtrl used to display some info about
167  // gerber data (format..)
168 
169 private:
170  int m_displayMode; // Gerber images ("layers" in Gerbview) can be drawn:
171  // - in fast mode (write mode) but if there are negative
172  // items only the last image is correctly drawn (no
173  // problem to see only one image or when no negative items)
174  // - in "exact" mode (but slower) in write mode:
175  // last image covers previous images
176  // - in "exact" mode (also slower) in OR mode
177  // (transparency mode)
178  // m_displayMode = 0, 1 or 2
179 
181 
185  void updateDCodeSelectBox();
186  void unitsChangeRefresh() override; // See class EDA_DRAW_FRAME
187 
188  void OnClearJobFileHistory( wxCommandEvent& aEvent );
189  void OnClearZipFileHistory( wxCommandEvent& aEvent );
190  void OnClearDrlFileHistory( wxCommandEvent& aEvent );
191  void OnClearGbrFileHistory( wxCommandEvent& aEvent );
192 
193  // The Tool Framework initalization
194  void setupTools();
195 
198 
207  bool loadListOfGerberAndDrillFiles( const wxString& aPath,
208  const wxArrayString& aFilenameList,
209  const std::vector<int>* aFileType = nullptr );
210 
211 public:
212  GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent );
213  ~GERBVIEW_FRAME();
214 
215  void doCloseWindow() override;
216 
217  bool OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl ) override;
218 
219  // Virtual basic functions:
220  void ReCreateHToolbar() override;
221  void ReCreateAuxiliaryToolbar() override;
222 
227  void ReCreateVToolbar() override;
228 
232  void ReCreateOptToolbar() override;
233 
234  void ReCreateMenuBar() override;
235  void UpdateStatusBar() override;
236 
243  int GetDisplayMode() { return m_displayMode; }
244 
251  void SetDisplayMode( int aMode ) { m_displayMode = aMode; }
252 
260  bool IsElementVisible( int aLayerID ) const;
261 
269  void SetElementVisibility( int aLayerID, bool aNewState );
270 
276  void SetGridVisibility( bool aVisible ) override;
277 
283  LSET GetVisibleLayers() const;
284 
290  void SetVisibleLayers( LSET aLayerMask );
291 
298  bool IsLayerVisible( int aLayer ) const;
299 
304  COLOR4D GetVisibleElementColor( int aLayerID );
305 
306  void SetVisibleElementColor( int aLayerID, COLOR4D aColor );
307 
308  COLOR4D GetLayerColor( int aLayer ) const;
309  void SetLayerColor( int aLayer, COLOR4D aColor );
310 
318 
323  void ReFillLayerWidget();
324 
329  void SetActiveLayer( int aLayer, bool doLayerWidgetUpdate = true );
330 
335  int GetActiveLayer() const { return m_activeLayer; }
336 
344  int getNextAvailableLayer( int aLayer = 0 ) const;
345 
354  void syncLayerWidget();
355 
363  void syncLayerBox( bool aRebuildLayerBox = false );
364 
373  void UpdateTitleAndInfo();
374 
380  void DisplayGridMsg() override;
381 
382  void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
383 
384  void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
385 
386  void OnToggleShowLayerManager( wxCommandEvent& aEvent );
387 
388  void ShowChangedLanguage() override;
389 
390  void Process_Special_Functions( wxCommandEvent& event );
391 
393  void OnSelectHighlightChoice( wxCommandEvent& event );
394 
400  void OnSelectActiveDCode( wxCommandEvent& event );
401 
408  void OnSelectActiveLayer( wxCommandEvent& event );
409 
415  void OnShowGerberSourceFile( wxCommandEvent& event );
416 
423  void OnSelectDisplayMode( wxCommandEvent& event );
424 
429  void OnQuit( wxCommandEvent& event );
430 
431  void OnUpdateDrawMode( wxUpdateUIEvent& aEvent );
432  void OnUpdateSelectDCode( wxUpdateUIEvent& aEvent );
433  void OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent );
434 
435  void Files_io( wxCommandEvent& event );
436 
442  void OnGbrFileHistory( wxCommandEvent& event );
443 
449  void OnDrlFileHistory( wxCommandEvent& event );
450 
456  void OnZipFileHistory( wxCommandEvent& event );
457 
462  void OnJobFileHistory( wxCommandEvent& event );
463 
470  bool unarchiveFiles( const wxString& aFullFileName, REPORTER* aReporter = nullptr );
471 
480  bool LoadGerberFiles( const wxString& aFileName );
481  bool Read_GERBER_File( const wxString& GERBER_FullFileName );
482 
491  bool LoadExcellonFiles( const wxString& aFileName );
492  bool Read_EXCELLON_File( const wxString& aFullFileName );
493 
502  bool LoadZipArchiveFile( const wxString& aFileName );
503 
504 
512  bool LoadGerberJobFile( const wxString& aFileName );
513 
514 
518  void Liste_D_Codes();
519 
520  // PCB handling
521  bool Clear_DrawLayers( bool query );
522  void Erase_Current_DrawLayer( bool query );
523 
525 
530  void UpdateDisplayOptions( const GBR_DISPLAY_OPTIONS& aOptions );
531 
532  // Conversion function
533  void ExportDataInPcbnewFormat( wxCommandEvent& event );
534 
535  /* SaveCopyInUndoList() virtual
536  * currently: do nothing in GerbView.
537  */
539  UNDO_REDO aTypeCommand = UNDO_REDO::UNSPECIFIED,
540  const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) { }
541 
551  void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
552  UNDO_REDO aTypeCommand,
553  const wxPoint& aTransformPoint = wxPoint( 0, 0 ) )
554  {
555  // currently: do nothing in GerbView.
556  }
557 
559  void ActivateGalCanvas() override;
560 
564  void InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) override;
565 
569  void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
570 
571  SELECTION& GetCurrentSelection() override;
572 
573  DECLARE_EVENT_TABLE()
574 };
575 
576 #endif /* WX_GERBER_STRUCT_H */
Class GBR_DISPLAY_OPTIONS is a helper class to handle display options (filling modes and afew other o...
GBR_LAYOUT holds list of GERBER_DRAW_ITEM currently loaded.
Definition: gbr_layout.h:47
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.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
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 setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
void Files_io(wxCommandEvent &event)
void UpdateStatusBar() override
Update the status bar information.
COLOR4D GetNegativeItemsColor()
Function GetNegativeItemsColor.
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.
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...
void OnQuit(wxCommandEvent &event)
Function OnQuit called on request of application quit.
void OnClearDrlFileHistory(wxCommandEvent &aEvent)
FILE_HISTORY m_jobFileHistory
void SetPageSettings(const PAGE_INFO &aPageSettings) override
const TITLE_BLOCK & GetTitleBlock() const override
void SaveCopyInUndoList(const PICKED_ITEMS_LIST &aItemsList, UNDO_REDO aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0))
Function SaveCopyInUndoList (overloaded).
GERBER_LAYER_WIDGET * m_LayersManager
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
GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters (TODO:...
void SaveCopyInUndoList(GERBER_DRAW_ITEM *aItemToCopy, UNDO_REDO aTypeCommand=UNDO_REDO::UNSPECIFIED, const wxPoint &aTransformPoint=wxPoint(0, 0))
void SetActiveLayer(int aLayer, bool doLayerWidgetUpdate=true)
Function SetActiveLayer will change the currently active layer to aLayer and update the GERBER_LAYER_...
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
const GBR_DISPLAY_OPTIONS & GetDisplayOptions() const
void OnUpdateLayerSelectBox(wxUpdateUIEvent &aEvent)
void updateNetnameListSelectBox()
REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: filehistory.h:42
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...
void OnClearZipFileHistory(wxCommandEvent &aEvent)
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
Definition: title_block.h:40
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
void OnSelectActiveDCode(wxCommandEvent &event)
Function OnSelectActiveDCode Selects the active DCode for the current active layer.
wxChoice * m_SelNetnameBox
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 OnClearJobFileHistory(wxCommandEvent &aEvent)
void SetGridOrigin(const wxPoint &aPoint) override
FILE_HISTORY m_zipFileHistory
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Called after the preferences dialog is run.
void updateComponentListSelectBox()
void SetDisplayOptions(const GBR_DISPLAY_OPTIONS &aOptions)
void UpdateDisplayOptions(const GBR_DISPLAY_OPTIONS &aOptions)
Updates the display options and refreshes the view as needed.
LSET is a set of PCB_LAYER_IDs.
unsigned ImagesMaxCount() const
The max number of file images.
COLOR4D GetGridColor() override
bool unarchiveFiles(const wxString &aFullFileName, REPORTER *aReporter=nullptr)
Extracts gerber and drill files from the zip archive, and load them.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
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.
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.
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
GERBER_FILE_IMAGE * GetGbrImage(int aIdx) const
bool LoadZipArchiveFile(const wxString &aFileName)
function LoadZipArchiveFileLoadZipArchiveFile Load a zipped archive file.
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.
bool IsElementVisible(int aLayerID) const
Function IsElementVisible tests whether a given element category is visible.
GBR_LAYOUT * m_gerberLayout
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
void OnClearGbrFileHistory(wxCommandEvent &aEvent)
const wxPoint & GetGridOrigin() const override
Return the absolute coordinates of the origin of the snap grid.
GERBER_LAYER_WIDGET is here to implement the abtract functions of LAYER_WIDGET so they may be tied in...
PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
void doCloseWindow() override
FILE_HISTORY m_drillFileHistory
void OnShowGerberSourceFile(wxCommandEvent &event)
Function OnShowGerberSourceFile Call the preferred editor to show (and edit) the gerber source file l...
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void Process_Special_Functions(wxCommandEvent &event)
GBR_LAYOUT * GetGerberLayout() const
wxTextCtrl * m_TextInfo
DCODE_SELECTION_BOX * m_DCodeSelector
void DisplayGridMsg() override
Function DisplayGridMsg()
void ExportDataInPcbnewFormat(wxCommandEvent &event)
const PAGE_INFO & GetPageSettings() const override
wxStaticText * m_cmpText
int GetActiveLayer() const
Function SetActiveLayer returns the active layer.
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.
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
void OnUpdateDrawMode(wxUpdateUIEvent &aEvent)
COLOR4D GetLayerColor(int aLayer) const
int SelectPCBLayer(int aDefaultLayer, int aCopperLayerCount, wxString aGerberName)
Install the dialog box for layer selection.
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Definition: gbr_layout.cpp:44
void SetLayerColor(int aLayer, COLOR4D aColor)
wxStaticText * m_dcodeText
virtual void SetGridColor(COLOR4D aColor) override
wxPoint m_grid_origin
void syncLayerWidget()
Function syncLayerWidget updates the currently "selected" layer within the GERBER_LAYER_WIDGET.
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...
wxStaticText * m_netText
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.
wxStaticText * m_apertText
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 ReFillLayerWidget()
Function ReFillLayerWidget changes out all the layers in m_Layers; called upon loading new gerber fil...
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.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99
bool Read_EXCELLON_File(const wxString &aFullFileName)
void ReCreateOptToolbar() override
Create or update the left vertical toolbar (option toolbar)