From 2cc9a267ac527ad2ae9f1a678115f87bfa192583 Mon Sep 17 00:00:00 2001 From: jfa Date: Thu, 22 Mar 2007 13:44:22 +0000 Subject: [PATCH] Fix problems with usage in VISU of MED data from other modules (not only MED). These problems are raised after implementation of IMP 14355. --- src/VISUGUI/VisuGUI.cxx | 38 +++++++++++++++++++++++++++++++++++++ src/VISU_I/VISU_Gen_i.cc | 8 +++++++- src/VISU_I/VISU_Result_i.cc | 21 +++++++++++++++++++- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/VISUGUI/VisuGUI.cxx b/src/VISUGUI/VisuGUI.cxx index c967459c..bec2bebf 100644 --- a/src/VISUGUI/VisuGUI.cxx +++ b/src/VISUGUI/VisuGUI.cxx @@ -393,6 +393,44 @@ OnImportMedField() 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(); + //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 + SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_nil(); + 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)) + anEngine = SALOMEDS::Driver::_narrow(anEngineObj); + + if (!CORBA::is_nil(anEngine)) { + // try to load + SALOMEDS::StudyBuilder_ptr aStudyBuilder = aStudy->NewBuilder(); + //aStudyBuilder->LoadWith(aSComp, aDriverIOR.in()); + aStudyBuilder->LoadWith(aSComp, anEngine); + } + } + catch (...) { + } + } + } + CORBA::Object_var anObject = VISU::SObjectToObject(aSObject); if (!CORBA::is_nil(anObject)) { SALOME_MED::MED_var aMED = SALOME_MED::MED::_narrow(anObject); diff --git a/src/VISU_I/VISU_Gen_i.cc b/src/VISU_I/VISU_Gen_i.cc index 60a78ad0..11f24415 100644 --- a/src/VISU_I/VISU_Gen_i.cc +++ b/src/VISU_I/VISU_Gen_i.cc @@ -624,7 +624,13 @@ namespace VISU if(!CORBA::is_nil(aMedEngine)) { SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder(); - aStudyBuilder->LoadWith( myStudyDocument->FindComponent( "MED" ), aMedEngine ); + try { + aStudyBuilder->LoadWith( myStudyDocument->FindComponent( "MED" ), aMedEngine ); + } + catch( const SALOME::SALOME_Exception& ) { + // Oops, something went wrong while loading + // See also SalomeApp_Study::openDataModel() + } } } } else { diff --git a/src/VISU_I/VISU_Result_i.cc b/src/VISU_I/VISU_Result_i.cc index 0135f88f..4c53594b 100644 --- a/src/VISU_I/VISU_Result_i.cc +++ b/src/VISU_I/VISU_Result_i.cc @@ -64,7 +64,7 @@ using namespace VISU; using namespace std; #ifdef _DEBUG_ -static int MYDEBUG = 0; +static int MYDEBUG = 1; static int MYTIMEDEBUG = 0; #else static int MYDEBUG = 0; @@ -1292,6 +1292,7 @@ Restore(SALOMEDS::SObject_ptr theSObject, SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder(); SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp); aStudyBuilder->LoadWith(aCompRefSObj, aDriver); + /* if (strcmp(aDataType, "MED") == 0){ // create field or MED converter CORBA::Object_var aMedObject = VISU::SObjectToObject(aTargetRefSObj); @@ -1303,6 +1304,24 @@ Restore(SALOMEDS::SObject_ptr theSObject, myInput->Build(); }else throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!"); + //*/ + + // create field or MED converter + CORBA::Object_var aMedObject = VISU::SObjectToObject(aTargetRefSObj); + SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(aMedObject); + if (!CORBA::is_nil(aField)) { + // create field converter + myInput = CreateMEDFieldConvertor(aField); + myInput->Build(); + } + else if (strcmp(aDataType, "MED") == 0) { + // create MED converter + myInput = CreateMEDConvertor(aTargetRefSObj); + myInput->Build(); + } + else { + throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!"); + } } else { myFileInfo.setFile(thePrefix.c_str()); -- 2.39.2