Skip to content

Commit

Permalink
Improve showing control points of splines
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Oct 23, 2013
1 parent 8307543 commit 8b054f3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 57 deletions.
89 changes: 33 additions & 56 deletions src/Mod/Part/Gui/ViewProviderSpline.cpp
Expand Up @@ -37,7 +37,6 @@
# include <TopoDS_Wire.hxx>
# include <TopoDS_Face.hxx>
# include <TopoDS_Shape.hxx>
# include <TopoDS_Iterator.hxx>
# include <TopExp_Explorer.hxx>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoSeparator.h>
Expand Down Expand Up @@ -66,6 +65,18 @@ ViewProviderSpline::~ViewProviderSpline()
{
}

void ViewProviderSpline::updateData(const App::Property* prop)
{
ViewProviderPartExt::updateData(prop);
if (prop->getTypeId() == Part::PropertyPartShape::getClassTypeId() && strcmp(prop->getName(), "Shape") == 0) {
// update control points if there
if (pcControlPoints) {
pcControlPoints->removeAllChildren();
showControlPoints(this->ControlPoints.getValue(), prop);
}
}
}

void ViewProviderSpline::onChanged(const App::Property* prop)
{
if (prop == &ControlPoints) {
Expand Down Expand Up @@ -97,25 +108,28 @@ void ViewProviderSpline::showControlPoints(bool show, const App::Property* prop)
const TopoDS_Shape& shape = static_cast<const Part::PropertyPartShape*>(prop)->getValue();
if (shape.IsNull())
return; // empty shape
switch (shape.ShapeType())
{
case TopAbs_EDGE:
{
const TopoDS_Edge& edge = TopoDS::Edge(shape);
showControlPointsOfEdge(edge);
} break;
case TopAbs_WIRE:
{
const TopoDS_Wire& wire = TopoDS::Wire(shape);
showControlPointsOfWire(wire);
} break;
case TopAbs_FACE:
{
const TopoDS_Face& face = TopoDS::Face(shape);

for (TopExp_Explorer xp(shape, TopAbs_SHELL); xp.More(); xp.Next()) {
const TopoDS_Shell& shell = TopoDS::Shell(xp.Current());
for (TopExp_Explorer xp2(xp.Current(), TopAbs_FACE); xp2.More(); xp2.Next()) {
const TopoDS_Face& face = TopoDS::Face(xp2.Current());
showControlPointsOfFace(face);
} break;
default:
break;
}
}
for (TopExp_Explorer xp(shape, TopAbs_FACE, TopAbs_SHELL); xp.More(); xp.Next()) {
const TopoDS_Face& face = TopoDS::Face(xp.Current());
showControlPointsOfFace(face);
}
for (TopExp_Explorer xp(shape, TopAbs_WIRE, TopAbs_FACE); xp.More(); xp.Next()) {
const TopoDS_Wire& wire = TopoDS::Wire(xp.Current());
for (TopExp_Explorer xp2(xp.Current(), TopAbs_EDGE); xp2.More(); xp2.Next()) {
const TopoDS_Edge& edge = TopoDS::Edge(xp2.Current());
showControlPointsOfEdge(edge);
}
}
for (TopExp_Explorer xp(shape, TopAbs_EDGE, TopAbs_WIRE); xp.More(); xp.Next()) {
const TopoDS_Edge& edge = TopoDS::Edge(xp.Current());
showControlPointsOfEdge(edge);
}
}
}
Expand Down Expand Up @@ -183,43 +197,6 @@ void ViewProviderSpline::showControlPointsOfEdge(const TopoDS_Edge& edge)
pcControlPoints->addChild(nodes);
}

void ViewProviderSpline::showControlPointsOfWire(const TopoDS_Wire& wire)
{
TopoDS_Iterator it;
for (it.Initialize(wire); it.More(); it.Next()) {
if (it.Value().ShapeType() == TopAbs_EDGE) {
const TopoDS_Edge& edge = TopoDS::Edge(it.Value());
BRepAdaptor_Curve curve(edge);

std::list<gp_Pnt> poles, knots;
gp_Pnt start, end;
switch (curve.GetType())
{
case GeomAbs_BezierCurve:
{
Handle(Geom_BezierCurve) hBezier = curve.Bezier();
for (Standard_Integer i = 1; i <= hBezier->NbPoles(); i++)
poles.push_back(hBezier->Pole(i));
start = hBezier->StartPoint();
end = hBezier->EndPoint();
} break;
case GeomAbs_BSplineCurve:
{
Handle(Geom_BSplineCurve) hBSpline = curve.BSpline();
for (Standard_Integer i = 1; i <= hBSpline->NbPoles(); i++)
poles.push_back(hBSpline->Pole(i));
start = hBSpline->StartPoint();
end = hBSpline->EndPoint();
for (Standard_Integer i = hBSpline->FirstUKnotIndex()+1; i <= hBSpline->LastUKnotIndex()-1; i++)
knots.push_back(hBSpline->Value(hBSpline->Knot(i)));
} break;
default:
break;
}
}
}
}

void ViewProviderSpline::showControlPointsOfFace(const TopoDS_Face& face)
{
std::list<gp_Pnt> knots;
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Part/Gui/ViewProviderSpline.h
Expand Up @@ -43,11 +43,12 @@ class PartGuiExport ViewProviderSpline : public ViewProviderPartExt
// Display properties
App::PropertyBool ControlPoints;

void updateData(const App::Property* prop);

protected:
void onChanged(const App::Property* prop);
void showControlPoints(bool, const App::Property* prop);
void showControlPointsOfEdge(const TopoDS_Edge&);
void showControlPointsOfWire(const TopoDS_Wire&);
void showControlPointsOfFace(const TopoDS_Face&);

SoSwitch *pcControlPoints;
Expand Down

0 comments on commit 8b054f3

Please sign in to comment.