SHAPER  9.15.0
Model_Data.h
1 // Copyright (C) 2014-2025 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
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
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 http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef Model_Data_H_
21 #define Model_Data_H_
22 
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>
41 
42 #include <TDF_Label.hxx>
43 #include <TDataStd_BooleanArray.hxx>
44 
45 #include <memory>
46 
47 #include <map>
48 #include <list>
49 #include <string>
50 #include <vector>
51 #include <set>
52 
53 class ModelAPI_Attribute;
54 
61 class Model_Data : public ModelAPI_Data
62 {
63  typedef std::map<std::string, std::pair<std::shared_ptr<ModelAPI_Attribute>, int> > AttributeMap;
64 
65  TDF_Label myLab;
68  AttributeMap myAttrs;
70  Handle(TDataStd_BooleanArray) myFlags;
71 
73  ObjectPtr myObject;
74 
76  std::set<AttributePtr> myRefsToMe;
78  bool mySendAttributeUpdated;
80  std::list<ModelAPI_Attribute*> myWasChangedButBlocked;
81 
83  TDF_Label label()
84  {
85  return myLab;
86  }
87 
88  friend class Model_Document;
89  friend class Model_Objects;
90  friend class Model_Update;
91  friend class Model_AttributeReference;
92  friend class Model_AttributeRefAttr;
93  friend class Model_AttributeRefList;
94  friend class Model_AttributeRefAttrList;
95  friend class Model_AttributeSelection;
96  friend class Model_AttributeSelectionList;
97  friend class Model_ValidatorsFactory;
98  friend class Model_SelectionNaming;
99  friend class Model_ResultConstruction;
100  friend class Model_ResultBody;
101  friend class Model_Tools;
102 
103  public:
105  Model_Data();
107  MODEL_EXPORT virtual std::wstring name();
109  MODEL_EXPORT virtual std::wstring name(std::shared_ptr<GeomAPI_Shape> theSubShape);
111  MODEL_EXPORT virtual void setName(const std::wstring& theName);
113  MODEL_EXPORT virtual bool hasUserDefinedName() const;
115  MODEL_EXPORT virtual std::string version();
117  MODEL_EXPORT virtual void setVersion(const std::string& theVersion);
119  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID);
121  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID);
123  MODEL_EXPORT virtual
124  std::shared_ptr<ModelAPI_AttributeDoubleArray> realArray(const std::string& theID);
126  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeInteger>
127  integer(const std::string& theID);
129  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeReference>
130  reference(const std::string& theID);
132  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection>
133  selection(const std::string& theID);
135  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelectionList>
136  selectionList(const std::string& theID);
138  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeRefAttr>
139  refattr(const std::string& theID);
141  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeRefList>
142  reflist(const std::string& theID);
145  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeRefAttrList>
146  refattrlist(const std::string& theID);
148  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeBoolean>
149  boolean(const std::string& theID);
151  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeString>
152  string(const std::string& theID);
154  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeIntArray>
155  intArray(const std::string& theID);
157  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeStringArray>
158  stringArray(const std::string& theID);
160  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeTables>
161  tables(const std::string& theID);
163  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeImage>
164  image(const std::string& theID);
165 
168  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID);
171  MODEL_EXPORT virtual std::list<std::shared_ptr<ModelAPI_Attribute> >
172  attributes(const std::string& theType);
175  MODEL_EXPORT virtual std::list<std::string> attributesIDs(const std::string& theType);
176 
179  MODEL_EXPORT virtual const std::string& id(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
181  MODEL_EXPORT virtual bool isEqual(const std::shared_ptr<ModelAPI_Data>& theData);
183  MODEL_EXPORT virtual bool isValid();
184 
186  TDF_Label shapeLab() const
187  {
188  return myLab.IsNull() ? myLab : myLab.Father().FindChild(2);
189  }
190 
198  MODEL_EXPORT virtual AttributePtr
199  addAttribute(const std::string& theID, const std::string theAttrType, const int theIndex = -1);
200 
205  MODEL_EXPORT virtual AttributePtr
206  addFloatingAttribute(const std::string& theID, const std::string theAttrType,
207  const std::string& theGroup);
208 
210  MODEL_EXPORT virtual void allGroups(std::list<std::string>& theGroups);
211 
213  MODEL_EXPORT virtual void attributesOfGroup(const std::string& theGroup,
214  std::list<std::shared_ptr<ModelAPI_Attribute> >& theAttrs);
215 
217  MODEL_EXPORT virtual void removeAttributes(const std::string& theGroup);
218 
221  MODEL_EXPORT virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr);
228  MODEL_EXPORT virtual bool blockSendAttributeUpdated(
229  const bool theBlock, const bool theSendMessage = true);
230 
232  MODEL_EXPORT void setLabel(TDF_Label theLab);
233 
235  MODEL_EXPORT virtual void setObject(ObjectPtr theObject)
236  {
237  myObject = theObject;
238  }
239 
241  MODEL_EXPORT virtual void erase();
242 
244  MODEL_EXPORT virtual void execState(const ModelAPI_ExecState theState);
245 
247  MODEL_EXPORT virtual ModelAPI_ExecState execState();
248 
250  MODEL_EXPORT virtual void setError(const std::string& theError, bool theSend = true);
251 
253  void eraseErrorString();
254 
256  MODEL_EXPORT virtual std::string error() const;
257 
259  MODEL_EXPORT virtual int featureId() const;
260 
262  MODEL_EXPORT virtual const std::set<AttributePtr>& refsToMe() {return myRefsToMe;}
263 
267  MODEL_EXPORT virtual void referencesToObjects(
268  std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs);
269 
271  MODEL_EXPORT virtual void copyTo(std::shared_ptr<ModelAPI_Data> theTarget);
272 
274  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Data> invalidPtr();
275 
277  static std::shared_ptr<ModelAPI_Data> invalidData();
278 
280  MODEL_EXPORT virtual int updateID();
281 
284  MODEL_EXPORT virtual void setUpdateID(const int theID);
285 
288  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Object> owner();
289 
290 protected:
292  MODEL_EXPORT virtual bool isInHistory();
293 
295  MODEL_EXPORT virtual void setIsInHistory(const bool theFlag);
296 
298  MODEL_EXPORT virtual bool isDeleted();
299 
301  MODEL_EXPORT virtual void setIsDeleted(const bool theFlag);
302 
304  void clearAttributes();
305 
306 private:
310  void removeBackReference(ObjectPtr theObject, std::string theAttrID);
313  void removeBackReference(AttributePtr theAttr);
318  void addBackReference(FeaturePtr theFeature, std::string theAttrID,
319  const bool theApplyConcealment = true);
323  void addBackReference(ObjectPtr theObject, std::string theAttrID);
324 
326  MODEL_EXPORT virtual void updateConcealmentFlag();
327 
331  MODEL_EXPORT virtual bool isDisplayed();
332 
335  MODEL_EXPORT virtual void setDisplayed(const bool theDisplay);
336 
338  MODEL_EXPORT virtual bool isPrecedingAttribute(const std::string& theAttribute1,
339  const std::string& theAttribute2) const;
340 
341 };
342 
345 #define ADD_BACK_REF(TARGET) \
346  if (TARGET.get() != NULL) { \
347  std::shared_ptr<Model_Data> aTargetData = \
348  std::dynamic_pointer_cast<Model_Data>((TARGET)->data()); \
349  FeaturePtr anAttributeOwnerFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner()); \
350  if (anAttributeOwnerFeature.get()) \
351  aTargetData->addBackReference(anAttributeOwnerFeature, id(), false); \
352  else { \
353  FolderPtr anAttributeOwnerFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(owner()); \
354  if (anAttributeOwnerFolder.get()) \
355  aTargetData->addBackReference(ObjectPtr(anAttributeOwnerFolder), id()); \
356  } \
357  }
358 
361 #define REMOVE_BACK_REF(TARGET) \
362  if (TARGET.get() != NULL) { \
363  std::shared_ptr<Model_Data> aTargetData = \
364  std::dynamic_pointer_cast<Model_Data>((TARGET)->data()); \
365  FeaturePtr anAttOwnerFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner()); \
366  if (anAttOwnerFeature.get()) \
367  aTargetData->removeBackReference(anAttOwnerFeature, id()); \
368  else { \
369  FolderPtr anAttributeOwnerFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(owner()); \
370  if (anAttributeOwnerFolder.get()) \
371  aTargetData->removeBackReference(ObjectPtr(anAttributeOwnerFolder), id()); \
372  } \
373  }
374 
375 #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:73
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:62
Model_Data()
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:392
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:150
virtual MODEL_EXPORT void copyTo(std::shared_ptr< ModelAPI_Data > theTarget)
Copies all attributes content into theTarget data.
Definition: Model_Data.cpp:860
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:597
virtual MODEL_EXPORT void setObject(ObjectPtr theObject)
Sets the object of this data.
Definition: Model_Data.h:235
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:402
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:602
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_Attribute > attribute(const std::string &theID)
Returns the generic attribute by identifier.
Definition: Model_Data.cpp:409
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:925
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:211
virtual MODEL_EXPORT bool isDeleted()
Returns true if the object is deleted, but some data is still kept in memory.
Definition: Model_Data.cpp:880
virtual MODEL_EXPORT int updateID()
Identifier of the transaction when object (feature or result) was updated last time.
Definition: Model_Data.cpp:592
virtual MODEL_EXPORT void removeAttributes(const std::string &theGroup)
Remove all attributes of the given group.
Definition: Model_Data.cpp:354
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeBoolean > boolean(const std::string &theID)
Returns the attribute that contains boolean value.
Definition: Model_Data.cpp:395
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:400
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:401
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:442
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:290
virtual MODEL_EXPORT std::string error() const
Registers error during the execution, causes the ExecutionFailed state.
Definition: Model_Data.cpp:616
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeImage > image(const std::string &theID)
Returns the attribute that contains image.
Definition: Model_Data.cpp:407
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:406
virtual MODEL_EXPORT const std::set< AttributePtr > & refsToMe()
returns all objects referenced to this
Definition: Model_Data.h:262
virtual MODEL_EXPORT int featureId() const
Returns the identifier of feature-owner, unique in this document.
Definition: Model_Data.cpp:625
void eraseErrorString()
Erases the error string if it is not empty.
Definition: Model_Data.cpp:611
virtual MODEL_EXPORT bool isEqual(const std::shared_ptr< ModelAPI_Data > &theData)
Returns true if data belongs to same features.
Definition: Model_Data.cpp:429
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:404
void clearAttributes()
Erases all attributes from myAttrs, but keeping them in the data structure.
Definition: Model_Data.cpp:374
virtual MODEL_EXPORT bool hasUserDefinedName() const
Return true if the object has been renamed by the user.
Definition: Model_Data.cpp:188
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:393
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:455
virtual MODEL_EXPORT void erase()
Erases all the data from the data model.
Definition: Model_Data.cpp:535
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:405
static std::shared_ptr< ModelAPI_Data > invalidData()
Returns the invalid data pointer: static method.
Definition: Model_Data.cpp:920
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:885
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:468
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:870
virtual MODEL_EXPORT void setIsInHistory(const bool theFlag)
Defines the custom "is in history" behavior.
Definition: Model_Data.cpp:875
virtual MODEL_EXPORT void allGroups(std::list< std::string > &theGroups)
Returns all groups of this data (ordered).
Definition: Model_Data.cpp:326
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:915
virtual MODEL_EXPORT void setVersion(const std::string &theVersion)
Initialize the version of the feature.
Definition: Model_Data.cpp:202
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:398
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:751
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:186
virtual MODEL_EXPORT std::shared_ptr< ModelAPI_AttributeInteger > integer(const std::string &theID)
Returns the attribute that contains integer value.
Definition: Model_Data.cpp:394
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:339
virtual MODEL_EXPORT std::string version()
Returns version of the feature (empty string if not applicable)
Definition: Model_Data.cpp:193
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:399
virtual MODEL_EXPORT bool isValid()
Returns true if it is correctly connected to the data model.
Definition: Model_Data.cpp:437
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:417
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:396
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:397
virtual MODEL_EXPORT bool blockSendAttributeUpdated(const bool theBlock, const bool theSendMessage=true)
Blocks sending "attribute updated" if theBlock is true.
Definition: Model_Data.cpp:502
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:403
virtual MODEL_EXPORT ModelAPI_ExecState execState()
Returns the state of the latest execution of the feature.
Definition: Model_Data.cpp:587
Document for internal data structure of any object storage.
Definition: Model_Document.h:45
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