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 : Gavin Bell (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_FIELD_CONTAINER_ 00051 #define _SO_FIELD_CONTAINER_ 00052 00053 #include <Inventor/fields/SoSubFieldContainer.h> 00054 #include <Inventor/misc/SoBase.h> 00055 #include <Inventor/STL/set> 00056 00058 // 00059 // Class: SoFieldContainer 00060 // 00061 // Base class for engines and nodes. This takes care of keeping 00062 // track of the fields in a node, or the input fields of an engine; 00063 // reading them, writing them, copying them, etc. 00064 // 00066 00067 class SbDict; 00068 class SoFieldData; 00069 class SoFieldList; 00070 class SoField; 00071 00072 00095 class SoFieldContainer : public SoBase { 00096 00097 public: 00098 00102 static SoType getClassTypeId(); 00103 00107 void setToDefaults(); 00108 00117 SbBool hasDefaultValues() const; 00118 00123 SbBool fieldsAreEqual(const SoFieldContainer *fc) const; 00124 00131 void copyFieldValues(const SoFieldContainer *fc, 00132 SbBool copyConnections = FALSE); 00133 00138 SoNONUNICODE SbBool set(const char *fieldDataString) 00139 { return set(fieldDataString, NULL); } 00140 00166 SbBool set(const SbString& fieldDataString) 00167 { return set(fieldDataString, NULL); } 00168 00175 void get(SbString &fieldDataString) 00176 { get(fieldDataString, NULL); } 00177 00186 virtual int getFields(SoFieldList &list) const; 00187 00191 virtual int getAllFields(SoFieldList &list) const; 00192 // Added this method to allow the eventIns and eventOuts to be returned 00193 // along with the fields 00194 00199 virtual SoField *getField(const SbName &fieldName) const; 00200 00205 virtual SoField *getEventIn(const SbName &fieldName) const; 00206 00211 virtual SoField *getEventOut(const SbName &fieldName) const; 00212 00217 SbBool getFieldName(const SoField *field, SbName &fieldName) const; 00218 00224 SbBool enableNotify(SbBool flag) 00225 { SbBool e = notifyEnabled; notifyEnabled = flag; return e; } 00226 00249 SbBool isNotifyEnabled() const 00250 { return notifyEnabled; } 00251 00261 virtual void setUserData(void *data) 00262 { m_userData = data; } 00263 00268 void *getUserData(void) const 00269 { return m_userData; } 00270 00271 private: 00272 00273 // Setup type information 00274 static void initClass(); 00275 static void exitClass(); 00276 00277 // This is used by the PROTOInstance to get the copy dictionary 00278 SbPList *getCopyDictionary() 00279 { return copyDictList; } 00280 00281 // Versions of set() and get() that take SoInput or SoOutput from 00282 // which to inherit reference dictionary. 00283 SoNONUNICODE SbBool set(const char *fieldDataString, SoInput *dictIn); 00284 SbBool set(const SbString& fieldDataString, SoInput *dictIn); 00285 void get(SbString &fieldDataString, SoOutput *dictOut); 00286 00287 // Propagates modification notification through an instance. 00288 virtual void notify(SoNotList *); 00289 00290 // Manages dependencies between field (and member), update the container according to a change 00291 virtual void fieldHasChanged( SoField* field ); 00292 00293 // Initiates notification from an instance. 00294 virtual void startNotify(); 00295 00296 // Returns whether the about to be set field value is a valid one for 00297 // This container 00298 virtual SbBool validateNewFieldValue(SoField *pField, void *newValue); 00299 00300 // Adds a reference to the instance when writing. isFromField 00301 // indicates whether the reference is from a field-to-field 00302 // connection. 00303 virtual void addWriteReference(SoOutput *out, SbBool isFromField = FALSE); 00304 00305 // Writes instance to SoOutput. (Used only for last stage of writing) 00306 virtual void writeInstance(SoOutput *out); 00307 00308 // Returns whether or not instance is considered 'built-in' to the 00309 // library. Used during writing. 00310 virtual SbBool getIsBuiltIn() const { return FALSE; } 00311 00312 // Returns an SoFieldData structure for the node. Objects with no 00313 // fields should return NULL, which is what the default method does. 00314 virtual const SoFieldData *getFieldData() const; 00315 00316 // During a copy operation, copies of nodes and engines are 00317 // stored in a dictionary, keyed by the original node or engine 00318 // pointer, so that copies can be re-used. These methods 00319 // operate on that dictionary. 00320 00321 // Initializes a new copy dictionary 00322 static void initCopyDict(); 00323 00324 // Adds an instance to the dictionary 00325 static void addCopy(const SoFieldContainer *orig, 00326 const SoFieldContainer *copy); 00327 00328 // If a copy of the given instance is in the dictionary, this 00329 // returns it. Otherwise, it returns NULL. The copy is not changed 00330 // in any way. 00331 static SoFieldContainer *checkCopy(const SoFieldContainer *orig); 00332 00333 // If a copy of the given instance is not in the dictionary, this 00334 // returns NULL. Otherwise, this copies the contents of the 00335 // original into the copy (if not already done) and returns a 00336 // pointer to the copy. 00337 static SoFieldContainer *findCopy(const SoFieldContainer *orig, 00338 SbBool copyConnections); 00339 00340 // Cleans up the dictionary when done. 00341 static void copyDone(); 00342 00343 // Copies the contents of the given node into this instance. The 00344 // default implementation copies just field values and the name. 00345 virtual void copyContents(const SoFieldContainer *fromFC, 00346 SbBool copyConnections); 00347 00348 // During a copy operation, this copies an instance that is 00349 // encountered through a field connection. The default 00350 // implementation just returns the original pointer - no copy is 00351 // done. Subclasses such as nodes and engines handle this 00352 // differently. 00353 virtual SoFieldContainer *copyThroughConnection() const; 00354 00355 // return all fieldContainer in parent path that satify the condition 00356 // defined by the given searchFieldContainerFunc function 00357 typedef bool searchFieldContainerFunc(const SoFieldContainer *fc); 00358 static void searchParents(SoFieldContainer* node, searchFieldContainerFunc *func, std::set<SoFieldContainer*>& fclist); 00359 00360 // calls setSameValueNotificationEnabled(flag) on each fields of this fieldcontainer 00361 void setSameFieldsValueNotificationEnabled(SbBool value); 00362 00363 private: 00364 00365 // Is the subclass a built-in Inventor subclass or an extender subclass? 00366 // This is used to determine whether to read/write field type information. 00367 // MFO SbBool isBuiltIn; 00368 00369 // Default constructor 00370 SoFieldContainer(); 00371 00372 // WARNING : Copy constructor should never be called. 00373 // WARNING : Implemented here only to add a debug message to derived class. 00374 SoFieldContainer(const SoFieldContainer&); 00375 00376 // Destructor 00377 virtual ~SoFieldContainer(); 00378 00379 // Reads stuff into instance. Returns FALSE on error 00380 virtual SbBool readInstance(SoInput *in, unsigned short flags); 00381 00382 static const SoFieldData** getFieldDataPtr() { return NULL; } 00383 00384 private: 00385 00386 // This pointer can be used by user to add informations in all nodes he use. 00387 // The user must allocate and deallocate this pointer. 00388 // Use it with setUserData and getUserData. 00389 void *m_userData; 00390 00391 SbBool notifyEnabled; // Whether notification is enabled 00392 00393 static SoType classTypeId; 00394 00395 // This holds a list of SbDict instances used during copy 00396 // operations. It is a list to allow recursive copying. 00397 static SbPList *copyDictList; 00398 00399 // These are used by SoFieldContainer::get() to hold 00400 // the returned field string 00401 static char *fieldBuf; 00402 static size_t fieldBufSize; 00403 00404 // And this callback is used to unref() all instances in the 00405 // copyDict when copyDone() is called 00406 static void unrefCopy(uintptr_t key, void *instPtr); 00407 00408 // This is used to reallocate the string buffer used by 00409 // SoFieldContainer::get() 00410 static void *reallocFieldBuf(void *ptr, size_t newSize); 00411 00412 private: 00413 // These 2 pointers allow to keep a linked list of all SoFieldContainer 00414 // created to be able to resync them in case of cluster Connection/disconnction. 00415 // they are fully managed by the SoFieldContainerExt class. 00416 SoFieldContainer *cacheNext; 00417 SoFieldContainer *cachePrev; 00418 friend class SoFieldContainerExt; 00419 00420 }; 00421 00422 #endif /* _SO_FIELD_CONTAINER_ */ 00423 00424 00425