00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef SO_WX_VIEWER
00025 #define SO_WX_VIEWER
00026
00028
00029
00030
00032
00033 #include <Inventor/Wx/SoWxRenderArea.h>
00034
00035 #include <Inventor/Gui/viewers/SoGuiViewer.h>
00036 #include <Inventor/SoType.h>
00037 #include <Inventor/misc/SoCallbackList.h>
00038 #include <Inventor/SbElapsedTime.h>
00039
00040 #include <Inventor/components/stereo/SoStereoViewer.h>
00041
00042
00043 class SoNode;
00044 class SoDirectionalLight;
00045 class SoGroup;
00046 class SoRotation;
00047 class SoCamera;
00048 class SoDrawStyle;
00049 class SoLightModel;
00050 class SoFieldSensor;
00051 class SoWxViewer;
00052 class SoGetBoundingBoxAction;
00053 class SbPList;
00054 class SoSeparator;
00055 class SoSwitch;
00056 class SoComplexity;
00057 class SoPackedColor;
00058 class SoMaterialBinding;
00059 class SoSFTime;
00060 class SoAlarmSensor;
00061 class SoNodeSensor;
00062 class SoGetPrimitiveCountAction;
00063 class SoStereoViewer;
00064 class SoBaseStereo;
00065
00066 class SoGuiViewer;
00067
00068
00069 typedef void SoWxViewerCB(void* userData, SoWxViewer* viewer);
00070 typedef void SoWxViewerCameraTypeChangeCB(void* userData, SoCamera* camera, SoWxViewer* viewer);
00071
00072
00073
00074 typedef void SoWxViewerFPSCB(float fps, void* userData, SoWxViewer* viewer);
00075 typedef void SoWxViewerDecimationPercentageCB(float percentage, void* userData, SoWxViewer* viewer);
00076
00078
00079
00080
00081
00082
00083
00084
00086
00156 class SoWxViewer : public SoWxRenderArea, public SoStereoViewer
00157 {
00158 public:
00159
00170 enum Type
00171 {
00175 BROWSER,
00179 EDITOR
00180 };
00181
00188 enum DrawStyle
00189 {
00193 VIEW_AS_IS,
00197 VIEW_HIDDEN_LINE,
00201 VIEW_NO_TEXTURE,
00205 VIEW_LOW_COMPLEXITY,
00209 VIEW_LINE,
00213 VIEW_POINT,
00217 VIEW_BBOX,
00221 VIEW_LOW_RES_LINE,
00225 VIEW_LOW_RES_POINT,
00229 VIEW_SAME_AS_STILL
00230 };
00231
00233 enum DrawType
00234 {
00238 STILL,
00242 INTERACTIVE
00243 };
00244
00246 enum BufferType
00247 {
00251 BUFFER_SINGLE,
00255 BUFFER_DOUBLE,
00259 BUFFER_INTERACTIVE
00260 };
00261
00263 enum DecimationStrategy
00264 {
00268 NORMAL,
00272 FIXED_NUM_TRIANGLES,
00276 FRAMES_PER_SECOND,
00280 FIXED_PERCENTAGE
00281 };
00282
00288 enum CursorStyle
00289 {
00293 CLASSIC,
00297 XOR,
00301 SHADOW
00302 };
00303
00312 virtual void setSceneGraph( SoNode* newScene );
00313
00317 virtual SoNode* getSceneGraph();
00318
00324 virtual void setCamera( SoCamera* cam );
00325
00329 SoCamera* getCamera() { return m_guiViewer->getCamera(); }
00330
00339 virtual void setCameraType( SoType type );
00340
00345 SoType getCameraType() { return m_guiViewer->getCameraType(); }
00346
00352 virtual void setPreserveCameraHeightAngle( SbBool flag )
00353 { m_guiViewer->setPreserveCameraHeightAngle( flag ); }
00354
00360 virtual SbBool isCameraHeightAnglePreserved() const { return m_guiViewer->isCameraHeightAnglePreserved(); }
00361
00366 virtual void enableSeekWithOrtho(SbBool flag) { m_guiViewer->enableSeekWithOrtho( flag ); }
00367
00372 virtual SbBool isSeekWithOrthoEnabled() const { return m_guiViewer->isSeekWithOrthoEnabled(); }
00373
00392 virtual void viewAll();
00393
00397 virtual void saveHomePosition();
00398
00402 virtual void resetToHomePosition();
00403
00408 void setCameraTypeChangeCallback( SoWxViewerCameraTypeChangeCB* callback, void* userdata );
00409
00416 virtual void setHeadlight( SbBool onOrOff );
00417
00421 SbBool isHeadlight() { return m_guiViewer->isHeadlight(); }
00422
00426 SoDirectionalLight* getHeadlight() { return m_guiViewer->getHeadlight(); }
00427
00476 virtual void setDrawStyle( SoWxViewer::DrawType type, SoWxViewer::DrawStyle style );
00477
00481 SoWxViewer::DrawStyle getDrawStyle( SoWxViewer::DrawType type );
00482
00487 virtual void setBufferingType( SoWxViewer::BufferType type );
00488
00492 SoWxViewer::BufferType getBufferingType()
00493 { return (SoWxViewer::BufferType)m_guiViewer->getBufferingType(); }
00494
00507 virtual void setViewing( SbBool onOrOff );
00508
00512 SbBool isViewing() const { return m_guiViewer->isViewing(); }
00513
00517 virtual void enableDirectViz( SbBool onOrOff );
00518
00522 virtual void showDirectVizDialog( SbBool show );
00523
00524
00535 virtual void setCursorEnabled( SbBool onOrOff );
00536
00541 SbBool isCursorEnabled() const { return m_guiViewer->isCursorEnabled(); }
00542
00553 void setAutoClipping( SbBool onOrOff );
00554
00558 SbBool isAutoClipping() const { return m_guiViewer->isAutoClipping(); }
00559
00567 virtual void setStereoViewing( SbBool onOrOff );
00568
00573 virtual SbBool isStereoViewing();
00574
00578 void setStereoOffset( float dist );
00579
00583 float getStereoOffset();
00584
00592 void setDetailSeek( SbBool onOrOff ) { m_guiViewer->setDetailSeek( onOrOff ); }
00593
00597 SbBool isDetailSeek() { return m_guiViewer->isDetailSeek(); }
00598
00611 void setSeekTime( float seconds ) { m_guiViewer->setSeekTime( seconds ); }
00612
00616 float getSeekTime() { return m_guiViewer->getSeekTime(); }
00617
00626 void addStartCallback( SoWxViewerCB* f, void* userData = NULL )
00627 { m_guiViewer->addStartCallback( (SoGuiViewerCB*)f, userData ); }
00628
00637 void addFinishCallback( SoWxViewerCB* f, void* userData = NULL )
00638 { m_guiViewer->addFinishCallback( (SoGuiViewerCB*)f, userData ); }
00639
00645 void removeStartCallback( SoWxViewerCB* f, void* userData = NULL )
00646 { m_guiViewer->removeStartCallback( (SoGuiViewerCB*)f, userData ); }
00647
00653 void removeFinishCallback( SoWxViewerCB* f, void* userData = NULL )
00654 { m_guiViewer->removeFinishCallback( (SoGuiViewerCB*)f, userData ); }
00655
00662 virtual void recomputeSceneSize();
00663
00664 #ifndef HIDDEN_FROM_DOC
00665 void saveSceneGraph( const char* fileName );
00666 #endif // HIDDEN_FROM_DOC
00667
00668
00669
00678 void setDecimationStrategy( SoWxViewer::DecimationStrategy strategy );
00679
00683 SoWxViewer::DecimationStrategy getDecimationStrategy()
00684 { return (SoWxViewer::DecimationStrategy)m_guiViewer->getDecimationStrategy(); }
00685
00693 void setGoalNumberOfTriangles( int32_t goal );
00694
00698 int32_t getGoalNumberOfTriangles() { return m_guiViewer->getGoalNumberOfTriangles(); }
00699
00707 void setGoalFramesPerSecond( float goal );
00708
00712 float getGoalFramesPerSecond() { return m_guiViewer->getGoalFramesPerSecond(); }
00713
00721 void setFixedPercentage( float percent );
00722
00726 float getFixedPercentage() { return m_guiViewer->getFixedPercentage(); }
00727
00736 void enableFullRenderingWhenStill( SbBool onOff );
00737
00742 SbBool isFullRenderingWhenStill() { return m_guiViewer->isFullRenderingWhenStill(); }
00743
00747 SbBool isStillNow() { return m_guiViewer->isStillNow(); }
00748
00752 void setFramesPerSecondCallback( SoWxViewerFPSCB* callback, void* userData = NULL );
00753
00758 void setNumSamples( int numFrames );
00759
00764 int getNumSamples() { return m_guiViewer->getNumSamples(); }
00765
00769 void setDecimationPercentageCallback( SoWxViewerDecimationPercentageCB* callback, void* userData = NULL );
00770
00774 float getCurrentDecimationPercentage();
00775
00776
00777
00778 virtual SoCamera* getViewerCamera();
00779 virtual SbBool isViewerDoubleBuffer();
00780 virtual void actualRendering();
00781 virtual const SbVec2s& getSize();
00782 virtual const SbVec2s& getTopLeft() ;
00783 virtual const SbVec2s& getBottomRight() ;
00784 void setStereoViewType( SoBaseStereo* stereo );
00785 SoBaseStereo* getStereoViewType();
00786 void reverseStereoView( SbBool reverse );
00787 SbBool isStereoViewReversed();
00788 virtual void setStereoAbsoluteAdjustments( SbBool absolute );
00789 virtual SbBool isStereoAbsoluteAdjustments() const { return m_guiViewer->isStereoAbsoluteAdjustments(); }
00790 virtual void setStereoBalance( float balance, SbBool nearFrac = false );
00791 virtual float getStereoBalance();
00792 virtual SbBool isStereoBalanceNearFrac();
00793 virtual void setStereoActive( SbBool activate ) ;
00794 virtual SbBool isStereoActive() ;
00795 void setViewport( short left, short bottom, short width, short height );
00796 void getViewport( short& left, short& bottom, short& width, short& height );
00797
00798 SoSeparator* getSceneRoot() { return m_guiViewer->getSceneRoot(); }
00799
00814 virtual void setCursorStyle( SoWxViewer::CursorStyle style );
00815
00819 SoWxViewer::CursorStyle getCursorStyle()
00820 { return (SoWxViewer::CursorStyle)m_guiViewer->getCursorStyle(); }
00821
00831 void setAutoClipTolerance ( float tolerance ) { m_guiViewer->setAutoClipTolerance( tolerance ); }
00832
00836 float getAutoClipTolerance () const { return m_guiViewer->getAutoClipTolerance(); }
00837
00862 virtual void setCameraSceneGraph( SoNode* cameraSceneGraph );
00863
00867 SoNode* getCameraSceneGraph();
00868
00873 void enableMouseWheelDolly( SbBool onOff ) { m_guiViewer->enableMouseWheelDolly( onOff ); }
00874
00883 virtual void setSeekMode( SbBool onOrOff );
00884 SbBool isSeekMode() { return m_guiViewer->isSeekMode(); }
00885
00895 virtual void toggleCameraType();
00896
00902 void setPickRadius( float radius );
00903
00907 float getPickRadius() const;
00908
00909 #if 1 SoDEPRECATED
00915 HDC getCurrentDC() { return NULL; }
00916 SoDEPRECATED
00918 virtual void adjustClippingPlanes();
00919
00920 #endif
00927 SbBool getDepthValue(int x, int y, float &depth)
00928 {
00929 return m_guiViewer->getDepthValue(x, y, depth);
00930 }
00931
00932 private:
00933
00934 SoGuiViewer* getGuiViewer() const;
00935
00936 virtual ~SoWxViewer();
00937
00938
00939 virtual void setDoubleBuffer( SbBool onOrOff );
00940
00941
00942
00943 virtual void setNormalVisual( int* attribList );
00944
00945 SbBool isInteractive() const;
00946
00947 virtual SoGLContext* getViewerContext() { return getNormalSoContext(); }
00948 virtual SoSceneManager* getViewerSceneManager() { return getSceneManager(); }
00949
00950 private:
00951
00952
00953 SoWxViewer( wxWindow* parent,
00954 const char* name,
00955 SbBool buildInsideParent,
00956 SoWxViewer::Type type,
00957 SbBool buildNow,
00958 SbBool sync = true );
00959
00960 SoWxViewer( wxWindow* parent,
00961 const char* name,
00962 SbBool buildInsideParent,
00963 SoWxViewer::Type type,
00964 SbBool buildNow,
00965 SbBool sync,
00966 SoGuiViewer* guiViewer );
00967
00968
00969 SbBool altSwitchBack;
00970
00971
00972
00973
00974
00975
00976 wxCursor normalCursor, dollyCursor, panCursor, rollCursor, seekCursor,
00977 spinCursor, upCursor, flyCursor, walkCursor;
00978
00979
00980
00981
00982
00983 virtual void defineCursors();
00984
00985
00986
00987 virtual void updateCursor() {};
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998 SbBool processCommonEvents( wxEvent& xe );
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011 void interactiveCountInc();
01012 void interactiveCountDec();
01013 int getInteractiveCount() { return m_guiViewer->getInteractiveCount(); }
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025 SbBool seekToPoint( const SbVec2s& mouseLocation );
01026
01027
01028
01029
01030
01031
01032
01033
01034 virtual void interpolateSeekAnimation( float t );
01035 virtual void computeSeekFinalOrientation();
01036
01037
01038
01039
01040 virtual void actualRedraw();
01041
01042
01043
01044
01045 virtual void changeCameraValues( SoCamera* newCamera );
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059 static void setFeedbackOrthoProjection(const SbVec2s& glxSize);
01060
01061
01062
01063 static void restoreGLStateAfterFeedback();
01064
01065
01066 static void drawViewerCrossFeedback(SbVec2s loc);
01067
01068
01069 static void drawViewerRollFeedback( SbVec2s center, SbVec2s loc );
01070
01071 virtual void widgetChanged( wxWindow* w );
01072
01073
01074 virtual void afterRealizeHook();
01075
01076
01077 virtual void adjustCameraClippingPlanes();
01078
01079
01080
01081 virtual void redraw();
01082
01083
01084
01085
01086
01087
01088
01089 virtual float decimationForFramesPerSecond( float fps, double timeTaken, float decimation );
01090
01091
01092
01093
01094
01095
01096 virtual float decimationForNumTriangles( uint32_t numTris );
01097
01098
01099 void* getViewer() { return (void*)this; }
01100
01101 void setCurrentDrawStyle(SoWxViewer::DrawStyle style);
01102
01103 private:
01104
01105 void constructorCommon( SoWxViewer::Type t, SbBool buildNow );
01106 void constructorCommon2( SoWxViewer::Type t, SbBool buildNow );
01107
01108 SoGuiViewer* m_guiViewer;
01109
01110
01111 void setZbufferState();
01112 SbBool isZbufferOff();
01113 void arrowKeyPressed( int rawKey );
01114
01115
01116 static SoGLRenderAction::AbortCode renderAbortCB( void* data );
01117 SoAlarmSensor* stillSensor;
01118 static void alarmCB( void* thisp, SoSensor* ) { ((SoWxViewer*)thisp)->stillSensorCalled(); }
01119 void stillSensorCalled();
01120
01121
01122 static void seekAnimationSensorCB( void* p, SoSensor* sensor );
01123
01124
01140 static SbBool viewingEventCB( SoWxViewer* viewer, wxEvent& anyEvent );
01141
01142 SoNode* m_cameraSceneGraph;
01143 SbBool m_runOnce;
01144
01145
01146
01147 SoCamera* camera;
01148 SbBool createdCursors, viewingFlag;
01149 CursorStyle cursorStyle;
01150 SoSeparator* sceneRoot;
01151 float sceneSize;
01152 SoBaseStereo* stereoViewType;
01153 SbBool m_seekWithOrtho, m_preserveHeightAngle, cursorEnabledFlag, seekDistAsPercentage, computeSeekVariables;
01154 float m_previousHeightAngle, viewerSpeed, seekDistance;
01155 SoWxViewer::Type type;
01156 SoNode* sceneGraph;
01157 SbVec3f seekPoint, seekNormal, oldCamPosition, newCamPosition;
01158 SbRotation oldCamOrientation, newCamOrientation;
01159 };
01160
01161 #endif // SO_WX_VIEWER
01162
01163
01164