diff --git a/src/Mod/Part/Gui/ViewProviderExt.cpp b/src/Mod/Part/Gui/ViewProviderExt.cpp index fce0a886f0..8536c14c4f 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.cpp +++ b/src/Mod/Part/Gui/ViewProviderExt.cpp @@ -245,6 +245,7 @@ ViewProviderPartExt::ViewProviderPartExt() ADD_PROPERTY(LineColor,(mat.diffuseColor)); ADD_PROPERTY(PointColor,(mat.diffuseColor)); ADD_PROPERTY(DiffuseColor,(ShapeColor.getValue())); + ADD_PROPERTY(LineColorArray,(LineColor.getValue())); ADD_PROPERTY(LineWidth,(lwidth)); LineWidth.setConstraints(&sizeRange); PointSize.setConstraints(&sizeRange); @@ -275,6 +276,8 @@ ViewProviderPartExt::ViewProviderPartExt() pcShapeBind = new SoMaterialBinding(); pcShapeBind->ref(); + pcLineBind = new SoMaterialBinding(); + pcLineBind->ref(); pcLineMaterial = new SoMaterial; pcLineMaterial->ref(); LineMaterial.touch(); @@ -306,6 +309,7 @@ ViewProviderPartExt::ViewProviderPartExt() ViewProviderPartExt::~ViewProviderPartExt() { pcShapeBind->unref(); + pcLineBind->unref(); pcLineMaterial->unref(); pcPointMaterial->unref(); pcLineStyle->unref(); @@ -337,13 +341,13 @@ void ViewProviderPartExt::onChanged(const App::Property* prop) const App::Color& c = LineColor.getValue(); pcLineMaterial->diffuseColor.setValue(c.r,c.g,c.b); if (c != LineMaterial.getValue().diffuseColor) - LineMaterial.setDiffuseColor(c); + LineMaterial.setDiffuseColor(c); } else if (prop == &PointColor) { const App::Color& c = PointColor.getValue(); pcPointMaterial->diffuseColor.setValue(c.r,c.g,c.b); if (c != PointMaterial.getValue().diffuseColor) - PointMaterial.setDiffuseColor(c); + PointMaterial.setDiffuseColor(c); } else if (prop == &LineMaterial) { const App::Material& Mat = LineMaterial.getValue(); @@ -367,15 +371,59 @@ void ViewProviderPartExt::onChanged(const App::Property* prop) pcPointMaterial->shininess.setValue(Mat.shininess); pcPointMaterial->transparency.setValue(Mat.transparency); } + else if (prop == &PointColorArray) { + const std::vector& c = PointColorArray.getValues(); + 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); + } + } + 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); + } + } // For testing else if (prop == &DiffuseColor) { const std::vector& c = DiffuseColor.getValues(); int size = (int)c.size(); if (size > 1 && size == this->faceset->partIndex.getNum()) { pcShapeBind->value = SoMaterialBinding::PER_PART; - pcShapeMaterial->diffuseColor.setNum(c.size()); + pcShapeMaterial->diffuseColor.setNum(size); SbColor* ca = pcShapeMaterial->diffuseColor.startEditing(); - for (unsigned int i=0; i < c.size(); i++) + for (unsigned int i=0; i < size; i++) ca[i].setValue(c[i].r,c[i].g,c[i].b); pcShapeMaterial->diffuseColor.finishEditing(); } @@ -461,6 +509,7 @@ void ViewProviderPartExt::attach(App::DocumentObject *pcFeat) // wireframe node SoSeparator* wireframe = new SoSeparator(); + wireframe->addChild(pcLineBind); wireframe->addChild(pcLineMaterial); wireframe->addChild(pcLineStyle); wireframe->addChild(lineset); diff --git a/src/Mod/Part/Gui/ViewProviderExt.h b/src/Mod/Part/Gui/ViewProviderExt.h index 2167c252ef..97170e878a 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.h +++ b/src/Mod/Part/Gui/ViewProviderExt.h @@ -69,19 +69,23 @@ public: virtual ~ViewProviderPartExt(); // Display properties - App::PropertyFloatConstraint LineWidth; - App::PropertyFloatConstraint PointSize; App::PropertyFloatConstraint Deviation; + App::PropertyBool ControlPoints; App::PropertyAngle AngularDeflection; - App::PropertyColor LineColor; - App::PropertyColor PointColor; - App::PropertyMaterial LineMaterial; - App::PropertyMaterial PointMaterial; App::PropertyEnumeration Lighting; App::PropertyEnumeration DrawStyle; - - App::PropertyColorList DiffuseColor; - + // Points + App::PropertyFloatConstraint PointSize; + App::PropertyColor PointColor; + App::PropertyMaterial PointMaterial; + App::PropertyColorList PointColorArray; + // Lines + App::PropertyFloatConstraint LineWidth; + App::PropertyColor LineColor; + App::PropertyMaterial LineMaterial; + App::PropertyColorList LineColorArray; + // Faces (Gui::ViewProviderGeometryObject::ShapeColor and Gui::ViewProviderGeometryObject::ShapeMaterial apply) + App::PropertyColorList DiffuseColor; virtual void attach(App::DocumentObject *); virtual void setDisplayMode(const char* ModeName); @@ -124,6 +128,7 @@ protected: // nodes for the data representation SoMaterialBinding * pcShapeBind; + SoMaterialBinding * pcLineBind; SoMaterial * pcLineMaterial; SoMaterial * pcPointMaterial; SoDrawStyle * pcLineStyle; diff --git a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp index 82afe610d4..09b2b2987c 100644 --- a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp @@ -208,6 +208,7 @@ TaskDlgDressUpParameters::~TaskDlgDressUpParameters() bool TaskDlgDressUpParameters::accept() { std::string name = DressUpView->getObject()->getNameInDocument(); + DressUpView->highlightReferences(false); try { std::vector refs = parameter->getReferences(); @@ -232,9 +233,11 @@ bool TaskDlgDressUpParameters::accept() bool TaskDlgDressUpParameters::reject() { + DressUpView->highlightReferences(false); + // roll back the done things Gui::Command::abortCommand(); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); // Body housekeeping if (ActivePartObject != NULL) { diff --git a/src/Mod/PartDesign/Gui/ViewProviderDressUp.cpp b/src/Mod/PartDesign/Gui/ViewProviderDressUp.cpp index 6b879bcd0b..35e01fa65a 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDressUp.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDressUp.cpp @@ -97,25 +97,46 @@ void ViewProviderDressUp::highlightReferences(const bool on) Gui::Application::Instance->getViewProvider(base)); if (vp == NULL) return; - if (on) { - std::vector SubVals = pcDressUp->Base.getSubValuesStartsWith("Face"); - if (SubVals.size() == 0) return; + std::vector faces = pcDressUp->Base.getSubValuesStartsWith("Face"); + std::vector edges = pcDressUp->Base.getSubValuesStartsWith("Edge"); - TopTools_IndexedMapOfShape fMap; - TopExp::MapShapes(base->Shape.getValue(), TopAbs_FACE, fMap); + if (on) { + if (!faces.empty() && originalFaceColors.empty()) { + TopTools_IndexedMapOfShape fMap; + TopExp::MapShapes(base->Shape.getValue(), TopAbs_FACE, fMap); - originalColors = vp->DiffuseColor.getValues(); - std::vector colors = originalColors; - colors.resize(fMap.Extent(), ShapeColor.getValue()); + originalFaceColors = vp->DiffuseColor.getValues(); + std::vector colors = originalFaceColors; + colors.resize(fMap.Extent(), ShapeColor.getValue()); - for (std::vector::const_iterator f = SubVals.begin(); f != SubVals.end(); f++) { - int idx = atoi(f->substr(4).c_str()) - 1; - // TODO: Find a better colour - colors[idx] = App::Color(0.2f,1.0f,0.2f); + for (std::vector::const_iterator f = faces.begin(); f != faces.end(); ++f) { + int idx = atoi(f->substr(4).c_str()) - 1; + if (idx < colors.size()) + colors[idx] = App::Color(1.0,0.0,1.0); // magenta + } + vp->DiffuseColor.setValues(colors); + } else if (!edges.empty() && originalLineColors.empty()) { + TopTools_IndexedMapOfShape eMap; + TopExp::MapShapes(base->Shape.getValue(), TopAbs_EDGE, eMap); + originalLineColors = vp->LineColorArray.getValues(); + std::vector colors = originalLineColors; + colors.resize(eMap.Extent(), LineColor.getValue()); + + for (std::vector::const_iterator e = edges.begin(); e != edges.end(); ++e) { + int idx = atoi(e->substr(4).c_str()) - 1; + if (idx < colors.size()) + colors[idx] = App::Color(1.0,0.0,1.0); // magenta + } + vp->LineColorArray.setValues(colors); } - vp->DiffuseColor.setValues(colors); } else { - vp->DiffuseColor.setValues(originalColors); + if (!faces.empty() && !originalFaceColors.empty()) { + vp->DiffuseColor.setValues(originalFaceColors); + originalFaceColors.clear(); + } else if (!edges.empty() && !originalLineColors.empty()) { + vp->LineColorArray.setValues(originalLineColors); + originalLineColors.clear(); + } } } diff --git a/src/Mod/PartDesign/Gui/ViewProviderDressUp.h b/src/Mod/PartDesign/Gui/ViewProviderDressUp.h index 723dd23127..dabb95c629 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDressUp.h +++ b/src/Mod/PartDesign/Gui/ViewProviderDressUp.h @@ -58,7 +58,8 @@ protected: const bool checkDlgOpen(TaskDlgDressUpParameters* dressUpDlg); private: - std::vector originalColors; + std::vector originalFaceColors; + std::vector originalLineColors; };