![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2008 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 /****************************************************************************** 00006 ** $RCSfile: DtObserver.h,v $ $Revision: 1.43 $ $State: Exp $ 00007 ******************************************************************************/ 00008 00012 00013 #pragma once 00014 00015 #include <vrvCore/vrvCore.h> 00016 #include <vrvCore/DtElementData.h> 00017 #include <vrvCore/DtUniqueID.h> 00018 #include <vrvCore/DtObserverObject.h> 00019 #include <vrvUtil/DtSignalConnectionManager.h> 00020 #include <makArchives/DtObserverSettingsRecord.h> 00021 #include <makArchives/DtObserverStateRecord.h> 00022 #include <boost/signals.hpp> 00023 #include <string> 00024 #include <vector> 00025 00026 class DtTaitBryan; 00027 class DtVector; 00028 00029 namespace makVrv 00030 { 00031 class DtObserverObjectAgent; 00032 class DtDe; 00033 class DtAgentManagerInterface; 00034 class DtObserverConfiguration; 00035 00038 class DT_DLL_VRVCORE DtObserver 00039 { 00040 public: 00041 00042 typedef std::vector<DtElementID> ElementList; 00043 00045 DtObserver(DtDe& de, DtAgentManagerInterface& sceneInterface, 00046 const DtObserverConfiguration& config ); 00047 00049 ~DtObserver(); 00050 00052 inline DtDe& de() 00053 { 00054 return myDe; 00055 } 00056 00058 DtObserverObjectAgent& agent(); 00059 00061 const DtObserverObjectAgent& agent() const; 00062 00064 bool getRecord(makArchives::DtObserverStateRecord& recOut) const; 00065 00067 void setFromRecord(const makArchives::DtObserverStateRecord& rec); 00068 00070 bool getRecord(makArchives::DtObserverSettingsRecord& recOut) const; 00071 00073 void setFromRecord(const makArchives::DtObserverSettingsRecord& rec); 00074 00077 bool hasInitialLocation() const; 00078 00080 const std::string& name() const; 00081 void setName( const std::string& name ); 00082 00084 int observerMode() const; 00085 00087 void setObserverMode( int observerMode ); 00088 00090 double viewResolution() const; 00091 00093 void setViewResolution( double resolution ); 00094 00096 double viewMagnification() const; 00097 00099 void setViewMagnification( double magnficationFactor ); 00100 00103 bool acceptingViewControl() const; 00104 00105 DtObserverConfiguration& configuration(); 00106 const DtObserverConfiguration& configuration() const; 00107 00109 bool inUse( const std::string& channelKeyToIgnore = "" ) const; 00110 00111 //@name Attachment functions. 00113 00115 void attachToNextElement(); 00116 00118 void attachToPreviousElement(); 00119 00121 bool isAttached(DtElementID) const; 00122 00124 bool isPrimaryAttached(DtElementID) const; 00125 00127 bool isSecondaryAttached(DtElementID) const; 00128 00132 void setPrimaryAttachment( const ElementList& element ); 00133 00138 void setSecondaryAttachment( const ElementList& objects ); 00139 00143 void setPartAttachment(int partId); 00144 00146 int partAttachment() const; 00147 00149 void detach(); 00150 00152 bool attached() const; 00153 00155 bool tracking() const; 00156 00158 const ElementList& primaryAttachments() const; 00159 00161 const ElementList& secondaryAttachments() const; 00162 00163 void setHideModelOnAttach( bool hide ); 00164 bool hideModelOnAttach() const; 00165 00166 void setAttachType( DtObserverObject::AttachType type ); 00167 DtObserverObject::AttachType attachType() const; 00168 00169 void setOrientToTargetConstraint( bool orient ); 00170 bool orientToTargetConstraint() const; 00171 00174 DtElementID lastSingleAttached() const; 00175 00177 bool haveLastSingleAttached() const; 00178 00180 00181 //@name Movement functions 00183 00186 void reset(); 00187 00190 void setAllowReset(bool b); 00191 00193 bool allowReset() const; 00194 00196 void setAllowAttach(bool b); 00197 00199 bool allowAttach() const; 00200 00202 void setAllowDetach(bool b); 00203 00205 bool allowDetach() const; 00206 00208 void centerOnTerrain(); 00209 00211 void centerOnTerrain( const DtUniqueID& terrainPatch ); 00212 00215 void suppressConstrainToTerrain( bool trueFalse ); 00216 00218 void setConstrainToCenter( bool trueFalse ); 00219 void toggleConstrainToCenter(); 00220 bool constrainToCenter() const; 00221 00223 void getLocation( double &x, double &y, double& z ) const; 00224 00226 DtVector location() const; 00227 00229 void setLocation( double x, double y, double z ); 00230 00232 void getOrientation( double& psi, double& theta, double& phi ) const; 00233 00235 void setOrientation( double psi, double theta, double phi ); 00236 00238 void getOrientation( double& x, double& y, double& z, double& w ) const; 00239 00241 void setOrientation( double x, double y, double z, double w ); 00242 00245 void moveUnit(const DtVector& direction); 00246 00249 void rotateUnit(const DtTaitBryan& rotation); 00250 00252 void getLinearVelocity(double &x, double &y, double &z) const; 00253 00255 void getRotationalVelocity( double& x, double& y, double& z ) const; 00256 00258 bool observerObjectMoving() const; 00259 00261 double observerAltitude() const; 00263 00264 //@name Attached Movement functions 00266 00269 void setAttachedLocation( double x, double y, double z ); 00270 00273 void setAttachedOrientation( double psi, double theta, double phi ); 00274 00277 void setLocalModelScalingEnabled( bool enabled ); 00278 00281 void setLocalModelScalingAmount( float amount ); 00282 00284 00285 //@name Speed functions 00287 00289 void setOrbitSpeedGain( int gain, bool forwardToObserverModeManager = true ); 00290 00292 int orbitSpeedGain() const; 00293 00295 int orbitSpeedGainFromSpeed( double speed ) const; 00296 00297 void setRotationSpeedGain( int gain, bool forwardToObserverModeManager = true ); 00298 int rotationSpeedGain() const; 00299 00301 void setLinearSpeedGain( int gain ); 00302 int linearSpeedGain() const; 00303 00304 void setLinearScaledSpeedGain( int gain, bool forwardToObserverModeManager = true ); 00305 int linearScaledSpeedGain() const; 00306 00307 void setLinearUnscaledSpeedGain( int gain, bool forwardToObserverModeManager = true ); 00308 int linearUnscaledSpeedGain() const; 00309 00310 void setGainPrecision( int amt, bool forwardToObserverModeManager = true ); 00311 int gainPrecision() const; 00312 00313 void setModelScaleFactor( double modelScaleFactor, bool forwardToObserverModeManager = true ); 00314 double modelScaleFactor() const; 00315 00316 void setModelScaleType( DtObserverObject::ScaleType modelScaleType, 00317 bool forwardToObserverModeManager = true ); 00318 DtObserverObject::ScaleType modelScaleType() const; 00319 00320 void setOrbitSpeed( double speed ); 00321 double orbitSpeed() const; 00322 00323 void setRotationSpeed( double speed ); 00324 double rotationSpeed() const; 00325 00326 void setLinearSpeed( double speed ); 00327 double linearSpeed() const; 00328 00330 00331 // Called by the input driver before any mouse or keyboard input is processed for the 00332 // frame, to sync local and remote observers. 00333 virtual void synchronize(); 00334 00336 boost::signal<void(const std::string&, DtUniqueID)> signal_objectAttached; 00337 00339 boost::signal<void(const std::string&)> signal_objectsDetached; 00340 00342 boost::signal<void(DtObserver*, int)> signal_observerModeChanged; 00343 00345 boost::signal<void(DtObserver*, int)> signal_linearScaledSpeedGainChanged; 00346 00348 boost::signal<void(DtObserver*, int)> signal_linearUnscaledSpeedGainChanged; 00349 00351 boost::signal<void(DtObserver*, int)> signal_rotationSpeedGainChanged; 00352 00354 boost::signal<void(DtObserver*, int)> signal_orbitSpeedGainChanged; 00355 00357 boost::signal<void(DtObserver*, int)> signal_gainPrecisionChanged; 00358 00360 boost::signal<void(DtObserver*, double)> signal_modelScaleFactorChanged; 00361 00363 boost::signal<void(DtObserver*, DtObserverObject::ScaleType)> signal_modelScaleTypeChanged; 00364 00366 boost::signal<void(DtObserver*, double)> signal_viewMagnificationChanged; 00367 00368 protected: 00369 00371 void slot_terrainCleared(); 00372 00373 void updateGlobalTerrainFlag(bool flag); 00374 00375 double calcLinearSpeed() const; 00376 double calcRotationSpeed() const; 00377 double calcOrbitSpeed() const; 00378 00379 void getObserverOffsetVector( double& x, double& y, double& z ) const; 00380 void setObserverOffsetVector( double x, double y, double z ); 00381 00382 void getObserverRotationOffset( double& x, double& y, double& z, double& w ) const; 00383 void setObserverRotationOffset( double x, double y, double z, double w ); 00384 00385 void getDisplayNamesFromUniqueIds(const std::vector<DtUniqueID>& idsIn, 00386 std::set<std::string>& displayNamesOut) const; 00387 bool getUniqueIdsFromDisplayNames(const std::set<std::string>& displayNamesIn, 00388 std::vector<DtUniqueID>& idsOut) const; 00389 00390 makArchives::DtObserverSettingsRecord::AttachType convertObserverAttachType( 00391 DtObserverObject::AttachType type) const; 00392 DtObserverObject::AttachType convertObserverSettingsAttachType( 00393 makArchives::DtObserverSettingsRecord::AttachType type) const; 00394 00395 void connectToElementDataSignals(); 00396 void disconnectFromElementDataSignals(); 00397 00398 void setModeSpecificObserverObjectData(); 00399 00401 virtual void slot_onElementsAdded( const DtElementData::ElementList& elements ); 00402 00404 virtual void slot_onElementAttributesChanged( 00405 const DtElementData::EntryAttributesList& attributes ); 00406 00407 void slot_observerModeModelSetChanged( int observerMode ); 00408 void slot_observerModeIs2DChanged( int observerMode ); 00409 void slot_observerModeKeyMapChanged( int observerMode ); 00410 void slot_observerModeGainPrecisionChanged( int observerMode ); 00411 void slot_observerModeOrbitSpeedGainChanged( int observerMode ); 00412 void slot_observerModeRotationSpeedGainChanged( int observerMode ); 00413 void slot_observerModeLinearScaledSpeedGainChanged( int observerMode ); 00414 void slot_observerModeLinearUnscaledSpeedGainChanged( int observerMode ); 00415 void slot_observerModeModelScaleFactorChanged( int observerMode ); 00416 void slot_observerModeModelScaleTypeChanged( int observerMode ); 00417 void slot_observerModeSettingChanged( int observerMode, int settingKey ); 00418 void slot_observerModeAdded( int observerMode ); 00419 00421 void attachTo( bool afterTrue ); 00422 00423 protected: 00424 00425 static const double theMoveStepSize; 00426 00427 DtDe& myDe; 00428 DtSignalConnectionManager myConnections; 00429 DtObserverObjectAgent* myObserverObjectAgent; 00430 DtObserverConfiguration* myConfiguration; 00431 makArchives::DtObserverStateRecord myCachedObserverStateRecord; 00432 int myObserverMode; 00433 bool myHideModelOnAttach; 00434 DtObserverObject::AttachType myAttachType; 00435 std::vector<DtUniqueID> myCurrentAttachments; 00436 std::vector<DtUniqueID> mySecondaryAttachments; 00437 DtUniqueID myLastSingleAttached; 00438 unsigned int myPartId; 00439 bool myOrientToTargetConstraint; 00440 bool myConstrainToCenter; 00441 bool myConnectedToElementDataSignals; 00442 bool myAllowReset; 00443 bool myAllowAttach; 00444 bool myAllowDetach; 00445 bool myHasInitialLocation; 00446 double myViewMagnification; 00447 }; 00448 }