X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCalc%2Fgui%2FDatasourceController.cxx;h=8f9ac3a779d36a93cdb1cd2310a0a1e966a8a870;hb=e14b6ab9f409fe42f5c210582b1520e213eb3e8c;hp=dda57da3db4d9206c9725a240d2f4b2ef1445932;hpb=b29346253f2ca9139088351013761a970e1647ba;p=modules%2Fmed.git diff --git a/src/MEDCalc/gui/DatasourceController.cxx b/src/MEDCalc/gui/DatasourceController.cxx index dda57da3d..8f9ac3a77 100644 --- a/src/MEDCalc/gui/DatasourceController.cxx +++ b/src/MEDCalc/gui/DatasourceController.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D +// Copyright (C) 2007-2022 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -75,7 +75,8 @@ void DatasourceController::createActions() { QString tooltip = tr("TIP_ADD_DATA_SOURCE"); QString icon = tr("ICO_DATASOURCE_ADD"); int actionId; - actionId = _salomeModule->createStandardAction(label,this, SLOT(OnAddDatasource()),icon,tooltip); + actionId = _salomeModule->createStandardAction(label, this, SLOT(OnAddDatasource()), + icon, tooltip, FIELDSOp::OpAddDataSource); _salomeModule->createTool(actionId, toolbarId); // This action has to be placed in the general file menu with the label "Import MED file" @@ -112,7 +113,7 @@ void DatasourceController::createActions() { * This function adds the specified MED file as a datasource in the * dataspace. Technically speaking, the engine loads the * meta-information concerning med data from the file, gives this - * informations to the GUI, and the GUI creates a tree view of these + * information to the GUI, and the GUI creates a tree view of these * data in the study object browser. */ // This function emits a signal that will be caught by workspace to delegate command (datasource creation) to python console. @@ -138,10 +139,7 @@ DatasourceController::updateTreeViewWithNewDatasource(const MEDCALC::DatasourceH return; } - SalomeApp_Study* study = dynamic_cast(_salomeModule->application()->activeStudy()); - _PTR(Study) studyDS = study->studyDS(); - - _salomeModule->engine()->addDatasourceToStudy(_CAST(Study, studyDS)->GetStudy(), *datasourceHandler); + _salomeModule->engine()->addDatasourceToStudy(*datasourceHandler); // update Object browser _salomeModule->getApp()->updateObjectBrowser(true); @@ -197,8 +195,8 @@ void DatasourceController::OnAddImagesource() QString medFilename = dialog.getMedFilepath(); bool autoLoad = dialog.isAutoLoaded(); - std::string ROOT_DIR(getenv("MED_ROOT_DIR")); - std::string command(ROOT_DIR+"/bin/salome/med/image2med.py"); + std::string ROOT_DIR(getenv("FIELDS_ROOT_DIR")); + std::string command(ROOT_DIR+"/bin/salome/fields/image2med.py"); command += " -i "+QS2S(imageFilename); command += " -m "+QS2S(medFilename); int error = system(command.c_str()); @@ -223,12 +221,20 @@ void DatasourceController::OnAddImagesource() void DatasourceController::OnExpandField() { - // We need a studyEditor updated on the active study - _studyEditor->updateActiveStudy(); + SALOMEDS::Study_var aStudy = KERNEL::getStudyServant(); + // check if reference to study is valid + if (CORBA::is_nil(aStudy)) + return; + + // check if reference to use case builder is valid + SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder(); + if (CORBA::is_nil(useCaseBuilder)) + return; + // Get the selected objects in the study (SObject) SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects(); - for (int i=0; isize(); i++) { + for (int i=0; i<(int)listOfSObject->size(); i++) { SALOMEDS::SObject_var soFieldseries = listOfSObject->at(i); std::string name(_studyEditor->getName(soFieldseries)); if (soFieldseries->_is_nil() || name == "MEDCalc") @@ -237,11 +243,11 @@ void DatasourceController::OnExpandField() // First retrieve the fieldseries id associated to this study object SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeParameter_var aParam; - if ( soFieldseries->FindAttribute(anAttr,"AttributeParameter") ) { - aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); - if (! aParam->IsSet(FIELD_SERIES_ID, PT_INTEGER)) - return; - } + if ( !soFieldseries->FindAttribute(anAttr,"AttributeParameter") ) + return; + aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); + if (! aParam->IsSet(FIELD_SERIES_ID, PT_INTEGER)) + return; long fieldseriesId = aParam->GetInt(FIELD_SERIES_ID); STDLOG("Expand the field timeseries "<setName(soField,label.c_str()); _studyEditor->setParameterInt(soField, FIELD_ID, fieldHandler.id); _studyEditor->setParameterBool(soField,IS_IN_WORKSPACE,false); + useCaseBuilder->AppendTo(soField->GetFather(), soField); } } _salomeModule->updateObjBrowser(true); } void DatasourceController::OnUseInWorkspace() { - // We need a studyEditor updated on the active study - _studyEditor->updateActiveStudy(); - // Get the selected objects in the study (SObject) SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects(); if ( listOfSObject->size() == 1 ) { @@ -293,11 +297,11 @@ void DatasourceController::OnUseInWorkspace() { return; SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeParameter_var aParam; - if ( soField->FindAttribute(anAttr,"AttributeParameter") ) { - aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); - if (! aParam->IsSet(IS_IN_WORKSPACE, PT_BOOLEAN)) - return; - } + if ( !soField->FindAttribute(anAttr,"AttributeParameter") ) + return; + aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); + if (! aParam->IsSet(IS_IN_WORKSPACE, PT_BOOLEAN)) + return; bool isInWorkspace = aParam->GetBool(IS_IN_WORKSPACE); if ( isInWorkspace ) { QMessageBox::warning(_salomeModule->getApp()->desktop(), @@ -356,17 +360,17 @@ void DatasourceController::OnUseInWorkspace() { else { // In this case, we don't ask the user to specify an alias for // each item, we just import the whole set of items. - for (int i=0; isize(); i++) { + for (int i=0; i<(int)listOfSObject->size(); i++) { SALOMEDS::SObject_var soField = listOfSObject->at(i); if (soField->_is_nil()) continue; SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeParameter_var aParam; - if ( soField->FindAttribute(anAttr,"AttributeParameter") ) { - aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); - if (! aParam->IsSet(IS_IN_WORKSPACE, PT_BOOLEAN)) - return; - } + if ( !soField->FindAttribute(anAttr,"AttributeParameter") ) + return; + aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); + if (! aParam->IsSet(IS_IN_WORKSPACE, PT_BOOLEAN)) + return; bool isInWorkspace = aParam->GetBool(IS_IN_WORKSPACE); if ( !isInWorkspace ) { if (! aParam->IsSet(FIELD_ID, PT_INTEGER))