Part: move code to create shape from mesh to dialog ShapeFromMesh
This commit is contained in:
@@ -3717,7 +3717,7 @@ void TopoShape::setFaces(const std::vector<Base::Vector3d> &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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<App::DocumentObject*> meshes;
|
||||
meshes = Gui::Selection().getObjectsOfType(meshid);
|
||||
Gui::WaitCursor wc;
|
||||
std::vector<App::DocumentObject*>::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)
|
||||
|
||||
110
src/Mod/Part/Gui/ShapeFromMesh.cpp
Normal file
110
src/Mod/Part/Gui/ShapeFromMesh.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2021 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 <sstream>
|
||||
#endif
|
||||
|
||||
#include "ShapeFromMesh.h"
|
||||
#include "ui_ShapeFromMesh.h"
|
||||
#include <App/Application.h>
|
||||
#include <App/DocumentObserver.h>
|
||||
#include <Gui/CommandT.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/WaitCursor.h>
|
||||
|
||||
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<App::DocumentObject*> 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"
|
||||
49
src/Mod/Part/Gui/ShapeFromMesh.h
Normal file
49
src/Mod/Part/Gui/ShapeFromMesh.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2021 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_SHAPEFROMMESH_H
|
||||
#define PARTGUI_SHAPEFROMMESH_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <memory>
|
||||
|
||||
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_ShapeFromMesh> ui;
|
||||
};
|
||||
|
||||
} // namespace PartGui
|
||||
|
||||
#endif // PARTGUI_SHAPEFROMMESH_H
|
||||
102
src/Mod/Part/Gui/ShapeFromMesh.ui
Normal file
102
src/Mod/Part/Gui/ShapeFromMesh.ui
Normal file
@@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>PartGui::ShapeFromMesh</class>
|
||||
<widget class="QDialog" name="PartGui::ShapeFromMesh">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>349</width>
|
||||
<height>148</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Shape from mesh</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="groupBoxSew">
|
||||
<property name="title">
|
||||
<string>Sew shape</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Enter tolerance for sewing shape:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBox"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>PartGui::ShapeFromMesh</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>PartGui::ShapeFromMesh</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user