ML Reference
|
00001 // **InsertLicense** code 00002 //------------------------------------------------------------------------- 00012 //------------------------------------------------------------------------- 00013 #ifndef __mlField_H 00014 #define __mlField_H 00015 00016 // ML-includes 00017 #ifndef __mlInitSystemML_H 00018 #include "mlInitSystemML.h" 00019 #endif 00020 #ifndef __mlRuntimeSubClass_H 00021 #include "mlRuntimeSubClass.h" 00022 #endif 00023 #ifndef __mlFieldSensor_H 00024 #include "mlFieldSensor.h" 00025 #endif 00026 00027 ML_START_NAMESPACE 00028 00029 class OutputConnectorField; 00030 class BaseField; 00031 class SoNodeField; 00032 class NotifyField; 00033 class FieldContainer; 00034 00035 //------------------------------------------------------------------------- 00070 //------------------------------------------------------------------------- 00071 class MLEXPORT Field 00072 { 00073 00074 public: 00075 00076 //--------------------------------------------------------------------------- 00078 00079 //--------------------------------------------------------------------------- 00081 Field(const std::string& name = std::string()); 00082 00084 virtual ~Field(); 00086 00087 //--------------------------------------------------------------------------- 00089 00090 //--------------------------------------------------------------------------- 00091 00093 FieldContainer* getFieldContainer() const { return _fieldContainer; } 00094 00096 00097 //---------------------------------------------------------- 00099 00100 //---------------------------------------------------------- 00102 const std::string& getName() const { return _name; } 00103 00105 void setName(const std::string& name) { _name = name; } 00107 00108 //---------------------------------------------------------- 00110 00111 //---------------------------------------------------------- 00112 00115 virtual void setStringValue(const std::string& value) =0; 00116 00123 virtual std::string getStringValue() const =0; 00124 00128 virtual MLint isValidValue(){ return 1; } 00129 00130 00134 void copyCStringValue(char* valueBuffer, MLint bufferSize); 00135 00137 MLint getCStringValueSize(){ return static_cast<MLint>(getStringValue().size()); } 00139 00140 00141 //------------------------------------------------------------------------ 00143 00144 //------------------------------------------------------------------------ 00146 void attachFieldSensor(FieldSensor* sensor); 00147 00149 void detachFieldSensor(FieldSensor* sensor); 00150 00152 void detachFieldSensors(); 00153 00158 void attachField(OutputConnectorField* targetField); 00159 void attachField(BaseField* targetField); 00160 void attachField(SoNodeField* targetField); 00161 void attachField(NotifyField* targetField); 00162 00166 void attachField(Field* targetField, bool propagateValueOnConnect); 00167 00169 void detachField(Field* targetField); 00170 00172 void detachSourceFields(); 00173 00175 void detachDestinationFields(); 00176 00178 void detachAllFields(); 00179 00181 size_t getNumDestinationFields(); 00182 00184 Field* getDestinationField(size_t index); 00185 00187 size_t getNumSourceFields(); 00188 00190 Field* getSourceField(size_t index); 00191 00206 virtual void touch(FieldSensor::Strength strength=FieldSensor::CHANGED); 00207 00211 void enableNotifications(bool flag); 00212 00215 bool areNotificationsEnabled(); 00216 00223 static void enableNotificationsGlobally(bool flag); 00224 00230 static bool areNotificationsEnabledGlobally(); 00231 00236 static MLint& enableNotificationsCounterState(); 00238 00239 protected: 00242 void attachSourceField(Field* field); 00243 00245 void detachSourceField(Field* field); 00246 00248 void detachFieldInternal(Field* field); 00249 00253 virtual void setValueFromField(const Field& field); 00254 00256 std::string _name; 00257 00259 std::vector <FieldSensor*> _sensors; 00260 00263 std::vector <Field*> _destinationFields; 00264 00267 std::vector <Field*> _sourceFields; 00268 00270 FieldContainer* _fieldContainer; 00271 00273 struct Flags { 00274 unsigned int observersWereRemovedInsideTouch:1; 00275 unsigned int insideTouch:1; 00276 unsigned int notifyAttachmentsFlag:1; 00277 }; 00278 00279 Flags _flags; 00280 00282 static MLint _enableNotifications; 00283 00284 private: 00285 friend class FieldContainer; 00286 00288 void setFieldContainer(FieldContainer* container) { _fieldContainer = container; } 00289 00291 ML_ABSTRACT_CLASS_HEADER(Field) 00292 00293 00294 #ifdef ML_DEPRECATED 00295 00297 00298 00299 public: 00300 00303 #define notifyAttachments touch 00304 00305 #if defined(WIN32) && defined(ML_WARN_DEPRECATED) 00306 #pragma deprecated("notifyAttachments") 00307 #endif 00308 00311 inline ML_DEPRECATED void deactivateAttachments() { enableNotifications(false); } 00314 inline ML_DEPRECATED void activateAttachments() { enableNotifications(true); } 00317 inline ML_DEPRECATED MLint isActiveAttachments() { return areNotificationsEnabled(); } 00320 inline ML_DEPRECATED static void disableNotifications() { enableNotificationsGlobally(false); } 00323 inline ML_DEPRECATED static void enableNotifications() { enableNotificationsGlobally(true); } 00326 inline ML_DEPRECATED static MLint isEnabledNotifications() { return areNotificationsEnabledGlobally(); } 00327 00329 00330 #endif // ML_DEPRECATED 00331 00332 00333 }; 00334 00335 ML_END_NAMESPACE 00336 00337 00338 //----------------------------------------------------------------------------------- 00339 // Stream output for std::ostream 00340 //----------------------------------------------------------------------------------- 00341 namespace std 00342 { 00343 00345 MLEXPORT std::ostream& operator<<(std::ostream& s, const ML_NAMESPACE::Field &v); 00346 00347 } 00348 00349 00350 #endif // __mlField_H 00351 00352 00353