Reference highlighting for fillets and chamfers
This commit is contained in:
committed by
Stefan Tröger
parent
1772eb70bc
commit
af25c0c793
@@ -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<App::Color>& 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<App::Color>& 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<App::Color>& 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -208,6 +208,7 @@ TaskDlgDressUpParameters::~TaskDlgDressUpParameters()
|
||||
bool TaskDlgDressUpParameters::accept()
|
||||
{
|
||||
std::string name = DressUpView->getObject()->getNameInDocument();
|
||||
DressUpView->highlightReferences(false);
|
||||
|
||||
try {
|
||||
std::vector<std::string> 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) {
|
||||
|
||||
@@ -97,25 +97,46 @@ void ViewProviderDressUp::highlightReferences(const bool on)
|
||||
Gui::Application::Instance->getViewProvider(base));
|
||||
if (vp == NULL) return;
|
||||
|
||||
if (on) {
|
||||
std::vector<std::string> SubVals = pcDressUp->Base.getSubValuesStartsWith("Face");
|
||||
if (SubVals.size() == 0) return;
|
||||
std::vector<std::string> faces = pcDressUp->Base.getSubValuesStartsWith("Face");
|
||||
std::vector<std::string> 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<App::Color> colors = originalColors;
|
||||
colors.resize(fMap.Extent(), ShapeColor.getValue());
|
||||
originalFaceColors = vp->DiffuseColor.getValues();
|
||||
std::vector<App::Color> colors = originalFaceColors;
|
||||
colors.resize(fMap.Extent(), ShapeColor.getValue());
|
||||
|
||||
for (std::vector<std::string>::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<std::string>::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<App::Color> colors = originalLineColors;
|
||||
colors.resize(eMap.Extent(), LineColor.getValue());
|
||||
|
||||
for (std::vector<std::string>::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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,8 @@ protected:
|
||||
const bool checkDlgOpen(TaskDlgDressUpParameters* dressUpDlg);
|
||||
|
||||
private:
|
||||
std::vector<App::Color> originalColors;
|
||||
std::vector<App::Color> originalFaceColors;
|
||||
std::vector<App::Color> originalLineColors;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user