SHAPER  9.12.0
ModelAPI_Data.h
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
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 ModelAPI_Data_H_
21 #define ModelAPI_Data_H_
22 
23 #ifdef _WINDOWS // to avoid too long decorated name warning
24 #pragma warning( disable : 4503 )
25 #endif
26 
27 #include "ModelAPI.h"
28 #include <string>
29 #include <list>
30 #include <set>
31 #include <memory>
32 
33 class ModelAPI_Attribute;
45 class ModelAPI_Document;
46 class ModelAPI_Attribute;
47 class ModelAPI_Feature;
53 class ModelAPI_Object;
54 class GeomAPI_Shape;
55 
57 enum ModelAPI_ExecState {
58  ModelAPI_StateDone,
59  ModelAPI_StateMustBeUpdated,
60  ModelAPI_StateExecFailed,
61  ModelAPI_StateInvalidArgument,
62  ModelAPI_StateNothing
63 };
64 
71 class MODELAPI_EXPORT ModelAPI_Data
72 {
73  public:
74 
76  virtual std::wstring name() = 0;
78  virtual void setName(const std::wstring& theName) = 0;
80  virtual bool hasUserDefinedName() const = 0;
81 
83  virtual std::string version() = 0;
85  virtual void setVersion(const std::string& theVersion) = 0;
86 
88  virtual std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID) = 0;
90  virtual std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID) = 0;
92  virtual std::shared_ptr<ModelAPI_AttributeDoubleArray> realArray(const std::string& theID) = 0;
94  virtual std::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID) = 0;
96  virtual std::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID) = 0;
98  virtual std::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID) = 0;
100  virtual std::shared_ptr<ModelAPI_AttributeSelectionList>
101  selectionList(const std::string& theID) = 0;
103  virtual std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID) = 0;
105  virtual std::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID) = 0;
108  virtual std::shared_ptr<ModelAPI_AttributeRefAttrList> refattrlist(const std::string& theID) = 0;
110  virtual std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID) = 0;
112  virtual std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID) = 0;
114  virtual std::shared_ptr<ModelAPI_AttributeIntArray> intArray(const std::string& theID) = 0;
116  virtual std::shared_ptr<ModelAPI_AttributeStringArray> stringArray(const std::string& theID) = 0;
118  virtual std::shared_ptr<ModelAPI_AttributeImage> image(const std::string& theID) = 0;
120  virtual std::shared_ptr<ModelAPI_AttributeTables> tables(const std::string& theID) = 0;
121 
124  virtual std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID) = 0;
127  virtual std::list<std::shared_ptr<ModelAPI_Attribute> >
128  attributes(const std::string& theType) = 0;
131  virtual std::list<std::string> attributesIDs(const std::string& theType) = 0;
134  virtual const std::string& id(const std::shared_ptr<ModelAPI_Attribute>& theAttr) = 0;
136  virtual bool isEqual(const std::shared_ptr<ModelAPI_Data>& theData) = 0;
138  virtual bool isValid() = 0;
139 
147  virtual std::shared_ptr<ModelAPI_Attribute> addAttribute(
148  const std::string& theID, const std::string theAttrType, const int theIndex = -1) = 0;
149 
154  virtual std::shared_ptr<ModelAPI_Attribute>
155  addFloatingAttribute(const std::string& theID, const std::string theAttrType,
156  const std::string& theGroup) = 0;
157 
159  virtual void allGroups(std::list<std::string>& theGroups) = 0;
160 
162  virtual void attributesOfGroup(const std::string& theGroup,
163  std::list<std::shared_ptr<ModelAPI_Attribute> >& theAttrs) = 0;
164 
166  virtual void removeAttributes(const std::string& theGroup) = 0;
167 
170  virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr) = 0;
176  const bool theBlock, const bool theSendMessage = true) = 0;
177 
179  virtual void erase() = 0;
180 
182  virtual ~ModelAPI_Data();
183 
185  virtual void execState(const ModelAPI_ExecState theState) = 0;
186 
188  virtual ModelAPI_ExecState execState() = 0;
189 
191  virtual void setError(const std::string& theError, bool theSend = true) = 0;
192 
194  virtual std::string error() const = 0;
195 
197  virtual int featureId() const = 0;
198 
200  virtual const std::set<std::shared_ptr<ModelAPI_Attribute> >& refsToMe() = 0;
201 
205  virtual void referencesToObjects(
206  std::list<std::pair<std::string, std::list<std::shared_ptr<ModelAPI_Object> > > >& theRefs) =0;
207 
209  virtual void copyTo(std::shared_ptr<ModelAPI_Data> theTarget) = 0;
210 
212  virtual std::shared_ptr<ModelAPI_Data> invalidPtr() = 0;
213 
215  virtual int updateID() = 0;
216 
219  virtual void setUpdateID(const int theID) = 0;
220 
222  virtual std::shared_ptr<ModelAPI_Object> owner() = 0;
223 
225  virtual bool isDeleted() = 0;
226 
228  virtual void setIsDeleted(const bool theFlag) = 0;
229 
231  virtual bool isPrecedingAttribute(const std::string& theAttribute1,
232  const std::string& theAttribute2) const = 0;
233 
234  protected:
236  ModelAPI_Data();
237 
239  virtual bool isInHistory() = 0;
240 
242  virtual void setIsInHistory(const bool theFlag) = 0;
243 
247  virtual bool isDisplayed() = 0;
248 
251  virtual void setDisplayed(const bool theDisplay) = 0;
252 
253  friend class ModelAPI_Object;
254 };
255 
256 typedef std::shared_ptr<ModelAPI_Data> DataPtr;
257 
258 #endif
Interface to the topological shape object.
Definition: GeomAPI_Shape.h:43
Attribute that contains boolean value.
Definition: ModelAPI_AttributeBoolean.h:31
Attribute that contains reference to another document.
Definition: ModelAPI_AttributeDocRef.h:32
API for the attribute that contains several double in the array inside.
Definition: ModelAPI_AttributeDoubleArray.h:32
Attribute that contains real value with double precision.
Definition: ModelAPI_AttributeDouble.h:34
API for the attribute that contains binary data.
Definition: ModelAPI_AttributeImage.h:37
API for the attribute that contains several integers in the array inside.
Definition: ModelAPI_AttributeIntArray.h:36
API for the attribute that contains integer (int).
Definition: ModelAPI_AttributeInteger.h:34
Attribute that contains list of references to features (located in the same document) or references t...
Definition: ModelAPI_AttributeRefAttrList.h:34
Attribute that contains reference to an attribute of a feature or reference to a feature (switchable)
Definition: ModelAPI_AttributeRefAttr.h:33
Attribute that contains list of references to features (located in the same document).
Definition: ModelAPI_AttributeRefList.h:33
Attribute that contains reference to feature (located in the same document).
Definition: ModelAPI_AttributeReference.h:32
Attribute that contains list of references to the sub-shapes with possibility to manage them.
Definition: ModelAPI_AttributeSelectionList.h:37
Attribute that contains reference to the sub-shape of some result, the selected shape.
Definition: ModelAPI_AttributeSelection.h:35
API for the attribute that contains several strings in the array inside.
Definition: ModelAPI_AttributeStringArray.h:32
API for the attribute that contains std (null terminated) string.
Definition: ModelAPI_AttributeString.h:33
API for the attribute that contains tables of some values type.
Definition: ModelAPI_AttributeTables.h:39
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
virtual void setError(const std::string &theError, bool theSend=true)=0
Registers error during the execution, causes the ExecutionFailed state.
virtual std::shared_ptr< ModelAPI_AttributeSelectionList > selectionList(const std::string &theID)=0
Returns the attribute that contains selection to a shape.
virtual bool isDisplayed()=0
Returns true if object must be displayed in the viewer: flag is stored in the data model,...
virtual std::shared_ptr< ModelAPI_Attribute > addAttribute(const std::string &theID, const std::string theAttrType, const int theIndex=-1)=0
Initializes object by the attributes: must be called just after the object is created for each attrib...
virtual int featureId() const =0
Returns the identifier of feature-owner, unique in this document.
virtual bool isInHistory()=0
Returns true if "is in history" custom behaviors is defined for the feature.
virtual std::list< std::string > attributesIDs(const std::string &theType)=0
Returns all attributes ids of the feature of the given type or all attributes if "theType" is empty.
virtual void sendAttributeUpdated(ModelAPI_Attribute *theAttr)=0
Useful method for "set" methods of the attributes: sends an UPDATE event and makes attribute initiali...
virtual void setName(const std::wstring &theName)=0
Defines the name of the feature visible by the user in the object browser.
virtual std::shared_ptr< ModelAPI_AttributeRefList > reflist(const std::string &theID)=0
Returns the attribute that contains list of references to features.
virtual std::string version()=0
Returns version of the feature (empty string if not applicable)
virtual int updateID()=0
Identifier of the transaction when object (feature or result) was updated last time.
virtual std::shared_ptr< ModelAPI_AttributeIntArray > intArray(const std::string &theID)=0
Returns the attribute that contains integer values array.
virtual bool isDeleted()=0
Returns true if the object is deleted, but some data is still kept in memory.
virtual std::shared_ptr< ModelAPI_Attribute > attribute(const std::string &theID)=0
Returns the generic attribute by identifier.
virtual bool isEqual(const std::shared_ptr< ModelAPI_Data > &theData)=0
Returns true if data belongs to same features.
virtual std::string error() const =0
Returns error, arose during the execution.
virtual void setVersion(const std::string &theVersion)=0
Initialize the version of the feature.
virtual std::shared_ptr< ModelAPI_AttributeRefAttr > refattr(const std::string &theID)=0
Returns the attribute that contains reference to an attribute of a feature.
virtual std::shared_ptr< ModelAPI_Attribute > addFloatingAttribute(const std::string &theID, const std::string theAttrType, const std::string &theGroup)=0
Adds a floating attribute (that may be added/removed during the data life)
virtual void removeAttributes(const std::string &theGroup)=0
Remove all attributes of the given group.
virtual bool isValid()=0
Returns true if it is correctly connected to the data model.
virtual std::shared_ptr< ModelAPI_AttributeReference > reference(const std::string &theID)=0
Returns the attribute that contains reference to a feature.
virtual std::shared_ptr< ModelAPI_AttributeString > string(const std::string &theID)=0
Returns the attribute that contains boolean value.
virtual bool isPrecedingAttribute(const std::string &theAttribute1, const std::string &theAttribute2) const =0
Returns true if theAttribute1 is going earlier than theAttribute2 in the data.
virtual void setUpdateID(const int theID)=0
Identifier of the transaction when object (feature or result) was updated last time.
virtual const std::string & id(const std::shared_ptr< ModelAPI_Attribute > &theAttr)=0
Identifier by the id (not fast, iteration by map)
virtual const std::set< std::shared_ptr< ModelAPI_Attribute > > & refsToMe()=0
returns all objects referenced to this
virtual std::wstring name()=0
Returns the name of the feature visible by the user in the object browser.
virtual std::shared_ptr< ModelAPI_AttributeInteger > integer(const std::string &theID)=0
Returns the attribute that contains integer value.
virtual std::shared_ptr< ModelAPI_AttributeDocRef > document(const std::string &theID)=0
Returns the attribute that references to another document.
virtual void copyTo(std::shared_ptr< ModelAPI_Data > theTarget)=0
Copies all attributes content into theTarget data.
virtual std::shared_ptr< ModelAPI_Data > invalidPtr()=0
Returns the invalid data pointer (to avoid working with NULL shared pointers in swig)
virtual bool blockSendAttributeUpdated(const bool theBlock, const bool theSendMessage=true)=0
Blocks sending "attribute updated" if theBlock is true.
virtual std::shared_ptr< ModelAPI_AttributeTables > tables(const std::string &theID)=0
Returns the attribute that contains tables.
virtual std::shared_ptr< ModelAPI_Object > owner()=0
Returns the owner of this data.
virtual void attributesOfGroup(const std::string &theGroup, std::list< std::shared_ptr< ModelAPI_Attribute > > &theAttrs)=0
Returns an ordered list of attributes that belong to the given group.
virtual std::shared_ptr< ModelAPI_AttributeStringArray > stringArray(const std::string &theID)=0
Returns the attribute that contains string values array.
virtual ModelAPI_ExecState execState()=0
Returns the state of the latest execution of the feature.
virtual void erase()=0
Erases all the data from the data model.
virtual std::shared_ptr< ModelAPI_AttributeBoolean > boolean(const std::string &theID)=0
Returns the attribute that contains boolean value.
virtual void execState(const ModelAPI_ExecState theState)=0
Stores the state of the object to execute it later accordingly.
virtual std::shared_ptr< ModelAPI_AttributeDouble > real(const std::string &theID)=0
Returns the attribute that contains real value with double precision.
virtual void setDisplayed(const bool theDisplay)=0
Sets the displayed/hidden state of the object.
virtual std::shared_ptr< ModelAPI_AttributeDoubleArray > realArray(const std::string &theID)=0
Returns the attribute that contains double values array.
virtual std::list< std::shared_ptr< ModelAPI_Attribute > > attributes(const std::string &theType)=0
Returns all attributes of the feature of the given type or all attributes if "theType" is empty.
virtual std::shared_ptr< ModelAPI_AttributeRefAttrList > refattrlist(const std::string &theID)=0
Returns the attribute that contains list of references to features or reference to an attribute of a ...
virtual void referencesToObjects(std::list< std::pair< std::string, std::list< std::shared_ptr< ModelAPI_Object > > > > &theRefs)=0
returns all references by attributes of this data
virtual void allGroups(std::list< std::string > &theGroups)=0
Returns all groups of this data (ordered).
virtual std::shared_ptr< ModelAPI_AttributeImage > image(const std::string &theID)=0
Returns the attribute that contains image.
virtual void setIsDeleted(const bool theFlag)=0
Sets true if the object is deleted, but some data is still kept in memory.
virtual void setIsInHistory(const bool theFlag)=0
Defines the custom "is in history" behavior.
virtual bool hasUserDefinedName() const =0
Return true if the object has been renamed by the user.
virtual std::shared_ptr< ModelAPI_AttributeSelection > selection(const std::string &theID)=0
Returns the attribute that contains selection to a shape.
Document for internal data structure of any object storage.
Definition: ModelAPI_Document.h:52
Feature function that represents the particular functionality of this operation.
Definition: ModelAPI_Feature.h:39
Represents any object in the data model and in the object browser.
Definition: ModelAPI_Object.h:45