Import: Move options handling to ImportGui.importOptions
Currently a modal dialog is used directly in ImportGui.open()/ImportGui.insert() that makes it impossible to use the functions in a script because they will be blocked
This commit is contained in:
@@ -74,6 +74,7 @@
|
||||
#include <Mod/Part/App/ProgressIndicator.h>
|
||||
#include <Mod/Part/App/encodeFilename.h>
|
||||
#include <Mod/Part/Gui/DlgExportStep.h>
|
||||
#include <Mod/Part/Gui/DlgImportStep.h>
|
||||
#include <Mod/Part/Gui/ViewProvider.h>
|
||||
|
||||
|
||||
@@ -98,6 +99,9 @@ public:
|
||||
&Module::readDXF,
|
||||
"readDXF(filename,[document,ignore_errors,option_source]): Imports a "
|
||||
"DXF file into the given document. ignore_errors is True by default.");
|
||||
add_varargs_method("importOptions",
|
||||
&Module::importOptions,
|
||||
"importOptions(string) -- Return the import options of a file type.");
|
||||
add_varargs_method("exportOptions",
|
||||
&Module::exportOptions,
|
||||
"exportOptions(string) -- Return the export options of a file type.");
|
||||
@@ -109,23 +113,63 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
Py::Object importOptions(const Py::Tuple& args)
|
||||
{
|
||||
char* Name {};
|
||||
if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &Name)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
std::string Utf8Name = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
std::string name8bit = Part::encodeFilename(Utf8Name);
|
||||
|
||||
Py::Dict options;
|
||||
Base::FileInfo file(name8bit.c_str());
|
||||
if (file.hasExtension({"stp", "step"})) {
|
||||
PartGui::TaskImportStep dlg(Gui::getMainWindow());
|
||||
if (!dlg.showDialog() || dlg.exec()) {
|
||||
auto stepSettings = dlg.getSettings();
|
||||
options.setItem("merge", Py::Boolean(stepSettings.merge));
|
||||
options.setItem("useLinkGroup", Py::Boolean(stepSettings.useLinkGroup));
|
||||
options.setItem("useBaseName", Py::Boolean(stepSettings.useBaseName));
|
||||
options.setItem("importHidden", Py::Boolean(stepSettings.importHidden));
|
||||
options.setItem("reduceObjects", Py::Boolean(stepSettings.reduceObjects));
|
||||
options.setItem("showProgress", Py::Boolean(stepSettings.showProgress));
|
||||
options.setItem("expandCompound", Py::Boolean(stepSettings.expandCompound));
|
||||
options.setItem("mode", Py::Long(stepSettings.mode));
|
||||
options.setItem("codePage", Py::Long(stepSettings.codePage));
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
Py::Object insert(const Py::Tuple& args, const Py::Dict& kwds)
|
||||
{
|
||||
char* Name;
|
||||
char* DocName = nullptr;
|
||||
PyObject* pyoptions = nullptr;
|
||||
PyObject* importHidden = Py_None;
|
||||
PyObject* merge = Py_None;
|
||||
PyObject* useLinkGroup = Py_None;
|
||||
int mode = -1;
|
||||
static const std::array<const char*, 7>
|
||||
kwd_list {"name", "docName", "importHidden", "merge", "useLinkGroup", "mode", nullptr};
|
||||
static const std::array<const char*, 8> kwd_list {"name",
|
||||
"docName",
|
||||
"options",
|
||||
"importHidden",
|
||||
"merge",
|
||||
"useLinkGroup",
|
||||
"mode",
|
||||
nullptr};
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args.ptr(),
|
||||
kwds.ptr(),
|
||||
"et|sO!O!O!i",
|
||||
"et|sO!O!O!O!i",
|
||||
kwd_list,
|
||||
"utf-8",
|
||||
&Name,
|
||||
&DocName,
|
||||
&PyDict_Type,
|
||||
&pyoptions,
|
||||
&PyBool_Type,
|
||||
&importHidden,
|
||||
&PyBool_Type,
|
||||
@@ -138,7 +182,6 @@ private:
|
||||
|
||||
std::string Utf8Name = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
std::string name8bit = Part::encodeFilename(Utf8Name);
|
||||
|
||||
try {
|
||||
Base::FileInfo file(Utf8Name.c_str());
|
||||
@@ -165,15 +208,52 @@ private:
|
||||
mode = ocaf.getMode();
|
||||
}
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
auto handle = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/Import/hSTEP");
|
||||
if (handle->GetBool("ReadShowDialogImport", false)) {
|
||||
Gui::Command::doCommand(Gui::Command::Gui,
|
||||
"Gui.showPreferences('Import-Export', 8)");
|
||||
}
|
||||
Part::OCAF::ImportExportSettings settings;
|
||||
Resource_FormatType cp = settings.getImportCodePage();
|
||||
Resource_FormatType cp = Resource_FormatType_UTF8;
|
||||
#endif
|
||||
|
||||
// new way
|
||||
if (pyoptions) {
|
||||
Py::Dict options(pyoptions);
|
||||
if (options.hasKey("merge")) {
|
||||
ocaf.setMerge(static_cast<bool>(Py::Boolean(options.getItem("merge"))));
|
||||
}
|
||||
if (options.hasKey("useLinkGroup")) {
|
||||
ocaf.setUseLinkGroup(
|
||||
static_cast<bool>(Py::Boolean(options.getItem("useLinkGroup"))));
|
||||
}
|
||||
if (options.hasKey("useBaseName")) {
|
||||
ocaf.setBaseName(
|
||||
static_cast<bool>(Py::Boolean(options.getItem("useBaseName"))));
|
||||
}
|
||||
if (options.hasKey("importHidden")) {
|
||||
ocaf.setImportHiddenObject(
|
||||
static_cast<bool>(Py::Boolean(options.getItem("importHidden"))));
|
||||
}
|
||||
if (options.hasKey("reduceObjects")) {
|
||||
ocaf.setReduceObjects(
|
||||
static_cast<bool>(Py::Boolean(options.getItem("reduceObjects"))));
|
||||
}
|
||||
if (options.hasKey("showProgress")) {
|
||||
ocaf.setShowProgress(
|
||||
static_cast<bool>(Py::Boolean(options.getItem("showProgress"))));
|
||||
}
|
||||
if (options.hasKey("expandCompound")) {
|
||||
ocaf.setExpandCompound(
|
||||
static_cast<bool>(Py::Boolean(options.getItem("expandCompound"))));
|
||||
}
|
||||
if (options.hasKey("mode")) {
|
||||
ocaf.setMode(static_cast<int>(Py::Long(options.getItem("mode"))));
|
||||
}
|
||||
if (options.hasKey("codePage")) {
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
int codePage = static_cast<int>(Py::Long(options.getItem("codePage")));
|
||||
if (codePage >= 0) {
|
||||
cp = static_cast<Resource_FormatType>(codePage);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (mode && !pcDoc->isSaved()) {
|
||||
auto gdoc = Gui::Application::Instance->getDocument(pcDoc);
|
||||
if (!gdoc->save()) {
|
||||
|
||||
Reference in New Issue
Block a user