Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/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 
39 class SbString;
40 class SoEngineOutput;
41 class SoFieldContainer;
42 class SoFieldConverter;
43 class SoFieldList;
44 class SoInput;
45 class SoOutput;
46 
47 class COIN_DLL_API SoField {
48 
49 public:
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 
145 protected:
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 
159 private:
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
The SoBase class is the top-level superclass for a number of class-hierarchies.SoBase provides the ba...
Definition: SoBase.h:45
The SoOutput class is an abstraction of an output stream.SoOutput offers the ability to write basic t...
Definition: SoOutput.h:51
The SoNotRec class specifies records for notification lists.
Definition: SoNotRec.h:42
The SoFieldContainer class is a base class for all classes that contain fields.The classes containing...
Definition: SoFieldContainer.h:43
The SoField class is the top-level abstract base class for fields.Fields is the mechanism used throug...
Definition: SoField.h:47
The SoFieldConverter class is the abstract base class for field converters.When fields of different t...
Definition: SoFieldConverter.h:41
void evaluate(void) const
Definition: SoField.h:140
The SoEngineOutput class is the output slots in SoEngine instances.SoEngineOutput has methods for con...
Definition: SoEngineOutput.h:45
The SoInput class is an abstraction of file import functionality.This class takes care of most of the...
Definition: SoInput.h:61
The SoFieldList class is a container for pointers to SoField objects.
Definition: SoFieldList.h:40
The SbString class is a string class with convenience functions for string operations.This is the class used for storing and working with character strings. It automatically takes care of supporting all the "bookkeeping" tasks usually associated with working with character strings, like memory allocation and deallocation etc.
Definition: SbString.h:52
The SoNotList class is a list of SoNotRec notification records.
Definition: SoNotification.h:43
The SoType class is the basis for the run-time type system in Coin.Many of the classes in the Coin li...
Definition: SoType.h:59
The SbName class stores strings by reference.The class is used by Coin for storing keywords...
Definition: SbName.h:40
Type
Definition: SoNotRec.h:44