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
00169 class SoQtViewer : public SoQtRenderArea, public SoStereoViewer
00170 {
00171
00172 Q_OBJECT
00173
00174 public:
00175
00186 enum Type
00187 {
00191 BROWSER,
00195 EDITOR
00196 };
00197
00198
00204 enum DrawStyle
00205 {
00209 VIEW_AS_IS,
00213 VIEW_HIDDEN_LINE,
00217 VIEW_NO_TEXTURE,
00221 VIEW_LOW_COMPLEXITY,
00225 VIEW_LINE,
00229 VIEW_POINT,
00233 VIEW_BBOX,
00237 VIEW_LOW_RES_LINE,
00241 VIEW_LOW_RES_POINT,
00245 VIEW_SAME_AS_STILL
00246 };
00247
00249 enum DrawType
00250 {
00254 STILL,
00258 INTERACTIVE
00259 };
00260
00262 enum BufferType
00263 {
00267 BUFFER_SINGLE,
00271 BUFFER_DOUBLE,
00275 BUFFER_INTERACTIVE
00276 };
00277
00279 enum DecimationStrategy
00280 {
00284 NORMAL,
00288 FIXED_NUM_TRIANGLES,
00292 FRAMES_PER_SECOND,
00296 FIXED_PERCENTAGE
00297 };
00298
00303 enum CursorStyle
00304 {
00308 CLASSIC,
00312 XOR,
00316 SHADOW
00317 };
00318
00327 virtual void setSceneGraph( SoNode* newScene );
00328
00332 virtual SoNode* getSceneGraph();
00333
00334 #ifndef HIDDEN_FROM_DOC
00335 void saveSceneGraph( const char* fileName ) ;
00336 #endif //HIDDEN_FROM_DOC
00337
00343 virtual void setCamera( SoCamera* cam );
00344
00348 SoCamera* getCamera() { return m_guiViewer->getCamera(); }
00349
00358 virtual void setCameraType( SoType type );
00359
00364 SoType getCameraType() { return m_guiViewer->getCameraType(); }
00365
00371 virtual void setPreserveCameraHeightAngle( SbBool flag )
00372 { m_guiViewer->setPreserveCameraHeightAngle( flag ); }
00373
00379 virtual SbBool isCameraHeightAnglePreserved() const { return m_guiViewer->isCameraHeightAnglePreserved(); }
00380
00385 virtual void enableSeekWithOrtho( SbBool flag ) { m_guiViewer->enableSeekWithOrtho( flag ); }
00386
00391 virtual SbBool isSeekWithOrthoEnabled() const { return m_guiViewer->isSeekWithOrthoEnabled(); }
00392
00411 virtual void viewAll();
00412
00416 virtual void saveHomePosition();
00417
00421 virtual void resetToHomePosition();
00422
00427 void setCameraTypeChangeCallback( SoQtViewerCameraTypeChangeCB* callback,
00428 void* userdata );
00429
00436 virtual void setHeadlight( SbBool onOrOff );
00437
00441 SbBool isHeadlight() { return m_guiViewer->isHeadlight(); }
00442
00446 SoDirectionalLight* getHeadlight() { return m_guiViewer->getHeadlight(); }
00447
00496 virtual void setDrawStyle( SoQtViewer::DrawType type,
00497 SoQtViewer::DrawStyle style );
00501 SoQtViewer::DrawStyle getDrawStyle( SoQtViewer::DrawType type );
00502
00507 virtual void setBufferingType( SoQtViewer::BufferType type );
00508
00512 SoQtViewer::BufferType getBufferingType()
00513 { return (SoQtViewer::BufferType)m_guiViewer->getBufferingType(); }
00514
00527 virtual void setViewing( SbBool onOrOff );
00528
00532 SbBool isViewing() const { return m_guiViewer->isViewing(); }
00533
00538 virtual void enableDirectViz( SbBool onOrOff );
00539
00543 virtual void showDirectVizDialog( SbBool show );
00544
00548 SbBool isDirectVizEnabled() const { return m_guiViewer->getDirectVizFlag(); }
00549
00560 virtual void setCursorEnabled( SbBool onOrOff );
00561
00566 SbBool isCursorEnabled() const { return m_guiViewer->isCursorEnabled(); }
00567
00578 void setAutoClipping( SbBool onOrOff );
00579
00583 SbBool isAutoClipping() const { return m_guiViewer->isAutoClipping(); }
00584
00592 virtual void setStereoViewing( SbBool onOrOff );
00593
00598 virtual SbBool isStereoViewing();
00599
00603 void setStereoOffset( float dist );
00604
00608 float getStereoOffset();
00609
00617 void setDetailSeek( SbBool onOrOff ) { m_guiViewer->setDetailSeek( onOrOff ); }
00618
00622 SbBool isDetailSeek() { return m_guiViewer->isDetailSeek(); }
00623
00636 void setSeekTime( float seconds ) { m_guiViewer->setSeekTime( seconds ); }
00637
00641 float getSeekTime() { return m_guiViewer->getSeekTime(); }
00642
00651 void addStartCallback( SoQtViewerCB* f, void* userData = NULL )
00652 { m_guiViewer->addStartCallback( (SoGuiViewerCB*)f, userData ); }
00653
00662 void addFinishCallback( SoQtViewerCB* f, void* userData = NULL )
00663 { m_guiViewer->addFinishCallback( (SoGuiViewerCB*)f, userData ); }
00664
00670 void removeStartCallback( SoQtViewerCB* f, void* userData = NULL )
00671 { m_guiViewer->removeStartCallback( (SoGuiViewerCB*)f, userData ); }
00672
00678 void removeFinishCallback( SoQtViewerCB* f, void* userData = NULL )
00679 { m_guiViewer->removeFinishCallback( (SoGuiViewerCB*)f, userData ); }
00680
00687 virtual void recomputeSceneSize();
00688
00689
00690
00699 void setDecimationStrategy( SoQtViewer::DecimationStrategy strategy );
00700
00704 SoQtViewer::DecimationStrategy getDecimationStrategy()
00705 { return (SoQtViewer::DecimationStrategy)m_guiViewer->getDecimationStrategy(); }
00706
00714 void setGoalNumberOfTriangles( int32_t goal );
00715
00719 int32_t getGoalNumberOfTriangles() { return m_guiViewer->getGoalNumberOfTriangles(); }
00720
00728 void setGoalFramesPerSecond( float goal );
00729
00733 float getGoalFramesPerSecond() { return m_guiViewer->getGoalFramesPerSecond(); }
00734
00742 void setFixedPercentage( float percent );
00743
00747 float getFixedPercentage() { return m_guiViewer->getFixedPercentage(); }
00748
00757 void enableFullRenderingWhenStill( SbBool onOff );
00758
00763 SbBool isFullRenderingWhenStill() { return m_guiViewer->isFullRenderingWhenStill(); }
00764
00768 SbBool isStillNow() { return m_guiViewer->isStillNow(); }
00769
00773 void setFramesPerSecondCallback( SoQtViewerFPSCB* callback, void* userData = NULL );
00774
00779 void setNumSamples( int numFrames );
00784 int getNumSamples() { return m_guiViewer->getNumSamples(); }
00785
00789 void setDecimationPercentageCallback( SoQtViewerDecimationPercentageCB *callback, void* userData = NULL );
00790
00794 float getCurrentDecimationPercentage();
00795
00796
00797
00801 virtual SoCamera* getViewerCamera();
00802
00806 virtual SbBool isViewerDoubleBuffer();
00807
00814 virtual void actualRendering();
00815
00820 virtual const SbVec2s& getSize();
00821
00829 virtual const SbVec2s& getTopLeft() ;
00830
00838 virtual const SbVec2s& getBottomRight() ;
00839
00846 void setStereoViewType( SoBaseStereo* stereo );
00847
00851 SoBaseStereo* getStereoViewType();
00852
00856 void reverseStereoView( SbBool reverse );
00857
00861 SbBool isStereoViewReversed();
00862
00866 virtual void setStereoAbsoluteAdjustments( SbBool absolute );
00867
00871 virtual SbBool isStereoAbsoluteAdjustments() const { return m_guiViewer->isStereoAbsoluteAdjustments(); }
00872
00877 virtual void setStereoBalance( float balance, SbBool nearFrac = false );
00878
00882 virtual float getStereoBalance();
00883
00888 virtual SbBool isStereoBalanceNearFrac();
00889
00894 virtual void setStereoActive( SbBool activate ) ;
00895
00899 virtual SbBool isStereoActive() ;
00900
00904 void setViewport( short left, short bottom, short width, short height );
00905
00909 void getViewport( short& left, short& bottom, short& width, short& height );
00910
00914 SoSeparator* getSceneRoot() { return m_guiViewer->getSceneRoot(); }
00915
00930 virtual void setCursorStyle( SoQtViewer::CursorStyle style );
00931
00935 SoQtViewer::CursorStyle getCursorStyle()
00936 { return (SoQtViewer::CursorStyle)m_guiViewer->getCursorStyle(); }
00937
00947 void setAutoClipTolerance ( float tolerance ) { m_guiViewer->setAutoClipTolerance( tolerance ); }
00948
00952 float getAutoClipTolerance () const { return m_guiViewer->getAutoClipTolerance(); }
00953
00978 virtual void setCameraSceneGraph(SoNode *cameraSceneGraph);
00979
00983 SoNode* getCameraSceneGraph();
00984
00989 void enableMouseWheelDolly(SbBool onOff) { m_guiViewer->enableMouseWheelDolly( onOff ); }
00990
00999 virtual void setSeekMode( SbBool onOrOff );
01000
01004 SbBool isSeekMode() { return m_guiViewer->isSeekMode(); }
01005
01015 virtual void toggleCameraType();
01016
01026 void setPickRadius( float radius );
01027
01031 float getPickRadius() const;
01032
01033 #if 1 SoDEPRECATED
01040 virtual void adjustClippingPlanes();
01041
01042 #endif
01049 SbBool getDepthValue(int x, int y, float &depth)
01050 {
01051 return m_guiViewer->getDepthValue(x, y, depth);
01052 }
01053
01054 #if 1 SoDEPRECATED
01059 HDC getCurrentDC() { return NULL; }
01060
01061 #endif
01063 private:
01064
01065 SoGuiViewer* getGuiViewer() const;
01066
01067 virtual ~SoQtViewer();
01068
01069
01070 virtual void setDoubleBuffer( SbBool onOrOff );
01071
01072
01073
01074 virtual void setNormalVisual( QSurfaceFormat vi );
01075
01076 SbBool isInteractive() const;
01077
01078 void saveSceneGraph( const SbString& fileName );
01079
01080
01081
01082 SoCamera* camera;
01083 SbBool createdCursors, viewingFlag;
01084 CursorStyle cursorStyle;
01085 SoSeparator* sceneRoot;
01086 float sceneSize;
01087 SoBaseStereo* stereoViewType;
01088 SbBool m_seekWithOrtho, m_preserveHeightAngle, cursorEnabledFlag, seekDistAsPercentage, computeSeekVariables;
01089 float m_previousHeightAngle, viewerSpeed, seekDistance;
01090 SoQtViewer::Type type;
01091 SoNode* sceneGraph;
01092 SbVec3f seekPoint, seekNormal, oldCamPosition, newCamPosition;
01093 SbRotation oldCamOrientation, newCamOrientation;
01094
01095 void setCurrentDrawStyle(SoQtViewer::DrawStyle style);
01096
01100 virtual void defineDefaultCursor( const QCursor& cursor );
01101
01105 virtual void defineFlyCursor( const QCursor& cursor );
01106
01110 virtual void defineRotationCursor( const QCursor& cursor );
01111
01115 virtual void defineSeekCursor( const QCursor& cursor );
01116
01120 virtual void defineTranslationCursor( const QCursor& cursor );
01121
01125 virtual void defineUpCursor( const QCursor& cursor );
01126
01130 virtual void defineViewingCursor( const QCursor& cursor );
01131
01135 virtual void defineWalkCursor( const QCursor& cursor );
01136
01140 virtual void defineZoomCursor( const QCursor& cursor );
01141
01142 virtual SoGLContext* getViewerContext() { return getNormalSoContext(); }
01143 virtual SoSceneManager* getViewerSceneManager() { return getSceneManager(); }
01144
01145 #if 1 SoDEPRECATED
01148 virtual void setNormalVisual( SbGlContextHelper::VisualInfo vi );
01149
01150 #endif
01152 private:
01153
01154
01155 SoQtViewer( QWidget* parent,
01156 const char* name,
01157 SbBool buildInsideParent,
01158 SoQtViewer::Type type,
01159 SbBool buildNow,
01160 SbBool sync = true );
01161
01162 SoQtViewer( QWidget* parent,
01163 const char* name,
01164 SbBool buildInsideParent,
01165 SoQtViewer::Type type,
01166 SbBool buildNow,
01167 SbBool sync,
01168 SoGuiViewer* guiViewer );
01169
01170
01171 SbBool altSwitchBack;
01172
01173
01174
01175
01176
01177
01178 QCursor normalCursor, dollyCursor, panCursor, rollCursor, seekCursor,
01179 spinCursor, upCursor, flyCursor, walkCursor;
01180
01181
01182
01183
01184
01185 virtual void defineCursors();
01186
01187
01188
01189 virtual void updateCursor() {};
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200 SbBool processCommonEvents( QEvent* xe );
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213 void interactiveCountInc();
01214 void interactiveCountDec();
01215 int getInteractiveCount() { return m_guiViewer->getInteractiveCount(); }
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227 SbBool seekToPoint( const SbVec2s &mouseLocation );
01228
01229
01230
01231
01232
01233
01234
01235
01236 virtual void interpolateSeekAnimation( float t );
01237 virtual void computeSeekFinalOrientation();
01238
01239
01240
01241
01242 virtual void actualRedraw();
01243
01244
01245
01246
01247 virtual void changeCameraValues( SoCamera* newCamera );
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262 static void setFeedbackOrthoProjection( const SbVec2s& glxSize );
01263
01264
01265
01266 static void restoreGLStateAfterFeedback();
01267
01268
01269 static void drawViewerCrossFeedback( SbVec2s loc );
01270
01271
01272 static void drawViewerRollFeedback( SbVec2s center, SbVec2s loc );
01273
01274 virtual void widgetChanged( QWidget* w );
01275
01276
01277 virtual void afterRealizeHook();
01278
01279
01280 virtual void adjustCameraClippingPlanes();
01281
01282
01283
01284 virtual void redraw();
01285
01286
01287
01288
01289
01290
01291
01292 virtual float decimationForFramesPerSecond( float fps,
01293 double timeTaken,
01294 float decimation );
01295
01296
01297
01298
01299
01300
01301 virtual float decimationForNumTriangles( uint32_t numTris );
01302
01303
01304 void* getViewer() {return (void*)this;}
01305
01306 protected Q_SLOTS:
01310 void processCommonEnterEvents( unsigned int state );
01311
01312 private:
01313
01314 #if !defined(_WIN32) && !defined(__APPLE__)
01315 unsigned int m_zoomBoxPixel;
01316 #endif // UNIX
01317
01318 void constructorCommon( SoQtViewer::Type t, SbBool buildNow );
01319 void constructorCommon2( SoQtViewer::Type t, SbBool buildNow );
01320
01321 SoGuiViewer* m_guiViewer;
01322
01323
01324 SoQtInputFocus* inputFocus;
01325 SbBool m_firstRealize;
01326
01327
01328 void setZbufferState();
01329 SbBool isZbufferOff();
01330 void arrowKeyPressed( int rawKey );
01331
01332
01333 static SoGLRenderAction::AbortCode renderAbortCB( void* data );
01334 SoAlarmSensor* stillSensor;
01335 static void alarmCB( void* thisp, SoSensor* ) { ((SoQtViewer*)thisp)->stillSensorCalled(); }
01336 void stillSensorCalled();
01337
01338
01354 static SbBool viewingEventCB( SoQtViewer* viewer, QEvent* anyEvent );
01355
01356
01357 static void seekAnimationSensorCB( void* p, SoSensor* sensor );
01358
01359 SoNode* m_cameraSceneGraph;
01360
01361
01362 SbVec2s m_size;
01363 };
01364
01365 #endif
01366
01367
01368