Point Cloud Library (PCL)
1.7.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2011, Willow Garage, Inc. 00006 * Copyright (c) 2012-, Open Perception, Inc. 00007 * 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 00014 * * Redistributions of source code must retain the above copyright 00015 * notice, this list of conditions and the following disclaimer. 00016 * * Redistributions in binary form must reproduce the above 00017 * copyright notice, this list of conditions and the following 00018 * disclaimer in the documentation and/or other materials provided 00019 * with the distribution. 00020 * * Neither the name of the copyright holder(s) nor the names of its 00021 * contributors may be used to endorse or promote products derived 00022 * from this software without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00025 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00026 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00027 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00028 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00029 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00030 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00031 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00033 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00034 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00035 * POSSIBILITY OF SUCH DAMAGE. 00036 * 00037 */ 00038 00039 #ifndef PCL_VISUALIZATION_KEYBOARD_EVENT_H_ 00040 #define PCL_VISUALIZATION_KEYBOARD_EVENT_H_ 00041 00042 #include <string> 00043 00044 namespace pcl 00045 { 00046 namespace visualization 00047 { 00048 /** /brief Class representing key hit/release events */ 00049 class KeyboardEvent 00050 { 00051 public: 00052 /** \brief bit patter for the ALT key*/ 00053 static const unsigned int Alt = 1; 00054 /** \brief bit patter for the Control key*/ 00055 static const unsigned int Ctrl = 2; 00056 /** \brief bit patter for the Shift key*/ 00057 static const unsigned int Shift = 4; 00058 00059 /** \brief Constructor 00060 * \param[in] action true for key was pressed, false for released 00061 * \param[in] key_sym the key-name that caused the action 00062 * \param[in] key the key code that caused the action 00063 * \param[in] alt whether the alt key was pressed at the time where this event was triggered 00064 * \param[in] ctrl whether the ctrl was pressed at the time where this event was triggered 00065 * \param[in] shift whether the shift was pressed at the time where this event was triggered 00066 */ 00067 inline KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, 00068 bool alt, bool ctrl, bool shift); 00069 00070 /** 00071 * \return whether the alt key was pressed at the time where this event was triggered 00072 */ 00073 inline bool 00074 isAltPressed () const; 00075 00076 /** 00077 * \return whether the ctrl was pressed at the time where this event was triggered 00078 */ 00079 inline bool 00080 isCtrlPressed () const; 00081 00082 /** 00083 * \return whether the shift was pressed at the time where this event was triggered 00084 */ 00085 inline bool 00086 isShiftPressed () const; 00087 00088 /** 00089 * \return the ASCII Code of the key that caused the event. If 0, then it was a special key, like ALT, F1, F2,... PgUp etc. Then the name of the key is in the keysym field. 00090 */ 00091 inline unsigned char 00092 getKeyCode () const; 00093 00094 /** 00095 * \return name of the key that caused the event 00096 */ 00097 inline const std::string& 00098 getKeySym () const; 00099 00100 /** 00101 * \return true if a key-press caused the event, false otherwise 00102 */ 00103 inline bool 00104 keyDown () const; 00105 00106 /** 00107 * \return true if a key-release caused the event, false otherwise 00108 */ 00109 inline bool 00110 keyUp () const; 00111 00112 protected: 00113 00114 bool action_; 00115 unsigned int modifiers_; 00116 unsigned char key_code_; 00117 std::string key_sym_; 00118 }; 00119 00120 KeyboardEvent::KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, 00121 bool alt, bool ctrl, bool shift) 00122 : action_ (action) 00123 , modifiers_ (0) 00124 , key_code_(key) 00125 , key_sym_ (key_sym) 00126 { 00127 if (alt) 00128 modifiers_ = Alt; 00129 00130 if (ctrl) 00131 modifiers_ |= Ctrl; 00132 00133 if (shift) 00134 modifiers_ |= Shift; 00135 } 00136 00137 bool 00138 KeyboardEvent::isAltPressed () const 00139 { 00140 return (modifiers_ & Alt) != 0; 00141 } 00142 00143 bool 00144 KeyboardEvent::isCtrlPressed () const 00145 { 00146 return (modifiers_ & Ctrl) != 0; 00147 } 00148 00149 bool 00150 KeyboardEvent::isShiftPressed () const 00151 { 00152 return (modifiers_ & Shift) != 0; 00153 } 00154 00155 unsigned char 00156 KeyboardEvent::getKeyCode () const 00157 { 00158 return (key_code_); 00159 } 00160 00161 const std::string& 00162 KeyboardEvent::getKeySym () const 00163 { 00164 return (key_sym_); 00165 } 00166 00167 bool 00168 KeyboardEvent::keyDown () const 00169 { 00170 return (action_); 00171 } 00172 00173 bool 00174 KeyboardEvent::keyUp () const 00175 { 00176 return (!action_); 00177 } 00178 } // namespace visualization 00179 } // namespace pcl 00180 00181 #endif /* PCL_VISUALIZATION_KEYBOARD_EVENT_H_ */ 00182