Salome HOME
4c852d5a4ec94816806f81fba34dcb81fe041efc
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_SymbolPrs.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_SymbolPrs.h
4 // Created:     12 March 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #ifndef SketcherPrs_SymbolPrs_H
8 #define SketcherPrs_SymbolPrs_H
9
10 #include "SketcherPrs_SensitivePoint.h"
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_AttributeRefList.h>
13
14 #include <AIS_InteractiveObject.hxx>
15 #include <GeomAPI_Ax3.h>
16 #include <Graphic3d_ArrayOfPoints.hxx>
17 #include <Graphic3d_AspectMarker3d.hxx>
18 #include <Image_AlienPixMap.hxx>
19 #include <SelectMgr_EntityOwner.hxx>
20 #include <Select3D_EntitySequence.hxx>
21
22 #include <Standard_DefineHandle.hxx>
23 #include <map>
24
25 #include <OpenGl_Workspace.hxx>
26
27 class OpenGl_Context;
28
29
30 DEFINE_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject)
31
32 class SketcherPrs_SymbolArray;
33 /**
34 * \ingroup GUI
35 * A base class of constraint presentation which is represented by an icon
36 */
37 class SketcherPrs_SymbolPrs: public AIS_InteractiveObject
38 {
39 public:
40   /// Constructor
41   /// \param theConstraint a constraint feature
42   /// \param thePlane a coordinate plane of current sketch
43   Standard_EXPORT SketcherPrs_SymbolPrs(ModelAPI_Feature* theConstraint,
44                         const std::shared_ptr<GeomAPI_Ax3>& thePlane);
45
46   virtual ~SketcherPrs_SymbolPrs();
47
48   //! Method which draws selected owners ( for fast presentation draw )
49   Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
50                                                const SelectMgr_SequenceOfOwner& theOwners);
51
52   //! Method which hilight an owner belonging to
53   //! this selectable object  ( for fast presentation draw )
54   Standard_EXPORT virtual void HilightOwnerWithColor(
55     const Handle(PrsMgr_PresentationManager3d)& thePM,
56     const Handle(Graphic3d_HighlightStyle)& theStyle,
57     const Handle(SelectMgr_EntityOwner)& theOwner);
58
59   /// Returns sketcher plane
60   Standard_EXPORT std::shared_ptr<GeomAPI_Ax3> plane() const { return myPlane; }
61
62   /// Returns feature object
63   Standard_EXPORT ModelAPI_Feature* feature() const { return myConstraint; }
64
65   /// Return array of points where symbols will be placed
66   const Handle(Graphic3d_ArrayOfPoints)& pointsArray() const { return myPntArray; }
67
68   /// Set state of the presentation, in case of conflicting state, the icon of the presentation is
69   /// visualized in error color. The state is stored in an internal field, so should be changed
70   /// when constraint become not conflicting
71   /// \param theConflicting a state
72   /// \param theColor a color for conflicting object
73   Standard_EXPORT void SetConflictingConstraint(const bool& theConflicting,
74                                                 const std::vector<int>& theColor);
75
76   /// Add a bounding box of the presentation to common bounding box
77   /// \param theBndBox the common bounding box to update
78   Standard_EXPORT virtual void BoundingBox (Bnd_Box& theBndBox) Standard_OVERRIDE;
79
80   DEFINE_STANDARD_RTTIEXT(SketcherPrs_SymbolPrs, AIS_InteractiveObject)
81
82 protected:
83   /// Redefinition of virtual function
84   Standard_EXPORT virtual void Compute(
85     const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
86     const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
87
88   /// Redefinition of virtual function
89   /// \param aSelection selection
90   /// \param aMode compute mode
91   Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
92     const Standard_Integer aMode);
93
94   /// Returns an icon file name. Has to be redefined in successors
95   virtual const char* iconName() const = 0;
96
97   /// Check and creates if it is necessary myAspect member.
98   /// It has to be called before the object computation
99   virtual void prepareAspect();
100
101   /// Returns icon corresponded to the current constraint type
102   Handle(Image_AlienPixMap) icon();
103
104   /// Add a line into the given group
105   /// \param theGroup a group for drawing
106   /// \param theAttrName an attribute name which corresponds to referenced line
107   void addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const;
108
109   /// Redefine this function in order to add additiona lines of constraint base
110   /// \param thePrs a presentation
111   /// \param theColor a color of additiona lines
112   virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const {}
113
114   /// Update myPntArray according to presentation positions
115   /// \return true in case of success
116   virtual bool updateIfReadyToDisplay(double theStep) const { return true; }
117
118   /// Draw a shape into the given presentation scene
119   /// \param theShape the shape to draw
120   /// \param thePrs the presentation scene
121   void drawShape(const std::shared_ptr<GeomAPI_Shape>& theShape,
122     const Handle(Prs3d_Presentation)& thePrs) const;
123
124   /// Draw a list of shapes stored in a RefListAttribute
125   /// \param theListAttr the attribute of reference3s list
126   /// \param thePrs the presentation scene
127   void drawListOfShapes(const std::shared_ptr<ModelAPI_AttributeRefList>& theListAttr,
128                         const Handle(Prs3d_Presentation)& thePrs) const;
129
130 protected:
131   /// Constraint feature
132   ModelAPI_Feature* myConstraint;
133
134   /// Plane of the current sketcher
135   std::shared_ptr<GeomAPI_Ax3> myPlane;
136
137   /// Aspect for entities drawing
138   Handle(Graphic3d_AspectMarker3d) myAspect;
139
140   /// Array of symbols positions
141   mutable Handle(Graphic3d_ArrayOfPoints) myPntArray;
142
143   /// An owner object of the presentation
144   Handle(SelectMgr_EntityOwner) myOwner;
145
146 private:
147   /// Static map to collect constraints icons {IconName : IconPixMap}
148   static std::map<const char*, Handle(Image_AlienPixMap)> myIconsMap;
149
150   Select3D_EntitySequence mySPoints;
151
152   Quantity_Color myColor;
153   bool myIsConflicting; /// state if the presentation is visualized in error state
154   Handle(Image_AlienPixMap) myErrorIcon;
155   Handle(Graphic3d_MarkerImage) myErrorImage;
156
157   friend class SketcherPrs_SymbolArray;
158 };
159
160 #endif