Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/opencascade/AIS_LightSource.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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
0033 //! enable/disable light.
0034 class AIS_LightSource : public AIS_InteractiveObject
0035 {
0036   friend class AIS_LightSourceOwner;
0037   DEFINE_STANDARD_RTTIEXT(AIS_LightSource, AIS_InteractiveObject)
0038 public:
0039   //! Initializes the light source by copying Graphic3d_CLight settings.
0040   Standard_EXPORT AIS_LightSource(const occ::handle<Graphic3d_CLight>& theLightSource);
0041 
0042   //! Returns the light.
0043   const occ::handle<Graphic3d_CLight>& Light() const { return myLightSource; }
0044 
0045   //! Set the light.
0046   void SetLight(const occ::handle<Graphic3d_CLight>& theLight)
0047   {
0048     myLightSource = theLight;
0049     SetToUpdate();
0050   }
0051 
0052 public: //! @name Light properties
0053   //! Returns TRUE if the light source name should be displayed; TRUE by default.
0054   bool ToDisplayName() const { return myToDisplayName; }
0055 
0056   //! Show/hide light source name.
0057   void SetDisplayName(bool theToDisplay)
0058   {
0059     if (myToDisplayName != theToDisplay)
0060     {
0061       myToDisplayName = theToDisplay;
0062       SetToUpdate();
0063     }
0064   }
0065 
0066   //! Returns TRUE to display light source range as sphere (positional light) or cone (spot light);
0067   //! TRUE by default. Has no effect for non-zoomable presentation.
0068   bool ToDisplayRange() const { return myToDisplayRange; }
0069 
0070   //! Show/hide light source range shaded presentation.
0071   void SetDisplayRange(bool theToDisplay)
0072   {
0073     if (myToDisplayRange != theToDisplay)
0074     {
0075       myToDisplayRange = theToDisplay;
0076       SetToUpdate();
0077     }
0078   }
0079 
0080   //! Returns the size of presentation; 50 by default.
0081   double Size() const { return mySize; }
0082 
0083   //! Sets the size of presentation.
0084   void SetSize(double theSize)
0085   {
0086     if (mySize != theSize)
0087     {
0088       mySize = theSize;
0089       SetToUpdate();
0090     }
0091   }
0092 
0093   //! Returns Sensitive sphere arc size in pixels; 20 by default.
0094   int ArcSize() const { return mySensSphereArcSize; }
0095 
0096   //! Sets the size of sensitive sphere arc.
0097   void SetArcSize(int theSize)
0098   {
0099     if (mySensSphereArcSize != theSize)
0100     {
0101       mySensSphereArcSize = theSize;
0102       SetToUpdate();
0103     }
0104   }
0105 
0106   //! Returns TRUE if transform-persistence is allowed;
0107   //! TRUE by default for Ambient and Directional lights
0108   //! and FALSE by default for Positional and Spot lights.
0109   bool IsZoomable() const { return myIsZoomable; }
0110 
0111   //! Sets if transform-persistence is allowed.
0112   void SetZoomable(bool theIsZoomable)
0113   {
0114     if (myIsZoomable != theIsZoomable)
0115     {
0116       myIsZoomable = theIsZoomable;
0117       SetToUpdate();
0118     }
0119   }
0120 
0121   //! Sets if dragging is allowed.
0122   void SetDraggable(bool theIsDraggable)
0123   {
0124     if (myIsDraggable != theIsDraggable)
0125     {
0126       myIsDraggable = theIsDraggable;
0127     }
0128   }
0129 
0130   //! Returns TRUE if mouse click will turn light on/off; TRUE by default.
0131   bool ToSwitchOnClick() const { return myToSwitchOnClick; }
0132 
0133   //! Sets if mouse click should turn light on/off.
0134   void SetSwitchOnClick(bool theToHandle) { myToSwitchOnClick = theToHandle; }
0135 
0136   //! Returns a number of directional light arrows to display; 5 by default.
0137   int NbArrows() const { return myNbArrows; }
0138 
0139   //! Returns a number of directional light arrows to display (supported values: 1, 3, 5, 9).
0140   void SetNbArrows(int theNbArrows)
0141   {
0142     if (myNbArrows != theNbArrows)
0143     {
0144       myNbArrows = theNbArrows;
0145       SetToUpdate();
0146     }
0147   }
0148 
0149   //! Returns light source icon.
0150   //! @param[in] theIsEnabled  marker index for enabled/disabled light source states
0151   const occ::handle<Graphic3d_MarkerImage>& MarkerImage(bool theIsEnabled) const
0152   {
0153     return myMarkerImages[theIsEnabled ? 1 : 0];
0154   }
0155 
0156   //! Returns light source icon.
0157   //! @param[in] theIsEnabled  marker index for enabled/disabled light source states
0158   Aspect_TypeOfMarker MarkerType(bool theIsEnabled) const
0159   {
0160     return myMarkerTypes[theIsEnabled ? 1 : 0];
0161   }
0162 
0163   //! Sets custom icon to light source.
0164   void SetMarkerImage(const occ::handle<Graphic3d_MarkerImage>& theImage, bool theIsEnabled)
0165   {
0166     myMarkerImages[theIsEnabled ? 1 : 0] = theImage;
0167     myMarkerTypes[theIsEnabled ? 1 : 0]  = !theImage.IsNull()
0168                                              ? Aspect_TOM_USERDEFINED
0169                                              : (theIsEnabled ? Aspect_TOM_O_POINT : Aspect_TOM_O_X);
0170   }
0171 
0172   //! Sets standard icon to light source.
0173   void SetMarkerType(Aspect_TypeOfMarker theType, bool theIsEnabled)
0174   {
0175     myMarkerTypes[theIsEnabled ? 1 : 0] = theType;
0176   }
0177 
0178   //! Returns tessellation level for quadric surfaces; 30 by default.
0179   int NbSplitsQuadric() const { return myNbSplitsQuadric; }
0180 
0181   //! Sets tessellation level for quadric surfaces.
0182   void SetNbSplitsQuadric(int theNbSplits) { myNbSplitsQuadric = theNbSplits; }
0183 
0184   //! Returns tessellation level for arrows; 20 by default.
0185   int NbSplitsArrow() const { return myNbSplitsArrow; }
0186 
0187   //! Sets tessellation level for arrows.
0188   void SetNbSplitsArrow(int theNbSplits) { myNbSplitsArrow = theNbSplits; }
0189 
0190   //! Returns kind of the object.
0191   AIS_KindOfInteractive Type() const override { return AIS_KindOfInteractive_LightSource; }
0192 
0193 protected:
0194   //! Return true if specified display mode is supported: 0 for main presentation and 1 for
0195   //! highlight.
0196   bool AcceptDisplayMode(const int theMode) const override { return theMode == 0 || theMode == 1; }
0197 
0198   //! Computes selection sensitive zones(triangulation) for light source presentation.
0199   Standard_EXPORT void Compute(const occ::handle<PrsMgr_PresentationManager>& thePrsMgr,
0200                                const occ::handle<Prs3d_Presentation>&         thePrs,
0201                                const int                                      theMode) override;
0202 
0203   //! Fills presentation.
0204   Standard_EXPORT void ComputeSelection(const occ::handle<SelectMgr_Selection>& theSel,
0205                                         const int                               theMode) override;
0206 
0207   //! Drag object in the viewer.
0208   //! @param[in] theCtx      interactive context
0209   //! @param[in] theView     active View
0210   //! @param[in] theOwner    the owner of detected entity
0211   //! @param[in] theDragFrom drag start point
0212   //! @param[in] theDragTo   drag end point
0213   //! @param[in] theAction   drag action
0214   //! @return FALSE if object rejects dragging action (e.g. AIS_DragAction_Start)
0215   Standard_EXPORT bool ProcessDragging(const occ::handle<AIS_InteractiveContext>& theCtx,
0216                                        const occ::handle<V3d_View>&               theView,
0217                                        const occ::handle<SelectMgr_EntityOwner>&  theOwner,
0218                                        const NCollection_Vec2<int>&               theDragFrom,
0219                                        const NCollection_Vec2<int>&               theDragTo,
0220                                        const AIS_DragAction theAction) override;
0221 
0222   //! Sets new local transformation, which is propagated to Graphic3d_CLight instance.
0223   Standard_EXPORT void setLocalTransformation(const occ::handle<TopLoc_Datum3D>& theTrsf) override;
0224 
0225   //! Updates local transformation basing on a type of light source.
0226   Standard_EXPORT virtual void updateLightLocalTransformation();
0227 
0228   //! Updates transform persistence basing on a type of light source.
0229   Standard_EXPORT virtual void updateLightTransformPersistence();
0230 
0231   //! Sets color of light.
0232   Standard_EXPORT virtual void updateLightAspects();
0233 
0234   //! Compute ambient light source presentation as a sphere at view corner.
0235   Standard_EXPORT virtual void computeAmbient(const occ::handle<Prs3d_Presentation>& thePrs,
0236                                               const int                              theMode);
0237 
0238   //! Compute directional light source presentation as a set of arrows at view corner.
0239   Standard_EXPORT virtual void computeDirectional(const occ::handle<Prs3d_Presentation>& thePrs,
0240                                                   const int                              theMode);
0241 
0242   //! Compute positional light source presentation as a sphere of either fixed size (no range) or of
0243   //! size representing a maximum range.
0244   Standard_EXPORT virtual void computePositional(const occ::handle<Prs3d_Presentation>& thePrs,
0245                                                  const int                              theMode);
0246 
0247   //! Compute spot light source presentation as a cone.
0248   Standard_EXPORT virtual void computeSpot(const occ::handle<Prs3d_Presentation>& thePrs,
0249                                            const int                              theMode);
0250 
0251 protected:
0252   occ::handle<Graphic3d_CLight> myLightSource; //!< displayed light source
0253 
0254   // clang-format off
0255   occ::handle<Graphic3d_AspectMarker3d> myDisabledMarkerAspect;  //!< disabled light source marker style
0256   occ::handle<Graphic3d_AspectLine3d>   myArrowLineAspectShadow; //!< arrow shadow style
0257   occ::handle<Graphic3d_MarkerImage>    myMarkerImages[2];       //!< icon of disabled (0) and enabled (1) light
0258   occ::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   double    mySize;              //!< presentation size
0265   int myNbArrows;          //!< number of directional light arrows
0266   int myNbSplitsQuadric;   //!< tessellation level for quadric surfaces
0267   int myNbSplitsArrow;     //!< tessellation level for arrows
0268   int mySensSphereArcSize; //! sensitive sphere arc size in pixels
0269   bool myIsZoomable;        //!< flag to allow/disallow transform-persistence when possible
0270   bool myIsDraggable;       //!< flag to allow/disallow rotate directional light source by dragging
0271   // clang-format on
0272   bool myToDisplayName;   //!< flag to show/hide name
0273   bool myToDisplayRange;  //!< flag to show/hide range of positional/spot light
0274   bool myToSwitchOnClick; //!< flag to handle mouse click to turn light on/off
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   //! Main constructor.
0283   Standard_EXPORT AIS_LightSourceOwner(const occ::handle<AIS_LightSource>& theObject,
0284                                        int                                 thePriority = 5);
0285 
0286   //! Handle mouse button click event.
0287   Standard_EXPORT bool HandleMouseClick(const NCollection_Vec2<int>& thePoint,
0288                                         Aspect_VKeyMouse             theButton,
0289                                         Aspect_VKeyFlags             theModifiers,
0290                                         bool                         theIsDoubleClick) override;
0291 
0292   //! Highlights selectable object's presentation with display mode in presentation manager with
0293   //! given highlight style. Also a check for auto-highlight is performed - if selectable object
0294   //! manages highlighting on its own, execution will be passed to
0295   //! SelectMgr_SelectableObject::HilightOwnerWithColor method.
0296   Standard_EXPORT void HilightWithColor(const occ::handle<PrsMgr_PresentationManager>& thePrsMgr,
0297                                         const occ::handle<Prs3d_Drawer>&               theStyle,
0298                                         const int theMode) override;
0299 
0300   //! Always update dynamic highlighting.
0301   Standard_EXPORT bool IsForcedHilight() const override;
0302 };
0303 
0304 #endif // _AIS_LightSource_HeaderFile