Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoDB.h
Go to the documentation of this file.
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Paul S. Strauss (MMM yyyy)
25** Modified by : Nick Thompson (MMM yyyy)
26** Modified by : Gavin Bell (MMM yyyy)
27**=======================================================================*/
28/*=======================================================================
29 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
30 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
31 *** ***
32 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
33 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
34 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
35 *** ***
36 *** RESTRICTED RIGHTS LEGEND ***
37 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
38 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
39 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
40 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
41 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
42 *** ***
43 *** COPYRIGHT (C) 1996-2021 BY FEI S.A.S, ***
44 *** BORDEAUX, FRANCE ***
45 *** ALL RIGHTS RESERVED ***
46**=======================================================================*/
47/*=======================================================================
48** Modified by : VSG (MMM YYYY)
49**=======================================================================*/
50
51
52#ifndef _SO_DB_
53#define _SO_DB_
54
55#include <Inventor/SoType.h>
56#include <Inventor/SbTime.h>
59
60#ifndef LIBRARYBUILD
61// uneeded header be kept for application built compatibility
63#include <Inventor/SbPList.h>
65#endif
66
67class SbPList;
68class SoBase;
69class SoSFRealTime;
70class SoGroup;
71class SoSeparator;
72class SoInput;
73class SoPath;
74class SoNode;
75class SoField;
76class SbColor;
77class SoGlobalField;
78class SoSensorManager;
79class SoTimerSensor;
80class SoSensor;
81class SoSystemTimer;
82
83#ifdef _WIN32
84#pragma warning( push )
85#pragma warning(disable:4251)
86#endif
87
89
90#include <Inventor/SoModule.h>
91SO_MODULE_HEADER(SoInventor, __INVENTORDLL)
92
93#if defined(_WIN32)
94// Detect compilation that uses any form of /clr
95#if ((_MANAGED == 1) || (_M_CEE == 1))
96#if defined(SO_MODULE_CHECK)
97static SoModuleCheck myModule((bool)_SECURE_SCL);
98#endif
99#elif !defined HIDDEN_FROM_DOC && !defined(LIBRARYBUILD)
100static SoModuleCheck myModule((bool)_SECURE_SCL);
101#endif /* (_MANAGED == 1) || (_M_CEE == 1) */
102#endif /* _WIN32 */
103
104#if defined SO_VERSION_DEPRECATED_ERROR && !defined(LIBRARYBUILD)
105static SoModuleCheck soVersionDeprecatedErrorCheck(SO_VERSION_DEPRECATED_ERROR);
106#endif
107
108typedef void SoDBHeaderCB(void *userData, SoInput *in);
109
111//
112// Class: SoDB
113//
114// Inventor database class. This class maintains all the global
115// information necessary for reading and writing, naming classes, and
116// so on. All public methods on this class are static - users should
117// never explicitly create instances of this class. Initialization of
118// the database class causes a global instance to be created.
119//
121
219class SoDB {
220
221 public:
222
223SoDEPRECATED enum
239 };
240
246 static void init();
247
259 static void finish();
260
261#if 1 SoDEPRECATED
270 static void threadInit();
271#endif
283 static void setSystemTimer(SoSystemTimer* timer);
284
308 static SbBool read(SoInput *in, SoNode *&rootNode);
309
335 static SbBool read(SoInput *in, SoPath *&path);
336
354
367 static SbBool registerHeader(const SbString &headerString,
368 SbBool isBinary,
369 float ivVersion,
370 SoDBHeaderCB *preCB,
371 SoDBHeaderCB *postCB,
372 void *userData = NULL);
384 static SbBool getHeaderData(const SbString &string,
385 SbBool &isBinary,
386 float &ivVersion,
387 SoDBHeaderCB *&preCB,
388 SoDBHeaderCB *&postCB,
389 void *&userData,
390 SbBool substringOK = FALSE);
395 static int getNumHeaders();
396
402
408 static SbBool isValidHeader(const char *testString);
409
437 static SoField *createGlobalField(const SbName &name, SoType type);
438
444 static SoField *getGlobalField(const SbName &name);
445
453 static void renameGlobalField(const SbName &oldName, const SbName &newName);
454
490 static void setRealTimeInterval(const SbTime &deltaT);
491
501
518 static void setDelaySensorTimeout(const SbTime &t);
519
525
530 static void processEvents();
531
542 static int doSelect(int nfds, fd_set *readfds, fd_set *writefds,
543 fd_set *exceptfds, struct timeval *userTimeOut);
544
545#if 1 SoDEPRECATED
551#endif
568 static void writelock();
569
574 static void writeunlock();
575
586 static void readlock();
587
592 static void readunlock();
593
594#if 1 SoDEPRECATED
600 static void setNumRenderCaches( int /*num*/ )
601 {}
602#endif
604#if 1 SoDEPRECATED
610 { return s_numRenderCaches; }
611#endif
613#if 1 SoDEPRECATED
620#endif
622#if 1 SoDEPRECATED
628#endif
634
660 static bool addPlugin( const SbString& fileName );
661
666 static bool removePlugin( const SbString& fileName );
667
672 static const std::vector<SbString>& getLoadedPlugins();
673
678 static const std::vector<SbString>& getUnloadedPlugins();
679
684 static bool addPluginsDirectory( const SbString& dirName );
685
690 static bool removePluginsDirectory( const SbString& dirName );
691
696 static const std::vector<SbString>& getPluginsDirectories();
697
705 static void addConverter(SoType fromField, SoType toField,
706 SoType converterEngine);
707
713 static SoType getConverter(SoType fromField, SoType toField);
714
719 static void removeConverter(SoType fromField, SoType toField);
720
725 static void setIvTuneAllowed(SbBool ivTuneAllowed);
726
732
733private:
734
735#ifdef _WIN32
744 static long openRegistryKey(const SbBool readOnlyFlag=FALSE);
745
751 static long getRegistryKeyValue(LPTSTR keyName,
752 LPTSTR lpValueName, // address of name of value to query
753 LPDWORD lpType, // address of buffer for value type
754 LPBYTE lpData, // address of data buffer
755 LPDWORD lpcbData, // address of data buffer size
756 const SbBool readOnlyFlag=FALSE // readOnly access if TRUE
757 );
758
762 static long closeRegistryKey();
763
764#endif //_WIN32
765
766 private:
767
768#if 1 SoDEPRECATED
773 static void threadFinish();
774#endif
776 // The following two functions are internal-only for now because we do
777 // not have a reliable cross-platform implementation of trylock for a
778 // read-write lock.
779
780 // Provides a global try-write-lock mutex (see threads/SbThreadRWMutex.h)
781 static SbBool trywritelock();
782
783 // Provides a global try-read-lock mutex (see threads/SbThreadRWMutex.h)
784 static SbBool tryreadlock();
785
786 // Get ptr to global RWMutex for use with autolock
787 // just an alias to SoInventorBase::getGlobalMutex()
788 static SbThreadRWMutex *getGlobalMutex()
789 { return SoInventorBase::getGlobalMutex(); }
790
791 // Accesses sensor manager
792 static SoSensorManager *getSensorManager();
793
794 // Accesses UNLOCK sensor manager
795 static SoSensorManager *getUnlockSensorManager();
796
797 // Returns TRUE if database is initialized for the current thread.
798 static bool isInitialized();
799
800 // Returns FALSE if pick culling has been disabled
801 static SbBool getPickCullingEnabled()
802 { return m_pickCullingEnabled; }
803
804 static const char* profileName;
805
806 // This is called when some instance begins or ends a notification
807 // process. It increments or decrements a counter of notifications
808 // in progress. When the counter reaches 0, all priority 0
809 // (immediate) delay queue sensors are triggered. By doing this,
810 // all notification has a chance to finish before any evaluation
811 // (due to data sensors, primarily) takes place.
812 static void startNotify();
813 static SbBool isNotifying();
814 static void endNotify();
815
816 // Enables/disables realTime sensor processing
817 static void enableRealTimeSensor(SbBool enable);
818
819 // Reads a base of any type, returning a pointer to it. Returns
820 // FALSE on error.
821 static SbBool read(SoInput *in, SoBase *&base);
822
823 static SbBool m_readingAll;
824
825 // Returns a copy of the path to the SoInput file (dirname).
826 // If in does not contain a filename or if in is NULL, returns an empty string.
827 // Returns empty string on error.
828 static SbString getDirNameFromFullFileName(SoInput *in);
829
830 // Flag to control use of valid names
831 static SbBool useNameCompat;
832
833 // Returns the threadId of the first thread that called SoDB::init()
834 // it is usefull for nodes that do not support Multi-thread
835 static SbThreadId_t getMainThreadId();
836
838 static bool isInMainThread();
839
840 // OpenInventor Java internal usage only
841 static void resetMainThreadId();
842
843 // remove a header String previously added by calling registerHeader()
844 static SbBool unregisterHeader(const SbString &headerString);
845
846 // Two-Way synchronization between a field and a GlobalField.
847 template <class T> static void
848 syncFieldGlobaly( T& field, const SbName& name )
849 {
850 T* globalField = static_cast<T*>( getGlobalField( name ) );
851 if ( !globalField )
852 {
853 globalField = static_cast<T*>( createGlobalField( name, T::getClassTypeId() ) );
854 globalField->setValue( field.getValue() );
855 }
856 field.connectFrom( globalField );
857 field.setOnValueChangedCallback( [name]( SoField* _field ) {
858 T* field = static_cast<T*>( _field );
859 T* globalField = static_cast<T*>( getGlobalField( name ) );
860 if ( globalField && ( *field != *globalField ) )
861 *globalField = *field;
862 } );
863 }
864
865 // declare TLS class
866 SB_THREAD_TLS_HEADER();
867
868 private:
869#ifdef _WIN32
870 // Key used by openRegistryKey, getRegistryKeyValue, and closeRegistryKey
871 static HKEY s_vsgRegistryKeys;
872#endif
873
874 SoDB();
875 virtual ~SoDB();
876
877 // Protects notification
878 static SbThreadMutex *notifyMutex;
879
880 // Used to read all graphs and paths from the Open Inventor file
881 // specified by the given SoInput.
882 static SoGroup *internalReadAll(SoInput *, SoGroup *);
883
884 // Reads the graph from the external file specified by the given SoInput.
885 // This returns NULL if nothing is read.
886 static SoSeparator *readAllFromInputReaders(SoInput *in);
887
888 // Flag to control what time is used
889 static SbBool useGlobalFieldTime;
890
891 // Store if OpenGL/RenderRngine must be init/fiish
892 // OIV_NOTUSEGPU SoPreference
893 static bool s_notUseGPU;
894
895 // Struct that contains all the information about the Global Database
896 class SoGlobalDBInfos
897 {
898 public:
899 // Constructor (allocate the sensorManager)
900 SoGlobalDBInfos();
901
902 // Init members that depends on node/field
903 void init();
904 // Cleanup members that depends on node/field
905 void cleanup();
906
907 // Destructor
908 ~SoGlobalDBInfos();
909
910 SoSensorManager* m_sensorManager;
911 SoGlobalField* m_globalField;
912 SoTimerSensor* m_realTimeSensor;
913 SoSFRealTime *m_realTime;
914 bool m_isInit;
915 };
916
917 // Thread local storage struct declaration
918 struct MTstruct
919 {
920 SoGlobalDBInfos* globalDBInfos;
921 };
922
923 // get access to global database info
924 // depending on the OIV mode used it is local to Thread or
925 // global to all thread
926 static SoGlobalDBInfos* getGlobalDBInfos();
927
928 // WARNING: this static vars should never be access directly
929 // always use getGlobalDBInfos() accessor
930 static SoGlobalDBInfos* s_globalInfos;
931
932 // How many current notifications
933 static int notifyCount;
934
935 static void realTimeSensorCallback(void *data, SoSensor *sensor);
936
937 // List of valid header strings, and their corresponding callbacks
938 static SbPList *headerList;
939
940 // This dictionary stores field conversion engine types. The key
941 // is created by mangling the types of the two fields to convert
942 // from. The dictionary maps the key to the type of the conversion
943 // engine.
944 static SbDict *conversionDict;
945
946 // Returns a conversionDict key from the two given field type id's.
947 static uint32_t getConversionKey(SoType fromField, SoType toField);
948
949 static void iv2_1PreCallback(void *userData, SoInput *in);
950 static void iv2_0PreCallback(void *userData, SoInput *in);
951 static void iv1_0PreCallback(void *userData, SoInput *in);
952 static void iv2_0PostCallback(void *userData, SoInput *in);
953 static void iv1_0PostCallback(void *userData, SoInput *in);
954
955 // Global maximum number of render caches per node
956 // (used by nodes that create OpenGL display lists or texture objects)
957 static int s_numRenderCaches;
958 static SbBool m_ivTuneAllowed;
959
960 // Render cache creation mode
961 // (used by nodes that create OpenGL display lists)
962 static RenderCacheMode s_renderCacheMode;
963
964 static SbBool m_pickCullingEnabled;
965
966 static int s_initRefCount;
967
968 static SbThreadId_t m_mainThreadId;
969
970 static bool internalInit();
971
972 friend class SoGlobalField;
973 friend class SoVRMLDB;
974 friend class SoVRMLInline;
975};
976
977#if defined(_WIN32)
978#pragma warning( pop )
979#endif
980
981#endif /* _SO_DB_ */
982
983
#define SoEXTENDER_Documented
#define FALSE
Possible value of SbBool.
Definition SbBase.h:75
void SoDBHeaderCB(void *userData, SoInput *in)
Definition SoDB.h:108
#define __INVENTORDLL
virtual void enable(QWidget *w, XtEventHandler f, XtPointer data, void *unused=NULL)
Color vector class.
Definition SbColor.h:82
Character string stored in a hash table.
Definition SbName.h:162
List of generic (void *) pointers.
Definition SbPList.h:77
Class for smart character strings.
Definition SbString.h:202
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable readers...
Class for representation of a time.
Definition SbTime.h:91
Base class for all nodes, paths, and engines.
Definition SoBase.h:111
Scene graph database class.
Definition SoDB.h:219
static const std::vector< SbString > & getLoadedPlugins()
Returns the list of currently loaded plugins (file names).
static void renameGlobalField(const SbName &oldName, const SbName &newName)
Renames the global field named oldName.
static SbBool read(SoInput *in, SoPath *&path)
Reads a graph from the file specified by the given SoInput, returning the resulting path in path.
static SbBool isValidHeader(const char *testString)
This returns TRUE if the given character string is one of the valid Open Inventor file headers,...
static void processEvents()
Process Open Inventor sensor queues (TimerQueue and DelayQueue).
friend class SoGlobalField
Definition SoDB.h:972
static SoField * createGlobalField(const SbName &name, SoType type)
The database maintains a namespace for global fields, making sure that there is at most one instance ...
static void finish()
Frees Open Inventor's internal static memory allocations.
static void setDelaySensorTimeout(const SbTime &t)
This sets the timeout value for sensors that are delay queue sensors (one-shot sensors,...
friend class SoVRMLInline
Definition SoDB.h:974
static SoDEPRECATED void threadInit()
Initializes the database.
static int doSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *userTimeOut)
UNIX/Linux Only In order to keep timer and idle sensors running as expected, it is necessary that ...
static SoType getConverter(SoType fromField, SoType toField)
Returns the field conversion engine registered for the two given field types.
friend class SoVRMLDB
Definition SoDB.h:973
static const std::vector< SbString > & getUnloadedPlugins()
Returns the list of plugins that failed to load (file names).
static SbBool read(SoInput *in, SoNode *&rootNode)
Reads a graph from the file specified by the given SoInput, returning the resulting root node in root...
static bool removePluginsDirectory(const SbString &dirName)
Remove directory from the list of search directories for plugin loading.
static void setRealTimeInterval(const SbTime &deltaT)
The database automatically creates one global field when SoDB::init() is called.
static int getNumHeaders()
Returns the number of valid headers, including standard Open Inventor headers, and user-registered he...
static SoDEPRECATED SbBool isMultiThread()
Returns whether multi-thread support is enabled in Open Inventor.
static void addConverter(SoType fromField, SoType toField, SoType converterEngine)
Registers a field conversion engine that can be used to convert from one type of field to another.
static bool removePlugin(const SbString &fileName)
Unloads the specified plugin library.
static SoDEPRECATED void setRenderCacheMode(RenderCacheMode mode)
Since Open Inventor 10.3, this method has no effect because render caches are automatically managed...
static void readlock()
Acquire a non-exclusive global scene graph read-lock.
static void readunlock()
Release a non-exclusive global scene graph read-lock.
static SbString getHeaderString(int i)
Returns the i'th header.
static SoDEPRECATED void setNumRenderCaches(int)
Since Open Inventor 10.3, this method has no effect because render caches are automatically managed...
Definition SoDB.h:600
static const std::vector< SbString > & getPluginsDirectories()
Returns the list of search directories for plugin loading.
static void writeunlock()
Release the global scene graph write-lock.
static void setIvTuneAllowed(SbBool ivTuneAllowed)
Specifies if launching IvTune interactively using the keyboard shortcut is allowed.
static SoDEPRECATED int getNumRenderCaches()
See method setNumRenderCaches().
Definition SoDB.h:609
static SoDEPRECATED RenderCacheMode getRenderCacheMode()
See setRenderCacheMode().
static bool addPluginsDirectory(const SbString &dirName)
Adds a directory to search for libraries defining new Open Inventor plugins.
static void writelock()
Acquire the global scene graph write-lock.
static void setSystemTimer(SoSystemTimer *timer)
The system dependent timer allows Inventor to manage its sensor queue (for timers,...
static const SbTime & getDelaySensorTimeout()
Returns the current delay queue timeout value.
static SoField * getGlobalField(const SbName &name)
Returns the global field with the given name, or NULL if there is none.
static SoSeparator * readAll(SoInput *in)
Reads all graphs and paths from the file specified by the given SoInput.
static bool addPlugin(const SbString &fileName)
Loads a plugin library.
static SbBool registerHeader(const SbString &headerString, SbBool isBinary, float ivVersion, SoDBHeaderCB *preCB, SoDBHeaderCB *postCB, void *userData=NULL)
Registers the given string as a valid header for input files.
static SbTime getCurrentTime()
Returns the current time.
static const SbTime & getRealTimeInterval()
Returns how often the database is updating the realTime global field.
RenderCacheMode
Render cache modes.
Definition SoDB.h:226
@ AUTO_RENDER_CACHE
Automatically choose mode depending on the hardware.
Definition SoDB.h:238
@ COMPILE_AND_EXECUTE
Display lists are created with COMPILE_AND_EXECUTE mode.
Definition SoDB.h:234
@ COMPILE
Display lists are created with COMPILE mode.
Definition SoDB.h:230
static void removeConverter(SoType fromField, SoType toField)
Remove a previously added converter.
static void init()
Initializes the database.
static SbBool getIvTuneAllowed()
Returns TRUE if IvTune can be launched interactively using the keyboard shortcut.
static SbBool getHeaderData(const SbString &string, SbBool &isBinary, float &ivVersion, SoDBHeaderCB *&preCB, SoDBHeaderCB *&postCB, void *&userData, SbBool substringOK=FALSE)
Passes back the data registered with the given header string, including the flag specifying whether t...
Base class for all fields.
Definition SoField.h:234
Base class for all group nodes.
Definition SoGroup.h:122
Used to read Open Inventor data files.
Definition SoInput.h:363
Class used to check and report library and application consistency.
Definition SoModule.h:41
Abstract base class for all database nodes.
Definition SoNode.h:145
Path that points to a list of hierarchical nodes.
Definition SoPath.h:187
Abstract base class for Open Inventor sensors.
Definition SoSensor.h:97
Group node that saves and restores traversal state.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Common interface...
Sensor that triggers repeatedly at regular intervals.
Stores runtime type information.
Definition SoType.h:98
int SbBool
Boolean type.
Definition SbBase.h:87