0023429: BRepFeat_SplitShape algorithm misses some section edges while building resul...
[occt.git] / src / LocOpe / LocOpe_GluedShape.cxx
CommitLineData
b311480e 1// Created on: 1996-01-30
2// Created by: Jacques GOUSSARD
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
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.
10//
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.
13//
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.
20
7fd59977 21
22
23#include <LocOpe_GluedShape.ixx>
24
25#include <TopExp_Explorer.hxx>
26#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
27#include <TopTools_MapOfShape.hxx>
28#include <TopTools_MapIteratorOfMapOfShape.hxx>
29#include <TopTools_ListIteratorOfListOfShape.hxx>
30
31#include <TopoDS.hxx>
32#include <TopExp.hxx>
33
34#include <Standard_ConstructionError.hxx>
35
36//=======================================================================
37//function : LocOpe_GluedShape
38//purpose :
39//=======================================================================
40
41LocOpe_GluedShape::LocOpe_GluedShape ()
42{}
43
44
45//=======================================================================
46//function : LocOpe_GluedShape
47//purpose :
48//=======================================================================
49
50LocOpe_GluedShape::LocOpe_GluedShape(const TopoDS_Shape& S) :
51 myShape(S)
52{}
53
54
55//=======================================================================
56//function : Init
57//purpose :
58//=======================================================================
59
60void LocOpe_GluedShape::Init(const TopoDS_Shape& S)
61{
62 myShape = S;
63 myMap.Clear();
64 myGShape.Clear();
65 myList.Clear();
66 myGEdges.Clear();
67}
68
69
70//=======================================================================
71//function : GlueOnFace
72//purpose :
73//=======================================================================
74
75void LocOpe_GluedShape::GlueOnFace(const TopoDS_Face& F)
76{
77// for (TopExp_Explorer exp(myShape,TopAbs_FACE); exp.More();exp.Next()) {
78 TopExp_Explorer exp(myShape,TopAbs_FACE) ;
79 for ( ; exp.More();exp.Next()) {
80 if (exp.Current().IsSame(F)) {
81 break;
82 }
83 }
84 if (!exp.More()) {
85 Standard_ConstructionError::Raise();
86 }
87 myMap.Add(exp.Current()); // bonne orientation
88}
89
90
91//=======================================================================
92//function : MapEdgeAndVertices
93//purpose :
94//=======================================================================
95
96void LocOpe_GluedShape::MapEdgeAndVertices()
97{
98 if (!myGShape.IsEmpty()) {
99 return;
100 }
101
102
103 // Edges et faces generes
104
105 TopTools_IndexedDataMapOfShapeListOfShape theMapEF;
106 TopExp::MapShapesAndAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, theMapEF);
107
108 TopTools_MapOfShape mapdone;
109 TopTools_MapIteratorOfMapOfShape itm(myMap);
110 TopTools_ListIteratorOfListOfShape itl;
111 TopExp_Explorer exp,exp2,exp3;
112
113 for (; itm.More(); itm.Next()) {
114 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
115 for (exp.Init(fac,TopAbs_EDGE); exp.More(); exp.Next()) {
116 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
117 if (mapdone.Contains(edg)) {
118 continue;
119 }
120 // Est-ce un edge de connexite entre les faces collees
121 if (theMapEF.FindFromKey(edg).Extent() != 2) {
122 Standard_ConstructionError::Raise();
123 }
124 for (itl.Initialize(theMapEF.FindFromKey(edg)); itl.More(); itl.Next()) {
125 if (!myMap.Contains(itl.Value())) {
126 break;
127 }
128 }
129
130 if (itl.More()) {
131// myGEdges.Append(edg);
132 myGEdges.Append(edg.Reversed());
133 myGShape.Bind(edg,itl.Value()); // voir orientation,
134 //mais devrait etre bon
135 }
136
137 mapdone.Add(edg);
138 }
139 }
140
141 for (itl.Initialize(myGEdges); itl.More(); itl.Next()) {
142 const TopoDS_Edge& edg = TopoDS::Edge(itl.Value());
143 for (exp.Init(edg,TopAbs_VERTEX); exp.More(); exp.Next()) {
144 const TopoDS_Vertex& vtx = TopoDS::Vertex(exp.Current());
145 if (myGShape.IsBound(vtx)) {
146 continue;
147 }
148 for (exp2.Init(myGShape(edg),TopAbs_EDGE);exp2.More();exp2.Next()) {
149 if (exp2.Current().IsSame(edg)) {
150 continue;
151 }
152 for (exp3.Init(exp2.Current(),TopAbs_VERTEX);
153 exp3.More(); exp3.Next()) {
154 if (exp3.Current().IsSame(vtx)) {
155 if (myGShape.IsBound(exp2.Current())) {
156 myGShape.Bind(vtx,TopoDS_Edge());
157 }
158 else {
159 myGShape.Bind(vtx,exp2.Current());
160 }
161 break;
162 }
163 }
164 if (exp3.More()) {
165 break;
166 }
167 }
168 }
169 }
170
171 // liste de faces
172
173 for (exp.Init(myShape,TopAbs_FACE); exp.More(); exp.Next()) {
174 if (!myMap.Contains(exp.Current())) {
175 myList.Append(exp.Current());
176 }
177 }
178}
179
180
181
182
183//=======================================================================
184//function : GeneratingEdges
185//purpose :
186//=======================================================================
187
188const TopTools_ListOfShape& LocOpe_GluedShape::GeneratingEdges()
189{
190 if (myGShape.IsEmpty()) {
191 MapEdgeAndVertices();
192 }
193 return myGEdges;
194}
195
196
197//=======================================================================
198//function : Generated
199//purpose :
200//=======================================================================
201
202TopoDS_Edge LocOpe_GluedShape::Generated(const TopoDS_Vertex& V)
203{
204 if (myGShape.IsEmpty()) {
205 MapEdgeAndVertices();
206 }
207 return TopoDS::Edge(myGShape(V));
208}
209
210
211//=======================================================================
212//function : Generated
213//purpose :
214//=======================================================================
215
216TopoDS_Face LocOpe_GluedShape::Generated(const TopoDS_Edge& E)
217{
218 if (myGShape.IsEmpty()) {
219 MapEdgeAndVertices();
220 }
221 return TopoDS::Face(myGShape(E));
222}
223
224
225//=======================================================================
226//function : OrientedFaces
227//purpose :
228//=======================================================================
229
230const TopTools_ListOfShape& LocOpe_GluedShape::OrientedFaces()
231{
232 if (myGShape.IsEmpty()) {
233 MapEdgeAndVertices();
234 }
235 return myList;
236}
237