b311480e |
1 | // Created on: 1997-08-22 |
2 | // Created by: Prestataire Mary FABIEN |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <BRep_Builder.hxx> |
19 | #include <BRepAlgo_DataMapOfShapeBoolean.hxx> |
20 | #include <BRepAlgo_EdgeConnector.hxx> |
21 | #include <Standard_Type.hxx> |
22 | #include <TopoDS_Edge.hxx> |
7fd59977 |
23 | #include <TopoDS_Shape.hxx> |
7fd59977 |
24 | #include <TopoDS_Wire.hxx> |
7fd59977 |
25 | #include <TopOpeBRepBuild_BlockBuilder.hxx> |
42cf5bc1 |
26 | #include <TopOpeBRepBuild_BlockIterator.hxx> |
27 | #include <TopOpeBRepBuild_ShapeSet.hxx> |
28 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
29 | #include <TopTools_ListOfShape.hxx> |
7fd59977 |
30 | |
31 | //======================================================================= |
32 | //function : Create |
33 | //purpose : |
34 | //======================================================================= |
7fd59977 |
35 | BRepAlgo_EdgeConnector::BRepAlgo_EdgeConnector() |
36 | :myIsDone(Standard_False) |
37 | { |
38 | myListeOfEdge.Clear(); |
39 | } |
40 | |
41 | //======================================================================= |
42 | //function : Add |
43 | //purpose : |
44 | //======================================================================= |
45 | |
46 | void BRepAlgo_EdgeConnector::Add(const TopoDS_Edge& e) |
47 | { |
48 | if(e.IsNull()) return; |
49 | myListeOfEdge.Append(e); |
50 | } |
51 | |
52 | //======================================================================= |
53 | //function : Add |
54 | //purpose : |
55 | //======================================================================= |
56 | |
57 | void BRepAlgo_EdgeConnector::Add(TopTools_ListOfShape& LOEdge) |
58 | { |
59 | if(LOEdge.IsEmpty()) return; |
60 | myListeOfEdge.Append(LOEdge); |
61 | } |
62 | |
63 | //======================================================================= |
64 | //function : AddStart |
65 | //purpose : |
66 | //======================================================================= |
67 | |
68 | void BRepAlgo_EdgeConnector::AddStart(const TopoDS_Shape& e) |
69 | { |
70 | if(e.IsNull()) return; |
71 | myListeOfStartEdge.Append(e); |
72 | } |
73 | |
74 | //======================================================================= |
75 | //function : AddStart |
76 | //purpose : |
77 | //======================================================================= |
78 | |
79 | void BRepAlgo_EdgeConnector::AddStart(TopTools_ListOfShape& LOEdge) |
80 | { |
81 | if(LOEdge.IsEmpty()) return; |
82 | myListeOfStartEdge.Append(LOEdge); |
83 | } |
84 | |
85 | //======================================================================= |
86 | //function : ClearStartElement |
87 | //purpose : |
88 | //======================================================================= |
89 | |
90 | void BRepAlgo_EdgeConnector::ClearStartElement() |
91 | { |
92 | myListeOfStartEdge.Clear(); |
93 | } |
94 | |
95 | //======================================================================= |
96 | //function : MakeBlock |
97 | //purpose : |
98 | //======================================================================= |
99 | |
100 | TopTools_ListOfShape& BRepAlgo_EdgeConnector::MakeBlock() |
101 | { |
102 | Standard_Boolean b; |
103 | if(myListeOfStartEdge.IsEmpty()) return myListeOfStartEdge; |
104 | TopOpeBRepBuild_ShapeSet SS(TopAbs_VERTEX); |
105 | myResultMap.Clear(); |
106 | myResultList.Clear(); |
107 | TopTools_ListIteratorOfListOfShape it(myListeOfEdge); |
108 | for(;it.More();it.Next()) { |
109 | const TopoDS_Shape& edge = it.Value(); |
110 | SS.AddElement(edge); |
111 | } |
112 | it.Initialize(myListeOfStartEdge); |
113 | for(;it.More();it.Next()) { |
114 | const TopoDS_Shape& edge = it.Value(); |
115 | SS.AddStartElement(edge); |
116 | } |
117 | myBlockB.MakeBlock(SS); |
118 | BRep_Builder WireB; |
119 | for(myBlockB.InitBlock();myBlockB.MoreBlock();myBlockB.NextBlock()) { |
0797d9d3 |
120 | //#ifndef OCCT_DEBUG |
7fd59977 |
121 | TopOpeBRepBuild_BlockIterator BI = myBlockB.BlockIterator(); |
122 | //#else |
123 | // TopOpeBRepBuild_BlockIterator& BI = myBlockB.BlockIterator(); |
124 | //#endif |
125 | TopoDS_Wire W; |
126 | WireB.MakeWire(W); |
127 | for(BI.Initialize();BI.More();BI.Next()) { |
128 | const TopoDS_Shape& CurrentE = myBlockB.Element(BI); |
129 | WireB.Add(W, CurrentE); |
130 | } |
131 | b = myBlockB.CurrentBlockIsRegular(); |
132 | myResultMap.Bind(W, b); |
133 | myResultList.Append(W); |
134 | } |
135 | Done(); |
136 | return myResultList; |
137 | } |
138 | |
139 | //======================================================================= |
140 | //function : IsWire |
141 | //purpose : |
142 | //======================================================================= |
143 | |
144 | Standard_Boolean BRepAlgo_EdgeConnector::IsWire(const TopoDS_Shape& S) |
145 | { |
146 | if(!myResultMap.IsBound(S)) { |
147 | return Standard_False; |
148 | } |
149 | Standard_Boolean b = Standard_False; |
150 | myBlockB.InitBlock(); |
151 | TopTools_ListIteratorOfListOfShape LI(myResultList); |
152 | for(;myBlockB.MoreBlock();myBlockB.NextBlock(),LI.Next()) { |
153 | if(S == LI.Value()) { |
154 | b = myBlockB.CurrentBlockIsRegular(); |
155 | break; |
156 | } |
157 | } |
158 | return b; |
159 | } |
160 | |
161 | //======================================================================= |
162 | //function : IsDone |
163 | //purpose : |
164 | //======================================================================= |
165 | |
166 | |
167 | Standard_Boolean BRepAlgo_EdgeConnector::IsDone() const |
168 | { |
169 | return myIsDone; |
170 | } |
171 | |
172 | //======================================================================= |
173 | //function : Done |
174 | //purpose : |
175 | //======================================================================= |
176 | |
177 | |
178 | void BRepAlgo_EdgeConnector::Done() |
179 | { |
180 | myIsDone = Standard_True; |
181 | } |
182 | |