| 1 |
NAME SoField "" "" { base class for all fields } |
| 2 |
|
| 3 |
INCLUDE fields/SoField.h |
| 4 |
|
| 5 |
DESC { |
| 6 |
\cSoField\. is the abstract base class for all fields. Fields |
| 7 |
are the data elements contained within nodes and are the input values |
| 8 |
for engines. |
| 9 |
Each node or engine class specifies a set of fields and associates a |
| 10 |
name with each. |
| 11 |
These names define the semantics of the field (e.g., the \cSoCube\. |
| 12 |
node contains three float fields named width, height, and depth). |
| 13 |
Field classes provide the access methods that indirectly allow editing |
| 14 |
and querying of data within nodes. |
| 15 |
\p |
| 16 |
There are two abstract subclasses of \cSoField\.: \cSoSField\. |
| 17 |
is the base class for all single-valued field classes and |
| 18 |
\cSoMField\. is the base class for all multiple-valued fields, which |
| 19 |
contain dynamic arrays of values. Subclasses of \cSoSField\. have an |
| 20 |
\cSoSF\. prefix, and subclasses of \cSoMField\. have an \cSoMF\. |
| 21 |
prefix. See the reference pages for \cSoSField\. and \cSoMField\. for |
| 22 |
additional methods. |
| 23 |
\p |
| 24 |
Fields are typically constructed only within node or engine |
| 25 |
instances; if you need a field that is not part of a node or engine, |
| 26 |
you can create a \cGlobalField\.; see the methods on \cSoDB\. for |
| 27 |
creating global fields. |
| 28 |
\p |
| 29 |
Fields can be connected either directly to another field, or can be |
| 30 |
connected to the output of an engine. The value of a field with a |
| 31 |
connection will change when the thing it is connected to changes. For |
| 32 |
example, consider a field "A" that is connected from "B" (by |
| 33 |
\m\+A->connectFrom(B)\.\-SoFieldConnectFrom((SoField *)A, (SoField *)B)\.\.). |
| 34 |
When B's value is changed, A's value will also |
| 35 |
change. Note that A and B may have different values, even if they are |
| 36 |
connected: if A's value is set after B's value, A's value will be |
| 37 |
different from B's until B's value is set. |
| 38 |
\p |
| 39 |
A field can be connected to several other fields, but can be connected |
| 40 |
from only one source. |
| 41 |
\p |
| 42 |
It is possible (and often useful) to create loops of field |
| 43 |
connections (for example, A connected from B and B connected from A). |
| 44 |
If there are loops, then the rule is that the last |
| 45 |
\m\+setValue()\.\-SetValue()\.\. done |
| 46 |
overrides any connections in to that value. You can think of setting |
| 47 |
the value of a field as immediately propagating that value forward |
| 48 |
into all the fields it is connected to, with the propagation stopping |
| 49 |
at the place where the original \msetValue()\. occurred if there is a |
| 50 |
connection loop. (Actually, a more efficient mechanism than this is |
| 51 |
used, but the semantics are the same.) |
| 52 |
\p |
| 53 |
If you try to connect two fields of differing types, Inventor will |
| 54 |
automatically try to insert a field converter engine between them to |
| 55 |
convert values from one type into the other. Inventor has most |
| 56 |
reasonable conversions built-in (multiple-valued field to single-valued |
| 57 |
and vice versa, anything to \mSoSFString\., anything to |
| 58 |
\mSoSFTrigger\., float/short/unsigned short/int32_t/uint32_t/etc |
| 59 |
numeric conversions, etc). \+You can add field converters using \cSoDB\.'s |
| 60 |
extender method \maddConverter()\.; see the SoDB.h header file for |
| 61 |
details. You can also find out if a converter is available with the |
| 62 |
\mSoDB::getConverter()\. method.\. |
| 63 |
\p |
| 64 |
Fields each define their own file format for reading and being written |
| 65 |
to files, but all fields follow the same conventions: |
| 66 |
\p |
| 67 |
Fields in a node or engine are written as the name of the field |
| 68 |
followed by the field's value; fields are not written if they have not |
| 69 |
been modified since they were created (if they have their default |
| 70 |
value). |
| 71 |
\p |
| 72 |
The ignored flag is written as a "~" character after the field's |
| 73 |
value (if the field's value is its default value, just the "~" is |
| 74 |
written). |
| 75 |
\p |
| 76 |
Field connections are written as an "=" followed by the container of |
| 77 |
the field or engine output that the field is connected to, followed by |
| 78 |
a "." and the name of the field or engine output. For example: |
| 79 |
\b |
| 80 |
DEF node1 Transform \{ translation 1 1 1 \} |
| 81 |
DEF node2 Scale \{ scaleFactor 1 1 1 = USE node1.translation \} |
| 82 |
\. |
| 83 |
\p |
| 84 |
Global fields are written as part of an internal \cSoFieldContainer\. |
| 85 |
class called \cGlobalField\., which writes out an \vSoSFName\. field named |
| 86 |
\vtype\. whose value is the type of the global field, followed by |
| 87 |
a field of that type whose name is the name of the global field. For |
| 88 |
example, a global uint32_t field called "FrameCounter" whose |
| 89 |
value is 494 would be written as: |
| 90 |
\b |
| 91 |
GlobalField \{ |
| 92 |
type SoSFUInt32 |
| 93 |
FrameCounter 494 |
| 94 |
\} |
| 95 |
\. |
| 96 |
} |
| 97 |
|
| 98 |
METHOD "" void setIgnored(SbBool ignore) {} |
| 99 |
METHOD "" SbBool isIgnored() const { |
| 100 |
Sets/gets the ignore flag for this field. When a field's ignore flag |
| 101 |
is set to TRUE, the field is not used during traversal for rendering |
| 102 |
and other actions. The default value for this flag is FALSE. |
| 103 |
} |
| 104 |
METHOD isDflt SbBool isDefault() const { |
| 105 |
Gets the state of default flag of the field. This flag will be TRUE |
| 106 |
for any field whose value is not modified after construction and will |
| 107 |
be FALSE for those that have changed (each node or engine determines |
| 108 |
what the default values for its fields are). Note: the state of this |
| 109 |
flag should not be set explicitly from within applications. |
| 110 |
} |
| 111 |
|
| 112 |
METHOD "" static SoType getClassTypeId() { |
| 113 |
Return the type identifier for this field class. |
| 114 |
} |
| 115 |
METHOD "" virtual SoType getTypeId() const { |
| 116 |
Return the type identifier for this field instance (SoField *). |
| 117 |
} |
| 118 |
METHOD "" virtual SbBool isOfType(SoType type) const { |
| 119 |
Returns TRUE if this field is the given type or derived from that |
| 120 |
type. This is typically used |
| 121 |
with the getClassTypeId() method to determine the type of an SoField * |
| 122 |
at run-time: |
| 123 |
\b\+ |
| 124 |
SoField *field = ....; |
| 125 |
if (field->isOfType(SoSFFloat::getClassTypeId())) \{ |
| 126 |
SoSFFloat *floatField = (SoSFFloat *)field); |
| 127 |
floatField->setValue(4.5); |
| 128 |
\} |
| 129 |
\.\-SoField *field = ...; |
| 130 |
if (SoFieldIsOfType(field, SoSFFloatGetClassTypeId())) \{ |
| 131 |
SoSFFloat *floatField = (SoSFFloat *)field); |
| 132 |
SoSFFloatSetValue(floatField, 4.5); |
| 133 |
\} \.\. |
| 134 |
} |
| 135 |
METHOD setFromStr SbBool set(const char *valueString) { |
| 136 |
Sets the field to the given value, which is an ASCII string in the |
| 137 |
Inventor file format. Each field subclass defines its own file |
| 138 |
format; see their reference pages for information on their file format. |
| 139 |
The string should contain only the field's value, \enot\. the field's |
| 140 |
name (e.g., "1.0", \enot\. "width 1.0"). This method |
| 141 |
returns TRUE if the string is valid, FALSE if it is not. |
| 142 |
} |
| 143 |
METHOD getIntoStr void get(SbString &valueString) { |
| 144 |
Returns the value of the field in the Inventor file format, even if |
| 145 |
the field has its default value. |
| 146 |
} |
| 147 |
METHOD IsEq int operator ==(const SoField &f) const {} |
| 148 |
METHOD IsNEq int operator !=(const SoField &f) const { |
| 149 |
Return TRUE (FALSE) if this field is of the same type and has the same |
| 150 |
value as \af\.. |
| 151 |
} |
| 152 |
METHOD "" void touch() { |
| 153 |
Simulates a change to the field, causing attached sensors to fire, |
| 154 |
connected fields and engines to be marked as needing evaluation, and so |
| 155 |
forth. Calling \mtouch()\. on an instance of a derived field class is |
| 156 |
equivalent to calling \msetValue(getValue())\. using the derived class's |
| 157 |
methods, except that the field's \misDefault()\. status remains |
| 158 |
unchanged. |
| 159 |
} |
| 160 |
METHOD connFromField SbBool connectFrom(SoField *fromField) {} |
| 161 |
METHOD connFrom SbBool connectFrom(SoEngineOutput *fromEngine) { |
| 162 |
Connects this field to another field or from an engine output. |
| 163 |
If the field was connected to |
| 164 |
something before, it will be automatically disconnected (a field may |
| 165 |
have only one connection writing into it at a time). Unless |
| 166 |
connections to the field are disabled (see |
| 167 |
\m\+enableConnection()\.\-EnableConn()\.\.), the field's value will be |
| 168 |
set to the value of the thing it is connected to. |
| 169 |
} |
| 170 |
METHOD disconn void disconnect() { |
| 171 |
Disconnect the field from whatever it was connected to. This does |
| 172 |
nothing if the field was not connected. |
| 173 |
} |
| 174 |
METHOD isConn SbBool isConnected() const { |
| 175 |
Returns TRUE if the field is connected to anything. |
| 176 |
} |
| 177 |
METHOD isConnFromField SbBool isConnectedFromField() const { |
| 178 |
Returns TRUE if the field is connected to another field. |
| 179 |
} |
| 180 |
METHOD getConnField |
| 181 |
SbBool getConnectedField(SoField *&writingField) const { |
| 182 |
Returns TRUE if this field is being written into by another field, and |
| 183 |
returns the field it is connected to in \awritingField\.. Returns |
| 184 |
FALSE and does not modify \awritingField\. if it is not connected to a |
| 185 |
field. |
| 186 |
} |
| 187 |
METHOD isConnFromEngine SbBool isConnectedFromEngine() const { |
| 188 |
Returns TRUE if the field is connected to an engine's output. |
| 189 |
} |
| 190 |
METHOD getConnEngine |
| 191 |
SbBool getConnectedEngine(SoEngineOutput *&engineOutput) const { |
| 192 |
Returns TRUE if this field is being written into by an engine, and |
| 193 |
returns the engine output it is connected to in \aengineOutput\.. Returns |
| 194 |
FALSE and does not modify \aengineOutput\. if it is not connected to an |
| 195 |
engine. |
| 196 |
} |
| 197 |
METHOD enableConn void enableConnection(SbBool flag) { |
| 198 |
Field connections may be enabled and disabled. Disabling a field's |
| 199 |
connection is almost exactly like disconnecting it; the only |
| 200 |
difference is that you can later re-enable the connection by calling |
| 201 |
enableConnection(TRUE). Note that disconnecting an engine output can |
| 202 |
cause the engine's reference count to be decremented and the engine to |
| 203 |
be deleted, but disabling the connection does not decrement its |
| 204 |
reference count. |
| 205 |
\p |
| 206 |
Re-enabling a connection will cause the value of the field to be |
| 207 |
changed to the engine output or field to which it is connected. |
| 208 |
\p |
| 209 |
A field's connection-enabled status is maintained even if the field is |
| 210 |
disconnected or reconnected. By default, connections are enabled. |
| 211 |
} |
| 212 |
METHOD isConnEnabled SbBool isConnectionEnabled() const { |
| 213 |
Returns FALSE if connections to this field are disabled. Note that this |
| 214 |
may return FALSE even if the field is not connected to anything. |
| 215 |
} |
| 216 |
METHOD getForwardConn int getForwardConnections(SoFieldList &list) const { |
| 217 |
Adds pointers to all of the fields that this field is writing into |
| 218 |
(either fields in nodes, global fields or engine inputs) to the given |
| 219 |
field list, and returns the number of forward connections. |
| 220 |
} |
| 221 |
METHOD "" SoFieldContainer *getContainer() const { |
| 222 |
Returns the object that contains this field. The type of the |
| 223 |
object will be either \cSoNode\., \cSoEngine\., or will be a |
| 224 |
global field container (note that the global field container |
| 225 |
class is internal to Inventor; see the methods for creating and accessing |
| 226 |
global fields on \cSoDB\.). For example: |
| 227 |
\b\+ |
| 228 |
SoFieldContainer *f = field->getContainer(); |
| 229 |
if (f->isOfType(SoNode::getClassTypeId())) \{ |
| 230 |
... do something ... |
| 231 |
\} else if (f->isOfType(SoEngine::getClassTypeId())) \{ |
| 232 |
... do someting else ... |
| 233 |
\} else \{ |
| 234 |
... it must be a global field. We can figure out its name, but |
| 235 |
that is about it: |
| 236 |
const SbName &globalFieldName = f->getName(); |
| 237 |
\} |
| 238 |
\.\- |
| 239 |
SoFieldContainer *f = SoFieldGetContainer(field); |
| 240 |
if (SoFieldContIsOfType(f, SoNodeGetClassTypeId())) \{ |
| 241 |
... do something ... |
| 242 |
\} else if (SoFieldContIsOfType(f, SoEngineGetClassTypeId())) \{ |
| 243 |
... do someting else ... |
| 244 |
\} else \{ |
| 245 |
... it must be a global field. We can figure out its name, but |
| 246 |
that is about it: |
| 247 |
const char *globalFieldName = SoFieldContGetName(f); |
| 248 |
\}\.\. |
| 249 |
} |
| 250 |
ALSO { SoSField, SoMField, SoNode, SoDB } |