+
+//#define USE_COMPOUND
+#include "CurveCreator_Curve.hxx" // TODO - remove
+void CurveCreator_Utils::constructShape( const CurveCreator_ICurve* theCurve,
+ const int theISection, TopoDS_Shape& theShape,
+ std::vector<Handle_AIS_InteractiveObject>& aSectionRepresentation )
+{
+ CurveCreator::SectionType aSectType = theCurve->getSectionType( theISection );
+
+
+ int aPointSize = theCurve->getNbPoints( theISection );
+ bool aSectIsClosed = theCurve->isClosed( theISection );
+ if( aSectType == CurveCreator::Polyline )
+ {
+#ifdef USE_COMPOUND
+ BRep_Builder aBuilder;
+ TopoDS_Compound aComp;
+ aBuilder.MakeCompound(aComp);
+
+ int iPoint = 0;
+ gp_Pnt aPrevPoint, aPoint;
+ if ( aPointSize == 1 ) {
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPrevPoint );
+ TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex( aPrevPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ }
+ else if ( aPointSize > 1 ) {
+ TopoDS_Edge aPointEdge;
+ TopoDS_Vertex aVertex;
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPrevPoint );
+ aVertex = BRepBuilderAPI_MakeVertex( aPrevPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ iPoint++;
+ for( ; iPoint < aPointSize; iPoint++ ) {
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint );
+ aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
+ aBuilder.Add( aComp, aPointEdge );
+ aPrevPoint = aPoint;
+ }
+ if( aSectIsClosed && ( aPointSize > 2 ) ) {
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, 0, aPoint );
+ aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
+ aBuilder.Add( aComp, aPointEdge );
+ }
+ theShape = aComp;
+ }
+#endif
+ }
+ else if( aSectType == CurveCreator::Spline )
+ {
+ std::vector<double> aPoints;
+ for( int iPoint = 0; iPoint < aPointSize; iPoint++ )
+ {
+ CurveCreator::Coordinates aCoords = theCurve->getPoint( theISection, iPoint );
+ double aX = aCoords[0];
+ double aY = aCoords[1];
+ double aZ = aCoords[2];
+ aPoints.push_back( aX );
+ aPoints.push_back( aY );
+ }
+
+ if( aPointSize > 1 )
+ {
+ Handle(Geom_BSplineCurve) aBSplineCurve;
+ // fill array for algorithm by the received coordinates
+ int aLen = aPoints.size() / 2;
+ Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen);
+ std::vector<double>::const_iterator aListIter = aPoints.begin();
+ for (int ind = 1; ind <= aLen; ind++) {
+ gp_Pnt aPnt(gp::Origin());
+ aPnt.SetX(*aListIter);
+ aListIter++;
+ aPnt.SetY(*aListIter);
+ aListIter++;
+ aPnt.SetZ(0);
+ aHCurvePoints->SetValue(ind, aPnt);
+ }
+ // compute BSpline
+ GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution());
+ aGBC.Perform();
+ if (aGBC.IsDone()) {
+ aBSplineCurve = aGBC.Curve();
+ }
+ TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge();
+
+ TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
+ theShape = aWire;
+ }
+ }
+
+ const CurveCreator_Curve* aCurve = dynamic_cast<const CurveCreator_Curve*>( theCurve );
+ if ( !aCurve )
+ return;
+
+ if( aSectType == CurveCreator::Polyline )
+ {
+#ifndef USE_COMPOUND
+ int iPoint = 0;
+ for( ; iPoint < ( aPointSize - 1 ) ; iPoint++ ){
+ Handle_AIS_Point anAISPnt = aCurve->getAISPoint(theISection, iPoint);
+ aSectionRepresentation.push_back( anAISPnt );
+ Handle_AIS_Line aLine = aCurve->getAISLine( theISection, iPoint, iPoint+1 );
+ aSectionRepresentation.push_back( aLine );
+ }
+ if( aPointSize != 0 ){
+ Handle_AIS_Point anAISPnt = aCurve->getAISPoint(theISection, iPoint);
+ aSectionRepresentation.push_back( anAISPnt );
+ if( aSectIsClosed && ( aPointSize > 1 ) ){
+ Handle_AIS_Line aLine = aCurve->getAISLine( theISection, iPoint, 0 );
+ aSectionRepresentation.push_back( aLine );
+ }
+ }
+#endif
+ }
+ else if( aSectType == CurveCreator::Spline )
+ {
+ std::vector<double> aPoints;
+ for( int iPoint = 0; iPoint < aPointSize; iPoint++ )
+ {
+ Handle_AIS_Point anAISPnt = aCurve->getAISPoint( theISection, iPoint );
+ aSectionRepresentation.push_back( anAISPnt );
+ }
+ }
+}
+