1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2011-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2014 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file events_called_functions.cpp
* @brief GerbView command event functions.
*/
#include <fctsys.h>
#include <pgm_base.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <common.h>
#include <gestfich.h>
#include <gerbview.h>
#include <gerbview_frame.h>
#include <kicad_device_context.h>
#include <gerbview_id.h>
#include <class_GERBER.h>
#include <dialog_helpers.h>
#include <class_DCodeSelectionbox.h>
#include <class_gerbview_layer_widget.h>
#include <dialog_show_page_borders.h>
// Event table:
BEGIN_EVENT_TABLE( GERBVIEW_FRAME, EDA_DRAW_FRAME )
EVT_CLOSE( GERBVIEW_FRAME::OnCloseWindow )
EVT_SIZE( GERBVIEW_FRAME::OnSize )
EVT_TOOL( wxID_FILE, GERBVIEW_FRAME::Files_io )
EVT_TOOL( ID_GERBVIEW_ERASE_ALL, GERBVIEW_FRAME::Files_io )
EVT_TOOL( ID_GERBVIEW_LOAD_DRILL_FILE, GERBVIEW_FRAME::Files_io )
EVT_TOOL( ID_NEW_BOARD, GERBVIEW_FRAME::Files_io )
EVT_TOOL( ID_GERBVIEW_SET_PAGE_BORDER, GERBVIEW_FRAME::Process_Special_Functions )
// Menu Files:
EVT_MENU( wxID_FILE, GERBVIEW_FRAME::Files_io )
EVT_MENU( ID_NEW_BOARD, GERBVIEW_FRAME::Files_io )
EVT_MENU( ID_GEN_PLOT, GERBVIEW_FRAME::ToPlotter )
EVT_MENU( ID_GERBVIEW_EXPORT_TO_PCBNEW, GERBVIEW_FRAME::ExportDataInPcbnewFormat )
EVT_MENU_RANGE( wxID_FILE1, wxID_FILE9, GERBVIEW_FRAME::OnGbrFileHistory )
EVT_MENU_RANGE( ID_GERBVIEW_DRILL_FILE1, ID_GERBVIEW_DRILL_FILE9,
GERBVIEW_FRAME::OnDrlFileHistory )
EVT_MENU( wxID_EXIT, GERBVIEW_FRAME::OnQuit )
// menu Preferences
EVT_MENU_RANGE( ID_PREFERENCES_HOTKEY_START, ID_PREFERENCES_HOTKEY_END,
GERBVIEW_FRAME::Process_Config )
EVT_MENU( ID_MENU_GERBVIEW_SHOW_HIDE_LAYERS_MANAGER_DIALOG,
GERBVIEW_FRAME::OnSelectOptionToolbar )
EVT_MENU( wxID_PREFERENCES, GERBVIEW_FRAME::InstallGerberOptionsDialog )
// menu Postprocess
EVT_MENU( ID_GERBVIEW_SHOW_LIST_DCODES, GERBVIEW_FRAME::Process_Special_Functions )
EVT_MENU( ID_GERBVIEW_SHOW_SOURCE, GERBVIEW_FRAME::OnShowGerberSourceFile )
EVT_MENU( ID_MENU_GERBVIEW_SELECT_PREFERED_EDITOR,
EDA_BASE_FRAME::OnSelectPreferredEditor )
// menu Miscellaneous
EVT_MENU( ID_GERBVIEW_GLOBAL_DELETE, GERBVIEW_FRAME::Process_Special_Functions )
// Menu Help
EVT_MENU( wxID_HELP, EDA_DRAW_FRAME::GetKicadHelp )
EVT_MENU( wxID_INDEX, EDA_DRAW_FRAME::GetKicadHelp )
EVT_MENU( wxID_ABOUT, EDA_DRAW_FRAME::GetKicadAbout )
EVT_TOOL( wxID_UNDO, GERBVIEW_FRAME::Process_Special_Functions )
EVT_TOOL( wxID_PRINT, GERBVIEW_FRAME::ToPrinter )
EVT_COMBOBOX( ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER,
GERBVIEW_FRAME::OnSelectActiveLayer )
EVT_SELECT_DCODE( ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE, GERBVIEW_FRAME::OnSelectActiveDCode )
// Vertical toolbar:
EVT_TOOL( ID_NO_TOOL_SELECTED, GERBVIEW_FRAME::Process_Special_Functions )
EVT_MENU_RANGE( ID_POPUP_GENERAL_START_RANGE, ID_POPUP_GENERAL_END_RANGE,
GERBVIEW_FRAME::Process_Special_Functions )
// Option toolbar
EVT_TOOL( ID_TB_OPTIONS_SHOW_POLAR_COORD, GERBVIEW_FRAME::OnSelectOptionToolbar )
EVT_TOOL( ID_TB_OPTIONS_SHOW_POLYGONS_SKETCH, GERBVIEW_FRAME::OnSelectOptionToolbar )
EVT_TOOL( ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH, GERBVIEW_FRAME::OnSelectOptionToolbar )
EVT_TOOL( ID_TB_OPTIONS_SHOW_LINES_SKETCH, GERBVIEW_FRAME::OnSelectOptionToolbar )
EVT_TOOL( ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR,
GERBVIEW_FRAME::OnSelectOptionToolbar )
EVT_TOOL( ID_TB_OPTIONS_SHOW_DCODES, GERBVIEW_FRAME::OnSelectOptionToolbar )
EVT_TOOL( ID_TB_OPTIONS_SHOW_NEGATIVE_ITEMS, GERBVIEW_FRAME::OnSelectOptionToolbar )
EVT_TOOL_RANGE( ID_TB_OPTIONS_SHOW_GBR_MODE_0, ID_TB_OPTIONS_SHOW_GBR_MODE_2,
GERBVIEW_FRAME::OnSelectDisplayMode )
EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_POLAR_COORD, GERBVIEW_FRAME::OnUpdateCoordType )
EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH,
GERBVIEW_FRAME::OnUpdateFlashedItemsDrawMode )
EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_LINES_SKETCH, GERBVIEW_FRAME::OnUpdateLinesDrawMode )
EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_POLYGONS_SKETCH, GERBVIEW_FRAME::OnUpdatePolygonsDrawMode )
EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_DCODES, GERBVIEW_FRAME::OnUpdateShowDCodes )
EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_NEGATIVE_ITEMS, GERBVIEW_FRAME::OnUpdateShowNegativeItems )
EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR,
GERBVIEW_FRAME::OnUpdateShowLayerManager )
EVT_UPDATE_UI( ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE, GERBVIEW_FRAME::OnUpdateSelectDCode )
EVT_UPDATE_UI( ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER,
GERBVIEW_FRAME::OnUpdateLayerSelectBox )
EVT_UPDATE_UI_RANGE( ID_TB_OPTIONS_SHOW_GBR_MODE_0, ID_TB_OPTIONS_SHOW_GBR_MODE_2,
GERBVIEW_FRAME::OnUpdateDrawMode )
END_EVENT_TABLE()
/* Handles the selection of tools, menu, and popup menu commands.
*/
void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
{
int id = event.GetId();
switch( id )
{
case ID_POPUP_PLACE_BLOCK:
case ID_POPUP_ZOOM_BLOCK:
break;
case ID_POPUP_CANCEL_CURRENT_COMMAND:
m_canvas->EndMouseCapture();
if( GetScreen()->m_BlockLocate.GetCommand() != BLOCK_IDLE )
{
/* Should not be executed, except bug */
GetScreen()->m_BlockLocate.SetCommand( BLOCK_IDLE );
GetScreen()->m_BlockLocate.SetState( STATE_NO_BLOCK );
GetScreen()->m_BlockLocate.ClearItemsList();
}
if( GetToolId() == ID_NO_TOOL_SELECTED )
SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
else
m_canvas->SetCursor( (wxStockCursor) m_canvas->GetCurrentCursor() );
break;
default:
m_canvas->EndMouseCapture();
break;
}
INSTALL_UNBUFFERED_DC( dc, m_canvas );
switch( id )
{
case ID_GERBVIEW_SET_PAGE_BORDER:
{
DIALOG_PAGE_SHOW_PAGE_BORDERS dlg( this );
if( dlg.ShowModal() == wxID_OK )
m_canvas->Refresh();
}
break;
case ID_GERBVIEW_GLOBAL_DELETE:
Erase_Current_DrawLayer( true );
ClearMsgPanel();
break;
case ID_NO_TOOL_SELECTED:
SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
break;
case ID_POPUP_CLOSE_CURRENT_TOOL:
SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
break;
case ID_POPUP_CANCEL_CURRENT_COMMAND:
break;
case ID_GERBVIEW_SHOW_LIST_DCODES:
Liste_D_Codes();
break;
case ID_POPUP_PLACE_BLOCK:
GetScreen()->m_BlockLocate.SetCommand( BLOCK_MOVE );
m_canvas->SetAutoPanRequest( false );
HandleBlockPlace( &dc );
break;
case ID_POPUP_ZOOM_BLOCK:
GetScreen()->m_BlockLocate.SetCommand( BLOCK_ZOOM );
GetScreen()->m_BlockLocate.SetMessageBlock( this );
HandleBlockEnd( &dc );
break;
default:
wxFAIL_MSG( wxT( "GERBVIEW_FRAME::Process_Special_Functions error" ) );
break;
}
}
void GERBVIEW_FRAME::OnSelectActiveDCode( wxCommandEvent& event )
{
GERBER_IMAGE* gerber_image = g_GERBER_List.GetGbrImage( getActiveLayer() );
if( gerber_image )
{
int tool = m_DCodeSelector->GetSelectedDCodeId();
if( tool != gerber_image->m_Selected_Tool )
{
gerber_image->m_Selected_Tool = tool;
m_canvas->Refresh();
}
}
}
void GERBVIEW_FRAME::OnSelectActiveLayer( wxCommandEvent& event )
{
int layer = getActiveLayer();
setActiveLayer( event.GetSelection() );
if( layer != getActiveLayer() )
{
if( m_LayersManager->OnLayerSelected() )
m_canvas->Refresh();
}
}
void GERBVIEW_FRAME::OnShowGerberSourceFile( wxCommandEvent& event )
{
int layer = getActiveLayer();
GERBER_IMAGE* gerber_layer = g_GERBER_List.GetGbrImage( layer );
if( gerber_layer )
{
wxString editorname = Pgm().GetEditorName();
if( !editorname.IsEmpty() )
{
wxFileName fn( gerber_layer->m_FileName );
ExecuteFile( this, editorname, QuoteFullPath( fn ) );
}
else
wxMessageBox( _( "No editor defined. Please select one" ) );
}
else
{
wxString msg;
msg.Printf( _( "No file loaded on the active layer %d" ), layer + 1 );
wxMessageBox( msg );
}
}
void GERBVIEW_FRAME::OnSelectDisplayMode( wxCommandEvent& event )
{
int oldMode = GetDisplayMode();
switch( event.GetId() )
{
case ID_TB_OPTIONS_SHOW_GBR_MODE_0:
SetDisplayMode( 0 );
break;
case ID_TB_OPTIONS_SHOW_GBR_MODE_1:
SetDisplayMode( 1 );
break;
case ID_TB_OPTIONS_SHOW_GBR_MODE_2:
SetDisplayMode( 2 );
break;
}
if( GetDisplayMode() != oldMode )
m_canvas->Refresh();
}
void GERBVIEW_FRAME::OnQuit( wxCommandEvent& event )
{
Close( true );
}
void GERBVIEW_FRAME::ShowChangedLanguage()
{
// call my base class
EDA_DRAW_FRAME::ShowChangedLanguage();
m_LayersManager->SetLayersManagerTabsText();
wxAuiPaneInfo& pane_info = m_auimgr.GetPane( m_LayersManager );
pane_info.Caption( _( "Visibles" ) );
m_auimgr.Update();
ReFillLayerWidget();
}
void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
{
int id = event.GetId();
bool state;
switch( id )
{
case ID_MENU_GERBVIEW_SHOW_HIDE_LAYERS_MANAGER_DIALOG:
state = ! m_show_layer_manager_tools;
id = ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR;
break;
default:
state = m_optionsToolBar->GetToolToggled( id );
break;
}
switch( id )
{
case ID_TB_OPTIONS_SHOW_POLAR_COORD:
m_DisplayOptions.m_DisplayPolarCood = state;
break;
case ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH:
m_DisplayOptions.m_DisplayFlashedItemsFill = not state;
m_canvas->Refresh( true );
break;
case ID_TB_OPTIONS_SHOW_LINES_SKETCH:
m_DisplayOptions.m_DisplayLinesFill = not state;
m_canvas->Refresh( true );
break;
case ID_TB_OPTIONS_SHOW_POLYGONS_SKETCH:
m_DisplayOptions.m_DisplayPolygonsFill = not state;
m_canvas->Refresh( true );
break;
case ID_TB_OPTIONS_SHOW_DCODES:
SetElementVisibility( DCODES_VISIBLE, state );
m_canvas->Refresh( true );
break;
case ID_TB_OPTIONS_SHOW_NEGATIVE_ITEMS:
SetElementVisibility( NEGATIVE_OBJECTS_VISIBLE, state );
m_canvas->Refresh( true );
break;
case ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR:
// show/hide auxiliary Vertical layers and visibility manager toolbar
m_show_layer_manager_tools = state;
m_auimgr.GetPane( wxT( "m_LayersManagerToolBar" ) ).Show( m_show_layer_manager_tools );
m_auimgr.Update();
GetMenuBar()->SetLabel( ID_MENU_GERBVIEW_SHOW_HIDE_LAYERS_MANAGER_DIALOG,
m_show_layer_manager_tools ?
_("Hide &Layers Manager" ) : _("Show &Layers Manager" ));
break;
default:
wxMessageBox( wxT( "GERBVIEW_FRAME::OnSelectOptionToolbar error" ) );
break;
}
}
|