]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
BUG 8930: Crash on opening animation several times
authorvsv <vsv@opencascade.com>
Tue, 31 May 2005 11:03:52 +0000 (11:03 +0000)
committervsv <vsv@opencascade.com>
Tue, 31 May 2005 11:03:52 +0000 (11:03 +0000)
src/VISU_I/VISU_TimeAnimation.cxx
src/VISU_I/VISU_TimeAnimation.h

index 2d6644490d1ebdb93ecc0752d33bc6190ff8b36b..e46fce49062f742ee962a41c29aed568cea052fa 100644 (file)
@@ -32,7 +32,8 @@ using namespace std;
 
 //************************************************************************
 VISU_TimeAnimation::VISU_TimeAnimation(SALOMEDS::Study_ptr theStudy, VISU::View3D_ptr theView3D) {
-  myStudy = theStudy;
+  //  myStudy = theStudy;
+  myStudy = SALOMEDS::Study::_duplicate(theStudy);
   myIsActive = false;
   myFrame = 0;
   mySpeed = 1;
@@ -52,7 +53,8 @@ VISU_TimeAnimation::VISU_TimeAnimation(SALOMEDS::Study_ptr theStudy, VISU::View3
   myLastError = "";
   myCycling = false;
 
-  myAnimSObject = SALOMEDS::SObject::_nil();
+  myAnimEntry = "";
+  //myAnimSObject = SALOMEDS::SObject::_nil();
 }
 
 
@@ -566,11 +568,8 @@ QString VISU_TimeAnimation::GenerateName()
 SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy()
 {
   if (myStudy->GetProperties()->IsLocked())
-    return myAnimSObject;
+    return SALOMEDS::SObject::_nil();
 
-  if (!myAnimSObject->_is_nil()) {
-    myAnimSObject = SALOMEDS::SObject::_nil();
-  }
   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
   aStudyBuilder->NewCommand();  // There is a transaction
   SALOMEDS::SComponent_var aSComponent = VISU::FindOrCreateVisuComponent(myStudy);
@@ -580,11 +579,12 @@ SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy()
   aComment.sprintf("myComment=ANIMATION;myType=%d;myMinVal=%g;myMaxVal=%g",VISU::TANIMATION,myMinVal,myMaxVal);
   
   string anEntry = VISU::CreateAttributes(myStudy,aSComponentEntry.in(),"","", GenerateName(),"",aComment,true);
-  myAnimSObject = myStudy->FindObjectID(anEntry.c_str());
+  myAnimEntry = anEntry.c_str();
+  SALOMEDS::SObject_var aAnimSObject = myStudy->FindObjectID(anEntry.c_str());
   
   for (int i = 0; i < getNbFields(); i++) {
     FieldData& aData = myFieldsLst[i];
-    SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(myAnimSObject);
+    SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(aAnimSObject);
     aStudyBuilder->Addreference(newObj, aData.myField);
     if (!aData.myPrs.empty()) {
       ostringstream strOut;
@@ -594,14 +594,18 @@ SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy()
     }
   }
   aStudyBuilder->CommitCommand();
-  return myAnimSObject;
+  return aAnimSObject._retn();
 }
   
 //************************************************************************
 void  VISU_TimeAnimation::saveAnimation()
 {
-  if (myStudy->GetProperties()->IsLocked())  return ;
-  if (myAnimSObject->_is_nil()) return;
+  if (myStudy->GetProperties()->IsLocked())  return;
+  //  if (myAnimSObject->_is_nil()) return;
+  if (myAnimEntry.isEmpty()) return;
+
+  SALOMEDS::SObject_var aAnimSObject = myStudy->FindObjectID(myAnimEntry);
+  if (aAnimSObject->_is_nil()) return;
 
   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
   aStudyBuilder->NewCommand();  // There is a transaction
@@ -612,11 +616,11 @@ void  VISU_TimeAnimation::saveAnimation()
   aComment.sprintf("myComment=ANIMATION;myType=%d;myMinVal=%g;myMaxVal=%g",VISU::TANIMATION,myMinVal,myMaxVal);
 
   SALOMEDS::GenericAttribute_var anAttr;
-  anAttr = aStudyBuilder->FindOrCreateAttribute(myAnimSObject, "AttributeComment");
+  anAttr = aStudyBuilder->FindOrCreateAttribute(aAnimSObject, "AttributeComment");
   SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
   aCmnt->SetValue(aComment);
   
-  SALOMEDS::ChildIterator_var anIter = myStudy->NewChildIterator(myAnimSObject);
+  SALOMEDS::ChildIterator_var anIter = myStudy->NewChildIterator(aAnimSObject);
   int i;
   for (i = 0, anIter->Init(); anIter->More(); anIter->Next(), i++) {
     SALOMEDS::SObject_var aRefObj = anIter->Value();
@@ -638,16 +642,17 @@ void  VISU_TimeAnimation::saveAnimation()
     SALOMEDS::AttributeName_var aPrsName = SALOMEDS::AttributeName::_narrow(anAttr);
     aPrsName->SetValue(aData.myPrs[0]->GetComment());
   }
+  aStudyBuilder->CommitCommand();
 }
 
 //************************************************************************
 void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField)
 {
-  myAnimSObject = SALOMEDS::SObject::_duplicate(theField);
+  SALOMEDS::SObject_var aAnimSObject = SALOMEDS::SObject::_duplicate(theField);
 
   VISU::Storable::TRestoringMap aMap;
   SALOMEDS::GenericAttribute_var anAttr;
-  if (!myAnimSObject->FindAttribute(anAttr, "AttributeComment")) return;
+  if (!aAnimSObject->FindAttribute(anAttr, "AttributeComment")) return;
 
   SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
   string aComm = aComment->Value();
@@ -658,7 +663,7 @@ void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField)
   myMinVal = VISU::Storable::FindValue(aMap,"myMinVal",&isExist).toDouble();
   myMaxVal = VISU::Storable::FindValue(aMap,"myMaxVal",&isExist).toDouble();
   
-  SALOMEDS::ChildIterator_var anIter = myStudy->NewChildIterator(myAnimSObject);
+  SALOMEDS::ChildIterator_var anIter = myStudy->NewChildIterator(aAnimSObject);
   for (anIter->Init(); anIter->More(); anIter->Next()) {
     SALOMEDS::SObject_var aRefObj = anIter->Value();
     SALOMEDS::SObject_var aFieldObj;
@@ -666,6 +671,7 @@ void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField)
     addField(aFieldObj);
     FieldData& aData = getFieldData(getNbFields()-1);
 
+    // Get Presentation object
     SALOMEDS::ChildIterator_var anPrsIter = myStudy->NewChildIterator(aRefObj);
     anPrsIter->Init();
     if (!anPrsIter->More()) continue;
@@ -704,7 +710,9 @@ void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField)
       aData.myPrs[i]->SameAs(aData.myPrs[0]);     
     }
   }
-    
+  CORBA::String_var aEntry = aAnimSObject->GetID();
+  string aStr(aEntry);
+  myAnimEntry = aStr.c_str();
 }
 
 
index df37ab63ab13af8a138da03fcfd5862cd0a76d61..c1eb9b35c91a2643f55fd0dcd78f7f03a63b67ae 100644 (file)
@@ -106,7 +106,7 @@ class VISU_TimeAnimation: public QObject, public QThread
   SALOMEDS::SObject_ptr publishInStudy();
   void restoreFromStudy(SALOMEDS::SObject_ptr theField);
   void saveAnimation();
-  bool isSavedInStudy() const { return !myAnimSObject->_is_nil(); }
+  bool isSavedInStudy() const { return !myAnimEntry.isEmpty(); }
 
  public slots:
   void setProportionalSlot(bool theProp) { myProportional = theProp; }
@@ -136,7 +136,8 @@ class VISU_TimeAnimation: public QObject, public QThread
   QString myDumpPath;
   VTKViewer_ViewFrame* myView;
 
-  SALOMEDS::SObject_var myAnimSObject;
+  //  SALOMEDS::SObject_var myAnimSObject;
+  QString myAnimEntry;
 
   static int myNBAnimations;
 };