From 59980c33d1169beb882690ce37c8a8af0a31a373 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 9 May 2016 23:48:30 +0200 Subject: [PATCH] + methods to highlight points, edges or faces of a shape --- src/Mod/Part/Gui/ViewProviderExt.cpp | 175 ++++++++++++++++++--------- src/Mod/Part/Gui/ViewProviderExt.h | 21 +++- 2 files changed, 136 insertions(+), 60 deletions(-) diff --git a/src/Mod/Part/Gui/ViewProviderExt.cpp b/src/Mod/Part/Gui/ViewProviderExt.cpp index afdf98962..d312a1e39 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.cpp +++ b/src/Mod/Part/Gui/ViewProviderExt.cpp @@ -373,7 +373,7 @@ void ViewProviderPartExt::onChanged(const App::Property* prop) else if (prop == &PointMaterial) { const App::Material& Mat = PointMaterial.getValue(); if (PointColor.getValue() != Mat.diffuseColor) - PointColor.setValue(Mat.diffuseColor); + PointColor.setValue(Mat.diffuseColor); pcPointMaterial->ambientColor.setValue(Mat.ambientColor.r,Mat.ambientColor.g,Mat.ambientColor.b); pcPointMaterial->diffuseColor.setValue(Mat.diffuseColor.r,Mat.diffuseColor.g,Mat.diffuseColor.b); pcPointMaterial->specularColor.setValue(Mat.specularColor.r,Mat.specularColor.g,Mat.specularColor.b); @@ -382,65 +382,13 @@ void ViewProviderPartExt::onChanged(const App::Property* prop) pcPointMaterial->transparency.setValue(Mat.transparency); } else if (prop == &PointColorArray) { - const std::vector& c = PointColorArray.getValues(); - unsigned int size = (int)c.size(); - if (size > 1) { - // FIXME: Check for size mismatch between number of points and number of colors - pcShapeBind->value = SoMaterialBinding::PER_VERTEX; - pcPointMaterial->diffuseColor.setNum(size); - SbColor* ca = pcPointMaterial->diffuseColor.startEditing(); - for (unsigned int i=0; i < size; ++i) - ca[i].setValue(c[i].r,c[i].g,c[i].b); - pcPointMaterial->diffuseColor.finishEditing(); - } - else if (size == 1) { - pcShapeBind->value = SoMaterialBinding::OVERALL; - pcPointMaterial->diffuseColor.setValue(c[0].r,c[0].g,c[0].b); - } + setHighlightedPoints(PointColorArray.getValues()); } else if (prop == &LineColorArray) { - const std::vector& c = LineColorArray.getValues(); - int size = (int)c.size(); - if (size > 1) { - pcLineBind->value = SoMaterialBinding::PER_PART; - const int32_t* cindices = this->lineset->coordIndex.getValues(0); - int numindices = this->lineset->coordIndex.getNum(); - pcLineMaterial->diffuseColor.setNum(size); - SbColor* ca = pcLineMaterial->diffuseColor.startEditing(); - int linecount = 0; - - for (int i = 0; i < numindices; ++i) { - if (cindices[i] < 0) { - ca[linecount].setValue(c[linecount].r,c[linecount].g,c[linecount].b); - linecount++; - if (linecount >= size) - break; - } - } - - pcLineMaterial->diffuseColor.finishEditing(); - } - else if (size == 1) { - pcLineBind->value = SoMaterialBinding::OVERALL; - pcLineMaterial->diffuseColor.setValue(c[0].r,c[0].g,c[0].b); - } + setHighlightedEdges(LineColorArray.getValues()); } - // For testing else if (prop == &DiffuseColor) { - const std::vector& c = DiffuseColor.getValues(); - int size = static_cast(c.size()); - if (size > 1 && size == this->faceset->partIndex.getNum()) { - pcShapeBind->value = SoMaterialBinding::PER_PART; - pcShapeMaterial->diffuseColor.setNum(size); - SbColor* ca = pcShapeMaterial->diffuseColor.startEditing(); - for (int i=0; i < size; i++) - ca[i].setValue(c[i].r,c[i].g,c[i].b); - pcShapeMaterial->diffuseColor.finishEditing(); - } - else if (c.size() == 1) { - pcShapeBind->value = SoMaterialBinding::OVERALL; - pcShapeMaterial->diffuseColor.setValue(c[0].r,c[0].g,c[0].b); - } + setHighlightedFaces(DiffuseColor.getValues()); } else if (prop == &ShapeMaterial || prop == &ShapeColor) { pcShapeBind->value = SoMaterialBinding::OVERALL; @@ -691,6 +639,121 @@ std::vector ViewProviderPartExt::getSelectionShape(const char* E return std::vector(); } +void ViewProviderPartExt::setHighlightedFaces(const std::vector& colors) +{ + int size = static_cast(colors.size()); + if (size > 1 && size == this->faceset->partIndex.getNum()) { + pcShapeBind->value = SoMaterialBinding::PER_PART; + pcShapeMaterial->diffuseColor.setNum(size); + SbColor* ca = pcShapeMaterial->diffuseColor.startEditing(); + for (int i = 0; i < size; i++) + ca[i].setValue(colors[i].r, colors[i].g, colors[i].b); + pcShapeMaterial->diffuseColor.finishEditing(); + } + else if (colors.size() == 1) { + pcShapeBind->value = SoMaterialBinding::OVERALL; + pcShapeMaterial->diffuseColor.setValue(colors[0].r, colors[0].g, colors[0].b); + } +} + +void ViewProviderPartExt::setHighlightedFaces(const std::vector& colors) +{ + int size = static_cast(colors.size()); + if (size > 1 && size == this->faceset->partIndex.getNum()) { + pcShapeBind->value = SoMaterialBinding::PER_PART; + + pcShapeMaterial->diffuseColor.setNum(size); + pcShapeMaterial->ambientColor.setNum(size); + pcShapeMaterial->specularColor.setNum(size); + pcShapeMaterial->emissiveColor.setNum(size); + + SbColor* dc = pcShapeMaterial->diffuseColor.startEditing(); + SbColor* ac = pcShapeMaterial->ambientColor.startEditing(); + SbColor* sc = pcShapeMaterial->specularColor.startEditing(); + SbColor* ec = pcShapeMaterial->emissiveColor.startEditing(); + + for (int i = 0; i < size; i++) { + dc[i].setValue(colors[i].diffuseColor.r, colors[i].diffuseColor.g, colors[i].diffuseColor.b); + ac[i].setValue(colors[i].ambientColor.r, colors[i].ambientColor.g, colors[i].ambientColor.b); + sc[i].setValue(colors[i].specularColor.r, colors[i].specularColor.g, colors[i].specularColor.b); + ec[i].setValue(colors[i].emissiveColor.r, colors[i].emissiveColor.g, colors[i].emissiveColor.b); + } + + pcShapeMaterial->diffuseColor.finishEditing(); + pcShapeMaterial->ambientColor.finishEditing(); + pcShapeMaterial->specularColor.finishEditing(); + pcShapeMaterial->emissiveColor.finishEditing(); + } + else if (colors.size() == 1) { + pcShapeBind->value = SoMaterialBinding::OVERALL; + pcShapeMaterial->diffuseColor.setValue(colors[0].diffuseColor.r, colors[0].diffuseColor.g, colors[0].diffuseColor.b); + pcShapeMaterial->ambientColor.setValue(colors[0].ambientColor.r, colors[0].ambientColor.g, colors[0].ambientColor.b); + pcShapeMaterial->specularColor.setValue(colors[0].specularColor.r, colors[0].specularColor.g, colors[0].specularColor.b); + pcShapeMaterial->emissiveColor.setValue(colors[0].emissiveColor.r, colors[0].emissiveColor.g, colors[0].emissiveColor.b); + } +} + +void ViewProviderPartExt::unsetHighlightedFaces() +{ + ShapeMaterial.touch(); +} + +void ViewProviderPartExt::setHighlightedEdges(const std::vector& colors) +{ + int size = static_cast(colors.size()); + if (size > 1) { + pcLineBind->value = SoMaterialBinding::PER_PART; + const int32_t* cindices = this->lineset->coordIndex.getValues(0); + int numindices = this->lineset->coordIndex.getNum(); + pcLineMaterial->diffuseColor.setNum(size); + SbColor* ca = pcLineMaterial->diffuseColor.startEditing(); + int linecount = 0; + + for (int i = 0; i < numindices; ++i) { + if (cindices[i] < 0) { + ca[linecount].setValue(colors[linecount].r, colors[linecount].g, colors[linecount].b); + linecount++; + if (linecount >= size) + break; + } + } + + pcLineMaterial->diffuseColor.finishEditing(); + } + else if (size == 1) { + pcLineBind->value = SoMaterialBinding::OVERALL; + pcLineMaterial->diffuseColor.setValue(colors[0].r, colors[0].g, colors[0].b); + } +} + +void ViewProviderPartExt::unsetHighlightedEdges() +{ + LineMaterial.touch(); +} + +void ViewProviderPartExt::setHighlightedPoints(const std::vector& colors) +{ + int size = static_cast(colors.size()); + if (size > 1) { + // FIXME: Check for size mismatch between number of points and number of colors + pcShapeBind->value = SoMaterialBinding::PER_VERTEX; + pcPointMaterial->diffuseColor.setNum(size); + SbColor* ca = pcPointMaterial->diffuseColor.startEditing(); + for (int i = 0; i < size; ++i) + ca[i].setValue(colors[i].r, colors[i].g, colors[i].b); + pcPointMaterial->diffuseColor.finishEditing(); + } + else if (size == 1) { + pcShapeBind->value = SoMaterialBinding::OVERALL; + pcPointMaterial->diffuseColor.setValue(colors[0].r, colors[0].g, colors[0].b); + } +} + +void ViewProviderPartExt::unsetHighlightedPoints() +{ + PointMaterial.touch(); +} + bool ViewProviderPartExt::loadParameter() { bool changed = false; diff --git a/src/Mod/Part/Gui/ViewProviderExt.h b/src/Mod/Part/Gui/ViewProviderExt.h index 0f68a0024..36f2130df 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.h +++ b/src/Mod/Part/Gui/ViewProviderExt.h @@ -99,10 +99,10 @@ public: virtual void updateData(const App::Property*); - /** @name Selection handling - * This group of methodes do the selection handling. - * Here you can define how the selection for your ViewProfider - * works. + /** @name Selection handling + * This group of methods do the selection handling. + * Here you can define how the selection for your ViewProfider + * works. */ //@{ /// indicates if the ViewProvider use the new Selection model @@ -115,6 +115,19 @@ public: virtual std::vector getSelectionShape(const char* Element) const; //@} + /** @name Highlight handling + * This group of methods do the highlighting of elements. + */ + //@{ + void setHighlightedFaces(const std::vector& colors); + void setHighlightedFaces(const std::vector& colors); + void unsetHighlightedFaces(); + void setHighlightedEdges(const std::vector& colors); + void unsetHighlightedEdges(); + void setHighlightedPoints(const std::vector& colors); + void unsetHighlightedPoints(); + //@} + /** @name Edit methods */ //@{ void setupContextMenu(QMenu*, QObject*, const char*);