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>
38 #include <tool/tool_manager.h>
39 #include <tool/selection.h>
41 #include <gerbview_painter.h>
42 #include <view/view.h>
43 
44 
45 // Event table:
46 
47 BEGIN_EVENT_TABLE( GERBVIEW_FRAME, EDA_DRAW_FRAME )
49  EVT_SIZE( GERBVIEW_FRAME::OnSize )
50 
51  EVT_TOOL( wxID_FILE, GERBVIEW_FRAME::Files_io )
58 
59  // Menu Files:
60  EVT_MENU( wxID_FILE, GERBVIEW_FRAME::Files_io )
63 
66 
70 
72  GERBVIEW_FRAME::OnZipFileHistory )
73  EVT_MENU( ID_GERBVIEW_ZIP_FILE_LIST_CLEAR, GERBVIEW_FRAME::OnClearZipFileHistory )
74 
76  GERBVIEW_FRAME::OnJobFileHistory )
77  EVT_MENU( ID_GERBVIEW_JOB_FILE_LIST_CLEAR, GERBVIEW_FRAME::OnClearJobFileHistory )
78 
79  EVT_MENU( wxID_EXIT, GERBVIEW_FRAME::OnQuit )
80 
81  // menu Postprocess
82  EVT_MENU( ID_GERBVIEW_SHOW_LIST_DCODES, GERBVIEW_FRAME::Process_Special_Functions )
83  EVT_MENU( ID_GERBVIEW_SHOW_SOURCE, GERBVIEW_FRAME::OnShowGerberSourceFile )
84 
85  // menu Miscellaneous
86  EVT_MENU( ID_GERBVIEW_ERASE_CURR_LAYER, GERBVIEW_FRAME::Process_Special_Functions )
87 
88  EVT_COMBOBOX( ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, GERBVIEW_FRAME::OnSelectActiveLayer )
89 
91 
92  // Option toolbar
94  GERBVIEW_FRAME::OnToggleShowLayerManager )
96  GERBVIEW_FRAME::OnSelectDisplayMode )
97 
98  // Auxiliary horizontal toolbar
99  EVT_CHOICE( ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE, GERBVIEW_FRAME::OnSelectHighlightChoice )
100  EVT_CHOICE( ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE, GERBVIEW_FRAME::OnSelectHighlightChoice )
102  GERBVIEW_FRAME::OnSelectHighlightChoice )
103  EVT_CHOICE( ID_ON_ZOOM_SELECT, GERBVIEW_FRAME::OnSelectZoom )
104  EVT_CHOICE( ID_ON_GRID_SELECT, GERBVIEW_FRAME::OnSelectGrid )
105 
106  // Right click context menu
107  EVT_MENU( ID_HIGHLIGHT_CMP_ITEMS, GERBVIEW_FRAME::Process_Special_Functions )
108  EVT_MENU( ID_HIGHLIGHT_NET_ITEMS, GERBVIEW_FRAME::Process_Special_Functions )
109  EVT_MENU( ID_HIGHLIGHT_APER_ATTRIBUTE_ITEMS, GERBVIEW_FRAME::Process_Special_Functions )
110  EVT_MENU( ID_HIGHLIGHT_REMOVE_ALL, GERBVIEW_FRAME::Process_Special_Functions )
111 
112  EVT_UPDATE_UI( ID_ON_GRID_SELECT, GERBVIEW_FRAME::OnUpdateSelectGrid )
115  GERBVIEW_FRAME::OnUpdateLayerSelectBox )
117  GERBVIEW_FRAME::OnUpdateDrawMode )
118 
119 END_EVENT_TABLE()
120 
121 
122 /* Handles the selection of tools, menu, and popup menu commands.
123  */
124 void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
125 {
126  int id = event.GetId();
127  GERBVIEW_SELECTION_TOOL* selTool = GetToolManager()->GetTool<GERBVIEW_SELECTION_TOOL>();
128  GERBVIEW_SELECTION& selection = selTool->GetSelection();
129  GERBER_DRAW_ITEM* currItem = (GERBER_DRAW_ITEM*) selection.Front();
130 
131  switch( id )
132  {
134  Erase_Current_DrawLayer( true );
135  ClearMsgPanel();
136  break;
137 
139  Liste_D_Codes();
140  break;
141 
143  m_SelComponentBox->SetStringSelection( currItem->GetNetAttributes().m_Cmpref );
144  break;
145 
147  m_SelNetnameBox->SetStringSelection( UnescapeString( currItem->GetNetAttributes().m_Netname ) );
148  break;
149 
151  m_SelAperAttributesBox->SetStringSelection( currItem->GetDcodeDescr()->m_AperFunction );
152  break;
153 
155  m_SelComponentBox->SetSelection( 0 );
156  m_SelNetnameBox->SetSelection( 0 );
157  m_SelAperAttributesBox->SetSelection( 0 );
158 
159  if( GetGbrImage( GetActiveLayer() ) )
160  GetGbrImage( GetActiveLayer() )->m_Selected_Tool = 0;
161  break;
162 
163  default:
164  wxFAIL_MSG( wxT( "GERBVIEW_FRAME::Process_Special_Functions error" ) );
165  break;
166  }
167 
168  GetCanvas()->Refresh();
169 }
170 
171 
172 void GERBVIEW_FRAME::OnSelectHighlightChoice( wxCommandEvent& event )
173 {
174  auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>( GetCanvas()->GetView()->GetPainter() )->GetSettings();
175 
176  switch( event.GetId() )
177  {
179  settings->m_componentHighlightString = m_SelComponentBox->GetStringSelection();
180  break;
181 
183  settings->m_netHighlightString = m_SelNetnameBox->GetStringSelection();
184  break;
185 
187  settings->m_attributeHighlightString = m_SelAperAttributesBox->GetStringSelection();
188  break;
189 
190  }
191 
193  GetCanvas()->Refresh();
194 }
195 
196 
197 void GERBVIEW_FRAME::OnSelectActiveDCode( wxCommandEvent& event )
198 {
199  GERBER_FILE_IMAGE* gerber_image = GetGbrImage( GetActiveLayer() );
200 
201  if( gerber_image )
202  {
203  int tool = m_DCodeSelector->GetSelectedDCodeId();
204 
205  if( tool != gerber_image->m_Selected_Tool )
206  {
207  gerber_image->m_Selected_Tool = tool;
208  GetCanvas()->Refresh();
209  }
210  }
211 }
212 
213 
214 void GERBVIEW_FRAME::OnSelectActiveLayer( wxCommandEvent& event )
215 {
216  SetActiveLayer( event.GetSelection(), true );
217 
218  // Rebuild the DCode list in toolbar (but not the Layer Box) after change
219  syncLayerBox( false );
220 }
221 
222 
223 void GERBVIEW_FRAME::OnShowGerberSourceFile( wxCommandEvent& event )
224 {
225  int layer = GetActiveLayer();
226  GERBER_FILE_IMAGE* gerber_layer = GetGbrImage( layer );
227 
228  if( gerber_layer )
229  {
230  wxString editorname = Pgm().GetEditorName();
231 
232  if( !editorname.IsEmpty() )
233  {
234  wxFileName fn( gerber_layer->m_FileName );
235 
236  // Call the editor only if the Gerber/drill source file is available.
237  // This is not always the case, because it can be a temporary file
238  // if it comes from a zip archive.
239  if( !fn.FileExists() )
240  {
241  wxString msg;
242  msg.Printf( _( "Source file \"%s\" is not available" ),
243  GetChars( fn.GetFullPath() ) );
244  wxMessageBox( msg );
245  }
246  else
247  ExecuteFile( this, editorname, QuoteFullPath( fn ) );
248  }
249  else
250  wxMessageBox( _( "No editor defined. Please select one" ) );
251  }
252  else
253  {
254  wxString msg;
255  msg.Printf( _( "No file loaded on the active layer %d" ), layer + 1 );
256  wxMessageBox( msg );
257  }
258 }
259 
260 
261 void GERBVIEW_FRAME::OnSelectDisplayMode( wxCommandEvent& event )
262 {
263  switch( event.GetId() )
264  {
268  }
269 
270  GetCanvas()->Refresh();
271 }
272 
273 
274 void GERBVIEW_FRAME::OnQuit( wxCommandEvent& event )
275 {
276  Close( true );
277 }
278 
279 
281 {
282  // call my base class
284 
286 
287  wxAuiPaneInfo& pane_info = m_auimgr.GetPane( m_LayersManager );
288  pane_info.Caption( _( "Visibles" ) );
289  m_auimgr.Update();
290 
292 }
293 
294 
295 void GERBVIEW_FRAME::OnToggleShowLayerManager( wxCommandEvent& aEvent )
296 {
298 
299  // show/hide auxiliary Vertical layers and visibility manager toolbar
300  m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
301  m_auimgr.Update();
302 }
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:103
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 also update the GERBER_L...
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:56
The base class for create windows for drawing purpose.
int GetActiveLayer()
Function SetActiveLayer returns the active layer.
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)
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:101
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 and may be called upon loading new ...
void OnSelectActiveLayer(wxCommandEvent &event)
Function OnSelectActiveLayer Selects the active layer:
void SetDisplayMode(int aMode)
Function SetDisplayMode.