]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Added possibility to restore Animations
authorsrn <srn@opencascade.com>
Mon, 12 Feb 2007 14:50:38 +0000 (14:50 +0000)
committersrn <srn@opencascade.com>
Mon, 12 Feb 2007 14:50:38 +0000 (14:50 +0000)
src/VISU_I/VISU_DumpPython.cc

index 0806825c6b5e51c3842a33bef13bee7c4a67325a..9b5af88c38a9e0c695034d81e513d6c696443f9d 100644 (file)
@@ -1311,6 +1311,92 @@ namespace VISU
     }
   }
 
+  //===========================================================================
+  void
+  DumpAnimationsToPython(SALOMEDS::Study_ptr theStudy,
+                        CORBA::Boolean theIsPublished,
+                        CORBA::Boolean& theIsValidScript,
+                        SALOMEDS::SObject_ptr theSObject,
+                        std::ostream& theStr,
+                        std::string thePrefix)
+  {
+
+    if(!theIsPublished) return;
+
+    SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
+    for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
+      SALOMEDS::SObject_var aSObject = aChildItet->Value();
+          
+      SALOMEDS::GenericAttribute_var anAttr;
+      if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
+      
+      SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
+      QString value (aStringAttr->Value());
+      if(value.isEmpty()) continue;
+
+      VISU::Storable::TRestoringMap aMap;
+      VISU::Storable::StrToMap(value, aMap);
+      bool isExist;
+      
+      QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
+      if(!isExist || aTypeName != "ANIMATION") continue;
+
+      //ANIMATION
+      theStr<<endl;
+      QString animName = aSObject->GetName();
+      theStr<<thePrefix<<"#Animation: "<<animName<<endl;
+      theStr<<endl;
+      theStr<<thePrefix<<"animSO = aBuilder.NewObject(aSComponent)"<<endl;
+      theStr<<thePrefix<<"aBuilder.SetName(animSO, '"<<animName<<"')"<< endl;
+      theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(animSO, 'AttributeString')"<< endl;
+      theStr<<thePrefix<<"strAttr.SetValue('"<<value<<"')"<< endl;
+
+
+    
+      SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
+      for (anIter->Init(); anIter->More(); anIter->Next()) {
+       SALOMEDS::SObject_var anObj = anIter->Value();
+
+       //FIELD
+       theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(animSO)"<<endl;
+       if (anObj->FindAttribute(anAttr, "AttributeString")) {
+         aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
+         theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
+         theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
+       }
+       
+       SALOMEDS::SObject_var refObj;
+       if(anObj->ReferencedObject(refObj)) {
+         SALOMEDS::SObject_var father = refObj->GetFather();
+         value = refObj->GetName();
+         QString path(theStudy->GetObjectPath(father));
+         //The following code requierd as a field name can contain '/' character
+         theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,getSObjectByFatherPathAndName(theStudy,'"<<path<<"','"<<value<<"'))"<<endl;
+       }
+       value = anObj->GetName();
+       if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value<<"')"<< endl;
+
+       //SCALARMAP,...
+       SALOMEDS::ChildIterator_var aSubIter = theStudy->NewChildIterator(anObj);
+       for (aSubIter->Init(); aSubIter->More(); aSubIter->Next()) {
+         SALOMEDS::SObject_var aSubObj = aSubIter->Value();
+         
+         theStr<<thePrefix<<"subSO = aBuilder.NewObject(fieldSO)"<<endl;
+         value = aSubObj->GetName();
+         if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(subSO, '"<<value<<"')"<< endl;
+         if (aSubObj->FindAttribute(anAttr, "AttributeString")) {
+           aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
+           theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(subSO, 'AttributeString')"<< endl;
+           theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
+         }
+       }
+
+      }
+      
+    }
+
+    theStr<<endl;
+  }
 
   //===========================================================================
   Engines::TMPFile*
@@ -1354,6 +1440,7 @@ namespace VISU
     SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
     VISU::DumpChildrenToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aName2EntryMap,aEntry2NameMap,"",aPrefix);
     VISU::DumpContainersToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aName2EntryMap,aEntry2NameMap,"",aPrefix);
+    VISU::DumpAnimationsToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aPrefix);
 
     //Output the script that sets up the visul parameters.
     if(theIsPublished) {
@@ -1365,6 +1452,26 @@ namespace VISU
     }
 
     aStr<<aPrefix<<"pass"<<endl;
+
+    if(theIsPublished) { //SRN: define function for Animation
+
+      //Define a function that find a SObject by its father's path and its name
+      aStr<<endl;
+      aStr<<endl;
+
+      aStr<<"def getSObjectByFatherPathAndName(theStudy, thePath, theName):"<<endl;
+      aStr<<aPrefix<<"father = theStudy.FindObjectByPath(thePath)"<<endl;
+      aStr<<aPrefix<<"itr = theStudy.NewChildIterator(father)"<<endl;
+      aStr<<aPrefix<<"while itr.More():"<<endl;
+      aStr<<aPrefix<<aPrefix<<"so = itr.Value()"<<endl;
+      aStr<<aPrefix<<aPrefix<<"if so.GetName()==theName: return so"<<endl;
+      aStr<<aPrefix<<aPrefix<<"itr.Next()"<<endl;
+      aStr<<aPrefix<<aPrefix<<"pass"<<endl;
+      aStr<<aPrefix<<"return None"<<endl;
+
+      aStr<<endl;
+    }
+
     // theIsValidScript currently is not used by internal dump methods (DumpChildrenToPython(), etc.)
     // If the situation changes, then the following line should be removed, and theIsValidScript
     // should be set properly by those internal methods