]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
AIS presentation for a curve creator
authornds <nds@opencascade.com>
Mon, 2 Dec 2013 09:58:36 +0000 (09:58 +0000)
committernds <nds@opencascade.com>
Mon, 2 Dec 2013 09:58:36 +0000 (09:58 +0000)
src/HYDROCurveCreator/CurveCreator_AISCurve.cxx
src/HYDROCurveCreator/CurveCreator_AISCurve.hxx
src/HYDROCurveCreator/CurveCreator_Curve.cxx
src/HYDROCurveCreator/CurveCreator_Curve.hxx
src/HYDROCurveCreator/CurveCreator_Displayer.cxx
src/HYDROCurveCreator/CurveCreator_Displayer.h

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,
index 3672e57b24056c22e1cd20f1b84585ac0fd7214e..292e77c077edfe696913b6235544262724ae692b 100644 (file)
@@ -27,6 +27,8 @@
 
 #include <AIS_Shape.hxx>
 
+class CurveCreator_ICurve;
+
 DEFINE_STANDARD_HANDLE(CurveCreator_AISCurve, AIS_Shape)
 
 /**
@@ -36,7 +38,7 @@ DEFINE_STANDARD_HANDLE(CurveCreator_AISCurve, AIS_Shape)
 class CurveCreator_AISCurve : public AIS_Shape
 {
 public:
-  Standard_EXPORT CurveCreator_AISCurve();
+  Standard_EXPORT CurveCreator_AISCurve( CurveCreator_ICurve* theCurve );
 
 protected:
   /**
@@ -59,6 +61,9 @@ protected:
 
 public:
   DEFINE_STANDARD_RTTI(CurveCreator_AISCurve)
+
+protected:
+  CurveCreator_ICurve* myCurve;
 };
 
 #endif // CURVECREATOR_AIS_CURVE_H
index d0c18958846d6f6da2886283a1a2fb217d2092a6..25939c148716e0bf549d00a75a4e8cb04a5838e5 100644 (file)
@@ -43,6 +43,8 @@
 
 #include <stdio.h>
 
+//#define AIS_CURVE_DISPLAY
+
 //=======================================================================
 // function: Constructor
 // purpose:
@@ -56,6 +58,9 @@ CurveCreator_Curve::CurveCreator_Curve( const CurveCreator::Dimension theDimensi
   myUndoDepth (-1),
   myOpLevel(0)
 {
+#ifdef AIS_CURVE_DISPLAY
+  myAISCurve = new CurveCreator_AISCurve( this );
+#endif
 }
 
 //=======================================================================
@@ -105,6 +110,10 @@ std::string CurveCreator_Curve::getUniqSectionName() const
 void CurveCreator_Curve::setDisplayer( CurveCreator_Displayer* theDisplayer )
 {
   myDisplayer = theDisplayer;
+  
+#ifdef AIS_CURVE_DISPLAY
+  myDisplayer->displayAIS( myAISCurve, false );
+#endif
 }
 
 //=======================================================================
@@ -352,8 +361,12 @@ void CurveCreator_Curve::getCoordinates( int theISection, int theIPoint, double&
 void CurveCreator_Curve::redisplayCurve()
 {
   if( myDisplayer ) {
+#ifdef AIS_CURVE_DISPLAY
+    myDisplayer->redisplayAIS(myAISCurve, false);
+#else
     myDisplayer->erase( false );
     myDisplayer->display( constructWire(), true );
+#endif
   }
 }
 
index 5747dd8bbc2dce64eb6006d3a7b565b098701345..e359e66c44a5ee83b5259f9c46c48ac3cf57e957 100644 (file)
@@ -28,6 +28,7 @@
 #include "CurveCreator_Macro.hxx"
 #include "CurveCreator.hxx"
 #include "CurveCreator_Diff.hxx"
+#include "CurveCreator_AISCurve.hxx"
 
 #include <AIS_Point.hxx>
 #include <AIS_Line.hxx>
@@ -269,7 +270,7 @@ public:
   virtual ListAISObjects constructWire() const;
 
 public:
-
+  Handle(CurveCreator_AISCurve)   myAISCurve;
   bool                            myIsLocked;
   CurveCreator::Sections          mySections;   //!< curve data
   CurveCreator::Dimension         myDimension;  //!< curve dimension
index 92df32341fd1c5c7a3a2ef54cf816dc25fc2863d..f0c5463d8e32d348eb19a10ee6ccdfe3493e0470 100644 (file)
@@ -38,6 +38,22 @@ void CurveCreator_Displayer::erase( bool isUpdate )
     myContext->UpdateCurrentViewer();
 }
 
+void CurveCreator_Displayer::displayAIS( Handle(AIS_InteractiveObject) theObject, bool isUpdate )
+{
+  myContext->Display( theObject, Standard_False );
+
+  if( isUpdate )
+    myContext->UpdateCurrentViewer();
+}
+
+void CurveCreator_Displayer::redisplayAIS( Handle(AIS_InteractiveObject) theObject, bool isUpdate )
+{
+  myContext->Redisplay( theObject, Standard_False );
+
+  if( isUpdate )
+    myContext->UpdateCurrentViewer();
+}
+
 Quantity_Color CurveCreator_Displayer::getActiveColor( bool isHL )
 {
   if( isHL ){
index 6bfc8d08e3399d8a6f9a59f622faf041728c4d4d..92ed520bfb38e94d838457c8cbfbbda6d3b5d5e6 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef CURVECREATOR_AIS_CURVE_H
-#define CURVECREATOR_AIS_CURVE_H
+#ifndef CURVECREATOR_DISPLAYER_H
+#define CURVECREATOR_DISPLAYER_H
 
 #include "CurveCreator_Macro.hxx"
 
@@ -20,6 +20,9 @@ public:
   void erase( bool isUpdate );
   void highlight( const AISObjectsList& theObjects, bool isHL );
 
+  void displayAIS( Handle_AIS_InteractiveObject theObject, bool isUpdate );
+  void redisplayAIS( Handle_AIS_InteractiveObject theObject, bool isUpdate );
+
 protected:
   Quantity_Color getActiveColor( bool isHL );