Salome HOME
merge BR_v14_rc
[modules/hydro.git] / src / HYDROData / HYDROData_Entity.cxx
index ac0c59620697b369915318c24728f6f98c711215..6af65981490a2ba5209ed69b0759fd83fc892cec 100644 (file)
@@ -41,7 +41,7 @@
 #define _DEVDEBUG_
 #include "HYDRO_trace.hxx"
 
-static const Standard_GUID GUID_MUST_BE_UPDATED("80f2bb81-3873-4631-8ddd-940d2119f000");
+//static const Standard_GUID GUID_MUST_BE_UPDATED("80f2bb81-3873-4631-8ddd-940d2119f000");
 
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Entity,MMgt_TShared)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Entity,MMgt_TShared)
@@ -85,7 +85,7 @@ QStringList HYDROData_Entity::DumpToPython( MapOfTreatedObjects& theTreatedObjec
 
 void HYDROData_Entity::Update()
 {
-  SetToUpdate( false );
+  ClearChanged();
 }
 
 void HYDROData_Entity::UpdateLocalCS( double theDx, double theDy )
@@ -115,31 +115,59 @@ QVariant HYDROData_Entity::GetDataVariant()
   return QVariant();
 }
 
-void HYDROData_Entity::SetToUpdate( bool theFlag )
+void HYDROData_Entity::ClearChanged()
 {
-  if ( IsMustBeUpdated() == theFlag )
+  TDataStd_Integer::Set( myLab.FindChild( DataTag_GeomChange ), 0 );
+}
+
+int HYDROData_Entity::GetGeomChangeFlag() const
+{
+  int aGeomChangeFlag = 0;
+  Handle(TDataStd_Integer) aGeomChangeAttr;
+  TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange );
+  aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr );
+  if ( !aGeomChangeAttr.IsNull() )
+    aGeomChangeFlag = aGeomChangeAttr->Get();
+  return aGeomChangeFlag;
+}
+
+void HYDROData_Entity::Changed( Geometry theChangedGeometry )
+{
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if( aDocument.IsNull() )
     return;
 
-  if ( theFlag )
-  {
-    TDataStd_UAttribute::Set( myLab, GUID_MUST_BE_UPDATED );
+  int aGeomChangeFlag = 0;
+  Handle(TDataStd_Integer) aGeomChangeAttr;
+  TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange );
+  aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr );
+  if ( !aGeomChangeAttr.IsNull() )
+    aGeomChangeFlag = aGeomChangeAttr->Get();
+
+  int aBitsToChange = ( myGeom & theChangedGeometry );
+  if( aBitsToChange == 0 )
+    return;
 
-    Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
-    if ( !aDocument.IsNull() )
+  aGeomChangeFlag = ( aGeomChangeFlag | aBitsToChange );
+  TDataStd_Integer::Set( aGeomChangeLab, aGeomChangeFlag );
+
+  HYDROData_Iterator anIter( aDocument );
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    Handle(HYDROData_Entity) anObject = anIter.Current();
+    HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects();
+    for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i )
     {
-      // Change the states of this and all depended objects
-      HYDROData_Tool::SetMustBeUpdatedObjects( aDocument );
+      Handle(HYDROData_Entity) aRefObject = aRefSeq.Value( i );
+      if( aRefObject->Label()==myLab )
+        anObject->Changed( theChangedGeometry );
     }
   }
-  else
-  {
-    myLab.ForgetAttribute( GUID_MUST_BE_UPDATED );
-  }
 }
 
-bool HYDROData_Entity::IsMustBeUpdated() const
+bool HYDROData_Entity::IsMustBeUpdated( Geometry theGeom ) const
 {
-  return myLab.IsAttribute( GUID_MUST_BE_UPDATED );
+  return ( ( GetGeomChangeFlag() & theGeom ) != 0 );
 }
 
 bool HYDROData_Entity::CanBeUpdated() const
@@ -162,7 +190,8 @@ bool HYDROData_Entity::CanRemove()
   return true;
 }
 
-HYDROData_Entity::HYDROData_Entity()
+HYDROData_Entity::HYDROData_Entity( Geometry theGeom )
+  : myGeom( theGeom )
 {
 }
 
@@ -170,7 +199,8 @@ HYDROData_Entity::~HYDROData_Entity()
 {
 }
 
-void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination ) const
+void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination,
+                               bool isGenerateNewName ) const
 {
   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
   if ( aDocument.IsNull() ) {
@@ -180,23 +210,26 @@ void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination )
   TDF_CopyLabel aCopy(myLab, theDestination->Label());
   aCopy.Perform();
          
-  // generate a new unique name for the clone object:
-  // case 1: Image_1 -> Image_2
-  // case 2: ImageObj -> ImageObj_1
-  QString aName = theDestination->GetName();
-  QString aPrefix = aName;
-  if( aName.contains( '_' ) ) { // case 1
-    QString aSuffix = aName.section( '_', -1 );
-    bool anIsInteger = false;
-    aSuffix.toInt( &anIsInteger );
-    if( anIsInteger )
-      aPrefix = aName.section( '_', 0, -2 );
-  } else { // case 2
-    aPrefix = aName;
-  }
+  if( isGenerateNewName )
+  {
+    // generate a new unique name for the clone object:
+    // case 1: Image_1 -> Image_2
+    // case 2: ImageObj -> ImageObj_1
+    QString aName = theDestination->GetName();
+    QString aPrefix = aName;
+    if( aName.contains( '_' ) ) { // case 1
+      QString aSuffix = aName.section( '_', -1 );
+      bool anIsInteger = false;
+      aSuffix.toInt( &anIsInteger );
+      if( anIsInteger )
+        aPrefix = aName.section( '_', 0, -2 );
+    } else { // case 2
+      aPrefix = aName;
+    }
 
-  aName = HYDROData_Tool::GenerateObjectName( aDocument, aPrefix );
-  theDestination->SetName( aName );
+    aName = HYDROData_Tool::GenerateObjectName( aDocument, aPrefix );
+    theDestination->SetName( aName );
+  }
 }
 
 Handle(HYDROData_Entity) HYDROData_Entity::GetFatherObject() const