]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
NPAL14355: Persistence for MED objects in other modules. 'Load Component Data' functi...
authorjfa <jfa@opencascade.com>
Fri, 1 Jun 2007 11:56:53 +0000 (11:56 +0000)
committerjfa <jfa@opencascade.com>
Fri, 1 Jun 2007 11:56:53 +0000 (11:56 +0000)
src/VISUGUI/VISU_msg_en.po
src/VISUGUI/VisuGUI.cxx
src/VISUGUI/VisuGUI.h
src/VISUGUI/VisuGUI_ActionsDef.h

index e69b20bec95e85927568654846248c7c3f33e623..d443df1795f8667ff556627281764e5790a306f1 100644 (file)
@@ -34,6 +34,9 @@ msgstr "Warning"
 msgid "INF_DONE"
 msgstr " done"
 
+msgid "INF_FAILED"
+msgstr " failed!"
+
 msgid "WRN_STUDY_LOCKED"
 msgstr "Current Study is locked"
 
@@ -422,6 +425,9 @@ msgstr "Import TimeStamp"
 msgid "VisuGUI::MEN_IMPORT_MED_FIELD"
 msgstr "Import Field"
 
+msgid "VisuGUI::MEN_LOAD_COMPONENT_DATA"
+msgstr "Load Component Data"
+
 msgid "VisuGUI::MEN_DELETE_OBJS"
 msgstr "Delete"
 
index 738129244c0c60bbaec661de12dc0cb51ff71012..ce94a925d6d10ce2035bb7e2879774853b2e0acb 100644 (file)
@@ -398,11 +398,9 @@ OnImportMedField()
       // The same in SUPERVISION: NPAL14522
       {
         SALOMEDS::SComponent_ptr aSComp = aSObject->GetFatherComponent();
-        //std::string aCompIOR;
         CORBA::String_var aCompIOR;
         if (!aSComp->ComponentIOR(aCompIOR)) { // not loaded
           CORBA::String_var aCompDataType = aSComp->ComponentDataType();
-          //std::string aCompDataType = aSComp->ComponentDataType();
 
           // obtain a driver by a component data type
           // like it is done in SALOMEDS_DriverFactory_i::GetDriverByType
@@ -410,10 +408,8 @@ OnImportMedField()
           SALOME_LifeCycleCORBA * LCC = getApp()->lcc();
           try {
             CORBA::Object_var
-              //anEngineObj = LCC->FindOrLoad_Component("FactoryServer", aCompDataType.c_str());
               anEngineObj = LCC->FindOrLoad_Component("FactoryServer", aCompDataType);
             if (CORBA::is_nil(anEngineObj))
-              //anEngineObj = LCC->FindOrLoad_Component("FactoryServerPy", aCompDataType.c_str());
               anEngineObj = LCC->FindOrLoad_Component("FactoryServerPy", aCompDataType);
 
             if (!CORBA::is_nil(anEngineObj))
@@ -422,7 +418,6 @@ OnImportMedField()
             if (!CORBA::is_nil(anEngine)) {
               // try to load
               SALOMEDS::StudyBuilder_ptr aStudyBuilder = aStudy->NewBuilder();
-              //aStudyBuilder->LoadWith(aSComp, aDriverIOR.in());
               aStudyBuilder->LoadWith(aSComp, anEngine);
             }
           }
@@ -454,6 +449,67 @@ OnImportMedField()
   QApplication::restoreOverrideCursor();
 }
 
+void VisuGUI::OnLoadComponentData()
+{
+  _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
+  if (CheckLock(aCStudy,GetDesktop(this)))
+    return;
+  SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy);
+
+  LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+  SALOME_ListIO aListIO;
+  aSelectionMgr->selectedObjects(aListIO);
+
+  SALOME_ListIteratorOfListIO It (aListIO);
+  QApplication::setOverrideCursor(Qt::waitCursor);
+  for (; It.More(); It.Next()) {
+    Handle(SALOME_InteractiveObject) anIO = It.Value();
+    SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(anIO->getEntry());
+    if (!aSObject->_is_nil()) {
+
+      // try to load a component data from an opened (presumably) study
+      // The same in SUPERVISION: NPAL14522
+      {
+        SALOMEDS::SComponent_ptr aSComp = aSObject->GetFatherComponent();
+        CORBA::String_var aCompIOR;
+        if (!aSComp->ComponentIOR(aCompIOR)) { // not loaded
+          CORBA::String_var aCompDataType = aSComp->ComponentDataType();
+
+          QString anInfo ("Loading ");
+          anInfo = anInfo + aCompDataType.in() + " Component Data ..."; 
+          application()->putInfo( anInfo );
+
+          // obtain a driver by a component data type
+          // like it is done in SALOMEDS_DriverFactory_i::GetDriverByType
+          SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_nil();
+          SALOME_LifeCycleCORBA * LCC = getApp()->lcc();
+          try {
+            CORBA::Object_var
+              anEngineObj = LCC->FindOrLoad_Component("FactoryServer", aCompDataType);
+            if (CORBA::is_nil(anEngineObj))
+              anEngineObj = LCC->FindOrLoad_Component("FactoryServerPy", aCompDataType);
+
+            if (!CORBA::is_nil(anEngineObj))
+              anEngine = SALOMEDS::Driver::_narrow(anEngineObj);
+
+            if (!CORBA::is_nil(anEngine)) {
+              // try to load
+              SALOMEDS::StudyBuilder_ptr aStudyBuilder = aStudy->NewBuilder();
+              aStudyBuilder->LoadWith(aSComp, anEngine);
+            }
+
+            application()->putInfo( anInfo + tr("INF_DONE"));
+          }
+          catch (...) {
+            application()->putInfo( anInfo + tr("INF_FAILED"));
+          }
+        }
+      }
+    }
+  }
+  QApplication::restoreOverrideCursor();
+}
+
 void
 CreateCurves( SalomeApp_Module* theModule,
               VISU::CutLines_i* thePrs,
@@ -2133,6 +2189,10 @@ createActions()
                 tr("MEN_IMPORT_MED_FIELD"), "", 0, aParent, false,
                 this, SLOT(OnImportMedField()));
 
+  createAction( VISU_LOAD_COMPONENT_DATA, tr("MEN_LOAD_COMPONENT_DATA"), QIconSet(),
+                tr("MEN_LOAD_COMPONENT_DATA"), "", 0, aParent, false,
+                this, SLOT(OnLoadComponentData()));
+
   createAction( VISU_CREATE_PRS, tr("MEN_CREATE_PRS"), QIconSet(),
                 tr("MEN_CREATE_PRS"), "", 0, aParent, false,
                 this, SLOT(OnCreateMesh()));
@@ -2825,6 +2885,15 @@ void VisuGUI::contextMenuPopup( const QString& theClient, QPopupMenu* theMenu, Q
   _PTR(SObject) SO = aCStudy->FindObjectID(anIO->getEntry());
   if ( !SO )
     return;
+
+  // Check if the object's data is loaded
+  _PTR(SComponent) aSComp = SO->GetFatherComponent();
+  std::string aCompIOR;
+  if (!aSComp->ComponentIOR(aCompIOR)) { // not loaded
+    //std::string aCompDataType = aSComp->ComponentDataType();
+    action( VISU_LOAD_COMPONENT_DATA )->addTo(theMenu); // "Load Component Data"
+  }
+
   bool isExist;
   VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
 
@@ -2841,24 +2910,19 @@ void VisuGUI::contextMenuPopup( const QString& theClient, QPopupMenu* theMenu, Q
       if (!CORBA::is_nil(anObject)) {
         SALOME_MED::MED_var aMED = SALOME_MED::MED::_narrow(anObject);
         if (!CORBA::is_nil(aMED.in())) {
-          action( VISU_IMPORT_MED_STRUCTURE )->addTo(theMenu);
+          action( VISU_IMPORT_MED_STRUCTURE )->addTo(theMenu); // "Import Structure"
         }
 
-        SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(anObject); // "Import Structure"
+        SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(anObject);
         if (!CORBA::is_nil(aField)) {
           action( VISU_IMPORT_MED_TIMESTAMP )->addTo(theMenu); // "Import TimeStamp"
         }
       } else {
-        _PTR(SObject) aSFather = SO->GetFather();
-        if (aSFather) {
-          _PTR(GenericAttribute) anAttr;
-          aSFather->FindAttribute(anAttr, "AttributeName");
-          if (anAttr) {
-            _PTR(AttributeName) aName (anAttr);
-            std::string aValue = aName->Value();
-            if (strcmp(aValue.c_str(), "MEDFIELD") == 0) {
-              action( VISU_IMPORT_MED_FIELD )->addTo(theMenu); // "Import Field"
-            }
+        _PTR(SObject) aSFather1 = SO->GetFather();
+        if (aSFather1) {
+          std::string aValue = aSFather1->GetName();
+          if (strcmp(aValue.c_str(), "MEDFIELD") == 0) {
+            action( VISU_IMPORT_MED_FIELD )->addTo(theMenu); // "Import Field"
           }
         }
       }
index ba4a09e3595d286000f95cf68cd55c2bff60a6af..5970037659097837cb0f07fbe7879c3f3a97d333 100644 (file)
@@ -86,6 +86,8 @@ protected slots:
   void OnExportTableToFile();
   void OnImportMedField();
 
+  void OnLoadComponentData();
+
   void OnCreateMesh();
   void OnCreateScalarMap();
   void OnCreateDeformedShape();
index 4f78df4b749018415be5e316aff063434032b2c3..12ffe37793dea241ace15338a798158502aab967 100644 (file)
@@ -28,6 +28,7 @@
 #define VISU_IMPORT_MED_STRUCTURE   4004
 #define VISU_IMPORT_MED_TIMESTAMP   4005
 #define VISU_IMPORT_MED_FIELD       4006
+#define VISU_LOAD_COMPONENT_DATA    4007
 
 #define VISU_SCALAR_MAP             4011
 #define VISU_DEFORMED_SHAPE         4012