From 57fc62a13c7222e72ff89fa54e10b1215c20831c Mon Sep 17 00:00:00 2001 From: abn Date: Wed, 6 Jul 2016 13:46:57 +0200 Subject: [PATCH] [MEDCalc]: deletion of an existing presentation + preparation for the Python dump. --- src/MEDCalc/cmp/CMakeLists.txt | 2 + src/MEDCalc/cmp/MEDPresentation.cxx | 71 +++++++++++++----- src/MEDCalc/cmp/MEDPresentation.hxx | 15 ++-- src/MEDCalc/cmp/MEDPresentationContour.cxx | 48 ++++++------ .../cmp/MEDPresentationDeflectionShape.cxx | 48 ++++++------ .../cmp/MEDPresentationPointSprite.cxx | 48 ++++++------ src/MEDCalc/cmp/MEDPresentationScalarMap.cxx | 52 ++++++++----- src/MEDCalc/cmp/MEDPresentationSlices.cxx | 48 ++++++------ .../cmp/MEDPresentationVectorField.cxx | 48 ++++++------ src/MEDCalc/gui/MEDModule.cxx | 64 ++++++++++++---- src/MEDCalc/gui/MEDModule.hxx | 3 + src/MEDCalc/gui/MED_images.ts | 4 + src/MEDCalc/gui/MED_msg_en.ts | 8 ++ src/MEDCalc/gui/PresentationController.cxx | 47 +++++++++++- src/MEDCalc/gui/PresentationController.hxx | 7 +- src/MEDCalc/gui/WorkspaceController.cxx | 5 ++ src/MEDCalc/gui/XmedDataModel.cxx | 9 ++- src/MEDCalc/gui/XmedDataModel.hxx | 4 + src/MEDCalc/res/close.png | Bin 0 -> 1260 bytes 19 files changed, 348 insertions(+), 183 deletions(-) create mode 100755 src/MEDCalc/res/close.png diff --git a/src/MEDCalc/cmp/CMakeLists.txt b/src/MEDCalc/cmp/CMakeLists.txt index 7ae135aa3..63415add6 100644 --- a/src/MEDCalc/cmp/CMakeLists.txt +++ b/src/MEDCalc/cmp/CMakeLists.txt @@ -29,6 +29,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${PROJECT_BINARY_DIR}/idl + ${GUI_INCLUDE_DIRS} # For PyLockWrapper ) SET(COMMON_SOURCES @@ -68,6 +69,7 @@ SET(COMMON_LIBS ${OMNIORB_LIBRARIES} ${PYTHON_LIBRARIES} ${MEDCoupling_medcoupling} ${MEDCoupling_medloader} ${MEDCoupling_medcouplingremapper} + ${GUI_PyInterp} ) # This undefines the macros MIN and MAX which are specified in the windows headers diff --git a/src/MEDCalc/cmp/MEDPresentation.cxx b/src/MEDCalc/cmp/MEDPresentation.cxx index aa5075387..2fd8ff90d 100644 --- a/src/MEDCalc/cmp/MEDPresentation.cxx +++ b/src/MEDCalc/cmp/MEDPresentation.cxx @@ -22,10 +22,14 @@ #include "MEDPresentation.hxx" #include "MEDPresentationException.hxx" #include "MEDCouplingRefCountObject.hxx" -#include +#include "Basics_Utils.hxx" +#include "PyInterp_Utils.h" + +#include MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name) - : _fieldHandlerId(fieldHandlerId), _pipeline(0), _display(0), _properties() + : _fieldHandlerId(fieldHandlerId), _pipeline(0), _display(0), _properties(), + _renderViewPyId(GeneratePythonId()) { MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager()); MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId); @@ -47,8 +51,19 @@ MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const s MEDPresentation::~MEDPresentation() { - std::cout << "###TODO#### ~MEDPresentation: clear pipeline\n"; - std::cout << "###TODO#### ~MEDPresentation: clear display\n"; + STDLOG("~MEDPresentation(): clear display"); + { + PyLockWrapper lock; + std::ostringstream oss_o, oss_v, oss; + // Get top level object and display: + oss_o << "__obj" << _pipeline.front().first; + 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()); + } } void @@ -60,12 +75,21 @@ MEDPresentation::generatePipeline() } void -MEDPresentation::pushInternal(PyObject* obj, PyObject* disp) +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()); +} + void MEDPresentation::setProperty(const std::string& propName, const std::string& propValue) { @@ -86,7 +110,7 @@ MEDPresentation::getProperty(const std::string& propName) const return (*it).second; } else { - std::cerr << "getProperty(): no property named " << propName << std::endl; + STDLOG("MEDPresentation::getProperty(): no property named " + propName); return std::string(); } } @@ -112,7 +136,7 @@ MEDPresentation::getFieldTypeString(MEDCoupling::TypeOfField fieldType) const case MEDCoupling::ON_NODES: return "POINTS"; default: - std::cerr << "MEDPresentation::getFieldTypeString() -- Not implemented ! Gauss points?"; + STDLOG("MEDPresentation::getFieldTypeString() -- Not implemented ! Gauss points?"); return ""; } } @@ -120,29 +144,33 @@ MEDPresentation::getFieldTypeString(MEDCoupling::TypeOfField fieldType) const std::string MEDPresentation::getRenderViewCommand(MEDCALC::MEDPresentationViewMode viewMode) const { - std::string cmd = std::string("pvs._DisableFirstRenderCameraReset();"); + std::ostringstream oss, oss2; + oss << "__view" << _renderViewPyId; + std::string view(oss.str()); + oss2 << "pvs._DisableFirstRenderCameraReset();"; if (viewMode == MEDCALC::VIEW_MODE_OVERLAP) { - cmd += std::string("__view1 = pvs.GetActiveViewOrCreate('RenderView');"); + oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');"; } else if (viewMode == MEDCALC::VIEW_MODE_REPLACE) { - cmd += std::string("__view1 = pvs.GetActiveViewOrCreate('RenderView');"); - cmd += std::string("pvs.active_objects.source and pvs.Hide(view=__view1);"); - cmd += std::string("pvs.Render();"); + 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) { - cmd += std::string("__layout1 = pvs.servermanager.misc.ViewLayout(registrationGroup='layouts');"); - cmd += std::string("__view1 = pvs.CreateView('RenderView');"); + oss2 << "__layout1 = pvs.servermanager.misc.ViewLayout(registrationGroup='layouts');"; + oss2 << view << " = pvs.CreateView('RenderView');"; } else if (viewMode == MEDCALC::VIEW_MODE_SPLIT_VIEW) { - cmd += std::string("__view1 = pvs.CreateView('RenderView');"); + oss2 << view << " = pvs.CreateView('RenderView');"; } - return cmd; + return oss2.str(); } std::string MEDPresentation::getResetCameraCommand() const { - return std::string("__view1.ResetCamera();"); + std::ostringstream oss; + oss << "__view" << _renderViewPyId << ".ResetCamera();"; + return oss.str(); } - std::string MEDPresentation::getColorMapCommand(MEDCALC::MEDPresentationColorMap colorMap) const { @@ -151,3 +179,10 @@ MEDPresentation::getColorMapCommand(MEDCALC::MEDPresentationColorMap colorMap) c case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "Cool to Warm"; } } + +int +MEDPresentation::GeneratePythonId() +{ + static int INIT_ID = 0; + return INIT_ID++; +} diff --git a/src/MEDCalc/cmp/MEDPresentation.hxx b/src/MEDCalc/cmp/MEDPresentation.hxx index 5be9e89cf..c407be158 100644 --- a/src/MEDCalc/cmp/MEDPresentation.hxx +++ b/src/MEDCalc/cmp/MEDPresentation.hxx @@ -47,6 +47,7 @@ public: const std::string getProperty(const std::string& propName) const; protected: + typedef std::pair PyObjectId; MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name); std::string getRenderViewCommand(MEDCALC::MEDPresentationViewMode viewMode) const; @@ -55,10 +56,13 @@ protected: virtual void internalGeneratePipeline() = 0; PyObject* getPythonObjectFromMain(const char* var) const; - void pushInternal(PyObject* obj, PyObject* disp = NULL); + void pushPyObjects(PyObjectId obj, PyObjectId disp); + void pushAndExecPyLine(const std::string & lin); MEDPresentation::TypeID getID() const { return _fieldHandlerId; } + static int GeneratePythonId(); + private: std::string getFieldTypeString(MEDCoupling::TypeOfField fieldType) const; @@ -70,20 +74,21 @@ private: void updatePipeline(PresentationParameters params); protected: - std::string _fileName; std::string _fieldName; std::string _fieldType; -private: + ///! Identifier (in the Python dump) of the render view + int _renderViewPyId; +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; diff --git a/src/MEDCalc/cmp/MEDPresentationContour.cxx b/src/MEDCalc/cmp/MEDPresentationContour.cxx index cdf86ed67..87ce8e8c2 100644 --- a/src/MEDCalc/cmp/MEDPresentationContour.cxx +++ b/src/MEDCalc/cmp/MEDPresentationContour.cxx @@ -22,30 +22,30 @@ 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); +// 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); } void diff --git a/src/MEDCalc/cmp/MEDPresentationDeflectionShape.cxx b/src/MEDCalc/cmp/MEDPresentationDeflectionShape.cxx index e56aa9f4b..12a1d288a 100644 --- a/src/MEDCalc/cmp/MEDPresentationDeflectionShape.cxx +++ b/src/MEDCalc/cmp/MEDPresentationDeflectionShape.cxx @@ -22,30 +22,30 @@ void MEDPresentationDeflectionShape::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("__warpByVector1 = pvs.WarpByVector(Input=__obj1);"); - cmd += std::string("__disp1 = pvs.Show(__warpByVector1, __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("__warpByVector1"); - PyObject* disp = getPythonObjectFromMain("__disp1"); - pushInternal(obj, disp); - - PyGILState_Release(_gil_state); +// 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("__warpByVector1 = pvs.WarpByVector(Input=__obj1);"); +// cmd += std::string("__disp1 = pvs.Show(__warpByVector1, __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("__warpByVector1"); +// PyObject* disp = getPythonObjectFromMain("__disp1"); +// pushInternal(obj, disp); +// +// PyGILState_Release(_gil_state); } void diff --git a/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx b/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx index f36880369..18fdff4d3 100644 --- a/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx +++ b/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx @@ -22,30 +22,30 @@ void MEDPresentationPointSprite::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("__disp1 = pvs.Show(__obj1, __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("__disp1.SetRepresentationType('Point Sprite');"); - 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("__obj1"); - PyObject* disp = getPythonObjectFromMain("__disp1"); - pushInternal(obj, disp); - - PyGILState_Release(_gil_state); +// 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("__disp1 = pvs.Show(__obj1, __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("__disp1.SetRepresentationType('Point Sprite');"); +// 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("__obj1"); +// PyObject* disp = getPythonObjectFromMain("__disp1"); +// pushInternal(obj, disp); +// +// PyGILState_Release(_gil_state); } void diff --git a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx index 6042bf8f3..6af5375bd 100644 --- a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx +++ b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx @@ -18,35 +18,47 @@ // #include "MEDPresentationScalarMap.hxx" +#include "PyInterp_Utils.h" + +#include void MEDPresentationScalarMap::internalGeneratePipeline() { - PyGILState_STATE _gil_state = PyGILState_Ensure(); + PyLockWrapper lock; - std::string cmd = std::string("import pvsimple as pvs;"); - cmd += getRenderViewCommand(_params.viewMode); // define __view1 + 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()); - cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');"); - cmd += std::string("__disp1 = pvs.Show(__obj1, __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("__lut = pvs.GetColorTransferFunction('")+_fieldName+std::string("');"); - cmd += std::string("__lut.ApplyPreset('")+getColorMapCommand(_params.colorMap)+std::string("',True);"); - cmd += std::string("pvs.Render();"); + pushAndExecPyLine( "import pvsimple as pvs;"); + pushAndExecPyLine( getRenderViewCommand(_params.viewMode) ); // define __viewXXX - cmd += getResetCameraCommand(); + oss_v << "__view" << _renderViewPyId; std::string view(oss_v.str()); - //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("__obj1"); - PyObject* disp = getPythonObjectFromMain("__disp1"); - pushInternal(obj, disp); + oss << obj << " = pvs.MEDReader(FileName='" << _fileName << "');"; + pushAndExecPyLine(oss.str()); oss.str(""); + 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 << "');"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << "__lut.ApplyPreset('" << getColorMapCommand(_params.colorMap) << "',True);"; + pushAndExecPyLine(oss.str()); oss.str(""); + pushAndExecPyLine(getResetCameraCommand()); + pushAndExecPyLine("pvs.Render();"); - PyGILState_Release(_gil_state); + // 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)); } void diff --git a/src/MEDCalc/cmp/MEDPresentationSlices.cxx b/src/MEDCalc/cmp/MEDPresentationSlices.cxx index 9b5d97c3c..243468f0b 100644 --- a/src/MEDCalc/cmp/MEDPresentationSlices.cxx +++ b/src/MEDCalc/cmp/MEDPresentationSlices.cxx @@ -22,30 +22,30 @@ void MEDPresentationSlices::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("__slice1 = pvs.Slice(Input=__obj1);"); - cmd += std::string("__disp1 = pvs.Show(__slice1, __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("__slice1"); - PyObject* disp = getPythonObjectFromMain("__disp1"); - pushInternal(obj, disp); - - PyGILState_Release(_gil_state); +// 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("__slice1 = pvs.Slice(Input=__obj1);"); +// cmd += std::string("__disp1 = pvs.Show(__slice1, __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("__slice1"); +// PyObject* disp = getPythonObjectFromMain("__disp1"); +// pushInternal(obj, disp); +// +// PyGILState_Release(_gil_state); } void diff --git a/src/MEDCalc/cmp/MEDPresentationVectorField.cxx b/src/MEDCalc/cmp/MEDPresentationVectorField.cxx index c5a1b3e34..979f8ed8c 100644 --- a/src/MEDCalc/cmp/MEDPresentationVectorField.cxx +++ b/src/MEDCalc/cmp/MEDPresentationVectorField.cxx @@ -22,30 +22,30 @@ void MEDPresentationVectorField::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("__disp1 = pvs.Show(__obj1, __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("__disp1.SetRepresentationType('3D Glyphs');"); - 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("__obj1"); - PyObject* disp = getPythonObjectFromMain("__disp1"); - pushInternal(obj, disp); - - PyGILState_Release(_gil_state); +// 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("__disp1 = pvs.Show(__obj1, __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("__disp1.SetRepresentationType('3D Glyphs');"); +// 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("__obj1"); +// PyObject* disp = getPythonObjectFromMain("__disp1"); +// pushInternal(obj, disp); +// +// PyGILState_Release(_gil_state); } void diff --git a/src/MEDCalc/gui/MEDModule.cxx b/src/MEDCalc/gui/MEDModule.cxx index 4278c0a9b..83443ad7e 100644 --- a/src/MEDCalc/gui/MEDModule.cxx +++ b/src/MEDCalc/gui/MEDModule.cxx @@ -106,6 +106,8 @@ MEDModule::initialize( CAM_Application* app ) if (app && app->desktop()) { connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(onDblClick(const QModelIndex&))); + connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(clicked(const QModelIndex&)), + this, SLOT(onClick(const QModelIndex&))); } // The following initializes the GUI widget and associated actions @@ -308,7 +310,7 @@ void MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule) { // _GBO_ for a fine customization of the rule (for example with a - // test on the type of the selected object), see the LIGTH module: + // test on the type of the selected object), see the LIGHT module: // implement "LightApp_Selection* createSelection() const;" int parentId = -1; QtxPopupMgr* mgr = this->popupMgr(); @@ -332,45 +334,77 @@ MEDModule::getSelectedColorMap() return _presentationController->getSelectedColorMap(); } -void -MEDModule::onDblClick(const QModelIndex& index) +bool +MEDModule::itemClickGeneric(const QModelIndex & index, std::string & name, int & fieldId, int & presId) const { DataObjectList dol = getApp()->objectBrowser()->getSelected(); if (dol.isEmpty()) - return; + return false; SalomeApp_DataObject* item = dynamic_cast(dol[0]); if (!item) - return; + return false; SalomeApp_DataModel *model = dynamic_cast(dataModel()); if (!model) - return; + return false; if (item->componentDataType().toStdString() != "MED") - return; + return false; _PTR(SObject) obj = item->object(); _PTR(GenericAttribute) anAttribute; if (! obj->FindAttribute(anAttribute, "AttributeName")) - return; + return false; _PTR(AttributeName) attrName(anAttribute); - std::string name = attrName->Value(); + name = attrName->Value(); if (! obj->FindAttribute(anAttribute, "AttributeParameter")) - return; + return false; _PTR(AttributeParameter) attrParam(anAttribute); if (! attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN) || ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation - return; + return false; } if (!attrParam->IsSet(FIELD_ID, PT_INTEGER)) + return false; + fieldId = attrParam->GetInt(FIELD_ID); + if (!attrParam->IsSet(PRESENTATION_ID, PT_INTEGER)) + return false; + presId = attrParam->GetInt(PRESENTATION_ID); + return true; +} + +void +MEDModule::onClick(const QModelIndex & index) +{ + int fieldId, presId; + std::string name; + if (!itemClickGeneric(index, name, fieldId, presId)) + return; + + STDLOG("Presentation selection (should activate view): NOT IMPLEMENTED YET"); + STDLOG(" Presention infos:"); + std::ostringstream oss; + oss << fieldId << " / " << presId; + STDLOG(" - Field id / pres id: " + oss.str()); + STDLOG(" - Presentation name: " + name); + + // TODO: activate corresponding view + +} + +void +MEDModule::onDblClick(const QModelIndex& index) +{ + int fieldId, presId; + std::string name; + if (!itemClickGeneric(index, name, fieldId, presId)) return; - int fieldId = attrParam->GetInt(FIELD_ID); STDLOG("Presentation edition: NOT IMPLEMENTED YET"); STDLOG(" Presention infos:"); - STDLOG(" - Component: " + item->componentDataType().toStdString()); - STDLOG(" - Item entry: " + item->entry().toStdString()); - STDLOG(" - Item name: " + item->name().toStdString()); +// STDLOG(" - Component: " + item->componentDataType().toStdString()); +// STDLOG(" - Item entry: " + item->entry().toStdString()); +// STDLOG(" - Item name: " + item->name().toStdString()); std::ostringstream oss; oss << fieldId; STDLOG(" - Field id: " + oss.str()); diff --git a/src/MEDCalc/gui/MEDModule.hxx b/src/MEDCalc/gui/MEDModule.hxx index d5cfa816f..38c624e88 100644 --- a/src/MEDCalc/gui/MEDModule.hxx +++ b/src/MEDCalc/gui/MEDModule.hxx @@ -87,6 +87,7 @@ public slots: virtual bool activateModule(SUIT_Study* theStudy); virtual bool deactivateModule(SUIT_Study* theStudy); virtual void onDblClick(const QModelIndex& index); + virtual void onClick(const QModelIndex& index); @@ -94,6 +95,8 @@ private: void createModuleWidgets(); void createModuleActions(); void initToolbars(); + bool itemClickGeneric(const QModelIndex & index, std::string & name, int & fieldId, int & presId) const; + static void init(); private: diff --git a/src/MEDCalc/gui/MED_images.ts b/src/MEDCalc/gui/MED_images.ts index 7484fc4c1..cd650e743 100644 --- a/src/MEDCalc/gui/MED_images.ts +++ b/src/MEDCalc/gui/MED_images.ts @@ -213,5 +213,9 @@ ICO_MEDPresentationPointSprite_CLASSIC visu_points16.png + + ICO_DELETE_PRESENTATION + close.png + diff --git a/src/MEDCalc/gui/MED_msg_en.ts b/src/MEDCalc/gui/MED_msg_en.ts index 381290792..8841a7d85 100644 --- a/src/MEDCalc/gui/MED_msg_en.ts +++ b/src/MEDCalc/gui/MED_msg_en.ts @@ -55,6 +55,14 @@ TIP_PRESENTATION_POINT_SPRITE Point sprite + + LAB_DELETE_PRESENTATION + Delete presentation + + + TIP_DELETE_PRESENTATION + Delete selected presentation + MENU_PRESENTATIONS Presentations diff --git a/src/MEDCalc/gui/PresentationController.cxx b/src/MEDCalc/gui/PresentationController.cxx index 3537c843c..99ba86d64 100644 --- a/src/MEDCalc/gui/PresentationController.cxx +++ b/src/MEDCalc/gui/PresentationController.cxx @@ -43,11 +43,11 @@ 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; -PresentationController::PresentationController(MEDModule* salomeModule) +PresentationController::PresentationController(MEDModule* salomeModule) : + _salomeModule(salomeModule), + _studyEditor(salomeModule->getStudyEditor()) { STDLOG("Creating a PresentationController"); - _salomeModule = salomeModule; - _studyEditor = _salomeModule->getStudyEditor(); _widgetPresentationParameters = new WidgetPresentationParameters(); @@ -174,6 +174,15 @@ PresentationController::createActions() _salomeModule->createTool(actionId, presentationToolbarId); _salomeModule->action(actionId)->setIconVisibleInMenu(true); _salomeModule->createMenu(actionId, 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); +// _salomeModule->createTool(actionId, presentationToolbarId); +// _salomeModule->action(actionId)->setIconVisibleInMenu(true); + _salomeModule->createMenu(actionId, presentationMenuId); + } MEDCALC::MEDPresentationViewMode @@ -291,6 +300,38 @@ PresentationController::OnVisualizePointSprite() this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE); } +void +PresentationController::OnDeletePresentation() +{ + // 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 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); + // 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 + } +} + void PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId) { diff --git a/src/MEDCalc/gui/PresentationController.hxx b/src/MEDCalc/gui/PresentationController.hxx index 78d7ca36b..d2d9fc461 100644 --- a/src/MEDCalc/gui/PresentationController.hxx +++ b/src/MEDCalc/gui/PresentationController.hxx @@ -39,7 +39,8 @@ typedef struct { EVENT_VIEW_OBJECT_POINT_SPRITE, EVENT_VIEW_OBJECT_SCALAR_MAP, EVENT_VIEW_OBJECT_SLICES, - EVENT_VIEW_OBJECT_VECTOR_FIELD + EVENT_VIEW_OBJECT_VECTOR_FIELD, + EVENT_DELETE_PRESENTATION }; int eventtype; XmedDataObject* objectdata; @@ -72,6 +73,9 @@ protected slots: void OnVisualizeSlices(); void OnVisualizeDeflectionShape(); void OnVisualizePointSprite(); + + void OnDeletePresentation(); + void processWorkspaceEvent(const MEDCALC::MedEvent*); private: @@ -83,6 +87,7 @@ private: private: MEDModule* _salomeModule; SALOME_AppStudyEditor* _studyEditor; // borrowed to MEDModule + QDockWidget *_dockWidget; WidgetPresentationParameters* _widgetPresentationParameters; }; diff --git a/src/MEDCalc/gui/WorkspaceController.cxx b/src/MEDCalc/gui/WorkspaceController.cxx index b85ea1f9d..10de8f6a6 100644 --- a/src/MEDCalc/gui/WorkspaceController.cxx +++ b/src/MEDCalc/gui/WorkspaceController.cxx @@ -619,6 +619,11 @@ void WorkspaceController::processPresentationEvent(const PresentationEvent* even 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"); } diff --git a/src/MEDCalc/gui/XmedDataModel.cxx b/src/MEDCalc/gui/XmedDataModel.cxx index 62e37a660..cb4b6fc15 100644 --- a/src/MEDCalc/gui/XmedDataModel.cxx +++ b/src/MEDCalc/gui/XmedDataModel.cxx @@ -27,7 +27,7 @@ // ================================================================= // -XmedDataObject::XmedDataObject() : DataObject() { +XmedDataObject::XmedDataObject() : DataObject(), _presId(-1) { } /*! This function specified the localization of the object in the @@ -48,6 +48,13 @@ MEDCALC::FieldHandler * XmedDataObject::getFieldHandler() { return &_fieldHandler; } +void XmedDataObject::setPresentationId(int presId) { + _presId = presId; +} + +int XmedDataObject::getPresentationId() const { return _presId; } + + /*! * This function implements the convention for displaying a fieldname * characterized by its spatial discretisation type. diff --git a/src/MEDCalc/gui/XmedDataModel.hxx b/src/MEDCalc/gui/XmedDataModel.hxx index 4027ccf6b..43f225290 100644 --- a/src/MEDCalc/gui/XmedDataModel.hxx +++ b/src/MEDCalc/gui/XmedDataModel.hxx @@ -40,8 +40,12 @@ public: void setFieldHandler(MEDCALC::FieldHandler fieldHandler); MEDCALC::FieldHandler * getFieldHandler(); + void setPresentationId(int presId); + int getPresentationId() const; + private: MEDCALC::FieldHandler _fieldHandler; + int _presId; string _getTypedFieldLabel(); }; diff --git a/src/MEDCalc/res/close.png b/src/MEDCalc/res/close.png new file mode 100755 index 0000000000000000000000000000000000000000..4364ce7fe7d8ef363f0560fb0b4042fee232e748 GIT binary patch literal 1260 zcmVz@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZ=Vo5|nRCwBA{Qv(y10y3N0}`kQVhJE#55y;d_$Ltm z0^)xRL;!#QVgMP41cc@J1+L8Z3I1;(EeA5F28gwRSP+Prv1kWb90K+FcjEC2z- zge(hmsiK~!grc2{JVURO2b;Q(NEuK#0Ekt9m!$FDolUrG*_Y4;xz&P)Z$$Wq_C+sIdJE-f$0Rjl!K!$(+|M$$jcoq}@3}1i$W{A_)XAt4!@`QS+HCR=% zB2CAT;m4of4DY}HVAy!?Hp8oLU+)6tJ_GR&fB<5`63|BvJ$|tIih@S%l5F?gk0|I7N(sH}n zY@PXk{rSW2``=%NtFK=(XbFojy#Mi?;o|F;K>UJX-;;+o|Ni^87O4Ie5Z?siD*yq+ zgd;VbI`;I@rXx>)t^`{4|KEQGJy9`+r=LGD?0s~P;n0(ZAj7T!4O^2bJ0I>lA zhy{m%s=%b6#m&OX@CO(N2=tAk6>)gl?dT zI5*GEW*a9}V4`LC4h%n#%RtHFH;|U%=4LP!mEZ=dQwHKMK>P%h)L@2z06+jC8)ziQ zC$O!}+DT4bP?+Jz??1p~@r_~k!}|;y?%ZHt0fyywU@~%-Rb&9hxD8M}ClGT$vm`uL z0RjkSpfC?B>x?=JJ5eP8L56R?ela}y^pRoHy;}_PuAYCr?f#v&PrrO-0OfiS4o(I; zX*p1?F$H2-C+jxR z02*)|=%Ve=z(2Y3(fwy1fBpc6sRS^wn~O?_1I3L&zC$iJ00M{!QYbJy=sSCyq5s@* zV3^(g56qiafLZVuG~nL?@%4|ter(>&dyFf4xnBg+C9<4lZ9IzTy5Xz>N|@;`t8 zf*8o~fAPz2Uk^U}^7+N<@89+Sg+Q744-mhGCJRt5ShD}=|!@m;b=-0s?>lLe9%vKr95re9)xu9qQ#D&~)}2stHt-r9yMb6)1fHnq$5K1Q-Bj WYPb*HL2?`b0000