From ebe7ceea33acde376ba446a7df6b85e1034c02f6 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 4 Oct 2022 20:30:03 +0200 Subject: [PATCH] Part: add dialog for STEP export --- src/Mod/Import/Gui/AppImportGuiPy.cpp | 15 +- .../Part/App/STEP/ImportExportSettings.cpp | 11 + src/Mod/Part/App/STEP/ImportExportSettings.h | 3 + src/Mod/Part/Gui/CMakeLists.txt | 4 + src/Mod/Part/Gui/DlgExportStep.cpp | 213 ++++++++++++++++ src/Mod/Part/Gui/DlgExportStep.h | 83 +++++++ src/Mod/Part/Gui/DlgExportStep.ui | 232 ++++++++++++++++++ 7 files changed, 554 insertions(+), 7 deletions(-) create mode 100644 src/Mod/Part/Gui/DlgExportStep.cpp create mode 100644 src/Mod/Part/Gui/DlgExportStep.h create mode 100644 src/Mod/Part/Gui/DlgExportStep.ui diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index e8f11ca207..c8d61826a1 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -101,6 +101,7 @@ #include #include #include +#include #include #include @@ -572,14 +573,14 @@ private: Py::Dict options; Base::FileInfo file(name8bit.c_str()); - // Here we can open a model dialog... if (file.hasExtension("stp") || file.hasExtension("step")) { - auto ocafSettings = Import::ExportOCAF2::customExportOptions(); - options.setItem("exportHidden", Py::Boolean(ocafSettings.exportHidden)); - options.setItem("keepPlacement", Py::Boolean(ocafSettings.keepPlacement)); - - Part::OCAF::ImportExportSettings stepSettings; - options.setItem("legacy", Py::Boolean(stepSettings.getExportLegacy())); + PartGui::TaskExportStep dlg(Gui::getMainWindow()); + if (!dlg.showDialog() || dlg.exec()) { + auto stepSettings = dlg.getSettings(); + options.setItem("exportHidden", Py::Boolean(stepSettings.exportHidden)); + options.setItem("keepPlacement", Py::Boolean(stepSettings.keepPlacement)); + options.setItem("legacy", Py::Boolean(stepSettings.exportLegacy)); + } } return options; diff --git a/src/Mod/Part/App/STEP/ImportExportSettings.cpp b/src/Mod/Part/App/STEP/ImportExportSettings.cpp index 28c99def00..3569d5cdf5 100644 --- a/src/Mod/Part/App/STEP/ImportExportSettings.cpp +++ b/src/Mod/Part/App/STEP/ImportExportSettings.cpp @@ -37,6 +37,17 @@ ImportExportSettings::ImportExportSettings() pGroup = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Part/STEP"); } +void ImportExportSettings::setVisibleExportDialog(bool on) +{ + pGroup->SetBool("VisibleExportDialog", on); +} + +bool ImportExportSettings::isVisibleExportDialog() const +{ + return pGroup->GetBool("VisibleExportDialog", true); +} + + void ImportExportSettings::setWriteSurfaceCurveMode(bool on) { ParameterGrp::handle grp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Part/General"); diff --git a/src/Mod/Part/App/STEP/ImportExportSettings.h b/src/Mod/Part/App/STEP/ImportExportSettings.h index aa255959b5..325f7821b8 100644 --- a/src/Mod/Part/App/STEP/ImportExportSettings.h +++ b/src/Mod/Part/App/STEP/ImportExportSettings.h @@ -37,6 +37,9 @@ class PartExport ImportExportSettings public: ImportExportSettings(); + void setVisibleExportDialog(bool); + bool isVisibleExportDialog() const; + void setWriteSurfaceCurveMode(bool); bool getWriteSurfaceCurveMode() const; diff --git a/src/Mod/Part/Gui/CMakeLists.txt b/src/Mod/Part/Gui/CMakeLists.txt index 4f1aeda1fc..f89e1e0905 100644 --- a/src/Mod/Part/Gui/CMakeLists.txt +++ b/src/Mod/Part/Gui/CMakeLists.txt @@ -48,6 +48,7 @@ set(PartGui_UIC_SRCS CrossSections.ui Mirroring.ui DlgBooleanOperation.ui + DlgExportStep.ui DlgExtrusion.ui DlgFilletEdges.ui DlgImportExportIges.ui @@ -100,6 +101,9 @@ SET(PartGui_SRCS DlgBooleanOperation.cpp DlgBooleanOperation.h DlgBooleanOperation.ui + DlgExportStep.cpp + DlgExportStep.h + DlgExportStep.ui DlgExtrusion.cpp DlgExtrusion.h DlgExtrusion.ui diff --git a/src/Mod/Part/Gui/DlgExportStep.cpp b/src/Mod/Part/Gui/DlgExportStep.cpp new file mode 100644 index 0000000000..0a2cf97ca6 --- /dev/null +++ b/src/Mod/Part/Gui/DlgExportStep.cpp @@ -0,0 +1,213 @@ +/*************************************************************************** + * Copyright (c) 2022 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +# include +# include +# include +#endif + +#include +#include +#include +#include + +#include "DlgExportStep.h" +#include "ui_DlgExportStep.h" + + +using namespace PartGui; + +DlgExportStep::DlgExportStep(QWidget* parent) + : PreferencePage(parent) + , ui(new Ui_DlgExportStep) +{ + ui->setupUi(this); + + ui->comboBoxSchema->setItemData(0, QByteArray("AP203")); + ui->comboBoxSchema->setItemData(1, QByteArray("AP214CD")); + ui->comboBoxSchema->setItemData(2, QByteArray("AP214DIS")); + ui->comboBoxSchema->setItemData(3, QByteArray("AP214IS")); + ui->comboBoxSchema->setItemData(4, QByteArray("AP242DIS")); + + ui->lineEditProduct->setReadOnly(true); + + // https://tracker.dev.opencascade.org/view.php?id=25654 + ui->checkBoxPcurves->setToolTip(tr("This parameter indicates whether parametric curves (curves in parametric space of surface)\n" + "should be written into the STEP file. This parameter can be set to off in order to minimize\n" + "the size of the resulting STEP file.")); + + QRegExp rx; + rx.setPattern(QString::fromLatin1("[\\x00-\\x7F]+")); + QRegExpValidator* companyValidator = new QRegExpValidator(ui->lineEditCompany); + companyValidator->setRegExp(rx); + ui->lineEditCompany->setValidator(companyValidator); + QRegExpValidator* authorValidator = new QRegExpValidator(ui->lineEditAuthor); + authorValidator->setRegExp(rx); + ui->lineEditAuthor->setValidator(authorValidator); + + Part::OCAF::ImportExportSettings settings; + ui->checkBoxExportHiddenObj->setChecked(settings.getExportHiddenObject()); + ui->checkBoxExportLegacy->setChecked(settings.getExportLegacy()); + ui->checkBoxKeepPlacement->setChecked(settings.getExportKeepPlacement()); +} + +/** + * Destroys the object and frees any allocated resources + */ +DlgExportStep::~DlgExportStep() +{ + // no need to delete child widgets, Qt does it all for us +} + +void DlgExportStep::saveSettings() +{ + // General + Part::STEP::ImportExportSettings settings; + settings.setWriteSurfaceCurveMode(ui->checkBoxPcurves->isChecked()); + + // STEP + int unit = ui->comboBoxUnits->currentIndex(); + settings.setUnit(static_cast(unit)); + + // scheme + // possible values: AP203, AP214CD (1996), AP214DIS (1998), AP214IS (2002), AP242DIS + QByteArray schema = ui->comboBoxSchema->itemData(ui->comboBoxSchema->currentIndex()).toByteArray(); + settings.setScheme(schema); + + // header info + settings.setCompany(ui->lineEditCompany->text().toLatin1()); + settings.setAuthor(ui->lineEditAuthor->text().toLatin1()); + + // (h)STEP of Import module + ui->checkBoxExportHiddenObj->onSave(); + ui->checkBoxExportLegacy->onSave(); + ui->checkBoxKeepPlacement->onSave(); +} + +void DlgExportStep::loadSettings() +{ + // General + Part::STEP::ImportExportSettings settings; + ui->checkBoxPcurves->setChecked(settings.getWriteSurfaceCurveMode()); + + // STEP + ui->comboBoxUnits->setCurrentIndex(static_cast(settings.getUnit())); + + // scheme + QByteArray ap(settings.getScheme().c_str()); + int index = ui->comboBoxSchema->findData(QVariant(ap)); + if (index >= 0) + ui->comboBoxSchema->setCurrentIndex(index); + + // header info + ui->lineEditCompany->setText(QString::fromStdString(settings.getCompany())); + ui->lineEditAuthor->setText(QString::fromStdString(settings.getAuthor())); + ui->lineEditProduct->setText(QString::fromStdString(settings.getProductName())); + + // (h)STEP of Import module + ui->checkBoxExportHiddenObj->onRestore(); + ui->checkBoxExportLegacy->onRestore(); + ui->checkBoxKeepPlacement->onRestore(); +} + +StepSettings DlgExportStep::getSettings() const +{ + StepSettings set; + set.exportLegacy = ui->checkBoxExportLegacy->isChecked(); + set.exportHidden = ui->checkBoxExportHiddenObj->isChecked(); + set.keepPlacement = ui->checkBoxKeepPlacement->isChecked(); + return set; +} + +/** + * Sets the strings of the subwidgets using the current language. + */ +void DlgExportStep::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } + else { + QWidget::changeEvent(e); + } +} + +// ---------------------------------------------------------------------------- + +TaskExportStep::TaskExportStep(QWidget* parent) + : QDialog(parent) + , ui(new DlgExportStep(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, &TaskExportStep::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &TaskExportStep::reject); +} + +TaskExportStep::~TaskExportStep() +{ + QApplication::restoreOverrideCursor(); +} + +void TaskExportStep::accept() +{ + QDialog::accept(); + ui->saveSettings(); + + Part::STEP::ImportExportSettings settings; + settings.setVisibleExportDialog(!showThis->isChecked()); +} + +bool TaskExportStep::showDialog() const +{ + Part::STEP::ImportExportSettings settings; + return settings.isVisibleExportDialog(); +} + +StepSettings TaskExportStep::getSettings() const +{ + return ui->getSettings(); +} + + +#include "moc_DlgExportStep.cpp" diff --git a/src/Mod/Part/Gui/DlgExportStep.h b/src/Mod/Part/Gui/DlgExportStep.h new file mode 100644 index 0000000000..5657afe7cb --- /dev/null +++ b/src/Mod/Part/Gui/DlgExportStep.h @@ -0,0 +1,83 @@ +/*************************************************************************** + * Copyright (c) 2022 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef PARTGUI_DLGEXPORTSTEP_H +#define PARTGUI_DLGEXPORTSTEP_H + +#include +#include +#include + +class QButtonGroup; +class QCheckBox; + +namespace PartGui { + +struct StepSettings +{ + bool exportLegacy = false; + bool exportHidden = false; + bool keepPlacement = false; +}; + +class Ui_DlgExportStep; +class DlgExportStep : public Gui::Dialog::PreferencePage +{ + Q_OBJECT + +public: + explicit DlgExportStep(QWidget* parent = nullptr); + ~DlgExportStep() override; + + void saveSettings() override; + void loadSettings() override; + + StepSettings getSettings() const; + +protected: + void changeEvent(QEvent *e) override; + +private: + std::unique_ptr ui; +}; + +class PartExport TaskExportStep : public QDialog +{ + Q_OBJECT + +public: + explicit TaskExportStep(QWidget* parent = nullptr); + ~TaskExportStep() override; + + bool showDialog() const; + void accept() override; + StepSettings getSettings() const; + +private: + QCheckBox* showThis; + std::unique_ptr ui; +}; + +} // namespace PartGui + +#endif // PARTGUI_DLGEXPORTSTEP_H diff --git a/src/Mod/Part/Gui/DlgExportStep.ui b/src/Mod/Part/Gui/DlgExportStep.ui new file mode 100644 index 0000000000..b51dd23958 --- /dev/null +++ b/src/Mod/Part/Gui/DlgExportStep.ui @@ -0,0 +1,232 @@ + + + PartGui::DlgExportStep + + + + 0 + 0 + 445 + 426 + + + + STEP + + + + + + Export + + + + + + Units for export of STEP + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Millimeter + + + + + Meter + + + + + Inch + + + + + + + + Write out curves in parametric space of surface + + + + + + + Uncheck this to skip invisible object when exporting, which is useful for CADs that do not support invisibility STEP styling. + + + Export invisible objects + + + ExportHiddenObject + + + Mod/Import + + + + + + + Check this option to keep the placement information when exporting +a single object. Please note that when import back the STEP file, the +placement will be encoded into the shape geometry, instead of keeping +it inside the Placement property. + + + Export single object placement + + + ExportKeepPlacement + + + Mod/Import + + + + + + + Use legacy exporter + + + ExportLegacy + + + Mod/Import + + + + + + + Scheme + + + + + + + AP203 + + + + + AP214 Committee Draft + + + + + AP214 Draft International Standard + + + + + AP214 International Standard + + + + + AP242 Draft International Standard + + + + + + + + + + + + + + If not empty, field contents will be used in the STEP file header. + + + Header + + + + + + Company + + + + + + + + + + Author + + + + + + + + + + Product + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 82 + + + + + + + + + Gui::PrefCheckBox + QCheckBox +
Gui/PrefWidgets.h
+
+
+ + comboBoxUnits + checkBoxPcurves + checkBoxExportHiddenObj + lineEditCompany + lineEditAuthor + lineEditProduct + + + +