-
-
Notifications
You must be signed in to change notification settings - Fork 500
/
Copy pathkicad.cpp
379 lines (288 loc) · 12 KB
/
kicad.cpp
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
/*****************************************************************************/
/**
* @file kicad.cpp
* @brief Main kicad library manager file
*/
/*****************************************************************************/
#ifdef __GNUG__
#pragma implementation
#endif
#define MAIN
#define eda_global
#include "fctsys.h"
#include <wx/image.h>
#ifdef USE_SPLASH_IMAGE
#define SPLASH_IMAGE logo_kicad.png
#include "wx/splash.h"
#include "wx/mediactrl.h"
#endif
#include <wx/button.h>
#include "wxstruct.h"
#include "common.h"
#include "bitmaps.h"
#include "kicad.h"
#include "macros.h"
#ifdef KICAD_PYTHON
#include <pyhandler.h>
#endif
/* Export functions */
/* Import functions */
char *GetFileName(char *FullPathName);
void ShowLogo(char * FonteFileName);
/* Local functions */
/************************************/
/* Called to initialize the program */
/************************************/
// Create a new application object
IMPLEMENT_APP(WinEDA_App)
#ifdef KICAD_PYTHON
using namespace boost::python;
/*****************************************************************************/
// Global functions:
/*****************************************************************************/
static WinEDA_MainFrame& GetMainFrame() { return *( wxGetApp().m_MainFrame ); }
static void WinEDAPrint( str msg ) { GetMainFrame().PrintMsg( PyHandler::MakeStr( msg ) + wxT("\n") ); }
static void WinEDAClear() { GetMainFrame().ClearMsg(); }
static object GetTypeExt( enum TreeFileType type ) { return PyHandler::Convert( WinEDA_PrjFrame::GetFileExt( type ) ); }
/*****************************************************************************/
// WinEDA_MainFrame Special binding functions:
// (one line functions are simple wrappers)
/*****************************************************************************/
object WinEDA_MainFrame::GetPrjName() const { return PyHandler::Convert( m_PrjFileName ); }
object WinEDA_MainFrame::ToWx() { return object( handle<>( borrowed( wxPyMake_wxObject( this, false ) ) ) ); }
WinEDA_PrjFrame* WinEDA_MainFrame::GetTree() const { return m_LeftWin; }
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_MainFrame::AddFastLaunchPy( object & button )
/*****************************************************************************/
{
wxBitmapButton * btn;
bool success = wxPyConvertSwigPtr( button.ptr(), (void**)&btn, _T("wxBitmapButton"));
if(!success)
return;
Py_INCREF( button.ptr() );
btn->Reparent( m_CommandWin );
m_CommandWin->AddFastLaunch( btn );
}
/*****************************************************************************/
// WinEDA_PrjFrame Special binding functions:
// (one line functions are simple wrappers)
/*****************************************************************************/
// TODO To WxWidgets ?
object WinEDA_PrjFrame::ToWx()
{ return object( handle<>( borrowed( wxPyMake_wxObject( this, false ) ) ) ); }
// TODO Get ?
object WinEDA_PrjFrame::GetFtExPy( enum TreeFileType type ) const
{ return PyHandler::Convert( GetFileExt( type ) ); }
// Get python menu
object WinEDA_PrjFrame::GetMenuPy( enum TreeFileType type )
{ return object( handle<>( borrowed( wxPyMake_wxObject( GetContextMenu( (int) type ), false ) ) ) ); }
// Get tree control
object WinEDA_PrjFrame::GetTreeCtrl()
{ return object( handle<>( borrowed( wxPyMake_wxObject( m_TreeProject, false ) ) ) ); }
// Get current menu
object WinEDA_PrjFrame::GetCurrentMenu()
{ return object( handle<>( borrowed( wxPyMake_wxObject( m_PopupMenu, false ) ) ) ); }
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::NewFilePy( const str & name,
enum TreeFileType type,
object & id )
/*****************************************************************************/
{
wxTreeItemId root;
if (! wxPyConvertSwigPtr( id.ptr(), (void**)&root, _T("wxTreeItemId") ) ) return;
NewFile( PyHandler::MakeStr( name ), type, root );
}
/**
* @brief Add a file to the tree under root, or m_root if conversion is wrong
*/
/*****************************************************************************/
void WinEDA_PrjFrame::AddFilePy( const str & file, object & root )
/*****************************************************************************/
{
wxTreeItemId * theroot = &m_root;
if ( !wxPyConvertSwigPtr( root.ptr(), (void**)&root, _T("wxTreeItemId") ) )
{
theroot = &m_root;
}
AddFile( PyHandler::MakeStr( file ), *theroot );
}
/**
* @brief convert wxTreeItem into TreePrjItemData
*/
/*****************************************************************************/
TreePrjItemData * WinEDA_PrjFrame::GetItemData( const object & item )
/*****************************************************************************/
{
wxTreeItemId *id = NULL;
if (!wxPyConvertSwigPtr( item.ptr(), (void**)&id, _T("wxTreeItemId")))
{
return NULL;
}
return dynamic_cast<TreePrjItemData *>( m_TreeProject->GetItemData( *id ) );
}
/*****************************************************************************/
// TreePrjItemData Special binding functions
// (one line functions are simple wrappers)
/*****************************************************************************/
// Python rename
bool TreePrjItemData::RenamePy( const str & newname, bool check )
{ return Rename( PyHandler::MakeStr(newname), check ); }
// Get python directory
object TreePrjItemData::GetDirPy() const
{ return PyHandler::Convert( GetDir() ); }
// Get python filename
object TreePrjItemData::GetFileNamePy() const
{ return PyHandler::Convert( GetFileName() ); }
// Get python menu
object TreePrjItemData::GetMenuPy()
{ return object( handle<>( borrowed( wxPyMake_wxObject( &m_fileMenu, false ) ) ) ); }
/**
* @brief KiCad python module init, \n
* This function is called from PyHandler to init the kicad module
*/
/*****************************************************************************/
static void py_kicad_init()
/*****************************************************************************/
{
def( "GetMainFrame", &GetMainFrame, return_value_policy< reference_existing_object >() );
def( "GetTypeExtension", &GetTypeExt );
class_<TreePrjItemData>( "PrjItem" )
// Internal data:
.def( "GetFileName", &TreePrjItemData::GetFileNamePy )
.def( "GetDir", &TreePrjItemData::GetDirPy )
.def( "GetType", &TreePrjItemData::GetType )
.def( "GetId", &TreePrjItemData::GetIdPy )
.def( "GetMenu", &TreePrjItemData::GetMenuPy )
// Item control
.def( "SetState", &TreePrjItemData::SetState )
.def( "Rename", &TreePrjItemData::RenamePy )
.def( "Move", &TreePrjItemData::Move )
.def( "Delete", &TreePrjItemData::Delete )
.def( "Activate", &TreePrjItemData::Activate )
;
enum_<TreeFileType>( "FileType" )
.value( "PROJECT", TREE_PROJECT )
.value( "SCHEMA", TREE_SCHEMA )
.value( "BOARD", TREE_PCB )
.value( "PYSCRIPT", TREE_PY )
.value( "GERBER", TREE_GERBER )
.value( "PDF", TREE_PDF )
.value( "TXT", TREE_TXT )
.value( "NETLIST", TREE_NET )
.value( "UNKNOWN", TREE_UNKNOWN )
.value( "DIRECTORY", TREE_DIRECTORY )
.value( "MAX", TREE_MAX );
class_<WinEDA_PrjFrame>( "TreeWindow" )
// wx Interface
.def( "ToWx", &WinEDA_PrjFrame::ToWx )
// common features
.def( "GetContextMenu", &WinEDA_PrjFrame::GetMenuPy )
.def( "GetFileExtension", &WinEDA_PrjFrame::GetFtExPy )
// file filters control
.def( "AddFilter", &WinEDA_PrjFrame::AddFilter )
.def( "ClearFilters", &WinEDA_PrjFrame::ClearFilters )
.def( "RemoveFilter", &WinEDA_PrjFrame::RemoveFilterPy )
.def( "GetFilters", &WinEDA_PrjFrame::GetFilters, return_value_policy < copy_const_reference >() )
.def( "GetCurrentMenu", &WinEDA_PrjFrame::GetCurrentMenu )
/** Project tree control **/
// AddState
.def( "AddState",
&WinEDA_PrjFrame::AddStatePy )
// GetTreeCtrl
.def( "GetTreeCtrl",
&WinEDA_PrjFrame::GetTreeCtrl )
// GetItemData
.def( "GetItemData",
&WinEDA_PrjFrame::GetItemData,
return_value_policy < reference_existing_object >() )
// FindItemData
.def( "FindItemData",
&WinEDA_PrjFrame::FindItemData,
return_value_policy < reference_existing_object >() )
// NewFile
.def( "NewFile",
&WinEDA_PrjFrame::NewFilePy )
// AddFile
.def( "AddFile",
&WinEDA_PrjFrame::AddFilePy )
; /* ENDOF class_<WinEDA_PrjFrame>( "TreeWindow" ) */
class_<WinEDA_MainFrame>( "MainFrame" )
// Wx interface
.def( "ToWx", &WinEDA_MainFrame::ToWx )
// Common controls
.def( "AddFastLaunch", &WinEDA_MainFrame::AddFastLaunchPy )
.def( "Refresh", &WinEDA_MainFrame::OnRefreshPy )
.def( "GetProjectName", &WinEDA_MainFrame::GetPrjName )
.def( "GetProjectWindow", &WinEDA_MainFrame::GetTree, return_value_policy< reference_existing_object >() );
}
/**
* @brief Common python module init
*/
/*****************************************************************************/
static void py_common_init()
/*****************************************************************************/
{
def( "Print", &WinEDAPrint );
def( "Clear", &WinEDAClear );
}
#endif
/*****************************************************************************/
bool WinEDA_App::OnInit()
/*****************************************************************************/
{
wxImage::AddHandler(new wxPNGHandler);
g_EDA_Appl = this;
InitEDA_Appl( wxT("KiCad"));
/* init kicad */
GetSettings(); // read current setup
/* Make nameless project translatable */
wxString project_ext = _T(".pro");
wxString nameless_project = _("noname") + project_ext;
m_MainFrame = new WinEDA_MainFrame(this, NULL, wxT("KiCad"),
wxPoint(30,20), wxSize(600,400) );
if(argc > 1 )
m_MainFrame->m_PrjFileName = argv[1];
else if ( m_EDA_Config )
{
m_MainFrame->m_PrjFileName = m_EDA_Config->Read(wxT("LastProject"),
nameless_project );
}
else
m_MainFrame->m_PrjFileName = nameless_project;
wxString Title = g_Main_Title + wxT(" ") + GetBuildVersion();
Title += wxT(" ") + m_MainFrame->m_PrjFileName;
m_MainFrame->SetTitle(Title);
m_MainFrame->ReCreateMenuBar();
m_MainFrame->RecreateBaseHToolbar();
m_MainFrame->m_LeftWin->ReCreateTreePrj();
SetTopWindow(m_MainFrame);
/* Splash screen logo */
#ifdef USE_SPLASH_IMAGE
wxString logoname( wxString(m_BinDir) + _T("logokicad.png") );
wxBitmap splash_screen;
if ( splash_screen.LoadFile( logoname, wxBITMAP_TYPE_PNG ) )
{
wxSplashScreen *splash = new wxSplashScreen(splash_screen,
wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
3000, m_MainFrame, wxID_ANY, wxDefaultPosition, wxDefaultSize,
wxSIMPLE_BORDER|wxSTAY_ON_TOP);
}
#endif /* USE_SPLASH_IMAGE */
m_MainFrame->Show(TRUE);
m_MainFrame->Raise();
if( wxFileExists(m_MainFrame->m_PrjFileName) )
{
m_MainFrame->Load_Prj_Config();
}
#ifdef KICAD_PYTHON
PyHandler::GetInstance()->AddToModule( wxT("kicad"), &py_kicad_init );
PyHandler::GetInstance()->AddToModule( wxT("common"), &py_common_init );
#endif
return TRUE;
}