Open Inventor Release 2024.1.1
 
Loading...
Searching...
No Matches
SoDB.h
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-2024 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>
57#include <Inventor/threads/SbThread.h>
58#include <Inventor/threads/SbThreadLocalStorage.h>
59
60#ifndef LIBRARYBUILD
61// uneeded header be kept for application built compatibility
62#include <Inventor/sensors/SoSensorManager.h>
63#include <Inventor/SbPList.h>
64#include <Inventor/SoPreferences.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
88#include <Inventor/SoInventorLibName.h>
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
111typedef void SoDBHeaderCB(void *userData, SoInput *in);
112
114//
115// Class: SoDB
116//
117// Inventor database class. This class maintains all the global
118// information necessary for reading and writing, naming classes, and
119// so on. All public methods on this class are static - users should
120// never explicitly create instances of this class. Initialization of
121// the database class causes a global instance to be created.
122//
124
222class SoDB {
223
224 public:
225
226SoDEPRECATED enum
242 };
243
249 static void init();
250
262 static void finish();
263
264#if 1 SoDEPRECATED
273 static void threadInit();
274#endif
286 static void setSystemTimer(SoSystemTimer* timer);
287
311 static SbBool read(SoInput *in, SoNode *&rootNode);
312
338 static SbBool read(SoInput *in, SoPath *&path);
339
357
370 static SbBool registerHeader(const SbString &headerString,
371 SbBool isBinary,
372 float ivVersion,
373 SoDBHeaderCB *preCB,
374 SoDBHeaderCB *postCB,
375 void *userData = NULL);
387 static SbBool getHeaderData(const SbString &string,
388 SbBool &isBinary,
389 float &ivVersion,
390 SoDBHeaderCB *&preCB,
391 SoDBHeaderCB *&postCB,
392 void *&userData,
393 SbBool substringOK = FALSE);
398 static int getNumHeaders();
399
405
411 static SbBool isValidHeader(const char *testString);
412
440 static SoField *createGlobalField(const SbName &name, SoType type);
441
447 static SoField *getGlobalField(const SbName &name);
448
456 static void renameGlobalField(const SbName &oldName, const SbName &newName);
457
493 static void setRealTimeInterval(const SbTime &deltaT);
494
504
521 static void setDelaySensorTimeout(const SbTime &t);
522
528
533 static void processEvents();
534
545 static int doSelect(int nfds, fd_set *readfds, fd_set *writefds,
546 fd_set *exceptfds, struct timeval *userTimeOut);
547
548#if 1 SoDEPRECATED
554#endif
571 static void writelock();
572
577 static void writeunlock();
578
589 static void readlock();
590
595 static void readunlock();
596
597#if 1 SoDEPRECATED
603 static void setNumRenderCaches( int /*num*/ )
604 {}
605#endif
607#if 1 SoDEPRECATED
613 { return s_numRenderCaches; }
614#endif
616#if 1 SoDEPRECATED
623#endif
625#if 1 SoDEPRECATED
631#endif
637
663 static bool addPlugin( const SbString& fileName );
664
669 static bool removePlugin( const SbString& fileName );
670
675 static const std::vector<SbString>& getLoadedPlugins();
676
681 static const std::vector<SbString>& getUnloadedPlugins();
682
687 static bool addPluginsDirectory( const SbString& dirName );
688
693 static bool removePluginsDirectory( const SbString& dirName );
694
699 static const std::vector<SbString>& getPluginsDirectories();
700
701SoEXTENDER_Documented public:
708 static void addConverter(SoType fromField, SoType toField,
709 SoType converterEngine);
710
716 static SoType getConverter(SoType fromField, SoType toField);
717
722 static void removeConverter(SoType fromField, SoType toField);
723
728 static void setIvTuneAllowed(SbBool ivTuneAllowed);
729
735
736private:
737
738#ifdef _WIN32
747 static long openRegistryKey(const SbBool readOnlyFlag=FALSE);
748
754 static long getRegistryKeyValue(LPTSTR keyName,
755 LPTSTR lpValueName, // address of name of value to query
756 LPDWORD lpType, // address of buffer for value type
757 LPBYTE lpData, // address of data buffer
758 LPDWORD lpcbData, // address of data buffer size
759 const SbBool readOnlyFlag=FALSE // readOnly access if TRUE
760 );
761
765 static long closeRegistryKey();
766
767#endif //_WIN32
768
769 private:
770
771#if 1 SoDEPRECATED
776 static void threadFinish();
777#endif
779 // The following two functions are internal-only for now because we do
780 // not have a reliable cross-platform implementation of trylock for a
781 // read-write lock.
782
783 // Provides a global try-write-lock mutex (see threads/SbThreadRWMutex.h)
784 static SbBool trywritelock();
785
786 // Provides a global try-read-lock mutex (see threads/SbThreadRWMutex.h)
787 static SbBool tryreadlock();
788
789 // Get ptr to global RWMutex for use with autolock
790 // just an alias to SoInventorBase::getGlobalMutex()
791 static SbThreadRWMutex *getGlobalMutex()
792 { return SoInventorBase::getGlobalMutex(); }
793
794 // Accesses sensor manager
795 static SoSensorManager *getSensorManager();
796
797 // Accesses UNLOCK sensor manager
798 static SoSensorManager *getUnlockSensorManager();
799
800 // Returns TRUE if database is initialized for the current thread.
801 static bool isInitialized();
802
803 // Returns FALSE if pick culling has been disabled
804 static SbBool getPickCullingEnabled()
805 { return m_pickCullingEnabled; }
806
807 static const char* profileName;
808
809 // This is called when some instance begins or ends a notification
810 // process. It increments or decrements a counter of notifications
811 // in progress. When the counter reaches 0, all priority 0
812 // (immediate) delay queue sensors are triggered. By doing this,
813 // all notification has a chance to finish before any evaluation
814 // (due to data sensors, primarily) takes place.
815 static void startNotify();
816 static SbBool isNotifying();
817 static void endNotify();
818
819 // Enables/disables realTime sensor processing
820 static void enableRealTimeSensor(SbBool enable);
821
822 // Reads a base of any type, returning a pointer to it. Returns
823 // FALSE on error.
824 static SbBool read(SoInput *in, SoBase *&base);
825
826 static SbBool m_readingAll;
827
828 // Returns a copy of the path to the SoInput file (dirname).
829 // If in does not contain a filename or if in is NULL, returns an empty string.
830 // Returns empty string on error.
831 static SbString getDirNameFromFullFileName(SoInput *in);
832
833 // Flag to control use of valid names
834 static SbBool useNameCompat;
835
836 // Returns the threadId of the first thread that called SoDB::init()
837 // it is usefull for nodes that do not support Multi-thread
838 static SbThreadId_t getMainThreadId();
839
841 static bool isInMainThread();
842
843 // OpenInventor Java internal usage only
844 static void resetMainThreadId();
845
846 // remove a header String previously added by calling registerHeader()
847 static SbBool unregisterHeader(const SbString &headerString);
848
849 // Two-Way synchronization between a field and a GlobalField.
850 template <class T> static void
851 syncFieldGlobaly( T& field, const SbName& name )
852 {
853 T* globalField = static_cast<T*>( getGlobalField( name ) );
854 if ( !globalField )
855 {
856 globalField = static_cast<T*>( createGlobalField( name, T::getClassTypeId() ) );
857 globalField->setValue( field.getValue() );
858 }
859 field.connectFrom( globalField );
860 field.setOnValueChangedCallback( [name]( SoField* _field ) {
861 T* field = static_cast<T*>( _field );
862 T* globalField = static_cast<T*>( getGlobalField( name ) );
863 if ( globalField && ( *field != *globalField ) )
864 *globalField = *field;
865 } );
866 }
867
868 // declare TLS class
869 SB_THREAD_TLS_HEADER();
870
871 private:
872#ifdef _WIN32
873 // Key used by openRegistryKey, getRegistryKeyValue, and closeRegistryKey
874 static HKEY s_vsgRegistryKeys;
875#endif
876
877 SoDB();
878 virtual ~SoDB();
879
880 // Protects notification
881 static SbThreadMutex *notifyMutex;
882
883 // Used to read all graphs and paths from the Open Inventor file
884 // specified by the given SoInput.
885 static SoGroup *internalReadAll(SoInput *, SoGroup *);
886
887 // Reads the graph from the external file specified by the given SoInput.
888 // This returns NULL if nothing is read.
889 static SoSeparator *readAllFromInputReaders(SoInput *in);
890
891 // Flag to control what time is used
892 static SbBool useGlobalFieldTime;
893
894 // Store if OpenGL/RenderRngine must be init/fiish
895 // OIV_NOTUSEGPU SoPreference
896 static bool s_notUseGPU;
897
898 // Struct that contains all the information about the Global Database
899 class SoGlobalDBInfos
900 {
901 public:
902 // Constructor (allocate the sensorManager)
903 SoGlobalDBInfos();
904
905 // Init members that depends on node/field
906 void init();
907 // Cleanup members that depends on node/field
908 void cleanup();
909
910 // Destructor
911 ~SoGlobalDBInfos();
912
913 SoSensorManager* m_sensorManager;
914 SoGlobalField* m_globalField;
915 SoTimerSensor* m_realTimeSensor;
916 SoSFRealTime *m_realTime;
917 bool m_isInit;
918 };
919
920 // Thread local storage struct declaration
921 struct MTstruct
922 {
923 SoGlobalDBInfos* globalDBInfos;
924 };
925
926 // get access to global database info
927 // depending on the OIV mode used it is local to Thread or
928 // global to all thread
929 static SoGlobalDBInfos* getGlobalDBInfos();
930
931 // WARNING: this static vars should never be access directly
932 // always use getGlobalDBInfos() accessor
933 static SoGlobalDBInfos* s_globalInfos;
934
935 // How many current notifications
936 static int notifyCount;
937
938 static void realTimeSensorCallback(void *data, SoSensor *sensor);
939
940 // List of valid header strings, and their corresponding callbacks
941 static SbPList *headerList;
942
943 // This dictionary stores field conversion engine types. The key
944 // is created by mangling the types of the two fields to convert
945 // from. The dictionary maps the key to the type of the conversion
946 // engine.
947 static SbDict *conversionDict;
948
949 // Returns a conversionDict key from the two given field type id's.
950 static uint32_t getConversionKey(SoType fromField, SoType toField);
951
952 static void iv2_1PreCallback(void *userData, SoInput *in);
953 static void iv2_0PreCallback(void *userData, SoInput *in);
954 static void iv1_0PreCallback(void *userData, SoInput *in);
955 static void iv2_0PostCallback(void *userData, SoInput *in);
956 static void iv1_0PostCallback(void *userData, SoInput *in);
957
958 // Global maximum number of render caches per node
959 // (used by nodes that create OpenGL display lists or texture objects)
960 static int s_numRenderCaches;
961 static SbBool m_ivTuneAllowed;
962
963 // Render cache creation mode
964 // (used by nodes that create OpenGL display lists)
965 static RenderCacheMode s_renderCacheMode;
966
967 static SbBool m_pickCullingEnabled;
968
969 static int s_initRefCount;
970
971 static SbThreadId_t m_mainThreadId;
972
973 static bool internalInit();
974
975 friend class SoGlobalField;
976 friend class SoVRMLDB;
977 friend class SoVRMLInline;
978};
979
980#if defined(_WIN32)
981#pragma warning( pop )
982#endif
983
984#endif /* _SO_DB_ */
985
986
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:222
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:975
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:977
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:976
static const std::vector< SbString > & getUnloadedPlugins()
Returns the list of plugins that failed to load (file names).
void SoDBHeaderCB(void *userData, SoInput *in)
Definition SoDB.h:111
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:603
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:612
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:229
@ AUTO_RENDER_CACHE
Automatically choose mode depending on the hardware.
Definition SoDB.h:241
@ COMPILE_AND_EXECUTE
Display lists are created with COMPILE_AND_EXECUTE mode.
Definition SoDB.h:237
@ COMPILE
Display lists are created with COMPILE mode.
Definition SoDB.h:233
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:100
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