Salome HOME
patch for crash
[modules/geom.git] / src / CurveCreator / CurveCreator_Curve.cxx
index e6be346fa1e7f9781004835cd385ff69f48e97b3..35843c83a7b8ec70dcbf16942592ba4eee3fe545 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2013-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -38,7 +38,6 @@
 #include <TopoDS_Wire.hxx>
 
 #include <Prs3d_PointAspect.hxx>
-#include <Handle_Prs3d_PointAspect.hxx>
 #include <iostream>
 #define DEBTRACE(msg) {std::cerr<<std::flush<<__FILE__<<" ["<<__LINE__<<"] : "<<msg<<std::endl<<std::flush;}
 
@@ -57,7 +56,11 @@ CurveCreator_Curve::CurveCreator_Curve( const CurveCreator::Dimension theDimensi
   myNbRedos   (0),
   myUndoDepth (-1),
   myOpLevel(0),
-  mySkipSorting(false)
+  mySkipSorting(false),
+  myPointAspectColor (Quantity_NOC_ROYALBLUE4), 
+  myCurveColor (Quantity_NOC_RED),
+  myEraseAll(true),
+  myLineWidth(1)
 {
 }
 
@@ -250,13 +253,16 @@ void CurveCreator_Curve::getCoordinates( int theISection, int theIPoint, double&
   }
 }
 
-void CurveCreator_Curve::redisplayCurve()
+void CurveCreator_Curve::redisplayCurve(bool preEraseAllObjects)
 {
   //DEBTRACE("redisplayCurve");
-  if( myDisplayer ) {
-    myDisplayer->eraseAll( false );
+  if( myDisplayer ) 
+  {
+    if (preEraseAllObjects)
+      myDisplayer->eraseAll( false );
+    else
+      myDisplayer->erase( myAISShape, false);
     myAISShape = NULL;
-
     myDisplayer->display( getAISObject( true ), true );
   }
 }
@@ -358,8 +364,12 @@ bool CurveCreator_Curve::redo()
 bool CurveCreator_Curve::clearInternal()
 {
   // erase curve from the viewer
-  if( myDisplayer ) {
-    myDisplayer->eraseAll( true );
+  if( myDisplayer )
+  {
+    if (myEraseAll)
+      myDisplayer->eraseAll( true );
+    else
+      myDisplayer->erase(myAISShape, false);
     myAISShape = NULL;
   }
   // Delete all allocated data.
@@ -395,6 +405,23 @@ bool CurveCreator_Curve::clear()
   return res;
 }
 
+//=======================================================================
+// function: clear
+// purpose:
+//=======================================================================
+void CurveCreator_Curve::SetEraseAllState(bool toEraseAll)
+{
+  myEraseAll = toEraseAll;
+}
+//=======================================================================
+// function: clear
+// purpose:
+//=======================================================================
+bool CurveCreator_Curve::GetEraseAllState() const
+{
+  return myEraseAll;
+}
+
 //! For internal use only! Undo/Redo are not used here.
 bool CurveCreator_Curve::joinInternal( const std::list<int>& theSections )
 {
@@ -423,7 +450,7 @@ bool CurveCreator_Curve::joinInternal( const std::list<int>& theSections )
       break;
   }
 
-  redisplayCurve();
+  redisplayCurve(false);
   return res;
 }
 
@@ -466,7 +493,7 @@ int CurveCreator_Curve::addSectionInternal
   aSection->myIsClosed = theIsClosed;
   aSection->myPoints   = thePoints;
   mySections.push_back(aSection);
-  redisplayCurve();
+  redisplayCurve(false);
   return mySections.size()-1;
 }
 
@@ -526,7 +553,7 @@ bool CurveCreator_Curve::removeSectionInternal( const int theISection )
     delete *anIterRm;
     mySections.erase(anIterRm);
   }
-  redisplayCurve();
+  redisplayCurve(false);
   return true;
 }
   
@@ -617,14 +644,14 @@ bool CurveCreator_Curve::setClosedInternal( const int theISection,
       aSection = (CurveCreator_Section*)getSection( i );
       if( aSection ) {
         aSection->myIsClosed = theIsClosed;
-        redisplayCurve();
+        redisplayCurve(false);
       }
     }
   } else {
     aSection = (CurveCreator_Section*)getSection( theISection );
     if ( aSection ) {
       aSection->myIsClosed = theIsClosed;
-      redisplayCurve();
+      redisplayCurve(false);
     }
   }
   return true;
@@ -707,12 +734,12 @@ bool CurveCreator_Curve::setSectionTypeInternal( const int theISection,
       if ( aSection )
         aSection->myType = theType;
     }
-    redisplayCurve();
+    redisplayCurve(false);
   } else {
     aSection = (CurveCreator_Section*)getSection( theISection );
     if ( aSection && aSection->myType != theType ){
       aSection->myType = theType;
-      redisplayCurve();
+      redisplayCurve(false);
     }
   }
   return true;
@@ -773,7 +800,7 @@ bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &the
     }
   }
   if(res)
-    redisplayCurve();
+    redisplayCurve(false);
   return res;
 }
 
@@ -831,7 +858,7 @@ bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theS
     }
   }
   if(res)
-    redisplayCurve();
+    redisplayCurve(false);
   
   return res;
 }
@@ -915,7 +942,7 @@ bool CurveCreator_Curve::removePointsInternal( const SectionToPointList &thePoin
     aRes = removeSectionPoints(aSectionId, anIt->second);
   }
   if( aRes)
-    redisplayCurve();
+    redisplayCurve(false);
 
   return aRes;
 }
@@ -972,32 +999,39 @@ CurveCreator::Coordinates CurveCreator_Curve::getPoint( const int theISection,
 // function: getPoints
 // purpose:
 //=======================================================================
-CurveCreator::Coordinates CurveCreator_Curve::getPoints( const int theISection ) const
+CurveCreator::Coordinates CurveCreator_Curve::getCoords( int theISection ) const
 {
-  //DEBTRACE("getPoints");
   CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
   return aSection ? aSection->myPoints : CurveCreator::Coordinates();
 }
 
+Handle(TColgp_HArray1OfPnt) CurveCreator_Curve::GetDifferentPoints( int theISection ) const
+{
+  //DEBTRACE("getPoints");
+  CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
+  return aSection ? aSection->GetDifferentPoints( (int)myDimension ) : Handle(TColgp_HArray1OfPnt)();
+}
+
 void CurveCreator_Curve::constructAISObject()
 {
   //DEBTRACE("constructAISObject");
   TopoDS_Shape aShape;
   CurveCreator_Utils::constructShape( this, aShape );
-
-  myAISShape = new AIS_Shape( aShape );
+  myAISShape = new AIS_Shape( aShape );  
+  myAISShape->SetColor( myCurveColor );
+  myAISShape->SetWidth( myLineWidth );
   Handle(Prs3d_PointAspect) anAspect = myAISShape->Attributes()->PointAspect();
   anAspect->SetScale( 3.0 );
   anAspect->SetTypeOfMarker(Aspect_TOM_O_POINT);
-  anAspect->SetColor(Quantity_NOC_ROYALBLUE4);
+  anAspect->SetColor(myPointAspectColor);
   myAISShape->Attributes()->SetPointAspect( anAspect );
-
 }
 
 Handle(AIS_InteractiveObject) CurveCreator_Curve::getAISObject( const bool theNeedToBuild ) const
 {
   //DEBTRACE("getAISObject");
-  if ( !myAISShape && theNeedToBuild ) {
+  if ( !myAISShape && theNeedToBuild ) 
+  {
     CurveCreator_Curve* aCurve = (CurveCreator_Curve*)this;
     aCurve->constructAISObject();
   }