diff --git a/src/Mod/Complete/Gui/Workbench.cpp b/src/Mod/Complete/Gui/Workbench.cpp index 63b42a126..ebc9b06b7 100644 --- a/src/Mod/Complete/Gui/Workbench.cpp +++ b/src/Mod/Complete/Gui/Workbench.cpp @@ -209,7 +209,6 @@ Gui::MenuItem* Workbench::setupMenuBar() const mesh->setCommand("&Meshes"); *mesh << "Mesh_Import" << "Mesh_Export" - << "Mesh_FromGeometry" << "MeshPart_Mesher" << "Separator" << analyze diff --git a/src/Mod/Mesh/Gui/Workbench.cpp b/src/Mod/Mesh/Gui/Workbench.cpp index b5005b98d..227122213 100644 --- a/src/Mod/Mesh/Gui/Workbench.cpp +++ b/src/Mod/Mesh/Gui/Workbench.cpp @@ -185,7 +185,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *boolean << "Mesh_Union" << "Mesh_Intersection" << "Mesh_Difference"; mesh->setCommand("&Meshes"); - *mesh << "Mesh_Import" << "Mesh_Export" << "Mesh_FromGeometry" << "Separator" + *mesh << "Mesh_Import" << "Mesh_Export" << "MeshPart_Mesher" << "Separator" << analyze << "Mesh_HarmonizeNormals" << "Mesh_FlipNormals" << "Separator" << "Mesh_FillupHoles" << "Mesh_FillInteractiveHole" << "Mesh_RemoveComponents" << "Mesh_RemoveCompByHand" << "Mesh_AddFacet" << "Mesh_Smoothing" << "Separator" diff --git a/src/Mod/Mesh/InitGui.py b/src/Mod/Mesh/InitGui.py index 83be29aa5..9994159af 100644 --- a/src/Mod/Mesh/InitGui.py +++ b/src/Mod/Mesh/InitGui.py @@ -69,6 +69,10 @@ class MeshWorkbench ( Workbench ): def Initialize(self): # load the module import MeshGui + try: + import MeshPartGui + except: + pass def GetClassName(self): return "MeshGui::Workbench" diff --git a/src/Mod/MeshPart/Gui/Tessellation.cpp b/src/Mod/MeshPart/Gui/Tessellation.cpp index f1b50c396..5e7924bf6 100644 --- a/src/Mod/MeshPart/Gui/Tessellation.cpp +++ b/src/Mod/MeshPart/Gui/Tessellation.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -48,7 +49,7 @@ Tessellation::Tessellation(QWidget* parent) : QWidget(parent), ui(new Ui_Tessellation) { ui->setupUi(this); - Gui::Command::doCommand(Gui::Command::Doc, "import MeshPart"); + Gui::Command::doCommand(Gui::Command::Doc, "import Mesh, MeshPart"); findShapes(); } @@ -56,6 +57,20 @@ Tessellation::~Tessellation() { } +void Tessellation::on_checkSimpleMethod_toggled(bool on) +{ + if (!on) { + if (ui->checkMaxEdgeLength->isChecked()) { + ui->checkMaxEdgeLength->setEnabled(true); + ui->spinMaxEdgeLength->setEnabled(true); + } + } + else { + ui->checkMaxEdgeLength->setEnabled(false); + ui->spinMaxEdgeLength->setEnabled(false); + } +} + void Tessellation::changeEvent(QEvent *e) { if (e->type() == QEvent::LanguageChange) { @@ -74,6 +89,8 @@ void Tessellation::findShapes() this->document = QString::fromAscii(activeDoc->getName()); std::vector objs = activeDoc->getObjectsOfType(); + double edgeLen = 0; + bool foundSelection = false; for (std::vector::iterator it = objs.begin(); it!=objs.end(); ++it) { const TopoDS_Shape& shape = (*it)->Shape.getValue(); if (shape.IsNull()) continue; @@ -85,6 +102,10 @@ void Tessellation::findShapes() } if (hasfaces) { + Base::BoundBox3d bbox = (*it)->Shape.getBoundingBox(); + edgeLen = std::max(edgeLen, bbox.LengthX()); + edgeLen = std::max(edgeLen, bbox.LengthY()); + edgeLen = std::max(edgeLen, bbox.LengthZ()); QString label = QString::fromUtf8((*it)->Label.getValue()); QString name = QString::fromAscii((*it)->getNameInDocument()); @@ -95,8 +116,16 @@ void Tessellation::findShapes() Gui::ViewProvider* vp = activeGui->getViewProvider(*it); if (vp) child->setIcon(0, vp->getIcon()); ui->treeWidget->addTopLevelItem(child); + if (Gui::Selection().isSelected(*it)) { + child->setSelected(true); + foundSelection = true; + } } } + + ui->spinMaxEdgeLength->setValue(edgeLen/10); + if (foundSelection) + ui->treeWidget->hide(); } bool Tessellation::accept() @@ -117,7 +146,19 @@ bool Tessellation::accept() try { QString shape, label; Gui::WaitCursor wc; - + + bool simple = ui->checkSimpleMethod->isChecked(); + double devFace = ui->spinDeviation->value(); + if (!ui->spinDeviation->isEnabled()) { + if (simple) + devFace = 0.1; + else + devFace = 0; + } + double maxEdge = ui->spinMaxEdgeLength->value(); + if (!ui->spinMaxEdgeLength->isEnabled()) + maxEdge = 0; + activeDoc->openTransaction("Meshing"); QList items = ui->treeWidget->selectedItems(); std::vector shapes = Gui::Selection().getObjectsOfType(); @@ -125,17 +166,32 @@ bool Tessellation::accept() shape = (*it)->data(0, Qt::UserRole).toString(); label = (*it)->text(0); - QString cmd = QString::fromAscii( - "__doc__=FreeCAD.getDocument(\"%1\")\n" - "__mesh__=__doc__.addObject(\"Mesh::Feature\",\"Mesh\")\n" - "__mesh__.Mesh=MeshPart.meshFromShape(__doc__.getObject(\"%2\").Shape,%3,0,0,%4)\n" - "__mesh__.Label=\"%5 (Meshed)\"\n" - "del __doc__, __mesh__\n") - .arg(this->document) - .arg(shape) - .arg(ui->spinMaxEdgeLength->value()) - .arg(ui->spinDeviation->value()) - .arg(label); + QString cmd; + if (simple) { + cmd = QString::fromAscii( + "__doc__=FreeCAD.getDocument(\"%1\")\n" + "__mesh__=__doc__.addObject(\"Mesh::Feature\",\"Mesh\")\n" + "__mesh__.Mesh=Mesh.Mesh(__doc__.getObject(\"%2\").Shape.tessellate(%3))\n" + "__mesh__.Label=\"%4 (Meshed)\"\n" + "del __doc__, __mesh__\n") + .arg(this->document) + .arg(shape) + .arg(devFace) + .arg(label); + } + else { + cmd = QString::fromAscii( + "__doc__=FreeCAD.getDocument(\"%1\")\n" + "__mesh__=__doc__.addObject(\"Mesh::Feature\",\"Mesh\")\n" + "__mesh__.Mesh=MeshPart.meshFromShape(__doc__.getObject(\"%2\").Shape,%3,0,0,%4)\n" + "__mesh__.Label=\"%5 (Meshed)\"\n" + "del __doc__, __mesh__\n") + .arg(this->document) + .arg(shape) + .arg(maxEdge) + .arg(devFace) + .arg(label); + } Gui::Command::doCommand(Gui::Command::Doc, (const char*)cmd.toAscii()); } activeDoc->commitTransaction(); diff --git a/src/Mod/MeshPart/Gui/Tessellation.h b/src/Mod/MeshPart/Gui/Tessellation.h index f3c092740..81e2627d4 100644 --- a/src/Mod/MeshPart/Gui/Tessellation.h +++ b/src/Mod/MeshPart/Gui/Tessellation.h @@ -47,6 +47,9 @@ protected: private: void findShapes(); +private Q_SLOTS: + void on_checkSimpleMethod_toggled(bool); + private: QString document; std::auto_ptr ui; diff --git a/src/Mod/MeshPart/Gui/Tessellation.ui b/src/Mod/MeshPart/Gui/Tessellation.ui index 6f0158b41..12e8c01a9 100644 --- a/src/Mod/MeshPart/Gui/Tessellation.ui +++ b/src/Mod/MeshPart/Gui/Tessellation.ui @@ -31,58 +31,69 @@ Settings - + - - - Surface deviation: - - - true - - - - - - - 3 - - - 0.001000000000000 - - - 0.100000000000000 - - - 0.100000000000000 - - - - - - - Max. edge length: - - - true - - - - - - - 3 - - - 0.001000000000000 - - - 0.100000000000000 - - - 1.000000000000000 - - + + + + + Surface deviation: + + + true + + + + + + + 3 + + + 0.001000000000000 + + + 0.100000000000000 + + + 0.100000000000000 + + + + + + + Use simplified mesh generation method + + + + + + + Max. edge length: + + + true + + + + + + + 3 + + + 0.001000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + @@ -93,6 +104,7 @@ treeWidget checkDeviation spinDeviation + checkSimpleMethod checkMaxEdgeLength spinMaxEdgeLength @@ -105,12 +117,12 @@ setEnabled(bool) - 84 - 375 + 104 + 359 - 219 - 380 + 308 + 360