Skip to content

Commit

Permalink
Mesh: issue #6131: Colors set prior to saving aren't retained when re…
Browse files Browse the repository at this point in the history
…-opening file

Note: A mesh feature must have a PropertyColorList property with the name FaceColors or VertexColors. The colors won't be set when loading a project but in the context-menu there is the function 'Display colors'
  • Loading branch information
wwmayer committed May 17, 2022
1 parent 2e7a7e7 commit a5ff515
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 7 deletions.
64 changes: 58 additions & 6 deletions src/Mod/Mesh/Gui/ViewProvider.cpp
Expand Up @@ -741,14 +741,20 @@ void ViewProviderMesh::setupContextMenu(QMenu* menu, QObject* receiver, const ch
QAction* act = menu->addAction(QObject::tr("Display components"));
act->setCheckable(true);
act->setChecked(pcMatBinding->value.getValue() == SoMaterialBinding::PER_FACE &&
highlightMode == "Component");
highlightMode == HighlighMode::Component);
func->toggle(act, boost::bind(&ViewProviderMesh::setHighlightedComponents, this, bp::_1));

QAction* seg = menu->addAction(QObject::tr("Display segments"));
seg->setCheckable(true);
seg->setChecked(pcMatBinding->value.getValue() == SoMaterialBinding::PER_FACE &&
highlightMode == "Segment");
highlightMode == HighlighMode::Segment);
func->toggle(seg, boost::bind(&ViewProviderMesh::setHighlightedSegments, this, bp::_1));

QAction* col = menu->addAction(QObject::tr("Display colors"));
col->setVisible(canHighlightColors());
col->setCheckable(true);
col->setChecked(highlightMode == HighlighMode::Color);
func->toggle(col, boost::bind(&ViewProviderMesh::setHighlightedColors, this, bp::_1));
}

bool ViewProviderMesh::setEdit(int ModNum)
Expand Down Expand Up @@ -2136,11 +2142,11 @@ void ViewProviderMesh::unhighlightSelection()
void ViewProviderMesh::setHighlightedComponents(bool on)
{
if (on) {
highlightMode = "Component";
highlightMode = HighlighMode::Component;
highlightComponents();
}
else {
highlightMode.clear();
highlightMode = HighlighMode::None;
unhighlightSelection();
}
}
Expand Down Expand Up @@ -2171,11 +2177,11 @@ void ViewProviderMesh::highlightComponents()
void ViewProviderMesh::setHighlightedSegments(bool on)
{
if (on) {
highlightMode = "Segment";
highlightMode = HighlighMode::Segment;
highlightSegments();
}
else {
highlightMode.clear();
highlightMode = HighlighMode::None;
unhighlightSelection();
}
}
Expand Down Expand Up @@ -2227,6 +2233,52 @@ void ViewProviderMesh::highlightSegments(const std::vector<App::Color>& colors)
}
}

void ViewProviderMesh::setHighlightedColors(bool on)
{
if (on) {
highlightMode = HighlighMode::Color;
highlightColors();
}
else {
highlightMode = HighlighMode::None;
unhighlightSelection();
}
}

void ViewProviderMesh::highlightColors()
{
const Mesh::MeshObject& rMesh = static_cast<Mesh::Feature*>(pcObject)->Mesh.getValue();
{
App::PropertyColorList* prop = Base::freecad_dynamic_cast<App::PropertyColorList>(pcObject->getPropertyByName("FaceColors"));
if (prop && prop->getSize() == int(rMesh.countFacets())) {
setColorPerFace(prop);
}
}
{
App::PropertyColorList* prop = Base::freecad_dynamic_cast<App::PropertyColorList>(pcObject->getPropertyByName("VertexColors"));
if (prop && prop->getSize() == int(rMesh.countPoints())) {
setColorPerVertex(prop);
}
}
}

bool ViewProviderMesh::canHighlightColors() const
{
const Mesh::MeshObject& rMesh = static_cast<Mesh::Feature*>(pcObject)->Mesh.getValue();
{
App::PropertyColorList* prop = Base::freecad_dynamic_cast<App::PropertyColorList>(pcObject->getPropertyByName("FaceColors"));
if (prop && prop->getSize() == int(rMesh.countFacets()))
return true;
}
{
App::PropertyColorList* prop = Base::freecad_dynamic_cast<App::PropertyColorList>(pcObject->getPropertyByName("VertexColors"));
if (prop && prop->getSize() == int(rMesh.countPoints()))
return true;
}

return false;
}

PyObject* ViewProviderMesh::getPyObject()
{
if (!pyViewObject)
Expand Down
11 changes: 10 additions & 1 deletion src/Mod/Mesh/Gui/ViewProvider.h
Expand Up @@ -191,6 +191,9 @@ class MeshGuiExport ViewProviderMesh : public Gui::ViewProviderGeometryObject
void setHighlightedComponents(bool);
void highlightSegments();
void setHighlightedSegments(bool);
void setHighlightedColors(bool);
void highlightColors();
bool canHighlightColors() const;
App::PropertyColorList* getColorProperty() const;
void tryColorPerVertexOrFace(bool);
void setColorPerVertex(const App::PropertyColorList*);
Expand Down Expand Up @@ -218,7 +221,13 @@ class MeshGuiExport ViewProviderMesh : public Gui::ViewProviderGeometryObject
static void panCamera(SoCamera*, float, const SbPlane&, const SbVec2f&, const SbVec2f&);

protected:
std::string highlightMode;
enum class HighlighMode {
None,
Component,
Segment,
Color
};
HighlighMode highlightMode;
Gui::SoFCSelection * pcHighlight;
SoGroup * pcShapeGroup;
SoDrawStyle * pcLineStyle;
Expand Down

2 comments on commit a5ff515

@ceanwang
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was raised in FEM WB for femMesh. Is femMesh based on mesh in Mesh WB?
I tested the code, The problem remains.

@wwmayer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mesh and FEM are two separated and independent wb but the problem exists in both of them. The commit handles it for the former and for the latter it still must be implemented.

Please sign in to comment.