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