From f0e817475ccff7327c791764646975f43ffb6943 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Mon, 7 Nov 2016 17:44:15 +0100 Subject: [PATCH] [MEDCalc] Use API from mesh support change and field interpolation --- idl/MEDEventListener.idl | 2 + src/MEDCalc/gui/ProcessingController.cxx | 59 +++++----------------- src/MEDCalc/gui/ProcessingController.hxx | 8 +-- src/MEDCalc/gui/WorkspaceController.cxx | 46 ++++++++++++------ src/MEDCalc/tui/CMakeLists.txt | 1 + src/MEDCalc/tui/__init__.py | 4 ++ src/MEDCalc/tui/medevents.py | 14 ++++-- src/MEDCalc/tui/medprocessing.py | 62 ++++++++++++++++++++++++ 8 files changed, 126 insertions(+), 70 deletions(-) create mode 100644 src/MEDCalc/tui/medprocessing.py diff --git a/idl/MEDEventListener.idl b/idl/MEDEventListener.idl index d53d6b1f3..547972966 100644 --- a/idl/MEDEventListener.idl +++ b/idl/MEDEventListener.idl @@ -36,6 +36,8 @@ module MEDCALC EVENT_ADD_PRESENTATION, EVENT_REMOVE_PRESENTATION, EVENT_MODIFY_PRESENTATION, + EVENT_CHANGE_UNDERLYING_MESH, + EVENT_INTERPOLATE_FIELD, EVENT_PLAY_TEST, EVENT_QUIT_SALOME, EVENT_ERROR, diff --git a/src/MEDCalc/gui/ProcessingController.cxx b/src/MEDCalc/gui/ProcessingController.cxx index d78eacd61..e6f8474c2 100644 --- a/src/MEDCalc/gui/ProcessingController.cxx +++ b/src/MEDCalc/gui/ProcessingController.cxx @@ -115,30 +115,16 @@ ProcessingController::OnChangeUnderlyingMesh() void ProcessingController::OnChangeUnderlyingMeshInputValidated() { + STDLOG("Change Underlying Mesh"); int meshId = _dlgChangeUnderlyingMesh->getMeshId(); STDLOG("meshId = " << ToString(meshId)); int fieldId = _dlgChangeUnderlyingMesh->getFieldId(); - MEDCALC::FieldHandler* fieldHandler = - MEDFactoryClient::getDataManager()->getFieldHandler(fieldId); - // We don't modify the original field but create first a duplicate - MEDCALC::FieldHandler* duplicate = MEDFactoryClient::getCalculator()->dup(*fieldHandler); - MEDFactoryClient::getDataManager()->changeUnderlyingMesh(duplicate->id, meshId); - - // Request once more the duplicate to update the meta-data on this - // client side - duplicate = MEDFactoryClient::getDataManager()->getFieldHandler(duplicate->id); - - // >>> - // WARN: the following is a temporary code for test purpose - // Automatically add in ws ProcessingEvent* event = new ProcessingEvent(); - event->eventtype = ProcessingEvent::EVENT_IMPORT_OBJECT; - XmedDataObject* dataObject = new XmedDataObject(); - dataObject->setFieldHandler(*duplicate); - event->objectdata = dataObject; - emit processingSignal(event); - // Note that this signal is processed by the WorkspaceController + event->eventtype = ProcessingEvent::EVENT_CHANGE_UNDERLYING_MESH; + event->fieldId = fieldId; + event->meshId = meshId; + emit processingSignal(event); // --> WorkspaceController::processProcessingEvent() // Tag the item to prevent double import //_studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true); @@ -180,6 +166,7 @@ ProcessingController::OnInterpolateField() void ProcessingController::OnInterpolateFieldInputValidated() { + STDLOG("Interpolate Field"); MEDCALC::InterpolationParameters params; params.precision = _dlgInterpolateField->getPrecision(); STDLOG("precision = " << params.precision); @@ -197,37 +184,13 @@ ProcessingController::OnInterpolateFieldInputValidated() int meshId = _dlgInterpolateField->getMeshId(); STDLOG("meshId = " << ToString(meshId)); int fieldId = _dlgInterpolateField->getFieldId(); - MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId); - - // We don't modify the original field but create first a duplicate - // MEDCALC::FieldHandler* duplicate = MEDFactoryClient::getCalculator()->dup(*fieldHandler); - //MEDFactoryClient::getDataManager()->changeUnderlyingMesh(duplicate->id, meshId); - MEDCALC::FieldHandler* result = NULL; - try { - result = MEDFactoryClient::getDataManager()->interpolateField(fieldId, meshId, params); - } - catch(...) { - STDLOG("Unable to process field interpolation; please check interpolation parameters"); - QMessageBox::critical(_salomeModule->getApp()->desktop(), - tr("Operation failed"), - tr("Unable to process field interpolation; please check interpolation parameters")); - return; - } - - // Request once more the duplicate to update the meta-data on this - // client side - // duplicate = MEDFactoryClient::getDataManager()->getFieldHandler(duplicate->id); - // >>> - // WARN: the following is a temporary code for test purpose - // Automatically add in ws ProcessingEvent* event = new ProcessingEvent(); - event->eventtype = ProcessingEvent::EVENT_IMPORT_OBJECT; - XmedDataObject* dataObject = new XmedDataObject(); - dataObject->setFieldHandler(*result); - event->objectdata = dataObject; - emit processingSignal(event); - // Note that this signal is processed by the WorkspaceController + event->eventtype = ProcessingEvent::EVENT_INTERPOLATE_FIELD; + event->fieldId = fieldId; + event->meshId = meshId; + event->interpParams = params; + emit processingSignal(event); // --> WorkspaceController::processProcessingEvent() // // Tag the item to prevent double import // //_studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true); diff --git a/src/MEDCalc/gui/ProcessingController.hxx b/src/MEDCalc/gui/ProcessingController.hxx index 0dd9478c2..0683e1696 100644 --- a/src/MEDCalc/gui/ProcessingController.hxx +++ b/src/MEDCalc/gui/ProcessingController.hxx @@ -37,11 +37,13 @@ typedef struct { enum EventType { EVENT_IMPORT_OBJECT, - EVENT_PROCESS_INTERPOLATE_FIELD, - EVENT_PROCESS_CHANGE_UNDERLYING_MESH + EVENT_INTERPOLATE_FIELD, + EVENT_CHANGE_UNDERLYING_MESH }; int eventtype; - XmedDataObject* objectdata; + int fieldId; + int meshId; + MEDCALC::InterpolationParameters interpParams; } ProcessingEvent; class MEDModule; diff --git a/src/MEDCalc/gui/WorkspaceController.cxx b/src/MEDCalc/gui/WorkspaceController.cxx index a2c442aa4..67eaa1486 100644 --- a/src/MEDCalc/gui/WorkspaceController.cxx +++ b/src/MEDCalc/gui/WorkspaceController.cxx @@ -317,6 +317,20 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent* event) { else if ( event->type == MEDCALC::EVENT_MODIFY_PRESENTATION ) { emit workspaceSignal(event); // forward to PresentationController } + else if ( event->type == MEDCALC::EVENT_CHANGE_UNDERLYING_MESH + || event->type == MEDCALC::EVENT_INTERPOLATE_FIELD ) { + int fieldId = event->dataId; + MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId); + XmedDataObject* dataObject = new XmedDataObject(); + dataObject->setFieldHandler(*fieldHandler); + std::cout << "IMPORT object in workspace: " << dataObject->toString() << std::endl; + STDLOG("IMPORT object in workspace:\n"<toString()); + // _GBO_ QUESTION: tag automatically the object as a peristant object ?? + // We first add the data object to the internal data model + dataModel->addDataObject(dataObject); + // Then we request the tree view to consider this new object + this->getDataTreeModel()->addData(dataObject); + } else if ( event->type == MEDCALC::EVENT_PLAY_TEST ) { emit workspaceSignal(event); // forward to TestController } @@ -554,23 +568,25 @@ WorkspaceController::processProcessingEvent(const ProcessingEvent* event) return; } - // >>> - // __GBO__ To know what to do we should test the type, because the - // object could be a mesh, a timeseries or a single field. We test - // here the case of a single field. Moreover, there could have - // options such that "change the underlying mesh". - // <<< + int fieldId = event->fieldId; + int meshId = event->meshId; - XmedDataObject* dataObject = event->objectdata; + if ( event->eventtype == ProcessingEvent::EVENT_CHANGE_UNDERLYING_MESH ) { + QStringList commands; + commands += QString("result_id = medcalc.ChangeUnderlyingMesh(fieldId=%1,meshId=%2)").arg(fieldId).arg(meshId); + commands += QString("result_id"); + _consoleDriver->exec(commands); + } + else if ( event->eventtype == ProcessingEvent::EVENT_INTERPOLATE_FIELD ) { + MEDCALC::InterpolationParameters params = event->interpParams; + QString method = QString(params.method); + QString nature = QString(params.nature); + QString intersectionType = QString(params.intersectionType); - if ( event->eventtype == ProcessingEvent::EVENT_IMPORT_OBJECT ) { - std::cout << "IMPORT object in workspace: " << dataObject->toString() << std::endl; - STDLOG("IMPORT object in workspace:\n"<toString()); - // _GBO_ QUESTION: tag automatically the object as a peristant object ?? - // We first add the data object to the internal data model - dataModel->addDataObject(dataObject); - // Then we request the tree view to consider this new object - this->getDataTreeModel()->addData(dataObject); + QStringList commands; + commands += QString("result_id = medcalc.InterpolateField(fieldId=%1,meshId=%2,precision=%3,defaultValue=%4,reverse=%5,method='%6',nature='%7',intersectionType='%8')").arg(fieldId).arg(meshId).arg(params.precision).arg(params.defaultValue).arg(params.reverse).arg(method).arg(nature).arg(intersectionType); + commands += QString("result_id"); + _consoleDriver->exec(commands); } } diff --git a/src/MEDCalc/tui/CMakeLists.txt b/src/MEDCalc/tui/CMakeLists.txt index ba1b5b810..52e943865 100644 --- a/src/MEDCalc/tui/CMakeLists.txt +++ b/src/MEDCalc/tui/CMakeLists.txt @@ -26,6 +26,7 @@ SET(PYFILES_TO_INSTALL medimages.py medio.py medpresentation.py + medprocessing.py medtest.py ) diff --git a/src/MEDCalc/tui/__init__.py b/src/MEDCalc/tui/__init__.py index 71845ab46..7b3ce7cbb 100644 --- a/src/MEDCalc/tui/__init__.py +++ b/src/MEDCalc/tui/__init__.py @@ -65,6 +65,10 @@ from medpresentation import UpdateDeflectionShape from medpresentation import ComputeCellAverageSize, GetDomainCenter, GetSliceOrigins, SelectSourceField +# Processing +from medprocessing import ChangeUnderlyingMesh +from medprocessing import InterpolateField + # Console commands import medconsole diff --git a/src/MEDCalc/tui/medevents.py b/src/MEDCalc/tui/medevents.py index 2e17a3710..26d394646 100644 --- a/src/MEDCalc/tui/medevents.py +++ b/src/MEDCalc/tui/medevents.py @@ -118,14 +118,20 @@ def notifyGui_addPresentation(fieldId, presId): def notifyGui_removePresentation(presId): __notifyGui(MEDCALC.EVENT_REMOVE_PRESENTATION, presentationId=presId) # +def notifyGui_modifyPresentation(presId): + __notifyGui(MEDCALC.EVENT_MODIFY_PRESENTATION, presentationId=presId) + def notifyGui_playQtTestingScenario(filename): __notifyGui(MEDCALC.EVENT_PLAY_TEST, filename=filename) # def notifyGui_termination(): __notifyGui(MEDCALC.EVENT_QUIT_SALOME) - + def notifyGui_error(msg): __notifyGui(MEDCALC.EVENT_ERROR, msg=msg) - -def notifyGui_modifyPresentation(presId): - __notifyGui(MEDCALC.EVENT_MODIFY_PRESENTATION, presentationId=presId) + +def notifyGui_changeUnderlyingMesh(fieldId): + __notifyGui(MEDCALC.EVENT_CHANGE_UNDERLYING_MESH, dataId=fieldId) + +def notifyGui_interpolateField(fieldId): + __notifyGui(MEDCALC.EVENT_INTERPOLATE_FIELD, dataId=fieldId) diff --git a/src/MEDCalc/tui/medprocessing.py b/src/MEDCalc/tui/medprocessing.py new file mode 100644 index 000000000..3501e6084 --- /dev/null +++ b/src/MEDCalc/tui/medprocessing.py @@ -0,0 +1,62 @@ +# Copyright (C) 2011-2016 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 +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import medcalc +import MEDCALC +import SALOME +from medcalc.medevents import notifyGui_error + + +def ChangeUnderlyingMesh(fieldId, meshId): + try: + dataManager = medcalc.medcorba.factory.getDataManager() + fieldHandler = dataManager.getFieldHandler(fieldId) + + # We don't modify the original field but create first a duplicate + duplicate = medcalc.medcorba.factory.getCalculator().dup(fieldHandler) + dataManager.changeUnderlyingMesh(duplicate.id, meshId) + + from medcalc.medevents import notifyGui_changeUnderlyingMesh + notifyGui_changeUnderlyingMesh(duplicate.id) + return duplicate.id + except SALOME.SALOME_Exception as e: + notifyGui_error("An error occured while changing underlying mesh:\n" + e.details.text) + raise Exception(e.details.text) +# + +def InterpolateField(fieldId, + meshId, + precision, + defaultValue, + reverse, + method, + nature, + intersectionType + ): + params = MEDCALC.InterpolationParameters(precision, defaultValue, reverse, method, nature, intersectionType) + try: + dataManager = medcalc.medcorba.factory.getDataManager() + fieldHandler = dataManager.interpolateField(fieldId, meshId, params) + from medcalc.medevents import notifyGui_interpolateField + notifyGui_interpolateField(fieldHandler.id) + return fieldHandler.id + except SALOME.SALOME_Exception as e: + notifyGui_error("An error occured while interpolating field:\n" + e.details.text) + raise Exception(e.details.text) +# -- 2.39.2