1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_SymbolPrs.h
4 // Created: 12 March 2015
5 // Author: Vitaly SMETANNIKOV
7 #ifndef SketcherPrs_SymbolPrs_H
8 #define SketcherPrs_SymbolPrs_H
10 #include "SketcherPrs_SensitivePoint.h"
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_AttributeRefList.h>
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>
22 #include <Standard_DefineHandle.hxx>
25 #include <OpenGl_Workspace.hxx>
30 DEFINE_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject)
34 * A base class of constraint presentation which is represented by an icon
36 class SketcherPrs_SymbolPrs: public AIS_InteractiveObject
40 /// \param theConstraint a constraint feature
41 /// \param thePlane a coordinate plane of current sketch
42 Standard_EXPORT SketcherPrs_SymbolPrs(ModelAPI_Feature* theConstraint,
43 const std::shared_ptr<GeomAPI_Ax3>& thePlane);
45 virtual ~SketcherPrs_SymbolPrs();
47 //! Method which draws selected owners ( for fast presentation draw )
48 Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
49 const SelectMgr_SequenceOfOwner& theOwners);
51 //! Method which hilight an owner belonging to
52 //! this selectable object ( for fast presentation draw )
53 Standard_EXPORT virtual void HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
54 const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner);
56 /// Returns sketcher plane
57 Standard_EXPORT std::shared_ptr<GeomAPI_Ax3> plane() const { return myPlane; }
59 /// Returns feature object
60 Standard_EXPORT ModelAPI_Feature* feature() const { return myConstraint; }
62 /// Return array of points where symbols will be placed
63 const Handle(Graphic3d_ArrayOfPoints)& pointsArray() const { return myPntArray; }
65 /// Set state of the presentation, in case of conflicting state, the icon of the presentation is
66 /// visualized in error color. The state is stored in an internal field, so should be changed when
67 /// constraint become not conflicting
68 /// \param theConflicting a state
69 /// \param theColor a color for conflicting object
70 Standard_EXPORT void SetConflictingConstraint(const bool& theConflicting, const std::vector<int>& theColor);
72 /// Render of the presentation
73 /// \param theWorkspace is OpenGl workspace
74 void Render(const Handle(OpenGl_Workspace)& theWorkspace) const;
76 /// Release used OpenGl resources
77 /// \param theContext is an OpenGL context
78 void Release (OpenGl_Context* theContext);
80 /// Add a bounding box of the presentation to common bounding box
81 /// \param theBndBox the common bounding box to update
82 Standard_EXPORT virtual void BoundingBox (Bnd_Box& theBndBox) Standard_OVERRIDE;
84 DEFINE_STANDARD_RTTI(SketcherPrs_SymbolPrs)
87 /// Redefinition of virtual function
88 Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
89 const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
91 /// Redefinition of virtual function
92 /// \param aSelection selection
93 /// \param aMode compute mode
94 Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
95 const Standard_Integer aMode);
97 /// Returns an icon file name. Has to be redefined in successors
98 virtual const char* iconName() const = 0;
100 /// Check and creates if it is necessary myAspect member.
101 /// It has to be called before the object computation
102 virtual void prepareAspect();
104 /// Returns icon corresponded to the current constraint type
105 Handle(Image_AlienPixMap) icon();
107 /// Add a line into the given group
108 /// \param theGroup a group for drawing
109 /// \param theAttrName an attribute name which corresponds to referenced line
110 void addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const;
112 /// Redefine this function in order to add additiona lines of constraint base
113 /// \param thePrs a presentation
114 /// \param theColor a color of additiona lines
115 virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const {}
117 /// Update myPntArray according to presentation positions
118 /// \return true in case of success
119 virtual bool updatePoints(double theStep) const { return true; }
121 /// Draw a shape into the given presentation scene
122 /// \param theShape the shape to draw
123 /// \param thePrs the presentation scene
124 void drawShape(const std::shared_ptr<GeomAPI_Shape>& theShape,
125 const Handle(Prs3d_Presentation)& thePrs) const;
127 /// Draw a list of shapes stored in a RefListAttribute
128 /// \param theListAttr the attribute of reference3s list
129 /// \param thePrs the presentation scene
130 void drawListOfShapes(const std::shared_ptr<ModelAPI_AttributeRefList>& theListAttr,
131 const Handle(Prs3d_Presentation)& thePrs) const;
134 /// Constraint feature
135 ModelAPI_Feature* myConstraint;
137 /// Plane of the current sketcher
138 std::shared_ptr<GeomAPI_Ax3> myPlane;
140 /// Aspect for entities drawing
141 Handle(Graphic3d_AspectMarker3d) myAspect;
143 /// Array of symbols positions
144 mutable Handle(Graphic3d_ArrayOfPoints) myPntArray;
146 /// An owner object of the presentation
147 Handle(SelectMgr_EntityOwner) myOwner;
150 /// Static map to collect constraints icons {IconName : IconPixMap}
151 static std::map<const char*, Handle(Image_AlienPixMap)> myIconsMap;
153 mutable Handle(OpenGl_VertexBuffer) myVboAttribs;
155 Select3D_EntitySequence mySPoints;
157 bool myIsConflicting; /// state if the presentation is visualized in error state
158 Handle(Image_AlienPixMap) myErrorIcon;
159 Handle(Graphic3d_MarkerImage) myErrorImage;