1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #ifndef SketcherPrs_SymbolPrs_H
21 #define SketcherPrs_SymbolPrs_H
23 #include "SketcherPrs_SensitivePoint.h"
24 #include <ModelAPI_Feature.h>
25 #include <ModelAPI_AttributeRefList.h>
27 #include <AIS_InteractiveObject.hxx>
28 #include <GeomAPI_Ax3.h>
29 #include <Graphic3d_ArrayOfPoints.hxx>
30 #include <Graphic3d_AspectMarker3d.hxx>
31 #include <Image_AlienPixMap.hxx>
32 #include <SelectMgr_EntityOwner.hxx>
33 #include <Select3D_EntitySequence.hxx>
35 #include <Standard_DefineHandle.hxx>
38 #include <OpenGl_Workspace.hxx>
43 DEFINE_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject)
45 class SketcherPrs_SymbolArray;
48 * A base class of constraint presentation which is represented by an icon
50 class SketcherPrs_SymbolPrs: public AIS_InteractiveObject
54 /// \param theConstraint a constraint feature
55 /// \param thePlane a coordinate plane of current sketch
56 Standard_EXPORT SketcherPrs_SymbolPrs(ModelAPI_Feature* theConstraint,
57 const std::shared_ptr<GeomAPI_Ax3>& thePlane);
59 virtual ~SketcherPrs_SymbolPrs();
61 //! Method which draws selected owners ( for fast presentation draw )
62 Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
63 const SelectMgr_SequenceOfOwner& theOwners);
65 //! Method which hilight an owner belonging to
66 //! this selectable object ( for fast presentation draw )
67 Standard_EXPORT virtual void HilightOwnerWithColor(
68 const Handle(PrsMgr_PresentationManager3d)& thePM,
69 const Handle(Graphic3d_HighlightStyle)& theStyle,
70 const Handle(SelectMgr_EntityOwner)& theOwner);
72 /// Returns sketcher plane
73 Standard_EXPORT std::shared_ptr<GeomAPI_Ax3> plane() const { return myPlane; }
75 /// Returns feature object
76 Standard_EXPORT ModelAPI_Feature* feature() const { return myConstraint; }
78 /// Return array of points where symbols will be placed
79 const Handle(Graphic3d_ArrayOfPoints)& pointsArray() const { return myPntArray; }
81 /// Set state of the presentation, in case of conflicting state, the icon of the presentation is
82 /// visualized in error color. The state is stored in an internal field, so should be changed
83 /// when constraint become not conflicting
84 /// \param theColor a color for conflicting object
85 Standard_EXPORT void SetCustomColor(const std::vector<int>& theColor);
87 /// Add a bounding box of the presentation to common bounding box
88 /// \param theBndBox the common bounding box to update
89 Standard_EXPORT virtual void BoundingBox (Bnd_Box& theBndBox) Standard_OVERRIDE;
91 DEFINE_STANDARD_RTTIEXT(SketcherPrs_SymbolPrs, AIS_InteractiveObject)
94 /// Redefinition of virtual function
95 Standard_EXPORT virtual void Compute(
96 const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
97 const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
99 /// Redefinition of virtual function
100 /// \param aSelection selection
101 /// \param aMode compute mode
102 Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
103 const Standard_Integer aMode);
105 /// Returns an icon file name. Has to be redefined in successors
106 virtual const char* iconName() const = 0;
108 /// Check and creates if it is necessary myAspect member.
109 /// It has to be called before the object computation
110 virtual void prepareAspect();
112 /// Returns icon corresponded to the current constraint type
113 Handle(Image_AlienPixMap) icon();
115 /// Add a line into the given group
116 /// \param theGroup a group for drawing
117 /// \param theAttrName an attribute name which corresponds to referenced line
118 void addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const;
120 /// Redefine this function in order to add additiona lines of constraint base
121 /// \param thePrs a presentation
122 /// \param theColor a color of additiona lines
123 virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const {}
125 /// Update myPntArray according to presentation positions
126 /// \return true in case of success
127 virtual bool updateIfReadyToDisplay(double theStep, bool withColor) const { return true; }
129 /// Draw a shape into the given presentation scene
130 /// \param theShape the shape to draw
131 /// \param thePrs the presentation scene
132 void drawShape(const std::shared_ptr<GeomAPI_Shape>& theShape,
133 const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
135 /// Draw a list of shapes stored in a RefListAttribute
136 /// \param theListAttr the attribute of reference3s list
137 /// \param thePrs the presentation scene
138 void drawListOfShapes(const std::shared_ptr<ModelAPI_AttributeRefList>& theListAttr,
139 const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
142 /// Constraint feature
143 ModelAPI_Feature* myConstraint;
145 /// Plane of the current sketcher
146 std::shared_ptr<GeomAPI_Ax3> myPlane;
148 /// Aspect for entities drawing
149 Handle(Graphic3d_AspectMarker3d) myAspect;
151 /// Array of symbols positions
152 mutable Handle(Graphic3d_ArrayOfPoints) myPntArray;
154 /// An owner object of the presentation
155 Handle(SelectMgr_EntityOwner) myOwner;
158 /// Static map to collect constraints icons {IconName : IconPixMap}
159 static std::map<const char*, Handle(Image_AlienPixMap)> myIconsMap;
161 Select3D_EntitySequence mySPoints;
163 bool myIsCustomColor; /// state if the presentation is visualized in custom color
164 Quantity_Color myCustomColor; /// the color of mid ring if there is a conflict
166 //bool myIsConflicting; /// state if the presentation is visualized in error state
167 Handle(Image_AlienPixMap) myErrorIcon;
168 Handle(Graphic3d_MarkerImage) myErrorImage;
170 friend class SketcherPrs_SymbolArray;