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_SelectionNaming_H_
22 #define Model_SelectionNaming_H_
24 #include <ModelAPI_Result.h>
25 #include <GeomAPI_Shape.h>
26 #include <Model_Document.h>
27 #include <TDF_Label.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <NCollection_DataMap.hxx>
30 #include <Geom_Curve.hxx>
31 #include <TopoDS_Edge.hxx>
33 // class to compare curves in the same way as in GeomAPI_Edge
34 class Model_CurvesHasher
38 /// standard hash code
39 static int HashCode (const Handle(Geom_Curve)& theCurve, const Standard_Integer Upper);
40 /// comapre curves by parameters and points on them
41 static bool IsEqual (const Handle(Geom_Curve)& theC1, const Handle(Geom_Curve)& theC2);
44 // class to compare edges in the same way as in GeomAPI_Edge
45 class Model_EdgesHasher
49 /// standard hash code
50 static int HashCode (const TopoDS_Edge& theEdge, const Standard_Integer Upper);
51 /// comapre curves by parameters and points on them
52 static bool IsEqual (const TopoDS_Edge& theE1, const TopoDS_Edge& theE2);
56 /**\class Model_SelectionNaming
58 * \brief The set of methods that allow to generate a string-name for the selection attribute.
60 class Model_SelectionNaming
62 TDF_Label myLab; ///< Selection label of the selection attribute
64 /// Constructor for the selection attribute by the selection label
65 Model_SelectionNaming(TDF_Label theSelectionLab);
67 /// Produces the string-name for the selected shape
68 std::string namingName(ResultPtr& theContext, std::shared_ptr<GeomAPI_Shape> theSubSh,
69 const std::string& theDefaultName, const bool theAnotherDoc);
71 /// Makes a selection by the string-name
72 /// \param theType string of the type of the shape
73 /// \param theSubShapeName string-identifier of the selected shape
74 /// \param theDoc document where the selected shape is searched
75 /// \param theShapeToBeSelected resulting selected shape
76 /// \param theCont the selection context of the resulting selected shape
77 bool selectSubShape(const std::string& theType, const std::string& theSubShapeName,
78 std::shared_ptr<Model_Document> theDoc, std::shared_ptr<GeomAPI_Shape>& theShapeToBeSelected,
79 std::shared_ptr<ModelAPI_Result>& theCont);
81 /// Searches the face more appropriate to the given curves
82 /// (with higher level of matched parameters)
83 /// \param theConstr construction result that contains one or several faces
84 /// \param theCurves map from the face edges curves to orientation
85 /// (-1 reversed, 0 unknown, 1 forward)
86 /// \param theIsWire for wire algorithm isquite the same,
87 /// but if in face several wires, it returns the needed wire
88 /// \returns faces fron this construction if found
89 static std::shared_ptr<GeomAPI_Shape> findAppropriateFace(
90 std::shared_ptr<ModelAPI_Result>& theConstr,
91 NCollection_DataMap<Handle(Geom_Curve), int, Model_CurvesHasher>& theCurves,
92 const bool theIsWire);
94 /// Returns orientation of the edge in the context shape
95 static int edgeOrientation(const TopoDS_Shape& theContext, TopoDS_Edge& theEdge);
97 /// Returns the name of sketch sub-element, shortened by exclusion of some symbols and with added
98 /// the vertex position (if needed)
99 /// \param theConstr result with name - basis for the name
100 /// \param theEdgeVertexPos position of the vertex on edge: 1 - first , 2 - second
101 /// \returns the generated name
102 static std::string shortName(std::shared_ptr<ModelAPI_ResultConstruction>& theConstr,
103 const int theEdgeVertexPos = 0);
106 /// Gets the stored name from the document
107 std::string getShapeName(std::shared_ptr<Model_Document> theDoc, const TopoDS_Shape& theShape,
108 ResultPtr& theContext, const bool theAnotherDoc, const bool theWholeContext);
110 /// Tries to find the name of the context sub-shape as combination of edges in context
111 std::string vertexNameByEdges(TopoDS_Shape theContext, TopoDS_Shape theSub,
112 std::shared_ptr<Model_Document> theDoc, ResultPtr& theContextRes, const bool theAnotherDoc);