SHAPER  9.12.0
Model_Objects.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 Model_Objects_H_
21 #define Model_Objects_H_
22 
23 #include <Model.h>
24 #include <ModelAPI_Document.h>
25 #include <ModelAPI_Feature.h>
26 #include <ModelAPI_Folder.h>
27 #include <ModelAPI_Result.h>
28 #include <ModelAPI_ResultParameter.h>
29 
30 #include <NCollection_DataMap.hxx>
31 #include <TDF_Label.hxx>
32 #include <TDF_LabelList.hxx>
33 #include <map>
34 #include <set>
35 #include <vector>
36 
37 extern int kUNDEFINED_FEATURE_INDEX;
38 
46 {
47  public:
52  void addFeature(FeaturePtr theFeature, const FeaturePtr theAfterThis);
53 
58  void refsToFeature(FeaturePtr theFeature,
59  std::set<FeaturePtr>& theRefs,
60  const bool isSendError = true);
61 
64  void removeFeature(FeaturePtr theFeature);
65 
67  void moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis);
68 
71  FeaturePtr feature(TDF_Label theLabel) const;
72 
75  ObjectPtr object(TDF_Label theLabel);
76 
81  std::shared_ptr<ModelAPI_Object> objectByName(
82  const std::string& theGroupID, const std::wstring& theName);
83 
85  ResultPtr findByName(const std::wstring theName);
86 
87 
92  const int index(std::shared_ptr<ModelAPI_Object> theObject,
93  const bool theAllowFolder = false);
94 
99  ObjectPtr object(const std::string& theGroupID,
100  const int theIndex,
101  const bool theAllowFolder = false);
102 
106  int size(const std::string& theGroupID, const bool theAllowFolder = false);
107 
110  std::shared_ptr<ModelAPI_Object> parent(const std::shared_ptr<ModelAPI_Object> theChild);
111 
114  void allResults(const std::string& theGroupID, std::list<ResultPtr>& theResults);
115 
117  int numInternalFeatures();
119  std::shared_ptr<ModelAPI_Feature> internalFeature(const int theIndex);
120 
122  std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
123  const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
125  std::shared_ptr<ModelAPI_ResultBody> createBody(
126  const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0,
127  const std::wstring& theNameShape = L"");
129  std::shared_ptr<ModelAPI_ResultPart> createPart(
130  const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
132  std::shared_ptr<ModelAPI_ResultPart> copyPart(
133  const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
134  const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
136  std::shared_ptr<ModelAPI_ResultGroup> createGroup(
137  const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
139  std::shared_ptr<ModelAPI_ResultField> createField(
140  const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
142  std::shared_ptr<ModelAPI_ResultParameter> createParameter(
143  const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
144 
146  std::shared_ptr<ModelAPI_Feature>
147  feature(const std::shared_ptr<ModelAPI_Result>& theResult);
148 
150  std::shared_ptr<ModelAPI_Folder> createFolder(
151  const std::shared_ptr<ModelAPI_Feature>& theBeforeThis);
153  void removeFolder(std::shared_ptr<ModelAPI_Folder> theFolder);
159  std::shared_ptr<ModelAPI_Folder> findFolder(
160  const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
161  const bool theBelow);
167  std::shared_ptr<ModelAPI_Folder> findContainingFolder(
168  const std::shared_ptr<ModelAPI_Feature>& theFeature,
169  int& theIndexInFolder);
173  bool moveToFolder(const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
174  const std::shared_ptr<ModelAPI_Folder>& theFolder);
181  bool removeFromFolder(const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
182  const bool theBefore = true);
183 
185  void setOwner(DocumentPtr theDoc);
186 
188  DocumentPtr owner() {return myDoc;}
189 
191  virtual ~Model_Objects();
192 
193  protected:
194 
196  TDF_Label featuresLabel() const;
197 
200  void setUniqueName(FeaturePtr theFeature);
201 
203  void setUniqueName(FolderPtr theFolder);
204 
212  void synchronizeFeatures(const TDF_LabelList& theUpdated, const bool theUpdateReferences,
213  const bool theOpen, const bool theExecuteFeatures, const bool theFlush);
215  void synchronizeBackRefs();
216 
218  Model_Objects(TDF_Label theMainLab);
219 
221  void initData(ObjectPtr theObj, TDF_Label theLab, const int theTag);
222 
225  void storeResult(std::shared_ptr<ModelAPI_Data> theFeatureData,
226  std::shared_ptr<ModelAPI_Result> theResult,
227  const int theResultIndex = 0,
228  const std::wstring& theNameShape = L"");
229 
231  TDF_Label resultLabel(const std::shared_ptr<ModelAPI_Data>& theFeatureData,
232  const int theResultIndex);
233 
236  void updateResults(FeaturePtr theFeature, std::set<FeaturePtr>& theProcessed);
237 
239  void updateHistory(const std::shared_ptr<ModelAPI_Object> theObject);
240 
242  void updateHistory(const std::string theGroup);
243 
245  void clearHistory(ObjectPtr theObj);
246 
248  void createHistory(const std::string& theGroupID);
249 
254  FeaturePtr nextFeature(FeaturePtr theCurrent, int& theIndex, const bool theReverse = false);
256  FeaturePtr firstFeature();
258  FeaturePtr lastFeature();
260  bool isLater(FeaturePtr theLater, FeaturePtr theCurrent) const;
261 
265  TDF_Label nextLabel(TDF_Label theCurrent, int& theIndex, const bool theReverse = false);
266 
269  std::string featureResultGroup(FeaturePtr theFeature);
270 
273  std::list<std::shared_ptr<ModelAPI_Feature> > allFeatures();
274 
277  std::list<std::shared_ptr<ModelAPI_Object> > allObjects();
278 
281  const std::set<std::shared_ptr<ModelAPI_Attribute>>& theNewRefs, ObjectPtr theObject);
282 
284  virtual void eraseAllFeatures();
285 
286  // Check whether the predefined-image of the result had user-defined name.
287  // If yes, return this name.
288  bool hasCustomName(DataPtr theFeatureData,
289  ResultPtr theResult,
290  int theResultIndex,
291  std::wstring& theParentName) const;
292 
294  const ObjectPtr& folder(TDF_Label theLabel) const;
295 
296  private:
297  TDF_Label myMain;
298 
299  DocumentPtr myDoc;
300 
303  NCollection_DataMap<TDF_Label, FeaturePtr> myFeatures;
304 
306  NCollection_DataMap<TDF_Label, ObjectPtr> myFolders;
307 
310  std::map<std::string, std::vector<ObjectPtr> > myHistory;
311 
312  friend class Model_Document;
313  friend class Model_Session;
314  friend class Model_Update;
315  friend class Model_AttributeReference;
316  friend class Model_AttributeRefAttr;
317  friend class Model_AttributeRefList;
318  friend class Model_AttributeSelection;
319  friend class Model_SelectionNaming;
320 };
321 
322 #endif
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 reference to the sub-shape of some result, the selected shape.
Definition: Model_AttributeSelection.h:40
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
void removeFolder(std::shared_ptr< ModelAPI_Folder > theFolder)
Removes the folder from the document (all features in the folder will be kept).
Definition: Model_Objects.cpp:1416
std::shared_ptr< ModelAPI_Folder > findFolder(const std::list< std::shared_ptr< ModelAPI_Feature > > &theFeatures, const bool theBelow)
Search a folder applicable for the list of features (it means the list of features stored in the fold...
Definition: Model_Objects.cpp:1464
TDF_Label resultLabel(const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theResultIndex)
returns the label of result by index; creates this label if it was not created before
Definition: Model_Objects.cpp:1182
void synchronizeFeatures(const TDF_LabelList &theUpdated, const bool theUpdateReferences, const bool theOpen, const bool theExecuteFeatures, const bool theFlush)
Synchronizes myFeatures list with the updated document.
Definition: Model_Objects.cpp:806
void storeResult(std::shared_ptr< ModelAPI_Data > theFeatureData, std::shared_ptr< ModelAPI_Result > theResult, const int theResultIndex=0, const std::wstring &theNameShape=L"")
Allows to store the result in the data tree of the document (attaches 'data' of result to tree)
Definition: Model_Objects.cpp:1227
TDF_Label nextLabel(TDF_Label theCurrent, int &theIndex, const bool theReverse=false)
Returns the next or previous label.
Definition: Model_Objects.cpp:1977
std::list< std::shared_ptr< ModelAPI_Feature > > allFeatures()
Returns all features of the document including the hidden features which are not in history.
Definition: Model_Objects.cpp:2083
void moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
Moves the feature to make it after the given one in the history.
Definition: Model_Objects.cpp:379
std::shared_ptr< ModelAPI_ResultPart > copyPart(const std::shared_ptr< ModelAPI_ResultPart > &theOrigin, const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theIndex=0)
Copies a part result, keeping the reference to origin.
Definition: Model_Objects.cpp:1312
DocumentPtr owner()
Returns the owner of this manager.
Definition: Model_Objects.h:188
FeaturePtr feature(TDF_Label theLabel) const
Returns the existing feature by the label.
Definition: Model_Objects.cpp:557
std::shared_ptr< ModelAPI_Feature > internalFeature(const int theIndex)
Returns the feature by zero-based index: features in the history or not.
Definition: Model_Objects.cpp:2106
bool removeFromFolder(const std::list< std::shared_ptr< ModelAPI_Feature > > &theFeatures, const bool theBefore=true)
Remove features from the folder.
Definition: Model_Objects.cpp:1663
std::shared_ptr< ModelAPI_Folder > createFolder(const std::shared_ptr< ModelAPI_Feature > &theBeforeThis)
Creates a folder (group of the features in the object browser)
Definition: Model_Objects.cpp:1372
void addFeature(FeaturePtr theFeature, const FeaturePtr theAfterThis)
Registers the feature in the data structure.
Definition: Model_Objects.cpp:179
FeaturePtr nextFeature(FeaturePtr theCurrent, int &theIndex, const bool theReverse=false)
Returns the next (from the history point of view) feature, any: invisible or disabled.
Definition: Model_Objects.cpp:1997
void removeFeature(FeaturePtr theFeature)
Removes the feature from the document (with result)
Definition: Model_Objects.cpp:311
std::shared_ptr< ModelAPI_Object > objectByName(const std::string &theGroupID, const std::wstring &theName)
Returns the first found object in the group by the object name.
Definition: Model_Objects.cpp:631
void refsToFeature(FeaturePtr theFeature, std::set< FeaturePtr > &theRefs, const bool isSendError=true)
Return a list of features, which refers to the feature.
Definition: Model_Objects.cpp:270
int numInternalFeatures()
Returns the number of all features: in the history or not.
Definition: Model_Objects.cpp:2097
virtual ~Model_Objects()
Deletes all managed features with emitting of corresponded signal.
Definition: Model_Objects.cpp:112
void setOwner(DocumentPtr theDoc)
Sets the owner of this manager.
Definition: Model_Objects.cpp:103
const int index(std::shared_ptr< ModelAPI_Object > theObject, const bool theAllowFolder=false)
Returns the object index in the group.
Definition: Model_Objects.cpp:662
std::shared_ptr< ModelAPI_Folder > findContainingFolder(const std::shared_ptr< ModelAPI_Feature > &theFeature, int &theIndexInFolder)
Search a folder containing the given feature.
Definition: Model_Objects.cpp:1745
void clearHistory(ObjectPtr theObj)
Clears the history arrays related to this object.
Definition: Model_Objects.cpp:434
Model_Objects(TDF_Label theMainLab)
Creates manager on the OCAF document main label.
Definition: Model_Objects.cpp:99
FeaturePtr firstFeature()
Returns to the first (from the history point of view) feature, any: invisible or disabled.
Definition: Model_Objects.cpp:2016
ResultPtr findByName(const std::wstring theName)
Returns the result by the result name.
Definition: Model_Objects.cpp:1950
bool isLater(FeaturePtr theLater, FeaturePtr theCurrent) const
Returns true if theLater is in history of features creation later than theCurrent.
Definition: Model_Objects.cpp:2040
int size(const std::string &theGroupID, const bool theAllowFolder=false)
Returns the number of features in the group.
Definition: Model_Objects.cpp:685
void synchronizeBackRefsForObject(const std::set< std::shared_ptr< ModelAPI_Attribute >> &theNewRefs, ObjectPtr theObject)
synchronizes back references for the given object basing on the collected data
Definition: Model_Objects.cpp:1011
void updateResults(FeaturePtr theFeature, std::set< FeaturePtr > &theProcessed)
Updates the results list of the feature basing on the current data tree theProcessed is used to avoid...
Definition: Model_Objects.cpp:1846
void setUniqueName(FeaturePtr theFeature)
Initializes feature with a unique name in this group (unique name is generated as feature type + "_" ...
Definition: Model_Objects.cpp:743
void updateHistory(const std::shared_ptr< ModelAPI_Object > theObject)
Internally makes document know that feature was removed or added in history after creation.
Definition: Model_Objects.cpp:531
virtual void eraseAllFeatures()
Just removes all features without touching the document data (to be able undo)
Definition: Model_Objects.cpp:351
void createHistory(const std::string &theGroupID)
Creates the history: up to date with the current state.
Definition: Model_Objects.cpp:453
void synchronizeBackRefs()
Synchronizes the BackReferences list in Data of Features and Results.
Definition: Model_Objects.cpp:1122
std::shared_ptr< ModelAPI_ResultGroup > createGroup(const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theIndex=0)
Creates a group result.
Definition: Model_Objects.cpp:1321
std::shared_ptr< ModelAPI_Object > parent(const std::shared_ptr< ModelAPI_Object > theChild)
Returns the parent object of this child.
Definition: Model_Objects.cpp:692
void allResults(const std::string &theGroupID, std::list< ResultPtr > &theResults)
Returns all (and disabled) results of the given type.
Definition: Model_Objects.cpp:707
TDF_Label featuresLabel() const
Returns (creates if needed) the features label.
Definition: Model_Objects.cpp:731
FeaturePtr lastFeature()
Returns to the last (from the history point of view) feature, any: invisible or disabled.
Definition: Model_Objects.cpp:2025
std::shared_ptr< ModelAPI_ResultParameter > createParameter(const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theIndex=0)
Creates a parameter result.
Definition: Model_Objects.cpp:1355
std::shared_ptr< ModelAPI_ResultPart > createPart(const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theIndex=0)
Creates a part result.
Definition: Model_Objects.cpp:1295
bool moveToFolder(const std::list< std::shared_ptr< ModelAPI_Feature > > &theFeatures, const std::shared_ptr< ModelAPI_Folder > &theFolder)
Add a list of features to the folder.
Definition: Model_Objects.cpp:1568
ObjectPtr object(TDF_Label theLabel)
Returns the existing object: result or feature.
Definition: Model_Objects.cpp:564
std::shared_ptr< ModelAPI_ResultBody > createBody(const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theIndex=0, const std::wstring &theNameShape=L"")
Creates a body result.
Definition: Model_Objects.cpp:1276
void initData(ObjectPtr theObj, TDF_Label theLab, const int theTag)
Initializes the data fields of the feature.
Definition: Model_Objects.cpp:788
std::shared_ptr< ModelAPI_ResultConstruction > createConstruction(const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theIndex=0)
Creates a construction result.
Definition: Model_Objects.cpp:1259
std::string featureResultGroup(FeaturePtr theFeature)
Returns the result group identifier of the given feature (for this at least one result must be create...
Definition: Model_Objects.cpp:1830
const ObjectPtr & folder(TDF_Label theLabel) const
Return object representing a folder or empty pointer.
Definition: Model_Objects.cpp:549
std::shared_ptr< ModelAPI_ResultField > createField(const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theIndex=0)
Creates a field result.
Definition: Model_Objects.cpp:1338
std::list< std::shared_ptr< ModelAPI_Object > > allObjects()
Returns all objects of the document including the hidden features which are not in history.
Definition: Model_Objects.cpp:2067
Object that knows (from the initial XML file) which plugin contains which feature,...
Definition: Model_Session.h:43
Updates the results of features when it is needed.
Definition: Model_Update.h:40