From 3dd1c7e83cb79b658d6ffaab8d818b2d6263927f Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Wed, 9 Nov 2016 16:40:09 +0100 Subject: [PATCH] [MEDCalc] Visualize result of mesh support change and field interpolation --- src/MEDCalc/gui/MEDModule.cxx | 16 +++++++ src/MEDCalc/gui/MEDModule.hxx | 4 +- src/MEDCalc/gui/PresentationController.cxx | 28 +++-------- src/MEDCalc/gui/PresentationController.hxx | 2 - src/MEDCalc/gui/ProcessingController.cxx | 56 +++++++++++++++------- src/MEDCalc/gui/WorkspaceController.cxx | 20 ++++++++ src/MEDCalc/tui/__init__.py | 5 +- src/MEDCalc/tui/medio.py | 12 +++++ 8 files changed, 99 insertions(+), 44 deletions(-) diff --git a/src/MEDCalc/gui/MEDModule.cxx b/src/MEDCalc/gui/MEDModule.cxx index d7fe92a03..ebadeaa4e 100644 --- a/src/MEDCalc/gui/MEDModule.cxx +++ b/src/MEDCalc/gui/MEDModule.cxx @@ -487,3 +487,19 @@ MEDModule::requestSALOMETermination() const //{ // return _eventLoopStarted; //} + +int +MEDModule::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char* name) +{ + if (obj->_is_nil()) + return -1; + + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::AttributeParameter_var aParam; + if ( obj->FindAttribute(anAttr,"AttributeParameter") ) { + aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); + if (aParam->IsSet(name, PT_INTEGER)) + return aParam->GetInt(name); + } + return -1; +} diff --git a/src/MEDCalc/gui/MEDModule.hxx b/src/MEDCalc/gui/MEDModule.hxx index fa38c1790..7d7fab55f 100644 --- a/src/MEDCalc/gui/MEDModule.hxx +++ b/src/MEDCalc/gui/MEDModule.hxx @@ -87,7 +87,9 @@ public: inline SALOME_AppStudyEditor* getStudyEditor() { return _studyEditor; } void requestSALOMETermination() const; - bool itemClickGeneric(std::string & name, std::string & type, int & presId) const; + bool itemClickGeneric(std::string& name, std::string& type, int& presId) const; + + int getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char* name); signals: void presentationSelected(int presId, const QString& presType, const QString& presName); diff --git a/src/MEDCalc/gui/PresentationController.cxx b/src/MEDCalc/gui/PresentationController.cxx index c0fd9bce4..77b517613 100644 --- a/src/MEDCalc/gui/PresentationController.cxx +++ b/src/MEDCalc/gui/PresentationController.cxx @@ -110,22 +110,6 @@ PresentationController::~PresentationController() delete((*it).second); } -int -PresentationController::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char * name) -{ - if (obj->_is_nil()) - return -1; - - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeParameter_var aParam; - if ( obj->FindAttribute(anAttr,"AttributeParameter") ) { - aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); - if (aParam->IsSet(name, PT_INTEGER)) - return aParam->GetInt(name); - } - return -1; -} - std::string PresentationController::_getIconName(const std::string& name) { @@ -314,8 +298,8 @@ PresentationController::visualize(PresentationEvent::EventType eventType) if (soObj->_is_nil() || name == "MEDCalc") return; - int fieldId = getIntParamFromStudyEditor(soObj, FIELD_ID); - int meshId = getIntParamFromStudyEditor(soObj, MESH_ID); + int fieldId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_ID); + int meshId = _salomeModule->getIntParamFromStudyEditor(soObj, MESH_ID); MEDCALC::FieldHandler* fieldHandler = 0; MEDCALC::MeshHandler* meshHandler = 0; @@ -328,9 +312,9 @@ PresentationController::visualize(PresentationEvent::EventType eventType) } else { - if (fieldId < 0) // is it a field serie ? + if (fieldId < 0) // is it a field series? { - int fieldSeriesId = getIntParamFromStudyEditor(soObj, FIELD_SERIES_ID); + int fieldSeriesId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_SERIES_ID); // If fieldId and fieldSeriesId equals -1, then it means that it is not a field // managed by the MED module, and we stop this function process. if ( fieldSeriesId < 0) @@ -418,7 +402,7 @@ PresentationController::onDeletePresentation() std::string name(_studyEditor->getName(soPres)); if (soPres->_is_nil() || name == "MEDCalc") return; - int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID); + int presId = _salomeModule->getIntParamFromStudyEditor(soPres,PRESENTATION_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. if ( presId < 0 ) @@ -676,7 +660,7 @@ PresentationController::onParavisDump() std::string name(_studyEditor->getName(soPres)); if (soPres->_is_nil() || name == "MEDCalc") return; - int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID); + int presId = _salomeModule->getIntParamFromStudyEditor(soPres,PRESENTATION_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. if ( presId < 0 ) diff --git a/src/MEDCalc/gui/PresentationController.hxx b/src/MEDCalc/gui/PresentationController.hxx index 0c187e562..7faa1a4dc 100644 --- a/src/MEDCalc/gui/PresentationController.hxx +++ b/src/MEDCalc/gui/PresentationController.hxx @@ -86,8 +86,6 @@ private: MEDWidgetHelper * findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string& type, const std::string& name); - int getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char * name); - QString getViewModePython() const; QString getColorMapPython() const; QString getScalarBarRangePython() const; diff --git a/src/MEDCalc/gui/ProcessingController.cxx b/src/MEDCalc/gui/ProcessingController.cxx index e6f8474c2..9c4a22309 100644 --- a/src/MEDCalc/gui/ProcessingController.cxx +++ b/src/MEDCalc/gui/ProcessingController.cxx @@ -90,18 +90,28 @@ ProcessingController::OnChangeUnderlyingMesh() // item must be selected. SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects(); if ( listOfSObject->size() > 0 ) { - SALOMEDS::SObject_var soField = listOfSObject->at(0); - std::string name(_studyEditor->getName(soField)); - if (soField->_is_nil() || name == "MEDCalc") + SALOMEDS::SObject_var soObj = listOfSObject->at(0); + std::string name(_studyEditor->getName(soObj)); + if (soObj->_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(FIELD_SERIES_ID, PT_INTEGER)) + + int fieldId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_ID); + if (fieldId < 0) { // is it a field series? + int fieldSeriesId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_SERIES_ID); + // If fieldId and fieldSeriesId equals -1, then it means that it is not a field + // managed by the MED module, and we stop this function process. + if ( fieldSeriesId < 0) + return; + MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId); + if (fieldHandlerList->length() < 0) + return; + // For a field series, get the first real field entry: + MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0]; + fieldId = fieldHandler.id; + if (fieldId < 0) return; } - int fieldId = aParam->GetInt(FIELD_SERIES_ID); + // _GBO_ : the dialog should not be modal, so that we can choose a // mesh in the browser. Then we have to emit a signal from the // dialog.accept, connected to a slot of the DatasourceControler @@ -141,18 +151,28 @@ ProcessingController::OnInterpolateField() // item must be selected. SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects(); if ( listOfSObject->size() > 0 ) { - SALOMEDS::SObject_var soField = listOfSObject->at(0); - std::string name(_studyEditor->getName(soField)); - if (soField->_is_nil() || name == "MEDCalc") + SALOMEDS::SObject_var soObj = listOfSObject->at(0); + std::string name(_studyEditor->getName(soObj)); + if (soObj->_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(FIELD_SERIES_ID, PT_INTEGER)) + + int fieldId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_ID); + if (fieldId < 0) { // is it a field series? + int fieldSeriesId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_SERIES_ID); + // If fieldId and fieldSeriesId equals -1, then it means that it is not a field + // managed by the MED module, and we stop this function process. + if ( fieldSeriesId < 0) + return; + MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId); + if (fieldHandlerList->length() < 0) + return; + // For a field series, get the first real field entry: + MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0]; + fieldId = fieldHandler.id; + if (fieldId < 0) return; } - int fieldId = aParam->GetInt(FIELD_SERIES_ID); + // _GBO_ : the dialog should not be modal, so that we can choose a // mesh in the browser. Then we have to emit a signal from the // dialog.accept, connected to a slot of the DatasourceControler diff --git a/src/MEDCalc/gui/WorkspaceController.cxx b/src/MEDCalc/gui/WorkspaceController.cxx index 67eaa1486..a29685830 100644 --- a/src/MEDCalc/gui/WorkspaceController.cxx +++ b/src/MEDCalc/gui/WorkspaceController.cxx @@ -38,6 +38,10 @@ #include #include +#include "MEDLoader.hxx" +using namespace MEDCoupling; +#include "MEDDataManager_i.hxx" + /*! * This class defines a DockWidget plugged in the SALOME application, * and containing a tree view for rendering a hierarchical data @@ -330,6 +334,22 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent* event) { dataModel->addDataObject(dataObject); // Then we request the tree view to consider this new object this->getDataTreeModel()->addData(dataObject); + + // Workaround to visualize the result + MEDCouplingFieldDouble* fieldDouble = MEDDataManager_i::getInstance()->getFieldDouble(fieldHandler); + std::string filename = std::tmpnam(nullptr); + WriteField(filename.c_str(), fieldDouble, true); + + QStringList commands; + commands += QString("source_id = medcalc.LoadDataSource('%1')").arg(filename.c_str()); + commands += QString("source_id"); + commands += QString("mesh_id = medcalc.GetFirstMeshFromDataSource(source_id)"); + commands += QString("mesh_id"); + commands += QString("field_id = medcalc.GetFirstFieldFromMesh(mesh_id)"); + commands += QString("field_id"); + commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(field_id), viewMode=MEDCALC.VIEW_MODE_NEW_LAYOUT)"); + commands += QString("presentation_id"); + _consoleDriver->exec(commands); } else if ( event->type == MEDCALC::EVENT_PLAY_TEST ) { emit workspaceSignal(event); // forward to TestController diff --git a/src/MEDCalc/tui/__init__.py b/src/MEDCalc/tui/__init__.py index 7b3ce7cbb..149d37762 100644 --- a/src/MEDCalc/tui/__init__.py +++ b/src/MEDCalc/tui/__init__.py @@ -35,7 +35,10 @@ import medevents from fieldproxy import newFieldProxy, FieldProxy # Input/Output -from medio import LoadDataSource, LoadImageAsDataSource, GetFirstMeshFromDataSource +from medio import LoadDataSource +from medio import LoadImageAsDataSource +from medio import GetFirstMeshFromDataSource +from medio import GetFirstFieldFromMesh # Presentations from medpresentation import MakeMeshView diff --git a/src/MEDCalc/tui/medio.py b/src/MEDCalc/tui/medio.py index 013842d04..df59c1ba5 100644 --- a/src/MEDCalc/tui/medio.py +++ b/src/MEDCalc/tui/medio.py @@ -46,3 +46,15 @@ def GetFirstMeshFromDataSource(datasource_id): if not len(handlerLst): return -1 return handlerLst[0].id +# + +def GetFirstFieldFromMesh(mesh_id): + dataManager = medcalc.medcorba.factory.getDataManager() + series = dataManager.getFieldseriesListOnMesh(mesh_id) + if not len(series): + return -1 + fields = dataManager.getFieldListInFieldseries(series[0].id) + if not len(fields): + return -1 + return fields[0].id +# -- 2.39.2