1 // Created on: 1997-05-27
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by skv - Mon May 31 12:58:34 2004 OCC5865
19 #include <BRep_Builder.hxx>
20 #include <LocOpe_BuildWires.hxx>
21 #include <LocOpe_WiresOnShape.hxx>
22 #include <Standard_ConstructionError.hxx>
23 #include <StdFail_NotDone.hxx>
26 #include <TopoDS_Compound.hxx>
27 #include <TopoDS_Edge.hxx>
28 #include <TopoDS_Vertex.hxx>
29 #include <TopoDS_Wire.hxx>
30 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
31 #include <TopTools_IndexedMapOfShape.hxx>
32 #include <TopTools_ListIteratorOfListOfShape.hxx>
33 #include <TopTools_MapIteratorOfMapOfShape.hxx>
34 #include <TopTools_MapOfShape.hxx>
36 static Standard_Integer FindFirstEdge
37 (const TopTools_IndexedDataMapOfShapeListOfShape&,
38 const TopTools_MapOfShape&);
42 //=======================================================================
43 //function : LocOpe_BuildWires
45 //=======================================================================
47 LocOpe_BuildWires::LocOpe_BuildWires () : myDone(Standard_False)
51 //=======================================================================
52 //function : LocOpe_BuildWires
54 //=======================================================================
56 // Modified by skv - Mon May 31 12:58:27 2004 OCC5865 Begin
57 LocOpe_BuildWires::LocOpe_BuildWires (const TopTools_ListOfShape& L,
58 const Handle(LocOpe_WiresOnShape)& PW)
62 // Modified by skv - Mon May 31 12:58:28 2004 OCC5865 End
65 //=======================================================================
68 //=======================================================================
70 // Modified by skv - Mon May 31 12:59:09 2004 OCC5865 Begin
71 void LocOpe_BuildWires::Perform(const TopTools_ListOfShape& L,
72 const Handle(LocOpe_WiresOnShape)& PW)
74 // Modified by skv - Mon May 31 12:59:10 2004 OCC5865 End
75 myDone = Standard_False;
82 TopTools_MapOfShape theMap;
83 TopTools_ListIteratorOfListOfShape itl(L);
84 for (; itl.More(); itl.Next()) {
85 const TopoDS_Shape& edg = itl.Value();
86 if (theMap.Add(edg) && edg.ShapeType() == TopAbs_EDGE) {
87 B.Add(C,edg.Oriented(TopAbs_FORWARD)); // orientation importante pour
88 // appel a TopExp::Vertices
92 TopTools_IndexedDataMapOfShapeListOfShape theMapVE;
93 TopExp::MapShapesAndAncestors(C,TopAbs_VERTEX,TopAbs_EDGE,theMapVE);
95 TopTools_MapOfShape Bords;
96 // for (Standard_Integer i = 1; i <= theMapVE.Extent(); i++) {
99 for ( i = 1; i <= theMapVE.Extent(); i++) {
100 // Modified by skv - Mon May 31 13:07:50 2004 OCC5865 Begin
101 // if (theMapVE(i).Extent() == 1) {
102 TopoDS_Vertex vtx = TopoDS::Vertex(theMapVE.FindKey(i));
104 TopoDS_Vertex aV_border;
105 Standard_Real partmp;
106 if (theMapVE(i).Extent() == 1 || (PW->OnVertex(vtx, aV_border) || PW->OnEdge(vtx, etmp, partmp)) ) {
108 // Modified by skv - Mon May 31 13:07:50 2004 OCC5865 End
113 while ((i=FindFirstEdge(theMapVE,Bords)) <= theMapVE.Extent()) {
114 TopTools_IndexedMapOfShape mapE;
115 TopTools_MapOfShape mapV;
116 const TopoDS_Edge& edgf = TopoDS::Edge(theMapVE(i).First());
119 TopExp::Vertices(edgf,VF,VL);
121 if (Bords.Contains(VL) && !Bords.Contains(VF)) {
122 mapE.Add(edgf.Oriented(TopAbs_REVERSED));
123 TopoDS_Vertex temp = VF;
128 mapE.Add(edgf.Oriented(TopAbs_FORWARD));
132 while (!(mapV.Contains(VL) || Bords.Contains(VL))) {
133 Standard_Integer ind = theMapVE.FindIndex(VL);
134 TopTools_ListIteratorOfListOfShape anIterl(theMapVE(ind));
135 for (; anIterl.More(); anIterl.Next()) {
136 if (!mapE.Contains(anIterl.Value())) {
141 if (!anIterl.More()) {
142 Standard_ConstructionError::Raise();
144 const TopoDS_Edge& theEdge = TopoDS::Edge(anIterl.Value());
146 TopExp::Vertices(theEdge,Vf,Vl);
149 mapE.Add(theEdge.Oriented(TopAbs_FORWARD));
152 else { // on doit avoir Vl == VL
153 mapE.Add(theEdge.Oriented(TopAbs_REVERSED));
161 if (mapV.Contains(VL)) { // on sort avec une boucle a recreer
163 // for (Standard_Integer j = 1; j<= mapE.Extent(); j++) {
165 for ( j = 1; j<= mapE.Extent(); j++) {
166 const TopoDS_Edge& edg = TopoDS::Edge(mapE(j));
167 if (edg.Orientation() == TopAbs_FORWARD) {
168 Vf = TopExp::FirstVertex(edg);
171 Vf = TopExp::LastVertex(edg);
178 for (; j<= mapE.Extent(); j++) {
179 B.Add(newWire,mapE(j));
181 newWire.Closed(Standard_True);
183 else { // on sort sur un bord : wire ouvert...
185 for (Standard_Integer j = 1; j <= mapE.Extent(); j++) {
186 B.Add(newWire,mapE(j));
188 newWire.Closed(Standard_False);
191 myRes.Append(newWire);
192 TopTools_MapIteratorOfMapOfShape itm;
193 for (itm.Initialize(mapV);
194 itm.More();itm.Next()) {
195 const TopoDS_Vertex& vtx = TopoDS::Vertex(itm.Key());
197 Standard_Integer ind = theMapVE.FindIndex(vtx);
198 itl.Initialize(theMapVE(ind));
200 if (mapE.Contains(itl.Value())) {
201 theMapVE(ind).Remove(itl);
210 myDone = Standard_True;
215 //=======================================================================
218 //=======================================================================
220 Standard_Boolean LocOpe_BuildWires::IsDone() const
227 //=======================================================================
230 //=======================================================================
232 const TopTools_ListOfShape& LocOpe_BuildWires::Result () const
235 StdFail_NotDone::Raise();
241 //=======================================================================
242 //function : FindFirstEdge
244 //=======================================================================
246 static Standard_Integer FindFirstEdge
247 (const TopTools_IndexedDataMapOfShapeListOfShape& theMapVE,
248 const TopTools_MapOfShape& theBord)
250 Standard_Integer i = 1;
252 for (; i<=theMapVE.Extent(); i++) {
253 if (theMapVE(i).Extent() >0) {
258 if (i>theMapVE.Extent()) {
262 Standard_Integer goodi = i;
263 for (; i <= theMapVE.Extent(); i++) {
264 const TopoDS_Shape& vtx = theMapVE.FindKey(i);
265 if (theMapVE(i).Extent() >0 && theBord.Contains(vtx)) {