home *** CD-ROM | disk | FTP | other *** search
- // -*- C++ -*-
-
- /*
- * Copyright (C) 1990-93 Silicon Graphics, Inc.
- *
- _______________________________________________________________________
- ______________ S I L I C O N G R A P H I C S I N C . ____________
- |
- | $Revision: 1.4 $
- |
- | Classes : SoSceneViewer
- |
- | Author(s) : Thad Beier, Alain Dumesny, David Mott, Paul Isaacs
- |
- ______________ S I L I C O N G R A P H I C S I N C . ____________
- _______________________________________________________________________
- */
-
- #ifndef _SCENE_VIEWER_
- #define _SCENE_VIEWER_
-
- #ifndef WIN32
- #include <X11/Intrinsic.h>
- #include <Xm/Xm.h>
- #include <Xm/RowColumn.h>
- #endif
-
- #include <Inventor/nodes/SoNode.h>
- #include <Inventor/SbPList.h>
- #include <Inventor/nodes/SoPerspectiveCamera.h>
- #include <Inventor/actions/SoGLRenderAction.h> // transparency levels
- #include <Inventor/actions/SoCallbackAction.h>
- #include <Inventor/Win/viewers/SoWinFullViewer.h>
-
- // components
- #ifdef WIN32
- #define MyColorEditor SoWinColorEditor
- // this can be changed below with setFirstLightMenuId
- #define ID_SV_FIRST_LIGHT 16386
- #endif
-
- class MyColorEditor;
- class SoWinMaterialEditor;
-
- #ifdef NOTYET
- class SoWinPrintDialog;
- class SoWinTransformSliderSet;
- #endif
-
- class SoWinClipboard;
- class SoWinDirectionalLightEditor;
-
- // interaction
- class SoBoxHighlightRenderAction;
- class SoSelection;
- class SoPickedPoint;
-
- // nodes
- class SoDirectionalLight;
- class SoEnvironment;
- class SoGroup;
- class SoLabel;
- class SoMaterial;
- class SoSceneViewer;
- class SoSwitch;
- class SoLight;
- class SoTransform;
-
- // misc.
- class SvManipList;
-
- enum SvEViewer {
- SV_VWR_EXAMINER = 0,
- SV_VWR_FLY,
- SV_VWR_WALK,
- SV_VWR_PLANE,
- };
-
- enum SvEManipMode {
- SV_NONE, // None
- SV_TRACKBALL, // Trackball manip
- SV_HANDLEBOX, // Handlebox manip
- SV_JACK, // Jack manip
- SV_CENTERBALL, // Centerball manip
- SV_XFBOX, // TransformBox manip
- SV_TABBOX // TabBox manip
- };
-
- #ifdef WIN32
-
- #define SvMenuAction(p,action) \
- { \
- SoSceneViewerData data ; \
- data.classPt = pSV ; \
- data.id = action ; \
- data.widget = NULL ; \
- SoSceneViewer::processTopbarEvent( \
- pSV, \
- &data, \
- NULL \
- ) ; \
- }
-
- struct SoSceneViewerData {
- int id;
- SoSceneViewer *classPt;
- Widget widget;
- };
- #else
- struct SoSceneViewerData;
- #endif
- struct SvLightData;
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // Class: SoSceneViewer
- //
- // The SceneViewer component lets you select between different viewers
- // (Examiner, Navigator,..) and lets you perform some simple attribute
- // assignment, and some manipulation of data.
- //
- //////////////////////////////////////////////////////////////////////////////
-
- class SoSceneViewer : public SoWinComponent {
-
- public:
- // Constructor:
- // envFile is the environment file to use. This is where the camera,
- // environment node, and lights are found.
- // Passing NULL means use the default environment.
- //
- // Save will save all the children of root, not including root itself.
- // Save Environment will save the lights and camera environment into envFile
- //
- SoSceneViewer(
- Widget parent = NULL,
- const char *name = NULL,
- SbBool buildInsideParent = TRUE,
- SoSelection *root = NULL,
- const char *envFile = NULL);
- ~SoSceneViewer();
-
- #ifdef WIN32
- SoEXTENDER
- SoSceneViewer(
- Widget parent,
- const char *name,
- SbBool buildInsideParent,
- SoSelection *root,
- const char *envFile,
- SbBool buildNow);
-
- static void processTopbarEvent(Widget, SoSceneViewerData *,
- XmAnyCallbackStruct *);
-
- void realizeWidget() ;
- #endif
-
-
- protected:
-
- #ifdef WIN32
- SbBool realized ;
- #endif
- // This constructor takes a boolean whether to build the widget now.
- // Subclasses can pass FALSE, then call SoSceneViewer::buildWidget()
- // when they are ready for it to be built.
- #ifndef WIN32
- SoEXTENDER
- SoSceneViewer(
- Widget parent,
- const char *name,
- SbBool buildInsideParent,
- SoSelection *root,
- const char *envFile,
- SbBool buildNow);
-
- #endif
-
-
- public:
- void saveViewerSceneGraph(const char *fileName) ;
- #ifdef WIN32
- void setFileMode(int nMode) { fileMode = nMode ; } ;
- void doFileIO(const char *filename);
- SoWinFullViewer *getViewer(int n) {return viewerList[n];} ;
- SoWinFullViewer *getCurrViewer() {return viewerList[whichViewer];} ;
- SvEViewer getWhichViewer() { return whichViewer ; } ;
-
- SoWinMaterialEditor *getMaterialEditor() {return materialEditor;} ;
- SoWinColorEditor *getBackgroundColorEditor() {return backgroundColorEditor;} ;
- SoWinColorEditor *getAmbientColorEditor() {return ambientColorEditor;} ;
- SoWinColorEditor *getColorEditor() {return colorEditor;} ;
- SoWinDirectionalLightEditor *getHeadlightEditor()
- {return headlightEditor; } ;
-
- SoSelection *getSelection() {return selection;} ;
-
- SvLightData *getHeadlightData() {return headlightData;} ;
-
- void editHeadlight() { editLight(headlightData,TRUE); } ;
-
-
- SvEManipMode getCurrManip() {return curManip;};
-
- SoSeparator *getSceneGraph() { return sceneGraph;};
- SbBool setSceneGraph(SoNode *node) ;
-
- void setMenuWidget(HMENU hMenu) { menuWidget = hMenu; } ;
- void setLightMenuWidget(HMENU hMenu) { hLightMenu = hMenu; } ;
- void setFirstLightMenuId(ULONG nId) {nFirstLightMenuId = nId; } ;
-
- SbBool getAAFlag() { return antialiasingFlag;} ;
- SbBool getFogFlag() { return fogFlag ; } ;
-
- #ifdef NOTDEF
- SbBool onCommand(UINT nId,int nCode) ;
- #endif
- SbBool onCommand(WPARAM wParam, LPARAM lParam) ;
-
-
- #endif
- //
- // Camera operation routines
- //
- void viewAll()
- { if (currentViewer != NULL) currentViewer->viewAll(); }
- void viewSelection();
- void saveHomePosition()
- { if (currentViewer != NULL) currentViewer->saveHomePosition(); }
- void setCamera(SoCamera *cam) ;
- // NOTE: because the camera may be changed dynamically (switch between ortho
- // and perspective), the user shouldn't cache the camera.
- SoCamera *getCamera()
- { return (currentViewer) ? currentViewer->getCamera() : NULL; }
-
- //
- // Before new data is sent to the viewer, the newData method should
- // be called to disconnect all manipulators and highlights
- //
- void newData();
-
- // Show/hide the pulldown menu bar (default shown)
- void showMenu(SbBool onOrOff);
- SbBool isMenuShown() { return showMenuFlag; }
-
- // Show/hide the viewer component trims (default shown)
- void setDecoration(SbBool onOrOff)
- { if (currentViewer != NULL) currentViewer->setDecoration(onOrOff); }
- SbBool isDecoration()
- { return currentViewer != NULL ? currentViewer->isDecoration() : FALSE; }
-
- // Show/hide headlight (default on) and get to the headlight node.
- void setHeadlight(SbBool onOrOff)
- { if (currentViewer != NULL) currentViewer->setHeadlight(onOrOff); }
- SbBool isHeadlight()
- { return currentViewer != NULL ? currentViewer->isHeadlight() : FALSE; }
- SoDirectionalLight *getHeadlight()
- { return currentViewer != NULL ? currentViewer->getHeadlight() : NULL; }
-
- //
- // Sets/gets the current drawing style in the main view - The user
- // can specify the INTERACTIVE draw style (draw style used when
- // the scene changes) independently from the STILL style.
- //
- // (default VIEW_AS_IS for both STILL and INTERACTIVE)
- //
- void setDrawStyle(SoWinViewer::DrawType type,
- SoWinViewer::DrawStyle style)
- { currentViewer->setDrawStyle(type, style); }
- SoWinViewer::DrawStyle getDrawStyle(SoWinViewer::DrawType type)
- { return currentViewer->getDrawStyle(type); }
-
- //
- // Sets/gets the current buffering type in the main view
- // (default BUFFER_INTERACTIVE on Indigo, BUFFER_DOUBLE otherwise)
- //
- void setBufferingType(SoWinViewer::BufferType type)
- { currentViewer->setBufferingType(type); }
- SoWinViewer::BufferType getBufferingType()
- { return currentViewer->getBufferingType(); }
-
- // Turn viewing on/off (Default to on) in the viewers.
- void setViewing(SbBool onOrOff) { currentViewer->setViewing(onOrOff); }
- SbBool isViewing() { return currentViewer->isViewing(); }
-
- // Set/get the level of transparency type
- void setTransparencyType(SoGLRenderAction::TransparencyType type)
- { currentViewer->setTransparencyType(type); }
- SoGLRenderAction::TransparencyType getTransparencyType()
- { return currentViewer->getTransparencyType(); }
-
- // returns the current render area widget
- Widget getRenderAreaWidget() { return currentViewer->getRenderAreaWidget(); }
-
- #ifdef EXPLORER
- // set the EXPLORER user mode callback routine
- void setUserModeEventCallback(SoWinRenderAreaEventCB *fcn);
- #endif /* EXPLORER */
-
- protected:
- #ifdef WIN32
- HMENU hLightMenu ;
- ULONG nFirstLightMenuId ;
- #endif
- char *envFileName ;
-
-
- // redefine these
- virtual const char * getDefaultWidgetName() const;
- virtual const char * getDefaultTitle() const;
- virtual const char * getDefaultIconTitle() const;
-
- // Support for menus in the popup planes
- Widget popupWidget;
-
- // Stuff to do after the component has been realized (shown)
- virtual void afterRealizeHook();
-
- private:
- // Scene graph data
- SoSelection *selection; // the same user supplied graph
- SoSeparator *sceneGraph; // user supplied scene graph
-
- // Lights, camera, environment!
- SoGroup *lightsCameraEnvironment;
- SoLabel *envLabel;
- SoEnvironment *environment;
- SoGroup *lightGroup;
- SoCamera *pCamera ;
-
- void createLightsCameraEnvironment();
-
- // Selection highlight
- SoBoxHighlightRenderAction *highlightRA;
-
- //
- // Widgets and menus
- //
-
- Widget mgrWidget; // our topmost form widget
- Widget menuWidget; // topbar menu widget
- SbBool showMenuFlag;
- #ifndef WIN32
- SoSceneViewerData *menuItems; // list of menu items data
- #endif
-
- Widget buildWidget(Widget parent);
- void buildAndLayoutMenu(Widget parent);
- void buildAndLayoutViewer(SoWinFullViewer *vwr);
-
- // callback for all menu buttons to perform action
- #ifndef WIN32
- static void processTopbarEvent(Widget, SoSceneViewerData *,
- XmAnyCallbackStruct *);
- #endif
- // callback when a menu is displayed
- static void menuDisplay(Widget, SoSceneViewerData *, XtPointer);
-
- // this is called after objects are added/deleted or the selection changes
- void updateCommandAvailability();
-
- //
- // File
- //
-
- // file reading methods
- int fileMode;
- char *fileName;
- SbBool useShowcaseBrowser;
- void getFileName();
- #ifndef WIN32
- void doFileIO(const char *filename);
- #endif
- SbBool readFile(const char *filename);
- SbBool writeFile(const char *filename);
- SbBool readEnvFile(const char *filename);
- SbBool writeEnvFile(const char *filename);
- void deleteScene();
- void save();
-
- // cameras
- void removeCameras(SoGroup *root);
- // Returns the last scene kit camera in a scene.
- SoCamera *getLastSceneKitCamera(SoGroup *root);
- // Copies our camera into the last scene kit camera in a scene.
- void setLastSceneKitCamera(SoGroup *root, SoCamera *theCam);
- // Switches off/ restores camera num settings of scenekits.
- void switchOffSceneKitCameras(SoGroup *root);
- void restoreSceneKitCameras(SoGroup *root);
- // Copies from given camera into this viewer's camera, if types match.
- void setCameraFields( SoCamera *fromCam );
- SbDict *sceneKitCamNumDict;
-
- // motif vars for file reading/writting
- #ifndef WIN32
- Widget fileDialog;
- static void fileDialogCB(Widget, SoSceneViewer *,
- XmFileSelectionBoxCallbackStruct *);
- #endif
-
- // printing vars
- #ifdef NOTYET
- SoWinPrintDialog *printDialog;
- void print();
- static void beforePrintCallback(void *uData, SoWinPrintDialog *);
- static void afterPrintCallback(void *uData, SoWinPrintDialog *);
- #endif
-
-
- SbBool feedbackShown;
-
- void showAboutDialog();
-
- //
- // Edit
- //
-
- // Select parent, if there is one; select everything.
- void pickParent();
- void pickAll();
-
- // for copy and paste
- SoWinClipboard *clipboard; // copy/paste 3d data
- void destroySelectedObjects();
-
- // Paste callback - invoked when paste data transfer is complete
- void pasteDone(SoPathList *pathList);
- static void pasteDoneCB(void *userData, SoPathList *pathList);
-
-
- //
- // Viewing
- //
-
- SoWinFullViewer *viewerList[4]; // list of viewers
- SvEViewer whichViewer; // current viewer ID
- SoWinFullViewer *currentViewer; // current viewer pt
-
- void switchToViewer(SvEViewer newViewer);
-
- // Environment: fog, antialiasing
- SbBool fogFlag; // Fog on/off
- void setFog(SbBool onOrOff); // Turns fog on/off
- SbBool antialiasingFlag; // AA-ing on/off
- void setAntialiasing(SbBool onOrOff); // Turns AA-ing on/off
-
- // Background color
- MyColorEditor *backgroundColorEditor;
- const SbColor & getBackgroundColor() { return currentViewer->getBackgroundColor(); }
- void editBackgroundColor(); // Invokes color editor on bkg
- static void backgroundColorCallback(void *userData,
- const SbColor *color);
-
- //
- // Editors
- //
-
- SbBool ignoreCallback;
- SoMaterial *findMaterialForAttach( const SoPath *target );
- SoPath *findTransformForAttach( const SoPath * target );
- // callback used by Accum state action created by findMaterialForAttach
- #ifdef WIN32
- static int findMtlPreTailCB(void *data,
- SoCallbackAction *accum,
- const SoNode *);
- #else
-
- static SoCallbackAction::Response findMtlPreTailCB(void *data,
- SoCallbackAction *accum,
- const SoNode *);
- #endif
-
- // transform slider set
- #ifdef NOTYET
- SoWinTransformSliderSet *transformSliderSet;
- void createTransformSliderSet();
- #endif
-
- // Material editor
- SoWinMaterialEditor *materialEditor;
- void createMaterialEditor();
-
- // Color editor
- MyColorEditor *colorEditor;
- void createColorEditor();
-
-
- //
- // Manips
- //
- SvEManipMode curManip;
- SbBool curManipReplaces;
- SvManipList *maniplist; // list of selection/manip/xfPath triplets.
-
- // replaces manips with the given type for all selected objects.
- void replaceAllManips( SvEManipMode manipType );
-
- // attaches a manipulator
- void attachManip( SvEManipMode manipType, SoPath *p );
- void attachManipToAll( SvEManipMode manipType );
-
- // detaches a manipulator
- void detachManip( SoPath *p );
- void detachManipFromAll();
-
- // Temporarily remove manips for writing, printing, copying, etc.
- // and restore later
- void removeManips();
- void restoreManips();
-
- // Callback to adjust size of scale tabs. Used only for SoTabBoxManip
- // Added to viewer as a finishCallback.
- static void SoSceneViewer::adjustScaleTabSizeCB( void *, SoWinViewer *);
-
- //
- // Lighting
- //
-
- SbPList lightDataList;
- SoWinDirectionalLightEditor *headlightEditor;
- SvLightData *headlightData;
- void addLight(SoLight *light);
- SvLightData *addLightEntry(SoLight *light, SoSwitch *lightSwitch);
- void addLightMenuEntry(SvLightData *);
- void turnLightOnOff(SvLightData *data, SbBool flag);
- static void lightToggleCB(Widget, SvLightData *, void *);
- void editLight(SvLightData *data, SbBool flag);
- static void editLightToggleCB(Widget, SvLightData *, void *);
- static void editLightColorCB(Widget, SvLightData *, void *);
- void removeLight(SvLightData *);
- static void removeLightCB(Widget, SvLightData *, void *);
- static void lightSubmenuDisplay(Widget, SvLightData *, void *);
- void transferDirectionalLightLocation( SvLightData *data );
-
- #ifdef WIN32
- static void headlightEditorCloseCB(void *userData, SoWinComponent *comp) ;
- static void lightColorEditorCloseCB(void *userData, SoWinComponent *comp) ;
- #endif
-
- // vars to make the light manips all the same size
- void calculateLightManipSize();
- float lightManipSize;
- SbBool calculatedLightManipSize;
-
- // temporary remove/add the light manip geometry of the attached manips
- // (used for file writting and printing)
- void removeAttachedLightManipGeometry();
- void addAttachedLightManipGeometry();
-
- // Ambient lighting color
- MyColorEditor *ambientColorEditor;
- void editAmbientColor(); // Invokes color editor on amb
- static void ambientColorCallback(void *userData,
- const SbColor *color);
-
- //
- // Selection
- //
- // manages changes in the selection.
- static void deselectionCallback(void *userData, SoPath *obj);
- static void selectionCallback(void *userData, SoPath *obj);
- static SoPath * pickFilterCB(void *userData, const SoPickedPoint *pick);
-
- //
- // Convenience routines
- //
- static SbBool isAffectedByTransform( SoNode *node );
- static SbBool isAffectedByMaterial( SoNode *node );
-
- #ifdef EXPLORER
- //
- // user pick function
- //
- SoWinRenderAreaEventCB *userModeCB;
- void *userModedata;
- SbBool userModeFlag;
- #endif /* EXPLORER */
-
- void constructorCommon(SoSelection *root, const char *envFile, SbBool buildNow);
- };
-
- #endif /* _SCENE_VIEWER_ */
-