Mesh: issue #6131: Colors set prior to saving aren't retained when re-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'
This commit is contained in:
wmayer
2022-05-17 16:43:53 +02:00
parent eaaed0d81c
commit cad6882025
2 changed files with 68 additions and 7 deletions

View File

@@ -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)
@@ -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();
}
}
@@ -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();
}
}
@@ -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)

View File

@@ -191,6 +191,9 @@ protected:
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*);
@@ -218,7 +221,13 @@ private:
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;