From 76619b65c189ab5566de07bb1f8822e5cdf2b9e9 Mon Sep 17 00:00:00 2001 From: jfa Date: Fri, 1 Jun 2007 11:56:53 +0000 Subject: [PATCH] NPAL14355: Persistence for MED objects in other modules. 'Load Component Data' functionality now available in Post-Pro via popup. --- src/VISUGUI/VISU_msg_en.po | 6 ++ src/VISUGUI/VisuGUI.cxx | 98 ++++++++++++++++++++++++++------ src/VISUGUI/VisuGUI.h | 2 + src/VISUGUI/VisuGUI_ActionsDef.h | 1 + 4 files changed, 90 insertions(+), 17 deletions(-) diff --git a/src/VISUGUI/VISU_msg_en.po b/src/VISUGUI/VISU_msg_en.po index e69b20be..d443df17 100644 --- a/src/VISUGUI/VISU_msg_en.po +++ b/src/VISUGUI/VISU_msg_en.po @@ -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" diff --git a/src/VISUGUI/VisuGUI.cxx b/src/VISUGUI/VisuGUI.cxx index 73812924..ce94a925 100644 --- a/src/VISUGUI/VisuGUI.cxx +++ b/src/VISUGUI/VisuGUI.cxx @@ -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" } } } diff --git a/src/VISUGUI/VisuGUI.h b/src/VISUGUI/VisuGUI.h index ba4a09e3..59700376 100644 --- a/src/VISUGUI/VisuGUI.h +++ b/src/VISUGUI/VisuGUI.h @@ -86,6 +86,8 @@ protected slots: void OnExportTableToFile(); void OnImportMedField(); + void OnLoadComponentData(); + void OnCreateMesh(); void OnCreateScalarMap(); void OnCreateDeformedShape(); diff --git a/src/VISUGUI/VisuGUI_ActionsDef.h b/src/VISUGUI/VisuGUI_ActionsDef.h index 4f78df4b..12ffe377 100644 --- a/src/VISUGUI/VisuGUI_ActionsDef.h +++ b/src/VISUGUI/VisuGUI_ActionsDef.h @@ -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 -- 2.39.2