App: add methods to change import/export module of a registered filetype
This commit is contained in:
@@ -130,13 +130,13 @@
|
||||
using namespace App;
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
using namespace boost::program_options;
|
||||
|
||||
|
||||
// scriptings (scripts are built-in but can be overridden by command line option)
|
||||
#include <App/InitScript.h>
|
||||
#include <App/TestScript.h>
|
||||
#include <App/CMakeScript.h>
|
||||
using namespace boost::program_options;
|
||||
|
||||
|
||||
// scriptings (scripts are built-in but can be overridden by command line option)
|
||||
#include <App/InitScript.h>
|
||||
#include <App/TestScript.h>
|
||||
#include <App/CMakeScript.h>
|
||||
|
||||
#ifdef _MSC_VER // New handler for Microsoft Visual C++ compiler
|
||||
# pragma warning( disable : 4535 )
|
||||
@@ -1082,6 +1082,16 @@ void Application::addImportType(const char* Type, const char* ModuleName)
|
||||
}
|
||||
}
|
||||
|
||||
void Application::changeImportModule(const char* Type, const char* OldModuleName, const char* NewModuleName)
|
||||
{
|
||||
for (auto& it : _mImportTypes) {
|
||||
if (it.filter == Type && it.module == OldModuleName) {
|
||||
it.module = NewModuleName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> Application::getImportModules(const char* Type) const
|
||||
{
|
||||
std::vector<std::string> modules;
|
||||
@@ -1195,6 +1205,16 @@ void Application::addExportType(const char* Type, const char* ModuleName)
|
||||
}
|
||||
}
|
||||
|
||||
void Application::changeExportModule(const char* Type, const char* OldModuleName, const char* NewModuleName)
|
||||
{
|
||||
for (auto& it : _mExportTypes) {
|
||||
if (it.filter == Type && it.module == OldModuleName) {
|
||||
it.module = NewModuleName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> Application::getExportModules(const char* Type) const
|
||||
{
|
||||
std::vector<std::string> modules;
|
||||
@@ -2256,7 +2276,7 @@ void Application::LoadParameters(void)
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
// fix weird error while linking boost (all versions of VC)
|
||||
// VS2010: https://forum.freecadweb.org/viewtopic.php?f=4&t=1886&p=12553&hilit=boost%3A%3Afilesystem%3A%3Aget#p12553
|
||||
// VS2010: https://forum.freecadweb.org/viewtopic.php?f=4&t=1886&p=12553&hilit=boost%3A%3Afilesystem%3A%3Aget#p12553
|
||||
namespace boost { namespace program_options { std::string arg="arg"; } }
|
||||
#if (defined (BOOST_VERSION) && (BOOST_VERSION >= 104100))
|
||||
namespace boost { namespace program_options {
|
||||
@@ -2946,7 +2966,7 @@ std::string Application::FindHomePath(const char* sCall)
|
||||
binPath += L"bin";
|
||||
SetDllDirectoryW(binPath.c_str());
|
||||
|
||||
// https://stackoverflow.com/questions/5625884/conversion-of-stdwstring-to-qstring-throws-linker-error
|
||||
// https://stackoverflow.com/questions/5625884/conversion-of-stdwstring-to-qstring-throws-linker-error
|
||||
#ifdef _MSC_VER
|
||||
QString str = QString::fromUtf16(reinterpret_cast<const ushort *>(homePath.c_str()));
|
||||
#else
|
||||
|
||||
@@ -300,6 +300,8 @@ public:
|
||||
//@{
|
||||
/// Register an import filetype and a module name
|
||||
void addImportType(const char* Type, const char* ModuleName);
|
||||
/// Change the module name of a registered filetype
|
||||
void changeImportModule(const char* Type, const char* OldModuleName, const char* NewModuleName);
|
||||
/// Return a list of modules that support the given filetype.
|
||||
std::vector<std::string> getImportModules(const char* Type) const;
|
||||
/// Return a list of all modules.
|
||||
@@ -316,6 +318,8 @@ public:
|
||||
//@{
|
||||
/// Register an export filetype and a module name
|
||||
void addExportType(const char* Type, const char* ModuleName);
|
||||
/// Change the module name of a registered filetype
|
||||
void changeExportModule(const char* Type, const char* OldModuleName, const char* NewModuleName);
|
||||
/// Return a list of modules that support the given filetype.
|
||||
std::vector<std::string> getExportModules(const char* Type) const;
|
||||
/// Return a list of all modules.
|
||||
@@ -458,8 +462,10 @@ private:
|
||||
static PyObject* sSetConfig (PyObject *self,PyObject *args);
|
||||
static PyObject* sDumpConfig (PyObject *self,PyObject *args);
|
||||
static PyObject* sAddImportType (PyObject *self,PyObject *args);
|
||||
static PyObject* sChangeImportModule(PyObject *self,PyObject *args);
|
||||
static PyObject* sGetImportType (PyObject *self,PyObject *args);
|
||||
static PyObject* sAddExportType (PyObject *self,PyObject *args);
|
||||
static PyObject* sChangeExportModule(PyObject *self,PyObject *args);
|
||||
static PyObject* sGetExportType (PyObject *self,PyObject *args);
|
||||
static PyObject* sGetResourceDir (PyObject *self,PyObject *args);
|
||||
static PyObject* sGetUserAppDataDir (PyObject *self,PyObject *args);
|
||||
|
||||
@@ -72,6 +72,8 @@ PyMethodDef Application::Methods[] = {
|
||||
"Dump the configuration to the output."},
|
||||
{"addImportType", (PyCFunction) Application::sAddImportType, METH_VARARGS,
|
||||
"Register filetype for import"},
|
||||
{"changeImportModule", (PyCFunction) Application::sChangeImportModule, METH_VARARGS,
|
||||
"Change the import module name of a registered filetype"},
|
||||
{"getImportType", (PyCFunction) Application::sGetImportType, METH_VARARGS,
|
||||
"Get the name of the module that can import the filetype"},
|
||||
{"EndingAdd", (PyCFunction) Application::sAddImportType, METH_VARARGS, // deprecated
|
||||
@@ -80,6 +82,8 @@ PyMethodDef Application::Methods[] = {
|
||||
"deprecated -- use getImportType"},
|
||||
{"addExportType", (PyCFunction) Application::sAddExportType, METH_VARARGS,
|
||||
"Register filetype for export"},
|
||||
{"changeExportModule", (PyCFunction) Application::sChangeExportModule, METH_VARARGS,
|
||||
"Change the export module name of a registered filetype"},
|
||||
{"getExportType", (PyCFunction) Application::sGetExportType, METH_VARARGS,
|
||||
"Get the name of the module that can export the filetype"},
|
||||
{"getResourceDir", (PyCFunction) Application::sGetResourceDir, METH_VARARGS,
|
||||
@@ -526,6 +530,18 @@ PyObject* Application::sAddImportType(PyObject * /*self*/, PyObject *args)
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* Application::sChangeImportModule(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *key,*oldMod,*newMod;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "sss", &key,&oldMod,&newMod))
|
||||
return nullptr;
|
||||
|
||||
GetApplication().changeImportModule(key,oldMod,newMod);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* Application::sGetImportType(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char* psKey=0;
|
||||
@@ -578,6 +594,18 @@ PyObject* Application::sAddExportType(PyObject * /*self*/, PyObject *args)
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* Application::sChangeExportModule(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *key,*oldMod,*newMod;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "sss", &key,&oldMod,&newMod))
|
||||
return nullptr;
|
||||
|
||||
GetApplication().changeExportModule(key,oldMod,newMod);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* Application::sGetExportType(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char* psKey=0;
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
#***************************************************************************/
|
||||
|
||||
|
||||
# Registered in Part's Init.py file
|
||||
FreeCAD.changeImportModule("STEP with colors (*.step *.stp)","Import","ImportGui")
|
||||
FreeCAD.changeExportModule("STEP with colors (*.step *.stp)","Import","ImportGui")
|
||||
|
||||
"""
|
||||
class ImportWorkbench ( Workbench ):
|
||||
"Import workbench object"
|
||||
|
||||
@@ -32,7 +32,7 @@ FreeCAD.addImportType("BREP format (*.brep *.brp)","Part")
|
||||
FreeCAD.addExportType("BREP format (*.brep *.brp)","Part")
|
||||
FreeCAD.addImportType("IGES format (*.iges *.igs)","Part")
|
||||
FreeCAD.addExportType("IGES format (*.iges *.igs)","Part")
|
||||
FreeCAD.addImportType("STEP with colors (*.step *.stp)","ImportGui")
|
||||
FreeCAD.addExportType("STEP with colors (*.step *.stp)","ImportGui")
|
||||
FreeCAD.addImportType("STEP with colors (*.step *.stp)","Import")
|
||||
FreeCAD.addExportType("STEP with colors (*.step *.stp)","Import")
|
||||
|
||||
FreeCAD.__unit_test__ += [ "TestPartApp" ]
|
||||
|
||||
Reference in New Issue
Block a user