1 // Created on: 1998-05-20
2 // Created by: Didier PIFFAULT
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <BRepLib_MakeWire.ixx>
24 #include <BRepLib.hxx>
25 #include <TopTools_MapOfShape.hxx>
26 #include <TopTools_MapOfOrientedShape.hxx>
27 #include <TopTools_MapIteratorOfMapOfShape.hxx>
28 #include <TopTools_MapIteratorOfMapOfOrientedShape.hxx>
29 #include <TopTools_DataMapOfShapeShape.hxx>
30 #include <TopTools_ListOfShape.hxx>
31 #include <TopTools_ListIteratorOfListOfShape.hxx>
32 #include <BRep_Builder.hxx>
34 #include <TopExp_Explorer.hxx>
36 #include <TopoDS_Vertex.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Compound.hxx>
39 #include <BRep_Tool.hxx>
41 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
44 //=======================================================================
46 //purpose : Add the list of edges to the current wire
47 //=======================================================================
49 void BRepLib_MakeWire::Add(const TopTools_ListOfShape& L)
51 myError = BRepLib_WireDone;
52 if (!myShape.IsNull()) myShape.Closed(Standard_False);
56 TopTools_MapOfShape mapLocale;
57 mapLocale.Assign(myVertices);
58 TopTools_DataMapOfShapeShape toCopy;
59 TopTools_ListOfShape toAdd, nlist, rlist;
63 TopTools_MapIteratorOfMapOfShape itMS;
64 TopTools_ListIteratorOfListOfShape itList(L);
65 for (;itList.More(); itList.Next()) {
66 const TopoDS_Edge& curEd=TopoDS::Edge(itList.Value());
67 if (!curEd.IsNull()) {
70 Standard_Boolean copEd=Standard_False;
71 if (myEdge.IsNull()) {
73 if (!VF.IsNull()) mapLocale.Add(VF);
74 if (!VL.IsNull()) mapLocale.Add(VL);
78 for (exv.Init(curEd, TopAbs_VERTEX); exv.More(); exv.Next()) {
79 const TopoDS_Vertex& edVer=TopoDS::Vertex(exv.Current());
82 if (!mapLocale.Contains(edVer)) {
84 Standard_Boolean notYetFound = Standard_True;
86 Standard_Boolean notYetFound;
88 Standard_Real gap=BRep_Tool::Tolerance(edVer);
89 gp_Pnt pVer=BRep_Tool::Pnt(edVer);
90 for (itMS.Initialize(mapLocale); itMS.More(); itMS.Next()) {
91 notYetFound=Standard_True;
92 const TopoDS_Vertex& refVer=TopoDS::Vertex(itMS.Key());
93 gap +=BRep_Tool::Tolerance(refVer);
94 if (pVer.Distance(BRep_Tool::Pnt(TopoDS::Vertex(refVer))) <= gap) {
96 nlist.Prepend(refVer.Oriented(edVer.Orientation()));
98 notYetFound=Standard_False;
102 if (notYetFound) mapLocale.Add(edVer);
106 TopoDS_Shape aLocalShape = curEd.EmptyCopied();
107 TopoDS_Edge newEd=TopoDS::Edge(aLocalShape);
108 // TopoDS_Edge newEd=TopoDS::Edge(curEd.EmptyCopied());
109 BB.Transfert(curEd, newEd);
110 newEd.Closed(curEd.Closed());
111 TopTools_ListIteratorOfListOfShape itV(nlist);
112 for (; itV.More(); itV.Next()) {
113 BB.Add(newEd, itV.Value());
114 BB.Transfert(curEd, newEd, TopoDS::Vertex(rlist.First()), TopoDS::Vertex(itV.Value()));
124 if (!toAdd.IsEmpty()) {
125 TopoDS_Compound comp;
126 BB.MakeCompound(comp);
127 TopTools_MapIteratorOfMapOfOrientedShape itMOS;
128 TopTools_MapOfOrientedShape theEdges;
129 for (itList.Initialize(toAdd); itList.More(); itList.Next()) {
130 BB.Add(comp, itList.Value());
131 theEdges.Add(itList.Value());
133 TopTools_IndexedDataMapOfShapeListOfShape lesMeres;
134 TopExp::MapShapesAndAncestors(comp, TopAbs_VERTEX, TopAbs_EDGE, lesMeres);
135 TopoDS_Vertex vf, vl;
137 Standard_Boolean usedVertex;
139 Standard_Boolean closedEdge = Standard_False;
141 Standard_Boolean closedEdge;
143 Standard_Integer vvInd, lastInd;
145 if (!VL.IsNull() && lesMeres.Contains(VL)) {
146 if (!VF.IsNull()) closedEdge=VF.IsSame(VL);
147 usedVertex=Standard_True;
148 for (itList.Initialize(lesMeres.FindFromKey(VL)); itList.More(); itList.Next()) {
149 if (theEdges.Contains(itList.Value())) {
150 usedVertex=Standard_False;
151 theEdges.Remove(itList.Value());
152 TopExp::Vertices(TopoDS::Edge(itList.Value()), vf,vl);
154 BB.Add(myShape, itList.Value());
160 BB.Add(myShape, itList.Value());
164 BB.Add(myShape, itList.Value().Reversed());
173 lastInd=lesMeres.Extent();
174 vvInd=lesMeres.FindIndex(VL);
175 if (vvInd != lastInd) {
176 theKey=lesMeres.FindKey(lastInd);
177 nlist=lesMeres.FindFromIndex(lastInd);
179 lesMeres.RemoveLast();
180 if (vvInd != lastInd) {
181 lesMeres.Substitute(vvInd, theKey, nlist);
185 else if (!VF.IsNull() && lesMeres.Contains(VF)) {
186 usedVertex=Standard_True;
187 for (itList.Initialize(lesMeres.FindFromKey(VF)); itList.More(); itList.Next()) {
188 if (theEdges.Contains(itList.Value())) {
189 usedVertex=Standard_False;
190 theEdges.Remove(itList.Value());
191 TopExp::Vertices(TopoDS::Edge(itList.Value()), vf,vl);
193 BB.Add(myShape, itList.Value());
198 BB.Add(myShape, itList.Value().Reversed());
206 lastInd=lesMeres.Extent();
207 vvInd=lesMeres.FindIndex(VF);
208 if (vvInd != lastInd) {
209 theKey=lesMeres.FindKey(lastInd);
210 nlist=lesMeres.FindFromIndex(lastInd);
212 lesMeres.RemoveLast();
213 if (vvInd != lastInd) {
214 lesMeres.Substitute(vvInd, theKey, nlist);
219 if (theEdges.Extent()>0) {
220 Standard_Boolean noCandidat=Standard_True;
221 for (itMOS.Initialize(theEdges); itMOS.More(); itMOS.Next()) {
222 TopExp::Vertices(TopoDS::Edge(itMOS.Key()), vf,vl);
223 if (myVertices.Contains(vl)) {
224 if (myError==BRepLib_WireDone) myError = BRepLib_NonManifoldWire;
225 BB.Add(myShape, itMOS.Key());
228 noCandidat=Standard_False;
231 else if (myVertices.Contains(vf)) {
232 if (myError==BRepLib_WireDone) myError = BRepLib_NonManifoldWire;
233 BB.Add(myShape, itMOS.Key());
236 noCandidat=Standard_False;
242 // Some Edges are not connected to first edge and the diagnosis is as follows
243 // but the "Maker" is Done() because otherwise it is not possible to return the constructed connected part...
244 myError=BRepLib_DisconnectedWire;
246 else theEdges.Remove(itMOS.Key());
249 } while (theEdges.Extent()>0);
253 if (!VF.IsNull() && !VL.IsNull() && VF.IsSame(VL))
254 myShape.Closed(Standard_True);