-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2020 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
#include <QStringList>
#include <QString>
#include <QMessageBox>
+#include <QFileDialog>
#include "DlgAlias.hxx"
icon = tr("ICO_DATASOURCE_USE");
actionId = _salomeModule->createStandardAction(label,this,SLOT(OnUseInWorkspace()),icon);
_salomeModule->addActionInPopupMenu(actionId);
+
}
/**
* 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.
DatasourceEvent* event = new DatasourceEvent();
event->eventtype = DatasourceEvent::EVENT_ADD_DATASOURCE;
event->objectalias = filename;
- emit datasourceSignal(event);
+ emit datasourceSignal(event); // --> WorkspaceController::processDatasourceEvent()
+//#ifdef MED_WITH_QTTESTING
+// _dirtyAddDataSource = true;
+// while(_dirtyAddDataSource)
+// QApplication::processEvents();
+//#endif
}
+
// After above data source creation, python console emits a signal, forwarded by workspace, to update the GUI
void
DatasourceController::updateTreeViewWithNewDatasource(const MEDCALC::DatasourceHandler* datasourceHandler)
return;
}
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_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);
+
+//#ifdef MED_WITH_QTTESTING
+// _dirtyAddDataSource = false;
+//#endif
}
void DatasourceController::OnAddDatasource()
if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
anInitialPath = QDir::currentPath();
- QStringList filenames = SUIT_FileDlg::getOpenFileNames( _salomeModule->getApp()->desktop(),
+// QStringList filenames = SUIT_FileDlg::getOpenFileNames( _salomeModule->getApp()->desktop(),
+// anInitialPath,
+// filter,
+// tr("IMPORT_MED_FIELDS") );
+ // [ABN] the below to be compatible with QtTesting:
+ QStringList filenames = QFileDialog::getOpenFileNames( _salomeModule->getApp()->desktop(),
+ tr("IMPORT_MED_FIELDS"),
anInitialPath,
- filter,
- tr("IMPORT_MED_FIELDS") );
+ tr("FILE_FILTER_MED") );
if ( filenames.count() <= 0 ) return;
for ( QStringList::ConstIterator itFile = filenames.begin();
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());
DatasourceEvent* event = new DatasourceEvent();
event->eventtype = DatasourceEvent::EVENT_ADD_IMAGE_AS_DATASOURCE;
event->objectalias = imageFilename;
- emit datasourceSignal(event);
+ emit datasourceSignal(event); // --> WorkspaceController::processDatasourceEvent()
}
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; i<listOfSObject->size(); 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")
+ return;
// First retrieve the fieldseries id associated to this study object
- //long fieldseriesId = _studyEditor->getParameterInt(soFieldseries,FIELD_SERIES_ID);
- long fieldseriesId = _studyEditor->getParameterInt(soFieldseries,FIELD_ID);
+ 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;
+ }
+ long fieldseriesId = aParam->GetInt(FIELD_SERIES_ID);
STDLOG("Expand the field timeseries "<<fieldseriesId);
// If fieldseriesId equals -1, then it means that it is not a
_studyEditor->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 ) {
// <<<
SALOMEDS::SObject_var soField = listOfSObject->at(0);
-
- bool isInWorkspace = _studyEditor->getParameterBool(soField,IS_IN_WORKSPACE);
+ std::string name(_studyEditor->getName(soField));
+ if (soField->_is_nil() || name == "MEDCalc")
+ 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;
+ }
+ bool isInWorkspace = aParam->GetBool(IS_IN_WORKSPACE);
if ( isInWorkspace ) {
QMessageBox::warning(_salomeModule->getApp()->desktop(),
tr("Operation not allowed"),
return;
}
- int fieldId = _studyEditor->getParameterInt(soField,FIELD_ID);
+ if (! aParam->IsSet(FIELD_ID, PT_INTEGER))
+ return;
+ int fieldId = aParam->GetInt(FIELD_ID);
// If fieldId equals -1, then it means that it is not a field
// managed by the MED module, and we stop this function process.
dataObject->setFieldHandler(*fieldHandler);
event->objectdata = dataObject;
event->objectalias = alias;
- emit datasourceSignal(event);
+ emit datasourceSignal(event); // --> WorkspaceController::processDatasourceEvent()
// Tag the item to prevent double import
// _studyEditor->setParameterBool(soField,IS_IN_WORKSPACE,true);
// Tag the field as persistent on the server. It means that a
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; i<listOfSObject->size(); i++) {
+ for (int i=0; i<(int)listOfSObject->size(); i++) {
SALOMEDS::SObject_var soField = listOfSObject->at(i);
-
- bool isInWorkspace = _studyEditor->getParameterBool(soField,IS_IN_WORKSPACE);
+ 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;
+ }
+ bool isInWorkspace = aParam->GetBool(IS_IN_WORKSPACE);
if ( !isInWorkspace ) {
- int fieldId = _studyEditor->getParameterInt(soField,FIELD_ID);
+ if (! aParam->IsSet(FIELD_ID, PT_INTEGER))
+ continue;
+ int fieldId = aParam->GetInt(FIELD_ID);
MEDCALC::FieldHandler* fieldHandler =
MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
DatasourceEvent* event = new DatasourceEvent();
XmedDataObject* dataObject = new XmedDataObject();
dataObject->setFieldHandler(*fieldHandler);
event->objectdata = dataObject;
- emit datasourceSignal(event);
+ emit datasourceSignal(event); // --> WorkspaceController::processDatasourceEvent()
// Note that this signal is processed by the WorkspaceController
// Tag the item to prevent double import