]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Publish in study for animation
authorvsv <vsv@opencascade.com>
Tue, 17 May 2005 09:15:23 +0000 (09:15 +0000)
committervsv <vsv@opencascade.com>
Tue, 17 May 2005 09:15:23 +0000 (09:15 +0000)
idl/VISU_Gen.idl
src/VISUGUI/VisuGUI.cxx
src/VISUGUI/VisuGUI.h
src/VISUGUI/VisuGUI_TimeAnimation.cxx
src/VISUGUI/VisuGUI_TimeAnimation.h
src/VISU_I/VISU_Prs3d_i.cc
src/VISU_I/VISU_TimeAnimation.cxx
src/VISU_I/VISU_TimeAnimation.h

index 46c1e0f04f28fb5cbf311b7015d8f8864897385b..c8421de0d7cd380bc22ac802ad363a95b49720e0 100644 (file)
@@ -70,6 +70,7 @@ can be applied on different presentations.
                  TGROUP, /*!< A group of families */
                  TFIELD, /*!< Field represents the results of calculations (it can be scalar or vector values), grouped together under one physical concept. */
                  TTIMESTAMP, /*!<Time stamp represents a subfield: the results of calculations are taken in one definite moment. */
+                 TANIMATION, /*!< Represents Animation object. */
                   TALL
                  };
 
@@ -1056,6 +1057,15 @@ the animation will be generated on the basis of all time stamps contained in the
 \param theCycle If this boolean parameter is True, playback of your animation will be set as cycling.
 */
     void setCycling(in boolean theCycle);
+
+
+    SALOMEDS::SObject publishInStudy();
+
+    void saveAnimation();
+
+    void restoreFromStudy(in SALOMEDS::SObject theSObj);
+
+    boolean isSavedInStudy();
   };
 
   /*!
index f1077b27dc1f2b8c4dcdf632049a3a7d2de74794..199bedbf5cfe566dbc75df0f72c649617c240719 100644 (file)
@@ -2392,8 +2392,10 @@ void VisuGUI::Sweep() {
 
 
 
+//************************************************************************
 void VisuGUI::TimeAnimation() {
-  VisuGUI_TimeAnimationDlg* aAnimationDlg = new VisuGUI_TimeAnimationDlg(GetStudyDocument());
+  //  VisuGUI_TimeAnimationDlg* aAnimationDlg = new VisuGUI_TimeAnimationDlg(GetStudyDocument());
+  VisuGUI_TimeAnimationDlg* aAnimationDlg = new VisuGUI_TimeAnimationDlg(GetActiveStudy());
   SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
   
   bool isDefined = false;
@@ -2419,7 +2421,33 @@ void VisuGUI::TimeAnimation() {
   else delete aAnimationDlg;
 }
 
+//************************************************************************
+void VisuGUI::ShowAnimation()
+{
+  SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
+  if ( Sel->IObjectCount() != 1 )
+    return;
+  SALOMEDS::SObject_var aSObj = GetStudyDocument()->FindObjectID( Sel->firstIObject()->getEntry() );
+  if( aSObj->_is_nil() ) return;
+
+  VISU::Storable::TRestoringMap aMap;
+  SALOMEDS::GenericAttribute_var anAttr;
+  if (!aSObj->FindAttribute(anAttr, "AttributeComment")) return;
 
+  SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
+  string aComm = aComment->Value();
+  QString strIn(aComm.c_str());
+  VISU::Storable::StrToMap(strIn,aMap);
+  bool isExist;
+  VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
+  if (aType != VISU::TANIMATION) return;
+
+  VisuGUI_TimeAnimationDlg* aAnimationDlg = new VisuGUI_TimeAnimationDlg(GetActiveStudy());
+  aAnimationDlg->restoreFromStudy(aSObj);
+  aAnimationDlg->show();
+}
+
+//************************************************************************
 void VisuGUI::ImportMedField() {
   if (checkLock(GetStudyDocument())) return;
   SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() );
@@ -2951,7 +2979,7 @@ bool VisuGUI::CustomPopup (QAD_Desktop* parent, QPopupMenu* thePopup, const QStr
       case VISU::TRESULT:
        if (!aIsLocked) thePopup->insertItem("Delete", visuGUI, SLOT(DeleteObject()));
        break;
-       
+
       case VISU::TTABLE:
        if (!aIsLocked) thePopup->insertItem( "Rename...", visuGUI, SLOT( RenameTable() ) );
        thePopup->insertItem( "Show Table",    visuGUI, SLOT( ShowTable() ) );
@@ -3181,6 +3209,11 @@ bool VisuGUI::CustomPopup (QAD_Desktop* parent, QPopupMenu* thePopup, const QStr
       VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
       if(isExist){
        switch (aType) {
+       case VISU::TANIMATION:
+         thePopup->insertItem("Show..", visuGUI, SLOT(ShowAnimation()));
+         if ( !aIsLocked ) thePopup->insertItem("Delete", visuGUI, SLOT(DeleteObject()));
+         break;
+       
        case VISU::TENTITY:
        case VISU::TFAMILY:
        case VISU::TGROUP: 
index dad1adddaad97340683e3cb934498fa2418cdfa3..e4fb4591519b87ec7dd17d1d59edf5f56f522e72 100644 (file)
@@ -273,6 +273,7 @@ public slots:
   void ClippingPlanes();
   void Sweep();
   void TimeAnimation();
+  void ShowAnimation();
   
   void ImportMedField();
   //void ImportMedMesh();
index 3c5b9ebfb977bb3f8040a4910ef69db1f6e90994..00f0d8dacfdb00f9ca9412d1f0599151a01fbc23 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "VisuGUI_TimeAnimation.h"
 #include "VisuGUI.h"
+#include "QAD_Study.h"
 
 #include <qlayout.h>
 #include <qhbox.h>
@@ -768,15 +769,16 @@ static const char * pauseIco[] = {
 static QPixmap MYpausePixmap(pauseIco);
 
 
-VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg(SALOMEDS::Study_var theStudy
+VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg(QAD_Study* theStudyFrame
   : QDialog( QAD_Application::getDesktop(), "VisuGUI_TimeAnimationDlg", false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose)
 {
   setCaption("Animation");
   setSizeGripEnabled( TRUE );
-  myStudy = theStudy;
+  myStudyFrame = theStudyFrame;
+  myStudy = myStudyFrame->getStudyDocument();
   isClosing = false;
 
-  myAnimator = new VISU_TimeAnimation(theStudy);
+  myAnimator = new VISU_TimeAnimation(myStudy);
   myAnimator->setSpeed(1);
   myAnimator->setViewer(VisuGUI::GetVtkViewFrame());
   connect( myAnimator, SIGNAL( frameChanged(long, double) ), 
@@ -914,6 +916,19 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg(SALOMEDS::Study_var theStudy)
 
   aMainLayout->addWidget(myPlayFrame);
 
+  QHBox* aPublishBox = new QHBox(this);
+  aPublishBox->setSpacing(5);
+
+  myPublishBtn = new QPushButton("Publish to study", aPublishBox);
+  connect(myPublishBtn, SIGNAL(clicked()), this, SLOT(publishToStudy()));
+
+  mySaveBtn = new QPushButton("Save Animation", aPublishBox);
+  mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
+  connect(mySaveBtn, SIGNAL(clicked()), this, SLOT(saveToStudy()));
+
+  aMainLayout->addWidget(aPublishBox);
+
+
   QHBox* aBtnBox = new QHBox(this);
   QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout()); 
   aBtnLayout->addStretch();
@@ -1100,3 +1115,25 @@ void VisuGUI_TimeAnimationDlg::onStop() {
     myGenBtn->setEnabled(true);
   }
 }
+
+//************************************************************************
+void VisuGUI_TimeAnimationDlg::saveToStudy() 
+{
+  myAnimator->saveAnimation();
+  myStudyFrame->updateObjBrowser( true );
+}
+
+//************************************************************************
+void VisuGUI_TimeAnimationDlg::publishToStudy()
+{
+  myAnimator->publishInStudy();
+  myStudyFrame->updateObjBrowser( true );
+  mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
+}
+
+//************************************************************************
+void VisuGUI_TimeAnimationDlg::restoreFromStudy(SALOMEDS::SObject_var theAnimation)
+{
+  myAnimator->restoreFromStudy(theAnimation);
+  mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
+}
index 6d5a9c5a7a222b530973e10018ccfc905b072664..e4083657dc6da7890f1e9e3022c23364d553c35d 100644 (file)
@@ -27,6 +27,7 @@
 
 class VISU_TimeAnimation;
 class VTKViewer_ViewFrame;
+class QAD_Study;
 
 /**
  * Auxilliary class for presentations definition
@@ -112,12 +113,14 @@ class VisuGUI_TimeAnimationDlg: public QDialog
 { 
     Q_OBJECT
  public:
-    VisuGUI_TimeAnimationDlg(SALOMEDS::Study_var theStudy);
+    VisuGUI_TimeAnimationDlg(QAD_Study* theStudyFrame);
     ~VisuGUI_TimeAnimationDlg();
 
     void addField(SALOMEDS::SObject_var theField);
     void clearView();
 
+    void restoreFromStudy(SALOMEDS::SObject_var theAnimation);
+
  protected:
     virtual void closeEvent(QCloseEvent* theEvent);
     void stopAnimation();
@@ -136,6 +139,8 @@ class VisuGUI_TimeAnimationDlg: public QDialog
    void onExecution(long theNewFrame, double theTime);
    void onBrowse();
    void onStop();
+   void saveToStudy();
+   void publishToStudy();
 
  private:
     QSlider* mySlider;
@@ -148,11 +153,15 @@ class VisuGUI_TimeAnimationDlg: public QDialog
 
     QFrame* myPlayFrame;
     SALOMEDS::Study_var myStudy;
+    QAD_Study* myStudyFrame;
 
     VISU_TimeAnimation* myAnimator;
     QCheckBox* mySaveCheck;
     QLineEdit* myPathEdit;
     bool isClosing;
     QCloseEvent* myEvent;
+
+    QPushButton* myPublishBtn;
+    QPushButton* mySaveBtn;
 };
 #endif  //VISUGUI_TIMEANIMATION_H
index 97028bcfa704d32448fd30578187374fa6c89d54..2711fb599ffc60465408d2b4503863477e20fa28 100644 (file)
@@ -102,11 +102,17 @@ void VISU::Prs3d_i::UpdateActor(VISU_Actor* theActor) {
 VISU::Storable* VISU::Prs3d_i::Restore(const Storable::TRestoringMap& theMap)
 {
   myName = VISU::Storable::FindValue(theMap,"myName").latin1();
+  myOffset[0] = VISU::Storable::FindValue(theMap,"myOffset[0]").toFloat();
+  myOffset[1] = VISU::Storable::FindValue(theMap,"myOffset[1]").toFloat();
+  myOffset[2] = VISU::Storable::FindValue(theMap,"myOffset[2]").toFloat();
   return this;
 }
 
 void VISU::Prs3d_i::ToStream(std::ostringstream& theStr){
   Storable::DataToStream( theStr, "myName",   myName.c_str() );
+  Storable::DataToStream( theStr, "myOffset[0]", myOffset[0] );
+  Storable::DataToStream( theStr, "myOffset[1]", myOffset[1] );
+  Storable::DataToStream( theStr, "myOffset[2]", myOffset[2] );
 }
 
 void VISU::Prs3d_i::Update() {
index c827743e3a9a7b3dd237ab7c55668186aa7a7164..2d6644490d1ebdb93ecc0752d33bc6190ff8b36b 100644 (file)
@@ -51,6 +51,8 @@ VISU_TimeAnimation::VISU_TimeAnimation(SALOMEDS::Study_ptr theStudy, VISU::View3
   myTimeMax = 0;
   myLastError = "";
   myCycling = false;
+
+  myAnimSObject = SALOMEDS::SObject::_nil();
 }
 
 
@@ -553,7 +555,161 @@ void VISU_TimeAnimation::setSpeed(CORBA::Long theSpeed) {
   mySpeed = (theSpeed<1)? 1 : theSpeed; 
 }
 
+//************************************************************************
+int VISU_TimeAnimation::myNBAnimations = 0;
+QString VISU_TimeAnimation::GenerateName()
+{
+  return VISU::GenerateName("Animation", myNBAnimations++);
+}
+
+//************************************************************************
+SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy()
+{
+  if (myStudy->GetProperties()->IsLocked())
+    return myAnimSObject;
+
+  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);
+  CORBA::String_var aSComponentEntry = aSComponent->GetID();
+  
+  QString aComment;
+  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());
+  
+  for (int i = 0; i < getNbFields(); i++) {
+    FieldData& aData = myFieldsLst[i];
+    SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(myAnimSObject);
+    aStudyBuilder->Addreference(newObj, aData.myField);
+    if (!aData.myPrs.empty()) {
+      ostringstream strOut;
+      aData.myPrs[0]->ToStream(strOut);
+      string aPrsComment = strOut.str();
+      VISU::CreateAttributes(myStudy, newObj->GetID(),"","", aData.myPrs[0]->GetComment(),"",aPrsComment.c_str(),true);
+    }
+  }
+  aStudyBuilder->CommitCommand();
+  return myAnimSObject;
+}
+  
+//************************************************************************
+void  VISU_TimeAnimation::saveAnimation()
+{
+  if (myStudy->GetProperties()->IsLocked())  return ;
+  if (myAnimSObject->_is_nil()) return;
+
+  SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
+  aStudyBuilder->NewCommand();  // There is a transaction
+  SALOMEDS::SComponent_var aSComponent = VISU::FindOrCreateVisuComponent(myStudy);
+  CORBA::String_var aSComponentEntry = aSComponent->GetID();
+
+  QString aComment;
+  aComment.sprintf("myComment=ANIMATION;myType=%d;myMinVal=%g;myMaxVal=%g",VISU::TANIMATION,myMinVal,myMaxVal);
+
+  SALOMEDS::GenericAttribute_var anAttr;
+  anAttr = aStudyBuilder->FindOrCreateAttribute(myAnimSObject, "AttributeComment");
+  SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
+  aCmnt->SetValue(aComment);
+  
+  SALOMEDS::ChildIterator_var anIter = myStudy->NewChildIterator(myAnimSObject);
+  int i;
+  for (i = 0, anIter->Init(); anIter->More(); anIter->Next(), i++) {
+    SALOMEDS::SObject_var aRefObj = anIter->Value();
+    SALOMEDS::ChildIterator_var anPrsIter = myStudy->NewChildIterator(aRefObj);
+    anPrsIter->Init();
+    if (!anPrsIter->More()) continue;
+    FieldData& aData = myFieldsLst[i];
+    if (aData.myPrs.empty()) continue;
+
+    SALOMEDS::SObject_var aPrsObj = anPrsIter->Value();
+    ostringstream strOut;
+    aData.myPrs[0]->ToStream(strOut);
+    string aPrsComment = strOut.str();
+    anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeComment");
+    aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
+    aCmnt->SetValue(aPrsComment.c_str());
+
+    anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeName");
+    SALOMEDS::AttributeName_var aPrsName = SALOMEDS::AttributeName::_narrow(anAttr);
+    aPrsName->SetValue(aData.myPrs[0]->GetComment());
+  }
+}
+
+//************************************************************************
+void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField)
+{
+  myAnimSObject = SALOMEDS::SObject::_duplicate(theField);
+
+  VISU::Storable::TRestoringMap aMap;
+  SALOMEDS::GenericAttribute_var anAttr;
+  if (!myAnimSObject->FindAttribute(anAttr, "AttributeComment")) return;
+
+  SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
+  string aComm = aComment->Value();
+  QString strIn(aComm.c_str());
+  VISU::Storable::StrToMap(strIn,aMap);
+  bool isExist;
+
+  myMinVal = VISU::Storable::FindValue(aMap,"myMinVal",&isExist).toDouble();
+  myMaxVal = VISU::Storable::FindValue(aMap,"myMaxVal",&isExist).toDouble();
+  
+  SALOMEDS::ChildIterator_var anIter = myStudy->NewChildIterator(myAnimSObject);
+  for (anIter->Init(); anIter->More(); anIter->Next()) {
+    SALOMEDS::SObject_var aRefObj = anIter->Value();
+    SALOMEDS::SObject_var aFieldObj;
+    if (!aRefObj->ReferencedObject(aFieldObj) ) continue;
+    addField(aFieldObj);
+    FieldData& aData = getFieldData(getNbFields()-1);
+
+    SALOMEDS::ChildIterator_var anPrsIter = myStudy->NewChildIterator(aRefObj);
+    anPrsIter->Init();
+    if (!anPrsIter->More()) continue;
+    SALOMEDS::SObject_var aPrsObj = anPrsIter->Value();
+    if (!aPrsObj->FindAttribute(anAttr, "AttributeName")) continue;
+    SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
+    string aStr = aName->Value();
+    QString strName(aStr.c_str());
+
+    if (strName == VISU::ScalarMap_i::myComment.c_str())
+      aData.myPrsType = VISU::TSCALARMAP;
+    else if (strName == VISU::IsoSurfaces_i::myComment.c_str())
+      aData.myPrsType = VISU::TISOSURFACE;
+    else if (strName == VISU::CutPlanes_i::myComment.c_str())
+      aData.myPrsType = VISU::TCUTPLANES;
+    else if (strName == VISU::DeformedShape_i::myComment.c_str())
+      aData.myPrsType = VISU::TDEFORMEDSHAPE;
+    else if (strName == VISU::Vectors_i::myComment.c_str())
+      aData.myPrsType = VISU::TVECTORS;
+    else if (strName == VISU::StreamLines_i::myComment.c_str())
+      aData.myPrsType = VISU::TSTREAMLINES;
+    else
+      continue;
+    generatePresentations(getNbFields()-1);
+
+    if (!aPrsObj->FindAttribute(anAttr, "AttributeComment")) return;
+    SALOMEDS::AttributeComment_var aPrsComment = SALOMEDS::AttributeComment::_narrow(anAttr);
+    string aPrsComm = aPrsComment->Value();
+    QString strPrsIn(aPrsComm.c_str());
+    VISU::Storable::TRestoringMap aPrsMap;
+    VISU::Storable::StrToMap(strPrsIn,aPrsMap);
+    
+    aData.myPrs[0]->Restore(aPrsMap);
+    aData.myPrs[0]->GetOffset(aData.myOffset);
+    for (int i = 1; i < aData.myNbFrames; i++) {
+      aData.myPrs[i]->SameAs(aData.myPrs[0]);     
+    }
+  }
+    
+}
+
 
+//========================================================================
+//========================================================================
 //========================================================================
 VISU_TimeAnimation_i::VISU_TimeAnimation_i(SALOMEDS::Study_ptr theStudy, VISU::View3D_ptr theView3D){
   myAnim = new VISU_TimeAnimation(theStudy,theView3D);
@@ -720,3 +876,22 @@ void VISU_TimeAnimation_i::setCycling(CORBA::Boolean theCycle){
 }
 
 
+SALOMEDS::SObject_ptr VISU_TimeAnimation_i::publishInStudy()
+{
+  return myAnim->publishInStudy();
+}
+
+void VISU_TimeAnimation_i::restoreFromStudy(SALOMEDS::SObject_ptr theObj)
+{
+  myAnim->restoreFromStudy(theObj);
+}
+  
+CORBA::Boolean VISU_TimeAnimation_i::isSavedInStudy()
+{
+  return myAnim->isSavedInStudy();
+}
+  
+void VISU_TimeAnimation_i::saveAnimation()
+{
+  myAnim->saveAnimation();
+}
index 9cdb13b493b0b1366baa3c4931fee57f6351f752..df37ab63ab13af8a138da03fcfd5862cd0a76d61 100644 (file)
@@ -103,6 +103,11 @@ class VISU_TimeAnimation: public QObject, public QThread
   void setProportional(CORBA::Boolean theProp) { myProportional = theProp; }
   void setCycling(CORBA::Boolean theCycle) { myCycling = theCycle; }
 
+  SALOMEDS::SObject_ptr publishInStudy();
+  void restoreFromStudy(SALOMEDS::SObject_ptr theField);
+  void saveAnimation();
+  bool isSavedInStudy() const { return !myAnimSObject->_is_nil(); }
+
  public slots:
   void setProportionalSlot(bool theProp) { myProportional = theProp; }
   void setCyclingSlot(bool theCycle) { myCycling = theCycle; }
@@ -113,6 +118,7 @@ class VISU_TimeAnimation: public QObject, public QThread
 
  protected:
   void run();
+  QString GenerateName();
 
  private:
   QString myLastError;
@@ -129,6 +135,10 @@ class VISU_TimeAnimation: public QObject, public QThread
   double myTimeMin, myTimeMax;
   QString myDumpPath;
   VTKViewer_ViewFrame* myView;
+
+  SALOMEDS::SObject_var myAnimSObject;
+
+  static int myNBAnimations;
 };
 
 
@@ -188,6 +198,12 @@ public:
 
   virtual void setProportional(CORBA::Boolean theProp);
   virtual void setCycling(CORBA::Boolean theCycle);
+
+  virtual SALOMEDS::SObject_ptr publishInStudy();
+  virtual void restoreFromStudy(SALOMEDS::SObject_ptr theField);
+  virtual CORBA::Boolean isSavedInStudy();
+  virtual void saveAnimation();
+
 };