Salome HOME
a93089e98dbca8b8c5e09686d4e5469410747554
[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 #include <Prs3d_IsoAspect.hxx>
34
35 #include <QMap>
36
37 class AIS_ColoredDrawer;
38 class AIS_InteractiveContext;
39
40 DEFINE_STANDARD_HANDLE(ModuleBase_ResultPrs, ViewerData_AISShape)
41
42 /**
43 * \ingroup GUI
44 * A redefinition of standard AIS Interactive Object in order to provide specific behaviour 
45 * for wire presentations based in a one plane
46 */
47 class ModuleBase_ResultPrs: public ViewerData_AISShape
48 {
49 public:
50   enum SelectionModes {
51     Sel_Result = TopAbs_SHAPE + 1 /// it should be combined with Compsolid results, so it is not
52                                   /// the Shape type. It is not defined in XML as compound type
53                                   /// because this type is processed as shape with compounds inside.
54   };
55
56 public:
57   /// Constructor
58   /// \param theResult a result object
59   Standard_EXPORT ModuleBase_ResultPrs(ResultPtr theResult);
60
61   //! Method which draws selected owners ( for fast presentation draw )
62   Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
63                                                const SelectMgr_SequenceOfOwner& theOwners);
64
65   //! Method which hilight an owner belonging to
66   //! this selectable object  ( for fast presentation draw )
67   Standard_EXPORT virtual void HilightOwnerWithColor(
68                                         const Handle(PrsMgr_PresentationManager3d)& thePM,
69                                         const Handle(Prs3d_Drawer)& theStyle,
70                                         const Handle(SelectMgr_EntityOwner)& theOwner);
71
72   /// Returns result object
73   Standard_EXPORT ResultPtr getResult() const { return myResult; }
74
75   /// Returns selection priorities that will be added to created selection owner
76   /// \return integer value
77   Standard_EXPORT int getAdditionalSelectionPriority() const
78   { return myAdditionalSelectionPriority; }
79
80   /// Appends a special priority for the mode of selection
81   /// \param theSelectionMode a mode of selection, used in ComputeSelection
82   /// \param thePriority a new priority value
83   Standard_EXPORT void setAdditionalSelectionPriority(const int thePriority);
84
85   //! Updates color of sub shape drawer
86   Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor);
87
88   /// Change presentation to have given shape hidden.
89   /// It suports FACE type of the shape to be hidden.
90   /// If presentation type is greater than FACE, the SHELL with be shown with the FACE hidden
91   /// It is possible to hide more than one FACE by calling the method with given FACES
92   /// Visual state of the face is controlled by the second parameter
93   /// \param theShapes a container of shape objects
94   /// \returns true if the presentation is changed, or false (if for example it was hidden)
95   Standard_EXPORT void setSubShapeHidden(const TopoDS_ListOfShape& theShapes);
96
97   /// Returns true if parameter shape has been hidden
98   /// \param theShape sub-shape of the presentation shape
99   /// \return boolean value
100   Standard_EXPORT bool isSubShapeHidden(const TopoDS_Shape& theShape);
101
102   /// Returns hidden sub shapes list
103   Standard_EXPORT const TopoDS_ListOfShape& hiddenSubShapes() const
104   { return myHiddenSubShapes; }
105
106   /// Returns true if there are no hidden sub shapes or original shape has at least one not hidden
107   /// \param theShapesToSkip container of shape to be hidden in the presentation (faces)
108   /// \return boolean value
109   Standard_EXPORT bool hasSubShapeVisible(const TopoDS_ListOfShape& theShapesToSkip);
110
111   /// Set transparency of hidden sub shapes: if value is 1, shapes are entirely hidden
112   /// \param theTransparency transparency value
113   /// \return false if parameter is out of [0, 1]
114   Standard_EXPORT bool setHiddenSubShapeTransparency(double theTransparency);
115
116   /// Returns the original shape of the presentation
117   Standard_EXPORT TopoDS_Shape originalShape() const { return myOriginalShape; }
118
119   /// Returns True if the original shape is substituted by a corresponded shell
120   Standard_EXPORT bool isSubstituted() const { return myIsSubstituted; }
121
122   /// Set number of Iso-lines
123   /// \param theU a number of U Iso-lines
124   /// \param theV a number of V Iso-lines
125   Standard_EXPORT void setIsolinesNumber(int theU, int theV) {
126     myUIsoAspect->SetNumber(theU); myVIsoAspect->SetNumber(theV);
127   }
128
129   /// Returns number of U Iso-lines
130   Standard_EXPORT int UIsoLines() const {
131     return myUIsoAspect->Number();
132   }
133
134   /// Returns number of V Iso-lines
135   Standard_EXPORT int VIsoLines() const {
136     return myVIsoAspect->Number();
137   }
138
139   DEFINE_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape)
140
141 protected:
142   /// Redefinition of virtual function
143   Standard_EXPORT virtual void Compute(
144     const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
145     const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
146
147   /// Redefinition of virtual function
148   Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
149                                                 const Standard_Integer theMode) ;
150
151 private:
152   /// If the shape of this presentation is Vertex, it appends custom sensitive and owners for it.
153   /// Owner is a usual Brep owner with "isDecomposite" in true. It is necessary to have "Ring"
154   /// highlight/selected marker.
155   /// \param theSelection a current filled selection
156   /// \param theMode a selection mode
157   /// \return true if the owner is created
158   bool appendVertexSelection(const Handle(SelectMgr_Selection)& aSelection,
159                              const Standard_Integer theMode);
160
161   /// Creates compound of vertices, edges and faces.
162   /// If the shape is COMPOUND, iterate by sub-shapes.
163   /// If the shape is SOLID/SHEL, explore shape by FACES,
164   /// If the shape is WIRE, explore shape by EDGES
165   /// \param theBuilder result compound builder
166   /// \param theCompound the result shape
167   /// \param theShape the processed shape
168   /// \param theHiddenSubShapes container of shapes to be skipped (faces)
169   void collectSubShapes(BRep_Builder& theBuilder, TopoDS_Shape& theCompound,
170     const TopoDS_Shape& theShape, const TopoDS_ListOfShape& theHiddenSubShapes);
171
172   void setEdgesDefaultColor();
173
174 private:
175   /// Reference to result object
176   ResultPtr myResult;
177
178   /// Original shape of the result object
179   TopoDS_Shape myOriginalShape;
180
181   bool myIsSubstituted;
182
183   /// Container of original Shape sub shape to be hidden and not selectable
184   TopoDS_ListOfShape myHiddenSubShapes;
185   TopoDS_Compound myVisibleCompound; /// compound of hidden sub shapes
186   TopoDS_Compound myHiddenCompound; /// compound of hidden sub shapes
187   double myTransparency; ///< transparency of hidden shapes, where 0 - there is no transparency
188   Handle(AIS_ColoredDrawer) myHiddenSubShapesDrawer; ///< drawer for hidden sub shapes
189
190   /// selection priority that will be added to the standard
191   /// selection priority of the selection entity
192   int myAdditionalSelectionPriority;
193
194   Handle(Prs3d_IsoAspect) myUIsoAspect;
195   Handle(Prs3d_IsoAspect) myVIsoAspect;
196 };
197
198
199 #endif