Salome HOME
fa069c4aa09d31b5e72e8f898226b3aff2b46b2d
[modules/shaper.git] / src / Selector / Selector_Selector.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 Selector_Selector_H_
22 #define Selector_Selector_H_
23
24 #include "Selector.h"
25
26 #include <TDF_Label.hxx>
27 #include <TDF_LabelList.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <list>
30
31 class Selector_NameGenerator;
32
33 /**\class Selector_Selector
34  * \ingroup DataModel
35  * \brief Main object for selection of the sub-shapes in the parametrically updated
36  * shapes using topological naming mechanism.
37  */
38 class Selector_Selector
39 {
40   /// Type of a selector: on this type depends what is stored in this label and how to
41   /// restore it on update.
42   enum Selector_Type {
43     SELTYPE_CONTAINER, ///< just a container of sub-elements, keeps the shape type of container
44     SELTYPE_INTERSECT, ///< sub-shape is intersection of higher level objects
45     SELTYPE_PRIMITIVE, ///< sub-shape found as a primitive on some label
46     SELTYPE_MODIFICATION, ///< modification of base shapes to the final label
47     SELTYPE_FILTER_BY_NEIGHBOR,  ///< identification by neighbor shapes in context
48     SELTYPE_WEAK_NAMING, ///< pure weak naming by weak index in context
49   };
50
51   Selector_Type myType; ///< Type of this selector.
52   TopAbs_ShapeEnum myShapeType; ///< type of this shape: in container, intersection or neighbors
53   std::list<Selector_Selector> mySubSelList; ///< list of sub-selectors if needed
54   TDF_Label myFinal; ///< final label of the primitive or generation, where the value is
55   TDF_LabelList myBases; ///< initial labels that contain shapes that produce the modification
56   int myWeakIndex; ///< index of the shape among commons for the modification type (-1 - not set)
57
58   std::list<int> myNBLevel; ///< list of integers corresponding to mySubSelList neighborhood level
59
60   TDF_Label myLab; ///< main label where selector is performed
61
62   TDF_Label myBaseDocumentLab; ///< an access-label to the document that may contain initial shapes
63
64   bool myGeometricalNaming; ///< flag that indicates that geometrical naming selection is enabled
65
66 public:
67   /// Initializes selector on the label
68   SELECTOR_EXPORT Selector_Selector(TDF_Label theLab);
69   /// Returns label of this selector
70   SELECTOR_EXPORT TDF_Label label();
71
72   /// Sets the base document access label.
73   SELECTOR_EXPORT void setBaseDocument(const TDF_Label theAccess);
74
75   /// Initializes the selector structure on the label.
76   /// Stores the name data to restore after modification.
77   /// \param theContext whole shape that contains the selected sub-shape
78   /// \param theValue selected subshape
79   /// \param theGeometricalNaming treats selection with equal surfaces as one
80   /// \param theUseNeighbors enables searching algorithm by neighbors
81   /// \param theUseIntersections enables searching algorithm by intersection of higher level shapes
82   SELECTOR_EXPORT bool select(const TopoDS_Shape theContext, const TopoDS_Shape theValue,
83     const bool theGeometricalNaming = false,
84     const bool theUseNeighbors = true, const bool theUseIntersections = true);
85
86   /// Stores the name to the label and sub-labels tree
87   SELECTOR_EXPORT void store();
88
89   /// Restores the selected shape by the topological naming kept in the data structure
90   /// Returns true if it can restore structure correctly
91   SELECTOR_EXPORT bool restore();
92
93   /// Restores the selected shape by the topological name string.
94   /// Returns not empty label of the context.
95   SELECTOR_EXPORT TDF_Label restoreByName(
96     std::string theName, const TopAbs_ShapeEnum theShapeType,
97     Selector_NameGenerator* theNameGenerator, const bool theGeometricalNaming = false);
98
99   /// Updates the current shape by the stored topological name
100   SELECTOR_EXPORT bool solve(const TopoDS_Shape& theContext);
101
102   /// Returns the current sub-shape value (null if can not resolve)
103   SELECTOR_EXPORT TopoDS_Shape value();
104
105   /// Returns the naming name of the selection
106   SELECTOR_EXPORT std::string name(Selector_NameGenerator* theNameGenerator);
107
108 private:
109
110   /// Create and keep in the list the sub-selector that select the given value.
111   /// Returns true if selection is correct.
112   bool selectBySubSelector(const TopoDS_Shape theContext, const TopoDS_Shape theValue,
113     const bool theGeometricalNaming = false, const bool theUseNeighbors = true,
114     const bool theUseIntersections = true);
115   /// Searches the final shapes presented in all results from bases basing on modification fields
116   void findModificationResult(TopoDS_ListOfShape& theCommon);
117 };
118
119 #endif