Open Inventor Reference
SoField.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37
38/*
39 * Copyright (C) 1990,91 Silicon Graphics, Inc.
40 *
41 _______________________________________________________________________
42 ______________ S I L I C O N G R A P H I C S I N C . ____________
43 |
44 | $Revision: 1.1.1.1 $
45 |
46 | Description:
47 | Defines the SoField class, which is the base class for all fields.
48 |
49 | Author(s) : Paul S. Strauss, Nick Thompson, Gavin Bell
50 |
51 ______________ S I L I C O N G R A P H I C S I N C . ____________
52 _______________________________________________________________________
53 */
54
55#ifndef _SO_FIELD_
56#define _SO_FIELD_
57
58#include <Inventor/SbString.h>
59#include <Inventor/SoType.h>
61
62class SoEngineOutput;
64struct SoFieldAuditorInfo;
66class SoFieldList;
67class SoInput;
68class SoNotList;
69class SoOutput;
70
71
74
184
186 public:
188 virtual ~SoField();
189
193 void setIgnored(bool ig);
196 bool isIgnored() const { return flags.ignored; }
197
203 bool isDefault() const { return flags.hasDefault; }
204
206 static SoType getClassTypeId() { return classTypeId; }
207
209 virtual SoType getTypeId() const = 0;
210
223 bool isOfType(SoType type) const;
224
240 void enableConnection(bool flag);
244 { return flags.connectionEnabled; }
245
248 bool connectFrom(SoEngineOutput *engineOutput);
249 bool connectFrom(SoField *field);
250
254
256 bool isConnected() const { return flags.connected; }
259 { return (flags.connected && flags.fromEngine); }
262 { return (flags.connected && ! flags.fromEngine); }
263
268 bool getConnectedEngine(SoEngineOutput *&engineOutput) const;
273 bool getConnectedField(SoField *&field) const;
274
279
282
289 bool set(const char *valueString);
290
293 void get(SbString &valueString);
294
301 virtual void touch();
302
305 bool operator ==(const SoField &f) const
306 { return isSame(f); }
309 bool operator !=(const SoField &f) const
310 { return ! isSame(f); }
311
312 SoEXTENDER protected:
315
316 SoINTERNAL public:
317 static void initClass();
318
320 static void initClasses();
321
323 void setDefault(bool def) { flags.hasDefault = (def ? 1 : 0 ); }
324
326 virtual void startNotify();
327 virtual void notify(SoNotList *list);
328
332
336 bool shouldWrite() const;
337
339 void addAuditor(void *auditor, SoNotRec::Type type);
340 void removeAuditor(void *auditor, SoNotRec::Type type);
341
345 bool enableNotify(bool flag);
346 bool isNotifyEnabled() const
347 { return flags.notifyEnabled; }
348
361 bool enableContainerNotify(bool flag);
363 { return flags.notifyContainerEnabled; }
364
370 virtual void connectionStatusChanged(int numConnections);
371
375 bool isReadOnly() const { return flags.readOnly; }
376
380 virtual bool isSame(const SoField &f) const = 0;
381
383 virtual void copyFrom(const SoField &f) = 0;
384
389 virtual void fixCopy(bool copyConnections);
390
397 virtual bool referencesCopy() const;
398
401 void copyConnection(const SoField *fromField);
402
406 virtual bool read(SoInput *in, const SbName &name);
407
409 virtual void write(SoOutput *out, const SbName &name) const;
410
412 virtual void countWriteRefs(SoOutput *out) const;
413
418 void evaluate() const
419 { if (flags.dirty) evaluateConnection(); }
420
421 protected:
425 void valueChanged(bool resetDefault = TRUE);
426
430 virtual void evaluateConnection() const;
431
433 virtual bool readValue(SoInput *in) = 0;
434
436 virtual bool readConnection(SoInput *in);
437
439 virtual void writeValue(SoOutput *out) const = 0;
440
442 virtual void writeConnection(SoOutput *out) const;
443
444 private:
445 static SoType classTypeId;
446
448 static char *fieldBuf;
449 static int fieldBufSize;
450
452 struct {
453 unsigned int hasDefault : 1;
454 unsigned int ignored : 1;
455 unsigned int connected : 1;
456 unsigned int converted : 1;
457 unsigned int fromEngine : 1;
458 unsigned int connectionEnabled : 1;
459 unsigned int notifyEnabled : 1;
460 unsigned int hasAuditors : 1;
461 unsigned int isEngineModifying : 1;
462 unsigned int readOnly : 1;
464 unsigned int dirty : 1;
466 unsigned int notifyContainerEnabled : 1;
467 } flags;
468
474 union {
476 SoFieldAuditorInfo *auditorInfo;
477 };
478
480 void createAuditorInfo();
481
484 SoFieldConverter *createConverter(const SoType &fromFieldType) const;
485
487 void reallyDisconnect();
488
491 SoFieldConverter * getConverter() const;
492
494 void getConnectionInfo(SoFieldContainer *&, SbName&) const;
495
498 static void * reallocFieldBuf(void *ptr, size_t newSize);
499
500friend class SoEngineOutput;
501};
502
503
506
536
538 public:
540 virtual ~SoSField();
541
543 static SoType getClassTypeId() { return classTypeId; }
544
545 protected:
548
549 SoINTERNAL public:
550 static void initClass();
551
552 static void * createInstance();
553
554 private:
555 static SoType classTypeId;
556
558 virtual bool readValue(SoInput *in) = 0;
559
561 virtual void writeValue(SoOutput *out) const = 0;
562};
563
564
567
627
629
630 public:
632 virtual ~SoMField();
633
635 int getNum() const { evaluate(); return num; }
636
639 void setNum(int num);
640
647 virtual void deleteValues(int start, int num = -1);
648
653 virtual void insertSpace(int start, int num);
654
658 bool set1(int index, const char *valueString);
662 void get1(int index, SbString &valueString);
663
665 static SoType getClassTypeId() { return classTypeId; }
666
667 SoINTERNAL public:
668 static void initClass();
669
670 static void * createInstance();
671
672 protected:
673 int num;
674 int maxNum;
675
678
680 virtual void makeRoom(int newNum);
681
682 private:
683 static SoType classTypeId;
684
686 static char *fieldBuf;
687 static int fieldBufSize;
688
691 virtual void allocValues(int num) = 0;
692
694 virtual void deleteAllValues() = 0;
695
697 virtual void copyValue(int to, int from) = 0;
698
700 virtual bool readValue(SoInput *in);
701
703 virtual bool read1Value(SoInput *in, int index) = 0;
704
706 virtual void writeValue(SoOutput *out) const;
707
709 virtual void write1Value(SoOutput *out, int index) const = 0;
710
712 virtual bool readBinaryValues(SoInput *in, int numToRead);
713
715 virtual void writeBinaryValues(SoOutput *out) const;
716
718 virtual int getNumValuesPerLine() const;
719
722 static void * reallocFieldBuf(void *ptr, size_t newSize);
723};
724
725#endif /* _SO_FIELD_ */
#define SoEXTENDER
Provide inline template functions for abs, swap, min, max, and clamp.
Definition SbBasic.h:154
#define TRUE
Definition SbBasic.h:76
#define SoINTERNAL
Definition SbBasic.h:155
INVENTOR_API bool operator!=(const SbBox3f &b1, const SbBox3f &b2)
Definition SbBox.h:207
INVENTOR_API bool operator==(const SbBox3f &b1, const SbBox3f &b2)
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition SbSystem.h:77
Character string stored in a hash table.
Definition SbString.h:264
Class for smart character strings.
Definition SbString.h:85
Class for all engine outputs.
Definition SoEngine.h:228
Abstract base class for objects that contain fields.
Abstract base class for all field converter engines.
Maintains a list of pointers to fields.
Definition SoLists.h:426
Base class for all fields.
Definition SoField.h:185
static void initClass()
virtual bool readValue(SoInput *in)=0
Reads value(s) of field.
virtual void connectionStatusChanged(int numConnections)
Indicates to a field that a change has been made involving a connection from it (as source) to anothe...
bool isIgnored() const
Gets the ignore flag for this field.
Definition SoField.h:196
void setIgnored(bool ig)
Sets the ignore flag for this field.
virtual bool read(SoInput *in, const SbName &name)
Reads value of field (with given name) from file as defined by SoInput.
virtual SoType getTypeId() const =0
Return the type identifier for this field instance (SoField *).
bool isConnectedFromField() const
Returns TRUE if the field is connected to another field.
Definition SoField.h:261
virtual void fixCopy(bool copyConnections)
After a field value has been copied using copyFrom(), this is called to allow fields to update the co...
unsigned int notifyEnabled
Notification is enabled.
Definition SoField.h:459
virtual void writeConnection(SoOutput *out) const
Writes field connection.
bool connectFrom(SoField *field)
virtual void copyFrom(const SoField &f)=0
Copies the value from one field to another, assuming same subclass.
bool getConnectedField(SoField *&field) const
Returns TRUE if this field is being written into by another field, and returns the field it is connec...
bool connectFrom(SoEngineOutput *engineOutput)
Connects the field to the given output of an engine or to another field.
unsigned int hasAuditors
Connected, or FieldSensor.
Definition SoField.h:460
bool isOfType(SoType type) const
Returns TRUE if this field is the given type or derived from that type.
bool set(const char *valueString)
Sets the field to the given value, which is an ASCII string in the Inventor file format.
virtual bool referencesCopy() const
This returns TRUE if this field contains a reference to a node or engine that is copied during a copy...
void enableConnection(bool flag)
Field connections may be enabled and disabled.
unsigned int notifyContainerEnabled
If set to 0, the container is not notified on Field changed.
Definition SoField.h:466
virtual void startNotify()
Initiates or propagates notification through container.
void disconnect()
Disconnect the field from whatever it was connected to.
virtual bool readConnection(SoInput *in)
Reads connection.
bool enableNotify(bool flag)
Indicates whether notification will propagate as the result of setting the field value.
SoFieldAuditorInfo * auditorInfo
Definition SoField.h:476
void addAuditor(void *auditor, SoNotRec::Type type)
Adds/removes an auditor to/from list.
unsigned int fromEngine
Connection is from engine.
Definition SoField.h:457
bool isReadOnly() const
If this returns TRUE, it means we're in the middle of doing a setValue()+valueChanged() and values fr...
Definition SoField.h:375
unsigned int connected
Field connected from something.
Definition SoField.h:455
unsigned int readOnly
Must not write into this field.
Definition SoField.h:462
unsigned int isEngineModifying
Engine evaluating.
Definition SoField.h:461
bool isConnectedFromEngine() const
Returns TRUE if the field is connected to an engine's output.
Definition SoField.h:258
SoFieldContainer * container
Definition SoField.h:475
void evaluate() const
Evaluates the field from whatever it's connected to.
Definition SoField.h:418
bool shouldWrite() const
Returns TRUE if the field really needs to be written out.
virtual void touch()
Simulates a change to the field, causing attached sensors to fire, connected fields and engines to be...
bool getConnectedEngine(SoEngineOutput *&engineOutput) const
Returns TRUE if this field is being written into by an engine, and returns the engine output it is co...
bool isConnectionEnabled() const
Returns FALSE if connections to this field are disabled.
Definition SoField.h:243
bool isDefault() const
Gets the state of default flag of the field.
Definition SoField.h:203
virtual void write(SoOutput *out, const SbName &name) const
Writes field (with given name) to file as defined by SoOutput.
void removeAuditor(void *auditor, SoNotRec::Type type)
void setContainer(SoFieldContainer *cont)
Sets the containing node.
unsigned int hasDefault
Field is set to default value.
Definition SoField.h:453
bool isNotifyEnabled() const
Definition SoField.h:346
virtual void evaluateConnection() const
Evaluates the field or engine the field is connected to, storing the result in the field.
virtual ~SoField()
Destructor.
static void initClasses()
Initialize ALL Inventor node classes.
SoField()
Constuctor:
bool enableContainerNotify(bool flag)
Indicates whether notification will propagate to the SoFieldContainer that owns the field.
unsigned int ignored
Field value is to be ignored.
Definition SoField.h:454
virtual void notify(SoNotList *list)
static SoType getClassTypeId()
Return the type identifier for this field class.
Definition SoField.h:206
int getForwardConnections(SoFieldList &list) const
Adds pointers to all of the fields that this field is writing into (either fields in nodes,...
bool isContainerNotifyEnabled() const
Definition SoField.h:362
virtual void countWriteRefs(SoOutput *out) const
Counts write-references on field to prepare for writing.
void valueChanged(bool resetDefault=TRUE)
Called by an instance to indicate that a value has changed.
void get(SbString &valueString)
Returns the value of the field in the Inventor file format, even if the field has its default value.
void copyConnection(const SoField *fromField)
Copies connection from one field to another.
unsigned int converted
Connection required converter.
Definition SoField.h:456
unsigned int dirty
Field was notified and needs evaluation.
Definition SoField.h:464
unsigned int connectionEnabled
Connection is enabled.
Definition SoField.h:458
virtual void writeValue(SoOutput *out) const =0
Writes value(s) of field.
virtual bool isSame(const SoField &f) const =0
Returns TRUE if the given field is of the same type and has the same value(s) as this.
void setDefault(bool def)
Sets default flag.
Definition SoField.h:323
SoFieldContainer * getContainer() const
Returns the containing node or engine.
bool isConnected() const
Returns TRUE if the field is connected to anything.
Definition SoField.h:256
Used to read Inventor data files.
Definition SoInput.h:128
Base class for all multiple-valued fields.
Definition SoField.h:628
virtual ~SoMField()
Destructor.
virtual void makeRoom(int newNum)
Make sure there is room for newNum vals.
static void initClass()
int getNum() const
Returns the number of values currently in the field.
Definition SoField.h:635
void get1(int index, SbString &valueString)
This is equivalent to the get() method of SoField, but operates on only one value.
virtual void insertSpace(int start, int num)
Inserts space for num values at index start.
static void * createInstance()
SoMField()
Constructor.
void setNum(int num)
Forces this field to have exactly num values, inserting or deleting values as necessary.
static SoType getClassTypeId()
Return the type identifier for this field class.
Definition SoField.h:665
int maxNum
Number of values allocated.
Definition SoField.h:674
virtual void deleteValues(int start, int num=-1)
Deletes num values beginning at index start (index start through start+num-1 will be deleted,...
int num
Number of values.
Definition SoField.h:673
bool set1(int index, const char *valueString)
This is equivalent to the set() method of SoField, but operates on only one value.
Holds a list of SoNotRec notification records.
Type
Notification types (what receives notification).
Used to write Inventor data files.
Definition SoOutput.h:90
Abstract base class for all single-value fields.
Definition SoField.h:537
static void initClass()
static SoType getClassTypeId()
Return the type identifier for this field class.
Definition SoField.h:543
virtual ~SoSField()
Destructor.
static void * createInstance()
SoSField()
Constructor.
SoType has no virtual functions to keep it small...
Definition SoType.h:103