2015-12-08 07:31:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-01-31 02:21:12 +00:00
|
|
|
* Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
2020-12-16 18:19:28 +00:00
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-12-08 07:31:57 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
#include <iostream>
|
2016-01-31 02:21:12 +00:00
|
|
|
#include <sstream>
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-02-23 20:26:58 +00:00
|
|
|
#include <wx/dir.h>
|
2016-01-11 04:47:08 +00:00
|
|
|
#include <wx/dynlib.h>
|
2016-02-23 20:26:58 +00:00
|
|
|
#include <wx/filename.h>
|
|
|
|
#include <wx/log.h>
|
|
|
|
#include <wx/stdpaths.h>
|
|
|
|
#include <wx/string.h>
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-23 15:46:48 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <paths.h>
|
2015-12-09 07:30:48 +00:00
|
|
|
#include "3d_plugin_manager.h"
|
|
|
|
#include "plugins/3d/3d_plugin.h"
|
|
|
|
#include "3d_cache/sg/scenegraph.h"
|
2015-12-13 21:45:22 +00:00
|
|
|
#include "plugins/ldr/3d/pluginldr3D.h"
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag to enable 3D plugin manager debug tracing.
|
|
|
|
*
|
|
|
|
* Use "KI_TRACE_EDA_3D_VIEWER" to enable.
|
|
|
|
*
|
|
|
|
* @ingroup trace_env_vars
|
|
|
|
*/
|
2016-02-23 03:33:24 +00:00
|
|
|
#define MASK_3D_PLUGINMGR "3D_PLUGIN_MANAGER"
|
|
|
|
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
S3D_PLUGIN_MANAGER::S3D_PLUGIN_MANAGER()
|
|
|
|
{
|
|
|
|
// create the initial file filter list entry
|
2021-08-20 19:56:47 +00:00
|
|
|
m_FileFilters.push_back( _( "All Files" ) + wxT( " (*.*)|*.*" ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
// discover and load plugins
|
|
|
|
loadPlugins();
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if( !m_ExtMap.empty() )
|
|
|
|
{
|
2015-12-13 21:45:22 +00:00
|
|
|
std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::const_iterator sM = m_ExtMap.begin();
|
|
|
|
std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::const_iterator eM = m_ExtMap.end();
|
2016-02-23 03:33:24 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, " * Extension [plugin name]:\n" );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
while( sM != eM )
|
|
|
|
{
|
2016-08-19 07:45:59 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, " + '%s' [%s]\n", sM->first.GetData(),
|
2020-12-16 18:19:28 +00:00
|
|
|
sM->second->GetKicadPluginName() );
|
2015-12-08 07:31:57 +00:00
|
|
|
++sM;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-23 03:33:24 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, " * No plugins available\n" );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( !m_FileFilters.empty() )
|
|
|
|
{
|
|
|
|
/// list of file filters
|
|
|
|
std::list< wxString >::const_iterator sFF = m_FileFilters.begin();
|
|
|
|
std::list< wxString >::const_iterator eFF = m_FileFilters.end();
|
2016-02-23 03:33:24 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, " * File filters:\n" );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
while( sFF != eFF )
|
|
|
|
{
|
2016-08-19 07:45:59 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, " + '%s'\n", (*sFF).GetData() );
|
2015-12-08 07:31:57 +00:00
|
|
|
++sFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-23 03:33:24 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, " * No file filters available\n" );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
S3D_PLUGIN_MANAGER::~S3D_PLUGIN_MANAGER()
|
|
|
|
{
|
2015-12-13 21:45:22 +00:00
|
|
|
std::list< KICAD_PLUGIN_LDR_3D* >::iterator sP = m_Plugins.begin();
|
|
|
|
std::list< KICAD_PLUGIN_LDR_3D* >::iterator eP = m_Plugins.end();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
while( sP != eP )
|
|
|
|
{
|
|
|
|
(*sP)->Close();
|
|
|
|
delete *sP;
|
|
|
|
++sP;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Plugins.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void S3D_PLUGIN_MANAGER::loadPlugins( void )
|
|
|
|
{
|
|
|
|
std::list< wxString > searchpaths;
|
|
|
|
std::list< wxString > pluginlist;
|
|
|
|
wxFileName fn;
|
|
|
|
|
2016-02-29 23:08:19 +00:00
|
|
|
#ifndef __WXMAC__
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
#ifdef DEBUG
|
2015-12-08 07:31:57 +00:00
|
|
|
// set up to work from the build directory
|
|
|
|
fn.Assign( wxStandardPaths::Get().GetExecutablePath() );
|
2020-12-16 18:19:28 +00:00
|
|
|
fn.AppendDir( wxT( ".." ) );
|
|
|
|
fn.AppendDir( wxT( "plugins" ) );
|
|
|
|
fn.AppendDir( wxT( "3d" ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
std::string testpath = std::string( fn.GetPathWithSep().ToUTF8() );
|
|
|
|
checkPluginPath( testpath, searchpaths );
|
2017-08-21 12:17:01 +00:00
|
|
|
|
|
|
|
// add subdirectories too
|
2017-11-17 09:20:55 +00:00
|
|
|
wxDir debugPluginDir;
|
2017-08-21 12:17:01 +00:00
|
|
|
wxString subdir;
|
|
|
|
|
2017-11-17 09:20:55 +00:00
|
|
|
debugPluginDir.Open( testpath );
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
if( debugPluginDir.IsOpened() && debugPluginDir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS ) )
|
2017-08-21 12:17:01 +00:00
|
|
|
{
|
|
|
|
checkPluginPath( testpath + subdir, searchpaths );
|
|
|
|
|
|
|
|
while( debugPluginDir.GetNext( &subdir ) )
|
|
|
|
checkPluginPath( testpath + subdir, searchpaths );
|
|
|
|
}
|
2020-12-16 18:19:28 +00:00
|
|
|
#endif
|
2015-12-13 21:45:22 +00:00
|
|
|
|
2021-01-23 15:46:48 +00:00
|
|
|
fn.AssignDir( PATHS::GetStockPlugins3DPath() );
|
2017-04-17 01:41:21 +00:00
|
|
|
checkPluginPath( std::string( fn.GetPathWithSep().ToUTF8() ), searchpaths );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2017-04-17 01:41:21 +00:00
|
|
|
// check for per-user third party plugins
|
2015-12-08 07:31:57 +00:00
|
|
|
// note: GetUserDataDir() gives '.pcbnew' rather than '.kicad' since it uses the exe name;
|
2021-01-23 15:46:48 +00:00
|
|
|
fn.AssignDir( PATHS::GetUserPlugins3DPath() );
|
2015-12-08 07:31:57 +00:00
|
|
|
checkPluginPath( fn.GetPathWithSep(), searchpaths );
|
2016-02-29 23:08:19 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
// Search path on OS X is
|
|
|
|
// (1) User ~/Library/Application Support/kicad/PlugIns/3d
|
2021-02-17 04:26:46 +00:00
|
|
|
checkPluginPath( PATHS::GetOSXKicadUserDataDir() + wxT( "/PlugIns/3d" ), searchpaths );
|
2020-12-16 18:19:28 +00:00
|
|
|
|
2016-02-29 23:08:19 +00:00
|
|
|
// (2) Machine /Library/Application Support/kicad/PlugIns/3d
|
2021-02-17 04:26:46 +00:00
|
|
|
checkPluginPath( PATHS::GetOSXKicadMachineDataDir() + wxT( "/PlugIns/3d" ), searchpaths );
|
2020-12-16 18:19:28 +00:00
|
|
|
|
2016-02-29 23:08:19 +00:00
|
|
|
// (3) Bundle kicad.app/Contents/PlugIns/3d
|
2021-01-23 21:45:02 +00:00
|
|
|
fn.AssignDir( PATHS::GetStockPlugins3DPath() );
|
2016-02-29 23:08:19 +00:00
|
|
|
checkPluginPath( fn.GetPathWithSep(), searchpaths );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
std::list< wxString >::iterator sPL = searchpaths.begin();
|
|
|
|
std::list< wxString >::iterator ePL = searchpaths.end();
|
|
|
|
|
|
|
|
while( sPL != ePL )
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, "%s:%s:%d * [DEBUG] searching path: '%s'",
|
|
|
|
__FILE__, __FUNCTION__, __LINE__, (*sPL).ToUTF8() );
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
listPlugins( *sPL, pluginlist );
|
|
|
|
++sPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pluginlist.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
sPL = pluginlist.begin();
|
|
|
|
ePL = pluginlist.end();
|
|
|
|
|
|
|
|
while( sPL != ePL )
|
|
|
|
{
|
2015-12-13 21:45:22 +00:00
|
|
|
KICAD_PLUGIN_LDR_3D* pp = new KICAD_PLUGIN_LDR_3D;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
if( pp->Open( sPL->ToUTF8() ) )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, "%s:%s:%d * [DEBUG] adding plugin",
|
|
|
|
__FILE__, __FUNCTION__, __LINE__ );
|
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
m_Plugins.push_back( pp );
|
|
|
|
int nf = pp->GetNFilters();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, "%s:%s:%d * [DEBUG] adding %d filters",
|
|
|
|
__FILE__, __FUNCTION__, __LINE__, nf );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
for( int i = 0; i < nf; ++i )
|
|
|
|
{
|
|
|
|
char const* cp = pp->GetFileFilter( i );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
if( cp )
|
|
|
|
addFilterString( wxString::FromUTF8Unchecked( cp ) );
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
addExtensionMap( pp );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
// close the loaded library
|
|
|
|
pp->Close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, "%s:%s:%d * [DEBUG] deleting plugin",
|
|
|
|
__FILE__, __FUNCTION__, __LINE__ );
|
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
delete pp;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++sPL;
|
|
|
|
}
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, "%s:%s:%d * [DEBUG] plugins loaded",
|
|
|
|
__FILE__, __FUNCTION__, __LINE__ );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
void S3D_PLUGIN_MANAGER::listPlugins( const wxString& aPath, std::list< wxString >& aPluginList )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-01-11 04:47:08 +00:00
|
|
|
// list potential plugins given a search path
|
2020-10-21 03:48:06 +00:00
|
|
|
wxString nameFilter; // filter for user-loadable libraries (aka footprints)
|
2015-12-08 07:31:57 +00:00
|
|
|
wxString lName; // stores name of enumerated files
|
|
|
|
wxString fName; // full name of file
|
|
|
|
wxDir wd;
|
|
|
|
wd.Open( aPath );
|
|
|
|
|
|
|
|
if( !wd.IsOpened() )
|
|
|
|
return;
|
|
|
|
|
2016-01-11 04:47:08 +00:00
|
|
|
nameFilter = wxT( "*" );
|
2016-02-29 23:08:19 +00:00
|
|
|
|
|
|
|
#ifndef __WXMAC__
|
2016-01-11 04:47:08 +00:00
|
|
|
nameFilter.Append( wxDynamicLibrary::GetDllExt( wxDL_MODULE ) );
|
2016-02-29 23:08:19 +00:00
|
|
|
#else
|
|
|
|
// wxDynamicLibrary::GetDllExt( wxDL_MODULE ) will return ".bundle" on OS X.
|
|
|
|
// This might be correct, but cmake builds a ".so" for a library MODULE.
|
|
|
|
// Per definition a loadable "xxx.bundle" is similar to an "xxx.app" app
|
|
|
|
// bundle being a folder with some special content in it. We obviously don't
|
|
|
|
// want to have that here for our loadable module, so just use ".so".
|
2016-06-09 05:48:49 +00:00
|
|
|
nameFilter.Append( ".so" );
|
2016-02-29 23:08:19 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
wxString lp = wd.GetNameWithSep();
|
|
|
|
|
2016-01-11 04:47:08 +00:00
|
|
|
if( wd.GetFirst( &lName, nameFilter, wxDIR_FILES ) )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-01-11 04:47:08 +00:00
|
|
|
fName = lp + lName;
|
|
|
|
checkPluginName( fName, aPluginList );
|
|
|
|
|
|
|
|
while( wd.GetNext( &lName ) )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
fName = lp + lName;
|
|
|
|
checkPluginName( fName, aPluginList );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wd.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void S3D_PLUGIN_MANAGER::checkPluginName( const wxString& aPath,
|
2020-12-16 18:19:28 +00:00
|
|
|
std::list< wxString >& aPluginList )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
// check the existence of a plugin name and add it to the list
|
|
|
|
|
|
|
|
if( aPath.empty() || !wxFileName::FileExists( aPath ) )
|
|
|
|
return;
|
|
|
|
|
2020-04-05 19:51:48 +00:00
|
|
|
wxFileName path( ExpandEnvVarSubstitutions( aPath, nullptr ) );
|
2016-06-09 05:48:49 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
path.Normalize();
|
|
|
|
|
|
|
|
// determine if the path is already in the list
|
|
|
|
wxString wxpath = path.GetFullPath();
|
|
|
|
std::list< wxString >::iterator bl = aPluginList.begin();
|
|
|
|
std::list< wxString >::iterator el = aPluginList.end();
|
|
|
|
|
|
|
|
while( bl != el )
|
|
|
|
{
|
|
|
|
if( 0 == (*bl).Cmp( wxpath ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
++bl;
|
|
|
|
}
|
|
|
|
|
|
|
|
aPluginList.push_back( wxpath );
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, " * [INFO] found 3D plugin '%s'\n", wxpath.GetData() );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void S3D_PLUGIN_MANAGER::checkPluginPath( const wxString& aPath,
|
2020-04-05 19:51:48 +00:00
|
|
|
std::list< wxString >& aSearchList )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
// check the existence of a path and add it to the path search list
|
|
|
|
if( aPath.empty() )
|
|
|
|
return;
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, " * [INFO] checking for 3D plugins in '%s'\n", aPath.GetData() );
|
2016-01-05 19:48:27 +00:00
|
|
|
|
2016-06-09 05:48:49 +00:00
|
|
|
wxFileName path;
|
|
|
|
|
|
|
|
if( aPath.StartsWith( "${" ) || aPath.StartsWith( "$(" ) )
|
2020-04-05 19:51:48 +00:00
|
|
|
path.Assign( ExpandEnvVarSubstitutions( aPath, nullptr ), "" );
|
2016-06-09 05:48:49 +00:00
|
|
|
else
|
|
|
|
path.Assign( aPath, "" );
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
path.Normalize();
|
|
|
|
|
|
|
|
if( !wxFileName::DirExists( path.GetFullPath() ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// determine if the directory is already in the list
|
|
|
|
wxString wxpath = path.GetFullPath();
|
|
|
|
std::list< wxString >::iterator bl = aSearchList.begin();
|
|
|
|
std::list< wxString >::iterator el = aSearchList.end();
|
|
|
|
|
|
|
|
while( bl != el )
|
|
|
|
{
|
|
|
|
if( 0 == (*bl).Cmp( wxpath ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
++bl;
|
|
|
|
}
|
|
|
|
|
|
|
|
aSearchList.push_back( wxpath );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void S3D_PLUGIN_MANAGER::addFilterString( const wxString& aFilterString )
|
|
|
|
{
|
|
|
|
// add an entry to the file filter list
|
|
|
|
if( aFilterString.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::list< wxString >::iterator sFF = m_FileFilters.begin();
|
|
|
|
std::list< wxString >::iterator eFF = m_FileFilters.end();
|
|
|
|
|
|
|
|
while( sFF != eFF )
|
|
|
|
{
|
|
|
|
if( 0 == (*sFF).Cmp( aFilterString ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
++sFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_FileFilters.push_back( aFilterString );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
void S3D_PLUGIN_MANAGER::addExtensionMap( KICAD_PLUGIN_LDR_3D* aPlugin )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
// add entries to the extension map
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr == aPlugin )
|
2015-12-08 07:31:57 +00:00
|
|
|
return;
|
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
int nExt = aPlugin->GetNExtensions();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, "%s:%s:%d * [INFO] adding %d extensions",
|
|
|
|
__FILE__, __FUNCTION__, __LINE__, nExt );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < nExt; ++i )
|
|
|
|
{
|
2015-12-13 21:45:22 +00:00
|
|
|
char const* cp = aPlugin->GetModelExtension( i );
|
|
|
|
wxString ws;
|
|
|
|
|
|
|
|
if( cp )
|
|
|
|
ws = wxString::FromUTF8Unchecked( cp );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
if( !ws.empty() )
|
|
|
|
{
|
2015-12-13 21:45:22 +00:00
|
|
|
m_ExtMap.insert( std::pair< const wxString, KICAD_PLUGIN_LDR_3D* >( ws, aPlugin ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
std::list< wxString > const* S3D_PLUGIN_MANAGER::GetFileFilters( void ) const noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
return &m_FileFilters;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-31 02:21:12 +00:00
|
|
|
SCENEGRAPH* S3D_PLUGIN_MANAGER::Load3DModel( const wxString& aFileName, std::string& aPluginInfo )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
wxFileName raw( aFileName );
|
2021-08-27 12:34:49 +00:00
|
|
|
wxString ext_to_find = raw.GetExt();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
#ifdef _WIN32
|
2017-02-22 09:22:33 +00:00
|
|
|
// note: plugins only have a lowercase filter within Windows; including an uppercase
|
|
|
|
// filter will result in duplicate file entries and should be avoided.
|
2021-08-27 12:34:49 +00:00
|
|
|
ext_to_find.MakeLower();
|
2020-12-16 18:19:28 +00:00
|
|
|
#endif
|
2017-02-22 09:22:33 +00:00
|
|
|
|
2021-08-30 21:42:08 +00:00
|
|
|
// .gz files are compressed versions that may have additional information in the previous extension
|
|
|
|
if( ext_to_find == "gz" )
|
|
|
|
{
|
|
|
|
wxFileName second( raw.GetName() );
|
|
|
|
ext_to_find = second.GetExt() + ".gz";
|
|
|
|
}
|
2021-08-27 12:34:49 +00:00
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
std::pair < std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::iterator,
|
|
|
|
std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::iterator > items;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-08-27 12:34:49 +00:00
|
|
|
items = m_ExtMap.equal_range( ext_to_find );
|
2015-12-13 21:45:22 +00:00
|
|
|
std::multimap< const wxString, KICAD_PLUGIN_LDR_3D* >::iterator sL = items.first;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
while( sL != items.second )
|
|
|
|
{
|
2015-12-13 21:45:22 +00:00
|
|
|
if( sL->second->CanRender() )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-01-11 03:04:54 +00:00
|
|
|
SCENEGRAPH* sp = sL->second->Load( aFileName.ToUTF8() );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr != sp )
|
2016-01-31 02:21:12 +00:00
|
|
|
{
|
|
|
|
sL->second->GetPluginInfo( aPluginInfo );
|
2015-12-08 07:31:57 +00:00
|
|
|
return sp;
|
2016-01-31 02:21:12 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++sL;
|
|
|
|
}
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
return nullptr;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void S3D_PLUGIN_MANAGER::ClosePlugins( void )
|
|
|
|
{
|
2015-12-13 21:45:22 +00:00
|
|
|
std::list< KICAD_PLUGIN_LDR_3D* >::iterator sP = m_Plugins.begin();
|
|
|
|
std::list< KICAD_PLUGIN_LDR_3D* >::iterator eP = m_Plugins.end();
|
|
|
|
|
2020-12-16 18:19:28 +00:00
|
|
|
wxLogTrace( MASK_3D_PLUGINMGR, "%s:%s:%d * [INFO] closing %d extensions",
|
|
|
|
__FILE__, __FUNCTION__, __LINE__, static_cast<int>( m_Plugins.size() ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
while( sP != eP )
|
|
|
|
{
|
|
|
|
(*sP)->Close();
|
|
|
|
++sP;
|
|
|
|
}
|
|
|
|
}
|
2016-01-31 02:21:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool S3D_PLUGIN_MANAGER::CheckTag( const char* aTag )
|
|
|
|
{
|
2020-12-16 18:19:28 +00:00
|
|
|
if( nullptr == aTag || aTag[0] == 0 || m_Plugins.empty() )
|
2016-01-31 02:21:12 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
std::string tname = aTag;
|
|
|
|
std::string pname; // plugin name
|
|
|
|
|
|
|
|
size_t cpos = tname.find( ':' );
|
|
|
|
|
|
|
|
// if there is no colon or plugin name then the tag is bad
|
|
|
|
if( cpos == std::string::npos || cpos == 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
pname = tname.substr( 0, cpos );
|
|
|
|
std::string ptag; // tag from the plugin
|
|
|
|
|
|
|
|
std::list< KICAD_PLUGIN_LDR_3D* >::iterator pS = m_Plugins.begin();
|
|
|
|
std::list< KICAD_PLUGIN_LDR_3D* >::iterator pE = m_Plugins.end();
|
|
|
|
|
|
|
|
while( pS != pE )
|
|
|
|
{
|
|
|
|
ptag.clear();
|
|
|
|
(*pS)->GetPluginInfo( ptag );
|
|
|
|
|
|
|
|
// if the plugin name matches then the version
|
|
|
|
// must also match
|
|
|
|
if( !ptag.compare( 0, pname.size(), pname ) )
|
|
|
|
{
|
|
|
|
if( ptag.compare( tname ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
++pS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|