diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 77651ccf1d..60183e64ca 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -3717,7 +3717,7 @@ void TopoShape::setFaces(const std::vector &Points, #if OCC_VERSION_HEX < 0x070500 Handle(Message_ProgressIndicator) pi = new ProgressIndicator(100); - pi->NewScope(100, "Sewing Faces..."); + pi->NewScope(100, "Create shape from mesh..."); pi->Show(); aSewingTool.Perform(pi); diff --git a/src/Mod/Part/Gui/CMakeLists.txt b/src/Mod/Part/Gui/CMakeLists.txt index d59a9daf4f..51bd0ecd43 100644 --- a/src/Mod/Part/Gui/CMakeLists.txt +++ b/src/Mod/Part/Gui/CMakeLists.txt @@ -63,6 +63,7 @@ set(PartGui_UIC_SRCS DlgSettingsGeneral.ui DlgSettingsObjectColor.ui DlgProjectionOnSurface.ui + ShapeFromMesh.ui TaskFaceColors.ui TaskShapeBuilder.ui TaskLoft.ui @@ -207,6 +208,8 @@ SET(PartGui_SRCS ViewProviderPrimitive.h Workbench.cpp Workbench.h + ShapeFromMesh.cpp + ShapeFromMesh.h TaskFaceColors.cpp TaskFaceColors.h TaskFaceColors.ui diff --git a/src/Mod/Part/Gui/CommandSimple.cpp b/src/Mod/Part/Gui/CommandSimple.cpp index 7d6ff8f63c..b7549ad675 100644 --- a/src/Mod/Part/Gui/CommandSimple.cpp +++ b/src/Mod/Part/Gui/CommandSimple.cpp @@ -43,6 +43,7 @@ #include "../App/PartFeature.h" #include "../App/TopoShape.h" #include "DlgPartCylinderImp.h" +#include "ShapeFromMesh.h" //=========================================================================== @@ -115,51 +116,8 @@ CmdPartShapeFromMesh::CmdPartShapeFromMesh() void CmdPartShapeFromMesh::activated(int iMsg) { Q_UNUSED(iMsg); - - double STD_OCC_TOLERANCE = 1e-6; - - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Units"); - int decimals = hGrp->GetInt("Decimals"); - double tolerance_from_decimals = pow(10., -decimals); - - double minimal_tolerance = tolerance_from_decimals < STD_OCC_TOLERANCE ? STD_OCC_TOLERANCE : tolerance_from_decimals; - - bool ok; - double tol = QInputDialog::getDouble(Gui::getMainWindow(), QObject::tr("Sewing Tolerance"), - QObject::tr("Enter tolerance for sewing shape:"), 0.1, minimal_tolerance, 10.0, decimals, &ok, Qt::MSWindowsFixedSizeDialogHint); - if (!ok) - return; - Base::Type meshid = Base::Type::fromName("Mesh::Feature"); - std::vector meshes; - meshes = Gui::Selection().getObjectsOfType(meshid); - Gui::WaitCursor wc; - std::vector::iterator it; - openCommand(QT_TRANSLATE_NOOP("Command", "Convert mesh")); - for (it = meshes.begin(); it != meshes.end(); ++it) { - App::Document* doc = (*it)->getDocument(); - std::string mesh = (*it)->getNameInDocument(); - std::string name = doc->getUniqueObjectName(mesh.c_str()); - doCommand(Doc,"import Part"); - doCommand(Doc,"FreeCAD.getDocument(\"%s\").addObject(\"Part::Feature\",\"%s\")" - ,doc->getName() - ,name.c_str()); - doCommand(Doc,"__shape__=Part.Shape()"); - doCommand(Doc,"__shape__.makeShapeFromMesh(" - "FreeCAD.getDocument(\"%s\").getObject(\"%s\").Mesh.Topology,%f" - ")" - ,doc->getName() - ,mesh.c_str() - ,tol); - doCommand(Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").Shape=__shape__" - ,doc->getName() - ,name.c_str()); - doCommand(Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").purgeTouched()" - ,doc->getName() - ,name.c_str()); - doCommand(Doc,"del __shape__"); - } - - commitCommand(); + PartGui::ShapeFromMesh dlg(Gui::getMainWindow()); + dlg.exec(); } bool CmdPartShapeFromMesh::isActive(void) diff --git a/src/Mod/Part/Gui/ShapeFromMesh.cpp b/src/Mod/Part/Gui/ShapeFromMesh.cpp new file mode 100644 index 0000000000..f031582a6d --- /dev/null +++ b/src/Mod/Part/Gui/ShapeFromMesh.cpp @@ -0,0 +1,110 @@ +/*************************************************************************** + * Copyright (c) 2021 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 +#endif + +#include "ShapeFromMesh.h" +#include "ui_ShapeFromMesh.h" +#include +#include +#include +#include +#include + +using namespace PartGui; + + +ShapeFromMesh::ShapeFromMesh(QWidget* parent, Qt::WindowFlags fl) + : QDialog(parent, fl) + , ui(new Ui_ShapeFromMesh) +{ + ui->setupUi(this); + ui->groupBoxSew->setChecked(false); + + double STD_OCC_TOLERANCE = 1e-6; + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Units"); + int decimals = hGrp->GetInt("Decimals"); + double tolerance_from_decimals = pow(10., -decimals); + + double minimal_tolerance = tolerance_from_decimals < STD_OCC_TOLERANCE ? STD_OCC_TOLERANCE : tolerance_from_decimals; + ui->doubleSpinBox->setRange(minimal_tolerance, 10.0); + ui->doubleSpinBox->setValue(0.1); + ui->doubleSpinBox->setSingleStep(0.1); + ui->doubleSpinBox->setDecimals(decimals); +} + +ShapeFromMesh::~ShapeFromMesh() +{ + +} + +void ShapeFromMesh::perform() +{ + double tolerance = ui->doubleSpinBox->value(); + bool sewShape = ui->groupBoxSew->isChecked(); + + Gui::WaitCursor wc; + + Base::Type meshid = Base::Type::fromName("Mesh::Feature"); + std::vector meshes; + meshes = Gui::Selection().getObjectsOfType(meshid); + + Gui::doCommandT(Gui::Command::Doc, "import Part"); + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Convert mesh")); + + for (auto it = meshes.begin(); it != meshes.end(); ++it) { + App::Document* doc = (*it)->getDocument(); + std::string mesh = (*it)->getNameInDocument(); + std::string name = doc->getUniqueObjectName(mesh.c_str()); + + Gui::cmdAppDocument(doc, std::ostringstream() << "addObject(\"Part::Feature\", \"" << name << "\")"); + std::string partObj = App::DocumentObjectT(doc, name).getObjectPython(); + std::string meshObj = App::DocumentObjectT(doc, mesh).getObjectPython(); + + Gui::doCommandT(Gui::Command::Doc, "__shape__ = Part.Shape()"); + Gui::doCommandT(Gui::Command::Doc, "__shape__.makeShapeFromMesh(%s.Mesh.Topology, %f, %s)", meshObj, tolerance, (sewShape ? "True" : "False")); + Gui::doCommandT(Gui::Command::Doc, partObj + ".Shape = __shape__"); + Gui::doCommandT(Gui::Command::Doc, partObj + ".purgeTouched()"); + Gui::doCommandT(Gui::Command::Doc, "del __shape__"); + } + + Gui::Command::commitCommand(); +} + +void ShapeFromMesh::accept() +{ + try { + perform(); + } + catch (const Base::Exception& e) { + e.ReportException(); + } + + QDialog::accept(); +} + +#include "moc_ShapeFromMesh.cpp" diff --git a/src/Mod/Part/Gui/ShapeFromMesh.h b/src/Mod/Part/Gui/ShapeFromMesh.h new file mode 100644 index 0000000000..eca9455e79 --- /dev/null +++ b/src/Mod/Part/Gui/ShapeFromMesh.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (c) 2021 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_SHAPEFROMMESH_H +#define PARTGUI_SHAPEFROMMESH_H + +#include +#include + +namespace PartGui { + +class Ui_ShapeFromMesh; +class ShapeFromMesh : public QDialog +{ + Q_OBJECT + +public: + ShapeFromMesh(QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags()); + ~ShapeFromMesh(); + + virtual void accept(); + +private: + void perform(); + std::unique_ptr ui; +}; + +} // namespace PartGui + +#endif // PARTGUI_SHAPEFROMMESH_H diff --git a/src/Mod/Part/Gui/ShapeFromMesh.ui b/src/Mod/Part/Gui/ShapeFromMesh.ui new file mode 100644 index 0000000000..db7e02674d --- /dev/null +++ b/src/Mod/Part/Gui/ShapeFromMesh.ui @@ -0,0 +1,102 @@ + + + PartGui::ShapeFromMesh + + + + 0 + 0 + 349 + 148 + + + + Shape from mesh + + + + + + Sew shape + + + true + + + true + + + + + + Enter tolerance for sewing shape: + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + PartGui::ShapeFromMesh + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + PartGui::ShapeFromMesh + reject() + + + 316 + 260 + + + 286 + 274 + + + + +