1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Standard_Stream.hxx>
22 #include <GEOMImpl_Block6Explorer.hxx>
24 #include <ShHealOper_ShapeProcess.hxx>
26 #include "utilities.h"
28 #include <BRep_Tool.hxx>
29 #include <BRep_TFace.hxx>
30 #include <BRep_Builder.hxx>
31 #include <BRepLib.hxx>
32 #include <BRepLib_FindSurface.hxx>
33 #include <BRepTools.hxx>
34 #include <BRepTools_WireExplorer.hxx>
35 #include <BRepOffsetAPI_ThruSections.hxx>
36 #include <BRepOffsetAPI_MakeFilling.hxx>
37 #include <BRepCheck_Analyzer.hxx>
38 #include <BRepBuilderAPI_Copy.hxx>
39 #include <BRepBuilderAPI_MakeEdge.hxx>
40 #include <BRepBuilderAPI_MakeWire.hxx>
41 #include <BRepBuilderAPI_MakeFace.hxx>
42 #include <BRepBuilderAPI_Transform.hxx>
46 #include <TopoDS_Shape.hxx>
47 #include <TopoDS_Edge.hxx>
48 #include <TopoDS_Wire.hxx>
49 #include <TopoDS_Solid.hxx>
51 #include <TopExp_Explorer.hxx>
52 #include <TopTools_MapOfShape.hxx>
53 #include <TopTools_ListOfShape.hxx>
54 #include <TopTools_ListIteratorOfListOfShape.hxx>
55 #include <TopTools_IndexedMapOfShape.hxx>
56 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
58 #include <Geom_Curve.hxx>
59 #include <Geom_TrimmedCurve.hxx>
60 #include <GeomFill_Generator.hxx>
62 #include <Precision.hxx>
64 #include <TColgp_Array1OfPnt.hxx>
66 #include <StdFail_NotDone.hxx>
67 #include <Standard_NullObject.hxx>
68 #include <Standard_TypeMismatch.hxx>
69 #include <Standard_ConstructionError.hxx>
70 #include <Standard_NoSuchObject.hxx>
76 static Standard_Integer mod4 (Standard_Integer nb)
78 if (nb <= 0) return nb + 4;
79 if (nb > 4) return nb - 4;
83 static Standard_Integer edge_id (const Standard_Integer theFaceID,
84 const Standard_Integer theEdgeNB)
86 static Standard_Integer edge_ids[NBFACES][4] = {
87 { 1, 2, 3, 4 }, // face 1
88 { 5, 6, 7, 8 }, // face 2
89 { 9, 5, 10, 1 }, // face 3
90 { 12, 7, 11, 3 }, // face 4
91 { 4, 12, 8, 9 }, // face 5
92 { 2, 11, 6, 10 } }; // face 6
94 return edge_ids[theFaceID - 1][theEdgeNB - 1];
97 static Standard_Integer side_edge_id (const Standard_Integer theEdgeNB)
99 static Standard_Integer side_edge_ids[4] = {9, 10, 11, 12};
101 return side_edge_ids[theEdgeNB - 1];
104 static Standard_Integer vertex_id (const Standard_Integer theFaceID,
105 const Standard_Integer theVertexNB)
107 static Standard_Integer vertex_ids[NBFACES][4] = {
108 { 1, 2, 3, 4 }, // face 1
109 { 5, 6, 7, 8 }, // face 2
110 { 1, 5, 6, 2 }, // face 3
111 { 4, 8, 7, 3 }, // face 4
112 { 1, 4, 8, 5 }, // face 5
113 { 2, 3, 7, 6 } }; // face 6
115 return vertex_ids[theFaceID - 1][theVertexNB - 1];
118 static Standard_Integer vertex_id_edge (const Standard_Integer theEdgeID, // [1,12]
119 const Standard_Integer theVertexNB) // [1,2]
121 static Standard_Integer vertex_ids_edge[NBEDGES][2] = {
135 return vertex_ids_edge[theEdgeID - 1][theVertexNB - 1];
138 static Standard_Integer face_id_edges (const Standard_Integer theEdge1ID, // [1,12]
139 const Standard_Integer theEdge2ID) // [1,12]
141 static Standard_Integer face_ids_edges[NBEDGES][NBEDGES] = {
142 // 1 2 3 4 5 6 7 8 9 10 11 12
143 { 0, 1, 1, 1, 3, 0, 0, 0, 3, 3, 0, 0 }, // edge 1
144 { 1, 0, 1, 1, 0, 6, 0, 0, 0, 6, 6, 0 }, // edge 2
145 { 1, 1, 0, 1, 0, 0, 4, 0, 0, 0, 4, 4 }, // edge 3
146 { 1, 1, 1, 0, 0, 0, 0, 5, 5, 0, 0, 5 }, // edge 4
147 { 3, 0, 0, 0, 0, 2, 2, 2, 3, 3, 0, 0 }, // edge 5
148 { 0, 6, 0, 0, 2, 0, 2, 2, 0, 6, 6, 0 }, // edge 6
149 { 0, 0, 4, 0, 2, 2, 0, 2, 0, 0, 4, 4 }, // edge 7
150 { 0, 0, 0, 5, 2, 2, 2, 0, 5, 0, 0, 5 }, // edge 8
151 { 3, 0, 0, 5, 3, 0, 0, 5, 0, 3, 0, 5 }, // edge 9
152 { 3, 6, 0, 0, 3, 6, 0, 0, 3, 0, 6, 0 }, // edge 10
153 { 0, 6, 4, 0, 0, 6, 4, 0, 0, 6, 0, 4 }, // edge 11
154 { 0, 0, 4, 5, 0, 0, 4, 5, 5, 0, 4, 0 } }; // edge 12
156 return face_ids_edges[theEdge1ID - 1][theEdge2ID - 1];
159 static Standard_Integer edge_id_vertices (const Standard_Integer theVertex1ID, // [1,8]
160 const Standard_Integer theVertex2ID) // [1,8]
162 static Standard_Integer edge_ids_vertices[NBVERTS][NBVERTS] = {
164 { 0, 1, 0, 4, 9, 0, 0, 0}, // vertex 1
165 { 1, 0, 2, 0, 0, 10, 0, 0}, // vertex 2
166 { 0, 2, 0, 3, 0, 0, 11, 0}, // vertex 3
167 { 4, 0, 3, 0, 0, 0, 0, 12}, // vertex 4
168 { 9, 0, 0, 0, 0, 5, 0, 8}, // vertex 5
169 { 0, 10, 0, 0, 5, 0, 6, 0}, // vertex 6
170 { 0, 0, 11, 0, 0, 6, 0, 7}, // vertex 7
171 { 0, 0, 0, 12, 8, 0, 7, 0} }; // vertex 8
173 return edge_ids_vertices[theVertex1ID - 1][theVertex2ID - 1];
176 static Standard_Integer edge_id_faces (const Standard_Integer theFace1ID, // [1,6]
177 const Standard_Integer theFace2ID) // [1,6]
179 static Standard_Integer edge_ids_faces[NBFACES][NBFACES] = {
181 { 0, 0, 1, 3, 4, 2 }, // face 1
182 { 0, 0, 5, 7, 8, 6 }, // face 2
183 { 1, 5, 0, 0, 9, 10 }, // face 3
184 { 3, 7, 0, 0, 12, 11 }, // face 4
185 { 4, 8, 9, 12, 0, 0 }, // face 5
186 { 2, 6, 10, 11, 0, 0 } }; // face 6
188 return edge_ids_faces[theFace1ID - 1][theFace2ID - 1];
191 //=======================================================================
192 //function : GEOMImpl_Block6Explorer
193 //purpose : Constructor
194 //=======================================================================
195 GEOMImpl_Block6Explorer::GEOMImpl_Block6Explorer ()
196 : myFaces(1,NBFACES), myEdges(1,NBEDGES), myVertices(1,NBVERTS)
200 //=======================================================================
201 //function : GetVertex
203 //=======================================================================
204 TopoDS_Shape GEOMImpl_Block6Explorer::GetVertex (const Standard_Integer theVertexID)
206 TopoDS_Shape aNullShape;
207 if (theVertexID < 1 || theVertexID > NBVERTS) return aNullShape;
208 return myVertices(theVertexID);
211 //=======================================================================
212 //function : GetVertexID
214 //=======================================================================
215 Standard_Integer GEOMImpl_Block6Explorer::GetVertexID (const TopoDS_Shape& theVertex)
217 for (Standard_Integer id = 1; id <= NBVERTS; id++) {
218 if (theVertex.IsSame(myVertices(id))) return id;
220 Standard_NoSuchObject::Raise("The Vertex does not belong to the Block");
224 //=======================================================================
225 //function : GetVertexID
227 //=======================================================================
228 Standard_Integer GEOMImpl_Block6Explorer::GetVertexID (const Standard_Integer theFaceID,
229 const Standard_Integer theVertexNB)
231 return vertex_id(theFaceID, theVertexNB);
234 //=======================================================================
235 //function : GetVertexOnEdgeID
237 //=======================================================================
238 Standard_Integer GEOMImpl_Block6Explorer::GetVertexOnEdgeID
239 (const Standard_Integer theEdgeID,
240 const Standard_Integer theVertexNB)
242 return vertex_id_edge(theEdgeID, theVertexNB);
245 //=======================================================================
248 //=======================================================================
249 TopoDS_Shape GEOMImpl_Block6Explorer::GetEdge (const Standard_Integer theEdgeID,
250 const Standard_Boolean doMake)
252 TopoDS_Shape aNullShape;
253 if (theEdgeID < 1 || theEdgeID > NBEDGES) return aNullShape;
254 if (myEdges(theEdgeID).IsNull() && doMake) {
255 // Create the required edge as a linear segment between
256 // corresponding vertices and put it in the Block's edges
257 BRepBuilderAPI_MakeEdge ME (TopoDS::Vertex(myVertices(vertex_id_edge(theEdgeID, 1))),
258 TopoDS::Vertex(myVertices(vertex_id_edge(theEdgeID, 2))));
260 Standard_ConstructionError::Raise("Edge construction failed");
262 myEdges(theEdgeID) = ME.Shape();
265 return myEdges(theEdgeID);
268 //=======================================================================
269 //function : GetEdgeID
271 //=======================================================================
272 Standard_Integer GEOMImpl_Block6Explorer::GetEdgeID (const TopoDS_Shape& theEdge)
274 for (Standard_Integer id = 1; id <= NBEDGES; id++) {
275 if (theEdge.IsSame(myEdges(id))) return id;
277 Standard_NoSuchObject::Raise("The Edge does not belong to the Block");
281 //=======================================================================
282 //function : GetEdgeID
284 //=======================================================================
285 Standard_Integer GEOMImpl_Block6Explorer::GetEdgeID (const Standard_Integer theFaceID,
286 const Standard_Integer theEdgeNB)
288 return edge_id(theFaceID, theEdgeNB);
291 //=======================================================================
292 //function : FindEdgeID
294 //=======================================================================
295 Standard_Integer GEOMImpl_Block6Explorer::FindEdgeID (const Standard_Integer theVertex1ID,
296 const Standard_Integer theVertex2ID)
298 return edge_id_vertices(theVertex1ID, theVertex2ID);
301 //=======================================================================
302 //function : FindCommonEdgeID
304 //=======================================================================
305 Standard_Integer GEOMImpl_Block6Explorer::FindCommonEdgeID
306 (const Standard_Integer theFace1ID,
307 const Standard_Integer theFace2ID)
309 return edge_id_faces(theFace1ID, theFace2ID);
312 //=======================================================================
315 //=======================================================================
316 TopoDS_Shape GEOMImpl_Block6Explorer::GetFace (const Standard_Integer theFaceID,
317 const Standard_Boolean doMake)
319 TopoDS_Shape aNullShape;
320 if (theFaceID < 1 || theFaceID > NBFACES) return aNullShape;
322 if (myFaces(theFaceID).IsNull() && doMake) {
324 // Create the required face between
325 // corresponding edges and put it in the Block's faces
327 TopoDS_Shape E1 = GetEdge(edge_id(theFaceID, 1), doMake);
328 TopoDS_Shape E2 = GetEdge(edge_id(theFaceID, 2), doMake);
329 TopoDS_Shape E3 = GetEdge(edge_id(theFaceID, 3), doMake);
330 TopoDS_Shape E4 = GetEdge(edge_id(theFaceID, 4), doMake);
332 BRepBuilderAPI_MakeWire MW (TopoDS::Edge(E1),
337 Standard_ConstructionError::Raise("Wire construction failed");
340 MakeFace(MW, Standard_False, aFace);
341 if (aFace.IsNull()) {
342 Standard_ConstructionError::Raise("Face construction failed");
344 myFaces(theFaceID) = aFace;
347 return myFaces(theFaceID);
350 //=======================================================================
351 //function : GetFaceID
353 //=======================================================================
354 Standard_Integer GEOMImpl_Block6Explorer::GetFaceID (const TopoDS_Shape& theFace)
356 for (Standard_Integer id = 1; id <= NBFACES; id++) {
357 if (theFace.IsSame(myFaces(id))) return id;
359 Standard_NoSuchObject::Raise("The Face does not belong to the Block");
363 //=======================================================================
364 //function : FindFaceID
366 //=======================================================================
367 Standard_Integer GEOMImpl_Block6Explorer::FindFaceID (const Standard_Integer theEdge1ID,
368 const Standard_Integer theEdge2ID)
370 return face_id_edges(theEdge1ID, theEdge2ID);
373 //=======================================================================
374 //function : GetOppositeFaceID
376 //=======================================================================
377 Standard_Integer GEOMImpl_Block6Explorer::GetOppositeFaceID (const Standard_Integer theFaceID)
379 Standard_Integer opp_face_id[NBFACES + 1] = {
388 return opp_face_id[theFaceID];
391 //=======================================================================
392 //function : IsSimilarFaces
394 //=======================================================================
395 Standard_Boolean GEOMImpl_Block6Explorer::IsSimilarFaces (const Standard_Integer theFace1ID,
396 const Standard_Integer theFace2ID,
397 const gp_Trsf theTransformation)
399 Standard_Integer common_edge_id = FindCommonEdgeID(theFace1ID, theFace2ID);
401 if (common_edge_id == 0) { // opposite faces
402 for (Standard_Integer id = 1; id <= 4; id++) {
403 TopoDS_Shape E1 = GetEdge(edge_id(theFace1ID, id));
404 TopoDS_Shape E2 = GetEdge(edge_id(theFace2ID, id));
406 BRepBuilderAPI_Transform aTrsf (E1, theTransformation, Standard_False);
407 if (!IsSimilarEdges(aTrsf.Shape(), E2))
408 return Standard_False;
410 } else { // the faces have common edge
411 TopTools_Array1OfShape aVerts1 (1,4);
412 TopTools_Array1OfShape aVerts2 (1,4);
414 Standard_Integer common_vertex1 = GetVertexOnEdgeID(common_edge_id, 1);
415 Standard_Integer common_vertex2 = GetVertexOnEdgeID(common_edge_id, 2);
416 aVerts1(1) = myVertices(common_vertex1);
417 aVerts1(2) = myVertices(common_vertex2);
418 aVerts2(1) = myVertices(common_vertex1);
419 aVerts2(2) = myVertices(common_vertex2);
421 Standard_Integer not_common_v11 = 0, not_common_v12 = 0;
422 Standard_Integer vnb, vid;
423 for (vnb = 1; vnb <= 4; vnb++) {
424 vid = GetVertexID(theFace1ID, vnb);
425 if (vid != common_vertex1 && FindEdgeID(vid, common_vertex1) == 0) {
426 not_common_v12 = vid;
428 if (vid != common_vertex2 && FindEdgeID(vid, common_vertex2) == 0) {
429 not_common_v11 = vid;
434 Standard_Integer not_common_v21 = 0, not_common_v22 = 0;
435 for (vnb = 1; vnb <= 4; vnb++) {
436 vid = GetVertexID(theFace2ID, vnb);
437 if (vid != common_vertex1 && FindEdgeID(vid, common_vertex1) == 0) {
438 not_common_v22 = vid;
440 if (vid != common_vertex2 && FindEdgeID(vid, common_vertex2) == 0) {
441 not_common_v21 = vid;
445 aVerts1(3) = myVertices(not_common_v11);
446 aVerts1(4) = myVertices(not_common_v12);
447 aVerts2(3) = myVertices(not_common_v21);
448 aVerts2(4) = myVertices(not_common_v22);
450 for (Standard_Integer id = 1; id <= 4; id++) {
451 BRepBuilderAPI_Transform aTrsf (aVerts1(id), theTransformation, Standard_False);
452 TopoDS_Vertex V1 = TopoDS::Vertex(aTrsf.Shape());
453 TopoDS_Vertex V2 = TopoDS::Vertex(aVerts2(id));
454 if (!BRepTools::Compare(V1, V2)) {
455 return Standard_False;
460 return Standard_True;
463 //============ Initialization methods ===================================
465 //=======================================================================
466 //function : InitByBlock
468 //=======================================================================
469 void GEOMImpl_Block6Explorer::InitByBlock (const TopoDS_Shape& theBlock)
471 // 1. Find any one face of the block
472 TopExp_Explorer faces (theBlock, TopAbs_FACE);
474 Standard_ConstructionError::Raise("The block has no faces");
476 TopoDS_Shape aFirstFace = faces.Current();
478 // 2. Store all elements of the block relatively aFirstFace
479 InitByBlockAndFace(theBlock, aFirstFace);
482 //=======================================================================
483 //function : InitByBlockAndFace
485 //=======================================================================
486 void GEOMImpl_Block6Explorer::InitByBlockAndFace (const TopoDS_Shape& theBlock,
487 const TopoDS_Shape& theFace)
489 myFaces(1) = theFace;
491 // 2. Get wire of the first face
492 TopExp_Explorer wires (myFaces(1), TopAbs_WIRE);
494 Standard_ConstructionError::Raise("A face of the block has no wires");
496 TopoDS_Shape aWire = wires.Current();
499 Standard_ConstructionError::Raise("A face of the block has more than one wires");
502 // 3. Explore wire to init edges and vertices of the first face
503 BRepTools_WireExplorer aWE (TopoDS::Wire(aWire), TopoDS::Face(myFaces(1)));
504 Standard_Integer nb = 1;
505 for (; aWE.More(); aWE.Next(), nb++) {
507 Standard_ConstructionError::Raise("A face of the block has more than four edges");
509 myEdges(edge_id(1, nb)) = aWE.Current();
510 myVertices(vertex_id(1, nb)) = aWE.CurrentVertex();
513 Standard_ConstructionError::Raise("A face of the block has less than four edges");
516 // 2. Store all other elements of the block
517 InitByBlockAndVertices (theBlock,
518 myVertices(vertex_id(1,1)),
519 myVertices(vertex_id(1,2)),
520 myVertices(vertex_id(1,3)));
523 //=======================================================================
524 //function : InitByBlockAndEdges
526 //=======================================================================
527 void GEOMImpl_Block6Explorer::InitByBlockAndEdges (const TopoDS_Shape& theBlock,
528 const TopoDS_Shape& theEdge1,
529 const TopoDS_Shape& theEdge3)
531 // 1. Store vertices and edges of the first face
533 // 1.1. Store two given edges
534 myEdges(edge_id(1, 1)) = theEdge1;
535 myEdges(edge_id(1, 3)) = theEdge3;
537 // 1.2. Find and store the first face
538 TopTools_IndexedDataMapOfShapeListOfShape MEF;
539 MapShapesAndAncestors(theBlock, TopAbs_EDGE, TopAbs_FACE, MEF);
540 if (MEF.Extent() != NBEDGES) {
541 Standard_TypeMismatch::Raise("Block has wrong number of edges");
543 const TopTools_ListOfShape& aFacesOfE1 = MEF.FindFromKey(theEdge1);
544 const TopTools_ListOfShape& aFacesOfE3 = MEF.FindFromKey(theEdge3);
546 Standard_Boolean isFound = Standard_False;
547 TopTools_ListIteratorOfListOfShape anIterF1 (aFacesOfE1);
548 for (; anIterF1.More() && !isFound; anIterF1.Next()) {
550 TopTools_ListIteratorOfListOfShape anIterF3 (aFacesOfE3);
551 for (; anIterF3.More() && !isFound; anIterF3.Next()) {
553 if (anIterF1.Value().IsSame(anIterF3.Value())) {
554 isFound = Standard_True;
556 // Store the face, defined by two opposite edges
557 myFaces(1) = anIterF1.Value();
562 Standard_ConstructionError::Raise
563 ("Edges 1 and 2 do not belong to one face of the block");
566 // 1.3. Make vertices of the first edge the first and the
567 // second vertices of the first face. Order is free.
568 TopoDS_Edge E = TopoDS::Edge(theEdge1);
569 TopoDS_Vertex V1, V2;
570 TopExp::Vertices(E, V1, V2, Standard_True);
571 myVertices(vertex_id(1,1)) = V1;
572 myVertices(vertex_id(1,2)) = V2;
574 // Init maps vertex->list_of_edges for the face
575 TopTools_IndexedDataMapOfShapeListOfShape M1;
576 MapShapesAndAncestors(myFaces(1), TopAbs_VERTEX, TopAbs_EDGE, M1);
577 if (M1.Extent() != 4) {
578 Standard_TypeMismatch::Raise("The first face of block has wrong number of vertices");
581 // 1.4. Find and store others elements of the first face
583 // edges of the first vertex
584 TopoDS_Shape E1_f = M1.FindFromKey(V1).First();
585 TopoDS_Shape E1_l = M1.FindFromKey(V1).Last();
587 if (E1_f.IsSame(theEdge1)) {
588 myEdges(edge_id(1, 4)) = E1_l;
590 myEdges(edge_id(1, 4)) = E1_f;
594 TopoDS_Edge E4 = TopoDS::Edge(myEdges(edge_id(1, 4)));
595 TopoDS_Vertex V41, V42;
596 TopExp::Vertices(E4, V41, V42, Standard_True);
597 if (V41.IsSame(V1)) {
598 myVertices(vertex_id(1,4)) = V42;
600 myVertices(vertex_id(1,4)) = V41;
603 // edges of the second vertex
604 TopoDS_Shape E2_f = M1.FindFromKey(V2).First();
605 TopoDS_Shape E2_l = M1.FindFromKey(V2).Last();
607 if (E2_f.IsSame(theEdge1)) {
608 myEdges(edge_id(1, 2)) = E2_l;
610 myEdges(edge_id(1, 2)) = E2_f;
614 TopoDS_Edge E2 = TopoDS::Edge(myEdges(edge_id(1, 2)));
615 TopoDS_Vertex V21, V22;
616 TopExp::Vertices(E2, V21, V22, Standard_True);
617 if (V21.IsSame(V2)) {
618 myVertices(vertex_id(1,3)) = V22;
620 myVertices(vertex_id(1,3)) = V21;
623 // 2. Store all other elements of the block
624 InitByBlockAndVertices (theBlock,
625 myVertices(vertex_id(1,1)),
626 myVertices(vertex_id(1,2)),
627 myVertices(vertex_id(1,3)));
630 //=======================================================================
631 //function : InitByBlockAndVertices
633 //=======================================================================
634 void GEOMImpl_Block6Explorer::InitByBlockAndVertices (const TopoDS_Shape& theBlock,
635 const TopoDS_Shape& theVertex1,
636 const TopoDS_Shape& theVertex2,
637 const TopoDS_Shape& theVertex3)
639 // Here we suppose, that vertices are ordered, i.e. exists edge between
640 // theVertex1 and theVertex2 and edge between theVertex2 and theVertex3
642 // 1. Store vertices and edges of the first face.
643 // If the first face is initialized, it means, that this
644 // method is called from another initialization method, and all
645 // vertices and edges of the first face are also initialized
646 if (myFaces(1).IsNull()) {
648 // 1.1. Store first three vertices
649 myVertices(vertex_id(1, 1)) = theVertex1;
650 myVertices(vertex_id(1, 2)) = theVertex2;
651 myVertices(vertex_id(1, 3)) = theVertex3;
653 // 1.2. Find and store the first face
654 TopTools_IndexedDataMapOfShapeListOfShape MVF;
655 MapShapesAndAncestors(theBlock, TopAbs_VERTEX, TopAbs_FACE, MVF);
656 if (MVF.Extent() != NBVERTS) {
657 Standard_TypeMismatch::Raise("Block has wrong number of vertices");
659 const TopTools_ListOfShape& aFacesOfV1 = MVF.FindFromKey(theVertex1);
660 const TopTools_ListOfShape& aFacesOfV3 = MVF.FindFromKey(theVertex3);
662 Standard_Boolean isFound = Standard_False;
663 TopTools_ListIteratorOfListOfShape anIterF1 (aFacesOfV1);
664 for (; anIterF1.More() && !isFound; anIterF1.Next()) {
666 TopTools_ListIteratorOfListOfShape anIterF3 (aFacesOfV3);
667 for (; anIterF3.More() && !isFound; anIterF3.Next()) {
669 if (anIterF1.Value().IsSame(anIterF3.Value())) {
670 isFound = Standard_True;
672 // Store the face, defined by two opposite vertices
673 myFaces(1) = anIterF1.Value();
678 Standard_ConstructionError::Raise
679 ("Vertices 1 and 3 do not belong to one face of the block");
682 // Init maps vertex->list_of_edges for the face
683 TopTools_IndexedDataMapOfShapeListOfShape M1;
684 MapShapesAndAncestors(myFaces(1), TopAbs_VERTEX, TopAbs_EDGE, M1);
685 if (M1.Extent() != 4) {
686 Standard_TypeMismatch::Raise("The first face of block has wrong number of vertices");
689 // 1.3. Find and store edges and last vertex of the first face
690 const TopTools_ListOfShape& anEdgesOfV1 = M1.FindFromKey(theVertex1);
691 const TopTools_ListOfShape& anEdgesOfV2 = M1.FindFromKey(theVertex2);
692 const TopTools_ListOfShape& anEdgesOfV3 = M1.FindFromKey(theVertex3);
694 TopTools_ListIteratorOfListOfShape anIterE2 (anEdgesOfV2);
695 for (; anIterE2.More(); anIterE2.Next()) {
697 TopTools_ListIteratorOfListOfShape anIterE1 (anEdgesOfV1);
698 for (; anIterE1.More(); anIterE1.Next()) {
700 if (anIterE1.Value().IsSame(anIterE2.Value())) {
701 // Store the first edge, defined by two vertices
702 myEdges(edge_id(1,1)) = anIterE1.Value();
705 // Store the last edge
706 myEdges(edge_id(1,4)) = anIterE1.Value();
708 // Find and store the last vertex
709 TopoDS_Edge E = TopoDS::Edge(myEdges(4));
710 TopoDS_Vertex V1, V2;
711 TopExp::Vertices(E, V1, V2, Standard_True);
713 if (V1.IsSame(theVertex1)) {
714 myVertices(vertex_id(1,4)) = V2;
716 myVertices(vertex_id(1,4)) = V1;
721 TopTools_ListIteratorOfListOfShape anIterE3 (anEdgesOfV3);
722 for (; anIterE3.More(); anIterE3.Next()) {
724 if (anIterE3.Value().IsSame(anIterE2.Value())) {
725 // Store the second edge, defined by two vertices
726 myEdges(edge_id(1,2)) = anIterE3.Value();
729 // Store the fird edge
730 myEdges(edge_id(1,3)) = anIterE3.Value();
736 // Init map vertex->list_of_edges for the block
737 TopTools_IndexedDataMapOfShapeListOfShape MB;
738 MapShapesAndAncestors(theBlock, TopAbs_VERTEX, TopAbs_EDGE, MB);
739 if (MB.Extent() != NBVERTS) {
740 Standard_TypeMismatch::Raise("Block has wrong number of vertices");
743 // 2. Store edges, linking the first face with the second one
744 // and vertices of the second face
745 TopTools_IndexedMapOfShape aFaceEdges;
746 TopExp::MapShapes(myFaces(1), TopAbs_EDGE, aFaceEdges);
748 Standard_Integer i = 1;
749 for (; i <= 4; i++) {
750 // Get i-th vertex of the face 1
751 TopoDS_Shape Vi = myVertices(vertex_id(1, i));
752 if (!MB.Contains(Vi)) {
753 Standard_ConstructionError::Raise("Face does not belong to the block");
756 // Get list of block's edges, sharing this Vertex
757 const TopTools_ListOfShape& anEdgesOfVi = MB.FindFromKey(Vi);
758 TopTools_ListIteratorOfListOfShape anEdgesIter (anEdgesOfVi);
760 // Get Edge (from the List), not belonging to the face 1
761 Standard_Boolean isFound = Standard_False;
762 for (; anEdgesIter.More() && !isFound; anEdgesIter.Next()) {
763 if (!aFaceEdges.Contains(anEdgesIter.Value())) {
764 isFound = Standard_True;
766 // Store the linking edge
767 TopoDS_Shape aLinkEdge = anEdgesIter.Value();
768 myEdges(side_edge_id(i)) = aLinkEdge;
770 // Get another vertex of the linking edge
771 TopoDS_Edge E = TopoDS::Edge(aLinkEdge);
772 TopoDS_Vertex V1, V2;
773 TopExp::Vertices(E, V1, V2, Standard_True);
775 // Store the i-th vertex of the second (opposite to the first) face
777 myVertices(vertex_id(2, i)) = V2;
779 myVertices(vertex_id(2, i)) = V1;
785 // 3. Store edges of the second (opposite to the first) face
786 for (i = 1; i <= 4; i++) {
787 // Get i-th and (i+1)-th vertices of the face 2
788 TopoDS_Shape Vi = myVertices(vertex_id(2, i));
789 TopoDS_Shape Vj = myVertices(vertex_id(2, mod4(i + 1)));
791 // Get list of block's edges, sharing Vi
792 const TopTools_ListOfShape& anEdgesOfVi = MB.FindFromKey(Vi);
793 // Get list of block's edges, sharing Vj
794 const TopTools_ListOfShape& anEdgesOfVj = MB.FindFromKey(Vj);
796 // Get Edge (from the List), linking this vertex with the next one
797 Standard_Boolean isFound = Standard_False;
798 TopTools_ListIteratorOfListOfShape anEdgesIteri (anEdgesOfVi);
799 for (; anEdgesIteri.More() && !isFound; anEdgesIteri.Next()) {
801 TopTools_ListIteratorOfListOfShape anEdgesIterj (anEdgesOfVj);
802 for (; anEdgesIterj.More() && !isFound; anEdgesIterj.Next()) {
804 if (anEdgesIteri.Value().IsSame(anEdgesIterj.Value())) {
805 isFound = Standard_True;
807 // Store the linking edge
808 myEdges(edge_id(2, i)) = anEdgesIteri.Value();
814 // 4. Store faces of the block
815 TopTools_IndexedDataMapOfShapeListOfShape MBE;
816 MapShapesAndAncestors(theBlock, TopAbs_EDGE, TopAbs_FACE, MBE);
817 if (MBE.Extent() != NBEDGES) {
818 Standard_TypeMismatch::Raise("Block has wrong number of edges");
821 for (i = 2; i <= NBFACES; i++) {
822 TopoDS_Shape Ei1 = myEdges(edge_id(i, 1));
823 TopoDS_Shape Ei2 = myEdges(edge_id(i, 2));
824 const TopTools_ListOfShape& aFacesOfEi1 = MBE.FindFromKey(Ei1);
825 const TopTools_ListOfShape& aFacesOfEi2 = MBE.FindFromKey(Ei2);
827 Standard_Boolean isFound = Standard_False;
828 TopTools_ListIteratorOfListOfShape anIterEi1 (aFacesOfEi1);
829 for (; anIterEi1.More() && !isFound; anIterEi1.Next()) {
831 TopTools_ListIteratorOfListOfShape anIterEi2 (aFacesOfEi2);
832 for (; anIterEi2.More() && !isFound; anIterEi2.Next()) {
834 if (anIterEi1.Value().IsSame(anIterEi2.Value())) {
835 isFound = Standard_True;
837 // Store the face, defined by two edges
838 myFaces(i) = anIterEi1.Value();
845 //=======================================================================
846 //function : InitByTwoFaces
848 //=======================================================================
849 void GEOMImpl_Block6Explorer::InitByTwoFaces (const TopoDS_Shape& theFace1,
850 const TopoDS_Shape& theFace2)
852 if (theFace1.IsSame(theFace2)) {
853 Standard_ConstructionError::Raise("The faces must be different");
856 // Add two given faces in the structure
857 myFaces(1) = theFace1;
858 myFaces(2) = theFace2;
860 // Step 1. Order vertices (and edges)
862 // 1.1. Ordered vertices and edges of the first face we put in <myVertices>
864 // Get wire of the first face
865 TopExp_Explorer wires1 (myFaces(1), TopAbs_WIRE);
866 if (!wires1.More()) {
867 Standard_ConstructionError::Raise("A face for the block has no wires");
869 TopoDS_Shape aWire1 = wires1.Current();
872 Standard_ConstructionError::Raise("A face for the block has more than one wire");
875 BRepTools_WireExplorer aWE1 (TopoDS::Wire(aWire1), TopoDS::Face(myFaces(1)));
877 for (nb = 1; aWE1.More(); aWE1.Next(), nb++) {
879 Standard_ConstructionError::Raise("A face for the block has more than four edges");
881 myEdges(edge_id(1, nb)) = aWE1.Current();
882 myVertices(vertex_id(1, nb)) = aWE1.CurrentVertex();
885 Standard_ConstructionError::Raise("A face for the block has less than four edges");
888 // 1.2. Ordered vertices and edges of the second face we temporarily store
889 // in arrays, to find for them rigth location in <myVertices> on the Step 2.
892 TopTools_Array1OfShape aVertis2(1,4); // ordered vertices of the second face
893 TopTools_Array1OfShape anEdges2(1,4); // anEdges2(i) links aVertis2(i) and aVertis2(i+1)
895 // Get wire of the second face
896 TopExp_Explorer wires2 (myFaces(2), TopAbs_WIRE);
897 if (!wires2.More()) {
898 Standard_ConstructionError::Raise("A face for the block has no wires");
900 TopoDS_Shape aWire2 = wires2.Current();
903 Standard_ConstructionError::Raise("A face for the block has more than one wire");
906 BRepTools_WireExplorer aWE2 (TopoDS::Wire(aWire2), TopoDS::Face(myFaces(2)));
907 for (nb = 1; aWE2.More(); aWE2.Next(), nb++) {
909 Standard_ConstructionError::Raise("A face for the block has more than four edges");
911 anEdges2(nb) = aWE2.Current();
912 aVertis2(nb) = aWE2.CurrentVertex();
915 Standard_ConstructionError::Raise("A face for the block has less than four edges");
918 // Step 2. Find right place in <myVertices> for the <aVertis2>,
919 // so as to minimize common length of linking edges
920 // between face 1 and face 2.
921 // Each linking edge (of four) will link vertices of the
922 // faces 1 and 2 with equal local numbers.
923 // The right place is defined by:
924 // - vertex <aVertis2(i_min)>, which will become the first vertex
925 // of the second face <myVertices(vertex_id(2,1))>
926 // - orientation of <aVertis2> relatively their future location
927 // in <myVertices> (s_min = 1 if direct, s_min = -1 if reversed)
928 Standard_Integer i_min = 0, s_min = 0;
930 TColgp_Array1OfPnt aPnts1 (1,4); // points of the first face
931 aPnts1(1) = BRep_Tool::Pnt(TopoDS::Vertex(myVertices(vertex_id(1, 1))));
932 aPnts1(2) = BRep_Tool::Pnt(TopoDS::Vertex(myVertices(vertex_id(1, 2))));
933 aPnts1(3) = BRep_Tool::Pnt(TopoDS::Vertex(myVertices(vertex_id(1, 3))));
934 aPnts1(4) = BRep_Tool::Pnt(TopoDS::Vertex(myVertices(vertex_id(1, 4))));
936 TColgp_Array1OfPnt aPnts2 (1,4); // points of the second face
937 aPnts2(1) = BRep_Tool::Pnt(TopoDS::Vertex(aVertis2(1)));
938 aPnts2(2) = BRep_Tool::Pnt(TopoDS::Vertex(aVertis2(2)));
939 aPnts2(3) = BRep_Tool::Pnt(TopoDS::Vertex(aVertis2(3)));
940 aPnts2(4) = BRep_Tool::Pnt(TopoDS::Vertex(aVertis2(4)));
942 Standard_Real Dist_min = RealLast();
943 // try all possible locations to find the best (with minimum sum distance)
944 Standard_Integer i = 1;
945 for (; i <= 4; i++) {
946 // try direct orientation
947 Standard_Real Dist_plus = aPnts1(1).Distance(aPnts2(i)) +
948 aPnts1(2).Distance(aPnts2(mod4(i + 1))) +
949 aPnts1(3).Distance(aPnts2(mod4(i + 2))) +
950 aPnts1(4).Distance(aPnts2(mod4(i + 3)));
951 if (Dist_plus < Dist_min) {
952 Dist_min = Dist_plus;
957 // try reversed orientation
958 Standard_Real Dist_minus = aPnts1(1).Distance(aPnts2(i)) +
959 aPnts1(2).Distance(aPnts2(mod4(i - 1))) +
960 aPnts1(3).Distance(aPnts2(mod4(i - 2))) +
961 aPnts1(4).Distance(aPnts2(mod4(i - 3)));
962 if (Dist_minus < Dist_min) {
963 Dist_min = Dist_minus;
969 // 3. Put vertices and edges of the second face to they
970 // permanent location in <myVertices> and <myEdges>
971 for (i = 1; i <= 4; i++) {
972 Standard_Integer nb = mod4(i_min + s_min*(i - 1));
974 if (aPnts1(i).Distance(aPnts2(nb)) < Precision::Confusion()) {
975 Standard_ConstructionError::Raise("The faces are too close");
978 myVertices(vertex_id(2, i)) = aVertis2(nb);
980 if (s_min == -1) nb = mod4(nb - 1);
981 myEdges(edge_id(2, i)) = anEdges2(nb);
984 // 4. Generate side surface
985 if (!aWire1.Closed() || !aWire2.Closed()) {
986 // BRepOffsetAPI_ThruSections is not applicable on not closed wires
987 GetFace(3, Standard_True);
988 GetFace(4, Standard_True);
989 GetFace(5, Standard_True);
990 GetFace(6, Standard_True);
992 // try to build faces on native surfaces of edges or planar
993 Standard_Boolean tryThru = Standard_False;
994 for (Standard_Integer i = 3; i <= 6 && !tryThru; i++) {
995 Standard_Boolean doMake = Standard_True;
996 TopoDS_Shape E1 = GetEdge(edge_id(i, 1), doMake);
997 TopoDS_Shape E2 = GetEdge(edge_id(i, 2), doMake);
998 TopoDS_Shape E3 = GetEdge(edge_id(i, 3), doMake);
999 TopoDS_Shape E4 = GetEdge(edge_id(i, 4), doMake);
1001 BRepBuilderAPI_MakeWire MW (TopoDS::Edge(E1),
1006 Standard_ConstructionError::Raise("Wire construction failed");
1009 BRepBuilderAPI_MakeFace MF (MW, Standard_False);
1011 myFaces(i) = MF.Shape();
1013 tryThru = Standard_True;
1017 // Build side surface by ThruSections algorithm
1019 BRepOffsetAPI_ThruSections THS;
1020 THS.AddWire(TopoDS::Wire(aWire1));
1021 THS.AddWire(TopoDS::Wire(aWire2));
1023 if (!THS.IsDone()) {
1024 StdFail_NotDone::Raise("Side surface generation failed");
1026 for (Standard_Integer i = 1; i <= 4; i++) {
1028 myFaces(i+2) = THS.GeneratedFace(myEdges(i));
1031 Standard_Integer ee = side_edge_id(i);
1032 TopTools_IndexedDataMapOfShapeListOfShape MVE;
1033 MapShapesAndAncestors(myFaces(i+2), TopAbs_VERTEX, TopAbs_EDGE, MVE);
1034 FindEdge(myEdges(ee),
1035 myVertices(vertex_id_edge(ee, 1)),
1036 myVertices(vertex_id_edge(ee, 2)),
1043 //=======================================================================
1044 //function : MapShapesAndAncestors
1046 //=======================================================================
1047 void GEOMImpl_Block6Explorer::MapShapesAndAncestors (const TopoDS_Shape& S,
1048 const TopAbs_ShapeEnum TS,
1049 const TopAbs_ShapeEnum TA,
1050 TopTools_IndexedDataMapOfShapeListOfShape& M)
1052 TopTools_ListOfShape empty;
1053 TopTools_MapOfShape mapA;
1056 TopExp_Explorer exa (S,TA);
1057 for (; exa.More(); exa.Next()) {
1059 const TopoDS_Shape& anc = exa.Current();
1060 if (mapA.Add(anc)) {
1061 TopExp_Explorer exs (anc,TS);
1062 TopTools_MapOfShape mapS;
1063 for (; exs.More(); exs.Next()) {
1064 if (mapS.Add(exs.Current())) {
1065 Standard_Integer index = M.FindIndex(exs.Current());
1066 if (index == 0) index = M.Add(exs.Current(),empty);
1067 M(index).Append(anc);
1073 // visit shapes not under ancestors
1074 TopExp_Explorer ex (S,TS,TA);
1075 for (; ex.More(); ex.Next()) {
1076 Standard_Integer index = M.FindIndex(ex.Current());
1077 if (index == 0) index = M.Add(ex.Current(),empty);
1081 //=======================================================================
1082 //function : IsSimilarEdges
1084 //=======================================================================
1085 Standard_Boolean GEOMImpl_Block6Explorer::IsSimilarEdges (const TopoDS_Shape& E1,
1086 const TopoDS_Shape& E2)
1088 TopoDS_Edge E1e = TopoDS::Edge(E1);
1089 TopoDS_Edge E2e = TopoDS::Edge(E2);
1090 TopoDS_Vertex V11, V12, V21, V22;
1091 TopExp::Vertices(E1e, V11, V12, Standard_True);
1092 TopExp::Vertices(E2e, V21, V22, Standard_True);
1093 if (BRepTools::Compare(V11, V21) && BRepTools::Compare(V12, V22))
1094 return Standard_True;
1095 if (BRepTools::Compare(V11, V22) && BRepTools::Compare(V12, V21))
1096 return Standard_True;
1098 return Standard_False;
1101 //=======================================================================
1102 //function : FindEdge
1104 //=======================================================================
1105 Standard_Integer GEOMImpl_Block6Explorer::FindEdge
1106 (TopoDS_Shape& theResult,
1107 const TopoDS_Shape& V1,
1108 const TopoDS_Shape& V2,
1109 const TopTools_IndexedDataMapOfShapeListOfShape& MVE,
1110 const Standard_Boolean findAll)
1112 Standard_Integer isFound = 0;
1114 const TopTools_ListOfShape& anEdgesOfV1 = MVE.FindFromKey(V1);
1115 const TopTools_ListOfShape& anEdgesOfV2 = MVE.FindFromKey(V2);
1117 TopTools_ListIteratorOfListOfShape it1 (anEdgesOfV1);
1118 for (; it1.More(); it1.Next()) {
1119 TopTools_ListIteratorOfListOfShape it2 (anEdgesOfV2);
1120 for (; it2.More(); it2.Next()) {
1121 if (it1.Value().IsSame(it2.Value())) {
1123 theResult = it1.Value();
1124 if (!findAll) return isFound;
1132 //=======================================================================
1133 //function : FindFace
1135 //=======================================================================
1136 Standard_Integer GEOMImpl_Block6Explorer::FindFace
1137 (TopoDS_Shape& theResult,
1138 const TopoDS_Shape& V1,
1139 const TopoDS_Shape& V2,
1140 const TopoDS_Shape& V3,
1141 const TopoDS_Shape& V4,
1142 const TopTools_IndexedDataMapOfShapeListOfShape& MVF,
1143 const Standard_Boolean findAll)
1145 Standard_Integer isFound = Standard_False;
1147 const TopTools_ListOfShape& aFacesOfV1 = MVF.FindFromKey(V1);
1148 const TopTools_ListOfShape& aFacesOfV2 = MVF.FindFromKey(V2);
1149 const TopTools_ListOfShape& aFacesOfV3 = MVF.FindFromKey(V3);
1150 const TopTools_ListOfShape& aFacesOfV4 = MVF.FindFromKey(V4);
1152 TopTools_ListIteratorOfListOfShape it1 (aFacesOfV1);
1153 for (; it1.More(); it1.Next()) {
1154 TopTools_ListIteratorOfListOfShape it2 (aFacesOfV2);
1155 for (; it2.More(); it2.Next()) {
1156 if (it1.Value().IsSame(it2.Value())) {
1157 TopTools_ListIteratorOfListOfShape it3 (aFacesOfV3);
1158 for (; it3.More(); it3.Next()) {
1159 if (it1.Value().IsSame(it3.Value())) {
1160 TopTools_ListIteratorOfListOfShape it4 (aFacesOfV4);
1161 for (; it4.More(); it4.Next()) {
1162 if (it1.Value().IsSame(it4.Value())) {
1164 theResult = it1.Value();
1165 if (!findAll) return isFound;
1177 //=======================================================================
1178 //function : MakeFace
1180 //=======================================================================
1181 void GEOMImpl_Block6Explorer::MakeFace (const TopoDS_Wire& theWire,
1182 const Standard_Boolean isPlanarWanted,
1183 TopoDS_Shape& theResult)
1185 // try to build face on plane or on any surface under the edges of the wire
1186 BRepBuilderAPI_MakeFace MK (theWire, isPlanarWanted);
1188 theResult = MK.Shape();
1192 if (!isPlanarWanted) {
1193 // try to construct filling surface
1194 BRepOffsetAPI_MakeFilling MF;
1196 Standard_Integer nbEdges = 0;
1197 BRepTools_WireExplorer aWE (theWire);
1198 for (; aWE.More(); aWE.Next(), nbEdges++) {
1199 MF.Add(TopoDS::Edge(aWE.Current()), GeomAbs_C0);
1204 // Result of filling
1205 TopoDS_Shape aFace = MF.Shape();
1207 // 12.04.2006 for PAL12149 begin
1208 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(aFace));
1209 BRepBuilderAPI_MakeFace MK1 (aGS, theWire);
1211 TopoDS_Shape aFace1 = MK1.Shape();
1213 BRepCheck_Analyzer ana (aFace1, false);
1214 if (!ana.IsValid()) {
1215 TopoDS_Shape aFace2;
1216 ShHealOper_ShapeProcess aHealer;
1217 aHealer.Perform(aFace1, aFace2);
1218 if (aHealer.isDone())
1222 // 12.04.2006 for PAL12149 end
1224 if (theResult.IsNull()) { // try to deal with pure result of filling
1226 Standard_Real aTol = MF.G0Error();
1228 TColgp_Array1OfPnt aPnts (1,nbEdges); // points of the given wire
1229 BRepTools_WireExplorer aWE1 (theWire);
1230 Standard_Integer vi = 1;
1231 for (; aWE1.More() && vi <= nbEdges; aWE1.Next(), vi++) {
1232 aPnts(vi) = BRep_Tool::Pnt(TopoDS::Vertex(aWE1.CurrentVertex()));
1235 // Find maximum deviation in vertices
1236 TopExp_Explorer exp (aFace, TopAbs_VERTEX);
1237 TopTools_MapOfShape mapShape;
1238 for (; exp.More(); exp.Next()) {
1239 if (mapShape.Add(exp.Current())) {
1240 TopoDS_Vertex aV = TopoDS::Vertex(exp.Current());
1241 Standard_Real aTolV = BRep_Tool::Tolerance(aV);
1242 gp_Pnt aP = BRep_Tool::Pnt(aV);
1243 Standard_Real min_dist = aP.Distance(aPnts(1));
1244 for (vi = 2; vi <= nbEdges; vi++) {
1245 min_dist = Min(min_dist, aP.Distance(aPnts(vi)));
1247 aTol = Max(aTol, aTolV);
1248 aTol = Max(aTol, min_dist);
1252 if ((*((Handle(BRep_TFace)*)&aFace.TShape()))->Tolerance() < aTol) {
1253 (*((Handle(BRep_TFace)*)&aFace.TShape()))->Tolerance(aTol);
1259 // try to update wire tolerances to build a planar face
1261 #if 1 //(OCC_VERSION_MAJOR < 6) || (OCC_VERSION_MAJOR == 6 && OCC_VERSION_MINOR <= 1)
1263 Standard_Real aToleranceReached, aTol;
1264 BRepLib_FindSurface aFS;
1265 aFS.Init(theWire, -1., isPlanarWanted);
1266 aToleranceReached = aFS.ToleranceReached();
1267 aTol = aFS.Tolerance();
1270 aFS.Init(theWire, aToleranceReached, isPlanarWanted);
1271 if (!aFS.Found()) return;
1272 aToleranceReached = aFS.ToleranceReached();
1273 aTol = aFS.Tolerance();
1275 aTol = Max(1.2 * aToleranceReached, aTol);
1277 // Copy the wire, bacause it can be updated with very-very big tolerance here
1278 BRepBuilderAPI_Copy aMC (theWire);
1279 if (!aMC.IsDone()) return;
1280 TopoDS_Wire aWire = TopoDS::Wire(aMC.Shape());
1281 // Update tolerances to <aTol>
1283 for (TopExp_Explorer expE (aWire, TopAbs_EDGE); expE.More(); expE.Next()) {
1284 TopoDS_Edge anE = TopoDS::Edge(expE.Current());
1285 B.UpdateEdge(anE, aTol);
1287 for (TopExp_Explorer expV (aWire, TopAbs_VERTEX); expV.More(); expV.Next()) {
1288 TopoDS_Vertex aV = TopoDS::Vertex(expV.Current());
1289 B.UpdateVertex(aV, aTol);
1291 //BRepLib::UpdateTolerances(aWire);
1293 BRepBuilderAPI_MakeFace MK1 (aWire, isPlanarWanted);
1295 theResult = MK1.Shape();
1299 #else // After migration on OCCT version, containing PKV's fix. See bug 8293
1300 BRepLib_MakeFace aBMF;
1301 aBMF.Init(theWire, isPlanarWanted, Standard_True);
1302 if (aBMF.Error() == BRepLib_FaceDone) {
1303 theResult = aBMF.Shape();