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