From af35266d7c7d3bdac54952f85b4d16ff6d1c9b0b Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 26 Jun 2019 16:55:36 +0300 Subject: [PATCH] Implement colored shape --- src/GeomAPI/GeomAPI_AISObject.h | 2 +- src/ModuleBase/CMakeLists.txt | 2 + src/ModuleBase/ModuleBase_IModule.cpp | 2 +- src/ModuleBase/ModuleBase_IModule.h | 3 +- src/ModuleBase/ModuleBase_IStepPrs.cpp | 24 +++++ src/ModuleBase/ModuleBase_IStepPrs.h | 36 +++++++ src/ModuleBase/ModuleBase_ResultPrs.cpp | 30 +----- src/ModuleBase/ModuleBase_ResultPrs.h | 11 -- src/PartSet/CMakeLists.txt | 2 + src/PartSet/PartSet_FieldStepPrs.cpp | 138 ++++++++++++++++++++++++ src/PartSet/PartSet_FieldStepPrs.h | 65 +++++++++++ src/PartSet/PartSet_Module.cpp | 16 ++- src/PartSet/PartSet_Module.h | 3 +- src/XGUI/XGUI_Displayer.cpp | 52 +++------ src/XGUI/XGUI_Displayer.h | 2 - src/XGUI/XGUI_SelectionMgr.cpp | 34 ++++++ src/XGUI/XGUI_ViewerProxy.cpp | 93 ++++++++++++++++ src/XGUI/XGUI_ViewerProxy.h | 39 +++++++ 18 files changed, 465 insertions(+), 89 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_IStepPrs.cpp create mode 100644 src/ModuleBase/ModuleBase_IStepPrs.h create mode 100644 src/PartSet/PartSet_FieldStepPrs.cpp create mode 100644 src/PartSet/PartSet_FieldStepPrs.h diff --git a/src/GeomAPI/GeomAPI_AISObject.h b/src/GeomAPI/GeomAPI_AISObject.h index 57bfa3922..7e4ebc98b 100644 --- a/src/GeomAPI/GeomAPI_AISObject.h +++ b/src/GeomAPI/GeomAPI_AISObject.h @@ -49,7 +49,7 @@ class GeomAPI_AISObject : public GeomAPI_Interface GEOMAPI_EXPORT void createShape(std::shared_ptr theShape); - /// Reyirns shape used for the presentation creation (can be NULL) + /// Returns shape used for the presentation creation (can be NULL) GEOMAPI_EXPORT std::shared_ptr getShape() const; /** \brief Creates AIS_LengthDimension object diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index ba2d74969..081f37b25 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -103,6 +103,7 @@ SET(PROJECT_HEADERS ModuleBase_WidgetRadiobox.h ModuleBase_WidgetPointInput.h ModuleBase_ITreeNode.h + ModuleBase_IStepPrs.h ) SET(PROJECT_MOC_HEADERS @@ -220,6 +221,7 @@ SET(PROJECT_SOURCES ModuleBase_WidgetNameEdit.cpp ModuleBase_WidgetRadiobox.cpp ModuleBase_WidgetPointInput.cpp + ModuleBase_IStepPrs.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index ac8f98dd6..05d1f93ef 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -147,7 +147,7 @@ void ModuleBase_IModule::launchOperation(const QString& theCmdId, } } -Handle(AIS_InteractiveObject) ModuleBase_IModule::createPresentation(const ResultPtr& theResult) +Handle(AIS_InteractiveObject) ModuleBase_IModule::createPresentation(const ObjectPtr& theResult) { return Handle(AIS_InteractiveObject)(); } diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 90d31cd14..165828fd0 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -301,8 +301,7 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// Create specific for the module presentation /// \param theResult an object for presentation /// \return created presentation or NULL(default value) - virtual Handle(AIS_InteractiveObject) createPresentation( - const std::shared_ptr& theResult); + virtual Handle(AIS_InteractiveObject) createPresentation(const ObjectPtr& theResult); //! Returns data object by AIS virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0; diff --git a/src/ModuleBase/ModuleBase_IStepPrs.cpp b/src/ModuleBase/ModuleBase_IStepPrs.cpp new file mode 100644 index 000000000..b08b3b37f --- /dev/null +++ b/src/ModuleBase/ModuleBase_IStepPrs.cpp @@ -0,0 +1,24 @@ +// Copyright (C) 2014-2019 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 "ModuleBase_IStepPrs.h" + +ModuleBase_IStepPrs::ModuleBase_IStepPrs() +{ +} diff --git a/src/ModuleBase/ModuleBase_IStepPrs.h b/src/ModuleBase/ModuleBase_IStepPrs.h new file mode 100644 index 000000000..445b4b752 --- /dev/null +++ b/src/ModuleBase/ModuleBase_IStepPrs.h @@ -0,0 +1,36 @@ +// Copyright (C) 2014-2019 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 ModuleBase_IStepPrs_H +#define ModuleBase_IStepPrs_H + +#include "ModuleBase.h" +#include + +class MODULEBASE_EXPORT ModuleBase_IStepPrs +{ +public: + ModuleBase_IStepPrs(); + + virtual ModelAPI_AttributeTables::ValueType dataType() const = 0; + + virtual bool dataRange(double& theMin, double& theMax) const = 0; +}; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index ff7a2b44b..e2d35c87b 100644 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -74,25 +74,6 @@ ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult) ResultBodyPtr aResOwner = ModelAPI_Tools::bodyOwner(myResult); SetAutoHilight(aResOwner.get() == NULL); - init(); -} - -//******************************************************************** -ModuleBase_ResultPrs::ModuleBase_ResultPrs(FieldStepPtr theStep) - : ViewerData_AISShape(TopoDS_Shape()), myStep(theStep), myAdditionalSelectionPriority(0), - myTransparency(1), myIsSubstituted(false) -{ - GeomShapePtr aShapePtr = theStep->field()->shape(); - TopoDS_Shape aShape = aShapePtr->impl(); - Set(aShape); - - init(); -} - - -//******************************************************************** -void ModuleBase_ResultPrs::init() -{ // Set own free boundaries aspect in order to have free // and unfree boundaries with different colors Handle(Prs3d_Drawer) aDrawer = Attributes(); @@ -116,7 +97,6 @@ void ModuleBase_ResultPrs::init() setEdgesDefaultColor(); } - //******************************************************************** void ModuleBase_ResultPrs::setAdditionalSelectionPriority(const int thePriority) { @@ -261,21 +241,13 @@ bool ModuleBase_ResultPrs::setHiddenSubShapeTransparency(double theTransparency) return true; } -//******************************************************************** -GeomShapePtr ModuleBase_ResultPrs::getOriginalShape() const -{ - if (myStep.get()) - return myStep->field()->shape(); - return myResult->shape(); -} - //******************************************************************** void ModuleBase_ResultPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) { - std::shared_ptr aShapePtr = getOriginalShape(); + std::shared_ptr aShapePtr = myResult->shape(); bool aReadyToDisplay = aShapePtr.get(); if (aReadyToDisplay) { myOriginalShape = aShapePtr->impl(); diff --git a/src/ModuleBase/ModuleBase_ResultPrs.h b/src/ModuleBase/ModuleBase_ResultPrs.h index df01f95c0..1868ad8db 100644 --- a/src/ModuleBase/ModuleBase_ResultPrs.h +++ b/src/ModuleBase/ModuleBase_ResultPrs.h @@ -57,10 +57,6 @@ public: /// \param theResult a result object Standard_EXPORT ModuleBase_ResultPrs(ResultPtr theResult); - /// Constructor - /// \param theResult a result object - Standard_EXPORT ModuleBase_ResultPrs(FieldStepPtr theStep); - //! Method which draws selected owners ( for fast presentation draw ) Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, const SelectMgr_SequenceOfOwner& theOwners); @@ -152,17 +148,10 @@ private: void setEdgesDefaultColor(); - void init(); - - GeomShapePtr getOriginalShape() const; - private: /// Reference to result object ResultPtr myResult; - /// Reference to step object (initialised is only or step or result) - FieldStepPtr myStep; - /// Original shape of the result object TopoDS_Shape myOriginalShape; diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 178c0b8bf..47f29b01b 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -58,6 +58,7 @@ SET(PROJECT_HEADERS PartSet_CenterPrs.h PartSet_ExternalPointsMgr.h PartSet_TreeNodes.h + PartSet_FieldStepPrs.h ) SET(PROJECT_MOC_HEADERS @@ -107,6 +108,7 @@ SET(PROJECT_SOURCES PartSet_CenterPrs.cpp PartSet_ExternalPointsMgr.cpp PartSet_TreeNodes.cpp + PartSet_FieldStepPrs.cpp ) SET(PROJECT_RESOURCES diff --git a/src/PartSet/PartSet_FieldStepPrs.cpp b/src/PartSet/PartSet_FieldStepPrs.cpp new file mode 100644 index 000000000..c699c8ed1 --- /dev/null +++ b/src/PartSet/PartSet_FieldStepPrs.cpp @@ -0,0 +1,138 @@ +// Copyright (C) 2014-2019 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 "PartSet_FieldStepPrs.h" + +#include + +#include +#include +#include + +#include + + +IMPLEMENT_STANDARD_RTTIEXT(PartSet_FieldStepPrs, ViewerData_AISShape); + + +void emptyDeleter(ModelAPI_ResultField* theF) +{ + // Do nothing +} + +PartSet_FieldStepPrs::PartSet_FieldStepPrs(FieldStepPtr theStep) +: ViewerData_AISShape(TopoDS_Shape()), myStep(theStep) +{ + ModelAPI_ResultField* aField = theStep->field(); + GeomShapePtr aShapePtr = aField->shape(); + TopoDS_Shape aShape = aShapePtr->impl(); + Set(aShape); + + // Get parameters of the Field + // Make shared_ptr which will not delete original pointer after exit + std::shared_ptr aFieldPtr(aField, emptyDeleter); + myFeature = ModelAPI_Feature::feature(aFieldPtr); +} + + +ModelAPI_AttributeTables::ValueType PartSet_FieldStepPrs::dataType() const +{ + DataPtr aData = myFeature->data(); + AttributeTablesPtr aTablesAttr = aData->tables(CollectionPlugin_Field::VALUES_ID()); + return aTablesAttr->type(); +} + +bool PartSet_FieldStepPrs::dataRange(double& theMin, double& theMax) const +{ + ModelAPI_AttributeTables::ValueType aType = dataType(); + if ((aType == ModelAPI_AttributeTables::DOUBLE) || (aType == ModelAPI_AttributeTables::INTEGER)) { + range(theMin, theMax); + return true; + } + return false; +} + +QList PartSet_FieldStepPrs::range(double& theMin, double& theMax) const +{ + ModelAPI_AttributeTables::ValueType aType = dataType(); + DataPtr aData = myFeature->data(); + int aStep = myStep->id(); + AttributeTablesPtr aTablesAttr = aData->tables(CollectionPlugin_Field::VALUES_ID()); + int aRows = aTablesAttr->rows(); + int aCols = aTablesAttr->columns(); + + QList aFieldStepData; + for (int j = 0; j < aCols; j++) { + for (int k = 1; k < aRows; k++) { // Do not use default values + ModelAPI_AttributeTables::Value aVal = aTablesAttr->value(k, j, aStep); + switch (aType) { + case ModelAPI_AttributeTables::DOUBLE: + aFieldStepData << aVal.myDouble; + break; + case ModelAPI_AttributeTables::INTEGER: + aFieldStepData << aVal.myInt; + break; + } + } + } + QList aShapeData; + double aRangeMin = aFieldStepData.first(), aRangeMax = aFieldStepData.last(); + for (int aRow = 0; aRow < aRows - 1; aRow++) { + double aNorm = 0; + int aBaseIndex = aRow * aCols; + for (int aCol = 0; aCol < aCols; aCol++) { + int anIndex = aCol + aBaseIndex; + double aValue = aFieldStepData.at(anIndex); + aNorm += aValue * aValue; + } + aNorm = pow(aNorm, 0.5); + aRangeMin = Min(aRangeMin, aNorm); + aRangeMax = Max(aRangeMax, aNorm); + aShapeData << aNorm; + } + theMin = aRangeMin; + theMax = aRangeMax; + return aShapeData; +} + + +void PartSet_FieldStepPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, + const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) +{ + ModelAPI_AttributeTables::ValueType aType = dataType(); + if ((aType == ModelAPI_AttributeTables::DOUBLE) || + (aType == ModelAPI_AttributeTables::INTEGER)) { + double aMin, aMax; + QList aShapeData = range(aMin, aMax); + int aNbIntertvals = 20; + + DataPtr aData = myFeature->data(); + AttributeSelectionListPtr aSelList = aData->selectionList(CollectionPlugin_Field::SELECTED_ID()); + for (int i = 0; i < aSelList->size(); i++) { + AttributeSelectionPtr aSelection = aSelList->value(i); + GeomShapePtr aShapePtr = aSelection->value(); + TopoDS_Shape aShape = aShapePtr->impl(); + double aValue = aShapeData.at(i); + Quantity_Color aColor; + if (AIS_ColorScale::FindColor(aValue, aMin, aMax, aNbIntertvals, aColor)) + SetCustomColor(aShape, aColor); + } + } + ViewerData_AISShape::Compute(thePrsMgr, thePrs, theMode); +} diff --git a/src/PartSet/PartSet_FieldStepPrs.h b/src/PartSet/PartSet_FieldStepPrs.h new file mode 100644 index 000000000..9aa671fc8 --- /dev/null +++ b/src/PartSet/PartSet_FieldStepPrs.h @@ -0,0 +1,65 @@ +// Copyright (C) 2014-2019 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 PartSet_FieldStepPrs_H +#define PartSet_FieldStepPrs_H + +#include "PartSet.h" +#include + +#include +#include + +#include + +#include + +DEFINE_STANDARD_HANDLE(PartSet_FieldStepPrs, ViewerData_AISShape) + +/** +* \ingroup GUI +* A redefinition of standard AIS Interactive Object in order to provide specific behaviour +* for wire presentations based in a one plane +*/ +class PartSet_FieldStepPrs : public ViewerData_AISShape, public ModuleBase_IStepPrs +{ +public: + /// Constructor + /// \param theResult a result object + Standard_EXPORT PartSet_FieldStepPrs(FieldStepPtr theStep); + + ModelAPI_AttributeTables::ValueType dataType() const; + + bool dataRange(double& theMin, double& theMax) const; + + DEFINE_STANDARD_RTTIEXT(PartSet_FieldStepPrs, ViewerData_AISShape) + +protected: + //! Compute presentation considering sub-shape color map. + virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, + const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode); + +private: + QList range(double& theMin, double& theMax) const; + + FieldStepPtr myStep; + FeaturePtr myFeature; +}; + +#endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index bbf82b6be..62987b497 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -38,6 +38,7 @@ #include "PartSet_IconFactory.h" #include "PartSet_OverconstraintListener.h" #include "PartSet_TreeNodes.h" +#include "PartSet_FieldStepPrs.h" #include "PartSet_Filters.h" #include "PartSet_FilterInfinite.h" @@ -62,6 +63,7 @@ #include #include #include +#include #include #include @@ -1313,9 +1315,19 @@ void PartSet_Module::onActiveDocPopup(const QPoint& thePnt) } //****************************************************** -Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult) +Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ObjectPtr& theObject) { - return mySketchMgr->createPresentation(theResult); + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get()) + return mySketchMgr->createPresentation(aResult); + else { + FieldStepPtr aStep = + std::dynamic_pointer_cast(theObject); + if (aStep.get()) { + return new PartSet_FieldStepPrs(aStep); + } + } + return Handle(AIS_InteractiveObject)(); } //****************************************************** diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 1f23bc733..25c269059 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -335,8 +335,7 @@ public: /// Create specific for the module presentation /// \param theResult an object for presentation /// \return created presentation or NULL(default value) - virtual Handle(AIS_InteractiveObject) createPresentation( - const std::shared_ptr& theResult); + virtual Handle(AIS_InteractiveObject) createPresentation(const ObjectPtr& theResult); //! Returns data object by AIS virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const; diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 30f94ef70..23753cf8c 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include @@ -158,24 +157,23 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer) } anAIS = aPrs->getAISObject(anAIS); } else { - ResultPtr aResult = std::dynamic_pointer_cast(theObject); - if (aResult.get() != NULL) { - anAIS = createPresentation(aResult); - isShading = true; - } - else { - FieldStepPtr aStep = - std::dynamic_pointer_cast(theObject); - if (aStep) { - GeomShapePtr aShapePtr = aStep->field()->shape(); + Handle(AIS_InteractiveObject) anAISPrs = + myWorkshop->module()->createPresentation(theObject); + if (anAISPrs.IsNull()) { + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get() != NULL) { + std::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); if (aShapePtr.get() != NULL) { - Handle(AIS_InteractiveObject) anAISPrs = new ModuleBase_ResultPrs(aStep); - anAIS = AISObjectPtr(new GeomAPI_AISObject()); - anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs)); - isShading = true; + anAISPrs = new ModuleBase_ResultPrs(aResult); } } } + Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs); + if (!aShapePrs.IsNull()) + ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*)aShapePrs.get()); + anAIS = AISObjectPtr(new GeomAPI_AISObject()); + anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs)); + isShading = true; } if (anAIS) aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer); @@ -184,30 +182,6 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer) } -//************************************************************** -AISObjectPtr XGUI_Displayer::createPresentation(const ResultPtr& theResult) const -{ - AISObjectPtr anAIS; - if (theResult.get() != NULL) { - std::shared_ptr aShapePtr = ModelAPI_Tools::shape(theResult); - if (aShapePtr.get() != NULL) { - anAIS = AISObjectPtr(new GeomAPI_AISObject()); - Handle(AIS_InteractiveObject) anAISPrs = - myWorkshop->module()->createPresentation(theResult); - if (anAISPrs.IsNull()) - anAISPrs = new ModuleBase_ResultPrs(theResult); - else { - Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs); - if (!aShapePrs.IsNull()) - ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*)aShapePrs.get()); - } - anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs)); - } - } - return anAIS; -} - - //************************************************************** bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule) { diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index df1237c43..62362084a 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -443,8 +443,6 @@ private: private: XGUI_SelectionActivate* selectionActivate() const; - AISObjectPtr createPresentation(const ResultPtr& theResult) const; - private: XGUI_Workshop* myWorkshop; ///< Reference to workshop #ifdef TINSPECTOR diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index 78b20ee7d..ba0129566 100644 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include @@ -130,6 +132,38 @@ void XGUI_SelectionMgr::onObjectBrowserSelection() } } aDisplayer->setSelected(aSelectedPrs); + myWorkshop->viewer()->setColorScaleShown(false); + if (aSelectedPrs.size() == 1) { + FieldStepPtr aStep = + std::dynamic_pointer_cast + (aSelectedPrs.first()->object()); + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + if (aStep.get() && aDisplayer->isVisible(aStep)) { + XGUI_ViewerProxy* aViewer = myWorkshop->viewer(); + AISObjectPtr aAisPtr = aDisplayer->getAISObject(aStep); + Handle(AIS_InteractiveObject) aIO = aAisPtr->impl(); + ModuleBase_IStepPrs* aPrs = dynamic_cast(aIO.get()); + if (aPrs) { + ModelAPI_AttributeTables::ValueType aType = aPrs->dataType(); + if ((aType == ModelAPI_AttributeTables::DOUBLE) || + (aType == ModelAPI_AttributeTables::INTEGER) || + (aType == ModelAPI_AttributeTables::BOOLEAN)) { + aViewer->setupColorScale(); + if (aType == ModelAPI_AttributeTables::BOOLEAN) { + aViewer->setColorScaleIntervals(2); + aViewer->setColorScaleRange(0, 1); + } + else { + double aMin, aMax; + aPrs->dataRange(aMin, aMax); + aViewer->setColorScaleRange(aMin, aMax); + } + aViewer->setColorScaleTitle("Step"); + aViewer->setColorScaleShown(true); + } + } + } + } emit selectionChanged(); } diff --git a/src/XGUI/XGUI_ViewerProxy.cpp b/src/XGUI/XGUI_ViewerProxy.cpp index 6a33fefb1..43890885b 100644 --- a/src/XGUI/XGUI_ViewerProxy.cpp +++ b/src/XGUI/XGUI_ViewerProxy.cpp @@ -559,6 +559,99 @@ void XGUI_ViewerProxy::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* t } #endif + +bool XGUI_ViewerProxy::isColorScaleVisible() const +{ +#ifdef HAVE_SALOME + return myWorkshop->salomeConnector()->viewer()->isColorScaleVisible(); +#else + return myWorkshop->mainWindow()->viewer()->isColorScaleVisible(); +#endif +} + +void XGUI_ViewerProxy::setColorScaleShown(bool on) +{ +#ifdef HAVE_SALOME + myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on); +#else + myWorkshop->mainWindow()->viewer()->setColorScaleShown(on); +#endif +} + +void XGUI_ViewerProxy::setColorScalePosition(double theX, double theY) +{ + QWidget* aWindow = activeViewPort(); +#ifdef HAVE_SALOME + myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on); +#else + Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); + aColorScale->SetPosition(aWindow->width() * theX, aWindow->height() * theY); +#endif +} + +void XGUI_ViewerProxy::setColorScaleSize(double theW, double theH) +{ + QWidget* aWindow = activeViewPort(); +#ifdef HAVE_SALOME + myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on); +#else + Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); + aColorScale->SetWidth(aWindow->width() * theW); + aColorScale->SetHeight(aWindow->height() * theH); +#endif +} + +void XGUI_ViewerProxy::setColorScaleRange(double theMin, double theMax) +{ +#ifdef HAVE_SALOME + myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on); +#else + Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); + aColorScale->SetRange(theMin, theMax); +#endif +} + +void XGUI_ViewerProxy::setColorScaleIntervals(int theNb) +{ +#ifdef HAVE_SALOME + myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on); +#else + Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); + aColorScale->SetNumberOfIntervals(theNb); +#endif +} + +void XGUI_ViewerProxy::setColorScaleTextHeigth(int theH) +{ +#ifdef HAVE_SALOME + myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on); +#else + Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); + aColorScale->SetTextHeight(theH); +#endif +} + +void XGUI_ViewerProxy::setColorScaleTitle(const QString& theText) +{ +#ifdef HAVE_SALOME + myWorkshop->salomeConnector()->viewer()->setColorScaleShown(on); +#else + Handle(AIS_ColorScale) aColorScale = myWorkshop->mainWindow()->viewer()->colorScale(); + aColorScale->SetTitle(theText.toStdString().c_str()); +#endif +} + + +//****************************************************** +void XGUI_ViewerProxy::setupColorScale() +{ + setColorScalePosition(0.03, 0.35); + setColorScaleSize(0.2, 0.5); + setColorScaleTextHeigth(14); + setColorScaleIntervals(20); +} + + //*************************************** //void XGUI_ViewerProxy::Zfitall() //{ diff --git a/src/XGUI/XGUI_ViewerProxy.h b/src/XGUI/XGUI_ViewerProxy.h index cf73432d8..384372390 100644 --- a/src/XGUI/XGUI_ViewerProxy.h +++ b/src/XGUI/XGUI_ViewerProxy.h @@ -119,6 +119,44 @@ Q_OBJECT virtual void updateHighlight(); + // Methods for color scale management + + //! Returns True if ColorScale is visible + virtual bool isColorScaleVisible() const; + + //! Show/Hide ColorScale object + virtual void setColorScaleShown(bool on); + + //! Set position of color scale + // \param theX is X position relative to current view width + // \param theY is Y position relative to current view heigth + virtual void setColorScalePosition(double theX, double theY); + + //! Set size of color scale + // \param theW is width relative to current view width + // \param theh is height relative to current view heigth + virtual void setColorScaleSize(double theW, double theH); + + //! Set range of color scale + // \param theMin is a minimal value + // \param theMax is a maximal value + virtual void setColorScaleRange(double theMin, double theMax); + + //! Set number of intervals of color scale + // \param theNb is number of intervals + virtual void setColorScaleIntervals(int theNb); + + //! Set text heigth of color scale + // \param theH is number of intervals + virtual void setColorScaleTextHeigth(int theH); + + //! Set title of color scale + // \param theText is a title + virtual void setColorScaleTitle(const QString& theText); + + //! Set color scale parameters according to user preferences and window size + void setupColorScale(); + // Fit all along Z (perpendicular to display) //virtual void Zfitall(); @@ -163,6 +201,7 @@ private slots: void displayHighlight(FeaturePtr theFeature, const TopoDS_Shape& theIgnoreShape); void eraseHighlight(); + XGUI_Workshop* myWorkshop; ResultPtr myResult; AIS_ListOfInteractive myHighlights; -- 2.39.2