]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_AttributeSelection.h
Salome HOME
Fix the problem with renamed sketch edges vertices selection (the stator_ermes case)
[modules/shaper.git] / src / Model / Model_AttributeSelection.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef Model_AttributeSelection_H_
22 #define Model_AttributeSelection_H_
23
24 #include "Model.h"
25 #include "Model_AttributeReference.h"
26 #include <ModelAPI_AttributeSelection.h>
27 #include <Selector_NameGenerator.h>
28 #include <TDF_LabelMap.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopTools_ListOfShape.hxx>
31
32 class Model_AttributeSelectionList;
33 class Model_Document;
34 class ModelAPI_ResultConstruction;
35
36 /**\class Model_AttributeSelection
37  * \ingroup DataModel
38  * \brief Attribute that contains reference to the sub-shape of some result, the selected shape.
39  */
40 class Model_AttributeSelection : public ModelAPI_AttributeSelection,
41                                  public Selector_NameGenerator
42 {
43   Model_AttributeReference myRef;  ///< The reference functionality re-usage
44   /// temporarily storages to avoid keeping in the data structure if not needed
45   ResultPtr myTmpContext;
46   /// temporarily storages to avoid keeping in the data structure if not needed
47   std::shared_ptr<GeomAPI_Shape> myTmpSubShape;
48   /// temporarily storages to avoid keeping in the data structure if not needed
49   CenterType myTmpCenterType;
50   /// Reference to the parent attribute, if any (to split selection compounds in issue 1799)
51   Model_AttributeSelectionList* myParent;
52
53   std::shared_ptr<Model_Document> myRestoreDocument; // current document to restore by name
54 public:
55   /// Defines the result and its selected sub-shape
56   /// \param theContext object where the sub-shape was selected
57   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
58   /// \param theTemporarily if it is true, do not store and name the added in the data framework
59   ///           (used to remove immediately, without the following updates)
60   /// \returns true if attribute was updated
61   MODEL_EXPORT virtual bool setValue(
62     const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
63     const bool theTemporarily = false);
64
65   /// Same as SetValue, but it takes an edge (on circular or elliptical curve)
66   /// and stores the vertex of the central point (for ellipse the first or the second focus point)
67   MODEL_EXPORT virtual void setValueCenter(
68     const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Edge>& theEdge,
69     const CenterType theCenterType,
70     const bool theTemporarily = false);
71
72   /// Makes this selection attribute selects the same as in theSource selection
73   MODEL_EXPORT virtual void selectValue(
74     const std::shared_ptr<ModelAPI_AttributeSelection>& theSource);
75
76   /// Reset temporary stored values
77   virtual void removeTemporaryValues();
78
79   /// Returns the selected subshape
80   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> value();
81
82   /// Returns the context of the selection (the whole shape owner)
83   MODEL_EXPORT virtual ResultPtr context();
84
85   /// Returns the context of the selection if the whole feature was selected
86   MODEL_EXPORT virtual FeaturePtr contextFeature();
87   /// Returns the context of the selection : result or feature
88   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Object> contextObject();
89
90   /// Sets the feature object
91   MODEL_EXPORT virtual void setObject(const std::shared_ptr<ModelAPI_Object>& theObject);
92
93   /// Updates the selection due to the changes in the referenced objects
94   /// \returns false if update is failed
95   MODEL_EXPORT virtual bool update();
96
97   /// Returns a textual string of the selection
98   /// \param theDefaultValue a name, which is returned if the naming name can not be obtained
99   MODEL_EXPORT virtual std::string namingName(const std::string& theDefaultValue = "");
100
101   /// Returns an Id of the selection
102   /// NOTE: This method has been added for temporary export of groups towards old GEOM
103   /// It should then be removed when a direct use of objects from SHAPER
104   /// will be possible from SMESH module of SALOME.
105   MODEL_EXPORT virtual int Id();
106
107   /// Defines the sub-shape by Id
108   /// NOTE: This method is opposite to Id() method.
109   MODEL_EXPORT virtual void setId(int theID);
110
111   /// Selects (i.e. creates Naming data structure) of sub-shape specified by textual name
112   MODEL_EXPORT virtual void selectSubShape(const std::string& theType,
113                                            const std::string& theSubShapeName);
114
115   /// Selects sub-shape by its inner point
116   MODEL_EXPORT virtual void selectSubShape(const std::string& theType,
117                                            const std::shared_ptr<GeomAPI_Pnt>& thePoint);
118   /// Selects sub-shape by weak naming index
119   MODEL_EXPORT virtual void selectSubShape(const std::string& theType,
120     const std::string& theContextName, const int theIndex);
121
122   /// Returns true if attribute was  initialized by some value
123   MODEL_EXPORT virtual bool isInitialized();
124
125   /// Returns true if recompute of selection become impossible
126   MODEL_EXPORT virtual bool isInvalid();
127
128   /// Updates the arguments of selection if something was affected by creation
129   /// or reorder of features upper in the history line (issue #1757)
130   MODEL_EXPORT virtual void updateInHistory();
131
132   // Implementation of the name generator method from the Selector package
133   // This method returns the context name by the label of the sub-selected shape
134   MODEL_EXPORT virtual std::string contextName(const TDF_Label theSelectionLab) override;
135
136   /// This method restores by the context and value name the context label and
137   /// sub-label where the value is. Returns true if it is valid.
138   MODEL_EXPORT virtual bool restoreContext(std::string theName,
139     TDF_Label& theContext, TDF_Label& theValue) override;
140
141   /// Returns the label of the newest context presented by the current one
142   MODEL_EXPORT virtual TDF_Label newestContext(const TDF_Label theCurrentContext) override;
143
144   /// Returns true if the first result is newer than the second one in the tree of features
145   MODEL_EXPORT virtual bool isLater(const TDF_Label theResult1, const TDF_Label theResult2)
146     const override;
147
148   /// Returns the name by context. Adds the part name if the context is located in other document
149   MODEL_EXPORT virtual std::string contextName(const ResultPtr& theContext) const;
150
151 protected:
152   /// Objects are created for features automatically
153   MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
154
155   /// Returns the selected subshape, internal method that works without knowledge
156   /// about special selection of circle and ellipse focuses (for that the public value
157   /// method calls this and makes additional processing).
158   /// Returns theType type of the center, or NOT_CENTER if it is not.
159   std::shared_ptr<GeomAPI_Shape> internalValue(CenterType& theType);
160
161   /// stores the naming structure of external construction (sketch element) in the data
162   /// tree of this document with name equal to selection-name in external document
163   void storeExternalConstruction(
164     const std::shared_ptr<ModelAPI_ResultConstruction>& theConstruction,
165     const std::shared_ptr<GeomAPI_Shape>& theSubShape);
166
167   /// Performs the selection for the body result (TNaming selection)
168   virtual void selectBody(
169     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
170
171   /// Performs the selection for the part result (selection by name of body result inside of part)
172   /// \param theContext the result - owner of the selection
173   /// \param theSubShape selected shape
174   /// \param theUpdate flag that shows that it must be just update, theShape is null
175   /// \returns true if everything is selected correctly
176   virtual bool selectPart(
177     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
178     const bool theUpdate = false);
179
180   /// Returns the label where TNaming_Selection results are stored
181   /// Note: there must be no attributes stored at the same label because Selector clears this lab
182   TDF_Label selectionLabel();
183
184   /// Sets the ID of the attribute in Data (called from Data): here it is used for myRef ID setting
185   MODEL_EXPORT virtual void setID(const std::string theID);
186
187   /// Sets the parent attribute
188   void setParent(Model_AttributeSelectionList* theParent);
189
190   /// Splits theNewShape into sub-shapes of theType type (for the list parent of this attribute)
191   void split(ResultPtr theContext, TopoDS_Shape theNewShape, TopAbs_ShapeEnum theType);
192
193   /// When group position is updated, searches the new context and new values
194   bool searchNewContext(std::shared_ptr<Model_Document> theDoc, const TopoDS_Shape theContShape,
195                         ResultPtr theContext, TopoDS_Shape theValShape, TDF_Label theAccessLabel,
196                         std::list<ResultPtr>& theResults, TopTools_ListOfShape& theValShapes);
197
198   /// Searches for the newest context, modification of the current, that contains theValue
199   ResultPtr newestContext(const ResultPtr theCurrent,
200     const std::shared_ptr<GeomAPI_Shape> theValue, const bool theAnyValue = false);
201
202   /// computes theShapes list - shapes that were generated/modified/deleted the theValShape
203   /// during creation from new to old context
204   void computeValues(ResultPtr theOldContext, ResultPtr theNewContext, TopoDS_Shape theValShape,
205     TopTools_ListOfShape& theShapes);
206
207   friend class Model_Data;
208   friend class Model_AttributeSelectionList;
209 };
210
211 #endif