MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlField.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_FIELD_H
14#define ML_FIELD_H
15
19
20// ML-includes
21#include "mlInitSystemML.h"
22#include "mlRuntimeSubClass.h"
23#include "mlFieldSensor.h"
24
25#include <string>
26#include <vector>
27
29
30class OutputConnectorField;
31class BaseField;
32class SoNodeField;
33class NotifyField;
34class FieldContainer;
35
36//-------------------------------------------------------------------------
71//-------------------------------------------------------------------------
73{
74
75public:
76 //---------------------------------------------------------------------------
79 //---------------------------------------------------------------------------
81 Field(const std::string& name = std::string());
82
84 virtual ~Field();
86
87 //---------------------------------------------------------------------------
90 //---------------------------------------------------------------------------
91
94 {
95 return _fieldContainer;
96 }
97
99
100 //----------------------------------------------------------
103 //----------------------------------------------------------
105 const std::string& getName() const
106 {
107 return _name;
108 }
109
111 void setName(const std::string& name)
112 {
113 _name = name;
114 }
115
118 std::string getFullName() const;
120
121 //----------------------------------------------------------
124 //----------------------------------------------------------
126 bool isOutputOnly() const;
127
129 void setOutputOnly(bool outputOnly = true);
131
132 //----------------------------------------------------------
135 //----------------------------------------------------------
136
139 virtual void setStringValue(const std::string& value) = 0;
140
147 virtual std::string getStringValue() const = 0;
148
153 {
154 return 1;
155 }
156
157
162
165 {
166 return static_cast<MLint>(getStringValue().size());
167 }
169
170
171 //------------------------------------------------------------------------
174 //------------------------------------------------------------------------
177
180
183
192
197
200
203
206
209
212
215
218
220 Field* getSourceField(size_t index);
221
236 virtual void touch(FieldSensor::Strength strength = FieldSensor::CHANGED);
237
242
246
254
261
268
269protected:
273
276
279
283 virtual void setValueFromField(const Field& field);
284
286 std::string _name;
287
289 std::vector<FieldSensor*> _sensors;
290
293 std::vector<Field*> _destinationFields;
294
297 std::vector<Field*> _sourceFields;
298
301
303 struct Flags
304 {
306 : 1;
307 unsigned int insideTouch
308 : 1;
310 : 1;
311 unsigned int outputOnly
312 : 1;
313 };
314
316
319
320private:
321 friend class FieldContainer;
322
324 void setFieldContainer(FieldContainer* container)
325 {
326 _fieldContainer = container;
327 }
328
329 // Disallow copying
330 Field(const Field&)
331 {}
332 Field& operator=(const Field&)
333 {
334 return *this;
335 }
336
339};
340
342
343
344//-----------------------------------------------------------------------------------
345// Stream output for std::ostream
346//-----------------------------------------------------------------------------------
347namespace std
348{
349
351 MLEXPORT std::ostream& operator<<(std::ostream& s, const ML_NAMESPACE::Field& v);
352
353} // namespace std
354
355
356#endif // __mlField_H
Field to encapsulate a pointer to an ML base object.
Definition mlFields.h:813
Defines the class FieldContainer to encapsulate a vector of fields (see class Field).
Class to define and to manage field sensors.
Strength
Enumeration type describing the strength of notifications.
Base class for all fields used in the ML.
Definition mlField.h:73
void setName(const std::string &name)
Sets the name of field. Should be called only once after or while construction.
Definition mlField.h:111
virtual std::string getStringValue() const =0
Returns the value of the field as string value.
size_t getNumDestinationFields()
Returns the number of destination fields that could receive notifications or value sets.
Field(const std::string &name=std::string())
Constructor: Creates a field with name.
static bool areNotificationsEnabledGlobally()
Returns whether the notification mechanism for all fields (e.g., when field values are set) is enable...
void attachField(Field *targetField, bool propagateValueOnConnect)
Connects this class instance with the target field targetField.
Flags _flags
Definition mlField.h:315
void detachFieldSensor(FieldSensor *sensor)
Detaches the field sensor sensor of this class instance in both directions.
FieldContainer * _fieldContainer
The owning field container.
Definition mlField.h:300
MLint getCStringValueSize()
Returns the length of the character string of the string value of the field.
Definition mlField.h:164
void setOutputOnly(bool outputOnly=true)
Marks this field as a pure output field that is only changed by its module.
Field * getDestinationField(size_t index)
Returns the destination field at index. Returns NULL if index is out of range.
void attachField(OutputConnectorField *targetField)
This calls attachField(targetField, false).
std::vector< Field * > _destinationFields
List of (target) fields that shall be set to the value of this field or that shall be notified only i...
Definition mlField.h:293
void copyCStringValue(char *valueBuffer, MLint bufferSize)
Copies the value of the field (as character string) into the specified buffer valueBuffer.
std::vector< Field * > _sourceFields
List of (source) fields that will notify this field or that will copy their value to this field.
Definition mlField.h:297
void attachField(BaseField *targetField)
size_t getNumSourceFields()
Returns the number of source fields that could send notifications or value sets.
std::string _name
The name of this field.
Definition mlField.h:286
virtual ~Field()
Destructor: Destroys a field and removes all connection to fields and sensors.
void detachAllFields()
Disconnects all source and target fields of this instance in both directions.
static void enableNotificationsGlobally(bool flag)
Enables or disables globally the notification mechanism for all fields and field sensors when field v...
void detachDestinationFields()
Disconnects all target fields of this instance in both directions.
static MLint & enableNotificationsCounterState()
Provides read/write access to the current counter state (see enableNotificationsGlobally(bool) ).
virtual MLint isValidValue()
Returns true (=1) if the field's value is valid; otherwise, false (=0) is returned.
Definition mlField.h:152
virtual void setStringValue(const std::string &value)=0
Sets the field value as string value.
void detachField(Field *targetField)
Disconnects connections between the target field targetField and this instance.
bool isOutputOnly() const
Returns whether this field is marked as a pure output field.
void detachFieldSensors()
Detaches all field sensors of this class instance in both directions.
void detachSourceField(Field *field)
Removes a source field from this instance. If not found, then this call does nothing.
virtual void touch(FieldSensor::Strength strength=FieldSensor::CHANGED)
Notifies all connected fields and field sensors.
void detachSourceFields()
Disconnects all source fields of this instance in both directions.
FieldContainer * getFieldContainer() const
Returns the field container of the field (which may be NULL).
Definition mlField.h:93
Field * getSourceField(size_t index)
Returns the source field at index. Returns NULL if index is out of range.
std::string getFullName() const
Returns 'fieldContainerType(instanceName).fieldName' if field container is available,...
std::vector< FieldSensor * > _sensors
List of field sensors.
Definition mlField.h:289
void attachSourceField(Field *field)
Inserts a field as source field in this instance, i.e., from now on *this might receive values and/or...
void detachFieldInternal(Field *field)
Only removes the given field from the destination list.
const std::string & getName() const
Returns the name of field.
Definition mlField.h:105
virtual void setValueFromField(const Field &field)
Sets the value of this field from the given field.
void attachFieldSensor(FieldSensor *sensor)
Attaches a field sensor sensor of this class instance in both directions.
void attachField(NotifyField *targetField)
bool areNotificationsEnabled()
Returns whether the notification mechanism for this field (e.g., when field values are set) is enable...
void attachField(SoNodeField *targetField)
void enableNotifications(bool flag)
Enables or disables notification of attached fields and field sensors when the field value is set or ...
static MLint _enableNotifications
Flag that disables the notification process of field (-sensors) globally.
Definition mlField.h:318
Field without value for notifications.
Definition mlFields.h:687
Field to encapsulate a pointer to an output connector which represents a module output.
Definition mlFields.h:721
Field to encapsulate a pointer to an SoNode instance of OpenInventor.
Definition mlFields.h:986
#define MLEXPORT
To export symbols from a DLL/shared object, we need to mark them with the MLEXPORT symbol.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define ML_ABSTRACT_ROOT_CLASS_HEADER(className)
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:489
STL namespace.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.
Flags for internal usage.
Definition mlField.h:304
unsigned int insideTouch
< Flag to suppress multiple notifications of fields, which otherwise could lead to endless loops.
Definition mlField.h:308
unsigned int observersWereRemovedInsideTouch
< Flag that indicates that the sensor/destination fields lists contain NULL entries
Definition mlField.h:306
unsigned int notifyAttachmentsFlag
< Flag to suppress the notification of connected fields and field sensors when field values are set.
Definition mlField.h:310
unsigned int outputOnly
< Flag to mark this field as a pure output field (this is used by the MeVisLab IDE).
Definition mlField.h:312