]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_AttributeSelection.h
Salome HOME
Merge branch 'Pre_2.8.0_development'
[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 <TDF_LabelMap.hxx>
28 #include <TopoDS_Shape.hxx>
29
30 class Model_AttributeSelectionList;
31
32 /**\class Model_AttributeSelection
33  * \ingroup DataModel
34  * \brief Attribute that contains reference to the sub-shape of some result, the selected shape.
35  */
36 class Model_AttributeSelection : public ModelAPI_AttributeSelection
37 {
38   Model_AttributeReference myRef;  ///< The reference functionality reusage
39   TDF_LabelMap myScope; ///< the map of valid labels for naming selection solving
40   /// temporarily storages to avoid keeping in the data structure if not needed
41   ResultPtr myTmpContext;
42   /// temporarily storages to avoid keeping in the data structure if not needed
43   std::shared_ptr<GeomAPI_Shape> myTmpSubShape;
44   /// temporarily storages to avoid keeping in the data structure if not needed
45   CenterType myTmpCenterType;
46   /// Reference to the partent attribute, if any (to split selection compounds in issue 1799)
47   Model_AttributeSelectionList* myParent;
48 public:
49   /// Defines the result and its selected sub-shape
50   /// \param theContext object where the sub-shape was selected
51   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
52   /// \param theTemporarily if it is true, do not store and name the added in the data framework
53   ///           (used to remove immideately, without the following updates)
54   MODEL_EXPORT virtual void setValue(
55     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
56     const bool theTemporarily = false);
57
58   /// Same as SetValue, but it takes an edge (on circular or elliptical curve)
59   /// and stores the vertex of the central point (for ellipse the first or the second focus point)
60   MODEL_EXPORT virtual void setValueCenter(
61     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Edge>& theEdge,
62     const CenterType theCenterType,
63     const bool theTemporarily = false);
64
65   /// Reset temporary stored values
66   virtual void removeTemporaryValues();
67
68   /// Returns the selected subshape
69   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> value();
70
71   /// Returns the context of the selection (the whole shape owner)
72   MODEL_EXPORT virtual ResultPtr context();
73
74   /// Sets the feature object
75   MODEL_EXPORT virtual void setObject(const std::shared_ptr<ModelAPI_Object>& theObject);
76
77   /// Updates the underlied selection due to the changes in the referenced objects
78   /// \returns false if update is failed
79   MODEL_EXPORT virtual bool update();
80
81   /// Returns a textual string of the selection
82   /// \param theDefaultValue a name, which is returned if the naming name can not be obtained
83   MODEL_EXPORT virtual std::string namingName(const std::string& theDefaultValue = "");
84
85   /// Returns an Id of the selection
86   /// NOTE: This method has been added for temporary export of groups towards old GEOM
87   /// It should then be removed when a direct use of objects from SHAPER
88   /// will be possible from SMESH module of SALOME.
89   MODEL_EXPORT virtual int Id();
90
91   /// Defines the sub-shape by Id
92   /// NOTE: This method is opposite to Id() method.
93   MODEL_EXPORT virtual void setId(int theID);
94
95   /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name
96   MODEL_EXPORT virtual void selectSubShape(const std::string& theType,
97                                            const std::string& theSubShapeName);
98
99   /// Returns true if attribute was  initialized by some value
100   MODEL_EXPORT virtual bool isInitialized();
101
102   /// Returns true if recomute of selection become impossible
103   MODEL_EXPORT virtual bool isInvalid();
104
105   /// Updates the arguments of selection if something was affected by creation
106   /// or reorder of features upper in the history line (issue #1757)
107   MODEL_EXPORT virtual void updateInHistory();
108
109 protected:
110   /// Objects are created for features automatically
111   MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
112
113   /// Performs the selection for the body result (TNaming Selection)
114
115   /// Performs the selection for the body result (TNaming selection)
116   virtual void selectBody(
117     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
118
119   /// Performs the selection for the part result (selection by name of body result inside of part)
120   /// \param theContext the result - owner of the selection
121   /// \param theSubShape selected shape
122   /// \param theUpdate flag that shows that it must be just update, theShape is null
123   /// \returns true if eveything is selected correctly
124   virtual bool selectPart(
125     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
126     const bool theUpdate = false);
127
128   /// Returns the label where TNaming_Selection results are stored
129   /// Note: there must be no attributes stored at the same label because Selector clears this lab
130   TDF_Label selectionLabel();
131
132   /// Returns the prepared map of valid labels for naming selection solving (creates if not exists)
133   TDF_LabelMap& scope();
134
135   /// Sets the ID of the attribute in Data (called from Data): here it is used for myRef ID setting
136   MODEL_EXPORT virtual void setID(const std::string theID);
137
138   /// Returns the name by context. Adds the part name if the context is located in other document
139   std::string contextName(const ResultPtr& theContext) const;
140
141   /// Sets the parent attribute
142   void setParent(Model_AttributeSelectionList* theParent);
143
144   /// Splits theNewShape into sub-shapes of theType type (for the list parent of this attribute)
145   void split(ResultPtr theContext, TopoDS_Shape theNewShape, TopAbs_ShapeEnum theType);
146
147   friend class Model_Data;
148   friend class Model_AttributeSelectionList;
149 };
150
151 #endif