SHAPER  9.12.0
1 // Copyright (C) 2014-2023 CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See or email :
18 //
20 #ifndef Model_Data_H_
21 #define Model_Data_H_
23 #include <Model.h>
24 #include <ModelAPI_Attribute.h>
25 #include <ModelAPI_AttributeBoolean.h>
26 #include <ModelAPI_AttributeDocRef.h>
27 #include <ModelAPI_AttributeDouble.h>
28 #include <ModelAPI_AttributeInteger.h>
29 #include <ModelAPI_AttributeRefAttr.h>
30 #include <ModelAPI_AttributeReference.h>
31 #include <ModelAPI_AttributeRefList.h>
32 #include <ModelAPI_AttributeRefAttrList.h>
33 #include <ModelAPI_AttributeString.h>
34 #include <ModelAPI_AttributeStringArray.h>
35 #include <ModelAPI_AttributeIntArray.h>
36 #include <ModelAPI_AttributeImage.h>
37 #include <ModelAPI_Data.h>
38 #include <ModelAPI_Feature.h>
39 #include <ModelAPI_Folder.h>
40 #include <ModelAPI_Object.h>
42 #include <TDF_Label.hxx>
43 #include <TDataStd_BooleanArray.hxx>
45 #include <memory>
47 #include <map>
48 #include <list>
49 #include <string>
50 #include <set>
52 class ModelAPI_Attribute;
60 class Model_Data : public ModelAPI_Data
61 {
62  typedef std::map<std::string, std::pair<std::shared_ptr<ModelAPI_Attribute>, int> > AttributeMap;
64  TDF_Label myLab;
67  AttributeMap myAttrs;
69  Handle(TDataStd_BooleanArray) myFlags;
72  ObjectPtr myObject;
75  std::set<AttributePtr> myRefsToMe;
77  bool mySendAttributeUpdated;
79  std::list<ModelAPI_Attribute*> myWasChangedButBlocked;
82  TDF_Label label()
83  {
84  return myLab;
85  }
87  friend class Model_Document;
88  friend class Model_Objects;
89  friend class Model_Update;
90  friend class Model_AttributeReference;
91  friend class Model_AttributeRefAttr;
92  friend class Model_AttributeRefList;
93  friend class Model_AttributeRefAttrList;
94  friend class Model_AttributeSelection;
95  friend class Model_AttributeSelectionList;
96  friend class Model_ValidatorsFactory;
97  friend class Model_SelectionNaming;
98  friend class Model_ResultConstruction;
99  friend class Model_ResultBody;
100  friend class Model_Tools;
102  public:
104  Model_Data();
106  MODEL_EXPORT virtual std::wstring name();
108  MODEL_EXPORT virtual void setName(const std::wstring& theName);
110  MODEL_EXPORT virtual bool hasUserDefinedName() const;
112  MODEL_EXPORT virtual std::string version();
114  MODEL_EXPORT virtual void setVersion(const std::string& theVersion);
116  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID);
118  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID);
120  MODEL_EXPORT virtual
121  std::shared_ptr<ModelAPI_AttributeDoubleArray> realArray(const std::string& theID);
123  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeInteger>
124  integer(const std::string& theID);
126  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeReference>
127  reference(const std::string& theID);
129  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection>
130  selection(const std::string& theID);
132  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelectionList>
133  selectionList(const std::string& theID);
135  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeRefAttr>
136  refattr(const std::string& theID);
138  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeRefList>
139  reflist(const std::string& theID);
142  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeRefAttrList>
143  refattrlist(const std::string& theID);
145  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeBoolean>
146  boolean(const std::string& theID);
148  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeString>
149  string(const std::string& theID);
151  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeIntArray>
152  intArray(const std::string& theID);
154  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeStringArray>
155  stringArray(const std::string& theID);
157  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeTables>
158  tables(const std::string& theID);
160  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeImage>
161  image(const std::string& theID);
165  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID);
168  MODEL_EXPORT virtual std::list<std::shared_ptr<ModelAPI_Attribute> >
169  attributes(const std::string& theType);
172  MODEL_EXPORT virtual std::list<std::string> attributesIDs(const std::string& theType);
176  MODEL_EXPORT virtual const std::string& id(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
178  MODEL_EXPORT virtual bool isEqual(const std::shared_ptr<ModelAPI_Data>& theData);
180  MODEL_EXPORT virtual bool isValid();
183  TDF_Label shapeLab() const
184  {
185  return myLab.IsNull() ? myLab : myLab.Father().FindChild(2);
186  }
195  MODEL_EXPORT virtual AttributePtr
196  addAttribute(const std::string& theID, const std::string theAttrType, const int theIndex = -1);
202  MODEL_EXPORT virtual AttributePtr
203  addFloatingAttribute(const std::string& theID, const std::string theAttrType,
204  const std::string& theGroup);
207  MODEL_EXPORT virtual void allGroups(std::list<std::string>& theGroups);
210  MODEL_EXPORT virtual void attributesOfGroup(const std::string& theGroup,
211  std::list<std::shared_ptr<ModelAPI_Attribute> >& theAttrs);
214  MODEL_EXPORT virtual void removeAttributes(const std::string& theGroup);
218  MODEL_EXPORT virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr);
225  MODEL_EXPORT virtual bool blockSendAttributeUpdated(
226  const bool theBlock, const bool theSendMessage = true);
229  MODEL_EXPORT void setLabel(TDF_Label theLab);
232  MODEL_EXPORT virtual void setObject(ObjectPtr theObject)
233  {
234  myObject = theObject;
235  }
238  MODEL_EXPORT virtual void erase();
241  MODEL_EXPORT virtual void execState(const ModelAPI_ExecState theState);
244  MODEL_EXPORT virtual ModelAPI_ExecState execState();
247  MODEL_EXPORT virtual void setError(const std::string& theError, bool theSend = true);
250  void eraseErrorString();
253  MODEL_EXPORT virtual std::string error() const;
256  MODEL_EXPORT virtual int featureId() const;
259  MODEL_EXPORT virtual const std::set<AttributePtr>& refsToMe() {return myRefsToMe;}
264  MODEL_EXPORT virtual void referencesToObjects(
265  std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs);
268  MODEL_EXPORT virtual void copyTo(std::shared_ptr<ModelAPI_Data> theTarget);
271  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Data> invalidPtr();
274  static std::shared_ptr<ModelAPI_Data> invalidData();
277  MODEL_EXPORT virtual int updateID();
281  MODEL_EXPORT virtual void setUpdateID(const int theID);
285  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Object> owner();
287 protected:
289  MODEL_EXPORT virtual bool isInHistory();
292  MODEL_EXPORT virtual void setIsInHistory(const bool theFlag);
295  MODEL_EXPORT virtual bool isDeleted();
298  MODEL_EXPORT virtual void setIsDeleted(const bool theFlag);
301  void clearAttributes();
303 private:
307  void removeBackReference(ObjectPtr theObject, std::string theAttrID);
310  void removeBackReference(AttributePtr theAttr);
315  void addBackReference(FeaturePtr theFeature, std::string theAttrID,
316  const bool theApplyConcealment = true);
320  void addBackReference(ObjectPtr theObject, std::string theAttrID);
323  MODEL_EXPORT virtual void updateConcealmentFlag();
328  MODEL_EXPORT virtual bool isDisplayed();
332  MODEL_EXPORT virtual void setDisplayed(const bool theDisplay);
335  MODEL_EXPORT virtual bool isPrecedingAttribute(const std::string& theAttribute1,
336  const std::string& theAttribute2) const;
338 };
342 #define ADD_BACK_REF(TARGET) \
343  if (TARGET.get() != NULL) { \
344  std::shared_ptr<Model_Data> aTargetData = \
345  std::dynamic_pointer_cast<Model_Data>((TARGET)->data()); \
346  FeaturePtr anAttributeOwnerFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner()); \
347  if (anAttributeOwnerFeature.get()) \
348  aTargetData->addBackReference(anAttributeOwnerFeature, id(), false); \
349  else { \
350  FolderPtr anAttributeOwnerFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(owner()); \
351  if (anAttributeOwnerFolder.get()) \
352  aTargetData->addBackReference(ObjectPtr(anAttributeOwnerFolder), id()); \
353  } \
354  }
359  if (TARGET.get() != NULL) { \
360  std::shared_ptr<Model_Data> aTargetData = \
361  std::dynamic_pointer_cast<Model_Data>((TARGET)->data()); \
362  FeaturePtr anAttOwnerFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner()); \
363  if (anAttOwnerFeature.get()) \
364  aTargetData->removeBackReference(anAttOwnerFeature, id()); \
365  else { \
366  FolderPtr anAttributeOwnerFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(owner()); \
367  if (anAttributeOwnerFolder.get()) \
368  aTargetData->removeBackReference(ObjectPtr(anAttributeOwnerFolder), id()); \
369  } \
370  }
372 #endif
Generic attribute of the Object.
Definition: ModelAPI_Attribute.h:34
General object of the application that allows to get/set attributes from the document and compute res...
Definition: ModelAPI_Data.h:72
Attribute that contains list of references to features (located in the same document) or references t...
Definition: Model_AttributeRefAttrList.h:38
Attribute that contains reference to an attribute of a feature (located in the same document).
Definition: Model_AttributeRefAttr.h:36
Attribute that contains list of references to features, may be located in different documents.
Definition: Model_AttributeRefList.h:37
Attribute that contains reference to feature (located in the same document).
Definition: Model_AttributeReference.h:35
Attribute that contains list of references to the sub-shapes with possibility to manage them.
Definition: Model_AttributeSelectionList.h:38
Attribute that contains reference to the sub-shape of some result, the selected shape.
Definition: Model_AttributeSelection.h:40
General object of the application that allows to get/set attributes from the document and compute res...
Definition: Model_Data.h:61
The simplest constructor. "setLabel" must be called just after to initialize correctly.
Definition: Model_Data.cpp:95
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeDocRef > document(const std::string &theID)
Returns the attribute that references to another document.
Definition: Model_Data.cpp:366
virtual MODEL_EXPORT void setName(const std::wstring &theName)
Defines the name of the feature visible by the user in the object browser.
Definition: Model_Data.cpp:124
virtual MODEL_EXPORT void copyTo(std::shared_ptr< ModelAPI_Data > theTarget)
Copies all attributes content into theTarget data.
Definition: Model_Data.cpp:834
virtual MODEL_EXPORT void setUpdateID(const int theID)
Identifier of the transaction when object (feature or result) was updated last time.
Definition: Model_Data.cpp:571
virtual MODEL_EXPORT void setObject(ObjectPtr theObject)
Sets the object of this data.
Definition: Model_Data.h:232
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeRefList > reflist(const std::string &theID)
Returns the attribute that contains list of references to features.
Definition: Model_Data.cpp:376
virtual MODEL_EXPORT void setError(const std::string &theError, bool theSend=true)
Registers error during the execution, causes the ExecutionFailed state.
Definition: Model_Data.cpp:576
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_Attribute > attribute(const std::string &theID)
Returns the generic attribute by identifier.
Definition: Model_Data.cpp:383
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_Object > owner()
Returns true if the given object is owner of this data (needed for correct erase of object with dupli...
Definition: Model_Data.cpp:899
virtual MODEL_EXPORT AttributePtr addAttribute(const std::string &theID, const std::string theAttrType, const int theIndex=-1)
Initializes object by the attributes: must be called just after the object is created for each attrib...
Definition: Model_Data.cpp:185
virtual MODEL_EXPORT bool isDeleted()
Returns true if the object is deleted, but some data is still kept in memory.
Definition: Model_Data.cpp:854
virtual MODEL_EXPORT int updateID()
Identifier of the transaction when object (feature or result) was updated last time.
Definition: Model_Data.cpp:566
virtual MODEL_EXPORT void removeAttributes(const std::string &theGroup)
Remove all attributes of the given group.
Definition: Model_Data.cpp:328
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeBoolean > boolean(const std::string &theID)
Returns the attribute that contains boolean value.
Definition: Model_Data.cpp:369
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeSelectionList > selectionList(const std::string &theID)
Returns the attribute that contains selection to a shape.
Definition: Model_Data.cpp:374
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeRefAttr > refattr(const std::string &theID)
Returns the attribute that contains reference to an attribute of a feature.
Definition: Model_Data.cpp:375
virtual MODEL_EXPORT std::list< std::shared_ptr< ModelAPI_Attribute > > attributes(const std::string &theType)
Returns all attributes of the feature of the given type or all attributes if "theType" is empty.
Definition: Model_Data.cpp:416
virtual MODEL_EXPORT AttributePtr addFloatingAttribute(const std::string &theID, const std::string theAttrType, const std::string &theGroup)
Adds a floating attribute (that may be added/removed during the data life)
Definition: Model_Data.cpp:264
virtual MODEL_EXPORT std::string error() const
Registers error during the execution, causes the ExecutionFailed state.
Definition: Model_Data.cpp:590
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeImage > image(const std::string &theID)
Returns the attribute that contains image.
Definition: Model_Data.cpp:381
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeTables > tables(const std::string &theID)
Returns the attribute that contains string values array.
Definition: Model_Data.cpp:380
virtual MODEL_EXPORT const std::set< AttributePtr > & refsToMe()
returns all objects referenced to this
Definition: Model_Data.h:259
virtual MODEL_EXPORT int featureId() const
Returns the identifier of feature-owner, unique in this document.
Definition: Model_Data.cpp:599
void eraseErrorString()
Erases the error string if it is not empty.
Definition: Model_Data.cpp:585
virtual MODEL_EXPORT bool isEqual(const std::shared_ptr< ModelAPI_Data > &theData)
Returns true if data belongs to same features.
Definition: Model_Data.cpp:403
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeIntArray > intArray(const std::string &theID)
Returns the attribute that contains integer values array.
Definition: Model_Data.cpp:378
void clearAttributes()
Erases all attributes from myAttrs, but keeping them in the data structure.
Definition: Model_Data.cpp:348
virtual MODEL_EXPORT bool hasUserDefinedName() const
Return true if the object has been renamed by the user.
Definition: Model_Data.cpp:162
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeDouble > real(const std::string &theID)
Returns the attribute that contains real value with double precision.
Definition: Model_Data.cpp:367
virtual MODEL_EXPORT std::list< std::string > attributesIDs(const std::string &theType)
Returns all attributes ids of the feature of the given type or all attributes if "theType" is empty.
Definition: Model_Data.cpp:429
virtual MODEL_EXPORT void erase()
Erases all the data from the data model.
Definition: Model_Data.cpp:509
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeDoubleArray > realArray(const std::string &theID)
Returns the attribute that contains double values array.
Definition: Model_Data.cpp:379
static std::shared_ptr< ModelAPI_Data > invalidData()
Returns the invalid data pointer: static method.
Definition: Model_Data.cpp:894
virtual MODEL_EXPORT void setIsDeleted(const bool theFlag)
Sets true if the object is deleted, but some data is still kept in memory.
Definition: Model_Data.cpp:859
virtual MODEL_EXPORT void sendAttributeUpdated(ModelAPI_Attribute *theAttr)
Useful method for "set" methods of the attributes: sends an UPDATE event and makes attribute initiali...
Definition: Model_Data.cpp:442
MODEL_EXPORT void setLabel(TDF_Label theLab)
Puts feature to the document data sub-structure.
Definition: Model_Data.cpp:99
virtual MODEL_EXPORT bool isInHistory()
Returns true if "is in history" custom behaviors is defined for the feature.
Definition: Model_Data.cpp:844
virtual MODEL_EXPORT void setIsInHistory(const bool theFlag)
Defines the custom "is in history" behavior.
Definition: Model_Data.cpp:849
virtual MODEL_EXPORT void allGroups(std::list< std::string > &theGroups)
Returns all groups of this data (ordered).
Definition: Model_Data.cpp:300
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_Data > invalidPtr()
Returns the invalid data pointer (to avoid working with NULL shared pointers in swig)
Definition: Model_Data.cpp:889
virtual MODEL_EXPORT void setVersion(const std::string &theVersion)
Initialize the version of the feature.
Definition: Model_Data.cpp:176
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeReference > reference(const std::string &theID)
Returns the attribute that contains reference to a feature.
Definition: Model_Data.cpp:372
virtual MODEL_EXPORT void referencesToObjects(std::list< std::pair< std::string, std::list< ObjectPtr > > > &theRefs)
returns all references by attributes of this data
Definition: Model_Data.cpp:725
virtual MODEL_EXPORT std::wstring name()
Returns the name of the feature visible by the user in the object browser.
Definition: Model_Data.cpp:112
TDF_Label shapeLab() const
Returns the label where the shape must be stored (used in ResultBody)
Definition: Model_Data.h:183
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeInteger > integer(const std::string &theID)
Returns the attribute that contains integer value.
Definition: Model_Data.cpp:368
virtual MODEL_EXPORT void attributesOfGroup(const std::string &theGroup, std::list< std::shared_ptr< ModelAPI_Attribute > > &theAttrs)
Returns an ordered list of attributes that belong to the given group.
Definition: Model_Data.cpp:313
virtual MODEL_EXPORT std::string version()
Returns version of the feature (empty string if not applicable)
Definition: Model_Data.cpp:167
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeSelection > selection(const std::string &theID)
Returns the attribute that contains selection to a shape.
Definition: Model_Data.cpp:373
virtual MODEL_EXPORT bool isValid()
Returns true if it is correctly connected to the data model.
Definition: Model_Data.cpp:411
virtual MODEL_EXPORT const std::string & id(const std::shared_ptr< ModelAPI_Attribute > &theAttr)
Identifier by the id (not fast, iteration by map)
Definition: Model_Data.cpp:391
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeString > string(const std::string &theID)
Returns the attribute that contains real value with double precision.
Definition: Model_Data.cpp:370
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeStringArray > stringArray(const std::string &theID)
Returns the attribute that contains string values array.
Definition: Model_Data.cpp:371
virtual MODEL_EXPORT bool blockSendAttributeUpdated(const bool theBlock, const bool theSendMessage=true)
Blocks sending "attribute updated" if theBlock is true.
Definition: Model_Data.cpp:476
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeRefAttrList > refattrlist(const std::string &theID)
Returns the attribute that contains list of references to features or reference to an attribute of a ...
Definition: Model_Data.cpp:377
virtual MODEL_EXPORT ModelAPI_ExecState execState()
Returns the state of the latest execution of the feature.
Definition: Model_Data.cpp:561
Document for internal data structure of any object storage.
Definition: Model_Document.h:44
Manager of objects of the document.
Definition: Model_Objects.h:46
The body (shape) result of a feature.
Definition: Model_ResultBody.h:40
The construction element result of a feature.
Definition: Model_ResultConstruction.h:38
A collection of methods useful for different parts of data model.
Definition: Model_Tools.h:33
Updates the results of features when it is needed.
Definition: Model_Update.h:40
Manages the registered validators.
Definition: Model_Validator.h:41