orca-robotics INTRODUCTION Overview Download and Install Quick Start Documentation Publications REPOSITORY Interfaces Components Libraries Utilities Software Map DEVELOPER Tutorials Examples Dev Guide Dashboard Wiki login/pass: orca/orca PEOPLE Contributors Users Project Download Mailing lists
|
pathfollower2delement.h00001 /* 00002 * Orca-Robotics Project: Components for robotics 00003 * http://orca-robotics.sf.net/ 00004 * Copyright (c) 2004-2008 Alex Brooks, Alexei Makarenko, Tobias Kaupp 00005 * 00006 * This copy of Orca is licensed to you under the terms described in 00007 * the LICENSE file included in this distribution. 00008 * 00009 */ 00010 00011 #ifndef PATHFOLLOWER2DELEMENT_H 00012 #define PATHFOLLOWER2DELEMENT_H 00013 00014 #include <orca/pathfollower2d.h> 00015 00016 #include <gbxsickacfr/gbxiceutilacfr/store.h> 00017 #include <gbxsickacfr/gbxiceutilacfr/timer.h> 00018 00019 #include <hydroqguielementutil/guielement2d.h> 00020 #include <orcaqgui2dfactory/pathpainter.h> 00021 #include <orcaqgui2dfactory/pathinput.h> 00022 00023 namespace orcaqgui2d { 00024 00025 class hydroqguielementutil::IHumanManager; 00026 00028 // The consumer object. We need this here because PathFollower2dElement cannot inherit from IceStormElement. 00029 // Reason is that PathFollower2dConsumer has several non-standard purely virtual member functions. 00030 class PathUpdateConsumer : public orca::PathFollower2dConsumer 00031 { 00032 public: 00033 00034 void setData( const orca::PathFollower2dData& newPath, const ::Ice::Current& ); 00035 void setWaypointIndex( int index, const ::Ice::Current& ); 00036 void setActivationTime( const orca::Time& absoluteTime, double relativeTime, const ::Ice::Current& ); 00037 void setEnabledState( bool enabledState, const ::Ice::Current& ); 00038 00039 gbxsickacfr::gbxiceutilacfr::Store<orca::PathFollower2dData> pathPipe_; 00040 gbxsickacfr::gbxiceutilacfr::Store<int> indexPipe_; 00041 }; 00043 00045 // This class sets up all the buttons and actions for user interaction. 00046 // It can be instantiated on the heap and deleted, Qt cleans up for us 00047 class PathfollowerButtons : public QObject 00048 { 00049 Q_OBJECT 00050 00051 public: 00052 PathfollowerButtons( QObject *parent, 00053 hydroqguielementutil::IHumanManager &humanManager, 00054 hydroqguielementutil::ShortcutKeyManager &shortcutKeyManager, 00055 std::string proxyString); 00056 ~PathfollowerButtons(); 00057 00058 void setWpButton( bool onOff ); 00059 00060 private: 00061 QAction *hiWaypoints_; 00062 hydroqguielementutil::IHumanManager &humanManager_; 00063 hydroqguielementutil::ShortcutKeyManager &shortcutKeyManager_; 00064 }; 00066 00067 class PathFollower2dElement; 00068 // 00069 // Handles the human-interface stuff for the PathFollower2dElement 00070 // 00071 class PathFollowerHI : public QObject 00072 { 00073 Q_OBJECT 00074 00075 public: 00076 PathFollowerHI( PathFollower2dElement *pfElement, 00077 std::string proxyString, 00078 hydroqguielementutil::IHumanManager &humanManager, 00079 hydroqguielementutil::MouseEventManager &mouseEventManager, 00080 hydroqguielementutil::ShortcutKeyManager &shortcutKeyManager, 00081 const hydroqgui::GuiElementSet &guiElementSet, 00082 PathPainter &painter, 00083 WaypointSettings wpSettings, 00084 bool activateImmediately, 00085 QString dumpPath ); 00086 00087 void noLongerMouseEventReceiver(); 00088 void paint( QPainter *p ); 00089 00090 void mousePressEvent(QMouseEvent *e) 00091 {pathInput_->processPressEvent(e);} 00092 void mouseMoveEvent(QMouseEvent *e) {pathInput_->processMoveEvent(e);} 00093 void mouseReleaseEvent(QMouseEvent *e) {pathInput_->processReleaseEvent(e);} 00094 void mouseDoubleClickEvent(QMouseEvent *e) {pathInput_->processDoubleClickEvent(e);} 00095 void setFocus( bool inFocus ); 00096 void setUseTransparency( bool useTransparency ); 00097 00098 // to dump the user (green) path to /tmp 00099 void savePath( const QString &fileName ) const 00100 { 00101 pathInput_->savePath( fileName ); 00102 } 00103 00104 public slots: 00105 void savePathAs(); 00106 void savePath(); 00107 void waypointSettingsDialog(); 00108 void waypointModeSelected(); 00109 void send(); 00110 void cancel(); 00111 void allGo(); 00112 void allStop(); 00113 void go(); 00114 void stop(); 00115 00116 private: 00117 00118 PathFollower2dElement *pfElement_; 00119 std::string proxyString_; 00120 hydroqguielementutil::IHumanManager &humanManager_; 00121 hydroqguielementutil::MouseEventManager &mouseEventManager_; 00122 hydroqguielementutil::ShortcutKeyManager &shortcutKeyManager_; 00123 const hydroqgui::GuiElementSet &guiElementSet_; 00124 PathPainter &painter_; 00125 00126 QString pathFileName_; 00127 bool pathFileSet_; 00128 00129 WaypointSettings wpSettings_; 00130 bool activateImmediately_; 00131 00132 std::auto_ptr<PathFollowerInput> pathInput_; 00133 00134 // sets up and destroys buttons and associated actions 00135 std::auto_ptr<PathfollowerButtons> buttons_; 00136 00137 // Do we own the global mode? 00138 bool gotMode_; 00139 00140 bool useTransparency_; 00141 00142 QString dumpPath_; 00143 int numPathDumps_; 00144 QString lastSavedPathFile_; 00145 }; 00146 00147 // We need to inherit from GuiElement2d, not from IceStormElement. 00148 // Reason is that PathFollower2dConsumer has a non-standard purely virtual 00149 // member function setWaypointIndex. 00150 // Disadvantage is that we have to subscribe ourselves. 00151 class PathFollower2dElement : public hydroqguielementutil::GuiElement2d 00152 { 00153 00154 public: 00155 00156 PathFollower2dElement( const orcaice::Context & context, 00157 const std::string &proxyString, 00158 hydroqguielementutil::IHumanManager &humanManager, 00159 hydroqguielementutil::MouseEventManager &mouseEventManager, 00160 hydroqguielementutil::ShortcutKeyManager &shortcutKeyManager, 00161 const hydroqgui::GuiElementSet &guiElementSet ); 00162 00163 // inherited from guielement 00164 void update(); 00165 void paint( QPainter *p, int z ); 00166 bool paintThisLayer( int z ) const 00167 { return painter_.paintThisLayer(z); } 00168 00169 virtual bool isInGlobalCS() { return true; } 00170 virtual QStringList contextMenu(); 00171 virtual void execute( int action ); 00172 virtual void setColor( QColor color ) { painter_.setColor( color ); }; 00173 virtual void setFocus( bool inFocus ); 00174 virtual void setUseTransparency( bool useTransparency ); 00175 00176 virtual void noLongerMouseEventReceiver() { if ( pathHI_.get() ) pathHI_->noLongerMouseEventReceiver(); } 00177 virtual void mousePressEvent(QMouseEvent *e) { if ( pathHI_.get() ) pathHI_->mousePressEvent(e); } 00178 virtual void mouseMoveEvent(QMouseEvent *e) { if ( pathHI_.get() ) pathHI_->mouseMoveEvent(e); } 00179 virtual void mouseReleaseEvent(QMouseEvent *e) { if ( pathHI_.get() ) pathHI_->mouseReleaseEvent(e); } 00180 virtual void mouseDoubleClickEvent(QMouseEvent *e) { if ( pathHI_.get() ) pathHI_->mouseDoubleClickEvent(e); } 00181 00182 void go(); 00183 void stop(); 00184 void sendPath( const PathFollowerInput &pathInput, bool activateImmediately ); 00185 00186 void enableHI(); 00187 void disableHI(); 00188 bool isHIEnabled() { return pathHI_.get() != 0; } 00189 00190 PathPainter &pathPainter() { return painter_; } 00191 00192 private: 00193 void doInitialSetup(); 00194 00195 PathPainter painter_; 00196 00197 int connectToInterface(); 00198 bool isConnected_; 00199 void getInitialData(); 00200 00201 PathUpdateConsumer *pathUpdateConsumer_; 00202 orca::PathFollower2dConsumerPrx callbackPrx_; 00203 orca::PathFollower2dPrx pathFollower2dPrx_; 00204 std::string proxyString_; 00205 00206 orcaice::Context context_; 00207 00208 hydroqguielementutil::IHumanManager &humanManager_; 00209 hydroqguielementutil::MouseEventManager &mouseEventManager_; 00210 hydroqguielementutil::ShortcutKeyManager &shortcutKeyManager_; 00211 const hydroqgui::GuiElementSet &guiElementSet_; 00212 00213 bool firstTime_; 00214 gbxsickacfr::gbxiceutilacfr::Timer *timer_; 00215 gbxsickacfr::gbxiceutilacfr::Timer *activationTimer_; 00216 00217 // toggle states 00218 bool displayWaypoints_; 00219 bool displayPastWaypoints_; 00220 bool displayFutureWaypoints_; 00221 bool displayOlympicMarker_; 00222 bool currentTransparency_; 00223 bool isInFocus_; 00224 00225 bool isRemoteInterfaceSick_; 00226 00227 // Handles human interface 00228 std::auto_ptr<PathFollowerHI> pathHI_; 00229 00230 // returns 0 if remote call works otherwise -1 00231 int isFollowerEnabled( bool &isEnabled ); 00232 00233 }; 00234 00235 } 00236 00237 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)