Salome HOME
patch for correct compilation on Linux
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Curve.cxx
index 129520136437240ed6e21fce61cf9ae439a34aad..3f88a8b2bddda6622673f0070e50d193fa438794 100644 (file)
@@ -28,9 +28,8 @@
 #include "CurveCreator_Displayer.h"
 #include "CurveCreator_Utils.h"
 
-#include <AIS_Point.hxx>
-#include <AIS_Line.hxx>
 #include <AIS_Shape.hxx>
+#include <AIS_InteractiveObject.hxx>
 #include <Geom_CartesianPoint.hxx>
 #include <gp_Pnt.hxx>
 #include <gp_Lin.hxx>
@@ -40,8 +39,6 @@
 
 #include <stdio.h>
 
-//#define AIS_CURVE_DISPLAY
-
 //=======================================================================
 // function: Constructor
 // purpose:
@@ -50,14 +47,12 @@ CurveCreator_Curve::CurveCreator_Curve( const CurveCreator::Dimension theDimensi
 : myIsLocked  (false),
   myDimension (theDimension),
   myDisplayer (NULL),
+  myAISShape  (NULL),
   myNbUndos   (0),
   myNbRedos   (0),
   myUndoDepth (-1),
   myOpLevel(0)
 {
-#ifdef AIS_CURVE_DISPLAY
-  myAISCurve = new CurveCreator_AISCurve( this );
-#endif
 }
 
 //=======================================================================
@@ -107,10 +102,6 @@ std::string CurveCreator_Curve::getUniqSectionName() const
 void CurveCreator_Curve::setDisplayer( CurveCreator_Displayer* theDisplayer )
 {
   myDisplayer = theDisplayer;
-  
-#ifdef AIS_CURVE_DISPLAY
-  myDisplayer->displayAIS( myAISCurve, false );
-#endif
 }
 
 //=======================================================================
@@ -182,20 +173,6 @@ int CurveCreator_Curve::toICoord(const int theIPnt) const
   return theIPnt * myDimension;
 }
 
-std::vector<Handle_AIS_InteractiveObject> CurveCreator_Curve::constructSection( int theISection ) const
-{
-  std::vector<Handle_AIS_InteractiveObject> aSectionRepresentation;
-
-  TopoDS_Shape aShape;
-  CurveCreator_Utils::constructShape( this, theISection, aShape, aSectionRepresentation );
-
-  AIS_Shape* anAISShape = new AIS_Shape( aShape );
-  //aShape->SetSelectionMode( AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_VERTEX ) );
-  aSectionRepresentation.push_back( anAISShape );
-
-  return aSectionRepresentation;
-}
-
 //=======================================================================
 // function: setUndoDepth
 // purpose:
@@ -254,35 +231,6 @@ int CurveCreator_Curve::getUndoDepth() const
   return myUndoDepth;
 }
 
-Handle_AIS_Point CurveCreator_Curve::getAISPoint( int theISection, int theIPoint ) const
-{
-  double anX, anY, aZ;
-  getCoordinates( theISection, theIPoint, anX, anY, aZ );
-  gp_Pnt aPoint( anX, anY, aZ);
-
-  AIS_Point* aPnt = new AIS_Point( new Geom_CartesianPoint(aPoint));
-  return aPnt;
-}
-
-Handle_AIS_Line CurveCreator_Curve::getAISLine( int theISection, int theIPoint1, int theIPoint2 ) const
-{
-  double anX, anY, aZ;
-  getCoordinates( theISection, theIPoint1, anX, anY, aZ );
-  gp_Pnt aPoint1( anX, anY, aZ);
-
-  double anX2, anY2, aZ2;
-  getCoordinates( theISection, theIPoint2, anX2, anY2, aZ2 );
-//MTN to avoid crash during line construction
-  if( ( anX == anX2 ) && ( anY == anY2 ) && (aZ == aZ2 ) ){
-    aZ2 += 1e-7;
-  }
-
-  gp_Pnt aPoint2( anX2, anY2, aZ2 );
-
-  AIS_Line* aLine = new AIS_Line( new Geom_CartesianPoint(aPoint1), new Geom_CartesianPoint(aPoint2) );
-  return aLine;
-}
-
 void CurveCreator_Curve::getCoordinates( int theISection, int theIPoint, double& theX, double& theY, double& theZ ) const
 {
   CurveCreator::Coordinates aCoords = getPoint( theISection, theIPoint );
@@ -294,30 +242,13 @@ void CurveCreator_Curve::getCoordinates( int theISection, int theIPoint, double&
   }
 }
 
-//#define USE_COMPOUND
 void CurveCreator_Curve::redisplayCurve()
 {
   if( myDisplayer ) {
-#ifdef AIS_CURVE_DISPLAY
-    myDisplayer->redisplayAIS(myAISCurve, false);
-#else
-    myDisplayer->erase( false );
-//#ifndef USE_COMPOUND
-    myDisplayer->display( constructWire(), true );
-//#else
-    /*std::vector<Handle_AIS_InteractiveObject> anAISObjects = constructWire();
-    int aSelMode = AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_VERTEX );
-    Handle(AIS_InteractiveContext) aContext = myDisplayer->getAISContext();
-    for( int i = 0 ; i < anAISObjects.size() ; i++ ){
-      Handle_AIS_InteractiveObject anAISObject = anAISObjects[i];
-      //anAISObject->SetSelectionMode( aSelMode );
-      aContext->Display( anAISObject, Standard_False );
-      //aContext->Display( anAISObject, 0, aSelMode, Standard_False, Standard_True );
-    }
-      aContext->UpdateCurrentViewer();
-    */
-//#endif
-#endif
+    myDisplayer->eraseAll( false );
+    myAISShape = NULL;
+
+    myDisplayer->display( getAISObject( true ), true );
   }
 }
 
@@ -435,8 +366,10 @@ bool CurveCreator_Curve::redo()
 bool CurveCreator_Curve::clearInternal()
 {
   // erase curve from the viewer
-  if( myDisplayer )
-    myDisplayer->erase( true );
+  if( myDisplayer ) {
+    myDisplayer->eraseAll( true );
+    myAISShape = NULL;
+  }
   // Delete all allocated data.
   int i = 0;
   const int aNbSections = getNbSections();
@@ -1008,27 +941,19 @@ CurveCreator::Coordinates CurveCreator_Curve::getPoints( const int theISection )
   return aCoords;
 }
 
-
-/***********************************************/
-/***       Presentation methods              ***/
-/***********************************************/
-std::vector<Handle_AIS_InteractiveObject> CurveCreator_Curve::constructWire() const
+void CurveCreator_Curve::constructAISObject()
 {
-  std::vector<Handle_AIS_InteractiveObject> aCurveRepresentation;
-  std::vector<Handle_AIS_InteractiveObject> aSectionObjects;
-  for( int iSection = 0 ; iSection < getNbSections() ; iSection++ ){
-    aSectionObjects = constructSection( iSection );
-    for( int iObject = 0 ; iObject < aSectionObjects.size() ; iObject++ ){
-      aCurveRepresentation.push_back( aSectionObjects.at(iObject) );
-    }
-  }
-  return aCurveRepresentation;
+  TopoDS_Shape aShape;
+  CurveCreator_Utils::constructShape( this, aShape );
+
+  myAISShape = new AIS_Shape( aShape );
 }
 
-void CurveCreator_Curve::getPoint( const int theISection, const int theIPoint,
-                                   gp_Pnt& thePoint ) const
+Handle(AIS_InteractiveObject) CurveCreator_Curve::getAISObject( const bool theNeedToBuild ) const
 {
-  double anX, anY, aZ;
-  getCoordinates( theISection, theIPoint, anX, anY, aZ );
-  thePoint = gp_Pnt( anX, anY, aZ);
-}
+  if ( !myAISShape && theNeedToBuild ) {
+    CurveCreator_Curve* aCurve = (CurveCreator_Curve*)this;
+    aCurve->constructAISObject();
+  }
+  return myAISShape;
+}
\ No newline at end of file