Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SoFieldContainer.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 : Gavin Bell (MMM yyyy)
25**=======================================================================*/
26/*=======================================================================
27 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
28 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
29 *** ***
30 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
31 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
32 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
33 *** ***
34 *** RESTRICTED RIGHTS LEGEND ***
35 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
36 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
37 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
38 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
39 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
40 *** ***
41 *** COPYRIGHT (C) 1996-2019 BY FEI S.A.S, ***
42 *** BORDEAUX, FRANCE ***
43 *** ALL RIGHTS RESERVED ***
44**=======================================================================*/
45/*=======================================================================
46** Modified by : VSG (MMM YYYY)
47**=======================================================================*/
48
49
50#ifndef _SO_FIELD_CONTAINER_
51#define _SO_FIELD_CONTAINER_
52
53#include <Inventor/fields/SoSubFieldContainer.h>
54#include <Inventor/misc/SoBase.h>
55#include <Inventor/STL/set>
56
58//
59// Class: SoFieldContainer
60//
61// Base class for engines and nodes. This takes care of keeping
62// track of the fields in a node, or the input fields of an engine;
63// reading them, writing them, copying them, etc.
64//
66
67class SbDict;
68class SoFieldData;
69class SoFieldList;
70class SoField;
71
72
94class SoFieldContainer : public SoBase {
95
96 public:
97
102
107
117
123
131 SbBool copyConnections = FALSE);
132
137 SoNONUNICODE SbBool set(const char *fieldDataString)
138 { return set(fieldDataString, NULL); }
139
165 SbBool set(const SbString& fieldDataString)
166 { return set(fieldDataString, NULL); }
167
174 void get(SbString &fieldDataString)
175 { get(fieldDataString, NULL); }
176
185 virtual int getFields(SoFieldList &list) const;
186
190 virtual int getAllFields(SoFieldList &list) const;
191 // Added this method to allow the eventIns and eventOuts to be returned
192 // along with the fields
193
198 virtual SoField *getField(const SbName &fieldName) const;
199
204 virtual SoField *getEventIn(const SbName &fieldName) const;
205
210 virtual SoField *getEventOut(const SbName &fieldName) const;
211
216 SbBool getFieldName(const SoField *field, SbName &fieldName) const;
217
224 { SbBool e = notifyEnabled; notifyEnabled = flag; return e; }
225
249 { return notifyEnabled; }
250
260 virtual void setUserData(void *data)
261 { m_userData = data; }
262
267 void *getUserData(void) const
268 { return m_userData; }
269
270 private:
271
272 // Setup type information
273 static void initClass();
274 static void exitClass();
275
280 void connectFromAllCommonFields(const SoFieldContainer* source);
281
288 void disconnectFromAllCommonFields(const SoFieldContainer* source);
289
290 // This is used by the PROTOInstance to get the copy dictionary
291 SbPList *getCopyDictionary()
292 { return copyDictList; }
293
294 // Versions of set() and get() that take SoInput or SoOutput from
295 // which to inherit reference dictionary.
296 SoNONUNICODE SbBool set(const char *fieldDataString, SoInput *dictIn);
297 SbBool set(const SbString& fieldDataString, SoInput *dictIn);
298 void get(SbString &fieldDataString, SoOutput *dictOut);
299
300 // Propagates modification notification through an instance.
301 virtual void notify(SoNotList *);
302
303 // Manages dependencies between field (and member), update the container according to a change
304 virtual void fieldHasChanged( SoField* field );
305
306 // Initiates notification from an instance.
307 virtual void startNotify();
308
309 // Returns whether the about to be set field value is a valid one for
310 // This container
311 virtual SbBool validateNewFieldValue(SoField *pField, void *newValue);
312
313 // Adds a reference to the instance when writing. isFromField
314 // indicates whether the reference is from a field-to-field
315 // connection.
316 virtual void addWriteReference(SoOutput *out, SbBool isFromField = FALSE);
317
318 // Writes instance to SoOutput. (Used only for last stage of writing)
319 virtual void writeInstance(SoOutput *out);
320
321 // Returns whether or not instance is considered 'built-in' to the
322 // library. Used during writing.
323 virtual SbBool getIsBuiltIn() const { return FALSE; }
324
325 // Returns an SoFieldData structure for the node. Objects with no
326 // fields should return NULL, which is what the default method does.
327 virtual const SoFieldData *getFieldData() const;
328
329 // During a copy operation, copies of nodes and engines are
330 // stored in a dictionary, keyed by the original node or engine
331 // pointer, so that copies can be re-used. These methods
332 // operate on that dictionary.
333
334 // Initializes a new copy dictionary
335 static void initCopyDict();
336
337 // Adds an instance to the dictionary
338 static void addCopy(const SoFieldContainer *orig,
339 const SoFieldContainer *copy);
340
341 // If a copy of the given instance is in the dictionary, this
342 // returns it. Otherwise, it returns NULL. The copy is not changed
343 // in any way.
344 static SoFieldContainer *checkCopy(const SoFieldContainer *orig);
345
346 // If a copy of the given instance is not in the dictionary, this
347 // returns NULL. Otherwise, this copies the contents of the
348 // original into the copy (if not already done) and returns a
349 // pointer to the copy.
350 static SoFieldContainer *findCopy(const SoFieldContainer *orig,
351 SbBool copyConnections);
352
353 // Cleans up the dictionary when done.
354 static void copyDone();
355
356 // Copies the contents of the given node into this instance. The
357 // default implementation copies just field values and the name.
358 virtual void copyContents(const SoFieldContainer *fromFC,
359 SbBool copyConnections);
360
361 // During a copy operation, this copies an instance that is
362 // encountered through a field connection. The default
363 // implementation just returns the original pointer - no copy is
364 // done. Subclasses such as nodes and engines handle this
365 // differently.
366 virtual SoFieldContainer *copyThroughConnection() const;
367
368 // return all fieldContainer in parent path that satify the condition
369 // defined by the given searchFieldContainerFunc function
370 typedef bool searchFieldContainerFunc(const SoFieldContainer *fc);
371 static void searchParents(SoFieldContainer* node, searchFieldContainerFunc *func, std::set<SoFieldContainer*>& fclist);
372
373 private:
374
375 // Is the subclass a built-in Inventor subclass or an extender subclass?
376 // This is used to determine whether to read/write field type information.
377 // MFO SbBool isBuiltIn;
378
379 // Default constructor
381
382 // WARNING : Copy constructor should never be called.
383 // WARNING : Implemented here only to add a debug message to derived class.
385
386 // Destructor
387 virtual ~SoFieldContainer();
388
389 // Reads stuff into instance. Returns FALSE on error
390 virtual SbBool readInstance(SoInput *in, unsigned short flags);
391
392 static const SoFieldData** getFieldDataPtr() { return NULL; }
393
394 private:
395
396 // This pointer can be used by user to add informations in all nodes he use.
397 // The user must allocate and deallocate this pointer.
398 // Use it with setUserData and getUserData.
399 void *m_userData;
400
401 SbBool notifyEnabled; // Whether notification is enabled
402
403 static SoType classTypeId;
404
405 // This holds a list of SbDict instances used during copy
406 // operations. It is a list to allow recursive copying.
407 static SbPList *copyDictList;
408
409 // These are used by SoFieldContainer::get() to hold
410 // the returned field string
411 static char *fieldBuf;
412 static size_t fieldBufSize;
413
414 // And this callback is used to unref() all instances in the
415 // copyDict when copyDone() is called
416 static void unrefCopy(uintptr_t key, void *instPtr);
417
418 // This is used to reallocate the string buffer used by
419 // SoFieldContainer::get()
420 static void *reallocFieldBuf(void *ptr, size_t newSize);
421
422private:
423 // These 2 pointers allow to keep a linked list of all SoFieldContainer
424 // created to be able to resync them in case of cluster Connection/disconnction.
425 // they are fully managed by the SoFieldContainerExt class.
426 SoFieldContainer *cacheNext;
427 SoFieldContainer *cachePrev;
429
430};
431
432#endif /* _SO_FIELD_CONTAINER_ */
433
434
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
Base class for all nodes, paths, and engines.
Definition SoBase.h:111
Abstract base class for objects that contain fields.
SoNONUNICODE SbBool set(const char *fieldDataString)
Sets one or more fields in this object to the values specified in the given string,...
SbBool getFieldName(const SoField *field, SbName &fieldName) const
Returns the name of the given field in the fieldName argument.
virtual int getAllFields(SoFieldList &list) const
Returns a list of fields, including the eventIn's and eventOut's.
virtual SoField * getEventIn(const SbName &fieldName) const
Returns a the eventIn with the given name.
void get(SbString &fieldDataString)
Returns the values of the fields of this object in the Open Inventor ASCII file format in the given s...
static SoType getClassTypeId()
Returns the type of this class.
SbBool fieldsAreEqual(const SoFieldContainer *fc) const
Returns TRUE if this object's fields are exactly equal to fc's fields.
void setToDefaults()
Sets all fields in this object to their default values.
SbBool enableNotify(SbBool flag)
Notification at this Field Container is enabled (if flag == TRUE) or disabled (if flag == FALSE).
void * getUserData(void) const
Gets user application data.
virtual SoField * getField(const SbName &fieldName) const
Returns a the field of this object whose name is fieldName.
virtual void setUserData(void *data)
Sets application data.
SbBool hasDefaultValues() const
Returns TRUE if all of the object's fields have their default values.
friend class SoFieldContainerExt
SbBool set(const SbString &fieldDataString)
Sets one or more fields in this object to the values specified in the given string,...
virtual SoField * getEventOut(const SbName &fieldName) const
Returns the eventOut with the given name.
void copyFieldValues(const SoFieldContainer *fc, SbBool copyConnections=FALSE)
Copies the contents of fc's fields into this object's fields.
virtual int getFields(SoFieldList &list) const
Appends references to all of this object's fields to resultList, and returns the number of fields app...
SbBool isNotifyEnabled() const
Notification is the process of telling interested objects that this object has changed.
Base class for all fields.
Definition SoField.h:234
Maintains a list of pointers to fields.
Definition SoFieldList.h:72
Used to read Open Inventor data files.
Definition SoInput.h:363
Used to write Open Inventor data files.
Definition SoOutput.h:186
Stores runtime type information.
Definition SoType.h:98
int SbBool
Boolean type.
Definition SbBase.h:87