]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_OperationPrs.h
Salome HOME
#1404 Random crash with Shaper: AIS presentations: operation prs, result sketch prs...
[modules/shaper.git] / src / PartSet / PartSet_OperationPrs.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_OperationPrs.h
4 // Created:     01 Jul 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #ifndef PartSet_OperationPrs_H
8 #define PartSet_OperationPrs_H
9
10 #include "PartSet.h"
11
12 #include <ModelAPI_Object.h>
13 #include <ModelAPI_Feature.h>
14 #include <ModelAPI_Result.h>
15 #include <ModelAPI_Attribute.h>
16
17 #include <ModuleBase_IWorkshop.h>
18
19 #include <GeomAPI_Shape.h>
20
21 #include <ViewerData_AISShape.hxx>
22 #include <Standard_DefineHandle.hxx>
23
24 #include <Quantity_Color.hxx>
25 #include <NCollection_List.hxx>
26
27 #include <QMap>
28 #include <QList>
29
30 #include <list>
31
32 DEFINE_STANDARD_HANDLE(PartSet_OperationPrs, ViewerData_AISShape)
33
34 class XGUI_Displayer;
35
36 /**
37 * \ingroup GUI
38 * A redefinition of standard AIS Interactive Object in order to provide colored presentation of
39 * a list of shapes. It contains a shapes where the parameter feature refers. It processes the following
40 * types of attributes: ModelAPI_AttributeSelectionList, ModelAPI_AttributeRefAttr,
41 * ModelAPI_AttributeSelection and ModelAPI_AttributeReference.
42 * The selection for this presentation is absent.
43 */
44 class PartSet_OperationPrs : public ViewerData_AISShape
45 {
46 public:
47   /// Constructor
48   Standard_EXPORT PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop);
49
50   /// Returns true if the feature contains shapes or results
51   bool hasShapes();
52
53   /// Sets the colors for the presentation compute
54   /// \param theColor an argument shapes color
55   void setShapeColor(const Quantity_Color& theColor);
56
57   /// Switch on using of the AIS presentation with of the shape object increased on the delta
58   void useAISWidth();
59
60   DEFINE_STANDARD_RTTI(PartSet_OperationPrs)
61
62 protected:
63   /// Redefinition of virtual function
64   Standard_EXPORT virtual void Compute(
65             const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
66             const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
67
68   /// Redefinition of virtual function
69   Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
70                                                 const Standard_Integer aMode) ;
71
72 protected:
73   /// Returns map of feature shapes to be able to fill it outside this class, e.g. in friend
74   /// \return a map of object to shape
75   QMap<ObjectPtr, QList<GeomShapePtr> >& featureShapes() { return myFeatureShapes; }
76
77 private:
78   /// Fills the map by the feature object and shapes, which should be visuaziled
79   /// Gets feature attributes, collect objects to whom the attributes refer
80   /// \param theFeature a current feature
81   /// \param theWorkshop a current workshop
82   /// \param theObjectShapes an output map
83   /// \param theObjectShape an output map of objects
84   static void getFeatureShapes(const FeaturePtr& theFeature,
85                                ModuleBase_IWorkshop* theWorkshop,
86                                QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes);
87
88   /// Fills the map by the feature object and shapes, which should be visuaziled
89   /// Gets feature attributes, collect objects to whom the attributes refer
90   /// \param theFeature a current feature
91   /// \param theWorkshop a current workshop
92   /// \param theObjectShapes an output map
93   /// \param theObjectShape an output map of objects
94   static void getResultShapes(const FeaturePtr& theFeature,
95                               ModuleBase_IWorkshop* theWorkshop,
96                               QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes,
97                               const bool theListShouldBeCleared = true);
98
99   /// Fills the map by the feature object and shapes, which should be visuaziled
100   /// Gets the active widget, obtain the highlighted presentations if it has such and
101   /// fill map by object and shapes
102   /// \param theWorkshop a current workshop
103   /// \param theObjectShapes an output map of objects
104   static void getHighlightedShapes(ModuleBase_IWorkshop* theWorkshop,
105                                    QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes);
106
107   /// Returns true if the attribute type belong to reference attribute
108   /// \param theAttribute an attribute
109   /// \return a boolean value
110   static bool isSelectionAttribute(const AttributePtr& theAttribute);
111
112   /// Appends the shape for the result into the container if the result is visible and
113   /// the shape is not null.
114   /// \param theWorkshop a current workshop
115   /// \param theResult an object to be appended
116   /// \param theGeomShape a shape to be appended
117   /// \param theObjectShapes a filled container
118   static void addValue(const ObjectPtr& theObject, const GeomShapePtr& theShape,
119                 const FeaturePtr& theFeature, ModuleBase_IWorkshop* theWorkshop,
120                 QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes);
121
122   /// Appends the shape for the result into the container if the result is visible and
123   /// the shape is not null.
124   /// \param theWorkshop a current workshop
125   /// \param theObject an object to be appended
126   /// \param theGeomShape a shape to be appended
127   /// \param theObjectShapes a filled container
128   static void appendShapeIfVisible(ModuleBase_IWorkshop* theWorkshop,
129                                    const ObjectPtr& theObject,
130                                    GeomShapePtr theGeomShape,
131                                    QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes);
132
133   /// Fills the list of shapes by map of model objects
134   /// \param theFeatureShape a container to find shapes
135   /// \param theShapesMap an out container
136   void fillShapeList(const QMap<ObjectPtr, QList<GeomShapePtr> >& theFeatureShapes,
137                      NCollection_DataMap<TopoDS_Shape, Handle(AIS_InteractiveObject)>& theShapeToPrsMap);
138
139 private:
140   NCollection_DataMap<TopoDS_Shape, Handle(AIS_InteractiveObject)> myShapeToPrsMap; /// list of visualized shapes
141
142   QMap<ObjectPtr, QList<GeomShapePtr> > myFeatureShapes; /// visualized shapes
143
144   ModuleBase_IWorkshop* myWorkshop; /// current workshop
145   Quantity_Color myShapeColor; /// color of feature depended shapes
146   bool myUseAISWidth; /// flag if the width of a shape object should be used for the shape visualization
147
148   friend class PartSet_CustomPrs;
149 };
150
151
152 #endif