00001 /*======================================================================= 00002 * Copyright 1991-1996, Silicon Graphics, Inc. 00003 * ALL RIGHTS RESERVED 00004 * 00005 * UNPUBLISHED -- Rights reserved under the copyright laws of the United 00006 * States. Use of a copyright notice is precautionary only and does not 00007 * imply publication or disclosure. 00008 * 00009 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: 00010 * Use, duplication or disclosure by the Government is subject to restrictions 00011 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights 00012 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or 00013 * in similar or successor clauses in the FAR, or the DOD or NASA FAR 00014 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., 00015 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. 00016 * 00017 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY 00018 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, 00019 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY 00020 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON 00021 * GRAPHICS, INC. 00022 **=======================================================================*/ 00023 /*======================================================================= 00024 ** Author : Paul Isaacs (MMM yyyy) 00025 **=======================================================================*/ 00026 /*======================================================================= 00027 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00028 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00029 *** *** 00030 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00031 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00032 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00033 *** *** 00034 *** RESTRICTED RIGHTS LEGEND *** 00035 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00036 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00037 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00038 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00039 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00040 *** *** 00041 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00042 *** BORDEAUX, FRANCE *** 00043 *** ALL RIGHTS RESERVED *** 00044 **=======================================================================*/ 00045 /*======================================================================= 00046 ** Modified by : VSG (MMM YYYY) 00047 **=======================================================================*/ 00048 00049 00050 #ifndef _SO_INTERACTION_KIT_ 00051 #define _SO_INTERACTION_KIT_ 00052 00053 #include <Inventor/nodes/SoSeparator.h> 00054 #include <Inventor/nodekits/SoBaseKit.h> 00055 #include <Inventor/fields/SoSFEnum.h> 00056 #include <Inventor/sensors/SoFieldSensor.h> 00057 #include <Inventor/SoNodeKitPath.h> 00058 #include <Inventor/SbRenderCaching.h> 00059 00060 class SoPath; 00061 class SoPathList; 00062 00064 // 00065 // Class: SoInteractionKit 00066 // 00067 // NOTE TO DEVELOPERS: 00068 // For info about the structure of SoInteractionKit: 00069 // [1] compile: /usr/share/src/Inventor/samples/ivNodeKitStructure 00070 // [2] type: ivNodeKitStructure SoInteractionKit. 00071 // [3] The program prints a diagram of the scene graph and a table with 00072 // information about each part. 00073 // 00074 // Base class for all draggers. 00075 // 00077 00152 class SoInteractionKit : public SoBaseKit { 00153 00154 SO_KIT_HEADER(SoInteractionKit); 00155 00156 SO_KIT_CATALOG_ENTRY_HEADER(topSeparator); 00157 SO_KIT_CATALOG_ENTRY_HEADER(geomSeparator); 00158 00159 public: 00160 00188 virtual SbBool setPartAsPath( const SbName &partName, 00189 SoPath *surrogatePath ); 00190 00191 // Override the default behavior of SoNode 00192 virtual SbBool affectsState() const; 00193 00195 enum CacheEnabled { 00199 OFF = SO_RENDERCACHING_OFF, 00203 ON = SO_RENDERCACHING_ON, 00207 AUTO = SO_RENDERCACHING_AUTO 00208 }; 00209 00210 // Fields 00215 SoSFEnum renderCaching; 00221 SoSFEnum boundingBoxCaching; 00227 SoSFEnum renderCulling; 00232 SoSFEnum pickCulling; 00233 00234 private: 00235 00236 // Sets the part, then sets the field for that part to default. 00237 // using partField.setDefault(TRUE). 00238 // Hence 'newNode' becomes the new default value, and the part 00239 // only writes if [a] the part is set to a different node. 00240 // [b] values are changes in the fields of newNode. 00241 // [c] any child below newNode changes. 00242 // 00243 // If the flag 'onlyIfAlready' is TRUE, then this will only change values 00244 // of parts that are already in a default state. 00245 // 00246 // Returns FALSE on failure, TRUE otherwise. 00247 // First version sets the part to the given node. 00248 // Second version looks up resourceName in the global dictionary and sets 00249 // the part with the node found. 00250 virtual SbBool setPartAsDefault(const SbName &partName, 00251 SoNode *newNode, SbBool onlyIfAlready = TRUE ); 00252 virtual SbBool setPartAsDefault(const SbName &partName, 00253 const SbName &newNodeName, SbBool onlyIfAlready = TRUE); 00254 00255 // Is the 'inPath' valid as a surrogate path anywhere in this node's 00256 // subgraph? 00257 // Examines the surrogate paths of all InteractionKits from this node down. 00258 // The first time a surrogate path is found that is contained within 00259 // 'inPath', then TRUE is returned. 00260 // The second version also returns information about the surrogate, 00261 // only if (fillArgs == TRUE). 00262 SbBool isPathSurrogateInMySubgraph(const SoPath *pathToCheck); 00263 SbBool isPathSurrogateInMySubgraph(const SoPath *pathToCheck, 00264 SoPath *&pathToOwner, 00265 SbName &surrogateNameInOwner, 00266 SoPath *&surrogatePathInOwner, 00267 SbBool fillArgs = TRUE ); 00268 00269 static void setSwitchValue( SoNode *n, int newVal ); 00270 00271 private: 00272 static void initClass(); // initialize the class 00273 static void exitClass(); 00274 00275 private: 00276 SoInteractionKit(); 00277 ~SoInteractionKit(); 00278 00279 // Copies the contents of the given instance into this instance 00280 // This copies the surrogatePartPathList and the surrogatePartNameList 00281 virtual void copyContents(const SoFieldContainer *fromFC, 00282 SbBool copyConnections); 00283 00284 // These are overloaded to set the surrogate path to NULL after completing 00285 // their work. 00286 virtual SoNode *getAnyPart( const SbName &partName, SbBool makeIfNeeded, 00287 SbBool leafCheck = FALSE, SbBool publicCheck = FALSE ); 00288 virtual SoNodeKitPath *createPathToAnyPart(const SbName &partName, 00289 SbBool makeIfNeeded, 00290 SbBool leafCheck = FALSE, SbBool publicCheck = FALSE, 00291 const SoPath *pathToExtend = NULL ); 00292 virtual SbBool setAnyPart( const SbName &partName, SoNode *from, 00293 SbBool anyPart = TRUE ); 00294 00295 // This allows you to set any part in the nodekit as a surrogate path. 00296 // Note: The node corresponding to 'partName' will become empty. 00297 // If 'partName' is not a leaf, the subgraph below it will disappear. 00298 virtual SbBool setAnyPartAsPath( const SbName &partName, 00299 SoPath *surrogatePath, 00300 SbBool leafCheck = FALSE, 00301 SbBool publicCheck = FALSE ); 00302 00303 // Reads in from file. Takes care of checking values in 00304 // the topSeparator fields and the field of this node. 00305 virtual SbBool readInstance(SoInput *in, unsigned short flags); 00306 00307 static void readDefaultParts(const SbString& fileName, // file to read 00308 const char defaultBuffer[], // if no file, 00309 int defBufSize); // read from buffer 00310 00311 // Protected versions of these methods that allow you to set non-leaf 00312 // and/or private parts. 00313 virtual SbBool setAnyPartAsDefault(const SbName &partName, 00314 SoNode *newNode, SbBool anyPart = TRUE, 00315 SbBool onlyIfAlready = TRUE ); 00316 virtual SbBool setAnyPartAsDefault(const SbName &partName, 00317 const SbName &newNodeName, SbBool anyPart = TRUE, 00318 SbBool onlyIfAlready = TRUE ); 00319 00320 SbBool setAnySurrogatePath( const SbName &inName, SoPath *inPath, 00321 SbBool leafCheck = FALSE, SbBool publicCheck = FALSE ); 00322 00323 // detach/attach any sensors, callbacks, and/or field connections. 00324 // Called by: start/end of SoBaseKit::readInstance 00325 // and on new copy by: start/end of SoBaseKit::copy. 00326 // Classes that redefine must call setUpConnections(TRUE,TRUE) 00327 // at end of constructor. 00328 // Returns the state of the node when this was called. 00329 virtual SbBool setUpConnections( SbBool onOff, SbBool doItAlways = FALSE ); 00330 00331 // Called by the SoBaseKit::write() method. 00332 // 00333 // InteractionKits don't want to write fields if they have default vals. 00334 // 00335 // Calls setDefault(TRUE) on caching fields if default and not 00336 // connected. 00337 // 00338 // Calls setDefault(TRUE) on the topSeparator. 00339 // Calls setDefault(TRUE) on the geomSeparator. 00340 // 00341 // Calls setDefault(TRUE) on any non-leaf part of type exactly == SoSwitch. 00342 // Subclasses can override this if they like, since the function is virtual. 00343 // But interactionKits use non-leaf switches to turn parts on and off, and 00344 // this does not need to be written to file. 00345 // 00346 // Lastly, calls same method on SoBaseKit. 00347 // 00348 // NOTE: Parts which are set to default may still wind up writing to file 00349 // if, for example, they lie on a path. 00350 virtual void setDefaultOnNonWritingFields(); 00351 00352 // This sensor will watch the topSeparator part. If the part changes to a 00353 // new node, then the fields of the old part will be disconnected and 00354 // the fields of the new part will be connected. 00355 // Connections are made from/to the renderCaching, boundingBoxCaching, 00356 // renderCulling and pickCulling fields. This way, the SoInteractionKit 00357 // can be treated from the outside just like a regular SoSeparator node. 00358 // Setting the fields will affect caching and culling, even though the 00359 // topSeparator takes care of it. 00360 // oldTopSep keeps track of the part for comparison. 00361 SoFieldSensor *fieldSensor; 00362 static void fieldSensorCB( void *, SoSensor *); 00363 SoSeparator *oldTopSep; 00364 00365 void connectSeparatorFields( SoSeparator *dest, SbBool onOff ); 00366 00367 private: 00368 00369 // This list stores all paths that represent surrogate parts. 00370 // These special parts do not have geometry in the dragger subgraph. 00371 // Rather, picking one of these paths is regarded as tantamount to 00372 // picking a particular part. 00373 SoPathList *surrogatePartPathList; 00374 SbPList *surrogatePartNameList; 00375 00376 void setMySurrogatePath( const SbName &name, SoPath *newPath ); 00377 int indexOfSurrogateInMyList(const SoPath *pathToCheck); 00378 00379 // used to read information by 'readDefaultParts' 00380 static SoGroup *readFromFile(const SbString& fileName); 00381 static SoGroup *readFromBuffer(const char defaultBuffer[], int defBufSize); 00382 00383 static SbPList* m_buffStuffList; 00384 static SbPList* m_fileStuffList; 00385 }; 00386 00387 #endif /* _SO_INTERACTION_KIT_ */ 00388 00389 00390