From 6149e4228ca17b6cf365076867a332b933d39a25 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Thu, 25 Feb 2016 10:54:17 +0100 Subject: [PATCH] [MEDCalc] Manage color maps --- src/MEDCalc/cmp/MEDPresentation.cxx | 9 +++++ src/MEDCalc/cmp/MEDPresentation.hxx | 3 ++ src/MEDCalc/cmp/MEDPresentationScalarMap.cxx | 2 + src/MEDCalc/gui/MEDModule.cxx | 6 +++ src/MEDCalc/gui/MEDModule.hxx | 1 + src/MEDCalc/gui/MED_msg_en.ts | 16 ++++---- src/MEDCalc/gui/PresentationController.cxx | 6 +++ src/MEDCalc/gui/PresentationController.hxx | 1 + src/MEDCalc/gui/WorkspaceController.cxx | 38 ++++++++++++------- src/MEDCalc/gui/WorkspaceController.hxx | 1 + .../dialogs/WidgetPresentationParameters.cxx | 10 ++++- .../dialogs/WidgetPresentationParameters.hxx | 2 +- 12 files changed, 71 insertions(+), 24 deletions(-) diff --git a/src/MEDCalc/cmp/MEDPresentation.cxx b/src/MEDCalc/cmp/MEDPresentation.cxx index 4ae979910..09ce776ae 100644 --- a/src/MEDCalc/cmp/MEDPresentation.cxx +++ b/src/MEDCalc/cmp/MEDPresentation.cxx @@ -124,3 +124,12 @@ MEDPresentation::getRenderViewCommand(MEDCALC::MEDPresentationViewMode viewMode) cmd += std::string("__view1.ResetCamera();"); return cmd; } + +std::string +MEDPresentation::getColorMapCommand(MEDCALC::MEDPresentationColorMap colorMap) +{ + switch(colorMap) { + case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "Blue to Red Rainbow"; + case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "Cool to Warm"; + } +} diff --git a/src/MEDCalc/cmp/MEDPresentation.hxx b/src/MEDCalc/cmp/MEDPresentation.hxx index 480723a98..f9abab44b 100644 --- a/src/MEDCalc/cmp/MEDPresentation.hxx +++ b/src/MEDCalc/cmp/MEDPresentation.hxx @@ -50,11 +50,14 @@ protected: MEDPresentation(MEDPresentation::TypeID fieldHandlerId, std::string name); std::string getRenderViewCommand(MEDCALC::MEDPresentationViewMode viewMode); + std::string getColorMapCommand(MEDCALC::MEDPresentationColorMap colorMap); virtual void internalGeneratePipeline() = 0; PyObject * getPythonObjectFromMain(const char * var); void pushInternal(PyObject * obj, PyObject * disp = NULL); + MEDPresentation::TypeID getID() { return _fieldHandlerId; } + private: void generatePipeline(); // reserved to friend class MEDPresentationManager diff --git a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx index 58a99a553..17e9916e9 100644 --- a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx +++ b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx @@ -13,6 +13,8 @@ MEDPresentationScalarMap::internalGeneratePipeline() cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));"); cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);"); cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();"); + cmd += std::string("__lut = pvs.GetColorTransferFunction('")+_fieldName+std::string("');"); + cmd += std::string("__lut.ApplyPreset('")+getColorMapCommand(_params.colorMap)+std::string("',True);"); cmd += std::string("pvs.Render();"); //std::cerr << "Python command:" << std::endl; diff --git a/src/MEDCalc/gui/MEDModule.cxx b/src/MEDCalc/gui/MEDModule.cxx index 7d5770b6d..f5f091420 100644 --- a/src/MEDCalc/gui/MEDModule.cxx +++ b/src/MEDCalc/gui/MEDModule.cxx @@ -272,3 +272,9 @@ MEDModule::getSelectedViewMode() { return _presentationController->getSelectedViewMode(); } + +MEDCALC::MEDPresentationColorMap +MEDModule::getSelectedColorMap() +{ + return _presentationController->getSelectedColorMap(); +} diff --git a/src/MEDCalc/gui/MEDModule.hxx b/src/MEDCalc/gui/MEDModule.hxx index b0853c61d..97cf19888 100644 --- a/src/MEDCalc/gui/MEDModule.hxx +++ b/src/MEDCalc/gui/MEDModule.hxx @@ -75,6 +75,7 @@ public: const QString& rule="client='ObjectBrowser'"); MEDCALC::MEDPresentationViewMode getSelectedViewMode(); + MEDCALC::MEDPresentationColorMap getSelectedColorMap(); inline SALOME_AppStudyEditor* getStudyEditor() { return _studyEditor; } diff --git a/src/MEDCalc/gui/MED_msg_en.ts b/src/MEDCalc/gui/MED_msg_en.ts index 251b402ab..ba14c9e84 100644 --- a/src/MEDCalc/gui/MED_msg_en.ts +++ b/src/MEDCalc/gui/MED_msg_en.ts @@ -198,14 +198,6 @@ LAB_COLOR_MAP Color map: - - LAB_BLUE_TO_RED - Blue to red rainbow - - - LAB_COOL_TO_WARM - Cool to warm - DlgAlias @@ -524,5 +516,13 @@ LAB_VIEW_MODE_SPLIT_VIEW Split + + LAB_BLUE_TO_RED + Blue to red rainbow + + + LAB_COOL_TO_WARM + Cool to warm + diff --git a/src/MEDCalc/gui/PresentationController.cxx b/src/MEDCalc/gui/PresentationController.cxx index bd2b83058..b6cbe19c1 100644 --- a/src/MEDCalc/gui/PresentationController.cxx +++ b/src/MEDCalc/gui/PresentationController.cxx @@ -145,6 +145,12 @@ PresentationController::getSelectedViewMode() return _widgetPresentationParameters->getViewMode(); } +MEDCALC::MEDPresentationColorMap +PresentationController::getSelectedColorMap() +{ + return _widgetPresentationParameters->getColorMap(); +} + void PresentationController::visualize(PresentationEvent::EventType eventType) { diff --git a/src/MEDCalc/gui/PresentationController.hxx b/src/MEDCalc/gui/PresentationController.hxx index c4a1dacc7..19384c52f 100644 --- a/src/MEDCalc/gui/PresentationController.hxx +++ b/src/MEDCalc/gui/PresentationController.hxx @@ -58,6 +58,7 @@ public: void createActions(); MEDCALC::MEDPresentationViewMode getSelectedViewMode(); + MEDCALC::MEDPresentationColorMap getSelectedColorMap(); signals: void presentationSignal(const PresentationEvent*); diff --git a/src/MEDCalc/gui/WorkspaceController.cxx b/src/MEDCalc/gui/WorkspaceController.cxx index 5458ecb72..ec6f3e2b2 100644 --- a/src/MEDCalc/gui/WorkspaceController.cxx +++ b/src/MEDCalc/gui/WorkspaceController.cxx @@ -458,17 +458,6 @@ void WorkspaceController::_viewItemList(QStringList itemNameIdList) { _consoleDriver->exec(commands); } -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"; - } -} - /** * This slot can process the event coming from the * DatasourceController. The connection between the datasource signal @@ -527,6 +516,29 @@ void WorkspaceController::processDatasourceEvent(const DatasourceEvent* event) { STDLOG("The event "<eventtype<<" is not implemented yet"); } } + +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"; + } +} + +QString +WorkspaceController::_getColorMap() +{ + 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"; + } +} + /** * This slot can process the event coming from the * DatasourceController. The connection between the datasource signal @@ -553,10 +565,10 @@ void WorkspaceController::processPresentationEvent(const PresentationEvent* even QString viewMode = _getViewMode(); //QString displayedInfo = ; // from PresentationController combobox //QString scalarBarRange = ; // from PresentationController spinbox - //QString colorMap = ; // from PresentationController combobox + QString colorMap = _getColorMap(); MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler(); QStringList commands; - commands += QString("medcalc.MakeScalarMap(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); + commands += QString("medcalc.MakeScalarMap(accessField(%1), %2, colorMap=%3)").arg(fieldHandler->id).arg(viewMode).arg(colorMap); _consoleDriver->exec(commands); } else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) { diff --git a/src/MEDCalc/gui/WorkspaceController.hxx b/src/MEDCalc/gui/WorkspaceController.hxx index 876ae6eab..b53c73db5 100644 --- a/src/MEDCalc/gui/WorkspaceController.hxx +++ b/src/MEDCalc/gui/WorkspaceController.hxx @@ -78,6 +78,7 @@ private: void _removeItemList(QStringList itemNameIdList); void _viewItemList(QStringList itemNameIdList); QString _getViewMode(); + QString _getColorMap(); private: XmedConsoleDriver* _consoleDriver; diff --git a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx index 08823ca73..37e41391a 100644 --- a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx +++ b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx @@ -53,8 +53,14 @@ WidgetPresentationParameters::getScalarBarMaxVal() return this->ui.doubleSpinBoxMaxVal->value(); } -std::string +MEDCALC::MEDPresentationColorMap WidgetPresentationParameters::getColorMap() { - return this->ui.comboBoxColorMap->currentText().toStdString(); + QString colorMap = this->ui.comboBoxColorMap->currentText(); + if (colorMap == tr("LAB_BLUE_TO_RED")) { + return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW; + } + else if (colorMap == tr("LAB_COOL_TO_WARM")) { + return MEDCALC::COLOR_MAP_COOL_TO_WARM; + } } diff --git a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx index a8a971416..b605b03af 100644 --- a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx +++ b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx @@ -20,7 +20,7 @@ public: double getScalarBarTimestep(); double getScalarBarMinVal(); double getScalarBarMaxVal(); - std::string getColorMap(); + MEDCALC::MEDPresentationColorMap getColorMap(); private: Ui_WidgetPresentationParameters ui; // instance of the class defined in ui_WidgetPresentationParameters.h -- 2.30.2