MeVisLabToolboxReference
mlField.h
Go to the documentation of this file.
1 // **InsertLicense** code
2 //-------------------------------------------------------------------------
12 //-------------------------------------------------------------------------
13 #ifndef __mlField_H
14 #define __mlField_H
15 
16 // ML-includes
17 #include "mlInitSystemML.h"
18 #include "mlRuntimeSubClass.h"
19 #include "mlFieldSensor.h"
20 
21 ML_START_NAMESPACE
22 
23 class OutputConnectorField;
24 class BaseField;
25 class SoNodeField;
26 class NotifyField;
27 class FieldContainer;
28 
29 //-------------------------------------------------------------------------
64 //-------------------------------------------------------------------------
66 {
67 
68 public:
69 
70  //---------------------------------------------------------------------------
72 
73  //---------------------------------------------------------------------------
75  Field(const std::string& name = std::string());
76 
78  virtual ~Field();
80 
81  //---------------------------------------------------------------------------
83 
84  //---------------------------------------------------------------------------
85 
87  FieldContainer* getFieldContainer() const { return _fieldContainer; }
88 
90 
91  //----------------------------------------------------------
93 
94  //----------------------------------------------------------
96  const std::string& getName() const { return _name; }
97 
99  void setName(const std::string& name) { _name = name; }
101 
102  //----------------------------------------------------------
104 
105  //----------------------------------------------------------
107  bool isOutputOnly() const;
108 
110  void setOutputOnly(bool outputOnly = true);
112 
113  //----------------------------------------------------------
115 
116  //----------------------------------------------------------
117 
120  virtual void setStringValue(const std::string& value) =0;
121 
128  virtual std::string getStringValue() const =0;
129 
133  virtual MLint isValidValue(){ return 1; }
134 
135 
139  void copyCStringValue(char* valueBuffer, MLint bufferSize);
140 
142  MLint getCStringValueSize(){ return static_cast<MLint>(getStringValue().size()); }
144 
145 
146  //------------------------------------------------------------------------
148 
149  //------------------------------------------------------------------------
151  void attachFieldSensor(FieldSensor* sensor);
152 
154  void detachFieldSensor(FieldSensor* sensor);
155 
157  void detachFieldSensors();
158 
163  void attachField(OutputConnectorField* targetField);
164  void attachField(BaseField* targetField);
165  void attachField(SoNodeField* targetField);
166  void attachField(NotifyField* targetField);
167 
171  void attachField(Field* targetField, bool propagateValueOnConnect);
172 
174  void detachField(Field* targetField);
175 
177  void detachSourceFields();
178 
180  void detachDestinationFields();
181 
183  void detachAllFields();
184 
186  size_t getNumDestinationFields();
187 
189  Field* getDestinationField(size_t index);
190 
192  size_t getNumSourceFields();
193 
195  Field* getSourceField(size_t index);
196 
211  virtual void touch(FieldSensor::Strength strength=FieldSensor::CHANGED);
212 
216  void enableNotifications(bool flag);
217 
220  bool areNotificationsEnabled();
221 
228  static void enableNotificationsGlobally(bool flag);
229 
235  static bool areNotificationsEnabledGlobally();
236 
241  static MLint& enableNotificationsCounterState();
243 
244 protected:
247  void attachSourceField(Field* field);
248 
250  void detachSourceField(Field* field);
251 
253  void detachFieldInternal(Field* field);
254 
258  virtual void setValueFromField(const Field& field);
259 
261  std::string _name;
262 
264  std::vector <FieldSensor*> _sensors;
265 
268  std::vector <Field*> _destinationFields;
269 
272  std::vector <Field*> _sourceFields;
273 
276 
278  struct Flags {
279  unsigned int observersWereRemovedInsideTouch:1;
280  unsigned int insideTouch:1;
281  unsigned int notifyAttachmentsFlag:1;
282  unsigned int outputOnly:1;
283  };
284 
286 
289 
290 private:
291  friend class FieldContainer;
292 
294  void setFieldContainer(FieldContainer* container) { _fieldContainer = container; }
295 
298 
299 
300 #ifdef ML_DEPRECATED
301 
303 
304 
305 public:
306 
309  #define notifyAttachments touch
310 
311 #if defined(WIN32) && defined(ML_WARN_DEPRECATED)
312  #pragma deprecated("notifyAttachments")
313 #endif
314 
317  inline ML_DEPRECATED void deactivateAttachments() { enableNotifications(false); }
320  inline ML_DEPRECATED void activateAttachments() { enableNotifications(true); }
323  inline ML_DEPRECATED MLint isActiveAttachments() { return areNotificationsEnabled(); }
326  inline ML_DEPRECATED static void disableNotifications() { enableNotificationsGlobally(false); }
329  inline ML_DEPRECATED static void enableNotifications() { enableNotificationsGlobally(true); }
332  inline ML_DEPRECATED static MLint isEnabledNotifications() { return areNotificationsEnabledGlobally(); }
333 
335 
336 #endif // ML_DEPRECATED
337 
338 
339 };
340 
341 ML_END_NAMESPACE
342 
343 
344 //-----------------------------------------------------------------------------------
345 // Stream output for std::ostream
346 //-----------------------------------------------------------------------------------
347 namespace std
348 {
349 
351  MLEXPORT std::ostream& operator<<(std::ostream& s, const ML_NAMESPACE::Field &v);
352 
353 }
354 
355 
356 #endif // __mlField_H
357 
358 
359 
MLint getCStringValueSize()
Returns the length of the character string of the string value of the field.
Definition: mlField.h:142
Defines the class FieldSensor to realize the concept of field sensors which can observe fields...
Flags _flags
Definition: mlField.h:285
#define ML_DEPRECATED
Definition: mlMacros.h:40
Strength
Enumeration type describing the strength of notifications.
Definition: mlFieldSensor.h:39
STL namespace.
virtual MLint isValidValue()
Returns true (=1) if the field's value is valid; otherwise false (=0) is returned.
Definition: mlField.h:133
void activateAttachments()
Definition: mlField.h:320
FieldContainer * _fieldContainer
The owning field container.
Definition: mlField.h:275
Field to encapsulate a pointer to an SoNode instance of OpenInventor.
Definition: mlFields.h:1273
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:576
static void enableNotifications()
Definition: mlField.h:329
Defines system-specific macros for this project/DLL.
std::vector< FieldSensor * > _sensors
List of field sensors.
Definition: mlField.h:264
#define MLEXPORT
To export symbols from a dll/shared object, we need to mark them with the MLEXPORT symbol...
static void disableNotifications()
Definition: mlField.h:326
static MLint _enableNotifications
Flag which disables the notification process of field (sensors) globally.
Definition: mlField.h:288
Base class for all fields used in the ML.
Definition: mlField.h:65
std::vector< Field * > _destinationFields
List of (target) fields which shall be set to the value of this field or which shall be notified only...
Definition: mlField.h:268
Field to encapsulate a pointer to an ML base object.
Definition: mlFields.h:1169
Flags for internal usage.
Definition: mlField.h:278
std::vector< Field * > _sourceFields
List of (source) fields, which will notify this field or which will copy their value to this field...
Definition: mlField.h:272
FieldContainer * getFieldContainer() const
Get the field container of the field (which may be NULL).
Definition: mlField.h:87
This file defines macros, which are inserted in classes to declare and implement additional class mem...
std::ostream & operator<<(std::ostream &out, const ml::Variant &variant)
Definition: mlVariant.h:205
static MLint isEnabledNotifications()
Definition: mlField.h:332
void deactivateAttachments()
Definition: mlField.h:317
Defines the class FieldContainer to encapsulate a vector of fields for (see class Field)...
void setName(const std::string &name)
Sets the name of field. Should be called only once after or while construction.
Definition: mlField.h:99
Field to encapsulate a pointer to an output connector which represents a module output.
Definition: mlFields.h:1067
Class to define and to manage field sensors.
Definition: mlFieldSensor.h:33
#define ML_ABSTRACT_CLASS_HEADER(className)
Same like ML_ABSTRACT_CLASS_HEADER_EXPORTED with a non existing export symbol.
Field without value for notifications.
Definition: mlFields.h:1034
const std::string & getName() const
Returns name of field.
Definition: mlField.h:96
MLint isActiveAttachments()
Definition: mlField.h:323
std::string _name
The name of this field.
Definition: mlField.h:261