SHAPER  9.15.0
Model_Objects.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_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 storeSubShapeWithColor(std::shared_ptr<ModelAPI_Result> theResult,
186  std::shared_ptr<GeomAPI_Shape> theSubShape,
187  const std::vector<int>& theColor);
188 
190  std::vector<int> getSubShapeColor(std::shared_ptr<ModelAPI_Result> theResult,
191  std::shared_ptr<GeomAPI_Shape> theSubShape);
192 
194  void getColoredSubShapes(const std::shared_ptr<ModelAPI_Result> theResult,
195  std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredSubShapes);
196 
198  void removeSubShapeColors(const std::shared_ptr<ModelAPI_Result> theResult);
199 
201  void setOwner(DocumentPtr theDoc);
202 
204  DocumentPtr owner() {return myDoc;}
205 
207  virtual ~Model_Objects();
208 
209  protected:
210 
212  TDF_Label featuresLabel() const;
213 
215  //TDF_Label shapesFromResult(std::shared_ptr<ModelAPI_Result> theResult) const;
216  TDF_Label coloredSubShapesLabel(std::shared_ptr<ModelAPI_Result> theResult) const;
217 
219  TDF_Label coloredSubShapeLabel(TDF_Label& theSubShapesLabel,
220  const int theSubShapeIndex);
221 
226  const int coloredSubShapeIndex(std::shared_ptr<ModelAPI_Result> theResult,
227  std::shared_ptr<GeomAPI_Shape> theSubShape);
228 
231  void setUniqueName(FeaturePtr theFeature);
232 
234  void setUniqueName(FolderPtr theFolder);
235 
243  void synchronizeFeatures(const TDF_LabelList& theUpdated, const bool theUpdateReferences,
244  const bool theOpen, const bool theExecuteFeatures, const bool theFlush);
246  void synchronizeBackRefs();
247 
249  Model_Objects(TDF_Label theMainLab);
250 
252  void initData(ObjectPtr theObj, TDF_Label theLab, const int theTag);
253 
256  void storeResult(std::shared_ptr<ModelAPI_Data> theFeatureData,
257  std::shared_ptr<ModelAPI_Result> theResult,
258  const int theResultIndex = 0,
259  const std::wstring& theNameShape = L"");
260 
262  TDF_Label resultLabel(const std::shared_ptr<ModelAPI_Data>& theFeatureData,
263  const int theResultIndex);
264 
267  void updateResults(FeaturePtr theFeature, std::set<FeaturePtr>& theProcessed);
268 
270  void updateHistory(const std::shared_ptr<ModelAPI_Object> theObject);
271 
273  void updateHistory(const std::string theGroup);
274 
276  void clearHistory(ObjectPtr theObj);
277 
279  void createHistory(const std::string& theGroupID);
280 
285  FeaturePtr nextFeature(FeaturePtr theCurrent, int& theIndex, const bool theReverse = false);
287  FeaturePtr firstFeature();
289  FeaturePtr lastFeature();
291  bool isLater(FeaturePtr theLater, FeaturePtr theCurrent) const;
292 
296  TDF_Label nextLabel(TDF_Label theCurrent, int& theIndex, const bool theReverse = false);
297 
300  std::string featureResultGroup(FeaturePtr theFeature);
301 
304  std::list<std::shared_ptr<ModelAPI_Feature> > allFeatures();
305 
308  std::list<std::shared_ptr<ModelAPI_Object> > allObjects();
309 
312  const std::set<std::shared_ptr<ModelAPI_Attribute>>& theNewRefs, ObjectPtr theObject);
313 
315  virtual void eraseAllFeatures();
316 
317  // Check whether the predefined-image of the result had user-defined name.
318  // If yes, return this name.
319  bool hasCustomName(DataPtr theFeatureData,
320  ResultPtr theResult,
321  int theResultIndex,
322  std::wstring& theParentName) const;
323 
325  const ObjectPtr& folder(TDF_Label theLabel) const;
326 
327  private:
328  TDF_Label myMain;
329 
330  DocumentPtr myDoc;
331 
334  NCollection_DataMap<TDF_Label, FeaturePtr> myFeatures;
335 
337  NCollection_DataMap<TDF_Label, ObjectPtr> myFolders;
338 
341  std::map<std::string, std::vector<ObjectPtr> > myHistory;
342 
343  friend class Model_Document;
344  friend class Model_Session;
345  friend class Model_Update;
346  friend class Model_AttributeReference;
347  friend class Model_AttributeRefAttr;
348  friend class Model_AttributeRefList;
349  friend class Model_AttributeSelection;
350  friend class Model_SelectionNaming;
351 };
352 
353 #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:45
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:1588
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:1636
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:1354
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:978
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:1399
TDF_Label nextLabel(TDF_Label theCurrent, int &theIndex, const bool theReverse=false)
Returns the next or previous label.
Definition: Model_Objects.cpp:2156
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:2262
void moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
Moves the feature to make it after the given one in the history.
Definition: Model_Objects.cpp:396
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:1484
DocumentPtr owner()
Returns the owner of this manager.
Definition: Model_Objects.h:204
FeaturePtr feature(TDF_Label theLabel) const
Returns the existing feature by the label.
Definition: Model_Objects.cpp:574
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:2285
bool removeFromFolder(const std::list< std::shared_ptr< ModelAPI_Feature > > &theFeatures, const bool theBefore=true)
Remove features from the folder.
Definition: Model_Objects.cpp:1835
void getColoredSubShapes(const std::shared_ptr< ModelAPI_Result > theResult, std::map< std::shared_ptr< GeomAPI_Shape >, std::vector< int >> &theColoredSubShapes)
Get colored subshapes from result.
Definition: Model_Objects.cpp:862
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:1544
const int coloredSubShapeIndex(std::shared_ptr< ModelAPI_Result > theResult, std::shared_ptr< GeomAPI_Shape > theSubShape)
Returns the index of the colored subshape in the result.
Definition: Model_Objects.cpp:766
void addFeature(FeaturePtr theFeature, const FeaturePtr theAfterThis)
Registers the feature in the data structure.
Definition: Model_Objects.cpp:196
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:2176
void removeFeature(FeaturePtr theFeature)
Removes the feature from the document (with result)
Definition: Model_Objects.cpp:328
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:648
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:287
int numInternalFeatures()
Returns the number of all features: in the history or not.
Definition: Model_Objects.cpp:2276
TDF_Label coloredSubShapeLabel(TDF_Label &theSubShapesLabel, const int theSubShapeIndex)
Returns (creates if needed) the label of colored subshape by index.
Definition: Model_Objects.cpp:760
virtual ~Model_Objects()
Deletes all managed features with emitting of corresponded signal.
Definition: Model_Objects.cpp:129
void removeSubShapeColors(const std::shared_ptr< ModelAPI_Result > theResult)
Forget subshape colors.
Definition: Model_Objects.cpp:892
void storeSubShapeWithColor(std::shared_ptr< ModelAPI_Result > theResult, std::shared_ptr< GeomAPI_Shape > theSubShape, const std::vector< int > &theColor)
Store theSubShape in theResult, set color attribute to theSubShape.
Definition: Model_Objects.cpp:786
void setOwner(DocumentPtr theDoc)
Sets the owner of this manager.
Definition: Model_Objects.cpp:120
const int index(std::shared_ptr< ModelAPI_Object > theObject, const bool theAllowFolder=false)
Returns the object index in the group.
Definition: Model_Objects.cpp:679
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:1917
void clearHistory(ObjectPtr theObj)
Clears the history arrays related to this object.
Definition: Model_Objects.cpp:451
Model_Objects(TDF_Label theMainLab)
Creates manager on the OCAF document main label.
Definition: Model_Objects.cpp:116
FeaturePtr firstFeature()
Returns to the first (from the history point of view) feature, any: invisible or disabled.
Definition: Model_Objects.cpp:2195
ResultPtr findByName(const std::wstring theName)
Returns the result by the result name.
Definition: Model_Objects.cpp:2122
bool isLater(FeaturePtr theLater, FeaturePtr theCurrent) const
Returns true if theLater is in history of features creation later than theCurrent.
Definition: Model_Objects.cpp:2219
int size(const std::string &theGroupID, const bool theAllowFolder=false)
Returns the number of features in the group.
Definition: Model_Objects.cpp:702
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:1183
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:2018
void setUniqueName(FeaturePtr theFeature)
Initializes feature with a unique name in this group (unique name is generated as feature type + "_" ...
Definition: Model_Objects.cpp:915
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:548
virtual void eraseAllFeatures()
Just removes all features without touching the document data (to be able undo)
Definition: Model_Objects.cpp:368
void createHistory(const std::string &theGroupID)
Creates the history: up to date with the current state.
Definition: Model_Objects.cpp:470
void synchronizeBackRefs()
Synchronizes the BackReferences list in Data of Features and Results.
Definition: Model_Objects.cpp:1294
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:1493
std::shared_ptr< ModelAPI_Object > parent(const std::shared_ptr< ModelAPI_Object > theChild)
Returns the parent object of this child.
Definition: Model_Objects.cpp:709
void allResults(const std::string &theGroupID, std::list< ResultPtr > &theResults)
Returns all (and disabled) results of the given type.
Definition: Model_Objects.cpp:724
TDF_Label featuresLabel() const
Returns (creates if needed) the features label.
Definition: Model_Objects.cpp:748
TDF_Label coloredSubShapesLabel(std::shared_ptr< ModelAPI_Result > theResult) const
Returns (creates if needed) the label of colored subshapes of the result.
Definition: Model_Objects.cpp:753
FeaturePtr lastFeature()
Returns to the last (from the history point of view) feature, any: invisible or disabled.
Definition: Model_Objects.cpp:2204
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:1527
std::vector< int > getSubShapeColor(std::shared_ptr< ModelAPI_Result > theResult, std::shared_ptr< GeomAPI_Shape > theSubShape)
Get color of subshape.
Definition: Model_Objects.cpp:836
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:1467
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:1740
ObjectPtr object(TDF_Label theLabel)
Returns the existing object: result or feature.
Definition: Model_Objects.cpp:581
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:1448
void initData(ObjectPtr theObj, TDF_Label theLab, const int theTag)
Initializes the data fields of the feature.
Definition: Model_Objects.cpp:960
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:1431
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:2002
const ObjectPtr & folder(TDF_Label theLabel) const
Return object representing a folder or empty pointer.
Definition: Model_Objects.cpp:566
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:1510
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:2246
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