1 // Created on: 2001-01-16
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BRep_Builder.hxx>
18 #include <BRep_Tool.hxx>
19 #include <Geom_Curve.hxx>
20 #include <GeomAPI_ProjectPointOnCurve.hxx>
22 #include <QANewModTopOpe_Glue.hxx>
24 #include <TopoDS_Edge.hxx>
25 #include <TopoDS_Face.hxx>
26 #include <TopoDS_Iterator.hxx>
27 #include <TopoDS_Shape.hxx>
28 #include <TopoDS_Vertex.hxx>
29 #include <TopTools_ListIteratorOfListOfShape.hxx>
31 //=======================================================================
32 //function : ProjPointOnEdge
34 //=======================================================================
36 QANewModTopOpe_Glue::ProjPointOnEdge (const gp_Pnt& thePnt, const TopoDS_Edge& theEdge,
37 Standard_Real& thePar, Standard_Real& theDist)
39 Standard_Real aParF, aParL;
40 Handle(Geom_Curve) aCurv = BRep_Tool::Curve(theEdge, aParF, aParL);
41 GeomAPI_ProjectPointOnCurve aProjector(thePnt, aCurv, aParF, aParL);
42 if (aProjector.NbPoints() == 0)
43 return Standard_False;
44 thePar = aProjector.LowerDistanceParameter();
45 theDist = aProjector.LowerDistance();
49 //=======================================================================
50 //function : InsertVertexInEdge
52 //=======================================================================
55 QANewModTopOpe_Glue::InsertVertexInEdge (const TopoDS_Edge& theEdge,
56 const TopoDS_Vertex& theVer,
57 const Standard_Real thePar,
58 TopoDS_Edge& theNewEdge)
62 TopoDS_Shape aDummy = theEdge.EmptyCopied().Oriented(TopAbs_FORWARD);
63 theNewEdge = TopoDS::Edge (aDummy);
64 Standard_Real aParF, aParL;
65 BRep_Tool::Range (theEdge, aParF, aParL);
66 aBld.Range (theNewEdge, aParF, aParL);
68 TopoDS_Iterator aIterE (theEdge, Standard_False);
69 for (; aIterE.More(); aIterE.Next())
70 aBld.Add (theNewEdge, aIterE.Value());
71 // add new internal vertex
72 aBld.Add (theNewEdge, theVer.Oriented(TopAbs_INTERNAL));
73 Standard_Real aTol = Max (BRep_Tool::Tolerance(theVer),
74 BRep_Tool::Tolerance(theEdge));
75 aBld.UpdateVertex (theVer, thePar, theNewEdge, aTol);
76 theNewEdge.Orientation (theEdge.Orientation());
79 //=======================================================================
80 //function : SplitEdgeByVertex
82 //=======================================================================
85 QANewModTopOpe_Glue::SplitEdgeByVertex (const TopoDS_Edge& theEdge,
86 const TopoDS_Vertex& theVer,
87 const Standard_Real thePar,
88 TopTools_ListOfShape& theListE)
91 // construct 2 new edges
92 TopoDS_Shape aDummy1 = theEdge.EmptyCopied().Oriented(TopAbs_FORWARD);
93 TopoDS_Shape aDummy2 = theEdge.EmptyCopied().Oriented(TopAbs_FORWARD);
94 TopoDS_Edge aNewE1 = TopoDS::Edge (aDummy1);
95 TopoDS_Edge aNewE2 = TopoDS::Edge (aDummy2);
96 Standard_Real aParF, aParL;
97 BRep_Tool::Range (theEdge, aParF, aParL);
98 aBld.Range (aNewE1, aParF, thePar);
99 aBld.Range (aNewE2, thePar, aParL);
101 TopoDS_Iterator aIterE (theEdge, Standard_False);
102 for (; aIterE.More(); aIterE.Next()) {
103 const TopoDS_Vertex& aVer = TopoDS::Vertex (aIterE.Value());
104 Standard_Real aParV = BRep_Tool::Parameter (aVer, theEdge);
105 if (aParV < thePar) aBld.Add (aNewE1, aVer);
106 else aBld.Add (aNewE2, aVer);
109 aBld.Add (aNewE1, theVer.Oriented(TopAbs_REVERSED));
110 aBld.Add (aNewE2, theVer.Oriented(TopAbs_FORWARD));
111 Standard_Real aTol = Max (BRep_Tool::Tolerance(theVer),
112 BRep_Tool::Tolerance(theEdge));
113 aBld.UpdateVertex (theVer, thePar, aNewE1, aTol);
114 aBld.UpdateVertex (theVer, thePar, aNewE2, aTol);
115 theListE.Append (aNewE1.Oriented(theEdge.Orientation()));
116 theListE.Append (aNewE2.Oriented(theEdge.Orientation()));
119 //=======================================================================
120 //function : CompareVertices
122 //=======================================================================
125 QANewModTopOpe_Glue::CompareVertices (const TopoDS_Vertex& theV1, const TopoDS_Vertex& theV2,
126 Standard_Real& theDist)
128 theDist = BRep_Tool::Pnt(theV1).Distance(BRep_Tool::Pnt(theV2));
129 if (theDist <= BRep_Tool::Tolerance(theV1) ||
130 theDist <= BRep_Tool::Tolerance(theV2))
131 return Standard_True;
132 return Standard_False;
135 //=======================================================================
136 //function : FindWireOrUpdateMap
138 //=======================================================================
141 QANewModTopOpe_Glue::FindWireOrUpdateMap (const TopoDS_Shape& theWire,
142 TopTools_IndexedDataMapOfShapeListOfShape& theMapELW)
144 TopoDS_Iterator aIterW (theWire);
145 // const TopoDS_Shape& aRefEdge = aIterW.Value();
146 TopoDS_Shape aRefEdge = aIterW.Value();
147 if (theMapELW.Contains (aRefEdge)) {
148 // map edges of theWire
149 Standard_Integer nbEdges = 0;
150 TopTools_MapOfShape aMapE;
151 for (; aIterW.More(); aIterW.Next()) {
152 aMapE.Add (aIterW.Value());
156 // find in the list a wire with the same set of edges
157 const TopTools_ListOfShape& aListW = theMapELW.FindFromKey (aRefEdge);
158 TopTools_ListIteratorOfListOfShape aIterLW (aListW);
159 for (; aIterLW.More(); aIterLW.Next()) {
160 const TopoDS_Shape& aWire = aIterLW.Value();
161 Standard_Integer nbE = 0;
162 for (aIterW.Initialize (aWire); aIterW.More(); aIterW.Next()) {
164 if (nbE > nbEdges || !aMapE.Contains(aIterW.Value())) break;
166 if (nbE == nbEdges && !aIterW.More())
167 return aWire; // found
171 // remember the edges of this wire in the map for further reference
172 for (aIterW.Initialize (theWire); aIterW.More(); aIterW.Next()) {
173 const TopoDS_Shape& aEdge = aIterW.Value();
174 if (!theMapELW.Contains (aEdge)) {
175 // for Mandrake-10 - mkv,02.06.06 - theMapELW.Add (aEdge, TopTools_ListOfShape());
176 TopTools_ListOfShape aListOfShape;
177 theMapELW.Add (aEdge, aListOfShape);
179 theMapELW.ChangeFromKey(aEdge).Append (theWire);