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