X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCalc%2Fgui%2FWorkspaceController.cxx;h=97235c63a3b8835eb735044ade2eb46aee44912e;hb=aec2051b4624c4fdc835a901e30a4b7801022af5;hp=dd59a244776e709b9d1a9052e1951f3ac087960f;hpb=3304fa52c5fddf724af1eafe419d9686454d3f98;p=modules%2Fmed.git diff --git a/src/MEDCalc/gui/WorkspaceController.cxx b/src/MEDCalc/gui/WorkspaceController.cxx index dd59a2447..97235c63a 100644 --- a/src/MEDCalc/gui/WorkspaceController.cxx +++ b/src/MEDCalc/gui/WorkspaceController.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D +// Copyright (C) 2007-2019 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 @@ -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 @@ -226,8 +230,8 @@ void WorkspaceController::_importFieldIntoConsole(MEDCALC::FieldHandler* fieldHa effectiveAlias = new QString(alias); } - // We can propose to the user to specify some additionnal - // informations concerning what must be imported. + // We can propose to the user to specify some additional + // information concerning what must be imported. // // In this version, we just ask the alias the field will be // manipulated with. The default alias is the field name. This alias @@ -317,6 +321,36 @@ 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); + + // Workaround to visualize the result + MEDCouplingFieldDouble* fieldDouble = MEDDataManager_i::getInstance()->getFieldDouble(fieldHandler); + std::string filename = std::tmpnam(NULL); + 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 } @@ -435,7 +469,7 @@ void WorkspaceController::_exportItemList(QStringList itemNameIdList) { .arg(fieldHandler->type) .arg(fieldHandler->iteration); */ - commands += "print 'Not implemented yet'"; + commands += "print('Not implemented yet')"; _consoleDriver->exec(commands); } @@ -474,7 +508,7 @@ void WorkspaceController::_viewItemList(QStringList itemNameIdList) { // generate the scalar map on this field. QStringList commands; //commands+=QString("view(accessField(%1))").arg(fieldHandler->id); - commands += "print 'Not implemented yet'"; + commands += "print('Not implemented yet')"; _consoleDriver->exec(commands); } @@ -527,6 +561,12 @@ void WorkspaceController::processDatasourceEvent(const DatasourceEvent* event) { commands += QString("source_id = medcalc.LoadDataSource('%1')").arg(event->objectalias); commands += QString("source_id"); _consoleDriver->exec(commands); + + // Create a default presentation when loading a file + MEDCALC::MedEvent* evt = new MEDCALC::MedEvent(); + evt->type = MEDCALC::EVENT_ADD_PRESENTATION; + evt->dataId = -1; + emit workspaceSignal(evt); // forward to PresentationController } else if ( event->eventtype == DatasourceEvent::EVENT_ADD_IMAGE_AS_DATASOURCE ) { QStringList commands; @@ -548,23 +588,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); } }