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 )
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  // Right click context menu
101  EVT_MENU( ID_HIGHLIGHT_CMP_ITEMS, GERBVIEW_FRAME::Process_Special_Functions )
102  EVT_MENU( ID_HIGHLIGHT_NET_ITEMS, GERBVIEW_FRAME::Process_Special_Functions )
103  EVT_MENU( ID_HIGHLIGHT_APER_ATTRIBUTE_ITEMS, GERBVIEW_FRAME::Process_Special_Functions )
104  EVT_MENU( ID_HIGHLIGHT_REMOVE_ALL, GERBVIEW_FRAME::Process_Special_Functions )
105 
106  EVT_UPDATE_UI( ID_ON_GRID_SELECT, GERBVIEW_FRAME::OnUpdateSelectGrid )
109  GERBVIEW_FRAME::OnUpdateLayerSelectBox )
111  GERBVIEW_FRAME::OnUpdateDrawMode )
112 
113 END_EVENT_TABLE()
114 
115 
116 /* Handles the selection of tools, menu, and popup menu commands.
117  */
118 void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
119 {
120  int id = event.GetId();
121  GERBVIEW_SELECTION_TOOL* selTool = GetToolManager()->GetTool<GERBVIEW_SELECTION_TOOL>();
122  GERBVIEW_SELECTION& selection = selTool->GetSelection();
123  GERBER_DRAW_ITEM* currItem = (GERBER_DRAW_ITEM*) selection.Front();
124 
125  switch( id )
126  {
128  Erase_Current_DrawLayer( true );
129  ClearMsgPanel();
130  break;
131 
133  Liste_D_Codes();
134  break;
135 
137  m_SelComponentBox->SetStringSelection( currItem->GetNetAttributes().m_Cmpref );
138  break;
139 
141  m_SelNetnameBox->SetStringSelection( UnescapeString( currItem->GetNetAttributes().m_Netname ) );
142  break;
143 
145  m_SelAperAttributesBox->SetStringSelection( currItem->GetDcodeDescr()->m_AperFunction );
146  break;
147 
149  m_SelComponentBox->SetSelection( 0 );
150  m_SelNetnameBox->SetSelection( 0 );
151  m_SelAperAttributesBox->SetSelection( 0 );
152 
153  if( GetGbrImage( GetActiveLayer() ) )
154  GetGbrImage( GetActiveLayer() )->m_Selected_Tool = 0;
155  break;
156 
157  default:
158  wxFAIL_MSG( wxT( "GERBVIEW_FRAME::Process_Special_Functions error" ) );
159  break;
160  }
161 
162  GetCanvas()->Refresh();
163 }
164 
165 
166 void GERBVIEW_FRAME::OnSelectHighlightChoice( wxCommandEvent& event )
167 {
168  auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>( GetCanvas()->GetView()->GetPainter() )->GetSettings();
169 
170  switch( event.GetId() )
171  {
173  settings->m_componentHighlightString = m_SelComponentBox->GetStringSelection();
174  break;
175 
177  settings->m_netHighlightString = m_SelNetnameBox->GetStringSelection();
178  break;
179 
181  settings->m_attributeHighlightString = m_SelAperAttributesBox->GetStringSelection();
182  break;
183 
184  }
185 
187  GetCanvas()->Refresh();
188 }
189 
190 
191 void GERBVIEW_FRAME::OnSelectActiveDCode( wxCommandEvent& event )
192 {
193  GERBER_FILE_IMAGE* gerber_image = GetGbrImage( GetActiveLayer() );
194 
195  if( gerber_image )
196  {
197  int tool = m_DCodeSelector->GetSelectedDCodeId();
198 
199  if( tool != gerber_image->m_Selected_Tool )
200  {
201  gerber_image->m_Selected_Tool = tool;
202  GetCanvas()->Refresh();
203  }
204  }
205 }
206 
207 
208 void GERBVIEW_FRAME::OnSelectActiveLayer( wxCommandEvent& event )
209 {
210  SetActiveLayer( event.GetSelection(), true );
211 
212  // Rebuild the DCode list in toolbar (but not the Layer Box) after change
213  syncLayerBox( false );
214 }
215 
216 
217 void GERBVIEW_FRAME::OnShowGerberSourceFile( wxCommandEvent& event )
218 {
219  int layer = GetActiveLayer();
220  GERBER_FILE_IMAGE* gerber_layer = GetGbrImage( layer );
221 
222  if( gerber_layer )
223  {
224  wxString editorname = Pgm().GetEditorName();
225 
226  if( !editorname.IsEmpty() )
227  {
228  wxFileName fn( gerber_layer->m_FileName );
229 
230  // Call the editor only if the Gerber/drill source file is available.
231  // This is not always the case, because it can be a temporary file
232  // if it comes from a zip archive.
233  if( !fn.FileExists() )
234  {
235  wxString msg;
236  msg.Printf( _( "Source file \"%s\" is not available" ),
237  GetChars( fn.GetFullPath() ) );
238  wxMessageBox( msg );
239  }
240  else
241  ExecuteFile( this, editorname, QuoteFullPath( fn ) );
242  }
243  else
244  wxMessageBox( _( "No editor defined. Please select one" ) );
245  }
246  else
247  {
248  wxString msg;
249  msg.Printf( _( "No file loaded on the active layer %d" ), layer + 1 );
250  wxMessageBox( msg );
251  }
252 }
253 
254 
255 void GERBVIEW_FRAME::OnSelectDisplayMode( wxCommandEvent& event )
256 {
257  switch( event.GetId() )
258  {
262  }
263 
264  GetCanvas()->Refresh();
265 }
266 
267 
268 void GERBVIEW_FRAME::OnQuit( wxCommandEvent& event )
269 {
270  Close( true );
271 }
272 
273 
275 {
276  // call my base class
278 
280 
281  wxAuiPaneInfo& pane_info = m_auimgr.GetPane( m_LayersManager );
282  pane_info.Caption( _( "Visibles" ) );
283  m_auimgr.Update();
284 
286 }
287 
288 
289 void GERBVIEW_FRAME::OnToggleShowLayerManager( wxCommandEvent& aEvent )
290 {
292 
293  // show/hide auxiliary Vertical layers and visibility manager toolbar
294  m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
295  m_auimgr.Update();
296 }
void OnSelectHighlightChoice(wxCommandEvent &event)
Handles the changing of the highlighted component/net/attribute.
D_CODE * GetDcodeDescr() const
Function GetDcodeDescr returns the GetDcodeDescr of this object, or NULL.
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:1444
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...
wxString m_Cmpref
the component reference parent of the data
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.
wxString m_Netname
for items associated to a net: the netname
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
const GBR_NETLIST_METADATA & GetNetAttributes() const
GERBVIEW_SELECTION & GetSelection()
Function GetSelection()
void OnCloseWindow(wxCloseEvent &Event)
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...
wxString m_AperFunction
the aperture attribute (created by a TA.AperFunction command) attached to the D_CODE
Definition: dcode.h:105
DCODE_SELECTION_BOX * m_DCodeSelector
void ExportDataInPcbnewFormat(wxCommandEvent &event)
int GetActiveLayer() const
Function SetActiveLayer returns the active layer.
GERBVIEW_SELECTION_TOOL.
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:378
#define _(s)
Definition: 3d_actions.cpp:33
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131
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:174
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.