Salome HOME
patch for crash
[modules/geom.git] / src / CurveCreator / CurveCreator_Curve.cxx
index fb59efdd09ede81cc6cadca409cf0a33f0c46c38..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
 #include <TopoDS_Face.hxx>
 #include <TopoDS_Wire.hxx>
 
+#include <Prs3d_PointAspect.hxx>
+#include <iostream>
+#define DEBTRACE(msg) {std::cerr<<std::flush<<__FILE__<<" ["<<__LINE__<<"] : "<<msg<<std::endl<<std::flush;}
+
 #include <stdio.h>
 
 //=======================================================================
@@ -52,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)
 {
 }
 
@@ -88,7 +96,7 @@ std::string CurveCreator_Curve::getUniqSectionName() const
         std::string aName(aBuffer);
         int j;
         for( j = 0 ; j < mySections.size() ; j++ ){
-            aSection = getSection( j );
+            aSection = (CurveCreator_Section*)getSection( j );
             if ( aSection && aSection->myName == aName )
               break;
         }
@@ -245,12 +253,16 @@ void CurveCreator_Curve::getCoordinates( int theISection, int theIPoint, double&
   }
 }
 
-void CurveCreator_Curve::redisplayCurve()
+void CurveCreator_Curve::redisplayCurve(bool preEraseAllObjects)
 {
-  if( myDisplayer ) {
-    myDisplayer->eraseAll( false );
+  //DEBTRACE("redisplayCurve");
+  if( myDisplayer ) 
+  {
+    if (preEraseAllObjects)
+      myDisplayer->eraseAll( false );
+    else
+      myDisplayer->erase( myAISShape, false);
     myAISShape = NULL;
-
     myDisplayer->display( getAISObject( true ), true );
   }
 }
@@ -263,7 +275,7 @@ bool CurveCreator_Curve::moveSectionInternal(const int theISection,
   int aMovedSectionId = theISection >= 0 ? theISection : mySections.size()-1;
 
   if (aMovedSectionId != theNewIndex) {
-    CurveCreator_Section* aSection = getSection( aMovedSectionId );
+    CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( aMovedSectionId );
 
     // Remove section
     CurveCreator::Sections::iterator anIter = mySections.begin() + aMovedSectionId;
@@ -352,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.
@@ -362,7 +378,7 @@ bool CurveCreator_Curve::clearInternal()
 
   CurveCreator_Section* aSection;
   for (; i < aNbSections; i++) {
-    aSection = getSection( i );
+    aSection = (CurveCreator_Section*)getSection( i );
     if ( aSection )
       delete aSection;
   }
@@ -389,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 )
 {
@@ -397,7 +430,8 @@ bool CurveCreator_Curve::joinInternal( const std::list<int>& theSections )
     return res;
 
   int anISectionMain = theSections.front();
-  CurveCreator_Section* aSectionMain = getSection( anISectionMain );
+  CurveCreator_Section* aSectionMain =
+    (CurveCreator_Section*)getSection( anISectionMain );
 
   std::list <int> aSectionsToJoin = theSections;
   aSectionsToJoin.erase( aSectionsToJoin.begin() ); // skip the main section
@@ -408,7 +442,7 @@ bool CurveCreator_Curve::joinInternal( const std::list<int>& theSections )
   std::list<int>::const_iterator anIt = aSectionsToJoin.begin(), aLast = aSectionsToJoin.end();
   CurveCreator_Section* aSection;
   for (; anIt != aLast; anIt++) {
-    aSection = getSection( *anIt );
+    aSection = (CurveCreator_Section*)getSection( *anIt );
     aSectionMain->myPoints.insert(aSectionMain->myPoints.end(), aSection->myPoints.begin(),
                                   aSection->myPoints.end());
     res = removeSectionInternal(*anIt);
@@ -416,7 +450,7 @@ bool CurveCreator_Curve::joinInternal( const std::list<int>& theSections )
       break;
   }
 
-  redisplayCurve();
+  redisplayCurve(false);
   return res;
 }
 
@@ -459,7 +493,7 @@ int CurveCreator_Curve::addSectionInternal
   aSection->myIsClosed = theIsClosed;
   aSection->myPoints   = thePoints;
   mySections.push_back(aSection);
-  redisplayCurve();
+  redisplayCurve(false);
   return mySections.size()-1;
 }
 
@@ -519,7 +553,7 @@ bool CurveCreator_Curve::removeSectionInternal( const int theISection )
     delete *anIterRm;
     mySections.erase(anIterRm);
   }
-  redisplayCurve();
+  redisplayCurve(false);
   return true;
 }
   
@@ -552,12 +586,12 @@ int CurveCreator_Curve::getNbPoints( const int theISection ) const
     const int aNbSections = getNbSections();
 
     for (; i < aNbSections; i++) {
-      aSection = getSection( i );
+      aSection = (CurveCreator_Section*)getSection( i );
       if ( aSection )
         aNbCoords += aSection->myPoints.size();
     }
   } else {
-    aSection = getSection( theISection );
+    aSection = (CurveCreator_Section*)getSection( theISection );
     if ( aSection )
       aNbCoords = aSection->myPoints.size();
   }
@@ -592,7 +626,8 @@ void CurveCreator_Curve::saveCoordDiff( const SectionToPointCoordsList &theOldCo
 //! Get "closed" flag of the specified section
 bool CurveCreator_Curve::isClosed( const int theISection ) const
 {
-  CurveCreator_Section* aSection = getSection( theISection );
+  const CurveCreator_Section* aSection =
+    (CurveCreator_Section*)getSection( theISection );
   return aSection ? aSection->myIsClosed : false;
 }
 
@@ -606,17 +641,17 @@ bool CurveCreator_Curve::setClosedInternal( const int theISection,
     int i;
 
     for (i = 0; i < aSize; i++) {
-      aSection = getSection( i );
+      aSection = (CurveCreator_Section*)getSection( i );
       if( aSection ) {
         aSection->myIsClosed = theIsClosed;
-        redisplayCurve();
+        redisplayCurve(false);
       }
     }
   } else {
-    aSection = getSection( theISection );
+    aSection = (CurveCreator_Section*)getSection( theISection );
     if ( aSection ) {
       aSection->myIsClosed = theIsClosed;
-      redisplayCurve();
+      redisplayCurve(false);
     }
   }
   return true;
@@ -644,7 +679,7 @@ bool CurveCreator_Curve::setClosed( const int theISection,
 //! Returns specified section name
 std::string CurveCreator_Curve::getSectionName( const int theISection ) const
 {
-  CurveCreator_Section* aSection = getSection( theISection );
+  CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
   return aSection ? aSection->myName : "";
 }
 
@@ -653,7 +688,7 @@ bool CurveCreator_Curve::setSectionNameInternal( const int theISection,
                                                  const std::string& theName )
 {
   bool res = false;
-  CurveCreator_Section* aSection = getSection( theISection );
+  CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
   if( aSection ) {
     aSection->myName = theName;
     res = true;
@@ -681,7 +716,7 @@ bool CurveCreator_Curve::setSectionName( const int theISection,
 CurveCreator::SectionType CurveCreator_Curve::getSectionType
   ( const int theISection ) const
 {
-  CurveCreator_Section* aSection = getSection( theISection );
+  CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
   return aSection ? aSection->myType : CurveCreator::Polyline;
 }
 
@@ -695,16 +730,16 @@ bool CurveCreator_Curve::setSectionTypeInternal( const int theISection,
     const int aNbSections = getNbSections();
 
     for (; i < aNbSections; i++) {
-      aSection = getSection( i );
+      aSection = (CurveCreator_Section*)getSection( i );
       if ( aSection )
         aSection->myType = theType;
     }
-    redisplayCurve();
+    redisplayCurve(false);
   } else {
-    aSection = getSection( theISection );
+    aSection = (CurveCreator_Section*)getSection( theISection );
     if ( aSection && aSection->myType != theType ){
       aSection->myType = theType;
-      redisplayCurve();
+      redisplayCurve(false);
     }
   }
   return true;
@@ -744,7 +779,7 @@ bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &the
   CurveCreator_Section *aSection = 0;
   for ( ; anIt != theSectionsMap.end(); anIt++ ) {
     int anISection = anIt->first;
-    aSection = getSection( anISection );
+    aSection = (CurveCreator_Section*)getSection( anISection );
     if( aSection ) {
       CurveCreator::PosPointsList aSectionPoints = anIt->second;
       CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
@@ -765,7 +800,7 @@ bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &the
     }
   }
   if(res)
-    redisplayCurve();
+    redisplayCurve(false);
   return res;
 }
 
@@ -777,6 +812,7 @@ bool CurveCreator_Curve::addPoints( const CurveCreator::Coordinates& theCoords,
                                     const int theISection,
                                     const int theIPnt )
 {
+  //DEBTRACE("addPoints");
   bool res = false;
   CurveCreator::Coordinates aCoords = theCoords;
   // Set the difference.
@@ -808,7 +844,7 @@ bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theS
   CurveCreator_Section *aSection = 0;
   for ( ; anIt != theSectionsMap.end(); anIt++ ) {
     int anISection = anIt->first;
-    aSection = getSection( anISection );
+    aSection = (CurveCreator_Section*)getSection( anISection );
     if( aSection ) { 
       CurveCreator::PosPointsList aSectionPoints = anIt->second;
       CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
@@ -822,7 +858,7 @@ bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theS
     }
   }
   if(res)
-    redisplayCurve();
+    redisplayCurve(false);
   
   return res;
 }
@@ -832,6 +868,7 @@ bool CurveCreator_Curve::setPoint( const int theISection,
                                    const int theIPnt,
                                    const CurveCreator::Coordinates& theNewCoords )
 {
+  //DEBTRACE("setPoint");
   bool res = false;
   // Set the difference.
   startOperation();
@@ -860,6 +897,7 @@ bool CurveCreator_Curve::setPoint( const int theISection,
 bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords,
                                            const bool theIsToSaveDiff )
 {
+  //DEBTRACE("setSeveralPoints");
   bool res = false;
   // Set the difference.
   startOperation();
@@ -904,7 +942,7 @@ bool CurveCreator_Curve::removePointsInternal( const SectionToPointList &thePoin
     aRes = removeSectionPoints(aSectionId, anIt->second);
   }
   if( aRes)
-    redisplayCurve();
+    redisplayCurve(false);
 
   return aRes;
 }
@@ -948,7 +986,8 @@ bool CurveCreator_Curve::removeSeveralPoints( const SectionToPointList &theSecti
 CurveCreator::Coordinates CurveCreator_Curve::getPoint( const int theISection,
                                                         const int theIPnt) const
 {
-  CurveCreator_Section* aSection = getSection( theISection );
+  //DEBTRACE("getPoint");
+  CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
   CurveCreator::Coordinates::const_iterator
     anIter = aSection->myPoints.begin() + toICoord(theIPnt);
   CurveCreator::Coordinates aResult(anIter, anIter + myDimension);
@@ -960,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
 {
-  CurveCreator_Section* aSection = getSection( theISection );
+  CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
   return aSection ? aSection->myPoints : CurveCreator::Coordinates();
 }
 
-void CurveCreator_Curve::constructAISObject()
+Handle(TColgp_HArray1OfPnt) CurveCreator_Curve::GetDifferentPoints( int theISection ) const
 {
-  TopoDS_Shape aShape;
-  CurveCreator_Utils::constructShape( this, aShape );
-
-  myAISShape = new AIS_Shape( aShape );
+  //DEBTRACE("getPoints");
+  CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
+  return aSection ? aSection->GetDifferentPoints( (int)myDimension ) : Handle(TColgp_HArray1OfPnt)();
 }
 
-CurveCreator_Section* CurveCreator_Curve::getSection( const int theSectionId ) const
+void CurveCreator_Curve::constructAISObject()
 {
-  CurveCreator_Section *aSection = 0;
-  if ( theSectionId >= 0 && theSectionId < mySections.size() )
-    aSection = mySections.at( theSectionId );
-
-  return aSection;
+  //DEBTRACE("constructAISObject");
+  TopoDS_Shape aShape;
+  CurveCreator_Utils::constructShape( this, 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(myPointAspectColor);
+  myAISShape->Attributes()->SetPointAspect( anAspect );
 }
 
 Handle(AIS_InteractiveObject) CurveCreator_Curve::getAISObject( const bool theNeedToBuild ) const
 {
-  if ( !myAISShape && theNeedToBuild ) {
+  //DEBTRACE("getAISObject");
+  if ( !myAISShape && theNeedToBuild ) 
+  {
     CurveCreator_Curve* aCurve = (CurveCreator_Curve*)this;
     aCurve->constructAISObject();
   }
@@ -997,7 +1043,7 @@ bool CurveCreator_Curve::removeSectionPoints( const int theSectionId,
 {
   bool aRes = false;
 
-  CurveCreator_Section* aSection = getSection( theSectionId );
+  CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theSectionId );
   if ( !aSection )
     return aRes;