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:
@@ -33,7 +33,6 @@
|
||||
#include <QMessageBox>
|
||||
#include <SMESH_Mesh.hxx>
|
||||
#include <SMESHDS_Mesh.hxx>
|
||||
#include <Standard_math.hxx>
|
||||
#include <SMESH_MeshEditor.hxx>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -127,18 +127,6 @@ std::list<ImportExportSettings::CodePage> ImportExportSettings::getCodePageList(
|
||||
return codePageList;
|
||||
}
|
||||
|
||||
void ImportExportSettings::setReadShowDialogImport(bool on)
|
||||
{
|
||||
auto grp = pGroup->GetGroup("hSTEP");
|
||||
grp->SetBool("ReadShowDialogImport", on);
|
||||
}
|
||||
|
||||
bool ImportExportSettings::getReadShowDialogImport() const
|
||||
{
|
||||
auto grp = pGroup->GetGroup("hSTEP");
|
||||
return grp->GetBool("ReadShowDialogImport", false);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void ImportExportSettings::initSTEP(Base::Reference<ParameterGrp> hGrp)
|
||||
|
||||
@@ -103,9 +103,6 @@ public:
|
||||
ImportMode getImportMode() const;
|
||||
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
void setReadShowDialogImport(bool);
|
||||
bool getReadShowDialogImport() const;
|
||||
|
||||
void setImportCodePage(int);
|
||||
Resource_FormatType getImportCodePage() const;
|
||||
std::list<ImportExportSettings::CodePage> getCodePageList() const;
|
||||
|
||||
@@ -47,6 +47,15 @@ bool ImportExportSettings::isVisibleExportDialog() const
|
||||
return pGroup->GetBool("VisibleExportDialog", true);
|
||||
}
|
||||
|
||||
void ImportExportSettings::setVisibleImportDialog(bool on)
|
||||
{
|
||||
pGroup->SetBool("VisibleImportDialog", on);
|
||||
}
|
||||
|
||||
bool ImportExportSettings::isVisibleImportDialog() const
|
||||
{
|
||||
return pGroup->GetBool("VisibleImportDialog", true);
|
||||
}
|
||||
|
||||
void ImportExportSettings::setWriteSurfaceCurveMode(bool on)
|
||||
{
|
||||
|
||||
@@ -40,6 +40,9 @@ public:
|
||||
void setVisibleExportDialog(bool);
|
||||
bool isVisibleExportDialog() const;
|
||||
|
||||
void setVisibleImportDialog(bool);
|
||||
bool isVisibleImportDialog() const;
|
||||
|
||||
void setWriteSurfaceCurveMode(bool);
|
||||
bool getWriteSurfaceCurveMode() const;
|
||||
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <QDialogButtonBox>
|
||||
#endif
|
||||
|
||||
#include <Mod/Part/App/OCAF/ImportExportSettings.h>
|
||||
#include <Mod/Part/App/STEP/ImportExportSettings.h>
|
||||
|
||||
@@ -45,7 +49,6 @@ DlgImportStep::DlgImportStep(QWidget* parent)
|
||||
ui->checkBoxExpandCompound->setChecked(settings.getExpandCompound());
|
||||
ui->checkBoxShowProgress->setChecked(settings.getShowProgress());
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
ui->checkBoxShowOnImport->setChecked(settings.getReadShowDialogImport());
|
||||
std::list<Part::OCAF::ImportExportSettings::CodePage> codepagelist;
|
||||
codepagelist = settings.getCodePageList();
|
||||
for (const auto& codePage : codepagelist) {
|
||||
@@ -54,10 +57,8 @@ DlgImportStep::DlgImportStep(QWidget* parent)
|
||||
#else
|
||||
// hide options that not supported in this OCCT version (7.8.0)
|
||||
ui->label_6->hide();
|
||||
ui->checkBoxShowOnImport->hide();
|
||||
ui->comboBoxImportCodePage->hide();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +70,6 @@ void DlgImportStep::saveSettings()
|
||||
{
|
||||
// (h)STEP of Import module
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
ui->checkBoxShowOnImport->onSave();
|
||||
ui->comboBoxImportCodePage->onSave();
|
||||
#endif
|
||||
ui->checkBoxMergeCompound->onSave();
|
||||
@@ -86,7 +86,6 @@ void DlgImportStep::loadSettings()
|
||||
{
|
||||
// (h)STEP of Import module
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
ui->checkBoxShowOnImport->onRestore();
|
||||
ui->comboBoxImportCodePage->onRestore();
|
||||
#endif
|
||||
ui->checkBoxMergeCompound->onRestore();
|
||||
@@ -99,6 +98,25 @@ void DlgImportStep::loadSettings()
|
||||
ui->comboBoxImportMode->onRestore();
|
||||
}
|
||||
|
||||
StepImportSettings DlgImportStep::getSettings() const
|
||||
{
|
||||
StepImportSettings set;
|
||||
Part::OCAF::ImportExportSettings settings;
|
||||
set.merge = settings.getReadShapeCompoundMode();
|
||||
set.useLinkGroup = settings.getUseLinkGroup();
|
||||
set.useBaseName = settings.getUseBaseName();
|
||||
set.importHidden = settings.getImportHiddenObject();
|
||||
set.reduceObjects = settings.getReduceObjects();
|
||||
set.showProgress = settings.getShowProgress();
|
||||
set.expandCompound = settings.getExpandCompound();
|
||||
set.mode = static_cast<int>(settings.getImportMode());
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
Resource_FormatType cp = settings.getImportCodePage();
|
||||
set.codePage = static_cast<int>(cp);
|
||||
#endif
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the strings of the subwidgets using the current language.
|
||||
*/
|
||||
@@ -112,5 +130,57 @@ void DlgImportStep::changeEvent(QEvent *e)
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
TaskImportStep::TaskImportStep(QWidget* parent)
|
||||
: QDialog(parent)
|
||||
, ui(new DlgImportStep(this))
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::ArrowCursor);
|
||||
|
||||
ui->loadSettings();
|
||||
setWindowTitle(ui->windowTitle());
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->addWidget(ui.get());
|
||||
setLayout(layout);
|
||||
|
||||
showThis = new QCheckBox(this);
|
||||
showThis->setText(tr("Don't show this dialog again"));
|
||||
layout->addWidget(showThis);
|
||||
|
||||
QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
|
||||
buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
layout->addWidget(buttonBox);
|
||||
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &TaskImportStep::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &TaskImportStep::reject);
|
||||
}
|
||||
|
||||
TaskImportStep::~TaskImportStep()
|
||||
{
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void TaskImportStep::accept()
|
||||
{
|
||||
QDialog::accept();
|
||||
ui->saveSettings();
|
||||
|
||||
Part::STEP::ImportExportSettings settings;
|
||||
settings.setVisibleImportDialog(!showThis->isChecked());
|
||||
}
|
||||
|
||||
bool TaskImportStep::showDialog() const
|
||||
{
|
||||
Part::STEP::ImportExportSettings settings;
|
||||
return settings.isVisibleImportDialog();
|
||||
}
|
||||
|
||||
StepImportSettings TaskImportStep::getSettings() const
|
||||
{
|
||||
return ui->getSettings();
|
||||
}
|
||||
|
||||
|
||||
#include "moc_DlgImportStep.cpp"
|
||||
|
||||
@@ -24,13 +24,28 @@
|
||||
#ifndef PARTGUI_DLGIMPORTSTEP_H
|
||||
#define PARTGUI_DLGIMPORTSTEP_H
|
||||
|
||||
#include <Mod/Part/PartGlobal.h>
|
||||
#include <Gui/PropertyPage.h>
|
||||
#include <QDialog>
|
||||
|
||||
class QButtonGroup;
|
||||
class QCheckBox;
|
||||
|
||||
namespace PartGui {
|
||||
|
||||
struct StepImportSettings
|
||||
{
|
||||
bool merge = false;
|
||||
bool useLinkGroup = false;
|
||||
bool useBaseName = true;
|
||||
bool importHidden = true;
|
||||
bool reduceObjects = false;
|
||||
bool showProgress = false;
|
||||
bool expandCompound = false;
|
||||
int mode = 0;
|
||||
int codePage = -1;
|
||||
};
|
||||
|
||||
class Ui_DlgImportStep;
|
||||
class DlgImportStep : public Gui::Dialog::PreferencePage
|
||||
{
|
||||
@@ -43,6 +58,8 @@ public:
|
||||
void saveSettings() override;
|
||||
void loadSettings() override;
|
||||
|
||||
StepImportSettings getSettings() const;
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e) override;
|
||||
|
||||
@@ -50,6 +67,25 @@ private:
|
||||
std::unique_ptr<Ui_DlgImportStep> ui;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class PartGuiExport TaskImportStep : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TaskImportStep(QWidget* parent = nullptr);
|
||||
~TaskImportStep() override;
|
||||
|
||||
bool showDialog() const;
|
||||
void accept() override;
|
||||
StepImportSettings getSettings() const;
|
||||
|
||||
private:
|
||||
QCheckBox* showThis;
|
||||
std::unique_ptr<DlgImportStep> ui;
|
||||
};
|
||||
|
||||
} // namespace PartGui
|
||||
|
||||
#endif // PARTGUI_DLGIMPORTSTEP_H
|
||||
|
||||
@@ -20,22 +20,6 @@
|
||||
<string>Import</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="Gui::PrefCheckBox" name="checkBoxShowOnImport">
|
||||
<property name="toolTip">
|
||||
<string>If checked, this Dialog will be shown during Import</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Show this Dialog when importing</string>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>ReadShowDialogImport</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Import/hSTEP</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::PrefCheckBox" name="checkBoxMergeCompound">
|
||||
<property name="toolTip">
|
||||
|
||||
Reference in New Issue
Block a user