Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / PartSet / PartSet_OperationPrs.h
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef PartSet_OperationPrs_H
22 #define PartSet_OperationPrs_H
23
24 #include "PartSet.h"
25
26 #include <ModelAPI_Object.h>
27 #include <ModelAPI_Feature.h>
28 #include <ModelAPI_Result.h>
29 #include <ModelAPI_Attribute.h>
30
31 #include <ModuleBase_IWorkshop.h>
32
33 #include <GeomAPI_Shape.h>
34
35 #include <ViewerData_AISShape.hxx>
36 #include <Standard_DefineHandle.hxx>
37
38 #include <Quantity_Color.hxx>
39 #include <NCollection_List.hxx>
40 #include <NCollection_DataMap.hxx>
41 #include <TopoDS_Shape.hxx>
42 #include <AIS_InteractiveObject.hxx>
43
44 #include <QMap>
45 #include <QList>
46
47 #include <list>
48
49 DEFINE_STANDARD_HANDLE(PartSet_OperationPrs, ViewerData_AISShape)
50
51 class XGUI_Displayer;
52 class SelectMgr_Selection;
53
54 /**
55 * \ingroup GUI
56 * A redefinition of standard AIS Interactive Object in order to provide colored presentation of
57 * a list of shapes. It contains a shapes where the parameter feature refers. It processes the following
58 * types of attributes: ModelAPI_AttributeSelectionList, ModelAPI_AttributeRefAttr,
59 * ModelAPI_AttributeSelection and ModelAPI_AttributeReference.
60 * The selection for this presentation is absent.
61 */
62 class PartSet_OperationPrs : public ViewerData_AISShape
63 {
64 public:
65   /// Constructor
66   Standard_EXPORT PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop);
67
68   /// Returns true if the feature contains shapes or results
69   bool hasShapes();
70
71   /// Sets the colors for the presentation compute
72   /// \param theColor an argument shapes color
73   void setShapeColor(const Quantity_Color& theColor);
74
75   /// Switch on using of the AIS presentation with of the shape object increased on the delta
76   void useAISWidth();
77
78   DEFINE_STANDARD_RTTIEXT(PartSet_OperationPrs, ViewerData_AISShape)
79
80 protected:
81   /// Redefinition of virtual function
82   Standard_EXPORT virtual void Compute(
83             const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
84             const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
85
86   /// Redefinition of virtual function
87   Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
88                                                 const Standard_Integer aMode) ;
89
90 protected:
91   /// list of visualized shapes
92   /// \return a map of shapes
93   NCollection_DataMap<TopoDS_Shape, Handle(AIS_InteractiveObject)>& shapesMap();
94
95 private:
96   /// Fills the map by the feature object and shapes, which should be visuaziled
97   /// Gets feature attributes, collect objects to whom the attributes refer
98   /// \param theFeature a current feature
99   /// \param theWorkshop a current workshop
100   /// \param theObjectShapes an output map
101   /// \param theObjectShape an output map of objects
102   static void getFeatureShapes(const FeaturePtr& theFeature,
103                                ModuleBase_IWorkshop* theWorkshop,
104                                QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes);
105
106   /// Fills the map by the feature object and shapes, which should be visuaziled
107   /// Gets feature attributes, collect objects to whom the attributes refer
108   /// \param theFeature a current feature
109   /// \param theWorkshop a current workshop
110   /// \param theObjectShapes an output map
111   /// \param theObjectShape an output map of objects
112   static void getResultShapes(const FeaturePtr& theFeature,
113                               ModuleBase_IWorkshop* theWorkshop,
114                               QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes,
115                               const bool theListShouldBeCleared = true);
116
117   /// Fills the map by the feature presentation if the feature is presentable
118   /// \param theFeature a current feature
119   /// \param theWorkshop a current workshop
120   /// \param theObjectShapes an output map
121   /// \param theObjectShape an output map of objects
122   static void getPresentationShapes(const FeaturePtr& theFeature,
123                               ModuleBase_IWorkshop* theWorkshop,
124                               QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes,
125                               const bool theListShouldBeCleared = true);
126
127   /// Fills the map by the feature object and shapes, which should be visuaziled
128   /// Gets the active widget, obtain the highlighted presentations if it has such and
129   /// fill map by object and shapes
130   /// \param theWorkshop a current workshop
131   /// \param theObjectShapes an output map of objects
132   static void getHighlightedShapes(ModuleBase_IWorkshop* theWorkshop,
133                                    QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes);
134
135   /// Returns true if the attribute type belong to reference attribute
136   /// \param theAttribute an attribute
137   /// \return a boolean value
138   static bool isSelectionAttribute(const AttributePtr& theAttribute);
139
140   /// Appends the shape for the result into the container if the result is visible and
141   /// the shape is not null.
142   /// \param theWorkshop a current workshop
143   /// \param theResult an object to be appended
144   /// \param theGeomShape a shape to be appended
145   /// \param theObjectShapes a filled container
146   static void addValue(const ObjectPtr& theObject, const GeomShapePtr& theShape,
147                 const FeaturePtr& theFeature, ModuleBase_IWorkshop* theWorkshop,
148                 QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes);
149
150   /// Appends the shape for the result into the container if the result is visible and
151   /// the shape is not null.
152   /// \param theWorkshop a current workshop
153   /// \param theObject an object to be appended
154   /// \param theGeomShape a shape to be appended
155   /// \param theObjectShapes a filled container
156   static void appendShapeIfVisible(ModuleBase_IWorkshop* theWorkshop,
157                                    const ObjectPtr& theObject,
158                                    GeomShapePtr theGeomShape,
159                                    QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes);
160
161   /// Fills the list of shapes by map of model objects
162   /// \param theFeatureShape a container to find shapes
163   /// \param theShapesMap an out container
164   static void fillShapeList(const QMap<ObjectPtr, QList<GeomShapePtr> >& theFeatureShapes,
165           ModuleBase_IWorkshop* theWorkshop,
166           NCollection_DataMap<TopoDS_Shape, Handle(AIS_InteractiveObject)>& theShapeToPrsMap);
167
168 private:
169   /// list of visualized shapes
170   NCollection_DataMap<TopoDS_Shape, Handle(AIS_InteractiveObject)> myShapeToPrsMap;
171
172   ModuleBase_IWorkshop* myWorkshop; /// current workshop
173   Quantity_Color myShapeColor; /// color of feature depended shapes
174
175   /// flag if the width of a shape object should be used for the shape visualization
176   bool myUseAISWidth;
177
178   friend class PartSet_CustomPrs;
179 };
180
181
182 #endif