From: nds Date: Wed, 6 Dec 2017 09:11:57 +0000 (+0300) Subject: Issue #2309 Possibility to hide faces : transparency using X-Git-Tag: V_2.10.0RC~93^2~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4b7e6acd7e2430b11a86eeb9867ea54396c05f08;p=modules%2Fshaper.git Issue #2309 Possibility to hide faces : transparency using --- diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index 41724e977..b988f7fec 100755 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -33,23 +33,26 @@ #include #include +#include +#include +#include #include +#include #include #include #include #include -#include -#include +#include #include #include #include #include +#include #include -#include -#include #include -#include #include +#include +#include //******************************************************************************************* @@ -57,8 +60,10 @@ IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape); +//******************************************************************** ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult) - : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myAdditionalSelectionPriority(0) + : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myAdditionalSelectionPriority(0), + myTransparency(1) { std::shared_ptr aShapePtr = ModelAPI_Tools::shape(theResult); TopoDS_Shape aShape = aShapePtr->impl(); @@ -73,24 +78,43 @@ ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult) ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult); SetAutoHilight(aCompSolid.get() == NULL); + myHiddenSubShapesDrawer = new AIS_ColoredDrawer (myDrawer); + Handle(Prs3d_ShadingAspect) aShadingAspect = new Prs3d_ShadingAspect(); + aShadingAspect->SetMaterial(Graphic3d_NOM_BRASS); //default value of context material + myHiddenSubShapesDrawer->SetShadingAspect(aShadingAspect); + ModuleBase_Tools::setPointBallHighlighting(this); } +//******************************************************************** void ModuleBase_ResultPrs::setAdditionalSelectionPriority(const int thePriority) { myAdditionalSelectionPriority = thePriority; } +//******************************************************************** +void ModuleBase_ResultPrs::SetColor (const Quantity_Color& theColor) +{ + ViewerData_AISShape::SetColor(theColor); + myHiddenSubShapesDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel); +} + +//******************************************************************** bool ModuleBase_ResultPrs::setSubShapeHidden(const NCollection_List& theShapes) { bool isModified = false; + TopoDS_Compound aCompound; + BRep_Builder aBBuilder; + aBBuilder.MakeCompound (aCompound); // restore hidden shapes if there are not the shapes in parameter container NCollection_List aVisibleSubShapes; for (NCollection_List::Iterator aHiddenIt(myHiddenSubShapes); aHiddenIt.More(); aHiddenIt.Next()) { if (!theShapes.Contains(aHiddenIt.Value())) aVisibleSubShapes.Append(aHiddenIt.Value()); + else + aBBuilder.Add (aCompound, aHiddenIt.Value()); } isModified = !aVisibleSubShapes.IsEmpty(); for (NCollection_List::Iterator aVisibleIt(aVisibleSubShapes); aVisibleIt.More(); @@ -106,12 +130,15 @@ bool ModuleBase_ResultPrs::setSubShapeHidden(const NCollection_List 1 || theTransparency < 0) + return false; + + myTransparency = theTransparency; + myHiddenSubShapesDrawer->ShadingAspect()->SetTransparency (theTransparency, myCurrentFacingModel); + return true; +} + +//******************************************************************** void ModuleBase_ResultPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, @@ -164,6 +203,12 @@ void ModuleBase_ResultPrs::Compute( //ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes()); AIS_Shape::Compute(thePresentationManager, thePresentation, theMode); + // visualize hidden sub-shapes transparent + if (myTransparency < 1 && !myHiddenSubShapes.IsEmpty()) + { + StdPrs_ShadedShape::Add (thePresentation, myHiddenCompound, myHiddenSubShapesDrawer); + } + if (!aReadyToDisplay) { Events_InfoMessage("ModuleBase_ResultPrs", "An empty AIS presentation: ModuleBase_ResultPrs").send(); @@ -172,6 +217,7 @@ void ModuleBase_ResultPrs::Compute( } } +//******************************************************************** void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer theMode) { @@ -237,6 +283,7 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a } } +//******************************************************************** bool ModuleBase_ResultPrs::appendVertexSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer theMode) { @@ -264,6 +311,7 @@ bool ModuleBase_ResultPrs::appendVertexSelection(const Handle(SelectMgr_Selectio return false; } +//******************************************************************** void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, const SelectMgr_SequenceOfOwner& theOwners) { @@ -290,6 +338,7 @@ void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManag } } +//******************************************************************** void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, const Handle(Graphic3d_HighlightStyle)& theStyle, const Handle(SelectMgr_EntityOwner)& theOwner) diff --git a/src/ModuleBase/ModuleBase_ResultPrs.h b/src/ModuleBase/ModuleBase_ResultPrs.h index e95018a79..642beb8fb 100644 --- a/src/ModuleBase/ModuleBase_ResultPrs.h +++ b/src/ModuleBase/ModuleBase_ResultPrs.h @@ -28,9 +28,13 @@ #include #include #include +#include #include +class AIS_ColoredDrawer; +class AIS_InteractiveContext; + DEFINE_STANDARD_HANDLE(ModuleBase_ResultPrs, ViewerData_AISShape) /** @@ -76,6 +80,9 @@ public: /// \param thePriority a new priority value Standard_EXPORT void setAdditionalSelectionPriority(const int thePriority); + //! Updates color of sub shape drawer + Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor); + /// Change presentation to have given shape hidden. /// It suports FACE type of the shape to be hidden. /// If presentation type is greater than FACE, the SHELL with be shown with the FACE hidden @@ -90,6 +97,11 @@ public: /// \return boolean value Standard_EXPORT bool hasSubShapeVisible(const TopoDS_Shape& theShapeToSkip); + /// Set transparency of hidden sub shapes: if value is 1, shapes are entirely hidden + /// \param theTransparency transparency value + /// \return false if parameter is out of [0, 1] + Standard_EXPORT bool setHiddenSubShapeTransparency(double theTransparency); + DEFINE_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape) protected: @@ -120,6 +132,9 @@ private: /// Container of original Shape sub shape to be hidden and not selectable NCollection_List myHiddenSubShapes; + TopoDS_Compound myHiddenCompound; /// compound of hidden sub shapes + double myTransparency; ///< transparency of hidden shapes, where 0 - there is no transparency + Handle(AIS_ColoredDrawer) myHiddenSubShapesDrawer; ///< drawer for hidden sub shapes /// selection priority that will be added to the standard /// selection priority of the selection entity diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 8b2d83405..1455f1ab0 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -191,6 +191,11 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) Config_PropManager::registerProp("Visualization", "sketch_preview_plane", "Color of sketch plane", Config_Prop::Color, PartSet_CustomPrs::OPERATION_SKETCH_PLANE()); + + Config_PropManager::registerProp("Visualization", "hidden_face_transparency", + "Hidden faces transparency", + Config_Prop::Double, + "0.8"); } PartSet_Module::~PartSet_Module() diff --git a/src/XGUI/XGUI_FacesPanel.cpp b/src/XGUI/XGUI_FacesPanel.cpp index 79f299077..5f9c9d583 100644 --- a/src/XGUI/XGUI_FacesPanel.cpp +++ b/src/XGUI/XGUI_FacesPanel.cpp @@ -20,8 +20,9 @@ #include "XGUI_FacesPanel.h" +#include #include -#include "GeomAlgoAPI_CompoundBuilder.h" +#include #include @@ -60,7 +61,6 @@ XGUI_FacesPanel::XGUI_FacesPanel(QWidget* theParent, ModuleBase_IWorkshop* theWo myHiddenOrTransparent = new QCheckBox(tr("Transparent"), aContent); myListView = new ModuleBase_ListView(aContent, "", "Hidden/transparent faces in 3D view"); - connect(myListView->getControl(), SIGNAL(itemSelectionChanged()), SLOT(onListSelection())); connect(myListView, SIGNAL(deleteActionClicked()), SLOT(onDeleteItem())); aMainLayout->addWidget(myHiddenOrTransparent, 0, 0); @@ -128,6 +128,12 @@ void XGUI_FacesPanel::setActivePanel(const bool theIsActive) } } +//******************************************************************** +bool XGUI_FacesPanel::useTransparency() const +{ + return myHiddenOrTransparent->isChecked(); +} + //******************************************************************** void XGUI_FacesPanel::restoreObjects(const std::set& theHiddenObjects) { @@ -379,6 +385,9 @@ bool XGUI_FacesPanel::customizeObject(const ObjectPtr& theObject, const bool isD aHiddenSubShapes.Append(aShape); } isModified = aResultPrs->setSubShapeHidden(aHiddenSubShapes); + double aTransparency = !useTransparency() ? 1 + : Config_PropManager::real("Visualization", "hidden_face_transparency"); + aResultPrs->setHiddenSubShapeTransparency(aTransparency); return isModified; } diff --git a/src/XGUI/XGUI_FacesPanel.h b/src/XGUI/XGUI_FacesPanel.h index cd3ff00fa..4c147ab7d 100644 --- a/src/XGUI/XGUI_FacesPanel.h +++ b/src/XGUI/XGUI_FacesPanel.h @@ -79,6 +79,10 @@ public: /// \param theIsActive state whether the panel should be activated or deactivated void setActivePanel(const bool theIsActive); + /// Returns true if transparency choice is checked + /// \return boolean value + bool useTransparency() const; + /// Returns true if the object is in internal container of hidden objects by this panel /// \param theObject a checked object /// \return boolean value