From 853adf7d9df740c10fd79b119bd587a919267d57 Mon Sep 17 00:00:00 2001 From: jrheinlaender Date: Fri, 20 Sep 2013 20:35:09 +0200 Subject: [PATCH] Highlighting for datum features --- .../PartDesign/Gui/ViewProviderDatumLine.cpp | 47 +++----- .../PartDesign/Gui/ViewProviderDatumPlane.cpp | 103 ++++++++++++------ .../PartDesign/Gui/ViewProviderDatumPoint.cpp | 41 +++---- 3 files changed, 98 insertions(+), 93 deletions(-) diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp index 79426eaff..fa0bd4931 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp @@ -25,17 +25,8 @@ #ifndef _PreComp_ # include -# include -# include # include -# include -# include -# include -# include -# include -# include -# include -# include +# include # include # include # include @@ -49,6 +40,9 @@ #include "ViewProviderDatumLine.h" #include "TaskDatumParameters.h" #include "Workbench.h" +#include +#include +#include #include #include #include @@ -101,29 +95,24 @@ void ViewProviderDatumLine::updateData(const App::Property* prop) } // Display the line - SoMFVec3f v; - v.setNum(2); - v.set1Value(0, p1.x, p1.y, p1.z); - v.set1Value(1, p2.x, p2.y, p2.z); - SoMFInt32 idx; - idx.setNum(1); - idx.set1Value(0, 2); - - SoLineSet* lineSet; - SoVertexProperty* vprop; + PartGui::SoBrepEdgeSet* lineSet; + SoCoordinate3* coord; if (pShapeSep->getNumChildren() == 1) { - lineSet = new SoLineSet(); - vprop = new SoVertexProperty(); - vprop->vertex = v; - lineSet->vertexProperty = vprop; - lineSet->numVertices = idx; + coord = new SoCoordinate3(); + coord->point.setNum(2); + coord->point.set1Value(0, p1.x, p1.y, p1.z); + coord->point.set1Value(1, p2.x, p2.y, p2.z); + pShapeSep->addChild(coord); + lineSet = new PartGui::SoBrepEdgeSet(); + lineSet->coordIndex.setNum(2); + lineSet->coordIndex.set1Value(0, 0); + lineSet->coordIndex.set1Value(1, 1); pShapeSep->addChild(lineSet); } else { - lineSet = static_cast(pShapeSep->getChild(1)); - vprop = static_cast(lineSet->vertexProperty.getValue()); - vprop->vertex = v; - lineSet->numVertices = idx; + coord = static_cast(pShapeSep->getChild(1)); + coord->point.set1Value(0, p1.x, p1.y, p1.z); + coord->point.set1Value(1, p2.x, p2.y, p2.z); } } diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp index d8fbec81f..7305f6962 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp @@ -25,17 +25,9 @@ #ifndef _PreComp_ # include -# include -# include # include -# include -# include -# include +# include # include -# include -# include -# include -# include # include # include # include @@ -50,6 +42,9 @@ #include "TaskDatumParameters.h" #include "Workbench.h" #include +#include +#include +#include #include #include #include @@ -185,38 +180,74 @@ void ViewProviderDatumPlane::updateData(const App::Property* prop) } // Display the plane - SoMFVec3f v; - v.setNum(points.size()); - for (int p = 0; p < points.size(); p++) - v.set1Value(p, points[p].x, points[p].y, points[p].z); - SoMFInt32 idx; - idx.setNum(1); - idx.set1Value(0, points.size()); - - SoFaceSet* faceSet; - SoLineSet* lineSet; - SoVertexProperty* vprop; + // Note: To achieve different colours on the two sides of the plane, see: + // http://doc.coin3d.org/Coin/classSoIndexedFaceSet.html + SoCoordinate3* coord; + PartGui::SoBrepFaceSet* faceSet; + SoIndexedLineSet* lineSet; if (pShapeSep->getNumChildren() == 1) { - faceSet = new SoFaceSet(); - vprop = new SoVertexProperty(); - vprop->vertex = v; - faceSet->vertexProperty = vprop; - faceSet->numVertices = idx; + // The polygon must be split up into triangles because the SoBRepFaceSet only handles those + if (points.size() < 3) + return; + coord = new SoCoordinate3(); + coord->point.setNum(points.size()); + for (int p = 0; p < points.size(); p++) + coord->point.set1Value(p, points[p].x, points[p].y, points[p].z); + pShapeSep->addChild(coord); + + faceSet = new PartGui::SoBrepFaceSet(); + faceSet->partIndex.setNum(1); // One face + faceSet->partIndex.set1Value(0, points.size()-3 + 1); // with this many triangles + faceSet->coordIndex.setNum(4 + 4*(points.size()-3)); + // The first triangle + faceSet->coordIndex.set1Value(0, 0); + faceSet->coordIndex.set1Value(1, 1); + faceSet->coordIndex.set1Value(2, 2); + faceSet->coordIndex.set1Value(3, SO_END_FACE_INDEX); + // One more triangle for every extra polygon point + for (int p = 3; p < points.size(); p++) { + faceSet->coordIndex.set1Value(4 + 4*(p-3), 0); + faceSet->coordIndex.set1Value(4 + 4*(p-3) + 1, p-1); + faceSet->coordIndex.set1Value(4 + 4*(p-3) + 2, p); + faceSet->coordIndex.set1Value(4 + 4*(p-3) + 3, SO_END_FACE_INDEX); + } pShapeSep->addChild(faceSet); - lineSet = new SoLineSet(); - lineSet->vertexProperty = vprop; - lineSet->numVertices = idx; + + lineSet = new SoIndexedLineSet(); + lineSet->coordIndex.setNum(points.size()+2); + for (int p = 0; p < points.size(); p++) + lineSet->coordIndex.set1Value(p, p); + lineSet->coordIndex.set1Value(points.size(), 0); + lineSet->coordIndex.set1Value(points.size()+1, SO_END_LINE_INDEX); pShapeSep->addChild(lineSet); } else { - faceSet = static_cast(pShapeSep->getChild(1)); - vprop = static_cast(faceSet->vertexProperty.getValue()); - vprop->vertex = v; - faceSet->numVertices = idx; - lineSet = static_cast(pShapeSep->getChild(2)); - vprop = static_cast(lineSet->vertexProperty.getValue()); - vprop->vertex = v; - lineSet->numVertices = idx; + coord = static_cast(pShapeSep->getChild(1)); + coord->point.setNum(points.size()); + for (int p = 0; p < points.size(); p++) + coord->point.set1Value(p, points[p].x, points[p].y, points[p].z); + faceSet = static_cast(pShapeSep->getChild(2)); + faceSet->partIndex.setNum(1); // One face + faceSet->partIndex.set1Value(0, points.size()-3 + 1); // with this many triangles + faceSet->coordIndex.setNum(4 + 4*(points.size()-3)); + // The first triangle + faceSet->coordIndex.set1Value(0, 0); + faceSet->coordIndex.set1Value(1, 1); + faceSet->coordIndex.set1Value(2, 2); + faceSet->coordIndex.set1Value(3, SO_END_FACE_INDEX); + // One more triangle for every extra polygon point + for (int p = 3; p < points.size(); p++) { + faceSet->coordIndex.set1Value(4 + 4*(p-3), 0); + faceSet->coordIndex.set1Value(4 + 4*(p-3) + 1, p-1); + faceSet->coordIndex.set1Value(4 + 4*(p-3) + 2, p); + faceSet->coordIndex.set1Value(4 + 4*(p-3) + 3, SO_END_FACE_INDEX); + } + lineSet = static_cast(pShapeSep->getChild(3)); + lineSet->coordIndex.setNum(points.size()+2); + for (int p = 0; p < points.size(); p++) + lineSet->coordIndex.set1Value(p, p); + lineSet->coordIndex.set1Value(points.size(), 0); + lineSet->coordIndex.set1Value(points.size()+1, SO_END_LINE_INDEX); } } diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumPoint.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumPoint.cpp index 008858392..b5ad2eaa0 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumPoint.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumPoint.cpp @@ -25,35 +25,15 @@ #ifndef _PreComp_ # include -# include -# include -# include -# include # include # include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include #endif #include "ViewProviderDatumPoint.h" -#include "TaskDatumParameters.h" -#include "Workbench.h" +#include +#include +#include #include -#include -#include -#include -#include using namespace PartDesignGui; @@ -61,16 +41,21 @@ PROPERTY_SOURCE(PartDesignGui::ViewProviderDatumPoint,PartDesignGui::ViewProvide ViewProviderDatumPoint::ViewProviderDatumPoint() { - SoMarkerSet* points = new SoMarkerSet(); - points->markerIndex = SoMarkerSet::DIAMOND_FILLED_9_9; SoMFVec3f v; v.setNum(1); v.set1Value(0, 0,0,0); SoVertexProperty* vprop = new SoVertexProperty(); vprop->vertex = v; + // Using a marker gives a larger point but it doesn't do highlighting automatically like the SoBrepPointSet + SoMarkerSet* marker = new SoMarkerSet(); + marker->markerIndex = SoMarkerSet::DIAMOND_FILLED_9_9; + marker->vertexProperty = vprop; + marker->numPoints = 1; + PartGui::SoBrepPointSet* points = new PartGui::SoBrepPointSet(); points->vertexProperty = vprop; points->numPoints = 1; pShapeSep->addChild(points); + pShapeSep->addChild(marker); } ViewProviderDatumPoint::~ViewProviderDatumPoint() @@ -81,10 +66,10 @@ void ViewProviderDatumPoint::updateData(const App::Property* prop) { if (strcmp(prop->getName(),"Placement") == 0) { // The only reason to do this is to display the point in the correct position after loading the document - SoMarkerSet* points = static_cast(pShapeSep->getChild(0)); + SoMarkerSet* marker = static_cast(pShapeSep->getChild(1)); + marker->touch(); + PartGui::SoBrepPointSet* points = static_cast(pShapeSep->getChild(0)); points->touch(); - //points->numPoints = 0; - //points->numPoints = 1; } ViewProviderDatum::updateData(prop);