Coin: SoField.h Source File

| Coin3D is Free Software, published under the BSD 3-clause license. | https://coin3d.github.io https://www.kongsberg.com/en/kogt/

SoField.h
1#ifndef COIN_SOFIELD_H
2#define COIN_SOFIELD_H
3
4/**************************************************************************\
5 * Copyright (c) Kongsberg Oil & Gas Technologies AS
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34\**************************************************************************/
35
36#include <Inventor/SoType.h>
37#include <Inventor/misc/SoNotification.h>
38
39class SbString;
40class SoEngineOutput;
41class SoFieldContainer;
42class SoFieldConverter;
43class SoFieldList;
44class SoInput;
45class SoOutput;
46
47 class COIN_DLL_API SoField {
48
49public:
50 virtual ~SoField();
51
52 static void initClass(void);
53 static void initClasses(void);
54 static void cleanupClass(void);
55
56 void setIgnored(SbBool ignore);
57 SbBool isIgnored(void) const;
58
59 void setDefault(SbBool defaultVal);
60 SbBool isDefault(void) const;
61
62 virtual SoType getTypeId(void) const = 0;
63
64 static SoType getClassTypeId(void);
65 SbBool isOfType(const SoType type) const;
66
67 void enableConnection(SbBool flag);
68 SbBool isConnectionEnabled(void) const;
69
70 // Field<-Engine connection stuff.
71 SbBool connectFrom(SoEngineOutput * master,
72 SbBool notnotify = FALSE, SbBool append = FALSE);
73 SbBool appendConnection(SoEngineOutput * master, SbBool notnotify = FALSE);
74 void disconnect(SoEngineOutput * engineoutput);
75 SbBool isConnectedFromEngine(void) const;
76 SbBool getConnectedEngine(SoEngineOutput *& master) const;
77
78 // Field<->Field connection stuff.
79 SbBool connectFrom(SoField * master,
80 SbBool notnotify = FALSE, SbBool append = FALSE);
81 SbBool appendConnection(SoField * master, SbBool notnotify = FALSE);
82 void disconnect(SoField * field);
83 SbBool isConnectedFromField(void) const;
84 SbBool getConnectedField(SoField *& master) const;
85 int getNumConnections(void) const;
86 int getForwardConnections(SoFieldList & slavelist) const;
87 int getConnections(SoFieldList & masterlist) const;
88
89 void disconnect(void);
90 SbBool isConnected(void) const;
91
92 void setContainer(SoFieldContainer * cont);
93 SoFieldContainer * getContainer(void) const;
94
95 SbBool set(const char * valuestring);
96 void get(SbString & valuestring);
97
98 SbBool shouldWrite(void) const;
99
100 virtual void touch(void);
101 virtual void startNotify(void);
102 virtual void notify(SoNotList * nlist);
103 SbBool enableNotify(SbBool on);
104 SbBool isNotifyEnabled(void) const;
105
106 void addAuditor(void * f, SoNotRec::Type type);
107 void removeAuditor(void * f, SoNotRec::Type type);
108
109 int operator ==(const SoField & f) const;
110 int operator !=(const SoField & f) const;
111
112 virtual void connectionStatusChanged(int numconnections);
113 SbBool isReadOnly(void) const;
114 virtual SbBool isSame(const SoField & f) const = 0;
115 virtual void copyFrom(const SoField & f) = 0;
116
117 virtual void fixCopy(SbBool copyconnections);
118 virtual SbBool referencesCopy(void) const;
119 void copyConnection(const SoField * fromfield);
120
121 virtual SbBool read(SoInput * input, const SbName & name);
122 virtual void write(SoOutput * out, const SbName & name) const;
123
124 virtual void countWriteRefs(SoOutput * out) const;
125
126 // enums for setFieldType()/getFieldType()
127 enum FieldType {
128 NORMAL_FIELD = 0,
129 EVENTIN_FIELD,
130 EVENTOUT_FIELD,
131 EXPOSED_FIELD
132 };
133
134 void setFieldType(int type);
135 int getFieldType(void) const;
136
137 SbBool getDirty(void) const;
138 void setDirty(SbBool dirty);
139
140 void evaluate(void) const {
141 if ((this->statusbits & (FLAG_EXTSTORAGE|FLAG_NEEDEVALUATION)) ==
142 (FLAG_EXTSTORAGE|FLAG_NEEDEVALUATION)) this->evaluateField();
143 }
144
145protected:
146 SoField(void);
147
148 void valueChanged(SbBool resetdefault = TRUE);
149 virtual void evaluateConnection(void) const;
150 virtual SbBool readValue(SoInput * in) = 0;
151 virtual void writeValue(SoOutput * out) const = 0;
152 virtual SbBool readConnection(SoInput * in);
153 virtual void writeConnection(SoOutput * out) const;
154
155 SbBool isDestructing(void) const;
156
157 virtual SoNotRec createNotRec(SoBase * cont);
158
159private:
160
161 enum FieldFlags {
162 FLAG_TYPEMASK = 0x0007, // need 3 bits for values [0-5]
163 FLAG_ISDEFAULT = 0x0008,
164 FLAG_IGNORE = 0x0010,
165 FLAG_EXTSTORAGE = 0x0020,
166 FLAG_ENABLECONNECTS = 0x0040,
167 FLAG_NEEDEVALUATION = 0x0080,
168 FLAG_READONLY = 0x0100,
169 FLAG_DONOTIFY = 0x0200,
170 FLAG_ISDESTRUCTING = 0x0400,
171 FLAG_ISEVALUATING = 0x0800,
172 FLAG_ISNOTIFIED = 0x1000
173 };
174
175 void evaluateField(void) const;
176 void extendStorageIfNecessary(void);
177 SoFieldConverter * createConverter(SoType from) const;
178 SoFieldContainer * resolveWriteConnection(SbName & mastername) const;
179
180 void notifyAuditors(SoNotList * l);
181
182 static SoType classTypeId;
183
184 // These are bit flags.
185 enum FileFormatFlags {
186 IGNORED = 0x01,
187 CONNECTED = 0x02,
188 DEFAULT = 0x04,
189 ALLFILEFLAGS = IGNORED|CONNECTED|DEFAULT
190 };
191
192 SbBool changeStatusBits(const unsigned int bits, const SbBool onoff);
193 void clearStatusBits(const unsigned int bits);
194 void setStatusBits(const unsigned int bits);
195 SbBool getStatus(const unsigned int bits) const;
196 unsigned int statusbits;
197 union {
198 SoFieldContainer * container;
199 class SoConnectStorage * storage;
200 };
201
202 SbBool hasExtendedStorage(void) const;
203};
204
205
206#ifndef COIN_INTERNAL
207// Added to be Inventor compliant.
208#include <Inventor/fields/SoSField.h>
209#include <Inventor/fields/SoMField.h>
210#endif // !COIN_INTERNAL
211
212#endif // !COIN_SOFIELD_H
SbName
The SbName class stores strings by reference.
Definition SbName.h:40
SbString
The SbString class is a string class with convenience functions for string operations.
Definition SbString.h:52
SoBase
The SoBase class is the top-level superclass for a number of class-hierarchies.
Definition SoBase.h:45
SoEngineOutput
The SoEngineOutput class is the output slots in SoEngine instances.
Definition SoEngineOutput.h:45
SoFieldContainer
The SoFieldContainer class is a base class for all classes that contain fields.
Definition SoFieldContainer.h:43
SoFieldConverter
The SoFieldConverter class is the abstract base class for field converters.
Definition SoFieldConverter.h:41
SoFieldList
The SoFieldList class is a container for pointers to SoField objects.
Definition SoFieldList.h:40
SoField
The SoField class is the top-level abstract base class for fields.
Definition SoField.h:47
SoField::cleanupClass
static void cleanupClass(void)
Definition SoField.cpp:650
SoField::disconnect
void disconnect(SoEngineOutput *engineoutput)
Definition SoField.cpp:1096
SoField::isSame
virtual SbBool isSame(const SoField &f) const =0
SoField::isNotifyEnabled
SbBool isNotifyEnabled(void) const
Definition SoField.cpp:1588
SoField::setIgnored
void setIgnored(SbBool ignore)
Definition SoField.cpp:668
SoField::isDestructing
SbBool isDestructing(void) const
Definition SoField.cpp:2589
SoField::set
SbBool set(const char *valuestring)
Definition SoField.cpp:1350
SoField::readValue
virtual SbBool readValue(SoInput *in)=0
SoField::evaluate
void evaluate(void) const
Definition SoField.h:140
SoField::copyConnection
void copyConnection(const SoField *fromfield)
Definition SoField.cpp:1795
SoField::startNotify
virtual void startNotify(void)
Definition SoField.cpp:1439
SoField::isConnected
SbBool isConnected(void) const
Definition SoField.cpp:1217
SoField::copyFrom
virtual void copyFrom(const SoField &f)=0
SoField::getClassTypeId
static SoType getClassTypeId(void)
Definition SoField.cpp:727
SoField::getConnectedEngine
SbBool getConnectedEngine(SoEngineOutput *&master) const
Definition SoField.cpp:1280
SoField::getForwardConnections
int getForwardConnections(SoFieldList &slavelist) const
Definition SoField.cpp:1292
SoField::enableNotify
SbBool enableNotify(SbBool on)
Definition SoField.cpp:1574
SoField::connectionStatusChanged
virtual void connectionStatusChanged(int numconnections)
Definition SoField.cpp:1714
SoField::referencesCopy
virtual SbBool referencesCopy(void) const
Definition SoField.cpp:1762
SoField::isOfType
SbBool isOfType(const SoType type) const
Definition SoField.cpp:737
SoField::isConnectionEnabled
SbBool isConnectionEnabled(void) const
Definition SoField.cpp:768
SoField::touch
virtual void touch(void)
Definition SoField.cpp:1427
SoField::getConnectedField
SbBool getConnectedField(SoField *&master) const
Definition SoField.cpp:1266
SoField::connectFrom
SbBool connectFrom(SoEngineOutput *master, SbBool notnotify=FALSE, SbBool append=FALSE)
Definition SoField.cpp:929
SoField::fixCopy
virtual void fixCopy(SbBool copyconnections)
Definition SoField.cpp:1747
SoField::write
virtual void write(SoOutput *out, const SbName &name) const
Definition SoField.cpp:2019
SoField::isConnectedFromEngine
SbBool isConnectedFromEngine(void) const
Definition SoField.cpp:1243
SoField::getConnections
int getConnections(SoFieldList &masterlist) const
Definition SoField.cpp:1183
SoField::notify
virtual void notify(SoNotList *nlist)
Definition SoField.cpp:1464
SoField::getContainer
SoFieldContainer * getContainer(void) const
Definition SoField.cpp:1331
SoField::setContainer
void setContainer(SoFieldContainer *cont)
Definition SoField.cpp:1312
SoField::countWriteRefs
virtual void countWriteRefs(SoOutput *out) const
Definition SoField.cpp:2099
SoField::appendConnection
SbBool appendConnection(SoEngineOutput *master, SbBool notnotify=FALSE)
Definition SoField.cpp:2237
SoField::isConnectedFromField
SbBool isConnectedFromField(void) const
Definition SoField.cpp:1230
SoField::enableConnection
void enableConnection(SbBool flag)
Definition SoField.cpp:755
SoField::initClass
static void initClass(void)
Definition SoField.cpp:627
SoField::read
virtual SbBool read(SoInput *input, const SbName &name)
Definition SoField.cpp:1876
SoField::isReadOnly
SbBool isReadOnly(void) const
Definition SoField.cpp:1727
SoField::removeAuditor
void removeAuditor(void *f, SoNotRec::Type type)
Definition SoField.cpp:1619
SoField::readConnection
virtual SbBool readConnection(SoInput *in)
Definition SoField.cpp:2299
SoField::getTypeId
virtual SoType getTypeId(void) const =0
SoField::SoField
SoField(void)
Definition SoField.cpp:539
SoField::isDefault
SbBool isDefault(void) const
Definition SoField.cpp:716
SoField::get
void get(SbString &valuestring)
Definition SoField.cpp:1369
SoField::setDefault
void setDefault(SbBool defaultVal)
Definition SoField.cpp:693
SoField::initClasses
static void initClasses(void)
Definition SoField.cpp:2609
SoField::getNumConnections
int getNumConnections(void) const
Definition SoField.cpp:1167
SoField::shouldWrite
SbBool shouldWrite(void) const
Definition SoField.cpp:1661
SoField::writeValue
virtual void writeValue(SoOutput *out) const =0
SoField::addAuditor
void addAuditor(void *f, SoNotRec::Type type)
Definition SoField.cpp:1608
SoField::writeConnection
virtual void writeConnection(SoOutput *out) const
Definition SoField.cpp:2402
SoField::isIgnored
SbBool isIgnored(void) const
Definition SoField.cpp:681
SoInput
The SoInput class is an abstraction of file import functionality.
Definition SoInput.h:61
SoNotList
The SoNotList class is a list of SoNotRec notification records.
Definition SoNotification.h:43
SoNotRec
The SoNotRec class specifies records for notification lists.
Definition SoNotRec.h:42
SoNotRec::Type
Type
Definition SoNotRec.h:44
SoOutput
The SoOutput class is an abstraction of an output stream.
Definition SoOutput.h:51
SoType
The SoType class is the basis for the runtime type system in Coin.
Definition SoType.h:59