Salome HOME
Update Help for VISU module.
[modules/visu.git] / src / VISU_I / VISU_Result_i.cc
index 20594a77bea8b3af0f1266f16ea0980a77034413..167c412b8879e0d8dedb7e0edf1e0c40dd8f32f6 100644 (file)
@@ -32,8 +32,6 @@
 
 #include "SUIT_ResourceMgr.h"
 
-#include "SALOME_Event.hxx"
-
 #include "SALOMEDS_Tool.hxx"
 #include "HDFascii.hxx"
 
@@ -43,6 +41,7 @@
 
 // VTK Includes
 #include <vtkCell.h>
+#include <vtkUnstructuredGrid.h>
 
 // OCCT Includes
 #include <Bnd_Box.hxx>
@@ -67,7 +66,7 @@ VISU::Result_var VISU::FindResult (SALOMEDS::SObject_ptr theSObject)
     CORBA::Object_var anObject = VISU::SObjectToObject(aFather);
     if (!CORBA::is_nil(anObject)) {
       aResult = VISU::Result::_narrow(anObject);
-      if(!aResult->_is_nil()) return aResult;
+      if (!aResult->_is_nil()) return aResult;
     }
     aFather = aFather->GetFather();
     aFatherID = aFather->GetID();
@@ -115,7 +114,6 @@ void CreateReference (SALOMEDS::Study_ptr theStudyDocument,
 
 string GetComponentDataType (SALOMEDS::SObject_ptr theSObject)
 {
-  SALOMEDS::Study_var aStudy = theSObject->GetStudy();
   SALOMEDS::SComponent_var aCompRefSObj = theSObject->GetFatherComponent();
   CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
   return aDataType.in();
@@ -251,65 +249,68 @@ VISU::Storable*
 VISU::Result_i::
 Build(SALOMEDS::SObject_ptr theSObject)
 {
+  if(MYDEBUG) MESSAGE("Result_i::Build");
+
   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
   aStudyBuilder->NewCommand();  // There is a transaction
-  if(MYDEBUG) MESSAGE("Result_i::Build");
-  try{
+
+  try {
     const TMeshMap& aMeshMap = myInput->GetMeshMap();
-    if(aMeshMap.empty())
+    if (aMeshMap.empty())
       throw std::runtime_error("Build - There is no any mesh information in the file !!!");
+
     mySComponent = FindOrCreateVisuComponent(myStudyDocument);
     CORBA::String_var aSComponentEntry = mySComponent->GetID(), anIOR(GetID());
     string aRefFatherEntry = GetRefFatherEntry();
+
     QString aComment;
     aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
-                    GetComment(),
-                    VISU::TRESULT,
-                    myFileInfo.filePath().latin1(),
+                    GetComment(), VISU::TRESULT, myFileInfo.filePath().latin1(),
                     myInitFileName.c_str()); // Restoring of Python dump
     string aResultEntry =
-      CreateAttributes(myStudyDocument,
-                      aSComponentEntry,
-                      aRefFatherEntry.c_str(),
-                      anIOR,
-                      myName.c_str(),
-                      "",
-                      aComment.latin1(),
-                      true);
+      CreateAttributes(myStudyDocument, aSComponentEntry, aRefFatherEntry.c_str(),
+                      anIOR, myName.c_str(), "", aComment.latin1(), true);
+
     mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str());
-    if(mySObject->_is_nil()) throw std::runtime_error("Build - There is no SObject for the Result !!!");
-    if(!CORBA::is_nil(theSObject)){
+    if (mySObject->_is_nil())
+      throw std::runtime_error("Build - There is no SObject for the Result !!!");
+
+    if (!CORBA::is_nil(theSObject)) {
       CORBA::String_var aString = theSObject->GetID();
-      CreateReference(myStudyDocument,aResultEntry,aString.in());
+      CreateReference(myStudyDocument, aResultEntry, aString.in());
     }
+
     TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
-    for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
+    for (; aMeshMapIter != aMeshMap.end(); aMeshMapIter++) {
       const string& aMeshName = aMeshMapIter->first;
       const VISU::PMesh aMesh = aMeshMapIter->second;
-      const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
-      VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
       aComment.sprintf("myComment=MESH;myName=%s;myDim=%d",
-                      aMeshName.c_str(),aMesh->myDim);
-      string aMeshEntry = CreateAttributes(myStudyDocument,aResultEntry.c_str(),aRefFatherEntry.c_str(),
-                                          "",aMeshName.c_str(),"",aComment.latin1(),true);
-      if(aMeshOnEntityMap.empty()) continue;
-      aComment.sprintf("myComment=FAMILIES;myMeshName=%s",aMeshName.c_str());
-      string aSubMeshesEntry = CreateAttributes(myStudyDocument,aMeshEntry.c_str(),aRefFatherEntry.c_str(),
-                                               "","Families","",aComment.latin1(),true);
+                      aMeshName.c_str(), aMesh->myDim);
+      string aMeshEntry =
+       CreateAttributes(myStudyDocument, aResultEntry.c_str(), aRefFatherEntry.c_str(),
+                        "", aMeshName.c_str(), "", aComment.latin1(), true);
+
+      const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
+      if (aMeshOnEntityMap.empty()) continue;
+
+      aComment.sprintf("myComment=FAMILIES;myMeshName=%s", aMeshName.c_str());
+      string aSubMeshesEntry =
+       CreateAttributes(myStudyDocument, aMeshEntry.c_str(), aRefFatherEntry.c_str(),
+                        "", "Families", "", aComment.latin1(), true);
+
       //Import entities and according families
-      aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
       typedef std::map<std::string,std::string> TComment2EntryMap;
-      TComment2EntryMap aComment2EntryMap;
       typedef std::map<VISU::TEntity,std::string> TEntity2EntryMap;
+      TComment2EntryMap aComment2EntryMap;
       TEntity2EntryMap aEntity2EntryMap;
-      for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
+
+      VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
+      for (; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) {
        const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
        aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
-                        VISU::TENTITY,
-                        aMeshName.c_str(),
-                        anEntity);
+                        VISU::TENTITY, aMeshName.c_str(), anEntity);
        string anEntityName;
-       switch(anEntity){
+       switch (anEntity) {
        case VISU::NODE_ENTITY : anEntityName = "onNodes"; break;
        case VISU::EDGE_ENTITY : anEntityName = "onEdges"; break;
        case VISU::FACE_ENTITY : anEntityName = "onFaces"; break;
@@ -318,118 +319,105 @@ Build(SALOMEDS::SObject_ptr theSObject)
          throw std::runtime_error("Build >> Value of entity is incorrect!");
        }
        aEntity2EntryMap[anEntity] = CreateAttributes
-         (myStudyDocument,aSubMeshesEntry.c_str(),aRefFatherEntry.c_str(),
-          "",anEntityName.c_str(),"",aComment.latin1(),true);
+         (myStudyDocument, aSubMeshesEntry.c_str(), aRefFatherEntry.c_str(),
+          "", anEntityName.c_str(), "", aComment.latin1(), true);
+
        const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
        const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
        VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
-       for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
+       for (; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++) {
          const string& aFamilyName = aFamilyMapIter->first;
          aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
-                          VISU::TFAMILY,
-                          aMeshName.c_str(),
-                          anEntity,
-                          aFamilyName.c_str());
+                          VISU::TFAMILY, aMeshName.c_str(), anEntity, aFamilyName.c_str());
          aComment2EntryMap[aComment.latin1()] =
-           CreateAttributes(myStudyDocument,
-                            aEntity2EntryMap[anEntity].c_str(),
-                            aRefFatherEntry.c_str(),
-                            "",
-                            aFamilyName.c_str(),
-                            "",
-                            aComment.latin1(),
-                            true);
+           CreateAttributes(myStudyDocument, aEntity2EntryMap[anEntity].c_str(), aRefFatherEntry.c_str(),
+                            "", aFamilyName.c_str(), "", aComment.latin1(), true);
        }
       }
+
       //Importing groups
       const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
-      if(aGroupMap.size() > 0){
-       aComment.sprintf("myComment=GROUPS;myMeshName=%s",
-                        aMeshName.c_str());
+      if (aGroupMap.size() > 0) {
+       aComment.sprintf("myComment=GROUPS;myMeshName=%s", aMeshName.c_str());
        string aGroupsEntry =
-         CreateAttributes(myStudyDocument,
-                          aMeshEntry.c_str(),
-                          aRefFatherEntry.c_str(),
-                          "",
-                          "Groups",
-                          "",
-                          aComment.latin1(),
-                          true);
+         CreateAttributes(myStudyDocument, aMeshEntry.c_str(), aRefFatherEntry.c_str(),
+                          "", "Groups", "", aComment.latin1(), true);
+
        VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
-       for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
+       for (; aGroupMapIter != aGroupMap.end(); aGroupMapIter++) {
          const string& aGroupName = aGroupMapIter->first;
          aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
-                          VISU::TGROUP,aMeshName.c_str(),aGroupName.c_str());
-         string aGroupEntry = CreateAttributes(myStudyDocument,aGroupsEntry.c_str(),aRefFatherEntry.c_str(),
-                                               "",aGroupName.c_str(),"",aComment.latin1(),true);
+                          VISU::TGROUP, aMeshName.c_str(), aGroupName.c_str());
+         string aGroupEntry =
+           CreateAttributes(myStudyDocument, aGroupsEntry.c_str(), aRefFatherEntry.c_str(),
+                            "", aGroupName.c_str(), "", aComment.latin1(), true);
+
          const VISU::PGroup aGroup = aGroupMapIter->second;
          const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup->myFamilyAndEntitySet;
          VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = aFamilyAndEntitySet.begin();
-         for(; aFamilyAndEntitySetIter != aFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
+         for (; aFamilyAndEntitySetIter != aFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++) {
            const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter;
            const string& aFamilyName = aFamilyAndEntity.first;
            const VISU::TEntity& anEntity = aFamilyAndEntity.second;
            aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
-                            VISU::TFAMILY,
-                            aMeshName.c_str(),
-                            anEntity,
-                            aFamilyName.c_str());
-           CreateReference(myStudyDocument,aGroupEntry,aComment2EntryMap[aComment.latin1()]);
+                            VISU::TFAMILY, aMeshName.c_str(), anEntity, aFamilyName.c_str());
+           if (aComment2EntryMap.count(aComment.latin1()) > 0)
+             CreateReference(myStudyDocument, aGroupEntry, aComment2EntryMap[aComment.latin1()]);
          }
        }
       }
+
       //Import fields
       string aFieldsEntry;
       bool isFieldEntryCreated = 0;
       aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
-      for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
+      for (; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) {
        const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
        const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
        const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
        VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
-       for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
-         if(!isFieldEntryCreated){
-           aComment.sprintf("myComment=FIELDS;myMeshName=%s",
-                            aMeshName.c_str());
+       for (; aFieldMapIter != aFieldMap.end(); aFieldMapIter++) {
+         if (!isFieldEntryCreated) {
+           aComment.sprintf("myComment=FIELDS;myMeshName=%s", aMeshName.c_str());
            aFieldsEntry =
-             CreateAttributes(myStudyDocument,
-                              aMeshEntry.c_str(),
-                              aRefFatherEntry.c_str(),
-                              "",
-                              "Fields",
-                              "",
-                              aComment.latin1(),
-                              true);
+             CreateAttributes(myStudyDocument, aMeshEntry.c_str(), aRefFatherEntry.c_str(),
+                              "", "Fields", "", aComment.latin1(), true);
            isFieldEntryCreated = true;
          }
          const string& aFieldName = aFieldMapIter->first;
          const VISU::PField aField = aFieldMapIter->second;
          const VISU::TValField& aValField = aField->myValField;
          QString aFieldNameWithUnit = ::GenerateFieldName(aFieldName,aField->myUnitNames[0]);
-         aComment.sprintf("myComment=FIELD;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s;myNbTimeStamps=%d;myNumComponent=%d",
-                          VISU::TFIELD,aMeshName.c_str(),anEntity,aFieldName.c_str(),aValField.size(),aField->myNbComp);
-         string aFieldEntry = CreateAttributes(myStudyDocument,aFieldsEntry.c_str(),aRefFatherEntry.c_str(),
-                                               "",aFieldNameWithUnit.latin1(),"",aComment.latin1(),true);
-         CreateReference(myStudyDocument,aFieldEntry,aEntity2EntryMap[anEntity]);
+         aComment.sprintf("myComment=FIELD;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s;"
+                          "myNbTimeStamps=%d;myNumComponent=%d",
+                          VISU::TFIELD, aMeshName.c_str(), anEntity, aFieldName.c_str(),
+                          aValField.size(), aField->myNbComp);
+         string aFieldEntry =
+           CreateAttributes(myStudyDocument, aFieldsEntry.c_str(), aRefFatherEntry.c_str(),
+                            "", aFieldNameWithUnit.latin1(), "", aComment.latin1(), true);
+         CreateReference(myStudyDocument, aFieldEntry, aEntity2EntryMap[anEntity]);
+
          VISU::TValField::const_iterator aValFieldIter = aValField.begin();
-         for(; aValFieldIter != aValField.end(); aValFieldIter++){
+         for (; aValFieldIter != aValField.end(); aValFieldIter++) {
            int aTimeStamp = aValFieldIter->first;
            const VISU::PValForTime aValForTime = aValFieldIter->second;
-           aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
-                            VISU::TTIMESTAMP,aMeshName.c_str(),anEntity,aFieldName.c_str(),aTimeStamp,aField->myNbComp);
+           aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;"
+                            "myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
+                            VISU::TTIMESTAMP, aMeshName.c_str(), anEntity,
+                            aFieldName.c_str(), aTimeStamp, aField->myNbComp);
            string aTimeStampId = VISU_Convertor::GenerateName(aValForTime->myTime);
-           CreateAttributes(myStudyDocument,aFieldEntry.c_str(),aRefFatherEntry.c_str(),
-                            "",aTimeStampId.c_str(),"",aComment.latin1(),true);
+           CreateAttributes(myStudyDocument, aFieldEntry.c_str(), aRefFatherEntry.c_str(),
+                            "", aTimeStampId.c_str(), "", aComment.latin1(), true);
          }
        }
       }
     }
     bool isBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
-    if(isBuildAll) BuildAll();
-  }catch(std::exception& exc){
+    if (isBuildAll) BuildAll();
+  } catch(std::exception& exc) {
     INFOS("Follow exception was occured :\n"<<exc.what());
     return NULL;
-  }catch(...){
+  } catch(...) {
     INFOS("Unknown exception was occured!!!");
     return NULL;
   }
@@ -555,8 +543,15 @@ Restore(SALOMEDS::SObject_ptr theSObject,
       SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
       SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp);
       aStudyBuilder->LoadWith(aCompRefSObj, aDriver);
-      if (strcmp(aDataType,"MED") == 0)
-       myInput = CreateMEDConvertor(aTargetRefSObj);
+      if (strcmp(aDataType, "MED") == 0) {
+        // create field or MED converter
+        CORBA::Object_var aMedObject = VISU::SObjectToObject(aTargetRefSObj);
+        SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(aMedObject);
+        if(!CORBA::is_nil(aField))
+          myInput = CreateMEDFieldConvertor(aField);
+        else
+          myInput = CreateMEDConvertor(aTargetRefSObj);
+      }
       else
        throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!");
     } else {
@@ -623,7 +618,8 @@ Restore(SALOMEDS::SObject_ptr theSObject,
       aCmnt->SetValue(aComment.latin1());
     }
     bool isBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
-    if (isBuildAll) BuildAll();
+    if (isBuildAll)
+      BuildAll();
     return this;
   } catch(std::exception& exc) {
     INFOS("Follow exception was occured :\n"<<exc.what());
@@ -657,7 +653,7 @@ VISU::Result_i::Restore(SALOMEDS::SObject_ptr theSObject,
     aSourceId = eRestoredComponent;
 
   VISU::Result_i* pResult = new VISU::Result_i(aStudy,aSourceId,aCreationId);
-  if(pResult == NULL)
+  if (pResult == NULL)
     return NULL;
 
   return pResult->Restore(theSObject,theMap,thePrefix);
@@ -681,9 +677,10 @@ std::string VISU::Result_i::GetEntry(const std::string& theComment)
   return FindEntryWithComment(myStudyDocument,GetEntry().c_str(),theComment.c_str());
 }
 
-VISU::Result_i::~Result_i() {
+VISU::Result_i::~Result_i()
+{
   MESSAGE("Result_i::~Result_i() - this = "<<this);
-  if(mySourceId == eRestoredFile){
+  if (mySourceId == eRestoredFile) {
     static QString aCommand;
     aCommand.sprintf("rm %s",myFileInfo.filePath().latin1());
     MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));