Salome HOME
Creat\Edit stream operation.
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_AISCurve.cxx
index 952364d0689343d63028a0d8d69c3d23d5620b14..668e8564115a08974c4668a0cd7815e711e589e0 100644 (file)
 //
 
 #include "CurveCreator_AISCurve.hxx"
+#include "CurveCreator_ICurve.hxx"
+
+#include <Quantity_Color.hxx>
+#include <Prs3d_Presentation.hxx>
+#include <StdPrs_WFDeflectionShape.hxx>
+#include <Geom_BSplineCurve.hxx>
+#include <TColgp_HArray1OfPnt.hxx>
+#include <GeomAPI_Interpolate.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
 
 IMPLEMENT_STANDARD_HANDLE(CurveCreator_AISCurve, AIS_Shape)
 IMPLEMENT_STANDARD_RTTIEXT(CurveCreator_AISCurve, AIS_Shape)
 
-CurveCreator_AISCurve::CurveCreator_AISCurve()
-: AIS_Shape( TopoDS_Shape() )
+CurveCreator_AISCurve::CurveCreator_AISCurve( CurveCreator_ICurve* theCurve )
+: AIS_Shape( TopoDS_Shape() ), myCurve( theCurve )
 {
 }
 
@@ -31,7 +43,83 @@ void CurveCreator_AISCurve::Compute( const Handle(PrsMgr_PresentationManager3d)&
                                      const Handle(Prs3d_Presentation)& thePrs,
                                      const Standard_Integer theMode )
 {
-  AIS_Shape::Compute( thePM, thePrs, theMode );
+  thePrs->Clear();
+  //AIS_Shape::Compute( thePM, thePrs, theMode );
+
+  for( int iSection = 0 ; iSection < myCurve->getNbSections() ; iSection++ ) {
+    //TopoDS_Shape aShape;
+
+    CurveCreator::SectionType aSectType = myCurve->getSectionType( iSection );
+    int aSectSize = myCurve->getNbPoints( iSection );
+    bool aSectIsClosed = myCurve->isClosed( iSection );
+    /*if( aSectType == CurveCreator::Polyline )
+    {
+      int iPoint = 0; 
+      for( ; iPoint < ( aSectSize - 1 ) ; iPoint++ ){
+        Handle_AIS_Point anAISPnt = getAISPoint(theISection, iPoint);
+        aSectionRepresentation.push_back( anAISPnt );
+        Handle_AIS_Line aLine = getAISLine( theISection, iPoint, iPoint+1 );
+        aSectionRepresentation.push_back( aLine );
+      }
+      if( aSectSize != 0 ){
+        Handle_AIS_Point anAISPnt = getAISPoint(theISection, iPoint); 
+        aSectionRepresentation.push_back( anAISPnt );
+        if( isClosed(theISection) && ( aSectSize > 1 ) ){
+          Handle_AIS_Line aLine = getAISLine( theISection, iPoint, 0 );
+          aSectionRepresentation.push_back( aLine );
+        }
+      }
+    }*/
+    //else if( aSectType == CurveCreator::Spline )
+    {
+      std::vector<double> aPoints;
+      for( int iPoint = 0; iPoint < aSectSize; iPoint++ )
+      {
+        /*Handle_AIS_Point anAISPnt = getAISPoint( theISection, iPoint );
+        aSectionRepresentation.push_back( anAISPnt );
+        */
+        CurveCreator::Coordinates aCoords = myCurve->getPoint( iSection, iPoint );
+        double aX = aCoords[0];
+        double aY = aCoords[1];
+        double aZ = aCoords[2];
+        aPoints.push_back( aX );
+        aPoints.push_back( aY );
+      }
+      if( aSectSize > 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();
+
+        //Handle(AIS_Shape) aShape = new AIS_Shape( aWire );
+        //aSectionRepresentation.push_back( aShape );
+        StdPrs_WFDeflectionShape::Add( thePrs, aWire/*aShape*/, myDrawer );
+        //Quantity_Color aColor( 200, 200, 100, Quantity_TOC_RGB );
+        //SetColor(aColor);
+      }
+    }
+    //StdPrs_WFDeflectionShape::Add( thePrs, aShape, myDrawer );
+  }
 }
 
 void CurveCreator_AISCurve::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,