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;
33 /**\class Model_AttributeSelection
35 * \brief Attribute that contains reference to the sub-shape of some result, the selected shape.
37 class Model_AttributeSelection : public ModelAPI_AttributeSelection
39 Model_AttributeReference myRef; ///< The reference functionality reusage
40 TDF_LabelMap myScope; ///< the map of valid labels for naming selection solving
41 /// temporarily storages to avoid keeping in the data structure if not needed
42 ResultPtr myTmpContext;
43 /// temporarily storages to avoid keeping in the data structure if not needed
44 std::shared_ptr<GeomAPI_Shape> myTmpSubShape;
45 /// Reference to the partent attribute, if any (to split selection compounds in issue 1799)
46 Model_AttributeSelectionList* myParent;
48 /// Defines the result and its selected sub-shape
49 /// \param theContext object where the sub-shape was selected
50 /// \param theSubShape selected sub-shape (if null, the whole context is selected)
51 /// \param theTemporarily if it is true, do not store and name the added in the data framework
52 /// (used to remove immideately, without the following updates)
53 MODEL_EXPORT virtual void setValue(
54 const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
55 const bool theTemporarily = false);
57 /// Reset temporary stored values
58 virtual void removeTemporaryValues();
60 /// Returns the selected subshape
61 MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> value();
63 /// Returns the context of the selection (the whole shape owner)
64 MODEL_EXPORT virtual ResultPtr context();
66 /// Sets the feature object
67 MODEL_EXPORT virtual void setObject(const std::shared_ptr<ModelAPI_Object>& theObject);
69 /// Updates the underlied selection due to the changes in the referenced objects
70 /// \returns false if update is failed
71 MODEL_EXPORT virtual bool update();
73 /// Returns a textual string of the selection
74 /// \param theDefaultValue a name, which is returned if the naming name can not be obtained
75 MODEL_EXPORT virtual std::string namingName(const std::string& theDefaultValue = "");
77 /// Returns an Id of the selection
78 /// NOTE: This method has been added for temporary export of groups towards old GEOM
79 /// It should then be removed when a direct use of objects from SHAPER
80 /// will be possible from SMESH module of SALOME.
81 MODEL_EXPORT virtual int Id();
83 /// Defines the sub-shape by Id
84 /// NOTE: This method is opposite to Id() method.
85 MODEL_EXPORT virtual void setId(int theID);
87 /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name
88 MODEL_EXPORT virtual void selectSubShape(const std::string& theType,
89 const std::string& theSubShapeName);
91 /// Returns true if attribute was initialized by some value
92 MODEL_EXPORT virtual bool isInitialized();
94 /// Returns true if recomute of selection become impossible
95 MODEL_EXPORT virtual bool isInvalid();
97 /// Updates the arguments of selection if something was affected by creation
98 /// or reorder of features upper in the history line (issue #1757)
99 MODEL_EXPORT virtual void updateInHistory();
102 /// Objects are created for features automatically
103 MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
105 /// Performs the selection for the body result (TNaming Selection)
107 /// Performs the selection for the body result (TNaming selection)
108 virtual void selectBody(
109 const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
111 /// Performs the selection for the part result (selection by name of body result inside of part)
112 /// \param theContext the result - owner of the selection
113 /// \param theSubShape selected shape
114 /// \param theUpdate flag that shows that it must be just update, theShape is null
115 /// \returns true if eveything is selected correctly
116 virtual bool selectPart(
117 const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
118 const bool theUpdate = false);
120 /// Returns the label where TNaming_Selection results are stored
121 /// Note: there must be no attributes stored at the same label because Selector clears this lab
122 TDF_Label selectionLabel();
124 /// Returns the prepared map of valid labels for naming selection solving (creates if not exists)
125 TDF_LabelMap& scope();
127 /// Sets the ID of the attribute in Data (called from Data): here it is used for myRef ID setting
128 MODEL_EXPORT virtual void setID(const std::string theID);
130 /// Returns the name by context. Adds the part name if the context is located in other document
131 std::string contextName(const ResultPtr& theContext) const;
133 /// Sets the parent attribute
134 void setParent(Model_AttributeSelectionList* theParent);
136 /// Splits theNewShape into sub-shapes of theType type (for the list parent of this attribute)
137 void split(ResultPtr theContext, TopoDS_Shape theNewShape, TopAbs_ShapeEnum theType);
139 /// When group position is updated, searches the new context and new values
140 bool searchNewContext(std::shared_ptr<Model_Document> theDoc, const TopoDS_Shape theContShape,
141 ResultPtr theContext, TopoDS_Shape theValShape, TDF_Label theAccessLabel,
142 std::list<ResultPtr>& theResults, TopTools_ListOfShape& theValShapes);
144 /// computes theShapes list - shapes that were generated/modified/deleted the theValShape
145 /// during creation from new to old context
146 void computeValues(ResultPtr theOldContext, ResultPtr theNewContext, TopoDS_Shape theValShape,
147 TopTools_ListOfShape& theShapes);
149 friend class Model_Data;
150 friend class Model_AttributeSelectionList;