From: abn Date: Mon, 1 Aug 2016 07:55:17 +0000 (+0200) Subject: [MEDCalc] Contour presentation X-Git-Tag: V8_1_0b1~15 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5f54667df6e8f1fb2558e85ab67c440ea98d4e93;p=modules%2Fmed.git [MEDCalc] Contour presentation --- diff --git a/idl/MEDEventListener.idl b/idl/MEDEventListener.idl index 97a84d6f1..60c6b11e7 100644 --- a/idl/MEDEventListener.idl +++ b/idl/MEDEventListener.idl @@ -37,6 +37,7 @@ module MEDCALC EVENT_REMOVE_PRESENTATION, EVENT_PLAY_TEST, EVENT_QUIT_SALOME, + EVENT_ERROR, EVENT_UNKNOWN }; @@ -45,6 +46,7 @@ module MEDCALC long dataId; string filename; long presentationId; + string msg; }; interface MEDEventListener: SALOME::GenericObj { diff --git a/idl/MEDPresentationManager.idl b/idl/MEDPresentationManager.idl index a62aaa241..d95aca9bc 100644 --- a/idl/MEDPresentationManager.idl +++ b/idl/MEDPresentationManager.idl @@ -72,7 +72,6 @@ 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; const string DISPLAY_DEFAULT = DISPLAY_EUCLIDEAN_NORM; @@ -90,20 +89,25 @@ module MEDCALC }; // A contour is an isoline in 2D and an isosurface in 3D -// struct ContourParameters { + struct ContourParameters { // Contour are only for scalar fields + long fieldHandlerId; + MEDPresentationScalarBarRange scalarBarRange; + MEDPresentationColorMap colorMap; + long nbContours; + }; + +// struct VectorFieldParameters { // long fieldHandlerId; // string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name -// ScalarBarRange scalarBarRange; +// MEDPresentationScalarBarRange scalarBarRange; // MEDPresentationColorMap colorMap; -// long nbContours; -// }; -// -// struct VectorFieldParameters { -// long fieldHandlerId; // }; // // struct SlicesParameters { // long fieldHandlerId; +// string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name +// MEDPresentationScalarBarRange scalarBarRange; +// MEDPresentationColorMap colorMap; // SliceOrientation orientation; // long nbSlices; // }; @@ -115,7 +119,7 @@ module MEDCALC // struct PointSpriteParameters { // long fieldHandlerId; // string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name -// ScalarBarRange scalarBarRange; +// MEDPresentationScalarBarRange scalarBarRange; // MEDPresentationColorMap colorMap; // }; @@ -126,7 +130,8 @@ module MEDCALC interface MEDPresentationManager : SALOME::GenericObj { long makeScalarMap(in ScalarMapParameters params, in MEDPresentationViewMode viewMode); -// long makeContour(in ContourParameters params, in MEDPresentationViewMode viewMode); + long makeContour(in ContourParameters params, in MEDPresentationViewMode viewMode) + raises (SALOME::SALOME_Exception); // long makeVectorField(in VectorFieldParameters params, in MEDPresentationViewMode viewMode); // long makeSlices(in SlicesParameters params, in MEDPresentationViewMode viewMode); // long makeDeflectionShape(in DeflectionShapeParameters params, in MEDPresentationViewMode viewMode); @@ -138,9 +143,10 @@ module MEDCALC long getPresentationIntProperty(in long presId, in string propName); ScalarMapParameters getScalarMapParameters(in long presId); + ContourParameters getContourParameters(in long presId); void updateScalarMap(in long presId, in ScalarMapParameters params); -// void updateContour(in long presId, in ContourParameters 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); @@ -153,7 +159,7 @@ module MEDCALC // Low level ParaVis dump string getParavisDump(in long presId); - + // MEDPresentationViewMode getPresentationViewMode(in long presId); PresentationsList getAllPresentations(); diff --git a/src/MEDCalc/cmp/CMakeLists.txt b/src/MEDCalc/cmp/CMakeLists.txt index 22657a8ea..edad94b61 100644 --- a/src/MEDCalc/cmp/CMakeLists.txt +++ b/src/MEDCalc/cmp/CMakeLists.txt @@ -40,7 +40,7 @@ SET(COMMON_SOURCES MEDPresentation.cxx # presentations MEDPresentationScalarMap.cxx -# MEDPresentationContour.cxx + MEDPresentationContour.cxx # MEDPresentationVectorField.cxx # MEDPresentationSlices.cxx # MEDPresentationDeflectionShape.cxx diff --git a/src/MEDCalc/cmp/MEDPresentation.cxx b/src/MEDCalc/cmp/MEDPresentation.cxx index 88c4a2fcf..04e618dab 100644 --- a/src/MEDCalc/cmp/MEDPresentation.cxx +++ b/src/MEDCalc/cmp/MEDPresentation.cxx @@ -47,8 +47,6 @@ MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const s _colorMap(colorMap), _sbRange(sbRange), _renderViewPyId(-1), // will be set by getRenderViewCommand() - _objId(GeneratePythonId()), - _dispId(_objId), _lutId(_objId), _globalDict(0) { MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager()); @@ -72,8 +70,20 @@ MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const s 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)); + setIntProperty(MEDPresentation::PROP_COLOR_MAP, static_cast(colorMap)); + setIntProperty(MEDPresentation::PROP_SCALAR_BAR_RANGE, static_cast(sbRange)); + + // Python variables: + int id = GeneratePythonId(); + std::ostringstream oss_o, oss_d, oss_l, oss_s; + oss_o << "__obj" << id; + oss_s << "__srcObj" << id; + oss_d << "__disp" << id; + oss_l << "__lut" << id; + _objVar = oss_o.str(); + _srcObjVar = oss_s.str(); + _dispVar = oss_d.str(); + _lutVar = oss_l.str(); } MEDPresentation::~MEDPresentation() @@ -81,10 +91,9 @@ MEDPresentation::~MEDPresentation() STDLOG("~MEDPresentation(): clear display"); { MEDPyLockWrapper lock; - std::ostringstream oss_o, oss_v, oss; - oss_o << "__obj" << _objId; + std::ostringstream oss_v, oss; oss_v << "__view" << _renderViewPyId; - oss << "pvs.Hide(" << oss_o.str() << ", view=" << oss_v.str() << ");"; + oss << "pvs.Hide(" << _objVar << ", view=" << oss_v.str() << ");"; oss << "pvs.Render();"; PyRun_SimpleString(oss.str().c_str()); @@ -117,7 +126,7 @@ void MEDPresentation::execPyLine(const std::string & lin) { MEDPyLockWrapper lock; -// STDLOG("@@@@ MEDPresentation::execPyLine() about to exec >> " << lin); + STDLOG("@@@@ MEDPresentation::execPyLine() about to exec >> " << lin); if(PyRun_SimpleString(lin.c_str())) { std::ostringstream oss; @@ -126,7 +135,6 @@ MEDPresentation::execPyLine(const std::string & lin) STDLOG(oss.str()); throw KERNEL::createSalomeException(oss.str().c_str()); } - } void @@ -228,13 +236,20 @@ MEDPresentation::getFieldTypeString(MEDCoupling::TypeOfField fieldType) const } } +std::string +MEDPresentation::getRenderViewVar() const +{ + std::ostringstream oss; + oss << "__view" << _renderViewPyId; + return oss.str(); +} + std::string MEDPresentation::getRenderViewCommand() const { std::ostringstream oss, oss2; - oss << "__view" << _renderViewPyId; - std::string view(oss.str()); + std::string view(getRenderViewVar()); oss2 << "pvs._DisableFirstRenderCameraReset();" << std::endl; if (_viewMode == MEDCALC::VIEW_MODE_OVERLAP) { // this might potentially re-assign to an existing view variable, but this is OK, we @@ -257,25 +272,23 @@ MEDPresentation::getRenderViewCommand() const std::string MEDPresentation::getResetCameraCommand() const { - std::ostringstream oss; - oss << "__view" << _renderViewPyId << ".ResetCamera();"; - return oss.str(); + return getRenderViewVar() + ".ResetCamera();"; } std::string MEDPresentation::getComponentSelectionCommand() const { std::ostringstream oss, oss_l; - oss_l << "__lut" << _lutId; std::string lut(oss_l.str()); + std::string ret; if (_selectedComponentIndex != -1) { - oss << lut << ".VectorMode = 'Component';\n"; - oss << lut << ".VectorComponent = " << _selectedComponentIndex << ";"; + oss << _lutVar << ".VectorMode = 'Component';\n"; + oss << _lutVar << ".VectorComponent = " << _selectedComponentIndex << ";"; } else // Euclidean norm { - oss << lut << ".VectorMode = 'Magnitude';"; + oss << _lutVar << ".VectorMode = 'Magnitude';"; } return oss.str(); } @@ -283,39 +296,37 @@ MEDPresentation::getComponentSelectionCommand() const std::string MEDPresentation::getColorMapCommand() const { - std::ostringstream oss, oss_l; - oss_l << "__lut" << _lutId; std::string lut(oss_l.str()); + std::string ret; switch (_colorMap) { case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: - oss << lut << ".ApplyPreset('Blue to Red Rainbow',True);"; + ret = _lutVar + ".ApplyPreset('Blue to Red Rainbow',True);"; break; case MEDCALC::COLOR_MAP_COOL_TO_WARM: - oss << lut << ".ApplyPreset('Cool to Warm',True);"; + ret = _lutVar + ".ApplyPreset('Cool to Warm',True);"; break; default: STDLOG("MEDPresentation::getColorMapCommand(): invalid colormap!"); throw KERNEL::createSalomeException("MEDPresentation::getColorMapCommand(): invalid colormap!"); } - return oss.str(); + return ret; } std::string MEDPresentation::getRescaleCommand() const { - std::ostringstream oss, oss_d; - oss_d << "__disp" << _dispId; std::string disp(oss_d.str()); + std::string ret; switch(_sbRange) { case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: - oss << disp << ".RescaleTransferFunctionToDataRangeOverTime();"; + ret = _dispVar + ".RescaleTransferFunctionToDataRangeOverTime();"; break; case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: - oss << disp << ".RescaleTransferFunctionToDataRange(False);"; + ret = _dispVar + ".RescaleTransferFunctionToDataRange(False);"; break; default: STDLOG("MEDPresentation::getRescaleCommand(): invalid range!"); throw KERNEL::createSalomeException("MEDPresentation::getRescaleCommand(): invalid range!"); } - return oss.str(); + return ret; } int @@ -329,10 +340,7 @@ void MEDPresentation::activateView() { MEDPyLockWrapper lock; - - std::ostringstream oss; - oss << "pvs.SetActiveView(__view" << _renderViewPyId << ");"; - pushAndExecPyLine(oss.str()); + pushAndExecPyLine("pvs.SetActiveView(" + getRenderViewVar() + ");"); } @@ -361,9 +369,6 @@ void MEDPresentation::fillAvailableFieldComponents() { MEDPyLockWrapper lock; // GIL! - - std::ostringstream oss_o; - oss_o << "__obj" << _objId; std::string obj(oss_o.str()); std::string typ; if(_fieldType == "CELLS") { @@ -379,7 +384,7 @@ MEDPresentation::fillAvailableFieldComponents() } std::ostringstream oss; - oss << "__nbCompo = " << obj << "." << typ << ".GetArray('" << _fieldName << "').GetNumberOfComponents();"; + oss << "__nbCompo = " << _srcObjVar << "." << typ << ".GetArray('" << _fieldName << "').GetNumberOfComponents();"; execPyLine(oss.str()); PyObject* p_obj = getPythonObjectFromMain("__nbCompo"); long nbCompo; @@ -394,7 +399,7 @@ MEDPresentation::fillAvailableFieldComponents() for (long i = 0; i +#undef LOG // should be fixed in KERNEL - double definition +#include + +#include + +const std::string MEDPresentationContour::TYPE_NAME = "MEDPresentationContour"; const std::string MEDPresentationContour::PROP_NB_CONTOUR = "nbContour"; +MEDPresentationContour::MEDPresentationContour(const MEDCALC::ContourParameters& params, + const MEDCALC::MEDPresentationViewMode viewMode) : + MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), + _params(params) +{ + setIntProperty(MEDPresentationContour::PROP_NB_CONTOUR, params.nbContours); +} + +std::string +MEDPresentationContour::getContourCommand() const +{ + std::ostringstream oss1; + + oss1 << "min_max = " << _srcObjVar << ".PointData.GetArray('" << _fieldName << "').GetRange();\n"; + oss1 << "delta = (min_max[1]-min_max[0])/float(" << _params.nbContours << ");\n"; + oss1 << _objVar << ".Isosurfaces = [min_max[0]+0.5*delta+i*delta for i in range(" << _params.nbContours << ")];\n"; + return oss1.str(); +} + void MEDPresentationContour::internalGeneratePipeline() { -// PyGILState_STATE _gil_state = PyGILState_Ensure(); -// -// std::string cmd = std::string("import pvsimple as pvs;"); -// cmd += getRenderViewCommand(_params.viewMode); // define __view1 -// -// cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');"); -// cmd += std::string("__isovolume1 = pvs.IsoVolume(Input=__obj1);"); -// cmd += std::string("__disp1 = pvs.Show(__isovolume1, __view1);"); -// cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));"); -// cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);"); -// cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();"); -// cmd += std::string("pvs.Render();"); -// -// cmd += getResetCameraCommand(); -// -// //std::cerr << "Python command:" << std::endl; -// //std::cerr << cmd << std::endl; -// PyRun_SimpleString(cmd.c_str()); -// // Retrieve Python object for internal storage: -// PyObject* obj = getPythonObjectFromMain("__isovolume1"); -// PyObject* disp = getPythonObjectFromMain("__disp1"); -// pushInternal(obj, disp); -// -// PyGILState_Release(_gil_state); + MEDPresentation::internalGeneratePipeline(); + + MEDPyLockWrapper lock; + + std::ostringstream oss_o, oss; + std::string view(getRenderViewVar()); + + oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');"; + pushAndExecPyLine(oss.str()); oss.str(""); + + // Populate internal array of available components: + fillAvailableFieldComponents(); + if (getIntProperty(MEDPresentation::PROP_NB_COMPONENTS) > 1) + { + const char * msg = "Contour presentation only works for scalar field!"; // this message will appear in GUI too + STDLOG(msg); + throw KERNEL::createSalomeException(msg); + } + + pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX + + if(_fieldType == "CELLS") + { + // In case of a CELLS field need to convert to POINT field, and update source + STDLOG("Applying CellDatatoPointData filter"); + std::ostringstream oss2, oss4; + // Apply Cell data to point data: + oss2 << "__obj" << GeneratePythonId(); + oss << oss2.str() << " = pvs.CellDatatoPointData(Input=" << _srcObjVar << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + // Now the source becomes the result of the CellDatatoPointData: + _srcObjVar = oss2.str(); + } + oss << _objVar << " = pvs.Contour(Input=" << _srcObjVar << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _objVar << ".ContourBy = ['POINTS', '" << _fieldName << "'];"; + pushAndExecPyLine(oss.str()); oss.str(""); + + // Set number of contours + pushAndExecPyLine(getContourCommand()); + + oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << "pvs.ColorBy(" << _dispVar << ", ('POINTS', '" << _fieldName << "'));"; // necessarily POINTS + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _dispVar << ".SetScalarBarVisibility(" << view << ", True);"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << getRescaleCommand(); + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');"; + pushAndExecPyLine(oss.str()); oss.str(""); + pushAndExecPyLine(getColorMapCommand()); oss.str(""); + pushAndExecPyLine(getResetCameraCommand()); + pushAndExecPyLine("pvs.Render();"); } void MEDPresentationContour::updatePipeline(const MEDCALC::ContourParameters& params) { - // :TODO: + if (params.fieldHandlerId != _params.fieldHandlerId) + throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!"); + + if (params.scalarBarRange != _params.scalarBarRange) + updateScalarBarRange(params.scalarBarRange); + if (params.colorMap != _params.colorMap) + updateColorMap(params.colorMap); + + if (params.nbContours != _params.nbContours) + updateNbContours(params.nbContours); +} + +void +MEDPresentationContour::updateNbContours(const int nbContours) +{ + _params.nbContours = nbContours; + + // GUI helper: + setIntProperty(MEDPresentationContour::PROP_NB_CONTOUR, nbContours); + + // Update the pipeline: + { + MEDPyLockWrapper lock; + std::string cmd = getContourCommand(); + pushAndExecPyLine(cmd); + pushAndExecPyLine("pvs.Render();"); + } } diff --git a/src/MEDCalc/cmp/MEDPresentationContour.hxx b/src/MEDCalc/cmp/MEDPresentationContour.hxx index 36acc6f72..4fb42ab28 100644 --- a/src/MEDCalc/cmp/MEDPresentationContour.hxx +++ b/src/MEDCalc/cmp/MEDPresentationContour.hxx @@ -26,19 +26,24 @@ class MEDCALC_EXPORT MEDPresentationContour : public MEDPresentation { public: + static const std::string TYPE_NAME; static const std::string PROP_NB_CONTOUR; - MEDPresentationContour(const MEDCALC::ContourParameters& params) : - MEDPresentation(params.fieldHandlerId, "MEDPresentationContour"), _params(params) - {} + MEDPresentationContour(const MEDCALC::ContourParameters& params, const MEDCALC::MEDPresentationViewMode viewMode); virtual ~MEDPresentationContour() {} void updatePipeline(const MEDCALC::ContourParameters& params); - MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } +// MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } + + void getParameters(MEDCALC::ContourParameters & params) const { params = _params; } ; + void setParameters(const MEDCALC::ContourParameters & params) { _params = params; } ; protected: + void updateNbContours(const int nbContours); virtual void internalGeneratePipeline(); + std::string getContourCommand() const; + private: MEDCALC::ContourParameters _params; }; diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx index 8fc47d514..fc758a161 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx @@ -23,9 +23,9 @@ // presentations #include "MEDPresentationScalarMap.hxx" -//#include "MEDPresentationContour.hxx" -//#include "MEDPresentationVectorField.hxx" +#include "MEDPresentationContour.hxx" //#include "MEDPresentationSlices.hxx" +//#include "MEDPresentationVectorField.hxx" //#include "MEDPresentationDeflectionShape.hxx" //#include "MEDPresentationPointSprite.hxx" @@ -128,12 +128,12 @@ MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& para return _makePresentation(params, viewMode); } -//MEDPresentation::TypeID -//MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params) -//{ -// return _makePresentation(params); -//} -// +MEDPresentation::TypeID +MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params, const MEDCALC::MEDPresentationViewMode viewMode) +{ + return _makePresentation(params, viewMode); +} + //MEDPresentation::TypeID //MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params) //{ @@ -167,18 +167,26 @@ MEDPresentationManager_i::getScalarMapParameters(MEDPresentation::TypeID present return tmp._retn(); } +MEDCALC::ContourParameters +MEDPresentationManager_i::getContourParameters(MEDPresentation::TypeID presentationID) +{ + MEDCALC::ContourParameters p; + _getParameters(presentationID, p); + return p; +} + void MEDPresentationManager_i::updateScalarMap(MEDPresentation::TypeID presentationID, const MEDCALC::ScalarMapParameters& params) { return _updatePresentation(presentationID, params); } -//void -//MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& 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) //{ @@ -232,6 +240,7 @@ MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID) presentation->activateView(); _activeViewPythonId = presentation->getPyViewID(); + STDLOG("Activated view " << _activeViewPythonId); return true; } diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx index 82fabe186..1016968e8 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx @@ -40,7 +40,7 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, static MEDPresentationManager_i* getInstance(); 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 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&); @@ -53,9 +53,10 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, MEDCALC_EXPORT CORBA::Long getPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName); MEDCALC_EXPORT MEDCALC::ScalarMapParameters* getScalarMapParameters(MEDPresentation::TypeID presentationID); + MEDCALC_EXPORT MEDCALC::ContourParameters getContourParameters(MEDPresentation::TypeID presentationID); MEDCALC_EXPORT void updateScalarMap(MEDPresentation::TypeID, const MEDCALC::ScalarMapParameters&); -// MEDCALC_EXPORT void updateContour(MEDPresentation::TypeID, const MEDCALC::ContourParameters&); + 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&); diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.txx b/src/MEDCalc/cmp/MEDPresentationManager_i.txx index 3ae7c4986..898140895 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.txx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.txx @@ -29,19 +29,18 @@ MEDPresentationManager_i::_makePresentation(const PresentationParameters params, int activeViewId = getActiveViewPythonId(); // Replace = Remove then add + std::vector to_del; if (viewMode == MEDCALC::VIEW_MODE_REPLACE) { // Remove all presentations from this view: + STDLOG("About to remove all presentations from view " << activeViewId); std::map::const_iterator it; - std::vector to_del; for (it = _presentations.begin(); it != _presentations.end(); ++it) { int viewId2 = (*it).second->getPyViewID(); if (viewId2 == activeViewId) to_del.push_back((*it).first); } - for (std::vector::const_iterator it2 = to_del.begin(); it2 != to_del.end(); ++it2) - removePresentation(*it2); } // Create a new presentation instance @@ -64,6 +63,11 @@ MEDPresentationManager_i::_makePresentation(const PresentationParameters params, _presentations.insert( std::pair(newID, presentation) ); presentation->generatePipeline(); + + // If generatePipeline didn't throw, we can actually remove presentations to be deleted: + for (std::vector::const_iterator it2 = to_del.begin(); it2 != to_del.end(); ++it2) + removePresentation(*it2); + // Make the view holding the newly created presentation the active one: activateView(newID); return newID; diff --git a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx index 573a34b39..50d6ebbdc 100644 --- a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx +++ b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx @@ -43,15 +43,12 @@ MEDPresentationScalarMap::internalGeneratePipeline() MEDPyLockWrapper lock; - 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()); - oss_v << "__view" << _renderViewPyId; std::string view(oss_v.str()); + std::ostringstream oss; + std::string view(getRenderViewVar()); pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX - oss << obj << " = pvs.MEDReader(FileName='" << _fileName << "');"; + oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');"; pushAndExecPyLine(oss.str()); oss.str(""); // Populate internal array of available components: @@ -59,15 +56,17 @@ MEDPresentationScalarMap::internalGeneratePipeline() // dumpIntProperties(); // dumpStringProperties(); - oss << disp << " = pvs.Show(" << obj << ", " << view << ");"; + pushAndExecPyLine(_objVar + " = " + _srcObjVar); + + oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");"; pushAndExecPyLine(oss.str()); oss.str(""); - oss << "pvs.ColorBy(" << disp << ", ('" << _fieldType << "', '" << _fieldName << "'));"; + oss << "pvs.ColorBy(" << _dispVar << ", ('" << _fieldType << "', '" << _fieldName << "'));"; pushAndExecPyLine(oss.str()); oss.str(""); - oss << disp << ".SetScalarBarVisibility(" << view << ", True);"; + oss << _dispVar << ".SetScalarBarVisibility(" << view << ", True);"; pushAndExecPyLine(oss.str()); oss.str(""); oss << getRescaleCommand(); pushAndExecPyLine(oss.str()); oss.str(""); - oss << lut << " = pvs.GetColorTransferFunction('" << _fieldName << "');"; + oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');"; pushAndExecPyLine(oss.str()); oss.str(""); pushAndExecPyLine(getColorMapCommand()); oss.str(""); pushAndExecPyLine(getResetCameraCommand()); @@ -85,8 +84,13 @@ MEDPresentationScalarMap::updatePipeline(const MEDCALC::ScalarMapParameters& par if (params.fieldHandlerId != _params.fieldHandlerId) throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!"); - if (params.displayedComponent != _params.displayedComponent) - updateComponent(std::string(params.displayedComponent)); + if (std::string(params.displayedComponent) != std::string(_params.displayedComponent)) + { + STDLOG("about to updateCompo in scalar map"); + STDLOG("from param " << params.displayedComponent); + STDLOG("from intern " << _params.displayedComponent); + updateComponent(std::string(params.displayedComponent)); + } if (params.scalarBarRange != _params.scalarBarRange) updateScalarBarRange(params.scalarBarRange); if (params.colorMap != _params.colorMap) diff --git a/src/MEDCalc/gui/CMakeLists.txt b/src/MEDCalc/gui/CMakeLists.txt index 66c91bb24..f0398bb01 100644 --- a/src/MEDCalc/gui/CMakeLists.txt +++ b/src/MEDCalc/gui/CMakeLists.txt @@ -39,6 +39,7 @@ SET(MEDCALCGUI_SOURCES XmedDataModel.cxx MEDWidgetHelper.cxx MEDWidgetHelperScalarMap.cxx + MEDWidgetHelperContour.cxx ) IF(SALOME_MED_WITH_QTTESTING) @@ -54,6 +55,7 @@ SET(MEDCALCGUI_HEADERS ProcessingController.hxx MEDWidgetHelper.hxx MEDWidgetHelperScalarMap.hxx + MEDWidgetHelperContour.hxx ) IF(SALOME_MED_WITH_QTTESTING) diff --git a/src/MEDCalc/gui/MEDWidgetHelperContour.cxx b/src/MEDCalc/gui/MEDWidgetHelperContour.cxx new file mode 100644 index 000000000..40ded91d5 --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperContour.cxx @@ -0,0 +1,80 @@ +// 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 "MEDWidgetHelperContour.hxx" +#include "MEDPresentationContour.hxx" // from component side. +#include "PresentationController.hxx" + +#include + +#include + +MEDWidgetHelperContour::MEDWidgetHelperContour(const PresentationController * presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, + const std::string & presName, WidgetPresentationParameters * paramW): + MEDWidgetHelper(presController, presManager, presId, presName, paramW), + _nbContours(-1) +{} + +MEDWidgetHelperContour::~MEDWidgetHelperContour() +{} + +void MEDWidgetHelperContour::loadParametersFromEngine() +{ + MEDWidgetHelper::loadParametersFromEngine(); + _nbContours = _presManager->getPresentationIntProperty(_presId, MEDPresentationContour::PROP_NB_CONTOUR.c_str()); +} + +void MEDWidgetHelperContour::udpateWidget() +{ + MEDWidgetHelper::udpateWidget(); + STDLOG("MEDWidgetHelperContour::udpateWidget() nbContour is " << _nbContours); + + // Contour presentation needs the number of contours +// _paramWidget->setComponents(_allCompos, _selectedCompo); + _paramWidget->setNbContour(_nbContours); + + // 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)) ); + QObject::connect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbContourChanged(int)) ); +} + +void MEDWidgetHelperContour::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)) ); + QObject::disconnect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbContourChanged(int)) ); +} + +void MEDWidgetHelperContour::onNbContourChanged(int nbContour) +{ + STDLOG("MEDWidgetHelperContour::onNbContourChanged"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_CHANGE_NB_CONTOUR; + event->presentationId = _presId; + event->anInteger = nbContour; + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} + diff --git a/src/MEDCalc/gui/MEDWidgetHelperContour.hxx b/src/MEDCalc/gui/MEDWidgetHelperContour.hxx new file mode 100644 index 000000000..0e545fe78 --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperContour.hxx @@ -0,0 +1,52 @@ +// 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_MEDWIDGETHELPERCONTOUR_HXX_ +#define SRC_MEDCALC_GUI_MEDWIDGETHELPERCONTOUR_HXX_ + +#include "MEDWidgetHelper.hxx" + +class PresentationController; + +class MEDWidgetHelperContour: public MEDWidgetHelper +{ + Q_OBJECT + +public: + MEDWidgetHelperContour(const PresentationController* presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, + WidgetPresentationParameters * paramW); + virtual ~MEDWidgetHelperContour(); + + virtual void udpateWidget(); + virtual void releaseWidget(); + + virtual std::string getPythonTag() const { return "Contour"; } + +protected slots: + void onNbContourChanged(int nbContour); + +protected: + virtual void loadParametersFromEngine(); + +private: + int _nbContours; +}; + +#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERCONTOUR_HXX_ */ diff --git a/src/MEDCalc/gui/MEDWidgetHelperScalarMap.hxx b/src/MEDCalc/gui/MEDWidgetHelperScalarMap.hxx index c068705ed..ee17a5307 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperScalarMap.hxx +++ b/src/MEDCalc/gui/MEDWidgetHelperScalarMap.hxx @@ -21,7 +21,6 @@ #define SRC_MEDCALC_GUI_MEDWIDGETHELPERSCALARMAP_HXX_ #include "MEDWidgetHelper.hxx" -#include class PresentationController; @@ -39,10 +38,6 @@ public: virtual void releaseWidget(); virtual std::string getPythonTag() const { return "ScalarMap"; } - -protected: - - }; #endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERSCALARMAP_HXX_ */ diff --git a/src/MEDCalc/gui/PresentationController.cxx b/src/MEDCalc/gui/PresentationController.cxx index a845c48f8..9d9b7c0ba 100644 --- a/src/MEDCalc/gui/PresentationController.cxx +++ b/src/MEDCalc/gui/PresentationController.cxx @@ -27,8 +27,11 @@ #include "MEDPresentationManager_i.hxx" #include "XmedConsoleDriver.hxx" -#include "MEDWidgetHelperScalarMap.hxx" #include "MEDPresentationScalarMap.hxx" +#include "MEDPresentationContour.hxx" + +#include "MEDWidgetHelperScalarMap.hxx" +#include "MEDWidgetHelperContour.hxx" #include #include @@ -55,11 +58,11 @@ static const int OPTIONS_VIEW_MODE_SPLIT_VIEW_ID = 947; MEDCALC::MEDPresentationManager_ptr PresentationController::_presManager; PresentationController::PresentationController(MEDModule* salomeModule) : - _salomeModule(salomeModule), - _consoleDriver(0), - _studyEditor(salomeModule->getStudyEditor()), - _presHelperMap(), - _currentWidgetHelper(0) + _salomeModule(salomeModule), + _consoleDriver(0), + _studyEditor(salomeModule->getStudyEditor()), + _presHelperMap(), + _currentWidgetHelper(0) { STDLOG("Creating a PresentationController"); @@ -79,11 +82,11 @@ PresentationController::PresentationController(MEDModule* salomeModule) : // 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&) ) ); + this, SLOT(onPresentationSelected(int , const QString&, const QString&) ) ); } PresentationController::~PresentationController() @@ -119,9 +122,9 @@ PresentationController::_getIconName(const std::string& name) // Read value from preferences and suffix name to select icon theme int theme = mgr->integerValue("MEDCalc", "icons"); if (theme == 0) { - return name + "_MODERN"; + return name + "_MODERN"; } else if (theme == 1) { - return name + "_CLASSIC"; + return name + "_CLASSIC"; } return name + "_DEFAULT"; } @@ -223,8 +226,8 @@ PresentationController::createActions() tooltip = tr("TIP_DELETE_PRESENTATION"); icon = tr(_getIconName("ICO_DELETE_PRESENTATION").c_str()); actionId = _salomeModule->createStandardAction(label,this, SLOT(onDeletePresentation()),icon,tooltip); -// _salomeModule->createTool(actionId, presentationToolbarId); -// _salomeModule->action(actionId)->setIconVisibleInMenu(true); + // _salomeModule->createTool(actionId, presentationToolbarId); + // _salomeModule->action(actionId)->setIconVisibleInMenu(true); _salomeModule->createMenu(actionId, presentationMenuId); // @@ -243,16 +246,16 @@ MEDCALC::MEDPresentationViewMode PresentationController::getSelectedViewMode() const { if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) { - return MEDCALC::VIEW_MODE_REPLACE; + return MEDCALC::VIEW_MODE_REPLACE; } else if (_salomeModule->action(OPTIONS_VIEW_MODE_OVERLAP_ID)->isChecked()) { - return MEDCALC::VIEW_MODE_OVERLAP; + return MEDCALC::VIEW_MODE_OVERLAP; } else if (_salomeModule->action(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID)->isChecked()) { - return MEDCALC::VIEW_MODE_NEW_LAYOUT; + return MEDCALC::VIEW_MODE_NEW_LAYOUT; } else if (_salomeModule->action(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID)->isChecked()) { - return MEDCALC::VIEW_MODE_SPLIT_VIEW; + return MEDCALC::VIEW_MODE_SPLIT_VIEW; } // Should not happen STDLOG("Strange!! No matching view mode found - returning VIEW_MODE_REPLACE."); @@ -284,35 +287,35 @@ PresentationController::visualize(PresentationEvent::EventType eventType) // visualisation using the tui command (so that the user can see how // 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 = getIntParamFromStudyEditor(soField, FIELD_ID); - if (fieldId < 0) // is it a field serie ? - { - 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) - continue; - MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId); - if (fieldHandlerList->length() < 0) - continue; - // For a field series, get the first real field entry: - MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0]; - fieldId = fieldHandler.id; - } + SALOMEDS::SObject_var soField = listOfSObject->at(i); + int fieldId = getIntParamFromStudyEditor(soField, FIELD_ID); + if (fieldId < 0) // is it a field serie ? + { + 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) + continue; + MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId); + if (fieldHandlerList->length() < 0) + continue; + // For a field series, get the first real field entry: + MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0]; + fieldId = fieldHandler.id; + } - MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId); - if (! fieldHandler) { - QMessageBox::warning(_salomeModule->getApp()->desktop(), - tr("Operation not allowed"), - tr("No field is defined")); - return; - } + MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId); + if (! fieldHandler) { + QMessageBox::warning(_salomeModule->getApp()->desktop(), + tr("Operation not allowed"), + tr("No field is defined")); + return; + } - PresentationEvent* event = new PresentationEvent(); - event->eventtype = eventType; - event->fieldHandler = fieldHandler; - emit presentationSignal(event); // --> processPresentationEvent() + PresentationEvent* event = new PresentationEvent(); + event->eventtype = eventType; + event->fieldHandler = fieldHandler; + emit presentationSignal(event); // --> processPresentationEvent() } } @@ -363,17 +366,17 @@ 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 = 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; - - PresentationEvent* event = new PresentationEvent(); - event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION; - event->presentationId = presId; - emit presentationSignal(event); // --> processPresentationEvent() + 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; + + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION; + event->presentationId = presId; + emit presentationSignal(event); // --> processPresentationEvent() } } @@ -382,10 +385,10 @@ 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"; + 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(); } @@ -395,8 +398,8 @@ 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"; + 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(); } @@ -405,11 +408,11 @@ 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(); + 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 @@ -417,99 +420,78 @@ PresentationController::getPresTypeFromWidgetHelper(int presId) const { std::map::const_iterator it =_presHelperMap.find(presId); if (it != _presHelperMap.end()) - return (*it).second->getPythonTag(); + return (*it).second->getPythonTag(); return "UNKNOWN"; } void PresentationController::processPresentationEvent(const PresentationEvent* event) { // --> Send commands to SALOME Python console + QString viewMode = getViewModePython(); + QString colorMap = getColorMapPython(); + QString scalarBarRange = getScalarBarRangePython(); + MEDCALC::FieldHandler* fieldHandler = event->fieldHandler; + QStringList commands; 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); + commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") + .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); + commands += QString("presentation_id"); + } + else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) { + commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") + .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); + commands += QString("presentation_id"); } -// 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); -// } + // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) { + // commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); + // commands += QString("presentation_id"); + // } + // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) { + // commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); + // commands += QString("presentation_id"); + // } + // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) { + // commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); + // commands += QString("presentation_id"); + // } + // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) { + // commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); + // commands += QString("presentation_id"); + // } // [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_CHANGE_NB_CONTOUR ) { + std::string typ = getPresTypeFromWidgetHelper(event->presentationId); + commands += QString("params = medcalc.GetContourParameters(%2)").arg(event->presentationId); + commands += QString("params.nbContours = %1").arg(event->anInteger); + commands += QString("medcalc.UpdateContour(%1, params)").arg(event->presentationId); } 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"); + STDLOG("The event "<eventtype<<" is not implemented yet"); } + _consoleDriver->exec(commands); } MEDWidgetHelper * @@ -522,22 +504,24 @@ PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager MEDWidgetHelper * wh; if (type == MEDPresentationScalarMap::TYPE_NAME) wh = new MEDWidgetHelperScalarMap(this, _presManager, presId, name, _widgetPresentationParameters); + else if (type == MEDPresentationContour::TYPE_NAME) + wh = new MEDWidgetHelperContour(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: + // 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; } @@ -575,19 +559,19 @@ PresentationController::onParavisDump() // 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 + 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 } } @@ -595,8 +579,8 @@ void PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId) { if (presentationId < 0) { - std::cerr << "Unknown presentation\n"; - return; + std::cerr << "Unknown presentation\n"; + return; } std::string name(_presManager->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str())); @@ -617,30 +601,30 @@ PresentationController::updateTreeViewWithNewPresentation(long fieldId, long pre oss.str().c_str(), type.c_str(),ico.c_str(), presentationId); -// MEDCALC::MEDPresentationViewMode viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId); -// -// // Remove sibling presentations if view mode is set to REPLACE -// if (viewMode == MEDCALC::VIEW_MODE_REPLACE) { -// MED_ORB::PresentationsList* presList = _salomeModule->engine()->getSiblingPresentations(_CAST(Study, studyDS)->GetStudy(), presentationId); -// CORBA::ULong size = presList->length(); -// -// std::stringstream sstm; -// sstm << "Removing sibling presentation(s): "; -// for (int i = 0; i < size; ++i) -// sstm << (*presList)[i] << " "; -// STDLOG(sstm.str()); -// -// for (int i = 0; i < size; ++i) { -// PresentationEvent* event = new PresentationEvent(); -// event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION; -// XmedDataObject* dataObject = new XmedDataObject(); -// dataObject->setPresentationId((*presList)[i]); -// event->objectdata = dataObject; -// emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent -// } -// -// delete presList; -// } + // MEDCALC::MEDPresentationViewMode viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId); + // + // // Remove sibling presentations if view mode is set to REPLACE + // if (viewMode == MEDCALC::VIEW_MODE_REPLACE) { + // MED_ORB::PresentationsList* presList = _salomeModule->engine()->getSiblingPresentations(_CAST(Study, studyDS)->GetStudy(), presentationId); + // CORBA::ULong size = presList->length(); + // + // std::stringstream sstm; + // sstm << "Removing sibling presentation(s): "; + // for (int i = 0; i < size; ++i) + // sstm << (*presList)[i] << " "; + // STDLOG(sstm.str()); + // + // for (int i = 0; i < size; ++i) { + // PresentationEvent* event = new PresentationEvent(); + // event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION; + // XmedDataObject* dataObject = new XmedDataObject(); + // dataObject->setPresentationId((*presList)[i]); + // event->objectdata = dataObject; + // emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent + // } + // + // delete presList; + // } // update Object browser _salomeModule->getApp()->updateObjectBrowser(true); @@ -650,8 +634,8 @@ void PresentationController::updateTreeViewForPresentationRemoval(long presentationId) { if (presentationId < 0) { - std::cerr << "Unknown presentation\n"; - return; + std::cerr << "Unknown presentation\n"; + return; } SalomeApp_Study* study = dynamic_cast(_salomeModule->application()->activeStudy()); @@ -688,7 +672,7 @@ PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event) } } else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) { - updateTreeViewForPresentationRemoval(event->presentationId); + updateTreeViewForPresentationRemoval(event->presentationId); } } diff --git a/src/MEDCalc/gui/PresentationEvent.hxx b/src/MEDCalc/gui/PresentationEvent.hxx index 536631af9..784fbb314 100644 --- a/src/MEDCalc/gui/PresentationEvent.hxx +++ b/src/MEDCalc/gui/PresentationEvent.hxx @@ -15,7 +15,9 @@ typedef struct { EVENT_CHANGE_COMPONENT, EVENT_CHANGE_COLORMAP, - EVENT_CHANGE_TIME_RANGE + EVENT_CHANGE_TIME_RANGE, + + EVENT_CHANGE_NB_CONTOUR }; EventType eventtype; diff --git a/src/MEDCalc/gui/WorkspaceController.cxx b/src/MEDCalc/gui/WorkspaceController.cxx index ad2c1e231..f135d38fc 100644 --- a/src/MEDCalc/gui/WorkspaceController.cxx +++ b/src/MEDCalc/gui/WorkspaceController.cxx @@ -36,6 +36,7 @@ #include #include +#include /*! * This class defines a DockWidget plugged in the SALOME application, @@ -319,6 +320,10 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent* event) { else if ( event->type == MEDCALC::EVENT_QUIT_SALOME ) { emit workspaceSignal(event); // forward to TestController } + else if ( event->type == MEDCALC::EVENT_ERROR ) { + std::string msg(event->msg); + QMessageBox::warning(_salomeModule->getApp()->desktop(), "Error", QString::fromStdString(msg)); + } } /*! diff --git a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx index 05765430e..4e7231b11 100644 --- a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx +++ b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx @@ -34,6 +34,8 @@ WidgetPresentationParameters::WidgetPresentationParameters(QWidget* parent) this, SLOT(onComboScalarBarRangeIndexChanged(int)) ); QObject::connect(_ui.comboBoxColorMap, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboColorMapIndexChanged(int)) ); + QObject::connect(_ui.spinBox, SIGNAL(valueChanged(int)), + this, SLOT(onSpinBoxValueChanged(int)) ); } void @@ -54,6 +56,11 @@ WidgetPresentationParameters::onComboScalarBarRangeIndexChanged(int idx) if (!_blockSig) emit comboScalarBarRangeIndexChanged(idx); } +void +WidgetPresentationParameters::onSpinBoxValueChanged(int val) +{ + if (!_blockSig) emit spinBoxValueChanged(val); +} void WidgetPresentationParameters::toggleWidget(bool show) @@ -112,6 +119,30 @@ WidgetPresentationParameters::setComponents(vector compos, int selecInde _blockSig = false; } +void +WidgetPresentationParameters::setNbContour(int nbContour) +{ + if (nbContour <= 0) + { + //TODO throw? + STDLOG("WidgetPresentationParameters::setNbContour(): invalid number of contours!"); + } + + // Show the widget: + _ui.labelSpinBox->setText(tr("LAB_NB_CONTOUR")); + _ui.labelSpinBox->show(); + _ui.spinBox->show(); + + _blockSig = true; + _ui.spinBox->setValue(nbContour); + _blockSig = false; +} + +int WidgetPresentationParameters::getNbContour() const +{ + return _ui.spinBox->value(); +} + void WidgetPresentationParameters::setScalarBarRange(MEDCALC::MEDPresentationScalarBarRange sbrange) { diff --git a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx index 03f70bdb0..42888a65a 100644 --- a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx +++ b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx @@ -53,6 +53,9 @@ public: void setPresName(const std::string& name); + int getNbContour() const; + void setNbContour(int nbContour); + void toggleWidget(bool show); bool isShown() const; QComboBox * getComboBoxCompo(); @@ -61,11 +64,13 @@ signals: void comboScalarBarRangeIndexChanged(int); void comboColorMapIndexChanged(int); void comboCompoIndexChanged(int); + void spinBoxValueChanged(int); private slots: void onComboScalarBarRangeIndexChanged(int); void onComboColorMapIndexChanged(int); void onComboCompoIndexChanged(int); + void onSpinBoxValueChanged(int); private: Ui_WidgetPresentationParameters _ui; // instance of the class defined in ui_WidgetPresentationParameters.h diff --git a/src/MEDCalc/test/tui/contour.py b/src/MEDCalc/test/tui/contour.py new file mode 100644 index 000000000..b1e47e4c1 --- /dev/null +++ b/src/MEDCalc/test/tui/contour.py @@ -0,0 +1,45 @@ +# 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 +# + +import os +from time import sleep + +import medcalc +medcalc.medconsole.setConsoleGlobals(globals()) +import MEDCALC +from medcalc.medconsole import accessField + +from medcalc_testutils import GetMEDFileDirTUI + +datafile = os.path.join(GetMEDFileDirTUI(), "agitateur.med") +source_id = medcalc.LoadDataSource(datafile) + +# Field 0 = CONCENTRATION_ELEM_DOM (ON_CELLS) -> scalar +presentation_id = medcalc.MakeContour(accessField(0), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW) +sleep(2) +medcalc.RemovePresentation(presentation_id) +sleep(2) + +# Field 55 = VITESSE_ELEM_DOM (ON_CELLS) -> vector field, contour should fail. +try: + presentation_id = medcalc.MakeContour(accessField(55), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW) + sys.exit(-1); +except: + print "Contour failed as expected." +sleep(2) diff --git a/src/MEDCalc/test/tui/medfiles/agitateur.med b/src/MEDCalc/test/tui/medfiles/agitateur.med new file mode 100644 index 000000000..73c62e127 Binary files /dev/null and b/src/MEDCalc/test/tui/medfiles/agitateur.med differ diff --git a/src/MEDCalc/test/tui/scalar_map.py b/src/MEDCalc/test/tui/scalar_map.py index 54541ad23..343aa051d 100644 --- a/src/MEDCalc/test/tui/scalar_map.py +++ b/src/MEDCalc/test/tui/scalar_map.py @@ -17,22 +17,20 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +import os +from time import sleep + import medcalc medcalc.medconsole.setConsoleGlobals(globals()) import MEDCALC - -from medcalc.medconsole import saveWorkspace, cleanWorkspace -from medcalc.medconsole import putInWorkspace, removeFromWorkspace from medcalc.medconsole import accessField -from medcalc.medconsole import getEnvironment, ls, la - -import os from medcalc_testutils import GetMEDFileDirTUI datafile = os.path.join(GetMEDFileDirTUI(), "smooth_surface_and_field.med") source_id = medcalc.LoadDataSource(datafile) -presentation_id = medcalc.MakeScalarMap(accessField(source_id), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW) - +presentation_id = medcalc.MakeScalarMap(accessField(0), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW) +sleep(2) medcalc.RemovePresentation(presentation_id) +sleep(2) diff --git a/src/MEDCalc/tui/__init__.py b/src/MEDCalc/tui/__init__.py index 1bf752c9e..cf4dd4ea9 100644 --- a/src/MEDCalc/tui/__init__.py +++ b/src/MEDCalc/tui/__init__.py @@ -40,7 +40,7 @@ from medio import LoadImageAsDataSource # Presentations from medpresentation import MakeScalarMap -#from medpresentation import MakeContour +from medpresentation import MakeContour #from medpresentation import MakeVectorField #from medpresentation import MakeSlices #from medpresentation import MakeDeflectionShape @@ -48,8 +48,10 @@ from medpresentation import MakeScalarMap from medpresentation import RemovePresentation from medpresentation import GetScalarMapParameters +from medpresentation import GetContourParameters from medpresentation import UpdateScalarMap +from medpresentation import UpdateContour # Console commands import medconsole diff --git a/src/MEDCalc/tui/medevents.py b/src/MEDCalc/tui/medevents.py index 2c819f6b3..42a3f55c1 100644 --- a/src/MEDCalc/tui/medevents.py +++ b/src/MEDCalc/tui/medevents.py @@ -83,8 +83,8 @@ connectEventListener() # that they could be used in another context than the FieldProxy instances import MEDCALC -def __notifyGui(eventType, dataId=-1, filename="", presentationId=-1): - medEvent = MEDCALC.MedEvent(eventType, dataId, filename, presentationId) +def __notifyGui(eventType, dataId=-1, filename="", presentationId=-1, msg=""): + medEvent = MEDCALC.MedEvent(eventType, dataId, filename, presentationId, msg) if not eventListenerIsRunning(): return # Notify the GUI of the update event @@ -123,3 +123,6 @@ def notifyGui_playQtTestingScenario(filename): # def notifyGui_termination(): __notifyGui(MEDCALC.EVENT_QUIT_SALOME) + +def notifyGui_error(msg): + __notifyGui(MEDCALC.EVENT_ERROR, msg=msg) diff --git a/src/MEDCalc/tui/medpresentation.py b/src/MEDCalc/tui/medpresentation.py index 8762d9a02..b59490093 100644 --- a/src/MEDCalc/tui/medpresentation.py +++ b/src/MEDCalc/tui/medpresentation.py @@ -18,8 +18,8 @@ # import medcalc -import MEDCALC -from medcalc.medevents import notifyGui_addPresentation, notifyGui_removePresentation +import MEDCALC, SALOME +from medcalc.medevents import notifyGui_addPresentation, notifyGui_removePresentation, notifyGui_error __manager = medcalc.medcorba.factory.getPresentationManager() @@ -32,22 +32,30 @@ def MakeScalarMap(proxy, # Create the presentation instance in CORBA engine # The engine in turn creates the ParaView pipeline elements params = MEDCALC.ScalarMapParameters(proxy.id, displayedComponent, scalarBarRange, colorMap) - presentation_id = __manager.makeScalarMap(params, viewMode) - notifyGui_addPresentation(proxy.id, presentation_id) - return presentation_id -# + try: + presentation_id = __manager.makeScalarMap(params, viewMode) + notifyGui_addPresentation(proxy.id, presentation_id) + return presentation_id + except SALOME.SALOME_Exception as e: + notifyGui_error("An error occured while creating the scalar map:\n" + e.details.text) + raise Exception(e.details.text) + +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, scalarBarRange, colorMap, nbContours) + try: + presentation_id = __manager.makeContour(params, viewMode) + notifyGui_addPresentation(proxy.id, presentation_id) + return presentation_id + except SALOME.SALOME_Exception as e: + notifyGui_error("An error occured while creating the contour:\n" + e.details.text) + raise Exception(e.details.text) -#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, @@ -102,5 +110,14 @@ def GetScalarMapParameters(presentation_id): params = __manager.getScalarMapParameters(presentation_id) return params +def GetContourParameters(presentation_id): + # TODO: check that pres id is really a ScalarMap ... + params = __manager.getContourParameters(presentation_id) + return params + def UpdateScalarMap(presentation_id, params): __manager.updateScalarMap(presentation_id, params) + +def UpdateContour(presentation_id, params): + __manager.updateContour(presentation_id, params) +