KiCad PCB EDA Suite
KICAD_PLUGIN_LDR_3D Class Reference

#include <pluginldr3D.h>

Inheritance diagram for KICAD_PLUGIN_LDR_3D:
KICAD_PLUGIN_LDR

Public Member Functions

 KICAD_PLUGIN_LDR_3D ()
 
virtual ~KICAD_PLUGIN_LDR_3D ()
 
bool Open (const wxString &aFullFileName) override
 Open a plugin of the given class, performs version compatibility checks, and links all required functions. More...
 
void Close (void) override
 Clean up and closes/unloads the plugin. More...
 
void GetLoaderVersion (unsigned char *Major, unsigned char *Minor, unsigned char *Revision, unsigned char *Patch) const override
 Return the version information of the Plugin Loader for plugin compatibility checking. More...
 
int GetNExtensions (void)
 
char const * GetModelExtension (int aIndex)
 
int GetNFilters (void)
 
char const * GetFileFilter (int aIndex)
 
bool CanRender (void)
 
SCENEGRAPHLoad (char const *aFileName)
 
std::string GetLastError (void) const
 Return the value of the internal error string. More...
 
char const * GetKicadPluginClass (void)
 
bool GetClassVersion (unsigned char *Major, unsigned char *Minor, unsigned char *Patch, unsigned char *Revision)
 
bool CheckClassVersion (unsigned char Major, unsigned char Minor, unsigned char Patch, unsigned char Revision)
 
const char * GetKicadPluginName (void)
 
bool GetVersion (unsigned char *Major, unsigned char *Minor, unsigned char *Patch, unsigned char *Revision)
 
void GetPluginInfo (std::string &aPluginInfo)
 

Protected Member Functions

bool open (const wxString &aFullFileName, const char *aPluginClass)
 Open a plugin of the specified class and links the extensions required by kicad_plugin. More...
 
void close (void)
 Nullify internal pointers in preparation for closing the plugin. More...
 
bool reopen (void)
 Reopen a plugin. More...
 

Protected Attributes

std::string m_error
 
wxDynamicLibrary m_PluginLoader
 

Private Attributes

bool ok
 
PLUGIN_3D_GET_N_EXTENSIONS m_getNExtensions
 
PLUGIN_3D_GET_MODEL_EXTENSION m_getModelExtension
 
PLUGIN_3D_GET_N_FILTERS m_getNFilters
 
PLUGIN_3D_GET_FILE_FILTER m_getFileFilter
 
PLUGIN_3D_CAN_RENDER m_canRender
 
PLUGIN_3D_LOAD m_load
 
GET_PLUGIN_CLASS m_getPluginClass
 
GET_CLASS_VERSION m_getClassVersion
 
CHECK_CLASS_VERSION m_checkClassVersion
 
GET_PLUGIN_NAME m_getPluginName
 
GET_VERSION m_getVersion
 
wxString m_fileName
 
std::string m_pluginInfo
 

Detailed Description

Definition at line 52 of file pluginldr3D.h.

Constructor & Destructor Documentation

◆ KICAD_PLUGIN_LDR_3D()

KICAD_PLUGIN_LDR_3D::KICAD_PLUGIN_LDR_3D ( )

Definition at line 39 of file pluginldr3D.cpp.

40{
41 ok = false;
42 m_getNExtensions = nullptr;
43 m_getModelExtension = nullptr;
44 m_getNFilters = nullptr;
45 m_getFileFilter = nullptr;
46 m_canRender = nullptr;
47 m_load = nullptr;
48
49 return;
50}
PLUGIN_3D_GET_FILE_FILTER m_getFileFilter
Definition: pluginldr3D.h:82
PLUGIN_3D_GET_N_FILTERS m_getNFilters
Definition: pluginldr3D.h:81
PLUGIN_3D_LOAD m_load
Definition: pluginldr3D.h:84
PLUGIN_3D_CAN_RENDER m_canRender
Definition: pluginldr3D.h:83
PLUGIN_3D_GET_MODEL_EXTENSION m_getModelExtension
Definition: pluginldr3D.h:80
PLUGIN_3D_GET_N_EXTENSIONS m_getNExtensions
Definition: pluginldr3D.h:79

References m_canRender, m_getFileFilter, m_getModelExtension, m_getNExtensions, m_getNFilters, m_load, and ok.

◆ ~KICAD_PLUGIN_LDR_3D()

KICAD_PLUGIN_LDR_3D::~KICAD_PLUGIN_LDR_3D ( )
virtual

Definition at line 53 of file pluginldr3D.cpp.

54{
55 Close();
56
57 return;
58}
void Close(void) override
Clean up and closes/unloads the plugin.

References Close().

Member Function Documentation

◆ CanRender()

bool KICAD_PLUGIN_LDR_3D::CanRender ( void  )

Definition at line 361 of file pluginldr3D.cpp.

362{
363 m_error.clear();
364
365 if( !ok && !reopen() )
366 {
367 if( m_error.empty() )
368 m_error = "[INFO] no open plugin / plugin could not be opened";
369
370 return false;
371 }
372
373 if( nullptr == m_canRender )
374 {
375 m_error = "[BUG] CanRender is not linked";
376
377 wxLogTrace( tracePluginLoader, wxT( "%s:%s:%d\n"
378 "%s" ),
379 __FILE__, __FUNCTION__, __LINE__, m_error );;
380
381 return false;
382 }
383
384 return m_canRender();
385}
std::string m_error
Definition: pluginldr.h:134
bool reopen(void)
Reopen a plugin.
Definition: pluginldr.cpp:275
const wxChar *const tracePluginLoader
Flag to enable plugin loader trace output.
Definition: pluginldr.cpp:40

References m_canRender, KICAD_PLUGIN_LDR::m_error, ok, KICAD_PLUGIN_LDR::reopen(), and tracePluginLoader.

◆ CheckClassVersion()

bool KICAD_PLUGIN_LDR::CheckClassVersion ( unsigned char  Major,
unsigned char  Minor,
unsigned char  Patch,
unsigned char  Revision 
)
inherited

Definition at line 380 of file pluginldr.cpp.

382{
383 m_error.clear();
384
385 if( !ok && !reopen() )
386 {
387 if( m_error.empty() )
388 m_error = "[INFO] no open plugin / plugin could not be opened";
389
390 return false;
391 }
392
393 if( nullptr == m_checkClassVersion )
394 {
395 m_error = "[BUG] CheckClassVersion is not linked";
396
397 wxLogTrace( tracePluginLoader, wxT( "%s:%s:%d\n"
398 "%s" ),
399 __FILE__, __FUNCTION__, __LINE__, m_error );;
400
401 return false;
402 }
403
404 return m_checkClassVersion( Major, Minor, Patch, Revision );
405}
CHECK_CLASS_VERSION m_checkClassVersion
Definition: pluginldr.h:143

References KICAD_PLUGIN_LDR::m_checkClassVersion, KICAD_PLUGIN_LDR::m_error, KICAD_PLUGIN_LDR::ok, KICAD_PLUGIN_LDR::reopen(), and tracePluginLoader.

◆ close()

void KICAD_PLUGIN_LDR::close ( void  )
protectedinherited

Nullify internal pointers in preparation for closing the plugin.

Definition at line 261 of file pluginldr.cpp.

262{
263 ok = false;
264 m_getPluginClass = nullptr;
265 m_getClassVersion = nullptr;
266 m_checkClassVersion = nullptr;
267 m_getPluginName = nullptr;
268 m_getVersion = nullptr;
269 m_PluginLoader.Unload();
270
271 return;
272}
GET_PLUGIN_CLASS m_getPluginClass
Definition: pluginldr.h:141
GET_CLASS_VERSION m_getClassVersion
Definition: pluginldr.h:142
GET_VERSION m_getVersion
Definition: pluginldr.h:145
GET_PLUGIN_NAME m_getPluginName
Definition: pluginldr.h:144
wxDynamicLibrary m_PluginLoader
Definition: pluginldr.h:137

References KICAD_PLUGIN_LDR::m_checkClassVersion, KICAD_PLUGIN_LDR::m_getClassVersion, KICAD_PLUGIN_LDR::m_getPluginClass, KICAD_PLUGIN_LDR::m_getPluginName, KICAD_PLUGIN_LDR::m_getVersion, KICAD_PLUGIN_LDR::m_PluginLoader, and KICAD_PLUGIN_LDR::ok.

Referenced by Close(), KICAD_PLUGIN_LDR::open(), and KICAD_PLUGIN_LDR::~KICAD_PLUGIN_LDR().

◆ Close()

void KICAD_PLUGIN_LDR_3D::Close ( void  )
overridevirtual

Clean up and closes/unloads the plugin.

Implements KICAD_PLUGIN_LDR.

Definition at line 210 of file pluginldr3D.cpp.

211{
212#ifdef DEBUG
213 if( ok )
214 {
215 wxLogTrace( tracePluginLoader, wxT( "%s:%s:%d\n"
216 " * [INFO] closing plugin" ),
217 __FILE__, __FUNCTION__, __LINE__ );
218 }
219#endif
220
221 ok = false;
222 m_getNExtensions = nullptr;
223 m_getModelExtension = nullptr;
224 m_getNFilters = nullptr;
225 m_getFileFilter = nullptr;
226 m_canRender = nullptr;
227 m_load = nullptr;
228 close();
229
230 return;
231}
void close(void)
Nullify internal pointers in preparation for closing the plugin.
Definition: pluginldr.cpp:261

References KICAD_PLUGIN_LDR::close(), m_canRender, m_getFileFilter, m_getModelExtension, m_getNExtensions, m_getNFilters, m_load, ok, and tracePluginLoader.

Referenced by S3D_PLUGIN_MANAGER::loadPlugins(), Open(), and ~KICAD_PLUGIN_LDR_3D().

◆ GetClassVersion()

bool KICAD_PLUGIN_LDR::GetClassVersion ( unsigned char *  Major,
unsigned char *  Minor,
unsigned char *  Patch,
unsigned char *  Revision 
)
inherited

Definition at line 321 of file pluginldr.cpp.

323{
324 m_error.clear();
325
326 if( Major )
327 *Major = 0;
328
329 if( Minor )
330 *Minor = 0;
331
332 if( Patch )
333 *Patch = 0;
334
335 if( Revision )
336 *Revision = 0;
337
338 unsigned char major;
339 unsigned char minor;
340 unsigned char patch;
341 unsigned char revno;
342
343 if( !ok && !reopen() )
344 {
345 if( m_error.empty() )
346 m_error = "[INFO] no open plugin / plugin could not be opened";
347
348 return false;
349 }
350
351 if( nullptr == m_checkClassVersion )
352 {
353 m_error = "[BUG] CheckClassVersion is not linked";
354
355 wxLogTrace( tracePluginLoader, wxT( "%s:%s:%d\n"
356 "%s" ),
357 __FILE__, __FUNCTION__, __LINE__, m_error );;
358
359 return false;
360 }
361
362 m_getClassVersion( &major, &minor, &patch, &revno );
363
364 if( Major )
365 *Major = major;
366
367 if( Minor )
368 *Minor = minor;
369
370 if( Patch )
371 *Patch = patch;
372
373 if( Revision )
374 *Revision = revno;
375
376 return true;
377}

References KICAD_PLUGIN_LDR::m_checkClassVersion, KICAD_PLUGIN_LDR::m_error, KICAD_PLUGIN_LDR::m_getClassVersion, KICAD_PLUGIN_LDR::ok, KICAD_PLUGIN_LDR::reopen(), and tracePluginLoader.

◆ GetFileFilter()

char const * KICAD_PLUGIN_LDR_3D::GetFileFilter ( int  aIndex)

Definition at line 334 of file pluginldr3D.cpp.

335{
336 m_error.clear();
337
338 if( !ok && !reopen() )
339 {
340 if( m_error.empty() )
341 m_error = "[INFO] no open plugin / plugin could not be opened";
342
343 return nullptr;
344 }
345
346 if( nullptr == m_getFileFilter )
347 {
348 m_error = "[BUG] GetFileFilter is not linked";
349
350 wxLogTrace( tracePluginLoader, wxT( "%s:%s:%d\n"
351 "%s" ),
352 __FILE__, __FUNCTION__, __LINE__, m_error );;
353
354 return nullptr;
355 }
356
357 return m_getFileFilter( aIndex );
358}

References KICAD_PLUGIN_LDR::m_error, m_getFileFilter, ok, KICAD_PLUGIN_LDR::reopen(), and tracePluginLoader.

Referenced by S3D_PLUGIN_MANAGER::loadPlugins().

◆ GetKicadPluginClass()

char const * KICAD_PLUGIN_LDR::GetKicadPluginClass ( void  )
inherited

Definition at line 294 of file pluginldr.cpp.

295{
296 m_error.clear();
297
298 if( !ok && !reopen() )
299 {
300 if( m_error.empty() )
301 m_error = "[INFO] no open plugin / plugin could not be opened";
302
303 return nullptr;
304 }
305
306 if( nullptr == m_getPluginClass )
307 {
308 m_error = "[BUG] GetPluginClass is not linked";
309
310 wxLogTrace( tracePluginLoader, wxT( "%s:%s:%d\n"
311 "%s" ),
312 __FILE__, __FUNCTION__, __LINE__, m_error );;
313
314 return nullptr;
315 }
316
317 return m_getPluginClass();
318}

References KICAD_PLUGIN_LDR::m_error, KICAD_PLUGIN_LDR::m_getPluginClass, KICAD_PLUGIN_LDR::ok, KICAD_PLUGIN_LDR::reopen(), and tracePluginLoader.

◆ GetKicadPluginName()

const char * KICAD_PLUGIN_LDR::GetKicadPluginName ( void  )
inherited

Definition at line 408 of file pluginldr.cpp.

409{
410 m_error.clear();
411
412 if( !ok && !reopen() )
413 {
414 if( m_error.empty() )
415 m_error = "[INFO] no open plugin / plugin could not be opened";
416
417 return nullptr;
418 }
419
420 if( nullptr == m_getPluginName )
421 {
422 m_error = "[BUG] GetKicadPluginName is not linked";
423
424 wxLogTrace( tracePluginLoader, wxT( "%s:%s:%d\n"
425 "%s" ),
426 __FILE__, __FUNCTION__, __LINE__, m_error );;
427
428 return nullptr;
429 }
430
431 return m_getPluginName();
432}

References KICAD_PLUGIN_LDR::m_error, KICAD_PLUGIN_LDR::m_getPluginName, KICAD_PLUGIN_LDR::ok, KICAD_PLUGIN_LDR::reopen(), and tracePluginLoader.

Referenced by KICAD_PLUGIN_LDR::open().

◆ GetLastError()

std::string KICAD_PLUGIN_LDR::GetLastError ( void  ) const
inherited

Return the value of the internal error string.

Definition at line 288 of file pluginldr.cpp.

289{
290 return m_error;
291}

References KICAD_PLUGIN_LDR::m_error.

◆ GetLoaderVersion()

void KICAD_PLUGIN_LDR_3D::GetLoaderVersion ( unsigned char *  Major,
unsigned char *  Minor,
unsigned char *  Patch,
unsigned char *  Revision 
) const
overridevirtual

Return the version information of the Plugin Loader for plugin compatibility checking.

Implements KICAD_PLUGIN_LDR.

Definition at line 234 of file pluginldr3D.cpp.

236{
237 if( Major )
238 *Major = PLUGIN_3D_MAJOR;
239
240 if( Minor )
241 *Minor = PLUGIN_3D_MINOR;
242
243 if( Patch )
244 *Patch = PLUGIN_3D_PATCH;
245
246 if( Revision )
247 *Revision = PLUGIN_3D_REVISION;
248
249 return;
250}
#define PLUGIN_3D_REVISION
Definition: pluginldr3D.cpp:36
#define PLUGIN_3D_PATCH
Definition: pluginldr3D.cpp:35
#define PLUGIN_3D_MAJOR
Definition: pluginldr3D.cpp:33
#define PLUGIN_3D_MINOR
Definition: pluginldr3D.cpp:34

References PLUGIN_3D_MAJOR, PLUGIN_3D_MINOR, PLUGIN_3D_PATCH, and PLUGIN_3D_REVISION.

◆ GetModelExtension()

char const * KICAD_PLUGIN_LDR_3D::GetModelExtension ( int  aIndex)

Definition at line 280 of file pluginldr3D.cpp.

281{
282 m_error.clear();
283
284 if( !ok && !reopen() )
285 {
286 if( m_error.empty() )
287 m_error = "[INFO] no open plugin / plugin could not be opened";
288
289 return nullptr;
290 }
291
292 if( nullptr == m_getModelExtension )
293 {
294 m_error = "[BUG] GetModelExtension is not linked";
295
296 wxLogTrace( tracePluginLoader, wxT( "%s:%s:%d\n"
297 "%s" ),
298 __FILE__, __FUNCTION__, __LINE__, m_error );;
299
300 return nullptr;
301 }
302
303 return m_getModelExtension( aIndex );
304}

References KICAD_PLUGIN_LDR::m_error, m_getModelExtension, ok, KICAD_PLUGIN_LDR::reopen(), and tracePluginLoader.

Referenced by S3D_PLUGIN_MANAGER::addExtensionMap().

◆ GetNExtensions()

int KICAD_PLUGIN_LDR_3D::GetNExtensions ( void  )

Definition at line 253 of file pluginldr3D.cpp.

254{
255 m_error.clear();
256
257 if( !ok && !reopen() )
258 {
259 if( m_error.empty() )
260 m_error = "[INFO] no open plugin / plugin could not be opened";
261
262 return 0;
263 }
264
265 if( nullptr == m_getNExtensions )
266 {
267 m_error = "[BUG] GetNExtensions is not linked";
268
269 wxLogTrace( tracePluginLoader, wxT( "%s:%s:%d\n"
270 "%s" ),
271 __FILE__, __FUNCTION__, __LINE__, m_error );;
272
273 return 0;
274 }
275
276 return m_getNExtensions();
277}

References KICAD_PLUGIN_LDR::m_error, m_getNExtensions, ok, KICAD_PLUGIN_LDR::reopen(), and tracePluginLoader.

Referenced by S3D_PLUGIN_MANAGER::addExtensionMap().

◆ GetNFilters()

int KICAD_PLUGIN_LDR_3D::GetNFilters ( void  )

Definition at line 307 of file pluginldr3D.cpp.

308{
309 m_error.clear();
310
311 if( !ok && !reopen() )
312 {
313 if( m_error.empty() )
314 m_error = "[INFO] no open plugin / plugin could not be opened";
315
316 return 0;
317 }
318
319 if( nullptr == m_getNFilters )
320 {
321 m_error = "[BUG] GetNFilters is not linked";
322
323 wxLogTrace( tracePluginLoader, wxT( "%s:%s:%d\n"
324 "%s" ),
325 __FILE__, __FUNCTION__, __LINE__, m_error );;
326
327 return 0;
328 }
329
330 return m_getNFilters();
331}

References KICAD_PLUGIN_LDR::m_error, m_getNFilters, ok, KICAD_PLUGIN_LDR::reopen(), and tracePluginLoader.

Referenced by S3D_PLUGIN_MANAGER::loadPlugins().

◆ GetPluginInfo()

void KICAD_PLUGIN_LDR::GetPluginInfo ( std::string &  aPluginInfo)
inherited

Definition at line 465 of file pluginldr.cpp.

466{
467 aPluginInfo = m_pluginInfo;
468}
std::string m_pluginInfo
Definition: pluginldr.h:147

References KICAD_PLUGIN_LDR::m_pluginInfo.

◆ GetVersion()

bool KICAD_PLUGIN_LDR::GetVersion ( unsigned char *  Major,
unsigned char *  Minor,
unsigned char *  Patch,
unsigned char *  Revision 
)
inherited

Definition at line 435 of file pluginldr.cpp.

437{
438 m_error.clear();
439
440 if( !ok && !reopen() )
441 {
442 if( m_error.empty() )
443 m_error = "[INFO] no open plugin / plugin could not be opened";
444
445 return false;
446 }
447
448 if( nullptr == m_getVersion )
449 {
450 m_error = "[BUG] GetKicadPluginName is not linked";
451
452 wxLogTrace( tracePluginLoader, wxT( "%s:%s:%d\n"
453 "%s" ),
454 __FILE__, __FUNCTION__, __LINE__, m_error );;
455
456 return false;
457 }
458
459 m_getVersion( Major, Minor, Patch, Revision );
460
461 return true;
462}

References KICAD_PLUGIN_LDR::m_error, KICAD_PLUGIN_LDR::m_getVersion, KICAD_PLUGIN_LDR::ok, KICAD_PLUGIN_LDR::reopen(), and tracePluginLoader.

Referenced by KICAD_PLUGIN_LDR::open().

◆ Load()

SCENEGRAPH * KICAD_PLUGIN_LDR_3D::Load ( char const *  aFileName)

Definition at line 388 of file pluginldr3D.cpp.

389{
390 m_error.clear();
391
392 if( !ok && !reopen() )
393 {
394 if( m_error.empty() )
395 m_error = "[INFO] no open plugin / plugin could not be opened";
396
397 return nullptr;
398 }
399
400 if( nullptr == m_load )
401 {
402 m_error = "[BUG] Load is not linked";
403
404 wxLogTrace( tracePluginLoader, wxT( "%s:%s:%d\n"
405 "%s" ),
406 __FILE__, __FUNCTION__, __LINE__, m_error );;
407
408 return nullptr;
409 }
410
411 return m_load( aFileName );
412}

References KICAD_PLUGIN_LDR::m_error, m_load, ok, KICAD_PLUGIN_LDR::reopen(), and tracePluginLoader.

◆ Open()

bool KICAD_PLUGIN_LDR_3D::Open ( const wxString &  aFullFileName)
overridevirtual

Open a plugin of the given class, performs version compatibility checks, and links all required functions.

Returns
true on success or false if failure. An error message may be accessible via GetLastError()

Implements KICAD_PLUGIN_LDR.

Definition at line 61 of file pluginldr3D.cpp.

62{
63 m_error.clear();
64
65 if( ok )
66 Close();
67
68 if( !open( aFullFileName, PLUGIN_CLASS_3D ) )
69 {
70 if( m_error.empty() )
71 {
72 std::ostringstream ostr;
73 ostr << "Failed to open plugin '" << aFullFileName.ToUTF8() << "'";
74 m_error = ostr.str();
75 }
76
77 wxLogTrace( tracePluginLoader, wxT( "%s:%s:%d\n"
78 " * [INFO] failed on file '%s'\n"
79 " * [INFO] error: " ),
80 __FILE__, __FUNCTION__, __LINE__, aFullFileName.ToUTF8(), m_error );
81
82 return false;
83 }
84
85 // the version checks passed and the base KICAD_PLUGIN functions have been linked;
86 // now we link the remaining functions expected by PLUGIN_3D and confirm that the
87 // plugin is loaded
94
95#ifdef DEBUG
96 bool fail = false;
97
98 if( !m_getNExtensions )
99 {
100 wxLogTrace( tracePluginLoader,
101 wxT( "%s:%s:%d\n"
102 "incompatible plugin (missing function 'GetNExtensions')" ),
103 __FILE__, __FUNCTION__, __LINE__ );
104
105 fail = true;
106 }
107
109 {
110 if( !fail )
111 {
112 wxLogTrace( tracePluginLoader,
113 wxT( "%s:%s:%d\n"
114 "incompatible plugin (missing function 'GetModelExtension')" ),
115 __FILE__, __FUNCTION__, __LINE__ );
116
117 fail = true;
118 }
119 else
120 {
121 wxLogTrace( tracePluginLoader, wxT( "missing function 'GetModelExtension'" ) );
122 }
123 }
124
125 if( !m_getNFilters )
126 {
127 if( !fail )
128 {
129 wxLogTrace( tracePluginLoader,
130 wxT( "%s:%s:%d\n"
131 "incompatible plugin (missing function 'GetNFilters')" ),
132 __FILE__, __FUNCTION__, __LINE__ );
133
134 fail = true;
135 }
136 else
137 {
138 wxLogTrace( tracePluginLoader, wxT( "missing function 'GetNFilters'" ) );
139 }
140 }
141
142 if( !m_getFileFilter )
143 {
144 if( !fail )
145 {
146 wxLogTrace( tracePluginLoader,
147 wxT( "%s:%s:%d\n"
148 "incompatible plugin (missing function 'GetFileFilter')" ),
149 __FILE__, __FUNCTION__, __LINE__ );
150
151 fail = true;
152 }
153 else
154 {
155 wxLogTrace( tracePluginLoader, wxT( "missing function 'GetFileFilter'" ) );
156 }
157 }
158
159 if( !m_canRender )
160 {
161 if( !fail )
162 {
163 wxLogTrace( tracePluginLoader,
164 wxT( "%s:%s:%d\n"
165 "incompatible plugin (missing function 'CanRender')" ),
166 __FILE__, __FUNCTION__, __LINE__ );
167
168 fail = true;
169 }
170 else
171 {
172 wxLogTrace( tracePluginLoader, wxT( "missing function 'CanRender'" ) );
173 }
174 }
175
176 if( !m_load )
177 {
178 if( !fail )
179 {
180 wxLogTrace( tracePluginLoader,
181 wxT( "%s:%s:%d\n"
182 "incompatible plugin (missing function 'Load')" ),
183 __FILE__, __FUNCTION__, __LINE__ );
184 }
185 else
186 {
187 wxLogTrace( tracePluginLoader, wxT( "missing function 'Load'" ) );
188 }
189 }
190
191#endif
192
195 {
196 Close();
197
198 std::ostringstream ostr;
199 ostr << "Failed to open plugin '" << aFullFileName.ToUTF8() << "'; missing functions";
200 m_error = ostr.str();
201
202 return false;
203 }
204
205 ok = true;
206 return true;
207}
bool open(const wxString &aFullFileName, const char *aPluginClass)
Open a plugin of the specified class and links the extensions required by kicad_plugin.
Definition: pluginldr.cpp:63
#define PLUGIN_CLASS_3D
Definition: pluginldr3D.cpp:32
int(* PLUGIN_3D_GET_N_EXTENSIONS)(void)
Definition: pluginldr3D.h:39
char const *(* PLUGIN_3D_GET_MODEL_EXTENSION)(int aIndex)
Definition: pluginldr3D.h:41
char const *(* PLUGIN_3D_GET_FILE_FILTER)(int aIndex)
Definition: pluginldr3D.h:45
SCENEGRAPH *(* PLUGIN_3D_LOAD)(char const *aFileName)
Definition: pluginldr3D.h:49
bool(* PLUGIN_3D_CAN_RENDER)(void)
Definition: pluginldr3D.h:47
int(* PLUGIN_3D_GET_N_FILTERS)(void)
Definition: pluginldr3D.h:43
#define LINK_ITEM(funcPtr, funcType, funcName)
Definition: pluginldr.h:45

References Close(), LINK_ITEM, m_canRender, KICAD_PLUGIN_LDR::m_error, m_getFileFilter, m_getModelExtension, m_getNExtensions, m_getNFilters, m_load, ok, KICAD_PLUGIN_LDR::open(), PLUGIN_CLASS_3D, and tracePluginLoader.

Referenced by S3D_PLUGIN_MANAGER::loadPlugins().

◆ open()

bool KICAD_PLUGIN_LDR::open ( const wxString &  aFullFileName,
const char *  aPluginClass 
)
protectedinherited

Open a plugin of the specified class and links the extensions required by kicad_plugin.

Returns
true on success otherwise false.

Definition at line 63 of file pluginldr.cpp.

64{
65 m_error.clear();
66
67 if( ok )
68 Close();
69
70 if( aFullFileName.empty() )
71 return false;
72
73 m_fileName.clear();
74
75 m_PluginLoader.Load( aFullFileName, wxDL_LAZY );
76
77 if( !m_PluginLoader.IsLoaded() )
78 {
79 wxLogTrace( tracePluginLoader, wxT( " * could not open file: '%s'" ),
80 aFullFileName.ToUTF8() );
81
82 return false;
83 }
84
85 LINK_ITEM( m_getPluginClass, GET_PLUGIN_CLASS, "GetKicadPluginClass" );
86 LINK_ITEM( m_getClassVersion, GET_CLASS_VERSION, "GetClassVersion" );
87 LINK_ITEM( m_checkClassVersion, CHECK_CLASS_VERSION , "CheckClassVersion" );
88 LINK_ITEM( m_getPluginName, GET_PLUGIN_NAME, "GetKicadPluginName" );
89 LINK_ITEM( m_getVersion, GET_VERSION, "GetPluginVersion" );
90
91#ifdef DEBUG
92 bool fail = false;
93
94 if( !m_getPluginClass )
95 {
96 wxLogTrace( tracePluginLoader,
97 wxT( "%s:%s:%d\n"
98 "incompatible plugin (missing function 'GetKicadPluginClass')" ),
99 __FILE__, __FUNCTION__, __LINE__ );
100
101 fail = true;
102 }
103
104 if( !m_getClassVersion )
105 {
106 if( !fail )
107 {
108 wxLogTrace( tracePluginLoader,
109 wxT( "%s:%s:%d\n"
110 "incompatible plugin (missing function 'GetClassVersion')" ),
111 __FILE__, __FUNCTION__, __LINE__ );
112 fail = true;
113 }
114 else
115 {
116 wxLogTrace( tracePluginLoader, wxT( "missing function 'GetClassVersion'" ) );
117 }
118 }
119
121 {
122 if( !fail )
123 {
124 wxLogTrace( tracePluginLoader,
125 wxT( "%s:%s:%d\n"
126 "incompatible plugin (missing function 'CheckClassVersion')" ),
127 __FILE__, __FUNCTION__, __LINE__ );
128
129 fail = true;
130 }
131 else
132 {
133 wxLogTrace( tracePluginLoader, wxT( "missing function 'CheckClassVersion'" ) );
134 }
135 }
136
137 if( !m_getPluginName )
138 {
139 if( !fail )
140 {
141 wxLogTrace( tracePluginLoader,
142 wxT( "%s:%s:%d\n"
143 "incompatible plugin (missing function 'GetKicadPluginName')" ),
144 __FILE__, __FUNCTION__, __LINE__ );
145
146 fail = true;
147 }
148 else
149 {
150 wxLogTrace( tracePluginLoader, wxT( "missing function 'GetKicadPluginName'" ) );
151 }
152 }
153
154 if( !m_getVersion )
155 {
156 if( !fail )
157 {
158 wxLogTrace( tracePluginLoader,
159 wxT( "%s:%s:%d\n"
160 "incompatible plugin (missing function 'GetVersion')" ),
161 __FILE__, __FUNCTION__, __LINE__ );
162 }
163 else
164 {
165 wxLogTrace( tracePluginLoader, wxT( "missing function 'GetVersion'" ) );
166 }
167 }
168
169#endif
170
173 {
174 m_error = "incompatible plugin interface (missing functions)";
175 close();
176 return false;
177 }
178
179 // note: since 'ok' is not yet set at this point we must use the function
180 // pointers directly rather than invoking the functions exposed by this class
181
182 // check that the Plugin Class matches
183 char const* pclassName = m_getPluginClass();
184
185 if( !pclassName || strcmp( aPluginClass, pclassName ) )
186 {
187 m_error = "Loader type (";
188 m_error.append( aPluginClass );
189 m_error.append( ") does not match Plugin type (" );
190
191 if( pclassName )
192 m_error.append( pclassName );
193 else
194 m_error.append( "nullptr" );
195
196 m_error.append( ")" );
197
198 close();
199 return false;
200 }
201
202 // perform a universally enforced version check (major number must match)
203 unsigned char lMajor;
204 unsigned char lMinor;
205 unsigned char lPatch;
206 unsigned char lRevno;
207 unsigned char pMajor;
208 unsigned char pMinor;
209 unsigned char pPatch;
210 unsigned char pRevno;
211
212 m_getClassVersion( &pMajor, &pMinor, &pPatch, &pRevno );
213 GetLoaderVersion( &lMajor, &lMinor, &lPatch, &lRevno );
214
215 // major version changes by definition are incompatible and that is enforced here.
216 if( pMajor != lMajor )
217 {
218 std::ostringstream ostr;
219 ostr << "Loader Major version (" << lMajor;
220 ostr << ") does not match Plugin Major version (" << pMajor << ")";
221
222 m_error = ostr.str();
223 close();
224 return false;
225 }
226
227 if( !m_checkClassVersion( lMajor, lMinor, lPatch, lRevno ) )
228 {
229 std::ostringstream ostr;
230 ostr << "Plugin Version (" << pMajor << "." << pMinor << "." << pPatch << "." << pRevno;
231 ostr << ") does not support Loader Version (" << pMajor << "." << pMinor;
232 ostr << "." << pPatch << "." << pRevno << ")";
233
234 m_error = ostr.str();
235 close();
236 return false;
237 }
238
239 m_fileName = aFullFileName;
240
241 wxLogTrace( tracePluginLoader,
242 wxT( "%s:%s:%d\n"
243 " * [INFO] opened plugin '%s'" ),
244 __FILE__, __FUNCTION__, __LINE__, m_fileName );
245
246 ok = true;
247
248 // set the plugin info string
250 std::ostringstream ostr;
251 unsigned char r0, r1, r2, r3;
252 GetVersion( &r0, &r1, &r2, &r3 );
253 ostr << ":" << (unsigned int)r0 << "." << (unsigned int)r1;
254 ostr << "." << (unsigned int)r2 << "." << (unsigned int)r3;
255 m_pluginInfo.append( ostr.str() );
256
257 return true;
258}
virtual void GetLoaderVersion(unsigned char *Major, unsigned char *Minor, unsigned char *Patch, unsigned char *Revision) const =0
Return the version information of the Plugin Loader for plugin compatibility checking.
virtual void Close(void)=0
Clean up and closes/unloads the plugin.
bool GetVersion(unsigned char *Major, unsigned char *Minor, unsigned char *Patch, unsigned char *Revision)
Definition: pluginldr.cpp:435
const char * GetKicadPluginName(void)
Definition: pluginldr.cpp:408
wxString m_fileName
Definition: pluginldr.h:146
void(* GET_VERSION)(unsigned char *, unsigned char *, unsigned char *, unsigned char *)
Definition: pluginldr.h:59
void(* GET_CLASS_VERSION)(unsigned char *, unsigned char *, unsigned char *, unsigned char *)
Definition: pluginldr.h:51
bool(* CHECK_CLASS_VERSION)(unsigned char, unsigned char, unsigned char, unsigned char)
Definition: pluginldr.h:54
char const *(* GET_PLUGIN_CLASS)(void)
Definition: pluginldr.h:49
const char *(* GET_PLUGIN_NAME)(void)
Definition: pluginldr.h:57

References KICAD_PLUGIN_LDR::close(), KICAD_PLUGIN_LDR::Close(), KICAD_PLUGIN_LDR::GetKicadPluginName(), KICAD_PLUGIN_LDR::GetLoaderVersion(), KICAD_PLUGIN_LDR::GetVersion(), LINK_ITEM, KICAD_PLUGIN_LDR::m_checkClassVersion, KICAD_PLUGIN_LDR::m_error, KICAD_PLUGIN_LDR::m_fileName, KICAD_PLUGIN_LDR::m_getClassVersion, KICAD_PLUGIN_LDR::m_getPluginClass, KICAD_PLUGIN_LDR::m_getPluginName, KICAD_PLUGIN_LDR::m_getVersion, KICAD_PLUGIN_LDR::m_pluginInfo, KICAD_PLUGIN_LDR::m_PluginLoader, KICAD_PLUGIN_LDR::ok, and tracePluginLoader.

Referenced by Open().

◆ reopen()

bool KICAD_PLUGIN_LDR::reopen ( void  )
protectedinherited

Reopen a plugin.

Returns
true on success or false on failure.

Definition at line 275 of file pluginldr.cpp.

276{
277 m_error.clear();
278
279 if( m_fileName.empty() )
280 return false;
281
282 wxString fname = m_fileName;
283
284 return Open( fname );
285}
virtual bool Open(const wxString &aFullFileName)=0
Open a plugin of the given class, performs version compatibility checks, and links all required funct...

References KICAD_PLUGIN_LDR::m_error, KICAD_PLUGIN_LDR::m_fileName, and KICAD_PLUGIN_LDR::Open().

Referenced by CanRender(), KICAD_PLUGIN_LDR::CheckClassVersion(), KICAD_PLUGIN_LDR::GetClassVersion(), GetFileFilter(), KICAD_PLUGIN_LDR::GetKicadPluginClass(), KICAD_PLUGIN_LDR::GetKicadPluginName(), GetModelExtension(), GetNExtensions(), GetNFilters(), KICAD_PLUGIN_LDR::GetVersion(), and Load().

Member Data Documentation

◆ m_canRender

PLUGIN_3D_CAN_RENDER KICAD_PLUGIN_LDR_3D::m_canRender
private

Definition at line 83 of file pluginldr3D.h.

Referenced by CanRender(), Close(), KICAD_PLUGIN_LDR_3D(), and Open().

◆ m_checkClassVersion

◆ m_error

◆ m_fileName

wxString KICAD_PLUGIN_LDR::m_fileName
privateinherited

Definition at line 146 of file pluginldr.h.

Referenced by KICAD_PLUGIN_LDR::open(), and KICAD_PLUGIN_LDR::reopen().

◆ m_getClassVersion

GET_CLASS_VERSION KICAD_PLUGIN_LDR::m_getClassVersion
privateinherited

◆ m_getFileFilter

PLUGIN_3D_GET_FILE_FILTER KICAD_PLUGIN_LDR_3D::m_getFileFilter
private

Definition at line 82 of file pluginldr3D.h.

Referenced by Close(), GetFileFilter(), KICAD_PLUGIN_LDR_3D(), and Open().

◆ m_getModelExtension

PLUGIN_3D_GET_MODEL_EXTENSION KICAD_PLUGIN_LDR_3D::m_getModelExtension
private

Definition at line 80 of file pluginldr3D.h.

Referenced by Close(), GetModelExtension(), KICAD_PLUGIN_LDR_3D(), and Open().

◆ m_getNExtensions

PLUGIN_3D_GET_N_EXTENSIONS KICAD_PLUGIN_LDR_3D::m_getNExtensions
private

Definition at line 79 of file pluginldr3D.h.

Referenced by Close(), GetNExtensions(), KICAD_PLUGIN_LDR_3D(), and Open().

◆ m_getNFilters

PLUGIN_3D_GET_N_FILTERS KICAD_PLUGIN_LDR_3D::m_getNFilters
private

Definition at line 81 of file pluginldr3D.h.

Referenced by Close(), GetNFilters(), KICAD_PLUGIN_LDR_3D(), and Open().

◆ m_getPluginClass

GET_PLUGIN_CLASS KICAD_PLUGIN_LDR::m_getPluginClass
privateinherited

◆ m_getPluginName

GET_PLUGIN_NAME KICAD_PLUGIN_LDR::m_getPluginName
privateinherited

◆ m_getVersion

GET_VERSION KICAD_PLUGIN_LDR::m_getVersion
privateinherited

◆ m_load

PLUGIN_3D_LOAD KICAD_PLUGIN_LDR_3D::m_load
private

Definition at line 84 of file pluginldr3D.h.

Referenced by Close(), KICAD_PLUGIN_LDR_3D(), Load(), and Open().

◆ m_pluginInfo

std::string KICAD_PLUGIN_LDR::m_pluginInfo
privateinherited

Definition at line 147 of file pluginldr.h.

Referenced by KICAD_PLUGIN_LDR::GetPluginInfo(), and KICAD_PLUGIN_LDR::open().

◆ m_PluginLoader

wxDynamicLibrary KICAD_PLUGIN_LDR::m_PluginLoader
protectedinherited

Definition at line 137 of file pluginldr.h.

Referenced by KICAD_PLUGIN_LDR::close(), and KICAD_PLUGIN_LDR::open().

◆ ok

bool KICAD_PLUGIN_LDR_3D::ok
private

The documentation for this class was generated from the following files: