File: dialog_eeschema_config.cpp

package info (click to toggle)
kicad 0.0.20060829-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 56,544 kB
  • ctags: 9,194
  • sloc: cpp: 88,990; ansic: 4,790; makefile: 88; sh: 39
file content (455 lines) | stat: -rw-r--r-- 13,947 bytes parent folder | download
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
/////////////////////////////////////////////////////////////////////////////
// Name:        dialog_eeschema_config.cpp
// Purpose:     
// Author:      jean-pierre Charras
// Modified by: 
// Created:     17/02/2006 21:14:46
// RCS-ID:      
// Copyright:   License GNU
// Licence:     
/////////////////////////////////////////////////////////////////////////////

// Generated by DialogBlocks (unregistered), 17/02/2006 21:14:46

#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "dialog_eeschema_config.h"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
////@end includes
#include "fctsys.h"

#include "common.h"
#include "program.h"
#include "libcmp.h"
#include "general.h"

#include "protos.h"
#include "netlist.h"

#include "id.h"

#include "dialog_eeschema_config.h"

////@begin XPM images
////@end XPM images

/******************************************************************/
void WinEDA_SchematicFrame::InstallConfigFrame(const wxPoint & pos)
/******************************************************************/
{
	KiConfigEeschemaFrame * CfgFrame = new KiConfigEeschemaFrame(this);
	CfgFrame->ShowModal(); CfgFrame->Destroy();
}


/*!
 * KiConfigEeschemaFrame type definition
 */

IMPLEMENT_DYNAMIC_CLASS( KiConfigEeschemaFrame, wxDialog )

/*!
 * KiConfigEeschemaFrame event table definition
 */

BEGIN_EVENT_TABLE( KiConfigEeschemaFrame, wxDialog )

////@begin KiConfigEeschemaFrame event table entries
    EVT_CLOSE( KiConfigEeschemaFrame::OnCloseWindow )

    EVT_BUTTON( SAVE_CFG, KiConfigEeschemaFrame::OnSaveCfgClick )

    EVT_RADIOBOX( FORMAT_NETLIST, KiConfigEeschemaFrame::OnFormatNetlistSelected )

    EVT_BUTTON( DEL_LIB, KiConfigEeschemaFrame::OnDelLibClick )

    EVT_BUTTON( ADD_LIB, KiConfigEeschemaFrame::OnAddLibClick )

    EVT_BUTTON( INSERT_LIB, KiConfigEeschemaFrame::OnInsertLibClick )

////@end KiConfigEeschemaFrame event table entries

END_EVENT_TABLE()

/*!
 * KiConfigEeschemaFrame constructors
 */

KiConfigEeschemaFrame::KiConfigEeschemaFrame( )
{
}

KiConfigEeschemaFrame::KiConfigEeschemaFrame( WinEDA_SchematicFrame* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
wxString msg;

	m_Parent = parent;
	m_LibListChanged = FALSE;

    Create(parent, id, caption, pos, size, style);
	
	msg = _("from ") + EDA_Appl->m_CurrentOptionFile;
	SetTitle(msg);
	SetFormatsNetListes();
	m_ListLibr->InsertItems(g_LibName_List, 0);
	m_LibDirCtrl->SetValue( g_UserLibDirBuffer );
}

/*!
 * KiConfigEeschemaFrame creator
 */

bool KiConfigEeschemaFrame::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin KiConfigEeschemaFrame member initialisation
    m_NetFormatBox = NULL;
    m_FileExtList = NULL;
    m_ListLibr = NULL;
    m_LibDirCtrl = NULL;
////@end KiConfigEeschemaFrame member initialisation

////@begin KiConfigEeschemaFrame creation
    SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
    wxDialog::Create( parent, id, caption, pos, size, style );

    CreateControls();
    GetSizer()->Fit(this);
    GetSizer()->SetSizeHints(this);
    Centre();
////@end KiConfigEeschemaFrame creation
    return true;
}

/*!
 * Control creation for KiConfigEeschemaFrame
 */

void KiConfigEeschemaFrame::CreateControls()
{    
	SetFont(*g_DialogFont);

////@begin KiConfigEeschemaFrame content construction
    // Generated by DialogBlocks, 18/02/2006 09:45:23 (unregistered)

    KiConfigEeschemaFrame* itemDialog1 = this;

    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
    itemDialog1->SetSizer(itemBoxSizer2);

    wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);

    wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
    itemBoxSizer3->Add(itemBoxSizer4, 0, wxGROW|wxALL, 5);

    wxButton* itemButton5 = new wxButton( itemDialog1, SAVE_CFG, _("Save Cfg"), wxDefaultPosition, wxDefaultSize, 0 );
    itemButton5->SetForegroundColour(wxColour(204, 0, 0));
    itemBoxSizer4->Add(itemButton5, 0, wxGROW|wxALL, 5);

    itemBoxSizer4->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);

    wxString m_NetFormatBoxStrings[] = {
        _("PcbNew"),
        _("&OrcadPcb2"),
        _("&CadStar"),
        _("&Spice"),
        _("Other")
    };
    m_NetFormatBox = new wxRadioBox( itemDialog1, FORMAT_NETLIST, _("NetList Formats:"), wxDefaultPosition, wxDefaultSize, 5, m_NetFormatBoxStrings, 1, wxRA_SPECIFY_COLS );
    itemBoxSizer4->Add(m_NetFormatBox, 0, wxGROW|wxALL, 5);

    itemBoxSizer4->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);

    wxStaticBox* itemStaticBoxSizer9Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Files ext:"));
    m_FileExtList = new wxStaticBoxSizer(itemStaticBoxSizer9Static, wxVERTICAL);
    itemBoxSizer4->Add(m_FileExtList, 0, wxGROW|wxALL, 5);

    wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxVERTICAL);
    itemBoxSizer3->Add(itemBoxSizer10, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);

    wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer10->Add(itemBoxSizer11, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT|wxBOTTOM, 5);

    wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxVERTICAL);
    itemBoxSizer11->Add(itemBoxSizer12, 0, wxALIGN_CENTER_VERTICAL, 5);

    wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer12->Add(itemBoxSizer13, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);

    wxButton* itemButton14 = new wxButton( itemDialog1, DEL_LIB, _("Del"), wxDefaultPosition, wxDefaultSize, 0 );
    itemButton14->SetForegroundColour(wxColour(204, 0, 0));
    itemBoxSizer13->Add(itemButton14, 0, wxGROW|wxALL, 5);

    wxButton* itemButton15 = new wxButton( itemDialog1, ADD_LIB, _("Add"), wxDefaultPosition, wxDefaultSize, 0 );
    itemButton15->SetForegroundColour(wxColour(0, 128, 0));
    itemBoxSizer13->Add(itemButton15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxButton* itemButton16 = new wxButton( itemDialog1, INSERT_LIB, _("Ins"), wxDefaultPosition, wxDefaultSize, 0 );
    itemButton16->SetForegroundColour(wxColour(0, 0, 255));
    itemBoxSizer13->Add(itemButton16, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxBoxSizer* itemBoxSizer17 = new wxBoxSizer(wxVERTICAL);
    itemBoxSizer12->Add(itemBoxSizer17, 0, wxGROW|wxALL, 5);

    wxStaticText* itemStaticText18 = new wxStaticText( itemDialog1, wxID_STATIC, _("Libraries"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStaticText18->SetForegroundColour(wxColour(204, 0, 0));
    itemBoxSizer17->Add(itemStaticText18, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);

    wxString* m_ListLibrStrings = NULL;
    m_ListLibr = new wxListBox( itemDialog1, ID_LIST_LIBS, wxDefaultPosition, wxSize(-1, 300), 0, m_ListLibrStrings, wxLB_SINGLE );
    itemBoxSizer17->Add(m_ListLibr, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);

    wxStaticText* itemStaticText20 = new wxStaticText( itemDialog1, wxID_STATIC, _("Library files path:"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStaticText20->SetForegroundColour(wxColour(204, 0, 0));
    itemBoxSizer2->Add(itemStaticText20, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);

    m_LibDirCtrl = new wxTextCtrl( itemDialog1, ID_TEXTCTRL, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer2->Add(m_LibDirCtrl, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);

////@end KiConfigEeschemaFrame content construction

wxString msg = _("Cmp file Ext: ") + g_NetCmpExtBuffer;
    wxStaticText * text = new wxStaticText( itemDialog1, -1, msg, wxDefaultPosition, wxDefaultSize, 0 );
    m_FileExtList->Add(text, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);

	msg = _("Net file Ext: ") + g_NetExtBuffer;
    text = new wxStaticText( itemDialog1, -1, msg, wxDefaultPosition, wxDefaultSize, 0 );
    m_FileExtList->Add(text, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);

	msg = _("Library file Ext: ") + g_LibExtBuffer;
    text = new wxStaticText( itemDialog1, -1, msg, wxDefaultPosition, wxDefaultSize, 0 );
    m_FileExtList->Add(text, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);

	msg = _("Symbol file Ext: ") + g_SymbolExtBuffer;
    text = new wxStaticText( itemDialog1, -1, msg, wxDefaultPosition, wxDefaultSize, 0 );
    m_FileExtList->Add(text, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);

	msg = _("Schematic file Ext: ") + g_SchExtBuffer;
    text = new wxStaticText( itemDialog1, -1, msg, wxDefaultPosition, wxDefaultSize, 0 );
    m_FileExtList->Add(text, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);
}

/*!
 * Should we show tooltips?
 */

bool KiConfigEeschemaFrame::ShowToolTips()
{
    return true;
}

/*!
 * Get bitmap resources
 */

wxBitmap KiConfigEeschemaFrame::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin KiConfigEeschemaFrame bitmap retrieval
    wxUnusedVar(name);
    return wxNullBitmap;
////@end KiConfigEeschemaFrame bitmap retrieval
}

/*!
 * Get icon resources
 */

wxIcon KiConfigEeschemaFrame::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin KiConfigEeschemaFrame icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end KiConfigEeschemaFrame icon retrieval
}



/**************************************************************/
void KiConfigEeschemaFrame::OnCloseWindow(wxCloseEvent & event)
/**************************************************************/
{
	ChangeSetup();
	if ( m_LibListChanged )
	{
		LoadLibraries(m_Parent);
		if ( m_Parent->m_Parent->ViewlibFrame )
			m_Parent->m_Parent->ViewlibFrame->ReCreateListLib();
	}
	EndModal(0);
}


/*********************************************/
void KiConfigEeschemaFrame::ChangeSetup(void)
/*********************************************/
{
	g_UserLibDirBuffer = m_LibDirCtrl->GetValue();
	SetRealLibraryPath( wxT("library") );
}



/********************************************************/
void KiConfigEeschemaFrame::LibDelFct(wxCommandEvent& event)
/********************************************************/
{
int ii;

	ii = m_ListLibr->GetSelection();
	if ( ii < 0 ) return;

	g_LibName_List.RemoveAt(ii);
	m_ListLibr->Clear();
	m_ListLibr->InsertItems(g_LibName_List, 0);
	m_LibListChanged = TRUE;
}

/****************************************************************/
void KiConfigEeschemaFrame::AddOrInsertLibrary(wxCommandEvent& event)
/****************************************************************/
/* Insert or add a library to the existing library list:
	New library is put in list before (insert) or after (add)
	the selection
*/
{
int ii;
wxString FullLibName,ShortLibName, Mask;

	ii = m_ListLibr->GetSelection();
	if ( ii < 0 ) ii = 0;
	ChangeSetup();
	if( event.GetId() == ADD_LIB)
	{
		if( g_LibName_List.GetCount() != 0 ) ii ++;	/* Add after selection */
	}

	Mask = wxT("*") + g_LibExtBuffer;
	FullLibName = EDA_FileSelector( _("Library files:"),
				g_RealLibDirBuffer,		/* Chemin par defaut */
				wxEmptyString,					/* nom fichier par defaut */
				g_LibExtBuffer,		/* extension par defaut */
				Mask,				/* Masque d'affichage */
				this,
				wxOPEN,
				TRUE
				);

	if ( FullLibName.IsEmpty() ) return;

	ShortLibName = MakeReducedFileName(FullLibName,g_RealLibDirBuffer,g_LibExtBuffer);

	//Add or insert new library name
	if (FindLibrary(ShortLibName) == NULL)
	{
		m_LibListChanged = TRUE;
		g_LibName_List.Insert(ShortLibName, ii);
		m_ListLibr->Clear();
		m_ListLibr->InsertItems(g_LibName_List, 0);
	}

	else DisplayError(this, _("Library already in use"));

}



/****************************************************/
void KiConfigEeschemaFrame::SetFormatsNetListes(void)
/****************************************************/
/* Adjust the m_NetFormatBox current selection, according to the current netlist format*/

{
	switch( g_NetFormat )
		{
		case NET_TYPE_NOT_INIT:
		case NET_TYPE_PCBNEW:
			m_NetFormatBox->SetSelection(0);
			break;

		case NET_TYPE_ORCADPCB2:
			m_NetFormatBox->SetSelection(1);
			break;

		case NET_TYPE_CADSTAR:
			m_NetFormatBox->SetSelection(2);
			break;

		case NET_TYPE_SPICE:
			m_NetFormatBox->SetSelection(3);
			break;

		default:
			m_NetFormatBox->SetSelection(4);
			break;
		}
}

/*!
 * wxEVT_COMMAND_RADIOBOX_SELECTED event handler for FORMAT_NETLIST
 */

void KiConfigEeschemaFrame::OnFormatNetlistSelected( wxCommandEvent& event )
{
int ii;

	ii = m_NetFormatBox->GetSelection();
	if ( ii == 0 ) g_NetFormat = NET_TYPE_PCBNEW;
	if ( ii == 1 ) g_NetFormat = NET_TYPE_ORCADPCB2;
	else if ( ii == 2 ) g_NetFormat = NET_TYPE_CADSTAR;
	else if ( ii == 3 ) g_NetFormat = NET_TYPE_SPICE;
	else if ( g_NetFormat < NET_TYPE_CUSTOM1 ) g_NetFormat = NET_TYPE_CUSTOM1;
}

/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for DEL_LIB
 */

void KiConfigEeschemaFrame::OnDelLibClick( wxCommandEvent& event )
{
	LibDelFct(event);
}

/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ADD_LIB
 */

void KiConfigEeschemaFrame::OnAddLibClick( wxCommandEvent& event )
{
	AddOrInsertLibrary(event);
}

/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for INSERT_LIB
 */

void KiConfigEeschemaFrame::OnInsertLibClick( wxCommandEvent& event )
{
	AddOrInsertLibrary(event);
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for SAVE_CFG
 */

void KiConfigEeschemaFrame::OnSaveCfgClick( wxCommandEvent& event )
{
	ChangeSetup();
	m_Parent->Save_Config(this);
}