Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:55

0001 // Created on: 2020-09-07
0002 // Created by: Maria KRYLOVA
0003 // Copyright (c) 2020 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _AIS_LightSource_HeaderFile
0017 #define _AIS_LightSource_HeaderFile
0018 
0019 #include <AIS_InteractiveObject.hxx>
0020 #include <Graphic3d_AspectLine3d.hxx>
0021 #include <Graphic3d_AspectMarker3d.hxx>
0022 #include <SelectMgr_EntityOwner.hxx>
0023 
0024 class Select3D_SensitiveSphere;
0025 
0026 //! Interactive object for a light source.
0027 //! Each type of light source has it's own presentation:
0028 //! - Ambient light is displayed as a sphere at view corner;
0029 //! - Positional light is represented by a sphere or marker;
0030 //! - Spot light is represented by a cone;
0031 //! - Directional light is represented by a set of arrows at the corner of view.
0032 //! In addition, light source name could be displayed, and clicking on presentation will enable/disable light.
0033 class AIS_LightSource : public AIS_InteractiveObject
0034 {
0035   friend class AIS_LightSourceOwner;
0036   DEFINE_STANDARD_RTTIEXT(AIS_LightSource, AIS_InteractiveObject)
0037 public:
0038 
0039   //! Initializes the light source by copying Graphic3d_CLight settings.
0040   Standard_EXPORT AIS_LightSource (const Handle(Graphic3d_CLight)& theLightSource);
0041 
0042   //! Returns the light.
0043   const Handle(Graphic3d_CLight)& Light() const { return myLightSource; }
0044 
0045   //! Set the light.
0046   void SetLight (const Handle(Graphic3d_CLight)& theLight)
0047   {
0048     myLightSource = theLight;
0049     SetToUpdate();
0050   }
0051 
0052 public: //! @name Light properties
0053 
0054   //! Returns TRUE if the light source name should be displayed; TRUE by default.
0055   Standard_Boolean ToDisplayName() const { return myToDisplayName; }
0056 
0057   //! Show/hide light source name.
0058   void SetDisplayName(Standard_Boolean theToDisplay)
0059   {
0060     if (myToDisplayName != theToDisplay)
0061     {
0062       myToDisplayName = theToDisplay;
0063       SetToUpdate();
0064     }
0065   }
0066 
0067   //! Returns TRUE to display light source range as sphere (positional light) or cone (spot light); TRUE by default.
0068   //! Has no effect for non-zoomable presentation.
0069   Standard_Boolean ToDisplayRange() const { return myToDisplayRange; }
0070 
0071   //! Show/hide light source range shaded presentation.
0072   void SetDisplayRange (Standard_Boolean theToDisplay)
0073   {
0074     if (myToDisplayRange != theToDisplay)
0075     {
0076       myToDisplayRange = theToDisplay;
0077       SetToUpdate();
0078     }
0079   }
0080 
0081   //! Returns the size of presentation; 50 by default.
0082   Standard_Real Size() const { return mySize; }
0083 
0084   //! Sets the size of presentation.
0085   void SetSize (Standard_Real theSize)
0086   {
0087     if (mySize != theSize)
0088     {
0089       mySize = theSize;
0090       SetToUpdate();
0091     }
0092   }
0093 
0094   //! Returns Sensitive sphere arc size in pixels; 20 by default.
0095   Standard_Integer ArcSize() const { return mySensSphereArcSize; }
0096 
0097   //! Sets the size of sensitive sphere arc.
0098   void SetArcSize (Standard_Integer theSize)
0099   {
0100     if (mySensSphereArcSize != theSize)
0101     {
0102       mySensSphereArcSize = theSize;
0103       SetToUpdate();
0104     }
0105   }
0106 
0107   //! Returns TRUE if transform-persistence is allowed;
0108   //! TRUE by default for Ambient and Directional lights
0109   //! and FALSE by default for Positional and Spot lights.
0110   bool IsZoomable() const { return myIsZoomable; }
0111 
0112   //! Sets if transform-persistence is allowed.
0113   void SetZoomable (bool theIsZoomable)
0114   {
0115     if (myIsZoomable != theIsZoomable)
0116     {
0117       myIsZoomable = theIsZoomable;
0118       SetToUpdate();
0119     }
0120   }
0121 
0122   //! Sets if dragging is allowed.
0123   void SetDraggable (bool theIsDraggable)
0124   {
0125     if (myIsDraggable != theIsDraggable)
0126     {
0127       myIsDraggable = theIsDraggable;
0128     }
0129   }
0130 
0131   //! Returns TRUE if mouse click will turn light on/off; TRUE by default.
0132   bool ToSwitchOnClick() const { return myToSwitchOnClick; }
0133 
0134   //! Sets if mouse click should turn light on/off.
0135   void SetSwitchOnClick (bool theToHandle) { myToSwitchOnClick = theToHandle; }
0136 
0137   //! Returns a number of directional light arrows to display; 5 by default.
0138   Standard_Integer NbArrows() const { return myNbArrows; }
0139 
0140   //! Returns a number of directional light arrows to display (supported values: 1, 3, 5, 9).
0141   void SetNbArrows (Standard_Integer theNbArrows)
0142   {
0143     if (myNbArrows != theNbArrows)
0144     {
0145       myNbArrows = theNbArrows;
0146       SetToUpdate();
0147     }
0148   }
0149 
0150   //! Returns light source icon.
0151   //! @param theIsEnabled [in] marker index for enabled/disabled light source states
0152   const Handle(Graphic3d_MarkerImage)& MarkerImage (bool theIsEnabled) const { return myMarkerImages[theIsEnabled ? 1 : 0]; }
0153 
0154   //! Returns light source icon.
0155   //! @param theIsEnabled [in] marker index for enabled/disabled light source states
0156   Aspect_TypeOfMarker MarkerType (bool theIsEnabled) const { return myMarkerTypes[theIsEnabled ? 1 : 0]; }
0157 
0158   //! Sets custom icon to light source.
0159   void SetMarkerImage (const Handle(Graphic3d_MarkerImage)& theImage,
0160                        bool theIsEnabled)
0161   {
0162     myMarkerImages[theIsEnabled ? 1 : 0] = theImage;
0163     myMarkerTypes [theIsEnabled ? 1 : 0] = !theImage.IsNull()
0164                                          ? Aspect_TOM_USERDEFINED
0165                                          : (theIsEnabled ? Aspect_TOM_O_POINT : Aspect_TOM_O_X);
0166   }
0167 
0168   //! Sets standard icon to light source.
0169   void SetMarkerType (Aspect_TypeOfMarker theType,
0170                       bool theIsEnabled)
0171   {
0172     myMarkerTypes[theIsEnabled ? 1 : 0] = theType;
0173   }
0174 
0175   //! Returns tessellation level for quadric surfaces; 30 by default.
0176   Standard_Integer NbSplitsQuadric() const { return myNbSplitsQuadric; }
0177 
0178   //! Sets tessellation level for quadric surfaces.
0179   void SetNbSplitsQuadric (Standard_Integer theNbSplits) { myNbSplitsQuadric = theNbSplits; }
0180 
0181   //! Returns tessellation level for arrows; 20 by default.
0182   Standard_Integer NbSplitsArrow() const { return myNbSplitsArrow; }
0183 
0184   //! Sets tessellation level for arrows.
0185   void SetNbSplitsArrow (Standard_Integer theNbSplits) { myNbSplitsArrow = theNbSplits; }
0186 
0187   //! Returns kind of the object.
0188   virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE { return AIS_KindOfInteractive_LightSource; }
0189 
0190 protected:
0191 
0192   //! Return true if specified display mode is supported: 0 for main presentation and 1 for highlight.
0193   virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE
0194   {
0195     return theMode == 0
0196         || theMode == 1;
0197   }
0198 
0199   //! Computes selection sensitive zones(triangulation) for light source presentation.
0200   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
0201                                         const Handle(Prs3d_Presentation)& thePrs,
0202                                         const Standard_Integer theMode) Standard_OVERRIDE;
0203 
0204   //! Fills presentation.
0205   Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel,
0206                                                  const Standard_Integer theMode) Standard_OVERRIDE;
0207 
0208   //! Drag object in the viewer.
0209   //! @param[in] theCtx      interactive context
0210   //! @param[in] theView     active View
0211   //! @param[in] theOwner    the owner of detected entity
0212   //! @param[in] theDragFrom drag start point
0213   //! @param[in] theDragTo   drag end point
0214   //! @param[in] theAction   drag action
0215   //! @return FALSE if object rejects dragging action (e.g. AIS_DragAction_Start)
0216   Standard_EXPORT virtual Standard_Boolean ProcessDragging (const Handle(AIS_InteractiveContext)& theCtx,
0217                                                             const Handle(V3d_View)& theView,
0218                                                             const Handle(SelectMgr_EntityOwner)& theOwner,
0219                                                             const Graphic3d_Vec2i& theDragFrom,
0220                                                             const Graphic3d_Vec2i& theDragTo,
0221                                                             const AIS_DragAction theAction) Standard_OVERRIDE;
0222 
0223   //! Sets new local transformation, which is propagated to Graphic3d_CLight instance.
0224   Standard_EXPORT virtual void setLocalTransformation (const Handle(TopLoc_Datum3D)& theTrsf) Standard_OVERRIDE;
0225 
0226   //! Updates local transformation basing on a type of light source.
0227   Standard_EXPORT virtual void updateLightLocalTransformation();
0228 
0229   //! Updates transform persistence basing on a type of light source.
0230   Standard_EXPORT virtual void updateLightTransformPersistence();
0231 
0232   //! Sets color of light.
0233   Standard_EXPORT virtual void updateLightAspects();
0234 
0235   //! Compute ambient light source presentation as a sphere at view corner.
0236   Standard_EXPORT virtual void computeAmbient (const Handle(Prs3d_Presentation)& thePrs,
0237                                                const Standard_Integer theMode);
0238 
0239   //! Compute directional light source presentation as a set of arrows at view corner.
0240   Standard_EXPORT virtual void computeDirectional (const Handle(Prs3d_Presentation)& thePrs,
0241                                                    const Standard_Integer theMode);
0242 
0243   //! Compute positional light source presentation as a sphere of either fixed size (no range) or of size representing a maximum range.
0244   Standard_EXPORT virtual void computePositional (const Handle(Prs3d_Presentation)& thePrs,
0245                                                   const Standard_Integer theMode);
0246 
0247   //! Compute spot light source presentation as a cone.
0248   Standard_EXPORT virtual void computeSpot (const Handle(Prs3d_Presentation)& thePrs,
0249                                             const Standard_Integer theMode);
0250 
0251 protected:
0252 
0253   Handle(Graphic3d_CLight)         myLightSource;           //!< displayed light source
0254 
0255   Handle(Graphic3d_AspectMarker3d) myDisabledMarkerAspect;  //!< disabled light source marker style
0256   Handle(Graphic3d_AspectLine3d)   myArrowLineAspectShadow; //!< arrow shadow style
0257   Handle(Graphic3d_MarkerImage)    myMarkerImages[2];       //!< icon of disabled (0) and enabled (1) light
0258   Handle(Select3D_SensitiveSphere) mySensSphere;            //!< sensitive sphere of directional light source
0259   Aspect_TypeOfMarker              myMarkerTypes[2];        //!< icon of disabled (0) and enabled (1) light
0260   Aspect_TypeOfMarker              myCodirMarkerType;       //!< icon of arrow co-directional to camera direction (look from)
0261   Aspect_TypeOfMarker              myOpposMarkerType;       //!< icon of arrow opposite to camera direction (look at)
0262 
0263   gp_Trsf          myLocTrsfStart;      //!< object transformation before transformation
0264   Standard_Real    mySize;              //!< presentation size
0265   Standard_Integer myNbArrows;          //!< number of directional light arrows
0266   Standard_Integer myNbSplitsQuadric;   //!< tessellation level for quadric surfaces
0267   Standard_Integer myNbSplitsArrow;     //!< tessellation level for arrows
0268   Standard_Integer mySensSphereArcSize; //! sensitive sphere arc size in pixels
0269   Standard_Boolean myIsZoomable;        //!< flag to allow/disallow transform-persistence when possible
0270   Standard_Boolean myIsDraggable;       //!< flag to allow/disallow rotate directional light source by dragging
0271   Standard_Boolean myToDisplayName;     //!< flag to show/hide name
0272   Standard_Boolean myToDisplayRange;    //!< flag to show/hide range of positional/spot light
0273   Standard_Boolean myToSwitchOnClick;   //!< flag to handle mouse click to turn light on/off
0274 
0275 };
0276 
0277 //! Owner of AIS_LightSource presentation.
0278 class AIS_LightSourceOwner : public SelectMgr_EntityOwner
0279 {
0280   DEFINE_STANDARD_RTTIEXT(AIS_LightSourceOwner, SelectMgr_EntityOwner)
0281 public:
0282 
0283   //! Main constructor.
0284   Standard_EXPORT AIS_LightSourceOwner (const Handle(AIS_LightSource)& theObject,
0285                                         Standard_Integer thePriority = 5);
0286 
0287   //! Handle mouse button click event.
0288   Standard_EXPORT virtual Standard_Boolean HandleMouseClick (const Graphic3d_Vec2i& thePoint,
0289                                                              Aspect_VKeyMouse theButton,
0290                                                              Aspect_VKeyFlags theModifiers,
0291                                                              bool theIsDoubleClick) Standard_OVERRIDE;
0292 
0293   //! Highlights selectable object's presentation with display mode in presentation manager with given highlight style.
0294   //! Also a check for auto-highlight is performed - if selectable object manages highlighting on its own,
0295   //! execution will be passed to SelectMgr_SelectableObject::HilightOwnerWithColor method.
0296   Standard_EXPORT virtual void HilightWithColor (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
0297                                                  const Handle(Prs3d_Drawer)& theStyle,
0298                                                  const Standard_Integer theMode) Standard_OVERRIDE;
0299 
0300   //! Always update dynamic highlighting.
0301   Standard_EXPORT virtual Standard_Boolean IsForcedHilight() const Standard_OVERRIDE;
0302 
0303 };
0304 
0305 #endif // _AIS_LightSource_HeaderFile