Mesh: Make colors persistent if meshing option 'Apply face colors to mesh' is used

This commit is contained in:
wmayer
2024-05-09 17:42:31 +02:00
committed by wwmayer
parent 0095e52466
commit 7b3eef3dcf
4 changed files with 54 additions and 12 deletions

View File

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

View File

@@ -200,6 +200,11 @@ public:
void highlightSegments(const std::vector<App::Color>&);
//@}
/** @name Restoring view provider from document load */
//@{
void finishRestoring() override;
//@}
protected:
/// Sets the edit mode
bool setEdit(int ModNum) override;

View File

@@ -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<Part::BodyBase*>(sel.pObject);
if (auto body = dynamic_cast<Part::BodyBase*>(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<MeshGui::ViewProviderMesh*>(vpm);
auto vpmesh = dynamic_cast<MeshGui::ViewProviderMesh*>(vpm);
auto svp = Base::freecad_dynamic_cast<PartGui::ViewProviderPartExt>(
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<Mesh::Feature*>(vpmesh->getObject()), diff_col);
}
}
}
}
void Tessellation::addFaceColors(Mesh::Feature* mesh, const std::vector<App::Color>& 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<App::Color> colorPerFace(uCtFacets);
for (unsigned long i = 0; i < numSegm; i++) {
App::Color segmColor = colorPerSegm[i];
std::vector<Mesh::FacetIndex> segm = kernel.getSegment(i).getIndices();
for (Mesh::FacetIndex it : segm) {
colorPerFace[it] = segmColor;
}
}
auto typeId = App::PropertyColorList::getClassTypeId();
if (auto prop = dynamic_cast<App::PropertyColorList*>(
mesh->addDynamicProperty(typeId.getName(), "FaceColors"))) {
prop->setValues(colorPerFace);
}
}
}
std::vector<App::Color> Tessellation::getUniqueColors(const std::vector<App::Color>& colors) const
{
// unique colors
@@ -397,6 +422,7 @@ std::vector<App::Color> Tessellation::getUniqueColors(const std::vector<App::Col
}
std::vector<App::Color> 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<Mesh::Feature*>(doc->addObject("Mesh::Feature", "Mesh"));
auto fea = static_cast<Mesh::Feature*>(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()
{

View File

@@ -97,6 +97,7 @@ protected:
void process(int method, App::Document* doc, const std::list<App::SubObjectT>&);
void saveParameters(int method);
void setFaceColors(int method, App::Document* doc, App::DocumentObject* obj);
void addFaceColors(Mesh::Feature* mesh, const std::vector<App::Color>& colorPerSegm);
QString getMeshingParameters(int method, App::DocumentObject* obj) const;
QString getStandardParameters(App::DocumentObject* obj) const;
QString getMefistoParameters() const;