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 #ifndef _SO_WIN_VIEWER_
00026 #define _SO_WIN_VIEWER_
00027
00028 #include <Inventor/Win/SoWinBeginStrict.h>
00029
00030 #include <Inventor/SoType.h>
00031 #include <Inventor/Win/SoWinRenderArea.h>
00032 #include <Inventor/misc/SoCallbackList.h>
00033 #include <Inventor/SbElapsedTime.h>
00034 #include <Inventor/events/SoKeyboardEvent.h>
00035 #include <Inventor/Gui/viewers/SoGuiViewer.h>
00036
00037 #include <Inventor/components/stereo/SoStereoViewer.h>
00038
00039
00040 class SoFieldSensor;
00041 class SoNode;
00042 class SoDirectionalLight;
00043 class SoGroup;
00044 class SoRotation;
00045 class SoCamera;
00046 class SoDrawStyle;
00047 class SoLightModel;
00048 class SoTimerSensor;
00049 class SoWinClipboard;
00050 class SoWinViewer;
00051 class SoGetBoundingBoxAction;
00052 class SbPList;
00053 class SoSeparator;
00054 class SoSwitch;
00055 class SoComplexity;
00056 class SoPackedColor;
00057 class SoMaterialBinding;
00058 class SoBaseColor;
00059 class SoSFTime;
00060 class SoAlarmSensor;
00061 class SoNodeSensor;
00062 class SoGetPrimitiveCountAction;
00063 class SoStereoViewer;
00064 class SoBaseStereo;
00065
00066 class SoType;
00067 class SbEventWrapperList;
00068
00069 class ScRayPickAction;
00070
00071
00072
00073 typedef void SoWinViewerCB( void* userData, SoWinViewer* viewer );
00074
00075 typedef void SoWinViewerCameraTypeChangeCB( void* userData, SoCamera* camera, SoWinViewer* viewer );
00076
00081 typedef void SoWinViewerFPSCB( float fps, void* userData, SoWinViewer* viewer );
00082
00083 typedef void SoWinViewerDecimationPercentageCB( float percentage, void* userData, SoWinViewer* viewer );
00084
00086
00087
00088
00089
00090
00091
00092
00094
00165 class SoWinViewer : public SoWinRenderArea, public SoStereoViewer {
00166
00167 public:
00168
00179 enum Type
00180 {
00184 BROWSER,
00188 EDITOR
00189 };
00190
00197 enum DrawStyle
00198 {
00202 VIEW_AS_IS,
00206 VIEW_HIDDEN_LINE,
00210 VIEW_NO_TEXTURE,
00214 VIEW_LOW_COMPLEXITY,
00218 VIEW_LINE,
00222 VIEW_POINT,
00226 VIEW_BBOX,
00230 VIEW_LOW_RES_LINE,
00234 VIEW_LOW_RES_POINT,
00238 VIEW_SAME_AS_STILL
00239 };
00241 enum DrawType
00242 {
00246 STILL,
00250 INTERACTIVE
00251 };
00252
00253
00255 enum BufferType
00256 {
00260 BUFFER_SINGLE,
00264 BUFFER_DOUBLE,
00268 BUFFER_INTERACTIVE
00269 };
00270
00271
00273 enum DecimationStrategy
00274 {
00278 NORMAL,
00282 FIXED_NUM_TRIANGLES,
00286 FRAMES_PER_SECOND,
00290 FIXED_PERCENTAGE
00291 };
00292
00298 enum CursorStyle
00299 {
00303 CLASSIC,
00307 XOR,
00311 SHADOW
00312 };
00313
00322 virtual void setSceneGraph( SoNode* newScene );
00323
00327 virtual SoNode* getSceneGraph();
00328
00329 #ifndef HIDDEN_FROM_DOC
00330 void saveSceneGraph( const char* fileName ) ;
00331 #endif //HIDDEN_FROM_DOC
00332
00338 virtual void setCamera(SoCamera *cam);
00339
00343 SoCamera* getCamera() { return m_guiViewer->getCamera(); }
00344
00353 virtual void setCameraType(SoType type);
00354
00359 SoType getCameraType() { return m_guiViewer->getCameraType(); }
00360
00366 virtual void setPreserveCameraHeightAngle(SbBool flag)
00367 { m_guiViewer->setPreserveCameraHeightAngle( flag ); }
00368
00374 virtual SbBool isCameraHeightAnglePreserved() const
00375 { return m_guiViewer->isCameraHeightAnglePreserved(); }
00376
00381 virtual void enableSeekWithOrtho( SbBool flag ) { m_guiViewer->enableSeekWithOrtho( flag ); }
00382
00387 virtual SbBool isSeekWithOrthoEnabled() const { return m_guiViewer->isSeekWithOrthoEnabled(); }
00388
00407 virtual void viewAll();
00408
00412 virtual void saveHomePosition();
00413
00417 virtual void resetToHomePosition();
00418
00423 void setCameraTypeChangeCallback( SoWinViewerCameraTypeChangeCB* callback, void* userdata );
00424
00431 void setHeadlight( SbBool onOrOff );
00432
00436 SbBool isHeadlight() { return m_guiViewer->isHeadlight(); }
00437
00441 SoDirectionalLight* getHeadlight() { return m_guiViewer->getHeadlight(); }
00442
00491 void setDrawStyle( SoWinViewer::DrawType type, SoWinViewer::DrawStyle style );
00492
00496 SoWinViewer::DrawStyle getDrawStyle( SoWinViewer::DrawType type );
00497
00502 void setBufferingType( SoWinViewer::BufferType type );
00503
00507 SoWinViewer::BufferType getBufferingType()
00508 { return (SoWinViewer::BufferType)m_guiViewer->getBufferingType(); }
00509
00522 virtual void setViewing( SbBool onOrOff );
00523
00527 SbBool isViewing() const { return m_guiViewer->isViewing(); }
00528
00537 virtual void setSeekMode(SbBool onOrOff);
00538
00543 SbBool isSeekMode() { return m_guiViewer->isSeekMode(); }
00544
00556 virtual void setCursorEnabled( SbBool onOrOff );
00557
00563 SbBool isCursorEnabled() const { return m_guiViewer->isCursorEnabled(); }
00564
00574 void setAutoClipping( SbBool onOrOff );
00575
00579 SbBool isAutoClipping() const { return m_guiViewer->isAutoClipping(); }
00580
00606 virtual void setStereoViewing( SbBool onOrOff );
00607
00612 virtual SbBool isStereoViewing();
00613
00617 void setStereoOffset( float dist );
00618
00622 float getStereoOffset();
00623
00631 void setDetailSeek( SbBool onOrOff ) { m_guiViewer->setDetailSeek( onOrOff ); }
00632
00636 SbBool isDetailSeek() { return m_guiViewer->isDetailSeek(); }
00637
00650 void setSeekTime( float seconds ) { m_guiViewer->setSeekTime( seconds ); }
00651
00655 float getSeekTime() { return m_guiViewer->getSeekTime(); }
00656
00666 void addStartCallback( SoWinViewerCB* f, void* userData = NULL )
00667 { m_guiViewer->addStartCallback( (SoGuiViewerCB*)f, userData ); }
00668
00678 void addFinishCallback( SoWinViewerCB* f, void* userData = NULL )
00679 { m_guiViewer->addFinishCallback( (SoGuiViewerCB*)f, userData ); }
00680
00687 void removeStartCallback( SoWinViewerCB* f, void* userData = NULL )
00688 { m_guiViewer->removeStartCallback( (SoGuiViewerCB*)f, userData ); }
00689
00696 void removeFinishCallback( SoWinViewerCB *f, void* userData = NULL )
00697 { m_guiViewer->removeFinishCallback( (SoGuiViewerCB*)f, userData ); }
00698
00704 void copyView( Time eventTime );
00705
00711 void pasteView( Time eventTime );
00712
00713
00714
00715 virtual void setNormalVisual( XVisualInfo* i );
00716
00723 virtual void recomputeSceneSize();
00724
00725
00726
00732 void setDecimationStrategy( SoWinViewer::DecimationStrategy strategy );
00733
00737 SoWinViewer::DecimationStrategy getDecimationStrategy()
00738 { return (SoWinViewer::DecimationStrategy)m_guiViewer->getDecimationStrategy(); }
00739
00747 void setGoalNumberOfTriangles(int32_t goal);
00748
00752 int32_t getGoalNumberOfTriangles() { return m_guiViewer->getGoalNumberOfTriangles(); }
00753
00761 void setGoalFramesPerSecond( float goal );
00762
00766 float getGoalFramesPerSecond() { return m_guiViewer->getGoalFramesPerSecond(); }
00767
00775 void setFixedPercentage( float percent );
00776
00780 float getFixedPercentage() { return m_guiViewer->getFixedPercentage(); }
00781
00790 void enableFullRenderingWhenStill( SbBool onOff );
00791
00796 SbBool isFullRenderingWhenStill() { return m_guiViewer->isFullRenderingWhenStill(); }
00797
00801 SbBool isStillNow() { return m_guiViewer->isStillNow(); }
00802
00806 void setFramesPerSecondCallback( SoWinViewerFPSCB* callback, void* userData = NULL );
00807
00812 void setNumSamples( int numFrames );
00813
00818 int getNumSamples() { return m_guiViewer->getNumSamples(); }
00819
00823 void setDecimationPercentageCallback( SoWinViewerDecimationPercentageCB *callback,
00824 void* userData = NULL );
00825
00829 float getCurrentDecimationPercentage();
00830
00835 void enableMouseWheelDolly( SbBool onOff ) { m_guiViewer->enableMouseWheelDolly( onOff ); }
00836
00837
00847 void setPickRadius( float radius );
00848
00852 float getPickRadius() const;
00853
00854 public:
00855
00859 virtual SoCamera* getViewerCamera();
00860
00864 virtual SbBool isViewerDoubleBuffer();
00865
00872 virtual void actualRendering();
00873
00878 virtual const SbVec2s& getSize();
00879
00887 virtual const SbVec2s& getTopLeft() ;
00888
00896 virtual const SbVec2s& getBottomRight() ;
00897
00904 void setStereoViewType( SoBaseStereo* stereo );
00905
00909 SoBaseStereo* getStereoViewType();
00910
00914 void reverseStereoView( SbBool reverse );
00915
00919 SbBool isStereoViewReversed();
00920
00924 virtual void setStereoAbsoluteAdjustments( SbBool absolute );
00925
00929 virtual SbBool isStereoAbsoluteAdjustments() const { return m_guiViewer->isStereoAbsoluteAdjustments(); }
00930
00935 virtual void setStereoBalance( float balance, SbBool nearFrac = false );
00936
00940 virtual float getStereoBalance();
00941
00946 virtual SbBool isStereoBalanceNearFrac();
00947
00952 virtual void setStereoActive( SbBool activate ) ;
00953
00957 virtual SbBool isStereoActive() ;
00958
00962 void setViewport( short left, short bottom, short width, short height ) ;
00963
00967 void getViewport( short& left, short& bottom, short& width, short& height ) ;
00968
00983 virtual void setCursorStyle( SoWinViewer::CursorStyle style );
00984
00988 SoWinViewer::CursorStyle getCursorStyle()
00989 { return (SoWinViewer::CursorStyle)m_guiViewer->getCursorStyle(); }
00990
01000 void setAutoClipTolerance ( float tolerance ) { m_guiViewer->setAutoClipTolerance( tolerance ); }
01001
01005 float getAutoClipTolerance () const { return m_guiViewer->getAutoClipTolerance(); }
01006
01031 virtual void setCameraSceneGraph( SoNode* cameraSceneGraph );
01032
01036 SoNode* getCameraSceneGraph();
01037
01047 virtual void toggleCameraType();
01048
01049 #if 1 SoDEPRECATED
01056 virtual void adjustClippingPlanes();
01057
01058 #endif
01065 SbBool getDepthValue(int x, int y, float &depth)
01066 {
01067 return m_guiViewer->getDepthValue(x, y, depth);
01068 }
01069
01070 private:
01071
01072 virtual ~SoWinViewer();
01073
01078 float getAntoClipTolerance() const { return m_guiViewer->getAutoClipTolerance(); }
01079
01080 SoSeparator* getSceneRoot() { return m_guiViewer->getSceneRoot(); }
01081
01082 virtual SbBool isInteractive() const;
01083
01084 SoGuiViewer* getGuiViewer() const;
01085
01086
01087
01088 SoCamera* camera;
01089 SbBool createdCursors, viewingFlag;
01090 CursorStyle cursorStyle;
01091 SoSeparator* sceneRoot;
01092 float sceneSize;
01093 SoBaseStereo* stereoViewType;
01094 SbBool m_seekWithOrtho, m_preserveHeightAngle, cursorEnabledFlag, seekDistAsPercentage, computeSeekVariables;
01095 float m_previousHeightAngle, viewerSpeed, seekDistance;
01096 SoWinViewer::Type type;
01097 SoNode* sceneGraph;
01098 SbVec3f seekPoint, seekNormal, oldCamPosition, newCamPosition;
01099 SbRotation oldCamOrientation, newCamOrientation;
01100
01101 virtual SoGLContext* getViewerContext() { return getNormalSoContext(); }
01102 virtual SoSceneManager* getViewerSceneManager() { return getSceneManager(); }
01103
01104 private:
01105
01106 virtual void adjustCameraClippingPlanes();
01107
01108
01109 SbEventWrapperList* m_eventWrapperList;
01110
01111 void windowsKeyArrayConvert();
01112 SoKeyboardEvent::Key* m_windowsKeyArray;
01113
01114
01115 SoWinViewer( SoWidget parent,
01116 const char* name,
01117 SbBool buildInsideParent,
01118 SoWinViewer::Type type,
01119 SbBool buildNow,
01120 SbBool sync );
01121
01122 SoWinViewer( SoWidget parent,
01123 const char* name,
01124 SbBool buildInsideParent,
01125 SoWinViewer::Type type,
01126 SbBool buildNow,
01127 SbBool sync,
01128 SoGuiViewer* guiViewer );
01129
01130
01131 SbBool altSwitchBack;
01132
01133
01134
01135
01136
01137
01138 HCURSOR normalCursor,
01139 dollyCursor, panCursor, rollCursor, seekCursor,
01140 spinCursor, upCursor, flyCursor, walkCursor,
01141 pickCursor, manipCursor;
01142
01143
01144
01145
01146
01147 virtual void defineCursors();
01148
01149
01150
01151 virtual void updateCursor() {};
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162 SbBool processCommonEvents(XAnyEvent *xe);
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175 void interactiveCountInc();
01176 void interactiveCountDec();
01177 int getInteractiveCount() { return m_guiViewer->getInteractiveCount(); }
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189 SbBool seekToPoint(const SbVec2s &mouseLocation);
01190
01191
01192
01193
01194
01195
01196
01197
01198 virtual void interpolateSeekAnimation(float t);
01199 virtual void computeSeekFinalOrientation();
01200
01201
01202
01203
01204 virtual void actualRedraw();
01205
01206
01207
01208
01209 virtual void changeCameraValues( SoCamera* newCamera );
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223 static void setFeedbackOrthoProjection( const SbVec2s& glxSize );
01224
01225
01226 static void restoreGLStateAfterFeedback();
01227
01228 static void drawViewerCrossFeedback( SbVec2s loc );
01229
01230 static void drawViewerRollFeedback( SbVec2s center, SbVec2s loc );
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240 virtual void widgetChanged( SoWidget );
01241
01242
01243 virtual void afterRealizeHook();
01244
01245
01246
01247 virtual void redraw();
01248
01249
01250
01251
01252
01253
01254
01255 virtual float decimationForFramesPerSecond( float fps, double timeTaken, float decimation );
01256
01257
01258
01259
01260
01261
01262 virtual float decimationForNumTriangles(uint32_t numTris);
01263
01264 void setCurrentDrawStyle(SoWinViewer::DrawStyle style);
01265
01266 private:
01267
01268 void constructorCommon( SoWinViewer::Type t, SbBool buildNow );
01269 void constructorCommon2( SoWinViewer::Type t, SbBool buildNow );
01270
01271 SoGuiViewer* m_guiViewer;
01272
01273 SbBool m_firstRealize;
01274
01275
01276 SoWinClipboard* clipboard;
01277 static void pasteDoneCB( void* userData, SoPathList* pathList );
01278
01279
01280 SoFieldSensor* headlightSensor;
01281 static void headlightSensorCB( void* v, SoSensor* s );
01282
01283
01284 static void visibilityChangeCB( void* pt, SbBool visible );
01285
01286
01287 void setZbufferState();
01288 SbBool isZbufferOff();
01289 void arrowKeyPressed( KeySym key );
01290
01291
01292 SoAlarmSensor* stillSensor;
01293 static void alarmCB( void* thisp, SoSensor* s );
01294 void stillSensorCalled();
01295
01296
01297 static void seekAnimationSensorCB( void* p, SoSensor* sensor );
01298
01299
01315 static SbBool viewingEventCB( SoWinViewer* viewer, XAnyEvent* anyEvent );
01316
01317 private:
01318 void* getViewer() { return (void*)this; }
01319 };
01320
01321 inline void
01322 SoWinViewer::alarmCB( void* thisp, SoSensor* )
01323 {
01324 ((SoWinViewer*)thisp)->stillSensorCalled();
01325 }
01326
01327 #include <Inventor/Win/SoWinEndStrict.h>
01328
01329 #endif
01330
01331
01332
01333
01334