Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/visu.git] / src / VISUGUI / VisuGUI_ScalarMapOnDeformedShapeDlg.cxx
index ccb1c5737824a1ab136e4e6811ed7e57ab10e5f0..54f79c9ccc9e21590de8f949197f8242fa0fc6ae 100644 (file)
 //  Module : VISU
 
 #include "VisuGUI_ScalarMapOnDeformedShapeDlg.h"
+
 #include "VisuGUI_Tools.h"
+
 #include "VISU_Result_i.hh"
 #include "VISU_ScalarMapOnDeformedShape_i.hh"
+
+#include "VISU_ScalarMapPL.hxx"
 #include "VISU_ScalarMapOnDeformedShapePL.hxx"
+
+#include "VISU_Convertor.hxx"
+
 #include "SalomeApp_Module.h"
 #include "LightApp_SelectionMgr.h"
 #include "SUIT_Desktop.h"
-#include "VISU_ScalarMapPL.hxx"
 
 #include "SALOME_ListIO.hxx"
 
-#include "VISU_Convertor.hxx"
-
 #include "SALOMEDSClient_AttributeComment.hxx"
 #include "SALOMEDSClient_AttributeName.hxx"
 
@@ -55,6 +59,7 @@ using namespace std;
 VisuGUI_ScalarMapOnDeformedShapeDlg::VisuGUI_ScalarMapOnDeformedShapeDlg (SalomeApp_Module* theModule)
     : QDialog(VISU::GetDesktop(theModule), "VisuGUI_ScalarMapOnDeformedShapeDlg", false,
               WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
+      myIsAnimation(false),
       myVisuGUI(theModule)
 {
   myPrs = NULL;
@@ -94,14 +99,14 @@ VisuGUI_ScalarMapOnDeformedShapeDlg::VisuGUI_ScalarMapOnDeformedShapeDlg (Salome
 
   TopGroupLayout->addWidget(FieldLabel, 1, 0);
   TopGroupLayout->addWidget(myFieldsCombo,1,1);
-  
+
   // TimeStamps combo box
   QLabel* TimeStampLabel = new QLabel (tr("TIMESTAMP_ITEM"), TopGroup, "TimeStampLabel");
   myTimeStampsCombo = new QComboBox (TopGroup,"TimeStamp");
 
   TopGroupLayout->addWidget(TimeStampLabel, 2, 0);
   TopGroupLayout->addWidget(myTimeStampsCombo,2,1);
-  
+
   //
   aTabBox->addTab(aBox, tr("SCALAR_MAP_ON_DEFORMED_SHAPE_TAB"));
 
@@ -143,23 +148,24 @@ VisuGUI_ScalarMapOnDeformedShapeDlg::VisuGUI_ScalarMapOnDeformedShapeDlg (Salome
   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
   connect(myFieldsCombo,     SIGNAL(activated(int)), this, SLOT(onFieldChanged(int)));
   connect(myTimeStampsCombo, SIGNAL(activated(int)), this, SLOT(onTimeStampChanged(int)));
-  
 }
 
-void VisuGUI_ScalarMapOnDeformedShapeDlg::initFromPrsObject (VISU::ScalarMapOnDeformedShape_i* thePrs,bool isAnim)
+void VisuGUI_ScalarMapOnDeformedShapeDlg::initFromPrsObject
+             (VISU::ScalarMapOnDeformedShape_i* thePrs, bool isAnim)
 {
+  myIsAnimation = isAnim;
   myPrs = thePrs;
 
-  setFactor(thePrs->GetScale());
+  setFactor(myPrs->GetScale());
   myTimeStampsCombo->setDisabled(isAnim);
-  
-  QString aFieldName(thePrs->GetScalarFieldName());
-  float aIterFloat = GetFloatValueOfTimeStamp(thePrs->GetMeshName().c_str(),
-                                             thePrs->GetScalarFieldName().c_str(),
-                                             thePrs->GetScalarIteration(),
-                                             thePrs->GetScalarEntity());
+
+  QString aFieldName(myPrs->GetScalarFieldName());
+  float aIterFloat = GetFloatValueOfTimeStamp(myPrs->GetMeshName().c_str(),
+                                             myPrs->GetScalarFieldName().c_str(),
+                                             myPrs->GetScalarIteration(),
+                                             myPrs->GetScalarEntity());
   QString aIteration(QString("%1").arg(aIterFloat));
-  
+
   if (myMeshFieldsTimes.size() == 0)
   {
     // find all fields and time stamps on it
@@ -171,67 +177,109 @@ void VisuGUI_ScalarMapOnDeformedShapeDlg::initFromPrsObject (VISU::ScalarMapOnDe
       Handle(SALOME_InteractiveObject) aIO = selected.First();
       if (aIO->hasEntry()) {
        _PTR(SObject) aSObject = aActiveStudy->FindObjectID(aIO->getEntry());
+
+       _PTR(GenericAttribute) anTmpAttr;
+       if (aSObject->FindAttribute(anTmpAttr, "AttributeComment")) {
+         _PTR(AttributeComment) aTmpComment (anTmpAttr);
+         string aTmpComm = aTmpComment->Value();
+         QString aTmpstrIn (aTmpComm.c_str());
+         VISU::Storable::TRestoringMap aTmpaMap;
+         VISU::Storable::StrToMap(aTmpstrIn,aTmpaMap);
+         bool aTmpisExist;
+         VISU::VISUType aTmpType =
+            (VISU::VISUType)VISU::Storable::FindValue(aTmpaMap,"myType",&aTmpisExist).toInt();
+         switch(aTmpType){
+         case VISU::TTIMESTAMP:
+           {
+             aSObject = aSObject->GetFather();
+             aSObject = aSObject->GetFather();
+             break;
+           }
+         case VISU::TFIELD:
+           {
+             _PTR(SObject) newSObject;
+             if(aSObject->ReferencedObject(newSObject)) aSObject = newSObject;
+             aSObject = aSObject->GetFather();
+             break;
+           }
+         case VISU::TANIMATION:
+           {
+             _PTR(ChildIterator) aTmpIter = aActiveStudy->NewChildIterator(aSObject);
+             for (aTmpIter->InitEx(true); aTmpIter->More(); aTmpIter->Next()) {
+               _PTR(SObject) aTmpChildSObj = aTmpIter->Value();
+               _PTR(SObject) newSObject;
+               if(aTmpChildSObj->ReferencedObject(newSObject)){
+                 aSObject = newSObject;
+                 aSObject->GetFather();
+                 break;
+               }
+             }
+             break;
+           }
+         }
+       }
+
        aSObject = aSObject->GetFather();
        aSObject = aSObject->GetFather();
-       aSObject = aSObject->GetFather();
-       aSObject = aSObject->GetFather();
+
        mySelectionObj = aSObject;
        CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
-       VISU::Result_var aResult;
        if (CORBA::is_nil(anObject)) {
          mySelectionObj = mySelectionObj->GetFather();
        }
-       _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj);
-       
-       for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
-         _PTR(SObject) aChildSObj = aIter->Value();
-         CORBA::Object_var aChildObject = VISU::ClientSObjectToObject(aChildSObj);
-         
-         _PTR(GenericAttribute) anAttr;
-         if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
-           _PTR(AttributeComment) aComment (anAttr);
-           string aComm = aComment->Value();
-           QString strIn (aComm.c_str());
-           VISU::Storable::TRestoringMap aMap;
-           VISU::Storable::StrToMap(strIn,aMap);
-           bool isExist;
-           VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
-           if (isExist) {
-             if ((aType == VISU::TTIMESTAMP)) {
-               _PTR(GenericAttribute) aNameAttr;
-               if (aChildSObj->FindAttribute(aNameAttr, "AttributeName")) {
-                 _PTR(AttributeName) aName (aNameAttr);
-                 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
-                 QString aMeshName  = VISU::getValue(aChildSObj,"myMeshName");
-                 if(QString(thePrs->GetMeshName().c_str()) != aMeshName) continue;
-                 myCurrMeshName = aMeshName;
-                 QString aFieldName = VISU::getValue(aChildSObj,"myFieldName");
-                 QString aTimeIter  = VISU::getValue(aChildSObj,"myTimeStampId");
-                 QString aEntity    = VISU::getValue(aChildSObj,"myEntityId");
-                 VISU::TEntity anEntity;
-                 switch(aEntity.toInt()){
-                 case 0: anEntity = VISU::NODE_ENTITY; break;
-                 case 1: anEntity = VISU::EDGE_ENTITY; break;
-                 case 2: anEntity = VISU::FACE_ENTITY; break;
-                 case 3: anEntity = VISU::CELL_ENTITY; break;
-                 }
-                 TFT &aFieldsMap = myMeshFieldsTimes[aMeshName.latin1()];
-                 TFE aKey(aFieldName.latin1(),anEntity);
-                 aFieldsMap[aKey][aTimeIter.toInt()] = 
-                   GetFloatValueOfTimeStamp(myPrs->GetMeshName().c_str(),
-                                            aFieldName.latin1(),
-                                            aTimeIter.toInt(),
-                                            anEntity);
-               }
-             }
-           }
-         }
-       }
       }
     }
-    
-    AddAllFieldNames();
 
+    if (mySelectionObj) {
+      _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj);
+
+      for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
+        _PTR(SObject) aChildSObj = aIter->Value();
+        CORBA::Object_var aChildObject = VISU::ClientSObjectToObject(aChildSObj);
+
+        _PTR(GenericAttribute) anAttr;
+        if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
+          _PTR(AttributeComment) aComment (anAttr);
+          string aComm = aComment->Value();
+          QString strIn (aComm.c_str());
+          VISU::Storable::TRestoringMap aMap;
+          VISU::Storable::StrToMap(strIn,aMap);
+          bool isExist;
+          VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
+          if (isExist) {
+            if ((aType == VISU::TTIMESTAMP)) {
+              _PTR(GenericAttribute) aNameAttr;
+              if (aChildSObj->FindAttribute(aNameAttr, "AttributeName")) {
+                _PTR(AttributeName) aName (aNameAttr);
+                VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
+                QString aMeshName = VISU::getValue(aChildSObj, "myMeshName");
+                if (QString(myPrs->GetMeshName().c_str()) != aMeshName) continue;
+                myCurrMeshName = aMeshName;
+                QString aFieldName = VISU::getValue(aChildSObj, "myFieldName");
+                QString aTimeIter  = VISU::getValue(aChildSObj, "myTimeStampId");
+                QString aEntity    = VISU::getValue(aChildSObj, "myEntityId");
+                VISU::TEntity anEntity;
+                switch (aEntity.toInt()) {
+                case 0: anEntity = VISU::NODE_ENTITY; break;
+                case 1: anEntity = VISU::EDGE_ENTITY; break;
+                case 2: anEntity = VISU::FACE_ENTITY; break;
+                case 3: anEntity = VISU::CELL_ENTITY; break;
+                }
+                TFT &aFieldsMap = myMeshFieldsTimes[aMeshName.latin1()];
+                TFE aKey (aFieldName.latin1(), anEntity);
+                aFieldsMap[aKey][aTimeIter.toInt()] = 
+                  GetFloatValueOfTimeStamp(myPrs->GetMeshName().c_str(),
+                                           aFieldName.latin1(),
+                                           aTimeIter.toInt(),
+                                           anEntity);
+              }
+            }
+          }
+        }
+      }
+    }
+
+    AddAllFieldNames();
   }
   myFieldsCombo->setCurrentText(aFieldName);
   AddAllTimes(myFieldsCombo->currentText());
@@ -241,21 +289,28 @@ void VisuGUI_ScalarMapOnDeformedShapeDlg::initFromPrsObject (VISU::ScalarMapOnDe
   myScalarPane->initFromPrsObject(myPrs);
 }
 
-int VisuGUI_ScalarMapOnDeformedShapeDlg::storeToPrsObject(VISU::ScalarMapOnDeformedShape_i* thePrs, bool theUpdateScalar) {
-
+int VisuGUI_ScalarMapOnDeformedShapeDlg::storeToPrsObject
+            (VISU::ScalarMapOnDeformedShape_i* thePrs, bool theUpdateScalars, int theIter)
+{
   thePrs->SetScale(getFactor());
-  
-  thePrs->SetScalarField(myPrs->GetScalarMeshName().c_str(),
-                        myPrs->GetScalarFieldName().c_str(),
-                        myPrs->GetScalarIteration(),
-                        myPrs->GetScalarEntity());
 
-  if (theUpdateScalar) SetScalarField();
+  if (myIsAnimation)
+    thePrs->SetScalarField(myPrs->GetScalarMeshName().c_str(),
+                          getCurrentScalarFieldName().latin1(),
+                          theIter,
+                          myPrs->GetScalarEntity());
+  else
+    thePrs->SetScalarField(myPrs->GetScalarMeshName().c_str(),
+                          getCurrentScalarFieldName().latin1(),
+                          myTimeStampsCombo->currentItem() + 1,
+                          myPrs->GetScalarEntity());
+
+  if (theUpdateScalars) SetScalarField();
 
   thePrs->ShowColored(true);
 
   myScalarPane->storeToPrsObject(thePrs);
-  
+
   myPrs = thePrs;
 
   return 1;
@@ -304,7 +359,7 @@ void VisuGUI_ScalarMapOnDeformedShapeDlg::SetScalarField(int theIter,QString the
                        aFieldName.latin1(),
                        theIter,
                        anEntity);
-  
+
   myScalarPane->storeToPrsObject(myPrs);
   
   UpdateScalarField();