diff --git a/src/Mod/Mesh/Gui/ViewProvider.cpp b/src/Mod/Mesh/Gui/ViewProvider.cpp index da3a52bda1..01bb872741 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.cpp +++ b/src/Mod/Mesh/Gui/ViewProvider.cpp @@ -511,6 +511,14 @@ void ViewProviderMesh::updateData(const App::Property* prop) } } +void ViewProviderMesh::finishRestoring() +{ + if (Coloring.getValue()) { + Coloring.touch(); + } + Gui::ViewProviderGeometryObject::finishRestoring(); +} + QIcon ViewProviderMesh::getIcon() const { static QIcon icon = Gui::BitmapFactory().pixmap("Mesh_Tree"); diff --git a/src/Mod/Mesh/Gui/ViewProvider.h b/src/Mod/Mesh/Gui/ViewProvider.h index 54972993ff..0858b415e7 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.h +++ b/src/Mod/Mesh/Gui/ViewProvider.h @@ -200,6 +200,11 @@ public: void highlightSegments(const std::vector&); //@} + /** @name Restoring view provider from document load */ + //@{ + void finishRestoring() override; + //@} + protected: /// Sets the edit mode bool setEdit(int ModNum) override; diff --git a/src/Mod/MeshPart/Gui/Tessellation.cpp b/src/Mod/MeshPart/Gui/Tessellation.cpp index b6a04a5fe2..134ad2969e 100644 --- a/src/Mod/MeshPart/Gui/Tessellation.cpp +++ b/src/Mod/MeshPart/Gui/Tessellation.cpp @@ -127,6 +127,7 @@ void Tessellation::meshingMethod(int id) void Tessellation::onComboFinenessCurrentIndexChanged(int index) { + // NOLINTBEGIN if (index == 5) { ui->doubleGrading->setEnabled(true); ui->spinEdgeElements->setEnabled(true); @@ -167,6 +168,7 @@ void Tessellation::onComboFinenessCurrentIndexChanged(int index) default: break; } + // NOLINTEND } void Tessellation::onCheckSecondOrderToggled(bool on) @@ -224,7 +226,7 @@ void Tessellation::onEstimateMaximumEdgeLengthClicked() } } - ui->spinMaximumEdgeLength->setValue(edgeLen / 10); + ui->spinMaximumEdgeLength->setValue(edgeLen / 10); // NOLINT } bool Tessellation::accept() @@ -255,8 +257,7 @@ bool Tessellation::accept() if (sel.pObject->isDerivedFrom(Part::Feature::getClassTypeId())) { partWithNoFace = true; } - if (sel.pObject->isDerivedFrom(Part::BodyBase::getClassTypeId())) { - Part::BodyBase* body = static_cast(sel.pObject); + if (auto body = dynamic_cast(sel.pObject)) { if (!body->Tip.getValue()) { bodyWithNoTip = true; } @@ -293,10 +294,9 @@ bool Tessellation::accept() gmsh->process(activeDoc, shapeObjects); return false; } - else { - process(method, activeDoc, shapeObjects); - return doClose; - } + + process(method, activeDoc, shapeObjects); + return doClose; } void Tessellation::process(int method, @@ -373,7 +373,7 @@ void Tessellation::setFaceColors(int method, App::Document* doc, App::DocumentOb if (ui->meshShapeColors->isChecked()) { Gui::ViewProvider* vpm = Gui::Application::Instance->getViewProvider(doc->getActiveObject()); - MeshGui::ViewProviderMesh* vpmesh = dynamic_cast(vpm); + auto vpmesh = dynamic_cast(vpm); auto svp = Base::freecad_dynamic_cast( Gui::Application::Instance->getViewProvider(obj)); @@ -382,12 +382,37 @@ void Tessellation::setFaceColors(int method, App::Document* doc, App::DocumentOb if (ui->groupsFaceColors->isChecked()) { diff_col = getUniqueColors(diff_col); } + vpmesh->highlightSegments(diff_col); + addFaceColors(dynamic_cast(vpmesh->getObject()), diff_col); } } } } +void Tessellation::addFaceColors(Mesh::Feature* mesh, const std::vector& colorPerSegm) +{ + const Mesh::MeshObject& kernel = mesh->Mesh.getValue(); + unsigned long numSegm = kernel.countSegments(); + if (numSegm > 0 && numSegm == colorPerSegm.size()) { + unsigned long uCtFacets = kernel.countFacets(); + std::vector colorPerFace(uCtFacets); + for (unsigned long i = 0; i < numSegm; i++) { + App::Color segmColor = colorPerSegm[i]; + std::vector segm = kernel.getSegment(i).getIndices(); + for (Mesh::FacetIndex it : segm) { + colorPerFace[it] = segmColor; + } + } + + auto typeId = App::PropertyColorList::getClassTypeId(); + if (auto prop = dynamic_cast( + mesh->addDynamicProperty(typeId.getName(), "FaceColors"))) { + prop->setValues(colorPerFace); + } + } +} + std::vector Tessellation::getUniqueColors(const std::vector& colors) const { // unique colors @@ -397,6 +422,7 @@ std::vector Tessellation::getUniqueColors(const std::vector unique; + unique.reserve(col_set.size()); for (const auto& it : col_set) { unique.emplace_back(it); } @@ -480,7 +506,7 @@ QString Tessellation::getNetgenParameters() const bool secondOrder = ui->checkSecondOrder->isChecked(); bool optimize = ui->checkOptimizeSurface->isChecked(); bool allowquad = ui->checkQuadDominated->isChecked(); - if (fineness < 5) { + if (fineness <= int(VeryFine)) { param = QString::fromLatin1("Shape=__shape__," "Fineness=%1,SecondOrder=%2,Optimize=%3,AllowQuad=%4") .arg(fineness) @@ -629,7 +655,7 @@ bool Mesh2ShapeGmsh::loadOutput() stlIn.close(); kernel.harmonizeNormals(); - Mesh::Feature* fea = static_cast(doc->addObject("Mesh::Feature", "Mesh")); + auto fea = static_cast(doc->addObject("Mesh::Feature", "Mesh")); fea->Label.setValue(d->label); fea->Mesh.setValue(kernel.getKernel()); stl.deleteFile(); @@ -652,8 +678,10 @@ TaskTessellation::TaskTessellation() void TaskTessellation::open() {} -void TaskTessellation::clicked(int) -{} +void TaskTessellation::clicked(int id) +{ + Q_UNUSED(id) +} bool TaskTessellation::accept() { diff --git a/src/Mod/MeshPart/Gui/Tessellation.h b/src/Mod/MeshPart/Gui/Tessellation.h index 991850dd10..c9361b0e3e 100644 --- a/src/Mod/MeshPart/Gui/Tessellation.h +++ b/src/Mod/MeshPart/Gui/Tessellation.h @@ -97,6 +97,7 @@ protected: void process(int method, App::Document* doc, const std::list&); void saveParameters(int method); void setFaceColors(int method, App::Document* doc, App::DocumentObject* obj); + void addFaceColors(Mesh::Feature* mesh, const std::vector& colorPerSegm); QString getMeshingParameters(int method, App::DocumentObject* obj) const; QString getStandardParameters(App::DocumentObject* obj) const; QString getMefistoParameters() const;