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
00346 SoCamera* getCamera() { return m_guiViewer->getCamera(); }
00347
00356 virtual void setCameraType(SoType type);
00357
00362 SoType getCameraType() { return m_guiViewer->getCameraType(); }
00363
00369 virtual void setPreserveCameraHeightAngle(SbBool flag)
00370 { m_guiViewer->setPreserveCameraHeightAngle( flag ); }
00371
00377 virtual SbBool isCameraHeightAnglePreserved() const
00378 { return m_guiViewer->isCameraHeightAnglePreserved(); }
00379
00384 virtual void enableSeekWithOrtho( SbBool flag ) { m_guiViewer->enableSeekWithOrtho( flag ); }
00385
00390 virtual SbBool isSeekWithOrthoEnabled() const { return m_guiViewer->isSeekWithOrthoEnabled(); }
00391
00410 virtual void viewAll();
00411
00415 virtual void saveHomePosition();
00416
00420 virtual void resetToHomePosition();
00421
00426 void setCameraTypeChangeCallback( SoWinViewerCameraTypeChangeCB* callback, void* userdata );
00427
00434 void setHeadlight( SbBool onOrOff );
00435
00439 SbBool isHeadlight() { return m_guiViewer->isHeadlight(); }
00440
00444 SoDirectionalLight* getHeadlight() { return m_guiViewer->getHeadlight(); }
00445
00494 void setDrawStyle( SoWinViewer::DrawType type, SoWinViewer::DrawStyle style );
00495
00499 SoWinViewer::DrawStyle getDrawStyle( SoWinViewer::DrawType type );
00500
00505 void setBufferingType( SoWinViewer::BufferType type );
00506
00510 SoWinViewer::BufferType getBufferingType()
00511 { return (SoWinViewer::BufferType)m_guiViewer->getBufferingType(); }
00512
00525 virtual void setViewing( SbBool onOrOff );
00526
00530 SbBool isViewing() const { return m_guiViewer->isViewing(); }
00531
00540 virtual void setSeekMode(SbBool onOrOff);
00541
00546 SbBool isSeekMode() { return m_guiViewer->isSeekMode(); }
00547
00559 virtual void setCursorEnabled( SbBool onOrOff );
00560
00566 SbBool isCursorEnabled() const { return m_guiViewer->isCursorEnabled(); }
00567
00577 void setAutoClipping( SbBool onOrOff );
00578
00582 SbBool isAutoClipping() const { return m_guiViewer->isAutoClipping(); }
00583
00609 virtual void setStereoViewing( SbBool onOrOff );
00610
00615 virtual SbBool isStereoViewing();
00616
00620 void setStereoOffset( float dist );
00621
00625 float getStereoOffset();
00626
00634 void setDetailSeek( SbBool onOrOff ) { m_guiViewer->setDetailSeek( onOrOff ); }
00635
00639 SbBool isDetailSeek() { return m_guiViewer->isDetailSeek(); }
00640
00653 void setSeekTime( float seconds ) { m_guiViewer->setSeekTime( seconds ); }
00654
00658 float getSeekTime() { return m_guiViewer->getSeekTime(); }
00659
00669 void addStartCallback( SoWinViewerCB* f, void* userData = NULL )
00670 { m_guiViewer->addStartCallback( (SoGuiViewerCB*)f, userData ); }
00671
00681 void addFinishCallback( SoWinViewerCB* f, void* userData = NULL )
00682 { m_guiViewer->addFinishCallback( (SoGuiViewerCB*)f, userData ); }
00683
00690 void removeStartCallback( SoWinViewerCB* f, void* userData = NULL )
00691 { m_guiViewer->removeStartCallback( (SoGuiViewerCB*)f, userData ); }
00692
00699 void removeFinishCallback( SoWinViewerCB *f, void* userData = NULL )
00700 { m_guiViewer->removeFinishCallback( (SoGuiViewerCB*)f, userData ); }
00701
00707 void copyView( Time eventTime );
00708
00714 void pasteView( Time eventTime );
00715
00716
00717
00718 virtual void setNormalVisual( XVisualInfo* i );
00719
00726 virtual void recomputeSceneSize();
00727
00728
00729
00735 void setDecimationStrategy( SoWinViewer::DecimationStrategy strategy );
00736
00740 SoWinViewer::DecimationStrategy getDecimationStrategy()
00741 { return (SoWinViewer::DecimationStrategy)m_guiViewer->getDecimationStrategy(); }
00742
00750 void setGoalNumberOfTriangles(int32_t goal);
00751
00755 int32_t getGoalNumberOfTriangles() { return m_guiViewer->getGoalNumberOfTriangles(); }
00756
00764 void setGoalFramesPerSecond( float goal );
00765
00769 float getGoalFramesPerSecond() { return m_guiViewer->getGoalFramesPerSecond(); }
00770
00778 void setFixedPercentage( float percent );
00779
00783 float getFixedPercentage() { return m_guiViewer->getFixedPercentage(); }
00784
00793 void enableFullRenderingWhenStill( SbBool onOff );
00794
00799 SbBool isFullRenderingWhenStill() { return m_guiViewer->isFullRenderingWhenStill(); }
00800
00804 SbBool isStillNow() { return m_guiViewer->isStillNow(); }
00805
00809 void setFramesPerSecondCallback( SoWinViewerFPSCB* callback, void* userData = NULL );
00810
00815 void setNumSamples( int numFrames );
00816
00821 int getNumSamples() { return m_guiViewer->getNumSamples(); }
00822
00826 void setDecimationPercentageCallback( SoWinViewerDecimationPercentageCB *callback,
00827 void* userData = NULL );
00828
00832 float getCurrentDecimationPercentage();
00833
00838 void enableMouseWheelDolly( SbBool onOff ) { m_guiViewer->enableMouseWheelDolly( onOff ); }
00839
00840
00850 void setPickRadius( float radius );
00851
00855 float getPickRadius() const;
00856
00857 public:
00858
00862 virtual SoCamera* getViewerCamera();
00863
00867 virtual SbBool isViewerDoubleBuffer();
00868
00875 virtual void actualRendering();
00876
00881 virtual const SbVec2s& getSize();
00882
00890 virtual const SbVec2s& getTopLeft() ;
00891
00899 virtual const SbVec2s& getBottomRight() ;
00900
00907 void setStereoViewType( SoBaseStereo* stereo );
00908
00912 SoBaseStereo* getStereoViewType();
00913
00917 void reverseStereoView( SbBool reverse );
00918
00922 SbBool isStereoViewReversed();
00923
00927 virtual void setStereoAbsoluteAdjustments( SbBool absolute );
00928
00932 virtual SbBool isStereoAbsoluteAdjustments() const { return m_guiViewer->isStereoAbsoluteAdjustments(); }
00933
00938 virtual void setStereoBalance( float balance, SbBool nearFrac = false );
00939
00943 virtual float getStereoBalance();
00944
00949 virtual SbBool isStereoBalanceNearFrac();
00950
00955 virtual void setStereoActive( SbBool activate ) ;
00956
00960 virtual SbBool isStereoActive() ;
00961
00965 void setViewport( short left, short bottom, short width, short height ) ;
00966
00970 void getViewport( short& left, short& bottom, short& width, short& height ) ;
00971
00986 virtual void setCursorStyle( SoWinViewer::CursorStyle style );
00987
00991 SoWinViewer::CursorStyle getCursorStyle()
00992 { return (SoWinViewer::CursorStyle)m_guiViewer->getCursorStyle(); }
00993
01003 void setAutoClipTolerance ( float tolerance ) { m_guiViewer->setAutoClipTolerance( tolerance ); }
01004
01008 float getAutoClipTolerance () const { return m_guiViewer->getAutoClipTolerance(); }
01009
01034 virtual void setCameraSceneGraph( SoNode* cameraSceneGraph );
01035
01039 SoNode* getCameraSceneGraph();
01040
01050 virtual void toggleCameraType();
01051
01052 #if 1 SoDEPRECATED
01059 virtual void adjustClippingPlanes();
01060
01061 #endif
01069 SbBool getDepthValue(int x, int y, float &depth)
01070 {
01071 return m_guiViewer->getDepthValue(x, y, depth);
01072 }
01073
01074 private:
01075
01076 virtual ~SoWinViewer();
01077
01082 float getAntoClipTolerance() const { return m_guiViewer->getAutoClipTolerance(); }
01083
01084 SoSeparator* getSceneRoot() { return m_guiViewer->getSceneRoot(); }
01085
01086 virtual SbBool isInteractive() const;
01087
01088 SoGuiViewer* getGuiViewer() const;
01089
01090
01091
01092 SoCamera* camera;
01093 SbBool createdCursors, viewingFlag;
01094 CursorStyle cursorStyle;
01095 SoSeparator* sceneRoot;
01096 float sceneSize;
01097 SoBaseStereo* stereoViewType;
01098 SbBool m_seekWithOrtho, m_preserveHeightAngle, cursorEnabledFlag, seekDistAsPercentage, computeSeekVariables;
01099 float m_previousHeightAngle, viewerSpeed, seekDistance;
01100 SoWinViewer::Type type;
01101 SoNode* sceneGraph;
01102 SbVec3f seekPoint, seekNormal, oldCamPosition, newCamPosition;
01103 SbRotation oldCamOrientation, newCamOrientation;
01104
01105 virtual SoGLContext* getViewerContext() { return getNormalSoContext(); }
01106 virtual SoSceneManager* getViewerSceneManager() { return getSceneManager(); }
01107
01108 private:
01109
01110 virtual void adjustCameraClippingPlanes();
01111
01112
01113 SbEventWrapperList* m_eventWrapperList;
01114
01115 void windowsKeyArrayConvert();
01116 SoKeyboardEvent::Key* m_windowsKeyArray;
01117
01118
01119 SoWinViewer( SoWidget parent,
01120 const char* name,
01121 SbBool buildInsideParent,
01122 SoWinViewer::Type type,
01123 SbBool buildNow,
01124 SbBool sync );
01125
01126 SoWinViewer( SoWidget parent,
01127 const char* name,
01128 SbBool buildInsideParent,
01129 SoWinViewer::Type type,
01130 SbBool buildNow,
01131 SbBool sync,
01132 SoGuiViewer* guiViewer );
01133
01134
01135 SbBool altSwitchBack;
01136
01137
01138
01139
01140
01141
01142 HCURSOR normalCursor,
01143 dollyCursor, panCursor, rollCursor, seekCursor,
01144 spinCursor, upCursor, flyCursor, walkCursor,
01145 pickCursor, manipCursor;
01146
01147
01148
01149
01150
01151 virtual void defineCursors();
01152
01153
01154
01155 virtual void updateCursor() {};
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166 SbBool processCommonEvents(XAnyEvent *xe);
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179 void interactiveCountInc();
01180 void interactiveCountDec();
01181 int getInteractiveCount() { return m_guiViewer->getInteractiveCount(); }
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193 SbBool seekToPoint(const SbVec2s &mouseLocation);
01194
01195
01196
01197
01198
01199
01200
01201
01202 virtual void interpolateSeekAnimation(float t);
01203 virtual void computeSeekFinalOrientation();
01204
01205
01206
01207
01208 virtual void actualRedraw();
01209
01210
01211
01212
01213 virtual void changeCameraValues( SoCamera* newCamera );
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227 static void setFeedbackOrthoProjection( const SbVec2s& glxSize );
01228
01229
01230 static void restoreGLStateAfterFeedback();
01231
01232 static void drawViewerCrossFeedback( SbVec2s loc );
01233
01234 static void drawViewerRollFeedback( SbVec2s center, SbVec2s loc );
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244 virtual void widgetChanged( SoWidget );
01245
01246
01247 virtual void afterRealizeHook();
01248
01249
01250
01251 virtual void redraw();
01252
01253
01254
01255
01256
01257
01258
01259 virtual float decimationForFramesPerSecond( float fps, double timeTaken, float decimation );
01260
01261
01262
01263
01264
01265
01266 virtual float decimationForNumTriangles(uint32_t numTris);
01267
01268 void setCurrentDrawStyle(SoWinViewer::DrawStyle style);
01269
01270 private:
01271
01272 void constructorCommon( SoWinViewer::Type t, SbBool buildNow );
01273 void constructorCommon2( SoWinViewer::Type t, SbBool buildNow );
01274
01275 SoGuiViewer* m_guiViewer;
01276
01277 SbBool m_firstRealize;
01278
01279
01280 SoWinClipboard* clipboard;
01281 static void pasteDoneCB( void* userData, SoPathList* pathList );
01282
01283
01284 SoFieldSensor* headlightSensor;
01285 static void headlightSensorCB( void* v, SoSensor* s );
01286
01287
01288 static void visibilityChangeCB( void* pt, SbBool visible );
01289
01290
01291 void setZbufferState();
01292 SbBool isZbufferOff();
01293 void arrowKeyPressed( KeySym key );
01294
01295
01296 SoAlarmSensor* stillSensor;
01297 static void alarmCB( void* thisp, SoSensor* s );
01298 void stillSensorCalled();
01299
01300
01301 static void seekAnimationSensorCB( void* p, SoSensor* sensor );
01302
01303
01319 static SbBool viewingEventCB( SoWinViewer* viewer, XAnyEvent* anyEvent );
01320
01321 private:
01322 void* getViewer() { return (void*)this; }
01323 };
01324
01325 inline void
01326 SoWinViewer::alarmCB( void* thisp, SoSensor* )
01327 {
01328 ((SoWinViewer*)thisp)->stillSensorCalled();
01329 }
01330
01331 #include <Inventor/Win/SoWinEndStrict.h>
01332
01333 #endif
01334
01335
01336
01337
01338