From 9a9f81053e1e8fa736b90baf2843b49e6df8af81 Mon Sep 17 00:00:00 2001 From: rnv Date: Mon, 25 Jan 2021 04:31:36 +0300 Subject: [PATCH] bos #20430 [CEA 20428] FIELDS : improvement of simplified visualisations --- idl/MEDEventListener.idl | 1 + idl/MEDPresentationManager.idl | 100 +++- src/MEDCalc/MEDCalcConstants.hxx | 3 + src/MEDCalc/cmp/CMakeLists.txt | 5 +- src/MEDCalc/cmp/MED.cxx | 5 +- src/MEDCalc/cmp/MEDPresentation.cxx | 484 ++++++++++++++++-- src/MEDCalc/cmp/MEDPresentation.hxx | 114 ++++- src/MEDCalc/cmp/MEDPresentation.txx | 72 ++- src/MEDCalc/cmp/MEDPresentationContour.cxx | 197 ++++++- src/MEDCalc/cmp/MEDPresentationContour.hxx | 9 +- src/MEDCalc/cmp/MEDPresentationCutSegment.cxx | 304 +++++++++++ src/MEDCalc/cmp/MEDPresentationCutSegment.hxx | 69 +++ .../cmp/MEDPresentationDeflectionShape.cxx | 16 +- src/MEDCalc/cmp/MEDPresentationManager_i.cxx | 123 ++++- src/MEDCalc/cmp/MEDPresentationManager_i.hxx | 19 +- src/MEDCalc/cmp/MEDPresentationMeshView.cxx | 3 + src/MEDCalc/cmp/MEDPresentationMeshView.hxx | 3 + src/MEDCalc/cmp/MEDPresentationPlot3D.cxx | 303 +++++++++++ src/MEDCalc/cmp/MEDPresentationPlot3D.hxx | 62 +++ .../cmp/MEDPresentationPointSprite.cxx | 72 ++- .../cmp/MEDPresentationPointSprite.hxx | 4 + src/MEDCalc/cmp/MEDPresentationScalarMap.cxx | 19 +- src/MEDCalc/cmp/MEDPresentationSlices.cxx | 24 +- .../cmp/MEDPresentationStreamLines.cxx | 231 +++++++++ .../cmp/MEDPresentationStreamLines.hxx | 58 +++ .../cmp/MEDPresentationVectorField.cxx | 71 ++- .../cmp/MEDPresentationVectorField.hxx | 5 +- src/MEDCalc/gui/CMakeLists.txt | 18 +- src/MEDCalc/gui/FIELDS_images.ts | 72 +++ src/MEDCalc/gui/FIELDS_msg_en.ts | 88 ++++ src/MEDCalc/gui/FIELDS_msg_fr.ts | 84 +++ src/MEDCalc/gui/FIELDS_msg_ja.ts | 72 +++ src/MEDCalc/gui/MEDCALCGUI_Displayer.cxx | 134 +++++ src/MEDCalc/gui/MEDCALCGUI_Displayer.hxx | 58 +++ src/MEDCalc/gui/MEDModule.cxx | 93 +++- src/MEDCalc/gui/MEDModule.hxx | 12 + src/MEDCalc/gui/MEDWidgetHelper.cxx | 71 ++- src/MEDCalc/gui/MEDWidgetHelper.hxx | 8 + src/MEDCalc/gui/MEDWidgetHelperContour.cxx | 22 +- src/MEDCalc/gui/MEDWidgetHelperContour.hxx | 2 + src/MEDCalc/gui/MEDWidgetHelperCutSegment.cxx | 95 ++++ src/MEDCalc/gui/MEDWidgetHelperCutSegment.hxx | 55 ++ src/MEDCalc/gui/MEDWidgetHelperPlot3D.cxx | 94 ++++ src/MEDCalc/gui/MEDWidgetHelperPlot3D.hxx | 56 ++ .../gui/MEDWidgetHelperStreamLines.cxx | 74 +++ .../gui/MEDWidgetHelperStreamLines.hxx | 53 ++ .../gui/MEDWidgetHelperVectorField.cxx | 86 ++++ .../gui/MEDWidgetHelperVectorField.hxx | 18 +- src/MEDCalc/gui/PresentationController.cxx | 226 +++++++- src/MEDCalc/gui/PresentationController.hxx | 9 + src/MEDCalc/gui/PresentationEvent.hxx | 34 +- src/MEDCalc/gui/WorkspaceController.cxx | 3 + .../dialogs/WidgetPresentationParameters.cxx | 420 ++++++++++++++- .../dialogs/WidgetPresentationParameters.hxx | 69 ++- .../dialogs/WidgetPresentationParameters.ui | 267 ++++++++-- .../classic/visu_cutsegment16.png | Bin 0 -> 466 bytes .../classic/visu_cutsegment24.png | Bin 0 -> 593 bytes .../presentations/classic/visu_plot3d16.png | Bin 0 -> 986 bytes .../presentations/classic/visu_plot3d24.png | Bin 0 -> 1617 bytes .../classic/visu_streamlines16.png | Bin 0 -> 894 bytes .../classic/visu_streamlines24.png | Bin 0 -> 1307 bytes .../res/presentations/modern/pqPlot16.png | Bin 0 -> 672 bytes .../res/presentations/modern/pqPlot24.png | Bin 0 -> 233 bytes .../presentations/modern/pqPlotOverLine16.png | Bin 0 -> 964 bytes .../presentations/modern/pqPlotOverLine24.png | Bin 0 -> 1745 bytes .../presentations/modern/pqStreamTracer16.png | Bin 0 -> 616 bytes .../presentations/modern/pqStreamTracer24.png | Bin 0 -> 669 bytes src/MEDCalc/tui/__init__.py | 10 + src/MEDCalc/tui/medevents.py | 3 + src/MEDCalc/tui/medpresentation.py | 245 ++++++++- 70 files changed, 4729 insertions(+), 198 deletions(-) create mode 100644 src/MEDCalc/cmp/MEDPresentationCutSegment.cxx create mode 100644 src/MEDCalc/cmp/MEDPresentationCutSegment.hxx create mode 100644 src/MEDCalc/cmp/MEDPresentationPlot3D.cxx create mode 100644 src/MEDCalc/cmp/MEDPresentationPlot3D.hxx create mode 100644 src/MEDCalc/cmp/MEDPresentationStreamLines.cxx create mode 100644 src/MEDCalc/cmp/MEDPresentationStreamLines.hxx create mode 100644 src/MEDCalc/gui/MEDCALCGUI_Displayer.cxx create mode 100644 src/MEDCalc/gui/MEDCALCGUI_Displayer.hxx create mode 100644 src/MEDCalc/gui/MEDWidgetHelperCutSegment.cxx create mode 100644 src/MEDCalc/gui/MEDWidgetHelperCutSegment.hxx create mode 100644 src/MEDCalc/gui/MEDWidgetHelperPlot3D.cxx create mode 100644 src/MEDCalc/gui/MEDWidgetHelperPlot3D.hxx create mode 100644 src/MEDCalc/gui/MEDWidgetHelperStreamLines.cxx create mode 100644 src/MEDCalc/gui/MEDWidgetHelperStreamLines.hxx create mode 100644 src/MEDCalc/gui/MEDWidgetHelperVectorField.cxx create mode 100644 src/MEDCalc/res/presentations/classic/visu_cutsegment16.png create mode 100644 src/MEDCalc/res/presentations/classic/visu_cutsegment24.png create mode 100644 src/MEDCalc/res/presentations/classic/visu_plot3d16.png create mode 100644 src/MEDCalc/res/presentations/classic/visu_plot3d24.png create mode 100644 src/MEDCalc/res/presentations/classic/visu_streamlines16.png create mode 100644 src/MEDCalc/res/presentations/classic/visu_streamlines24.png create mode 100644 src/MEDCalc/res/presentations/modern/pqPlot16.png create mode 100644 src/MEDCalc/res/presentations/modern/pqPlot24.png create mode 100644 src/MEDCalc/res/presentations/modern/pqPlotOverLine16.png create mode 100644 src/MEDCalc/res/presentations/modern/pqPlotOverLine24.png create mode 100644 src/MEDCalc/res/presentations/modern/pqStreamTracer16.png create mode 100644 src/MEDCalc/res/presentations/modern/pqStreamTracer24.png diff --git a/idl/MEDEventListener.idl b/idl/MEDEventListener.idl index 872e9f280..46bc3e14c 100644 --- a/idl/MEDEventListener.idl +++ b/idl/MEDEventListener.idl @@ -38,6 +38,7 @@ module MEDCALC EVENT_MODIFY_PRESENTATION, EVENT_CHANGE_UNDERLYING_MESH, EVENT_INTERPOLATE_FIELD, + EVENT_VISIBILITY_CHANGED, EVENT_PLAY_TEST, EVENT_QUIT_SALOME, EVENT_ERROR, diff --git a/idl/MEDPresentationManager.idl b/idl/MEDPresentationManager.idl index 3c5eaeabb..ee99d38a9 100644 --- a/idl/MEDPresentationManager.idl +++ b/idl/MEDPresentationManager.idl @@ -41,7 +41,8 @@ module MEDCALC enum ScalarBarRangeType { SCALAR_BAR_ALL_TIMESTEPS, - SCALAR_BAR_CURRENT_TIMESTEP + SCALAR_BAR_CURRENT_TIMESTEP, + SCALAR_BAR_CUSTOM_RANGE }; enum MeshModeType { @@ -49,7 +50,20 @@ module MEDCALC MESH_MODE_SURFACE_EDGES, MESH_MODE_SURFACE }; - + + enum PresentationVisibility { + PRESENTATION_INVISIBLE, + PRESENTATION_VISIBLE, + PRESENTATION_NOT_IN_VIEW + }; + + enum IntegrationDirType { + INTEGRATION_DIR_BOTH, + INTEGRATION_DIR_FORWARD, + INTEGRATION_DIR_BACKWARD + }; + + typedef sequence DoubleArray; // struct ScalarBarRange { @@ -84,6 +98,7 @@ module MEDCALC // const long SCALAR_BAR_RANGE_VAL_MAX_DEFAULT = -1; const string DISPLAY_DEFAULT = DISPLAY_EUCLIDEAN_NORM; const SliceOrientationType SLICE_ORIENTATION_DEFAULT = SLICE_NORMAL_TO_X; + const IntegrationDirType INTEGRATION_DIR_DEFAULT = INTEGRATION_DIR_BOTH; const long NB_CONTOURS_DEFAULT = 10; const long NB_SLICES_DEFAULT = 1; @@ -97,6 +112,7 @@ module MEDCALC struct MeshViewParameters { long meshHandlerId; MeshModeType mode; + boolean visibility; }; // A simple scalar map @@ -105,6 +121,10 @@ module MEDCALC string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name ScalarBarRangeType scalarBarRange; ColorMapType colorMap; + boolean visibility; + boolean scalarBarVisibility; + DoubleArray scalarBarRangeArray; + boolean hideDataOutsideCustomRange; }; // A contour is an isoline in 2D and an isosurface in 3D @@ -112,13 +132,24 @@ module MEDCALC long fieldHandlerId; ScalarBarRangeType scalarBarRange; ColorMapType colorMap; + boolean visibility; + boolean scalarBarVisibility; + DoubleArray scalarBarRangeArray; + boolean hideDataOutsideCustomRange; long nbContours; + string contourComponent; }; struct VectorFieldParameters { long fieldHandlerId; ScalarBarRangeType scalarBarRange; ColorMapType colorMap; + boolean visibility; + boolean scalarBarVisibility; + DoubleArray scalarBarRangeArray; + boolean hideDataOutsideCustomRange; + double scaleFactor; + boolean customScaleFactor; }; struct SlicesParameters { @@ -126,14 +157,23 @@ module MEDCALC string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name ScalarBarRangeType scalarBarRange; ColorMapType colorMap; + boolean visibility; + boolean scalarBarVisibility; + DoubleArray scalarBarRangeArray; + boolean hideDataOutsideCustomRange; SliceOrientationType orientation; long nbSlices; }; + struct DeflectionShapeParameters { long fieldHandlerId; ScalarBarRangeType scalarBarRange; ColorMapType colorMap; + boolean visibility; + boolean scalarBarVisibility; + DoubleArray scalarBarRangeArray; + boolean hideDataOutsideCustomRange; }; struct PointSpriteParameters { @@ -141,6 +181,45 @@ module MEDCALC string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name ScalarBarRangeType scalarBarRange; ColorMapType colorMap; + boolean visibility; + boolean scalarBarVisibility; + DoubleArray scalarBarRangeArray; + boolean hideDataOutsideCustomRange; + }; + + struct Plot3DParameters { + long fieldHandlerId; + ScalarBarRangeType scalarBarRange; + ColorMapType colorMap; + boolean visibility; + boolean scalarBarVisibility; + DoubleArray scalarBarRangeArray; + boolean hideDataOutsideCustomRange; + DoubleArray planeNormal; + double planePos; + }; + + struct StreamLinesParameters { + long fieldHandlerId; + ScalarBarRangeType scalarBarRange; + ColorMapType colorMap; + boolean visibility; + boolean scalarBarVisibility; + DoubleArray scalarBarRangeArray; + boolean hideDataOutsideCustomRange; + IntegrationDirType integrDir; + }; + + struct CutSegmentParameters { + long fieldHandlerId; + ScalarBarRangeType scalarBarRange; + ColorMapType colorMap; + boolean visibility; + boolean scalarBarVisibility; + DoubleArray scalarBarRangeArray; + boolean hideDataOutsideCustomRange; + DoubleArray point1; + DoubleArray point2; }; typedef sequence PresentationsList; @@ -156,11 +235,17 @@ module MEDCALC long makeSlices(in SlicesParameters params, in ViewModeType viewMode) raises (SALOME::SALOME_Exception); long makeDeflectionShape(in DeflectionShapeParameters params, in ViewModeType viewMode) raises (SALOME::SALOME_Exception); long makePointSprite(in PointSpriteParameters params, in ViewModeType viewMode) raises (SALOME::SALOME_Exception); + long makePlot3D(in Plot3DParameters params, in ViewModeType viewMode) raises (SALOME::SALOME_Exception); + long makeStreamLines(in StreamLinesParameters params, in ViewModeType viewMode) raises (SALOME::SALOME_Exception); + long makeCutSegment(in CutSegmentParameters params, in ViewModeType viewMode) raises (SALOME::SALOME_Exception); void setPresentationStringProperty(in long presId, in string propName, in string propValue); string getPresentationStringProperty(in long presId, in string propName); void setPresentationIntProperty(in long presId, in string propName, in long propValue); - long getPresentationIntProperty(in long presId, in string propName); + long getPresentationIntProperty(in long presId, in string propName); + void setPresentationDoubleProperty(in long presId, in string propName, in double propValue); + double getPresentationDoubleProperty(in long presId, in string propName); + MeshViewParameters getMeshViewParameters(in long presId); ScalarMapParameters getScalarMapParameters(in long presId); @@ -168,7 +253,10 @@ module MEDCALC SlicesParameters getSlicesParameters(in long presId); VectorFieldParameters getVectorFieldParameters(in long presId); PointSpriteParameters getPointSpriteParameters(in long presId); + Plot3DParameters getPlot3DParameters(in long presId); DeflectionShapeParameters getDeflectionShapeParameters(in long presId); + StreamLinesParameters getStreamLinesParameters(in long presId); + CutSegmentParameters getCutSegmentParameters(in long presId); void updateMeshView(in long presId, in MeshViewParameters params) raises (SALOME::SALOME_Exception); void updateScalarMap(in long presId, in ScalarMapParameters params) raises (SALOME::SALOME_Exception); @@ -177,6 +265,9 @@ module MEDCALC void updateSlices(in long presId, in SlicesParameters params) raises (SALOME::SALOME_Exception); void updateDeflectionShape(in long presId, in DeflectionShapeParameters params) raises (SALOME::SALOME_Exception); void updatePointSprite(in long presId, in PointSpriteParameters params) raises (SALOME::SALOME_Exception); + void updatePlot3D(in long presId, in Plot3DParameters params) raises (SALOME::SALOME_Exception); + void updateStreamLines(in long presId, in StreamLinesParameters params) raises (SALOME::SALOME_Exception); + void updateCutSegment(in long presId, in CutSegmentParameters params) raises (SALOME::SALOME_Exception); boolean removePresentation(in long presId) raises (SALOME::SALOME_Exception); @@ -190,6 +281,9 @@ module MEDCALC PresentationsList getAllPresentations(); +// Visibility State in the active ParaView viewer + PresentationVisibility stateInActiveView(in long presId); + void cleanUp() raises (SALOME::SALOME_Exception); }; }; diff --git a/src/MEDCalc/MEDCalcConstants.hxx b/src/MEDCalc/MEDCalcConstants.hxx index 85293e5ce..d74ae6c40 100644 --- a/src/MEDCalc/MEDCalcConstants.hxx +++ b/src/MEDCalc/MEDCalcConstants.hxx @@ -45,6 +45,9 @@ namespace FIELDSOp { OpSlices = 2504, // Menu Slices OpDeflectionShape = 2505, // Menu Deflection OpPointSprite = 2506, // Menu PointSprite + OpPlot3D = 2507, // Menu Plot3D + OpStreamLines = 2508, // Menu StreamLines + OpCutSegment = 2509, // Menu CutSegment // Interpolation OpProcessingInterpolation = 2601, // Menu Processing interpolation }; diff --git a/src/MEDCalc/cmp/CMakeLists.txt b/src/MEDCalc/cmp/CMakeLists.txt index 2c682ae6c..3eb34835a 100644 --- a/src/MEDCalc/cmp/CMakeLists.txt +++ b/src/MEDCalc/cmp/CMakeLists.txt @@ -45,7 +45,10 @@ SET(COMMON_SOURCES MEDPresentationVectorField.cxx MEDPresentationSlices.cxx MEDPresentationPointSprite.cxx - MEDPresentationDeflectionShape.cxx + MEDPresentationPlot3D.cxx + MEDPresentationDeflectionShape.cxx + MEDPresentationStreamLines.cxx + MEDPresentationCutSegment.cxx ) SET(MEDEngineCommon_SOURCES diff --git a/src/MEDCalc/cmp/MED.cxx b/src/MEDCalc/cmp/MED.cxx index 75890f3c4..d6b4d0903 100644 --- a/src/MEDCalc/cmp/MED.cxx +++ b/src/MEDCalc/cmp/MED.cxx @@ -193,8 +193,7 @@ MED::registerPresentationField(CORBA::Long fieldId, SALOMEDS::StudyBuilder_var studyBuilder = aStudy->NewBuilder(); SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder(); SALOMEDS::SObject_var soPresentation = studyBuilder->NewObject(soFieldseries); - useCaseBuilder->AppendTo(soPresentation->GetFather(), soPresentation); - + soPresentation->SetAttrString("AttributeName", name); soPresentation->SetAttrString("AttributePixMap", ico); @@ -207,6 +206,8 @@ MED::registerPresentationField(CORBA::Long fieldId, aParam->SetInt(PRESENTATION_ID, presentationId); aParam->SetString(PRESENTATION_TYPE, type); + useCaseBuilder->AppendTo(soPresentation->GetFather(), soPresentation); + return MED_ORB::OP_OK; } diff --git a/src/MEDCalc/cmp/MEDPresentation.cxx b/src/MEDCalc/cmp/MEDPresentation.cxx index fea83fd14..ef1d33fd4 100644 --- a/src/MEDCalc/cmp/MEDPresentation.cxx +++ b/src/MEDCalc/cmp/MEDPresentation.cxx @@ -44,6 +44,13 @@ const std::string MEDPresentation::PROP_SELECTED_COMPONENT = "selectedComponent" const std::string MEDPresentation::PROP_COMPONENT = "component_"; const std::string MEDPresentation::PROP_COLOR_MAP = "colorMap"; const std::string MEDPresentation::PROP_SCALAR_BAR_RANGE = "scalarBarRange"; +const std::string MEDPresentation::PROP_VISIBILITY = "visibility"; +const std::string MEDPresentation::PROP_SCALAR_BAR_VISIBILITY = "scalarBarVisibility"; +const std::string MEDPresentation::PROP_SCALAR_BAR_MIN_VALUE = "scalarBarMinValue"; +const std::string MEDPresentation::PROP_SCALAR_BAR_MAX_VALUE = "scalarBarMaxValue"; +const std::string MEDPresentation::PROP_HIDE_DATA_OUTSIDE_CUSTOM_RANGE = "hideDataOutsideCustomRange"; + +#define PROGRAMMABLE "__programmable" MEDPresentation::MEDPresentation(MEDPresentation::TypeID handlerId, const std::string& name, const MEDCALC::ViewModeType viewMode, @@ -58,7 +65,14 @@ MEDPresentation::MEDPresentation(MEDPresentation::TypeID handlerId, const std::s _colorMap(colorMap), _sbRange(sbRange), _renderViewPyId(-1), // will be set by MEDPresentationManager_i::_makePresentation() - _globalDict(0) + _globalDict(0), + _presentationVisibility(true), + _scalarBarVisibility(true), + _scalarBarRangeArray{ 0.0, 100.0 }, + _programmableInitialized(false), + _hideDataOutsideCustomRange(false), + _nbComponents(0), + _nbComponentsInThresholdInput(0) { setStringProperty(MEDPresentation::PROP_NAME, name); @@ -67,20 +81,28 @@ MEDPresentation::MEDPresentation(MEDPresentation::TypeID handlerId, const std::s setIntProperty(MEDPresentation::PROP_COLOR_MAP, static_cast(colorMap)); setIntProperty(MEDPresentation::PROP_SCALAR_BAR_RANGE, static_cast(sbRange)); + setIntProperty(MEDPresentation::PROP_VISIBILITY, static_cast(_presentationVisibility)); + setIntProperty(MEDPresentation::PROP_SCALAR_BAR_VISIBILITY, static_cast(_scalarBarVisibility)); + setDoubleProperty(MEDPresentation::PROP_SCALAR_BAR_MIN_VALUE, _scalarBarRangeArray[0]); + setDoubleProperty(MEDPresentation::PROP_SCALAR_BAR_MAX_VALUE, _scalarBarRangeArray[1]); + setIntProperty(MEDPresentation::PROP_HIDE_DATA_OUTSIDE_CUSTOM_RANGE, static_cast(_hideDataOutsideCustomRange)); + // Python variables: int id = GeneratePythonId(); - std::ostringstream oss_o, oss_d, oss_l, oss_s, oss_r; + std::ostringstream oss_o, oss_d, oss_l, oss_s, oss_r, oss_cl, oss_p; oss_o << "__obj" << id; oss_s << "__srcObj" << id; oss_d << "__disp" << id; oss_l << "__lut" << id; oss_r << "__range" << id; + oss_p << PROGRAMMABLE << id; _objVar = oss_o.str(); _srcObjVar = oss_s.str(); _dispVar = oss_d.str(); _lutVar = oss_l.str(); _rangeVar = oss_r.str(); + _programmableVar = oss_p.str(); } /** @@ -102,7 +124,7 @@ MEDPresentation::initFieldMeshInfos() _fieldName = fieldHandler->fieldname; _mcFieldType = (MEDCoupling::TypeOfField) fieldHandler->type; _pvFieldType = getPVFieldTypeString(_mcFieldType); - _colorByType = _pvFieldType; // by default the same; overridden in DeflectionShape, VectorField, PointSprite and Contour + _colorByType = _pvFieldType; // by default the same; overridden in DeflectionShape, VectorField, PointSprite and Contour, Plot3D _meshName = meshHandler->name; } @@ -136,6 +158,11 @@ MEDPresentation::~MEDPresentation() try { oss << "pvs.Hide(" << _objVar << ", view=" << getRenderViewVar() << ");"; + for (auto& value : _presentationThresolds) { + if (value._active) { + oss << "pvs.Hide(" << value._thresholdVar << ", view=" << getRenderViewVar() << ");"; + } + } execPyLine(oss.str()); // :TRICKY: The two following lines raise an exception when closing MED module // after sequence: MED - load file - PARAVIS - MED - close SALOME @@ -156,6 +183,63 @@ MEDPresentation::generatePipeline() this->internalGeneratePipeline(); } +void MEDPresentation::internalGenerateThreshold() { + std::ostringstream oss; + std::string inputFieldName = getFieldName(); + if (!_programmableInitialized) { + if (_nbComponentsInThresholdInput > 1) { + std::string typ = toScriptCellType(_colorByType); + oss << _programmableVar << " = pvs.ProgrammableFilter(Input = " << _objVar << ");"; + oss << _programmableVar << ".Script = \"\"\"import numpy as np" << std::endl; + oss << "import paraview.vtk.numpy_interface.dataset_adapter as dsa" << std::endl; + oss << "input0 = inputs[0]" << std::endl; + oss << "inputDataArray=input0." << typ << "['" << inputFieldName << "']" << std::endl; + oss << "if type(inputDataArray) == dsa.VTKCompositeDataArray:" << std::endl; + oss << "\tnpa = inputDataArray.GetArrays()" << std::endl; + oss << "else:" << std::endl; + oss << "\tnpa = inputDataArray" << std::endl; + oss << "if type(npa) == list:" << std::endl; + oss << "\tarrs = []" << std::endl; + oss << "\tfor a in npa:" << std::endl; + oss << "\t\tmgm = np.linalg.norm(a, axis = -1)" << std::endl; + oss << "\t\tmga = mgm.reshape(mgm.size, 1)" << std::endl; + oss << "\t\tarrs.append(mga)" << std::endl; + oss << "\tca = dsa.VTKCompositeDataArray(arrs)" << std::endl; + oss << "\toutput." << typ << ".append(ca, '" << inputFieldName << "_magnitude')" << std::endl; + oss << "else:" << std::endl; + oss << "\tmgm = np.linalg.norm(npa, axis = -1)" << std::endl; + oss << "\tmga = mgm.reshape(mgm.size, 1)" << std::endl; + oss << "\toutput." << typ << ".append(mga, '" << inputFieldName << "_magnitude')" << std::endl; + for (std::vector::size_type ii = 1; ii < _nbComponentsInThresholdInput + 1 ; ii++) { + oss << "dataArray" << ii << " = inputDataArray[:, [" << ii - 1 << "]]" << std::endl; + oss << "output." << typ << ".append(dataArray" << ii << ", '" << inputFieldName << "_" << ii << "')" << std::endl; + } + oss << "\"\"\"" << std::endl; + _programmableInitialized = true; + } + } + + ComponentThresold& currentThreshold = _presentationThresolds[getThresholdIndex()]; + if (!currentThreshold._thresholdInitialized) { + std::string& thInput = (_nbComponentsInThresholdInput > 1 ) ? _programmableVar : _objVar; + std::string arrayName = getThresholdFieldName(); + oss << currentThreshold._thresholdVar << " = pvs.Threshold(Input = " << thInput << ");"; + oss << currentThreshold._thresholdVar << ".Scalars = ['" << _colorByType << "', '" << arrayName << "'];"; + oss << additionalThresholdInitializationActions(); + oss << currentThreshold._thresholdDispVar << " = pvs.Show(" << currentThreshold._thresholdVar << ", " + << getRenderViewVar() << ");"; + oss << currentThreshold._thresholdLutVar << " = pvs.GetColorTransferFunction('" << arrayName << "', " + << currentThreshold._thresholdDispVar << ", separate=True);"; + oss << "pvs.ColorBy(" << currentThreshold._thresholdDispVar << ", ('" << _colorByType << "', '" + << arrayName << "'), separate = True);"; + oss << additionalThresholdVisualizationActions(); + currentThreshold._thresholdInitialized = true; + } + if (oss.str().length() > 0) { + pushAndExecPyLine(oss.str()); + } +} + //void //MEDPresentation::pushPyObjects(PyObjectId obj, PyObjectId disp) //{ @@ -236,6 +320,38 @@ MEDPresentation::getIntProperty(const std::string& propName) const } } + void + MEDPresentation::setDoubleProperty(const std::string& propName, const double propValue) + { + _propertiesDouble[propName] = propValue; + } + + double + MEDPresentation::getDoubleProperty(const std::string& propName) const + { + std::map::const_iterator it = _propertiesDouble.find(propName); + if (it != _propertiesDouble.end()) { + return (*it).second; + } + else { + STDLOG("MEDPresentation::getDoubleProperty(): no property named " + propName); + throw MEDPresentationException("MEDPresentation::getDoubleProperty(): no property named " + propName); + } + } + + void + MEDPresentation::dumpDoubleProperties() const + { + std::map::const_iterator it = _propertiesDouble.begin(); + STDLOG("@@@ Dumping DOUBLE properties"); + for (; it != _propertiesDouble.end(); ++it) + { + std::ostringstream oss; + oss << (*it).first << " -> " << (*it).second; + STDLOG(oss.str()); + } + } + void MEDPresentation::dumpStringProperties() const { @@ -388,11 +504,11 @@ MEDPresentation::setOrCreateRenderView() if (_viewMode == MEDCALC::VIEW_MODE_OVERLAP) { // this might potentially re-assign to an existing view variable, but this is OK, we // normally reassign exactly the same RenderView object. - oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');"; + oss2 << view << " = medcalc.FindOrCreateView('RenderView');"; pushAndExecPyLine(oss2.str()); oss2.str(""); } else if (_viewMode == MEDCALC::VIEW_MODE_REPLACE) { // same as above - oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');"; + oss2 << view << " = medcalc.FindOrCreateView('RenderView');"; pushAndExecPyLine(oss2.str()); oss2.str(""); oss2 << "pvs.active_objects.source and pvs.Hide(view=" << view << ");"; pushAndExecPyLine(oss2.str()); oss2.str(""); @@ -431,19 +547,51 @@ MEDPresentation::selectFieldComponent() { std::ostringstream oss, oss_l; std::string ret; - - if (_selectedComponentIndex != -1) + if (!_hideDataOutsideCustomRange) { + if (_selectedComponentIndex != -1) { oss << _lutVar << ".VectorMode = 'Component';"; pushAndExecPyLine(oss.str()); oss.str(""); oss << _lutVar << ".VectorComponent = " << _selectedComponentIndex << ";"; pushAndExecPyLine(oss.str()); oss.str(""); } - else // Euclidean norm + else // Euclidean norm { oss << _lutVar << ".VectorMode = 'Magnitude';"; pushAndExecPyLine(oss.str()); oss.str(""); } + } + else { + // Make sure that threshold is initialized + internalGenerateThreshold(); + // Set range + thresholdValues(); + + // Color map setting + selectColorMap(false); + + if (!_presentationThresolds[getThresholdIndex()]._active) { + std::vector::size_type idx = (_nbComponentsInThresholdInput > 1) ? -1 : 0; + for (auto& value : _presentationThresolds) { + // Hide previous threshold + if (value._active) { + bool currentVisibility = _presentationVisibility; + std::vector::size_type currentIndex = _selectedComponentIndex; + _presentationVisibility = false; + _selectedComponentIndex = idx; + visibility(); + _selectedComponentIndex = currentIndex; + _presentationVisibility = currentVisibility; + value._active = false; + } + idx++; + } + // Show new threshold + visibility(); + _presentationThresolds[getThresholdIndex()]._active = true; + scalarBarTitle(); + } + } } /** @@ -468,24 +616,24 @@ MEDPresentation::scalarBarTitle() compoName = "Magnitude"; } std::ostringstream oss; - oss << "pvs.GetScalarBar(" << _lutVar << ").ComponentTitle = '" << compoName << "';"; + if (_hideDataOutsideCustomRange) { + oss << "pvs.GetScalarBar(" << getLutVar() << ").Title = '" << _fieldName << "';"; + } + oss << "pvs.GetScalarBar(" << getLutVar() << ").ComponentTitle = '" << compoName << "';"; pushAndExecPyLine(oss.str()); oss.str(""); } void -MEDPresentation::selectColorMap() +MEDPresentation::selectColorMap(const bool updateFieldComponent) { - std::ostringstream oss, oss2; - - oss2 << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');"; - pushAndExecPyLine(oss2.str()); + std::ostringstream oss; switch (_colorMap) { case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: - oss << _lutVar << ".ApplyPreset('Blue to Red Rainbow',True);"; + oss << getLutVar() << ".ApplyPreset('Blue to Red Rainbow',True);"; break; case MEDCALC::COLOR_MAP_COOL_TO_WARM: - oss << _lutVar << ".ApplyPreset('Cool to Warm',True);"; + oss << getLutVar() << ".ApplyPreset('Cool to Warm',True);"; break; default: STDLOG("MEDPresentation::getColorMapCommand(): invalid colormap!"); @@ -493,7 +641,9 @@ MEDPresentation::selectColorMap() } pushAndExecPyLine(oss.str()); - selectFieldComponent(); // somehow PV keeps the LUT parameters of the previous presentation, so better reset this. + if(updateFieldComponent) { + selectFieldComponent(); // somehow PV keeps the LUT parameters of the previous presentation, so better reset this. + } } void @@ -501,28 +651,173 @@ MEDPresentation::showObject() { std::ostringstream oss; oss << _dispVar << " = pvs.Show(" << _objVar << ", " << getRenderViewVar() << ");"; + oss << _lutVar << " = pvs.GetColorTransferFunction('" << getFieldName() << "', " << _dispVar << ", separate=True);"; + pushAndExecPyLine(oss.str()); +} + +void +MEDPresentation::hideObject() +{ + std::ostringstream oss; + oss <<"pvs.Hide(" << _objVar << ", " << getRenderViewVar() << ");"; pushAndExecPyLine(oss.str()); } void MEDPresentation::showScalarBar() +{ + // Display Scalar Bar only if presentation is visible + if (_presentationVisibility) { + std::ostringstream oss; + oss << getDispVar() << ".SetScalarBarVisibility(" << getRenderViewVar() << ", True);"; + pushAndExecPyLine(oss.str()); + } +} + +void +MEDPresentation::hideScalarBar() { std::ostringstream oss; - oss << _dispVar << ".SetScalarBarVisibility(" << getRenderViewVar() << ", True);"; + oss << getDispVar() << ".SetScalarBarVisibility(" << getRenderViewVar() << ", False);"; pushAndExecPyLine(oss.str()); } +void +MEDPresentation::scalarBarVisibility() { + _scalarBarVisibility ? showScalarBar() : hideScalarBar(); +} + void MEDPresentation::colorBy() { std::ostringstream oss; - oss << "pvs.ColorBy(" << _dispVar << ", ('" << _colorByType << "', '" << _fieldName << "'));"; + oss << "pvs.ColorBy(" << getDispVar() << ", ('" << _colorByType << "', '" << getFieldName() << "'), separate=True);"; + pushAndExecPyLine(oss.str()); +} + +void MEDPresentation::visibility() { + std::ostringstream oss; + oss << getDispVar() << ".Visibility = " << (_presentationVisibility ? "True" : "False") << ";"; + pushAndExecPyLine(oss.str()); + + // Hide scalar bar with the presentation + if (!_presentationVisibility && _scalarBarVisibility) + hideScalarBar(); + + // Show scalar bar with the presentation + if (_presentationVisibility && _scalarBarVisibility) + showScalarBar(); +} + +void MEDPresentation::threshold() { + _hideDataOutsideCustomRange ? thresholdPresentation() : unThresholdPresentation(); +} + +void MEDPresentation::thresholdPresentation() { + if (!_hideDataOutsideCustomRange) + return; + + internalGenerateThreshold(); + + // Hide _dispVar, for that temporary switch the _presentationVisibility and _hideDataOutsideCustomRange + // flag to false and call visibility() method + bool prevVisibility = _presentationVisibility; + bool prevHideDataOutsideCustomRange = _hideDataOutsideCustomRange; + _presentationVisibility = false; + _hideDataOutsideCustomRange = false; + visibility(); + _presentationVisibility = prevVisibility; + _hideDataOutsideCustomRange = prevHideDataOutsideCustomRange; + + // Display _thresholdDispVar var + visibility(); + + // Select target colormap + selectColorMap(); + + // Adapt scalar bar title + scalarBarTitle(); + + // Additional threshold actions to be done + additionalThresholdActions(); + + _presentationThresolds[getThresholdIndex()]._active = true; +} + +void MEDPresentation::thresholdValues() { + if (!_hideDataOutsideCustomRange) + return; + std::ostringstream oss; + oss << _presentationThresolds[getThresholdIndex()]._thresholdVar << ".ThresholdRange = [ " << _scalarBarRangeArray[0] << ", " << _scalarBarRangeArray[1] << "];"; + oss << _presentationThresolds[getThresholdIndex()]._thresholdLutVar <<".RescaleTransferFunction(" << _scalarBarRangeArray[0] << ", " << _scalarBarRangeArray[1] << ");"; pushAndExecPyLine(oss.str()); } +void MEDPresentation::unThresholdPresentation() { + + if (_presentationThresolds[getThresholdIndex()]._active) { + // Hide _dispVar, for that temporary switch the _presentationVisibility to talse and _hideDataOutsideCustomRange + // flag to true and call visibility() method + bool prevVisibility = _presentationVisibility; + bool prevHideDataOutsideCustomRange = _hideDataOutsideCustomRange; + _presentationVisibility = false; + _hideDataOutsideCustomRange = true; + visibility(); + _presentationVisibility = prevVisibility; + _hideDataOutsideCustomRange = prevHideDataOutsideCustomRange; + + // Range + rescaleTransferFunction(); + + // Display _dispVar var + visibility(); + + // Select target colormap + selectColorMap(); + + // Adapt scalar bar title + scalarBarTitle(); + + // Additional unthreshold actions to be done + additionalUnThresholdActions(); + + _presentationThresolds[getThresholdIndex()]._active = false; + } +} + +int MEDPresentation::getThresholdIndex() const { + if (_nbComponentsInThresholdInput > 1 && _nbComponentsInThresholdInput <= 3) { + return _selectedComponentIndex + 1; + } + else { + return _selectedComponentIndex; + } +} + +/*! + Return _dispVar or _thresholdDispVar depending on _hideDataOutsideCustomRange flag: + _hideDataOutsideCustomRange == false : _dispVar is used + _hideDataOutsideCustomRange == true : _thresholdDispVar is used +*/ +const std::string& MEDPresentation::getDispVar() { + return (_hideDataOutsideCustomRange ? _presentationThresolds[getThresholdIndex()]._thresholdDispVar : _dispVar); +} + +/*! + Return _dispVar or _thresholdDispVar depending on _hideDataOutsideCustomRange flag: + _hideDataOutsideCustomRange == false : _dispVar is used + _hideDataOutsideCustomRange == true : _thresholdDispVar is used +*/ +const std::string& MEDPresentation::getLutVar() { + return (_hideDataOutsideCustomRange ? _presentationThresolds[getThresholdIndex()]._thresholdLutVar : _lutVar); +} + void MEDPresentation::rescaleTransferFunction() { + if (_hideDataOutsideCustomRange) + return; + std::ostringstream oss; switch(_sbRange) { @@ -532,20 +827,55 @@ MEDPresentation::rescaleTransferFunction() case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: oss << _dispVar << ".RescaleTransferFunctionToDataRange(False);"; break; + case MEDCALC::SCALAR_BAR_CUSTOM_RANGE: + oss << _lutVar << ".RescaleTransferFunction("<< _scalarBarRangeArray[0]<<", "<< _scalarBarRangeArray[1]<<");"; + break; default: STDLOG("MEDPresentation::getRescaleCommand(): invalid range!"); throw KERNEL::createSalomeException("MEDPresentation::getRescaleCommand(): invalid range!"); } pushAndExecPyLine(oss.str()); oss.str(""); // Get min-max - oss << _rangeVar << " = [" << _dispVar << ".LookupTable.RGBPoints[0], " << _dispVar << ".LookupTable.RGBPoints[-4]];"; - pushAndExecPyLine(oss.str()); + oss << _rangeVar << " = [" << _lutVar << ".RGBPoints[0], " << _lutVar << ".RGBPoints[-4]];"; + execPyLine(oss.str()); + //Update _scalarBarRange internal variable in case of rescaling to "Data Range" or "Data Range Over All Times" + if (_sbRange == MEDCALC::SCALAR_BAR_ALL_TIMESTEPS || + _sbRange == MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP) { + MEDPyLockWrapper lock; + PyObject * obj = getPythonObjectFromMain(_rangeVar.c_str()); + if (obj && PyList_Check(obj)) { + PyObject* objL0 = PyList_GetItem(obj, 0); + PyObject* objL1 = PyList_GetItem(obj, 1); + if (PyFloat_Check(objL0)) { + double min = PyFloat_AsDouble(objL0); + _scalarBarRangeArray[0] = min; + } + if (PyFloat_Check(objL1)) { + double max = PyFloat_AsDouble(objL1); + _scalarBarRangeArray[1] = max; + } + } + setDoubleProperty(MEDPresentation::PROP_SCALAR_BAR_MIN_VALUE, _scalarBarRangeArray[0]); + setDoubleProperty(MEDPresentation::PROP_SCALAR_BAR_MAX_VALUE, _scalarBarRangeArray[1]); + } // Adapt scalar bar title scalarBarTitle(); } +MEDCALC::PresentationVisibility +MEDPresentation::presentationStateInActiveView() { + MEDPyLockWrapper lock; + MEDCALC::PresentationVisibility result = MEDCALC::PRESENTATION_NOT_IN_VIEW; + execPyLine("__isInView = ( " + getRenderViewVar() + " == pvs.GetActiveView() )"); + PyObject * obj = getPythonObjectFromMain("__isInView"); + + if (obj && PyBool_Check(obj) && (obj == Py_True)) { + result = _presentationVisibility ? MEDCALC::PRESENTATION_VISIBLE : MEDCALC::PRESENTATION_INVISIBLE; + } + return result; +} int MEDPresentation::GeneratePythonId() @@ -554,6 +884,14 @@ MEDPresentation::GeneratePythonId() return INIT_ID++; } +bool MEDPresentation::isThresoldActive() const { + bool active = false; + for (auto const& value : _presentationThresolds) { + active = active || value._active; + } + return active; +} + bool MEDPresentation::activateView() { @@ -587,11 +925,15 @@ MEDPresentation::activateView() void MEDPresentation::recreateViewSetup() { + bool prevHideDataOutsideCustomRange = _hideDataOutsideCustomRange; + _hideDataOutsideCustomRange = false; showObject(); colorBy(); showScalarBar(); selectColorMap(); rescaleTransferFunction(); + _hideDataOutsideCustomRange = prevHideDataOutsideCustomRange; + threshold(); resetCameraAndRender(); } @@ -620,19 +962,7 @@ void MEDPresentation::fillAvailableFieldComponents() { MEDPyLockWrapper lock; // GIL! - std::string typ; - - if(_pvFieldType == "CELLS") { - typ = "CellData"; - } - else if (_pvFieldType == "POINTS") { - typ = "PointData"; - } - else { - std::string msg("Unsupported spatial discretisation: " + _pvFieldType); - STDLOG(msg); - throw KERNEL::createSalomeException(msg.c_str()); - } + std::string typ = getScriptCellType(); std::ostringstream oss; oss << "__nbCompo = " << _srcObjVar << "." << typ << ".GetArray('" << _fieldName << "').GetNumberOfComponents();"; @@ -646,6 +976,8 @@ MEDPresentation::fillAvailableFieldComponents() STDLOG("Unexpected Python error"); throw KERNEL::createSalomeException("Unexpected Python error"); } + _nbComponents = nbCompo; + _nbComponentsInThresholdInput = _nbComponents; setIntProperty(MEDPresentation::PROP_NB_COMPONENTS, nbCompo); // if the field is not a vector (2 or 3 components), select the first component of the tensor, @@ -695,15 +1027,69 @@ MEDPresentation::fillAvailableFieldComponents() oss_n << compo << "(" << val << ")"; aCompos.push_back(oss_n.str()); } - aCompoMap[compo] = aCompoMap[compo]++; + aCompoMap[compo] = aCompoMap[compo] + 1; } } - for (std::vector::size_type i = 0; i != aCompos.size(); i++) { + std::string aCopy = _programmableVar; + std::string id = aCopy.replace(aCopy.find(PROGRAMMABLE), std::string(aCopy).length() - 1, ""); + + std::vector::size_type up = (nbCompo > 1) ? nbCompo + 1 : nbCompo; + for (std::vector::size_type i = 0; i != up; i++) { std::ostringstream oss_p; - oss_p << MEDPresentation::PROP_COMPONENT << i; - setStringProperty(oss_p.str(), aCompos[i]); + if (i != 0 || nbCompo == 1) { + std::vector::size_type idx = (nbCompo > 1) ? i - 1 : i; + oss_p << MEDPresentation::PROP_COMPONENT << idx; + setStringProperty(oss_p.str(), aCompos[idx]); + } + std::ostringstream oss_thd, oss_th, oss_thl; + oss_th << "__threshold" << id <<"_"< 1 && _hideDataOutsideCustomRange) { + std::ostringstream oss; + if (_selectedComponentIndex == -1) { + oss << _fieldName << "_magnitude"; + } + else { + oss << _fieldName << "_" << _selectedComponentIndex + 1; + } + result = oss.str(); + } + return result; +} + +std::string MEDPresentation::getFieldName() const { + return _fieldName; +} + +std::string MEDPresentation::toScriptCellType(const std::string& pvType) { + std::string typ = ""; + if (pvType == "CELLS") { + typ = "CellData"; + } + else if (pvType == "POINTS") { + typ = "PointData"; } + else { + std::string msg("Unsupported spatial discretisation: " + pvType); + STDLOG(msg); + throw KERNEL::createSalomeException(msg.c_str()); + } + return typ; +} +std::string MEDPresentation::getScriptCellType() const { + return toScriptCellType(_pvFieldType); } /** @@ -725,6 +1111,28 @@ MEDPresentation::applyCellToPointIfNeeded() } } +/** +* Delete threshold filters and programmable filter +*/ +void +MEDPresentation::deleteThresholds() { + std::ostringstream oss; + for (auto& value : _presentationThresolds) { + if (value._active) { + oss << "pvs.Hide(" << value._thresholdVar << ");"; + } + if (value._thresholdInitialized) { + oss << "pvs.Delete(" << value._thresholdVar <<");"; + value.clear(); + } + } + if (_programmableInitialized) { + oss << "pvs.Delete(" << _programmableVar << ");"; + _programmableInitialized = false; + } + pushAndExecPyLine(oss.str()); +} + ///** // * Convert a vector field into a 3D vector field: // * - if the vector field is already 3D, nothing to do diff --git a/src/MEDCalc/cmp/MEDPresentation.hxx b/src/MEDCalc/cmp/MEDPresentation.hxx index cb158ad60..ba079fc4d 100644 --- a/src/MEDCalc/cmp/MEDPresentation.hxx +++ b/src/MEDCalc/cmp/MEDPresentation.hxx @@ -34,6 +34,36 @@ #include #include +struct ComponentThresold { + + ComponentThresold() { + _thresholdVar = ""; + _thresholdDispVar = ""; + _thresholdLutVar = ""; + _thresholdInitialized = false; + _active = false; + } + + ///! ParaView Threshold filter variable to hide data outside custom range in Python scripting + std::string _thresholdVar; + ///! ParaView Threshold display variable to hide data outside custom range in Python scripting + std::string _thresholdDispVar; + ///! ParaView Threshold LUT variable in the Python scripting commands + std::string _thresholdLutVar; + + ///! Initialization flag + bool _thresholdInitialized; + ///! Active flag + bool _active; + + void clear() { + _thresholdInitialized = false; + _active = false; + } +}; + +typedef std::vector PresentationThresolds; + class MEDCALC_EXPORT MEDPresentation { friend class MEDPresentationManager_i; @@ -45,12 +75,18 @@ public: virtual ~MEDPresentation(); - static const std::string PROP_NAME; // name of the presentation - static const std::string PROP_NB_COMPONENTS; // number of field components - static const std::string PROP_SELECTED_COMPONENT; // index of the selected component - 0 means Euclidean norm - static const std::string PROP_COMPONENT; // string prefix for all properties storing component names - static const std::string PROP_COLOR_MAP; // color map - TODO: arch fix - should be in params only - static const std::string PROP_SCALAR_BAR_RANGE; // scalar bar range - TODO: arch fix - should be in params only + static const std::string PROP_NAME; // name of the presentation + static const std::string PROP_NB_COMPONENTS; // number of field components + static const std::string PROP_SELECTED_COMPONENT; // index of the selected component - 0 means Euclidean norm + static const std::string PROP_COMPONENT; // string prefix for all properties storing component names + static const std::string PROP_COLOR_MAP; // color map - TODO: arch fix - should be in params only + static const std::string PROP_SCALAR_BAR_RANGE; // scalar bar range - TODO: arch fix - should be in params only + static const std::string PROP_VISIBILITY; // presentation visibility + static const std::string PROP_SCALAR_BAR_VISIBILITY; // scalar bar visiblity + static const std::string PROP_SCALAR_BAR_MIN_VALUE; // min value of scalar bar range + static const std::string PROP_SCALAR_BAR_MAX_VALUE; // max value of scalar bar range + static const std::string PROP_HIDE_DATA_OUTSIDE_CUSTOM_RANGE; // Hide data outside custom range + virtual void setStringProperty(const std::string& propName, const std::string& propValue); const std::string getStringProperty(const std::string& propName) const; @@ -58,19 +94,25 @@ public: virtual void setIntProperty(const std::string& propName, const int propValue); int getIntProperty(const std::string& propName) const; + virtual void setDoubleProperty(const std::string& propName, const double propValue); + double getDoubleProperty(const std::string& propName) const; + // returns True if the view was still alive, False if it must have been recreated // because the user closed it. - bool activateView(); + virtual bool activateView(); virtual void recreateViewSetup(); void dumpIntProperties() const; void dumpStringProperties() const; + void dumpDoubleProperties() const; std::string paravisDump() const; long getPyViewID() const { return _renderViewPyId; } void setPyViewID(long id) { _renderViewPyId = id; } + static std::string toScriptCellType(const std::string&); + protected: typedef std::pair PyObjectId; static int GeneratePythonId(); @@ -86,15 +128,35 @@ protected: void createSource(); void setTimestamp(); void selectFieldComponent(); - void showObject(); + void virtual showObject(); + void virtual hideObject(); void colorBy(); - void showScalarBar(); + virtual void showScalarBar(); + virtual void hideScalarBar(); + void scalarBarVisibility(); void rescaleTransferFunction(); - void selectColorMap(); - void scalarBarTitle(); + void selectColorMap(const bool updateFieldComponent=true); + virtual void scalarBarTitle(); void resetCameraAndRender(); + virtual void visibility(); + void threshold(); + void thresholdPresentation(); + void unThresholdPresentation(); + void thresholdValues(); + virtual void additionalThresholdActions() {}; + virtual std::string additionalThresholdVisualizationActions() { return ""; }; + virtual std::string additionalThresholdInitializationActions() { return ""; }; + virtual void additionalUnThresholdActions() {}; + virtual std::string getFieldName() const; + virtual std::string getThresholdFieldName() const; + + std::string getScriptCellType() const; + bool isThresoldActive() const; virtual void internalGeneratePipeline(); + virtual void internalGenerateThreshold(); + const std::string& getDispVar(); + const std::string& getLutVar(); PyObject* getPythonObjectFromMain(const char* var) const; void execPyLine(const std::string & lin); void pushAndExecPyLine(const std::string & lin); @@ -106,6 +168,8 @@ protected: void extractFileName(const std::string& name); // void convertTo3DVectorField(); + virtual MEDCALC::PresentationVisibility presentationStateInActiveView(); + template void updateComponent(const std::string& newCompo); @@ -113,7 +177,15 @@ protected: void updateColorMap(MEDCALC::ColorMapType colorMap); template - void updateScalarBarRange(MEDCALC::ScalarBarRangeType sbRange); + void updateScalarBarRange(MEDCALC::ScalarBarRangeType sbRange, + bool hideDataoutsideCustomRange, + double minValue, double maxValue); + + template + void updateVisibility(const bool theVisibility); + + template + void updateScalarBarVisibility(const bool theVisibility); template void getParameters(PresentationParameters& params) const; @@ -121,6 +193,10 @@ protected: template void setParameters(const PresentationParameters& params); + int getThresholdIndex() const; + + void deleteThresholds(); + private: std::string getPVFieldTypeString(MEDCoupling::TypeOfField fieldType) const; @@ -145,9 +221,15 @@ protected: MEDPresentation::TypeID _handlerId; // either a field or a mesh id (a field ID though, most of the time) int _selectedComponentIndex; + int _nbComponents; + int _nbComponentsInThresholdInput; MEDCALC::ViewModeType _viewMode; MEDCALC::ColorMapType _colorMap; MEDCALC::ScalarBarRangeType _sbRange; + bool _presentationVisibility; + bool _scalarBarVisibility; + bool _hideDataOutsideCustomRange; + double _scalarBarRangeArray[2]; ///! Identifier (in the Python dump) of the render view int _renderViewPyId; @@ -161,11 +243,19 @@ protected: std::string _lutVar; ///! ParaView variable in Python holding the data range std::string _rangeVar; + ///! Prorgammable variable in the Python scripting commands + std::string _programmableVar; + bool _programmableInitialized; + + //Thresolds + PresentationThresolds _presentationThresolds; + private: ///! Presentation properties std::map _propertiesStr; std::map _propertiesInt; + std::map _propertiesDouble; std::vector _pythonCmds; diff --git a/src/MEDCalc/cmp/MEDPresentation.txx b/src/MEDCalc/cmp/MEDPresentation.txx index 8fcca7999..79172f408 100644 --- a/src/MEDCalc/cmp/MEDPresentation.txx +++ b/src/MEDCalc/cmp/MEDPresentation.txx @@ -122,24 +122,90 @@ MEDPresentation::updateColorMap(MEDCALC::ColorMapType colorMap) template void -MEDPresentation::updateScalarBarRange(MEDCALC::ScalarBarRangeType sbRange) +MEDPresentation::updateScalarBarRange(MEDCALC::ScalarBarRangeType sbRange, + bool hideDataOutsideCustomRange, + double minValue, double maxValue) { PresentationType * p = static_cast(this); - PresentationParameters params; p->getParameters(params); + bool prevHideDataoutsideCustomRange = params.hideDataOutsideCustomRange; + params.scalarBarRange = sbRange; + params.scalarBarRangeArray[0] = minValue; + params.scalarBarRangeArray[1] = maxValue; + params.hideDataOutsideCustomRange = hideDataOutsideCustomRange; p->setParameters(params); p->_sbRange = sbRange; + p->_scalarBarRangeArray[0] = minValue; + p->_scalarBarRangeArray[1] = maxValue; + p->_hideDataOutsideCustomRange = hideDataOutsideCustomRange; // GUI helper: setIntProperty(MEDPresentation::PROP_SCALAR_BAR_RANGE, sbRange); + setDoubleProperty(MEDPresentation::PROP_SCALAR_BAR_MIN_VALUE, minValue); + setDoubleProperty(MEDPresentation::PROP_SCALAR_BAR_MAX_VALUE, maxValue); + setIntProperty(MEDPresentation::PROP_HIDE_DATA_OUTSIDE_CUSTOM_RANGE, static_cast(hideDataOutsideCustomRange)); + + // Update the pipeline: + if (hideDataOutsideCustomRange || hideDataOutsideCustomRange != prevHideDataoutsideCustomRange) { + MEDPyLockWrapper lock; + threshold(); //Swith on/off threshould or update threshould range + pushAndExecPyLine("pvs.Render();"); + } + else + { + MEDPyLockWrapper lock; + rescaleTransferFunction(); + pushAndExecPyLine("pvs.Render();"); + } +} + +template +void +MEDPresentation::updateVisibility(const bool theVisibility) +{ + PresentationType * p = static_cast(this); + + PresentationParameters params; + p->getParameters(params); + params.visibility = theVisibility; + p->setParameters(params); + + p->_presentationVisibility = theVisibility; + + // GUI helper: + setIntProperty(MEDPresentation::PROP_VISIBILITY, theVisibility); // Update the pipeline: { MEDPyLockWrapper lock; - rescaleTransferFunction(); + visibility(); + pushAndExecPyLine("pvs.Render();"); + } +} + +template +void +MEDPresentation::updateScalarBarVisibility(const bool theVisibility) +{ + PresentationType * p = static_cast(this); + + PresentationParameters params; + p->getParameters(params); + params.scalarBarVisibility = theVisibility; + p->setParameters(params); + + p->_scalarBarVisibility = theVisibility; + + // GUI helper: + setIntProperty(MEDPresentation::PROP_SCALAR_BAR_VISIBILITY, theVisibility); + + // Update the pipeline: + { + MEDPyLockWrapper lock; + scalarBarVisibility(); pushAndExecPyLine("pvs.Render();"); } } diff --git a/src/MEDCalc/cmp/MEDPresentationContour.cxx b/src/MEDCalc/cmp/MEDPresentationContour.cxx index f04f44f6b..5c891759b 100644 --- a/src/MEDCalc/cmp/MEDPresentationContour.cxx +++ b/src/MEDCalc/cmp/MEDPresentationContour.cxx @@ -27,6 +27,7 @@ const std::string MEDPresentationContour::TYPE_NAME = "MEDPresentationContour"; const std::string MEDPresentationContour::PROP_NB_CONTOUR = "nbContour"; +const std::string MEDPresentationContour::PROB_CONTOUR_COMPONENT_ID = "contourComponent"; MEDPresentationContour::MEDPresentationContour(const MEDCALC::ContourParameters& params, const MEDCALC::ViewModeType viewMode) : @@ -34,6 +35,40 @@ MEDPresentationContour::MEDPresentationContour(const MEDCALC::ContourParameters& _params(params) { setIntProperty(MEDPresentationContour::PROP_NB_CONTOUR, params.nbContours); + setIntProperty(MEDPresentationContour::PROB_CONTOUR_COMPONENT_ID, 0); + std::stringstream oss; + oss << "__contourProgrammable" << GeneratePythonId(); + _countourProgrammableVar = oss.str(); +} + +void +MEDPresentationContour::initProgFilter() { + std::ostringstream oss; + std::string typ = "PointData"; // Contour Filter is applicable only to Point Data + oss << _countourProgrammableVar << " = pvs.ProgrammableFilter(Input = " << _srcObjVar << ");"; + oss << _countourProgrammableVar << ".Script = \"\"\"import numpy as np" << std::endl; + oss << "import paraview.vtk.numpy_interface.dataset_adapter as dsa" << std::endl; + oss << "input0 = inputs[0]" << std::endl; + oss << "inputDataArray=input0." << typ << "['" << _fieldName << "']" << std::endl; + oss << "npa = inputDataArray.GetArrays()" << std::endl; + oss << "if type(npa) == list:" << std::endl; + oss << "\tarrs = []" << std::endl; + oss << "\tfor a in npa:" << std::endl; + oss << "\t\tmgm = np.linalg.norm(a, axis = -1)" << std::endl; + oss << "\t\tmga = mgm.reshape(mgm.size, 1)" << std::endl; + oss << "\t\tarrs.append(mga)" << std::endl; + oss << "\tca = dsa.VTKCompositeDataArray(arrs)" << std::endl; + oss << "\toutput." << typ << ".append(ca, '" << _fieldName << "_magnitude')" << std::endl; + oss << "else:" << std::endl; + oss << "\tmgm = np.linalg.norm(npa, axis = -1)" << std::endl; + oss << "\tmga = mgm.reshape(mgm.size, 1)" << std::endl; + oss << "\toutput." << typ << ".append(mga, '" << _fieldName << "_magnitude')" << std::endl; + for (std::vector::size_type ii = 1; ii < _nbComponents + 1 ; ii++) { + oss << "dataArray" << ii << " = inputDataArray[:, [" << ii - 1 << "]]" << std::endl; + oss << "output." << typ << ".append(dataArray" << ii << ", '" << _fieldName << "_" << ii << "')" << std::endl; + } + oss << "\"\"\"" << std::endl; + pushAndExecPyLine(oss.str()); } void @@ -47,8 +82,12 @@ void MEDPresentationContour::setNumberContours() { std::ostringstream oss; + std::string aVar = _srcObjVar; + if (_nbComponents > 1) { + aVar = _countourProgrammableVar; + } - oss << "min_max = " << _srcObjVar << ".PointData.GetArray('" << _fieldName << "').GetRange();"; + oss << "min_max = " << aVar << ".PointData.GetArray('" << getContourComponentName() << "').GetRange();"; pushAndExecPyLine(oss.str()); oss.str(""); oss << "delta = (min_max[1]-min_max[0])/float(" << _params.nbContours << ");"; pushAndExecPyLine(oss.str()); oss.str(""); @@ -68,32 +107,39 @@ MEDPresentationContour::internalGeneratePipeline() // Populate internal array of available components: fillAvailableFieldComponents(); - if (getIntProperty(MEDPresentation::PROP_NB_COMPONENTS) > 1) - { - const char * msg = "Contour presentation only works for scalar field!"; // this message will appear in GUI too - STDLOG(msg); - throw KERNEL::createSalomeException(msg); - } if (_params.nbContours < 1) - { - const char * mes = "Invalid number of contours!"; - STDLOG(mes); - throw KERNEL::createSalomeException(mes); - } - + { + const char * mes = "Invalid number of contours!"; + STDLOG(mes); + throw KERNEL::createSalomeException(mes); + } setOrCreateRenderView(); // instantiate __viewXXX, needs to be after the exception above otherwise previous elements in the view will be hidden. // Contour needs point data: applyCellToPointIfNeeded(); - std::ostringstream oss; - oss << _objVar << " = pvs.Contour(Input=" << _srcObjVar << ");"; - pushAndExecPyLine(oss.str()); oss.str(""); - showObject(); + // Calculate component + if (_nbComponents > 1) + { + pushAndExecPyLine(oss.str()); oss.str(""); + initProgFilter(); + _nbComponentsInThresholdInput = 1; // Because we extract all components as a separate array usign Programmable Filter + _selectedComponentIndex = 0; + oss << _objVar << " = pvs.Contour(Input=" << _countourProgrammableVar << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); - oss << _objVar << ".ContourBy = ['POINTS', '" << _fieldName << "'];"; - pushAndExecPyLine(oss.str()); oss.str(""); + oss << _objVar << ".ContourBy = ['POINTS', '" << _fieldName << "_magnitude" << "'];"; + pushAndExecPyLine(oss.str()); + } + else + { + oss << _objVar << " = pvs.Contour(Input=" << _srcObjVar << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + + oss << _objVar << ".ContourBy = ['POINTS', '" << _fieldName << "'];"; + pushAndExecPyLine(oss.str()); oss.str(""); + } // Colorize contour oss << _objVar << ".ComputeScalars = 1;"; @@ -102,7 +148,8 @@ MEDPresentationContour::internalGeneratePipeline() // Set number of contours setNumberContours(); - colorBy(); // see initFieldInfo() - necessarily POINTS because of the conversion above + showObject(); + colorBy(); showScalarBar(); selectColorMap(); rescaleTransferFunction(); @@ -115,8 +162,14 @@ MEDPresentationContour::updatePipeline(const MEDCALC::ContourParameters& params) if (params.fieldHandlerId != _params.fieldHandlerId) throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!"); - if (params.scalarBarRange != _params.scalarBarRange) - updateScalarBarRange(params.scalarBarRange); + if (params.scalarBarRange != _params.scalarBarRange || + params.hideDataOutsideCustomRange != _params.hideDataOutsideCustomRange || + params.scalarBarRangeArray[0] != _params.scalarBarRangeArray[0] || + params.scalarBarRangeArray[1] != _params.scalarBarRangeArray[1]) + updateScalarBarRange(params.scalarBarRange, + params.hideDataOutsideCustomRange, + params.scalarBarRangeArray[0], + params.scalarBarRangeArray[1]); if (params.colorMap != _params.colorMap) updateColorMap(params.colorMap); @@ -130,6 +183,16 @@ MEDPresentationContour::updatePipeline(const MEDCALC::ContourParameters& params) } updateNbContours(params.nbContours); } + + if (std::string(params.contourComponent) != std::string(_params.contourComponent)) + updateContourComponent(std::string(params.contourComponent)); + + if (params.visibility != _params.visibility) + updateVisibility(params.visibility); + + if (params.scalarBarVisibility != _params.scalarBarVisibility) + updateScalarBarVisibility(params.scalarBarVisibility); + } void @@ -147,3 +210,93 @@ MEDPresentationContour::updateNbContours(const int nbContours) pushAndExecPyLine("pvs.Render();"); } } + +void +MEDPresentationContour::updateContourComponent(const std::string& newCompo) +{ + _params.contourComponent = newCompo.c_str(); + + int id = getContourComponentId(); + + // GUI helper: + setIntProperty(MEDPresentationContour::PROB_CONTOUR_COMPONENT_ID, id); + + // Update the pipeline: + { + MEDPyLockWrapper lock; + std::ostringstream oss; + oss << _objVar << ".ContourBy = ['POINTS', '" << getContourComponentName() << "'];"; + pushAndExecPyLine(oss.str()); oss.str(""); + scalarBarTitle(); + pushAndExecPyLine("pvs.Render();"); + } +} + + +int MEDPresentationContour::getContourComponentId() const { + int result = -1; + if (std::string(_params.contourComponent) == "") { // Magnitude + result = 0; + } + for (std::vector::size_type i = 0; i < _nbComponents; i++) { + std::ostringstream oss_p; + oss_p << MEDPresentation::PROP_COMPONENT << i; + std::string compo = getStringProperty(oss_p.str()); + if (std::string(_params.contourComponent) == compo) { + result = i + 1; + break; + } + } + if (result == -1) { + std::ostringstream oss; + oss << "MEDPresentationContour::getContourComponentId(): unknown component '" <<_params.contourComponent + << "' !\n"; + STDLOG(oss.str()); + throw KERNEL::createSalomeException(oss.str().c_str()); + } + return result; +} + +std::string MEDPresentationContour::getContourComponentName() const { + std::ostringstream result; + result << _fieldName; + if (_nbComponents > 1) { + int id = getContourComponentId(); + switch (id) { + case 0: result << "_magnitude"; break; + default: result << "_" << id; break; + } + } + return result.str(); +} + +std::string MEDPresentationContour::getFieldName() const { + return getContourComponentName(); +} + +void +MEDPresentationContour::scalarBarTitle() +{ + if (_nbComponents > 1) { + // get selected component name: + int id = getContourComponentId(); + std::string compoName; + if (id != 0) + { + std::ostringstream oss1; + oss1 << MEDPresentation::PROP_COMPONENT << id - 1; + compoName = getStringProperty(oss1.str()); + } + else + { + compoName = "Magnitude"; + } + std::ostringstream oss; + oss << "pvs.GetScalarBar(" << getLutVar() << ").Title = '" << _fieldName << "';"; + oss << "pvs.GetScalarBar(" << getLutVar() << ").ComponentTitle = '" << compoName << "';"; + pushAndExecPyLine(oss.str()); oss.str(""); + } + else { + MEDPresentation::scalarBarTitle(); + } +} \ No newline at end of file diff --git a/src/MEDCalc/cmp/MEDPresentationContour.hxx b/src/MEDCalc/cmp/MEDPresentationContour.hxx index 657aaf439..2063a7131 100644 --- a/src/MEDCalc/cmp/MEDPresentationContour.hxx +++ b/src/MEDCalc/cmp/MEDPresentationContour.hxx @@ -28,6 +28,7 @@ class MEDCALC_EXPORT MEDPresentationContour : public MEDPresentation public: static const std::string TYPE_NAME; static const std::string PROP_NB_CONTOUR; + static const std::string PROB_CONTOUR_COMPONENT_ID; MEDPresentationContour(const MEDCALC::ContourParameters& params, const MEDCALC::ViewModeType viewMode); virtual ~MEDPresentationContour() {} @@ -40,13 +41,19 @@ public: void setParameters(const MEDCALC::ContourParameters & params) { _params = params; } ; protected: + void initProgFilter(); void updateNbContours(const int nbContours); + void updateContourComponent(const std::string& newCompo); virtual void internalGeneratePipeline(); - + int getContourComponentId() const; + std::string getContourComponentName() const; void setNumberContours(); + std::string getFieldName() const override; + void scalarBarTitle() override; private: MEDCALC::ContourParameters _params; + std::string _countourProgrammableVar; }; #endif diff --git a/src/MEDCalc/cmp/MEDPresentationCutSegment.cxx b/src/MEDCalc/cmp/MEDPresentationCutSegment.cxx new file mode 100644 index 000000000..5c4a9e7c4 --- /dev/null +++ b/src/MEDCalc/cmp/MEDPresentationCutSegment.cxx @@ -0,0 +1,304 @@ +// Copyright (C) 2016-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDPyLockWrapper.hxx" + +#include "MEDPresentationCutSegment.hxx" +#include "MEDPresentationException.hxx" + +#include +#undef LOG // should be fixed in KERNEL - double definition +#include + +#include + +const std::string MEDPresentationCutSegment::TYPE_NAME = "MEDPresentationCutSegment"; +const std::string MEDPresentationCutSegment::PROP_POINT1_X = "cutPoint1_X"; +const std::string MEDPresentationCutSegment::PROP_POINT1_Y = "cutPoint1_Y"; +const std::string MEDPresentationCutSegment::PROP_POINT1_Z = "cutPoint1_Z"; +const std::string MEDPresentationCutSegment::PROP_POINT2_X = "cutPoint2_X"; +const std::string MEDPresentationCutSegment::PROP_POINT2_Y = "cutPoint2_Y"; +const std::string MEDPresentationCutSegment::PROP_POINT2_Z = "cutPoint2_Z"; + + +MEDPresentationCutSegment::MEDPresentationCutSegment(const MEDCALC::CutSegmentParameters& params, + const MEDCALC::ViewModeType viewMode) : + MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), + _params(params) +{ + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT1_X, params.point1[0]); + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT1_Y, params.point1[1]); + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT1_Z, params.point1[2]); + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT2_X, params.point2[0]); + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT2_Y, params.point2[1]); + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT2_Z, params.point2[2]); + + int id = GeneratePythonId(); + std::ostringstream oss_ch; + oss_ch << "__chartViewDisp" << id; + _chartViewDispVar = oss_ch.str(); +} + +MEDPresentationCutSegment::~MEDPresentationCutSegment() { + //3D Presentation is erased by base class descructor, + // hide only 2D Presentation here: + std::ostringstream oss; + oss << "pvs.Hide(" << _objVar << ", " << getChartViewVar() << ");"; + oss << getChartViewVar() << ".Update();"; + pushAndExecPyLine(oss.str()); +} + +void +MEDPresentationCutSegment::internalGeneratePipeline() +{ + MEDPresentation::internalGeneratePipeline(); + + MEDPyLockWrapper lock; + + createSource(); + setTimestamp(); + + fillAvailableFieldComponents(); + setOrCreateRenderView(); + setOrCreateChartView(); + + std::ostringstream oss; + oss << _objVar << "= pvs.PlotOverLine(Input=" << _srcObjVar << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + // Get bouding box "min" and "max" as initial values of + oss << "P1 = " << _objVar << ".Source.Point1.GetData()"; // Source.Point1 is paraview.servermanager.VectorProperty, so call GetData() + execPyLine(oss.str()); oss.str(""); + PyObject * obj1 = getPythonObjectFromMain("P1"); + if (obj1 && PyList_Check(obj1)) { + PyObject* objP0 = PyList_GetItem(obj1, 0); + PyObject* objP1 = PyList_GetItem(obj1, 1); + PyObject* objP2 = PyList_GetItem(obj1, 2); + if (PyFloat_Check(objP0) && PyFloat_Check(objP1) && PyFloat_Check(objP2)) { + _params.point1[0] = PyFloat_AsDouble(objP0); + _params.point1[1] = PyFloat_AsDouble(objP1); + _params.point1[2] = PyFloat_AsDouble(objP2); + } + } + + oss << "P2 = " << _objVar << ".Source.Point2.GetData()"; // Source.Point2 is paraview.servermanager.VectorProperty, so call GetData() + execPyLine(oss.str()); oss.str(""); + PyObject * obj2 = getPythonObjectFromMain("P2"); + if (obj2 && PyList_Check(obj2)) { + PyObject* objP0 = PyList_GetItem(obj2, 0); + PyObject* objP1 = PyList_GetItem(obj2, 1); + PyObject* objP2 = PyList_GetItem(obj2, 2); + if (PyFloat_Check(objP0) && PyFloat_Check(objP1) && PyFloat_Check(objP2)) { + _params.point2[0] = PyFloat_AsDouble(objP0); + _params.point2[1] = PyFloat_AsDouble(objP1); + _params.point2[2] = PyFloat_AsDouble(objP2); + } + } + + // To update GUI + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT1_X, _params.point1[0]); + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT1_Y, _params.point1[1]); + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT1_Z, _params.point1[2]); + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT2_X, _params.point2[0]); + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT2_Y, _params.point2[1]); + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT2_Z, _params.point2[2]); + + showObject(); + colorBy(); // see initFieldInfo() - necessarily POINTS because of the conversion above + showScalarBar(); + selectColorMap(); + rescaleTransferFunction(); + resetCameraAndRender(); +} + +void +MEDPresentationCutSegment::updatePipeline(const MEDCALC::CutSegmentParameters& params) +{ + if (params.fieldHandlerId != _params.fieldHandlerId) + throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!"); + + if (params.colorMap != _params.colorMap) + updateColorMap(params.colorMap); + + if (params.scalarBarRange != _params.scalarBarRange || + params.hideDataOutsideCustomRange != _params.hideDataOutsideCustomRange || + params.scalarBarRangeArray[0] != _params.scalarBarRangeArray[0] || + params.scalarBarRangeArray[1] != _params.scalarBarRangeArray[1]) + updateScalarBarRange(params.scalarBarRange, + params.hideDataOutsideCustomRange, + params.scalarBarRangeArray[0], + params.scalarBarRangeArray[1]); + + if (params.point1[0] != _params.point1[0] || + params.point1[2] != _params.point1[1] || + params.point1[1] != _params.point1[2]) + updatePoint1(params.point1); + + if (params.point2[0] != _params.point2[0] || + params.point2[2] != _params.point2[1] || + params.point2[1] != _params.point2[2]) + updatePoint2(params.point2); + + if (params.visibility != _params.visibility) + updateVisibility(params.visibility); + if (params.scalarBarVisibility != _params.scalarBarVisibility) + updateScalarBarVisibility(params.scalarBarVisibility); +} + +void +MEDPresentationCutSegment::updatePoint1(MEDCALC::DoubleArray point1) +{ + _params.point1[0] = point1[0]; + _params.point1[1] = point1[1]; + _params.point1[2] = point1[2]; + + // GUI helper: + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT1_X, point1[0]); + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT1_Y, point1[1]); + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT1_Z, point1[2]); + + // Update Point1 + std::ostringstream oss; + oss << _objVar << ".Source.Point1 = [" << + _params.point1[0] << ", " << + _params.point1[1] << ", " << + _params.point1[2] << "];"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << getChartViewVar() << ".Update();"; + oss << "pvs.Render();"; + pushAndExecPyLine(oss.str()); +} + +void +MEDPresentationCutSegment::updatePoint2(MEDCALC::DoubleArray point2) +{ + _params.point2[0] = point2[0]; + _params.point2[1] = point2[1]; + _params.point2[2] = point2[2]; + + // GUI helper: + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT2_X, point2[0]); + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT2_Y, point2[1]); + setDoubleProperty(MEDPresentationCutSegment::PROP_POINT2_Z, point2[2]); + + // Update Point2 + std::ostringstream oss; + oss << _objVar << ".Source.Point2 = [" << + _params.point2[0] << ", " << + _params.point2[1] << ", " << + _params.point2[2] << "];"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << getChartViewVar() << ".Update();"; + oss << "pvs.Render();"; + pushAndExecPyLine(oss.str()); +} + +std::string MEDPresentationCutSegment::getChartViewVar() const { + std::ostringstream oss; + oss << "__chartView" << getPyViewID(); + return oss.str(); +} + +void MEDPresentationCutSegment::setOrCreateChartView() { + std::string lineChartViewName = getChartViewVar(); + std::ostringstream oss; + oss << lineChartViewName << " = medcalc.FindOrCreateView('XYChartView');"; + pushAndExecPyLine(oss.str()); +} + +void MEDPresentationCutSegment::visibility() { + // Base class implementation: hide 3D presentation in the RenderView + MEDPresentation::visibility(); + // Show/Hide 2D Presenation + std::ostringstream oss; + oss << getChartViewDispVar() << ".Visibility = " << (_presentationVisibility ? "True" : "False") << ";"; + oss << getChartViewVar() << ".Update();"; + pushAndExecPyLine(oss.str()); +} + +void MEDPresentationCutSegment::showObject() { + // 3D Presentation: + MEDPresentation::showObject(); + + // 2D Presentation: + std::ostringstream oss; + std::ostringstream oss_series; + oss_series << _fieldName; + if (_nbComponents > 1) { + oss_series << "_Magnitude"; + } + oss << _chartViewDispVar << " = pvs.Show(" << _objVar << ", " << getChartViewVar() << ", 'XYChartRepresentation');"; + oss << _chartViewDispVar << ".SeriesVisibility = ['" << oss_series.str() << "'];"; + oss << getChartViewVar() << ".Update();"; + pushAndExecPyLine(oss.str()); +} + +void MEDPresentationCutSegment::hideObject() { + // 3D Presentation: + MEDPresentation::hideObject(); + + // 2D Presentation: + std::ostringstream oss; + oss << "pvs.Hide(" << _objVar << ", " << getChartViewVar() << ");"; + oss << getChartViewVar() << ".Update();"; + pushAndExecPyLine(oss.str()); +} + +std::string MEDPresentationCutSegment::getChartViewDispVar() { + return _chartViewDispVar; +} + +bool MEDPresentationCutSegment::activateView() { + // if XYChartView of current MEDPresentationCutSegment is active, keep it active + // Owerwise call impplementation of base class + MEDPyLockWrapper lock; + execPyLine("__XYChartViewAlive = " + getChartViewDispVar() + " in pvs.GetActiveView()"); + PyObject * obj = getPythonObjectFromMain("__XYChartViewAlive"); + bool XYChartViewAlive = true; + if (obj && PyBool_Check(obj)) + XYChartViewAlive = (obj == Py_True); + if (!XYChartViewAlive) { + return MEDPresentation::activateView(); + } + return XYChartViewAlive; +} + +MEDCALC::PresentationVisibility +MEDPresentationCutSegment::presentationStateInActiveView() { + MEDPyLockWrapper lock; + MEDCALC::PresentationVisibility result = MEDCALC::PRESENTATION_NOT_IN_VIEW; + + execPyLine("__isInView = ( " + getRenderViewVar() + " == pvs.GetActiveView() or "\ + + getChartViewVar() +" == pvs.GetActiveView())"); + PyObject * obj = getPythonObjectFromMain("__isInView"); + + if (obj && PyBool_Check(obj) && (obj == Py_True)) { + result = _presentationVisibility ? MEDCALC::PRESENTATION_VISIBLE : MEDCALC::PRESENTATION_INVISIBLE; + } + return result; +} + +std::string MEDPresentationCutSegment::additionalThresholdInitializationActions() { + if (_hideDataOutsideCustomRange) { + std::ostringstream oss; + ComponentThresold& currentThreshold = _presentationThresolds[getThresholdIndex()]; + oss << currentThreshold._thresholdVar << ".AllScalars = 0;"; + return oss.str(); + } + return ""; +} diff --git a/src/MEDCalc/cmp/MEDPresentationCutSegment.hxx b/src/MEDCalc/cmp/MEDPresentationCutSegment.hxx new file mode 100644 index 000000000..ddde99cb6 --- /dev/null +++ b/src/MEDCalc/cmp/MEDPresentationCutSegment.hxx @@ -0,0 +1,69 @@ +// Copyright (C) 2016-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef SRC_MEDCALC_CMP_MEDPRESENTATION_CUT_SEGMENT_HXX_ +#define SRC_MEDCALC_CMP_MEDPRESENTATION_CUT_SEGMENT_HXX_ + +#include "MEDCALC.hxx" +#include "MEDPresentation.hxx" +#include + +class MEDCALC_EXPORT MEDPresentationCutSegment : public MEDPresentation +{ +public: + static const std::string TYPE_NAME; + static const std::string PROP_POINT1_X; + static const std::string PROP_POINT1_Y; + static const std::string PROP_POINT1_Z; + static const std::string PROP_POINT2_X; + static const std::string PROP_POINT2_Y; + static const std::string PROP_POINT2_Z; + + MEDPresentationCutSegment(const MEDCALC::CutSegmentParameters& params, const MEDCALC::ViewModeType viewMode); + virtual ~MEDPresentationCutSegment(); + + void updatePipeline(const MEDCALC::CutSegmentParameters& params); + + void getParameters(MEDCALC::CutSegmentParameters & params) const { params = _params; } ; + void setParameters(const MEDCALC::CutSegmentParameters & params) { _params = params; } ; + + bool activateView() override; + MEDCALC::PresentationVisibility presentationStateInActiveView() override; + +protected: + virtual void internalGeneratePipeline(); + void updatePoint1(const MEDCALC::DoubleArray); + void updatePoint2(const MEDCALC::DoubleArray); + + std::string getChartViewVar() const; + void setOrCreateChartView(); + std::string getChartViewDispVar(); + + std::string additionalThresholdInitializationActions() override; + void visibility() override; + void showObject() override; + void hideObject() override; + + +private: + MEDCALC::CutSegmentParameters _params; + std::string _chartViewDispVar; +}; + +#endif \ No newline at end of file diff --git a/src/MEDCalc/cmp/MEDPresentationDeflectionShape.cxx b/src/MEDCalc/cmp/MEDPresentationDeflectionShape.cxx index 4722f98db..4b8794896 100644 --- a/src/MEDCalc/cmp/MEDPresentationDeflectionShape.cxx +++ b/src/MEDCalc/cmp/MEDPresentationDeflectionShape.cxx @@ -105,12 +105,24 @@ MEDPresentationDeflectionShape::updatePipeline(const MEDCALC::DeflectionShapePar if (params.fieldHandlerId != _params.fieldHandlerId) throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!"); - if (params.scalarBarRange != _params.scalarBarRange) + if (params.scalarBarRange != _params.scalarBarRange || + params.hideDataOutsideCustomRange != _params.hideDataOutsideCustomRange || + params.scalarBarRangeArray[0] != _params.scalarBarRangeArray[0] || + params.scalarBarRangeArray[1] != _params.scalarBarRangeArray[1]) { - updateScalarBarRange(params.scalarBarRange); + updateScalarBarRange(params.scalarBarRange, + params.hideDataOutsideCustomRange, + params.scalarBarRangeArray[0], + params.scalarBarRangeArray[1]); autoScale(); pushAndExecPyLine("pvs.Render();"); } if (params.colorMap != _params.colorMap) updateColorMap(params.colorMap); + + if (params.visibility != _params.visibility) + updateVisibility(params.visibility); + + if (params.scalarBarVisibility != _params.scalarBarVisibility) + updateScalarBarVisibility(params.scalarBarVisibility); } diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx index f9e46fd7f..e39c46c1b 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx @@ -29,6 +29,9 @@ #include "MEDPresentationVectorField.hxx" #include "MEDPresentationDeflectionShape.hxx" #include "MEDPresentationPointSprite.hxx" +#include "MEDPresentationPlot3D.hxx" +#include "MEDPresentationStreamLines.hxx" +#include "MEDPresentationCutSegment.hxx" #include @@ -76,7 +79,7 @@ MEDPresentationManager_i::_getPresentation(MEDPresentation::TypeID presentationI STDLOG("Get presentation " << presentationID); std::map::const_iterator citr = _presentations.find(presentationID); if (citr == _presentations.end()) - return NULL; + return nullptr; return (*citr).second; } @@ -124,6 +127,30 @@ MEDPresentationManager_i::getPresentationIntProperty(MEDPresentation::TypeID pre } +void +MEDPresentationManager_i::setPresentationDoubleProperty(MEDPresentation::TypeID presentationID, const char* propName, + const CORBA::Double propValue) +{ + MEDPresentation* pres = _getPresentation(presentationID); + if (pres) + pres->setDoubleProperty(propName, propValue); + else + throw KERNEL::createSalomeException("setPresentationDoubleProperty(): presentation not found!!"); +} + +CORBA::Double +MEDPresentationManager_i::getPresentationDoubleProperty(MEDPresentation::TypeID presentationID, const char* propName) +{ + MEDPresentation* pres = _getPresentation(presentationID); + if (pres) { + return (CORBA::Double) pres->getDoubleProperty(propName); + } + else + throw KERNEL::createSalomeException("getPresentationIntProperty(): presentation not found!!"); + +} + + MEDPresentation::TypeID MEDPresentationManager_i::makeMeshView(const MEDCALC::MeshViewParameters& params, const MEDCALC::ViewModeType viewMode) { @@ -166,6 +193,24 @@ MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& return _makePresentation(params, viewMode); } +MEDPresentation::TypeID +MEDPresentationManager_i::makePlot3D(const MEDCALC::Plot3DParameters& params, const MEDCALC::ViewModeType viewMode) +{ + return _makePresentation(params, viewMode); +} + +MEDPresentation::TypeID +MEDPresentationManager_i::makeStreamLines(const MEDCALC::StreamLinesParameters& params, const MEDCALC::ViewModeType viewMode) +{ + return _makePresentation(params, viewMode); +} + +MEDPresentation::TypeID +MEDPresentationManager_i::makeCutSegment(const MEDCALC::CutSegmentParameters& params, const MEDCALC::ViewModeType viewMode) +{ + return _makePresentation(params, viewMode); +} + MEDCALC::MeshViewParameters MEDPresentationManager_i::getMeshViewParameters(MEDPresentation::TypeID presentationID) { @@ -185,7 +230,7 @@ MEDPresentationManager_i::getScalarMapParameters(MEDPresentation::TypeID present return tmp._retn(); } -MEDCALC::ContourParameters +MEDCALC::ContourParameters* MEDPresentationManager_i::getContourParameters(MEDPresentation::TypeID presentationID) { MEDCALC::ContourParameters* p = new MEDCALC::ContourParameters(); @@ -203,10 +248,10 @@ MEDPresentationManager_i::getSlicesParameters(MEDPresentation::TypeID presentati return tmp._retn(); } -MEDCALC::VectorFieldParameters +MEDCALC::VectorFieldParameters* MEDPresentationManager_i::getVectorFieldParameters(MEDPresentation::TypeID presentationID) { - MEDCALC::VectorFieldParameters* p = new MEDCALC::VectorFieldParameters(); + MEDCALC::VectorFieldParameters* p = new MEDCALC::VectorFieldParameters; _getParameters(presentationID, *p); MEDCALC::VectorFieldParameters_var tmp(p); return tmp._retn(); @@ -221,7 +266,34 @@ MEDPresentationManager_i::getPointSpriteParameters(MEDPresentation::TypeID prese return tmp._retn(); } -MEDCALC::DeflectionShapeParameters +MEDCALC::Plot3DParameters* +MEDPresentationManager_i::getPlot3DParameters(MEDPresentation::TypeID presentationID) +{ + MEDCALC::Plot3DParameters* p = new MEDCALC::Plot3DParameters(); + _getParameters(presentationID, *p); + MEDCALC::Plot3DParameters_var tmp(p); + return tmp._retn(); +} + +MEDCALC::StreamLinesParameters* +MEDPresentationManager_i::getStreamLinesParameters(MEDPresentation::TypeID presentationID) +{ + MEDCALC::StreamLinesParameters* p = new MEDCALC::StreamLinesParameters(); + _getParameters(presentationID, *p); + MEDCALC::StreamLinesParameters_var tmp(p); + return tmp._retn(); +} + +MEDCALC::CutSegmentParameters* +MEDPresentationManager_i::getCutSegmentParameters(MEDPresentation::TypeID presentationID) +{ + MEDCALC::CutSegmentParameters* p = new MEDCALC::CutSegmentParameters(); + _getParameters(presentationID, *p); + MEDCALC::CutSegmentParameters_var tmp(p); + return tmp._retn(); +} + +MEDCALC::DeflectionShapeParameters* MEDPresentationManager_i::getDeflectionShapeParameters(MEDPresentation::TypeID presentationID) { MEDCALC::DeflectionShapeParameters* p = new MEDCALC::DeflectionShapeParameters(); @@ -273,18 +345,34 @@ MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentation return _updatePresentation(presentationID, params); } +void +MEDPresentationManager_i::updatePlot3D(MEDPresentation::TypeID presentationID, const MEDCALC::Plot3DParameters& params) +{ + return _updatePresentation(presentationID, params); +} + +void +MEDPresentationManager_i::updateStreamLines(MEDPresentation::TypeID presentationID, const MEDCALC::StreamLinesParameters& params) +{ + return _updatePresentation(presentationID, params); +} + +void +MEDPresentationManager_i::updateCutSegment(MEDPresentation::TypeID presentationID, const MEDCALC::CutSegmentParameters& params) +{ + return _updatePresentation(presentationID, params); +} + CORBA::Boolean MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID) { STDLOG("Remove presentation " << presentationID); - std::map::const_iterator citr = _presentations.find(presentationID); - if (citr == _presentations.end()) { - std::cerr << "removePresentation(): presentation not found!!" << std::endl; + MEDPresentation* presentation = _getPresentation(presentationID); + + if (!presentation) return false; - } - MEDPresentation* presentation = (*citr).second; - if (presentation) - delete presentation; + + delete presentation; _presentations.erase(presentationID); STDLOG("Presentation " << presentationID << " has been removed."); @@ -363,6 +451,17 @@ MEDPresentationManager_i::getAllPresentations() return presList; } +MEDCALC::PresentationVisibility +MEDPresentationManager_i::stateInActiveView(MEDPresentation::TypeID presentationID) +{ + MEDPresentation* pres = _getPresentation(presentationID); + if (pres) + return pres->presentationStateInActiveView(); + else + throw KERNEL::createSalomeException("stateInActiveView(): presentation not found!!"); +} + + void MEDPresentationManager_i::cleanUp() { diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx index ac1ed281b..6893ea120 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx @@ -46,6 +46,9 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, MEDCALC_EXPORT MEDPresentation::TypeID makeSlices(const MEDCALC::SlicesParameters&, const MEDCALC::ViewModeType); MEDCALC_EXPORT MEDPresentation::TypeID makeDeflectionShape(const MEDCALC::DeflectionShapeParameters&, const MEDCALC::ViewModeType); MEDCALC_EXPORT MEDPresentation::TypeID makePointSprite(const MEDCALC::PointSpriteParameters&, const MEDCALC::ViewModeType); + MEDCALC_EXPORT MEDPresentation::TypeID makePlot3D(const MEDCALC::Plot3DParameters&, const MEDCALC::ViewModeType); + MEDCALC_EXPORT MEDPresentation::TypeID makeStreamLines(const MEDCALC::StreamLinesParameters&, const MEDCALC::ViewModeType); + MEDCALC_EXPORT MEDPresentation::TypeID makeCutSegment(const MEDCALC::CutSegmentParameters&, const MEDCALC::ViewModeType); MEDCALC_EXPORT void setPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue); MEDCALC_EXPORT char* getPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName); @@ -53,13 +56,19 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, MEDCALC_EXPORT void setPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName, const CORBA::Long propValue); MEDCALC_EXPORT CORBA::Long getPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName); + MEDCALC_EXPORT void setPresentationDoubleProperty(MEDPresentation::TypeID presentationID, const char* propName, const CORBA::Double propValue); + MEDCALC_EXPORT CORBA::Double getPresentationDoubleProperty(MEDPresentation::TypeID presentationID, const char* propName); + MEDCALC_EXPORT MEDCALC::MeshViewParameters getMeshViewParameters(MEDPresentation::TypeID presentationID); MEDCALC_EXPORT MEDCALC::ScalarMapParameters* getScalarMapParameters(MEDPresentation::TypeID presentationID); - MEDCALC_EXPORT MEDCALC::ContourParameters getContourParameters(MEDPresentation::TypeID presentationID); + MEDCALC_EXPORT MEDCALC::ContourParameters* getContourParameters(MEDPresentation::TypeID presentationID); MEDCALC_EXPORT MEDCALC::SlicesParameters* getSlicesParameters(MEDPresentation::TypeID presentationID); - MEDCALC_EXPORT MEDCALC::VectorFieldParameters getVectorFieldParameters(MEDPresentation::TypeID presentationID); + MEDCALC_EXPORT MEDCALC::VectorFieldParameters* getVectorFieldParameters(MEDPresentation::TypeID presentationID); MEDCALC_EXPORT MEDCALC::PointSpriteParameters* getPointSpriteParameters(MEDPresentation::TypeID presentationID); - MEDCALC_EXPORT MEDCALC::DeflectionShapeParameters getDeflectionShapeParameters(MEDPresentation::TypeID presentationID); + MEDCALC_EXPORT MEDCALC::Plot3DParameters* getPlot3DParameters(MEDPresentation::TypeID presentationID); + MEDCALC_EXPORT MEDCALC::DeflectionShapeParameters* getDeflectionShapeParameters(MEDPresentation::TypeID presentationID); + MEDCALC_EXPORT MEDCALC::StreamLinesParameters* getStreamLinesParameters(MEDPresentation::TypeID presentationID); + MEDCALC_EXPORT MEDCALC::CutSegmentParameters* getCutSegmentParameters(MEDPresentation::TypeID presentationID); MEDCALC_EXPORT void updateMeshView(MEDPresentation::TypeID, const MEDCALC::MeshViewParameters&); MEDCALC_EXPORT void updateScalarMap(MEDPresentation::TypeID, const MEDCALC::ScalarMapParameters&); @@ -68,6 +77,9 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, MEDCALC_EXPORT void updateSlices(MEDPresentation::TypeID, const MEDCALC::SlicesParameters&); MEDCALC_EXPORT void updateDeflectionShape(MEDPresentation::TypeID, const MEDCALC::DeflectionShapeParameters&); MEDCALC_EXPORT void updatePointSprite(MEDPresentation::TypeID, const MEDCALC::PointSpriteParameters&); + MEDCALC_EXPORT void updatePlot3D(MEDPresentation::TypeID, const MEDCALC::Plot3DParameters&); + MEDCALC_EXPORT void updateStreamLines(MEDPresentation::TypeID, const MEDCALC::StreamLinesParameters&); + MEDCALC_EXPORT void updateCutSegment(MEDPresentation::TypeID, const MEDCALC::CutSegmentParameters&); MEDCALC_EXPORT CORBA::Boolean removePresentation(MEDPresentation::TypeID); MEDCALC_EXPORT CORBA::Boolean activateView(MEDPresentation::TypeID); @@ -76,6 +88,7 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, MEDCALC_EXPORT char * getParavisDump(MEDPresentation::TypeID presentationID); MEDCALC_EXPORT MEDCALC::PresentationsList* getAllPresentations(); MEDCALC_EXPORT void cleanUp(); + MEDCALC_EXPORT MEDCALC::PresentationVisibility stateInActiveView(MEDPresentation::TypeID presentationID); private: MEDPresentationManager_i(); diff --git a/src/MEDCalc/cmp/MEDPresentationMeshView.cxx b/src/MEDCalc/cmp/MEDPresentationMeshView.cxx index 10222b656..7a4b09907 100644 --- a/src/MEDCalc/cmp/MEDPresentationMeshView.cxx +++ b/src/MEDCalc/cmp/MEDPresentationMeshView.cxx @@ -108,6 +108,9 @@ MEDPresentationMeshView::updatePipeline(const MEDCALC::MeshViewParameters& param if (params.mode != _params.mode) updateMeshMode(params.mode); + if (params.visibility != _params.visibility) + updateVisibility(params.visibility); + } void diff --git a/src/MEDCalc/cmp/MEDPresentationMeshView.hxx b/src/MEDCalc/cmp/MEDPresentationMeshView.hxx index fbe69ccc7..8efae59fb 100644 --- a/src/MEDCalc/cmp/MEDPresentationMeshView.hxx +++ b/src/MEDCalc/cmp/MEDPresentationMeshView.hxx @@ -40,6 +40,9 @@ public: virtual void recreateViewSetup(); + virtual void showScalarBar() override {}; + virtual void hideScalarBar() override {}; + protected: void updateMeshMode(const MEDCALC::MeshModeType mode); virtual void internalGeneratePipeline(); diff --git a/src/MEDCalc/cmp/MEDPresentationPlot3D.cxx b/src/MEDCalc/cmp/MEDPresentationPlot3D.cxx new file mode 100644 index 000000000..c1369113a --- /dev/null +++ b/src/MEDCalc/cmp/MEDPresentationPlot3D.cxx @@ -0,0 +1,303 @@ +// Copyright (C) 2016-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDPyLockWrapper.hxx" + +#include "MEDPresentationPlot3D.hxx" +#include "MEDPresentationException.hxx" + +#include +#undef LOG // should be fixed in KERNEL - double definition +#include + +#include + +const std::string MEDPresentationPlot3D::TYPE_NAME = "MEDPresentationPlot3D"; +const std::string MEDPresentationPlot3D::PROP_PLANE_NORMAL_X = "planeNormalX"; +const std::string MEDPresentationPlot3D::PROP_PLANE_NORMAL_Y = "planeNormalY"; +const std::string MEDPresentationPlot3D::PROP_PLANE_NORMAL_Z = "planeNormalZ"; +const std::string MEDPresentationPlot3D::PROP_PLANE_POS = "planePos"; +const std::string MEDPresentationPlot3D::PROP_IS_PLANAR = "isPlanar"; + + +MEDPresentationPlot3D::MEDPresentationPlot3D(const MEDCALC::Plot3DParameters& params, + const MEDCALC::ViewModeType viewMode) : + MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), + _params(params) +{ + setDoubleProperty(MEDPresentationPlot3D::PROP_PLANE_NORMAL_X, params.planeNormal[0]); + setDoubleProperty(MEDPresentationPlot3D::PROP_PLANE_NORMAL_Y, params.planeNormal[1]); + setDoubleProperty(MEDPresentationPlot3D::PROP_PLANE_NORMAL_Z, params.planeNormal[2]); + setDoubleProperty(MEDPresentationPlot3D::PROP_PLANE_POS, params.planePos); + + _isPlanar = 0; + setIntProperty(MEDPresentationPlot3D::PROP_IS_PLANAR, _isPlanar); +} + +void +MEDPresentationPlot3D::initFieldMeshInfos() +{ + MEDPresentation::initFieldMeshInfos(); + _colorByType = "POINTS"; +} + + +void +MEDPresentationPlot3D::getSliceObj() +{ + std::ostringstream oss; + oss << "__objSlice"; + _objSlice = oss.str(); oss.str(""); + + oss << _objSlice << " = pvs.Slice(" << _srcObjVar << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + + oss << _objSlice << ".SliceType.Normal = [" << + _params.planeNormal[0] << ", " << + _params.planeNormal[1] << ", " << + _params.planeNormal[2] << "];"; + pushAndExecPyLine(oss.str()); oss.str(""); + + oss << "slicePos = medcalc.GetPositions(" << _srcObjVar << ", [" << + _params.planeNormal[0] << ", " << + _params.planeNormal[1] << ", " << + _params.planeNormal[2] << "]," << + _params.planePos << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + + oss << _objSlice << ".SliceType.Origin = slicePos"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _objVar << " = " << _objSlice; + execPyLine(oss.str()); oss.str(""); +} + +void +MEDPresentationPlot3D::getMagnitude() +{ + std::ostringstream oss; + oss << "__objCalc"; + _objCalc = oss.str(); oss.str(""); + + oss << _objCalc <<"= pvs.Calculator(Input=" << _objSlice << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + if (_pvFieldType == "CELLS") { + oss << _objCalc << ".AttributeType = 'Cell Data'"; + pushAndExecPyLine(oss.str()); oss.str(""); + } + oss << _objCalc << ".ResultArrayName = 'resCalcMag'"; + pushAndExecPyLine(oss.str()); oss.str(""); + std::string fieldName = _fieldName; + if(_nbComponents == 2) + fieldName += "_Vector"; + oss << _objCalc << ".Function = 'mag(" << fieldName << ")'"; + pushAndExecPyLine(oss.str()); oss.str(""); + execPyLine(oss.str()); oss.str(""); +} + +void +MEDPresentationPlot3D::internalGeneratePipeline() +{ + MEDPresentation::internalGeneratePipeline(); + + MEDPyLockWrapper lock; + + createSource(); + setTimestamp(); + + fillAvailableFieldComponents(); + setOrCreateRenderView(); + + std::ostringstream oss; + oss << "is_planar = medcalc.IsPlanarObj("<< _srcObjVar<<");"; + pushAndExecPyLine(oss.str()); oss.str(""); + getPythonObjectFromMain("is_planar"); + PyObject * obj = getPythonObjectFromMain("is_planar"); + + // Planar mesh? + if (obj && PyBool_Check(obj) && (obj == Py_False)) + { + getSliceObj(); + } + else + { + oss << "__objSlice"; + _objSlice = oss.str(); oss.str(""); + oss << _objSlice << " = " << _srcObjVar; + execPyLine(oss.str()); oss.str(""); + _isPlanar = 1; + setIntProperty(MEDPresentationPlot3D::PROP_IS_PLANAR, _isPlanar); + } + // Vector field? + if(_nbComponents > 1) + { + getMagnitude(); + oss << "scalarArray = "<< _objCalc << ".ResultArrayName;"; + execPyLine(oss.str()); oss.str(""); + } + else + { + oss << "__objCalc"; + _objCalc = oss.str(); oss.str(""); + oss << _objCalc << " = " << _objSlice; + execPyLine(oss.str()); oss.str(""); + } + // cell data? + if (_pvFieldType == "CELLS") + { + oss << _objCalc << " = pvs.CellDatatoPointData(" << _objCalc << ");"; + oss << _objCalc << ".PassCellData = 1;"; + pushAndExecPyLine(oss.str()); oss.str(""); + } + + oss << _objVar << " = pvs.WarpByScalar(Input=" << _objCalc << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + if(_nbComponents > 1) + oss << _objVar << ".Scalars = ['" << "POINTS" << "', " << "scalarArray]"; + else + oss << _objVar << ".Scalars = ['" << "POINTS" << "', '" << _fieldName << "']"; + pushAndExecPyLine(oss.str()); oss.str(""); + if (obj && PyBool_Check(obj) && (obj == Py_False)) + { + oss << _objVar << ".Normal = [" << + _params.planeNormal[0] << ", " << + _params.planeNormal[1] << ", " << + _params.planeNormal[2] << "];"; + } + else + { + oss << "P2 = " << "medcalc.GetPlaneNormalVector(" << _objSlice << ")"; + execPyLine(oss.str()); oss.str(""); + PyObject * obj2 = getPythonObjectFromMain("P2"); + if (obj2 && PyList_Check(obj2)) { + PyObject* objP0 = PyList_GetItem(obj2, 0); + PyObject* objP1 = PyList_GetItem(obj2, 1); + PyObject* objP2 = PyList_GetItem(obj2, 2); + if (PyFloat_Check(objP0) && PyFloat_Check(objP1) && PyFloat_Check(objP2)) { + _params.planeNormal[0] = PyFloat_AsDouble(objP0); + _params.planeNormal[1] = PyFloat_AsDouble(objP1); + _params.planeNormal[2] = PyFloat_AsDouble(objP2); + } + } + + setDoubleProperty(MEDPresentationPlot3D::PROP_PLANE_NORMAL_X, _params.planeNormal[0]); + setDoubleProperty(MEDPresentationPlot3D::PROP_PLANE_NORMAL_Y, _params.planeNormal[1]); + setDoubleProperty(MEDPresentationPlot3D::PROP_PLANE_NORMAL_Z, _params.planeNormal[2]); + oss << _objVar << ".Normal = " << "medcalc.GetPlaneNormalVector(" << _objSlice << ")"; + } + pushAndExecPyLine(oss.str()); oss.str(""); + + showObject(); + colorBy(); // see initFieldInfo() - necessarily POINTS because of the conversion above + showScalarBar(); + selectColorMap(); + rescaleTransferFunction(); + resetCameraAndRender(); +} + +void +MEDPresentationPlot3D::updatePipeline(const MEDCALC::Plot3DParameters& params) +{ + if (params.fieldHandlerId != _params.fieldHandlerId) + throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!"); + + if (params.colorMap != _params.colorMap) + updateColorMap(params.colorMap); + + if (params.scalarBarRange != _params.scalarBarRange || + params.hideDataOutsideCustomRange != _params.hideDataOutsideCustomRange || + params.scalarBarRangeArray[0] != _params.scalarBarRangeArray[0] || + params.scalarBarRangeArray[1] != _params.scalarBarRangeArray[1]) + updateScalarBarRange(params.scalarBarRange, + params.hideDataOutsideCustomRange, + params.scalarBarRangeArray[0], + params.scalarBarRangeArray[1]); + + if (params.planeNormal[0] != _params.planeNormal[0] || + params.planeNormal[1] != _params.planeNormal[1] || + params.planeNormal[2] != _params.planeNormal[2]) + updatePlaneNormal(params.planeNormal); + + if (_isPlanar == 0 && params.planePos != _params.planePos) + updatePlanePos(params.planePos); + + if (params.visibility != _params.visibility) + updateVisibility(params.visibility); + if (params.scalarBarVisibility != _params.scalarBarVisibility) + updateScalarBarVisibility(params.scalarBarVisibility); +} + +void +MEDPresentationPlot3D::updatePlaneNormal(MEDCALC::DoubleArray planeNormal) +{ + _params.planeNormal[0] = planeNormal[0]; + _params.planeNormal[1] = planeNormal[1]; + _params.planeNormal[2] = planeNormal[2]; + + // GUI helper: + setDoubleProperty(MEDPresentationPlot3D::PROP_PLANE_NORMAL_X, planeNormal[0]); + setDoubleProperty(MEDPresentationPlot3D::PROP_PLANE_NORMAL_Y, planeNormal[1]); + setDoubleProperty(MEDPresentationPlot3D::PROP_PLANE_NORMAL_Z, planeNormal[2]); + + // Update Plane Normal + { + MEDPyLockWrapper lock; + std::ostringstream oss; + if(_isPlanar == 0) + { + oss << _objSlice << ".SliceType.Normal = [" << + _params.planeNormal[0] << ", " << + _params.planeNormal[1] << ", " << + _params.planeNormal[2] << "];"; + pushAndExecPyLine(oss.str()); oss.str(""); + updatePlanePos(_params.planePos); + } + + oss << _objVar << ".Normal = [" << + _params.planeNormal[0] << ", " << + _params.planeNormal[1] << ", " << + _params.planeNormal[2] << "];"; + pushAndExecPyLine(oss.str()); oss.str(""); + pushAndExecPyLine("pvs.Render();"); + } +} + +void +MEDPresentationPlot3D::updatePlanePos(const double planePos) +{ + _params.planePos = planePos; + + // GUI helper: + setDoubleProperty(MEDPresentationPlot3D::PROP_PLANE_POS, planePos); + + // Update Plane Position + { + MEDPyLockWrapper lock; + std::ostringstream oss; + oss << "slicePos = medcalc.GetPositions(" << _srcObjVar << ", [" << + _params.planeNormal[0] << ", " << + _params.planeNormal[1] << ", " << + _params.planeNormal[2] << "]," << + _params.planePos << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + + oss << _objSlice << ".SliceType.Origin = slicePos"; + pushAndExecPyLine(oss.str()); oss.str(""); + pushAndExecPyLine("pvs.Render();"); + } +} \ No newline at end of file diff --git a/src/MEDCalc/cmp/MEDPresentationPlot3D.hxx b/src/MEDCalc/cmp/MEDPresentationPlot3D.hxx new file mode 100644 index 000000000..ca0607821 --- /dev/null +++ b/src/MEDCalc/cmp/MEDPresentationPlot3D.hxx @@ -0,0 +1,62 @@ +// Copyright (C) 2016-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef SRC_MEDCALC_CMP_MEDPRESENTATION_PLOT3D_HXX_ +#define SRC_MEDCALC_CMP_MEDPRESENTATION_PLOT3D_HXX_ + +#include "MEDCALC.hxx" +#include "MEDPresentation.hxx" +#include + +class MEDCALC_EXPORT MEDPresentationPlot3D : public MEDPresentation +{ +public: + static const std::string TYPE_NAME; + static const std::string PROP_PLANE_NORMAL_X; + static const std::string PROP_PLANE_NORMAL_Y; + static const std::string PROP_PLANE_NORMAL_Z; + static const std::string PROP_PLANE_POS; + static const std::string PROP_IS_PLANAR; + + MEDPresentationPlot3D(const MEDCALC::Plot3DParameters& params, const MEDCALC::ViewModeType viewMode); + virtual ~MEDPresentationPlot3D() {} + + void updatePipeline(const MEDCALC::Plot3DParameters& params); + + void getParameters(MEDCALC::Plot3DParameters & params) const { params = _params; } ; + void setParameters(const MEDCALC::Plot3DParameters & params) { _params = params; } ; + + void initFieldMeshInfos() override; + + +protected: + virtual void internalGeneratePipeline(); + void getSliceObj(); + void getMagnitude(); + void updatePlaneNormal(const MEDCALC::DoubleArray); + void updatePlanePos(const double); + std::string _objSlice; + std::string _objCalc; + +private: + MEDCALC::Plot3DParameters _params; + int _isPlanar; +}; + +#endif \ No newline at end of file diff --git a/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx b/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx index a025b49b4..2d2eb4eeb 100644 --- a/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx +++ b/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx @@ -32,7 +32,8 @@ const std::string MEDPresentationPointSprite::TYPE_NAME = "MEDPresentationPointS MEDPresentationPointSprite::MEDPresentationPointSprite(const MEDCALC::PointSpriteParameters& params, const MEDCALC::ViewModeType viewMode) : - MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), _params(params) + MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), _params(params), + _gaussianRadius(0.0) { } @@ -50,21 +51,27 @@ MEDPresentationPointSprite::scaleBallRadius() int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS); // set component or euclidean norm as the array to scale the ball radius - if (nbCompo > 1) - { - if (_selectedComponentIndex == -1) - oss << _dispVar << ".ScaleArrayComponent = 'Magnitude';"; - else - oss << _dispVar << ".ScaleArrayComponent = " << _selectedComponentIndex << ";"; - pushAndExecPyLine(oss.str()); oss.str(""); + if (!_hideDataOutsideCustomRange) { + if (nbCompo > 1) + { + if (_selectedComponentIndex == -1) + oss << _dispVar << ".ScaleArrayComponent = 'Magnitude';"; + else + oss << _dispVar << ".ScaleArrayComponent = " << _selectedComponentIndex << ";"; + pushAndExecPyLine(oss.str()); oss.str(""); + } + } + else { + oss << getDispVar() << ".SetScaleArray = ['POINTS', '" << getThresholdFieldName() << "'];"; + oss << getDispVar() << ".ScaleArrayComponent = " << 0 << ";"; } // rescale transfer function to update scalar bar and get min-max range rescaleTransferFunction(); // _rangeVar (to get min and max of the fields) is updated in rescaleTransferFunction - oss << _dispVar << ".ScaleTransferFunction.RescaleTransferFunction(" << _rangeVar << "[0], " << _rangeVar << "[1]);"; - pushAndExecPyLine(oss.str()); oss.str(""); + oss << getDispVar() << ".ScaleTransferFunction.RescaleTransferFunction(" << _rangeVar << "[0], " << _rangeVar << "[1]);"; + pushAndExecPyLine(oss.str()); } @@ -108,7 +115,13 @@ MEDPresentationPointSprite::internalGeneratePipeline() // Make the radius twice the default radius oss << _dispVar << ".GaussianRadius = 2*" << _dispVar << ".GaussianRadius" << ";"; + oss <<"__gr = "<< _dispVar << ".GaussianRadius"; pushAndExecPyLine(oss.str()); oss.str(""); + + PyObject * obj = getPythonObjectFromMain("__gr"); + if (obj && PyFloat_Check(obj)) { + _gaussianRadius = PyFloat_AsDouble(obj); + } showScalarBar(); selectColorMap(); @@ -131,8 +144,43 @@ MEDPresentationPointSprite::updatePipeline(const MEDCALC::PointSpriteParameters& scaleBallRadius(); pushAndExecPyLine("pvs.Render();"); } - if (params.scalarBarRange != _params.scalarBarRange) - updateScalarBarRange(params.scalarBarRange); + if (params.scalarBarRange != _params.scalarBarRange || + params.hideDataOutsideCustomRange != _params.hideDataOutsideCustomRange || + params.scalarBarRangeArray[0] != _params.scalarBarRangeArray[0] || + params.scalarBarRangeArray[1] != _params.scalarBarRangeArray[1]) + updateScalarBarRange(params.scalarBarRange, + params.hideDataOutsideCustomRange, + params.scalarBarRangeArray[0], + params.scalarBarRangeArray[1]); if (params.colorMap != _params.colorMap) updateColorMap(params.colorMap); + if (params.visibility != _params.visibility) + updateVisibility(params.visibility); + if (params.scalarBarVisibility != _params.scalarBarVisibility) + updateScalarBarVisibility(params.scalarBarVisibility); +} + +std::string +MEDPresentationPointSprite::additionalThresholdVisualizationActions() { + if (_hideDataOutsideCustomRange) { + // Set point sprite: + std::ostringstream oss; + std::string aDispVar = getDispVar(); + oss << aDispVar << ".SetRepresentationType('Point Gaussian');"; + oss << aDispVar << ".ScaleByArray = 1;"; + oss << aDispVar << ".SetScaleArray = ['POINTS', '" << getThresholdFieldName() << "'];"; + oss << aDispVar << ".GaussianRadius = " << _gaussianRadius << ";"; + oss << aDispVar << ".ScaleTransferFunction.RescaleTransferFunction(" << _rangeVar << "[0], " << _rangeVar << "[1]);"; + return oss.str(); + } } + +void +MEDPresentationPointSprite::additionalThresholdActions() { + scaleBallRadius(); +} + +void +MEDPresentationPointSprite::additionalUnThresholdActions() { + scaleBallRadius(); +} \ No newline at end of file diff --git a/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx b/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx index c98c916f2..f2c5550ce 100644 --- a/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx +++ b/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx @@ -41,9 +41,13 @@ public: protected: virtual void internalGeneratePipeline(); void scaleBallRadius(); + void additionalThresholdActions() override; + std::string additionalThresholdVisualizationActions() override; + void additionalUnThresholdActions() override; private: MEDCALC::PointSpriteParameters _params; + double _gaussianRadius; }; #endif diff --git a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx index 5d3dcb0e7..2f969abb0 100644 --- a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx +++ b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx @@ -69,11 +69,22 @@ MEDPresentationScalarMap::updatePipeline(const MEDCALC::ScalarMapParameters& par if (params.fieldHandlerId != _params.fieldHandlerId) throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!"); - if (std::string(params.displayedComponent) != std::string(_params.displayedComponent)) - updateComponent(std::string(params.displayedComponent)); - if (params.scalarBarRange != _params.scalarBarRange) - updateScalarBarRange(params.scalarBarRange); if (params.colorMap != _params.colorMap) updateColorMap(params.colorMap); + + if (std::string(params.displayedComponent) != std::string(_params.displayedComponent)) + updateComponent(std::string(params.displayedComponent)); + if (params.scalarBarRange != _params.scalarBarRange || + params.hideDataOutsideCustomRange != _params.hideDataOutsideCustomRange || + params.scalarBarRangeArray[0] != _params.scalarBarRangeArray[0] || + params.scalarBarRangeArray[1] != _params.scalarBarRangeArray[1] ) + updateScalarBarRange(params.scalarBarRange, + params.hideDataOutsideCustomRange, + params.scalarBarRangeArray[0], + params.scalarBarRangeArray[1]); + if (params.visibility != _params.visibility) + updateVisibility(params.visibility); + if (params.scalarBarVisibility != _params.scalarBarVisibility) + updateScalarBarVisibility(params.scalarBarVisibility); } diff --git a/src/MEDCalc/cmp/MEDPresentationSlices.cxx b/src/MEDCalc/cmp/MEDPresentationSlices.cxx index 773beaace..4d248f7cd 100644 --- a/src/MEDCalc/cmp/MEDPresentationSlices.cxx +++ b/src/MEDCalc/cmp/MEDPresentationSlices.cxx @@ -65,8 +65,10 @@ MEDPresentationSlices::setSliceParametersAndGroup() void MEDPresentationSlices::deleteGroup() { + deleteThresholds(); std::ostringstream oss; - oss << "pvs.Delete(" << _objVar << ");"; + oss << "pvs.Hide(" << _objVar << ");"; + oss << "pvs.Delete(" << _objVar << ");del " <<_objVar<<";"; pushAndExecPyLine(oss.str()); oss.str(""); } @@ -76,11 +78,11 @@ MEDPresentationSlices::adaptNumberOfSlices() std::ostringstream oss; int nbSlices = getIntProperty(MEDPresentationSlices::PROP_NB_SLICES); - oss << "for _ in range(max(len(" << _sliceListVar << ")-" << nbSlices << ", 0)):\n"; + oss << "for _ in range(int(max(len(" << _sliceListVar << ")-" << nbSlices << ", 0))):\n"; oss << " pvs.Delete(" << _sliceListVar << ".pop());\n"; pushAndExecPyLine(oss.str()); oss.str(""); - oss << "for _ in range(" << nbSlices << "-max(len(" << _sliceListVar << "), 0)):\n"; + oss << "for _ in range(" << nbSlices << "-int(max(len(" << _sliceListVar << "), 0))):\n"; oss << " obj = pvs.Slice(Input=" << _srcObjVar << ");\n"; oss << " obj.SliceType = 'Plane';\n"; oss << " " << _sliceListVar << ".append(obj);\n"; @@ -92,7 +94,6 @@ MEDPresentationSlices::generateAndDisplay() { adaptNumberOfSlices(); setSliceParametersAndGroup(); - recreateViewSetup(); } @@ -169,8 +170,14 @@ MEDPresentationSlices::updatePipeline(const MEDCALC::SlicesParameters& params) if (std::string(params.displayedComponent) != std::string(_params.displayedComponent)) updateComponent(std::string(params.displayedComponent)); - if (params.scalarBarRange != _params.scalarBarRange) - updateScalarBarRange(params.scalarBarRange); + if (params.scalarBarRange != _params.scalarBarRange || + params.hideDataOutsideCustomRange != _params.hideDataOutsideCustomRange || + params.scalarBarRangeArray[0] != _params.scalarBarRangeArray[0] || + params.scalarBarRangeArray[1] != _params.scalarBarRangeArray[1]) + updateScalarBarRange(params.scalarBarRange, + params.hideDataOutsideCustomRange, + params.scalarBarRangeArray[0], + params.scalarBarRangeArray[1]); if (params.colorMap != _params.colorMap) updateColorMap(params.colorMap); @@ -186,6 +193,11 @@ MEDPresentationSlices::updatePipeline(const MEDCALC::SlicesParameters& params) } updateNbSlices(params.nbSlices); } + if (params.visibility != _params.visibility) + updateVisibility(params.visibility); + + if (params.scalarBarVisibility != _params.scalarBarVisibility) + updateScalarBarVisibility(params.scalarBarVisibility); } void diff --git a/src/MEDCalc/cmp/MEDPresentationStreamLines.cxx b/src/MEDCalc/cmp/MEDPresentationStreamLines.cxx new file mode 100644 index 000000000..f76562b90 --- /dev/null +++ b/src/MEDCalc/cmp/MEDPresentationStreamLines.cxx @@ -0,0 +1,231 @@ +// Copyright (C) 2016-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDPyLockWrapper.hxx" + +#include "MEDPresentationStreamLines.hxx" +#include "MEDPresentationException.hxx" + +#include +#undef LOG // should be fixed in KERNEL - double definition +#include + +#include + +const std::string MEDPresentationStreamLines::TYPE_NAME = "MEDPresentationStreamLines"; +const std::string MEDPresentationStreamLines::PROP_INTEGR_DIR_TYPE = "intDirType"; + +MEDPresentationStreamLines::MEDPresentationStreamLines(const MEDCALC::StreamLinesParameters& params, + const MEDCALC::ViewModeType viewMode) : + MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), + _params(params) +{ + setIntProperty(MEDPresentationStreamLines::PROP_INTEGR_DIR_TYPE, params.integrDir); +} + +std::string +MEDPresentationStreamLines::getIntegrDirType() const +{ + switch(_params.integrDir) + { + case MEDCALC::INTEGRATION_DIR_BOTH: + return "BOTH"; + case MEDCALC::INTEGRATION_DIR_FORWARD: + return "FORWARD"; + case MEDCALC::INTEGRATION_DIR_BACKWARD: + return "BACKWARD"; + default: + const char * mes = "Unexpected getIntegrDirType() error!"; + STDLOG(mes); + throw KERNEL::createSalomeException(mes); + } + return ""; // never happens +} + +void +MEDPresentationStreamLines::addThirdZeroComponent() +{ + std::ostringstream oss; + + oss << _objStreamCalc << " = pvs.Calculator(Input=" << _objStreamCalc << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + std::string typ = "Point Data"; // Because CellDatatoPointData filter has been applied erlier + oss << _objStreamCalc << ".AttributeType = '" << typ << "';"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _objStreamCalc << ".ResultArrayName = '" << _fieldName << "_CALC';"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _objStreamCalc << ".Function = '" << _fieldName << "_X*iHat + " << _fieldName << "_Y*jHat + 0.0*kHat';"; + pushAndExecPyLine(oss.str()); oss.str(""); + /* + oss << _dispVar << " = pvs.Show(" << _objStreamCalc << ", " << getRenderViewVar() << ");"; + oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "', " << _dispVar << ", separate=True);"; + execPyLine(oss.str()); oss.str(""); + oss << "pvs.ColorBy(" << getDispVar() << ", ('" << "POINTS" << "', '" << _fieldName << "_CALC'), separate=True);"; + execPyLine(oss.str()); oss.str(""); + oss << "pvs.Hide(" << _objStreamCalc << ", " << getRenderViewVar() << ");"; + execPyLine(oss.str()); oss.str(""); + */ +} + +void +MEDPresentationStreamLines::internalGeneratePipeline() +{ + MEDPresentation::internalGeneratePipeline(); + + MEDPyLockWrapper lock; + + createSource(); + setTimestamp(); + + fillAvailableFieldComponents(); + int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS); + if (nbCompo <= 1) + { + const char * msg = "Stream Lines field presentation does not work for scalar field!"; + STDLOG(msg); + throw KERNEL::createSalomeException(msg); + } + + setOrCreateRenderView(); + + std::ostringstream oss; + if (_pvFieldType == "CELLS") + { + oss << "__objStreamCalc"; + _objStreamCalc = oss.str(); oss.str(""); + oss << _objStreamCalc << " = pvs.CellDatatoPointData(" << _srcObjVar << ");"; + oss << _objStreamCalc << ".PassCellData = 1;"; + pushAndExecPyLine(oss.str()); oss.str(""); + } + else + { + oss << "__objStreamCalc"; + _objStreamCalc = oss.str(); oss.str(""); + oss << _objStreamCalc << "=" << _srcObjVar; + pushAndExecPyLine(oss.str()); oss.str(""); + } + + if (_nbComponents == 2) + addThirdZeroComponent(); + + std::string dirType = getIntegrDirType(); + + oss.str(""); + oss << _objVar << " = " << _objStreamCalc << ";"; + oss << _objVar << ".UpdatePipeline();"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _objVar << " = pvs.StreamTracer(Input=" << _objVar << ", SeedType='Point Cloud' if pvs.GetParaViewVersion().GetVersion() > 5.8 else 'Point Source');"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _objVar << ".IntegrationDirection = '" << dirType << "';"; + pushAndExecPyLine(oss.str()); oss.str(""); + + showObject(); + + oss << "pvs.ColorBy(" << getDispVar() << ", ('" << "POINTS" << "', '" << getFieldName() << "'), separate=True);"; + pushAndExecPyLine(oss.str()); oss.str(""); + + showScalarBar(); + selectColorMap(); + rescaleTransferFunction(); + scalarBarTitle(); + resetCameraAndRender(); +} + +void +MEDPresentationStreamLines::updatePipeline(const MEDCALC::StreamLinesParameters& params) +{ + if (params.fieldHandlerId != _params.fieldHandlerId) + throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!"); + + if (params.colorMap != _params.colorMap) + updateColorMap(params.colorMap); + + if (params.scalarBarRange != _params.scalarBarRange || + params.hideDataOutsideCustomRange != _params.hideDataOutsideCustomRange || + params.scalarBarRangeArray[0] != _params.scalarBarRangeArray[0] || + params.scalarBarRangeArray[1] != _params.scalarBarRangeArray[1]) + updateScalarBarRange(params.scalarBarRange, + params.hideDataOutsideCustomRange, + params.scalarBarRangeArray[0], + params.scalarBarRangeArray[1]); + + if (params.integrDir != _params.integrDir) + updateIntegrDir(params.integrDir); + + if (params.visibility != _params.visibility) + updateVisibility(params.visibility); + if (params.scalarBarVisibility != _params.scalarBarVisibility) + updateScalarBarVisibility(params.scalarBarVisibility); +} + +void +MEDPresentationStreamLines::updateIntegrDir(const MEDCALC::IntegrationDirType integrDir) +{ + _params.integrDir = integrDir; + + // GUI helper: + setIntProperty(MEDPresentationStreamLines::PROP_INTEGR_DIR_TYPE, integrDir); + + // Update the pipeline: + { + MEDPyLockWrapper lock; + std::ostringstream oss; + std::string dirType = getIntegrDirType(); + oss << _objVar << ".IntegrationDirection = '" << dirType << "'"; + pushAndExecPyLine(oss.str()); oss.str(""); + pushAndExecPyLine("pvs.Render();"); + } +} + +void +MEDPresentationStreamLines::initFieldMeshInfos() +{ + MEDPresentation::initFieldMeshInfos(); + _colorByType = "POINTS"; +} + +std::string MEDPresentationStreamLines::additionalThresholdInitializationActions() { + if (_hideDataOutsideCustomRange) { + std::ostringstream oss; + ComponentThresold& currentThreshold = _presentationThresolds[getThresholdIndex()]; + oss << currentThreshold._thresholdVar << ".AllScalars = 0;"; + return oss.str(); + } + return ""; +} + +std::string MEDPresentationStreamLines::getFieldName() const { + std::ostringstream oss; + oss << _fieldName; + if (_nbComponents == 2) { + oss << "_CALC"; + } + return oss.str(); +} + +void +MEDPresentationStreamLines::scalarBarTitle() +{ + if (_nbComponents == 2 && !_hideDataOutsideCustomRange) { + std::ostringstream oss; + oss << "pvs.GetScalarBar(" << getLutVar() << ").Title = '" << _fieldName << "';"; + pushAndExecPyLine(oss.str()); + } + MEDPresentation::scalarBarTitle(); +} \ No newline at end of file diff --git a/src/MEDCalc/cmp/MEDPresentationStreamLines.hxx b/src/MEDCalc/cmp/MEDPresentationStreamLines.hxx new file mode 100644 index 000000000..775626d6b --- /dev/null +++ b/src/MEDCalc/cmp/MEDPresentationStreamLines.hxx @@ -0,0 +1,58 @@ +// Copyright (C) 2016-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef SRC_MEDCALC_CMP_MEDPRESENTATION_STREAM_LINES_HXX_ +#define SRC_MEDCALC_CMP_MEDPRESENTATION_STREAM_LINES_HXX_ + +#include "MEDCALC.hxx" +#include "MEDPresentation.hxx" +#include + +class MEDCALC_EXPORT MEDPresentationStreamLines : public MEDPresentation +{ +public: + static const std::string TYPE_NAME; + static const std::string PROP_INTEGR_DIR_TYPE; + + MEDPresentationStreamLines(const MEDCALC::StreamLinesParameters& params, const MEDCALC::ViewModeType viewMode); + virtual ~MEDPresentationStreamLines() {} + + void updatePipeline(const MEDCALC::StreamLinesParameters& params); + + void getParameters(MEDCALC::StreamLinesParameters & params) const { params = _params; } ; + void setParameters(const MEDCALC::StreamLinesParameters & params) { _params = params; } ; + + void initFieldMeshInfos() override; + +protected: + void updateIntegrDir(const MEDCALC::IntegrationDirType mode); + virtual void internalGeneratePipeline(); + std::string additionalThresholdInitializationActions() override; + std::string getFieldName() const override; + void scalarBarTitle() override; + + +private: + std::string getIntegrDirType() const; + std::string _objStreamCalc; + void addThirdZeroComponent(); + MEDCALC::StreamLinesParameters _params; +}; + +#endif \ No newline at end of file diff --git a/src/MEDCalc/cmp/MEDPresentationVectorField.cxx b/src/MEDCalc/cmp/MEDPresentationVectorField.cxx index 8f916ef47..86b6488ac 100644 --- a/src/MEDCalc/cmp/MEDPresentationVectorField.cxx +++ b/src/MEDCalc/cmp/MEDPresentationVectorField.cxx @@ -29,11 +29,15 @@ #include const std::string MEDPresentationVectorField::TYPE_NAME = "MEDPresentationVectorField"; +const std::string MEDPresentationVectorField::PROP_SCALE_FACTOR = "scaleFactor"; +const std::string MEDPresentationVectorField::PROP_CUSTOM_SCALE_FACTOR = "customScaleFactor"; MEDPresentationVectorField::MEDPresentationVectorField(const MEDCALC::VectorFieldParameters& params, const MEDCALC::ViewModeType viewMode) : MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), _params(params) { + setDoubleProperty(MEDPresentationVectorField::PROP_SCALE_FACTOR, params.scaleFactor); + setIntProperty(MEDPresentationVectorField::PROP_CUSTOM_SCALE_FACTOR, params.customScaleFactor); } void @@ -47,11 +51,16 @@ void MEDPresentationVectorField::autoScale() { std::ostringstream oss; -// oss << "import medcalc;"; -// pushAndExecPyLine(oss.str()); oss.str(""); - oss << _objVar << ".ScaleFactor = 2.0*medcalc.ComputeCellAverageSize(" << _srcObjVar << ")/(" << _rangeVar + oss << "__autoScaleF = 2.0*medcalc.ComputeCellAverageSize(" << _srcObjVar << ")/(" << _rangeVar << "[1]-" << _rangeVar << "[0]);"; - pushAndExecPyLine(oss.str()); oss.str(""); + MEDPyLockWrapper lock; + execPyLine(oss.str()); + PyObject * obj = getPythonObjectFromMain("__autoScaleF"); + if (obj && PyFloat_Check(obj)) { + _params.scaleFactor = PyFloat_AsDouble(obj); + setDoubleProperty(MEDPresentationVectorField::PROP_SCALE_FACTOR, _params.scaleFactor); + } + } void @@ -102,7 +111,7 @@ MEDPresentationVectorField::internalGeneratePipeline() selectColorMap(); rescaleTransferFunction(); - autoScale(); // to be called after transfer function so we have the range + scale(); // to be called after transfer function so we have the range resetCameraAndRender(); } @@ -113,12 +122,58 @@ MEDPresentationVectorField::updatePipeline(const MEDCALC::VectorFieldParameters& if (params.fieldHandlerId != _params.fieldHandlerId) throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!"); - if (params.scalarBarRange != _params.scalarBarRange) + if (params.scalarBarRange != _params.scalarBarRange || + params.hideDataOutsideCustomRange != _params.hideDataOutsideCustomRange || + params.scalarBarRangeArray[0] != _params.scalarBarRangeArray[0] || + params.scalarBarRangeArray[1] != _params.scalarBarRangeArray[1]) { - updateScalarBarRange(params.scalarBarRange); - autoScale(); + updateScalarBarRange(params.scalarBarRange, + params.hideDataOutsideCustomRange, + params.scalarBarRangeArray[0], + params.scalarBarRangeArray[1]); + scale(); pushAndExecPyLine("pvs.Render();"); } + if (params.scaleFactor != _params.scaleFactor || + params.customScaleFactor != _params.customScaleFactor) { + updateScaleFactor(params.scaleFactor, params.customScaleFactor); + } + if (params.colorMap != _params.colorMap) updateColorMap(params.colorMap); + + if (params.visibility != _params.visibility) + updateVisibility(params.visibility); + + if (params.scalarBarVisibility != _params.scalarBarVisibility) + updateScalarBarVisibility(params.scalarBarVisibility); + +} + +void +MEDPresentationVectorField::updateScaleFactor(const double scaleFactor, const bool customScaleFactor) +{ + if (customScaleFactor) { + _params.scaleFactor = scaleFactor; + setDoubleProperty(MEDPresentationVectorField::PROP_SCALE_FACTOR, _params.scaleFactor); + } + + _params.customScaleFactor = customScaleFactor; + + setIntProperty(MEDPresentationVectorField::PROP_CUSTOM_SCALE_FACTOR, _params.customScaleFactor); + scale(); +} + +void +MEDPresentationVectorField::scale() +{ + if (!_params.customScaleFactor) { + autoScale(); + } + // Update Scale Factor + MEDPyLockWrapper lock; + std::ostringstream oss; + oss << _objVar << ".ScaleFactor = " << _params.scaleFactor << ";"; + pushAndExecPyLine(oss.str()); oss.str(""); + pushAndExecPyLine("pvs.Render();"); } diff --git a/src/MEDCalc/cmp/MEDPresentationVectorField.hxx b/src/MEDCalc/cmp/MEDPresentationVectorField.hxx index d8bd68930..eba828715 100644 --- a/src/MEDCalc/cmp/MEDPresentationVectorField.hxx +++ b/src/MEDCalc/cmp/MEDPresentationVectorField.hxx @@ -27,6 +27,8 @@ class MEDCALC_EXPORT MEDPresentationVectorField : public MEDPresentation { public: static const std::string TYPE_NAME; + static const std::string PROP_SCALE_FACTOR; + static const std::string PROP_CUSTOM_SCALE_FACTOR; MEDPresentationVectorField(const MEDCALC::VectorFieldParameters& params, const MEDCALC::ViewModeType viewMode); virtual ~MEDPresentationVectorField() {} @@ -40,8 +42,9 @@ public: protected: virtual void internalGeneratePipeline(); + void updateScaleFactor(const double, const bool); void autoScale(); - + void scale(); private: MEDCALC::VectorFieldParameters _params; diff --git a/src/MEDCalc/gui/CMakeLists.txt b/src/MEDCalc/gui/CMakeLists.txt index 860dacd2a..ba372d93f 100644 --- a/src/MEDCalc/gui/CMakeLists.txt +++ b/src/MEDCalc/gui/CMakeLists.txt @@ -46,13 +46,18 @@ SET(MEDCALCGUI_SOURCES MEDWidgetHelperComponent.cxx MEDWidgetHelperContour.cxx MEDWidgetHelperSlices.cxx + MEDWidgetHelperPlot3D.cxx + MEDWidgetHelperStreamLines.cxx + MEDWidgetHelperCutSegment.cxx + MEDWidgetHelperVectorField.cxx + MEDCALCGUI_Displayer.cxx ) IF(SALOME_FIELDS_WITH_QTTESTING) LIST(APPEND MEDCALCGUI_SOURCES TestController.cxx) ENDIF() -SET(MEDCALCGUI_HEADERS +SET(MEDCALCGUI_MOC_HEADERS MEDModule.hxx MEDEventListener_i.hxx WorkspaceController.hxx @@ -66,15 +71,22 @@ SET(MEDCALCGUI_HEADERS MEDWidgetHelperContour.hxx MEDWidgetHelperSlices.hxx MEDWidgetHelperPointSprite.hxx + MEDWidgetHelperPlot3D.hxx + MEDWidgetHelperStreamLines.hxx + MEDWidgetHelperCutSegment.hxx MEDWidgetHelperVectorField.hxx MEDWidgetHelperDeflectionShape.hxx ) + +SET(MEDCALCGUI_HEADERS + MEDCALCGUI_Displayer.hxx + ) IF(SALOME_FIELDS_WITH_QTTESTING) - LIST(APPEND MEDCALCGUI_HEADERS TestController.hxx) + LIST(APPEND MEDCALCGUI_MOC_HEADERS TestController.hxx) ENDIF() -QT_WRAP_MOC(MEDCALCGUI_HEADERS_MOC ${MEDCALCGUI_HEADERS}) +QT_WRAP_MOC(MEDCALCGUI_HEADERS_MOC ${MEDCALCGUI_MOC_HEADERS}) INCLUDE_DIRECTORIES( ${OMNIORB_INCLUDE_DIR} ${OMNIORB_INCLUDE_DIRS} diff --git a/src/MEDCalc/gui/FIELDS_images.ts b/src/MEDCalc/gui/FIELDS_images.ts index bc019e499..9dcc8aa4e 100644 --- a/src/MEDCalc/gui/FIELDS_images.ts +++ b/src/MEDCalc/gui/FIELDS_images.ts @@ -96,6 +96,18 @@ ICO_PRESENTATION_POINT_SPRITE_DEFAULT pqNodeMapData24.png + + ICO_PRESENTATION_PLOT3D_DEFAULT + pqPlot24.png + + + ICO_PRESENTATION_STREAM_LINES_DEFAULT + pqStreamTracer24.png + + + ICO_PRESENTATION_CUT_SEGMENT_DEFAULT + pqPlotOverLine24.png + ICO_MEDPresentationMeshView_DEFAULT @@ -125,6 +137,18 @@ ICO_MEDPresentationPointSprite_DEFAULT pqNodeMapData16.png + + ICO_MEDPresentationPlot3D_DEFAULT + pqPlot16.png + + + ICO_MEDPresentationStreamLines_DEFAULT + pqStreamTracer16.png + + + ICO_MEDPresentationCutSegment_DEFAULT + pqPlotOverLine16.png + ICO_PRESENTATION_MESH_VIEW_MODERN @@ -154,6 +178,18 @@ ICO_PRESENTATION_POINT_SPRITE_MODERN pqNodeMapData24.png + + ICO_PRESENTATION_PLOT3D_MODERN + pqPlot24.png + + + ICO_PRESENTATION_STREAM_LINES_MODERN + pqStreamTracer24.png + + + ICO_PRESENTATION_CUT_SEGMENT_MODERN + pqPlotOverLine24.png + ICO_MEDPresentationMeshView_MODERN @@ -183,6 +219,18 @@ ICO_MEDPresentationPointSprite_MODERN pqNodeMapData16.png + + ICO_MEDPresentationPlot3D_MODERN + pqPlot16.png + + + ICO_MEDPresentationStreamLines_MODERN + pqStreamTracer16.png + + + ICO_MEDPresentationCutSegment_MODERN + pqPlotOverLine16.png + ICO_PRESENTATION_MESH_VIEW_CLASSIC @@ -212,6 +260,18 @@ ICO_PRESENTATION_POINT_SPRITE_CLASSIC visu_points24.png + + ICO_PRESENTATION_PLOT3D_CLASSIC + visu_plot3d24.png + + + ICO_PRESENTATION_STREAM_LINES_CLASSIC + visu_streamlines24.png + + + ICO_PRESENTATION_CUT_SEGMENT_CLASSIC + visu_cutsegment24.png + ICO_MEDPresentationMeshView_CLASSIC @@ -241,6 +301,18 @@ ICO_MEDPresentationPointSprite_CLASSIC visu_points16.png + + ICO_MEDPresentationPlot3D_CLASSIC + visu_plot3d16.png + + + ICO_MEDPresentationStreamLines_CLASSIC + visu_streamlines16.png + + + ICO_MEDPresentationCutSegment_CLASSIC + visu_cutsegment16.png + ICO_DELETE_PRESENTATION close.png diff --git a/src/MEDCalc/gui/FIELDS_msg_en.ts b/src/MEDCalc/gui/FIELDS_msg_en.ts index 9977871d0..9a26ef00e 100644 --- a/src/MEDCalc/gui/FIELDS_msg_en.ts +++ b/src/MEDCalc/gui/FIELDS_msg_en.ts @@ -63,6 +63,30 @@ TIP_PRESENTATION_POINT_SPRITE Point sprite + + LAB_PRESENTATION_PLOT3D + Plot3D + + + TIP_PRESENTATION_PLOT3D + Plot3D + + + LAB_PRESENTATION_STREAM_LINES + Stream Lines + + + TIP_PRESENTATION_STREAM_LINES + Stream Lines + + + LAB_PRESENTATION_CUT_SEGMENT + Cut Segment + + + TIP_PRESENTATION_CUT_SEGMENT + Cut Segment + LAB_DELETE_PRESENTATION Delete presentation @@ -111,6 +135,18 @@ MEDPresentationPointSprite Point sprite + + MEDPresentationPlot3D + Plot3D + + + MEDPresentationStreamLines + Stream Lines + + + MEDPresentationCutSegment + Cut Segment + ProcessingController @@ -207,6 +243,18 @@ LAB_RANGE Range: + + LAB_SHOW_SCALAR_BAR + Show Scalar Bar + + + LAB_CUSTOM_RANGE + Custom Range: + + + LAB_HIDE_DATA_OUTSIDE_CR + Hide Data outside Custom Range + LAB_ALL_TIMESTEPS All timesteps @@ -247,10 +295,26 @@ LAB_MESH_SURF_EDGES Surface With Edges + + LAB_INTEGR_DIR_BOTH + BOTH + + + LAB_INTEGR_DIR_FORWARD + FORWARD + + + LAB_INTEGR_DIR_BACKWARD + BACKWARD + LAB_DISP_MESH_MODE Mesh display: + + LAB_INTEGR_DIR + Integration Direction: + LAB_NB_CONTOURS Number of contours (max. %1): @@ -303,6 +367,30 @@ LAB_COOL_TO_WARM Cool to warm + + LAB_CUT_PLANE_NORMAL + Plane Normal: + + + LAB_CUT_PLANE_POS + Cutting Plane Position: + + + LAB_CUT_POINT1 + Point 1: + + + LAB_CUT_POINT2 + Point 2: + + + LAB_CONTOUR_COMP + Contour By: + + + LAB_SCALE_FACTOR + Scale Factor + DlgAlias diff --git a/src/MEDCalc/gui/FIELDS_msg_fr.ts b/src/MEDCalc/gui/FIELDS_msg_fr.ts index 7a9d00b96..449b294e1 100644 --- a/src/MEDCalc/gui/FIELDS_msg_fr.ts +++ b/src/MEDCalc/gui/FIELDS_msg_fr.ts @@ -63,6 +63,30 @@ TIP_PRESENTATION_POINT_SPRITE Point sprite + + LAB_PRESENTATION_PLOT3D + Plot3D + + + TIP_PRESENTATION_PLOT3D + Plot3D + + + LAB_PRESENTATION_STREAM_LINES + Les Lignes DÉcoulement + + + TIP_PRESENTATION_STREAM_LINES + Les Lignes DÉcoulement + + + LAB_PRESENTATION_CUT_SEGMENT + Couper Des Segment + + + TIP_PRESENTATION_CUT_SEGMENT + Couper Des Segment + LAB_DELETE_PRESENTATION Supprimer @@ -111,6 +135,18 @@ MEDPresentationPointSprite Point sprite + + MEDPresentationPlot3D + Plot3D + + + MEDPresentationStreamLines + Les Lignes DeÉcoulement + + + MEDPresentationCutSegment + Couper Des Segment + ProcessingController @@ -207,6 +243,18 @@ LAB_RANGE Intervalle : + + LAB_SHOW_SCALAR_BAR + Afficher la barre scalaire + + + LAB_CUSTOM_RANGE + Gamme personnalisée: + + + LAB_HIDE_DATA_OUTSIDE_CR + Masquer les données en dehors de la plage personnalisée + LAB_ALL_TIMESTEPS Tous les pas de temps @@ -247,10 +295,26 @@ LAB_MESH_SURF_EDGES Surface Avec Arrêtes + + LAB_INTEGR_DIR_BOTH + Les DEUX + + + LAB_INTEGR_DIR_FORWARD + TRANSMETTRE + + + LAB_INTEGR_DIR_BACKWARD + ARRIÉRÉ + LAB_DISP_MESH_MODE Affichage du maillage: + + LAB_INTEGR_DIR + Intégration De Direction: + LAB_NB_CONTOURS Nombre de contours (max. %1) : @@ -303,6 +367,26 @@ LAB_COOL_TO_WARM Froid vers chaud + + LAB_CUT_PLANE_NORMAL + Plan Normal: + + + LAB_CUT_PLANE_POS + Position Du Plan De Coupe: + + + LAB_CUT_POINT1 + Point 1: + + + LAB_CUT_POINT2 + Point 2: + + + LAB_SCALE_FACTOR + Facteur Déchelle + DlgAlias diff --git a/src/MEDCalc/gui/FIELDS_msg_ja.ts b/src/MEDCalc/gui/FIELDS_msg_ja.ts index b494e145a..0ece69784 100644 --- a/src/MEDCalc/gui/FIELDS_msg_ja.ts +++ b/src/MEDCalc/gui/FIELDS_msg_ja.ts @@ -63,6 +63,30 @@ TIP_PRESENTATION_POINT_SPRITE 点スプライト + + LAB_PRESENTATION_PLOT3D + プロット3D + + + TIP_PRESENTATION_PLOT3D + プロット3D + + + LAB_PRESENTATION_STREAM_LINES + ストリーム線 + + + TIP_PRESENTATION_STREAM_LINES + ストリーム線 + + + LAB_PRESENTATION_CUT_SEGMENT + カット部分 + + + TIP_PRESENTATION_CUT_SEGMENT + カット部分 + LAB_DELETE_PRESENTATION プレゼンテーションの削除 @@ -111,6 +135,18 @@ MEDPresentationPointSprite 点スプライト描画 + + MEDPresentationPlot3D + プロット3D + + + MEDPresentationStreamLines + ストリーム線 + + + MEDPresentationCutSegment + カットセグ + ProcessingController @@ -247,10 +283,26 @@ LAB_MESH_SURF_EDGES エッジを持った表面 + + LAB_INTEGR_DIR_BOTH + どちらも + + + LAB_INTEGR_DIR_FORWARD + フォワード + + + LAB_INTEGR_DIR_BACKWARD + 後ろ向き + LAB_DISP_MESH_MODE メッシュ表示: + + LAB_INTEGR_DIR + 統合の方向: + LAB_NB_CONTOURS コンタ数 (max. %1): @@ -303,6 +355,26 @@ LAB_COOL_TO_WARM 冷却から温め + + LAB_CUT_PLANE_NORMAL + 平面ノーマル: + + + LAB_CUT_PLANE_POS + 切断の平面の位置: + + + LAB_CUT_POINT1 + ポイント 1: + + + LAB_CUT_POINT2 + ポイント 2: + + + LAB_SCALE_FACTOR + スケール係数 + DlgAlias diff --git a/src/MEDCalc/gui/MEDCALCGUI_Displayer.cxx b/src/MEDCalc/gui/MEDCALCGUI_Displayer.cxx new file mode 100644 index 000000000..b2951c987 --- /dev/null +++ b/src/MEDCalc/gui/MEDCALCGUI_Displayer.cxx @@ -0,0 +1,134 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : MEDCALCGUI_Displayer.cxx +// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) + +// Local includes +#include "PresentationController.hxx" +#include "MEDCALCGUI_Displayer.hxx" +#include +#include + +// KERNEL includes +#include +#include +#include CORBA_CLIENT_HEADER(SALOMEDS_Attributes) +#include + +// GUI includes +#include + + +MEDCALCGUI_Displayer::MEDCALCGUI_Displayer(PresentationController* presentationController): + LightApp_Displayer(), + _presentationController(presentationController) +{ +} +MEDCALCGUI_Displayer::~MEDCALCGUI_Displayer() +{ + _presentationController = nullptr; +} + +void MEDCALCGUI_Displayer::Display(const QStringList& list, const bool /*val*/, SALOME_View* /*theView*/) +{ + STDLOG("MEDCALCGUI_Displayer::Display"); + changeVisibility(list, true); +} + +void MEDCALCGUI_Displayer::Erase(const QStringList& list, const bool forced, const bool updateViewer, SALOME_View* theView) { + STDLOG( "MEDCALCGUI_Displayer::Erase" ); + changeVisibility(list, false); +} + +bool MEDCALCGUI_Displayer::canBeDisplayed(const QString& entry, const QString& viewer_type) const { + bool result = false; + if (viewer_type != PVViewer_Viewer::Type()) + return result; + MEDCALC::PresentationVisibility aState = visibilityState(entry); + result = (aState != MEDCALC::PRESENTATION_NOT_IN_VIEW); + STDLOG("MEDCALCGUI_Displayer::canBeDisplayed result is " << entry.toUtf8().constData() << " = " << result); + return result; +} + +bool MEDCALCGUI_Displayer::IsDisplayed(const QString& entry, SALOME_View* /*view*/) const +{ + return (visibilityState(entry) == MEDCALC::PRESENTATION_VISIBLE); +} + +void MEDCALCGUI_Displayer::changeVisibility(const QStringList& list, const bool visible) +{ + SALOMEDS::Study_var aStudy = KERNEL::getStudyServant(); + if (aStudy->_is_nil()) + return; + QStringList::const_iterator it = list.constBegin(); + for (; it != list.constEnd(); ++it) + { + QString entry = *it; + SALOMEDS::SObject_var sobject = aStudy->FindObjectID(entry.toUtf8().constData()); + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::AttributeParameter_var aParam; + if (sobject->FindAttribute(anAttr, "AttributeParameter")) { + aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); + if (!aParam->_is_nil() && aParam->IsSet(PRESENTATION_ID, PT_INTEGER)) { + int presId = aParam->GetInt(PRESENTATION_ID); + if (aParam->IsSet(PRESENTATION_TYPE, PT_STRING)) { + std::string type = aParam->GetString(PRESENTATION_TYPE); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = visible ? + PresentationEvent::EVENT_DISPLAY_PRESENTATION : PresentationEvent::EVENT_ERASE_PRESENTATION; + event->presentationId = presId; + event->presentationType = PresentationController::presentationName2Type(type); + _presentationController->emitPresentationSignal(event); + } + } + } + } +} + +MEDCALC::PresentationVisibility +MEDCALCGUI_Displayer::visibilityState(const QString& entry) const +{ + MEDCALC::PresentationVisibility result = MEDCALC::PRESENTATION_NOT_IN_VIEW; + SALOMEDS::Study_var aStudy = KERNEL::getStudyServant(); + if (aStudy->_is_nil()) + return result; + + SALOMEDS::SObject_var sobject = aStudy->FindObjectID(entry.toUtf8().constData()); + if (!sobject->_is_nil()) { + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::AttributeParameter_var aParam; + if (sobject->FindAttribute(anAttr, "AttributeParameter")) { + aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); + if (!aParam->_is_nil() && aParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)) { + if (aParam->IsSet(PRESENTATION_ID, PT_INTEGER)) { + long prsId = aParam->GetInt(PRESENTATION_ID); + MEDCALC::MEDPresentationManager_var presentationManager = + MEDFactoryClient::getFactory()->getPresentationManager(); + result = presentationManager->stateInActiveView(prsId); + } + } + } + } + STDLOG("MEDCALCGUI_Displayer::state result is " << entry.toUtf8().constData() << " = " << result); + return result; +} \ No newline at end of file diff --git a/src/MEDCalc/gui/MEDCALCGUI_Displayer.hxx b/src/MEDCalc/gui/MEDCALCGUI_Displayer.hxx new file mode 100644 index 000000000..ff72c4e4a --- /dev/null +++ b/src/MEDCalc/gui/MEDCALCGUI_Displayer.hxx @@ -0,0 +1,58 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : MEDCALCGUI_Displayer.h +// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) +// +#ifndef MEDCALCGUI_DISPLAYER_H +#define MEDCALCGUI_DISPLAYER_H +#include +#include CORBA_CLIENT_HEADER(MEDPresentationManager) +#include + +#include "MEDCALCGUI.hxx" + +class PresentationController; + +class MEDCALCGUI_EXPORT MEDCALCGUI_Displayer : public LightApp_Displayer +{ + +public: + /* Constructor */ + MEDCALCGUI_Displayer(PresentationController* presentationController); + /* Destructor */ + virtual ~MEDCALCGUI_Displayer() override; + virtual void Display(const QStringList&, const bool = true, SALOME_View* = 0) override; + virtual void Erase(const QStringList&, const bool forced = false, const bool updateViewer = true, SALOME_View* = 0) override; + virtual bool canBeDisplayed( const QString& /*entry*/, const QString& /*viewer_type*/ ) const override; + virtual bool IsDisplayed(const QString& /*entry*/, SALOME_View* = 0) const override; + +private: + void changeVisibility(const QStringList& list, const bool visible); + MEDCALC::PresentationVisibility visibilityState(const QString& entry) const; + +private: + PresentationController* _presentationController; +}; + +#endif // MEDCALCGUI_DISPLAYER_H + diff --git a/src/MEDCalc/gui/MEDModule.cxx b/src/MEDCalc/gui/MEDModule.cxx index 8cd3b7540..8c2f40105 100644 --- a/src/MEDCalc/gui/MEDModule.cxx +++ b/src/MEDCalc/gui/MEDModule.cxx @@ -22,6 +22,7 @@ #include "MEDModule.hxx" #include "QtHelper.hxx" #include +#include "MEDCALCGUI_Displayer.hxx" #include "SALOME_LifeCycleCORBA.hxx" #include "QtxPopupMgr.h" @@ -35,6 +36,8 @@ #include #include #include +#include +#include #include #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes) @@ -55,6 +58,8 @@ #include #include #include +#include +#include //! The only instance of the reference to engine MED_ORB::MED_Gen_var MEDModule::_MED_engine; @@ -62,7 +67,9 @@ MED_ORB::MED_Gen_var MEDModule::_MED_engine; MEDModule::MEDModule() : SalomeApp_Module("FIELDS"), _studyEditor(0), _datasourceController(0), _workspaceController(0), _presentationController(0), - _processingController(0), _pvGuiElements(0) + _processingController(0), _pvGuiElements(0), + _displayer(nullptr), + _enableVisibilityStateUpdate(true) { STDLOG("MEDModule::MEDModule()"); // Note also that we can't use the getApp() function here because @@ -134,7 +141,9 @@ MEDModule::initialize( CAM_Application* app ) if (! getApp()->objectBrowser()) getApp()->getWindow(SalomeApp_Application::WT_ObjectBrowser); - getApp()->objectBrowser()->setAutoOpenLevel(5); + // rnv: #20430 [CEA 20428] FIELDS : improvement of simplified visualisations: + // Disable auto expanding + //getApp()->objectBrowser()->setAutoOpenLevel(5); if (app && app->desktop()) { connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)), @@ -258,6 +267,9 @@ MEDModule::activateModule( SUIT_Study* theStudy ) int av5 = ip->addAction(action(FIELDSOp::OpSlices) , gv); int av6 = ip->addAction(action(FIELDSOp::OpDeflectionShape) , gv); int av7 = ip->addAction(action(FIELDSOp::OpPointSprite) , gv); + int av8 = ip->addAction(action(FIELDSOp::OpPlot3D) , gv); + int av9 = ip->addAction(action(FIELDSOp::OpStreamLines) , gv); + int av10 = ip->addAction(action(FIELDSOp::OpCutSegment) , gv); // getting started interpolation int gi = ip->addGroup(tr("HELP_GRP_INTERPOLATION")); @@ -279,6 +291,10 @@ MEDModule::activateModule( SUIT_Study* theStudy ) // QTimer::singleShot(0, this, SLOT(onEventLoopStarted())); // return the activation status + + QObject::connect(&pqActiveObjects::instance(), SIGNAL(viewChanged(pqView*)), this, + SLOT(onViewChanged()), Qt::QueuedConnection); + return bOk; } @@ -341,6 +357,65 @@ MEDModule::createModuleWidgets() { connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)), _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*))); + + connect(&pqActiveObjects::instance(), &pqActiveObjects::viewChanged, [this](pqView* view) { this->updateVisibilityState(); }); + +} + + +void MEDModule::updateVisibilityState(const bool all, const QStringList& entries) +{ + if (!_enableVisibilityStateUpdate) { + return; + } + QStringList allPrsEntries = QStringList(); + const QStringList& workList = ( all ? allPrsEntries : entries ); + if (all) { + SALOMEDS::Study_var aStudy = KERNEL::getStudyServant(); + if (aStudy->_is_nil()) + return; + SALOMEDS::SComponent_var father = aStudy->FindComponent("FIELDS"); + if (father->_is_nil()) + return; + SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(father); + SALOMEDS::GenericAttribute_var anAttribute; + 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; + allPrsEntries.append(child->GetID()); + } + } + } + + // update visibility state of objects + LightApp_Application* app = dynamic_cast(SUIT_Session::session()->activeApplication()); + if (!app) + return; + SalomeApp_Study* appStudy = dynamic_cast(app->activeStudy()); + if (!appStudy) + return; + SUIT_Study* activeStudy = app->activeStudy(); + if (!activeStudy) + return; + SUIT_ViewWindow* aViewWindow = app->desktop()->activeWindow(); + if (!aViewWindow) + return; + SUIT_ViewManager* aViewManager = aViewWindow->getViewManager(); + if (!aViewManager) + return; + + SUIT_ViewModel * aViewModel = aViewManager->getViewModel(); + DataObjectList aList; + for(const auto& str : workList) { + aList.append(appStudy->findObjectByEntry(str)); + } + app->updateVisibilityState(aList, aViewModel); + } void @@ -569,3 +644,17 @@ MEDModule::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char* nam } return -1; } + +LightApp_Displayer* MEDModule::displayer() +{ + if (!_displayer) + _displayer = new MEDCALCGUI_Displayer(_presentationController); + return _displayer; +} + +void MEDModule::visibilityStateUpdateOff() { + _enableVisibilityStateUpdate = false; +} +void MEDModule::visibilityStateUpdateOn() { + _enableVisibilityStateUpdate = true; +} \ No newline at end of file diff --git a/src/MEDCalc/gui/MEDModule.hxx b/src/MEDCalc/gui/MEDModule.hxx index b8be201a1..e9263cce0 100644 --- a/src/MEDCalc/gui/MEDModule.hxx +++ b/src/MEDCalc/gui/MEDModule.hxx @@ -44,6 +44,7 @@ class SalomeApp_Application; class PVViewer_GUIElements; class MEDPresentationManager_i; +class LightApp_Displayer; /*! * This class defines the gui of the MED module. @@ -95,6 +96,13 @@ public: double getCurrentAnimationTimestamp(); + virtual LightApp_Displayer* displayer() override; + + void updateVisibilityState(const bool all=true, const QStringList& entries = QStringList()); + + void visibilityStateUpdateOff(); + void visibilityStateUpdateOn(); + signals: void presentationSelected(int presId, const QString& presType, const QString& presName); @@ -122,6 +130,10 @@ private: PVViewer_GUIElements* _pvGuiElements; static MED_ORB::MED_Gen_var _MED_engine; + + LightApp_Displayer* _displayer; + + bool _enableVisibilityStateUpdate; #ifdef MED_HAS_QTTESTING TestController * _testController; diff --git a/src/MEDCalc/gui/MEDWidgetHelper.cxx b/src/MEDCalc/gui/MEDWidgetHelper.cxx index 7e3e6062f..b01841bdb 100644 --- a/src/MEDCalc/gui/MEDWidgetHelper.cxx +++ b/src/MEDCalc/gui/MEDWidgetHelper.cxx @@ -51,6 +51,14 @@ void MEDWidgetHelper::loadParametersFromEngine() _presManager->getPresentationIntProperty(_presId, MEDPresentation::PROP_COLOR_MAP.c_str())); _scalarBarRange = static_cast( _presManager->getPresentationIntProperty(_presId, MEDPresentation::PROP_SCALAR_BAR_RANGE.c_str())); + + _scalarBarVisibility = static_cast( + _presManager->getPresentationIntProperty(_presId, MEDPresentation::PROP_SCALAR_BAR_VISIBILITY.c_str())); + + _scalarBarRangeArray[0] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentation::PROP_SCALAR_BAR_MIN_VALUE.c_str()); + _scalarBarRangeArray[1] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentation::PROP_SCALAR_BAR_MAX_VALUE.c_str()); + + _hideDataOutsideCustomRange = _presManager->getPresentationIntProperty(_presId, MEDPresentation::PROP_HIDE_DATA_OUTSIDE_CUSTOM_RANGE.c_str()); } void MEDWidgetHelper::updateWidget(bool connect) @@ -69,13 +77,23 @@ void MEDWidgetHelper::updateWidget(bool connect) STDLOG("MEDWidgetHelper::udpateWidget() scalarBarRange is " << _scalarBarRange); _paramWidget->setScalarBarRange(_scalarBarRange); + _paramWidget->setScalarBarVisibility(_scalarBarVisibility); + + _paramWidget->setScalarBarRangeValue(_scalarBarRangeArray[0], _scalarBarRangeArray[1]); + + _paramWidget->setHideDataOutsideCustomRange(_hideDataOutsideCustomRange); + if (connect) { QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)), _presController, SIGNAL(presentationSignal(const PresentationEvent *)) ); QObject::connect( _paramWidget, SIGNAL(comboScalarBarRangeIndexChanged(int)), this, SLOT(onScalarBarRangeChanged(int)) ); QObject::connect( _paramWidget, SIGNAL(comboColorMapIndexChanged(int)), this, SLOT(onColorMapChanged(int)) ); - } + QObject::connect( _paramWidget, SIGNAL(checkboxScalarBarVisibilityChanged(int)), this, SLOT(onScalarBarVisibilityChanged(int)) ); + QObject::connect( _paramWidget, SIGNAL(checkboxCustomRangeChanged(int)), this, SLOT(onUseCustomRangeChanged(int))); + QObject::connect( _paramWidget, SIGNAL(spinboxCustomRangeChanged(double, double)), this, SLOT(onCustomRangeValueChanged(double, double))); + QObject::connect( _paramWidget, SIGNAL(checkboxHideDataOutsideCustomRangeChanged(int)), this, SLOT(onHideDataOutsideCustomRangeChanged(int))); + } } void MEDWidgetHelper::releaseWidget() @@ -84,12 +102,28 @@ void MEDWidgetHelper::releaseWidget() _presController, SIGNAL(presentationSignal(const PresentationEvent *)) ); QObject::disconnect( _paramWidget, SIGNAL(comboScalarBarRangeIndexChanged(int)), this, SLOT(onScalarBarRangeChanged(int)) ); QObject::disconnect( _paramWidget, SIGNAL(comboColorMapIndexChanged(int)), this, SLOT(onColorMapChanged(int)) ); + QObject::disconnect( _paramWidget, SIGNAL(checkboxScalarBarVisibilityChanged(int)), this, SLOT(onScalarBarVisibilityChanged(int))); + QObject::disconnect( _paramWidget, SIGNAL(checkboxCustomRangeChanged(int)), this, SLOT(onUseCustomRangeChanged(int))); + QObject::disconnect( _paramWidget, SIGNAL(spinboxCustomRangeChanged(double, double)), this, SLOT(onCustomRangeChanged(double, double))); + QObject::disconnect( _paramWidget, SIGNAL(checkboxHideDataOutsideCustomRangeChanged(int)), this, SLOT(onHideDataOutsideCustomRangeChanged(int))); + + // Reset default for color map and scalar bar range _paramWidget->setColorMap(MEDCALC::COLOR_MAP_DEFAULT); _paramWidget->setScalarBarRange(MEDCALC::SCALAR_BAR_RANGE_DEFAULT); } +void MEDWidgetHelper::onScalarBarVisibilityChanged(int flag) { + STDLOG("MEDWidgetHelper::onScalarBarVisibilityChanged"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_SCALAR_BAR_VISIBILITY_CHANGED; + event->presentationId = _presId; + event->anInteger = flag; + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} + void MEDWidgetHelper::onComponentChanged(int idx) { STDLOG("MEDWidgetHelper::onComponentChanged"); @@ -126,3 +160,38 @@ void MEDWidgetHelper::onScalarBarRangeChanged(int idx) emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent } + +void MEDWidgetHelper::onUseCustomRangeChanged(int flag) { + STDLOG("MEDWidgetHelper::onUseCustomRangeChanged"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_CHANGE_TIME_RANGE; + event->presentationId = _presId; + event->anInteger = flag ? _paramWidget->getRangeComboBox()->count() : _paramWidget->getRangeComboBox()->currentIndex(); + event->aDouble1 = _paramWidget->getMixCustomRange(); + event->aDouble2 = _paramWidget->getMaxCustomRange(); + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} + +void MEDWidgetHelper::onCustomRangeValueChanged(double min, double max) { + STDLOG("MEDWidgetHelper::onCustomRangeChanged"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_CUSTOM_RANGE_CHANGED; + event->presentationId = _presId; + event->aDouble1 = min; + event->aDouble2 = max; + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} + +void MEDWidgetHelper::onHideDataOutsideCustomRangeChanged(int flag) { + STDLOG("MEDWidgetHelper::onCustomRangeFlagChanged"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE_CHANGED; + event->presentationId = _presId; + event->anInteger = flag; + event->aDouble1 = _paramWidget->getMixCustomRange(); + event->aDouble2 = _paramWidget->getMaxCustomRange(); + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} \ No newline at end of file diff --git a/src/MEDCalc/gui/MEDWidgetHelper.hxx b/src/MEDCalc/gui/MEDWidgetHelper.hxx index d9f12e27a..1f552e9cc 100644 --- a/src/MEDCalc/gui/MEDWidgetHelper.hxx +++ b/src/MEDCalc/gui/MEDWidgetHelper.hxx @@ -61,6 +61,11 @@ protected slots: void onComponentChanged(int idx); void onColorMapChanged(int idx); void onScalarBarRangeChanged(int idx); + void onScalarBarVisibilityChanged(int idx); + void onUseCustomRangeChanged(int idx); + void onCustomRangeValueChanged(double min, double max); + void onHideDataOutsideCustomRangeChanged(int idx); + protected: ///! GUI needs to talk directly to the pres manager to activate a view, get some params, etc ...: @@ -75,6 +80,9 @@ protected: int _selectedCompo; // Selected field component int _nbCompos; // Total number of available components std::vector _allCompos; // All available components + bool _scalarBarVisibility; + double _scalarBarRangeArray[2]; + bool _hideDataOutsideCustomRange; // Color map MEDCALC::ColorMapType _colorMap; diff --git a/src/MEDCalc/gui/MEDWidgetHelperContour.cxx b/src/MEDCalc/gui/MEDWidgetHelperContour.cxx index a58a9c4e2..98e44e8e5 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperContour.cxx +++ b/src/MEDCalc/gui/MEDWidgetHelperContour.cxx @@ -29,7 +29,8 @@ MEDWidgetHelperContour::MEDWidgetHelperContour(const PresentationController * pr MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, WidgetPresentationParameters * paramW): MEDWidgetHelper(presController, presManager, presId, presName, paramW), - _nbContours(-1) + _nbContours(-1), + _contourComponent(0) {} MEDWidgetHelperContour::~MEDWidgetHelperContour() @@ -39,6 +40,8 @@ void MEDWidgetHelperContour::loadParametersFromEngine() { MEDWidgetHelper::loadParametersFromEngine(); _nbContours = _presManager->getPresentationIntProperty(_presId, MEDPresentationContour::PROP_NB_CONTOUR.c_str()); + _contourComponent = _presManager->getPresentationIntProperty(_presId, MEDPresentationContour::PROB_CONTOUR_COMPONENT_ID.c_str()); + } void MEDWidgetHelperContour::updateWidget(bool connect) @@ -48,6 +51,7 @@ void MEDWidgetHelperContour::updateWidget(bool connect) // Contour presentation needs the number of contours _paramWidget->setNbContour(_nbContours); + _paramWidget->setContourComponents(_allCompos, _contourComponent); // Connect combo box changes if (connect) @@ -55,7 +59,10 @@ void MEDWidgetHelperContour::updateWidget(bool connect) QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)), _presController, SIGNAL(presentationSignal(const PresentationEvent *)) ); QObject::connect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbContourChanged(int)) ); + QObject::connect( _paramWidget, SIGNAL(comboContCompIndexChanged(int)), this, SLOT(onContourComponentTypeChanged(int)) ); } + if(_nbCompos == 1) + _paramWidget->hideContourComponent(); } void MEDWidgetHelperContour::releaseWidget() @@ -64,8 +71,8 @@ void MEDWidgetHelperContour::releaseWidget() QObject::disconnect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)), _presController, SIGNAL(presentationSignal(const PresentationEvent *)) ); -// QObject::disconnect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) ); QObject::disconnect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbContourChanged(int)) ); + QObject::disconnect( _paramWidget, SIGNAL(comboContCompIndexChanged(int)), this, SLOT(onContourComponentTypeChanged(int)) ); } void MEDWidgetHelperContour::onNbContourChanged(int nbContour) @@ -79,3 +86,14 @@ void MEDWidgetHelperContour::onNbContourChanged(int nbContour) emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent } +void MEDWidgetHelperContour::onContourComponentTypeChanged(int index) +{ + STDLOG("MEDWidgetHelperContour::onContourComponentTypeChanged"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_CHANGE_CONTOUR_COMPONENT; + event->presentationId = _presId; + event->anInteger = index; + event->aString = _paramWidget->getContourComponent(); + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} \ No newline at end of file diff --git a/src/MEDCalc/gui/MEDWidgetHelperContour.hxx b/src/MEDCalc/gui/MEDWidgetHelperContour.hxx index b37a22310..b6380ec62 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperContour.hxx +++ b/src/MEDCalc/gui/MEDWidgetHelperContour.hxx @@ -41,12 +41,14 @@ public: protected slots: void onNbContourChanged(int nbContour); + void onContourComponentTypeChanged(int index); protected: virtual void loadParametersFromEngine(); private: int _nbContours; + int _contourComponent; }; #endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERCONTOUR_HXX_ */ diff --git a/src/MEDCalc/gui/MEDWidgetHelperCutSegment.cxx b/src/MEDCalc/gui/MEDWidgetHelperCutSegment.cxx new file mode 100644 index 000000000..a8b916809 --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperCutSegment.cxx @@ -0,0 +1,95 @@ +// Copyright (C) 2016-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDWidgetHelperCutSegment.hxx" +#include "MEDPresentationCutSegment.hxx" // from component side. +#include "PresentationController.hxx" + +#include + +#include + +MEDWidgetHelperCutSegment::MEDWidgetHelperCutSegment(const PresentationController* presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, + WidgetPresentationParameters * paramW): + MEDWidgetHelper(presController, presManager, presId, presName, paramW) + {} + +MEDWidgetHelperCutSegment::~MEDWidgetHelperCutSegment() +{} + +void MEDWidgetHelperCutSegment::loadParametersFromEngine() +{ + MEDWidgetHelper::loadParametersFromEngine(); + _point1[0] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationCutSegment::PROP_POINT1_X.c_str()); + _point1[1] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationCutSegment::PROP_POINT1_Y.c_str()); + _point1[2] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationCutSegment::PROP_POINT1_Z.c_str()); + _point2[0] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationCutSegment::PROP_POINT2_X.c_str()); + _point2[1] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationCutSegment::PROP_POINT2_Y.c_str()); + _point2[2] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationCutSegment::PROP_POINT2_Z.c_str()); +} + +void MEDWidgetHelperCutSegment::updateWidget(bool connect) +{ + MEDWidgetHelper::updateWidget(connect); + + _paramWidget->setCutPoint1(_point1[0], _point1[1], _point1[2]); + _paramWidget->setCutPoint2(_point2[0], _point2[1], _point2[2]); + + // Connect spin boxes changes + if (connect) + { + QObject::connect( _paramWidget, SIGNAL(spinCutPoint1ValuesChanged(double, double, double)), this, SLOT(onCutPoint1Changed(double, double, double)) ); + QObject::connect( _paramWidget, SIGNAL(spinCutPoint2ValuesChanged(double, double, double)), this, SLOT(onCutPoint2Changed(double, double, double)) ); + } +} + +void MEDWidgetHelperCutSegment::releaseWidget() +{ + MEDWidgetHelper::releaseWidget(); + + QObject::disconnect( _paramWidget, SIGNAL(spinCutPoint1ValuesChanged(double, double, double)), this, SLOT(onCutPoint1Changed(double, double, double)) ); + QObject::disconnect( _paramWidget, SIGNAL(spinCutPoint2ValuesChanged(double, double, double)), this, SLOT(onCutPoint2Changed(double, double, double)) ); +} + +void MEDWidgetHelperCutSegment::onCutPoint1Changed(double x, double y, double z) +{ + STDLOG("MEDWidgetHelperCutSegment::onCutPoint1Changed"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_CHANGE_CUT_POINT1; + event->presentationId = _presId; + event->aDoubleP1[0] = x; + event->aDoubleP1[1] = y; + event->aDoubleP1[2] = z; + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} + +void MEDWidgetHelperCutSegment::onCutPoint2Changed(double x, double y, double z) +{ + STDLOG("MEDWidgetHelperCutSegment::onCutPoint2Changed"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_CHANGE_CUT_POINT2; + event->presentationId = _presId; + event->aDoubleP2[0] = x; + event->aDoubleP2[1] = y; + event->aDoubleP2[2] = z; + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} \ No newline at end of file diff --git a/src/MEDCalc/gui/MEDWidgetHelperCutSegment.hxx b/src/MEDCalc/gui/MEDWidgetHelperCutSegment.hxx new file mode 100644 index 000000000..adb49c6a5 --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperCutSegment.hxx @@ -0,0 +1,55 @@ +// Copyright (C) 2016-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERCUTSEGMENT_HXX_ +#define SRC_MEDCALC_GUI_MEDWIDGETHELPERCUTSEGMENT_HXX_ + +#include "MEDWidgetHelperComponent.hxx" + +class PresentationController; + +class MEDWidgetHelperCutSegment: public MEDWidgetHelper +{ + Q_OBJECT + +public: + MEDWidgetHelperCutSegment(const PresentationController* presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, + WidgetPresentationParameters * paramW); + + virtual ~MEDWidgetHelperCutSegment(); + + virtual void updateWidget(bool connect); + virtual void releaseWidget(); + + virtual std::string getPythonTag() const { return "CutSegment"; } + +protected slots: + void onCutPoint1Changed(double, double, double); + void onCutPoint2Changed(double, double, double); + +protected: + virtual void loadParametersFromEngine(); + +private: + double _point1[3]; + double _point2[3]; +}; + +#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERCUTSEGMENT_HXX_ */ diff --git a/src/MEDCalc/gui/MEDWidgetHelperPlot3D.cxx b/src/MEDCalc/gui/MEDWidgetHelperPlot3D.cxx new file mode 100644 index 000000000..6bb69113b --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperPlot3D.cxx @@ -0,0 +1,94 @@ +// Copyright (C) 2016-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDWidgetHelperPlot3D.hxx" +#include "MEDPresentationPlot3D.hxx" // from component side. +#include "PresentationController.hxx" + +#include + +#include + +MEDWidgetHelperPlot3D::MEDWidgetHelperPlot3D(const PresentationController* presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, + WidgetPresentationParameters * paramW): + MEDWidgetHelper(presController, presManager, presId, presName, paramW) + {} + +MEDWidgetHelperPlot3D::~MEDWidgetHelperPlot3D() +{} + +void MEDWidgetHelperPlot3D::loadParametersFromEngine() +{ + MEDWidgetHelper::loadParametersFromEngine(); + _planeNormal[0] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationPlot3D::PROP_PLANE_NORMAL_X.c_str()); + _planeNormal[1] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationPlot3D::PROP_PLANE_NORMAL_Y.c_str()); + _planeNormal[2] = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationPlot3D::PROP_PLANE_NORMAL_Z.c_str()); + _planePos = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationPlot3D::PROP_PLANE_POS.c_str()); + _isPlanar = _presManager->getPresentationIntProperty(_presId, MEDPresentationPlot3D::PROP_IS_PLANAR.c_str()); +} + +void MEDWidgetHelperPlot3D::updateWidget(bool connect) +{ + MEDWidgetHelper::updateWidget(connect); + + _paramWidget->setNormal(_planeNormal[0], _planeNormal[1], _planeNormal[2]); + _paramWidget->setPlanePosition(_planePos); + + // Connect spin boxes changes + if (connect) + { + QObject::connect( _paramWidget, SIGNAL(spinNormalValuesChanged(double, double, double)), this, SLOT(onPlaneNormalChanged(double, double, double)) ); + QObject::connect( _paramWidget, SIGNAL(spinPlanePosValueChanged(double)), this, SLOT(onPlanePositionChanged(double)) ); + } + if(_isPlanar) + _paramWidget->hidePlot3D(); +} + +void MEDWidgetHelperPlot3D::releaseWidget() +{ + MEDWidgetHelper::releaseWidget(); + + QObject::disconnect( _paramWidget, SIGNAL(spinNormalValuesChanged(double, double, double)), this, SLOT(onPlaneNormalChanged(double, double, double)) ); + QObject::disconnect( _paramWidget, SIGNAL(spinPlanePosValueChanged(double)), this, SLOT(onPlanePositionChanged(double)) ); +} + +void MEDWidgetHelperPlot3D::onPlaneNormalChanged(double normX, double normY, double normZ) +{ + STDLOG("MEDWidgetHelperSlices::onNbSlicesChanged"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_CHANGE_NORMAL; + event->presentationId = _presId; + event->aDoubleN[0] = normX; + event->aDoubleN[1] = normY; + event->aDoubleN[2] = normZ; + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} + +void MEDWidgetHelperPlot3D::onPlanePositionChanged(double planePos) +{ + STDLOG("MEDWidgetHelperSlices::onNbSlicesChanged"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_CHANGE_PLANE_POS; + event->presentationId = _presId; + event->aDouble3 = planePos; + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} \ No newline at end of file diff --git a/src/MEDCalc/gui/MEDWidgetHelperPlot3D.hxx b/src/MEDCalc/gui/MEDWidgetHelperPlot3D.hxx new file mode 100644 index 000000000..83dfbf7d6 --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperPlot3D.hxx @@ -0,0 +1,56 @@ +// Copyright (C) 2016-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERPLOT3D_HXX_ +#define SRC_MEDCALC_GUI_MEDWIDGETHELPERPLOT3D_HXX_ + +#include "MEDWidgetHelper.hxx" + +class PresentationController; + +class MEDWidgetHelperPlot3D: public MEDWidgetHelper +{ + Q_OBJECT + +public: + MEDWidgetHelperPlot3D(const PresentationController* presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, + WidgetPresentationParameters * paramW); + + virtual ~MEDWidgetHelperPlot3D(); + + virtual void updateWidget(bool connect); + virtual void releaseWidget(); + + virtual std::string getPythonTag() const { return "Plot3D"; } + +protected slots: + void onPlaneNormalChanged(double, double, double); + void onPlanePositionChanged(double); + +protected: + virtual void loadParametersFromEngine(); + +private: + double _planeNormal[3]; + double _planePos; + int _isPlanar; +}; + +#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERPLOT3D_HXX_ */ diff --git a/src/MEDCalc/gui/MEDWidgetHelperStreamLines.cxx b/src/MEDCalc/gui/MEDWidgetHelperStreamLines.cxx new file mode 100644 index 000000000..ca625bfd6 --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperStreamLines.cxx @@ -0,0 +1,74 @@ +// Copyright (C) 2016-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDWidgetHelperStreamLines.hxx" +#include "MEDPresentationStreamLines.hxx" // from component side. +#include "PresentationController.hxx" + +#include + +#include + +MEDWidgetHelperStreamLines::MEDWidgetHelperStreamLines(const PresentationController* presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, + WidgetPresentationParameters * paramW): + MEDWidgetHelper(presController, presManager, presId, presName, paramW) + {} + +MEDWidgetHelperStreamLines::~MEDWidgetHelperStreamLines() +{} + +void MEDWidgetHelperStreamLines::loadParametersFromEngine() +{ + MEDWidgetHelper::loadParametersFromEngine(); + _intDirType = static_cast( + _presManager->getPresentationIntProperty(_presId, MEDPresentationStreamLines::PROP_INTEGR_DIR_TYPE.c_str())); +} + +void MEDWidgetHelperStreamLines::updateWidget(bool connect) +{ + MEDWidgetHelper::updateWidget(connect); + + _paramWidget->setIntegrationDir(_intDirType); + + // Connect spin boxes changes + if (connect) + { + QObject::connect( _paramWidget, SIGNAL(comboIntegrDirIndexChanged(int)), this, SLOT(onIntegrDirTypeChanged(int)) ); + } +} + +void MEDWidgetHelperStreamLines::releaseWidget() +{ + MEDWidgetHelper::releaseWidget(); + + QObject::disconnect( _paramWidget, SIGNAL(comboIntegrDirIndexChanged(int)), this, SLOT(onIntegrDirTypeChanged(int)) ); +} + +void MEDWidgetHelperStreamLines::onIntegrDirTypeChanged(int index) +{ + STDLOG("MEDWidgetHelperStreamLines::onIntegrDirTypeChanged"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_CHANGE_INTEGR_DIR; + event->presentationId = _presId; + event->anInteger = static_cast(_paramWidget->getIntegrationDir()); + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} + diff --git a/src/MEDCalc/gui/MEDWidgetHelperStreamLines.hxx b/src/MEDCalc/gui/MEDWidgetHelperStreamLines.hxx new file mode 100644 index 000000000..6806254a1 --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperStreamLines.hxx @@ -0,0 +1,53 @@ +// Copyright (C) 2016-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERSTREAMLINES_HXX_ +#define SRC_MEDCALC_GUI_MEDWIDGETHELPERSTREAMLINES_HXX_ + +#include "MEDWidgetHelper.hxx" + +class PresentationController; + +class MEDWidgetHelperStreamLines: public MEDWidgetHelper +{ + Q_OBJECT + +public: + MEDWidgetHelperStreamLines(const PresentationController* presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, + WidgetPresentationParameters * paramW); + + virtual ~MEDWidgetHelperStreamLines(); + + virtual void updateWidget(bool connect); + virtual void releaseWidget(); + + virtual std::string getPythonTag() const { return "StreamLines"; } + +protected slots: + void onIntegrDirTypeChanged(int index); + +protected: + virtual void loadParametersFromEngine(); + +private: + MEDCALC::IntegrationDirType _intDirType; +}; + +#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERSTREAMLINES_HXX_ */ diff --git a/src/MEDCalc/gui/MEDWidgetHelperVectorField.cxx b/src/MEDCalc/gui/MEDWidgetHelperVectorField.cxx new file mode 100644 index 000000000..298219b9a --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperVectorField.cxx @@ -0,0 +1,86 @@ +// Copyright (C) 2016-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDWidgetHelperVectorField.hxx" +#include "MEDPresentationVectorField.hxx" // from component side. +#include "PresentationController.hxx" + +#include + +#include + + +MEDWidgetHelperVectorField::MEDWidgetHelperVectorField(const PresentationController* presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, + WidgetPresentationParameters * paramW): + MEDWidgetHelper(presController, presManager, presId, presName, paramW) + {} +MEDWidgetHelperVectorField::~MEDWidgetHelperVectorField() {} + +void MEDWidgetHelperVectorField::loadParametersFromEngine() +{ + MEDWidgetHelper::loadParametersFromEngine(); + _scaleFactor = _presManager->getPresentationDoubleProperty(_presId, MEDPresentationVectorField::PROP_SCALE_FACTOR.c_str()); + _customScaleFactor = _presManager->getPresentationIntProperty(_presId, MEDPresentationVectorField::PROP_CUSTOM_SCALE_FACTOR.c_str()); +} + +void MEDWidgetHelperVectorField::updateWidget(bool connect) +{ + MEDWidgetHelper::updateWidget(connect); + _paramWidget->setScaleFactor(_scaleFactor); + _paramWidget->setScaleFactorFlag(_customScaleFactor); + + // Connect spin boxes changes + if (connect) + { + QObject::connect( _paramWidget, SIGNAL(spinboxScaleFactorChaged(double)), this, SLOT(onScaleFactorChanged(double)) ); + QObject::connect( _paramWidget, SIGNAL(checkboxCustomScaleFactorChanged(int)), this, SLOT(onCustomScaleFactorChanged(int))); + + } +} + +void MEDWidgetHelperVectorField::releaseWidget() +{ + MEDWidgetHelper::releaseWidget(); + + QObject::disconnect( _paramWidget, SIGNAL(spinboxScaleFactorChaged(double)), this, SLOT(onScaleFactorChanged(double)) ); +} + +void MEDWidgetHelperVectorField::onScaleFactorChanged(double scale) +{ + STDLOG("MEDWidgetHelperVectorField::onScaleFactorChanged"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_CHANGE_SCALE_FACTOR; + event->presentationId = _presId; + event->aDouble3 = scale; + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} + +void MEDWidgetHelperVectorField::onCustomScaleFactorChanged(int flag) +{ + STDLOG("MEDWidgetHelperVectorField::onScaleFactorChanged"); + PresentationEvent* event = new PresentationEvent(); + event->eventtype = PresentationEvent::EVENT_CHANGE_CUSTOM_SCALE_FACTOR; + event->presentationId = _presId; + event->anInteger = flag; + event->aDouble3 = _paramWidget->getScaleFactor(); + + emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent +} \ No newline at end of file diff --git a/src/MEDCalc/gui/MEDWidgetHelperVectorField.hxx b/src/MEDCalc/gui/MEDWidgetHelperVectorField.hxx index c1e8e1b38..62135c731 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperVectorField.hxx +++ b/src/MEDCalc/gui/MEDWidgetHelperVectorField.hxx @@ -31,13 +31,23 @@ class MEDWidgetHelperVectorField: public MEDWidgetHelper public: MEDWidgetHelperVectorField(const PresentationController* presController, MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, - WidgetPresentationParameters * paramW): - MEDWidgetHelper(presController, presManager, presId, presName, paramW) - {} - virtual ~MEDWidgetHelperVectorField() {} + WidgetPresentationParameters * paramW); + + virtual ~MEDWidgetHelperVectorField(); + + virtual void updateWidget(bool connect); + virtual void releaseWidget(); virtual std::string getPythonTag() const { return "VectorField"; } +protected slots: + void onScaleFactorChanged(double); + void onCustomScaleFactorChanged(int); + +protected: + virtual void loadParametersFromEngine(); + double _scaleFactor; + bool _customScaleFactor; }; #endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERVECTORFIELD_HXX_ */ diff --git a/src/MEDCalc/gui/PresentationController.cxx b/src/MEDCalc/gui/PresentationController.cxx index f408718a1..6ed54700e 100644 --- a/src/MEDCalc/gui/PresentationController.cxx +++ b/src/MEDCalc/gui/PresentationController.cxx @@ -33,6 +33,9 @@ #include "MEDPresentationSlices.hxx" #include "MEDPresentationPointSprite.hxx" #include "MEDPresentationVectorField.hxx" +#include "MEDPresentationPlot3D.hxx" +#include "MEDPresentationStreamLines.hxx" +#include "MEDPresentationCutSegment.hxx" #include "MEDPresentationDeflectionShape.hxx" #include "MEDWidgetHelperMeshView.hxx" @@ -40,6 +43,9 @@ #include "MEDWidgetHelperContour.hxx" #include "MEDWidgetHelperSlices.hxx" #include "MEDWidgetHelperPointSprite.hxx" +#include "MEDWidgetHelperPlot3D.hxx" +#include "MEDWidgetHelperStreamLines.hxx" +#include "MEDWidgetHelperCutSegment.hxx" #include "MEDWidgetHelperVectorField.hxx" #include "MEDWidgetHelperDeflectionShape.hxx" @@ -58,6 +64,7 @@ #include #include #include +#include #include "MEDFactoryClient.hxx" @@ -231,6 +238,34 @@ PresentationController::createActions() _salomeModule->action(actionId)->setIconVisibleInMenu(true); _salomeModule->createMenu(actionId, presentationMenuId); + label = tr("LAB_PRESENTATION_PLOT3D"); + tooltip = tr("TIP_PRESENTATION_PLOT3D"); + icon = tr(_getIconName("ICO_PRESENTATION_PLOT3D").c_str()); + actionId = _salomeModule->createStandardAction(label, this, SLOT(onVisualizePlot3D()), + icon, tooltip, FIELDSOp::OpPlot3D); + _salomeModule->createTool(actionId, presentationToolbarId); + _salomeModule->action(actionId)->setIconVisibleInMenu(true); + _salomeModule->createMenu(actionId, presentationMenuId); + + label = tr("LAB_PRESENTATION_STREAM_LINES"); + tooltip = tr("TIP_PRESENTATION_STREAM_LINES"); + icon = tr(_getIconName("ICO_PRESENTATION_STREAM_LINES").c_str()); + actionId = _salomeModule->createStandardAction(label, this, SLOT(onVisualizeStreamLines()), + icon, tooltip, FIELDSOp::OpStreamLines); + _salomeModule->createTool(actionId, presentationToolbarId); + _salomeModule->action(actionId)->setIconVisibleInMenu(true); + _salomeModule->createMenu(actionId, presentationMenuId); + + label = tr("LAB_PRESENTATION_CUT_SEGMENT"); + tooltip = tr("TIP_PRESENTATION_CUT_SEGMENT"); + icon = tr(_getIconName("ICO_PRESENTATION_CUT_SEGMENT").c_str()); + actionId = _salomeModule->createStandardAction(label, this, SLOT(onVisualizeCutSegment()), + icon, tooltip, FIELDSOp::OpCutSegment); + _salomeModule->createTool(actionId, presentationToolbarId); + _salomeModule->action(actionId)->setIconVisibleInMenu(true); + _salomeModule->createMenu(actionId, presentationMenuId); + + // Separator _salomeModule->createMenu(_salomeModule->separator(), presentationMenuId); @@ -387,6 +422,29 @@ PresentationController::onVisualizePointSprite() this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE); } +void +PresentationController::onVisualizePlot3D() +{ + this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_PLOT3D); +} + +void +PresentationController::onVisualizeStreamLines() +{ + this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_STREAM_LINES); +} + +void +PresentationController::onVisualizeCutSegment() +{ + // Cut segment presentation "creates" new view, so switch off visibility state update + // because pqActiveObjects::viewChanged is emmited + _salomeModule->visibilityStateUpdateOff(); + this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CUT_SEGMENT); + _salomeModule->visibilityStateUpdateOn(); + _salomeModule->updateVisibilityState(); +} + void PresentationController::onDeletePresentation() { @@ -439,10 +497,11 @@ PresentationController::getColorMapPython() const QString PresentationController::getScalarBarRangePython() const { - MEDCALC::ScalarBarRangeType colorMap = getSelectedScalarBarRange(); - switch(colorMap) { + MEDCALC::ScalarBarRangeType scalarBarRange = getSelectedScalarBarRange(); + switch(scalarBarRange) { case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: return "MEDCALC.SCALAR_BAR_ALL_TIMESTEPS"; case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: return "MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP"; + case MEDCALC::SCALAR_BAR_CUSTOM_RANGE: return "MEDCALC.SCALAR_BAR_CUSTOM_RANGE"; } return QString(); } @@ -475,6 +534,19 @@ PresentationController::getSliceOrientationPython(const int orientation) const return QString(); } +QString +PresentationController::getIntegrDirTypePython(const int intDir) const +{ + MEDCALC::IntegrationDirType type = static_cast(intDir); + switch(type) { + case MEDCALC::INTEGRATION_DIR_BOTH: return "MEDCALC.INTEGRATION_DIR_BOTH"; + case MEDCALC::INTEGRATION_DIR_FORWARD: return "MEDCALC.INTEGRATION_DIR_FORWARD"; + case MEDCALC::INTEGRATION_DIR_BACKWARD: return "MEDCALC.INTEGRATION_DIR_BACKWARD"; + } + return QString(); +} + + std::string PresentationController::getPresTypeFromWidgetHelper(int presId) const { @@ -484,6 +556,12 @@ PresentationController::getPresTypeFromWidgetHelper(int presId) const return "UNKNOWN"; } +void +PresentationController::emitPresentationSignal(const PresentationEvent* event) +{ + emit presentationSignal(event); +} + void PresentationController::processPresentationEvent(const PresentationEvent* event) { // --> Send commands to SALOME Python console @@ -527,7 +605,22 @@ PresentationController::processPresentationEvent(const PresentationEvent* event) .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); commands += QString("presentation_id"); } - else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) { + else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_PLOT3D ) { + commands += QString("presentation_id = medcalc.MakePlot3D(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") + .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); + commands += QString("presentation_id"); + } + else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_STREAM_LINES ) { + commands += QString("presentation_id = medcalc.MakeStreamLines(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") + .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); + commands += QString("presentation_id"); + } + else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CUT_SEGMENT ) { + commands += QString("presentation_id = medcalc.MakeCutSegment(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") + .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); + commands += QString("presentation_id"); + } + else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) { commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); commands += QString("presentation_id"); @@ -547,9 +640,20 @@ PresentationController::processPresentationEvent(const PresentationEvent* event) commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId); } else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_TIME_RANGE ) { + bool customRangeFlag = + (bool)_presManager->getPresentationIntProperty(event->presentationId, MEDPresentation::PROP_HIDE_DATA_OUTSIDE_CUSTOM_RANGE.c_str()); std::string typ = getPresTypeFromWidgetHelper(event->presentationId); commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId); commands += QString("params.scalarBarRange = %1").arg(getScalarBarRangePython()); + if (getSelectedScalarBarRange() == MEDCALC::SCALAR_BAR_CUSTOM_RANGE) { + commands += QString("params.scalarBarRangeArray = [%1, %2]").arg(event->aDouble1).arg(event->aDouble2); + } + else { + if (customRangeFlag) // switch off hideDataOutsideCustomRange + { + commands += QString("params.hideDataOutsideCustomRange = False"); + } + } commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId); } else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_CONTOUR ) { @@ -576,9 +680,98 @@ PresentationController::processPresentationEvent(const PresentationEvent* event) commands += QString("params.orientation = %1").arg(getSliceOrientationPython(event->anInteger)); commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId); } + else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_PLANE_POS ) { + std::string typ = getPresTypeFromWidgetHelper(event->presentationId); + commands += QString("params = medcalc.GetPlot3DParameters(%2)").arg(event->presentationId); + commands += QString("params.planePos = %1").arg(event->aDouble3); + commands += QString("medcalc.UpdatePlot3D(%1, params)").arg(event->presentationId); + } + else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NORMAL ) { + std::string typ = getPresTypeFromWidgetHelper(event->presentationId); + commands += QString("params = medcalc.GetPlot3DParameters(%2)").arg(event->presentationId); + commands += QString("params.planeNormal = [%1, %2, %3]").arg(event->aDoubleN[0]).arg(event->aDoubleN[1]).arg(event->aDoubleN[2]); + commands += QString("medcalc.UpdatePlot3D(%1, params)").arg(event->presentationId); + } + else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_CUT_POINT1 ) { + std::string typ = getPresTypeFromWidgetHelper(event->presentationId); + commands += QString("params = medcalc.GetCutSegmentParameters(%2)").arg(event->presentationId); + commands += QString("params.point1 = [%1, %2, %3]").arg(event->aDoubleP1[0]).arg(event->aDoubleP1[1]).arg(event->aDoubleP1[2]); + commands += QString("medcalc.UpdateCutSegment(%1, params)").arg(event->presentationId); + } + else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_CUT_POINT2 ) { + std::string typ = getPresTypeFromWidgetHelper(event->presentationId); + commands += QString("params = medcalc.GetCutSegmentParameters(%2)").arg(event->presentationId); + commands += QString("params.point2 = [%1, %2, %3]").arg(event->aDoubleP2[0]).arg(event->aDoubleP2[1]).arg(event->aDoubleP2[2]); + commands += QString("medcalc.UpdateCutSegment(%1, params)").arg(event->presentationId); + } + else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_INTEGR_DIR ) { + std::string typ = getPresTypeFromWidgetHelper(event->presentationId); + commands += QString("params = medcalc.GetStreamLinesParameters(%2)").arg(event->presentationId); + commands += QString("params.integrDir = %1").arg(getIntegrDirTypePython(event->anInteger)); + commands += QString("medcalc.UpdateStreamLines(%1, params)").arg(event->presentationId); + } + else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_CONTOUR_COMPONENT) { + std::string typ = getPresTypeFromWidgetHelper(event->presentationId); + commands += QString("params = medcalc.GetContourParameters(%2)").arg(event->presentationId); + commands += QString("params.contourComponent = '%1'").arg(event->aString.c_str()); + commands += QString("medcalc.UpdateContour(%1, params)").arg(event->presentationId); + } + else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_SCALE_FACTOR ) { + std::string typ = getPresTypeFromWidgetHelper(event->presentationId); + commands += QString("params = medcalc.GetVectorFieldParameters(%2)").arg(event->presentationId); + commands += QString("params.scaleFactor = %1").arg(event->aDouble3); + commands += QString("medcalc.UpdateVectorField(%1, params)").arg(event->presentationId); + } + + else if (event->eventtype == PresentationEvent::EVENT_CHANGE_CUSTOM_SCALE_FACTOR) { + std::string typ = getPresTypeFromWidgetHelper(event->presentationId); + commands += QString("params = medcalc.GetVectorFieldParameters(%2)").arg(event->presentationId); + commands += QString("params.customScaleFactor = %1").arg(event->anInteger); + if(event->anInteger) { + commands += QString("params.scaleFactor = %1").arg(event->aDouble3); + } + commands += QString("medcalc.UpdateVectorField(%1, params)").arg(event->presentationId); + } else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) { commands += QString("medcalc.RemovePresentation(%1)").arg(event->presentationId); + + } + else if (event->eventtype == PresentationEvent::EVENT_DISPLAY_PRESENTATION || + event->eventtype == PresentationEvent::EVENT_ERASE_PRESENTATION) { + commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(getPresTypeFromWidgetHelper(event->presentationId))) + .arg(event->presentationId); + QString visility = event->eventtype == PresentationEvent::EVENT_DISPLAY_PRESENTATION ? QString("True") : QString("False"); + commands += QString("params.visibility = %1").arg(visility); + commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(getPresTypeFromWidgetHelper(event->presentationId))) + .arg(event->presentationId); + } + else if (event->eventtype == PresentationEvent::EVENT_SCALAR_BAR_VISIBILITY_CHANGED || + event->eventtype == PresentationEvent::EVENT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE_CHANGED) { + std::string typ = getPresTypeFromWidgetHelper(event->presentationId); + QString param; + switch (event->eventtype) { + case PresentationEvent::EVENT_SCALAR_BAR_VISIBILITY_CHANGED: + param = QString("scalarBarVisibility"); + break; + case PresentationEvent::EVENT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE_CHANGED: + param = QString("hideDataOutsideCustomRange"); + break; + default: break; + } + commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId); + commands += QString("params.%1 = %2").arg(param).arg( event->anInteger ? QString("True") : QString("False")); + if (event->eventtype == PresentationEvent::EVENT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE_CHANGED && event->anInteger) { + commands += QString("params.scalarBarRangeArray = [%1, %2]").arg(event->aDouble1).arg(event->aDouble2); + } + commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId); + } + else if (event->eventtype == PresentationEvent::EVENT_CUSTOM_RANGE_CHANGED) + { + std::string typ = getPresTypeFromWidgetHelper(event->presentationId); + commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId); + commands += QString("params.scalarBarRangeArray = [%1, %2]").arg(event->aDouble1).arg(event->aDouble2); + commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId); } else { STDLOG("The event "<eventtype<<" is not implemented yet"); @@ -606,6 +799,12 @@ PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager wh = new MEDWidgetHelperVectorField(this, _presManager, presId, name, _widgetPresentationParameters); else if (type == MEDPresentationPointSprite::TYPE_NAME) wh = new MEDWidgetHelperPointSprite(this, _presManager, presId, name, _widgetPresentationParameters); + else if (type == MEDPresentationPlot3D::TYPE_NAME) + wh = new MEDWidgetHelperPlot3D(this, _presManager, presId, name, _widgetPresentationParameters); + else if (type == MEDPresentationStreamLines::TYPE_NAME) + wh = new MEDWidgetHelperStreamLines(this, _presManager, presId, name, _widgetPresentationParameters); + else if (type == MEDPresentationCutSegment::TYPE_NAME) + wh = new MEDWidgetHelperCutSegment(this, _presManager, presId, name, _widgetPresentationParameters); else if (type == MEDPresentationDeflectionShape::TYPE_NAME) wh = new MEDWidgetHelperDeflectionShape(this, _presManager, presId, name, _widgetPresentationParameters); else @@ -715,6 +914,7 @@ PresentationController::updateTreeViewWithNewPresentation(long dataId, long pres int presId = -1; _salomeModule->itemClickGeneric(name, type, presId); onPresentationSelected(presId, QString::fromStdString(type), QString::fromStdString(name)); + updateVisibilityState(presId); } void @@ -765,6 +965,9 @@ PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event) else { updateTreeViewWithNewPresentation(event->dataId, event->presentationId); _dealWithReplaceMode(); + // Update parameter widget if shown: some parameters should be updated after presentation has been added + if (_currentWidgetHelper) + _currentWidgetHelper->updateWidget(false); } } else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) { @@ -777,6 +980,9 @@ PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event) if(_currentWidgetHelper) _currentWidgetHelper->updateWidget(false); } + else if (event->type == MEDCALC::EVENT_VISIBILITY_CHANGED) { + updateVisibilityState(event->presentationId); + } } void @@ -784,3 +990,17 @@ PresentationController::showDockWidgets(bool isVisible) { _dockWidget->setVisible(isVisible); } + +void PresentationController::updateVisibilityState(long presId) +{ + char* str = _salomeModule->engine()->getStudyPresentationEntry(presId); + if (str) { + QStringList entries; + entries.append(str); + _salomeModule->updateVisibilityState(false, entries); + } +} + +std::string PresentationController::presentationName2Type(const std::string& name) { + return std::regex_replace(name, std::regex("MEDPresentation"), std::string("")); +} \ No newline at end of file diff --git a/src/MEDCalc/gui/PresentationController.hxx b/src/MEDCalc/gui/PresentationController.hxx index 2488b3ba3..c0693c227 100644 --- a/src/MEDCalc/gui/PresentationController.hxx +++ b/src/MEDCalc/gui/PresentationController.hxx @@ -56,9 +56,12 @@ public: void showDockWidgets(bool isVisible); std::string getPresTypeFromWidgetHelper(int presId) const; + static std::string presentationName2Type(const std::string& name); void setConsoleDriver(XmedConsoleDriver* driver) { _consoleDriver = driver; }; + void emitPresentationSignal(const PresentationEvent* event); + signals: void presentationSignal(const PresentationEvent*); @@ -70,6 +73,9 @@ protected slots: void onVisualizeSlices(); void onVisualizeDeflectionShape(); void onVisualizePointSprite(); + void onVisualizePlot3D(); + void onVisualizeStreamLines(); + void onVisualizeCutSegment(); void onDeletePresentation(); void onParavisDump(); @@ -83,6 +89,7 @@ private: void visualize(PresentationEvent::EventType); void updateTreeViewWithNewPresentation(long dataId, long presentationId); void updateTreeViewForPresentationRemoval(long presId); + void updateVisibilityState(long presId); std::string _getIconName(const std::string&); MEDWidgetHelper * findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string& type, const std::string& name); @@ -92,6 +99,8 @@ private: QString getScalarBarRangePython() const; QString getMeshModePython(const int mode) const; QString getSliceOrientationPython(const int orient) const; + QString getIntegrDirTypePython(const int intDir) const; + QString getContourComponentTypePython(const int comp) const; void _dealWithReplaceMode(); diff --git a/src/MEDCalc/gui/PresentationEvent.hxx b/src/MEDCalc/gui/PresentationEvent.hxx index b82252bd6..3cccb362f 100644 --- a/src/MEDCalc/gui/PresentationEvent.hxx +++ b/src/MEDCalc/gui/PresentationEvent.hxx @@ -28,6 +28,9 @@ typedef struct { EVENT_VIEW_OBJECT_CONTOUR, EVENT_VIEW_OBJECT_DEFLECTION_SHAPE, EVENT_VIEW_OBJECT_POINT_SPRITE, + EVENT_VIEW_OBJECT_PLOT3D, + EVENT_VIEW_OBJECT_STREAM_LINES, + EVENT_VIEW_OBJECT_CUT_SEGMENT, EVENT_VIEW_OBJECT_SCALAR_MAP, EVENT_VIEW_OBJECT_SLICES, EVENT_VIEW_OBJECT_VECTOR_FIELD, @@ -43,16 +46,45 @@ typedef struct { EVENT_CHANGE_NB_CONTOUR, EVENT_CHANGE_SLICE_ORIENTATION, - EVENT_CHANGE_NB_SLICES + EVENT_CHANGE_NB_SLICES, + + EVENT_CHANGE_NORMAL, + EVENT_CHANGE_PLANE_POS, + + EVENT_CHANGE_INTEGR_DIR, + + EVENT_CHANGE_CUT_POINT1, + EVENT_CHANGE_CUT_POINT2, + + EVENT_CHANGE_CONTOUR_COMPONENT, + + EVENT_CHANGE_SCALE_FACTOR, + EVENT_CHANGE_CUSTOM_SCALE_FACTOR, + + EVENT_DISPLAY_PRESENTATION, + EVENT_ERASE_PRESENTATION, + + EVENT_SCALAR_BAR_VISIBILITY_CHANGED, + + EVENT_CUSTOM_RANGE_CHANGED, + + EVENT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE_CHANGED }; EventType eventtype; MEDCALC::FieldHandler * fieldHandler; MEDCALC::MeshHandler * meshHandler; int presentationId; + std::string presentationType; // presentation type (can be empty) int anInteger; // multi-purpose variable //int anInteger2; // multi-purpose variable std::string aString; // multi-purpose variable + double aDouble1; // multi-purpose variable + double aDouble2; // multi-purpose variable + double aDouble3; + double aDoubleN[3]; // multi-purpose variable + double aDoubleP1[3]; // multi-purpose variable + double aDoubleP2[3]; // multi-purpose variable } PresentationEvent; #endif diff --git a/src/MEDCalc/gui/WorkspaceController.cxx b/src/MEDCalc/gui/WorkspaceController.cxx index af90db5f5..7d386075f 100644 --- a/src/MEDCalc/gui/WorkspaceController.cxx +++ b/src/MEDCalc/gui/WorkspaceController.cxx @@ -318,6 +318,9 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent* event) { else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) { emit workspaceSignal(event); // forward to PresentationController } + else if ( event->type == MEDCALC::EVENT_VISIBILITY_CHANGED ) { + emit workspaceSignal(event); // forward to PresentationController + } else if ( event->type == MEDCALC::EVENT_MODIFY_PRESENTATION ) { emit workspaceSignal(event); // forward to PresentationController } diff --git a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx index 670f58e74..a81da3933 100644 --- a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx +++ b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx @@ -24,6 +24,8 @@ #include "WidgetPresentationParameters.hxx" #include +#include + using namespace std; WidgetPresentationParameters::WidgetPresentationParameters(QWidget* parent) @@ -34,16 +36,70 @@ WidgetPresentationParameters::WidgetPresentationParameters(QWidget* parent) toggleWidget(false); QObject::connect(_ui.comboBoxCompo, SIGNAL(activated(int)), this, SLOT(onComboCompoIndexChanged(int)) ); - QObject::connect(_ui.comboBoxMesh, SIGNAL(activated(int)), - this, SLOT(onComboMeshIndexChanged(int)) ); + QObject::connect(_ui.comboBoxMesh, SIGNAL(activated(int)), + this, SLOT(onComboMeshIndexChanged(int)) ); QObject::connect(_ui.comboBoxScalarBarRange, SIGNAL(activated(int)), this, SLOT(onComboScalarBarRangeIndexChanged(int)) ); QObject::connect(_ui.comboBoxColorMap, SIGNAL(activated(int)), this, SLOT(onComboColorMapIndexChanged(int)) ); - QObject::connect(_ui.comboBoxSliceOrient, SIGNAL(activated(int)), + QObject::connect(_ui.comboBoxSliceOrient, SIGNAL(activated(int)), this, SLOT(onComboOrientIndexChanged(int)) ); + QObject::connect(_ui.comboBoxIntegrDir, SIGNAL(activated(int)), + this, SLOT(onComboIntegrDirIndexChanged(int)) ); + QObject::connect(_ui.comboBoxContComp, SIGNAL(activated(int)), + this, SLOT(onComboContCompIndexChanged(int)) ); QObject::connect(_ui.spinBox, SIGNAL(editingFinished()), this, SLOT(onSpinBoxEditingFinished()) ); + QObject::connect(_ui.checkBoxShowScalarBar, SIGNAL(stateChanged(int)), + this, SLOT(onCheckboxScalarBarVisibilityChanged(int))); + QObject::connect(_ui.checkBoxCustomRange, SIGNAL(stateChanged(int)), + this, SLOT(onCheckboxCustomRangeChanged(int))); + QObject::connect(_ui.checkBoxScaleFactor, SIGNAL(stateChanged(int)), + this, SLOT(onCheckboxScaleFactorChanged(int))); + QObject::connect(_ui.checkBoxScaleFactor, SIGNAL(stateChanged(int)), + this, SLOT(onCheckboxCustomScaleFactorChanged(int))); + QObject::connect(_ui.spinCustomRangeMin, SIGNAL(editingFinished()), + this, SLOT(onSpinboxCustomRangeChanged())); + QObject::connect(_ui.spinCustomRangeMax, SIGNAL(editingFinished()), + this, SLOT(onSpinboxCustomRangeChanged())); + QObject::connect(_ui.spinScaleFactor, SIGNAL(editingFinished()), + this, SLOT(onSpinboxScaleFactorChanged())); + QObject::connect(_ui.checkBoxHideDataOutsideCR, SIGNAL(stateChanged(int)), + this, SLOT(onCheckboxHideDataOutsideCustomRangeChanged(int))); + QObject::connect(_ui.spinNormalX, SIGNAL(editingFinished()), + this, SLOT(onSpinNormalEditingFinished()) ); + QObject::connect(_ui.spinNormalY, SIGNAL(editingFinished()), + this, SLOT(onSpinNormalEditingFinished()) ); + QObject::connect(_ui.spinNormalZ, SIGNAL(editingFinished()), + this, SLOT(onSpinNormalEditingFinished()) ); + QObject::connect(_ui.spinPoint1_X, SIGNAL(editingFinished()), + this, SLOT(onSpinCutPoint1EditingFinished()) ); + QObject::connect(_ui.spinPoint1_Y, SIGNAL(editingFinished()), + this, SLOT(onSpinCutPoint1EditingFinished()) ); + QObject::connect(_ui.spinPoint1_Z, SIGNAL(editingFinished()), + this, SLOT(onSpinCutPoint1EditingFinished()) ); + QObject::connect(_ui.spinPoint2_X, SIGNAL(editingFinished()), + this, SLOT(onSpinCutPoint2EditingFinished()) ); + QObject::connect(_ui.spinPoint2_Y, SIGNAL(editingFinished()), + this, SLOT(onSpinCutPoint2EditingFinished()) ); + QObject::connect(_ui.spinPoint2_Z, SIGNAL(editingFinished()), + this, SLOT(onSpinCutPoint2EditingFinished()) ); + QObject::connect(_ui.spinPlanePos, SIGNAL(editingFinished()), + this, SLOT(onSpinPlanePosEditingFinished()) ); + + // Disable Custom Range Spin boxes + _ui.spinCustomRangeMax->setEnabled(false); + _ui.spinCustomRangeMin->setEnabled(false); + _ui.spinScaleFactor->setEnabled(false); + _ui.checkBoxHideDataOutsideCR->setEnabled(false); + + // Min and max values + _ui.spinCustomRangeMin->setRange(std::numeric_limits::lowest(), std::numeric_limits::max()); + _ui.spinCustomRangeMax->setRange(std::numeric_limits::lowest(), std::numeric_limits::max()); + _ui.spinNormalX->setRange(0.0, 1.0); + _ui.spinNormalY->setRange(0.0, 1.0); + _ui.spinNormalZ->setRange(0.0, 1.0); + _ui.spinPlanePos->setRange(0.0, 1.0); } void @@ -77,12 +133,117 @@ WidgetPresentationParameters::onComboScalarBarRangeIndexChanged(int idx) if (!_blockSig) emit comboScalarBarRangeIndexChanged(idx); } +void +WidgetPresentationParameters::onComboIntegrDirIndexChanged(int idx) +{ + if (!_blockSig) emit comboIntegrDirIndexChanged(idx); +} + +void +WidgetPresentationParameters::onComboContCompIndexChanged(int idx) +{ + if (!_blockSig) emit comboContCompIndexChanged(idx); +} + +void +WidgetPresentationParameters::onCheckboxScalarBarVisibilityChanged(int flag) +{ + if (!_blockSig) emit checkboxScalarBarVisibilityChanged(flag); +} + +void +WidgetPresentationParameters::onCheckboxCustomRangeChanged(int flag) +{ + _ui.spinCustomRangeMin->setEnabled(flag); + _ui.spinCustomRangeMax->setEnabled(flag); + _ui.checkBoxHideDataOutsideCR->setEnabled(flag); + _ui.comboBoxScalarBarRange->setEnabled(!flag); + if (!_blockSig) emit checkboxCustomRangeChanged(flag); +} + +void +WidgetPresentationParameters::onCheckboxScaleFactorChanged(int flag) +{ + _ui.spinScaleFactor->setEnabled(flag); + if (!_blockSig) emit checkboxScaleFactorChanged(flag); +} + +void +WidgetPresentationParameters::onSpinboxCustomRangeChanged() +{ + if (!_blockSig) emit spinboxCustomRangeChanged(_ui.spinCustomRangeMin->value(), + _ui.spinCustomRangeMax->value()); +} + +void +WidgetPresentationParameters::onSpinboxScaleFactorChanged() +{ + if (!_blockSig) emit spinboxScaleFactorChaged(_ui.spinScaleFactor->value()); +} + +void +WidgetPresentationParameters:: +onCheckboxHideDataOutsideCustomRangeChanged(int flag) +{ + if (!_blockSig) emit checkboxHideDataOutsideCustomRangeChanged(flag); +} + +void +WidgetPresentationParameters:: +onCheckboxCustomScaleFactorChanged(int flag) { + if (!_blockSig) emit checkboxCustomScaleFactorChanged(flag); +} + void WidgetPresentationParameters::onSpinBoxEditingFinished() { if (!_blockSig) emit spinBoxValueChanged(_ui.spinBox->value()); } +void +WidgetPresentationParameters::onSpinNormalEditingFinished() +{ + if (!_blockSig) emit spinNormalValuesChanged(_ui.spinNormalX->value(), + _ui.spinNormalY->value(), + _ui.spinNormalZ->value()); +} + +void +WidgetPresentationParameters::onSpinCutPoint1EditingFinished() +{ + if (!_blockSig) emit spinCutPoint1ValuesChanged(_ui.spinPoint1_X->value(), + _ui.spinPoint1_Y->value(), + _ui.spinPoint1_Z->value()); +} + +void +WidgetPresentationParameters::onSpinCutPoint2EditingFinished() +{ + if (!_blockSig) emit spinCutPoint2ValuesChanged(_ui.spinPoint2_X->value(), + _ui.spinPoint2_Y->value(), + _ui.spinPoint2_Z->value()); +} + +void +WidgetPresentationParameters::onSpinPlanePosEditingFinished() +{ + if (!_blockSig) emit spinPlanePosValueChanged(_ui.spinPlanePos->value()); +} + +void +WidgetPresentationParameters::hidePlot3D() +{ + _ui.labelCutPlanePosition->hide(); + _ui.spinPlanePos->hide(); +} + +void +WidgetPresentationParameters::hideContourComponent() +{ + _ui.labelContourComp->hide(); + _ui.comboBoxContComp->hide(); +} + void WidgetPresentationParameters::toggleCommonFieldWidget(bool show) { @@ -116,6 +277,26 @@ WidgetPresentationParameters::toggleWidget(bool show) _ui.spinBox->hide(); _ui.labelSliceOrient->hide(); _ui.comboBoxSliceOrient->hide(); + _ui.labelCutPlaneNormal->hide(); + _ui.labelCutPlanePosition->hide(); + _ui.spinNormalX->hide(); + _ui.spinNormalY->hide(); + _ui.spinNormalZ->hide(); + _ui.spinPlanePos->hide(); + _ui.labelIntegrDir->hide(); + _ui.comboBoxIntegrDir->hide(); + _ui.labelPoint1->hide(); + _ui.spinPoint1_X->hide(); + _ui.spinPoint1_Y->hide(); + _ui.spinPoint1_Z->hide(); + _ui.labelPoint2->hide(); + _ui.spinPoint2_X->hide(); + _ui.spinPoint2_Y->hide(); + _ui.spinPoint2_Z->hide(); + _ui.labelContourComp->hide(); + _ui.comboBoxContComp->hide(); + _ui.checkBoxScaleFactor->hide(); + _ui.spinScaleFactor->hide(); _blockSig = false; } } @@ -224,15 +405,17 @@ WidgetPresentationParameters::setScalarBarRange(MEDCALC::ScalarBarRangeType sbra else if (sbrange == MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP) idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_CURRENT_TIMESTEP")); - if (idx >= 0) - { - _ui.comboBoxScalarBarRange->setCurrentIndex(idx); + if (idx >= 0) { + _ui.comboBoxScalarBarRange->setCurrentIndex(idx); + _ui.checkBoxCustomRange->setChecked(false); } - else - { - STDLOG("Strange!! No matching found - unable to set scalar bar range in GUI."); + else { + if (sbrange == MEDCALC::SCALAR_BAR_CUSTOM_RANGE) { + _ui.checkBoxCustomRange->setChecked(true); + } else { + STDLOG("Strange!! No matching found - unable to set scalar bar range in GUI."); + } } - _blockSig = false; } @@ -295,6 +478,65 @@ WidgetPresentationParameters::setMeshMode(MEDCALC::MeshModeType mode) _blockSig = false; } +void +WidgetPresentationParameters::setIntegrationDir(MEDCALC::IntegrationDirType iDir) +{ + _blockSig = true; + + // Show the widget; + _ui.labelIntegrDir->show(); + _ui.comboBoxIntegrDir->show(); + + int idx; + switch(iDir) + { + case MEDCALC::INTEGRATION_DIR_BOTH: + idx = _ui.comboBoxIntegrDir->findText(tr("LAB_INTEGR_DIR_BOTH")); + break; + case MEDCALC::INTEGRATION_DIR_FORWARD: + idx = _ui.comboBoxIntegrDir->findText(tr("LAB_INTEGR_DIR_FORWARD")); + break; + case MEDCALC::INTEGRATION_DIR_BACKWARD: + idx = _ui.comboBoxIntegrDir->findText(tr("LAB_INTEGR_DIR_BACKWARD")); + break; + default: + idx = -1; + } + if (idx >= 0) + { + _ui.comboBoxIntegrDir->setCurrentIndex(idx); + } + else + { + STDLOG("Strange!! No matching found - unable to set integration direction in GUI."); + } + + _blockSig = false; +} + +void +WidgetPresentationParameters::setContourComponents(std::vector compos, int selecIndex) +{ + _blockSig = true; + + // Show the widget; + _ui.labelContourComp->show(); + _ui.comboBoxContComp->show(); + + _ui.comboBoxContComp->clear(); + bool vectorField = (compos.size() > 1 && compos.size() <= 3); + if (vectorField) + _ui.comboBoxContComp->addItem(tr("LAB_EUCLIDEAN_NORM")); + for (vector::const_iterator it = compos.begin(); it != compos.end(); ++it) + _ui.comboBoxContComp->addItem(QString::fromStdString(*it)); + if (!vectorField) + _ui.comboBoxContComp->setCurrentIndex(std::max(0, selecIndex - 1)); + else + _ui.comboBoxContComp->setCurrentIndex(selecIndex); + + _blockSig = false; +} + void WidgetPresentationParameters::setSliceOrientation(MEDCALC::SliceOrientationType orient) { @@ -392,10 +634,39 @@ WidgetPresentationParameters::getMeshMode() const return MEDCALC::MESH_MODE_WIREFRAME; } +MEDCALC::IntegrationDirType +WidgetPresentationParameters::getIntegrationDir() const +{ + QString iDir = _ui.comboBoxIntegrDir->currentText(); + if (iDir == tr("LAB_INTEGR_DIR_BOTH")) { + return MEDCALC::INTEGRATION_DIR_BOTH; + } + else if (iDir == tr("LAB_INTEGR_DIR_FORWARD")) { + return MEDCALC::INTEGRATION_DIR_FORWARD; + } + else if (iDir == tr("LAB_INTEGR_DIR_BACKWARD")) { + return MEDCALC::INTEGRATION_DIR_BACKWARD; + } + // Should not happen + STDLOG("Strange!! No matching found - returning LAB_INTEGR_DIR_BOTH."); + return MEDCALC::INTEGRATION_DIR_BOTH; +} + +std::string +WidgetPresentationParameters::getContourComponent() const +{ + if (_ui.comboBoxContComp->count() > 1 && _ui.comboBoxContComp->count() <= 4) + if (_ui.comboBoxContComp->currentIndex() == 0) // Euclidean norm + return ""; + return _ui.comboBoxContComp->currentText().toStdString(); +} MEDCALC::ScalarBarRangeType WidgetPresentationParameters::getScalarBarRange() const { + if (_ui.checkBoxCustomRange->isChecked()) { + return MEDCALC::SCALAR_BAR_CUSTOM_RANGE; + } QString sbrange = _ui.comboBoxScalarBarRange->currentText(); if (sbrange == tr("LAB_ALL_TIMESTEPS")) { return MEDCALC::SCALAR_BAR_ALL_TIMESTEPS; @@ -449,3 +720,132 @@ WidgetPresentationParameters::setPresName(const std::string& name) f.setItalic(true); _ui.labelPresName->setFont(f); } + + +void +WidgetPresentationParameters::getScalarBarRangeValue(double* arr) const +{ + arr[0] = _ui.spinCustomRangeMin->value(); + arr[1] = _ui.spinCustomRangeMax->value(); +} + +void WidgetPresentationParameters::setScalarBarRangeValue(double aMin, double aMax) { + _blockSig = true; + _ui.spinCustomRangeMin->setValue(aMin); + _ui.spinCustomRangeMax->setValue(aMax); + _blockSig = false; +} + +void WidgetPresentationParameters::setScaleFactor(double scale) { + _blockSig = true; + + // Show widget: + _ui.checkBoxScaleFactor->show(); + _ui.spinScaleFactor->show(); + + _ui.spinScaleFactor->setValue(scale); + _blockSig = false; +} + +void WidgetPresentationParameters::getNormal(double* arr) const +{ + arr[0] = _ui.spinNormalX->value(); + arr[1] = _ui.spinNormalY->value(); + arr[2] = _ui.spinNormalZ->value(); +} + +void +WidgetPresentationParameters::setNormal(const double normX, const double normY, const double normZ) +{ + _blockSig = true; + _ui.labelCutPlaneNormal->show(); + _ui.spinNormalX->show(); + _ui.spinNormalY->show(); + _ui.spinNormalZ->show(); + _ui.spinNormalX->setValue(normX); + _ui.spinNormalY->setValue(normY); + _ui.spinNormalZ->setValue(normZ); + _blockSig = false; +} + +void WidgetPresentationParameters::getCutPoint1(double* arr) const +{ + arr[0] = _ui.spinPoint1_X->value(); + arr[1] = _ui.spinPoint1_Y->value(); + arr[2] = _ui.spinPoint1_Z->value(); +} + +void +WidgetPresentationParameters::setCutPoint1(const double x, const double y, const double z) +{ + _blockSig = true; + _ui.labelPoint1->show(); + _ui.spinPoint1_X->show(); + _ui.spinPoint1_Y->show(); + _ui.spinPoint1_Z->show(); + _ui.spinPoint1_X->setValue(x); + _ui.spinPoint1_Y->setValue(y); + _ui.spinPoint1_Z->setValue(z); + _blockSig = false; +} + +void WidgetPresentationParameters::getCutPoint2(double* arr) const +{ + arr[0] = _ui.spinPoint2_X->value(); + arr[1] = _ui.spinPoint2_Y->value(); + arr[2] = _ui.spinPoint2_Z->value(); +} + +void +WidgetPresentationParameters::setCutPoint2(const double x, const double y, const double z) +{ + _blockSig = true; + _ui.labelPoint2->show(); + _ui.spinPoint2_X->show(); + _ui.spinPoint2_Y->show(); + _ui.spinPoint2_Z->show(); + _ui.spinPoint2_X->setValue(x); + _ui.spinPoint2_Y->setValue(y); + _ui.spinPoint2_Z->setValue(z); + _blockSig = false; +} + +double WidgetPresentationParameters::getPlanePosition() const +{ + return _ui.spinPlanePos->value(); +} + +void WidgetPresentationParameters::setPlanePosition(double pos) +{ + _blockSig = true; + _ui.labelCutPlanePosition->show(); + _ui.spinPlanePos->show(); + _ui.spinPlanePos->setValue(pos); + _blockSig = false; +} + +bool WidgetPresentationParameters::getScalarBarVisibility() const { + return _ui.checkBoxShowScalarBar->isChecked(); +} + +void WidgetPresentationParameters::setScalarBarVisibility(const bool visibility) { + _blockSig = true; + _ui.checkBoxShowScalarBar->setChecked(visibility); + _blockSig = false; +} + +bool WidgetPresentationParameters::getHideDataOutsideCustomRange() const { + return _ui.checkBoxHideDataOutsideCR->isChecked(); +} + +void WidgetPresentationParameters::setHideDataOutsideCustomRange(const bool flag) { + _blockSig = true; + _ui.checkBoxHideDataOutsideCR->setChecked(flag); + _blockSig = false; +} + +void WidgetPresentationParameters::setScaleFactorFlag(const bool flag) { + _blockSig = true; + _ui.checkBoxScaleFactor->setChecked(flag); + _blockSig = false; +} \ No newline at end of file diff --git a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx index 32aef3d29..7531fe2a6 100644 --- a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx +++ b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.hxx @@ -48,6 +48,41 @@ public: MEDCALC::ScalarBarRangeType getScalarBarRange() const; void setScalarBarRange(MEDCALC::ScalarBarRangeType); + MEDCALC::IntegrationDirType getIntegrationDir() const; + void setIntegrationDir(MEDCALC::IntegrationDirType); + + std::string getContourComponent() const; + void setContourComponents(std::vector compos, int selecIndex); + + bool getScalarBarVisibility() const; + void setScalarBarVisibility(const bool); + + bool getHideDataOutsideCustomRange() const; + void setHideDataOutsideCustomRange(const bool); + + void getScalarBarRangeValue( double* ) const; + void setScalarBarRangeValue(const double, const double); + + double getScaleFactor() { return _ui.spinScaleFactor->value(); } + void setScaleFactor(double); + + bool getScaleFactorFlag() { return _ui.checkBoxScaleFactor->isChecked(); } + void setScaleFactorFlag(const bool); + + void getNormal( double * ) const; + void setNormal(const double, const double, const double); + + void getCutPoint1( double *) const; + void setCutPoint1(const double, const double, const double); + void getCutPoint2( double *) const; + void setCutPoint2(const double, const double, const double); + + void hidePlot3D(); + void hideContourComponent(); + + double getPlanePosition() const; + void setPlanePosition( double ); + // double getScalarBarTimestep() const; // double getScalarBarMinVal() const; // double getScalarBarMaxVal() const; @@ -70,13 +105,31 @@ public: void toggleCommonFieldWidget(bool show); + QComboBox* getRangeComboBox() { return _ui.comboBoxScalarBarRange; } + double getMixCustomRange() { return _ui.spinCustomRangeMin->value(); } + double getMaxCustomRange() { return _ui.spinCustomRangeMax->value(); } + signals: void comboScalarBarRangeIndexChanged(int); void comboColorMapIndexChanged(int); void comboCompoIndexChanged(int); void comboOrientIndexChanged(int); void comboMeshIndexChanged(int); + void comboIntegrDirIndexChanged(int); + void comboContCompIndexChanged(int); void spinBoxValueChanged(int); + void spinNormalValuesChanged(double, double, double); + void spinCutPoint1ValuesChanged(double, double, double); + void spinCutPoint2ValuesChanged(double, double, double); + void spinPlanePosValueChanged(double); + void checkboxScalarBarVisibilityChanged(int); + void checkboxCustomRangeChanged(int); + void checkboxScaleFactorChanged(int); + void spinboxCustomRangeChanged(double, double); + void spinboxScaleFactorChaged(double); + void checkboxCustomScaleFactorChanged(int); + void checkboxHideDataOutsideCustomRangeChanged(int); + private slots: void onComboScalarBarRangeIndexChanged(int); @@ -84,10 +137,22 @@ private slots: void onComboCompoIndexChanged(int); void onComboOrientIndexChanged(int); void onComboMeshIndexChanged(int); + void onComboIntegrDirIndexChanged(int); + void onComboContCompIndexChanged(int); void onSpinBoxEditingFinished(); - + void onSpinNormalEditingFinished(); + void onSpinCutPoint1EditingFinished(); + void onSpinCutPoint2EditingFinished(); + void onSpinPlanePosEditingFinished(); + void onCheckboxScalarBarVisibilityChanged(int); + void onCheckboxCustomRangeChanged(int); + void onCheckboxScaleFactorChanged(int); + void onSpinboxCustomRangeChanged(); + void onSpinboxScaleFactorChanged(); + void onCheckboxCustomScaleFactorChanged(int); + void onCheckboxHideDataOutsideCustomRangeChanged(int); private: - Ui_WidgetPresentationParameters _ui; // instance of the class defined in ui_WidgetPresentationParameters.h + Ui_WidgetPresentationParameters _ui; // instancte of the class defined in ui_WidgetPresentationParameters.h bool _blockSig; }; diff --git a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.ui b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.ui index d4500e896..88846dca9 100644 --- a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.ui +++ b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.ui @@ -6,14 +6,14 @@ 0 0 - 784 - 584 + 319 + 527 300 - 200 + 310 @@ -30,31 +30,34 @@ - - + + true - LAB_ALL_TIMESTEPS + LAB_BLUE_TO_RED - LAB_CURRENT_TIMESTEP + LAB_COOL_TO_WARM - - + + + + + - LAB_COLOR_MAP + LAB_HIDE_DATA_OUTSIDE_CR - + @@ -67,23 +70,63 @@ - - + + + + LAB_CUSTOM_RANGE + + + + + + + LAB_COLOR_MAP + + + + + + + 9999999999999999583119736832.000000000000000 + + + 0.500000000000000 + + + 100.000000000000000 + + + + + true + + + 0 + 0 + + - LAB_BLUE_TO_RED + LAB_ALL_TIMESTEPS - LAB_COOL_TO_WARM + LAB_CURRENT_TIMESTEP + + + + LAB_SHOW_SCALAR_BAR + + + @@ -104,7 +147,7 @@ - + @@ -130,7 +173,7 @@ - + @@ -146,7 +189,7 @@ - + LAB_SPINBOX_TOOLTIP @@ -159,27 +202,45 @@ - - - - Qt::Horizontal - - - - 235 - 20 - + + + + LAB_CONTOUR_COMP - + - + + + + + LAB_CONTOUR_MAGN + + + + + LAB_CONTOUR_X + + + + + LAB_CONTOUR_Y + + + + + LAB_CONTOUR_Z + + + + + LAB_SLICE_ORIENT - + @@ -218,6 +279,150 @@ + + + + LAB_CUT_PLANE_NORMAL + + + + + + + 0.050000000000000 + + + + + + + 0.050000000000000 + + + + + + + 0.050000000000000 + + + + + + + LAB_CUT_PLANE_POS + + + + + + + 0.100000000000000 + + + + + + + LAB_INTEGR_DIR + + + + + + + LAB_INTEGR_DIR_BOTH + + + 0 + + + + LAB_INTEGR_DIR_BOTH + + + + + LAB_INTEGR_DIR_FORWARD + + + + + LAB_INTEGR_DIR_BACKWARD + + + + + + + + LAB_CUT_POINT1 + + + + + + + 0.010000000000000 + + + + + + + 0.010000000000000 + + + + + + + 0.010000000000000 + + + + + + + LAB_CUT_POINT2 + + + + + + + 0.010000000000000 + + + + + + + 0.010000000000000 + + + + + + + 0.010000000000000 + + + + + + + 0.020000000000000 + + + + + + + LAB_SCALE_FACTOR + + + diff --git a/src/MEDCalc/res/presentations/classic/visu_cutsegment16.png b/src/MEDCalc/res/presentations/classic/visu_cutsegment16.png new file mode 100644 index 0000000000000000000000000000000000000000..0aea43f3096676f6964c77a7b99a34934f89a82f GIT binary patch literal 466 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkP>?0v z(btiIVPjv-@4(4GzCyA`kS_y6l_~>6Lo)-z&;LOBB?CjL0RzLU1O^7H84L{K`IF+0 zx-l>?dU(1xhE&{2`t$$4J+mr9bQH`kL&2{%Rt#v@JV8~)etGphOX zq4DAK{`D4D8CV2_nOlLDb4WR8%mwoP8T|O%`tb4bexCjHHOE)70j+2|IJ;b4Qf^=M zi4Si-yU)pDVB%QL7{9M3vEsuU>%))t_e<`p|J`$$p@HF0=7DB*eu;PXf6smR@;d8@mWS8BzyJSH5W9dw&kiTa8HH0CLpTJYom=~uK1wb4 xwfn>?pbhZ~O-=t41wK3eb9)dxdHTqw zwuy(&ZLGZ|y56OqphZa6-JQNzU-tp1F$WEeHEn0w719^fqKHrCLK58o_JB)U0eX$1 zZp~>Lcp*0?GGNvUw6x=2wQ~v#kK)+O##c zIigrhh>nlR7YXQA4GPFsfQ{J>)8#bflxm$(RV5g0-IuY@(KWDxTOc7~!5Ztfu2)@N zfQ<=Q5v(Yza(D0io&W?9b++U`iRT8eF0FtAh`%)c0GE4nDFPHqWb^LZyQdq!M9TFst&XU8witd!gMx+>C9`|MkU(cfA%Vm4)4dGd6<>mUbXvXHqZNtGA)2` ztVo|Kt^qfJ$H0T(1Z#k=zya_c`1sEq3|0f5hQ#iGaeFidz5)5R9b6o)tH916iCgaq fNC$v>{?mXTn}hm#$*(=p00000NkvXXu0mjftpXHP literal 0 HcmV?d00001 diff --git a/src/MEDCalc/res/presentations/classic/visu_plot3d16.png b/src/MEDCalc/res/presentations/classic/visu_plot3d16.png new file mode 100644 index 0000000000000000000000000000000000000000..fb5f6dbf4bdf5545c14f70bf60ce9f7164f7b209 GIT binary patch literal 986 zcmV<0110>4P)z@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZ9i|Q-fItQ)1F--Q z%OH$pVtDxN6NAXT7Yw`)UNGoA`@#_PhT+fMyLXM5n3$FWRRqG60t65X5cdGFI1ujy z3H$?ME0a22CdU6O{{CmQWBv1kA>j3XP*0;i__~D8!OM(e{4KGJn>)lJmBLn{>042_4#J+yLayf0N_I}j5KU-e<Mnx?*b?UivUF%>M4o!2bTD%bSM+E`Jz~GYE0K z*$)sva0BLx8nC`+V4A7@_R`@+p|ZoMu8)6b6#7X_pkj&Lb4 zmPJjS{8}R@2@8t~t{ssT|_k-aZ%U_0npZ_vgY+b~l^Y0hKr+pwB4BpyH^;Ak4qvX=(O@8$fN=009IxAU}^$`}gwGcfH3`h6`2!#jpA z4DWxlGJFIk)NlX(F#P<%%D|@bm_b(X=$lD>pYHtn^&h17H9!D?4bV1xBg(-0gW*5x zcZSch>pzBX-~TfF`1zmV*Ec4H`#-%ZSV zy#Mkt+pTBMo<0BY;lr=LfB*6T zF(V{JGyP*_W&O>>def{AOmj$1Q5st4}b<3{{H! z>yI5}9mhY8Y$t0i3u?TZ!sc?N!2LP zXri&N@PbN=Bv>N0A{3~NRcHfLV9P=;xa?APTXwf+FWo)2nKPH?dCW|=>Kpz5f62U= zJoEkjF5l<-8~*P@jE;`B0gnTJ1@KY-IF$=MvM>hCo-{v~BNZkl;|dv79}Ef55i6#Qz)Bx@zP*>(B3HnuGq*8bPD8fZjOU~Bma zDaG@?Z(tf0%>^rM(N}@D!8o9`emD$QF-?bofn78=uOp7@DS;NkP9CMDox!(<+Fbj~ z>v~_>qtuU=N+oKRnayQeGQQ{1*{SL4UtwWkHm%@wpbF}u)^gr3GPD-1C7W$c`)*2! zsnsrxdcY+@qM29C3{+xpykK@=?$pV#*Y9oLIQ)Iz?#&lk1$TXZk=61ThYntuL1Aqc zPLgd)aWj3J?&Nt{G;WG(@V=t zoc{U)F1zno;V;iZ99{wDsx(6xBAs^J;xHl#3=eiMwzYkCz9~PVl%{jJN>e3dtbd64 zs>%AZ0k^l5H~b*ecHeixmHoGUHsGEw2IR94`2SVWf8_U`VbkfAxa;EIkZz0mRqvMj zf4y$QNO~$x1YO{h)+~E(JxKQ*6IhdHAbz2L-#icYEyMQDF~04F6wb~!Q56QSqy!SE zp&7CZ+@}TG7G8mt;`&b&^G@qRNOxt0xAGnQw*5Mu(bti&j`GpsEGIrVfD?X!!7b$` zs`;P1xZJGd?3-pWeyMi&&pZ`{oJ$EjrMcuQ_FA2cx_ywdH=yFjc26GPzT5L*d5NXo zA?z)?`DHc7i{l?=Tz`m095ZjaV0A&{m~_mTKVAAErygVMz@PXX&}=CsNbX|B)ndJ6 zL#1hm!1@hF@DWrQqAFCXbd+A^p*P>)d%j}Hv#5ufOry$kty|c)c`w`mU+aE|8R?D3vg3Gj!{af{1A(_7OJt z^y&=j2i{?B@FM>>a$^3u!^{J%z^3F@TVY5nFrpoU;cYD=)3?yx*cFQ!W-Ue>=!SpV zXjUi(5moY3m4l}xfrdy4IyZR?Zv6vCjQd5rUq}Iq|Hoys!T5X~zqE?%f=;`S6IJIMkcnh6^zwG#A3I zu5OvjIT(h~X4`hrG|jDAYg0;D@O}S!rIewRN(TL8BGZ~u>cPbLY}+=1dfhBdPv^AO z$z@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZ;^hrcPRCwBAbai!QAOLiLSPh69vB(Jm1P}`W%`Th* zY?JupcwdEuDk%6WaWFji!o=|5H&EvPx36WnXWsz?5IzHZg_ZeBl-#A&tR&eqtz-ol zPP}Di=zV9)u0G8;qF%v=WPJC_+YvT=T# z&%(*_9~cUZjEq760ffx}XKpDr$*;e@2rG#QFq}KW!caFgo8j4`+h6)wIGFDL{Ppg~ zpFb~{n3%q^{Qi9%Ab^k!U7o|K9oc@85Nx+UG$06d-_L2Iv8?hqR@zlbAY(t*1OAlZ*fl!-qZ37@og;`nCVp zpYI>PemxA-cmb&HED+xT;`c!O10aAv2Dt0%2v1Pb6nHAB&1xT@%EWN{Jrje^MSq6$ z1%(XFKfkfO|NMC`P~B-DJ`BXSfcOhA0saBm3=lvd1E#fyye4F)5|10bNZ`=pJ%QCEZ zr^{e}co{>=s$PcjAK!W2e)_ZosOA(%Gf?9<^biLKAaEEoym4WC$H>ZHdUgjx%Yifo z$-7q>_I&yL;n%sH8QZUy!!F;)wl28k3jv7 z({>O52q2IFd^xgm@1H$;_W%9+_n&|M{CW4!pFdas|NnmmD0dQwU*obJ1ONgI0I_H! Ud%`OR!vFvP07*qoM6N<$f>W29AOHXW literal 0 HcmV?d00001 diff --git a/src/MEDCalc/res/presentations/classic/visu_streamlines24.png b/src/MEDCalc/res/presentations/classic/visu_streamlines24.png new file mode 100644 index 0000000000000000000000000000000000000000..53e969bd41dab6345a602283f217be8789670eaf GIT binary patch literal 1307 zcmV+$1?2jPP)Vs?tHyu?2*)|n4RCsWbNoHQY-}nEY@0;QO zzJ#Ygb?Vgr#t6^?3@!3asZ5=bOS??}i`wv!izK663^azJL0VYC*lqdbOIE*{8bq(K zHUyT!G#t4|+qyV9y!7d@&sIgIRTzZq7^RtR%2DJ5yZC;e%X^=<4(_^k&FCK>yxX%4 z!qK5zVJwJ`Dtzbs@B(B0_+sXdj9`ik(jLHP9YZ;n8OVTqhqgZf@{QlADgZMCFvP8v^@gnlm6F`oHLXVeYG*LTyT(n-f=SR;N!j|1Y^+S8Omd(@9}T0n56FGH%n) zY}~YzMj2(E>6fP*yAvr>XnhE{0Cb^sRQ5c#^#Kf1AhU%PB52DAx-7V1_vG-9spXoL z0l}UDli0BT0e;`Q65EY3SDW&b>s&^26s=o;M&K;a3?zWK2g?F{p19V+aFu1G)cEc} zp>MCgP&MSKVHR(QHmU+S)W!!>y7MT}*ahA)Ont)9ji{{a6F>uS1@J(fkoD>dD}YHXJUGvG|r*aAN1_mgPiUa zcK;dmEFc~it81rMJX29qR%MmJv`Uj9nIuRbE8J16zWO*bcKt$e*GcNV_9=A<*bjJ+ zlR)flUCIK4Pro*6Mo5etR{$MRWE8$kR}cV+!#}acFywWmnteAGCuAHr8->$*`D)u*s;?elIVM`lb~N4uP5rIqUjQW}v~)mO61stdd)cz} zQ%1BlV#_!mDU%J-?Lg~adsA~0ul)2|A0J?` zDV2_*R6Sa62Y%~K%{>9K6F9y+YFnCku=Oms4)rE1&IwX4B@G$710|1V3)NGkmU|WN z14u+>3U~l7G2U7{=l3NJ@E7}5KtXVf R$22^E}Ucj(GU!_EX@V3=OJInfJq= zS@Z(Z)gyrW9MlMK2YAIHVFIb0b_Hd}sd)Dh4p4f5p|k0#XiGvhcGzJW0A(#DMt+l} zfdQu5hv+I)3ETv3@GJ`@ESzXYOHlGq0E}XZLQfAKRZs>lA68bQ02x^F5r)aoMfZ=N7M$tio*&? zz>>BuS<6-*Y<`0j-Oj#%vwMY6lDOk`$Wq%tr!@97aOpxMfncFVzGjpk~|l8r$N@gBx$x?XL8;Y(2SP zH?t~SF2vV4>IRgZMjbjlo_=|jn_Tk&bR``vHg%jw~b8<=JQ0000#LA zw{>1Ue8eHyAdAuQfRl&g$B$n>aQyw8`zk{~kl!rcq?LW{`hS_nE~a=rwV3f!e&w2* z20p=pMnCH3Grmi9b7ebrF~sG+g#(-YH;)64n-4!_RsLJ^;Kl~oywCqGdblz5EHQ~b d!N|bK#vr7v^zeXtnG(<$44$rjF6*2UngCbsSo8n@ literal 0 HcmV?d00001 diff --git a/src/MEDCalc/res/presentations/modern/pqPlotOverLine16.png b/src/MEDCalc/res/presentations/modern/pqPlotOverLine16.png new file mode 100644 index 0000000000000000000000000000000000000000..8ab5e2f65b5f84df50a50cd8cf7833cd8cddaa92 GIT binary patch literal 964 zcmV;#13UbQP)1vJX7(^UyFI!sltPNMO3?OYwLsSl5)$Hh=qKBQx>i80FONyF}^b;3cd6)=6&H*#QM_UJ3>c&x2lb52KAelRd9M~rbKe(>2f*zB>Scr;(9PxoN4)-kw zOQxfGmL2V5C<0cNWO<@%6O7(u&)PRX!BM)U;>mInl3|qvb?zqo95_=CN+I#XqvTN`86Z`aCTMuS3~o$aHn zD##Lv1=;=i1~xSO%jxF_xjG&szK|LWuxQTf8WI8f?{G9w^K;)488ramB(Jti(a|(X zz+NFz?yDSBLuhj9(v|bS{L{H`xQ-E(XB!Uwv?4j>>pW8_ z{IX?(>)eYgFpPAhsA$=^lz-VgpwMd(_C-#AIQqyBTy40(s^0EuU(f!Y8-?iDWN>iq m`6|G1Py>Z{J$~Fg6Zj7@$&kpBRIdgA0000?H_auiO0B5m8{)6$E{SX?* z)(ZJU=Zlb=gz{;sQb`hhrlSw(+2r4Vi;C=PQ55fGA$%_L+EBnQptGx zEuY!qD0YPny>jyo%;Ydl4O8m zXj;ziu1(WG2tgoNL^x7`N0E@M9HS{s9KJ5kUs%yO|I5L1>(;k7{sy^OEiKzYNq^>j zNfX~u3$1fekxV0uytTJIFdYZOahzLz1Ga5r>l!*5*iaKyd2pJ|miA*a0`D z1-`iSeBkMZFxQS(O)ofo<6n`*ajtr5{)1k81ljnVJom|J9LJV~P@bPWxi;wada-Q_ zNdmveraG+hTKg1s?60T3dYlz?1H9J~C7uJW`ROh<+5CtfYgz@7;xG?XmGa9AtE(BS zT8=L@PkhS20^7p5E1+RXsD?~wp~kugN1!*v3vWKk_K&KdB*!BS!~FR9511QG(>th< z9nCSnxsX_-272m1v0QUUZv)tl3zr6LyK zgTKsXY9z-S%Q}hYywsPaID1K9+n!}G<==-0j8vgkY*6m{?U*hD)0PN$ps_X%HREt# z28|^Pom%+5698Vspfuxs1U;CI<2|pAVV9Id0giU)EaA?aZjz4pb&apx!6>99e zQo&n07s2W-c24>`Cq9|owldPfqWTVmC0p3Cjbo#`x>tr(e&lL?q=r?$T?DoS6Mjyt zZR4ru&gb=S?JJ@uQNXOSG;f@*=B=Gypnh!!r&pe*bs%J!qTuqFQ9?k@B1*d}aakZ+ zX2hqn?&vH6ibd1LHW&!r+O;iJEZ@73ZH?FY$2Z%E7MRpVv;5@rboTF_OY{1V+1=dD z*&abMoxbT+lwnu&tQ9~M^cU3yM~YB=YOW-pa&<7o&t89=V?9M6J3PB!fToSD&>!M> zM>!c?X5Qok8;;H3Eg`$#he=q(Z1#a z*G7W~VX=JoBDh$_>swFLP?n~BD2yT;BuQZC8rk$XitOpS2VivS5SC&(=_v)>k&|7u zFKK_Ic|{Eq3;O686kHe%Q64mC-t{Q-M)>uMry&5ZCn8o0rVD&3cKtSi8-#d+JD)deG@VbZcPVskH zWRhdpmf3l`-QNS?ZY$XnGVIs^b{$;G!Qr(qRshBcUVVHYr_M%*rTxgla(4-mee1u# zogewNBw?so0)a@&J=s6YAmUZGU5i_<9lZF&t0c=;;4>&~=z1y^YiqrpeyCU$jwuk9 z+u9w;F=)4(vh+%bWfPQG^7VN}!;Zde=obf|4>sBrmLyj)*|I z@XCaVFuKr6DGA+}ApXINFpAU|GltWOxt(^-E5E}}Fq%H_yg%NT_xV20_xXN*q5s`2 zQY^s~!gT z7Ro74M1T`%%ualc9#n7-*RdPd@EYF0lc+yD!4(W*1CEAzF;Eo6Oi{{uLhb-A;A`x` znfWLTpjWWUOtW)#!Q5xfO3_uG%D>Bt(gtPED}0cq7)cbS6TRaR;3M2NT`X<%W|unG z^j5pOy4)QbUpq5)r!{5FVxf!#h|Qa#NLh<*V7z$@foH zPgZM-pD;Q4n{cDCJ9M_XN1$!k{GeB=9V#UQ^@Wbm?~l2a6GK0LI9_gcl>W}X&-2n@ zne~d62d0xVe@Pzbz^@TtCq7mf(UuLD>fsBs*(Ig$s@#aeOL&i#r1Mf(hC^wR{h=HV z5~7X&#Cfbv|GtS=us9hh)(*$VI$An^lg=sB@E4xJ5v;%x{E&bng&1uSAo~0#?83Ln z!oSD8q-EVqc8x}zu{+^vpo0p>i0000e!E zK?^bpK`LPpWOE1IkuJj!Ud=?KiDx|boVkxPR%KaYmQC3cJJHq}4I%Xw^$nixQSa;V zQ}X5OlK{x@CJm7=+GoSCz(&+l-3jc+y#UNOVFM%nuQv~@lle4s_;faj9`ChVUjyti zb8R>w!)G+tU}J$`-7}2Ex^d-QEmRiEHVv_0c#9E}`0Uu{d|!#Hn|#(`j#iD#cdBv3LfvoydCZwL(|6Bo}%P>g|cg3MaCfsFg?Kqsy` z*z*EJOKl&1;6oQ;elWyv|NJ^#WonAdYC7Vk!D2he+Sl1?r-sJLJJc86phSUue2Cxs zzX;@CmjFIKrqHU^b93&sLanxl<(F^Kc=Z8Ac}dl%aQZ&i0G-E5Mb$M~Q5AT~!@Tzb zmxV{q)amz>W&>oCyu|2qh?9jsP)gAW3JfofuH(Sz`)sk>s|J;5WxbC2YMo+G;_uI6 zieK)!DpY5c6g|$eR0w0t z!gw~-MV!wupTy{Y$^tiFR~T^v%St@WurmhCFk(Y4pWcv?`@~Lr!o(n!axFHsgzNfZ z?cs9$%nK*u_}zWs2m{;fp4NZ8GG~72&-%0FN`L_X`IsQWm(ku800000NkvXXu0mjf D2Awob literal 0 HcmV?d00001 diff --git a/src/MEDCalc/tui/__init__.py b/src/MEDCalc/tui/__init__.py index 52fd7602a..232d50205 100644 --- a/src/MEDCalc/tui/__init__.py +++ b/src/MEDCalc/tui/__init__.py @@ -59,6 +59,9 @@ from .medpresentation import MakeSlices from .medpresentation import MakePointSprite from .medpresentation import RemovePresentation from .medpresentation import MakeDeflectionShape +from .medpresentation import MakePlot3D +from .medpresentation import MakeStreamLines +from .medpresentation import MakeCutSegment from .medpresentation import GetMeshViewParameters from .medpresentation import GetScalarMapParameters @@ -67,6 +70,9 @@ from .medpresentation import GetSlicesParameters from .medpresentation import GetPointSpriteParameters from .medpresentation import GetVectorFieldParameters from .medpresentation import GetDeflectionShapeParameters +from .medpresentation import GetPlot3DParameters +from .medpresentation import GetStreamLinesParameters +from .medpresentation import GetCutSegmentParameters from .medpresentation import UpdateMeshView from .medpresentation import UpdateScalarMap @@ -75,8 +81,12 @@ from .medpresentation import UpdateSlices from .medpresentation import UpdateVectorField from .medpresentation import UpdatePointSprite from .medpresentation import UpdateDeflectionShape +from .medpresentation import UpdatePlot3D +from .medpresentation import UpdateStreamLines +from .medpresentation import UpdateCutSegment from .medpresentation import ComputeCellAverageSize, GetDomainCenter, GetSliceOrigins, SelectSourceField +from .medpresentation import IsPlanarObj, GetPositions, GetPlaneNormalVector, FindOrCreateView # Processing from .medprocessing import ChangeUnderlyingMesh diff --git a/src/MEDCalc/tui/medevents.py b/src/MEDCalc/tui/medevents.py index 01e803d4a..939696de5 100644 --- a/src/MEDCalc/tui/medevents.py +++ b/src/MEDCalc/tui/medevents.py @@ -120,6 +120,9 @@ def notifyGui_removePresentation(presId): # def notifyGui_modifyPresentation(presId): __notifyGui(MEDCALC.EVENT_MODIFY_PRESENTATION, presentationId=presId) +# +def notifyGui_visibilityChanged(presId): + __notifyGui(MEDCALC.EVENT_VISIBILITY_CHANGED, presentationId=presId) def notifyGui_playQtTestingScenario(filename): __notifyGui(MEDCALC.EVENT_PLAY_TEST, filename=filename) diff --git a/src/MEDCalc/tui/medpresentation.py b/src/MEDCalc/tui/medpresentation.py index ebd2c1cbc..487f7f7b0 100644 --- a/src/MEDCalc/tui/medpresentation.py +++ b/src/MEDCalc/tui/medpresentation.py @@ -19,17 +19,31 @@ import medcalc import MEDCALC, SALOME -from medcalc.medevents import notifyGui_addPresentation, notifyGui_removePresentation, notifyGui_error, notifyGui_modifyPresentation +from medcalc.medevents import notifyGui_addPresentation, notifyGui_removePresentation, notifyGui_error, notifyGui_modifyPresentation, notifyGui_visibilityChanged from functools import reduce +import pvsimple as pvs __manager = medcalc.medcorba.factory.getPresentationManager() +DEFAULT_VISIBILITY = True +DEFAULT_SCALAR_BAR_VISIBILITY = True +DEFAULT_USE_CUSTOM_RANGE = False +DEFAULT_SCALAR_BAR_RANGE = [0.0, 100.0] +DEFAULT_PLANE_NORMAL = [0.0, 0.0, 1.0] +DEFAULT_PLANE_POS = 1.0 +DEFAULT_SCALE_FACTOR = 0.2 +DEFAULT_CUT_POINT1 = [0.0, 0.0, 0.0] +DEFAULT_CUT_POINT2 = [1.0, 1.0, 1.0] +DEFAULT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE = False +DEFAULT_CUSTOM_SCALE_FACTOR = False +DEFAULT_CONTOUR_COMPONENT = "" def MakeMeshView(meshID, viewMode=MEDCALC.VIEW_MODE_DEFAULT, meshMode=MEDCALC.MESH_MODE_DEFAULT): # Create the presentation instance in CORBA engine # The engine in turn creates the ParaView pipeline elements - params = MEDCALC.MeshViewParameters(meshID, meshMode) + visibility=True + params = MEDCALC.MeshViewParameters(meshID, meshMode, visibility) try: presentation_id = __manager.makeMeshView(params, viewMode) notifyGui_addPresentation(meshID, presentation_id) @@ -47,7 +61,12 @@ def MakeScalarMap(proxy, ): # Create the presentation instance in CORBA engine # The engine in turn creates the ParaView pipeline elements - params = MEDCALC.ScalarMapParameters(proxy.id, displayedComponent, scalarBarRange, colorMap) + visibility = DEFAULT_VISIBILITY + scalarBarVisibility = DEFAULT_SCALAR_BAR_VISIBILITY + scalarBarRangeArray = DEFAULT_SCALAR_BAR_RANGE + hideDataOutsideCustomRange = DEFAULT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE + params = MEDCALC.ScalarMapParameters(proxy.id, displayedComponent, scalarBarRange, colorMap, visibility, + scalarBarVisibility, scalarBarRangeArray, hideDataOutsideCustomRange) try: presentation_id = __manager.makeScalarMap(params, viewMode) notifyGui_addPresentation(proxy.id, presentation_id) @@ -62,10 +81,16 @@ def MakeContour(proxy, colorMap=MEDCALC.COLOR_MAP_DEFAULT, nbContours=MEDCALC.NB_CONTOURS_DEFAULT ): - params = MEDCALC.ContourParameters(proxy.id, scalarBarRange, colorMap, nbContours) + visibility = DEFAULT_VISIBILITY + scalarBarVisibility = DEFAULT_SCALAR_BAR_VISIBILITY + hideDataOutsideCustomRange = DEFAULT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE + scalarBarRangeArray = DEFAULT_SCALAR_BAR_RANGE + contourComponent = DEFAULT_CONTOUR_COMPONENT + params = MEDCALC.ContourParameters(proxy.id, scalarBarRange, colorMap, visibility, scalarBarVisibility, + scalarBarRangeArray, hideDataOutsideCustomRange, nbContours, contourComponent) try: presentation_id = __manager.makeContour(params, viewMode) - notifyGui_addPresentation(proxy.id, presentation_id) + notifyGui_addPresentation(proxy.id, presentation_id) return presentation_id except SALOME.SALOME_Exception as e: notifyGui_error("An error occurred while creating the contour:\n" + e.details.text) @@ -80,7 +105,14 @@ def MakeVectorField(proxy, ): # Create the presentation instance in CORBA engine # The engine in turn creates the ParaView pipeline elements - params = MEDCALC.VectorFieldParameters(proxy.id, scalarBarRange, colorMap) + visibility = DEFAULT_VISIBILITY + scalarBarVisibility = DEFAULT_SCALAR_BAR_VISIBILITY + scalarBarRangeArray = DEFAULT_SCALAR_BAR_RANGE + hideDataOutsideCustomRange = DEFAULT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE + scaleFactor = DEFAULT_SCALE_FACTOR + customScaleFactor = DEFAULT_CUSTOM_SCALE_FACTOR + params = MEDCALC.VectorFieldParameters(proxy.id, scalarBarRange, colorMap, visibility, scalarBarVisibility, + scalarBarRangeArray, hideDataOutsideCustomRange, scaleFactor, customScaleFactor) try: presentation_id = __manager.makeVectorField(params, viewMode) notifyGui_addPresentation(proxy.id, presentation_id) @@ -98,7 +130,12 @@ def MakeSlices(proxy, nbSlices=MEDCALC.NB_SLICES_DEFAULT): # Create the presentation instance in CORBA engine # The engine in turn creates the ParaView pipeline elements - params = MEDCALC.SlicesParameters(proxy.id, displayedComponent,scalarBarRange, colorMap, + visibility = DEFAULT_VISIBILITY + scalarBarVisibility = DEFAULT_SCALAR_BAR_VISIBILITY + scalarBarRangeArray = DEFAULT_SCALAR_BAR_RANGE + hideDataOutsideCustomRange = DEFAULT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE + params = MEDCALC.SlicesParameters(proxy.id, displayedComponent,scalarBarRange, colorMap, visibility, + scalarBarVisibility, scalarBarRangeArray, hideDataOutsideCustomRange, sliceOrientation, nbSlices) try: presentation_id = __manager.makeSlices(params, viewMode) @@ -116,7 +153,12 @@ def MakeDeflectionShape(proxy, ): # Create the presentation instance in CORBA engine # The engine in turn creates the ParaView pipeline elements - params = MEDCALC.DeflectionShapeParameters(proxy.id, scalarBarRange, colorMap) + visibility = DEFAULT_VISIBILITY + scalarBarVisibility = DEFAULT_SCALAR_BAR_VISIBILITY + scalarBarRangeArray = DEFAULT_SCALAR_BAR_RANGE + hideDataOutsideCustomRange = DEFAULT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE + params = MEDCALC.DeflectionShapeParameters(proxy.id, scalarBarRange, colorMap, visibility, + scalarBarVisibility, scalarBarRangeArray, hideDataOutsideCustomRange) try: presentation_id = __manager.makeDeflectionShape(params, viewMode) notifyGui_addPresentation(proxy.id, presentation_id) @@ -134,7 +176,12 @@ def MakePointSprite(proxy, ): # Create the presentation instance in CORBA engine # The engine in turn creates the ParaView pipeline elements - params = MEDCALC.PointSpriteParameters(proxy.id, displayedComponent, scalarBarRange, colorMap) + visibility = DEFAULT_VISIBILITY + scalarBarVisibility = DEFAULT_SCALAR_BAR_VISIBILITY + scalarBarRangeArray = DEFAULT_SCALAR_BAR_RANGE + hideDataOutsideCustomRange = DEFAULT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE + params = MEDCALC.PointSpriteParameters(proxy.id, displayedComponent, scalarBarRange, colorMap, visibility, + scalarBarVisibility, scalarBarRangeArray, hideDataOutsideCustomRange) try: presentation_id = __manager.makePointSprite(params, viewMode) notifyGui_addPresentation(proxy.id, presentation_id) @@ -143,6 +190,79 @@ def MakePointSprite(proxy, notifyGui_error("An error occurred while creating the point sprite:\n" + e.details.text) raise Exception(e.details.text) + +def MakePlot3D(proxy, + viewMode=MEDCALC.VIEW_MODE_DEFAULT, + scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT, + colorMap=MEDCALC.COLOR_MAP_DEFAULT + ): + # Create the presentation instance in CORBA engine + # The engine in turn creates the ParaView pipeline elements + visibility = DEFAULT_VISIBILITY + scalarBarVisibility = DEFAULT_SCALAR_BAR_VISIBILITY + scalarBarRangeArray = DEFAULT_SCALAR_BAR_RANGE + hideDataOutsideCustomRange = DEFAULT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE + scalarBarRangeArray = DEFAULT_SCALAR_BAR_RANGE + planeNormal = DEFAULT_PLANE_NORMAL + planePos = DEFAULT_PLANE_POS + params = MEDCALC.Plot3DParameters(proxy.id, scalarBarRange, colorMap, visibility, + scalarBarVisibility, scalarBarRangeArray, hideDataOutsideCustomRange, planeNormal, planePos) + try: + presentation_id = __manager.makePlot3D(params, viewMode) + notifyGui_addPresentation(proxy.id, presentation_id) + return presentation_id + except SALOME.SALOME_Exception as e: + notifyGui_error("An error occurred while creating the Plot3D:\n" + e.details.text) + raise Exception(e.details.text) + + +def MakeStreamLines(proxy, + viewMode=MEDCALC.VIEW_MODE_DEFAULT, + scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT, + colorMap=MEDCALC.COLOR_MAP_DEFAULT + ): + # Create the presentation instance in CORBA engine + # The engine in turn creates the ParaView pipeline elements + visibility = DEFAULT_VISIBILITY + scalarBarVisibility = DEFAULT_SCALAR_BAR_VISIBILITY + scalarBarRangeArray = DEFAULT_SCALAR_BAR_RANGE + hideDataOutsideCustomRange = DEFAULT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE + integrDir = MEDCALC.INTEGRATION_DIR_DEFAULT + params = MEDCALC.StreamLinesParameters(proxy.id, scalarBarRange, colorMap, visibility, + scalarBarVisibility, scalarBarRangeArray, hideDataOutsideCustomRange, integrDir) + try: + presentation_id = __manager.makeStreamLines(params, viewMode) + notifyGui_addPresentation(proxy.id, presentation_id) + return presentation_id + except SALOME.SALOME_Exception as e: + notifyGui_error("An error occurred while creating the StreamLines:\n" + e.details.text) + raise Exception(e.details.text) + + +def MakeCutSegment(proxy, + viewMode=MEDCALC.VIEW_MODE_DEFAULT, + scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT, + colorMap=MEDCALC.COLOR_MAP_DEFAULT + ): + # Create the presentation instance in CORBA engine + # The engine in turn creates the ParaView pipeline elements + visibility = DEFAULT_VISIBILITY + scalarBarVisibility = DEFAULT_SCALAR_BAR_VISIBILITY + hideDataOutsideCustomRange = DEFAULT_HIDE_DATA_OUTSIDE_CUSTOM_RANGE + scalarBarRangeArray = DEFAULT_SCALAR_BAR_RANGE + point1 = DEFAULT_CUT_POINT1 + point2 = DEFAULT_CUT_POINT2 + params = MEDCALC.CutSegmentParameters(proxy.id, scalarBarRange, colorMap, visibility, + scalarBarVisibility, scalarBarRangeArray, hideDataOutsideCustomRange, point1, point2) + try: + presentation_id = __manager.makeCutSegment(params, viewMode) + notifyGui_addPresentation(proxy.id, presentation_id) + return presentation_id + except SALOME.SALOME_Exception as e: + notifyGui_error("An error occurred while creating the CutSegment:\n" + e.details.text) + raise Exception(e.details.text) + + def RemovePresentation(presentation_id): ok = __manager.removePresentation(presentation_id) if ok: @@ -160,11 +280,18 @@ GetSlicesParameters = lambda pres_id: __GetGENERICParameters("Slices", pres_id) GetPointSpriteParameters = lambda pres_id: __GetGENERICParameters("PointSprite", pres_id) GetVectorFieldParameters = lambda pres_id: __GetGENERICParameters("VectorField", pres_id) GetDeflectionShapeParameters = lambda pres_id: __GetGENERICParameters("DeflectionShape", pres_id) +GetPlot3DParameters = lambda pres_id: __GetGENERICParameters("Plot3D", pres_id) +GetStreamLinesParameters = lambda pres_id: __GetGENERICParameters("StreamLines", pres_id) +GetCutSegmentParameters = lambda pres_id: __GetGENERICParameters("CutSegment", pres_id) def __UpdateGENERIC(tag, presentation_id, params): + old_params = __GetGENERICParameters(tag, presentation_id) exec("__manager.update%s(presentation_id, params)" % tag) notifyGui_modifyPresentation(presentation_id) + if old_params.visibility != params.visibility: + # visibility is changed + notifyGui_visibilityChanged(presentation_id) UpdateMeshView = lambda pres_id, params: __UpdateGENERIC("MeshView", pres_id, params) UpdateScalarMap = lambda pres_id, params: __UpdateGENERIC("ScalarMap", pres_id, params) @@ -173,6 +300,82 @@ UpdateSlices = lambda pres_id, params: __UpdateGENERIC("Slices", pres_id, params UpdateVectorField = lambda pres_id, params: __UpdateGENERIC("VectorField", pres_id, params) UpdatePointSprite = lambda pres_id, params: __UpdateGENERIC("PointSprite", pres_id, params) UpdateDeflectionShape = lambda pres_id, params: __UpdateGENERIC("DeflectionShape", pres_id, params) +UpdatePlot3D = lambda pres_id, params: __UpdateGENERIC("Plot3D", pres_id, params) +UpdateStreamLines = lambda pres_id, params: __UpdateGENERIC("StreamLines", pres_id, params) +UpdateCutSegment = lambda pres_id, params: __UpdateGENERIC("CutSegment", pres_id, params) + + +def get_bound_project(bound_box, planeNormal): + """Get bounds projection""" + EPS = 1E-3 + + def dot_product(a, b): + """Dot product of two 3-vectors.""" + dot = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + return dot + + bound_points = [[bound_box[1], bound_box[2], bound_box[4]], + [bound_box[0], bound_box[3], bound_box[4]], + [bound_box[0], bound_box[2], bound_box[5]]] + print(bound_points) + + bound_prj = [0.0, 0.0, 0.0] + + for i in range(0, 3): + tmp = dot_product(planeNormal, bound_points[i]) + bound_prj[i] = tmp + + return bound_prj + + +def GetPositions(obj, planeNormal, displacement): + """Compute plane positions.""" + positions = [] + bounds = obj.GetDataInformation().GetBounds() + bound_prj = get_bound_project(bounds, planeNormal) + positions = [i * displacement for i in bound_prj] + return positions + +def IsPlanarObj(obj): + """ + Check if the given input is planar + """ + bounds_info = obj.GetDataInformation().GetBounds() + FLT_MIN = 1E-37 + + if (abs(bounds_info[0] - bounds_info[1]) <= FLT_MIN or + abs(bounds_info[2] - bounds_info[3]) <= FLT_MIN or + abs(bounds_info[4] - bounds_info[5]) <= FLT_MIN): + return True + + return False + +def GetPlaneNormalVector(obj): + """Get Normal Vector""" + bounds = obj.GetDataInformation().GetBounds() + FLT_MIN = 1E-37 + + if abs(bounds[4] - bounds[5]) <= FLT_MIN: + p0 = [bounds[0], bounds[2], 0] + p1 = [bounds[1], bounds[2], 0] + p2 = [bounds[0], bounds[3], 0] + elif abs(bounds[2] - bounds[3]) <= FLT_MIN: + p0 = [bounds[0], 0, bounds[4]] + p1 = [bounds[1], 0, bounds[4]] + p2 = [bounds[0], 0, bounds[5]] + else: + p0 = [0, bounds[2], bounds[4]] + p1 = [0, bounds[3], bounds[4]] + p2 = [0, bounds[2], bounds[5]] + + x0, y0, z0 = p0 + x1, y1, z1 = p1 + x2, y2, z2 = p2 + ux, uy, uz = u = [x1-x0, y1-y0, z1-z0] + vx, vy, vz = v = [x2-x0, y2-y0, z2-z0] + u_cross_v = [uy*vz-uz*vy, uz*vx-ux*vz, ux*vy-uy*vx] + + return u_cross_v def ComputeCellAverageSize(obj): """ @@ -237,3 +440,27 @@ def SelectSourceField(obj, meshName, fieldName, discretisation): obj.AllArrays = [t] return raise Exception("Field not found") + + +def FindOrCreateView(vtype): + """ + Find and active or create a view with type vtype + """ + result = None + view = pvs.GetActiveView() + if not view: + result = pvs.GetActiveViewOrCreate(vtype) + else: + if view.SMProxy.GetXMLName() == vtype: + result = view + else: + layout1 = pvs.GetLayout(view) + views = pvs.GetViewsInLayout(layout1) + view = next((v for v in views if v.SMProxy.GetXMLName() == vtype), None) + if view is None: + result = pvs.CreateView(vtype) + pvs.AssignViewToLayout(view=view, layout=layout1, hint=0) + else: + pvs.SetActiveView(view) + result = view + return result \ No newline at end of file -- 2.39.2