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-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 
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 
53 #define GERBVIEW_FRAME_NAME wxT( "GerberFrame" )
54 
56 {
57 public:
58  GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent );
60 
61  void doCloseWindow() override;
62 
63  bool OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl ) override;
64 
74  bool LoadListOfGerberAndDrillFiles( const wxString& aPath,
75  const wxArrayString& aFilenameList,
76  const std::vector<int>* aFileType = nullptr );
77 
78  // Virtual basic functions:
79  void ReCreateHToolbar() override;
80  void ReCreateAuxiliaryToolbar() override;
81 
85  void ReCreateVToolbar() override;
86 
90  void ReCreateOptToolbar() override;
91 
92  void ReCreateMenuBar() override;
93  void UpdateStatusBar() override;
94  void UpdateToolbarControlSizes() override;
95 
101  int GetDisplayMode() { return m_displayMode; }
102 
108  void SetDisplayMode( int aMode ) { m_displayMode = aMode; }
109 
116  bool IsElementVisible( int aLayerID ) const;
117 
125  void SetElementVisibility( int aLayerID, bool aNewState );
126 
130  void SetGridVisibility( bool aVisible ) override;
131 
137  LSET GetVisibleLayers() const;
138 
144  void SetVisibleLayers( LSET aLayerMask );
145 
152  bool IsLayerVisible( int aLayer ) const;
153 
157  COLOR4D GetVisibleElementColor( int aLayerID );
158 
159  void SetVisibleElementColor( int aLayerID, COLOR4D aColor );
160 
161  COLOR4D GetLayerColor( int aLayer ) const;
162  void SetLayerColor( int aLayer, COLOR4D aColor );
163 
171 
175  void ReFillLayerWidget();
176 
180  void SetActiveLayer( int aLayer, bool doLayerWidgetUpdate = true );
181 
185  int GetActiveLayer() const { return m_activeLayer; }
186 
195  int getNextAvailableLayer( int aLayer = 0 ) const;
196 
204  void syncLayerWidget();
205 
212  void syncLayerBox( bool aRebuildLayerBox = false );
213 
222  void UpdateTitleAndInfo();
223 
227  void DisplayGridMsg() override;
228 
229  void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
230 
231  void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
232 
233  void ToggleLayerManager();
234 
235  void ShowChangedLanguage() override;
236 
238  void OnSelectHighlightChoice( wxCommandEvent& event );
239 
244  void OnSelectActiveDCode( wxCommandEvent& event );
245 
251  void OnSelectActiveLayer( wxCommandEvent& event );
252 
258  void OnSelectDisplayMode( wxCommandEvent& event );
259 
263  void OnQuit( wxCommandEvent& event );
264 
265  void OnUpdateDrawMode( wxUpdateUIEvent& aEvent );
266  void OnUpdateSelectDCode( wxUpdateUIEvent& aEvent );
267  void OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent );
268 
272  void OnGbrFileHistory( wxCommandEvent& event );
273 
278  void OnDrlFileHistory( wxCommandEvent& event );
279 
284  void OnZipFileHistory( wxCommandEvent& event );
285 
289  void OnJobFileHistory( wxCommandEvent& event );
290 
298  bool unarchiveFiles( const wxString& aFullFileName, REPORTER* aReporter = nullptr );
299 
308  bool LoadGerberFiles( const wxString& aFileName );
309  bool Read_GERBER_File( const wxString& GERBER_FullFileName );
310 
319  bool LoadExcellonFiles( const wxString& aFileName );
320  bool Read_EXCELLON_File( const wxString& aFullFileName );
321 
330  bool LoadZipArchiveFile( const wxString& aFileName );
331 
332 
341  bool LoadGerberJobFile( const wxString& aFileName );
342 
343  // PCB handling
344  bool Clear_DrawLayers( bool query );
345  void Erase_Current_DrawLayer( bool query );
346 
348 
354  void UpdateDisplayOptions( const GBR_DISPLAY_OPTIONS& aOptions );
355 
356  /*
357  * Do nothing in GerbView.
358  */
360  UNDO_REDO aTypeCommand = UNDO_REDO::UNSPECIFIED ) { }
361 
371  void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
372  UNDO_REDO aTypeCommand )
373  {
374  // currently: do nothing in GerbView.
375  }
376 
378  void ActivateGalCanvas() override;
379 
383  void InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) override;
384 
388  void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
389 
390  SELECTION& GetCurrentSelection() override;
391 
393  void SetDisplayOptions( const GBR_DISPLAY_OPTIONS& aOptions ) { m_DisplayOptions = aOptions; }
394 
400  void SetLayout( GBR_LAYOUT* aLayout )
401  {
402  delete m_gerberLayout;
403  m_gerberLayout = aLayout;
404  }
405 
407  {
408  wxASSERT( m_gerberLayout );
409  return m_gerberLayout;
410  }
411 
416  {
417  return m_gerberLayout->GetImagesList();
418  }
419 
420  GERBER_FILE_IMAGE* GetGbrImage( int aIdx ) const;
421 
422  unsigned ImagesMaxCount() const;
423 
424 
425  void SetPageSettings( const PAGE_INFO& aPageSettings ) override;
426  const PAGE_INFO& GetPageSettings() const override;
427  const wxSize GetPageSizeIU() const override;
428 
429  const wxPoint& GetGridOrigin() const override { return m_grid_origin; }
430  void SetGridOrigin( const wxPoint& aPoint ) override { m_grid_origin = aPoint; }
431 
432  const TITLE_BLOCK& GetTitleBlock() const override;
433  void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override;
434 
452  int SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount, wxString aGerberName );
453 
457  COLOR4D GetGridColor() override;
458 
460  virtual void SetGridColor( COLOR4D aColor ) override;
461 
462  const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override
463  {
464  wxASSERT( m_gerberLayout );
465  return m_gerberLayout->ViewBBox();
466  }
467 
468  DECLARE_EVENT_TABLE()
469 
470 protected:
471  void setupUIConditions() override;
472 
473 private:
477  void updateDCodeSelectBox();
478  void unitsChangeRefresh() override; // See class EDA_DRAW_FRAME
479 
480  void OnClearJobFileHistory( wxCommandEvent& aEvent );
481  void OnClearZipFileHistory( wxCommandEvent& aEvent );
482  void OnClearDrlFileHistory( wxCommandEvent& aEvent );
483  void OnClearGbrFileHistory( wxCommandEvent& aEvent );
484 
485  // The Tool Framework initialization
486  void setupTools();
487 
490 
491 public:
492  wxChoice* m_SelComponentBox; // a choice box to display and highlight component
493  // graphic items
494  wxChoice* m_SelNetnameBox; // a choice box to display and highlight netlist
495  // graphic items
496  wxChoice* m_SelAperAttributesBox; // a choice box to display aperture attributes and
497  // highlight items
498  GBR_LAYER_BOX_SELECTOR* m_SelLayerBox; // The combobox to select the current active
499  // graphic layer
500  // (which is drawn on top on the other layers
501  DCODE_SELECTION_BOX* m_DCodeSelector; // a list box to select the dcode Id to highlight.
502  wxTextCtrl* m_TextInfo; // a wxTextCtrl used to display some info about
503  // gerber data (format..)
504 
505 protected:
507 
511 
512  wxString m_lastFileName; // The last filename chosen to be proposed to the
513  // user.
514 
515 private:
516  int m_displayMode; // Gerber images ("layers" in Gerbview) can be drawn:
517  // - in fast mode (write mode) but if there are negative
518  // items only the last image is correctly drawn (no
519  // problem to see only one image or when no negative items)
520  // - in "exact" mode (but slower) in write mode:
521  // last image covers previous images
522  // - in "exact" mode (also slower) in OR mode
523  // (transparency mode)
524  // m_displayMode = 0, 1 or 2
525 
527 
530  wxPoint m_grid_origin;
531  PAGE_INFO m_paper; // used only to show paper limits to screen
533  wxStaticText* m_cmpText; // a message on the auxiliary toolbar,
534  // relative to the m_SelComponentBox
535  wxStaticText* m_netText; // a message on the auxiliary toolbar,
536  // relative to the m_SelNetnameBox
537  wxStaticText* m_apertText; // a message on the auxiliary toolbar,
538  // relative to the m_SelAperAttributesBox
539  wxStaticText* m_dcodeText; // a message on the auxiliary toolbar,
540  // relative to the m_DCodeSelector
541 };
542 
543 #endif /* WX_GERBER_STRUCT_H */
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Returns bbox of document with option to not include some items.
Class GBR_DISPLAY_OPTIONS is a helper class to handle display options (filling modes and afew other o...
A list of GERBER_DRAW_ITEM objects currently loaded.
Definition: gbr_layout.h:45
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
Save 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 UpdateStatusBar() override
Update the status bar information.
COLOR4D GetNegativeItemsColor()
This is usually the background color, but can be another color in order to see negative objects.
void syncLayerBox(bool aRebuildLayerBox=false)
Update the currently "selected" layer within m_SelLayerBox.
COLOR4D GetVisibleElementColor(int aLayerID)
Return the color of a gerber visible element.
LSET GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
void OnQuit(wxCommandEvent &event)
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
GERBER_LAYER_WIDGET * m_LayersManager
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl) override
Open a project or set of files given by aFileList.
bool Read_GERBER_File(const wxString &GERBER_FullFileName)
Definition: readgerb.cpp:40
Hold the image data and parameters for one gerber file and layer parameters.
void SetActiveLayer(int aLayer, bool doLayerWidgetUpdate=true)
change the currently active layer to aLayer and update the GERBER_LAYER_WIDGET.
void OnGbrFileHistory(wxCommandEvent &event)
Delete the current data and loads a Gerber file selected from history list on current layer.
GBR_LAYER_BOX_SELECTOR * m_SelLayerBox
const GBR_DISPLAY_OPTIONS & GetDisplayOptions() const
void OnUpdateLayerSelectBox(wxUpdateUIEvent &aEvent)
void updateNetnameListSelectBox()
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)
Hold the information shown in the lower right corner of a plot, printout, or editing view.
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)
Select the active DCode for the current active layer.
void SaveCopyInUndoList(const PICKED_ITEMS_LIST &aItemsList, UNDO_REDO aTypeCommand)
Create a new entry in undo list of commands and add a list of pickers to handle a list of items.
wxChoice * m_SelNetnameBox
void ActivateGalCanvas() override
Use to start up the GAL drawing canvas.
void SetGridVisibility(bool aVisible) override
GERBVIEW_FRAME(KIWAY *aKiway, wxWindow *aParent)
void UpdateToolbarControlSizes() override
Update the sizes of any controls in the toolbars of the frame.
void OnSelectDisplayMode(wxCommandEvent &event)
Called on a display mode selection.
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
void SaveCopyInUndoList(GERBER_DRAW_ITEM *aItemToCopy, UNDO_REDO aTypeCommand=UNDO_REDO::UNSPECIFIED)
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)
Update 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)
Extract 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
Create or update the right vertical toolbar.
bool LoadGerberFiles(const wxString &aFileName)
Load a photoplot (Gerber) file or many files.
void InstallPreferences(PAGED_DIALOG *aParent, PANEL_HOTKEYS_EDITOR *aHotkeysPanel) override
Allow Gerbview to install its preferences panels into the preferences dialog.
bool LoadListOfGerberAndDrillFiles(const wxString &aPath, const wxArrayString &aFilenameList, const std::vector< int > *aFileType=nullptr)
Load a list of Gerber and NC drill files and updates the view based on them.
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
GERBER_FILE_IMAGE * GetGbrImage(int aIdx) const
bool LoadZipArchiveFile(const wxString &aFileName)
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
Test whether a given element category is visible.
GBR_LAYOUT * m_gerberLayout
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
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...
A holder to handle information on schematic or board items.
void doCloseWindow() override
FILE_HISTORY m_drillFileHistory
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
GBR_LAYOUT * GetGerberLayout() const
wxTextCtrl * m_TextInfo
DCODE_SELECTION_BOX * m_DCodeSelector
void DisplayGridMsg() override
Display the current grid pane on the status bar.
const PAGE_INFO & GetPageSettings() const override
wxStaticText * m_cmpText
int GetActiveLayer() const
Return the active layer.
void OnJobFileHistory(wxCommandEvent &event)
Delete 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)
Show the dialog box for layer selection.
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Definition: gbr_layout.cpp:41
void SetLayerColor(int aLayer, COLOR4D aColor)
wxStaticText * m_dcodeText
virtual void SetGridColor(COLOR4D aColor) override
wxPoint m_grid_origin
void syncLayerWidget()
Update the currently "selected" layer within the GERBER_LAYER_WIDGET.
wxChoice * m_SelComponentBox
void OnDrlFileHistory(wxCommandEvent &event)
Delete the current data and load a drill file in Excellon format selected from history list on curren...
bool LoadExcellonFiles(const wxString &aFileName)
Load a drill (EXCELLON) file or many files.
void OnZipFileHistory(wxCommandEvent &event)
Delete the current data and load a zip archive file selected from the history list.
wxStaticText * m_netText
void SetVisibleLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
bool m_show_layer_manager_tools
void ReCreateMenuBar() override
Recreates the menu bar.
wxStaticText * m_apertText
int getNextAvailableLayer(int aLayer=0) const
Find the next empty layer starting at aLayer and returns it to the caller.
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: eda_item.cpp:190
void SetLayout(GBR_LAYOUT *aLayout)
Set the m_gerberLayout member in such as way as to ensure deleting any previous GBR_LAYOUT.
bool IsLayerVisible(int aLayer) const
Test whether a given layer is visible.
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data.
void SetElementVisibility(int aLayerID, bool aNewState)
Change the visibility of an element category.
void ReFillLayerWidget()
Change out all the layers in m_Layers; called upon loading new gerber files.
void OnSelectActiveLayer(wxCommandEvent &event)
Select the active layer:
void UpdateTitleAndInfo()
Display the short filename (if exists) of the selected layer on the caption of the main GerbView wind...
void SetDisplayMode(int aMode)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98
bool Read_EXCELLON_File(const wxString &aFullFileName)
void ReCreateOptToolbar() override
Create or update the left vertical toolbar (option toolbar)