00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #ifdef SOQT
00052 # include <Inventor/Qt/viewers/SoQtViewer.h>
00053 #elif defined(SOWX)
00054 # include <Inventor/Wx/viewers/SoWxViewer.h>
00055 #elif defined _WIN32
00056 # include <Inventor/Win/viewers/SoWinViewer.h>
00057 #else
00058
00059 #ifndef _SO_XT_VIEWER_
00060 #define _SO_XT_VIEWER_
00061
00062 #include <Inventor/SoType.h>
00063 #include <Inventor/Xt/SoXtRenderArea.h>
00064 #include <Inventor/misc/SoCallbackList.h>
00065 #include <Inventor/SbElapsedTime.h>
00066 #include <Inventor/events/SoKeyboardEvent.h>
00067 #include <Inventor/Gui/viewers/SoGuiViewer.h>
00068 #include <Inventor/components/stereo/SoStereoViewer.h>
00069
00070
00071 class SoNode;
00072 class SoDirectionalLight;
00073 class SoGroup;
00074 class SoRotation;
00075 class SoCamera;
00076 class SoDrawStyle;
00077 class SoLightModel;
00078 class SoFieldSensor;
00079 class SoXtClipboard;
00080 class SoXtViewer;
00081 class SoGetBoundingBoxAction;
00082 class SbPList;
00083 class SoSeparator;
00084 class SoSwitch;
00085 class SoComplexity;
00086 class SoPackedColor;
00087 class SoMaterialBinding;
00088 class SoSFTime;
00089 class SoXtInputFocus;
00090 class SoAlarmSensor;
00091 class SoNodeSensor;
00092 class SoGetPrimitiveCountAction;
00093 class SoStereoViewer;
00094 class SoBaseStereo;
00095 class ScRayPickAction;
00096
00097
00098 typedef void SoXtViewerCB( void* userData, SoXtViewer* viewer );
00099 typedef void SoXtViewerCameraTypeChangeCB( void* userData, SoCamera* camera, SoXtViewer* viewer );
00100
00101
00102
00103 typedef void SoXtViewerFPSCB( float fps, void* userData, SoXtViewer* viewer );
00104 typedef void SoXtViewerDecimationPercentageCB( float percentage, void* userData, SoXtViewer* viewer );
00105
00107
00108
00109
00110
00111
00112
00113
00115
00187 class SoXtViewer : public SoXtRenderArea, public SoStereoViewer
00188 {
00189 public:
00200 enum Type
00201 {
00205 BROWSER,
00209 EDITOR
00210 };
00211
00218 enum DrawStyle
00219 {
00223 VIEW_AS_IS,
00227 VIEW_HIDDEN_LINE,
00231 VIEW_NO_TEXTURE,
00235 VIEW_LOW_COMPLEXITY,
00239 VIEW_LINE,
00243 VIEW_POINT,
00247 VIEW_BBOX,
00251 VIEW_LOW_RES_LINE,
00255 VIEW_LOW_RES_POINT,
00259 VIEW_SAME_AS_STILL
00260 };
00261
00263 enum DrawType
00264 {
00268 STILL,
00272 INTERACTIVE
00273 };
00274
00276 enum BufferType
00277 {
00281 BUFFER_SINGLE,
00285 BUFFER_DOUBLE,
00289 BUFFER_INTERACTIVE
00290 };
00291
00293 enum DecimationStrategy
00294 {
00298 NORMAL,
00302 FIXED_NUM_TRIANGLES,
00306 FRAMES_PER_SECOND,
00310 FIXED_PERCENTAGE
00311 };
00312
00318 enum CursorStyle
00319 {
00323 CLASSIC,
00327 XOR,
00331 SHADOW
00332 };
00333
00334
00343 virtual void setSceneGraph(SoNode *newScene);
00344
00348 virtual SoNode* getSceneGraph();
00349
00355 virtual void setCamera( SoCamera* cam );
00356
00360 SoCamera* getCamera() { return m_guiViewer->getCamera(); }
00361
00370 virtual void setCameraType( SoType type );
00371
00376 SoType getCameraType() { return m_guiViewer->getCameraType(); }
00377
00383 virtual void setPreserveCameraHeightAngle( SbBool flag )
00384 { m_guiViewer->setPreserveCameraHeightAngle( flag ); }
00385
00391 virtual SbBool isCameraHeightAnglePreserved() const { return m_guiViewer->isCameraHeightAnglePreserved(); }
00392
00397 virtual void enableSeekWithOrtho( SbBool flag ) { m_guiViewer->enableSeekWithOrtho( flag ); }
00398
00403 virtual SbBool isSeekWithOrthoEnabled() const { return m_guiViewer->isSeekWithOrthoEnabled(); }
00404
00423 virtual void viewAll();
00424
00428 virtual void saveHomePosition();
00429
00433 virtual void resetToHomePosition();
00434
00439 void setCameraTypeChangeCallback( SoXtViewerCameraTypeChangeCB* callback, void* userdata );
00440
00447 virtual void setHeadlight( SbBool onOrOff );
00448
00452 SbBool isHeadlight() { return m_guiViewer->isHeadlight(); }
00453
00457 SoDirectionalLight* getHeadlight() { return m_guiViewer->getHeadlight(); }
00458
00507 virtual void setDrawStyle( SoXtViewer::DrawType type, SoXtViewer::DrawStyle style );
00508
00512 SoXtViewer::DrawStyle getDrawStyle( SoXtViewer::DrawType type );
00513
00518 virtual void setBufferingType( SoXtViewer::BufferType type) ;
00519
00523 SoXtViewer::BufferType getBufferingType()
00524 { return (SoXtViewer::BufferType)m_guiViewer->getBufferingType(); }
00525
00538 virtual void setViewing( SbBool onOrOff );
00539
00543 SbBool isViewing() const { return m_guiViewer->isViewing(); };
00544
00548 SbBool isDirectVizEnabled() const { return m_guiViewer->getDirectVizFlag(); }
00549
00550
00554 virtual void enableDirectViz( SbBool onOrOff );
00555
00566 virtual void setCursorEnabled( SbBool onOrOff );
00567
00572 SbBool isCursorEnabled() const { return m_guiViewer->isCursorEnabled(); }
00573
00584 void setAutoClipping( SbBool onOrOff );
00585
00589 SbBool isAutoClipping() const { return m_guiViewer->isAutoClipping(); }
00590
00598 virtual void setStereoViewing( SbBool onOrOff );
00599
00604 virtual SbBool isStereoViewing();
00605
00609 void setStereoOffset( float dist );
00610
00614 float getStereoOffset();
00615
00623 void setDetailSeek( SbBool onOrOff ) { m_guiViewer->setDetailSeek( onOrOff ); };
00624
00628 SbBool isDetailSeek() { return m_guiViewer->isDetailSeek(); }
00629
00642 void setSeekTime( float seconds ) { m_guiViewer->setSeekTime( seconds ); }
00643
00647 float getSeekTime() { return m_guiViewer->getSeekTime(); }
00648
00657 void addStartCallback( SoXtViewerCB* f, void* userData = NULL )
00658 { m_guiViewer->addStartCallback( (SoGuiViewerCB*)f, userData ); }
00659
00668 void addFinishCallback( SoXtViewerCB* f, void* userData = NULL )
00669 { m_guiViewer->addFinishCallback( (SoGuiViewerCB*)f, userData ); }
00670
00676 void removeStartCallback( SoXtViewerCB* f, void* userData = NULL )
00677 { m_guiViewer->removeStartCallback( (SoGuiViewerCB*)f, userData ); }
00678
00684 void removeFinishCallback( SoXtViewerCB* f, void* userData = NULL )
00685 { m_guiViewer->removeFinishCallback( (SoGuiViewerCB*)f, userData ); }
00686
00692 void copyView( Time eventTime );
00693
00699 void pasteView( Time eventTime );
00700
00707 virtual void recomputeSceneSize();
00708
00709
00710
00719 void setDecimationStrategy( SoXtViewer::DecimationStrategy strategy );
00720
00724 SoXtViewer::DecimationStrategy getDecimationStrategy()
00725 { return (SoXtViewer::DecimationStrategy)m_guiViewer->getDecimationStrategy(); }
00726
00734 void setGoalNumberOfTriangles( int32_t goal );
00735
00739 int32_t getGoalNumberOfTriangles() { return m_guiViewer->getGoalNumberOfTriangles(); };
00740
00748 void setGoalFramesPerSecond( float goal );
00749
00753 float getGoalFramesPerSecond() { return m_guiViewer->getGoalFramesPerSecond(); };
00754
00762 void setFixedPercentage( float percent );
00763
00767 float getFixedPercentage() { return m_guiViewer->getFixedPercentage(); };
00768
00777 void enableFullRenderingWhenStill( SbBool onOff );
00778
00783 SbBool isFullRenderingWhenStill() { return m_guiViewer->isFullRenderingWhenStill(); };
00784
00788 SbBool isStillNow() { return m_guiViewer->isStillNow(); };
00789
00793 void setFramesPerSecondCallback( SoXtViewerFPSCB* callback, void* userData = NULL );
00794
00799 void setNumSamples( int numFrames );
00804 int getNumSamples() { return m_guiViewer->getNumSamples(); }
00805
00809 void setDecimationPercentageCallback( SoXtViewerDecimationPercentageCB* callback, void* userData = NULL );
00810
00814 float getCurrentDecimationPercentage();
00815
00816
00817
00818 virtual SoCamera* getViewerCamera();
00819 virtual SbBool isViewerDoubleBuffer();
00820 virtual void actualRendering();
00821 virtual const SbVec2s& getSize();
00822 virtual const SbVec2s& getTopLeft() ;
00823 virtual const SbVec2s& getBottomRight() ;
00824 void setStereoViewType( SoBaseStereo* stereo );
00825 SoBaseStereo* getStereoViewType();
00826 void reverseStereoView( SbBool reverse );
00827 SbBool isStereoViewReversed();
00828 virtual void setStereoAbsoluteAdjustments( SbBool absolute );
00829 virtual SbBool isStereoAbsoluteAdjustments() const { return m_guiViewer->isStereoAbsoluteAdjustments(); }
00830 virtual void setStereoBalance( float balance, SbBool nearFrac );
00831 virtual float getStereoBalance();
00832 virtual SbBool isStereoBalanceNearFrac();
00833 virtual void setStereoActive( SbBool activate );
00834 virtual SbBool isStereoActive();
00835 void setViewport( short left, short bottom, short width, short height );
00836 void getViewport( short &left, short &bottom, short &width, short &height );
00837
00838
00853 virtual void setCursorStyle( SoXtViewer::CursorStyle style );
00854
00858 SoXtViewer::CursorStyle getCursorStyle()
00859 { return (SoXtViewer::CursorStyle)m_guiViewer->getCursorStyle(); }
00860
00861
00862 SoSeparator* getSceneRoot() { return m_guiViewer->getSceneRoot(); }
00863
00873 void setAutoClipTolerance ( float tolerance ) { m_guiViewer->setAutoClipTolerance( tolerance ); };
00874
00878 float getAutoClipTolerance () const { return m_guiViewer->getAutoClipTolerance(); };
00879
00904 virtual void setCameraSceneGraph( SoNode* cameraSceneGraph );
00905
00909 SoNode* getCameraSceneGraph();
00910
00920 virtual void toggleCameraType();
00921
00929 virtual void setSeekMode( SbBool onOrOff );
00930
00940 void setPickRadius( float radius );
00941
00945 float getPickRadius() const;
00946
00947 #if 1 SoDEPRECATED
00953 HDC getCurrentDC() { return NULL; }
00954 SoDEPRECATED
00956 virtual void adjustClippingPlanes();
00957
00958 #endif
00965 SbBool getDepthValue(int x, int y, float &depth)
00966 {
00967 return m_guiViewer->getDepthValue(x, y, depth);
00968 }
00969
00970 private:
00971 virtual ~SoXtViewer();
00972
00973
00974 virtual void setDoubleBuffer( SbBool onOrOff );
00975
00976
00977
00978 virtual void setNormalVisual( XVisualInfo* v );
00979
00980 #ifndef HIDDEN_FROM_DOC
00981 void saveSceneGraph( const char* fileName ) ;
00982
00983 void showDirectVizDialog( SbBool show );
00984 #endif //HIDDEN_FROM_DOC
00985
00986 SbBool isInteractive() const;
00987
00988 SoGuiViewer* getGuiViewer() const;
00989
00990
00991
00992 SoCamera* camera;
00993 SbBool createdCursors, viewingFlag;
00994 CursorStyle cursorStyle;
00995 SoSeparator* sceneRoot;
00996 float sceneSize;
00997 SoBaseStereo* stereoViewType;
00998 SbBool m_seekWithOrtho, m_preserveHeightAngle, cursorEnabledFlag, seekDistAsPercentage, computeSeekVariables;
00999 float m_previousHeightAngle, viewerSpeed, seekDistance;
01000 SoXtViewer::Type type;
01001 SoNode* sceneGraph;
01002 SbVec3f seekPoint, seekNormal, oldCamPosition, newCamPosition;
01003 SbRotation oldCamOrientation, newCamOrientation;
01004
01005 virtual SoGLContext* getViewerContext() { return getNormalSoContext(); }
01006 virtual SoSceneManager* getViewerSceneManager() { return getSceneManager(); }
01007
01008 private:
01009
01010
01011 SoXtViewer( SoWidget parent,
01012 const char* name,
01013 SbBool buildInsideParent,
01014 SoXtViewer::Type type,
01015 SbBool buildNow,
01016 SbBool sync = TRUE );
01017
01018 SoXtViewer( SoWidget parent,
01019 const char* name,
01020 SbBool buildInsideParent,
01021 SoXtViewer::Type type,
01022 SbBool buildNow,
01023 SbBool sync,
01024 SoGuiViewer* guiViewer );
01025
01026
01027
01028
01029 virtual void updateCursor() {};
01030
01031
01032 SbBool altSwitchBack;
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043 SbBool processCommonEvents( XAnyEvent* xe );
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056 void interactiveCountInc();
01057 void interactiveCountDec();
01058 int getInteractiveCount() { return m_guiViewer->getInteractiveCount(); }
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070 SbBool seekToPoint( const SbVec2s& mouseLocation );
01071
01072
01073
01074
01075
01076
01077
01078
01079 virtual void interpolateSeekAnimation( float t );
01080 virtual void computeSeekFinalOrientation();
01081
01082 SbBool isSeekMode() { return m_guiViewer->isSeekMode(); }
01083
01084
01085
01086
01087 virtual void actualRedraw();
01088
01089
01090
01091
01092 virtual void changeCameraValues( SoCamera* newCamera );
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106 static void setFeedbackOrthoProjection( const SbVec2s& glxSize );
01107
01108
01109
01110 static void restoreGLStateAfterFeedback();
01111
01112
01113 static void drawViewerCrossFeedback( SbVec2s loc );
01114
01115
01116 static void drawViewerRollFeedback( SbVec2s center, SbVec2s loc );
01117
01118
01119 virtual void afterRealizeHook();
01120
01121 virtual void widgetChanged( SoWidget );
01122
01123
01124 SbBool autoClipFlag;
01125 float minimumNearPlane;
01126 SoGetBoundingBoxAction* autoClipBboxAction;
01127 virtual void adjustCameraClippingPlanes();
01128
01129
01130
01131 virtual void redraw();
01132
01133
01134
01135
01136
01137
01138
01139 virtual float decimationForFramesPerSecond( float fps, double timeTaken, float decimation );
01140
01141
01142
01143
01144
01145
01146 virtual float decimationForNumTriangles( uint32_t numTris );
01147
01148
01149 void* getViewer() { return (void*)this; }
01150
01151 private:
01152 void constructorCommon( SoXtViewer::Type t, SbBool buildNow );
01153
01154 void constructorCommon2( SoXtViewer::Type t, SbBool buildNow );
01155
01156 SoGuiViewer* m_guiViewer;
01157
01158 SbBool m_firstRealize;
01159
01160
01161 SoXtInputFocus* inputFocus;
01162
01163
01164 void setCurrentDrawStyle( SoXtViewer::DrawStyle style );
01165
01166
01167 SoXtClipboard* clipboard;
01168 static void pasteDoneCB( void* userData, SoPathList* pathList );
01169
01170
01171 void setZbufferState();
01172 SbBool isZbufferOff();
01173 void arrowKeyPressed( KeySym key );
01174
01175
01176 static SoGLRenderAction::AbortCode renderAbortCB( void* data );
01177 SoAlarmSensor* stillSensor;
01178 static void alarmCB( void* thisp, SoSensor* )
01179 { ((SoXtViewer*)thisp)->stillSensorCalled(); }
01180
01181
01197 static SbBool viewingEventCB( SoXtViewer* viewer, XAnyEvent* anyEvent );
01198
01199 void stillSensorCalled();
01200
01201
01202 static void seekAnimationSensorCB( void* p, SoSensor* sensor );
01203 };
01204
01205 #endif
01206
01207 #endif
01208
01209
01210