From: abn Date: Wed, 27 Jul 2016 09:27:00 +0000 (+0200) Subject: [MEDCalc] Fully functional scalar map (other pres deactivated) X-Git-Tag: V8_1_0b1~19 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=66cadb9dc3ae762594c248a2c407914fa0e39325;p=modules%2Fmed.git [MEDCalc] Fully functional scalar map (other pres deactivated) + color map, scalar bar range, component can be edited + low level ParaVis dump available --- diff --git a/idl/MEDPresentationManager.idl b/idl/MEDPresentationManager.idl index c3e100225..4007aa8d5 100644 --- a/idl/MEDPresentationManager.idl +++ b/idl/MEDPresentationManager.idl @@ -39,16 +39,23 @@ module MEDCALC COLOR_MAP_COOL_TO_WARM }; - struct ScalarBarRange { - // (valMin,valMax) defines the scalar bar range from: - // (-1,timetep): the field values at the chosen timestep - // (-1,-1): the field values across all timesteps - // (start,end): a user-input range of values - long valMin; - long valMax; + enum MEDPresentationScalarBarRange { + SCALAR_BAR_ALL_TIMESTEPS, + SCALAR_BAR_CURRENT_TIMESTEP }; - const string DISPLAY_EUCLIDEAN_NORM = "Euclidean norm"; + +// struct ScalarBarRange { +// // (valMin,valMax) defines the scalar bar range from: +// // (-1,timestep): the field values at the chosen timestep +// // (-1,-1): the field values across all timesteps +// // (-2,-2): the field values at current timestep +// // (start,end): a user-input range of values +// long valMin; +// long valMax; +// }; + + const string DISPLAY_EUCLIDEAN_NORM = ""; // Void string to avoid clash with a real component name -- never used actually? enum SliceOrientation { SLICE_NORMAL_TO_X, @@ -64,6 +71,7 @@ module MEDCALC const MEDPresentationViewMode VIEW_MODE_DEFAULT = VIEW_MODE_REPLACE; const MEDPresentationColorMap COLOR_MAP_DEFAULT = COLOR_MAP_BLUE_TO_RED_RAINBOW; + const MEDPresentationScalarBarRange SCALAR_BAR_RANGE_DEFAULT = SCALAR_BAR_ALL_TIMESTEPS; //const ScalarBarRange SCALAR_BAR_RANGE_DEFAULT = ; const long SCALAR_BAR_RANGE_VAL_MIN_DEFAULT = -1; const long SCALAR_BAR_RANGE_VAL_MAX_DEFAULT = -1; @@ -76,77 +84,76 @@ module MEDCALC struct ScalarMapParameters { long fieldHandlerId; - MEDPresentationViewMode viewMode; - string displayedInfo; // DISPLAY_EUCLIDEAN_NORM or any field name - ScalarBarRange sbRange; + string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name + MEDPresentationScalarBarRange scalarBarRange; MEDPresentationColorMap colorMap; }; // A contour is an isoline in 2D and an isosurface in 3D - struct ContourParameters { - long fieldHandlerId; - MEDPresentationViewMode viewMode; - string displayedInfo; // DISPLAY_EUCLIDEAN_NORM or any field name - ScalarBarRange sbRange; - MEDPresentationColorMap colorMap; - long nbContours; - }; - - struct VectorFieldParameters { - long fieldHandlerId; - MEDPresentationViewMode viewMode; - }; - - struct SlicesParameters { - long fieldHandlerId; - MEDPresentationViewMode viewMode; - SliceOrientation orientation; - long nbSlices; - }; - - struct DeflectionShapeParameters { - long fieldHandlerId; - MEDPresentationViewMode viewMode; - }; - - struct PointSpriteParameters { - long fieldHandlerId; - MEDPresentationViewMode viewMode; - string displayedInfo; // DISPLAY_EUCLIDEAN_NORM or any field name - ScalarBarRange sbRange; - MEDPresentationColorMap colorMap; - }; +// struct ContourParameters { +// long fieldHandlerId; +// string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name +// ScalarBarRange scalarBarRange; +// MEDPresentationColorMap colorMap; +// long nbContours; +// }; +// +// struct VectorFieldParameters { +// long fieldHandlerId; +// }; +// +// struct SlicesParameters { +// long fieldHandlerId; +// SliceOrientation orientation; +// long nbSlices; +// }; +// +// struct DeflectionShapeParameters { +// long fieldHandlerId; +// }; +// +// struct PointSpriteParameters { +// long fieldHandlerId; +// string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name +// ScalarBarRange scalarBarRange; +// MEDPresentationColorMap colorMap; +// }; /* Functions */ interface MEDPresentationManager : SALOME::GenericObj { + long makeScalarMap(in ScalarMapParameters params, in MEDPresentationViewMode viewMode); +// long makeContour(in ContourParameters params, in MEDPresentationViewMode viewMode); +// long makeVectorField(in VectorFieldParameters params, in MEDPresentationViewMode viewMode); +// long makeSlices(in SlicesParameters params, in MEDPresentationViewMode viewMode); +// long makeDeflectionShape(in DeflectionShapeParameters params, in MEDPresentationViewMode viewMode); +// long makePointSprite(in PointSpriteParameters params, in MEDPresentationViewMode viewMode); - long makeScalarMap(in ScalarMapParameters params); - long makeContour(in ContourParameters params); - long makeVectorField(in VectorFieldParameters params); - long makeSlices(in SlicesParameters params); - long makeDeflectionShape(in DeflectionShapeParameters params); - long makePointSprite(in PointSpriteParameters params); + void setPresentationStringProperty(in long presId, in string propName, in string propValue); + string getPresentationStringProperty(in long presId, in string propName); + void setPresentationIntProperty(in long presId, in string propName, in long propValue); + long getPresentationIntProperty(in long presId, in string propName); - void setPresentationProperty(in long presId, in string propName, in string propValue); - string getPresentationProperty(in long presId, in string propName); + ScalarMapParameters getScalarMapParameters(in long presId); void updateScalarMap(in long presId, in ScalarMapParameters params); - void updateContour(in long presId, in ContourParameters params); - void updateVectorField(in long presId, in VectorFieldParameters params); - void updateSlices(in long presId, in SlicesParameters params); - void updateDeflectionShape(in long presId, in DeflectionShapeParameters params); - void updatePointSprite(in long presId, in PointSpriteParameters params); +// void updateContour(in long presId, in ContourParameters params); +// void updateVectorField(in long presId, in VectorFieldParameters params); +// void updateSlices(in long presId, in SlicesParameters params); +// void updateDeflectionShape(in long presId, in DeflectionShapeParameters params); +// void updatePointSprite(in long presId, in PointSpriteParameters params); boolean removePresentation(in long presId); - // Helper functions to keep GUI sync + // Helper function to keep GUI sync boolean activateView(in long presentationId); + // Low level ParaVis dump + string getParavisDump(in long presId); + MEDPresentationViewMode getPresentationViewMode(in long presId); }; - }; #endif diff --git a/idl/MED_Gen.idl b/idl/MED_Gen.idl index 21df0b933..94bd24136 100644 --- a/idl/MED_Gen.idl +++ b/idl/MED_Gen.idl @@ -46,7 +46,8 @@ module MED_ORB status registerPresentation(in SALOMEDS::Study study, in long fieldId, in string name, - in string label, + in string type, + in string ico, in long presentationId) raises (SALOME::SALOME_Exception); diff --git a/src/MEDCalc/MEDCalcConstants.hxx b/src/MEDCalc/MEDCalcConstants.hxx index 2023db6d7..934ee38b0 100644 --- a/src/MEDCalc/MEDCalcConstants.hxx +++ b/src/MEDCalc/MEDCalcConstants.hxx @@ -26,8 +26,9 @@ #define FIELD_ID "fieldId" #define PRESENTATION_ID "presentationId" #define IS_PRESENTATION "isPresentation" - +#define PRESENTATION_TYPE "presentationType" static const int NB_TYPE_OF_FIELDS = 4; static const char* mapTypeOfFieldLabel[NB_TYPE_OF_FIELDS] = {"ON_CELLS", "ON_NODES", "ON_GAUSS_PT", "ON_GAUSS_NE" }; + diff --git a/src/MEDCalc/cmp/CMakeLists.txt b/src/MEDCalc/cmp/CMakeLists.txt index 63415add6..489d221ce 100644 --- a/src/MEDCalc/cmp/CMakeLists.txt +++ b/src/MEDCalc/cmp/CMakeLists.txt @@ -41,11 +41,11 @@ SET(COMMON_SOURCES MEDPresentation.cxx # presentations MEDPresentationScalarMap.cxx - MEDPresentationContour.cxx - MEDPresentationVectorField.cxx - MEDPresentationSlices.cxx - MEDPresentationDeflectionShape.cxx - MEDPresentationPointSprite.cxx +# MEDPresentationContour.cxx +# MEDPresentationVectorField.cxx +# MEDPresentationSlices.cxx +# MEDPresentationDeflectionShape.cxx +# MEDPresentationPointSprite.cxx ) SET(MEDFactoryEngine_SOURCES diff --git a/src/MEDCalc/cmp/MED.cxx b/src/MEDCalc/cmp/MED.cxx index 99b6976c6..1d0ff2fe4 100644 --- a/src/MEDCalc/cmp/MED.cxx +++ b/src/MEDCalc/cmp/MED.cxx @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -159,22 +160,30 @@ MED_ORB::status MED::registerPresentation(SALOMEDS::Study_ptr study, CORBA::Long fieldId, const char* name, - const char* label, + const char* type, + const char* ico, CORBA::Long presentationId) { // set exception handler to catch unexpected CORBA exceptions Unexpect aCatch(SALOME_SalomeException); - if (_fieldSeriesEntries.find(fieldId) == _fieldSeriesEntries.end()) { - std::cerr << "Field not found\n"; + MEDCALC::FieldHandler_var fldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId); + int fieldSeriesId = fldHandler->fieldseriesId; + if (fieldSeriesId < 0){ + std::cerr << "MED::registerPresentation(): Error getting field handler\n"; + return MED_ORB::OP_ERROR ; + } + + if (_fieldSeriesEntries.find(fieldSeriesId) == _fieldSeriesEntries.end()) { + std::cerr << "MED::registerPresentation(): Field series not found\n"; return MED_ORB::OP_ERROR ; } - std::string entry = _fieldSeriesEntries[fieldId]; + std::string entry = _fieldSeriesEntries[fieldSeriesId]; SALOMEDS::SObject_var sobject = study->FindObjectID(entry.c_str()); SALOMEDS::SObject_ptr soFieldseries = sobject._retn(); if (soFieldseries->IsNull()) { - std::cerr << "Entry not found\n"; + std::cerr << "MED::registerPresentation(): Entry not found\n"; return MED_ORB::OP_ERROR; } @@ -184,7 +193,7 @@ MED::registerPresentation(SALOMEDS::Study_ptr study, useCaseBuilder->AppendTo(soPresentation->GetFather(), soPresentation); soPresentation->SetAttrString("AttributeName", name); - soPresentation->SetAttrString("AttributePixMap", label); + soPresentation->SetAttrString("AttributePixMap", ico); SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeParameter_var aParam; @@ -193,6 +202,7 @@ MED::registerPresentation(SALOMEDS::Study_ptr study, aParam->SetInt(FIELD_ID, fieldId); aParam->SetBool(IS_PRESENTATION, true); aParam->SetInt(PRESENTATION_ID, presentationId); + aParam->SetString(PRESENTATION_TYPE, type); return MED_ORB::OP_OK; } diff --git a/src/MEDCalc/cmp/MED.hxx b/src/MEDCalc/cmp/MED.hxx index ddd373a76..c4b432234 100644 --- a/src/MEDCalc/cmp/MED.hxx +++ b/src/MEDCalc/cmp/MED.hxx @@ -58,7 +58,8 @@ public: MED_ORB::status registerPresentation(SALOMEDS::Study_ptr study, CORBA::Long fieldId, const char* name, - const char* label, + const char* type, + const char* ico, CORBA::Long presentationId); MED_ORB::status unregisterPresentation(SALOMEDS::Study_ptr study, diff --git a/src/MEDCalc/cmp/MEDDataManager_i.cxx b/src/MEDCalc/cmp/MEDDataManager_i.cxx index 3db0cd3dd..7896465c8 100644 --- a/src/MEDCalc/cmp/MEDDataManager_i.cxx +++ b/src/MEDCalc/cmp/MEDDataManager_i.cxx @@ -182,6 +182,7 @@ MEDCALC::DatasourceHandler * MEDDataManager_i::loadDatasource(const char *filepa fieldHandler->meshid = meshHandler->id; fieldHandler->fieldseriesId = fieldseriesHandler->id; _fieldHandlerMap[fieldHandler->id] = fieldHandler; +// LOG("=== Storing " << fieldName << " (" << fieldHandler->id << ")"); } } } diff --git a/src/MEDCalc/cmp/MEDPresentation.cxx b/src/MEDCalc/cmp/MEDPresentation.cxx index 48305be82..61c631d68 100644 --- a/src/MEDCalc/cmp/MEDPresentation.cxx +++ b/src/MEDCalc/cmp/MEDPresentation.cxx @@ -22,14 +22,31 @@ #include "MEDPresentation.hxx" #include "MEDPresentationException.hxx" #include "MEDCouplingRefCountObject.hxx" -#include "Basics_Utils.hxx" -#include "PyInterp_Utils.h" +#include +#undef LOG +#include +#include #include -MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name) - : _fieldHandlerId(fieldHandlerId), _pipeline(0), _display(0), _properties(), - _renderViewPyId(GeneratePythonId()) +const std::string MEDPresentation::PROP_NAME = "name"; +const std::string MEDPresentation::PROP_NB_COMPONENTS = "nbComponents"; +const std::string MEDPresentation::PROP_SELECTED_COMPONENT = "selectedComponent"; +const std::string MEDPresentation::PROP_COMPONENT = "component_"; +const std::string MEDPresentation::PROP_COLOR_MAP = "colorMap"; +const std::string MEDPresentation::PROP_SCALAR_BAR_RANGE = "scalarBarRange"; + +MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name, + const MEDCALC::MEDPresentationViewMode viewMode, + const MEDCALC::MEDPresentationColorMap colorMap) + : _fieldHandlerId(fieldHandlerId), _propertiesStr(), + //_pipeline(0), _display(0) + _selectedComponentIndex(-1), + _viewMode(viewMode), + _colorMap(colorMap), + _renderViewPyId(GeneratePythonId()), + _objId(_renderViewPyId), _dispId(_renderViewPyId), _lutId(_renderViewPyId), + _globalDict(0) { MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager()); MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId); @@ -46,7 +63,13 @@ MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const s } _fileName = _fileName.substr(7, _fileName.size()); - setProperty("name", name); + setStringProperty(MEDPresentation::PROP_NAME, name); + + setIntProperty(MEDPresentation::PROP_NB_COMPONENTS, 0); + setIntProperty(MEDPresentation::PROP_SELECTED_COMPONENT, 0); + + setIntProperty(MEDPresentation::PROP_COLOR_MAP, static_cast(MEDCALC::COLOR_MAP_DEFAULT)); + setIntProperty(MEDPresentation::PROP_SCALAR_BAR_RANGE, static_cast(MEDCALC::SCALAR_BAR_RANGE_DEFAULT)); } MEDPresentation::~MEDPresentation() @@ -55,13 +78,11 @@ MEDPresentation::~MEDPresentation() { PyLockWrapper lock; std::ostringstream oss_o, oss_v, oss; - // Get top level object and display: - oss_o << "__obj" << _pipeline.front().first; + oss_o << "__obj" << _objId; oss_v << "__view" << _renderViewPyId; oss << "pvs.Hide(" << oss_o.str() << ", view=" << oss_v.str() << ");"; oss << "pvs.Render();"; -// std::cerr << oss.str() << std::endl; PyRun_SimpleString(oss.str().c_str()); } } @@ -74,56 +95,102 @@ MEDPresentation::generatePipeline() this->internalGeneratePipeline(); } -void -MEDPresentation::pushPyObjects(PyObjectId obj, PyObjectId disp) -{ - _pipeline.push_back(obj); - _display.push_back(disp); -} +//void +//MEDPresentation::pushPyObjects(PyObjectId obj, PyObjectId disp) +//{ +// _pipeline.push_back(obj); +// _display.push_back(disp); +//} void MEDPresentation::pushAndExecPyLine(const std::string & lin) { - // TODO: store internally for low level dump PyLockWrapper lock; // std::cerr << lin << std::endl; - PyRun_SimpleString(lin.c_str()); + if(PyRun_SimpleString(lin.c_str())) + { + std::ostringstream oss; + oss << "MEDPresentation::pushAndExecPyLine(): following Python command failed!\n"; + oss << ">> " << lin; + STDLOG(oss.str()); + throw KERNEL::createSalomeException(oss.str().c_str()); + } + _pythonCmds.push_back(lin); } void -MEDPresentation::setProperty(const std::string& propName, const std::string& propValue) +MEDPresentation::setStringProperty(const std::string& propName, const std::string& propValue) { - // LIMITED!!! For now switch the first display element to Wireframe - /* - PyLockWrapper lock; - PyObject_CallMethod(_display[0], (char*)"SetRepresentationType", (char*)"(s)", "Wireframe"); - */ - - _properties[propName] = propValue; + _propertiesStr[propName] = propValue; } const std::string -MEDPresentation::getProperty(const std::string& propName) const +MEDPresentation::getStringProperty(const std::string& propName) const { - std::map::const_iterator it = _properties.find(propName); - if (it != _properties.end()) { - return (*it).second; + std::map::const_iterator it = _propertiesStr.find(propName); + if (it != _propertiesStr.end()) { + return (*it).second; } else { - STDLOG("MEDPresentation::getProperty(): no property named " + propName); - return std::string(); + throw MEDPresentationException("MEDPresentation::getStringProperty(): no property named " + propName); } } +void +MEDPresentation::setIntProperty(const std::string& propName, const int propValue) +{ + _propertiesInt[propName] = propValue; +} + +int +MEDPresentation::getIntProperty(const std::string& propName) const +{ + std::map::const_iterator it = _propertiesInt.find(propName); + if (it != _propertiesInt.end()) { + return (*it).second; + } + else { + throw MEDPresentationException("MEDPresentation::getIntProperty(): no property named " + propName); + } +} + + void + MEDPresentation::dumpIntProperties() const + { + std::map::const_iterator it = _propertiesInt.begin(); + STDLOG("@@@ Dumping INT properties"); + for(; it != _propertiesInt.end(); ++it) + { + std::ostringstream oss; + oss << (*it).first << " -> " << (*it).second; + STDLOG(oss.str()); + } + } + + void + MEDPresentation::dumpStringProperties() const + { + std::map::const_iterator it = _propertiesStr.begin(); + STDLOG("@@@ Dumping STR properties"); + for(; it != _propertiesStr.end(); ++it) + { + std::ostringstream oss; + oss << (*it).first << " -> " << (*it).second; + STDLOG(oss.str()); + } + } + + PyObject* MEDPresentation::getPythonObjectFromMain(const char* python_var) const { - // TODO: improve to avoid getting dict at each call - - // All the calls below returns *borrowed* references - PyObject* main_module = PyImport_AddModule((char*)"__main__"); - PyObject* global_dict = PyModule_GetDict(main_module); - return PyDict_GetItemString(global_dict, python_var); + if (! _globalDict) + { + // All the calls below returns *borrowed* references + PyObject* main_module = PyImport_AddModule((char*)"__main__"); + _globalDict = PyModule_GetDict(main_module); + } + return PyDict_GetItemString(_globalDict, python_var); } std::string @@ -142,23 +209,23 @@ MEDPresentation::getFieldTypeString(MEDCoupling::TypeOfField fieldType) const } std::string -MEDPresentation::getRenderViewCommand(MEDCALC::MEDPresentationViewMode viewMode) const +MEDPresentation::getRenderViewCommand() const { std::ostringstream oss, oss2; oss << "__view" << _renderViewPyId; std::string view(oss.str()); - oss2 << "pvs._DisableFirstRenderCameraReset();"; - if (viewMode == MEDCALC::VIEW_MODE_OVERLAP) { - oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');"; - } else if (viewMode == MEDCALC::VIEW_MODE_REPLACE) { - oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');"; - oss2 << "pvs.active_objects.source and pvs.Hide(view=" << view << ");"; - oss2 << "pvs.Render();"; - } else if (viewMode == MEDCALC::VIEW_MODE_NEW_LAYOUT) { - oss2 << "__layout1 = pvs.servermanager.misc.ViewLayout(registrationGroup='layouts');"; - oss2 << view << " = pvs.CreateView('RenderView');"; - } else if (viewMode == MEDCALC::VIEW_MODE_SPLIT_VIEW) { - oss2 << view << " = pvs.CreateView('RenderView');"; + oss2 << "pvs._DisableFirstRenderCameraReset();" << std::endl; + if (_viewMode == MEDCALC::VIEW_MODE_OVERLAP) { + oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');" << std::endl; + } else if (_viewMode == MEDCALC::VIEW_MODE_REPLACE) { + oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');" << std::endl; + oss2 << "pvs.active_objects.source and pvs.Hide(view=" << view << ");" << std::endl; + oss2 << "pvs.Render();" << std::endl; + } else if (_viewMode == MEDCALC::VIEW_MODE_NEW_LAYOUT) { + oss2 << "__layout1 = pvs.servermanager.misc.ViewLayout(registrationGroup='layouts');" << std::endl; + oss2 << view << " = pvs.CreateView('RenderView');" << std::endl; + } else if (_viewMode == MEDCALC::VIEW_MODE_SPLIT_VIEW) { + oss2 << view << " = pvs.CreateView('RenderView');" << std::endl; } return oss2.str(); } @@ -172,12 +239,57 @@ MEDPresentation::getResetCameraCommand() const } std::string -MEDPresentation::getColorMapCommand(MEDCALC::MEDPresentationColorMap colorMap) const +MEDPresentation::getComponentSelectionCommand() const +{ + std::ostringstream oss, oss_l; + oss_l << "__lut" << _lutId; std::string lut(oss_l.str()); + + if (_selectedComponentIndex != -1) + { + oss << lut << ".VectorMode = 'Component';\n"; + oss << lut << ".VectorComponent = " << _selectedComponentIndex << ";"; + } + else // Euclidean norm + { + oss << lut << ".VectorMode = 'Magnitude';"; + } + return oss.str(); +} + +std::string +MEDPresentation::getColorMapCommand() const { - 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"; + std::ostringstream oss, oss_l; + oss_l << "__lut" << _lutId; std::string lut(oss_l.str()); + switch (_colorMap) { + case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: + oss << lut << ".ApplyPreset('Blue to Red Rainbow',True);"; + break; + case MEDCALC::COLOR_MAP_COOL_TO_WARM: + oss << lut << ".ApplyPreset('Cool to Warm',True);"; + break; + default: + throw KERNEL::createSalomeException("MEDPresentation::getColorMapCommand(): invalid colormap!"); } + return oss.str(); +} +std::string +MEDPresentation::getRescaleCommand() const +{ + std::ostringstream oss, oss_d; + oss_d << "__disp" << _dispId; std::string disp(oss_d.str()); + switch(_sbRange) + { + case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: + oss << disp << ".RescaleTransferFunctionToDataRangeOverTime();"; + break; + case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: + oss << disp << ".RescaleTransferFunctionToDataRange(False);"; + break; + default: + throw KERNEL::createSalomeException("MEDPresentation::getRescaleCommand(): invalid range!"); + } + return oss.str(); } int @@ -188,11 +300,81 @@ MEDPresentation::GeneratePythonId() } void -MEDPresentation::activateView() const +MEDPresentation::activateView() { PyLockWrapper lock; + std::ostringstream oss; oss << "pvs.SetActiveView(__view" << _renderViewPyId << ");"; - std::cerr << oss.str() << std::endl; + pushAndExecPyLine(oss.str()); +} + + +std::string +MEDPresentation::paravisDump() const +{ + using namespace std; + ostringstream oss; + for (vector::const_iterator it=_pythonCmds.begin(); it != _pythonCmds.end(); ++it) + { + oss << (*it); + oss << "\n"; + } + return oss.str(); +} + +/** + * Query all available component names for the field associated with this presentation. + * Fills in all the corresponding string properties: + * - PROP_COMPONENT1 + * - PROP_COMPONENT2 + * etc... + * and the number of components. + */ +void +MEDPresentation::fillAvailableFieldComponents() +{ + PyLockWrapper lock; // GIL! + + std::ostringstream oss_o; + oss_o << "__obj" << _objId; std::string obj(oss_o.str()); + std::string typ; + + if(_fieldType == "CELLS") { + typ = "CellData"; + } + else if (_fieldType == "POINTS") { + typ = "PointData"; + } + else { + std::string msg("Unsupported spatial discretisation: " + _fieldType); + throw KERNEL::createSalomeException(msg.c_str()); + } + + std::ostringstream oss; + oss << "__nbCompo = " << obj << "." << typ << ".GetArray('" << _fieldName << "').GetNumberOfComponents();"; PyRun_SimpleString(oss.str().c_str()); + PyObject* p_obj = getPythonObjectFromMain("__nbCompo"); + long nbCompo; + if (p_obj && PyInt_Check(p_obj)) + nbCompo = PyInt_AS_LONG(p_obj); + else + throw KERNEL::createSalomeException("Unexpected Python error"); + setIntProperty(MEDPresentation::PROP_NB_COMPONENTS, nbCompo); + for (long i = 0; i PyObjectId; + static int GeneratePythonId(); - MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name); - std::string getRenderViewCommand(MEDCALC::MEDPresentationViewMode viewMode) const; + MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name, + const MEDCALC::MEDPresentationViewMode viewMode, + const MEDCALC::MEDPresentationColorMap colorMap); + std::string getRenderViewCommand() const; std::string getResetCameraCommand() const; - std::string getColorMapCommand(MEDCALC::MEDPresentationColorMap colorMap) const; + + std::string getComponentSelectionCommand() const; + std::string getColorMapCommand() const; + std::string getRescaleCommand() const; virtual void internalGeneratePipeline() = 0; PyObject* getPythonObjectFromMain(const char* var) const; - void pushPyObjects(PyObjectId obj, PyObjectId disp); +// void pushPyObjects(PyObjectId obj, PyObjectId disp); void pushAndExecPyLine(const std::string & lin); MEDPresentation::TypeID getID() const { return _fieldHandlerId; } long getPyViewID() const { return _renderViewPyId; } - static int GeneratePythonId(); + void fillAvailableFieldComponents(); + // TODO: follow the pattern of the others methods: template! virtual MEDCALC::MEDPresentationViewMode getViewMode() = 0; -private: + template + void updateComponent(const std::string& newCompo); + template + void updateColorMap(MEDCALC::MEDPresentationColorMap colorMap); + + template + void updateScalarBarRange(MEDCALC::MEDPresentationScalarBarRange sbRange); + + template + void getParameters(PresentationParameters& params) const; + + template + void setParameters(const PresentationParameters& params); + +private: std::string getFieldTypeString(MEDCoupling::TypeOfField fieldType) const; // The following functions are reserved to friend class MEDPresentationManager void generatePipeline(); template - void updatePipeline(PresentationParameters params); + void updatePipeline(const PresentationParameters& params); protected: std::string _fileName; std::string _fieldName; std::string _fieldType; + MEDPresentation::TypeID _fieldHandlerId; + + int _selectedComponentIndex; + MEDCALC::MEDPresentationViewMode _viewMode; + MEDCALC::MEDPresentationColorMap _colorMap; + MEDCALC::MEDPresentationScalarBarRange _sbRange; + ///! Identifier (in the Python dump) of the render view int _renderViewPyId; + ///! ParaView object ID in the Python scripting commands + int _objId; + ///! ParaView display ID in the Python scripting commands + int _dispId; + ///! ParaView LUT ID in the Python scripting commands + int _lutId; private: - MEDPresentation::TypeID _fieldHandlerId; - ///! Pipeline elements - std::vector _pipeline; +// std::vector _pipeline; ///! Corresponding display object, if any: - std::vector _display; +// std::vector _display; ///! Presentation properties - std::map _properties; + std::map _propertiesStr; + std::map _propertiesInt; + + std::vector _pythonCmds; + + mutable PyObject* _globalDict; }; #include "MEDPresentation.txx" diff --git a/src/MEDCalc/cmp/MEDPresentation.txx b/src/MEDCalc/cmp/MEDPresentation.txx index a99a46260..f4100e77b 100644 --- a/src/MEDCalc/cmp/MEDPresentation.txx +++ b/src/MEDCalc/cmp/MEDPresentation.txx @@ -20,11 +20,134 @@ #ifndef _MED_PRESENTATION_TXX_ #define _MED_PRESENTATION_TXX_ +#include +#include +#include + template void -MEDPresentation::updatePipeline(PresentationParameters params) +MEDPresentation::updatePipeline(const PresentationParameters& params) { static_cast(this)->updatePipeline(params); } +template +void +MEDPresentation::getParameters(PresentationParameters& params) const +{ + const PresentationType * p = static_cast(this); + p->getParameters(params); +} + +template +void +MEDPresentation::setParameters(const PresentationParameters& params) +{ + PresentationType * p = static_cast(this); + p->setParameters(params); +} + + +/** + * Update the ParaVis pipeline so that the given component appears on screen. + * Blank means "Euclidean norm" + * The property PROP_SELECTED_COMPONENT holding the corresponding index selected is also updated (help for the GUI). + */ +template +void +MEDPresentation::updateComponent(const std::string& newCompo) +{ + PresentationType * p = static_cast(this); + + PresentationParameters params; + p->getParameters(params); + params.displayedComponent = newCompo.c_str(); + p->setParameters(params); + + + + int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS); + int idx = -1; + for (int i=0; i < nbCompo; i++) + { + std::ostringstream oss_p; + oss_p << MEDPresentation::PROP_COMPONENT << i; + std::string compo = getStringProperty(oss_p.str()); + if (compo == newCompo) + { + idx = i; + break; + } + } + if (idx == -1 && newCompo != "") + { + std::string msg("updateComponent(): internal error - field component not found!"); + throw KERNEL::createSalomeException(msg.c_str()); + } + setIntProperty(MEDPresentation::PROP_SELECTED_COMPONENT, idx+1); // +1 because idx=0 means Euclidean norm + p->_selectedComponentIndex = idx; + + // Update ParaView pipeline: + { + PyLockWrapper lock; + + std::ostringstream oss; + std::string cmd = getComponentSelectionCommand(); + pushAndExecPyLine(cmd); + pushAndExecPyLine("pvs.Render();"); + } + +} + +template +void +MEDPresentation::updateColorMap(MEDCALC::MEDPresentationColorMap colorMap) +{ + PresentationType * p = static_cast(this); + + PresentationParameters params; + p->getParameters(params); + params.colorMap = colorMap; + p->setParameters(params); + + p->_colorMap = colorMap; + + // GUI helper: + setIntProperty(MEDPresentation::PROP_COLOR_MAP, colorMap); + + // Update the pipeline: + { + PyLockWrapper lock; + std::string cmd = getColorMapCommand(); + pushAndExecPyLine(cmd); + pushAndExecPyLine("pvs.Render();"); + } +} + +template +void +MEDPresentation::updateScalarBarRange(MEDCALC::MEDPresentationScalarBarRange sbRange) +{ + PresentationType * p = static_cast(this); + + PresentationParameters params; + p->getParameters(params); + params.scalarBarRange = sbRange; + p->setParameters(params); + + p->_sbRange = sbRange; + + // GUI helper: + setIntProperty(MEDPresentation::PROP_SCALAR_BAR_RANGE, sbRange); + + // Update the pipeline: + { + PyLockWrapper lock; + std::string cmd = getRescaleCommand(); + pushAndExecPyLine(cmd); + pushAndExecPyLine("pvs.Render();"); + } +} + + #endif // _MED_PRESENTATION_TXX_ diff --git a/src/MEDCalc/cmp/MEDPresentationContour.cxx b/src/MEDCalc/cmp/MEDPresentationContour.cxx index 87ce8e8c2..a0f14a272 100644 --- a/src/MEDCalc/cmp/MEDPresentationContour.cxx +++ b/src/MEDCalc/cmp/MEDPresentationContour.cxx @@ -19,6 +19,8 @@ #include "MEDPresentationContour.hxx" +const std::string MEDPresentationContour::PROP_NB_CONTOUR = "nbContour"; + void MEDPresentationContour::internalGeneratePipeline() { diff --git a/src/MEDCalc/cmp/MEDPresentationContour.hxx b/src/MEDCalc/cmp/MEDPresentationContour.hxx index 364965cd6..36acc6f72 100644 --- a/src/MEDCalc/cmp/MEDPresentationContour.hxx +++ b/src/MEDCalc/cmp/MEDPresentationContour.hxx @@ -26,6 +26,8 @@ class MEDCALC_EXPORT MEDPresentationContour : public MEDPresentation { public: + static const std::string PROP_NB_CONTOUR; + MEDPresentationContour(const MEDCALC::ContourParameters& params) : MEDPresentation(params.fieldHandlerId, "MEDPresentationContour"), _params(params) {} diff --git a/src/MEDCalc/cmp/MEDPresentationException.hxx b/src/MEDCalc/cmp/MEDPresentationException.hxx index adebd5179..dd66635b2 100644 --- a/src/MEDCalc/cmp/MEDPresentationException.hxx +++ b/src/MEDCalc/cmp/MEDPresentationException.hxx @@ -36,6 +36,12 @@ public: this->_msg = oss.str(); } + MEDPresentationException(const std::string& msg) { + std::ostringstream oss; + oss << "Error: " << msg; + this->_msg = oss.str(); + } + virtual ~MEDPresentationException() throw() {} virtual const char* what() const throw() { diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx index e88e77cfb..f2608c125 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx @@ -23,11 +23,13 @@ // presentations #include "MEDPresentationScalarMap.hxx" -#include "MEDPresentationContour.hxx" -#include "MEDPresentationVectorField.hxx" -#include "MEDPresentationSlices.hxx" -#include "MEDPresentationDeflectionShape.hxx" -#include "MEDPresentationPointSprite.hxx" +//#include "MEDPresentationContour.hxx" +//#include "MEDPresentationVectorField.hxx" +//#include "MEDPresentationSlices.hxx" +//#include "MEDPresentationDeflectionShape.hxx" +//#include "MEDPresentationPointSprite.hxx" + +#include #include #include @@ -75,62 +77,92 @@ MEDPresentationManager_i::_getPresentation(MEDPresentation::TypeID presentationI } void -MEDPresentationManager_i::setPresentationProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue) +MEDPresentationManager_i::setPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue) { MEDPresentation* pres = _getPresentation(presentationID); if (pres) - pres->setProperty(propName, propValue); + pres->setStringProperty(propName, propValue); else - std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl; + throw KERNEL::createSalomeException("setPresentationStringProperty(): presentation not found!!"); } char* -MEDPresentationManager_i::getPresentationProperty(MEDPresentation::TypeID presentationID, const char* propName) +MEDPresentationManager_i::getPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName) { MEDPresentation* pres = _getPresentation(presentationID); if (pres) { - return (char*) pres->getProperty(propName).c_str(); - } - else { - std::cerr << "getPresentationProperty(): presentation not found!!" << std::endl; - return (char*) ""; + return (char*) pres->getStringProperty(propName).c_str(); } + else + throw KERNEL::createSalomeException("getPresentationStringProperty(): presentation not found!!"); } -MEDPresentation::TypeID -MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params) +void +MEDPresentationManager_i::setPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName, + const CORBA::Long propValue) { - return _makePresentation(params); + MEDPresentation* pres = _getPresentation(presentationID); + if (pres) + pres->setIntProperty(propName, propValue); + else + throw KERNEL::createSalomeException("setPresentationIntProperty(): presentation not found!!"); } -MEDPresentation::TypeID -MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params) +CORBA::Long +MEDPresentationManager_i::getPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName) { - return _makePresentation(params); -} + MEDPresentation* pres = _getPresentation(presentationID); + if (pres) { + return (CORBA::Long) pres->getIntProperty(propName); + } + else + throw KERNEL::createSalomeException("getPresentationIntProperty(): presentation not found!!"); -MEDPresentation::TypeID -MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params) -{ - return _makePresentation(params); } MEDPresentation::TypeID -MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params) +MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params, const MEDCALC::MEDPresentationViewMode viewMode) { - return _makePresentation(params); + return _makePresentation(params, viewMode); } -MEDPresentation::TypeID -MEDPresentationManager_i::makeDeflectionShape(const MEDCALC::DeflectionShapeParameters& params) -{ - return _makePresentation(params); -} +//MEDPresentation::TypeID +//MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params) +//{ +// return _makePresentation(params); +//} +// +//MEDPresentation::TypeID +//MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params) +//{ +// return _makePresentation(params); +//} +// +//MEDPresentation::TypeID +//MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params) +//{ +// return _makePresentation(params); +//} +// +//MEDPresentation::TypeID +//MEDPresentationManager_i::makeDeflectionShape(const MEDCALC::DeflectionShapeParameters& params) +//{ +// return _makePresentation(params); +//} +// +//MEDPresentation::TypeID +//MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params) +//{ +// return _makePresentation(params); +//} -MEDPresentation::TypeID -MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params) +MEDCALC::ScalarMapParameters* +MEDPresentationManager_i::getScalarMapParameters(MEDPresentation::TypeID presentationID) { - return _makePresentation(params); + MEDCALC::ScalarMapParameters* p = new MEDCALC::ScalarMapParameters(); + _getParameters(presentationID, *p); + MEDCALC::ScalarMapParameters_var tmp(p); + return tmp._retn(); } void @@ -139,35 +171,35 @@ MEDPresentationManager_i::updateScalarMap(MEDPresentation::TypeID presentationID return _updatePresentation(presentationID, params); } -void -MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params) -{ - return _updatePresentation(presentationID, params); -} - -void -MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params) -{ - return _updatePresentation(presentationID, params); -} - -void -MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters& params) -{ - return _updatePresentation(presentationID, params); -} - -void -MEDPresentationManager_i::updateDeflectionShape(MEDPresentation::TypeID presentationID, const MEDCALC::DeflectionShapeParameters& params) -{ - return _updatePresentation(presentationID, params); -} - -void -MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params) -{ - return _updatePresentation(presentationID, params); -} +//void +//MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params) +//{ +// return _updatePresentation(presentationID, params); +//} +// +//void +//MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params) +//{ +// return _updatePresentation(presentationID, params); +//} +// +//void +//MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters& params) +//{ +// return _updatePresentation(presentationID, params); +//} +// +//void +//MEDPresentationManager_i::updateDeflectionShape(MEDPresentation::TypeID presentationID, const MEDCALC::DeflectionShapeParameters& params) +//{ +// return _updatePresentation(presentationID, params); +//} +// +//void +//MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params) +//{ +// return _updatePresentation(presentationID, params); +//} CORBA::Boolean MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID) @@ -214,3 +246,15 @@ MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presen return MEDCALC::VIEW_MODE_DEFAULT; } } + +char* +MEDPresentationManager_i::getParavisDump(MEDPresentation::TypeID presentationID) +{ + MEDPresentation* pres = _getPresentation(presentationID); + if (pres) { + return (char*) pres->paravisDump().c_str(); + } + else + throw KERNEL::createSalomeException("getParavisDump(): presentation not found!!"); +} + diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx index 16c587583..509286729 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx @@ -39,30 +39,32 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, static MEDPresentationManager_i* getInstance(); - MEDCALC_EXPORT MEDPresentation::TypeID makeScalarMap(const MEDCALC::ScalarMapParameters&); - MEDCALC_EXPORT MEDPresentation::TypeID makeContour(const MEDCALC::ContourParameters&); - MEDCALC_EXPORT MEDPresentation::TypeID makeVectorField(const MEDCALC::VectorFieldParameters&); - MEDCALC_EXPORT MEDPresentation::TypeID makeSlices(const MEDCALC::SlicesParameters&); - MEDCALC_EXPORT MEDPresentation::TypeID makeDeflectionShape(const MEDCALC::DeflectionShapeParameters&); - MEDCALC_EXPORT MEDPresentation::TypeID makePointSprite(const MEDCALC::PointSpriteParameters&); + MEDCALC_EXPORT MEDPresentation::TypeID makeScalarMap(const MEDCALC::ScalarMapParameters&, const MEDCALC::MEDPresentationViewMode); +// MEDCALC_EXPORT MEDPresentation::TypeID makeContour(const MEDCALC::ContourParameters&, const MEDCALC::MEDPresentationViewMode); +// MEDCALC_EXPORT MEDPresentation::TypeID makeVectorField(const MEDCALC::VectorFieldParameters&); +// MEDCALC_EXPORT MEDPresentation::TypeID makeSlices(const MEDCALC::SlicesParameters&); +// MEDCALC_EXPORT MEDPresentation::TypeID makeDeflectionShape(const MEDCALC::DeflectionShapeParameters&); +// MEDCALC_EXPORT MEDPresentation::TypeID makePointSprite(const MEDCALC::PointSpriteParameters&); - MEDCALC_EXPORT void setPresentationProperty(MEDPresentation::TypeID, const char* propName, const char* propValue); - MEDCALC_EXPORT char* getPresentationProperty(MEDPresentation::TypeID, const char* propName); + MEDCALC_EXPORT void setPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue); + MEDCALC_EXPORT char* getPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName); + + MEDCALC_EXPORT void setPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName, const CORBA::Long propValue); + MEDCALC_EXPORT CORBA::Long getPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName); + + MEDCALC_EXPORT MEDCALC::ScalarMapParameters* getScalarMapParameters(MEDPresentation::TypeID presentationID); MEDCALC_EXPORT void updateScalarMap(MEDPresentation::TypeID, const MEDCALC::ScalarMapParameters&); - MEDCALC_EXPORT void updateContour(MEDPresentation::TypeID, const MEDCALC::ContourParameters&); - MEDCALC_EXPORT void updateVectorField(MEDPresentation::TypeID, const MEDCALC::VectorFieldParameters&); - MEDCALC_EXPORT void updateSlices(MEDPresentation::TypeID, const MEDCALC::SlicesParameters&); - MEDCALC_EXPORT void updateDeflectionShape(MEDPresentation::TypeID, const MEDCALC::DeflectionShapeParameters&); - MEDCALC_EXPORT void updatePointSprite(MEDPresentation::TypeID, const MEDCALC::PointSpriteParameters&); +// MEDCALC_EXPORT void updateContour(MEDPresentation::TypeID, const MEDCALC::ContourParameters&); +// MEDCALC_EXPORT void updateVectorField(MEDPresentation::TypeID, const MEDCALC::VectorFieldParameters&); +// MEDCALC_EXPORT void updateSlices(MEDPresentation::TypeID, const MEDCALC::SlicesParameters&); +// MEDCALC_EXPORT void updateDeflectionShape(MEDPresentation::TypeID, const MEDCALC::DeflectionShapeParameters&); +// MEDCALC_EXPORT void updatePointSprite(MEDPresentation::TypeID, const MEDCALC::PointSpriteParameters&); MEDCALC_EXPORT CORBA::Boolean removePresentation(MEDPresentation::TypeID); - MEDCALC_EXPORT CORBA::Boolean activateView(MEDPresentation::TypeID); - MEDCALC_EXPORT MEDCALC::MEDPresentationViewMode getPresentationViewMode(MEDPresentation::TypeID); - - MEDCALC_EXPORT CORBA::Boolean activateView(MEDPresentation::TypeID presentationID); + MEDCALC_EXPORT char* getParavisDump(MEDPresentation::TypeID presentationID); private: MEDPresentationManager_i(); @@ -72,11 +74,15 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, // Create a new presentation instance and return its unique ID template - MEDPresentation::TypeID _makePresentation(PresentationParameters params); + MEDPresentation::TypeID _makePresentation(const PresentationParameters params, MEDCALC::MEDPresentationViewMode viewMode); // Update presentation template - void _updatePresentation(MEDPresentation::TypeID presentationID, PresentationParameters params); + void _updatePresentation(MEDPresentation::TypeID presentationID, const PresentationParameters params); + + // Get presentation parameters + template + void _getParameters(MEDPresentation::TypeID presentationID, PresentationParameters & params) const; MEDPresentation* _getPresentation(MEDPresentation::TypeID) const; diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.txx b/src/MEDCalc/cmp/MEDPresentationManager_i.txx index eb283bf15..80f5e84f8 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.txx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.txx @@ -22,12 +22,19 @@ template MEDPresentation::TypeID -MEDPresentationManager_i::_makePresentation(PresentationParameters params) +MEDPresentationManager_i::_makePresentation(const PresentationParameters params, const MEDCALC::MEDPresentationViewMode viewMode) { + // Replace = Remove then add + if (viewMode == MEDCALC::VIEW_MODE_REPLACE) { + MEDPresentation::TypeID currentPresentationId = _getActivePresentationId(); + if (currentPresentationId > -1) + removePresentation(currentPresentationId); + } + // Create a new presentation instance PresentationType* presentation = NULL; try { - presentation = new PresentationType(params); // on stack or on heap?? stack for now + presentation = new PresentationType(params, viewMode); // on stack or on heap?? heap for now } catch (const std::exception& e) { std::cerr << e.what() << std::endl; @@ -42,7 +49,7 @@ MEDPresentationManager_i::_makePresentation(PresentationParameters params) template void -MEDPresentationManager_i::_updatePresentation(MEDPresentation::TypeID presentationID, PresentationParameters params) +MEDPresentationManager_i::_updatePresentation(MEDPresentation::TypeID presentationID, const PresentationParameters params) { MEDPresentation* presentation = _getPresentation(presentationID); if (!presentation) { @@ -53,4 +60,18 @@ MEDPresentationManager_i::_updatePresentation(MEDPresentation::TypeID presentati presentation->updatePipeline(params); } +template +void +MEDPresentationManager_i::_getParameters(MEDPresentation::TypeID presentationID, PresentationParameters & params) const +{ + MEDPresentation* presentation = _getPresentation(presentationID); + if (!presentation) { + std::cerr << "_getParameters(): presentation not found!!" << std::endl; + return; + } + + presentation->getParameters(params); +} + + #endif // _MED_PRESENTATION_MANAGER_I_TXX_ diff --git a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx index 6af5375bd..03c46af00 100644 --- a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx +++ b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx @@ -18,51 +18,77 @@ // #include "MEDPresentationScalarMap.hxx" -#include "PyInterp_Utils.h" +#include "MEDPresentationException.hxx" + +#include +#include +#undef LOG // should be fixed in KERNEL - double definition +#include #include +const std::string MEDPresentationScalarMap::TYPE_NAME = "MEDPresentationScalarMap"; + +MEDPresentationScalarMap::MEDPresentationScalarMap(const MEDCALC::ScalarMapParameters& params, + const MEDCALC::MEDPresentationViewMode viewMode) : + MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap), _params(params) +{ +} + void MEDPresentationScalarMap::internalGeneratePipeline() { PyLockWrapper lock; - int disp_id(GeneratePythonId()); - int obj_id(disp_id); - std::ostringstream oss_o, oss_d, oss, oss_v; - oss_o << "__obj" << obj_id; std::string obj(oss_o.str()); - oss_d << "__disp" << disp_id; std::string disp(oss_d.str()); + std::ostringstream oss_o, oss_d,oss_l, oss, oss_v; + oss_o << "__obj" << _objId; std::string obj(oss_o.str()); + oss_d << "__disp" << _dispId; std::string disp(oss_d.str()); + oss_l << "__lut" << _lutId; std::string lut(oss_l.str()); pushAndExecPyLine( "import pvsimple as pvs;"); - pushAndExecPyLine( getRenderViewCommand(_params.viewMode) ); // define __viewXXX + pushAndExecPyLine( getRenderViewCommand() ); // define __viewXXX oss_v << "__view" << _renderViewPyId; std::string view(oss_v.str()); oss << obj << " = pvs.MEDReader(FileName='" << _fileName << "');"; pushAndExecPyLine(oss.str()); oss.str(""); + + // Populate internal array of available components: + fillAvailableFieldComponents(); +// dumpIntProperties(); +// dumpStringProperties(); + oss << disp << " = pvs.Show(" << obj << ", " << view << ");"; pushAndExecPyLine(oss.str()); oss.str(""); oss << "pvs.ColorBy(" << disp << ", ('" << _fieldType << "', '" << _fieldName << "'));"; pushAndExecPyLine(oss.str()); oss.str(""); oss << disp << ".SetScalarBarVisibility(" << view << ", True);"; pushAndExecPyLine(oss.str()); oss.str(""); - oss << disp << ".RescaleTransferFunctionToDataRangeOverTime();"; - pushAndExecPyLine(oss.str()); oss.str(""); - oss << "__lut = pvs.GetColorTransferFunction('" << _fieldName << "');"; + oss << getRescaleCommand(); pushAndExecPyLine(oss.str()); oss.str(""); - oss << "__lut.ApplyPreset('" << getColorMapCommand(_params.colorMap) << "',True);"; + oss << lut << " = pvs.GetColorTransferFunction('" << _fieldName << "');"; pushAndExecPyLine(oss.str()); oss.str(""); + pushAndExecPyLine(getColorMapCommand()); oss.str(""); pushAndExecPyLine(getResetCameraCommand()); pushAndExecPyLine("pvs.Render();"); // Retrieve Python object for internal storage: - PyObject* p_obj = getPythonObjectFromMain(obj.c_str()); - PyObject* p_disp = getPythonObjectFromMain(disp.c_str()); - pushPyObjects(std::make_pair(obj_id, p_obj), std::make_pair(disp_id, p_disp)); +// PyObject* p_obj = getPythonObjectFromMain(obj.c_str()); +// PyObject* p_disp = getPythonObjectFromMain(disp.c_str()); +// pushPyObjects(std::make_pair(_objId, p_obj), std::make_pair(disp_id, p_disp)); } void MEDPresentationScalarMap::updatePipeline(const MEDCALC::ScalarMapParameters& params) { - // :TODO: + if (params.fieldHandlerId != _params.fieldHandlerId) + throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!"); + + if (params.displayedComponent != _params.displayedComponent) + updateComponent(std::string(params.displayedComponent)); + if (params.scalarBarRange != _params.scalarBarRange) + updateScalarBarRange(params.scalarBarRange); + if (params.colorMap != _params.colorMap) + updateColorMap(params.colorMap); } + diff --git a/src/MEDCalc/cmp/MEDPresentationScalarMap.hxx b/src/MEDCalc/cmp/MEDPresentationScalarMap.hxx index 2b35a3482..71c5521d4 100644 --- a/src/MEDCalc/cmp/MEDPresentationScalarMap.hxx +++ b/src/MEDCalc/cmp/MEDPresentationScalarMap.hxx @@ -22,18 +22,22 @@ #include "MEDCALC.hxx" #include "MEDPresentation.hxx" +#include class MEDCALC_EXPORT MEDPresentationScalarMap : public MEDPresentation { public: - MEDPresentationScalarMap(const MEDCALC::ScalarMapParameters& params) : - MEDPresentation(params.fieldHandlerId, "MEDPresentationScalarMap"), _params(params) - {} + static const std::string TYPE_NAME; + + MEDPresentationScalarMap(const MEDCALC::ScalarMapParameters& params, const MEDCALC::MEDPresentationViewMode viewMode); virtual ~MEDPresentationScalarMap() {} void updatePipeline(const MEDCALC::ScalarMapParameters& params); MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } + void getParameters(MEDCALC::ScalarMapParameters & params) const { params = _params; } ; + void setParameters(const MEDCALC::ScalarMapParameters & params) { _params = params; } ; + protected: virtual void internalGeneratePipeline(); diff --git a/src/MEDCalc/gui/CMakeLists.txt b/src/MEDCalc/gui/CMakeLists.txt index b33ab4dfc..66c91bb24 100644 --- a/src/MEDCalc/gui/CMakeLists.txt +++ b/src/MEDCalc/gui/CMakeLists.txt @@ -37,6 +37,8 @@ SET(MEDCALCGUI_SOURCES WorkspaceController.cxx XmedConsoleDriver.cxx XmedDataModel.cxx + MEDWidgetHelper.cxx + MEDWidgetHelperScalarMap.cxx ) IF(SALOME_MED_WITH_QTTESTING) @@ -50,6 +52,8 @@ SET(MEDCALCGUI_HEADERS DatasourceController.hxx PresentationController.hxx ProcessingController.hxx + MEDWidgetHelper.hxx + MEDWidgetHelperScalarMap.hxx ) IF(SALOME_MED_WITH_QTTESTING) diff --git a/src/MEDCalc/gui/DatasourceController.cxx b/src/MEDCalc/gui/DatasourceController.cxx index 8fa43b3f6..cbf2649d5 100644 --- a/src/MEDCalc/gui/DatasourceController.cxx +++ b/src/MEDCalc/gui/DatasourceController.cxx @@ -105,6 +105,7 @@ void DatasourceController::createActions() { icon = tr("ICO_DATASOURCE_USE"); actionId = _salomeModule->createStandardAction(label,this,SLOT(OnUseInWorkspace()),icon); _salomeModule->addActionInPopupMenu(actionId); + } /** @@ -121,13 +122,14 @@ DatasourceController::addDatasource(const char* filename) DatasourceEvent* event = new DatasourceEvent(); event->eventtype = DatasourceEvent::EVENT_ADD_DATASOURCE; event->objectalias = filename; - emit datasourceSignal(event); + emit datasourceSignal(event); // --> WorkspaceController::processDatasourceEvent() //#ifdef MED_WITH_QTTESTING // _dirtyAddDataSource = true; // while(_dirtyAddDataSource) // QApplication::processEvents(); //#endif } + // After above data source creation, python console emits a signal, forwarded by workspace, to update the GUI void DatasourceController::updateTreeViewWithNewDatasource(const MEDCALC::DatasourceHandler* datasourceHandler) @@ -216,7 +218,7 @@ void DatasourceController::OnAddImagesource() DatasourceEvent* event = new DatasourceEvent(); event->eventtype = DatasourceEvent::EVENT_ADD_IMAGE_AS_DATASOURCE; event->objectalias = imageFilename; - emit datasourceSignal(event); + emit datasourceSignal(event); // --> WorkspaceController::processDatasourceEvent() } void DatasourceController::OnExpandField() @@ -323,7 +325,7 @@ void DatasourceController::OnUseInWorkspace() { dataObject->setFieldHandler(*fieldHandler); event->objectdata = dataObject; event->objectalias = alias; - emit datasourceSignal(event); + emit datasourceSignal(event); // --> WorkspaceController::processDatasourceEvent() // Tag the item to prevent double import // _studyEditor->setParameterBool(soField,IS_IN_WORKSPACE,true); // Tag the field as persistent on the server. It means that a @@ -347,7 +349,7 @@ void DatasourceController::OnUseInWorkspace() { XmedDataObject* dataObject = new XmedDataObject(); dataObject->setFieldHandler(*fieldHandler); event->objectdata = dataObject; - emit datasourceSignal(event); + emit datasourceSignal(event); // --> WorkspaceController::processDatasourceEvent() // Note that this signal is processed by the WorkspaceController // Tag the item to prevent double import diff --git a/src/MEDCalc/gui/MEDModule.cxx b/src/MEDCalc/gui/MEDModule.cxx index 1a48312be..8cef0f7d1 100644 --- a/src/MEDCalc/gui/MEDModule.cxx +++ b/src/MEDCalc/gui/MEDModule.cxx @@ -41,24 +41,21 @@ #include #ifndef DISABLE_PVVIEWER -#include "PVViewer_ViewModel.h" -#include "PVViewer_GUIElements.h" +#include +#include #endif #include "MEDFactoryClient.hxx" #include "MEDPresentationManager_i.hxx" -#include +#include #include #include #include - //! The only instance of the reference to engine MED_ORB::MED_Gen_var MEDModule::_MED_engine; -//! The only instance of the MEDPresentationManager -MEDCALC::MEDPresentationManager_ptr MEDModule::_presManager; MEDModule::MEDModule() : SalomeApp_Module("MED"), _studyEditor(0), @@ -101,11 +98,6 @@ MEDModule::init() SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" ); _MED_engine = MED_ORB::MED_Gen::_narrow( comp ); } - - // Retrieve MEDFactory to get MEDPresentationManager (sometimes - if ( ! _presManager ) { - _presManager = MEDFactoryClient::getFactory()->getPresentationManager(); - } } //void MEDModule::onEventLoopStarted() @@ -256,6 +248,8 @@ MEDModule::createModuleWidgets() { _xmedDataModel = new XmedDataModel(); _workspaceController->setDataModel(_xmedDataModel); _presentationController = new PresentationController(this); + // ABN: ultimately console driver should be owned by module: everyone needs it, not only WorkspaceController + _presentationController->setConsoleDriver(_workspaceController->getConsoleDriver()); _processingController = new ProcessingController(this); #ifdef MED_HAS_QTTESTING _testController = new TestController(this); @@ -265,7 +259,7 @@ MEDModule::createModuleWidgets() { _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*))); connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)), - _workspaceController, SLOT(processPresentationEvent(const PresentationEvent*))); + _presentationController, SLOT(processPresentationEvent(const PresentationEvent*))); connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)), _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*))); @@ -366,20 +360,27 @@ MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule ); } -MEDCALC::MEDPresentationViewMode -MEDModule::getSelectedViewMode() -{ - return _presentationController->getSelectedViewMode(); -} +//MEDCALC::MEDPresentationViewMode +//MEDModule::getSelectedViewMode() const +//{ +// return _presentationController->getSelectedViewMode(); +//} +// +//MEDCALC::MEDPresentationColorMap +//MEDModule::getSelectedColorMap() const +//{ +// return _presentationController->getSelectedColorMap(); +//} +// +//MEDCALC::MEDPresentationScalarBarRange +//MEDModule::getSelectedScalarBarRange() const +//{ +// return _presentationController->getSelectedScalarBarRange(); +//} -MEDCALC::MEDPresentationColorMap -MEDModule::getSelectedColorMap() -{ - return _presentationController->getSelectedColorMap(); -} bool -MEDModule::itemClickGeneric(const QModelIndex & index, std::string & name, int & fieldId, int & presId) const +MEDModule::itemClickGeneric(const QModelIndex & index, std::string & name, std::string & type, int & fieldId, int & presId) const { DataObjectList dol = getApp()->objectBrowser()->getSelected(); if (dol.isEmpty()) @@ -414,6 +415,9 @@ MEDModule::itemClickGeneric(const QModelIndex & index, std::string & name, int & if (!attrParam->IsSet(PRESENTATION_ID, PT_INTEGER)) return false; presId = attrParam->GetInt(PRESENTATION_ID); + if (!attrParam->IsSet(PRESENTATION_TYPE, PT_STRING)) + return false; + type = attrParam->GetString(PRESENTATION_TYPE); return true; } @@ -421,29 +425,34 @@ void MEDModule::onClick(const QModelIndex & index) { int fieldId, presId; - std::string name; - if (!itemClickGeneric(index, name, fieldId, presId)) - return; + std::string name, type; + if (!itemClickGeneric(index, name, type, fieldId, presId)) + { + // Not a presentation - clear widget: + emit presentationSelected(-1, QString(""), QString("")); + return; + } - STDLOG("Presentation selection (activate view)"); - std::ostringstream oss; - oss << fieldId << " / " << presId; - STDLOG(" - Field id / pres id: " + oss.str()); - STDLOG(" - Presentation name: " + name); +// STDLOG("Presentation selection"); +// std::ostringstream oss; +// oss << fieldId << " / " << presId; +// STDLOG(" - Field id / pres id: " + oss.str()); +// STDLOG(" - Presentation type: " + type); +// STDLOG(" - Presentation name: " + name); - _presManager->activateView(presId); + emit presentationSelected(presId, QString::fromStdString(type), QString::fromStdString(name) ); // caught by PresentationController } void MEDModule::onDblClick(const QModelIndex& index) { int fieldId, presId; - std::string name; - if (!itemClickGeneric(index, name, fieldId, presId)) + std::string name, type; + if (!itemClickGeneric(index, name, type, fieldId, presId)) return; STDLOG("Presentation edition: NOT IMPLEMENTED YET"); - STDLOG(" Presention infos:"); + STDLOG(" Presentation infos:"); // STDLOG(" - Component: " + item->componentDataType().toStdString()); // STDLOG(" - Item entry: " + item->entry().toStdString()); // STDLOG(" - Item name: " + item->name().toStdString()); diff --git a/src/MEDCalc/gui/MEDModule.hxx b/src/MEDCalc/gui/MEDModule.hxx index d32a1c93c..ed3cafce5 100644 --- a/src/MEDCalc/gui/MEDModule.hxx +++ b/src/MEDCalc/gui/MEDModule.hxx @@ -80,14 +80,15 @@ public: const QString& menus="", const QString& rule="client='ObjectBrowser'"); - MEDCALC::MEDPresentationViewMode getSelectedViewMode(); - MEDCALC::MEDPresentationColorMap getSelectedColorMap(); +// MEDCALC::MEDPresentationViewMode getSelectedViewMode() const; +// MEDCALC::MEDPresentationColorMap getSelectedColorMap() const; +// MEDCALC::MEDPresentationScalarBarRange getSelectedScalarBarRange() const; inline SALOME_AppStudyEditor* getStudyEditor() { return _studyEditor; } - void requestSALOMETermination() const; -// bool hasMainEventLoopStarted() const; +signals: + void presentationSelected(int presId, const QString& presType, const QString& presName); public slots: virtual bool activateModule(SUIT_Study* theStudy); @@ -99,7 +100,9 @@ private: void createModuleWidgets(); void createModuleActions(); void initToolbars(); - bool itemClickGeneric(const QModelIndex & index, std::string & name, int & fieldId, int & presId) const; + + bool itemClickGeneric(const QModelIndex & index, std::string & name, + std::string & type, int & fieldId, int & presId) const; static void init(); @@ -121,7 +124,6 @@ private: #ifdef MED_HAS_QTTESTING TestController * _testController; #endif - }; #endif diff --git a/src/MEDCalc/gui/MEDWidgetHelper.cxx b/src/MEDCalc/gui/MEDWidgetHelper.cxx new file mode 100644 index 000000000..015bb8eaa --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelper.cxx @@ -0,0 +1,119 @@ +// Copyright (C) 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 +// + +#include "MEDWidgetHelper.hxx" +#include "PresentationController.hxx" +#include "MEDPresentation.hxx" +#include + +MEDWidgetHelper::MEDWidgetHelper(const PresentationController * presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, + const std::string & presName, WidgetPresentationParameters * paramWidget): + _presController(presController), + _presManager(presManager), + _presId(presId), + _presName(presName), + _paramWidget(paramWidget) +{} + +MEDWidgetHelper::~MEDWidgetHelper() +{} + +void MEDWidgetHelper::loadParametersFromEngine() +{ + _selectedCompo = _presManager->getPresentationIntProperty(_presId, MEDPresentation::PROP_SELECTED_COMPONENT.c_str()); + _nbCompos = _presManager->getPresentationIntProperty(_presId, MEDPresentation::PROP_NB_COMPONENTS.c_str()); + _allCompos.clear(); + _allCompos.reserve(_nbCompos); + for (int i = 0; i < _nbCompos; i++) + { + std::ostringstream oss; + oss << MEDPresentation::PROP_COMPONENT << i; + _allCompos.push_back(_presManager->getPresentationStringProperty(_presId, oss.str().c_str())); + } + _colorMap = static_cast( + _presManager->getPresentationIntProperty(_presId, MEDPresentation::PROP_COLOR_MAP.c_str())); + _scalarBarRange = static_cast( + _presManager->getPresentationIntProperty(_presId, MEDPresentation::PROP_SCALAR_BAR_RANGE.c_str())); +} + +void MEDWidgetHelper::udpateWidget() +{ + // Set presentation name + _paramWidget->setPresName(_presName); + + // Show dynamic part of the widget (i.e. everything else than color map and scalar bar range) + _paramWidget->toggleWidget(true); + + loadParametersFromEngine(); + + // Set properly color map and scalar bar range + _paramWidget->setColorMap(_colorMap); + _paramWidget->setScalarBarRange(_scalarBarRange); + + QObject::connect( _paramWidget, SIGNAL(comboScalarBarRangeIndexChanged(int)), this, SLOT(onScalarBarRangeChanged(int)) ); + QObject::connect( _paramWidget, SIGNAL(comboColorMapIndexChanged(int)), this, SLOT(onColorMapChanged(int)) ); +} + +void MEDWidgetHelper::releaseWidget() +{ + QObject::disconnect( _paramWidget, SIGNAL(comboScalarBarRangeIndexChanged(int)), this, SLOT(onScalarBarRangeChanged(int)) ); + QObject::disconnect( _paramWidget, SIGNAL(comboColorMapIndexChanged(int)), this, SLOT(onColorMapChanged(int)) ); + + // Reset default for color map and scalar bar range + _paramWidget->setColorMap(MEDCALC::COLOR_MAP_DEFAULT); + _paramWidget->setScalarBarRange(MEDCALC::SCALAR_BAR_RANGE_DEFAULT); +} + +void MEDWidgetHelper::onComponentChanged(int idx) +{ + STDLOG("MEDWidgetHelper::onComponentChanged"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_CHANGE_COMPONENT; + event->presentationId = _presId; + event->anInteger = idx; + event->aString = _paramWidget->getComponent(); + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} + +void MEDWidgetHelper::onColorMapChanged(int idx) +{ + STDLOG("MEDWidgetHelper::onColorMapChanged"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_CHANGE_COLORMAP; + event->presentationId = _presId; + // The actual selected item in the combo list is retrieved by the workspace controller _getColorMap() +// event->anInteger = idx; + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} + +void MEDWidgetHelper::onScalarBarRangeChanged(int idx) +{ + STDLOG("MEDWidgetHelper::onScalarBarRangeChanged"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_CHANGE_TIME_RANGE; + event->presentationId = _presId; + event->anInteger = idx; + // The actual selected item in the combo list is retrieved by the workspace controller _getScalarBarRange() + //event->aString = _paramWidget->getScalarBarRange(); + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} diff --git a/src/MEDCalc/gui/MEDWidgetHelper.hxx b/src/MEDCalc/gui/MEDWidgetHelper.hxx new file mode 100644 index 000000000..fa0e6a0c7 --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelper.hxx @@ -0,0 +1,85 @@ +// Copyright (C) 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 +// + +#ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPER_HXX_ +#define SRC_MEDCALC_GUI_MEDWIDGETHELPER_HXX_ + +#include "WidgetPresentationParameters.hxx" +#include "PresentationEvent.hxx" + +#include +#include CORBA_SERVER_HEADER(MEDPresentationManager) + +class WidgetPresentationParameters; +class PresentationController; + +/*! + * The widget helper hierarchy is in charge of seting up the WidgetPresentationParameters + * to display the Qt widgets relevant to the underlying presentation on the component side. + */ +class MEDWidgetHelper : public QObject +{ + Q_OBJECT + +public: + virtual ~MEDWidgetHelper(); + + virtual void udpateWidget(); + virtual void releaseWidget(); + + ///! Returns the string X in the Python command "Update" or "GetParameters" + virtual std::string getPythonTag() const = 0; + +signals: + void presentationUpdateSignal(const PresentationEvent *); + +protected: + // Only child classes to be instanciated: + MEDWidgetHelper(const PresentationController* presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, + WidgetPresentationParameters * paramWidget); + virtual void loadParametersFromEngine(); + +protected slots: + void onComponentChanged(int idx); + void onColorMapChanged(int idx); + void onScalarBarRangeChanged(int idx); + +protected: + ///! GUI needs to talk directly to the pres manager to activate a view, get some params, etc ...: + MEDCALC::MEDPresentationManager_ptr _presManager; + const PresentationController * _presController ; + const int _presId; + const std::string _presName; + + WidgetPresentationParameters* _paramWidget; + + // Component related members + int _selectedCompo; // Selected field component + int _nbCompos; // Total number of available components + std::vector _allCompos; // All available components + + // Color map + MEDCALC::MEDPresentationColorMap _colorMap; + + // Scalar bar range + MEDCALC::MEDPresentationScalarBarRange _scalarBarRange; +}; + +#endif diff --git a/src/MEDCalc/gui/MEDWidgetHelperScalarMap.cxx b/src/MEDCalc/gui/MEDWidgetHelperScalarMap.cxx new file mode 100644 index 000000000..755bf80fa --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperScalarMap.cxx @@ -0,0 +1,55 @@ +// Copyright (C) 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 +// + +#include "MEDWidgetHelperScalarMap.hxx" +#include "MEDPresentationScalarMap.hxx" // from component side. +#include "PresentationController.hxx" + +#include + +MEDWidgetHelperScalarMap::MEDWidgetHelperScalarMap(const PresentationController * presController, MEDCALC::MEDPresentationManager_ptr presManager, int presId, + const std::string & presName, WidgetPresentationParameters * paramW): + MEDWidgetHelper(presController, presManager, presId, presName, paramW) +{ +} + +MEDWidgetHelperScalarMap::~MEDWidgetHelperScalarMap() +{} + +void MEDWidgetHelperScalarMap::udpateWidget() +{ + MEDWidgetHelper::udpateWidget(); + + // Scalar map presentation needs the component name, that's all. + _paramWidget->setComponents(_allCompos, _selectedCompo); + + // Connect combo box changes + QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)), + _presController, SIGNAL(presentationSignal(const PresentationEvent *)) ); + QObject::connect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) ); +} + +void MEDWidgetHelperScalarMap::releaseWidget() +{ + MEDWidgetHelper::releaseWidget(); + + QObject::disconnect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)), + _presController, SIGNAL(presentationSignal(const PresentationEvent *)) ); + QObject::disconnect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) ); +} diff --git a/src/MEDCalc/gui/MEDWidgetHelperScalarMap.hxx b/src/MEDCalc/gui/MEDWidgetHelperScalarMap.hxx new file mode 100644 index 000000000..c068705ed --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperScalarMap.hxx @@ -0,0 +1,48 @@ +// Copyright (C) 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 +// + +#ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERSCALARMAP_HXX_ +#define SRC_MEDCALC_GUI_MEDWIDGETHELPERSCALARMAP_HXX_ + +#include "MEDWidgetHelper.hxx" +#include + +class PresentationController; + +class MEDWidgetHelperScalarMap: public MEDWidgetHelper +{ + Q_OBJECT + +public: + MEDWidgetHelperScalarMap(const PresentationController* presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, + WidgetPresentationParameters * paramW); + virtual ~MEDWidgetHelperScalarMap(); + + virtual void udpateWidget(); + virtual void releaseWidget(); + + virtual std::string getPythonTag() const { return "ScalarMap"; } + +protected: + + +}; + +#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERSCALARMAP_HXX_ */ diff --git a/src/MEDCalc/gui/MED_msg_en.ts b/src/MEDCalc/gui/MED_msg_en.ts index 8841a7d85..73d655dfe 100644 --- a/src/MEDCalc/gui/MED_msg_en.ts +++ b/src/MEDCalc/gui/MED_msg_en.ts @@ -188,8 +188,8 @@ All timesteps - LAB_ONE_TIMESTEP - Selected timestep + LAB_CURRENT_TIMESTEP + Current timestep LAB_USER_RANGE diff --git a/src/MEDCalc/gui/MED_msg_fr.ts b/src/MEDCalc/gui/MED_msg_fr.ts index acf347d1f..be5cf5ba2 100644 --- a/src/MEDCalc/gui/MED_msg_fr.ts +++ b/src/MEDCalc/gui/MED_msg_fr.ts @@ -180,8 +180,8 @@ Tous les pas de temps - LAB_ONE_TIMESTEP - Pas de temps sélectionné + LAB_CURRENT_TIMESTEP + Pas de temps courant LAB_USER_RANGE diff --git a/src/MEDCalc/gui/PresentationController.cxx b/src/MEDCalc/gui/PresentationController.cxx index 1785436a6..0f7735122 100644 --- a/src/MEDCalc/gui/PresentationController.cxx +++ b/src/MEDCalc/gui/PresentationController.cxx @@ -25,6 +25,10 @@ #include "QtxActionToolMgr.h" #include "MEDFactoryClient.hxx" #include "MEDPresentationManager_i.hxx" +#include "XmedConsoleDriver.hxx" + +#include "MEDWidgetHelperScalarMap.hxx" +#include "MEDPresentationScalarMap.hxx" #include #include @@ -39,15 +43,23 @@ #include #include +#include "MEDFactoryClient.hxx" + static const int OPTIONS_VIEW_MODE_ID = 943; static const int OPTIONS_VIEW_MODE_REPLACE_ID = 944; static const int OPTIONS_VIEW_MODE_OVERLAP_ID = 945; static const int OPTIONS_VIEW_MODE_NEW_LAYOUT_ID = 946; static const int OPTIONS_VIEW_MODE_SPLIT_VIEW_ID = 947; +//! The only instance of the MEDPresentationManager +MEDCALC::MEDPresentationManager_ptr PresentationController::_presManager; + PresentationController::PresentationController(MEDModule* salomeModule) : _salomeModule(salomeModule), - _studyEditor(salomeModule->getStudyEditor()) + _consoleDriver(0), + _studyEditor(salomeModule->getStudyEditor()), + _presHelperMap(), + _currentWidgetHelper(0) { STDLOG("Creating a PresentationController"); @@ -63,11 +75,38 @@ PresentationController::PresentationController(MEDModule* salomeModule) : _dockWidget->setWidget(_widgetPresentationParameters); parent->addDockWidget(Qt::LeftDockWidgetArea, _dockWidget); //_dockWidget->show(); + + // Retrieve MEDFactory to get MEDPresentationManager (sometimes GUI needs to talk to the engine directly) + if ( ! _presManager ) { + _presManager = MEDFactoryClient::getFactory()->getPresentationManager(); + } + + // Connect to the click in the object browser + connect(salomeModule, SIGNAL( presentationSelected(int , const QString&, const QString&) ), + this, SLOT(onPresentationSelected(int , const QString&, const QString&) ) ); } PresentationController::~PresentationController() { - STDLOG("Deleting the PresentationController"); + STDLOG("Deleting the resentationController"); + // Clean allocated widget helpers: + for ( std::map::iterator it = _presHelperMap.begin(); it != _presHelperMap.end(); ++it) + delete((*it).second); +} + +/** + * [ABN] Created this probably because I don't know the right way to deal with non existent + * attributes in an object from the study ... + */ +int +PresentationController::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char * name) +{ + int theInt = -1; + try { + theInt = _studyEditor->getParameterInt(obj,name); + } + catch(...) { } + return theInt; } std::string @@ -132,7 +171,7 @@ PresentationController::createActions() tooltip = tr("TIP_PRESENTATION_SCALAR_MAP"); QString icon = tr(_getIconName("ICO_PRESENTATION_SCALAR_MAP").c_str()); int actionId; - actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeScalarMap()),icon,tooltip); + actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeScalarMap()),icon,tooltip); _salomeModule->createTool(actionId, presentationToolbarId); _salomeModule->action(actionId)->setIconVisibleInMenu(true); _salomeModule->createMenu(actionId, presentationMenuId); @@ -140,7 +179,7 @@ PresentationController::createActions() label = tr("LAB_PRESENTATION_CONTOUR"); tooltip = tr("TIP_PRESENTATION_CONTOUR"); icon = tr(_getIconName("ICO_PRESENTATION_CONTOUR").c_str()); - actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeContour()),icon,tooltip); + actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeContour()),icon,tooltip); _salomeModule->createTool(actionId, presentationToolbarId); _salomeModule->action(actionId)->setIconVisibleInMenu(true); _salomeModule->createMenu(actionId, presentationMenuId); @@ -148,7 +187,7 @@ PresentationController::createActions() label = tr("LAB_PRESENTATION_VECTOR_FIELD"); tooltip = tr("TIP_PRESENTATION_VECTOR_FIELD"); icon = tr(_getIconName("ICO_PRESENTATION_VECTOR_FIELD").c_str()); - actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeVectorField()),icon,tooltip); + actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeVectorField()),icon,tooltip); _salomeModule->createTool(actionId, presentationToolbarId); _salomeModule->action(actionId)->setIconVisibleInMenu(true); _salomeModule->createMenu(actionId, presentationMenuId); @@ -156,7 +195,7 @@ PresentationController::createActions() label = tr("LAB_PRESENTATION_SLICES"); tooltip = tr("TIP_PRESENTATION_SLICES"); icon = tr(_getIconName("ICO_PRESENTATION_SLICES").c_str()); - actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeSlices()),icon,tooltip); + actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeSlices()),icon,tooltip); _salomeModule->createTool(actionId, presentationToolbarId); _salomeModule->action(actionId)->setIconVisibleInMenu(true); _salomeModule->createMenu(actionId, presentationMenuId); @@ -164,7 +203,7 @@ PresentationController::createActions() label = tr("LAB_PRESENTATION_DEFLECTION_SHAPE"); tooltip = tr("TIP_PRESENTATION_DEFLECTION_SHAPE"); icon = tr(_getIconName("ICO_PRESENTATION_DEFLECTION_SHAPE").c_str()); - actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeDeflectionShape()),icon,tooltip); + actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeDeflectionShape()),icon,tooltip); _salomeModule->createTool(actionId, presentationToolbarId); _salomeModule->action(actionId)->setIconVisibleInMenu(true); _salomeModule->createMenu(actionId, presentationMenuId); @@ -172,23 +211,36 @@ PresentationController::createActions() label = tr("LAB_PRESENTATION_POINT_SPRITE"); tooltip = tr("TIP_PRESENTATION_POINT_SPRITE"); icon = tr(_getIconName("ICO_PRESENTATION_POINT_SPRITE").c_str()); - actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizePointSprite()),icon,tooltip); + actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizePointSprite()),icon,tooltip); _salomeModule->createTool(actionId, presentationToolbarId); _salomeModule->action(actionId)->setIconVisibleInMenu(true); _salomeModule->createMenu(actionId, presentationMenuId); + // Separator + _salomeModule->createMenu(_salomeModule->separator(), presentationMenuId); + label = tr("LAB_DELETE_PRESENTATION"); tooltip = tr("TIP_DELETE_PRESENTATION"); icon = tr(_getIconName("ICO_DELETE_PRESENTATION").c_str()); - actionId = _salomeModule->createStandardAction(label,this, SLOT(OnDeletePresentation()),icon,tooltip); + actionId = _salomeModule->createStandardAction(label,this, SLOT(onDeletePresentation()),icon,tooltip); // _salomeModule->createTool(actionId, presentationToolbarId); // _salomeModule->action(actionId)->setIconVisibleInMenu(true); _salomeModule->createMenu(actionId, presentationMenuId); + // + // Actions for popup menu only + // + // Low level PARAVIS dump + label = tr("LAB_PARAVIS_DUMP"); + //icon = tr("ICO_DATASOURCE_EXPAND_FIELD"); + actionId = _salomeModule->createStandardAction(label,this,SLOT(onParavisDump()),""); + _salomeModule->addActionInPopupMenu(actionId); + + } MEDCALC::MEDPresentationViewMode -PresentationController::getSelectedViewMode() +PresentationController::getSelectedViewMode() const { if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) { return MEDCALC::VIEW_MODE_REPLACE; @@ -208,11 +260,17 @@ PresentationController::getSelectedViewMode() } MEDCALC::MEDPresentationColorMap -PresentationController::getSelectedColorMap() +PresentationController::getSelectedColorMap() const { return _widgetPresentationParameters->getColorMap(); } +MEDCALC::MEDPresentationScalarBarRange +PresentationController::getSelectedScalarBarRange() const +{ + return _widgetPresentationParameters->getScalarBarRange(); +} + void PresentationController::visualize(PresentationEvent::EventType eventType) { @@ -227,16 +285,10 @@ PresentationController::visualize(PresentationEvent::EventType eventType) // to make a view of an object from the tui console). for (int i=0; isize(); i++) { SALOMEDS::SObject_var soField = listOfSObject->at(i); - int fieldId = -1; - try { - fieldId = _studyEditor->getParameterInt(soField,FIELD_ID); } - catch(...) { } + int fieldId = getIntParamFromStudyEditor(soField, FIELD_ID); if (fieldId < 0) // is it a field serie ? { - int fieldSeriesId = -1; - try { - fieldSeriesId = _studyEditor->getParameterInt(soField,FIELD_SERIES_ID); } - catch(...) { } + int fieldSeriesId = getIntParamFromStudyEditor(soField, FIELD_SERIES_ID); // If fieldId and fieldSeriesId equals -1, then it means that it is not a field // managed by the MED module, and we stop this function process. if ( fieldSeriesId < 0) @@ -259,51 +311,49 @@ PresentationController::visualize(PresentationEvent::EventType eventType) PresentationEvent* event = new PresentationEvent(); event->eventtype = eventType; - XmedDataObject* dataObject = new XmedDataObject(); - dataObject->setFieldHandler(*fieldHandler); - event->objectdata = dataObject; - emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent + event->fieldHandler = fieldHandler; + emit presentationSignal(event); // --> processPresentationEvent() } } void -PresentationController::OnVisualizeScalarMap() +PresentationController::onVisualizeScalarMap() { this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP); } void -PresentationController::OnVisualizeContour() +PresentationController::onVisualizeContour() { this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR); } void -PresentationController::OnVisualizeVectorField() +PresentationController::onVisualizeVectorField() { this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD); } void -PresentationController::OnVisualizeSlices() +PresentationController::onVisualizeSlices() { this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES); } void -PresentationController::OnVisualizeDeflectionShape() +PresentationController::onVisualizeDeflectionShape() { this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE); } void -PresentationController::OnVisualizePointSprite() +PresentationController::onVisualizePointSprite() { this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE); } void -PresentationController::OnDeletePresentation() +PresentationController::onDeletePresentation() { // We need a _studyEditor updated on the active study _studyEditor->updateActiveStudy(); @@ -314,23 +364,230 @@ PresentationController::OnDeletePresentation() // For each object, emit a signal to the workspace to request pres deletion for (int i=0; isize(); i++) { SALOMEDS::SObject_var soPres = listOfSObject->at(i); - int presId = _studyEditor->getParameterInt(soPres,PRESENTATION_ID); + int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID); // If fieldId equals -1, then it means that it is not a field // managed by the MED module, and we stop this function process. if ( presId < 0 ) continue; - STDLOG("Requesting deletion of presentation: ") - std::ostringstream oss; - oss << presId; - STDLOG(" - Pres id: " + oss.str()); - PresentationEvent* event = new PresentationEvent(); event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION; - XmedDataObject* dataObject = new XmedDataObject(); - dataObject->setPresentationId(presId); - event->objectdata = dataObject; - emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent + event->presentationId = presId; + emit presentationSignal(event); // --> processPresentationEvent() + } +} + +QString +PresentationController::getViewModePython() const +{ + MEDCALC::MEDPresentationViewMode viewMode = 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 +PresentationController::getColorMapPython() const +{ + MEDCALC::MEDPresentationColorMap colorMap = 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(); +} + +QString +PresentationController::getScalarBarRangePython() const +{ + MEDCALC::MEDPresentationScalarBarRange colorMap = getSelectedScalarBarRange(); + switch(colorMap) { + case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: return "MEDCALC.SCALAR_BAR_ALL_TIMESTEPS"; + case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: return "MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP"; + } + return QString(); +} + +std::string +PresentationController::getPresTypeFromWidgetHelper(int presId) const +{ + std::map::const_iterator it =_presHelperMap.find(presId); + if (it != _presHelperMap.end()) + return (*it).second->getPythonTag(); + return "UNKNOWN"; +} + +void +PresentationController::processPresentationEvent(const PresentationEvent* event) { + // --> Send commands to SALOME Python console + if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) { + QString viewMode = getViewModePython(); + //QString displayedComponent = ; // from PresentationController combobox + //QString scalarBarRange = ; // from PresentationController spinbox + QString colorMap = getColorMapPython(); + MEDCALC::FieldHandler* fieldHandler = event->fieldHandler; + 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 = getViewModePython(); +// MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler; +// 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 = getViewModePython(); +// MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler; +// 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 = getViewModePython(); +// MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler; +// 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 = getViewModePython(); +// MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler; +// QStringList commands; +// commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); +// commands += QString("presentation_id"); +// _consoleDriver->exec(commands); +// } +// else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) { +// QString viewMode = getViewModePython(); +// MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler; +// QStringList commands; +// commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); +// commands += QString("presentation_id"); +// _consoleDriver->exec(commands); +// } + + // [ABN] using event mechanism for this is awkward? TODO: direct implementation in each + // dedicated widget helper class? + else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COMPONENT ) { + std::string typ = getPresTypeFromWidgetHelper(event->presentationId); + QStringList commands; + commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId); + commands += QString("params.displayedComponent = '%1'").arg(QString::fromStdString(event->aString)); + commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId); + _consoleDriver->exec(commands); + } + else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COLORMAP ) { + std::string typ = getPresTypeFromWidgetHelper(event->presentationId); + QStringList commands; + commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId); + commands += QString("params.colorMap = %1").arg(getColorMapPython()); + commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId); + _consoleDriver->exec(commands); + } + else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_TIME_RANGE ) { + std::string typ = getPresTypeFromWidgetHelper(event->presentationId); + QStringList commands; + commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId); + commands += QString("params.scalarBarRange = %1").arg(getScalarBarRangePython()); + commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId); + _consoleDriver->exec(commands); + } + else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) { + QStringList commands; + commands += QString("medcalc.RemovePresentation(%1)").arg(event->presentationId); + _consoleDriver->exec(commands); + } + else { + STDLOG("The event "<eventtype<<" is not implemented yet"); + } +} + +MEDWidgetHelper * +PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager_ptr presManager, + int presId, const std::string& type, const std::string& name ) +{ + std::map::const_iterator it =_presHelperMap.find(presId); + if (it != _presHelperMap.end()) + return (*it).second; + MEDWidgetHelper * wh; + if (type == MEDPresentationScalarMap::TYPE_NAME) + wh = new MEDWidgetHelperScalarMap(this, _presManager, presId, name, _widgetPresentationParameters); + else + { +// case PRES_CONTOUR: +//// break; +// case PRES_DEFLECTION: +//// break; +// case PRES_VECTOR_FIELD: +// // break; +// case PRES_POINT_SPRITE: +// // break; +// case PRES_POINT_SPRITE: +// // break; +// default: + STDLOG("findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!"); + + } + _presHelperMap[presId] = wh; + return wh; +} + +void +PresentationController::onPresentationSelected(int presId, const QString& presType, const QString& presName) +{ + if (presId == -1) + { + if (_widgetPresentationParameters->isShown()) + { + _widgetPresentationParameters->toggleWidget(false); + if(_currentWidgetHelper) + _currentWidgetHelper->releaseWidget(); + } + } + else + { + // Activate corresponding ParaView render view + _presManager->activateView(presId); + // Update widgets parameters + _currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString()); + _currentWidgetHelper->udpateWidget(); + } +} + +void +PresentationController::onParavisDump() +{ + // We need a _studyEditor updated on the active study + _studyEditor->updateActiveStudy(); + + // Get the selected objects in the study (SObject) + SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects(); + + // For the first object only, request the dump + for (int i=0; isize(); i++) { + SALOMEDS::SObject_var soPres = listOfSObject->at(i); + int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID); + // If fieldId equals -1, then it means that it is not a field + // managed by the MED module, and we stop this function process. + if ( presId < 0 ) + continue; + + std::string dump(_presManager->getParavisDump(presId)); + std::cerr << "#====== ParaVis dump =============== " << std::endl; + std::cerr << dump; + std::cerr << "#====== End of ParaVis dump ======== " << std::endl; + + break; // stop at the first one } } @@ -342,16 +599,22 @@ PresentationController::updateTreeViewWithNewPresentation(long fieldId, long pre return; } - std::string name = MEDFactoryClient::getPresentationManager()->getPresentationProperty(presentationId, "name"); - std::string icon = std::string("ICO_") + name; + std::string name(MEDFactoryClient::getPresentationManager()->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str())); + std::string type = name; + std::string icon = std::string("ICO_") + type; icon = _getIconName(icon); + std::string ico = tr(icon.c_str()).toStdString(); + + // Append presentation ID to the displayed name in the OB: + std::ostringstream oss; name = tr(name.c_str()).toStdString(); - std::string label = tr(icon.c_str()).toStdString(); + oss << name << " (" << presentationId << ")"; SalomeApp_Study* study = dynamic_cast(_salomeModule->application()->activeStudy()); _PTR(Study) studyDS = study->studyDS(); - _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId, name.c_str(), label.c_str(), presentationId); + _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId, + oss.str().c_str(), type.c_str(),ico.c_str(), presentationId); MEDCALC::MEDPresentationViewMode viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId); @@ -414,6 +677,6 @@ PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event) void PresentationController::showDockWidgets(bool isVisible) { - STDLOG("Switching PresentationController visibility to: " << isVisible); _dockWidget->setVisible(isVisible); } + diff --git a/src/MEDCalc/gui/PresentationController.hxx b/src/MEDCalc/gui/PresentationController.hxx index d2d9fc461..98fc9ffb6 100644 --- a/src/MEDCalc/gui/PresentationController.hxx +++ b/src/MEDCalc/gui/PresentationController.hxx @@ -32,22 +32,12 @@ #include #include "WidgetPresentationParameters.hxx" -typedef struct { - enum EventType { - EVENT_VIEW_OBJECT_CONTOUR, - EVENT_VIEW_OBJECT_DEFLECTION_SHAPE, - EVENT_VIEW_OBJECT_POINT_SPRITE, - EVENT_VIEW_OBJECT_SCALAR_MAP, - EVENT_VIEW_OBJECT_SLICES, - EVENT_VIEW_OBJECT_VECTOR_FIELD, - EVENT_DELETE_PRESENTATION - }; - int eventtype; - XmedDataObject* objectdata; -} PresentationEvent; +#include "PresentationEvent.hxx" class MEDModule; class QDockWidget; +class MEDWidgetHelper; +class XmedConsoleDriver; class MEDCALCGUI_EXPORT PresentationController : public QObject { Q_OBJECT @@ -58,38 +48,64 @@ public: void createActions(); - MEDCALC::MEDPresentationViewMode getSelectedViewMode(); - MEDCALC::MEDPresentationColorMap getSelectedColorMap(); + MEDCALC::MEDPresentationViewMode getSelectedViewMode() const; + MEDCALC::MEDPresentationColorMap getSelectedColorMap() const; + MEDCALC::MEDPresentationScalarBarRange getSelectedScalarBarRange() const; void showDockWidgets(bool isVisible); + std::string getPresTypeFromWidgetHelper(int presId) const; + + void setConsoleDriver(XmedConsoleDriver* driver) { _consoleDriver = driver; }; + signals: void presentationSignal(const PresentationEvent*); protected slots: - void OnVisualizeScalarMap(); - void OnVisualizeContour(); - void OnVisualizeVectorField(); - void OnVisualizeSlices(); - void OnVisualizeDeflectionShape(); - void OnVisualizePointSprite(); + void onVisualizeScalarMap(); + void onVisualizeContour(); + void onVisualizeVectorField(); + void onVisualizeSlices(); + void onVisualizeDeflectionShape(); + void onVisualizePointSprite(); - void OnDeletePresentation(); + void onDeletePresentation(); + void onParavisDump(); + + void onPresentationSelected(int presId, const QString& presType, const QString& presName); void processWorkspaceEvent(const MEDCALC::MedEvent*); + void processPresentationEvent(const PresentationEvent* event); private: void visualize(PresentationEvent::EventType); void updateTreeViewWithNewPresentation(long, long); void updateTreeViewForPresentationRemoval(long); std::string _getIconName(const std::string&); + MEDWidgetHelper * findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager_ptr presManager, + int presId, const std::string& type, const std::string& name); + + int getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char * name); + + QString getViewModePython() const; + QString getColorMapPython() const; + QString getScalarBarRangePython() const; private: MEDModule* _salomeModule; + XmedConsoleDriver* _consoleDriver; // the same as in WorkspaceController SALOME_AppStudyEditor* _studyEditor; // borrowed to MEDModule QDockWidget *_dockWidget; WidgetPresentationParameters* _widgetPresentationParameters; + + // GUI needs to talk directly to the pres manager to activate a view, get some params, print low level py dump, etc ...: + static MEDCALC::MEDPresentationManager_ptr _presManager; + + // Key: presentation ID, value MEDPresentationHelper * + std::map _presHelperMap; + + MEDWidgetHelper * _currentWidgetHelper; }; #endif /* PRESENTATION_CONTROLLER_HXX */ diff --git a/src/MEDCalc/gui/PresentationEvent.hxx b/src/MEDCalc/gui/PresentationEvent.hxx new file mode 100644 index 000000000..536631af9 --- /dev/null +++ b/src/MEDCalc/gui/PresentationEvent.hxx @@ -0,0 +1,29 @@ +#ifndef SRC_MEDCALC_GUI_PRESENTATIONEVENT_HXX_ +#define SRC_MEDCALC_GUI_PRESENTATIONEVENT_HXX_ + +#include + +typedef struct { + enum EventType { + EVENT_VIEW_OBJECT_CONTOUR, + EVENT_VIEW_OBJECT_DEFLECTION_SHAPE, + EVENT_VIEW_OBJECT_POINT_SPRITE, + EVENT_VIEW_OBJECT_SCALAR_MAP, + EVENT_VIEW_OBJECT_SLICES, + EVENT_VIEW_OBJECT_VECTOR_FIELD, + EVENT_DELETE_PRESENTATION, + + EVENT_CHANGE_COMPONENT, + EVENT_CHANGE_COLORMAP, + EVENT_CHANGE_TIME_RANGE + }; + + EventType eventtype; + MEDCALC::FieldHandler * fieldHandler; + int presentationId; + int anInteger; // multi-purpose variable + //int anInteger2; // multi-purpose variable + std::string aString; // multi-purpose variable +} PresentationEvent; + +#endif diff --git a/src/MEDCalc/gui/WorkspaceController.cxx b/src/MEDCalc/gui/WorkspaceController.cxx index 8a2231969..ad2c1e231 100644 --- a/src/MEDCalc/gui/WorkspaceController.cxx +++ b/src/MEDCalc/gui/WorkspaceController.cxx @@ -529,113 +529,6 @@ 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() -{ - 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". - // <<< - - 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(); - 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"); - _consoleDriver->exec(commands); - } - else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) { - QString viewMode = _getViewMode(); - MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler(); - QStringList commands; - commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); - commands += QString("presentation_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) { diff --git a/src/MEDCalc/gui/WorkspaceController.hxx b/src/MEDCalc/gui/WorkspaceController.hxx index f85a068e4..c5fac88ad 100644 --- a/src/MEDCalc/gui/WorkspaceController.hxx +++ b/src/MEDCalc/gui/WorkspaceController.hxx @@ -52,6 +52,7 @@ public: ~WorkspaceController(); void createActions(); + XmedConsoleDriver* getConsoleDriver() { return _consoleDriver; } public slots: // Slots overiding TreeGuiManager @@ -60,13 +61,10 @@ public slots: // Internal slots void processMedEvent(const MEDCALC::MedEvent* event); void processDatasourceEvent(const DatasourceEvent* event); - void processPresentationEvent(const PresentationEvent* event); void processProcessingEvent(const ProcessingEvent* event); void OnSaveWorkspace(); void OnCleanWorkspace(); - void onRequestTermination(); - signals: void workspaceSignal(const MEDCALC::MedEvent* event); @@ -81,15 +79,13 @@ private: void _saveItemList(QStringList itemNameIdList); void _removeItemList(QStringList itemNameIdList); void _viewItemList(QStringList itemNameIdList); - QString _getViewMode(); - QString _getColorMap(); private: XmedConsoleDriver* _consoleDriver; MEDModule* _salomeModule; MEDEventListener_i* _medEventListener; - // This structure is intended to memorized in a bundle the whole set + // This structure is intended to memorize in a bundle the whole set // of integers identifying the actions of the popup menu associated // to the TreeView embedded in this TreeGuiManager typedef struct { diff --git a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx index 380784b02..05765430e 100644 --- a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx +++ b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx @@ -20,46 +20,175 @@ #include "WidgetPresentationParameters.hxx" #include +using namespace std; + WidgetPresentationParameters::WidgetPresentationParameters(QWidget* parent) - : QWidget(parent) + : QWidget(parent), _blockSig(false) +{ + _ui.setupUi(this); // To be done first + + toggleWidget(false); + QObject::connect(_ui.comboBoxCompo, SIGNAL(currentIndexChanged(int)), + this, SLOT(onComboCompoIndexChanged(int)) ); + QObject::connect(_ui.comboBoxScalarBarRange, SIGNAL(currentIndexChanged(int)), + this, SLOT(onComboScalarBarRangeIndexChanged(int)) ); + QObject::connect(_ui.comboBoxColorMap, SIGNAL(currentIndexChanged(int)), + this, SLOT(onComboColorMapIndexChanged(int)) ); +} + +void +WidgetPresentationParameters::onComboCompoIndexChanged(int idx) +{ + if (!_blockSig) emit comboCompoIndexChanged(idx); +} + +void +WidgetPresentationParameters::onComboColorMapIndexChanged(int idx) +{ + if (!_blockSig) emit comboColorMapIndexChanged(idx); +} + +void +WidgetPresentationParameters::onComboScalarBarRangeIndexChanged(int idx) +{ + if (!_blockSig) emit comboScalarBarRangeIndexChanged(idx); +} + + +void +WidgetPresentationParameters::toggleWidget(bool show) +{ + if (!show) + { + _blockSig = true; + _ui.widgetDynamic->hide(); + setPresName("Choose a presentation"); + // reset colorMap and scalarBarRange: + setColorMap(MEDCALC::COLOR_MAP_DEFAULT); + setScalarBarRange(MEDCALC::SCALAR_BAR_RANGE_DEFAULT); + } + else + { + _ui.widgetDynamic->show(); + // It is the WidgetHelper responsability to re-show the widgets it needs + _ui.labelCompo->hide(); + _ui.comboBoxCompo->hide(); + _ui.labelSpinBox->hide(); + _ui.spinBox->hide(); + _ui.labelSliceOrient->hide(); + _ui.comboBoxSliceOrient->hide(); + _blockSig = false; + } +} + +bool +WidgetPresentationParameters::isShown() const { - ui.setupUi(this); // To be done first + return _ui.widgetDynamic->isVisible(); } -std::string -WidgetPresentationParameters::getField() +string +WidgetPresentationParameters::getComponent() const { - return this->ui.comboBoxField->currentText().toStdString(); + if (_ui.comboBoxCompo->currentIndex() == 0) // Euclidean norm + return ""; + + return _ui.comboBoxCompo->currentText().toStdString(); } -std::string -WidgetPresentationParameters::getScalarBarRange() +void +WidgetPresentationParameters::setComponents(vector compos, int selecIndex) { - return this->ui.comboBoxScalarBarRange->currentText().toStdString(); + // Show the widget: + _ui.labelCompo->show(); + _ui.comboBoxCompo->show(); + + _blockSig = true; + _ui.comboBoxCompo->clear(); + _ui.comboBoxCompo->addItem(tr("LAB_EUCLIDEAN_NORM")); + for(vector::const_iterator it = compos.begin(); it != compos.end(); ++it) + _ui.comboBoxCompo->addItem(QString::fromStdString(*it)); + _ui.comboBoxCompo->setCurrentIndex(selecIndex); + _blockSig = false; } -double -WidgetPresentationParameters::getScalarBarTimestep() +void +WidgetPresentationParameters::setScalarBarRange(MEDCALC::MEDPresentationScalarBarRange sbrange) { - return this->ui.doubleSpinBoxTimeStep->value(); + int idx; + if (sbrange == MEDCALC::SCALAR_BAR_ALL_TIMESTEPS) + idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_ALL_TIMESTEPS")); + else if (sbrange == MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP) + idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_CURRENT_TIMESTEP")); + + if (idx >= 0) + { + _blockSig = true; + _ui.comboBoxScalarBarRange->setCurrentIndex(idx); + _blockSig = false; + } + else + STDLOG("Strange!! No matching found - unable to set scalar bar range in GUI."); } -double -WidgetPresentationParameters::getScalarBarMinVal() +void +WidgetPresentationParameters::setColorMap(MEDCALC::MEDPresentationColorMap colorMap) { - return this->ui.doubleSpinBoxMinVal->value(); + int idx; + if (colorMap == MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW) + idx = _ui.comboBoxColorMap->findText(tr("LAB_BLUE_TO_RED")); + else if (colorMap == MEDCALC::COLOR_MAP_COOL_TO_WARM) + idx = _ui.comboBoxColorMap->findText(tr("LAB_COOL_TO_WARM")); + + if (idx >= 0) + { + _blockSig = true; + _ui.comboBoxColorMap->setCurrentIndex(idx); + _blockSig = false; + } + + else + STDLOG("Strange!! No matching found - unable to set color map in GUI."); } -double -WidgetPresentationParameters::getScalarBarMaxVal() + +MEDCALC::MEDPresentationScalarBarRange +WidgetPresentationParameters::getScalarBarRange() const { - return this->ui.doubleSpinBoxMaxVal->value(); + QString sbrange = _ui.comboBoxScalarBarRange->currentText(); + if (sbrange == tr("LAB_ALL_TIMESTEPS")) { + return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS; + } + else if (sbrange == tr("LAB_CURRENT_TIMESTEP")) { + return MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP; + } + // Should not happen + STDLOG("Strange!! No matching found - returning SCALAR_BAR_ALL_TIMESTEPS."); + return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS; } +//double +//WidgetPresentationParameters::getScalarBarTimestep() const +//{ +// return _ui.doubleSpinBoxTimeStep->value(); +//} +// +//double +//WidgetPresentationParameters::getScalarBarMinVal() const +//{ +// return _ui.doubleSpinBoxMinVal->value(); +//} +// +//double +//WidgetPresentationParameters::getScalarBarMaxVal() const +//{ +// return _ui.doubleSpinBoxMaxVal->value(); +//} + MEDCALC::MEDPresentationColorMap -WidgetPresentationParameters::getColorMap() +WidgetPresentationParameters::getColorMap() const { - QString colorMap = this->ui.comboBoxColorMap->currentText(); + QString colorMap = _ui.comboBoxColorMap->currentText(); if (colorMap == tr("LAB_BLUE_TO_RED")) { return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW; } @@ -70,3 +199,18 @@ WidgetPresentationParameters::getColorMap() STDLOG("Strange!! No matching color map found - returning blue to red."); return MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW; } + +QComboBox * +WidgetPresentationParameters::getComboBoxCompo() +{ + return _ui.comboBoxCompo; +} + +void +WidgetPresentationParameters::setPresName(const std::string& name) +{ + _ui.labelPresName->setText(QString::fromStdString(name)); + QFont f(_ui.labelPresName->font()); + f.setItalic(true); + _ui.labelPresName->setFont(f); +} diff --git a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx index 8e1905a8c..03f70bdb0 100644 --- a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx +++ b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx @@ -28,6 +28,8 @@ #include CORBA_SERVER_HEADER(MEDPresentationManager) #include +#include +#include class MEDCALCGUI_DIALOGS_EXPORT WidgetPresentationParameters : public QWidget { @@ -37,15 +39,37 @@ public: WidgetPresentationParameters(QWidget* parent = 0); virtual ~WidgetPresentationParameters() {} - std::string getField(); - std::string getScalarBarRange(); - double getScalarBarTimestep(); - double getScalarBarMinVal(); - double getScalarBarMaxVal(); - MEDCALC::MEDPresentationColorMap getColorMap(); + std::string getComponent() const; + void setComponents(std::vector compos, int selecIndex); - private: - Ui_WidgetPresentationParameters ui; // instance of the class defined in ui_WidgetPresentationParameters.h + MEDCALC::MEDPresentationScalarBarRange getScalarBarRange() const; + void setScalarBarRange(MEDCALC::MEDPresentationScalarBarRange); + +// double getScalarBarTimestep() const; +// double getScalarBarMinVal() const; +// double getScalarBarMaxVal() const; + MEDCALC::MEDPresentationColorMap getColorMap() const; + void setColorMap(MEDCALC::MEDPresentationColorMap); + + void setPresName(const std::string& name); + + void toggleWidget(bool show); + bool isShown() const; + QComboBox * getComboBoxCompo(); + +signals: + void comboScalarBarRangeIndexChanged(int); + void comboColorMapIndexChanged(int); + void comboCompoIndexChanged(int); + +private slots: + void onComboScalarBarRangeIndexChanged(int); + void onComboColorMapIndexChanged(int); + void onComboCompoIndexChanged(int); + +private: + Ui_WidgetPresentationParameters _ui; // instance of the class defined in ui_WidgetPresentationParameters.h + bool _blockSig; }; diff --git a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.ui b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.ui index 291ef54fe..85279d369 100644 --- a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.ui +++ b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.ui @@ -6,8 +6,8 @@ 0 0 - 404 - 200 + 439 + 359 @@ -19,145 +19,161 @@ Form - - - + + + - LAB_DISP_COMP + LAB_PRES_NAME - - - - - LAB_EUCLIDEAN_NORM - - + + + + + + + true + + + + LAB_ALL_TIMESTEPS + + + + + LAB_CURRENT_TIMESTEP + + + + + + + + LAB_COLOR_MAP + + + + + + + + LAB_BLUE_TO_RED + + + + + LAB_COOL_TO_WARM + + + + + + + + + 0 + 0 + + + + LAB_RANGE + + + + - - - - false - - - LAB_TIMESTEP - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + Qt::Horizontal - - - - false - - - - - - - false - - - LAB_MIN_VALUE - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + + + + + + + LAB_DISP_COMP + + + + + + + + LAB_EUCLIDEAN_NORM + + + + + + + + LAB_SPIN_BOX + + + + + + + + + + Qt::Horizontal + + + + 235 + 20 + + + + + + + + LAB_SLICE_ORIENT + + + + + + + + LAB_SLICE_NORMAL_TO_X + + + + + LAB_SLICE_NORMAL_TO_Y + + + + + LAB_SLICE_NORMAL_TO_Z + + + + + - - - - false - - - - - - - false - - - LAB_MAX_VALUE - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - false - - - - - - - LAB_COLOR_MAP - - - - - - - - LAB_BLUE_TO_RED - - - - - LAB_COOL_TO_WARM - - - - - - - - true - - - - LAB_ALL_TIMESTEPS - - - - - LAB_ONE_TIMESTEP - - - - - LAB_USER_RANGE - - - - - - - - LAB_SCALARBAR - - - - - - - true - - - LAB_RANGE - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + Qt::Vertical + + + + 20 + 167 + + + diff --git a/src/MEDCalc/tui/__init__.py b/src/MEDCalc/tui/__init__.py index 0877a8c1d..1bf752c9e 100644 --- a/src/MEDCalc/tui/__init__.py +++ b/src/MEDCalc/tui/__init__.py @@ -40,13 +40,17 @@ from medio import LoadImageAsDataSource # Presentations from medpresentation import MakeScalarMap -from medpresentation import MakeContour -from medpresentation import MakeVectorField -from medpresentation import MakeSlices -from medpresentation import MakeDeflectionShape -from medpresentation import MakePointSprite +#from medpresentation import MakeContour +#from medpresentation import MakeVectorField +#from medpresentation import MakeSlices +#from medpresentation import MakeDeflectionShape +#from medpresentation import MakePointSprite from medpresentation import RemovePresentation +from medpresentation import GetScalarMapParameters + +from medpresentation import UpdateScalarMap + # Console commands import medconsole diff --git a/src/MEDCalc/tui/fieldproxy.py b/src/MEDCalc/tui/fieldproxy.py index 04d252b9a..ac80b13a0 100644 --- a/src/MEDCalc/tui/fieldproxy.py +++ b/src/MEDCalc/tui/fieldproxy.py @@ -48,7 +48,7 @@ def _typeOfFieldLabel(typeOfField): try: return __mapTypeOfFieldLabel[typeOfField] except IndexError, e: - return "UNCKNOWN" + return "UNKNOWN" # def newFieldProxy(fieldHandlerId): diff --git a/src/MEDCalc/tui/medpresentation.py b/src/MEDCalc/tui/medpresentation.py index c48eebd48..8762d9a02 100644 --- a/src/MEDCalc/tui/medpresentation.py +++ b/src/MEDCalc/tui/medpresentation.py @@ -25,73 +25,70 @@ __manager = medcalc.medcorba.factory.getPresentationManager() def MakeScalarMap(proxy, viewMode=MEDCALC.VIEW_MODE_DEFAULT, - displayedInfo=MEDCALC.DISPLAY_DEFAULT, - scalarBarRange=MEDCALC.ScalarBarRange(MEDCALC.SCALAR_BAR_RANGE_VAL_MIN_DEFAULT, - MEDCALC.SCALAR_BAR_RANGE_VAL_MAX_DEFAULT), + displayedComponent=MEDCALC.DISPLAY_DEFAULT, + scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT, colorMap=MEDCALC.COLOR_MAP_DEFAULT ): # Create the presentation instance in CORBA engine # The engine in turn creates the ParaView pipeline elements - params = MEDCALC.ScalarMapParameters(proxy.id, viewMode, displayedInfo, scalarBarRange, colorMap) - presentation_id = __manager.makeScalarMap(params) + params = MEDCALC.ScalarMapParameters(proxy.id, displayedComponent, scalarBarRange, colorMap) + presentation_id = __manager.makeScalarMap(params, viewMode) notifyGui_addPresentation(proxy.id, presentation_id) return presentation_id # -def MakeContour(proxy, - viewMode=MEDCALC.VIEW_MODE_DEFAULT, - displayedInfo=MEDCALC.DISPLAY_DEFAULT, - scalarBarRange=MEDCALC.ScalarBarRange(MEDCALC.SCALAR_BAR_RANGE_VAL_MIN_DEFAULT, - MEDCALC.SCALAR_BAR_RANGE_VAL_MAX_DEFAULT), - colorMap=MEDCALC.COLOR_MAP_DEFAULT, - nbContours=MEDCALC.NB_CONTOURS_DEFAULT - ): - params = MEDCALC.ContourParameters(proxy.id, viewMode, displayedInfo, scalarBarRange, colorMap, nbContours) - presentation_id = __manager.makeContour(params) - notifyGui_addPresentation(proxy.id, presentation_id) - return presentation_id +#def MakeContour(proxy, +# viewMode=MEDCALC.VIEW_MODE_DEFAULT, +# displayedComponent=MEDCALC.DISPLAY_DEFAULT, +# scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT, +# colorMap=MEDCALC.COLOR_MAP_DEFAULT, +# nbContours=MEDCALC.NB_CONTOURS_DEFAULT +# ): +# params = MEDCALC.ContourParameters(proxy.id, viewMode, displayedComponent, scalarBarRange, colorMap, nbContours) +# presentation_id = __manager.makeContour(params) +# notifyGui_addPresentation(proxy.id, presentation_id) +# return presentation_id +## # - -def MakeVectorField(proxy, - viewMode=MEDCALC.VIEW_MODE_DEFAULT - ): - params = MEDCALC.VectorFieldParameters(proxy.id, viewMode) - presentation_id = __manager.makeVectorField(params) - notifyGui_addPresentation(proxy.id, presentation_id) - return presentation_id +#def MakeVectorField(proxy, +# viewMode=MEDCALC.VIEW_MODE_DEFAULT +# ): +# params = MEDCALC.VectorFieldParameters(proxy.id, viewMode) +# presentation_id = __manager.makeVectorField(params) +# notifyGui_addPresentation(proxy.id, presentation_id) +# return presentation_id +## # - -def MakeSlices(proxy, - viewMode=MEDCALC.VIEW_MODE_DEFAULT, - orientation=MEDCALC.SLICE_ORIENTATION_DEFAULT, - nbSlices=MEDCALC.NB_SLICES_DEFAULT - ): - params = MEDCALC.SlicesParameters(proxy.id, viewMode, orientation, nbSlices) - presentation_id = __manager.makeSlices(params) - notifyGui_addPresentation(proxy.id, presentation_id) - return presentation_id +#def MakeSlices(proxy, +# viewMode=MEDCALC.VIEW_MODE_DEFAULT, +# orientation=MEDCALC.SLICE_ORIENTATION_DEFAULT, +# nbSlices=MEDCALC.NB_SLICES_DEFAULT +# ): +# params = MEDCALC.SlicesParameters(proxy.id, viewMode, orientation, nbSlices) +# presentation_id = __manager.makeSlices(params) +# notifyGui_addPresentation(proxy.id, presentation_id) +# return presentation_id +## # - -def MakeDeflectionShape(proxy, - viewMode=MEDCALC.VIEW_MODE_DEFAULT - ): - params = MEDCALC.DeflectionShapeParameters(proxy.id, viewMode) - presentation_id = __manager.makeDeflectionShape(params) - notifyGui_addPresentation(proxy.id, presentation_id) - return presentation_id +#def MakeDeflectionShape(proxy, +# viewMode=MEDCALC.VIEW_MODE_DEFAULT +# ): +# params = MEDCALC.DeflectionShapeParameters(proxy.id, viewMode) +# presentation_id = __manager.makeDeflectionShape(params) +# notifyGui_addPresentation(proxy.id, presentation_id) +# return presentation_id +## # - -def MakePointSprite(proxy, - viewMode=MEDCALC.VIEW_MODE_DEFAULT, - displayedInfo=MEDCALC.DISPLAY_DEFAULT, - scalarBarRange=MEDCALC.ScalarBarRange(MEDCALC.SCALAR_BAR_RANGE_VAL_MIN_DEFAULT, - MEDCALC.SCALAR_BAR_RANGE_VAL_MAX_DEFAULT), - colorMap=MEDCALC.COLOR_MAP_DEFAULT, - ): - params = MEDCALC.PointSpriteParameters(proxy.id, viewMode, displayedInfo, scalarBarRange, colorMap) - presentation_id = __manager.makePointSprite(params) - notifyGui_addPresentation(proxy.id, presentation_id) - return presentation_id +#def MakePointSprite(proxy, +# viewMode=MEDCALC.VIEW_MODE_DEFAULT, +# displayedComponent=MEDCALC.DISPLAY_DEFAULT, +# scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT, +# colorMap=MEDCALC.COLOR_MAP_DEFAULT, +# ): +# params = MEDCALC.PointSpriteParameters(proxy.id, viewMode, displayedComponent, scalarBarRange, colorMap) +# presentation_id = __manager.makePointSprite(params) +# notifyGui_addPresentation(proxy.id, presentation_id) +# return presentation_id # def RemovePresentation(presentation_id): @@ -99,3 +96,11 @@ def RemovePresentation(presentation_id): if ok: notifyGui_removePresentation(presentation_id) # + +def GetScalarMapParameters(presentation_id): + # TODO: check that pres id is really a ScalarMap ... + params = __manager.getScalarMapParameters(presentation_id) + return params + +def UpdateScalarMap(presentation_id, params): + __manager.updateScalarMap(presentation_id, params)