Additional visual modes and some clean up in ViewProvider
This commit is contained in:
parent
450b028042
commit
5fc802dfa1
|
@ -164,20 +164,14 @@ App::PropertyFloatConstraint::Constraints ViewProviderFemMesh::floatRange = {1.0
|
||||||
|
|
||||||
ViewProviderFemMesh::ViewProviderFemMesh()
|
ViewProviderFemMesh::ViewProviderFemMesh()
|
||||||
{
|
{
|
||||||
App::Material mat;
|
|
||||||
mat.ambientColor.set(0.2f,0.2f,0.2f);
|
ADD_PROPERTY(PointColor,(App::Color(0.7f,0.7f,0.7f)));
|
||||||
mat.diffuseColor.set(0.1f,0.1f,0.1f);
|
ADD_PROPERTY(PointSize,(5.0f));
|
||||||
mat.specularColor.set(0.0f,0.0f,0.0f);
|
|
||||||
mat.emissiveColor.set(0.0f,0.0f,0.0f);
|
|
||||||
mat.shininess = 0.0f;
|
|
||||||
mat.transparency = 0.0f;
|
|
||||||
ADD_PROPERTY(PointMaterial,(mat));
|
|
||||||
ADD_PROPERTY(PointColor,(mat.diffuseColor));
|
|
||||||
ADD_PROPERTY(PointSize,(2.0f));
|
|
||||||
PointSize.setConstraints(&floatRange);
|
PointSize.setConstraints(&floatRange);
|
||||||
ADD_PROPERTY(LineWidth,(2.0f));
|
ADD_PROPERTY(LineWidth,(2.0f));
|
||||||
LineWidth.setConstraints(&floatRange);
|
LineWidth.setConstraints(&floatRange);
|
||||||
|
|
||||||
|
ShapeColor.setValue(App::Color(1.0f,0.7f,0.0f));
|
||||||
ADD_PROPERTY(BackfaceCulling,(true));
|
ADD_PROPERTY(BackfaceCulling,(true));
|
||||||
ADD_PROPERTY(ShowInner, (false));
|
ADD_PROPERTY(ShowInner, (false));
|
||||||
|
|
||||||
|
@ -215,7 +209,7 @@ ViewProviderFemMesh::ViewProviderFemMesh()
|
||||||
|
|
||||||
pcPointMaterial = new SoMaterial;
|
pcPointMaterial = new SoMaterial;
|
||||||
pcPointMaterial->ref();
|
pcPointMaterial->ref();
|
||||||
PointMaterial.touch();
|
//PointMaterial.touch();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,45 +280,57 @@ void ViewProviderFemMesh::attach(App::DocumentObject *pcObj)
|
||||||
pcPointsRoot->addChild(pcCoords);
|
pcPointsRoot->addChild(pcCoords);
|
||||||
pointset = new SoPointSet;
|
pointset = new SoPointSet;
|
||||||
pcPointsRoot->addChild(pointset);
|
pcPointsRoot->addChild(pointset);
|
||||||
addDisplayMaskMode(pcPointsRoot, "Points");
|
addDisplayMaskMode(pcPointsRoot, "Nodes");
|
||||||
|
|
||||||
// flat+line
|
// flat+line (Elements)
|
||||||
SoPolygonOffset* offset = new SoPolygonOffset();
|
SoPolygonOffset* offset = new SoPolygonOffset();
|
||||||
offset->styles = SoPolygonOffset::LINES;
|
offset->styles = SoPolygonOffset::LINES;
|
||||||
offset->factor = -2.0f;
|
//offset->factor = 2.0f;
|
||||||
offset->units = 1.0f;
|
//offset->units = 1.0f;
|
||||||
SoGroup* pcFlatWireRoot = new SoSeparator();
|
SoGroup* pcFlatWireRoot = new SoSeparator();
|
||||||
// add the complete flat group (contains the coordinates)
|
// add the complete flat group (contains the coordinates)
|
||||||
pcFlatWireRoot->addChild(pcFlatRoot);
|
pcFlatWireRoot->addChild(pcFlatRoot);
|
||||||
pcFlatWireRoot->addChild(offset);
|
//pcFlatWireRoot->addChild(offset); // makes no differents.....
|
||||||
//pcFlatWireRoot->addChild(pcWireRoot);
|
|
||||||
// add the line nodes
|
// add the line nodes
|
||||||
pcFlatWireRoot->addChild(pcDrawStyle);
|
pcFlatWireRoot->addChild(pcDrawStyle);
|
||||||
pcFlatWireRoot->addChild(pcLightModel);
|
pcFlatWireRoot->addChild(pcLightModel);
|
||||||
pcFlatWireRoot->addChild(color);
|
pcFlatWireRoot->addChild(color);
|
||||||
pcFlatWireRoot->addChild(pcLines);
|
pcFlatWireRoot->addChild(pcLines);
|
||||||
//pcFlatWireRoot->addChild(pcPointMaterial);
|
|
||||||
//pcFlatWireRoot->addChild(pcPointStyle);
|
|
||||||
//pcFlatWireRoot->addChild(pcPointMaterial);
|
|
||||||
//pcFlatWireRoot->addChild(pointset);
|
|
||||||
|
|
||||||
addDisplayMaskMode(pcFlatWireRoot, "Flat Lines");
|
addDisplayMaskMode(pcFlatWireRoot, "Elements");
|
||||||
|
|
||||||
|
// flat+line+Nodes (Elements&Nodes)
|
||||||
|
SoGroup* pcElemNodesRoot = new SoSeparator();
|
||||||
|
// add the complete flat group (contains the coordinates)
|
||||||
|
pcElemNodesRoot->addChild(pcFlatRoot);
|
||||||
|
//pcElemNodesRoot->addChild(offset);
|
||||||
|
// add the line nodes
|
||||||
|
pcElemNodesRoot->addChild(pcDrawStyle);
|
||||||
|
pcElemNodesRoot->addChild(pcLightModel);
|
||||||
|
pcElemNodesRoot->addChild(color);
|
||||||
|
pcElemNodesRoot->addChild(pcLines);
|
||||||
|
// add the points nodes
|
||||||
|
pcElemNodesRoot->addChild(pcPointMaterial);
|
||||||
|
pcElemNodesRoot->addChild(pcPointStyle);
|
||||||
|
pcElemNodesRoot->addChild(pcPointMaterial);
|
||||||
|
pcElemNodesRoot->addChild(pointset);
|
||||||
|
|
||||||
|
addDisplayMaskMode(pcElemNodesRoot, "Elements & Nodes");
|
||||||
|
|
||||||
//pcHighlight->addChild(pcCoords);
|
|
||||||
//pcHighlight->addChild(pcFaces);
|
|
||||||
//pcHighlight->addChild(pcLines);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewProviderFemMesh::setDisplayMode(const char* ModeName)
|
void ViewProviderFemMesh::setDisplayMode(const char* ModeName)
|
||||||
{
|
{
|
||||||
if (strcmp("Flat Lines",ModeName)==0)
|
if (strcmp("Elements",ModeName)==0)
|
||||||
setDisplayMaskMode("Flat Lines");
|
setDisplayMaskMode("Elements");
|
||||||
else if (strcmp("Shaded",ModeName)==0)
|
else if (strcmp("Elements & Nodes",ModeName)==0)
|
||||||
|
setDisplayMaskMode("Elements & Nodes");
|
||||||
|
else if (strcmp("Flat",ModeName)==0)
|
||||||
setDisplayMaskMode("Flat");
|
setDisplayMaskMode("Flat");
|
||||||
else if (strcmp("Wireframe",ModeName)==0)
|
else if (strcmp("Wireframe",ModeName)==0)
|
||||||
setDisplayMaskMode("Wireframe");
|
setDisplayMaskMode("Wireframe");
|
||||||
else if (strcmp("Points",ModeName)==0)
|
else if (strcmp("Nodes",ModeName)==0)
|
||||||
setDisplayMaskMode("Points");
|
setDisplayMaskMode("Nodes");
|
||||||
|
|
||||||
ViewProviderGeometryObject::setDisplayMode( ModeName );
|
ViewProviderGeometryObject::setDisplayMode( ModeName );
|
||||||
}
|
}
|
||||||
|
@ -332,10 +338,11 @@ void ViewProviderFemMesh::setDisplayMode(const char* ModeName)
|
||||||
std::vector<std::string> ViewProviderFemMesh::getDisplayModes(void) const
|
std::vector<std::string> ViewProviderFemMesh::getDisplayModes(void) const
|
||||||
{
|
{
|
||||||
std::vector<std::string> StrList;
|
std::vector<std::string> StrList;
|
||||||
StrList.push_back("Flat Lines");
|
StrList.push_back("Elements");
|
||||||
StrList.push_back("Shaded");
|
StrList.push_back("Elements & Nodes");
|
||||||
|
StrList.push_back("Flat");
|
||||||
StrList.push_back("Wireframe");
|
StrList.push_back("Wireframe");
|
||||||
StrList.push_back("Points");
|
StrList.push_back("Nodes");
|
||||||
return StrList;
|
return StrList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +350,7 @@ void ViewProviderFemMesh::updateData(const App::Property* prop)
|
||||||
{
|
{
|
||||||
if (prop->isDerivedFrom(Fem::PropertyFemMesh::getClassTypeId())) {
|
if (prop->isDerivedFrom(Fem::PropertyFemMesh::getClassTypeId())) {
|
||||||
ViewProviderFEMMeshBuilder builder;
|
ViewProviderFEMMeshBuilder builder;
|
||||||
builder.createMesh(prop, pcCoords, pcFaces, pcLines,vFaceElementIdx, ShowInner.getValue());
|
builder.createMesh(prop, pcCoords, pcFaces, pcLines,vFaceElementIdx,vNodeElementIdx, ShowInner.getValue());
|
||||||
}
|
}
|
||||||
Gui::ViewProviderGeometryObject::updateData(prop);
|
Gui::ViewProviderGeometryObject::updateData(prop);
|
||||||
}
|
}
|
||||||
|
@ -356,8 +363,6 @@ void ViewProviderFemMesh::onChanged(const App::Property* prop)
|
||||||
else if (prop == &PointColor) {
|
else if (prop == &PointColor) {
|
||||||
const App::Color& c = PointColor.getValue();
|
const App::Color& c = PointColor.getValue();
|
||||||
pcPointMaterial->diffuseColor.setValue(c.r,c.g,c.b);
|
pcPointMaterial->diffuseColor.setValue(c.r,c.g,c.b);
|
||||||
if (c != PointMaterial.getValue().diffuseColor)
|
|
||||||
PointMaterial.setDiffuseColor(c);
|
|
||||||
}
|
}
|
||||||
else if (prop == &BackfaceCulling) {
|
else if (prop == &BackfaceCulling) {
|
||||||
if(BackfaceCulling.getValue()){
|
if(BackfaceCulling.getValue()){
|
||||||
|
@ -371,18 +376,7 @@ void ViewProviderFemMesh::onChanged(const App::Property* prop)
|
||||||
else if (prop == &ShowInner) {
|
else if (prop == &ShowInner) {
|
||||||
// recalc mesh with new settings
|
// recalc mesh with new settings
|
||||||
ViewProviderFEMMeshBuilder builder;
|
ViewProviderFEMMeshBuilder builder;
|
||||||
builder.createMesh(&(dynamic_cast<Fem::FemMeshObject*>(this->pcObject)->FemMesh), pcCoords, pcFaces, pcLines,vFaceElementIdx, ShowInner.getValue());
|
builder.createMesh(&(dynamic_cast<Fem::FemMeshObject*>(this->pcObject)->FemMesh), pcCoords, pcFaces, pcLines,vFaceElementIdx,vNodeElementIdx, ShowInner.getValue());
|
||||||
}
|
|
||||||
else if (prop == &PointMaterial) {
|
|
||||||
const App::Material& Mat = PointMaterial.getValue();
|
|
||||||
if (PointColor.getValue() != 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);
|
|
||||||
pcPointMaterial->emissiveColor.setValue(Mat.emissiveColor.r,Mat.emissiveColor.g,Mat.emissiveColor.b);
|
|
||||||
pcPointMaterial->shininess.setValue(Mat.shininess);
|
|
||||||
pcPointMaterial->transparency.setValue(Mat.transparency);
|
|
||||||
}
|
}
|
||||||
else if (prop == &LineWidth) {
|
else if (prop == &LineWidth) {
|
||||||
pcDrawStyle->lineWidth = LineWidth.getValue();
|
pcDrawStyle->lineWidth = LineWidth.getValue();
|
||||||
|
@ -407,11 +401,11 @@ std::string ViewProviderFemMesh::getElement(const SoDetail* detail) const
|
||||||
// int edge = line_detail->getLineIndex() + 1;
|
// int edge = line_detail->getLineIndex() + 1;
|
||||||
// str << "Edge" << edge;
|
// str << "Edge" << edge;
|
||||||
//}
|
//}
|
||||||
//else if (detail->getTypeId() == SoPointDetail::getClassTypeId()) {
|
else if (detail->getTypeId() == SoPointDetail::getClassTypeId()) {
|
||||||
// const SoPointDetail* point_detail = static_cast<const SoPointDetail*>(detail);
|
const SoPointDetail* point_detail = static_cast<const SoPointDetail*>(detail);
|
||||||
// int vertex = 0;//point_detail->getCoordinateIndex() - nodeset->startIndex.getValue() + 1;
|
int vertex = vNodeElementIdx[point_detail->getCoordinateIndex()];
|
||||||
// str << "Vertex" << vertex;
|
str << "Node" << vertex;
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return str.str();
|
return str.str();
|
||||||
|
@ -430,7 +424,7 @@ SoDetail* ViewProviderFemMesh::getDetail(const char* subelement) const
|
||||||
SoDetail* detail = 0;
|
SoDetail* detail = 0;
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return detail;
|
return detail;
|
||||||
if (element == "Face") {
|
if (element == "Elem") {
|
||||||
detail = new SoFaceDetail();
|
detail = new SoFaceDetail();
|
||||||
static_cast<SoFaceDetail*>(detail)->setPartIndex(index - 1);
|
static_cast<SoFaceDetail*>(detail)->setPartIndex(index - 1);
|
||||||
}
|
}
|
||||||
|
@ -502,7 +496,8 @@ void ViewProviderFEMMeshBuilder::buildNodes(const App::Property* prop, std::vect
|
||||||
|
|
||||||
if (pcPointsCoord && pcFaces){
|
if (pcPointsCoord && pcFaces){
|
||||||
std::vector<unsigned long> vFaceElementIdx;
|
std::vector<unsigned long> vFaceElementIdx;
|
||||||
createMesh(prop, pcPointsCoord, pcFaces,pcLines,vFaceElementIdx);
|
std::vector<unsigned long> vNodeElementIdx;
|
||||||
|
createMesh(prop, pcPointsCoord, pcFaces,pcLines,vFaceElementIdx,vNodeElementIdx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,7 +516,7 @@ inline unsigned long ElemFold(unsigned long Element,unsigned long FaceNbr)
|
||||||
return t2;
|
return t2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewProviderFEMMeshBuilder::createMesh(const App::Property* prop, SoCoordinate3* coords, SoIndexedFaceSet* faces, SoIndexedLineSet* lines,std::vector<unsigned long> &vFaceElementIdx, bool ShowInner) const
|
void ViewProviderFEMMeshBuilder::createMesh(const App::Property* prop, SoCoordinate3* coords, SoIndexedFaceSet* faces, SoIndexedLineSet* lines,std::vector<unsigned long> &vFaceElementIdx,std::vector<unsigned long> &vNodeElementIdx, bool ShowInner) const
|
||||||
{
|
{
|
||||||
|
|
||||||
const Fem::PropertyFemMesh* mesh = static_cast<const Fem::PropertyFemMesh*>(prop);
|
const Fem::PropertyFemMesh* mesh = static_cast<const Fem::PropertyFemMesh*>(prop);
|
||||||
|
@ -703,11 +698,14 @@ void ViewProviderFEMMeshBuilder::createMesh(const App::Property* prop, SoCoordin
|
||||||
|
|
||||||
// set the point coordinates
|
// set the point coordinates
|
||||||
coords->point.setNum(mapNodeIndex.size());
|
coords->point.setNum(mapNodeIndex.size());
|
||||||
|
vNodeElementIdx.resize(mapNodeIndex.size() );
|
||||||
std::map<const SMDS_MeshNode*, int>::iterator it= mapNodeIndex.begin();
|
std::map<const SMDS_MeshNode*, int>::iterator it= mapNodeIndex.begin();
|
||||||
SbVec3f* verts = coords->point.startEditing();
|
SbVec3f* verts = coords->point.startEditing();
|
||||||
for (int i=0;it != mapNodeIndex.end() ;++it,i++) {
|
for (int i=0;it != mapNodeIndex.end() ;++it,i++) {
|
||||||
verts[i].setValue((float)it->first->X(),(float)it->first->Y(),(float)it->first->Z());
|
verts[i].setValue((float)it->first->X(),(float)it->first->Y(),(float)it->first->Z());
|
||||||
it->second = i;
|
it->second = i;
|
||||||
|
// set selection idx
|
||||||
|
vNodeElementIdx[i] = it->first->GetID();
|
||||||
}
|
}
|
||||||
coords->point.finishEditing();
|
coords->point.finishEditing();
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,14 @@ public:
|
||||||
ViewProviderFEMMeshBuilder(){}
|
ViewProviderFEMMeshBuilder(){}
|
||||||
~ViewProviderFEMMeshBuilder(){}
|
~ViewProviderFEMMeshBuilder(){}
|
||||||
virtual void buildNodes(const App::Property*, std::vector<SoNode*>&) const;
|
virtual void buildNodes(const App::Property*, std::vector<SoNode*>&) const;
|
||||||
void createMesh(const App::Property*, SoCoordinate3*, SoIndexedFaceSet*,SoIndexedLineSet*,std::vector<unsigned long>&,bool ShowInner=false) const;
|
void createMesh(const App::Property*,
|
||||||
|
SoCoordinate3*,
|
||||||
|
SoIndexedFaceSet*,
|
||||||
|
SoIndexedLineSet*,
|
||||||
|
std::vector<unsigned long>&,
|
||||||
|
std::vector<unsigned long>&,
|
||||||
|
bool ShowInner=false
|
||||||
|
) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FemGuiExport ViewProviderFemMesh : public Gui::ViewProviderGeometryObject
|
class FemGuiExport ViewProviderFemMesh : public Gui::ViewProviderGeometryObject
|
||||||
|
@ -61,7 +68,6 @@ public:
|
||||||
App::PropertyColor PointColor;
|
App::PropertyColor PointColor;
|
||||||
App::PropertyFloatConstraint PointSize;
|
App::PropertyFloatConstraint PointSize;
|
||||||
App::PropertyFloatConstraint LineWidth;
|
App::PropertyFloatConstraint LineWidth;
|
||||||
App::PropertyMaterial PointMaterial;
|
|
||||||
App::PropertyBool BackfaceCulling;
|
App::PropertyBool BackfaceCulling;
|
||||||
App::PropertyBool ShowInner;
|
App::PropertyBool ShowInner;
|
||||||
|
|
||||||
|
@ -98,6 +104,7 @@ protected:
|
||||||
|
|
||||||
/// index of elements to their triangles
|
/// index of elements to their triangles
|
||||||
std::vector<unsigned long> vFaceElementIdx;
|
std::vector<unsigned long> vFaceElementIdx;
|
||||||
|
std::vector<unsigned long> vNodeElementIdx;
|
||||||
|
|
||||||
SoMaterial * pcPointMaterial;
|
SoMaterial * pcPointMaterial;
|
||||||
SoDrawStyle * pcPointStyle;
|
SoDrawStyle * pcPointStyle;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user