Salome HOME
Update the names of Regions and Zones if case name changed (Bug #110).
[modules/hydro.git] / src / HYDROData / HYDROData_IPolyline.cxx
index 20fe2099ea3e0d96f04f8cf927a3ac8707ecde4b..00f7a04a0479222525be537c568cbc55d8a59b94 100755 (executable)
@@ -1,15 +1,20 @@
 
 #include "HYDROData_IPolyline.h"
 
-#include <gp_XY.hxx>
+#include "HYDROData_Document.h"
 
+#include <TDataStd_BooleanList.hxx>
+#include <TDataStd_ExtStringList.hxx>
+#include <TDataStd_Integer.hxx>
+#include <TDataStd_IntegerList.hxx>
 #include <TDataStd_RealList.hxx>
 
 IMPLEMENT_STANDARD_HANDLE(HYDROData_IPolyline, HYDROData_Entity)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_IPolyline, HYDROData_Entity)
 
 HYDROData_IPolyline::HYDROData_IPolyline()
-: HYDROData_Entity()
+: HYDROData_Entity(),
+  myIsOperation( false )
 {
 }
 
@@ -17,9 +22,198 @@ HYDROData_IPolyline::~HYDROData_IPolyline()
 {
 }
 
-int HYDROData_IPolyline::NbPoints( const int theSectionIndex ) const
+int HYDROData_IPolyline::getNbUndo() const
 {
-  return GetPoints( theSectionIndex ).Length();
+  return getNbOperations();
+}
+
+bool HYDROData_IPolyline::undo()
+{
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if ( aDocument.IsNull() )
+    return false;
+
+  if ( getNbUndo() < 1 )
+    return false;
+
+  aDocument->Undo();
+
+  int aNbUndoedOperations = getNbUndoedOperations();
+  setNbUndoedOperations( aNbUndoedOperations + 1 ); 
+
+  return true;
+}
+
+int HYDROData_IPolyline::getNbRedo() const
+{
+  return getNbUndoedOperations();
+}
+
+bool HYDROData_IPolyline::redo()
+{
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if ( aDocument.IsNull() )
+    return false;
+
+  if ( getNbRedo() < 1 )
+    return false;
+
+  aDocument->Redo();
+
+  int aNbUndoedOperations = getNbUndoedOperations();
+  setNbUndoedOperations( aNbUndoedOperations - 1 ); 
+
+  return true;
+}
+
+CurveCreator::Dimension HYDROData_IPolyline::getDimension() const
+{
+  return CurveCreator::Dim2d;
+}
+
+CurveCreator::Coordinates HYDROData_IPolyline::getPoint( const int theISection, 
+                                                         const int theIPnt ) const
+{
+  CurveCreator::Coordinates aResPoint;
+  if ( theISection < 0 || theIPnt < 0 )
+    return aResPoint;
+
+  CurveCreator::Coordinates aSectPoints = getPoints( theISection );
+  if ( theIPnt >= aSectPoints.size() )
+    return aResPoint;
+
+  CurveCreator::Coordinates::reverse_iterator anIt = aSectPoints.rbegin();
+
+  aResPoint.push_back( *anIt++ );
+  aResPoint.push_back( *anIt );
+
+  return aResPoint;
+}
+
+
+int HYDROData_IPolyline::getNbPoints( const int theSectionIndex ) const
+{
+  return getPoints( theSectionIndex ).size();
+}
+
+void HYDROData_IPolyline::startOperation()
+{
+  if ( myIsOperation )
+    return;
+
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if ( aDocument.IsNull() )
+    return;
+  
+  aDocument->StartOperation();
+  
+  myIsOperation = true;
+}
+
+void HYDROData_IPolyline::commitOperation()
+{
+  if ( !myIsOperation )
+    return;
+
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if ( aDocument.IsNull() )
+    return;
+
+  int aNbOperations = getNbOperations();
+  setNbOperations( aNbOperations + 1 ); 
+
+  aDocument->CommitOperation();
+
+  myIsOperation = false;
+}
+
+void HYDROData_IPolyline::abortOperation()
+{
+  if ( !myIsOperation )
+    return;
+
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if ( aDocument.IsNull() )
+    return;
+
+  aDocument->AbortOperation();
+
+  myIsOperation = false;
+}
+
+void HYDROData_IPolyline::setNbOperations( const int theNb )
+{
+  TDF_Label anOpLabel = myLab.FindChild( DataTag_Operations ).FindChild( OperationsTag_Commited );
+  TDataStd_Integer::Set( anOpLabel, theNb );
+}
+
+int HYDROData_IPolyline::getNbOperations() const
+{
+  TDF_Label aLabel = myLab.FindChild( DataTag_Operations, false );
+  if ( aLabel.IsNull() )
+    return 0;
+
+  TDF_Label anOpLabel = aLabel.FindChild( OperationsTag_Commited, false );
+  if ( anOpLabel.IsNull() )
+    return 0;
+
+  Handle(TDataStd_Integer) anOpCount;
+  if ( !anOpLabel.FindAttribute( TDataStd_Integer::GetID(), anOpCount ) )
+    return 0;
+
+  return anOpCount->Get();
+}
+
+void HYDROData_IPolyline::setNbUndoedOperations( const int theNb )
+{
+  TDF_Label anUndoedLabel = myLab.FindChild( DataTag_Operations ).FindChild( OperationsTag_Undoed );
+  TDataStd_Integer::Set( anUndoedLabel, theNb );
+}
+
+int HYDROData_IPolyline::getNbUndoedOperations() const
+{
+  TDF_Label aLabel = myLab.FindChild( DataTag_Operations, false );
+  if ( aLabel.IsNull() )
+    return 0;
+
+  TDF_Label anUndoedLabel = aLabel.FindChild( OperationsTag_Undoed, false );
+  if ( anUndoedLabel.IsNull() )
+    return 0;
+
+  Handle(TDataStd_Integer) anUndoedCount;
+  if ( !anUndoedLabel.FindAttribute( TDataStd_Integer::GetID(), anUndoedCount ) )
+    return 0;
+
+  return anUndoedCount->Get();
+}
+
+void HYDROData_IPolyline::getSectionsLists( Handle(TDataStd_ExtStringList)& theNamesList,
+                                            Handle(TDataStd_IntegerList)&   theTypesList,
+                                            Handle(TDataStd_BooleanList)&   theClosuresList,
+                                            const bool                      theIsCreate ) const
+{
+  TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, theIsCreate );
+  if ( aSectsLabel.IsNull() )
+    return;
+
+  Handle(TDataStd_ExtStringList) aNamesList;
+  if ( !aSectsLabel.FindAttribute( TDataStd_ExtStringList::GetID(), aNamesList ) && theIsCreate )
+    aNamesList = TDataStd_ExtStringList::Set( aSectsLabel );
+
+  Handle(TDataStd_IntegerList) aTypesList;
+  if ( !aSectsLabel.FindAttribute( TDataStd_IntegerList::GetID(), aTypesList ) && theIsCreate )
+    aTypesList = TDataStd_IntegerList::Set( aSectsLabel );
+
+  Handle(TDataStd_BooleanList) aClosuresList;
+  if ( !aSectsLabel.FindAttribute( TDataStd_BooleanList::GetID(), aClosuresList ) && theIsCreate )
+    aClosuresList = TDataStd_BooleanList::Set( aSectsLabel );
+}
+
+void HYDROData_IPolyline::removeSectionsLists()
+{
+  TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, false );
+  if ( !aSectsLabel.IsNull() )
+    aSectsLabel.ForgetAllAttributes();
 }
 
 void HYDROData_IPolyline::getPointsLists( const int                  theSectionIndex,
@@ -53,13 +247,20 @@ void HYDROData_IPolyline::getPointsLists( const int                  theSectionI
   }
 }
 
-void HYDROData_IPolyline::removePointsLists( const int theSectionIndex ) const
+void HYDROData_IPolyline::removePointsLists( const int theSectionIndex )
 {
   TDF_Label aLabel = myLab.FindChild( DataTag_Points, false );
   if ( aLabel.IsNull() )
     return;
 
-  TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
-  if ( !aSectLabel.IsNull() )
-    aSectLabel.ForgetAllAttributes();
+  if ( theSectionIndex == -1 )
+  {
+    aLabel.ForgetAllAttributes();
+  }
+  else
+  {
+    TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
+    if ( !aSectLabel.IsNull() )
+      aSectLabel.ForgetAllAttributes();
+  }
 }