From: abn Date: Wed, 27 Jul 2016 10:10:55 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/agr/fix_tests' X-Git-Tag: V8_1_0b1~26 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2150e7c3c1bfbd9a364d197b5ff016914a294c9b;hp=80657e4615027595184835a4c2f3d5548dc1b18d;p=modules%2Fmed.git Merge remote-tracking branch 'origin/agr/fix_tests' Conflicts: src/MEDCalc/gui/CMakeLists.txt src/MEDCalc/gui/MEDModule.cxx src/MEDCalc/gui/MEDModule.hxx --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f612e41dc..e9cda5107 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,9 @@ PROJECT(SalomeMED C CXX) # Ensure a proper linker behavior: CMAKE_POLICY(SET CMP0003 NEW) +IF(WIN32) + CMAKE_POLICY(SET CMP0020 OLD) # disable automatic linking to qtmain.lib +ENDIF(WIN32) # Versioning # =========== diff --git a/idl/MEDPresentationManager.idl b/idl/MEDPresentationManager.idl index c797e4036..c3e100225 100644 --- a/idl/MEDPresentationManager.idl +++ b/idl/MEDPresentationManager.idl @@ -141,6 +141,10 @@ module MEDCALC boolean removePresentation(in long presId); + // Helper functions to keep GUI sync + boolean activateView(in long presentationId); + + MEDPresentationViewMode getPresentationViewMode(in long presId); }; }; diff --git a/idl/MED_Gen.idl b/idl/MED_Gen.idl index 6dbae1d6a..21df0b933 100644 --- a/idl/MED_Gen.idl +++ b/idl/MED_Gen.idl @@ -34,6 +34,8 @@ module MED_ORB OP_ERROR //!< ERROR: other problems }; + typedef sequence PresentationsList; + interface MED_Gen : Engines::EngineComponent { @@ -51,6 +53,11 @@ module MED_ORB status unregisterPresentation(in SALOMEDS::Study study, in long presentationId) raises (SALOME::SALOME_Exception); + + PresentationsList getSiblingPresentations(in SALOMEDS::Study study, + in long presentationId) + raises (SALOME::SALOME_Exception); + }; }; diff --git a/src/MEDCalc/MEDCalcConstants.hxx b/src/MEDCalc/MEDCalcConstants.hxx index e9c72abbf..2023db6d7 100644 --- a/src/MEDCalc/MEDCalcConstants.hxx +++ b/src/MEDCalc/MEDCalcConstants.hxx @@ -22,7 +22,7 @@ #define IS_IN_WORKSPACE "isInWorkspace" #define SOURCE_ID "sourceId" #define MESH_ID "meshId" -//#define FIELD_SERIES_ID "fieldSeriesId" +#define FIELD_SERIES_ID "fieldSeriesId" #define FIELD_ID "fieldId" #define PRESENTATION_ID "presentationId" #define IS_PRESENTATION "isPresentation" 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/MED.cxx b/src/MEDCalc/cmp/MED.cxx index a69140721..99b6976c6 100644 --- a/src/MEDCalc/cmp/MED.cxx +++ b/src/MEDCalc/cmp/MED.cxx @@ -67,9 +67,6 @@ MED::addDatasourceToStudy(SALOMEDS::Study_ptr study, // set exception handler to catch unexpected CORBA exceptions Unexpect aCatch(SALOME_SalomeException); - // set result status to error initially - MED_ORB::status result = MED_ORB::OP_ERROR; - // check if reference to study is valid if (!CORBA::is_nil(study)) { // get full object path @@ -139,8 +136,8 @@ MED::addDatasourceToStudy(SALOMEDS::Study_ptr study, soFieldseries->SetAttrString("AttributePixMap", "ICO_DATASOURCE_FIELD"); anAttr = studyBuilder->FindOrCreateAttribute(soFieldseries, "AttributeParameter"); aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); - //aParam->SetInt(FIELD_SERIES_ID, fieldseriesHandler.id); - aParam->SetInt(FIELD_ID, fieldseriesHandler.id); + aParam->SetInt(FIELD_SERIES_ID, fieldseriesHandler.id); + //aParam->SetInt(FIELD_ID, fieldseriesHandler.id); aParam->SetBool(IS_IN_WORKSPACE, false); useCaseBuilder->AppendTo(soFieldseries->GetFather(), soFieldseries); @@ -155,8 +152,7 @@ MED::addDatasourceToStudy(SALOMEDS::Study_ptr study, } } - result = MED_ORB::OP_OK; - return result; + return MED_ORB::OP_OK; } MED_ORB::status @@ -169,9 +165,6 @@ MED::registerPresentation(SALOMEDS::Study_ptr study, // set exception handler to catch unexpected CORBA exceptions Unexpect aCatch(SALOME_SalomeException); - // set result status to error initially - MED_ORB::status result = MED_ORB::OP_ERROR; - if (_fieldSeriesEntries.find(fieldId) == _fieldSeriesEntries.end()) { std::cerr << "Field not found\n"; return MED_ORB::OP_ERROR ; @@ -182,7 +175,7 @@ MED::registerPresentation(SALOMEDS::Study_ptr study, if (soFieldseries->IsNull()) { std::cerr << "Entry not found\n"; - return MED_ORB::OP_ERROR; + return MED_ORB::OP_ERROR; } SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder(); @@ -201,8 +194,7 @@ MED::registerPresentation(SALOMEDS::Study_ptr study, aParam->SetBool(IS_PRESENTATION, true); aParam->SetInt(PRESENTATION_ID, presentationId); - result = MED_ORB::OP_OK; - return result; + return MED_ORB::OP_OK; } MED_ORB::status @@ -212,9 +204,6 @@ MED::unregisterPresentation(SALOMEDS::Study_ptr study, // set exception handler to catch unexpected CORBA exceptions Unexpect aCatch(SALOME_SalomeException); - // set result status to error initially - MED_ORB::status result = MED_ORB::OP_ERROR; - SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder(); SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder(); @@ -237,6 +226,56 @@ MED::unregisterPresentation(SALOMEDS::Study_ptr study, } } } + + return MED_ORB::OP_OK; +} + +MED_ORB::PresentationsList* +MED::getSiblingPresentations(SALOMEDS::Study_ptr study, CORBA::Long presentationId) +{ + // set exception handler to catch unexpected CORBA exceptions + Unexpect aCatch(SALOME_SalomeException); + + MED_ORB::PresentationsList* presList = new MED_ORB::PresentationsList; + + SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder(); + SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder(); + + SALOMEDS::GenericAttribute_var anAttribute; + SALOMEDS::SComponent_var father = study->FindComponent("MED"); + SALOMEDS::ChildIterator_var it = study->NewChildIterator(father); + for (it->InitEx(true); it->More(); it->Next()) { + SALOMEDS::SObject_var child(it->Value()); + + if (child->FindAttribute(anAttribute, "AttributeParameter")) { + SALOMEDS::AttributeParameter_var attrParam = SALOMEDS::AttributeParameter::_narrow(anAttribute); + if (!attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN) || !attrParam->GetBool(IS_PRESENTATION) || !attrParam->IsSet(PRESENTATION_ID, PT_INTEGER)) + continue; + + if (presentationId == attrParam->GetInt(PRESENTATION_ID)) { + // get siblings + SALOMEDS::ChildIterator_var siblItr = study->NewChildIterator(child->GetFather()); + for (siblItr->InitEx(true); siblItr->More(); siblItr->Next()) { + SALOMEDS::SObject_var sibl(siblItr->Value()); + + if (sibl->FindAttribute(anAttribute, "AttributeParameter")) { + SALOMEDS::AttributeParameter_var attrParam = SALOMEDS::AttributeParameter::_narrow(anAttribute); + if (!attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN) || !attrParam->GetBool(IS_PRESENTATION) || !attrParam->IsSet(PRESENTATION_ID, PT_INTEGER)) + continue; + + if (attrParam->GetInt(PRESENTATION_ID) != presentationId) { + CORBA::ULong size = presList->length(); + presList->length(size+1); + (*presList)[size] = attrParam->GetInt(PRESENTATION_ID); + } + } + } + return presList; + } + } + } + + return presList; } Engines::TMPFile* @@ -311,7 +350,7 @@ MED::getObjectInfo(CORBA::Long studyId, const char* entry) //bool isPresentation = false; int sourceId = -1; int meshId = -1; - //int fieldSeriesId = -1; + int fieldSeriesId = -1; int fieldId = -1; int presentationId = -1; if (aSObj->FindAttribute(anAttribute, "AttributeParameter")) { @@ -324,8 +363,8 @@ MED::getObjectInfo(CORBA::Long studyId, const char* entry) sourceId = attrParam->GetInt(SOURCE_ID); if (attrParam->IsSet(MESH_ID, PT_INTEGER)) meshId = attrParam->GetInt(MESH_ID); - //if (attrParam->IsSet(FIELD_SERIES_ID, PT_INTEGER)) - // fieldSeriesId = attrParam->GetInt(FIELD_SERIES_ID); + if (attrParam->IsSet(FIELD_SERIES_ID, PT_INTEGER)) + fieldSeriesId = attrParam->GetInt(FIELD_SERIES_ID); if (attrParam->IsSet(FIELD_ID, PT_INTEGER)) fieldId = attrParam->GetInt(FIELD_ID); if (attrParam->IsSet(PRESENTATION_ID, PT_INTEGER)) @@ -340,8 +379,8 @@ MED::getObjectInfo(CORBA::Long studyId, const char* entry) oss << "Source id: " << sourceId << std::endl; if (meshId > -1) oss << "Mesh id: " << meshId << std::endl; - //if (fieldSeriesId > -1) - // oss << "Field series id: " << fieldSeriesId << std::endl; + if (fieldSeriesId > -1) + oss << "Field series id: " << fieldSeriesId << std::endl; if (fieldId > -1) oss << "Field id: " << fieldId << std::endl; //oss << "Is presentation: " << isPresentation << std::endl; diff --git a/src/MEDCalc/cmp/MED.hxx b/src/MEDCalc/cmp/MED.hxx index 73270a208..ddd373a76 100644 --- a/src/MEDCalc/cmp/MED.hxx +++ b/src/MEDCalc/cmp/MED.hxx @@ -64,6 +64,10 @@ public: MED_ORB::status unregisterPresentation(SALOMEDS::Study_ptr study, CORBA::Long presentationId); + // Caller owns the returned list, and is responsible for the list deletion. + MED_ORB::PresentationsList* getSiblingPresentations(SALOMEDS::Study_ptr study, + CORBA::Long presentationId); + /*! Dump the study as a Python file */ virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy, CORBA::Boolean isPublished, diff --git a/src/MEDCalc/cmp/MEDPresentation.cxx b/src/MEDCalc/cmp/MEDPresentation.cxx index aa5075387..48305be82 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,20 @@ 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++; +} + +void +MEDPresentation::activateView() const +{ + PyLockWrapper lock; + std::ostringstream oss; + oss << "pvs.SetActiveView(__view" << _renderViewPyId << ");"; + std::cerr << oss.str() << std::endl; + PyRun_SimpleString(oss.str().c_str()); +} diff --git a/src/MEDCalc/cmp/MEDPresentation.hxx b/src/MEDCalc/cmp/MEDPresentation.hxx index 5be9e89cf..d67971dbe 100644 --- a/src/MEDCalc/cmp/MEDPresentation.hxx +++ b/src/MEDCalc/cmp/MEDPresentation.hxx @@ -46,7 +46,10 @@ public: void setProperty(const std::string& propName, const std::string& propValue); const std::string getProperty(const std::string& propName) const; + void activateView() const; + protected: + typedef std::pair PyObjectId; MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name); std::string getRenderViewCommand(MEDCALC::MEDPresentationViewMode viewMode) const; @@ -55,9 +58,15 @@ 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; } + long getPyViewID() const { return _renderViewPyId; } + + static int GeneratePythonId(); + + virtual MEDCALC::MEDPresentationViewMode getViewMode() = 0; private: @@ -70,20 +79,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/MEDPresentationContour.hxx b/src/MEDCalc/cmp/MEDPresentationContour.hxx index e03b76b58..364965cd6 100644 --- a/src/MEDCalc/cmp/MEDPresentationContour.hxx +++ b/src/MEDCalc/cmp/MEDPresentationContour.hxx @@ -32,6 +32,7 @@ public: virtual ~MEDPresentationContour() {} void updatePipeline(const MEDCALC::ContourParameters& params); + MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } protected: virtual void internalGeneratePipeline(); 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/MEDPresentationDeflectionShape.hxx b/src/MEDCalc/cmp/MEDPresentationDeflectionShape.hxx index f9bbbb2f2..f03240e08 100644 --- a/src/MEDCalc/cmp/MEDPresentationDeflectionShape.hxx +++ b/src/MEDCalc/cmp/MEDPresentationDeflectionShape.hxx @@ -32,6 +32,7 @@ public: virtual ~MEDPresentationDeflectionShape() {} void updatePipeline(const MEDCALC::DeflectionShapeParameters& params); + MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } protected: virtual void internalGeneratePipeline(); diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx index a2e3cfb09..920d0e060 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx @@ -19,6 +19,7 @@ #include "MEDPresentationManager_i.hxx" #include "MEDFactoryClient.hxx" +#include "Basics_Utils.hxx" // presentations #include "MEDPresentationScalarMap.hxx" @@ -29,6 +30,7 @@ #include "MEDPresentationPointSprite.hxx" #include +#include MEDPresentationManager_i* MEDPresentationManager_i::_instance = NULL; @@ -179,13 +181,36 @@ MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentatio if (presentation) delete presentation; _presentations.erase(presentationID); + + std::stringstream sstm; + sstm << "Presentation " << presentationID << " has been removed.\n"; + STDLOG(sstm.str()); + return true; } -MEDPresentation::TypeID -MEDPresentationManager_i::_getActivePresentationId() const +CORBA::Boolean +MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID) { - // :TODO: + std::map::const_iterator citr = _presentations.find(presentationID); + if (citr == _presentations.end()) { + std::cerr << "getPresentationPyViewId(): presentation not found!!" << std::endl; + return false; + } + MEDPresentation* presentation = (*citr).second; - return -1; + presentation->activateView(); + return true; +} + +MEDCALC::MEDPresentationViewMode +MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID) +{ + MEDPresentation* pres = _getPresentation(presentationID); + if (pres) { + return pres->getViewMode(); + } else { + std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl; + return MEDCALC::VIEW_MODE_DEFAULT; + } } diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx index e7ec9677c..4d455d20d 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx @@ -46,17 +46,21 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, MEDCALC_EXPORT MEDPresentation::TypeID makeDeflectionShape(const MEDCALC::DeflectionShapeParameters&); MEDCALC_EXPORT MEDPresentation::TypeID makePointSprite(const MEDCALC::PointSpriteParameters&); - MEDCALC_EXPORT void setPresentationProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue); - MEDCALC_EXPORT char* getPresentationProperty(MEDPresentation::TypeID presentationID, const char* propName); + MEDCALC_EXPORT void setPresentationProperty(MEDPresentation::TypeID, const char* propName, const char* propValue); + MEDCALC_EXPORT char* getPresentationProperty(MEDPresentation::TypeID, const char* propName); - MEDCALC_EXPORT void updateScalarMap(MEDPresentation::TypeID presentationID, const MEDCALC::ScalarMapParameters&); - MEDCALC_EXPORT void updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters&); - MEDCALC_EXPORT void updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters&); - MEDCALC_EXPORT void updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters&); - MEDCALC_EXPORT void updateDeflectionShape(MEDPresentation::TypeID presentationID, const MEDCALC::DeflectionShapeParameters&); - MEDCALC_EXPORT void updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters&); + MEDCALC_EXPORT void updateScalarMap(MEDPresentation::TypeID, const MEDCALC::ScalarMapParameters&); + MEDCALC_EXPORT void updateContour(MEDPresentation::TypeID, const MEDCALC::ContourParameters&); + MEDCALC_EXPORT void updateVectorField(MEDPresentation::TypeID, const MEDCALC::VectorFieldParameters&); + MEDCALC_EXPORT void updateSlices(MEDPresentation::TypeID, const MEDCALC::SlicesParameters&); + MEDCALC_EXPORT void updateDeflectionShape(MEDPresentation::TypeID, const MEDCALC::DeflectionShapeParameters&); + MEDCALC_EXPORT void updatePointSprite(MEDPresentation::TypeID, const MEDCALC::PointSpriteParameters&); - MEDCALC_EXPORT CORBA::Boolean removePresentation(MEDPresentation::TypeID presentationID); + MEDCALC_EXPORT CORBA::Boolean removePresentation(MEDPresentation::TypeID); + + MEDCALC_EXPORT CORBA::Boolean activateView(MEDPresentation::TypeID); + + MEDCALC_EXPORT MEDCALC::MEDPresentationViewMode getPresentationViewMode(MEDPresentation::TypeID); private: MEDPresentationManager_i(); @@ -73,7 +77,6 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, void _updatePresentation(MEDPresentation::TypeID presentationID, PresentationParameters params); MEDPresentation* _getPresentation(MEDPresentation::TypeID) const; - MEDPresentation::TypeID _getActivePresentationId() const; private : diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.txx b/src/MEDCalc/cmp/MEDPresentationManager_i.txx index 4c66cfc71..eb283bf15 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.txx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.txx @@ -24,13 +24,6 @@ template MEDPresentation::TypeID MEDPresentationManager_i::_makePresentation(PresentationParameters params) { - // Replace = Remove then add - if (params.viewMode == MEDCALC::VIEW_MODE_REPLACE) { - MEDPresentation::TypeID currentPresentationId = _getActivePresentationId(); - if (currentPresentationId > -1) - removePresentation(currentPresentationId); - } - // Create a new presentation instance PresentationType* presentation = NULL; try { 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/MEDPresentationPointSprite.hxx b/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx index 27530af82..49b200b12 100644 --- a/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx +++ b/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx @@ -32,6 +32,7 @@ public: virtual ~MEDPresentationPointSprite() {} void updatePipeline(const MEDCALC::PointSpriteParameters& params); + MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } protected: virtual void internalGeneratePipeline(); 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/MEDPresentationScalarMap.hxx b/src/MEDCalc/cmp/MEDPresentationScalarMap.hxx index d3d1ae1cf..2b35a3482 100644 --- a/src/MEDCalc/cmp/MEDPresentationScalarMap.hxx +++ b/src/MEDCalc/cmp/MEDPresentationScalarMap.hxx @@ -32,6 +32,7 @@ public: virtual ~MEDPresentationScalarMap() {} void updatePipeline(const MEDCALC::ScalarMapParameters& params); + MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } protected: virtual void internalGeneratePipeline(); 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/MEDPresentationSlices.hxx b/src/MEDCalc/cmp/MEDPresentationSlices.hxx index b7ee4184e..7166a92bd 100644 --- a/src/MEDCalc/cmp/MEDPresentationSlices.hxx +++ b/src/MEDCalc/cmp/MEDPresentationSlices.hxx @@ -32,6 +32,7 @@ public: virtual ~MEDPresentationSlices() {} void updatePipeline(const MEDCALC::SlicesParameters& params); + MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } protected: virtual void internalGeneratePipeline(); 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/cmp/MEDPresentationVectorField.hxx b/src/MEDCalc/cmp/MEDPresentationVectorField.hxx index 7981f4264..3da740311 100644 --- a/src/MEDCalc/cmp/MEDPresentationVectorField.hxx +++ b/src/MEDCalc/cmp/MEDPresentationVectorField.hxx @@ -32,6 +32,7 @@ public: virtual ~MEDPresentationVectorField() {} void updatePipeline(const MEDCALC::VectorFieldParameters& params); + MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } protected: virtual void internalGeneratePipeline(); diff --git a/src/MEDCalc/gui/DatasourceController.cxx b/src/MEDCalc/gui/DatasourceController.cxx index 36b014ce0..8fa43b3f6 100644 --- a/src/MEDCalc/gui/DatasourceController.cxx +++ b/src/MEDCalc/gui/DatasourceController.cxx @@ -230,8 +230,8 @@ void DatasourceController::OnExpandField() SALOMEDS::SObject_var soFieldseries = listOfSObject->at(i); // First retrieve the fieldseries id associated to this study object - //long fieldseriesId = _studyEditor->getParameterInt(soFieldseries,FIELD_SERIES_ID); - long fieldseriesId = _studyEditor->getParameterInt(soFieldseries,FIELD_ID); + long fieldseriesId = _studyEditor->getParameterInt(soFieldseries,FIELD_SERIES_ID); + //long fieldseriesId = _studyEditor->getParameterInt(soFieldseries,FIELD_ID); STDLOG("Expand the field timeseries "< #include +#include +#include + + //! The only instance of the reference to engine -MED_ORB::MED_Gen_var MEDModule::myEngine; +MED_ORB::MED_Gen_var MEDModule::_MED_engine; +//! The only instance of the MEDPresentationManager +MEDCALC::MEDPresentationManager_ptr MEDModule::_presManager; MEDModule::MEDModule() : - SalomeApp_Module("MED"), _studyEditor(0), _datasourceController(0), _workspaceController(0), - _presentationController(0), _processingController(0) + SalomeApp_Module("MED"), _studyEditor(0), + _datasourceController(0), _workspaceController(0), _presentationController(0), + _processingController(0), _pvGuiElements(0) { // Note also that we can't use the getApp() function here because // the initialize(...) function has not been called yet. @@ -79,18 +90,23 @@ MED_ORB::MED_Gen_var MEDModule::engine() { init(); // initialize engine, if necessary - return myEngine; + return _MED_engine; } void MEDModule::init() { // initialize MED module engine (load, if necessary) - if ( CORBA::is_nil( myEngine ) ) { + if ( CORBA::is_nil( _MED_engine ) ) { Engines::EngineComponent_var comp = SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" ); - myEngine = MED_ORB::MED_Gen::_narrow( comp ); + _MED_engine = MED_ORB::MED_Gen::_narrow( comp ); } + + // Retrieve MEDFactory to get MEDPresentationManager (sometimes + if ( ! _presManager ) { + _presManager = MEDFactoryClient::getFactory()->getPresentationManager(); + } } //void MEDModule::onEventLoopStarted() @@ -108,9 +124,13 @@ MEDModule::initialize( CAM_Application* app ) // call the parent implementation SalomeApp_Module::initialize( app ); + getApp()->objectBrowser()->setAutoOpenLevel(5); + 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 @@ -122,7 +142,7 @@ QString MEDModule::engineIOR() const { init(); // initialize engine, if necessary - CORBA::String_var anIOR = getApp()->orb()->object_to_string( myEngine.in() ); + CORBA::String_var anIOR = getApp()->orb()->object_to_string( _MED_engine.in() ); return QString( anIOR.in() ); } @@ -174,7 +194,7 @@ MEDModule::createPreferences() bool MEDModule::activateModule( SUIT_Study* theStudy ) { - if ( CORBA::is_nil( myEngine ) ) + if ( CORBA::is_nil( _MED_engine ) ) return false; // call parent implementation @@ -257,6 +277,28 @@ MEDModule::createModuleWidgets() { connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)), _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*))); + + // Now that the workspace controller is created, ParaView core application has normally been started, + // and hidden GUI elements have been created. We can fire the VCR toolbar activation: + initToolbars(); +} + +void +MEDModule::initToolbars() +{ + // VCR and Time toolbars: + SUIT_Desktop* dsk = getApp()->desktop(); + _pvGuiElements = PVViewer_GUIElements::GetInstance(dsk); + + _pvGuiElements->getVCRToolbar(); // make sure VCR toolbar is built + _pvGuiElements->setToolBarVisible(false); + _pvGuiElements->setVCRTimeToolBarVisible(true); + + // Emit signal in order to make sure that animation scene is set - same trick as in PARAVIS module activation + QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(), + "activeSceneChanged", + Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) ); + #ifdef MED_HAS_QTTESTING connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)), _testController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*))); @@ -313,7 +355,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(); @@ -337,45 +379,75 @@ 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 (activate view)"); + std::ostringstream oss; + oss << fieldId << " / " << presId; + STDLOG(" - Field id / pres id: " + oss.str()); + STDLOG(" - Presentation name: " + name); + + _presManager->activateView(presId); +} + +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 4a2e01851..7541e3f91 100644 --- a/src/MEDCalc/gui/MEDModule.hxx +++ b/src/MEDCalc/gui/MEDModule.hxx @@ -41,6 +41,8 @@ #include class SalomeApp_Application; +class PVViewer_GUIElements; +class MEDPresentationManager_i; /*! * This class defines the gui of the MED module. @@ -91,10 +93,15 @@ 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); + + private: void createModuleWidgets(); void createModuleActions(); + void initToolbars(); + bool itemClickGeneric(const QModelIndex & index, std::string & name, int & fieldId, int & presId) const; static void init(); @@ -105,10 +112,17 @@ private: XmedDataModel* _xmedDataModel; PresentationController* _presentationController; ProcessingController* _processingController; + + PVViewer_GUIElements* _pvGuiElements; + + static MED_ORB::MED_Gen_var _MED_engine; + + // GUI needs to talk directly to the pres manager to activate a view, get some params, etc ...: + static MEDCALC::MEDPresentationManager_ptr _presManager; + #ifdef MED_HAS_QTTESTING TestController * _testController; #endif - static MED_ORB::MED_Gen_var myEngine; }; #endif 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 4356a1074..1785436a6 100644 --- a/src/MEDCalc/gui/PresentationController.cxx +++ b/src/MEDCalc/gui/PresentationController.cxx @@ -24,6 +24,7 @@ #include "QtxActionGroup.h" #include "QtxActionToolMgr.h" #include "MEDFactoryClient.hxx" +#include "MEDPresentationManager_i.hxx" #include #include @@ -36,6 +37,7 @@ #include #include #include +#include static const int OPTIONS_VIEW_MODE_ID = 943; static const int OPTIONS_VIEW_MODE_REPLACE_ID = 944; @@ -43,11 +45,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 +176,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 @@ -216,11 +227,27 @@ PresentationController::visualize(PresentationEvent::EventType eventType) // to make a view of an object from the tui console). for (int i=0; isize(); i++) { SALOMEDS::SObject_var soField = listOfSObject->at(i); - int fieldId = _studyEditor->getParameterInt(soField,FIELD_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 ( fieldId < 0 ) - continue; + int fieldId = -1; + try { + fieldId = _studyEditor->getParameterInt(soField,FIELD_ID); } + catch(...) { } + if (fieldId < 0) // is it a field serie ? + { + int fieldSeriesId = -1; + try { + fieldSeriesId = _studyEditor->getParameterInt(soField,FIELD_SERIES_ID); } + catch(...) { } + // 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) { @@ -275,6 +302,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) { @@ -294,6 +353,32 @@ PresentationController::updateTreeViewWithNewPresentation(long fieldId, long pre _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId, name.c_str(), label.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; + } + // update Object browser _salomeModule->getApp()->updateObjectBrowser(true); } 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 b5c3d008d..8a2231969 100644 --- a/src/MEDCalc/gui/WorkspaceController.cxx +++ b/src/MEDCalc/gui/WorkspaceController.cxx @@ -626,6 +626,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/gui/dialogs/WidgetPresentationParameters.hxx b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx index 72be05804..8e1905a8c 100644 --- a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx +++ b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx @@ -29,7 +29,7 @@ #include -class WidgetPresentationParameters : public QWidget +class MEDCALCGUI_DIALOGS_EXPORT WidgetPresentationParameters : public QWidget { Q_OBJECT diff --git a/src/MEDCalc/res/close.png b/src/MEDCalc/res/close.png new file mode 100755 index 000000000..4364ce7fe Binary files /dev/null and b/src/MEDCalc/res/close.png differ