]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
To provide thread-safety for VISU_Gen::ImportFile functionality
authorapo <apo@opencascade.com>
Wed, 23 Nov 2005 09:27:15 +0000 (09:27 +0000)
committerapo <apo@opencascade.com>
Wed, 23 Nov 2005 09:27:15 +0000 (09:27 +0000)
src/VISUGUI/VisuGUI.cxx
src/VISU_I/VISU_Result_i.cc
src/VISU_I/VISU_Result_i.hh

index 0862abd444245e1c5eb3a661ab4723ac0052b28d..d1acbbc1481983131963986fe02082d2e7f66a7e 100644 (file)
@@ -219,8 +219,6 @@ OnImportFromFile()
       INFOS( "VisuGUI::OnImportFromFile() : File importing done in " <<
             vtkTimerLog::GetCPUTime() - initialTime << " seconds" );
 
-      UpdateObjBrowser(this);
-
       QTime aTime;
       int mSecs = ( int )( 1000 * ( vtkTimerLog::GetCPUTime() - initialTime ) );
       aTime = aTime.addMSecs( mSecs );
index 778dfd0851f8d8e74113e5d82933b35b067a34f3..fa1aece5a41352d4bcd28518da13cd6d973d8dfb 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "VISU_Convertor_impl.hxx"
 #include "VISU_CorbaMedConvertor.hxx"
+#include "VISU_ConvertorUtils.hxx"
 #include "VISU_PipeLine.hxx"
 
 #include "SUIT_ResourceMgr.h"
 #include "SalomeApp_Study.h"
 #include "SalomeApp_Application.h"
 
+#include <boost/thread/recursive_mutex.hpp>
 #include <boost/thread/thread.hpp>
+
+#include <boost/thread/mutex.hpp>
 #include <boost/bind.hpp>
 
 // QT Includes
@@ -61,11 +65,16 @@ using namespace std;
 
 #ifdef _DEBUG_
 static int MYDEBUG = 0;
+static int MYTIMEDEBUG = 0;
 #else
 static int MYDEBUG = 0;
+static int MYTIMEDEBUG = 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();
@@ -84,311 +93,200 @@ VISU::Result_var VISU::FindResult (SALOMEDS::SObject_ptr theSObject)
   return aResult;
 }
 
-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()) {
-    aMap[theName] = 0;
-    tmp = theName;
-  } 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)
+namespace VISU
 {
-  static QString aName;
-  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());
-  aName = aName.simplifyWhiteSpace();
-  return aName.latin1();
-}
+  //---------------------------------------------------------------
+  typedef boost::recursive_mutex TMutex;
+  typedef TMutex::scoped_lock TLock;
 
-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());
-  SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(aFather);
-  SALOMEDS::SObject_var aRefSObj = theStudyDocument->FindObjectID(theRefEntry.c_str());
-  aStudyBuilder->Addreference(newObj,aRefSObj);
-}
+  static TMutex myMutex;
 
-string GetComponentDataType (SALOMEDS::SObject_ptr theSObject)
-{
-  SALOMEDS::SComponent_var aCompRefSObj = theSObject->GetFatherComponent();
-  CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
-  return aDataType.in();
-}
+  //---------------------------------------------------------------
+  struct TGetStudy: public SALOME_Event
+  {
+    typedef _PTR(Study) TResult;
+    TResult myResult;
+    int myStudyId;
 
-//==============================================================================
+    TGetStudy(const int theStudyId):
+      myStudyId(theStudyId)
+    {}
+    
+    virtual
+    void
+    Execute()
+    {
+      SUIT_Session* aSession = SUIT_Session::session();
+      QPtrList<SUIT_Application> anApplications = aSession->applications();
+      QPtrListIterator<SUIT_Application> anIter (anApplications);
+      while (SUIT_Application* aSApp = anIter.current()) {
+       if(SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aSApp)){
+         if(SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy())) {
+           myResult = aStudy->studyDS();
+           break;
+         }
+       }
+       ++anIter;
+      }
+    }
+  };
 
-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):
-  myStudyDocument(SALOMEDS::Study::_duplicate(theStudy)),
-  myCreationId(theCreationId),
-  mySourceId(theSourceId),
-  myInput(NULL),
-  myIsFieldsDone(0),
-  myIsGroupsDone(0),
-  myIsMinMaxDone(0),
-  myIsDone(0)
-{
-}
 
+  //---------------------------------------------------------------
+  QString
+  GenerateName (const char* theName)
+  {
+    TLock aLock(myMutex);
 
-void VISU::Result_i::RemoveFromStudy()
-{
-  // Remove the result with all presentations and other possible sub-objects
-  VISU::RemoveFromStudy(mySObject,false);
-  Destroy();
-}
+    typedef map<string,int> TNameMap;
+    static TNameMap aMap;
 
+    TNameMap::const_iterator i = aMap.find(theName);
+    QString tmp;
+    if (i == aMap.end()) {
+      aMap[theName] = 0;
+      tmp = theName;
+    } else {
+      tmp = VISU::GenerateName(theName,++aMap[theName]);
+    }
+    if(MYDEBUG) MESSAGE("GenerateName - "<<tmp<<" from - "<<theName<<"; " <<aMap[theName]);
+    return tmp;
+  }
+  
 
-int
-VISU::Result_i
-::IsPossible()
-{
-  try{
-    float aSize = myInput->GetSize();
-    bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
-    MESSAGE("Result_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<float(aResult));
-    return aResult;
-  }catch(std::exception& exc){
-    INFOS("Follow exception was occured :\n"<<exc.what());
-  }catch(...){
-    INFOS("Unknown exception was occured!");
+  //---------------------------------------------------------------
+  QString 
+  GenerateFieldName (const string& theName, const string& theUnits)
+  {
+    QString aName;
+    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());
+    aName = aName.simplifyWhiteSpace();
+    return aName.latin1();
   }
-  return 0;
-}
 
 
-//---------------------------------------------------------------
-CORBA::Boolean
-VISU::Result_i
-::BuildAll()
-{
-  if(MYDEBUG) MESSAGE("Result_i::Build - myIsDone = "<<myIsDone);
-  if(myIsDone) return 1;
-  if(!IsPossible()) return 0;
-  try{
-    const VISU::TMeshMap& aMeshMap = myInput->GetMeshMap();
-    VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
-    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;
-      //Import fields
-      aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
-      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++){
-         const string& aFieldName = aFieldMapIter->first;
-         const VISU::PField aField = aFieldMapIter->second;
-         const VISU::TValField& aValField = aField->myValField;
-         VISU::TValField::const_iterator aValFieldIter = aValField.begin();
-         for(; aValFieldIter != aValField.end(); aValFieldIter++){
-           int aTimeStamp = aValFieldIter->first;
-           try{
-             myInput->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
-           }catch(std::exception& exc){
-             INFOS("Follow exception was occured :\n"<<exc.what());
-           }catch(...){
-             INFOS("Unknown exception was occured!!!");
-           }
-         }
-       }
-       //Importing groups
-       const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
-       VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
-       for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
-         const string& aGroupName = aGroupMapIter->first;
-         try{
-           myInput->GetMeshOnGroup(aMeshName,aGroupName);
-         }catch(std::exception& exc){
-           INFOS("Follow exception was occured :\n"<<exc.what());
-         }catch(...){
-           INFOS("Unknown exception was occured!!!");
-         }
-       }
-       //Import families
-       const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
-       VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
-       for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
-         const string& aFamilyName = aFamilyMapIter->first;
-         try{
-           myInput->GetFamilyOnEntity(aMeshName,anEntity,aFamilyName);
-         }catch(std::exception& exc){
-           INFOS("Follow exception was occured :\n"<<exc.what());
-         }catch(...){
-           INFOS("Unknown exception was occured!!!");
-         }
-       }
-       //Import mesh on entity
-       try{
-         myInput->GetMeshOnEntity(aMeshName,anEntity);
-       }catch(std::exception& exc){
-         INFOS("Follow exception was occured :\n"<<exc.what());
-       }catch(...){
-         INFOS("Unknown exception was occured!!!");
-       }
-      }
-    }
-    myIsDone = 1;
-  }catch(std::exception& exc){
-    INFOS("Follow exception was occured :\n"<<exc.what());
-  }catch(...){
-    INFOS("Unknown exception was occured!!!");
+  //---------------------------------------------------------------
+  string
+  GetComponentDataType (SALOMEDS::SObject_ptr theSObject)
+  {
+    SALOMEDS::SComponent_var aCompRefSObj = theSObject->GetFatherComponent();
+    CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
+    return aDataType.in();
   }
-  return myIsDone;
-}
 
 
-//---------------------------------------------------------------
-void
-VISU::Result_i
-::BuildEntities(SALOMEDS::SObject_ptr theSObject)
-{
-  SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
-  aStudyBuilder->NewCommand();  // There is a transaction
+  //---------------------------------------------------------------
+  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());
+    SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(aFather);
+    SALOMEDS::SObject_var aRefSObj = theStudyDocument->FindObjectID(theRefEntry.c_str());
+    aStudyBuilder->Addreference(newObj,aRefSObj);
+  }
 
-  QString aComment;
-  string aRefFatherEntry = GetRefFatherEntry();
 
-  mySComponent = FindOrCreateVisuComponent(myStudyDocument);
-  CORBA::String_var aSComponentEntry = mySComponent->GetID();
-  CORBA::String_var anIOR(GetID());
-  aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
-                  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);
-  mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str());
-  if(!CORBA::is_nil(theSObject)){
-    CORBA::String_var aString = theSObject->GetID();
-    CreateReference(myStudyDocument,aResultEntry,aString.in());
+  //---------------------------------------------------------------
+  void
+  CreateReference (_PTR(Study) theStudyDocument,
+                  const string& theFatherEntry, 
+                  const string& theRefEntry)
+  {
+    TLock aLock(myMutex);
+
+    _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
+    _PTR(SObject) aFather = theStudyDocument->FindObjectID(theFatherEntry);
+    _PTR(SObject) aNewObj = aStudyBuilder->NewObject(aFather);
+    _PTR(SObject) aRefSObj = theStudyDocument->FindObjectID(theRefEntry);
+    aStudyBuilder->Addreference(aNewObj,aRefSObj);
   }
 
-  myInput->BuildEntities();
-  const TMeshMap& aMeshMap = myInput->GetMeshMap();
-  TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
-  for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
-    const string& aMeshName = aMeshMapIter->first;
-    const PMesh& aMesh = aMeshMapIter->second;
-    const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
-    if(aMeshOnEntityMap.empty()) 
-      continue;
-    
-    aComment.sprintf("myComment=MESH;myName=%s;myDim=%d",
-                    aMeshName.c_str(),
-                    aMesh->myDim);
-    aMesh->myEntry = 
-      CreateAttributes(myStudyDocument,
-                      aResultEntry.c_str(),
-                      aRefFatherEntry.c_str(),
-                      "",
-                      aMeshName.c_str(),
-                      "",
-                      aComment.latin1(),
-                      true);
-    
-    aComment.sprintf("myComment=FAMILIES;myMeshName=%s",
-                    aMeshName.c_str());
-    string aSubMeshesEntry = 
-      CreateAttributes(myStudyDocument,
-                      aMesh->myEntry.c_str(),
-                      aRefFatherEntry.c_str(),
-                      "",
-                      "Families",
-                      "",
-                      aComment.latin1(),
-                      true);
-    //Import entities
-    TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
-    for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
-      const TEntity& anEntity = aMeshOnEntityMapIter->first;
-      const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
-      
-      string anEntityName;
-      switch(anEntity){
-      case NODE_ENTITY: 
-       anEntityName = "onNodes"; 
-       break;
-      case EDGE_ENTITY: 
-       anEntityName = "onEdges"; 
-       break;
-      case FACE_ENTITY: 
-       anEntityName = "onFaces"; 
-       break;
-      case CELL_ENTITY: 
-       anEntityName = "onCells"; 
-       break;
-      default:
-       continue;
-      }
-      
-      aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
-                      VISU::TENTITY,
-                      aMeshName.c_str(),
-                      anEntity);
-      
-      aMeshOnEntity->myEntry = 
-       CreateAttributes(myStudyDocument, 
-                        aSubMeshesEntry.c_str(), 
-                        aRefFatherEntry.c_str(),
-                        "", 
-                        anEntityName.c_str(), 
-                        "", 
-                        aComment.latin1(), 
-                        true);
+  string 
+  CreateAttributes(_PTR(Study) theStudyDocument,
+                  const string& theFatherEntry, 
+                  const string& theIOR, 
+                  const string& theName,
+                  const string& thePersistentRef, 
+                  const string& theComment,
+                  CORBA::Boolean theCreateNew)
+  {
+    TLock aLock(myMutex);
+
+    _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
+    _PTR(SObject) aFather = theStudyDocument->FindObjectID(theFatherEntry);
+
+    _PTR(SObject) aNewObj;
+    if(theCreateNew)
+      aNewObj = aStudyBuilder->NewObject(aFather);
+    else
+      aNewObj = aFather;
+
+    _PTR(GenericAttribute) anAttr;
+    if (theIOR != "") {
+      anAttr = aStudyBuilder->FindOrCreateAttribute(aNewObj, "AttributeIOR");
+      _PTR(AttributeIOR) anIOR (anAttr);
+      anIOR->SetValue(theIOR);
+    }
+    if (theName != "") {
+      anAttr = aStudyBuilder->FindOrCreateAttribute(aNewObj, "AttributeName");
+      _PTR(AttributeName) aName (anAttr);
+      aName->SetValue(theName);
+    }
+    if (thePersistentRef != "") {
+      anAttr = aStudyBuilder->FindOrCreateAttribute(aNewObj, "AttributePersistentRef");
+      _PTR(AttributePersistentRef) aPRef (anAttr);
+      aPRef->SetValue(thePersistentRef);
     }
+    if (theComment != "") {
+      anAttr = aStudyBuilder->FindOrCreateAttribute(aNewObj, "AttributeComment");
+      _PTR(AttributeComment) aCmnt (anAttr);
+      aCmnt->SetValue(theComment);
+    }
+    return aNewObj->GetID();
   }
-  
-  aStudyBuilder->CommitCommand();
-}
+
+  //---------------------------------------------------------------
+  struct TResultManager
+  {
+    VISU::Result_i* myResult;
+
+    TResultManager(VISU::Result_i* theResult):
+      myResult(theResult)
+    {
+      myResult->Register();
+    }
+
+    ~TResultManager()
+    {
+      myResult->Destroy();
+    }
+  };
 
 
-namespace
-{
   //---------------------------------------------------------------
-  struct TMemManager
+  struct TTransactionManager
   {
-    VISU::Result_i* myResult;
-    TMemManager(VISU::Result_i* theResult):
-      myResult(theResult)
+    _PTR(StudyBuilder) myStudyBuilder;
+
+    TTransactionManager(_PTR(Study) theStudyDocument):
+      myStudyBuilder(theStudyDocument->NewBuilder())
     {
-      myResult->Register();
+      TLock aLock(myMutex);
+      myStudyBuilder->NewCommand();
     }
 
-    ~TMemManager()
+    ~TTransactionManager()
     {
-      myResult->Destroy();
+      TLock aLock(myMutex);
+      myStudyBuilder->CommitCommand();
     }
   };
 
@@ -408,6 +306,7 @@ namespace
     void
     Execute()
     {
+      TLock aLock(myMutex);
       SUIT_Session* aSession = SUIT_Session::session();
       QPtrList<SUIT_Application> anApplications = aSession->applications();
       QPtrListIterator<SUIT_Application> anIter (anApplications);
@@ -416,7 +315,7 @@ namespace
          if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy())) {
            if (_PTR(Study) aCStudy = aStudy->studyDS()) {
              if (myStudyId == aCStudy->StudyId()) {
-               MESSAGE("Result_i::updateObjectBrowser");
+               TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::updateObjectBrowser");
                anApp->updateObjectBrowser();
                *myIsDone = true;
                break;
@@ -435,16 +334,18 @@ namespace
   BuildGroups(VISU::Result_i* theResult,
              VISU_Convertor* theInput,
              CORBA::Boolean* theIsDone,
-             SALOMEDS::Study_var theStudyDocument,
-             const std::string& theRefFatherEntry)
+             _PTR(Study) theStudy)
   {
-    TMemManager aMemManager(theResult);
-    
-    SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
-    aStudyBuilder->NewCommand();  // There is a transaction
+    TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::BuildGroups");
+    TResultManager aResultManager(theResult);
+    TTransactionManager aTransactionManager(theStudy);
     
+    {
+      TTimerLog aTimerLog(MYTIMEDEBUG,"theInput->BuildGroups");
+      theInput->BuildGroups();
+    }
+
     QString aComment;
-    theInput->BuildGroups();
     const TMeshMap& aMeshMap = theInput->GetMeshMap();
     TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
     for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
@@ -471,11 +372,10 @@ namespace
                           anEntity,
                           aFamilyName.c_str());
          aFamily->myEntry =
-           CreateAttributes(theStudyDocument,
-                            aMeshOnEntity->myEntry.c_str(),
-                            theRefFatherEntry.c_str(),
+           CreateAttributes(theStudy,
+                            aMeshOnEntity->myEntry,
                             "",
-                            aFamilyName.c_str(),
+                            aFamilyName,
                             "",
                             aComment.latin1(),
                             true);
@@ -487,9 +387,8 @@ namespace
        aComment.sprintf("myComment=GROUPS;myMeshName=%s",
                         aMeshName.c_str());
        string aGroupsEntry =
-         CreateAttributes(theStudyDocument,
-                          aMesh->myEntry.c_str(),
-                          theRefFatherEntry.c_str(),
+         CreateAttributes(theStudy,
+                          aMesh->myEntry,
                           "",
                           "Groups",
                           "",
@@ -502,11 +401,10 @@ namespace
          aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
                           TGROUP,aMeshName.c_str(),aGroupName.c_str());
          aGroup->myEntry = 
-           CreateAttributes(theStudyDocument,
-                            aGroupsEntry.c_str(),
-                            theRefFatherEntry.c_str(),
+           CreateAttributes(theStudy,
+                            aGroupsEntry,
                             "",
-                            aGroupName.c_str(),
+                            aGroupName,
                             "",
                             aComment.latin1(),
                             true);
@@ -514,7 +412,7 @@ namespace
          TFamilySet::const_iterator aFamilyIter = aFamilySet.begin();
          for(; aFamilyIter != aFamilySet.end(); aFamilyIter++){
            const PFamily& aFamily = *aFamilyIter;
-           CreateReference(theStudyDocument,
+           CreateReference(theStudy,
                            aGroup->myEntry,
                            aFamily->myEntry);
          }
@@ -522,9 +420,7 @@ namespace
       }
     }
     
-    aStudyBuilder->CommitCommand();
-
-    ProcessVoidEvent(new TUpdateObjBrowser(theStudyDocument->StudyId(),theIsDone));
+    ProcessVoidEvent(new TUpdateObjBrowser(theStudy->StudyId(),theIsDone));
   }
 
 
@@ -533,16 +429,18 @@ namespace
   BuildFields(VISU::Result_i* theResult,
              VISU_Convertor* theInput,
              CORBA::Boolean* theIsDone,
-             SALOMEDS::Study_var theStudyDocument,
-             const std::string& theRefFatherEntry)
+             _PTR(Study) theStudy)
   {
-    TMemManager aMemManager(theResult);
+    TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::BuildFields");
+    TResultManager aResultManager(theResult);
+    TTransactionManager aTransactionManager(theStudy);
+
+    {
+      TTimerLog aTimerLog(MYTIMEDEBUG,"theInput->BuildFields");
+      theInput->BuildFields();
+    }
 
-    SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
-    aStudyBuilder->NewCommand();  // There is a transaction
-    
     QString aComment;
-    theInput->BuildFields();
     const TMeshMap& aMeshMap = theInput->GetMeshMap();
     TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
     for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
@@ -568,9 +466,8 @@ namespace
            aComment.sprintf("myComment=FIELDS;myMeshName=%s",
                             aMeshName.c_str());
            aFieldsEntry =
-             CreateAttributes(theStudyDocument,
-                              aMesh->myEntry.c_str(),
-                              theRefFatherEntry.c_str(),
+             CreateAttributes(theStudy,
+                              aMesh->myEntry,
                               "",
                               "Fields",
                               "",
@@ -581,7 +478,7 @@ namespace
          const string& aFieldName = aFieldMapIter->first;
          const PField& aField = aFieldMapIter->second;
          const TValField& aValField = aField->myValField;
-         QString aFieldNameWithUnit = ::GenerateFieldName(aFieldName,aField->myUnitNames[0]);
+         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(),
@@ -590,15 +487,14 @@ namespace
                           aValField.size(),
                           aField->myNbComp);
          aField->myEntry = 
-           CreateAttributes(theStudyDocument,
-                            aFieldsEntry.c_str(),
-                            theRefFatherEntry.c_str(),
+           CreateAttributes(theStudy,
+                            aFieldsEntry,
                             "",
                             aFieldNameWithUnit.latin1(),
                             "",
                             aComment.latin1(),
                             true);
-         CreateReference(theStudyDocument,
+         CreateReference(theStudy,
                          aField->myEntry,
                          aMeshOnEntity->myEntry);
          TValField::const_iterator aValFieldIter = aValField.begin();
@@ -614,11 +510,10 @@ namespace
                             aField->myNbComp);
            string aTimeStampId = VISU_Convertor::GenerateName(aValForTime->myTime);
            aValForTime->myEntry = 
-             CreateAttributes(theStudyDocument,
-                              aField->myEntry.c_str(),
-                              theRefFatherEntry.c_str(),
+             CreateAttributes(theStudy,
+                              aField->myEntry,
                               "",
-                              aTimeStampId.c_str(),
+                              aTimeStampId,
                               "",
                               aComment.latin1(),
                               true);
@@ -627,9 +522,7 @@ namespace
       }
     }
     
-    aStudyBuilder->CommitCommand();
-
-    ProcessVoidEvent(new TUpdateObjBrowser(theStudyDocument->StudyId(),theIsDone));
+    ProcessVoidEvent(new TUpdateObjBrowser(theStudy->StudyId(),theIsDone));
   }
 
 
@@ -639,7 +532,8 @@ namespace
              VISU_Convertor* theInput,
              CORBA::Boolean* theIsDone)
   {
-    TMemManager aMemManager(theResult);
+    TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::BuildMinMax");
+    TResultManager aResultManager(theResult);
     
     theInput->BuildMinMax();
     *theIsDone = true;
@@ -648,24 +542,275 @@ namespace
 
   //---------------------------------------------------------------
   void
-  BuildMinMaxFields(VISU::Result_i* theResult,
-                   VISU_Convertor* theInput,
-                   CORBA::Boolean* theFieldsIsDone,
-                   CORBA::Boolean* theMinMaxIsDone,
-                   SALOMEDS::Study_var theStudyDocument,
-                   const std::string& theRefFatherEntry)
+  BuildDataTree(VISU::Result_i* theResult,
+               VISU_Convertor* theInput,
+               CORBA::Boolean* theIsFieldsDone,
+               CORBA::Boolean* theIsMinMaxDone,
+               CORBA::Boolean* theIsGroupsDone,
+               _PTR(Study) theStudy)
   {
     BuildFields(theResult,
                theInput,
-               theFieldsIsDone,
-               theStudyDocument,
-               theRefFatherEntry);
+               theIsFieldsDone,
+               theStudy);
 
     BuildMinMax(theResult,
                theInput,
-               theMinMaxIsDone);
+               theIsMinMaxDone);
+
+    BuildGroups(theResult,
+               theInput,
+               theIsGroupsDone,
+               theStudy);
+  }
+  
+}
+
+
+//---------------------------------------------------------------
+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):
+  myStudyDocument(SALOMEDS::Study::_duplicate(theStudy)),
+  myCreationId(theCreationId),
+  mySourceId(theSourceId),
+  myInput(NULL),
+  myIsFieldsDone(0),
+  myIsGroupsDone(0),
+  myIsMinMaxDone(0),
+  myIsDone(0)
+{
+  myStudy = ProcessEvent(new TGetStudy(myStudyDocument->StudyId()));
+}
+
+
+//---------------------------------------------------------------
+void
+VISU::Result_i
+::RemoveFromStudy()
+{
+  // Remove the result with all presentations and other possible sub-objects
+  VISU::RemoveFromStudy(mySObject,false);
+  Destroy();
+}
+
+
+//---------------------------------------------------------------
+int
+VISU::Result_i
+::IsPossible()
+{
+  try{
+    float aSize = myInput->GetSize();
+    bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
+    MESSAGE("Result_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<float(aResult));
+    return aResult;
+  }catch(std::exception& exc){
+    INFOS("Follow exception was occured :\n"<<exc.what());
+  }catch(...){
+    INFOS("Unknown exception was occured!");
+  }
+  return 0;
+}
+
+
+//---------------------------------------------------------------
+CORBA::Boolean
+VISU::Result_i
+::BuildAll()
+{
+  if(MYDEBUG) MESSAGE("Result_i::Build - myIsDone = "<<myIsDone);
+  if(myIsDone) return 1;
+  if(!IsPossible()) return 0;
+  try{
+    const VISU::TMeshMap& aMeshMap = myInput->GetMeshMap();
+    VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
+    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;
+      //Import fields
+      aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
+      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++){
+         const string& aFieldName = aFieldMapIter->first;
+         const VISU::PField aField = aFieldMapIter->second;
+         const VISU::TValField& aValField = aField->myValField;
+         VISU::TValField::const_iterator aValFieldIter = aValField.begin();
+         for(; aValFieldIter != aValField.end(); aValFieldIter++){
+           int aTimeStamp = aValFieldIter->first;
+           try{
+             myInput->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
+           }catch(std::exception& exc){
+             INFOS("Follow exception was occured :\n"<<exc.what());
+           }catch(...){
+             INFOS("Unknown exception was occured!!!");
+           }
+         }
+       }
+       //Importing groups
+       const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
+       VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
+       for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
+         const string& aGroupName = aGroupMapIter->first;
+         try{
+           myInput->GetMeshOnGroup(aMeshName,aGroupName);
+         }catch(std::exception& exc){
+           INFOS("Follow exception was occured :\n"<<exc.what());
+         }catch(...){
+           INFOS("Unknown exception was occured!!!");
+         }
+       }
+       //Import families
+       const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
+       VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
+       for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
+         const string& aFamilyName = aFamilyMapIter->first;
+         try{
+           myInput->GetFamilyOnEntity(aMeshName,anEntity,aFamilyName);
+         }catch(std::exception& exc){
+           INFOS("Follow exception was occured :\n"<<exc.what());
+         }catch(...){
+           INFOS("Unknown exception was occured!!!");
+         }
+       }
+       //Import mesh on entity
+       try{
+         myInput->GetMeshOnEntity(aMeshName,anEntity);
+       }catch(std::exception& exc){
+         INFOS("Follow exception was occured :\n"<<exc.what());
+       }catch(...){
+         INFOS("Unknown exception was occured!!!");
+       }
+      }
+    }
+    myIsDone = 1;
+  }catch(std::exception& exc){
+    INFOS("Follow exception was occured :\n"<<exc.what());
+  }catch(...){
+    INFOS("Unknown exception was occured!!!");
+  }
+  return myIsDone;
+}
+
+
+//---------------------------------------------------------------
+void
+VISU::Result_i
+::BuildEntities(SALOMEDS::SObject_ptr theSObject)
+{
+  TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::BuildEntities");
+  TResultManager aResultManager(this);
+  TTransactionManager aTransactionManager(myStudy);
+
+  QString aComment;
+
+  mySComponent = FindOrCreateVisuComponent(myStudyDocument);
+  CORBA::String_var aSComponentEntry = mySComponent->GetID();
+  CORBA::String_var anIOR(GetID());
+  aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
+                  GetComment(),
+                  VISU::TRESULT,
+                  myFileInfo.filePath().latin1(),
+                  myInitFileName.c_str()); // Restoring of Python dump
+  string aResultEntry =
+    CreateAttributes(myStudy,
+                    aSComponentEntry.in(),
+                    anIOR.in(),
+                    myName,
+                    "",
+                    aComment.latin1(),
+                    true);
+  mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str());
+  if(!CORBA::is_nil(theSObject)){
+    CORBA::String_var aString = theSObject->GetID();
+    CreateReference(myStudyDocument,aResultEntry,aString.in());
+  }
+
+  myInput->BuildEntities();
+  const TMeshMap& aMeshMap = myInput->GetMeshMap();
+  TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
+  for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
+    const string& aMeshName = aMeshMapIter->first;
+    const PMesh& aMesh = aMeshMapIter->second;
+    const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
+    if(aMeshOnEntityMap.empty()) 
+      continue;
+    
+    aComment.sprintf("myComment=MESH;myName=%s;myDim=%d",
+                    aMeshName.c_str(),
+                    aMesh->myDim);
+    aMesh->myEntry = 
+      CreateAttributes(myStudy,
+                      aResultEntry,
+                      "",
+                      aMeshName,
+                      "",
+                      aComment.latin1(),
+                      true);
+    
+    aComment.sprintf("myComment=FAMILIES;myMeshName=%s",
+                    aMeshName.c_str());
+    string aSubMeshesEntry = 
+      CreateAttributes(myStudy,
+                      aMesh->myEntry,
+                      "",
+                      "Families",
+                      "",
+                      aComment.latin1(),
+                      true);
+    //Import entities
+    TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
+    for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
+      const TEntity& anEntity = aMeshOnEntityMapIter->first;
+      const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
+      
+      string anEntityName;
+      switch(anEntity){
+      case NODE_ENTITY: 
+       anEntityName = "onNodes"; 
+       break;
+      case EDGE_ENTITY: 
+       anEntityName = "onEdges"; 
+       break;
+      case FACE_ENTITY: 
+       anEntityName = "onFaces"; 
+       break;
+      case CELL_ENTITY: 
+       anEntityName = "onCells"; 
+       break;
+      default:
+       continue;
+      }
+      
+      aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
+                      VISU::TENTITY,
+                      aMeshName.c_str(),
+                      anEntity);
+      
+      aMeshOnEntity->myEntry = 
+       CreateAttributes(myStudy, 
+                        aSubMeshesEntry, 
+                        "", 
+                        anEntityName.c_str(), 
+                        "", 
+                        aComment.latin1(), 
+                        true);
+    }
   }
   
+  CORBA::Boolean anIsEntitiesDone;
+  ProcessVoidEvent(new TUpdateObjBrowser(myStudy->StudyId(),&anIsEntitiesDone));
 }
 
 
@@ -678,32 +823,16 @@ VISU::Result_i
   if(isBuildAll) 
     return BuildAll(theSObject);
   else{
-    SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
-    aStudyBuilder->NewCommand();  // There is a transaction
-
     BuildEntities(theSObject);
 
-    std::string aRefFatherEntry = GetRefFatherEntry();
-
-    {
-      // To start build of the fields and min/max calculation
-      boost::thread aThread(boost::bind(&BuildMinMaxFields,
-                                       this,
-                                       myInput,
-                                       &myIsFieldsDone,
-                                       &myIsMinMaxDone,
-                                       myStudyDocument,
-                                       aRefFatherEntry));
-    }
-    {
-      // To start build of the groups
-      boost::thread aThread(boost::bind(&BuildGroups,
-                                       this,
-                                       myInput,
-                                       &myIsGroupsDone,
-                                       myStudyDocument,
-                                       aRefFatherEntry));
-    }
+    // To start build of the fields, groups and perfrom min/max calculation
+    boost::thread aThread(boost::bind(&BuildDataTree,
+                                     this,
+                                     myInput,
+                                     &myIsFieldsDone,
+                                     &myIsMinMaxDone,
+                                     &myIsGroupsDone,
+                                     myStudy));
     return this;
   }
 }
@@ -718,13 +847,10 @@ VISU::Result_i
   try{
     BuildEntities(theSObject);
 
-    std::string aRefFatherEntry = GetRefFatherEntry();
-
     BuildFields(this,
                myInput,
                &myIsFieldsDone,
-               myStudyDocument,
-               aRefFatherEntry);
+               myStudy);
 
     BuildMinMax(this,
                myInput,
@@ -733,8 +859,7 @@ VISU::Result_i
     BuildGroups(this,
                myInput,
                &myIsGroupsDone,
-               myStudyDocument,
-               aRefFatherEntry);
+               myStudy);
 
     BuildAll();
   }catch(std::exception& exc){
index af6c757baa79cd88c960f8deba9edc4cab8b930d..d414ff0b53151285d29f431edc46d934f34cdfce 100644 (file)
@@ -108,6 +108,7 @@ namespace VISU{
     const ECreationId& GetCreationId() const { return myCreationId;}
 
   private:
+    _PTR(Study) myStudy;
     SALOMEDS::SObject_var mySObject;
     SALOMEDS::Study_var myStudyDocument;
     SALOMEDS::SComponent_var mySComponent;