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 <[email protected]>
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 <config_params.h>
27#include <eda_draw_frame.h>
28#include <layer_ids.h>
29#include <gerbview.h>
30#include <gbr_layout.h>
31#include <page_info.h>
32#include <gbr_display_options.h>
33
34#define NO_AVAILABLE_LAYERS UNDEFINED_LAYER
35
43class REPORTER;
44class SELECTION;
45class wxStaticText;
46
47
52#define GERBVIEW_FRAME_NAME wxT( "GerberFrame" )
53
55{
56public:
57 GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent );
59
60 void doCloseWindow() override;
61
62 bool OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl ) override;
63
73 bool LoadListOfGerberAndDrillFiles( const wxString& aPath, const wxArrayString& aFilenameList,
74 std::vector<int>* aFileType );
75
76 // Virtual basic functions:
77 void ReCreateHToolbar() override;
78 void ReCreateAuxiliaryToolbar() override;
79
83 void ReCreateVToolbar() override;
84
88 void ReCreateOptToolbar() override;
89
90 void ReCreateMenuBar() override;
91 void UpdateStatusBar() override;
92 void UpdateToolbarControlSizes() override;
93
95
98
105
111 void SetDisplayMode( int aMode ) { m_displayMode = aMode; }
112
119 bool IsElementVisible( int aLayerID ) const;
120
128 void SetElementVisibility( int aLayerID, bool aNewState );
129
133 void SetGridVisibility( bool aVisible ) override;
134
140 LSET GetVisibleLayers() const;
141
147 void SetVisibleLayers( LSET aLayerMask );
148
155 bool IsLayerVisible( int aLayer ) const;
156
160 COLOR4D GetVisibleElementColor( int aLayerID );
161
162 void SetVisibleElementColor( int aLayerID, const COLOR4D& aColor );
163
164 COLOR4D GetLayerColor( int aLayer ) const;
165 void SetLayerColor( int aLayer, const COLOR4D& aColor );
166
170 void ReFillLayerWidget();
171
175 void SetActiveLayer( int aLayer, bool doLayerWidgetUpdate = true );
176
180 int GetActiveLayer() const { return m_activeLayer; }
181
189 int getNextAvailableLayer() const;
190
198 void syncLayerWidget();
199
206 void syncLayerBox( bool aRebuildLayerBox = false );
207
216 void UpdateTitleAndInfo();
217
221 void DisplayGridMsg() override;
222
223 void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
224 void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
225
226 COLOR_SETTINGS* GetColorSettings( bool aForceRefresh = false ) const override;
227
228 void ToggleLayerManager();
229
230 void ShowChangedLanguage() override;
231
233 void OnSelectHighlightChoice( wxCommandEvent& event );
234
239 void OnSelectActiveDCode( wxCommandEvent& event );
240
246 void OnSelectActiveLayer( wxCommandEvent& event );
247
253 void OnSelectDisplayMode( wxCommandEvent& event );
254
258 void OnQuit( wxCommandEvent& event );
259
260 void OnUpdateDrawMode( wxUpdateUIEvent& aEvent );
261 void OnUpdateSelectDCode( wxUpdateUIEvent& aEvent );
262 void OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent );
263
267 void OnGbrFileHistory( wxCommandEvent& event );
268
273 void OnDrlFileHistory( wxCommandEvent& event );
274
279 void OnZipFileHistory( wxCommandEvent& event );
280
284 void OnJobFileHistory( wxCommandEvent& event );
285
293 bool unarchiveFiles( const wxString& aFullFileName, REPORTER* aReporter = nullptr );
294
303 bool LoadAutodetectedFiles( const wxString& aFileName );
304
313 bool LoadGerberFiles( const wxString& aFileName );
314 bool Read_GERBER_File( const wxString& GERBER_FullFileName );
315
324 bool LoadExcellonFiles( const wxString& aFileName );
325 bool Read_EXCELLON_File( const wxString& aFullFileName );
326
335 bool LoadZipArchiveFile( const wxString& aFileName );
336
337
346 bool LoadGerberJobFile( const wxString& aFileName );
347
348 // PCB handling
349 bool Clear_DrawLayers( bool query );
350 void Erase_Current_DrawLayer( bool query );
351
354
361 void RemapLayers( std::unordered_map<int, int> remapping );
362
367 void UpdateXORLayers();
368
369 /*
370 * Do nothing in GerbView.
371 */
373 UNDO_REDO aTypeCommand = UNDO_REDO::UNSPECIFIED ) { }
374
384 void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
385 UNDO_REDO aTypeCommand )
386 {
387 // currently: do nothing in GerbView.
388 }
389
391 void ActivateGalCanvas() override;
392
396 void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
397
398 SELECTION& GetCurrentSelection() override;
399
405 void SetLayout( GBR_LAYOUT* aLayout )
406 {
407 delete m_gerberLayout;
408 m_gerberLayout = aLayout;
409 }
410
412 {
413 wxASSERT( m_gerberLayout );
414 return m_gerberLayout;
415 }
416
421 {
423 }
424
425 GERBER_FILE_IMAGE* GetGbrImage( int aIdx ) const;
426
427 unsigned ImagesMaxCount() const;
428
429
430 void SetPageSettings( const PAGE_INFO& aPageSettings ) override;
431 const PAGE_INFO& GetPageSettings() const override;
432 const wxSize GetPageSizeIU() const override;
433
434 const VECTOR2I& GetGridOrigin() const override { return m_grid_origin; }
435 void SetGridOrigin( const VECTOR2I& aPoint ) override { m_grid_origin = aPoint; }
436
437 const TITLE_BLOCK& GetTitleBlock() const override;
438 void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override;
439
457 int SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount, const wxString& aGerberName );
458
462 COLOR4D GetGridColor() override;
463
465 virtual void SetGridColor( const COLOR4D& aColor ) override;
466
467 const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override
468 {
469 wxASSERT( m_gerberLayout );
470 return m_gerberLayout->ViewBBox();
471 }
472
473 DECLARE_EVENT_TABLE()
474
475protected:
476 void setupUIConditions() override;
477
478private:
483 void unitsChangeRefresh() override; // See class EDA_DRAW_FRAME
484
485 void OnClearJobFileHistory( wxCommandEvent& aEvent );
486 void OnClearZipFileHistory( wxCommandEvent& aEvent );
487 void OnClearDrlFileHistory( wxCommandEvent& aEvent );
488 void OnClearGbrFileHistory( wxCommandEvent& aEvent );
489
490 void DoWithAcceptedFiles() override;
491
502 bool LoadFileOrShowDialog( const wxString& aFileName, const wxString& dialogFiletypes,
503 const wxString& dialogTitle, const int filetype );
504
505 // The Tool Framework initialization
506 void setupTools();
507
508public:
509 wxChoice* m_SelComponentBox; // a choice box to display and highlight component
510 // graphic items
511 wxChoice* m_SelNetnameBox; // a choice box to display and highlight netlist
512 // graphic items
513 wxChoice* m_SelAperAttributesBox; // a choice box to display aperture attributes and
514 // highlight items
515 GBR_LAYER_BOX_SELECTOR* m_SelLayerBox; // The combobox to select the current active
516 // graphic layer
517 // (which is drawn on top on the other layers
518 DCODE_SELECTION_BOX* m_DCodeSelector; // a list box to select the dcode Id to highlight.
519 wxTextCtrl* m_TextInfo; // a wxTextCtrl used to display some info about
520 // gerber data (format..)
521
523
524protected:
528
529 wxString m_lastFileName; // The last filename chosen to be proposed to the
530 // user.
531
532private:
533 int m_displayMode; // Gerber images ("layers" in Gerbview) can be drawn:
534 // - in fast mode (write mode) but if there are negative
535 // items only the last image is correctly drawn (no
536 // problem to see only one image or when no negative items)
537 // - in "exact" mode (but slower) in write mode:
538 // last image covers previous images
539 // - in "exact" mode (also slower) in OR mode
540 // (transparency mode)
541 // m_displayMode = 0, 1 or 2
542
544
548 PAGE_INFO m_paper; // used only to show paper limits to screen
549 wxStaticText* m_cmpText; // a message on the auxiliary toolbar,
550 // relative to the m_SelComponentBox
551 wxStaticText* m_netText; // a message on the auxiliary toolbar,
552 // relative to the m_SelNetnameBox
553 wxStaticText* m_apertText; // a message on the auxiliary toolbar,
554 // relative to the m_SelAperAttributesBox
555 wxStaticText* m_dcodeText; // a message on the auxiliary toolbar,
556 // relative to the m_DCodeSelector
557};
558
559#endif /* WX_GERBER_STRUCT_H */
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:110
Color settings are a bit different than most of the settings objects in that there can be more than o...
Helper to display a DCode list and select a DCode id.
The base class for create windows for drawing purpose.
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: eda_item.cpp:254
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: filehistory.h:43
A list of GERBER_DRAW_ITEM objects currently loaded.
Definition: gbr_layout.h:46
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Definition: gbr_layout.cpp:41
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
Hold the image data and parameters for one gerber file and layer parameters.
Abstract functions of LAYER_WIDGET so they may be tied into the GERBVIEW_FRAME's data and we can add ...
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
void SetLayerColor(int aLayer, const COLOR4D &aColor)
void OnUpdateSelectDCode(wxUpdateUIEvent &aEvent)
void OnQuit(wxCommandEvent &event)
Called on request of application quit.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Called after the preferences dialog is run.
void OnUpdateDrawMode(wxUpdateUIEvent &aEvent)
wxStaticText * m_dcodeText
wxChoice * m_SelAperAttributesBox
void UpdateXORLayers()
Update each layers' differential option.
void UpdateStatusBar() override
Update the status bar information.
COLOR4D GetVisibleElementColor(int aLayerID)
Return the color of a gerber visible element.
GERBVIEW_SETTINGS * gvconfig() const
const PAGE_INFO & GetPageSettings() const override
bool IsLayerVisible(int aLayer) const
Test whether a given layer is visible.
void DisplayGridMsg() override
Display the current grid pane on the status bar.
void OnDrlFileHistory(wxCommandEvent &event)
Delete the current data and load a drill file in Excellon format selected from history list on curren...
void OnUpdateLayerSelectBox(wxUpdateUIEvent &aEvent)
void SortLayersByX2Attributes()
void SetLayout(GBR_LAYOUT *aLayout)
Set the m_gerberLayout member in such as way as to ensure deleting any previous GBR_LAYOUT.
void ReCreateHToolbar() override
LSET GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
GBR_LAYER_BOX_SELECTOR * m_SelLayerBox
void UpdateToolbarControlSizes() override
Update the sizes of any controls in the toolbars of the frame.
bool Read_EXCELLON_File(const wxString &aFullFileName)
bool m_show_layer_manager_tools
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void ShowChangedLanguage() override
GBR_LAYOUT * m_gerberLayout
void SetPageSettings(const PAGE_INFO &aPageSettings) override
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 ApplyDisplaySettingsToGAL()
Updates the GAL with display settings changes.
PAGE_INFO m_paper
bool LoadFileOrShowDialog(const wxString &aFileName, const wxString &dialogFiletypes, const wxString &dialogTitle, const int filetype)
Loads the file provided or shows a dialog to get the file(s) from the user.
bool LoadGerberJobFile(const wxString &aFileName)
Load a Gerber job file, and load gerber files found in job files.
wxStaticText * m_cmpText
void OnClearDrlFileHistory(wxCommandEvent &aEvent)
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data.
int SelectPCBLayer(int aDefaultLayer, int aCopperLayerCount, const wxString &aGerberName)
Show the dialog box for layer selection.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
wxString m_lastFileName
void syncLayerBox(bool aRebuildLayerBox=false)
Update the currently "selected" layer within m_SelLayerBox.
const VECTOR2I & GetGridOrigin() const override
Return the absolute coordinates of the origin of the snap grid.
GBR_LAYOUT * GetGerberLayout() const
bool LoadGerberFiles(const wxString &aFileName)
Load a given Gerber file or selected file(s), if the filename is empty.
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock) override
bool unarchiveFiles(const wxString &aFullFileName, REPORTER *aReporter=nullptr)
Extract gerber and drill files from the zip archive, and load them.
void ReCreateAuxiliaryToolbar() override
void doCloseWindow() override
void OnSelectHighlightChoice(wxCommandEvent &event)
Handles the changing of the highlighted component/net/attribute.
wxChoice * m_SelComponentBox
FILE_HISTORY m_jobFileHistory
void OnJobFileHistory(wxCommandEvent &event)
Delete the current data and load a gerber job file selected from the history list.
void SetGridOrigin(const VECTOR2I &aPoint) override
wxChoice * m_SelNetnameBox
void OnZipFileHistory(wxCommandEvent &event)
Delete the current data and load a zip archive file selected from the history list.
int GetActiveLayer() const
Return the active layer.
wxTextCtrl * m_TextInfo
bool IsElementVisible(int aLayerID) const
Test whether a given element category is visible.
DCODE_SELECTION_BOX * m_DCodeSelector
GERBER_LAYER_WIDGET * m_LayersManager
void SetActiveLayer(int aLayer, bool doLayerWidgetUpdate=true)
change the currently active layer to aLayer and update the GERBER_LAYER_WIDGET.
wxStaticText * m_netText
void syncLayerWidget()
Update the currently "selected" layer within the GERBER_LAYER_WIDGET.
void SetVisibleElementColor(int aLayerID, const COLOR4D &aColor)
GERBVIEW_FRAME(KIWAY *aKiway, wxWindow *aParent)
unsigned ImagesMaxCount() const
The max number of file images.
void updateAperAttributesSelectBox()
void ReCreateOptToolbar() override
Create or update the left vertical toolbar (option toolbar)
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
void SetVisibleLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
wxStaticText * m_apertText
bool Read_GERBER_File(const wxString &GERBER_FullFileName)
Definition: readgerb.cpp:41
COLOR4D GetLayerColor(int aLayer) const
bool Clear_DrawLayers(bool query)
void SortLayersByFileExtension()
GERBER_FILE_IMAGE * GetGbrImage(int aIdx) const
void updateComponentListSelectBox()
void SetGridVisibility(bool aVisible) override
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Returns bbox of document with option to not include some items.
bool LoadListOfGerberAndDrillFiles(const wxString &aPath, const wxArrayString &aFilenameList, std::vector< int > *aFileType)
Load a list of Gerber and NC drill files and updates the view based on them.
void SaveCopyInUndoList(GERBER_DRAW_ITEM *aItemToCopy, UNDO_REDO aTypeCommand=UNDO_REDO::UNSPECIFIED)
void SetDisplayMode(int aMode)
const TITLE_BLOCK & GetTitleBlock() const override
bool LoadAutodetectedFiles(const wxString &aFileName)
Load a given file or selected file(s), if the filename is empty.
VECTOR2I m_grid_origin
void OnSelectActiveLayer(wxCommandEvent &event)
Select the active layer:
void ReFillLayerWidget()
Change out all the layers in m_Layers; called upon loading new gerber files.
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.
FILE_HISTORY m_zipFileHistory
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl) override
Open a project or set of files given by aFileList.
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
int getNextAvailableLayer() const
Find the next empty layer.
void Erase_Current_DrawLayer(bool query)
void OnSelectDisplayMode(wxCommandEvent &event)
Called on a display mode selection.
void updateNetnameListSelectBox()
bool LoadZipArchiveFile(const wxString &aFileName)
Load a zipped archive file.
void UpdateTitleAndInfo()
Display the short filename (if exists) of the selected layer on the caption of the main GerbView wind...
void OnClearGbrFileHistory(wxCommandEvent &aEvent)
void SetElementVisibility(int aLayerID, bool aNewState)
Change the visibility of an element category.
virtual void SetGridColor(const COLOR4D &aColor) override
void OnSelectActiveDCode(wxCommandEvent &event)
Select the active DCode for the current active layer.
void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
void ActivateGalCanvas() override
Use to start up the GAL drawing canvas.
void OnClearZipFileHistory(wxCommandEvent &aEvent)
void DoWithAcceptedFiles() override
Execute action on accepted dropped file.
void ReCreateVToolbar() override
Create or update the right vertical toolbar.
void RemapLayers(std::unordered_map< int, int > remapping)
Takes a layer remapping and reorders the layers.
void OnGbrFileHistory(wxCommandEvent &event)
Delete the current data and loads a Gerber file selected from history list on current layer.
FILE_HISTORY m_drillFileHistory
bool LoadExcellonFiles(const wxString &aFileName)
Load a drill (EXCELLON) file or many files.
void OnClearJobFileHistory(wxCommandEvent &aEvent)
COLOR4D GetGridColor() override
void ReCreateMenuBar() override
Recreates the menu bar.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:273
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
A holder to handle information on schematic or board items.
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:41
Class CLASS_GBR_LAYOUT to handle info to draw loaded Gerber images and page frame reference.
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...