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_MapOfShape.hxx>
35 static Standard_Integer FindFirstEdge
36 (const TopTools_IndexedDataMapOfShapeListOfShape&,
37 const TopTools_MapOfShape&);
41 //=======================================================================
42 //function : LocOpe_BuildWires
44 //=======================================================================
46 LocOpe_BuildWires::LocOpe_BuildWires () : myDone(Standard_False)
50 //=======================================================================
51 //function : LocOpe_BuildWires
53 //=======================================================================
55 // Modified by skv - Mon May 31 12:58:27 2004 OCC5865 Begin
56 LocOpe_BuildWires::LocOpe_BuildWires (const TopTools_ListOfShape& L,
57 const Handle(LocOpe_WiresOnShape)& PW)
61 // Modified by skv - Mon May 31 12:58:28 2004 OCC5865 End
64 //=======================================================================
67 //=======================================================================
69 // Modified by skv - Mon May 31 12:59:09 2004 OCC5865 Begin
70 void LocOpe_BuildWires::Perform(const TopTools_ListOfShape& L,
71 const Handle(LocOpe_WiresOnShape)& PW)
73 // Modified by skv - Mon May 31 12:59:10 2004 OCC5865 End
74 myDone = Standard_False;
81 TopTools_MapOfShape theMap;
82 TopTools_ListIteratorOfListOfShape itl(L);
83 for (; itl.More(); itl.Next()) {
84 const TopoDS_Shape& edg = itl.Value();
85 if (theMap.Add(edg) && edg.ShapeType() == TopAbs_EDGE) {
86 B.Add(C,edg.Oriented(TopAbs_FORWARD)); // orientation importante pour
87 // appel a TopExp::Vertices
91 TopTools_IndexedDataMapOfShapeListOfShape theMapVE;
92 TopExp::MapShapesAndAncestors(C,TopAbs_VERTEX,TopAbs_EDGE,theMapVE);
94 TopTools_MapOfShape Bords;
95 // for (Standard_Integer i = 1; i <= theMapVE.Extent(); i++) {
98 for ( i = 1; i <= theMapVE.Extent(); i++) {
99 // Modified by skv - Mon May 31 13:07:50 2004 OCC5865 Begin
100 // if (theMapVE(i).Extent() == 1) {
101 TopoDS_Vertex vtx = TopoDS::Vertex(theMapVE.FindKey(i));
103 TopoDS_Vertex aV_border;
104 Standard_Real partmp;
105 if (theMapVE(i).Extent() == 1 || (PW->OnVertex(vtx, aV_border) || PW->OnEdge(vtx, etmp, partmp)) ) {
107 // Modified by skv - Mon May 31 13:07:50 2004 OCC5865 End
112 while ((i=FindFirstEdge(theMapVE,Bords)) <= theMapVE.Extent()) {
113 TopTools_IndexedMapOfShape mapE;
114 TopTools_MapOfShape mapV;
115 const TopoDS_Edge& edgf = TopoDS::Edge(theMapVE(i).First());
118 TopExp::Vertices(edgf,VF,VL);
120 if (Bords.Contains(VL) && !Bords.Contains(VF)) {
121 mapE.Add(edgf.Oriented(TopAbs_REVERSED));
122 TopoDS_Vertex temp = VF;
127 mapE.Add(edgf.Oriented(TopAbs_FORWARD));
131 while (!(mapV.Contains(VL) || Bords.Contains(VL))) {
132 Standard_Integer ind = theMapVE.FindIndex(VL);
133 TopTools_ListIteratorOfListOfShape anIterl(theMapVE(ind));
134 for (; anIterl.More(); anIterl.Next()) {
135 if (!mapE.Contains(anIterl.Value())) {
140 if (!anIterl.More()) {
141 throw Standard_ConstructionError();
143 const TopoDS_Edge& theEdge = TopoDS::Edge(anIterl.Value());
145 TopExp::Vertices(theEdge,Vf,Vl);
148 mapE.Add(theEdge.Oriented(TopAbs_FORWARD));
151 else { // on doit avoir Vl == VL
152 mapE.Add(theEdge.Oriented(TopAbs_REVERSED));
160 if (mapV.Contains(VL)) { // on sort avec une boucle a recreer
162 // for (Standard_Integer j = 1; j<= mapE.Extent(); j++) {
164 for ( j = 1; j<= mapE.Extent(); j++) {
165 const TopoDS_Edge& edg = TopoDS::Edge(mapE(j));
166 if (edg.Orientation() == TopAbs_FORWARD) {
167 Vf = TopExp::FirstVertex(edg);
170 Vf = TopExp::LastVertex(edg);
177 for (; j<= mapE.Extent(); j++) {
178 B.Add(newWire,mapE(j));
180 newWire.Closed(Standard_True);
182 else { // on sort sur un bord : wire ouvert...
184 for (Standard_Integer j = 1; j <= mapE.Extent(); j++) {
185 B.Add(newWire,mapE(j));
187 newWire.Closed(Standard_False);
190 myRes.Append(newWire);
191 TopTools_MapIteratorOfMapOfShape itm;
192 for (itm.Initialize(mapV);
193 itm.More();itm.Next()) {
194 const TopoDS_Vertex& vtx = TopoDS::Vertex(itm.Key());
196 Standard_Integer ind = theMapVE.FindIndex(vtx);
197 itl.Initialize(theMapVE(ind));
199 if (mapE.Contains(itl.Value())) {
200 theMapVE(ind).Remove(itl);
209 myDone = Standard_True;
214 //=======================================================================
217 //=======================================================================
219 Standard_Boolean LocOpe_BuildWires::IsDone() const
226 //=======================================================================
229 //=======================================================================
231 const TopTools_ListOfShape& LocOpe_BuildWires::Result () const
234 throw StdFail_NotDone();
240 //=======================================================================
241 //function : FindFirstEdge
243 //=======================================================================
245 static Standard_Integer FindFirstEdge
246 (const TopTools_IndexedDataMapOfShapeListOfShape& theMapVE,
247 const TopTools_MapOfShape& theBord)
249 Standard_Integer i = 1;
251 for (; i<=theMapVE.Extent(); i++) {
252 if (theMapVE(i).Extent() >0) {
257 if (i>theMapVE.Extent()) {
261 Standard_Integer goodi = i;
262 for (; i <= theMapVE.Extent(); i++) {
263 const TopoDS_Shape& vtx = theMapVE.FindKey(i);
264 if (theMapVE(i).Extent() >0 && theBord.Contains(vtx)) {