Salome HOME
Remove useless files; Use SALOMEDSClient classes instead of CORBA interfaces; fix...
[modules/visu.git] / src / VISUGUI / VisuGUI_Tools.cxx
index 23b90dc2d03f5509b0e9bc5884f8fc958ad7d6b4..671c811d1627f99a1abe55afdde618e42a3c7676 100644 (file)
@@ -89,18 +89,6 @@ namespace VISU
     return theStudy->studyDS();
   }
 
-  SALOMEDS::StudyManager_var
-  GetStudyManager()
-  {
-    static SALOMEDS::StudyManager_var aStudyManager;
-    if(CORBA::is_nil(aStudyManager)){
-      SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
-      CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager");
-      aStudyManager = SALOMEDS::StudyManager::_narrow(anObject);
-    }
-    return aStudyManager;
-  }
-
   bool
   IsStudyLocked( _PTR(Study) theStudy )
   {
@@ -149,32 +137,6 @@ namespace VISU
     return aGen;
   }
 
-  VISU::Storable::TRestoringMap
-  getMapOfValue(SALOMEDS::SObject_var theSObject)
-  {
-    VISU::Storable::TRestoringMap aMap;
-    if(!theSObject->_is_nil()){
-      SALOMEDS::GenericAttribute_var anAttr;
-      if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
-       SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
-       CORBA::String_var aValue = aComment->Value();
-       QString aString(aValue.in());
-       VISU::Storable::StrToMap(aString,aMap);
-      }
-    }
-    return aMap;
-  }
-
-  QString
-  getValue(SALOMEDS::SObject_var theSObject,
-          QString theKey)
-  {
-    QString aStr("");
-    VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject);
-    if(!aMap.empty())
-      aStr = VISU::Storable::FindValue(aMap,theKey.latin1());
-    return aStr;
-  }
 
   VISU::Storable::TRestoringMap getMapOfValue (_PTR(SObject) theSObject)
   {
@@ -207,20 +169,20 @@ namespace VISU
                 const QString& theEntry,
                 VISU::Storable::TRestoringMap* theMap)
   {
-    if ( !theStudy || theEntry.isEmpty() )
+    if (!theStudy || theEntry.isEmpty())
       return CORBA::Object::_nil();
 
-    SALOMEDS::Study_var aStudy = GetDSStudy(GetCStudy( theStudy ));
-    SALOMEDS::SObject_var aSObject = aStudy->FindObjectID( theEntry.latin1() );
-    if(!aSObject->_is_nil()){
-      SALOMEDS::GenericAttribute_var anAttr;
-      if(theMap && aSObject->FindAttribute(anAttr,"AttributeComment")){
-       SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
+    _PTR(Study) aStudy = GetCStudy(theStudy);
+    _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry.latin1());
+    if (aSObject) {
+      _PTR(GenericAttribute) anAttr;
+      if (theMap && aSObject->FindAttribute(anAttr,"AttributeComment")) {
+       _PTR(AttributeComment) aComment (anAttr);
        std::string aValue = aComment->Value();
-       QString aString(aValue.c_str());
-       VISU::Storable::StrToMap(aString,*theMap);
+       QString aString (aValue.c_str());
+       VISU::Storable::StrToMap(aString, *theMap);
       }
-      return VISU::SObjectToObject(aSObject);
+      return VISU::ClientSObjectToObject(aSObject);
     }
     return CORBA::Object::_nil();
   }
@@ -407,17 +369,17 @@ namespace VISU
 
   void
   DeleteSObject (SalomeApp_Module* theModule,
-                 SALOMEDS::Study_ptr theStudy,
-                 SALOMEDS::SObject_ptr theSObject)
+                 _PTR(Study)       theStudy,
+                 _PTR(SObject)     theSObject)
   {
-    SALOMEDS::ChildIterator_var aChildIter = theStudy->NewChildIterator(theSObject);
+    _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
     for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
-      SALOMEDS::SObject_var aChildSObject = aChildIter->Value();
-      CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject);
+      _PTR(SObject) aChildSObject = aChildIter->Value();
+      CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
       ErasePrs(theModule, aChildObj);
     }
 
-    CORBA::Object_var anObj = VISU::SObjectToObject(theSObject);
+    CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject);
     if (!CORBA::is_nil(anObj)) {
       VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
       if (!CORBA::is_nil(aRemovableObject)) {
@@ -436,9 +398,9 @@ namespace VISU
              VISU::Prs3d_i* thePrs,
              const Handle(SALOME_InteractiveObject)& theIO)
   {
-    if(!thePrs)
+    if (!thePrs)
       return;
-    if(CheckLock(GetCStudy(GetAppStudy(theModule))))
+    if (CheckLock(GetCStudy(GetAppStudy(theModule))))
       return;
     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
     CORBA::String_var anEntry = aSObject->GetID();
@@ -513,18 +475,18 @@ namespace VISU
 
   bool
   CheckTimeStamp(const SalomeApp_Module* theModule,
-                SALOMEDS::SObject_var& theSObject,
+                _PTR(SObject)&          theSObject,
                 Handle(SALOME_InteractiveObject)* theIO)
   {
     Handle(SALOME_InteractiveObject) anIO;
-    CORBA::Object_var anObject = GetSelectedObj(theModule,&anIO);
-    if(theIO)
+    CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
+    if (theIO)
       *theIO = anIO;
-    if(!anIO.IsNull() && anIO->hasEntry()){
-      SALOMEDS::Study_var aStudy = GetDSStudy(GetCStudy(GetAppStudy(theModule)));
+    if (!anIO.IsNull() && anIO->hasEntry()){
+      _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
       theSObject = aStudy->FindObjectID(anIO->getEntry());
       QString aValue = getValue(theSObject,"myType");
-      if(aValue.toInt() == int(VISU::TTIMESTAMP))
+      if (aValue.toInt() == int(VISU::TTIMESTAMP))
        return true;
     }
     SUIT_MessageBox::warn1(GetDesktop(theModule),
@@ -534,32 +496,29 @@ namespace VISU
     return false;
   }
 
-
   VISU::Result_i*
   CheckResult(const SalomeApp_Module* theModule,
-             SALOMEDS::SObject_var theSource,
-             VISU::Result_var& theResult)
+             _PTR(SObject)           theSource,
+             VISU::Result_var&       theResult)
   {
-    SALOMEDS::SObject_var aSObj;
-
-    aSObj = theSource->GetFather();
-    if (CORBA::is_nil(aSObj))
+    _PTR(SObject) aSObj = theSource->GetFather();
+    if (!aSObj)
       return NULL;
 
     aSObj = aSObj->GetFather();
-    if (CORBA::is_nil(aSObj))
+    if (!aSObj)
       return NULL;
 
     aSObj = aSObj->GetFather();
-    if (CORBA::is_nil(aSObj))
+    if (!aSObj)
       return NULL;
 
-    CORBA::Object_var anObject = VISU::SObjectToObject(aSObj);
+    CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
     if (CORBA::is_nil(anObject)) {
       aSObj = aSObj->GetFather();
-      if (CORBA::is_nil(aSObj))
+      if (!aSObj)
         return NULL;
-      anObject = VISU::SObjectToObject(aSObj);
+      anObject = VISU::ClientSObjectToObject(aSObj);
     }
 
     if (CORBA::is_nil(anObject))
@@ -567,7 +526,7 @@ namespace VISU
 
     theResult = VISU::Result::_narrow(anObject);
     VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
-    if(pResult == NULL)
+    if (pResult == NULL)
       SUIT_MessageBox::warn1(GetDesktop(theModule),
                             QObject::tr("WRN_VISU"),
                             QObject::tr("WRN_NO_AVAILABLE_DATA"),
@@ -1009,14 +968,13 @@ namespace VISU
   // Others
 
   void CreateMesh (const SalomeApp_Module* theModule,
-                   const Handle(SALOME_InteractiveObject)& theIO)
+                    const Handle(SALOME_InteractiveObject)& theIO)
   {
     _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
     //if (CheckLock(aStudy))
     //  return;
 
-    SALOMEDS::SObject_var aResultSObj =
-      GetDSStudy(aStudy)->FindObjectID(theIO->getEntry());
+    _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
 
     // Get VISU::Result
     VISU::Result_var aResult;
@@ -1102,113 +1060,120 @@ namespace VISU
     std::vector<VISU::Prs3d_i*> aList;
     if (!theIO.IsNull() && theIO->hasEntry()) {
       _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
-      SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy);
-      SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(theIO->getEntry());
+      _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
       aList = GetPrs3dList(theModule, aSObject);
     }
     return aList;
   }
 
   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
-                                            SALOMEDS::SObject_ptr theObject)
+                                            _PTR(SObject) theObject)
   {
+    std::vector<VISU::Prs3d_i*> aList; int k = 0;
+    if (!theObject)
+      return aList;
+
     _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
-    SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy);
 
-    std::vector<VISU::Prs3d_i*> aList; int k = 0;
-    if (!theObject->_is_nil()) {
-      CORBA::Object_var aCORBAObject = VISU::SObjectToObject(theObject);
-      if (!CORBA::is_nil(aCORBAObject)) {
-        VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
-        if (!CORBA::is_nil(aVisuObj)) {
-         VISU::VISUType aType = aVisuObj->GetType();
-         switch (aType) {
-         case VISU::TSCALARMAP:
-         case VISU::TISOSURFACE:
-         case VISU::TDEFORMEDSHAPE:
-         case VISU::TCUTPLANES:
-         case VISU::TCUTLINES:
-         case VISU::TVECTORS:
-         case VISU::TSTREAMLINES:
-         case VISU::TPLOT3D:
-           {
-             PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
-             if (aServant.in()) {
-               VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
-               aList.resize(k+1); aList[k] = aPrsObject; k++;
-             }
-           }
-           break;
-         case VISU::TFIELD:
-           {
-             SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theObject);
-             SALOMEDS::SObject_var aTimeStamp;
-             anIter->Next(); // First is reference on support
-             for(;anIter->More();anIter->Next()) {
-               aTimeStamp = anIter->Value();
-                if (aTimeStamp->_is_nil()) continue;
+    CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
+    if (!CORBA::is_nil(aCORBAObject)) {
+      VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
+      if (!CORBA::is_nil(aVisuObj)) {
+        VISU::VISUType aType = aVisuObj->GetType();
+        switch (aType) {
+        case VISU::TSCALARMAP:
+        case VISU::TISOSURFACE:
+        case VISU::TDEFORMEDSHAPE:
+        case VISU::TCUTPLANES:
+        case VISU::TCUTLINES:
+        case VISU::TVECTORS:
+        case VISU::TSTREAMLINES:
+        case VISU::TPLOT3D:
+          {
+            PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
+            if (aServant.in()) {
+              VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
+              aList.resize(k+1);
+              aList[k] = aPrsObject;
+              k++;
+            }
+          }
+          break;
+        case VISU::TFIELD:
+          {
+            _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
+            _PTR(SObject) aTimeStamp;
+            anIter->Next(); // First is reference on support
+            for (; anIter->More(); anIter->Next()) {
+              aTimeStamp = anIter->Value();
+              if (!aTimeStamp) continue;
+              std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
+              if (!aSubList.empty()) {
+                int n = aSubList.size();
+                aList.resize(k+n);
+                for (int i = 0; i < n; i++) {
+                  aList[k] = aSubList[i];
+                  k++;
+                }
+              }
+            }
+          }
+          break;
+        }
+      }
+    } else {
+      _PTR(GenericAttribute) anAttr;
+      if (theObject->FindAttribute(anAttr, "AttributeComment")) {
+        _PTR(AttributeComment) aComment (anAttr);
+        string aComm = aComment->Value();
+        QString strIn (aComm.c_str());
+        VISU::Storable::TRestoringMap pMap;
+        VISU::Storable::StrToMap(strIn, pMap);
+        bool isExist;
+        VISU::VISUType aType =
+          (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
+        if (isExist) {
+          switch (aType) {
+          case VISU::TFIELD:
+            {
+              _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
+              _PTR(SObject) aTimeStamp;
+              anIter->Next(); // First is reference on support
+              for (; anIter->More(); anIter->Next()) {
+                aTimeStamp = anIter->Value();
+                if (!aTimeStamp) continue;
                 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
                 if (!aSubList.empty()) {
-                 int n = aSubList.size();
+                  int n = aSubList.size();
                   aList.resize(k+n);
-                  for (int i = 0; i < n; i++)
-                   { aList[k] = aSubList[i]; k++; }
-               }
-             }
-           }
-           break;
-         }
-        }
-      } else {
-        SALOMEDS::GenericAttribute_var anAttr;
-        if (theObject->FindAttribute(anAttr, "AttributeComment")) {
-         SALOMEDS::AttributeComment_var aComment =
-            SALOMEDS::AttributeComment::_narrow(anAttr);
-         string aComm = aComment->Value();
-         QString strIn( aComm.c_str() );
-         VISU::Storable::TRestoringMap pMap;
-         VISU::Storable::StrToMap( strIn, pMap );
-         bool isExist;
-         VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
-         if (isExist) {
-           switch (aType) {
-           case VISU::TFIELD:
-             {
-               SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theObject);
-               SALOMEDS::SObject_var aTimeStamp;
-               anIter->Next(); // First is reference on support
-               for (;anIter->More();anIter->Next()) {
-                 aTimeStamp = anIter->Value();
-                  if (aTimeStamp->_is_nil()) continue;
-                  std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
-                  if (!aSubList.empty()) {
-                   int n = aSubList.size();
-                    aList.resize(k+n);
-                    for (int i = 0; i < n; i++)
-                     { aList[k] = aSubList[i]; k++; }
-                 }
-               }
-             }
-             break;
-           case VISU::TTIMESTAMP:
-             {
-               SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theObject);
-               SALOMEDS::SObject_var aPrs;
-               for (;anIter->More();anIter->Next()) {
-                 aPrs = anIter->Value();
-                  if (aPrs->_is_nil()) continue;
-                  std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
-                  if (!aSubList.empty()) {
-                   int n = aSubList.size();
-                    aList.resize(k+n);
-                    for (int i = 0; i < n; i++)
-                     { aList[k] = aSubList[i]; k++; }
-                 }
-               }
-             }
-             break;
-           }
-         }
+                  for (int i = 0; i < n; i++) {
+                    aList[k] = aSubList[i];
+                    k++;
+                  }
+                }
+              }
+            }
+            break;
+          case VISU::TTIMESTAMP:
+            {
+              _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
+              _PTR(SObject) aPrs;
+              for (; anIter->More(); anIter->Next()) {
+                aPrs = anIter->Value();
+                if (!aPrs) continue;
+                std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
+                if (!aSubList.empty()) {
+                  int n = aSubList.size();
+                  aList.resize(k+n);
+                  for (int i = 0; i < n; i++) {
+                    aList[k] = aSubList[i];
+                    k++;
+                  }
+                }
+              }
+            }
+            break;
+          }
         }
       }
     }