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 ModelAPI_Feature_H_
21 #define ModelAPI_Feature_H_
23 #include <ModelAPI.h>
24 #include <ModelAPI_Object.h>
25 #include <ModelAPI_Data.h>
26 #include <ModelAPI_Document.h>
28 #include <memory>
30 #include <list>
31 #include <string>
39 {
41  std::list<std::shared_ptr<ModelAPI_Result> > myResults;
43  bool myIsDisabled;
45  bool myIsStable;
47  public:
49  virtual const std::string& getKind() = 0;
52  inline static std::string group()
53  {
54  static std::string MY_GROUP = "Features";
55  return MY_GROUP;
56  }
59  virtual std::shared_ptr<ModelAPI_Document> document() const
60  {
62  }
65  virtual std::string groupName()
66  {
67  return group();
68  }
71  virtual void execute() = 0;
76  virtual bool compute(const std::string& /*theAttributeId*/) { return false; };
79  MODELAPI_EXPORT virtual void setError(const std::string& theError,
80  bool isSend = true,
81  bool isTranslate = true);
84  virtual std::string error() const {
85  return data()->error();
86  }
89  MODELAPI_EXPORT const std::list<std::shared_ptr<ModelAPI_Result> >& results();
91  MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> firstResult() const;
93  MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> lastResult();
95  MODELAPI_EXPORT void setResult(const std::shared_ptr<ModelAPI_Result>& theResult);
97  MODELAPI_EXPORT void setResult(const std::shared_ptr<ModelAPI_Result>& theResult,
98  const int theIndex);
103  MODELAPI_EXPORT void removeResults(const int theSinceIndex,
104  const bool theForever = true, const bool theFlush = true);
106  MODELAPI_EXPORT void eraseResults(const bool theForever = true);
108  MODELAPI_EXPORT virtual void erase();
111  MODELAPI_EXPORT void eraseResultFromList(const std::shared_ptr<ModelAPI_Result>& theResult);
115  virtual bool isPersistentResult() {return true;}
119  virtual bool isAction()
120  {
121  return false;
122  }
126  MODELAPI_EXPORT virtual bool isMacro() const;
131  MODELAPI_EXPORT virtual bool isPreviewNeeded() const;
135  MODELAPI_EXPORT virtual const std::string& documentToAdd();
140  MODELAPI_EXPORT virtual bool setDisabled(const bool theFlag);
143  MODELAPI_EXPORT virtual bool isDisabled();
146  MODELAPI_EXPORT virtual ~ModelAPI_Feature();
149  MODELAPI_EXPORT static std::shared_ptr<ModelAPI_Feature> feature(ObjectPtr theObject);
153  MODELAPI_EXPORT virtual bool setStable(const bool theFlag);
156  MODELAPI_EXPORT virtual bool isStable();
159  MODELAPI_EXPORT virtual bool isEditable();
164  MODELAPI_EXPORT virtual bool customAction(const std::string& theActionId);
166  //
167  // Helper methods, aliases for data()->method()
168  // -----------------------------------------------------------------------------------------------
170  inline std::wstring name()
171  {
172  return data()->name();
173  }
175  inline std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID)
176  {
177  return data()->boolean(theID);
178  }
180  inline std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID)
181  {
182  return data()->document(theID);
183  }
185  inline std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID)
186  {
187  return data()->real(theID);
188  }
190  inline std::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID)
191  {
192  return data()->integer(theID);
193  }
195  inline std::shared_ptr<ModelAPI_AttributeIntArray> intArray(const std::string& theID)
196  {
197  return data()->intArray(theID);
198  }
200  inline std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID)
201  {
202  return data()->refattr(theID);
203  }
205  inline std::shared_ptr<ModelAPI_AttributeRefAttrList> refattrlist(const std::string& theID)
206  {
207  return data()->refattrlist(theID);
208  }
210  inline std::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID)
211  {
212  return data()->reference(theID);
213  }
215  inline std::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID)
216  {
217  return data()->reflist(theID);
218  }
220  inline std::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID)
221  {
222  return data()->selection(theID);
223  }
225  inline std::shared_ptr<ModelAPI_AttributeSelectionList> selectionList(const std::string& theID)
226  {
227  return data()->selectionList(theID);
228  }
230  inline std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID)
231  {
232  return data()->string(theID);
233  }
235  inline std::shared_ptr<ModelAPI_AttributeStringArray> stringArray(const std::string& theID)
236  {
237  return data()->stringArray(theID);
238  }
240  inline std::shared_ptr<ModelAPI_AttributeTables> tables(const std::string& theID)
241  {
242  return data()->tables(theID);
243  }
245  inline std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID)
246  {
247  return data()->attribute(theID);
248  }
249  protected:
252  MODELAPI_EXPORT virtual void init();
254  friend class Model_Document;
255  friend class Model_Objects;
256 };
259 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
264 public:
265  virtual ~ModelAPI_FeatureCopyInterface() {}
271  virtual void getCopies(ObjectPtr theContext, std::shared_ptr<GeomAPI_Shape> theValue,
272  std::list<ObjectPtr>& theCopyContext,
273  std::list<std::shared_ptr<GeomAPI_Shape> >& theCopyVals) = 0;
274 };
276 #endif
An interface for performing special copy actions.
Definition: ModelAPI_Feature.h:263
virtual void getCopies(ObjectPtr theContext, std::shared_ptr< GeomAPI_Shape > theValue, std::list< ObjectPtr > &theCopyContext, std::list< std::shared_ptr< GeomAPI_Shape > > &theCopyVals)=0
An algorithm to update the moved feature by the separate Copy feature.
Feature function that represents the particular functionality of this operation.
Definition: ModelAPI_Feature.h:39
virtual void execute()=0
Computes or recomputes the results.
MODELAPI_EXPORT std::shared_ptr< ModelAPI_Result > firstResult() const
returns the first result in the list or NULL reference
Definition: ModelAPI_Feature.cpp:46
virtual const std::string & getKind()=0
Returns the unique kind of a feature (like "Point")
virtual MODELAPI_EXPORT bool isStable()
Returns the feature is stable or not.
Definition: ModelAPI_Feature.cpp:251
virtual MODELAPI_EXPORT bool isEditable()
Returns the feature is editable or not. Most of features are editable.
Definition: ModelAPI_Feature.cpp:256
MODELAPI_EXPORT void eraseResults(const bool theForever=true)
removes all results from the feature
Definition: ModelAPI_Feature.cpp:150
std::shared_ptr< ModelAPI_AttributeString > string(const std::string &theID)
Returns the string attribute by the identifier.
Definition: ModelAPI_Feature.h:230
MODELAPI_EXPORT const std::list< std::shared_ptr< ModelAPI_Result > > & results()
returns the current results of the feature
Definition: ModelAPI_Feature.cpp:41
virtual MODELAPI_EXPORT bool isDisabled()
Returns the feature is disabled or not.
Definition: ModelAPI_Feature.cpp:230
virtual std::string error() const
Returns error, arose during the execution.
Definition: ModelAPI_Feature.h:84
std::shared_ptr< ModelAPI_AttributeTables > tables(const std::string &theID)
Returns the tables attribute by the identifier.
Definition: ModelAPI_Feature.h:240
MODELAPI_EXPORT std::shared_ptr< ModelAPI_Result > lastResult()
returns the last result in the list or NULL reference
Definition: ModelAPI_Feature.cpp:51
virtual bool isPersistentResult()
Returns true if result is persistent (stored in document) and on undo-redo, save-open it is not neede...
Definition: ModelAPI_Feature.h:115
std::shared_ptr< ModelAPI_Attribute > attribute(const std::string &theID)
Returns the attribute by the identifier.
Definition: ModelAPI_Feature.h:245
virtual bool compute(const std::string &)
Computes the attribute value on the base of other attributes if the value can be computed.
Definition: ModelAPI_Feature.h:76
std::shared_ptr< ModelAPI_AttributeDouble > real(const std::string &theID)
Returns the real attribute by the identifier.
Definition: ModelAPI_Feature.h:185
std::shared_ptr< ModelAPI_AttributeSelectionList > selectionList(const std::string &theID)
Returns the list of shape selections attribute by the identifier.
Definition: ModelAPI_Feature.h:225
virtual MODELAPI_EXPORT void init()
This method is called just after creation of the object: it must initialize all fields,...
Definition: ModelAPI_Feature.cpp:271
MODELAPI_EXPORT void removeResults(const int theSinceIndex, const bool theForever=true, const bool theFlush=true)
removes all results starting from the given index (zero-based)
Definition: ModelAPI_Feature.cpp:121
virtual MODELAPI_EXPORT bool isMacro() const
Returns true if this feature is used as macro: creates other features and then removed.
Definition: ModelAPI_Feature.cpp:199
std::shared_ptr< ModelAPI_AttributeIntArray > intArray(const std::string &theID)
Returns the integer array attribute by the identifier.
Definition: ModelAPI_Feature.h:195
static std::string group()
Returns the group identifier of all features.
Definition: ModelAPI_Feature.h:52
std::shared_ptr< ModelAPI_AttributeSelection > selection(const std::string &theID)
Returns the shape selection attribute by the identifier.
Definition: ModelAPI_Feature.h:220
virtual MODELAPI_EXPORT void setError(const std::string &theError, bool isSend=true, bool isTranslate=true)
Registers error during the execution, causes the ExecutionFailed state.
Definition: ModelAPI_Feature.cpp:32
MODELAPI_EXPORT void eraseResultFromList(const std::shared_ptr< ModelAPI_Result > &theResult)
removes the result from the list of feature (not doing in disabled): normally this method is not used...
Definition: ModelAPI_Feature.cpp:100
std::shared_ptr< ModelAPI_AttributeRefAttrList > refattrlist(const std::string &theID)
Returns the refattrlist attribute by the identifier.
Definition: ModelAPI_Feature.h:205
std::shared_ptr< ModelAPI_AttributeBoolean > boolean(const std::string &theID)
Returns the Boolean attribute by the identifier.
Definition: ModelAPI_Feature.h:175
std::shared_ptr< ModelAPI_AttributeStringArray > stringArray(const std::string &theID)
Returns the string array attribute by the identifier.
Definition: ModelAPI_Feature.h:235
virtual MODELAPI_EXPORT bool setStable(const bool theFlag)
Set the stable feature flag.
Definition: ModelAPI_Feature.cpp:236
std::shared_ptr< ModelAPI_AttributeRefList > reflist(const std::string &theID)
Returns the list of references attribute by the identifier.
Definition: ModelAPI_Feature.h:215
std::shared_ptr< ModelAPI_AttributeInteger > integer(const std::string &theID)
Returns the integer attribute by the identifier.
Definition: ModelAPI_Feature.h:190
virtual std::shared_ptr< ModelAPI_Document > document() const
Returns document this feature belongs to.
Definition: ModelAPI_Feature.h:59
virtual MODELAPI_EXPORT const std::string & documentToAdd()
Must return document where the new feature must be added to By default it is empty: it is added to th...
Definition: ModelAPI_Feature.cpp:155
std::shared_ptr< ModelAPI_AttributeDocRef > document(const std::string &theID)
Returns the document reference attribute.
Definition: ModelAPI_Feature.h:180
std::wstring name()
Returns the name stored in the attribute.
Definition: ModelAPI_Feature.h:170
virtual MODELAPI_EXPORT void erase()
removes all fields from this feature: results, data, etc
Definition: ModelAPI_Feature.cpp:162
std::shared_ptr< ModelAPI_AttributeRefAttr > refattr(const std::string &theID)
Returns the reference attribute by the identifier.
Definition: ModelAPI_Feature.h:200
static MODELAPI_EXPORT std::shared_ptr< ModelAPI_Feature > feature(ObjectPtr theObject)
Returns the feature by the object (result).
Definition: ModelAPI_Feature.cpp:186
std::shared_ptr< ModelAPI_AttributeReference > reference(const std::string &theID)
Returns the reference attribute by the identifier.
Definition: ModelAPI_Feature.h:210
virtual MODELAPI_EXPORT bool customAction(const std::string &theActionId)
Performs some custom feature specific functionality (normally called by some GUI button)
Definition: ModelAPI_Feature.cpp:261
virtual MODELAPI_EXPORT bool isPreviewNeeded() const
Returns true if preview update during the edition needed.
Definition: ModelAPI_Feature.cpp:266
virtual MODELAPI_EXPORT bool setDisabled(const bool theFlag)
Enables/disables the feature.
Definition: ModelAPI_Feature.cpp:204
MODELAPI_EXPORT void setResult(const std::shared_ptr< ModelAPI_Result > &theResult)
sets the alone result
Definition: ModelAPI_Feature.cpp:56
virtual bool isAction()
Returns true if this feature must not be created: this is just an action that is not stored in the fe...
Definition: ModelAPI_Feature.h:119
virtual std::string groupName()
Returns the group identifier of this result.
Definition: ModelAPI_Feature.h:65
virtual MODELAPI_EXPORT ~ModelAPI_Feature()
To virtually destroy the fields of successors.
Definition: ModelAPI_Feature.cpp:180
Represents any object in the data model and in the object browser.
Definition: ModelAPI_Object.h:45
virtual std::shared_ptr< ModelAPI_Data > data() const
Returns the data manager of this object: attributes.
Definition: ModelAPI_Object.cpp:45
virtual std::shared_ptr< ModelAPI_Document > document() const
Returns document this feature belongs to.
Definition: ModelAPI_Object.cpp:55
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