]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
[MEDCalc] Use API from mesh support change and field interpolation
authorCédric Aguerre <cedric.aguerre@edf.fr>
Mon, 7 Nov 2016 16:44:15 +0000 (17:44 +0100)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Mon, 7 Nov 2016 16:54:17 +0000 (17:54 +0100)
idl/MEDEventListener.idl
src/MEDCalc/gui/ProcessingController.cxx
src/MEDCalc/gui/ProcessingController.hxx
src/MEDCalc/gui/WorkspaceController.cxx
src/MEDCalc/tui/CMakeLists.txt
src/MEDCalc/tui/__init__.py
src/MEDCalc/tui/medevents.py
src/MEDCalc/tui/medprocessing.py [new file with mode: 0644]

index d53d6b1f3dbe4066ace61622b6979752ce542a98..5479729664f20447d8530a7ddadb45024e04b7f1 100644 (file)
@@ -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,
index d78eacd61f4fa7395470bfa3abff3ae4df7088bf..e6f8474c2c9804e5ec7f142b5f69462c2ebd6b67 100644 (file)
@@ -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);
index 0dd9478c24408b4094a5750998d509d988829667..0683e1696b449ba7de0340c108bdf68facac3f28 100644 (file)
 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;
index a2c442aa4b68e7a8644f7da7b01b325d252e8482..67eaa1486470f67eedbfe896c2370a5f07eae1b4 100644 (file)
@@ -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"<<dataObject->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"<<dataObject->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);
   }
 }
 
index ba1b5b810a0b39cca2b5fb8905ae433d15418bbf..52e94386524dd94d4b8dbf2a3b21d7ecb26c0ac7 100644 (file)
@@ -26,6 +26,7 @@ SET(PYFILES_TO_INSTALL
   medimages.py
   medio.py
   medpresentation.py
+  medprocessing.py
   medtest.py
   )
 
index 71845ab4650937515ec93c00018c9c2a4f8b90c0..7b3ce7cbbd428889aaa53732c749eaa273ff7c05 100644 (file)
@@ -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
 
index 2e17a37100f72789bad4db8f17573d8b4490aa74..26d394646c2b8da098444b5b065f56c16b8da8f4 100644 (file)
@@ -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 (file)
index 0000000..3501e60
--- /dev/null
@@ -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)
+#