0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / AIS / AIS_LightSource.hxx
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>
20 #include <Graphic3d_CLight.hxx>
21 #include <SelectMgr_EntityOwner.hxx>
22
23 class Prs3d_ShadingAspect;
24
25 //! Interactive object for a light source.
26 //! Each type of light source has it's own presentation:
27 //! - Ambient light is displayed as a sphere at view corner;
28 //! - Positional light is represented by a sphere or marker;
29 //! - Spot light is represented by a cone;
30 //! - Directional light is represented by a set of arrows at the corner of view.
31 //! In addition, light source name could be displayed, and clicking on presentation will enable/disable light.
32 class AIS_LightSource : public AIS_InteractiveObject
33 {
34   friend class AIS_LightSourceOwner;
35   DEFINE_STANDARD_RTTIEXT(AIS_LightSource, AIS_InteractiveObject)
36 public:
37
38   //! Initializes the light source by copying Graphic3d_CLight settings.
39   Standard_EXPORT AIS_LightSource (const Handle(Graphic3d_CLight)& theLightSource);
40
41   //! Returns the light.
42   const Handle(Graphic3d_CLight)& Light() const { return myLightSource; }
43
44   //! Set the light.
45   void SetLight (const Handle(Graphic3d_CLight)& theLight)
46   {
47     myLightSource = theLight;
48     SetToUpdate();
49   }
50
51 public: //! @name Light properties
52
53   //! Returns TRUE if the light source name should be displayed; TRUE by default.
54   Standard_Boolean ToDisplayName() const { return myToDisplayName; }
55
56   //! Show/hide light source name.
57   void SetDisplayName(Standard_Boolean theToDisplay)
58   {
59     if (myToDisplayName != theToDisplay)
60     {
61       myToDisplayName = theToDisplay;
62       SetToUpdate();
63     }
64   }
65
66   //! Returns TRUE to display light source range as sphere (positional light) or cone (spot light); TRUE by default.
67   //! Has no effect for non-zoomable presentation.
68   Standard_Boolean ToDisplayRange() const { return myToDisplayRange; }
69
70   //! Show/hide light source range shaded presentation.
71   void SetDisplayRange (Standard_Boolean theToDisplay)
72   {
73     if (myToDisplayRange != theToDisplay)
74     {
75       myToDisplayRange = theToDisplay;
76       SetToUpdate();
77     }
78   }
79
80   //! Returns the size of presentation; 50 by default.
81   Standard_Real Size() const { return mySize; }
82
83   //! Sets the size of presentation.
84   void SetSize (Standard_Real theSize)
85   {
86     if (mySize != theSize)
87     {
88       mySize = theSize;
89       SetToUpdate();
90     }
91   }
92
93   //! Returns TRUE if transform-persistence is allowed;
94   //! TRUE by default for Ambient and Directional lights
95   //! and FALSE by default for Positional and Spot lights.
96   bool IsZoomable() const { return myIsZoomable; }
97
98   //! Sets if transform-persistence is allowed.
99   void SetZoomable (bool theIsZoomable)
100   {
101     if (myIsZoomable != theIsZoomable)
102     {
103       myIsZoomable = theIsZoomable;
104       SetToUpdate();
105     }
106   }
107
108   //! Returns TRUE if mouse click will turn light on/off; TRUE by default.
109   bool ToSwitchOnClick() const { return myToSwitchOnClick; }
110
111   //! Sets if mouse click should turn light on/off.
112   void SetSwitchOnClick (bool theToHandle) { myToSwitchOnClick = theToHandle; }
113
114   //! Returns a number of directional light arrows to display; 5 by default.
115   Standard_Integer NbArrows() const { return myNbArrows; }
116
117   //! Returns a number of directional light arrows to display (supported values: 1, 3, 5, 9).
118   void SetNbArrows (Standard_Integer theNbArrows)
119   {
120     if (myNbArrows != theNbArrows)
121     {
122       myNbArrows = theNbArrows;
123       SetToUpdate();
124     }
125   }
126
127   //! Returns light source icon.
128   //! @param theIsEnabled [in] marker index for enabled/disabled light source states
129   const Handle(Graphic3d_MarkerImage)& MarkerImage (bool theIsEnabled) const { return myMarkerImages[theIsEnabled ? 1 : 0]; }
130
131   //! Returns light source icon.
132   //! @param theIsEnabled [in] marker index for enabled/disabled light source states
133   Aspect_TypeOfMarker MarkerType (bool theIsEnabled) const { return myMarkerTypes[theIsEnabled ? 1 : 0]; }
134
135   //! Sets custom icon to light source.
136   void SetMarkerImage (const Handle(Graphic3d_MarkerImage)& theImage,
137                        bool theIsEnabled)
138   {
139     myMarkerImages[theIsEnabled ? 1 : 0] = theImage;
140     myMarkerTypes [theIsEnabled ? 1 : 0] = !theImage.IsNull()
141                                          ? Aspect_TOM_USERDEFINED
142                                          : (theIsEnabled ? Aspect_TOM_O_POINT : Aspect_TOM_O_X);
143   }
144
145   //! Sets standard icon to light source.
146   void SetMarkerType (Aspect_TypeOfMarker theType,
147                       bool theIsEnabled)
148   {
149     myMarkerTypes[theIsEnabled ? 1 : 0] = theType;
150   }
151
152   //! Returns tessellation level for quadric surfaces; 30 by default.
153   Standard_Integer NbSplitsQuadric() const { return myNbSplitsQuadric; }
154
155   //! Sets tessellation level for quadric surfaces.
156   void SetNbSplitsQuadric (Standard_Integer theNbSplits) { myNbSplitsQuadric = theNbSplits; }
157
158   //! Returns tessellation level for arrows; 20 by default.
159   Standard_Integer NbSplitsArrow() const { return myNbSplitsArrow; }
160
161   //! Sets tessellation level for arrows.
162   void SetNbSplitsArrow (Standard_Integer theNbSplits) { myNbSplitsArrow = theNbSplits; }
163
164   //! Returns kind of the object.
165   virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE { return AIS_KindOfInteractive_LightSource; }
166
167 protected:
168
169   //! Return true if specified display mode is supported: 0 for main presentation and 1 for highlight.
170   virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE
171   {
172     return theMode == 0
173         || theMode == 1;
174   }
175
176   //! Computes selection sensitive zones(triangulation) for light source presentation.
177   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
178                                         const Handle(Prs3d_Presentation)& thePrs,
179                                         const Standard_Integer theMode) Standard_OVERRIDE;
180
181   //! Fills presentation.
182   Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel,
183                                                  const Standard_Integer theMode) Standard_OVERRIDE;
184
185   //! Sets new local transformation, which is propagated to Graphic3d_CLight instance.
186   Standard_EXPORT virtual void setLocalTransformation (const Handle(TopLoc_Datum3D)& theTrsf) Standard_OVERRIDE;
187
188   //! Updates local transformation basing on a type of light source.
189   Standard_EXPORT virtual void updateLightLocalTransformation();
190
191   //! Updates transform persistence basing on a type of light source.
192   Standard_EXPORT virtual void updateLightTransformPersistence();
193
194   //! Sets color of light.
195   Standard_EXPORT virtual void updateLightAspects();
196
197   //! Compute ambient light source presentation as a sphere at view corner.
198   Standard_EXPORT virtual void computeAmbient (const Handle(Prs3d_Presentation)& thePrs,
199                                                const Standard_Integer theMode);
200
201   //! Compute directional light source presentation as a set of arrows at view corner.
202   Standard_EXPORT virtual void computeDirectional (const Handle(Prs3d_Presentation)& thePrs,
203                                                    const Standard_Integer theMode);
204
205   //! Compute positional light source presentation as a sphere of either fixed size (no range) or of size representing a maximum range.
206   Standard_EXPORT virtual void computePositional (const Handle(Prs3d_Presentation)& thePrs,
207                                                   const Standard_Integer theMode);
208
209   //! Compute spot light source presentation as a cone.
210   Standard_EXPORT virtual void computeSpot (const Handle(Prs3d_Presentation)& thePrs,
211                                             const Standard_Integer theMode);
212
213 protected:
214
215   Handle(Graphic3d_CLight)         myLightSource;           //!< displayed light source
216
217   Handle(Graphic3d_AspectMarker3d) myDisabledMarkerAspect;  //!< disabled light source marker style
218   Handle(Graphic3d_AspectLine3d)   myArrowLineAspectShadow; //!< arrow shadow style
219   Handle(Graphic3d_MarkerImage)    myMarkerImages[2];       //!< icon of disabled (0) and enabled (1) light
220   Aspect_TypeOfMarker              myMarkerTypes[2];        //!< icon of disabled (0) and enabled (1) light
221   Aspect_TypeOfMarker              myCodirMarkerType;       //!< icon of arrow co-directional to camera direction (look from)
222   Aspect_TypeOfMarker              myOpposMarkerType;       //!< icon of arrow opposite to camera direction (look at)
223
224   Standard_Real    mySize;            //!< presentation size
225   Standard_Integer myNbArrows;        //!< number of directional light arrows
226   Standard_Integer myNbSplitsQuadric; //!< tessellation level for quadric surfaces
227   Standard_Integer myNbSplitsArrow;   //!< tessellation level for arrows
228   Standard_Boolean myIsZoomable;      //!< flag to allow/disallow transform-persistence when possible
229   Standard_Boolean myToDisplayName;   //!< flag to show/hide name
230   Standard_Boolean myToDisplayRange;  //!< flag to show/hide range of positional/spot light
231   Standard_Boolean myToSwitchOnClick; //!< flag to handle mouse click to turn light on/off
232
233 };
234
235 //! Owner of AIS_LightSource presentation.
236 class AIS_LightSourceOwner : public SelectMgr_EntityOwner
237 {
238   DEFINE_STANDARD_RTTIEXT(AIS_LightSourceOwner, SelectMgr_EntityOwner)
239 public:
240
241   //! Main constructor.
242   Standard_EXPORT AIS_LightSourceOwner (const Handle(AIS_LightSource)& theObject,
243                                         Standard_Integer thePriority = 5);
244
245   //! Handle mouse button click event.
246   Standard_EXPORT virtual Standard_Boolean HandleMouseClick (const Graphic3d_Vec2i& thePoint,
247                                                              Aspect_VKeyMouse theButton,
248                                                              Aspect_VKeyFlags theModifiers,
249                                                              bool theIsDoubleClick) Standard_OVERRIDE;
250
251 };
252
253 #endif // _AIS_LightSource_HeaderFile