Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-30 09:12:56

0001 // Copyright (c) 2016-2019 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _Aspect_VKeySet_HeaderFile
0015 #define _Aspect_VKeySet_HeaderFile
0016 
0017 #include <Aspect_VKey.hxx>
0018 
0019 #include <NCollection_Array1.hxx>
0020 #include <OSD_Timer.hxx>
0021 #include <Standard_Mutex.hxx>
0022 #include <Standard_Transient.hxx>
0023 
0024 //! Structure defining key state.
0025 class Aspect_VKeySet : public Standard_Transient
0026 {
0027   DEFINE_STANDARD_RTTIEXT(Aspect_VKeySet, Standard_Transient)
0028 public:
0029   //! Main constructor.
0030   Standard_EXPORT Aspect_VKeySet();
0031 
0032   //! Return active modifiers.
0033   Aspect_VKeyFlags Modifiers() const
0034   {
0035     Standard_Mutex::Sentry aLock(myLock);
0036     return myModifiers;
0037   }
0038 
0039   //! Return timestamp of press event.
0040   double DownTime(Aspect_VKey theKey) const
0041   {
0042     Standard_Mutex::Sentry aLock(myLock);
0043     return myKeys[theKey].TimeDown;
0044   }
0045 
0046   //! Return timestamp of release event.
0047   double TimeUp(Aspect_VKey theKey) const
0048   {
0049     Standard_Mutex::Sentry aLock(myLock);
0050     return myKeys[theKey].TimeUp;
0051   }
0052 
0053   //! Return TRUE if key is in Free state.
0054   bool IsFreeKey(Aspect_VKey theKey) const
0055   {
0056     Standard_Mutex::Sentry aLock(myLock);
0057     return myKeys[theKey].KStatus == KeyStatus_Free;
0058   }
0059 
0060   //! Return TRUE if key is in Pressed state.
0061   bool IsKeyDown(Aspect_VKey theKey) const
0062   {
0063     Standard_Mutex::Sentry aLock(myLock);
0064     return myKeys[theKey].KStatus == KeyStatus_Pressed;
0065   }
0066 
0067   //! Return mutex for thread-safe updates.
0068   //! All operations in class implicitly locks this mutex,
0069   //! so this method could be used only for batch processing of keys.
0070   Standard_Mutex& Mutex() { return myLock; }
0071 
0072 public:
0073   //! Reset the key state into unpressed state.
0074   Standard_EXPORT void Reset();
0075 
0076   //! Press key.
0077   //! @param theKey key pressed
0078   //! @param theTime event timestamp
0079   Standard_EXPORT void KeyDown(Aspect_VKey theKey, double theTime, double thePressure = 1.0);
0080 
0081   //! Release key.
0082   //! @param theKey key pressed
0083   //! @param theTime event timestamp
0084   Standard_EXPORT void KeyUp(Aspect_VKey theKey, double theTime);
0085 
0086   //! Simulate key up/down events from axis value.
0087   Standard_EXPORT void KeyFromAxis(Aspect_VKey theNegative,
0088                                    Aspect_VKey thePositive,
0089                                    double      theTime,
0090                                    double      thePressure);
0091 
0092   //! Return duration of the button in pressed state.
0093   //! @param theKey      key to check
0094   //! @param theTime     current time (for computing duration from key down time)
0095   //! @param theDuration key press duration
0096   //! @return TRUE if key was in pressed state
0097   bool HoldDuration(Aspect_VKey theKey, double theTime, double& theDuration)
0098   {
0099     double aPressure = -1.0;
0100     return HoldDuration(theKey, theTime, theDuration, aPressure);
0101   }
0102 
0103   //! Return duration of the button in pressed state.
0104   //! @param theKey      key to check
0105   //! @param theTime     current time (for computing duration from key down time)
0106   //! @param theDuration key press duration
0107   //! @param thePressure key pressure
0108   //! @return TRUE if key was in pressed state
0109   Standard_EXPORT bool HoldDuration(Aspect_VKey theKey,
0110                                     double      theTime,
0111                                     double&     theDuration,
0112                                     double&     thePressure);
0113 
0114 private:
0115   //! Key state.
0116   enum KeyStatus
0117   {
0118     KeyStatus_Free,     //!< free status
0119     KeyStatus_Pressed,  //!< key is in pressed state
0120     KeyStatus_Released, //!< key has been just released (transient state before KeyStatus_Free)
0121   };
0122 
0123   //! Structure defining key state.
0124   struct KeyState
0125   {
0126     KeyState()
0127         : TimeDown(0.0),
0128           TimeUp(0.0),
0129           Pressure(1.0),
0130           KStatus(KeyStatus_Free)
0131     {
0132     }
0133 
0134     void Reset()
0135     {
0136       KStatus  = KeyStatus_Free;
0137       TimeDown = 0.0;
0138       TimeUp   = 0.0;
0139       Pressure = 1.0;
0140     }
0141 
0142     double    TimeDown; //!< time of key press   event
0143     double    TimeUp;   //!< time of key release event
0144     double    Pressure; //!< key pressure
0145     KeyStatus KStatus;  //!< key status
0146   };
0147 
0148 private:
0149   NCollection_Array1<KeyState> myKeys;      //!< keys state
0150   mutable Standard_Mutex       myLock;      //!< mutex for thread-safe updates
0151   Aspect_VKeyFlags             myModifiers; //!< active modifiers
0152 };
0153 
0154 #endif // _Aspect_VKeySet_HeaderFile