1 // Copyright (C) 2014-2023 CEA, EDF
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 email : webmaster.salome@opencascade.com
20 #ifndef Selector_Algo_H_
21 #define Selector_Algo_H_
25 #include <Standard_GUID.hxx>
26 #include <TDF_Label.hxx>
27 #include <TDF_LabelList.hxx>
28 #include <TopoDS_Shape.hxx>
30 class Selector_NameGenerator;
32 /**\class Selector_Selector
34 * \brief Base class for all kinds of selection algorithms.
38 TopAbs_ShapeEnum myShapeType; ///< type of this shape
40 TDF_Label myLab; ///< label where this also may be located
41 TDF_Label myBaseDocumentLab; ///< an access-label of the document that may contain initial shapes
42 bool myGeometricalNaming; ///< flag that indicates that geometrical naming selection is enabled
43 bool myAlwaysGeometricalNaming; ///< to enable geometrical naming from beginning, at select
44 bool myUseNeighbors; ///< to use neighbors algorithms
45 bool myUseIntersections; ///< to use intersections algorithms
48 /// Type of a selector algorithm: on this type depends what is stored in this label and how to
49 /// restore it on update.
51 SELTYPE_CONTAINER, ///< just a container of sub-elements, keeps the shape type of container
52 SELTYPE_INTERSECT, ///< sub-shape is intersection of higher level objects
53 SELTYPE_PRIMITIVE, ///< sub-shape found as a primitive on some label
54 SELTYPE_MODIFICATION, ///< modification of base shapes to the final label
55 SELTYPE_FILTER_BY_NEIGHBOR, ///< identification by neighbor shapes in context
56 SELTYPE_WEAK_NAMING, ///< pure weak naming by weak index in context
59 /// Initializes the algorithm
60 SELECTOR_EXPORT Selector_Algo();
62 virtual ~Selector_Algo() {}
64 /// Initializes the selector structure on the label.
65 /// Stores the name data to restore after modification.
66 /// \param theContext whole shape that contains the selected sub-shape
67 /// \param theValue selected subshape
68 /// \param theGeometricalNaming treats selection with equal surfaces as one
69 /// \param theUseNeighbors enables searching algorithm by neighbors
70 /// \param theUseIntersections enables searching algorithm by intersection of higher level shapes
71 SELECTOR_EXPORT static Selector_Algo* select(
72 const TopoDS_Shape theContext, const TopoDS_Shape theValue,
73 const TDF_Label theAccess, const TDF_Label theBaseDocument,
74 const bool theGeometricalNaming = false,
75 const bool theUseNeighbors = true, const bool theUseIntersections = true,
76 const bool theAlwaysGeometricalNaming = false);
78 /// Stores the name to the label and sub-labels tree
79 SELECTOR_EXPORT virtual void store() = 0;
81 /// Restores the selected shape by the topological naming kept in the data structure
82 /// Returns true if it can restore structure correctly
83 SELECTOR_EXPORT virtual bool restore() = 0;
85 /// Restores the selected shape by the topological name string.
86 /// Returns not empty label of the context.
87 SELECTOR_EXPORT virtual TDF_Label restoreByName(std::wstring theName,
88 const TopAbs_ShapeEnum theShapeType, Selector_NameGenerator* theNameGenerator) = 0;
90 /// Updates the current shape by the stored topological name
91 SELECTOR_EXPORT virtual bool solve(const TopoDS_Shape& theContext) = 0;
93 /// Returns the naming name of the selection
94 SELECTOR_EXPORT virtual std::wstring name(Selector_NameGenerator* theNameGenerator) = 0;
95 /// Returns the current sub-shape value (null if can not resolve)
96 SELECTOR_EXPORT TopoDS_Shape value();
97 /// Restores sub-algorithm of a given type by the storage-label
98 SELECTOR_EXPORT static Selector_Algo* restoreByLab(TDF_Label theLab, TDF_Label theBaseDocLab);
99 /// Restores the selected sub-algorithm by the naming name.
100 /// Returns not empty label of the context.
101 SELECTOR_EXPORT static Selector_Algo* restoreByName(
102 TDF_Label theLab, TDF_Label theBaseDocLab, std::wstring theName,
103 const TopAbs_ShapeEnum theShapeType, const bool theGeomNaming,
104 Selector_NameGenerator* theNameGenerator, TDF_Label& theContextLab);
106 /// Returns true if the given shapes are based on the same geometry
107 static bool sameGeometry(const TopoDS_Shape theShape1, const TopoDS_Shape theShape2);
109 /// Creates a new selection algorithm for selection of all topology based on the same geometry
110 SELECTOR_EXPORT static Selector_Algo* relesectWithAllGeometry(
111 Selector_Algo* theOldAlgo, const TopoDS_Shape theContext);
112 /// Sets geometrical naming flag to true
113 void setGeometricalNaming()
114 {myGeometricalNaming = true;}
117 /// Returns label where this algorithm is attached to, or just an access label to the document
118 const TDF_Label& label() const
120 /// Stores the array of references to theLab: references to elements of ref-list, then the last
121 void storeBaseArray(const TDF_LabelList& theRef, const TDF_Label& theLast);
122 /// Restores references to the labels: references to elements of ref-list, then the last
123 bool restoreBaseArray(TDF_LabelList& theRef, TDF_Label& theLast);
124 /// Stores result of selection at the given label
125 void store(const TopoDS_Shape theShape);
126 /// Returns an access-label of the document that may contain initial shapes
127 const TDF_Label& baseDocument() const
128 {return myBaseDocumentLab;}
129 /// Returns the geometrical naming flag
130 bool geometricalNaming() const
131 {return myGeometricalNaming;}
132 /// Returns always geometrical naming flag
133 bool alwaysGeometricalNaming() const
134 {return myAlwaysGeometricalNaming;}
135 /// Returns use neighbors flag
136 bool useNeighbors() const
137 {return myUseNeighbors;}
138 /// Returns use intersections flag
139 bool useIntersections() const
140 {return myUseIntersections;}
141 /// Returns GUID for the weak index (integer attribute) of the sub-shape
142 static const Standard_GUID& weakID()
144 static const Standard_GUID kWEAK_INDEX("e9373a61-cabc-4ee8-aabf-aea47c62ed87");
147 /// Returns GUID for the type of the shape, stored in case it is intersection or container
148 static const Standard_GUID& shapeTypeID()
150 static const Standard_GUID kSHAPE_TYPE("864b3267-cb9d-4107-bf58-c3ce1775b171");
153 /// old string identifier of the weak name in modification or intersection types of algorithm
154 static const std::wstring& oldWeakNameID()
156 static const std::wstring kWEAK_NAME_IDENTIFIER = L"weak_name_";
157 return kWEAK_NAME_IDENTIFIER;
159 /// old string identifier of the pure weak name
160 static const std::wstring& oldPureWeakNameID()
162 static const std::wstring kPURE_WEAK_NAME_IDENTIFIER = L"_weak_name_";
163 return kPURE_WEAK_NAME_IDENTIFIER;
165 /// string identifier of the weak name in modification or intersection types of algorithm
166 static const std::wstring& weakNameID()
168 static const std::wstring kWEAK_NAME_IDENTIFIER = std::wstring(L"new_") + oldWeakNameID();
169 return kWEAK_NAME_IDENTIFIER;
171 /// string identifier of the pure weak name
172 static const std::wstring& pureWeakNameID()
174 static const std::wstring kPURE_WEAK_NAME_IDENTIFIER =
175 std::wstring(L"_new") + oldPureWeakNameID();
176 return kPURE_WEAK_NAME_IDENTIFIER;
178 /// Stores the type of an algorithm in the data tree (in myLab)
179 void storeType(const Selector_Type theType);
181 /// Searches the newer version of the shape in the document if the base shape does not
182 /// belong to context. Returns it in theResult (if any). Returns true is theResult is changed.
183 bool findNewVersion(const TopoDS_Shape& theContext, TopoDS_Shape& theResult) const;