33#include <wx/stdpaths.h>
52#define MASK_3D_PLUGINMGR "3D_PLUGIN_MANAGER"
58 m_FileFilters.emplace_back(
_(
"All Files" ) + wxT(
" (*.*)|*.*" ) );
66 std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::const_iterator sM =
m_ExtMap.begin();
67 std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::const_iterator eM =
m_ExtMap.end();
73 sM->second->GetKicadPluginName() );
87 std::list< wxString >::const_iterator sFF =
m_FileFilters.begin();
88 std::list< wxString >::const_iterator eFF =
m_FileFilters.end();
107 std::list< KICAD_PLUGIN_LDR_3D* >::iterator sP =
m_Plugins.begin();
108 std::list< KICAD_PLUGIN_LDR_3D* >::iterator eP =
m_Plugins.end();
123 std::list<wxString> searchpaths;
124 std::list<wxString> pluginlist;
128 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
131 fn.Assign( wxStandardPaths::Get().GetExecutablePath() );
132 fn.AppendDir( wxT(
".." ) );
133 fn.AppendDir( wxT(
"plugins" ) );
134 fn.AppendDir( wxT(
"3d" ) );
136 std::string testpath = std::string( fn.GetPathWithSep().ToUTF8() );
140 wxDir debugPluginDir;
143 debugPluginDir.Open( testpath );
145 if( debugPluginDir.IsOpened()
146 && debugPluginDir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS ) )
150 while( debugPluginDir.GetNext( &subdir ) )
156 checkPluginPath( std::string( fn.GetPathWithSep().ToUTF8() ), searchpaths );
158 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
162 fn.Assign( wxStandardPaths::Get().GetExecutablePath() );
164 if( fn.GetName() == wxT(
"kicad" ) )
166 fn.AppendDir( wxT(
".." ) );
170 fn.AppendDir( wxT(
".." ) );
171 fn.AppendDir( wxT(
".." ) );
172 fn.AppendDir( wxT(
".." ) );
173 fn.AppendDir( wxT(
".." ) );
174 fn.AppendDir( wxT(
"kicad" ) );
175 fn.AppendDir( wxT(
"KiCad.app" ) );
176 fn.AppendDir( wxT(
"Contents" ) );
179 fn.AppendDir( wxT(
"PlugIns" ) );
180 fn.AppendDir( wxT(
"3d" ) );
183 std::string testpath = std::string( fn.GetPathWithSep().ToUTF8() );
193 checkPluginPath( PATHS::GetOSXKicadMachineDataDir() + wxT(
"/PlugIns/3d" ), searchpaths );
201 std::list< wxString >::iterator sPL = searchpaths.begin();
202 std::list< wxString >::iterator ePL = searchpaths.end();
207 __FILE__, __FUNCTION__, __LINE__, (*sPL).ToUTF8() );
213 if( pluginlist.empty() )
216 sPL = pluginlist.begin();
217 ePL = pluginlist.end();
223 if( pp->
Open( sPL->ToUTF8() ) )
226 __FILE__, __FUNCTION__, __LINE__ );
232 __FILE__, __FUNCTION__, __LINE__, nf );
234 for(
int i = 0; i < nf; ++i )
250 __FILE__, __FUNCTION__, __LINE__ );
259 __FILE__, __FUNCTION__, __LINE__ );
275 nameFilter = wxT(
"*" );
278 nameFilter.Append( wxDynamicLibrary::GetDllExt( wxDL_MODULE ) );
285 nameFilter.Append( wxS(
".so" ) );
288 wxString lp = wd.GetNameWithSep();
290 if( wd.GetFirst( &lName, nameFilter, wxDIR_FILES ) )
295 while( wd.GetNext( &lName ) )
307 std::list< wxString >& aPluginList )
311 if( aPath.empty() || !wxFileName::FileExists( aPath ) )
319 wxString wxpath =
path.GetFullPath();
320 std::list< wxString >::iterator bl = aPluginList.begin();
321 std::list< wxString >::iterator el = aPluginList.end();
325 if( 0 == (*bl).Cmp( wxpath ) )
332 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
334 if( !
path.GetName().StartsWith(
"s3d_plugin" )
335 && !
path.GetName().StartsWith(
"libs3d_plugin" ) )
341 aPluginList.push_back( wxpath );
343 wxLogTrace(
MASK_3D_PLUGINMGR, wxT(
" * [INFO] found 3D plugin '%s'\n" ), wxpath.GetData() );
348 std::list< wxString >& aSearchList )
353 wxLogTrace(
MASK_3D_PLUGINMGR, wxT(
" * [INFO] checking if valid plugin directory '%s'\n" ),
357 path.AssignDir( aPath );
360 if( !wxFileName::DirExists(
path.GetFullPath() ) )
364 wxString wxpath =
path.GetFullPath();
365 std::list< wxString >::iterator bl = aSearchList.begin();
366 std::list< wxString >::iterator el = aSearchList.end();
370 if( 0 == (*bl).Cmp( wxpath ) )
376 aSearchList.push_back( wxpath );
383 if( aFilterString.empty() )
391 if( 0 == (*sFF).Cmp( aFilterString ) )
405 if(
nullptr == aPlugin )
411 __FILE__, __FUNCTION__, __LINE__, nExt );
413 for(
int i = 0; i < nExt; ++i )
432 return &m_FileFilters;
438 wxFileName raw( aFileName );
439 wxString ext_to_find = raw.GetExt();
444 ext_to_find.MakeLower();
448 if( ext_to_find == wxT(
"gz" ) )
450 wxFileName second( raw.GetName() );
451 ext_to_find = second.GetExt() + wxT(
".gz" );
454 std::pair < std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::iterator,
455 std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::iterator > items;
457 items =
m_ExtMap.equal_range( ext_to_find );
458 std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::iterator sL = items.first;
460 while( sL != items.second )
462 if( sL->second->CanRender() )
464 SCENEGRAPH* sp = sL->second->Load( aFileName.ToUTF8() );
468 sL->second->GetPluginInfo( aPluginInfo );
482 std::list< KICAD_PLUGIN_LDR_3D* >::iterator sP =
m_Plugins.begin();
483 std::list< KICAD_PLUGIN_LDR_3D* >::iterator eP =
m_Plugins.end();
486 __FILE__, __FUNCTION__, __LINE__,
static_cast<int>(
m_Plugins.size() ) );
498 if(
nullptr == aTag || aTag[0] == 0 ||
m_Plugins.empty() )
501 std::string tname = aTag;
504 size_t cpos = tname.find(
':' );
507 if( cpos == std::string::npos || cpos == 0 )
510 pname = tname.substr( 0, cpos );
513 std::list< KICAD_PLUGIN_LDR_3D* >::iterator pS =
m_Plugins.begin();
514 std::list< KICAD_PLUGIN_LDR_3D* >::iterator pE =
m_Plugins.end();
519 (*pS)->GetPluginInfo( ptag );
523 if( !ptag.compare( 0, pname.size(), pname ) )
525 if( ptag.compare( tname ) )
describes the runtime-loadable interface to support loading and parsing of 3D models.
bool Open(const wxString &aFullFileName) override
Open a plugin of the given class, performs version compatibility checks, and links all required funct...
char const * GetFileFilter(int aIndex)
char const * GetModelExtension(int aIndex)
void Close(void) override
Clean up and closes/unloads the plugin.
static wxString GetStockPlugins3DPath()
Gets the stock (install) 3d viewer plugins path.
void addFilterString(const wxString &aFilterString)
add an entry to the file filter list
std::list< wxString > m_FileFilters
list of file filters
std::list< KICAD_PLUGIN_LDR_3D * > m_Plugins
list of discovered plugins
void ClosePlugins(void)
Iterate through all discovered plugins and closes them to reclaim memory.
virtual ~S3D_PLUGIN_MANAGER()
void loadPlugins(void)
load plugins
SCENEGRAPH * Load3DModel(const wxString &aFileName, std::string &aPluginInfo)
void checkPluginPath(const wxString &aPath, std::list< wxString > &aSearchList)
check the existence of a path and add it to the path search list
void listPlugins(const wxString &aPath, std::list< wxString > &aPluginList)
list potential plugins
std::list< wxString > const * GetFileFilters(void) const noexcept
Return the list of file filters; this will contain at least the default "All Files (*....
void checkPluginName(const wxString &aPath, std::list< wxString > &aPluginList)
check the existence of a plugin name and add it to the list
std::multimap< const wxString, KICAD_PLUGIN_LDR_3D * > m_ExtMap
mapping of extensions to available plugins
bool CheckTag(const char *aTag)
Check the given tag and returns true if the plugin named in the tag is not loaded or the plugin is lo...
void addExtensionMap(KICAD_PLUGIN_LDR_3D *aPlugin)
add entries to the extension map
Define the basic data set required to represent a 3D model.
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
#define MASK_3D_PLUGINMGR
Flag to enable 3D plugin manager debug tracing.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().