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_QT_VIEWER_
00026 #define _SO_QT_VIEWER_
00027
00028 #include <Inventor/Qt/OivQtCompat.h>
00029 #include <Inventor/Qt/SoQtRenderArea.h>
00030
00031 #include <QPixmap>
00032
00033 #include <Inventor/SoType.h>
00034 #include <Inventor/misc/SoCallbackList.h>
00035 #include <Inventor/SbElapsedTime.h>
00036 #include <Inventor/events/SoKeyboardEvent.h>
00037 #include <Inventor/Gui/viewers/SoGuiViewer.h>
00038
00039 #include <Inventor/components/stereo/SoStereoViewer.h>
00040
00041
00042 class SoNode;
00043 class SoDirectionalLight;
00044 class SoGroup;
00045 class SoRotation;
00046 class SoCamera;
00047 class SoDrawStyle;
00048 class SoLightModel;
00049 class SoFieldSensor;
00050
00051 class SoQtViewer;
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 SoQtInputFocus;
00061 class SoAlarmSensor;
00062 class SoNodeSensor;
00063 class SoGetPrimitiveCountAction;
00064 class SoStereoViewer;
00065 class SoBaseStereo;
00066 class ScRayPickAction;
00067
00071 typedef void SoQtViewerCB( void* userData, SoQtViewer* viewer );
00072
00076 typedef void SoQtViewerCameraTypeChangeCB( void* userData, SoCamera* camera, SoQtViewer* viewer );
00077
00081 typedef void SoQtViewerFPSCB( float fps, void* userData, SoQtViewer* viewer );
00082
00086 typedef void SoQtViewerDecimationPercentageCB( float percentage, void* userData, SoQtViewer* viewer );
00087
00089
00090
00091
00092
00093
00094
00095
00097
00168 class SoQtViewer : public SoQtRenderArea, public SoStereoViewer
00169 {
00170
00171 Q_OBJECT
00172
00173 public:
00174
00185 enum Type
00186 {
00190 BROWSER,
00194 EDITOR
00195 };
00196
00197
00203 enum DrawStyle
00204 {
00208 VIEW_AS_IS,
00212 VIEW_HIDDEN_LINE,
00216 VIEW_NO_TEXTURE,
00220 VIEW_LOW_COMPLEXITY,
00224 VIEW_LINE,
00228 VIEW_POINT,
00232 VIEW_BBOX,
00236 VIEW_LOW_RES_LINE,
00240 VIEW_LOW_RES_POINT,
00244 VIEW_SAME_AS_STILL
00245 };
00246
00248 enum DrawType
00249 {
00253 STILL,
00257 INTERACTIVE
00258 };
00259
00261 enum BufferType
00262 {
00266 BUFFER_SINGLE,
00270 BUFFER_DOUBLE,
00274 BUFFER_INTERACTIVE
00275 };
00276
00278 enum DecimationStrategy
00279 {
00283 NORMAL,
00287 FIXED_NUM_TRIANGLES,
00291 FRAMES_PER_SECOND,
00295 FIXED_PERCENTAGE
00296 };
00297
00302 enum CursorStyle
00303 {
00307 CLASSIC,
00311 XOR,
00315 SHADOW
00316 };
00317
00326 virtual void setSceneGraph( SoNode* newScene );
00327
00331 virtual SoNode* getSceneGraph();
00332
00333 #ifndef HIDDEN_FROM_DOC
00334 void saveSceneGraph( const char* fileName ) ;
00335 #endif //HIDDEN_FROM_DOC
00336
00342 virtual void setCamera( SoCamera* cam );
00343
00347 SoCamera* getCamera() { return m_guiViewer->getCamera(); }
00348
00357 virtual void setCameraType( SoType type );
00358
00363 SoType getCameraType() { return m_guiViewer->getCameraType(); }
00364
00370 virtual void setPreserveCameraHeightAngle( SbBool flag )
00371 { m_guiViewer->setPreserveCameraHeightAngle( flag ); }
00372
00378 virtual SbBool isCameraHeightAnglePreserved() const { 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( SoQtViewerCameraTypeChangeCB* callback,
00427 void* userdata );
00428
00435 virtual void setHeadlight( SbBool onOrOff );
00436
00440 SbBool isHeadlight() { return m_guiViewer->isHeadlight(); }
00441
00445 SoDirectionalLight* getHeadlight() { return m_guiViewer->getHeadlight(); }
00446
00495 virtual void setDrawStyle( SoQtViewer::DrawType type,
00496 SoQtViewer::DrawStyle style );
00500 SoQtViewer::DrawStyle getDrawStyle( SoQtViewer::DrawType type );
00501
00506 virtual void setBufferingType( SoQtViewer::BufferType type );
00507
00511 SoQtViewer::BufferType getBufferingType()
00512 { return (SoQtViewer::BufferType)m_guiViewer->getBufferingType(); }
00513
00526 virtual void setViewing( SbBool onOrOff );
00527
00531 SbBool isViewing() const { return m_guiViewer->isViewing(); }
00532
00543 virtual void setCursorEnabled( SbBool onOrOff );
00544
00549 SbBool isCursorEnabled() const { return m_guiViewer->isCursorEnabled(); }
00550
00561 void setAutoClipping( SbBool onOrOff );
00562
00566 SbBool isAutoClipping() const { return m_guiViewer->isAutoClipping(); }
00567
00575 virtual void setStereoViewing( SbBool onOrOff );
00576
00581 virtual SbBool isStereoViewing();
00582
00586 void setStereoOffset( float dist );
00587
00591 float getStereoOffset();
00592
00600 void setDetailSeek( SbBool onOrOff ) { m_guiViewer->setDetailSeek( onOrOff ); }
00601
00605 SbBool isDetailSeek() { return m_guiViewer->isDetailSeek(); }
00606
00619 void setSeekTime( float seconds ) { m_guiViewer->setSeekTime( seconds ); }
00620
00624 float getSeekTime() { return m_guiViewer->getSeekTime(); }
00625
00634 void addStartCallback( SoQtViewerCB* f, void* userData = NULL )
00635 { m_guiViewer->addStartCallback( (SoGuiViewerCB*)f, userData ); }
00636
00645 void addFinishCallback( SoQtViewerCB* f, void* userData = NULL )
00646 { m_guiViewer->addFinishCallback( (SoGuiViewerCB*)f, userData ); }
00647
00653 void removeStartCallback( SoQtViewerCB* f, void* userData = NULL )
00654 { m_guiViewer->removeStartCallback( (SoGuiViewerCB*)f, userData ); }
00655
00661 void removeFinishCallback( SoQtViewerCB* f, void* userData = NULL )
00662 { m_guiViewer->removeFinishCallback( (SoGuiViewerCB*)f, userData ); }
00663
00670 virtual void recomputeSceneSize();
00671
00672
00673
00679 void setDecimationStrategy( SoQtViewer::DecimationStrategy strategy );
00680
00684 SoQtViewer::DecimationStrategy getDecimationStrategy()
00685 { return (SoQtViewer::DecimationStrategy)m_guiViewer->getDecimationStrategy(); }
00686
00694 void setGoalNumberOfTriangles( int32_t goal );
00695
00699 int32_t getGoalNumberOfTriangles() { return m_guiViewer->getGoalNumberOfTriangles(); }
00700
00708 void setGoalFramesPerSecond( float goal );
00709
00713 float getGoalFramesPerSecond() { return m_guiViewer->getGoalFramesPerSecond(); }
00714
00722 void setFixedPercentage( float percent );
00723
00727 float getFixedPercentage() { return m_guiViewer->getFixedPercentage(); }
00728
00737 void enableFullRenderingWhenStill( SbBool onOff );
00738
00743 SbBool isFullRenderingWhenStill() { return m_guiViewer->isFullRenderingWhenStill(); }
00744
00748 SbBool isStillNow() { return m_guiViewer->isStillNow(); }
00749
00753 void setFramesPerSecondCallback( SoQtViewerFPSCB* callback, void* userData = NULL );
00754
00759 void setNumSamples( int numFrames );
00764 int getNumSamples() { return m_guiViewer->getNumSamples(); }
00765
00769 void setDecimationPercentageCallback( SoQtViewerDecimationPercentageCB *callback, void* userData = NULL );
00770
00774 float getCurrentDecimationPercentage();
00775
00776
00777
00781 virtual SoCamera* getViewerCamera();
00782
00786 virtual SbBool isViewerDoubleBuffer();
00787
00794 virtual void actualRendering();
00795
00800 virtual const SbVec2s& getSize();
00801
00809 virtual const SbVec2s& getTopLeft() ;
00810
00818 virtual const SbVec2s& getBottomRight() ;
00819
00826 void setStereoViewType( SoBaseStereo* stereo );
00827
00831 SoBaseStereo* getStereoViewType();
00832
00836 void reverseStereoView( SbBool reverse );
00837
00841 SbBool isStereoViewReversed();
00842
00846 virtual void setStereoAbsoluteAdjustments( SbBool absolute );
00847
00851 virtual SbBool isStereoAbsoluteAdjustments() const { return m_guiViewer->isStereoAbsoluteAdjustments(); }
00852
00857 virtual void setStereoBalance( float balance, SbBool nearFrac = false );
00858
00862 virtual float getStereoBalance();
00863
00868 virtual SbBool isStereoBalanceNearFrac();
00869
00874 virtual void setStereoActive( SbBool activate ) ;
00875
00879 virtual SbBool isStereoActive() ;
00880
00884 void setViewport( short left, short bottom, short width, short height );
00885
00889 void getViewport( short& left, short& bottom, short& width, short& height );
00890
00894 SoSeparator* getSceneRoot() { return m_guiViewer->getSceneRoot(); }
00895
00910 virtual void setCursorStyle( SoQtViewer::CursorStyle style );
00911
00915 SoQtViewer::CursorStyle getCursorStyle()
00916 { return (SoQtViewer::CursorStyle)m_guiViewer->getCursorStyle(); }
00917
00927 void setAutoClipTolerance ( float tolerance ) { m_guiViewer->setAutoClipTolerance( tolerance ); }
00928
00932 float getAutoClipTolerance () const { return m_guiViewer->getAutoClipTolerance(); }
00933
00958 virtual void setCameraSceneGraph(SoNode *cameraSceneGraph);
00959
00963 SoNode* getCameraSceneGraph();
00964
00969 void enableMouseWheelDolly(SbBool onOff) { m_guiViewer->enableMouseWheelDolly( onOff ); }
00970
00979 virtual void setSeekMode( SbBool onOrOff );
00980
00984 SbBool isSeekMode() { return m_guiViewer->isSeekMode(); }
00985
00995 virtual void toggleCameraType();
00996
01006 void setPickRadius( float radius );
01007
01011 float getPickRadius() const;
01012
01013 #if 1 SoDEPRECATED
01020 virtual void adjustClippingPlanes();
01021
01022 #endif
01029 SbBool getDepthValue(int x, int y, float &depth)
01030 {
01031 return m_guiViewer->getDepthValue(x, y, depth);
01032 }
01033
01034 private:
01035
01036 SoGuiViewer* getGuiViewer() const;
01037
01038 virtual ~SoQtViewer();
01039
01040
01041
01042 virtual void setNormalVisual( QSurfaceFormat vi );
01043
01044 SbBool isInteractive() const;
01045
01046 void saveSceneGraph( const SbString& fileName );
01047
01048
01049
01050 SoCamera* camera;
01051 SbBool createdCursors, viewingFlag;
01052 CursorStyle cursorStyle;
01053 SoSeparator* sceneRoot;
01054 float sceneSize;
01055 SoBaseStereo* stereoViewType;
01056 SbBool m_seekWithOrtho, m_preserveHeightAngle, cursorEnabledFlag, seekDistAsPercentage, computeSeekVariables;
01057 float m_previousHeightAngle, viewerSpeed, seekDistance;
01058 SoQtViewer::Type type;
01059 SoNode* sceneGraph;
01060 SbVec3f seekPoint, seekNormal, oldCamPosition, newCamPosition;
01061 SbRotation oldCamOrientation, newCamOrientation;
01062
01063 void setCurrentDrawStyle(SoQtViewer::DrawStyle style);
01064
01068 virtual void defineDefaultCursor( const QCursor& cursor );
01069
01073 virtual void defineFlyCursor( const QCursor& cursor );
01074
01078 virtual void defineRotationCursor( const QCursor& cursor );
01079
01083 virtual void defineSeekCursor( const QCursor& cursor );
01084
01088 virtual void defineTranslationCursor( const QCursor& cursor );
01089
01093 virtual void defineUpCursor( const QCursor& cursor );
01094
01098 virtual void defineViewingCursor( const QCursor& cursor );
01099
01103 virtual void defineWalkCursor( const QCursor& cursor );
01104
01108 virtual void defineZoomCursor( const QCursor& cursor );
01109
01110 virtual SoGLContext* getViewerContext() { return getNormalSoContext(); }
01111 virtual SoSceneManager* getViewerSceneManager() { return getSceneManager(); }
01112
01113 private:
01114
01115
01116 SoQtViewer( QWidget* parent,
01117 const char* name,
01118 SbBool buildInsideParent,
01119 SoQtViewer::Type type,
01120 SbBool buildNow,
01121 SbBool sync = true );
01122
01123 SoQtViewer( QWidget* parent,
01124 const char* name,
01125 SbBool buildInsideParent,
01126 SoQtViewer::Type type,
01127 SbBool buildNow,
01128 SbBool sync,
01129 SoGuiViewer* guiViewer );
01130
01131
01132 SbBool altSwitchBack;
01133
01134
01135
01136
01137
01138
01139 QCursor normalCursor, dollyCursor, panCursor, rollCursor, seekCursor,
01140 spinCursor, upCursor, flyCursor, walkCursor;
01141
01142
01143
01144
01145
01146 virtual void defineCursors();
01147
01148
01149
01150 virtual void updateCursor() {};
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161 SbBool processCommonEvents( QEvent* xe );
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174 void interactiveCountInc();
01175 void interactiveCountDec();
01176 int getInteractiveCount() { return m_guiViewer->getInteractiveCount(); }
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188 SbBool seekToPoint( const SbVec2s &mouseLocation );
01189
01190
01191
01192
01193
01194
01195
01196
01197 virtual void interpolateSeekAnimation( float t );
01198 virtual void computeSeekFinalOrientation();
01199
01200
01201
01202
01203 virtual void actualRedraw();
01204
01205
01206
01207
01208 virtual void changeCameraValues( SoCamera* newCamera );
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223 static void setFeedbackOrthoProjection( const SbVec2s& glxSize );
01224
01225
01226
01227 static void restoreGLStateAfterFeedback();
01228
01229
01230 static void drawViewerCrossFeedback( SbVec2s loc );
01231
01232
01233 static void drawViewerRollFeedback( SbVec2s center, SbVec2s loc );
01234
01235 virtual void widgetChanged( QWidget* w );
01236
01237
01238 virtual void afterRealizeHook();
01239
01240
01241 virtual void adjustCameraClippingPlanes();
01242
01243
01244
01245 virtual void redraw();
01246
01247
01248
01249
01250
01251
01252
01253 virtual float decimationForFramesPerSecond( float fps,
01254 double timeTaken,
01255 float decimation );
01256
01257
01258
01259
01260
01261
01262 virtual float decimationForNumTriangles( uint32_t numTris );
01263
01264
01265 void* getViewer() {return (void*)this;}
01266
01267 protected Q_SLOTS:
01271 void processCommonEnterEvents( unsigned int state );
01272
01273 private:
01274
01275 #if !defined(_WIN32) && !defined(__APPLE__)
01276 unsigned int m_zoomBoxPixel;
01277 #endif // UNIX
01278
01279 void constructorCommon( SoQtViewer::Type t, SbBool buildNow );
01280 void constructorCommon2( SoQtViewer::Type t, SbBool buildNow );
01281
01282 SoGuiViewer* m_guiViewer;
01283
01284
01285 SoQtInputFocus* inputFocus;
01286 SbBool m_firstRealize;
01287
01288
01289 void setZbufferState();
01290 SbBool isZbufferOff();
01291 void arrowKeyPressed( int rawKey );
01292
01293
01294 static SoGLRenderAction::AbortCode renderAbortCB( void* data );
01295 SoAlarmSensor* stillSensor;
01296 static void alarmCB( void* thisp, SoSensor* ) { ((SoQtViewer*)thisp)->stillSensorCalled(); }
01297 void stillSensorCalled();
01298
01299
01315 static SbBool viewingEventCB( SoQtViewer* viewer, QEvent* anyEvent );
01316
01317
01318 static void seekAnimationSensorCB( void* p, SoSensor* sensor );
01319
01320 SoNode* m_cameraSceneGraph;
01321
01322
01323 SbVec2s m_size;
01324 };
01325
01326 #endif
01327
01328
01329