]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Fix application CRASH on load study with Post-Pro data from ASCII format
authorjfa <jfa@opencascade.com>
Wed, 3 Aug 2005 07:25:10 +0000 (07:25 +0000)
committerjfa <jfa@opencascade.com>
Wed, 3 Aug 2005 07:25:10 +0000 (07:25 +0000)
src/VISU_I/VISU_Result_i.cc

index 742539ffea60e9acd1f8de04b6a76bd1e1f537a9..20594a77bea8b3af0f1266f16ea0980a77034413 100644 (file)
 
 #include "VISU_Result_i.hh"
 
-#include "VISU_Prs3d_i.hh"
-#include "VISU_ViewManager_i.hh"
-
 #include "VISU_Convertor_impl.hxx"
 #include "VISU_CorbaMedConvertor.hxx"
 #include "VISU_PipeLine.hxx"
-#include "VISU_Actor.h"
 
-//#include "SVTK_ViewWindow.h"
+#include "SUIT_ResourceMgr.h"
 
-//#include "QAD_Desktop.h"
-//#include "QAD_Application.h"
-//#include "QAD_Study.h"
-//#include "QAD_StudyFrame.h"
-//#include "QAD_RightFrame.h"
+#include "SALOME_Event.hxx"
 
-#include "SUIT_ResourceMgr.h"
 #include "SALOMEDS_Tool.hxx"
 #include "HDFascii.hxx"
 
+// QT Includes
 #include <qstring.h>
 #include <qfileinfo.h>
 
-#include <memory>
-#include <fstream>
-//#include <set>
-
-#include <vtkUnstructuredGridReader.h>
-#include <vtkUnstructuredGridWriter.h>
+// VTK Includes
 #include <vtkCell.h>
 
-#include <gp_Pnt.hxx>
-#include <gp_Vec.hxx>
+// OCCT Includes
 #include <Bnd_Box.hxx>
 
 using namespace VISU;
@@ -70,42 +56,46 @@ static int MYDEBUG = 0;
 static int MYDEBUG = 0;
 #endif
 
-VISU::Result_var VISU::FindResult(SALOMEDS::SObject_ptr theSObject){
+VISU::Result_var VISU::FindResult (SALOMEDS::SObject_ptr theSObject)
+{
   SALOMEDS::SComponent_var aSComponent = theSObject->GetFatherComponent();
   SALOMEDS::SObject_var aFather = theSObject->GetFather();
-  CORBA::String_var aComponentID(aSComponent->GetID());
-  CORBA::String_var aFatherID(aFather->GetID());
+  CORBA::String_var aComponentID (aSComponent->GetID());
+  CORBA::String_var aFatherID    (aFather->GetID());
   VISU::Result_var aResult;
-  while(strcmp(aComponentID,aFatherID) != 0){
+  while (strcmp(aComponentID, aFatherID) != 0) {
     CORBA::Object_var anObject = VISU::SObjectToObject(aFather);
-    if(!CORBA::is_nil(anObject)){
+    if (!CORBA::is_nil(anObject)) {
       aResult = VISU::Result::_narrow(anObject);
       if(!aResult->_is_nil()) return aResult;
     }
     aFather = aFather->GetFather();
+    aFatherID = aFather->GetID();
   }
   return aResult;
 }
 
-QString GenerateName(const char* theName){
+QString GenerateName (const char* theName)
+{
   typedef map<string,int> TNameMap;
   static TNameMap aMap;
   TNameMap::const_iterator i = aMap.find(theName);
   QString tmp;
-  if(i == aMap.end()) {
+  if (i == aMap.end()) {
     aMap[theName] = 0;
     tmp = theName;
-  }else{
+  } else {
     tmp = VISU::GenerateName(theName,++aMap[theName]);
   }
   if(MYDEBUG) MESSAGE("GenerateName - "<<tmp<<" from - "<<theName<<"; " <<aMap[theName]);
   return tmp;
 }
 
-QString GenerateFieldName(const string& theName, const string& theUnits){
+QString GenerateFieldName (const string& theName, const string& theUnits)
+{
   static QString aName;
-  const string tmp(theUnits.size(),' ');
-  if(theUnits == "" || theUnits == tmp)
+  const string tmp (theUnits.size(),' ');
+  if (theUnits == "" || theUnits == tmp)
     aName.sprintf("%s, -",theName.c_str());
   else
     aName.sprintf("%s, %s",theName.c_str(),theUnits.c_str());
@@ -113,8 +103,8 @@ QString GenerateFieldName(const string& theName, const string& theUnits){
   return aName.latin1();
 }
 
-void CreateReference(SALOMEDS::Study_ptr theStudyDocument,
-                    const string& theFatherEntry, const string& theRefEntry)
+void CreateReference (SALOMEDS::Study_ptr theStudyDocument,
+                     const string& theFatherEntry, const string& theRefEntry)
 {
   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
   SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry.c_str());
@@ -136,9 +126,9 @@ string GetComponentDataType (SALOMEDS::SObject_ptr theSObject)
 const string VISU::Result_i::myComment = "RESULT";
 const char* VISU::Result_i::GetComment() const { return myComment.c_str();}
 
-VISU::Result_i::Result_i(SALOMEDS::Study_ptr theStudy,
-                        const ESourceId& theSourceId,
-                        const ECreationId& theCreationId):
+VISU::Result_i::Result_i (SALOMEDS::Study_ptr theStudy,
+                         const ESourceId& theSourceId,
+                         const ECreationId& theCreationId):
   myStudyDocument(SALOMEDS::Study::_duplicate(theStudy)),
   myCreationId(theCreationId),
   mySourceId(theSourceId),
@@ -327,8 +317,9 @@ Build(SALOMEDS::SObject_ptr theSObject)
        default:
          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);
+       aEntity2EntryMap[anEntity] = CreateAttributes
+         (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();
@@ -468,7 +459,8 @@ Create(const char* theFileName)
     }
     myInput = CreateConvertor(myFileInfo.absFilePath().latin1());
     if(!myInput)
-      throw std::runtime_error("Create - Cannot create a Convertor for this file!!!"); return Build();
+      throw std::runtime_error("Create - Cannot create a Convertor for this file!!!");
+    return Build();
   }catch(std::exception& exc){
     INFOS("Follow exception was occured :\n"<<exc.what());
   }catch(...){
@@ -540,90 +532,102 @@ Restore(SALOMEDS::SObject_ptr theSObject,
        const Storable::TRestoringMap& theMap,
        const string& thePrefix)
 {
-  if(MYDEBUG)  MESSAGE("Result_i::Restore - "<<thePrefix);
-  try{
+  if(MYDEBUG) MESSAGE("Result_i::Restore - " << thePrefix);
+  try {
     mySObject = SALOMEDS::SObject::_duplicate(theSObject);
     myStudyDocument = mySObject->GetStudy();
     mySComponent = mySObject->GetFatherComponent();
-    myName = VISU::Storable::FindValue(theMap,"myName").latin1();
-    myInitFileName = VISU::Storable::FindValue(theMap,"myInitFileName").latin1();
+    myName = VISU::Storable::FindValue(theMap, "myName").latin1();
+    myInitFileName = VISU::Storable::FindValue(theMap, "myInitFileName").latin1();
+
     SALOMEDS::SObject_var aRefSObj, aTargetRefSObj;
-    if(mySObject->FindSubObject(1,aRefSObj) && aRefSObj->ReferencedObject(aTargetRefSObj)){
-      if(MYDEBUG)  MESSAGE("Result_i::GetInput - There is some reference.");
+    if (mySObject->FindSubObject(1, aRefSObj) &&
+       aRefSObj->ReferencedObject(aTargetRefSObj)) {
+      if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference.");
       SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent();
       CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
       myFileInfo.setFile(aDataType.in());
-      if(MYDEBUG)  MESSAGE("Result_i::GetInput - aDataType = "<<aDataType);
-      Engines::Component_var aEngComp = Base_i::myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", aDataType.in());
+      if(MYDEBUG) MESSAGE("Result_i::GetInput - aDataType = " << aDataType);
+      Engines::Component_var aEngComp =
+       Base_i::myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", aDataType.in());
       if (CORBA::is_nil(aEngComp))
        throw std::runtime_error("Restore - There is no aEngComp for the aDataType !!!");
-      SALOMEDS::StudyBuilder_var  aStudyBuilder = myStudyDocument->NewBuilder();
+      SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
       SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp);
-      aStudyBuilder->LoadWith(aCompRefSObj,aDriver);
-      if(strcmp(aDataType,"MED") == 0)
+      aStudyBuilder->LoadWith(aCompRefSObj, aDriver);
+      if (strcmp(aDataType,"MED") == 0)
        myInput = CreateMEDConvertor(aTargetRefSObj);
       else
        throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!");
-    }else{
+    } else {
       myFileInfo.setFile(thePrefix.c_str());
 
-      string aStudyPrefix("");
-      if (IsMultifile()) aStudyPrefix = (SALOMEDS_Tool::GetNameFromPath(myStudyDocument->URL()));
-      if(!myFileInfo.isFile()){
+      string aStudyPrefix ("");
+      if (IsMultifile())
+       aStudyPrefix = SALOMEDS_Tool::GetNameFromPath(myStudyDocument->URL());
+      if (!myFileInfo.isFile()) {
        string aFileName = thePrefix + aStudyPrefix + "_" + myName;
        myFileInfo.setFile(aFileName.c_str());
       }
       if(MYDEBUG)
-       MESSAGE("Result_i::Restore - aFileName = "<<myFileInfo.filePath()<<"; "<<myFileInfo.isFile());
+       MESSAGE("Result_i::Restore - aFileName = " << myFileInfo.filePath() << "; " << myFileInfo.isFile());
 
-      if (HDFascii::isASCII(myFileInfo.filePath().latin1())) {
-       char* aResultPath = HDFascii::ConvertFromASCIIToHDF(myFileInfo.filePath().latin1());
+      const char* aPathLatin = myFileInfo.filePath().latin1();
+      if (HDFascii::isASCII(aPathLatin)) {
+       MESSAGE("ConvertFromASCIIToHDF(" << aPathLatin << ")");
+       char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aPathLatin);
+       MESSAGE("ConvertFromASCIIToHDF() DONE : " << aResultPath);
        char* aHDFFileName = new char[strlen(aResultPath) + 19];
        sprintf(aHDFFileName, "%shdf_from_ascii.hdf", aResultPath);
 
        if (IsMultifile()) { // set this file as new - temporary
          static QString aCommand;
          aCommand.sprintf("mv %s %s%s",aHDFFileName, aResultPath, myFileInfo.baseName().latin1());
-         if(system(aCommand) == -1){
-           if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :"<<aCommand);
+         if (system(aCommand) == -1) {
+           if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand);
            return NULL;
-         } else if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - "<<aCommand);
-         myFileInfo.setFile(QString(aResultPath)+QString(myFileInfo.baseName().latin1()));
+         } else {
+           if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand);
+         }
+         myFileInfo.setFile(QString(aResultPath) + QString(myFileInfo.baseName().latin1()));
        } else { // change current temporary file to the new: with hdf-format
          static QString aCommand;
          aCommand.sprintf("mv %s %s\0",aHDFFileName, myFileInfo.filePath().latin1());
-         if(system(aCommand.latin1()) == -1) {
-           if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :"<<aCommand);
+         if (system(aCommand.latin1()) == -1) {
+           if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand);
            return NULL;
-         } else if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - "<<aCommand);
+         } else {
+           if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand);
+         }
          SALOMEDS::ListOfFileNames_var anEmptyList = new SALOMEDS::ListOfFileNames;
          SALOMEDS_Tool::RemoveTemporaryFiles(aResultPath, anEmptyList.in(), true);
        }
        mySourceId = eRestoredFile;
        delete(aResultPath);
        delete(aHDFFileName);
-      } else if (!IsMultifile())
+      } else if (!IsMultifile()) {
        mySourceId = eRestoredFile;
-      else
+      } else {
        mySourceId = eFile;
-      if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = "<<mySourceId);
+      }
+      if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = " << mySourceId);
       myInput = CreateConvertor(myFileInfo.filePath().latin1());
       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
       SALOMEDS::GenericAttribute_var anAttr;
-      if(!theSObject->FindAttribute(anAttr, "AttributeComment"))
+      if (!theSObject->FindAttribute(anAttr, "AttributeComment"))
        throw std::runtime_error("Build - There is no AttributeComment for the SObject !!!");
       SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
       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){
+  } catch(std::exception& exc) {
     INFOS("Follow exception was occured :\n"<<exc.what());
-  }catch(...){
+  } catch(...) {
     INFOS("Unknown exception was occured!!!");
   }
   return NULL;