1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef Model_AttributeSelection_H_
22 #define Model_AttributeSelection_H_
25 #include "Model_AttributeReference.h"
26 #include <ModelAPI_AttributeSelection.h>
27 #include <TDF_LabelMap.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopTools_ListOfShape.hxx>
31 class Model_AttributeSelectionList;
34 /**\class Model_AttributeSelection
36 * \brief Attribute that contains reference to the sub-shape of some result, the selected shape.
38 class Model_AttributeSelection : public ModelAPI_AttributeSelection
40 Model_AttributeReference myRef; ///< The reference functionality reusage
41 TDF_LabelMap myScope; ///< the map of valid labels for naming selection solving
42 /// temporarily storages to avoid keeping in the data structure if not needed
43 ResultPtr myTmpContext;
44 /// temporarily storages to avoid keeping in the data structure if not needed
45 std::shared_ptr<GeomAPI_Shape> myTmpSubShape;
46 /// temporarily storages to avoid keeping in the data structure if not needed
47 CenterType myTmpCenterType;
48 /// Reference to the partent attribute, if any (to split selection compounds in issue 1799)
49 Model_AttributeSelectionList* myParent;
51 /// Defines the result and its selected sub-shape
52 /// \param theContext object where the sub-shape was selected
53 /// \param theSubShape selected sub-shape (if null, the whole context is selected)
54 /// \param theTemporarily if it is true, do not store and name the added in the data framework
55 /// (used to remove immideately, without the following updates)
56 /// \returns true if attribute was updated
57 MODEL_EXPORT virtual bool setValue(
58 const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
59 const bool theTemporarily = false);
61 /// Same as SetValue, but it takes an edge (on circular or elliptical curve)
62 /// and stores the vertex of the central point (for ellipse the first or the second focus point)
63 MODEL_EXPORT virtual void setValueCenter(
64 const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Edge>& theEdge,
65 const CenterType theCenterType,
66 const bool theTemporarily = false);
68 /// Makes this selection attribute selects the same as in theSource selection
69 MODEL_EXPORT virtual void selectValue(
70 const std::shared_ptr<ModelAPI_AttributeSelection>& theSource);
72 /// Reset temporary stored values
73 virtual void removeTemporaryValues();
75 /// Returns the selected subshape
76 MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> value();
78 /// Returns the context of the selection (the whole shape owner)
79 MODEL_EXPORT virtual ResultPtr context();
81 /// Returns the context of the selection if the whole feature was selected
82 MODEL_EXPORT virtual FeaturePtr contextFeature();
83 /// Returns the context of the selection : result or feature
84 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Object> contextObject();
86 /// Sets the feature object
87 MODEL_EXPORT virtual void setObject(const std::shared_ptr<ModelAPI_Object>& theObject);
89 /// Updates the underlied selection due to the changes in the referenced objects
90 /// \returns false if update is failed
91 MODEL_EXPORT virtual bool update();
93 /// Returns a textual string of the selection
94 /// \param theDefaultValue a name, which is returned if the naming name can not be obtained
95 MODEL_EXPORT virtual std::string namingName(const std::string& theDefaultValue = "");
97 /// Returns an Id of the selection
98 /// NOTE: This method has been added for temporary export of groups towards old GEOM
99 /// It should then be removed when a direct use of objects from SHAPER
100 /// will be possible from SMESH module of SALOME.
101 MODEL_EXPORT virtual int Id();
103 /// Defines the sub-shape by Id
104 /// NOTE: This method is opposite to Id() method.
105 MODEL_EXPORT virtual void setId(int theID);
107 /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name
108 MODEL_EXPORT virtual void selectSubShape(const std::string& theType,
109 const std::string& theSubShapeName);
111 /// Selects sub-shape by its inner point
112 MODEL_EXPORT virtual void selectSubShape(const std::string& theType,
113 const std::shared_ptr<GeomAPI_Pnt>& thePoint);
115 /// Returns true if attribute was initialized by some value
116 MODEL_EXPORT virtual bool isInitialized();
118 /// Returns true if recomute of selection become impossible
119 MODEL_EXPORT virtual bool isInvalid();
121 /// Updates the arguments of selection if something was affected by creation
122 /// or reorder of features upper in the history line (issue #1757)
123 MODEL_EXPORT virtual void updateInHistory();
126 /// Objects are created for features automatically
127 MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
129 /// Returns the selected subshape, internal method that works without knowledge
130 /// about special selection of circle and ellipse focuses (for that the public value
131 /// method calls this and makes additional processing).
132 /// Returns theType type of the center, or NOT_CENTER if it is not.
133 std::shared_ptr<GeomAPI_Shape> internalValue(CenterType& theType);
136 /// Performs the selection for the body result (TNaming Selection)
138 /// Performs the selection for the body result (TNaming selection)
139 virtual void selectBody(
140 const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
142 /// Performs the selection for the part result (selection by name of body result inside of part)
143 /// \param theContext the result - owner of the selection
144 /// \param theSubShape selected shape
145 /// \param theUpdate flag that shows that it must be just update, theShape is null
146 /// \returns true if eveything is selected correctly
147 virtual bool selectPart(
148 const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
149 const bool theUpdate = false);
151 /// Returns the label where TNaming_Selection results are stored
152 /// Note: there must be no attributes stored at the same label because Selector clears this lab
153 TDF_Label selectionLabel();
155 /// Returns the prepared map of valid labels for naming selection solving (creates if not exists)
156 TDF_LabelMap& scope();
158 /// Sets the ID of the attribute in Data (called from Data): here it is used for myRef ID setting
159 MODEL_EXPORT virtual void setID(const std::string theID);
161 /// Returns the name by context. Adds the part name if the context is located in other document
162 std::string contextName(const ResultPtr& theContext) const;
164 /// Sets the parent attribute
165 void setParent(Model_AttributeSelectionList* theParent);
167 /// Splits theNewShape into sub-shapes of theType type (for the list parent of this attribute)
168 void split(ResultPtr theContext, TopoDS_Shape theNewShape, TopAbs_ShapeEnum theType);
170 /// When group position is updated, searches the new context and new values
171 bool searchNewContext(std::shared_ptr<Model_Document> theDoc, const TopoDS_Shape theContShape,
172 ResultPtr theContext, TopoDS_Shape theValShape, TDF_Label theAccessLabel,
173 std::list<ResultPtr>& theResults, TopTools_ListOfShape& theValShapes);
175 /// computes theShapes list - shapes that were generated/modified/deleted the theValShape
176 /// during creation from new to old context
177 void computeValues(ResultPtr theOldContext, ResultPtr theNewContext, TopoDS_Shape theValShape,
178 TopTools_ListOfShape& theShapes);
180 friend class Model_Data;
181 friend class Model_AttributeSelectionList;