KiCad PCB EDA Suite
events_called_functions.cpp
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) 2011-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <fctsys.h>
26 #include <pgm_base.h>
27 #include <gestfich.h>
28 #include <gerbview.h>
29 #include <gerbview_frame.h>
30 #include <gerbview_id.h>
31 #include <gerber_file_image.h>
32 #include <gerber_file_image_list.h>
33 #include <dialog_helpers.h>
34 #include <DCodeSelectionbox.h>
35 #include <gerbview_layer_widget.h>
37 #include <tool/tool_manager.h>
38 #include <tool/selection.h>
40 #include <gerbview_painter.h>
41 #include <view/view.h>
42 
43 
44 // Event table:
45 
46 BEGIN_EVENT_TABLE( GERBVIEW_FRAME, EDA_DRAW_FRAME )
47  EVT_CLOSE( GERBVIEW_FRAME::OnCloseWindow )
48  EVT_SIZE( GERBVIEW_FRAME::OnSize )
49 
53 
54  // Menu Files:
57 
60 
64 
66  GERBVIEW_FRAME::OnZipFileHistory )
67  EVT_MENU( ID_GERBVIEW_ZIP_FILE_LIST_CLEAR, GERBVIEW_FRAME::OnClearZipFileHistory )
68 
70  GERBVIEW_FRAME::OnJobFileHistory )
71  EVT_MENU( ID_GERBVIEW_JOB_FILE_LIST_CLEAR, GERBVIEW_FRAME::OnClearJobFileHistory )
72 
73  EVT_MENU( wxID_EXIT, GERBVIEW_FRAME::OnQuit )
74 
75  // menu Postprocess
76  EVT_MENU( ID_GERBVIEW_SHOW_LIST_DCODES, GERBVIEW_FRAME::Process_Special_Functions )
77  EVT_MENU( ID_GERBVIEW_SHOW_SOURCE, GERBVIEW_FRAME::OnShowGerberSourceFile )
78 
79  // menu Miscellaneous
80  EVT_MENU( ID_GERBVIEW_ERASE_CURR_LAYER, GERBVIEW_FRAME::Process_Special_Functions )
81 
82  EVT_COMBOBOX( ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, GERBVIEW_FRAME::OnSelectActiveLayer )
83 
85 
86  // Option toolbar
88  GERBVIEW_FRAME::OnToggleShowLayerManager )
90  GERBVIEW_FRAME::OnSelectDisplayMode )
91 
92  // Auxiliary horizontal toolbar
93  EVT_CHOICE( ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE, GERBVIEW_FRAME::OnSelectHighlightChoice )
94  EVT_CHOICE( ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE, GERBVIEW_FRAME::OnSelectHighlightChoice )
96  GERBVIEW_FRAME::OnSelectHighlightChoice )
97  EVT_CHOICE( ID_ON_ZOOM_SELECT, GERBVIEW_FRAME::OnSelectZoom )
98  EVT_CHOICE( ID_ON_GRID_SELECT, GERBVIEW_FRAME::OnSelectGrid )
99 
100  EVT_UPDATE_UI( ID_ON_GRID_SELECT, GERBVIEW_FRAME::OnUpdateSelectGrid )
103  GERBVIEW_FRAME::OnUpdateLayerSelectBox )
105  GERBVIEW_FRAME::OnUpdateDrawMode )
106 
107 END_EVENT_TABLE()
108 
109 
110 /* Handles the selection of tools, menu, and popup menu commands.
111  */
112 void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
113 {
114  switch( event.GetId() )
115  {
117  Erase_Current_DrawLayer( true );
118  ClearMsgPanel();
119  break;
120 
122  Liste_D_Codes();
123  break;
124 
125  default:
126  wxFAIL_MSG( wxT( "GERBVIEW_FRAME::Process_Special_Functions error" ) );
127  break;
128  }
129 
130  GetCanvas()->Refresh();
131 }
132 
133 
134 void GERBVIEW_FRAME::OnSelectHighlightChoice( wxCommandEvent& event )
135 {
136  auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>( GetCanvas()->GetView()->GetPainter() )->GetSettings();
137 
138  switch( event.GetId() )
139  {
141  settings->m_componentHighlightString = m_SelComponentBox->GetStringSelection();
142  break;
143 
145  settings->m_netHighlightString = m_SelNetnameBox->GetStringSelection();
146  break;
147 
149  settings->m_attributeHighlightString = m_SelAperAttributesBox->GetStringSelection();
150  break;
151 
152  }
153 
155  GetCanvas()->Refresh();
156 }
157 
158 
159 void GERBVIEW_FRAME::OnSelectActiveDCode( wxCommandEvent& event )
160 {
161  GERBER_FILE_IMAGE* gerber_image = GetGbrImage( GetActiveLayer() );
162 
163  if( gerber_image )
164  {
165  int tool = m_DCodeSelector->GetSelectedDCodeId();
166 
167  if( tool != gerber_image->m_Selected_Tool )
168  {
169  gerber_image->m_Selected_Tool = tool;
170  GetCanvas()->Refresh();
171  }
172  }
173 }
174 
175 
176 void GERBVIEW_FRAME::OnSelectActiveLayer( wxCommandEvent& event )
177 {
178  SetActiveLayer( event.GetSelection(), true );
179 
180  // Rebuild the DCode list in toolbar (but not the Layer Box) after change
181  syncLayerBox( false );
182 }
183 
184 
185 void GERBVIEW_FRAME::OnShowGerberSourceFile( wxCommandEvent& event )
186 {
187  int layer = GetActiveLayer();
188  GERBER_FILE_IMAGE* gerber_layer = GetGbrImage( layer );
189 
190  if( gerber_layer )
191  {
192  wxString editorname = Pgm().GetEditorName();
193 
194  if( !editorname.IsEmpty() )
195  {
196  wxFileName fn( gerber_layer->m_FileName );
197 
198  // Call the editor only if the Gerber/drill source file is available.
199  // This is not always the case, because it can be a temporary file
200  // if it comes from a zip archive.
201  if( !fn.FileExists() )
202  {
203  wxString msg;
204  msg.Printf( _( "Source file \"%s\" is not available" ),
205  GetChars( fn.GetFullPath() ) );
206  wxMessageBox( msg );
207  }
208  else
209  ExecuteFile( this, editorname, QuoteFullPath( fn ) );
210  }
211  else
212  wxMessageBox( _( "No editor defined. Please select one" ) );
213  }
214  else
215  {
216  wxString msg;
217  msg.Printf( _( "No file loaded on the active layer %d" ), layer + 1 );
218  wxMessageBox( msg );
219  }
220 }
221 
222 
223 void GERBVIEW_FRAME::OnSelectDisplayMode( wxCommandEvent& event )
224 {
225  switch( event.GetId() )
226  {
230  }
231 
232  GetCanvas()->Refresh();
233 }
234 
235 
236 void GERBVIEW_FRAME::OnQuit( wxCommandEvent& event )
237 {
238  Close( true );
239 }
240 
241 
243 {
244  // call my base class
246 
248 
249  wxAuiPaneInfo& pane_info = m_auimgr.GetPane( m_LayersManager );
250  pane_info.Caption( _( "Visibles" ) );
251  m_auimgr.Update();
252 
254 }
255 
256 
257 void GERBVIEW_FRAME::OnToggleShowLayerManager( wxCommandEvent& aEvent )
258 {
260 
261  // show/hide auxiliary Vertical layers and visibility manager toolbar
262  m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
263  m_auimgr.Update();
264 }
void OnSelectHighlightChoice(wxCommandEvent &event)
Handles the changing of the highlighted component/net/attribute.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
This file is part of the common library TODO brief description.
void Files_io(wxCommandEvent &event)
void OnToggleShowLayerManager(wxCommandEvent &aEvent)
void syncLayerBox(bool aRebuildLayerBox=false)
Function syncLayerBox updates the currently "selected" layer within m_SelLayerBox The currently activ...
Definition: id.h:88
void OnQuit(wxCommandEvent &event)
Function OnQuit called on request of application quit.
void OnClearDrlFileHistory(wxCommandEvent &aEvent)
GERBER_LAYER_WIDGET * m_LayersManager
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
void UpdateAllItems(int aUpdateFlags)
Updates all items in the view according to the given flags.
Definition: view.cpp:1435
GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters (TODO:...
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...
wxAuiManager m_auimgr
Visibility flag has changed.
Definition: view_item.h:58
The base class for create windows for drawing purpose.
void OnSelectActiveDCode(wxCommandEvent &event)
Function OnSelectActiveDCode Selects the active DCode for the current active layer.
wxChoice * m_SelNetnameBox
void OnSelectDisplayMode(wxCommandEvent &event)
Function OnSelectDisplayMode called on a display mode selection Mode selection can be fast display,...
void SetLayersManagerTabsText()
Function SetLayersManagerTabsText Update the layer manager tabs labels Useful when changing Language ...
EVT_MENU_RANGE(ID_GERBVIEW_DRILL_FILE1, ID_GERBVIEW_DRILL_FILEMAX, GERBVIEW_FRAME::OnDrlFileHistory) EVT_MENU_RANGE(ID_GERBVIEW_ZIP_FILE1
GERBER_FILE_IMAGE * GetGbrImage(int aIdx) const
int GetSelectedDCodeId()
Function GetSelectedDCodeId.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
Helper dialog and control classes.
virtual KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
void OnClearGbrFileHistory(wxCommandEvent &aEvent)
virtual void OnSize(wxSizeEvent &event)
Recalculate the size of toolbars and display panel when the frame size changes.
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::OnToggleShowLayerManager GERBVIEW_FRAME::OnSelectHighlightChoice ID_TB_OPTIONS_SHOW_GBR_MODE_2
void OnShowGerberSourceFile(wxCommandEvent &event)
Function OnShowGerberSourceFile Call the preferred editor to show (and edit) the gerber source file l...
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::OnToggleShowLayerManager EVT_TOOL_RANGE(ID_TB_OPTIONS_SHOW_GBR_MODE_0, ID_TB_OPTIONS_SHOW_GBR_MODE_2, GERBVIEW_FRAME::OnSelectDisplayMode) EVT_CHOICE(ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
DCODE_SELECTION_BOX * m_DCodeSelector
void ExportDataInPcbnewFormat(wxCommandEvent &event)
int GetActiveLayer() const
Function SetActiveLayer returns the active layer.
wxChoice * m_SelAperAttributesBox
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153
see class PGM_BASE
PCB_EDIT_FRAME::OnUpdateSelectTrackWidth EVT_UPDATE_UI_RANGE(ID_POPUP_PCB_SELECT_VIASIZE1, ID_POPUP_PCB_SELECT_VIASIZE8, PCB_EDIT_FRAME::OnUpdateSelectViaSize) PCB_EDIT_FRAME
wxString QuoteFullPath(wxFileName &fn, wxPathFormat format)
Quote return value of wxFileName::GetFullPath().
Definition: gestfich.cpp:368
#define _(s)
Definition: 3d_actions.cpp:33
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::OnToggleShowLayerManager GERBVIEW_FRAME::OnSelectHighlightChoice EVT_UPDATE_UI(ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, GERBVIEW_FRAME::OnUpdateLayerSelectBox) EVT_UPDATE_UI_RANGE(ID_TB_OPTIONS_SHOW_GBR_MODE_0
wxChoice * m_SelComponentBox
void OnDrlFileHistory(wxCommandEvent &event)
Function OnDrlFileHistory deletes the current data and load a drill file in Excellon format selected ...
#define EVT_SELECT_DCODE
Definition: id.h:87
bool m_show_layer_manager_tools
int ExecuteFile(wxWindow *frame, const wxString &ExecFile, const wxString &param, wxProcess *callback)
Function ExecuteFile calls the executable file ExecFile with the command line parameters param.
Definition: gestfich.cpp:164
virtual void ShowChangedLanguage()
Redraw the menus and what not in current language.
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 SetDisplayMode(int aMode)
Function SetDisplayMode.