X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCalc%2Fgui%2FWorkspaceController.cxx;h=97235c63a3b8835eb735044ade2eb46aee44912e;hb=aec2051b4624c4fdc835a901e30a4b7801022af5;hp=10de8f6a61843e138775e8b21edea9b9e3b5f8ca;hpb=57fc62a13c7222e72ff89fa54e10b1215c20831c;p=modules%2Fmed.git diff --git a/src/MEDCalc/gui/WorkspaceController.cxx b/src/MEDCalc/gui/WorkspaceController.cxx index 10de8f6a6..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 @@ -35,6 +35,13 @@ #include #include +#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 @@ -223,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 @@ -311,7 +318,51 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent* event) { else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) { emit workspaceSignal(event); // forward to PresentationController } + 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 + } + else if ( event->type == MEDCALC::EVENT_QUIT_SALOME ) { + emit workspaceSignal(event); // forward to TestController + } + else if ( event->type == MEDCALC::EVENT_ERROR ) { + std::string msg(event->msg); + QMessageBox::warning(_salomeModule->getApp()->desktop(), "Error", QString::fromStdString(msg)); + } + else + STDLOG("WorkspaceController::processMedEvent(): Unhandled event!!!"); } /*! @@ -418,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); } @@ -457,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); } @@ -510,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; @@ -522,140 +579,35 @@ void WorkspaceController::processDatasourceEvent(const DatasourceEvent* event) { } } -QString -WorkspaceController::_getViewMode() -{ - MEDCALC::MEDPresentationViewMode viewMode = _salomeModule->getSelectedViewMode(); - switch(viewMode) { - case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE"; - case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP"; - case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT"; - case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW"; - } - return QString(); -} - -QString -WorkspaceController::_getColorMap() +void +WorkspaceController::processProcessingEvent(const ProcessingEvent* event) { - MEDCALC::MEDPresentationColorMap colorMap = _salomeModule->getSelectedColorMap(); - switch(colorMap) { - case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW"; - case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM"; - } - return QString(); -} - -/** - * This slot can process the event coming from the - * DatasourceController. The connection between the datasource signal - * and this slot is realized by the main class MEDModule. - */ -void WorkspaceController::processPresentationEvent(const PresentationEvent* event) { XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel(); if ( dataModel == NULL ) { STDLOG("No data model associated to this tree view"); 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; - - // --> Send commands to SALOME Python console - if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) { - QString viewMode = _getViewMode(); - //QString displayedInfo = ; // from PresentationController combobox - //QString scalarBarRange = ; // from PresentationController spinbox - QString colorMap = _getColorMap(); - MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler(); - QStringList commands; - commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(%1), %2, colorMap=%3)").arg(fieldHandler->id).arg(viewMode).arg(colorMap); - commands += QString("presentation_id"); - _consoleDriver->exec(commands); - } - else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) { - QString viewMode = _getViewMode(); - MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler(); + if ( event->eventtype == ProcessingEvent::EVENT_CHANGE_UNDERLYING_MESH ) { QStringList commands; - commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); - commands += QString("presentation_id"); - _consoleDriver->exec(commands); - } - else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) { - QString viewMode = _getViewMode(); - MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler(); - QStringList commands; - commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); - commands += QString("presentation_id"); - _consoleDriver->exec(commands); - } - else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) { - QString viewMode = _getViewMode(); - MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler(); - QStringList commands; - commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); - commands += QString("presentation_id"); - _consoleDriver->exec(commands); - } - else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) { - QString viewMode = _getViewMode(); - MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler(); - QStringList commands; - commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); - commands += QString("presentation_id"); + 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 == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) { - QString viewMode = _getViewMode(); - MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler(); + 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); + QStringList commands; - commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); - commands += QString("presentation_id"); + 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); } - else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) { - QStringList commands; - commands += QString("medcalc.RemovePresentation(%1)").arg(dataObject->getPresentationId()); - _consoleDriver->exec(commands); - } - else { - STDLOG("The event "<eventtype<<" is not implemented yet"); - } -} - -void -WorkspaceController::processProcessingEvent(const ProcessingEvent* event) -{ - XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel(); - if ( dataModel == NULL ) { - STDLOG("No data model associated to this tree view"); - 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". - // <<< - - XmedDataObject* dataObject = event->objectdata; - - 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); - } } void WorkspaceController::OnSaveWorkspace() {