1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_Data.hxx
4 // Created: 21 Mar 2014
5 // Author: Mikhail PONIKAROV
11 #include <ModelAPI_Attribute.h>
12 #include <ModelAPI_AttributeBoolean.h>
13 #include <ModelAPI_AttributeDocRef.h>
14 #include <ModelAPI_AttributeDouble.h>
15 #include <ModelAPI_AttributeInteger.h>
16 #include <ModelAPI_AttributeRefAttr.h>
17 #include <ModelAPI_AttributeReference.h>
18 #include <ModelAPI_AttributeRefList.h>
19 #include <ModelAPI_AttributeString.h>
20 #include <ModelAPI_Data.h>
21 #include <ModelAPI_Feature.h>
22 #include <ModelAPI_Object.h>
24 #include <TDF_Label.hxx>
33 class ModelAPI_Attribute;
37 * \brief General object of the application that allows
38 * to get/set attributes from the document and compute result of an operation.
41 class Model_Data : public ModelAPI_Data
43 TDF_Label myLab; ///< label of the feature in the document
44 /// All attributes of the object identified by the attribute ID
45 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> > myAttrs;
47 /// needed here to emit signal that object changed on change of the attribute
50 /// List of attributes referenced to owner (updated only during the transaction change)
51 std::set<AttributePtr> myRefsToMe;
52 /// flag that may block the "attribute updated" sending
53 bool mySendAttributeUpdated;
57 /// Returns label of this feature
63 friend class Model_Document;
64 friend class Model_Update;
65 friend class Model_AttributeReference;
66 friend class Model_AttributeRefAttr;
67 friend class Model_AttributeRefList;
68 friend class Model_AttributeSelection;
71 /// Returns the name of the feature visible by the user in the object browser
72 MODEL_EXPORT virtual std::string name();
73 /// Defines the name of the feature visible by the user in the object browser
74 MODEL_EXPORT virtual void setName(const std::string& theName);
75 /// Returns the attribute that references to another document
76 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID);
77 /// Returns the attribute that contains real value with double precision
78 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID);
79 /// Returns the attribute that contains integer value
80 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeInteger>
81 integer(const std::string& theID);
82 /// Returns the attribute that contains reference to a feature
83 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeReference>
84 reference(const std::string& theID);
85 /// Returns the attribute that contains selection to a shape
86 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection>
87 selection(const std::string& theID);
88 /// Returns the attribute that contains selection to a shape
89 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelectionList>
90 selectionList(const std::string& theID);
91 /// Returns the attribute that contains reference to an attribute of a feature
92 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeRefAttr>
93 refattr(const std::string& theID);
94 /// Returns the attribute that contains list of references to features
95 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeRefList>
96 reflist(const std::string& theID);
97 /// Returns the attribute that contains boolean value
98 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeBoolean>
99 boolean(const std::string& theID);
100 /// Returns the attribute that contains real value with double precision
101 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeString>
102 string(const std::string& theID);
103 /// Returns the generic attribute by identifier
104 /// \param theID identifier of the attribute
105 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID);
106 /// Returns all attributes of the feature of the given type
107 /// or all attributes if "theType" is empty
108 MODEL_EXPORT virtual std::list<std::shared_ptr<ModelAPI_Attribute> >
109 attributes(const std::string& theType);
110 /// Returns all attributes ids of the feature of the given type
111 /// or all attributes if "theType" is empty
112 MODEL_EXPORT virtual std::list<std::string> attributesIDs(const std::string& theType);
114 /// Identifier by the id (not fast, iteration by map)
115 /// \param theAttr attribute already created in this data
116 MODEL_EXPORT virtual const std::string& id(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
117 /// Returns true if data belongs to same features
118 MODEL_EXPORT virtual bool isEqual(const std::shared_ptr<ModelAPI_Data>& theData);
119 /// Returns true if it is correctly connected t othe data model
120 MODEL_EXPORT virtual bool isValid();
122 /// Returns the label where the shape must be stored (used in ResultBody)
123 TDF_Label& shapeLab()
128 /// Initializes object by the attributes: must be called just after the object is created
129 /// for each attribute of the object
130 /// \param theID identifier of the attribute that can be referenced by this ID later
131 /// \param theAttrType type of the created attribute (received from the type method)
132 MODEL_EXPORT virtual void addAttribute(const std::string& theID, const std::string theAttrType);
134 /// Useful method for "set" methods of the attributes: sends an UPDATE event and
135 /// makes attribute initialized
136 MODEL_EXPORT virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr);
137 /// Blocks sending "attribute updated" if theBlock is true
138 MODEL_EXPORT virtual void blockSendAttributeUpdated(const bool theBlock);
140 /// Puts feature to the document data sub-structure
141 MODEL_EXPORT void setLabel(TDF_Label theLab);
143 /// Sets the object of this data
144 MODEL_EXPORT virtual void setObject(ObjectPtr theObject)
146 myObject = theObject;
149 /// Erases all the data from the data model
150 MODEL_EXPORT virtual void erase();
152 /// Stores the state of the object to execute it later accordingly
153 MODEL_EXPORT virtual void execState(const ModelAPI_ExecState theState);
155 /// Returns the state of the latest execution of the feature
156 MODEL_EXPORT virtual ModelAPI_ExecState execState();
158 /// Registers error during the execution, causes the ExecutionFailed state
159 MODEL_EXPORT virtual void setError(const std::string& theError);
161 /// Returns the identifier of feature-owner, unique in this document
162 MODEL_EXPORT virtual int featureId() const;
164 /// returns all objects referenced to this
165 MODEL_EXPORT virtual const std::set<AttributePtr>& refsToMe() {return myRefsToMe;}
167 /// returns all references by attributes of this data
168 /// \param theRefs returned list of pairs: id of referenced attribute and list of referenced objects
169 MODEL_EXPORT virtual void referencesToObjects(
170 std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs);
173 /// removes all information about back references
174 void eraseBackReferences();
175 // adds a back reference (with identifier which attribute references to this object
176 void addBackReference(FeaturePtr theFeature, std::string theAttrID);