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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012-2015 Miguel Angel Ajo Pelayo <miguelangel@nbee.es>
* Copyright (C) 2012-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2015 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 footprint_wizard_frame.cpp
*/
#include <fctsys.h>
#include <kiface_i.h>
#include <class_drawpanel.h>
#include <wxPcbStruct.h>
#include <3d_viewer.h>
#include <msgpanel.h>
#include <macros.h>
#include <class_board.h>
#include <class_module.h>
#include <module_editor_frame.h>
#include <pcbnew_id.h>
#include "footprint_wizard_frame.h"
#include <footprint_info.h>
#include <wx/grid.h>
#include <hotkeys.h>
#include <wildcards_and_files_ext.h>
#include <base_units.h>
BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME )
// Window events
EVT_CLOSE( FOOTPRINT_WIZARD_FRAME::OnCloseWindow )
EVT_SIZE( FOOTPRINT_WIZARD_FRAME::OnSize )
EVT_ACTIVATE( FOOTPRINT_WIZARD_FRAME::OnActivate )
// Toolbar events
EVT_TOOL( ID_FOOTPRINT_WIZARD_SELECT_WIZARD,
FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard )
EVT_TOOL( ID_FOOTPRINT_WIZARD_NEXT,
FOOTPRINT_WIZARD_FRAME::Process_Special_Functions )
EVT_TOOL( ID_FOOTPRINT_WIZARD_PREVIOUS,
FOOTPRINT_WIZARD_FRAME::Process_Special_Functions )
EVT_TOOL( ID_FOOTPRINT_WIZARD_DONE,
FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint )
EVT_TOOL( ID_FOOTPRINT_WIZARD_SHOW_3D_VIEW,
FOOTPRINT_WIZARD_FRAME::Show3D_Frame )
// listbox events
EVT_LISTBOX( ID_FOOTPRINT_WIZARD_PAGE_LIST, FOOTPRINT_WIZARD_FRAME::ClickOnPageList )
EVT_GRID_CMD_CELL_CHANGED( ID_FOOTPRINT_WIZARD_PARAMETER_LIST,
FOOTPRINT_WIZARD_FRAME::ParametersUpdated )
EVT_MENU( ID_SET_RELATIVE_OFFSET, FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset )
END_EVENT_TABLE()
// Column index to display parameters in m_parameterGrid
int FOOTPRINT_WIZARD_FRAME::m_columnPrmName = 0;
int FOOTPRINT_WIZARD_FRAME::m_columnPrmValue = 1;
int FOOTPRINT_WIZARD_FRAME::m_columnPrmUnit = 2;
#define FOOTPRINT_WIZARD_FRAME_NAME wxT( "FootprintWizard" )
FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway,
wxWindow* aParent, FRAME_T aFrameType ) :
PCB_BASE_FRAME( aKiway, aParent, aFrameType, _( "Footprint Wizard" ),
wxDefaultPosition, wxDefaultSize,
#ifdef __WINDOWS__
KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP,
#else
KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT,
#endif
FOOTPRINT_WIZARD_FRAME_NAME )
{
wxASSERT( aFrameType==FRAME_PCB_FOOTPRINT_WIZARD_MODAL );
// This frame is always show modal:
SetModal( true );
m_messagesFrame = NULL; // This windows will be created the first time a wizard is loaded
m_showAxis = true; // true to draw axis.
// Give an icon
wxIcon icon;
icon.CopyFromBitmap( KiBitmap( module_wizard_xpm) );
SetIcon( icon );
m_hotkeysDescrList = g_Module_Viewer_Hokeys_Descr;
m_wizardName.Empty();
SetBoard( new BOARD() );
// Ensure all layers and items are visible:
GetBoard()->SetVisibleAlls();
SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
GetScreen()->m_Center = true; // Center coordinate origins on screen.
LoadSettings( config() );
SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
// Set some display options here, because the FOOTPRINT_WIZARD_FRAME
// does not have a config menu to do that:
DISPLAY_OPTIONS* disp_opts = (DISPLAY_OPTIONS*) GetDisplayOptions();
disp_opts->m_DisplayPadIsol = false;
disp_opts->m_DisplayPadNum = true;
GetBoard()->SetElementVisibility( PCB_VISIBLE(NO_CONNECTS_VISIBLE), false );
GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
ReCreateHToolbar();
ReCreateVToolbar();
// Creates the parameter pages list
m_pageList = new wxListBox( this, ID_FOOTPRINT_WIZARD_PAGE_LIST,
wxDefaultPosition, wxDefaultSize,
0, NULL, wxLB_HSCROLL );
// Creates the The list of parameters for the current parameter page
initParameterGrid();
ReCreatePageList();
DisplayWizardInfos();
m_auimgr.SetManagedWindow( this );
EDA_PANEINFO horiztb;
horiztb.HorizontalToolbarPane();
EDA_PANEINFO info;
info.InfoToolbarPane();
EDA_PANEINFO mesg;
mesg.MessageToolbarPane();
// Manage main toolbal
m_auimgr.AddPane( m_mainToolBar, wxAuiPaneInfo( horiztb ).
Name( wxT ("m_mainToolBar" ) ).Top().Row( 0 ) );
// Manage the left window (list of parameter pages)
EDA_PANEINFO paneList;
paneList.InfoToolbarPane().Name( wxT( "m_pageList" ) ).Left().Row( 0 );
m_auimgr.AddPane( m_pageList, wxAuiPaneInfo( paneList ) );
// Manage the parameters grid editor for the current parameter page
EDA_PANEINFO panePrms;
panePrms.InfoToolbarPane().Name( wxT( "m_parameterGrid" ) ).Left().Row( 1 );
m_auimgr.AddPane( m_parameterGrid, wxAuiPaneInfo( panePrms ) );
// Manage the draw panel
m_auimgr.AddPane( m_canvas,
wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() );
// Manage the message panel
m_auimgr.AddPane( m_messagePanel,
wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom().Layer(1) );
// Gives a min size and the last saved size to left windows
m_auimgr.GetPane( m_pageList ).MinSize( wxSize(60, -1 ) );
m_auimgr.GetPane( m_pageList ).BestSize( wxSize(m_pageListWidth, -1) );
m_auimgr.GetPane( m_parameterGrid ).MinSize( wxSize( 120, -1 ) );
m_auimgr.GetPane( m_parameterGrid ).BestSize( wxSize(m_parameterGridWidth, -1) );
m_auimgr.Update();
// Now Drawpanel is sized, we can use BestZoom to show the component (if any)
#ifdef USE_WX_GRAPHICS_CONTEXT
GetScreen()->SetZoom( BestZoom() );
#else
Zoom_Automatique( false );
#endif
// Do not Run a dialog here: on some Window Managers, it creates issues.
// Reason: the FOOTPRINT_WIZARD_FRAME is run as modal;
// It means the call to FOOTPRINT_WIZARD_FRAME::ShowModal will change the
// Event Loop Manager, and stop the one created by the dialog.
// It does not happen on all W.M., perhaps due to the way the order events are called
// SelectFootprintWizard();
}
FOOTPRINT_WIZARD_FRAME::~FOOTPRINT_WIZARD_FRAME()
{
if( m_Draw3DFrame )
m_Draw3DFrame->Destroy();
}
void FOOTPRINT_WIZARD_FRAME::OnCloseWindow( wxCloseEvent& Event )
{
if( m_messagesFrame )
m_messagesFrame->SaveSettings();
SaveSettings( config() );
if( IsModal() )
{
// Only dismiss a modal frame once, so that the return values set by
// the prior DismissModal() are not bashed for ShowModal().
if( !IsDismissed() )
DismissModal( false );
}
else
{
Destroy();
}
}
void FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint( wxCommandEvent& aEvent )
{
DismissModal( true );
Close();
}
void FOOTPRINT_WIZARD_FRAME::OnSize( wxSizeEvent& SizeEv )
{
if( m_auimgr.GetManagedWindow() )
m_auimgr.Update();
SizeEv.Skip();
}
void FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset( wxCommandEvent& event )
{
GetScreen()->m_O_Curseur = GetCrossHairPosition();
UpdateStatusBar();
}
void FOOTPRINT_WIZARD_FRAME::initParameterGrid()
{
// Prepare the grid where parameters are displayed
m_parameterGrid = new wxGrid( this, ID_FOOTPRINT_WIZARD_PARAMETER_LIST );
m_parameterGrid->CreateGrid( 0, 3 );
// Columns
m_parameterGrid->SetColLabelValue( m_columnPrmName, _( "Parameter" ) );
m_parameterGrid->SetColLabelValue( m_columnPrmValue, _( "Value" ) );
m_parameterGrid->SetColLabelValue( m_columnPrmUnit, _( "Units" ) );
m_parameterGrid->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTRE );
m_parameterGrid->AutoSizeColumns();
// Rows
m_parameterGrid->AutoSizeRows();
m_parameterGrid->SetRowLabelSize( 25 );
m_parameterGrid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
}
void FOOTPRINT_WIZARD_FRAME::ReCreatePageList()
{
if( m_pageList == NULL )
return;
FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
if( !footprintWizard )
return;
m_pageList->Clear();
int max_page = footprintWizard->GetNumParameterPages();
for( int i = 0; i<max_page; i++ )
{
wxString name = footprintWizard->GetParameterPageName( i );
m_pageList->Append( name );
}
m_pageList->SetSelection( 0, true );
ReCreateParameterList();
ReCreateHToolbar();
DisplayWizardInfos();
m_canvas->Refresh();
}
void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
{
if( m_parameterGrid == NULL )
return;
FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
if( footprintWizard == NULL )
return;
int page = m_pageList->GetSelection();
if( page<0 )
return;
m_parameterGrid->ClearGrid();
// Get the list of names, values, and types
wxArrayString fpList = footprintWizard->GetParameterNames( page );
wxArrayString fvList = footprintWizard->GetParameterValues( page );
wxArrayString ptList = footprintWizard->GetParameterTypes( page );
// Dimension the wxGrid
if( m_parameterGrid->GetNumberRows() > 0 )
m_parameterGrid->DeleteRows( 0, m_parameterGrid->GetNumberRows() );
m_parameterGrid->AppendRows( fpList.size() );
wxString value, units;
for( unsigned int i = 0; i< fpList.size(); i++ )
{
value = fvList[i];
m_parameterGrid->SetCellValue( i, m_columnPrmName, fpList[i] );
m_parameterGrid->SetReadOnly( i, m_columnPrmName );
if( ptList[i]==wxT( "IU" ) )
{
LOCALE_IO toggle;
// We are handling internal units, so convert them to the current
// system selected units and store into value.
double dValue;
value.ToDouble( &dValue );
dValue = To_User_Unit( g_UserUnit, dValue );
if( g_UserUnit==INCHES ) // we convert inches into mils for more detail
{
dValue = dValue * 1000.0;
units = wxT( "mils" );
}
else if( g_UserUnit==MILLIMETRES )
{
units = wxT( "mm" );
}
// Use Double2Str to build the string, because useless trailing 0
// are removed. The %f format does not remove them
std::string s = Double2Str( dValue );
value = FROM_UTF8( s.c_str() );
}
else if( ptList[i]==wxT( "UNITS" ) ) // 1,2,3,4,5 ... N
{
units = wxT( "" );
}
m_parameterGrid->SetCellValue( i, m_columnPrmValue, value );
m_parameterGrid->SetCellValue( i, m_columnPrmUnit, units );
m_parameterGrid->SetReadOnly( i, m_columnPrmUnit );
}
m_parameterGrid->AutoSizeColumns();
}
void FOOTPRINT_WIZARD_FRAME::ClickOnPageList( wxCommandEvent& event )
{
int ii = m_pageList->GetSelection();
if( ii < 0 )
return;
ReCreateParameterList();
m_canvas->Refresh();
DisplayWizardInfos();
}
#define PAGE_LIST_WIDTH_KEY wxT( "Fpwizard_Pagelist_width" )
#define PARAMLIST_WIDTH_KEY wxT( "Fpwizard_Paramlist_width" )
void FOOTPRINT_WIZARD_FRAME::LoadSettings( wxConfigBase* aCfg )
{
EDA_DRAW_FRAME::LoadSettings( aCfg );
aCfg->Read( PAGE_LIST_WIDTH_KEY, &m_pageListWidth, 100 );
aCfg->Read( PARAMLIST_WIDTH_KEY, &m_parameterGridWidth, 200 );
// Set parameters to a reasonable value.
if( m_pageListWidth > m_FrameSize.x / 3 )
m_pageListWidth = m_FrameSize.x / 3;
if( m_parameterGridWidth > m_FrameSize.x / 2 )
m_parameterGridWidth = m_FrameSize.x / 2;
}
void FOOTPRINT_WIZARD_FRAME::SaveSettings( wxConfigBase* aCfg )
{
EDA_DRAW_FRAME::SaveSettings( aCfg );
aCfg->Write( PAGE_LIST_WIDTH_KEY, m_pageList->GetSize().x );
aCfg->Write( PARAMLIST_WIDTH_KEY, m_parameterGrid->GetSize().x );
}
void FOOTPRINT_WIZARD_FRAME::OnActivate( wxActivateEvent& event )
{
EDA_DRAW_FRAME::OnActivate( event );
// Ensure we do not have old selection:
if( !event.GetActive() )
return;
#if 0
// Currently, we do not have a way to see if a Python wizard has changed,
// therefore the lists of parameters and option has to be rebuilt
// This code could be enabled when this way exists
bool footprintWizardsChanged = false;
if( footprintWizardsChanged )
{
// If we are here, the library list has changed, rebuild it
ReCreatePageList();
DisplayWizardInfos();
}
#endif
}
bool FOOTPRINT_WIZARD_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey )
{
bool eventHandled = true;
// Filter out the 'fake' mouse motion after a keyboard movement
if( !aHotKey && m_movingCursorWithKeyboard )
{
m_movingCursorWithKeyboard = false;
return false;
}
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
cmd.SetEventObject( this );
wxPoint pos = aPosition;
wxPoint oldpos = GetCrossHairPosition();
GeneralControlKeyMovement( aHotKey, &pos, true );
switch( aHotKey )
{
case WXK_F1:
cmd.SetId( ID_POPUP_ZOOM_IN );
GetEventHandler()->ProcessEvent( cmd );
break;
case WXK_F2:
cmd.SetId( ID_POPUP_ZOOM_OUT );
GetEventHandler()->ProcessEvent( cmd );
break;
case WXK_F3:
cmd.SetId( ID_ZOOM_REDRAW );
GetEventHandler()->ProcessEvent( cmd );
break;
case WXK_F4:
cmd.SetId( ID_POPUP_ZOOM_CENTER );
GetEventHandler()->ProcessEvent( cmd );
break;
case WXK_HOME:
cmd.SetId( ID_ZOOM_PAGE );
GetEventHandler()->ProcessEvent( cmd );
break;
case ' ':
GetScreen()->m_O_Curseur = GetCrossHairPosition();
break;
default:
eventHandled = false;
}
SetCrossHairPosition( pos );
RefreshCrossHair( oldpos, aPosition, aDC );
UpdateStatusBar(); // Display new cursor coordinates
return eventHandled;
}
void FOOTPRINT_WIZARD_FRAME::Show3D_Frame( wxCommandEvent& event )
{
if( m_Draw3DFrame )
{
// Raising the window does not show the window on Windows if iconized.
// This should work on any platform.
if( m_Draw3DFrame->IsIconized() )
m_Draw3DFrame->Iconize( false );
m_Draw3DFrame->Raise();
// Raising the window does not set the focus on Linux. This should work on any platform.
if( wxWindow::FindFocus() != m_Draw3DFrame )
m_Draw3DFrame->SetFocus();
return;
}
m_Draw3DFrame = new EDA_3D_FRAME( &Kiway(), this, wxEmptyString );
Update3D_Frame( false );
m_Draw3DFrame->Raise(); // Needed with some Window Managers
m_Draw3DFrame->Show( true );
}
/**
* Function Update3D_Frame
* must be called after a footprint selection
* Updates the 3D view and 3D frame title.
*/
void FOOTPRINT_WIZARD_FRAME::Update3D_Frame( bool aForceReloadFootprint )
{
if( m_Draw3DFrame == NULL )
return;
wxString frm3Dtitle;
frm3Dtitle.Printf( _( "ModView: 3D Viewer [%s]" ), GetChars( m_wizardName ) );
m_Draw3DFrame->SetTitle( frm3Dtitle );
if( aForceReloadFootprint )
{
m_Draw3DFrame->ReloadRequest();
// Force 3D screen refresh immediately
if( GetBoard()->m_Modules )
m_Draw3DFrame->NewDisplay();
}
}
void FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar()
{
wxString msg;
if( !m_mainToolBar )
{
m_mainToolBar = new wxAuiToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_HORZ_LAYOUT );
// Set up toolbar
m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_SELECT_WIZARD, wxEmptyString,
KiBitmap( module_wizard_xpm ),
_( "Select the wizard script to load and run" ) );
m_mainToolBar->AddSeparator();
m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_PREVIOUS, wxEmptyString,
KiBitmap( lib_previous_xpm ),
_( "Select previous parameters page" ) );
m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_NEXT, wxEmptyString,
KiBitmap( lib_next_xpm ),
_( "Select next parameters page" ) );
m_mainToolBar->AddSeparator();
m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_SHOW_3D_VIEW, wxEmptyString,
KiBitmap( three_d_xpm ),
_( "Show footprint in 3D viewer" ) );
m_mainToolBar->AddSeparator();
msg = AddHotkeyName( _( "Zoom in" ), g_Module_Editor_Hokeys_Descr,
HK_ZOOM_IN, IS_COMMENT );
m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString,
KiBitmap( zoom_in_xpm ), msg );
msg = AddHotkeyName( _( "Zoom out" ), g_Module_Editor_Hokeys_Descr,
HK_ZOOM_OUT, IS_COMMENT );
m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString,
KiBitmap( zoom_out_xpm ), msg );
msg = AddHotkeyName( _( "Redraw view" ), g_Module_Editor_Hokeys_Descr,
HK_ZOOM_REDRAW, IS_COMMENT );
m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString,
KiBitmap( zoom_redraw_xpm ), msg );
msg = AddHotkeyName( _( "Zoom auto" ), g_Module_Editor_Hokeys_Descr,
HK_ZOOM_AUTO, IS_COMMENT );
m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString,
KiBitmap( zoom_fit_in_page_xpm ), msg );
// The footprint wizard always can export the current footprint
m_mainToolBar->AddSeparator();
m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_DONE,
wxEmptyString, KiBitmap( export_footprint_names_xpm ),
_( "Export the footprint to the editor" ) );
// after adding the buttons to the toolbar, must call Realize() to
// reflect the changes
m_mainToolBar->Realize();
}
m_mainToolBar->Refresh();
}
void FOOTPRINT_WIZARD_FRAME::ReCreateVToolbar()
{
// Currently, there is no vertical toolbar
}
// frame to display messages from footprint builder scripts
FOOTPRINT_WIZARD_MESSAGES::FOOTPRINT_WIZARD_MESSAGES( FOOTPRINT_WIZARD_FRAME* aParent, wxConfigBase* aCfg ) :
wxMiniFrame( aParent, wxID_ANY, _( "Footprint Builder Messages" ),
wxDefaultPosition, wxDefaultSize,
wxCAPTION | wxRESIZE_BORDER | wxFRAME_FLOAT_ON_PARENT )
{
m_canClose = false;
wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
SetSizer( bSizer );
m_messageWindow = new wxTextCtrl( this, wxID_ANY, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE|wxTE_READONLY );
bSizer->Add( m_messageWindow, 1, wxEXPAND, 0 );
m_config = aCfg;
LoadSettings();
SetSize( m_position.x, m_position.y, m_size.x, m_size.y );
m_messageWindow->SetMinSize( wxSize( 350, 250 ) );
Layout();
bSizer->SetSizeHints( this );
}
FOOTPRINT_WIZARD_MESSAGES::~FOOTPRINT_WIZARD_MESSAGES()
{
}
BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_MESSAGES, wxMiniFrame )
EVT_CLOSE( FOOTPRINT_WIZARD_MESSAGES::OnCloseMsgWindow )
END_EVENT_TABLE()
void FOOTPRINT_WIZARD_MESSAGES::OnCloseMsgWindow( wxCloseEvent& aEvent )
{
if( !m_canClose )
aEvent.Veto();
else
aEvent.Skip();
}
void FOOTPRINT_WIZARD_MESSAGES::PrintMessage( const wxString& aMessage )
{
m_messageWindow->SetValue( aMessage );
}
void FOOTPRINT_WIZARD_MESSAGES::ClearScreen()
{
m_messageWindow->Clear();
}
#define MESSAGE_BOX_POSX_KEY wxT( "Fpwizard_Msg_PosX" )
#define MESSAGE_BOX_POSY_KEY wxT( "Fpwizard_Msg_PosY" )
#define MESSAGE_BOX_SIZEX_KEY wxT( "Fpwizard_Msg_SIZEX" )
#define MESSAGE_BOX_SIZEY_KEY wxT( "Fpwizard_Msg_SIZEY" )
void FOOTPRINT_WIZARD_MESSAGES::SaveSettings()
{
if( !IsIconized() )
{
m_position = GetPosition();
m_size = GetSize();
}
m_config->Write( MESSAGE_BOX_POSX_KEY, m_position.x );
m_config->Write( MESSAGE_BOX_POSY_KEY, m_position.y );
m_config->Write( MESSAGE_BOX_SIZEX_KEY, m_size.x );
m_config->Write( MESSAGE_BOX_SIZEY_KEY, m_size.y );
m_canClose = false; // close event now allowed
}
void FOOTPRINT_WIZARD_MESSAGES::LoadSettings()
{
m_config->Read( MESSAGE_BOX_POSX_KEY, &m_position.x, -1 );
m_config->Read( MESSAGE_BOX_POSY_KEY, &m_position.y, -1 );
m_config->Read( MESSAGE_BOX_SIZEX_KEY, &m_size.x, 350 );
m_config->Read( MESSAGE_BOX_SIZEY_KEY, &m_size.y, 250 );
}
|