Part: add dialog for STEP export

This commit is contained in:
wmayer
2022-10-04 20:30:03 +02:00
parent 5af6521377
commit 5ee0f0a8cf
7 changed files with 554 additions and 7 deletions

View File

@@ -101,6 +101,7 @@
#include <Mod/Part/App/Interface.h>
#include <Mod/Part/App/PartFeature.h>
#include <Mod/Part/App/ProgressIndicator.h>
#include <Mod/Part/Gui/DlgExportStep.h>
#include <TDataStd.hxx>
#include <TDataStd_Integer.hxx>
@@ -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;

View File

@@ -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");

View File

@@ -37,6 +37,9 @@ class PartExport ImportExportSettings
public:
ImportExportSettings();
void setVisibleExportDialog(bool);
bool isVisibleExportDialog() const;
void setWriteSurfaceCurveMode(bool);
bool getWriteSurfaceCurveMode() const;

View File

@@ -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

View File

@@ -0,0 +1,213 @@
/***************************************************************************
* Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <QButtonGroup>
# include <QCheckBox>
# include <QDialogButtonBox>
# include <QVBoxLayout>
# include <QRegExp>
# include <QRegExpValidator>
# include <Interface_Static.hxx>
#endif
#include <App/Application.h>
#include <Base/Parameter.h>
#include <Mod/Part/App/OCAF/ImportExportSettings.h>
#include <Mod/Part/App/STEP/ImportExportSettings.h>
#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<Part::Interface::Unit>(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<int>(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"

View File

@@ -0,0 +1,83 @@
/***************************************************************************
* Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <Mod/Part/PartGlobal.h>
#include <Gui/PropertyPage.h>
#include <QDialog>
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_DlgExportStep> 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<DlgExportStep> ui;
};
} // namespace PartGui
#endif // PARTGUI_DLGEXPORTSTEP_H

View File

@@ -0,0 +1,232 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PartGui::DlgExportStep</class>
<widget class="QWidget" name="PartGui::DlgExportStep">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>445</width>
<height>426</height>
</rect>
</property>
<property name="windowTitle">
<string>STEP</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Export</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Units for export of STEP</string>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="comboBoxUnits">
<item>
<property name="text">
<string>Millimeter</string>
</property>
</item>
<item>
<property name="text">
<string>Meter</string>
</property>
</item>
<item>
<property name="text">
<string>Inch</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="checkBoxPcurves">
<property name="text">
<string>Write out curves in parametric space of surface</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="Gui::PrefCheckBox" name="checkBoxExportHiddenObj">
<property name="toolTip">
<string>Uncheck this to skip invisible object when exporting, which is useful for CADs that do not support invisibility STEP styling.</string>
</property>
<property name="text">
<string>Export invisible objects</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>ExportHiddenObject</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Import</cstring>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="Gui::PrefCheckBox" name="checkBoxKeepPlacement">
<property name="toolTip">
<string>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.</string>
</property>
<property name="text">
<string>Export single object placement</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>ExportKeepPlacement</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Import</cstring>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="Gui::PrefCheckBox" name="checkBoxExportLegacy">
<property name="text">
<string>Use legacy exporter</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>ExportLegacy</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Import</cstring>
</property>
</widget>
</item>
<item row="6" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Scheme</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QComboBox" name="comboBoxSchema">
<item>
<property name="text">
<string notr="true">AP203</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">AP214 Committee Draft</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">AP214 Draft International Standard</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">AP214 International Standard</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">AP242 Draft International Standard</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBoxHeader">
<property name="toolTip">
<string>If not empty, field contents will be used in the STEP file header.</string>
</property>
<property name="title">
<string>Header</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Company</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditCompany"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Author</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditAuthor"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Product</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEditProduct"/>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>82</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>comboBoxUnits</tabstop>
<tabstop>checkBoxPcurves</tabstop>
<tabstop>checkBoxExportHiddenObj</tabstop>
<tabstop>lineEditCompany</tabstop>
<tabstop>lineEditAuthor</tabstop>
<tabstop>lineEditProduct</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>