1 // Copyright (C) 2014-2019 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 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 /// Initializes the selector structure on the label.
63 /// Stores the name data to restore after modification.
64 /// \param theContext whole shape that contains the selected sub-shape
65 /// \param theValue selected subshape
66 /// \param theGeometricalNaming treats selection with equal surfaces as one
67 /// \param theUseNeighbors enables searching algorithm by neighbors
68 /// \param theUseIntersections enables searching algorithm by intersection of higher level shapes
69 SELECTOR_EXPORT static Selector_Algo* select(
70 const TopoDS_Shape theContext, const TopoDS_Shape theValue,
71 const TDF_Label theAccess, const TDF_Label theBaseDocument,
72 const bool theGeometricalNaming = false,
73 const bool theUseNeighbors = true, const bool theUseIntersections = true,
74 const bool theAlwaysGeometricalNaming = false);
76 /// Stores the name to the label and sub-labels tree
77 SELECTOR_EXPORT virtual void store() = 0;
79 /// Restores the selected shape by the topological naming kept in the data structure
80 /// Returns true if it can restore structure correctly
81 SELECTOR_EXPORT virtual bool restore() = 0;
83 /// Restores the selected shape by the topological name string.
84 /// Returns not empty label of the context.
85 SELECTOR_EXPORT virtual TDF_Label restoreByName(std::string theName,
86 const TopAbs_ShapeEnum theShapeType, Selector_NameGenerator* theNameGenerator) = 0;
88 /// Updates the current shape by the stored topological name
89 SELECTOR_EXPORT virtual bool solve(const TopoDS_Shape& theContext) = 0;
91 /// Returns the naming name of the selection
92 SELECTOR_EXPORT virtual std::string name(Selector_NameGenerator* theNameGenerator) = 0;
93 /// Returns the current sub-shape value (null if can not resolve)
94 SELECTOR_EXPORT TopoDS_Shape value();
95 /// Restores sub-algorithm of a given type by the storage-label
96 SELECTOR_EXPORT static Selector_Algo* restoreByLab(TDF_Label theLab, TDF_Label theBaseDocLab);
97 /// Restores the selected sub-algorithm by the naming name.
98 /// Returns not empty label of the context.
99 SELECTOR_EXPORT static Selector_Algo* restoreByName(
100 TDF_Label theLab, TDF_Label theBaseDocLab, std::string theName,
101 const TopAbs_ShapeEnum theShapeType, const bool theGeomNaming,
102 Selector_NameGenerator* theNameGenerator, TDF_Label& theContextLab);
104 /// Returns true if the given shapes are based on the same geometry
105 static bool sameGeometry(const TopoDS_Shape theShape1, const TopoDS_Shape theShape2);
107 /// Creates a new selection algorithm for selection of all topology based on the same geometry
108 SELECTOR_EXPORT static Selector_Algo* relesectWithAllGeometry(
109 Selector_Algo* theOldAlgo, const TopoDS_Shape theContext);
110 /// Sets geometrical naming flag to true
111 void setGeometricalNaming()
112 {myGeometricalNaming = true;}
115 /// Returns label where this algorithm is attached to, or just an access label to the document
116 const TDF_Label& label() const
118 /// Stores the array of references to theLab: references to elements of ref-list, then the last
119 void storeBaseArray(const TDF_LabelList& theRef, const TDF_Label& theLast);
120 /// Restores references to the labels: references to elements of ref-list, then the last
121 bool restoreBaseArray(TDF_LabelList& theRef, TDF_Label& theLast);
122 /// Stores result of selection at the given label
123 void store(const TopoDS_Shape theShape);
124 /// Returns an access-label of the document that may contain initial shapes
125 const TDF_Label& baseDocument() const
126 {return myBaseDocumentLab;}
127 /// Returns the geometrical naming flag
128 bool geometricalNaming() const
129 {return myGeometricalNaming;}
130 /// Returns always geometrical naming flag
131 bool alwaysGeometricalNaming() const
132 {return myAlwaysGeometricalNaming;}
133 /// Returns use neighbors flag
134 bool useNeighbors() const
135 {return myUseNeighbors;}
136 /// Returns use intersections flag
137 bool useIntersections() const
138 {return myUseIntersections;}
139 /// Returns GUID for the weak index (integer attribute) of the sub-shape
140 static const Standard_GUID& weakID()
142 static const Standard_GUID kWEAK_INDEX("e9373a61-cabc-4ee8-aabf-aea47c62ed87");
145 /// Returns GUID for the type of the shape, stored in case it is intersection or container
146 static const Standard_GUID& shapeTypeID()
148 static const Standard_GUID kSHAPE_TYPE("864b3267-cb9d-4107-bf58-c3ce1775b171");
151 /// string identifier of the weak name in modification or intersection types of algorithm
152 static const std::string& weakNameID()
154 static const std::string kWEAK_NAME_IDENTIFIER = "weak_name_";
155 return kWEAK_NAME_IDENTIFIER;
157 /// string identifier of the pure weak name
158 static const std::string& pureWeakNameID()
160 static const std::string kPURE_WEAK_NAME_IDENTIFIER = "_weak_name_";
161 return kPURE_WEAK_NAME_IDENTIFIER;
163 /// Stores the type of an algorithm in the data tree (in myLab)
164 void storeType(const Selector_Type theType);
166 /// Searches the newer version of the shape in the document if the base shape does not
167 /// belong to context. Returns it in theResult (if any). Returns true is theResult is changed.
168 bool findNewVersion(const TopoDS_Shape& theContext, TopoDS_Shape& theResult) const;