2daa5d95 |
1 | // Created on: 2020-09-07 |
2 | // Created by: Maria KRYLOVA |
3 | // Copyright (c) 2020 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef _AIS_LightSource_HeaderFile |
17 | #define _AIS_LightSource_HeaderFile |
18 | |
19 | #include <AIS_InteractiveObject.hxx> |
2daa5d95 |
20 | #include <SelectMgr_EntityOwner.hxx> |
21 | |
a3b2aaef |
22 | class Select3D_SensitiveSphere; |
2daa5d95 |
23 | |
24 | //! Interactive object for a light source. |
25 | //! Each type of light source has it's own presentation: |
26 | //! - Ambient light is displayed as a sphere at view corner; |
27 | //! - Positional light is represented by a sphere or marker; |
28 | //! - Spot light is represented by a cone; |
29 | //! - Directional light is represented by a set of arrows at the corner of view. |
30 | //! In addition, light source name could be displayed, and clicking on presentation will enable/disable light. |
31 | class AIS_LightSource : public AIS_InteractiveObject |
32 | { |
33 | friend class AIS_LightSourceOwner; |
34 | DEFINE_STANDARD_RTTIEXT(AIS_LightSource, AIS_InteractiveObject) |
35 | public: |
36 | |
37 | //! Initializes the light source by copying Graphic3d_CLight settings. |
38 | Standard_EXPORT AIS_LightSource (const Handle(Graphic3d_CLight)& theLightSource); |
39 | |
40 | //! Returns the light. |
41 | const Handle(Graphic3d_CLight)& Light() const { return myLightSource; } |
42 | |
43 | //! Set the light. |
44 | void SetLight (const Handle(Graphic3d_CLight)& theLight) |
45 | { |
46 | myLightSource = theLight; |
47 | SetToUpdate(); |
48 | } |
49 | |
50 | public: //! @name Light properties |
51 | |
52 | //! Returns TRUE if the light source name should be displayed; TRUE by default. |
53 | Standard_Boolean ToDisplayName() const { return myToDisplayName; } |
54 | |
55 | //! Show/hide light source name. |
56 | void SetDisplayName(Standard_Boolean theToDisplay) |
57 | { |
58 | if (myToDisplayName != theToDisplay) |
59 | { |
60 | myToDisplayName = theToDisplay; |
61 | SetToUpdate(); |
62 | } |
63 | } |
64 | |
65 | //! Returns TRUE to display light source range as sphere (positional light) or cone (spot light); TRUE by default. |
66 | //! Has no effect for non-zoomable presentation. |
67 | Standard_Boolean ToDisplayRange() const { return myToDisplayRange; } |
68 | |
69 | //! Show/hide light source range shaded presentation. |
70 | void SetDisplayRange (Standard_Boolean theToDisplay) |
71 | { |
72 | if (myToDisplayRange != theToDisplay) |
73 | { |
74 | myToDisplayRange = theToDisplay; |
75 | SetToUpdate(); |
76 | } |
77 | } |
78 | |
79 | //! Returns the size of presentation; 50 by default. |
80 | Standard_Real Size() const { return mySize; } |
81 | |
82 | //! Sets the size of presentation. |
83 | void SetSize (Standard_Real theSize) |
84 | { |
85 | if (mySize != theSize) |
86 | { |
87 | mySize = theSize; |
88 | SetToUpdate(); |
89 | } |
90 | } |
91 | |
a3b2aaef |
92 | //! Returns Sensitive sphere arc size in pixels; 20 by default. |
93 | Standard_Integer ArcSize() const { return mySensSphereArcSize; } |
94 | |
95 | //! Sets the size of sensitive sphere arc. |
96 | void SetArcSize (Standard_Integer theSize) |
97 | { |
98 | if (mySensSphereArcSize != theSize) |
99 | { |
100 | mySensSphereArcSize = theSize; |
101 | SetToUpdate(); |
102 | } |
103 | } |
104 | |
2daa5d95 |
105 | //! Returns TRUE if transform-persistence is allowed; |
106 | //! TRUE by default for Ambient and Directional lights |
107 | //! and FALSE by default for Positional and Spot lights. |
108 | bool IsZoomable() const { return myIsZoomable; } |
109 | |
110 | //! Sets if transform-persistence is allowed. |
111 | void SetZoomable (bool theIsZoomable) |
112 | { |
113 | if (myIsZoomable != theIsZoomable) |
114 | { |
115 | myIsZoomable = theIsZoomable; |
116 | SetToUpdate(); |
117 | } |
118 | } |
119 | |
a3b2aaef |
120 | //! Sets if dragging is allowed. |
121 | void SetDraggable (bool theIsDraggable) |
122 | { |
123 | if (myIsDraggable != theIsDraggable) |
124 | { |
125 | myIsDraggable = theIsDraggable; |
126 | } |
127 | } |
128 | |
2daa5d95 |
129 | //! Returns TRUE if mouse click will turn light on/off; TRUE by default. |
130 | bool ToSwitchOnClick() const { return myToSwitchOnClick; } |
131 | |
132 | //! Sets if mouse click should turn light on/off. |
133 | void SetSwitchOnClick (bool theToHandle) { myToSwitchOnClick = theToHandle; } |
134 | |
135 | //! Returns a number of directional light arrows to display; 5 by default. |
136 | Standard_Integer NbArrows() const { return myNbArrows; } |
137 | |
138 | //! Returns a number of directional light arrows to display (supported values: 1, 3, 5, 9). |
139 | void SetNbArrows (Standard_Integer theNbArrows) |
140 | { |
141 | if (myNbArrows != theNbArrows) |
142 | { |
143 | myNbArrows = theNbArrows; |
144 | SetToUpdate(); |
145 | } |
146 | } |
147 | |
148 | //! Returns light source icon. |
149 | //! @param theIsEnabled [in] marker index for enabled/disabled light source states |
150 | const Handle(Graphic3d_MarkerImage)& MarkerImage (bool theIsEnabled) const { return myMarkerImages[theIsEnabled ? 1 : 0]; } |
151 | |
152 | //! Returns light source icon. |
153 | //! @param theIsEnabled [in] marker index for enabled/disabled light source states |
154 | Aspect_TypeOfMarker MarkerType (bool theIsEnabled) const { return myMarkerTypes[theIsEnabled ? 1 : 0]; } |
155 | |
156 | //! Sets custom icon to light source. |
157 | void SetMarkerImage (const Handle(Graphic3d_MarkerImage)& theImage, |
158 | bool theIsEnabled) |
159 | { |
160 | myMarkerImages[theIsEnabled ? 1 : 0] = theImage; |
161 | myMarkerTypes [theIsEnabled ? 1 : 0] = !theImage.IsNull() |
162 | ? Aspect_TOM_USERDEFINED |
163 | : (theIsEnabled ? Aspect_TOM_O_POINT : Aspect_TOM_O_X); |
164 | } |
165 | |
166 | //! Sets standard icon to light source. |
167 | void SetMarkerType (Aspect_TypeOfMarker theType, |
168 | bool theIsEnabled) |
169 | { |
170 | myMarkerTypes[theIsEnabled ? 1 : 0] = theType; |
171 | } |
172 | |
173 | //! Returns tessellation level for quadric surfaces; 30 by default. |
174 | Standard_Integer NbSplitsQuadric() const { return myNbSplitsQuadric; } |
175 | |
176 | //! Sets tessellation level for quadric surfaces. |
177 | void SetNbSplitsQuadric (Standard_Integer theNbSplits) { myNbSplitsQuadric = theNbSplits; } |
178 | |
179 | //! Returns tessellation level for arrows; 20 by default. |
180 | Standard_Integer NbSplitsArrow() const { return myNbSplitsArrow; } |
181 | |
182 | //! Sets tessellation level for arrows. |
183 | void SetNbSplitsArrow (Standard_Integer theNbSplits) { myNbSplitsArrow = theNbSplits; } |
184 | |
185 | //! Returns kind of the object. |
186 | virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE { return AIS_KindOfInteractive_LightSource; } |
187 | |
188 | protected: |
189 | |
190 | //! Return true if specified display mode is supported: 0 for main presentation and 1 for highlight. |
191 | virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE |
192 | { |
193 | return theMode == 0 |
194 | || theMode == 1; |
195 | } |
196 | |
197 | //! Computes selection sensitive zones(triangulation) for light source presentation. |
decbff0d |
198 | Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr, |
2daa5d95 |
199 | const Handle(Prs3d_Presentation)& thePrs, |
200 | const Standard_Integer theMode) Standard_OVERRIDE; |
201 | |
202 | //! Fills presentation. |
203 | Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, |
204 | const Standard_Integer theMode) Standard_OVERRIDE; |
205 | |
a3b2aaef |
206 | //! Drag object in the viewer. |
207 | //! @param[in] theCtx interactive context |
208 | //! @param[in] theView active View |
209 | //! @param[in] theOwner the owner of detected entity |
210 | //! @param[in] theDragFrom drag start point |
211 | //! @param[in] theDragTo drag end point |
212 | //! @param[in] theAction drag action |
213 | //! @return FALSE if object rejects dragging action (e.g. AIS_DragAction_Start) |
214 | Standard_EXPORT virtual Standard_Boolean ProcessDragging (const Handle(AIS_InteractiveContext)& theCtx, |
215 | const Handle(V3d_View)& theView, |
216 | const Handle(SelectMgr_EntityOwner)& theOwner, |
217 | const Graphic3d_Vec2i& theDragFrom, |
218 | const Graphic3d_Vec2i& theDragTo, |
219 | const AIS_DragAction theAction) Standard_OVERRIDE; |
220 | |
2daa5d95 |
221 | //! Sets new local transformation, which is propagated to Graphic3d_CLight instance. |
222 | Standard_EXPORT virtual void setLocalTransformation (const Handle(TopLoc_Datum3D)& theTrsf) Standard_OVERRIDE; |
223 | |
224 | //! Updates local transformation basing on a type of light source. |
225 | Standard_EXPORT virtual void updateLightLocalTransformation(); |
226 | |
227 | //! Updates transform persistence basing on a type of light source. |
228 | Standard_EXPORT virtual void updateLightTransformPersistence(); |
229 | |
230 | //! Sets color of light. |
231 | Standard_EXPORT virtual void updateLightAspects(); |
232 | |
233 | //! Compute ambient light source presentation as a sphere at view corner. |
234 | Standard_EXPORT virtual void computeAmbient (const Handle(Prs3d_Presentation)& thePrs, |
235 | const Standard_Integer theMode); |
236 | |
237 | //! Compute directional light source presentation as a set of arrows at view corner. |
238 | Standard_EXPORT virtual void computeDirectional (const Handle(Prs3d_Presentation)& thePrs, |
239 | const Standard_Integer theMode); |
240 | |
241 | //! Compute positional light source presentation as a sphere of either fixed size (no range) or of size representing a maximum range. |
242 | Standard_EXPORT virtual void computePositional (const Handle(Prs3d_Presentation)& thePrs, |
243 | const Standard_Integer theMode); |
244 | |
245 | //! Compute spot light source presentation as a cone. |
246 | Standard_EXPORT virtual void computeSpot (const Handle(Prs3d_Presentation)& thePrs, |
247 | const Standard_Integer theMode); |
248 | |
249 | protected: |
250 | |
251 | Handle(Graphic3d_CLight) myLightSource; //!< displayed light source |
252 | |
253 | Handle(Graphic3d_AspectMarker3d) myDisabledMarkerAspect; //!< disabled light source marker style |
254 | Handle(Graphic3d_AspectLine3d) myArrowLineAspectShadow; //!< arrow shadow style |
255 | Handle(Graphic3d_MarkerImage) myMarkerImages[2]; //!< icon of disabled (0) and enabled (1) light |
a3b2aaef |
256 | Handle(Select3D_SensitiveSphere) mySensSphere; //!< sensitive sphere of directional light source |
2daa5d95 |
257 | Aspect_TypeOfMarker myMarkerTypes[2]; //!< icon of disabled (0) and enabled (1) light |
258 | Aspect_TypeOfMarker myCodirMarkerType; //!< icon of arrow co-directional to camera direction (look from) |
259 | Aspect_TypeOfMarker myOpposMarkerType; //!< icon of arrow opposite to camera direction (look at) |
260 | |
a3b2aaef |
261 | gp_Trsf myLocTrsfStart; //!< object transformation before transformation |
262 | Standard_Real mySize; //!< presentation size |
263 | Standard_Integer myNbArrows; //!< number of directional light arrows |
264 | Standard_Integer myNbSplitsQuadric; //!< tessellation level for quadric surfaces |
265 | Standard_Integer myNbSplitsArrow; //!< tessellation level for arrows |
266 | Standard_Integer mySensSphereArcSize; //! sensitive sphere arc size in pixels |
267 | Standard_Boolean myIsZoomable; //!< flag to allow/disallow transform-persistence when possible |
268 | Standard_Boolean myIsDraggable; //!< flag to allow/disallow rotate directional light source by dragging |
269 | Standard_Boolean myToDisplayName; //!< flag to show/hide name |
270 | Standard_Boolean myToDisplayRange; //!< flag to show/hide range of positional/spot light |
271 | Standard_Boolean myToSwitchOnClick; //!< flag to handle mouse click to turn light on/off |
2daa5d95 |
272 | |
273 | }; |
274 | |
275 | //! Owner of AIS_LightSource presentation. |
276 | class AIS_LightSourceOwner : public SelectMgr_EntityOwner |
277 | { |
278 | DEFINE_STANDARD_RTTIEXT(AIS_LightSourceOwner, SelectMgr_EntityOwner) |
279 | public: |
280 | |
281 | //! Main constructor. |
282 | Standard_EXPORT AIS_LightSourceOwner (const Handle(AIS_LightSource)& theObject, |
283 | Standard_Integer thePriority = 5); |
284 | |
285 | //! Handle mouse button click event. |
286 | Standard_EXPORT virtual Standard_Boolean HandleMouseClick (const Graphic3d_Vec2i& thePoint, |
287 | Aspect_VKeyMouse theButton, |
288 | Aspect_VKeyFlags theModifiers, |
289 | bool theIsDoubleClick) Standard_OVERRIDE; |
290 | |
a3b2aaef |
291 | //! Highlights selectable object's presentation with display mode in presentation manager with given highlight style. |
292 | //! Also a check for auto-highlight is performed - if selectable object manages highlighting on its own, |
293 | //! execution will be passed to SelectMgr_SelectableObject::HilightOwnerWithColor method. |
294 | Standard_EXPORT virtual void HilightWithColor (const Handle(PrsMgr_PresentationManager)& thePrsMgr, |
295 | const Handle(Prs3d_Drawer)& theStyle, |
296 | const Standard_Integer theMode) Standard_OVERRIDE; |
297 | |
298 | //! Always update dynamic highlighting. |
299 | Standard_EXPORT virtual Standard_Boolean IsForcedHilight() const Standard_OVERRIDE; |
300 | |
2daa5d95 |
301 | }; |
302 | |
303 | #endif // _AIS_LightSource_HeaderFile |