Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

SoSceneViewer.h

00001 /*
00002  *
00003  *  Copyright (C) 2000 Silicon Graphics, Inc.  All Rights Reserved. 
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  Further, this software is distributed without any warranty that it is
00016  *  free of the rightful claim of any third person regarding infringement
00017  *  or the like.  Any license provided herein, whether implied or
00018  *  otherwise, applies only to this software file.  Patent licenses, if
00019  *  any, provided herein do not apply to combinations of this program with
00020  *  other software, or any other product whatsoever.
00021  * 
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with this library; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
00027  *  Mountain View, CA  94043, or:
00028  * 
00029  *  http://www.sgi.com 
00030  * 
00031  *  For further information regarding this notice, see: 
00032  * 
00033  *  http://oss.sgi.com/projects/GenInfo/NoticeExplan/
00034  *
00035  */
00036 
00037 //  -*- C++ -*-
00038 
00039 /*
00040  * Copyright (C) 1990-93   Silicon Graphics, Inc.
00041  *
00042  _______________________________________________________________________
00043  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00044  |
00045  |   $Revision: 1.1 $
00046  |
00047  |   Classes    : SoSceneViewer
00048  |
00049  |   Author(s)  : Thad Beier, Alain Dumesny, David Mott, Paul Isaacs
00050  |
00051  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00052  _______________________________________________________________________
00053  */
00054 
00055 #ifndef  _SCENE_VIEWER_
00056 #define  _SCENE_VIEWER_
00057 
00058 #include <X11/Intrinsic.h>
00059 #include <Xm/Xm.h>
00060 #include <Xm/RowColumn.h>
00061 
00062 #include <Inventor/nodes/SoNode.h>
00063 #include <Inventor/SbPList.h>
00064 #include <Inventor/nodes/SoPerspectiveCamera.h>
00065 #include <Inventor/actions/SoGLRenderAction.h>  // transparency levels
00066 #include <Inventor/actions/SoCallbackAction.h>
00067 #include <Inventor/Xt/viewers/SoXtFullViewer.h>
00068 
00069 // components
00070 class   MyColorEditor;
00071 class   SoXtMaterialEditor;
00072 class   SoXtPrintDialog;
00073 class   SoXtTransformSliderSet;
00074 class   SoXtClipboard;
00075 class   SoXtDirectionalLightEditor;
00076 
00077 // interaction
00078 class   SoBoxHighlightRenderAction;
00079 class   SoSelection;
00080 class   SoPickedPoint;
00081 
00082 // nodes
00083 class   SoDirectionalLight;
00084 class   SoEnvironment;
00085 class   SoGroup;
00086 class   SoLabel;
00087 class   SoMaterial;
00088 class   SoSceneViewer;
00089 class   SoSwitch;
00090 class   SoLight;
00091 class   SoTransform;
00092 
00093 // misc.
00094 class   SvManipList;
00095 
00096 enum SvEViewer {
00097     SV_VWR_EXAMINER = 0, 
00098     SV_VWR_FLY, 
00099     SV_VWR_WALK, 
00100     SV_VWR_PLANE 
00101 };
00102 
00103 enum SvEManipMode {
00104     SV_NONE,                         // None
00105     SV_TRANSFORMER,                  // Transformer manip
00106     SV_TRACKBALL,                    // Trackball manip
00107     SV_HANDLEBOX,                    // Handlebox manip
00108     SV_JACK,                         // Jack manip
00109     SV_CENTERBALL,                   // Centerball manip
00110     SV_XFBOX,                        // TransformBox manip
00111     SV_TABBOX                        // TabBox manip
00112 };
00113 
00114 struct  SoSceneViewerData;
00115 struct  SvLightData;
00116 
00118 //
00119 //  Class: SoSceneViewer
00120 //
00121 //      The SceneViewer component lets you select between different viewers
00122 //  (Examiner, Navigator,..) and lets you perform  some simple attribute
00123 //  assignment, and some manipulation of data.
00124 //
00126 
00127 class SoSceneViewer : public SoXtComponent {
00128 
00129   public:    
00130     // Constructor:
00131     // envFile is the environment file to use. This is where the camera,
00132     // environment node, and lights are found. 
00133     // Passing NULL means use the default environment.
00134     //
00135     // Save will save all the children of root, not including root itself.
00136     // Save Environment will save the lights and camera environment into envFile
00137     //
00138     SoSceneViewer(
00139         Widget parent = NULL, 
00140         const char *name = NULL, 
00141         SbBool buildInsideParent = TRUE, 
00142         SoSelection *root = NULL,
00143         const char *envFile = NULL);
00144     ~SoSceneViewer();
00145 
00146   protected:  
00147     // This constructor takes a boolean whether to build the widget now.
00148     // Subclasses can pass FALSE, then call SoSceneViewer::buildWidget()
00149     // when they are ready for it to be built.
00150     SoEXTENDER
00151     SoSceneViewer(
00152             Widget parent,
00153             const char *name, 
00154             SbBool buildInsideParent, 
00155             SoSelection *root,
00156             const char *envFile, 
00157             SbBool buildNow);
00158             
00159 
00160   public:
00161     //
00162     // Camera operation routines
00163     //
00164     void        viewAll()           
00165                     { if (currentViewer != NULL) currentViewer->viewAll(); }
00166     void        viewSelection();
00167     void        saveHomePosition()  
00168                     { if (currentViewer != NULL) currentViewer->saveHomePosition(); }
00169     void        setCamera(SoCamera *cam) 
00170                     { if (currentViewer != NULL) currentViewer->setCamera(cam); }
00171     // NOTE: because the camera may be changed dynamically (switch between ortho
00172     // and perspective), the user shouldn't cache the camera.
00173     SoCamera    *getCamera()        
00174                     { return (currentViewer) ? currentViewer->getCamera() : NULL; }
00175     
00176     //
00177     // Before new data is sent to the viewer, the newData method should
00178     // be called to disconnect all manipulators and highlights
00179     //
00180     void                newData();
00181     
00182     // Show/hide the pulldown menu bar (default shown)
00183     void                showMenu(SbBool onOrOff);
00184     SbBool              isMenuShown()       { return showMenuFlag; }
00185     
00186     // Show/hide the viewer component trims (default shown)
00187     void                setDecoration(SbBool onOrOff)   
00188                     { if (currentViewer != NULL) currentViewer->setDecoration(onOrOff); }
00189     SbBool              isDecoration()      
00190                     { return currentViewer != NULL ? currentViewer->isDecoration() : FALSE; }
00191     
00192     // Show/hide headlight (default on) and get to the headlight node.
00193     void                setHeadlight(SbBool onOrOff)    
00194                     { if (currentViewer != NULL) currentViewer->setHeadlight(onOrOff); }
00195     SbBool              isHeadlight()       
00196                     { return currentViewer != NULL ? currentViewer->isHeadlight() : FALSE; }
00197     SoDirectionalLight  *getHeadlight()     
00198                     { return currentViewer != NULL ? currentViewer->getHeadlight() : NULL; }
00199     
00200     //
00201     // Sets/gets the current drawing style in the main view - The user
00202     // can specify the INTERACTIVE draw style (draw style used when 
00203     // the scene changes) independently from the STILL style.
00204     //
00205     // (default VIEW_AS_IS for both STILL and INTERACTIVE)
00206     //
00207     void            setDrawStyle(SoXtViewer::DrawType type, 
00208                                 SoXtViewer::DrawStyle style)
00209                             { currentViewer->setDrawStyle(type, style); }
00210     SoXtViewer::DrawStyle getDrawStyle(SoXtViewer::DrawType type)
00211                             { return currentViewer->getDrawStyle(type); }
00212     
00213     //
00214     // Sets/gets the current buffering type in the main view
00215     // (default BUFFER_INTERACTIVE on Indigo, BUFFER_DOUBLE otherwise)
00216     //
00217     void                setBufferingType(SoXtViewer::BufferType type)
00218                             { currentViewer->setBufferingType(type); }
00219     SoXtViewer::BufferType getBufferingType()
00220                             { return currentViewer->getBufferingType(); }
00221 
00222     // Turn viewing on/off (Default to on) in the viewers.
00223     void                setViewing(SbBool onOrOff)  { currentViewer->setViewing(onOrOff); }
00224     SbBool              isViewing()     { return currentViewer->isViewing(); }
00225     
00226     // Set/get the level of transparency type
00227     void                setTransparencyType(SoGLRenderAction::TransparencyType type)
00228                                     { currentViewer->setTransparencyType(type); }
00229     SoGLRenderAction::TransparencyType  getTransparencyType()
00230                                     { return currentViewer->getTransparencyType(); }
00231 
00232     // returns the current render area widget
00233     Widget              getRenderAreaWidget()   { return currentViewer->getRenderAreaWidget(); }
00234     
00235 #ifdef EXPLORER
00236     // set the EXPLORER user mode callback routine
00237     void                setUserModeEventCallback(SoXtRenderAreaEventCB *fcn);
00238 #endif /* EXPLORER */
00239 
00240  protected:
00241     // redefine these
00242     virtual const char *    getDefaultWidgetName() const;
00243     virtual const char *    getDefaultTitle() const;
00244     virtual const char *    getDefaultIconTitle() const;
00245 
00246  private:
00247     // Scene graph data
00248     SoSelection         *selection;             // the same user supplied graph
00249     SoSeparator         *sceneGraph;            // user supplied scene graph
00250     
00251     // Lights, camera, environment!
00252     SoGroup             *lightsCameraEnvironment;
00253     SoLabel             *envLabel;
00254     SoEnvironment       *environment;
00255     SoGroup             *lightGroup;
00256     
00257     void                createLightsCameraEnvironment();
00258     
00259     // Selection highlight
00260     SoBoxHighlightRenderAction *highlightRA;
00261     
00262     //
00263     // Widgets and menus
00264     //
00265     
00266     Widget              mgrWidget;  // our topmost form widget
00267     Widget              menuWidget; // topbar menu widget
00268     SbBool              showMenuFlag;
00269     SoSceneViewerData   *menuItems; // list of menu items data
00270     
00271     Widget              buildWidget(Widget parent);
00272     void                buildAndLayoutMenu(Widget parent);
00273     void                buildAndLayoutViewer(SoXtFullViewer *vwr);
00274 
00275     // callback for all menu buttons to perform action
00276     static void         processTopbarEvent(Widget, SoSceneViewerData *,
00277                                    XmAnyCallbackStruct *);
00278     // callback when a menu is displayed
00279     static void         menuDisplay(Widget, SoSceneViewerData *, XtPointer);
00280     
00281     // this is called after objects are added/deleted or the selection changes
00282     void                updateCommandAvailability();
00283     
00284     //
00285     // File
00286     //
00287     
00288     // file reading methods
00289     int         fileMode;
00290     char        *fileName;
00291     SbBool      useShowcaseBrowser;
00292     void        getFileName();
00293     SbBool      doFileIO(const char *filename);
00294     SbBool      readFile(const char *filename);
00295     SbBool      writeFile(const char *filename);
00296     SbBool      readEnvFile(const char *filename);
00297     SbBool      writeEnvFile(const char *filename);
00298     void        deleteScene();
00299     void        save();
00300 
00301     // cameras
00302     void        removeCameras(SoGroup *root);
00303     // Returns the last scene kit camera in a scene.
00304     SoCamera    *getLastSceneKitCamera(SoGroup *root);
00305     // Copies our camera into the last scene kit camera in a scene.
00306     void        setLastSceneKitCamera(SoGroup *root, SoCamera *theCam);
00307     // Switches off/ restores camera num settings of scenekits.
00308     void        switchOffSceneKitCameras(SoGroup *root);
00309     void        restoreSceneKitCameras(SoGroup *root);
00310     // Copies from given camera into this viewer's camera, if types match.
00311     void        setCameraFields( SoCamera *fromCam );
00312     SbDict      *sceneKitCamNumDict;
00313     
00314     // motif vars for file reading/writting
00315     Widget              fileDialog;
00316     static void         fileDialogCB(Widget, SoSceneViewer *,
00317                                     XmFileSelectionBoxCallbackStruct *);
00318         
00319     // printing vars
00320     SoXtPrintDialog     *printDialog;
00321     void                print();
00322     static void         beforePrintCallback(void *uData, SoXtPrintDialog *);
00323     static void         afterPrintCallback(void *uData, SoXtPrintDialog *);
00324 
00325 
00326     SbBool              feedbackShown;
00327     
00328     void                showAboutDialog();
00329     
00330     //
00331     // Edit
00332     //
00333     
00334     // Select parent, if there is one; select everything.
00335     void                pickParent();
00336     void                pickAll();
00337 
00338     // for copy and paste
00339     SoXtClipboard       *clipboard;     // copy/paste 3d data
00340     void                destroySelectedObjects();
00341 
00342     // Paste callback - invoked when paste data transfer is complete
00343     void                pasteDone(SoPathList *pathList);
00344     static void         pasteDoneCB(void *userData, SoPathList *pathList);
00345     
00346     // Drag and drop support (allowing dropping of data into SceneViewer)
00347     static SbBool       iconDropCB(void *userData, const char *filename);
00348     static SbBool       objDropCB(
00349                             void *userData,
00350                             Atom dataType,
00351                             void *data, uint32_t numBytes);
00352     
00353     
00354     //
00355     // Viewing
00356     //
00357     
00358     SoXtFullViewer      *viewerList[4]; // list of viewers
00359     SvEViewer           whichViewer;    // current viewer ID
00360     SoXtFullViewer      *currentViewer; // current viewer pt
00361     
00362     void                switchToViewer(SvEViewer newViewer);
00363     
00364     // Environment: fog, antialiasing
00365     SbBool              fogFlag;                // Fog on/off
00366     void                setFog(SbBool onOrOff); // Turns fog on/off
00367     SbBool              antialiasingFlag;       // AA-ing on/off
00368     void                setAntialiasing(SbBool onOrOff); // Turns AA-ing on/off
00369     
00370     // Background color
00371     MyColorEditor       *backgroundColorEditor;
00372     const SbColor &     getBackgroundColor()    { return currentViewer->getBackgroundColor(); }
00373     void                editBackgroundColor();  // Invokes color editor on bkg
00374     static void         backgroundColorCallback(void *userData,
00375                                 const SbColor *color);
00376     
00377     //
00378     // Editors
00379     //
00380     
00381     SbBool              ignoreCallback;
00382     SoMaterial          *findMaterialForAttach( const SoPath *target );
00383     SoPath              *findTransformForAttach( const SoPath * target );
00384     // callback used by Accum state action created by findMaterialForAttach
00385     static SoCallbackAction::Response findMtlPreTailCB(void *data, 
00386                                             SoCallbackAction *accum,
00387                                             const SoNode *);
00388     
00389     // transform slider set
00390     SoXtTransformSliderSet *transformSliderSet;
00391     void                createTransformSliderSet();
00392 
00393     // Material editor
00394     SoXtMaterialEditor          *materialEditor;
00395     void                createMaterialEditor();
00396     
00397     // Color editor
00398     MyColorEditor       *colorEditor;
00399     void                createColorEditor();
00400 
00401 
00402     //
00403     // Manips
00404     //
00405     SvEManipMode curManip;
00406     SbBool       curManipReplaces;
00407     SvManipList  *maniplist;    // list of selection/manip/xfPath triplets.
00408 
00409     // replaces manips with the given type for all selected objects.
00410     void    replaceAllManips( SvEManipMode manipType );
00411 
00412     // attaches a manipulator
00413     void    attachManip( SvEManipMode manipType, SoPath *p );
00414     void    attachManipToAll( SvEManipMode manipType );
00415 
00416     // detaches a manipulator
00417     void    detachManip( SoPath *p );
00418     void    detachManipFromAll();
00419 
00420     // Temporarily remove manips for writing, printing, copying, etc.
00421     // and restore later
00422     void    removeManips();
00423     void    restoreManips();
00424 
00425     // Callback to adjust size of scale tabs. Used only for SoTabBoxManip
00426     // Added to viewer as a finishCallback.
00427     static void adjustScaleTabSizeCB( void *, SoXtViewer *);
00428 
00429     //
00430     // Lighting
00431     //
00432     
00433     SbPList             lightDataList;
00434     SoXtDirectionalLightEditor *headlightEditor;
00435     SvLightData         *headlightData;
00436     void                addLight(SoLight *light);
00437     SvLightData         *addLightEntry(SoLight *light, SoSwitch *lightSwitch);
00438     void                addLightMenuEntry(SvLightData *);
00439     void                turnLightOnOff(SvLightData *data, SbBool flag);
00440     static void         lightToggleCB(Widget, SvLightData *, void *);
00441     void                editLight(SvLightData *data, SbBool flag);
00442     static void         editLightToggleCB(Widget, SvLightData *, void *);
00443     static void         editLightColorCB(Widget, SvLightData *, void *);
00444     void                removeLight(SvLightData *);
00445     static void         removeLightCB(Widget, SvLightData *, void *);
00446     static void         lightSubmenuDisplay(Widget, SvLightData *, void *);
00447     void                transferDirectionalLightLocation( SvLightData *data );
00448     
00449     // vars to make the light manips all the same size
00450     void                calculateLightManipSize();
00451     float               lightManipSize;
00452     SbBool              calculatedLightManipSize;
00453     
00454     // temporary remove/add the light manip geometry of the attached manips
00455     // (used for file writting and printing)
00456     void                removeAttachedLightManipGeometry();
00457     void                addAttachedLightManipGeometry();
00458     
00459     // Ambient lighting color
00460     MyColorEditor       *ambientColorEditor;
00461     void                editAmbientColor();     // Invokes color editor on amb
00462     static void         ambientColorCallback(void *userData,
00463                                 const SbColor *color);
00464     
00465     //
00466     // Selection
00467     //
00468     // manages changes in the selection.
00469     static void         deselectionCallback(void *userData, SoPath *obj);
00470     static void         selectionCallback(void *userData, SoPath *obj);
00471     static SoPath *     pickFilterCB(void *userData, const SoPickedPoint *pick);
00472     
00473     //
00474     // Convenience routines
00475     //
00476     static SbBool    isAffectedByTransform( SoNode *node );
00477     static SbBool    isAffectedByMaterial( SoNode *node );
00478 
00479 #ifdef EXPLORER
00480     //
00481     // user pick function
00482     //
00483     SoXtRenderAreaEventCB   *userModeCB;
00484     void                    *userModedata;
00485     SbBool                  userModeFlag;
00486 #endif /* EXPLORER */
00487 
00488     void constructorCommon(SoSelection *root, const char *envFile, SbBool buildNow);
00489 };
00490 
00491 #endif  /* _SCENE_VIEWER_ */

Generated on Fri Oct 26 23:38:13 2001 for bicobj-intersection by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001