b311480e |
1 | // Created on: 2001-01-16 |
2 | // Created by: Michael SAZONOV |
973c2be1 |
3 | // Copyright (c) 2001-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
42cf5bc1 |
16 | |
17 | #include <BRep_Builder.hxx> |
18 | #include <BRep_Tool.hxx> |
7fd59977 |
19 | #include <Geom_Curve.hxx> |
42cf5bc1 |
20 | #include <GeomAPI_ProjectPointOnCurve.hxx> |
21 | #include <gp_Pnt.hxx> |
22 | #include <QANewModTopOpe_Glue.hxx> |
7fd59977 |
23 | #include <TopoDS.hxx> |
42cf5bc1 |
24 | #include <TopoDS_Edge.hxx> |
25 | #include <TopoDS_Face.hxx> |
7fd59977 |
26 | #include <TopoDS_Iterator.hxx> |
42cf5bc1 |
27 | #include <TopoDS_Shape.hxx> |
28 | #include <TopoDS_Vertex.hxx> |
7fd59977 |
29 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
7fd59977 |
30 | |
31 | //======================================================================= |
32 | //function : ProjPointOnEdge |
33 | //purpose : |
34 | //======================================================================= |
7fd59977 |
35 | Standard_Boolean |
36 | QANewModTopOpe_Glue::ProjPointOnEdge (const gp_Pnt& thePnt, const TopoDS_Edge& theEdge, |
37 | Standard_Real& thePar, Standard_Real& theDist) |
38 | { |
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(); |
46 | return Standard_True; |
47 | } |
48 | |
49 | //======================================================================= |
50 | //function : InsertVertexInEdge |
51 | //purpose : |
52 | //======================================================================= |
53 | |
54 | void |
55 | QANewModTopOpe_Glue::InsertVertexInEdge (const TopoDS_Edge& theEdge, |
56 | const TopoDS_Vertex& theVer, |
57 | const Standard_Real thePar, |
58 | TopoDS_Edge& theNewEdge) |
59 | { |
60 | BRep_Builder aBld; |
61 | // construct new edge |
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); |
67 | // add old vertices |
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()); |
77 | } |
78 | |
79 | //======================================================================= |
80 | //function : SplitEdgeByVertex |
81 | //purpose : |
82 | //======================================================================= |
83 | |
84 | void |
85 | QANewModTopOpe_Glue::SplitEdgeByVertex (const TopoDS_Edge& theEdge, |
86 | const TopoDS_Vertex& theVer, |
87 | const Standard_Real thePar, |
88 | TopTools_ListOfShape& theListE) |
89 | { |
90 | BRep_Builder aBld; |
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); |
100 | // add old vertices |
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); |
107 | } |
108 | // add new vertex |
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())); |
117 | } |
118 | |
119 | //======================================================================= |
120 | //function : CompareVertices |
121 | //purpose : |
122 | //======================================================================= |
123 | |
124 | Standard_Boolean |
125 | QANewModTopOpe_Glue::CompareVertices (const TopoDS_Vertex& theV1, const TopoDS_Vertex& theV2, |
126 | Standard_Real& theDist) |
127 | { |
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; |
133 | } |
134 | |
135 | //======================================================================= |
136 | //function : FindWireOrUpdateMap |
137 | //purpose : |
138 | //======================================================================= |
139 | |
140 | const TopoDS_Shape& |
141 | QANewModTopOpe_Glue::FindWireOrUpdateMap (const TopoDS_Shape& theWire, |
142 | TopTools_IndexedDataMapOfShapeListOfShape& theMapELW) |
143 | { |
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()); |
153 | nbEdges++; |
154 | } |
155 | |
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()) { |
163 | nbE++; |
164 | if (nbE > nbEdges || !aMapE.Contains(aIterW.Value())) break; |
165 | } |
166 | if (nbE == nbEdges && !aIterW.More()) |
167 | return aWire; // found |
168 | } |
169 | } |
170 | |
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); |
178 | } |
179 | theMapELW.ChangeFromKey(aEdge).Append (theWire); |
180 | } |
181 | return theWire; |
182 | } |