]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_ResultPrs.h
Salome HOME
Provide presentation for a step
[modules/shaper.git] / src / ModuleBase / ModuleBase_ResultPrs.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ModuleBase_ResultPrs_H
21 #define ModuleBase_ResultPrs_H
22
23 #include "ModuleBase.h"
24
25 #include <ModelAPI_Result.h>
26 #include <ModelAPI_ResultField.h>
27
28 #include <BRep_Builder.hxx>
29 #include <NCollection_List.hxx>
30 #include <ViewerData_AISShape.hxx>
31 #include <Standard_DefineHandle.hxx>
32 #include <TopoDS_Compound.hxx>
33
34 #include <QMap>
35
36 class AIS_ColoredDrawer;
37 class AIS_InteractiveContext;
38
39 DEFINE_STANDARD_HANDLE(ModuleBase_ResultPrs, ViewerData_AISShape)
40
41 /**
42 * \ingroup GUI
43 * A redefinition of standard AIS Interactive Object in order to provide specific behaviour 
44 * for wire presentations based in a one plane
45 */
46 class ModuleBase_ResultPrs: public ViewerData_AISShape
47 {
48 public:
49   enum SelectionModes {
50     Sel_Result = TopAbs_SHAPE + 1 /// it should be combined with Compsolid results, so it is not
51                                   /// the Shape type. It is not defined in XML as compound type
52                                   /// because this type is processed as shape with compounds inside.
53   };
54
55 public:
56   /// Constructor
57   /// \param theResult a result object
58   Standard_EXPORT ModuleBase_ResultPrs(ResultPtr theResult);
59
60   /// Constructor
61   /// \param theResult a result object
62   Standard_EXPORT ModuleBase_ResultPrs(FieldStepPtr theStep);
63
64   //! Method which draws selected owners ( for fast presentation draw )
65   Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
66                                                const SelectMgr_SequenceOfOwner& theOwners);
67
68   //! Method which hilight an owner belonging to
69   //! this selectable object  ( for fast presentation draw )
70   Standard_EXPORT virtual void HilightOwnerWithColor(
71                                         const Handle(PrsMgr_PresentationManager3d)& thePM,
72                                         const Handle(Prs3d_Drawer)& theStyle,
73                                         const Handle(SelectMgr_EntityOwner)& theOwner);
74
75   /// Returns result object
76   Standard_EXPORT ResultPtr getResult() const { return myResult; }
77
78   /// Returns selection priorities that will be added to created selection owner
79   /// \return integer value
80   Standard_EXPORT int getAdditionalSelectionPriority() const
81   { return myAdditionalSelectionPriority; }
82
83   /// Appends a special priority for the mode of selection
84   /// \param theSelectionMode a mode of selection, used in ComputeSelection
85   /// \param thePriority a new priority value
86   Standard_EXPORT void setAdditionalSelectionPriority(const int thePriority);
87
88   //! Updates color of sub shape drawer
89   Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor);
90
91   /// Change presentation to have given shape hidden.
92   /// It suports FACE type of the shape to be hidden.
93   /// If presentation type is greater than FACE, the SHELL with be shown with the FACE hidden
94   /// It is possible to hide more than one FACE by calling the method with given FACES
95   /// Visual state of the face is controlled by the second parameter
96   /// \param theShapes a container of shape objects
97   /// \returns true if the presentation is changed, or false (if for example it was hidden)
98   Standard_EXPORT bool setSubShapeHidden(const NCollection_List<TopoDS_Shape>& theShapes);
99
100   /// Returns true if parameter shape has been hidden
101   /// \param theShape sub-shape of the presentation shape
102   /// \return boolean value
103   Standard_EXPORT bool isSubShapeHidden(const TopoDS_Shape& theShape);
104
105   /// Returns true if there are no hidden sub shapes or original shape has at least one not hidden
106   /// \param theShapesToSkip container of shape to be hidden in the presentation (faces)
107   /// \return boolean value
108   Standard_EXPORT bool hasSubShapeVisible(const NCollection_List<TopoDS_Shape>& theShapesToSkip);
109
110   /// Set transparency of hidden sub shapes: if value is 1, shapes are entirely hidden
111   /// \param theTransparency transparency value
112   /// \return false if parameter is out of [0, 1]
113   Standard_EXPORT bool setHiddenSubShapeTransparency(double theTransparency);
114
115   Standard_EXPORT TopoDS_Shape originalShape() const { return myOriginalShape; }
116
117   Standard_EXPORT bool isSubstituted() const { return myIsSubstituted; }
118
119
120   DEFINE_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape)
121
122 protected:
123   /// Redefinition of virtual function
124   Standard_EXPORT virtual void Compute(
125     const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
126     const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
127
128   /// Redefinition of virtual function
129   Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
130                                                 const Standard_Integer theMode) ;
131
132 private:
133   /// If the shape of this presentation is Vertex, it appends custom sensitive and owners for it.
134   /// Owner is a usual Brep owner with "isDecomposite" in true. It is necessary to have "Ring"
135   /// highlight/selected marker.
136   /// \param theSelection a current filled selection
137   /// \param theMode a selection mode
138   /// \return true if the owner is created
139   bool appendVertexSelection(const Handle(SelectMgr_Selection)& aSelection,
140                              const Standard_Integer theMode);
141
142   /// Creates compound of vertices, edges and faces.
143   /// If the shape is COMPOUND, iterate by sub-shapes.
144   /// If the shape is SOLID/SHEL, explore shape by FACES,
145   /// If the shape is WIRE, explore shape by EDGES
146   /// \param theBuilder result compound builder
147   /// \param theCompound the result shape
148   /// \param theShape the processed shape
149   /// \param theHiddenSubShapes container of shapes to be skipped (faces)
150   void collectSubShapes(BRep_Builder& theBuilder, TopoDS_Shape& theCompound,
151     const TopoDS_Shape& theShape, const NCollection_List<TopoDS_Shape>& theHiddenSubShapes);
152
153   void setEdgesDefaultColor();
154
155   void init();
156
157   GeomShapePtr getOriginalShape() const;
158
159 private:
160   /// Reference to result object
161   ResultPtr myResult;
162
163   /// Reference to step object (initialised is only or step or result)
164   FieldStepPtr myStep;
165
166   /// Original shape of the result object
167   TopoDS_Shape myOriginalShape;
168
169   bool myIsSubstituted;
170
171   /// Container of original Shape sub shape to be hidden and not selectable
172   NCollection_List<TopoDS_Shape> myHiddenSubShapes;
173   TopoDS_Compound myHiddenCompound; /// compound of hidden sub shapes
174   double myTransparency; ///< transparency of hidden shapes, where 0 - there is no transparency
175   Handle(AIS_ColoredDrawer) myHiddenSubShapesDrawer; ///< drawer for hidden sub shapes
176
177   /// selection priority that will be added to the standard
178   /// selection priority of the selection entity
179   int myAdditionalSelectionPriority;
180 };
181
182
183 #endif