1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_Block6Explorer.hxx>
26 #include <ShHealOper_ShapeProcess.hxx>
28 #include "utilities.h"
30 #include <BRep_Tool.hxx>
31 #include <BRep_TFace.hxx>
32 #include <BRep_Builder.hxx>
33 #include <BRepLib.hxx>
34 #include <BRepLib_FindSurface.hxx>
35 #include <BRepTools.hxx>
36 #include <BRepTools_WireExplorer.hxx>
37 #include <BRepOffsetAPI_ThruSections.hxx>
38 #include <BRepOffsetAPI_MakeFilling.hxx>
39 #include <BRepCheck_Analyzer.hxx>
40 #include <BRepBuilderAPI_Copy.hxx>
41 #include <BRepBuilderAPI_MakeEdge.hxx>
42 #include <BRepBuilderAPI_MakeWire.hxx>
43 #include <BRepBuilderAPI_MakeFace.hxx>
44 #include <BRepBuilderAPI_Transform.hxx>
48 #include <TopoDS_Shape.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_Wire.hxx>
51 #include <TopoDS_Solid.hxx>
53 #include <TopExp_Explorer.hxx>
54 #include <TopTools_MapOfShape.hxx>
55 #include <TopTools_ListOfShape.hxx>
56 #include <TopTools_ListIteratorOfListOfShape.hxx>
57 #include <TopTools_IndexedMapOfShape.hxx>
58 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
60 #include <Geom_Curve.hxx>
61 #include <Geom_TrimmedCurve.hxx>
62 #include <GeomFill_Generator.hxx>
64 #include <Precision.hxx>
66 #include <TColgp_Array1OfPnt.hxx>
68 #include <StdFail_NotDone.hxx>
69 #include <Standard_NullObject.hxx>
70 #include <Standard_TypeMismatch.hxx>
71 #include <Standard_ConstructionError.hxx>
72 #include <Standard_NoSuchObject.hxx>
78 static Standard_Integer mod4 (Standard_Integer nb)
80 if (nb <= 0) return nb + 4;
81 if (nb > 4) return nb - 4;
85 static Standard_Integer edge_id (const Standard_Integer theFaceID,
86 const Standard_Integer theEdgeNB)
88 static Standard_Integer edge_ids[NBFACES][4] = {
89 { 1, 2, 3, 4 }, // face 1
90 { 5, 6, 7, 8 }, // face 2
91 { 9, 5, 10, 1 }, // face 3
92 { 12, 7, 11, 3 }, // face 4
93 { 4, 12, 8, 9 }, // face 5
94 { 2, 11, 6, 10 } }; // face 6
96 return edge_ids[theFaceID - 1][theEdgeNB - 1];
99 static Standard_Integer side_edge_id (const Standard_Integer theEdgeNB)
101 static Standard_Integer side_edge_ids[4] = {9, 10, 11, 12};
103 return side_edge_ids[theEdgeNB - 1];
106 static Standard_Integer vertex_id (const Standard_Integer theFaceID,
107 const Standard_Integer theVertexNB)
109 static Standard_Integer vertex_ids[NBFACES][4] = {
110 { 1, 2, 3, 4 }, // face 1
111 { 5, 6, 7, 8 }, // face 2
112 { 1, 5, 6, 2 }, // face 3
113 { 4, 8, 7, 3 }, // face 4
114 { 1, 4, 8, 5 }, // face 5
115 { 2, 3, 7, 6 } }; // face 6
117 return vertex_ids[theFaceID - 1][theVertexNB - 1];
120 static Standard_Integer vertex_id_edge (const Standard_Integer theEdgeID, // [1,12]
121 const Standard_Integer theVertexNB) // [1,2]
123 static Standard_Integer vertex_ids_edge[NBEDGES][2] = {
137 return vertex_ids_edge[theEdgeID - 1][theVertexNB - 1];
140 static Standard_Integer face_id_edges (const Standard_Integer theEdge1ID, // [1,12]
141 const Standard_Integer theEdge2ID) // [1,12]
143 static Standard_Integer face_ids_edges[NBEDGES][NBEDGES] = {
144 // 1 2 3 4 5 6 7 8 9 10 11 12
145 { 0, 1, 1, 1, 3, 0, 0, 0, 3, 3, 0, 0 }, // edge 1
146 { 1, 0, 1, 1, 0, 6, 0, 0, 0, 6, 6, 0 }, // edge 2
147 { 1, 1, 0, 1, 0, 0, 4, 0, 0, 0, 4, 4 }, // edge 3
148 { 1, 1, 1, 0, 0, 0, 0, 5, 5, 0, 0, 5 }, // edge 4
149 { 3, 0, 0, 0, 0, 2, 2, 2, 3, 3, 0, 0 }, // edge 5
150 { 0, 6, 0, 0, 2, 0, 2, 2, 0, 6, 6, 0 }, // edge 6
151 { 0, 0, 4, 0, 2, 2, 0, 2, 0, 0, 4, 4 }, // edge 7
152 { 0, 0, 0, 5, 2, 2, 2, 0, 5, 0, 0, 5 }, // edge 8
153 { 3, 0, 0, 5, 3, 0, 0, 5, 0, 3, 0, 5 }, // edge 9
154 { 3, 6, 0, 0, 3, 6, 0, 0, 3, 0, 6, 0 }, // edge 10
155 { 0, 6, 4, 0, 0, 6, 4, 0, 0, 6, 0, 4 }, // edge 11
156 { 0, 0, 4, 5, 0, 0, 4, 5, 5, 0, 4, 0 } }; // edge 12
158 return face_ids_edges[theEdge1ID - 1][theEdge2ID - 1];
161 static Standard_Integer edge_id_vertices (const Standard_Integer theVertex1ID, // [1,8]
162 const Standard_Integer theVertex2ID) // [1,8]
164 static Standard_Integer edge_ids_vertices[NBVERTS][NBVERTS] = {
166 { 0, 1, 0, 4, 9, 0, 0, 0}, // vertex 1
167 { 1, 0, 2, 0, 0, 10, 0, 0}, // vertex 2
168 { 0, 2, 0, 3, 0, 0, 11, 0}, // vertex 3
169 { 4, 0, 3, 0, 0, 0, 0, 12}, // vertex 4
170 { 9, 0, 0, 0, 0, 5, 0, 8}, // vertex 5
171 { 0, 10, 0, 0, 5, 0, 6, 0}, // vertex 6
172 { 0, 0, 11, 0, 0, 6, 0, 7}, // vertex 7
173 { 0, 0, 0, 12, 8, 0, 7, 0} }; // vertex 8
175 return edge_ids_vertices[theVertex1ID - 1][theVertex2ID - 1];
178 static Standard_Integer edge_id_faces (const Standard_Integer theFace1ID, // [1,6]
179 const Standard_Integer theFace2ID) // [1,6]
181 static Standard_Integer edge_ids_faces[NBFACES][NBFACES] = {
183 { 0, 0, 1, 3, 4, 2 }, // face 1
184 { 0, 0, 5, 7, 8, 6 }, // face 2
185 { 1, 5, 0, 0, 9, 10 }, // face 3
186 { 3, 7, 0, 0, 12, 11 }, // face 4
187 { 4, 8, 9, 12, 0, 0 }, // face 5
188 { 2, 6, 10, 11, 0, 0 } }; // face 6
190 return edge_ids_faces[theFace1ID - 1][theFace2ID - 1];
193 //=======================================================================
194 //function : GEOMImpl_Block6Explorer
195 //purpose : Constructor
196 //=======================================================================
197 GEOMImpl_Block6Explorer::GEOMImpl_Block6Explorer ()
198 : myFaces(1,NBFACES), myEdges(1,NBEDGES), myVertices(1,NBVERTS)
202 //=======================================================================
203 //function : GetVertex
205 //=======================================================================
206 TopoDS_Shape GEOMImpl_Block6Explorer::GetVertex (const Standard_Integer theVertexID)
208 TopoDS_Shape aNullShape;
209 if (theVertexID < 1 || theVertexID > NBVERTS) return aNullShape;
210 return myVertices(theVertexID);
213 //=======================================================================
214 //function : GetVertexID
216 //=======================================================================
217 Standard_Integer GEOMImpl_Block6Explorer::GetVertexID (const TopoDS_Shape& theVertex)
219 for (Standard_Integer id = 1; id <= NBVERTS; id++) {
220 if (theVertex.IsSame(myVertices(id))) return id;
222 Standard_NoSuchObject::Raise("The Vertex does not belong to the Block");
226 //=======================================================================
227 //function : GetVertexID
229 //=======================================================================
230 Standard_Integer GEOMImpl_Block6Explorer::GetVertexID (const Standard_Integer theFaceID,
231 const Standard_Integer theVertexNB)
233 return vertex_id(theFaceID, theVertexNB);
236 //=======================================================================
237 //function : GetVertexOnEdgeID
239 //=======================================================================
240 Standard_Integer GEOMImpl_Block6Explorer::GetVertexOnEdgeID
241 (const Standard_Integer theEdgeID,
242 const Standard_Integer theVertexNB)
244 return vertex_id_edge(theEdgeID, theVertexNB);
247 //=======================================================================
250 //=======================================================================
251 TopoDS_Shape GEOMImpl_Block6Explorer::GetEdge (const Standard_Integer theEdgeID,
252 const Standard_Boolean doMake)
254 TopoDS_Shape aNullShape;
255 if (theEdgeID < 1 || theEdgeID > NBEDGES) return aNullShape;
256 if (myEdges(theEdgeID).IsNull() && doMake) {
257 // Create the required edge as a linear segment between
258 // corresponding vertices and put it in the Block's edges
259 BRepBuilderAPI_MakeEdge ME (TopoDS::Vertex(myVertices(vertex_id_edge(theEdgeID, 1))),
260 TopoDS::Vertex(myVertices(vertex_id_edge(theEdgeID, 2))));
262 Standard_ConstructionError::Raise("Edge construction failed");
264 myEdges(theEdgeID) = ME.Shape();
267 return myEdges(theEdgeID);
270 //=======================================================================
271 //function : GetEdgeID
273 //=======================================================================
274 Standard_Integer GEOMImpl_Block6Explorer::GetEdgeID (const TopoDS_Shape& theEdge)
276 for (Standard_Integer id = 1; id <= NBEDGES; id++) {
277 if (theEdge.IsSame(myEdges(id))) return id;
279 Standard_NoSuchObject::Raise("The Edge does not belong to the Block");
283 //=======================================================================
284 //function : GetEdgeID
286 //=======================================================================
287 Standard_Integer GEOMImpl_Block6Explorer::GetEdgeID (const Standard_Integer theFaceID,
288 const Standard_Integer theEdgeNB)
290 return edge_id(theFaceID, theEdgeNB);
293 //=======================================================================
294 //function : FindEdgeID
296 //=======================================================================
297 Standard_Integer GEOMImpl_Block6Explorer::FindEdgeID (const Standard_Integer theVertex1ID,
298 const Standard_Integer theVertex2ID)
300 return edge_id_vertices(theVertex1ID, theVertex2ID);
303 //=======================================================================
304 //function : FindCommonEdgeID
306 //=======================================================================
307 Standard_Integer GEOMImpl_Block6Explorer::FindCommonEdgeID
308 (const Standard_Integer theFace1ID,
309 const Standard_Integer theFace2ID)
311 return edge_id_faces(theFace1ID, theFace2ID);
314 //=======================================================================
317 //=======================================================================
318 TopoDS_Shape GEOMImpl_Block6Explorer::GetFace (const Standard_Integer theFaceID,
319 const Standard_Boolean doMake)
321 TopoDS_Shape aNullShape;
322 if (theFaceID < 1 || theFaceID > NBFACES) return aNullShape;
324 if (myFaces(theFaceID).IsNull() && doMake) {
326 // Create the required face between
327 // corresponding edges and put it in the Block's faces
329 TopoDS_Shape E1 = GetEdge(edge_id(theFaceID, 1), doMake);
330 TopoDS_Shape E2 = GetEdge(edge_id(theFaceID, 2), doMake);
331 TopoDS_Shape E3 = GetEdge(edge_id(theFaceID, 3), doMake);
332 TopoDS_Shape E4 = GetEdge(edge_id(theFaceID, 4), doMake);
334 BRepBuilderAPI_MakeWire MW (TopoDS::Edge(E1),
339 Standard_ConstructionError::Raise("Wire construction failed");
342 MakeFace(MW, Standard_False, aFace);
343 if (aFace.IsNull()) {
344 Standard_ConstructionError::Raise("Face construction failed");
346 myFaces(theFaceID) = aFace;
349 return myFaces(theFaceID);
352 //=======================================================================
353 //function : GetFaceID
355 //=======================================================================
356 Standard_Integer GEOMImpl_Block6Explorer::GetFaceID (const TopoDS_Shape& theFace)
358 for (Standard_Integer id = 1; id <= NBFACES; id++) {
359 if (theFace.IsSame(myFaces(id))) return id;
361 Standard_NoSuchObject::Raise("The Face does not belong to the Block");
365 //=======================================================================
366 //function : FindFaceID
368 //=======================================================================
369 Standard_Integer GEOMImpl_Block6Explorer::FindFaceID (const Standard_Integer theEdge1ID,
370 const Standard_Integer theEdge2ID)
372 return face_id_edges(theEdge1ID, theEdge2ID);
375 //=======================================================================
376 //function : GetOppositeFaceID
378 //=======================================================================
379 Standard_Integer GEOMImpl_Block6Explorer::GetOppositeFaceID (const Standard_Integer theFaceID)
381 Standard_Integer opp_face_id[NBFACES + 1] = {
390 return opp_face_id[theFaceID];
393 //=======================================================================
394 //function : IsSimilarFaces
396 //=======================================================================
397 Standard_Boolean GEOMImpl_Block6Explorer::IsSimilarFaces (const Standard_Integer theFace1ID,
398 const Standard_Integer theFace2ID,
399 const gp_Trsf theTransformation)
401 Standard_Integer common_edge_id = FindCommonEdgeID(theFace1ID, theFace2ID);
403 if (common_edge_id == 0) { // opposite faces
404 for (Standard_Integer id = 1; id <= 4; id++) {
405 TopoDS_Shape E1 = GetEdge(edge_id(theFace1ID, id));
406 TopoDS_Shape E2 = GetEdge(edge_id(theFace2ID, id));
408 BRepBuilderAPI_Transform aTrsf (E1, theTransformation, Standard_False);
409 if (!IsSimilarEdges(aTrsf.Shape(), E2))
410 return Standard_False;
412 } else { // the faces have common edge
413 TopTools_Array1OfShape aVerts1 (1,4);
414 TopTools_Array1OfShape aVerts2 (1,4);
416 Standard_Integer common_vertex1 = GetVertexOnEdgeID(common_edge_id, 1);
417 Standard_Integer common_vertex2 = GetVertexOnEdgeID(common_edge_id, 2);
418 aVerts1(1) = myVertices(common_vertex1);
419 aVerts1(2) = myVertices(common_vertex2);
420 aVerts2(1) = myVertices(common_vertex1);
421 aVerts2(2) = myVertices(common_vertex2);
423 Standard_Integer not_common_v11 = 0, not_common_v12 = 0;
424 Standard_Integer vnb, vid;
425 for (vnb = 1; vnb <= 4; vnb++) {
426 vid = GetVertexID(theFace1ID, vnb);
427 if (vid != common_vertex1 && FindEdgeID(vid, common_vertex1) == 0) {
428 not_common_v12 = vid;
430 if (vid != common_vertex2 && FindEdgeID(vid, common_vertex2) == 0) {
431 not_common_v11 = vid;
436 Standard_Integer not_common_v21 = 0, not_common_v22 = 0;
437 for (vnb = 1; vnb <= 4; vnb++) {
438 vid = GetVertexID(theFace2ID, vnb);
439 if (vid != common_vertex1 && FindEdgeID(vid, common_vertex1) == 0) {
440 not_common_v22 = vid;
442 if (vid != common_vertex2 && FindEdgeID(vid, common_vertex2) == 0) {
443 not_common_v21 = vid;
447 aVerts1(3) = myVertices(not_common_v11);
448 aVerts1(4) = myVertices(not_common_v12);
449 aVerts2(3) = myVertices(not_common_v21);
450 aVerts2(4) = myVertices(not_common_v22);
452 for (Standard_Integer id = 1; id <= 4; id++) {
453 BRepBuilderAPI_Transform aTrsf (aVerts1(id), theTransformation, Standard_False);
454 TopoDS_Vertex V1 = TopoDS::Vertex(aTrsf.Shape());
455 TopoDS_Vertex V2 = TopoDS::Vertex(aVerts2(id));
456 if (!BRepTools::Compare(V1, V2)) {
457 return Standard_False;
462 return Standard_True;
465 //============ Initialization methods ===================================
467 //=======================================================================
468 //function : InitByBlock
470 //=======================================================================
471 void GEOMImpl_Block6Explorer::InitByBlock (const TopoDS_Shape& theBlock)
473 // 1. Find any one face of the block
474 TopExp_Explorer faces (theBlock, TopAbs_FACE);
476 Standard_ConstructionError::Raise("The block has no faces");
478 TopoDS_Shape aFirstFace = faces.Current();
480 // 2. Store all elements of the block relatively aFirstFace
481 InitByBlockAndFace(theBlock, aFirstFace);
484 //=======================================================================
485 //function : InitByBlockAndFace
487 //=======================================================================
488 void GEOMImpl_Block6Explorer::InitByBlockAndFace (const TopoDS_Shape& theBlock,
489 const TopoDS_Shape& theFace)
491 myFaces(1) = theFace;
493 // 2. Get wire of the first face
494 TopExp_Explorer wires (myFaces(1), TopAbs_WIRE);
496 Standard_ConstructionError::Raise("A face of the block has no wires");
498 TopoDS_Shape aWire = wires.Current();
501 Standard_ConstructionError::Raise("A face of the block has more than one wires");
504 // 3. Explore wire to init edges and vertices of the first face
505 BRepTools_WireExplorer aWE (TopoDS::Wire(aWire), TopoDS::Face(myFaces(1)));
506 Standard_Integer nb = 1;
507 for (; aWE.More(); aWE.Next(), nb++) {
509 Standard_ConstructionError::Raise("A face of the block has more than four edges");
511 myEdges(edge_id(1, nb)) = aWE.Current();
512 myVertices(vertex_id(1, nb)) = aWE.CurrentVertex();
515 Standard_ConstructionError::Raise("A face of the block has less than four edges");
518 // 2. Store all other elements of the block
519 InitByBlockAndVertices (theBlock,
520 myVertices(vertex_id(1,1)),
521 myVertices(vertex_id(1,2)),
522 myVertices(vertex_id(1,3)));
525 //=======================================================================
526 //function : InitByBlockAndEdges
528 //=======================================================================
529 void GEOMImpl_Block6Explorer::InitByBlockAndEdges (const TopoDS_Shape& theBlock,
530 const TopoDS_Shape& theEdge1,
531 const TopoDS_Shape& theEdge3)
533 // 1. Store vertices and edges of the first face
535 // 1.1. Store two given edges
536 myEdges(edge_id(1, 1)) = theEdge1;
537 myEdges(edge_id(1, 3)) = theEdge3;
539 // 1.2. Find and store the first face
540 TopTools_IndexedDataMapOfShapeListOfShape MEF;
541 MapShapesAndAncestors(theBlock, TopAbs_EDGE, TopAbs_FACE, MEF);
542 if (MEF.Extent() != NBEDGES) {
543 Standard_TypeMismatch::Raise("Block has wrong number of edges");
545 const TopTools_ListOfShape& aFacesOfE1 = MEF.FindFromKey(theEdge1);
546 const TopTools_ListOfShape& aFacesOfE3 = MEF.FindFromKey(theEdge3);
548 Standard_Boolean isFound = Standard_False;
549 TopTools_ListIteratorOfListOfShape anIterF1 (aFacesOfE1);
550 for (; anIterF1.More() && !isFound; anIterF1.Next()) {
552 TopTools_ListIteratorOfListOfShape anIterF3 (aFacesOfE3);
553 for (; anIterF3.More() && !isFound; anIterF3.Next()) {
555 if (anIterF1.Value().IsSame(anIterF3.Value())) {
556 isFound = Standard_True;
558 // Store the face, defined by two opposite edges
559 myFaces(1) = anIterF1.Value();
564 Standard_ConstructionError::Raise
565 ("Edges 1 and 2 do not belong to one face of the block");
568 // 1.3. Make vertices of the first edge the first and the
569 // second vertices of the first face. Order is free.
570 TopoDS_Edge E = TopoDS::Edge(theEdge1);
571 TopoDS_Vertex V1, V2;
572 TopExp::Vertices(E, V1, V2, Standard_True);
573 myVertices(vertex_id(1,1)) = V1;
574 myVertices(vertex_id(1,2)) = V2;
576 // Init maps vertex->list_of_edges for the face
577 TopTools_IndexedDataMapOfShapeListOfShape M1;
578 MapShapesAndAncestors(myFaces(1), TopAbs_VERTEX, TopAbs_EDGE, M1);
579 if (M1.Extent() != 4) {
580 Standard_TypeMismatch::Raise("The first face of block has wrong number of vertices");
583 // 1.4. Find and store others elements of the first face
585 // edges of the first vertex
586 TopoDS_Shape E1_f = M1.FindFromKey(V1).First();
587 TopoDS_Shape E1_l = M1.FindFromKey(V1).Last();
589 if (E1_f.IsSame(theEdge1)) {
590 myEdges(edge_id(1, 4)) = E1_l;
592 myEdges(edge_id(1, 4)) = E1_f;
596 TopoDS_Edge E4 = TopoDS::Edge(myEdges(edge_id(1, 4)));
597 TopoDS_Vertex V41, V42;
598 TopExp::Vertices(E4, V41, V42, Standard_True);
599 if (V41.IsSame(V1)) {
600 myVertices(vertex_id(1,4)) = V42;
602 myVertices(vertex_id(1,4)) = V41;
605 // edges of the second vertex
606 TopoDS_Shape E2_f = M1.FindFromKey(V2).First();
607 TopoDS_Shape E2_l = M1.FindFromKey(V2).Last();
609 if (E2_f.IsSame(theEdge1)) {
610 myEdges(edge_id(1, 2)) = E2_l;
612 myEdges(edge_id(1, 2)) = E2_f;
616 TopoDS_Edge E2 = TopoDS::Edge(myEdges(edge_id(1, 2)));
617 TopoDS_Vertex V21, V22;
618 TopExp::Vertices(E2, V21, V22, Standard_True);
619 if (V21.IsSame(V2)) {
620 myVertices(vertex_id(1,3)) = V22;
622 myVertices(vertex_id(1,3)) = V21;
625 // 2. Store all other elements of the block
626 InitByBlockAndVertices (theBlock,
627 myVertices(vertex_id(1,1)),
628 myVertices(vertex_id(1,2)),
629 myVertices(vertex_id(1,3)));
632 //=======================================================================
633 //function : InitByBlockAndVertices
635 //=======================================================================
636 void GEOMImpl_Block6Explorer::InitByBlockAndVertices (const TopoDS_Shape& theBlock,
637 const TopoDS_Shape& theVertex1,
638 const TopoDS_Shape& theVertex2,
639 const TopoDS_Shape& theVertex3)
641 // Here we suppose, that vertices are ordered, i.e. exists edge between
642 // theVertex1 and theVertex2 and edge between theVertex2 and theVertex3
644 // 1. Store vertices and edges of the first face.
645 // If the first face is initialized, it means, that this
646 // method is called from another initialization method, and all
647 // vertices and edges of the first face are also initialized
648 if (myFaces(1).IsNull()) {
650 // 1.1. Store first three vertices
651 myVertices(vertex_id(1, 1)) = theVertex1;
652 myVertices(vertex_id(1, 2)) = theVertex2;
653 myVertices(vertex_id(1, 3)) = theVertex3;
655 // 1.2. Find and store the first face
656 TopTools_IndexedDataMapOfShapeListOfShape MVF;
657 MapShapesAndAncestors(theBlock, TopAbs_VERTEX, TopAbs_FACE, MVF);
658 if (MVF.Extent() != NBVERTS) {
659 Standard_TypeMismatch::Raise("Block has wrong number of vertices");
661 const TopTools_ListOfShape& aFacesOfV1 = MVF.FindFromKey(theVertex1);
662 const TopTools_ListOfShape& aFacesOfV3 = MVF.FindFromKey(theVertex3);
664 Standard_Boolean isFound = Standard_False;
665 TopTools_ListIteratorOfListOfShape anIterF1 (aFacesOfV1);
666 for (; anIterF1.More() && !isFound; anIterF1.Next()) {
668 TopTools_ListIteratorOfListOfShape anIterF3 (aFacesOfV3);
669 for (; anIterF3.More() && !isFound; anIterF3.Next()) {
671 if (anIterF1.Value().IsSame(anIterF3.Value())) {
672 isFound = Standard_True;
674 // Store the face, defined by two opposite vertices
675 myFaces(1) = anIterF1.Value();
680 Standard_ConstructionError::Raise
681 ("Vertices 1 and 3 do not belong to one face of the block");
684 // Init maps vertex->list_of_edges for the face
685 TopTools_IndexedDataMapOfShapeListOfShape M1;
686 MapShapesAndAncestors(myFaces(1), TopAbs_VERTEX, TopAbs_EDGE, M1);
687 if (M1.Extent() != 4) {
688 Standard_TypeMismatch::Raise("The first face of block has wrong number of vertices");
691 // 1.3. Find and store edges and last vertex of the first face
692 const TopTools_ListOfShape& anEdgesOfV1 = M1.FindFromKey(theVertex1);
693 const TopTools_ListOfShape& anEdgesOfV2 = M1.FindFromKey(theVertex2);
694 const TopTools_ListOfShape& anEdgesOfV3 = M1.FindFromKey(theVertex3);
696 TopTools_ListIteratorOfListOfShape anIterE2 (anEdgesOfV2);
697 for (; anIterE2.More(); anIterE2.Next()) {
699 TopTools_ListIteratorOfListOfShape anIterE1 (anEdgesOfV1);
700 for (; anIterE1.More(); anIterE1.Next()) {
702 if (anIterE1.Value().IsSame(anIterE2.Value())) {
703 // Store the first edge, defined by two vertices
704 myEdges(edge_id(1,1)) = anIterE1.Value();
707 // Store the last edge
708 myEdges(edge_id(1,4)) = anIterE1.Value();
710 // Find and store the last vertex
711 TopoDS_Edge E = TopoDS::Edge(myEdges(4));
712 TopoDS_Vertex V1, V2;
713 TopExp::Vertices(E, V1, V2, Standard_True);
715 if (V1.IsSame(theVertex1)) {
716 myVertices(vertex_id(1,4)) = V2;
718 myVertices(vertex_id(1,4)) = V1;
723 TopTools_ListIteratorOfListOfShape anIterE3 (anEdgesOfV3);
724 for (; anIterE3.More(); anIterE3.Next()) {
726 if (anIterE3.Value().IsSame(anIterE2.Value())) {
727 // Store the second edge, defined by two vertices
728 myEdges(edge_id(1,2)) = anIterE3.Value();
731 // Store the fird edge
732 myEdges(edge_id(1,3)) = anIterE3.Value();
738 // Init map vertex->list_of_edges for the block
739 TopTools_IndexedDataMapOfShapeListOfShape MB;
740 MapShapesAndAncestors(theBlock, TopAbs_VERTEX, TopAbs_EDGE, MB);
741 if (MB.Extent() != NBVERTS) {
742 Standard_TypeMismatch::Raise("Block has wrong number of vertices");
745 // 2. Store edges, linking the first face with the second one
746 // and vertices of the second face
747 TopTools_IndexedMapOfShape aFaceEdges;
748 TopExp::MapShapes(myFaces(1), TopAbs_EDGE, aFaceEdges);
750 Standard_Integer i = 1;
751 for (; i <= 4; i++) {
752 // Get i-th vertex of the face 1
753 TopoDS_Shape Vi = myVertices(vertex_id(1, i));
754 if (!MB.Contains(Vi)) {
755 Standard_ConstructionError::Raise("Face does not belong to the block");
758 // Get list of block's edges, sharing this Vertex
759 const TopTools_ListOfShape& anEdgesOfVi = MB.FindFromKey(Vi);
760 TopTools_ListIteratorOfListOfShape anEdgesIter (anEdgesOfVi);
762 // Get Edge (from the List), not belonging to the face 1
763 Standard_Boolean isFound = Standard_False;
764 for (; anEdgesIter.More() && !isFound; anEdgesIter.Next()) {
765 if (!aFaceEdges.Contains(anEdgesIter.Value())) {
766 isFound = Standard_True;
768 // Store the linking edge
769 TopoDS_Shape aLinkEdge = anEdgesIter.Value();
770 myEdges(side_edge_id(i)) = aLinkEdge;
772 // Get another vertex of the linking edge
773 TopoDS_Edge E = TopoDS::Edge(aLinkEdge);
774 TopoDS_Vertex V1, V2;
775 TopExp::Vertices(E, V1, V2, Standard_True);
777 // Store the i-th vertex of the second (opposite to the first) face
779 myVertices(vertex_id(2, i)) = V2;
781 myVertices(vertex_id(2, i)) = V1;
787 // 3. Store edges of the second (opposite to the first) face
788 for (i = 1; i <= 4; i++) {
789 // Get i-th and (i+1)-th vertices of the face 2
790 TopoDS_Shape Vi = myVertices(vertex_id(2, i));
791 TopoDS_Shape Vj = myVertices(vertex_id(2, mod4(i + 1)));
793 // Get list of block's edges, sharing Vi
794 const TopTools_ListOfShape& anEdgesOfVi = MB.FindFromKey(Vi);
795 // Get list of block's edges, sharing Vj
796 const TopTools_ListOfShape& anEdgesOfVj = MB.FindFromKey(Vj);
798 // Get Edge (from the List), linking this vertex with the next one
799 Standard_Boolean isFound = Standard_False;
800 TopTools_ListIteratorOfListOfShape anEdgesIteri (anEdgesOfVi);
801 for (; anEdgesIteri.More() && !isFound; anEdgesIteri.Next()) {
803 TopTools_ListIteratorOfListOfShape anEdgesIterj (anEdgesOfVj);
804 for (; anEdgesIterj.More() && !isFound; anEdgesIterj.Next()) {
806 if (anEdgesIteri.Value().IsSame(anEdgesIterj.Value())) {
807 isFound = Standard_True;
809 // Store the linking edge
810 myEdges(edge_id(2, i)) = anEdgesIteri.Value();
816 // 4. Store faces of the block
817 TopTools_IndexedDataMapOfShapeListOfShape MBE;
818 MapShapesAndAncestors(theBlock, TopAbs_EDGE, TopAbs_FACE, MBE);
819 if (MBE.Extent() != NBEDGES) {
820 Standard_TypeMismatch::Raise("Block has wrong number of edges");
823 for (i = 2; i <= NBFACES; i++) {
824 TopoDS_Shape Ei1 = myEdges(edge_id(i, 1));
825 TopoDS_Shape Ei2 = myEdges(edge_id(i, 2));
826 const TopTools_ListOfShape& aFacesOfEi1 = MBE.FindFromKey(Ei1);
827 const TopTools_ListOfShape& aFacesOfEi2 = MBE.FindFromKey(Ei2);
829 Standard_Boolean isFound = Standard_False;
830 TopTools_ListIteratorOfListOfShape anIterEi1 (aFacesOfEi1);
831 for (; anIterEi1.More() && !isFound; anIterEi1.Next()) {
833 TopTools_ListIteratorOfListOfShape anIterEi2 (aFacesOfEi2);
834 for (; anIterEi2.More() && !isFound; anIterEi2.Next()) {
836 if (anIterEi1.Value().IsSame(anIterEi2.Value())) {
837 isFound = Standard_True;
839 // Store the face, defined by two edges
840 myFaces(i) = anIterEi1.Value();
847 //=======================================================================
848 //function : InitByTwoFaces
850 //=======================================================================
851 void GEOMImpl_Block6Explorer::InitByTwoFaces (const TopoDS_Shape& theFace1,
852 const TopoDS_Shape& theFace2)
854 if (theFace1.IsSame(theFace2)) {
855 Standard_ConstructionError::Raise("The faces must be different");
858 // Add two given faces in the structure
859 myFaces(1) = theFace1;
860 myFaces(2) = theFace2;
862 // Step 1. Order vertices (and edges)
864 // 1.1. Ordered vertices and edges of the first face we put in <myVertices>
866 // Get wire of the first face
867 TopExp_Explorer wires1 (myFaces(1), TopAbs_WIRE);
868 if (!wires1.More()) {
869 Standard_ConstructionError::Raise("A face for the block has no wires");
871 TopoDS_Shape aWire1 = wires1.Current();
874 Standard_ConstructionError::Raise("A face for the block has more than one wire");
877 BRepTools_WireExplorer aWE1 (TopoDS::Wire(aWire1), TopoDS::Face(myFaces(1)));
879 for (nb = 1; aWE1.More(); aWE1.Next(), nb++) {
881 Standard_ConstructionError::Raise("A face for the block has more than four edges");
883 myEdges(edge_id(1, nb)) = aWE1.Current();
884 myVertices(vertex_id(1, nb)) = aWE1.CurrentVertex();
887 Standard_ConstructionError::Raise("A face for the block has less than four edges");
890 // 1.2. Ordered vertices and edges of the second face we temporarily store
891 // in arrays, to find for them rigth location in <myVertices> on the Step 2.
894 TopTools_Array1OfShape aVertis2(1,4); // ordered vertices of the second face
895 TopTools_Array1OfShape anEdges2(1,4); // anEdges2(i) links aVertis2(i) and aVertis2(i+1)
897 // Get wire of the second face
898 TopExp_Explorer wires2 (myFaces(2), TopAbs_WIRE);
899 if (!wires2.More()) {
900 Standard_ConstructionError::Raise("A face for the block has no wires");
902 TopoDS_Shape aWire2 = wires2.Current();
905 Standard_ConstructionError::Raise("A face for the block has more than one wire");
908 BRepTools_WireExplorer aWE2 (TopoDS::Wire(aWire2), TopoDS::Face(myFaces(2)));
909 for (nb = 1; aWE2.More(); aWE2.Next(), nb++) {
911 Standard_ConstructionError::Raise("A face for the block has more than four edges");
913 anEdges2(nb) = aWE2.Current();
914 aVertis2(nb) = aWE2.CurrentVertex();
917 Standard_ConstructionError::Raise("A face for the block has less than four edges");
920 // Step 2. Find right place in <myVertices> for the <aVertis2>,
921 // so as to minimize common length of linking edges
922 // between face 1 and face 2.
923 // Each linking edge (of four) will link vertices of the
924 // faces 1 and 2 with equal local numbers.
925 // The right place is defined by:
926 // - vertex <aVertis2(i_min)>, which will become the first vertex
927 // of the second face <myVertices(vertex_id(2,1))>
928 // - orientation of <aVertis2> relatively their future location
929 // in <myVertices> (s_min = 1 if direct, s_min = -1 if reversed)
930 Standard_Integer i_min = 0, s_min = 0;
932 TColgp_Array1OfPnt aPnts1 (1,4); // points of the first face
933 aPnts1(1) = BRep_Tool::Pnt(TopoDS::Vertex(myVertices(vertex_id(1, 1))));
934 aPnts1(2) = BRep_Tool::Pnt(TopoDS::Vertex(myVertices(vertex_id(1, 2))));
935 aPnts1(3) = BRep_Tool::Pnt(TopoDS::Vertex(myVertices(vertex_id(1, 3))));
936 aPnts1(4) = BRep_Tool::Pnt(TopoDS::Vertex(myVertices(vertex_id(1, 4))));
938 TColgp_Array1OfPnt aPnts2 (1,4); // points of the second face
939 aPnts2(1) = BRep_Tool::Pnt(TopoDS::Vertex(aVertis2(1)));
940 aPnts2(2) = BRep_Tool::Pnt(TopoDS::Vertex(aVertis2(2)));
941 aPnts2(3) = BRep_Tool::Pnt(TopoDS::Vertex(aVertis2(3)));
942 aPnts2(4) = BRep_Tool::Pnt(TopoDS::Vertex(aVertis2(4)));
944 Standard_Real Dist_min = RealLast();
945 // try all possible locations to find the best (with minimum sum distance)
946 Standard_Integer i = 1;
947 for (; i <= 4; i++) {
948 // try direct orientation
949 Standard_Real Dist_plus = aPnts1(1).Distance(aPnts2(i)) +
950 aPnts1(2).Distance(aPnts2(mod4(i + 1))) +
951 aPnts1(3).Distance(aPnts2(mod4(i + 2))) +
952 aPnts1(4).Distance(aPnts2(mod4(i + 3)));
953 if (Dist_plus < Dist_min) {
954 Dist_min = Dist_plus;
959 // try reversed orientation
960 Standard_Real Dist_minus = aPnts1(1).Distance(aPnts2(i)) +
961 aPnts1(2).Distance(aPnts2(mod4(i - 1))) +
962 aPnts1(3).Distance(aPnts2(mod4(i - 2))) +
963 aPnts1(4).Distance(aPnts2(mod4(i - 3)));
964 if (Dist_minus < Dist_min) {
965 Dist_min = Dist_minus;
971 // 3. Put vertices and edges of the second face to they
972 // permanent location in <myVertices> and <myEdges>
973 for (i = 1; i <= 4; i++) {
974 Standard_Integer nb = mod4(i_min + s_min*(i - 1));
976 if (aPnts1(i).Distance(aPnts2(nb)) < Precision::Confusion()) {
977 Standard_ConstructionError::Raise("The faces are too close");
980 myVertices(vertex_id(2, i)) = aVertis2(nb);
982 if (s_min == -1) nb = mod4(nb - 1);
983 myEdges(edge_id(2, i)) = anEdges2(nb);
986 // check the wires closure
987 TopoDS_Wire wire1 = TopoDS::Wire(aWire1);
988 TopoDS_Wire wire2 = TopoDS::Wire(aWire2);
989 TopoDS_Vertex aV1, aV2;
991 TopExp::Vertices(wire1, aV1, aV2);
992 if ( !aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2) )
993 aWire1.Closed( true );
995 TopExp::Vertices(wire2, aV1, aV2);
996 if ( !aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2) )
997 aWire2.Closed( true );
999 // 4. Generate side surface
1000 if (!aWire1.Closed() || !aWire2.Closed()) {
1001 // BRepOffsetAPI_ThruSections is not applicable on not closed wires
1002 GetFace(3, Standard_True);
1003 GetFace(4, Standard_True);
1004 GetFace(5, Standard_True);
1005 GetFace(6, Standard_True);
1007 // try to build faces on native surfaces of edges or planar
1008 Standard_Boolean tryThru = Standard_False;
1009 for (Standard_Integer i = 3; i <= 6 && !tryThru; i++) {
1010 Standard_Boolean doMake = Standard_True;
1011 TopoDS_Shape E1 = GetEdge(edge_id(i, 1), doMake);
1012 TopoDS_Shape E2 = GetEdge(edge_id(i, 2), doMake);
1013 TopoDS_Shape E3 = GetEdge(edge_id(i, 3), doMake);
1014 TopoDS_Shape E4 = GetEdge(edge_id(i, 4), doMake);
1016 BRepBuilderAPI_MakeWire MW (TopoDS::Edge(E1),
1021 Standard_ConstructionError::Raise("Wire construction failed");
1024 BRepBuilderAPI_MakeFace MF (MW, Standard_False);
1026 myFaces(i) = MF.Shape();
1028 tryThru = Standard_True;
1032 // Build side surface by ThruSections algorithm
1034 BRepOffsetAPI_ThruSections THS;
1035 THS.AddWire(TopoDS::Wire(aWire1));
1036 THS.AddWire(TopoDS::Wire(aWire2));
1038 if (!THS.IsDone()) {
1039 StdFail_NotDone::Raise("Side surface generation failed");
1041 for (Standard_Integer i = 1; i <= 4; i++) {
1043 myFaces(i+2) = THS.GeneratedFace(myEdges(i));
1046 Standard_Integer ee = side_edge_id(i);
1047 TopTools_IndexedDataMapOfShapeListOfShape MVE;
1048 MapShapesAndAncestors(myFaces(i+2), TopAbs_VERTEX, TopAbs_EDGE, MVE);
1049 FindEdge(myEdges(ee),
1050 myVertices(vertex_id_edge(ee, 1)),
1051 myVertices(vertex_id_edge(ee, 2)),
1058 //=======================================================================
1059 //function : MapShapesAndAncestors
1061 //=======================================================================
1062 void GEOMImpl_Block6Explorer::MapShapesAndAncestors (const TopoDS_Shape& S,
1063 const TopAbs_ShapeEnum TS,
1064 const TopAbs_ShapeEnum TA,
1065 TopTools_IndexedDataMapOfShapeListOfShape& M)
1067 TopTools_ListOfShape empty;
1068 TopTools_MapOfShape mapA;
1071 TopExp_Explorer exa (S,TA);
1072 for (; exa.More(); exa.Next()) {
1074 const TopoDS_Shape& anc = exa.Current();
1075 if (mapA.Add(anc)) {
1076 TopExp_Explorer exs (anc,TS);
1077 TopTools_MapOfShape mapS;
1078 for (; exs.More(); exs.Next()) {
1079 if (mapS.Add(exs.Current())) {
1080 Standard_Integer index = M.FindIndex(exs.Current());
1081 if (index == 0) index = M.Add(exs.Current(),empty);
1082 M(index).Append(anc);
1088 // visit shapes not under ancestors
1089 TopExp_Explorer ex (S,TS,TA);
1090 for (; ex.More(); ex.Next()) {
1091 Standard_Integer index = M.FindIndex(ex.Current());
1092 if (index == 0) index = M.Add(ex.Current(),empty);
1096 //=======================================================================
1097 //function : IsSimilarEdges
1099 //=======================================================================
1100 Standard_Boolean GEOMImpl_Block6Explorer::IsSimilarEdges (const TopoDS_Shape& E1,
1101 const TopoDS_Shape& E2)
1103 TopoDS_Edge E1e = TopoDS::Edge(E1);
1104 TopoDS_Edge E2e = TopoDS::Edge(E2);
1105 TopoDS_Vertex V11, V12, V21, V22;
1106 TopExp::Vertices(E1e, V11, V12, Standard_True);
1107 TopExp::Vertices(E2e, V21, V22, Standard_True);
1108 if (BRepTools::Compare(V11, V21) && BRepTools::Compare(V12, V22))
1109 return Standard_True;
1110 if (BRepTools::Compare(V11, V22) && BRepTools::Compare(V12, V21))
1111 return Standard_True;
1113 return Standard_False;
1116 //=======================================================================
1117 //function : FindEdge
1119 //=======================================================================
1120 Standard_Integer GEOMImpl_Block6Explorer::FindEdge
1121 (TopoDS_Shape& theResult,
1122 const TopoDS_Shape& V1,
1123 const TopoDS_Shape& V2,
1124 const TopTools_IndexedDataMapOfShapeListOfShape& MVE,
1125 const Standard_Boolean findAll)
1127 Standard_Integer isFound = 0;
1129 const TopTools_ListOfShape& anEdgesOfV1 = MVE.FindFromKey(V1);
1130 const TopTools_ListOfShape& anEdgesOfV2 = MVE.FindFromKey(V2);
1132 TopTools_ListIteratorOfListOfShape it1 (anEdgesOfV1);
1133 for (; it1.More(); it1.Next()) {
1134 TopTools_ListIteratorOfListOfShape it2 (anEdgesOfV2);
1135 for (; it2.More(); it2.Next()) {
1136 if (it1.Value().IsSame(it2.Value())) {
1138 theResult = it1.Value();
1139 if (!findAll) return isFound;
1147 //=======================================================================
1148 //function : FindFace
1150 //=======================================================================
1151 Standard_Integer GEOMImpl_Block6Explorer::FindFace
1152 (TopoDS_Shape& theResult,
1153 const TopoDS_Shape& V1,
1154 const TopoDS_Shape& V2,
1155 const TopoDS_Shape& V3,
1156 const TopoDS_Shape& V4,
1157 const TopTools_IndexedDataMapOfShapeListOfShape& MVF,
1158 const Standard_Boolean findAll)
1160 Standard_Integer isFound = Standard_False;
1162 const TopTools_ListOfShape& aFacesOfV1 = MVF.FindFromKey(V1);
1163 const TopTools_ListOfShape& aFacesOfV2 = MVF.FindFromKey(V2);
1164 const TopTools_ListOfShape& aFacesOfV3 = MVF.FindFromKey(V3);
1165 const TopTools_ListOfShape& aFacesOfV4 = MVF.FindFromKey(V4);
1167 TopTools_ListIteratorOfListOfShape it1 (aFacesOfV1);
1168 for (; it1.More(); it1.Next()) {
1169 TopTools_ListIteratorOfListOfShape it2 (aFacesOfV2);
1170 for (; it2.More(); it2.Next()) {
1171 if (it1.Value().IsSame(it2.Value())) {
1172 TopTools_ListIteratorOfListOfShape it3 (aFacesOfV3);
1173 for (; it3.More(); it3.Next()) {
1174 if (it1.Value().IsSame(it3.Value())) {
1175 TopTools_ListIteratorOfListOfShape it4 (aFacesOfV4);
1176 for (; it4.More(); it4.Next()) {
1177 if (it1.Value().IsSame(it4.Value())) {
1179 theResult = it1.Value();
1180 if (!findAll) return isFound;
1192 //=======================================================================
1193 //function : MakeFace
1195 //=======================================================================
1196 void GEOMImpl_Block6Explorer::MakeFace (const TopoDS_Wire& theWire,
1197 const Standard_Boolean isPlanarWanted,
1198 TopoDS_Shape& theResult)
1200 // try to build face on plane or on any surface under the edges of the wire
1201 BRepBuilderAPI_MakeFace MK (theWire, isPlanarWanted);
1203 theResult = MK.Shape();
1207 if (!isPlanarWanted) {
1208 // try to construct filling surface
1209 BRepOffsetAPI_MakeFilling MF;
1211 Standard_Integer nbEdges = 0;
1212 BRepTools_WireExplorer aWE (theWire);
1213 for (; aWE.More(); aWE.Next(), nbEdges++) {
1214 MF.Add(TopoDS::Edge(aWE.Current()), GeomAbs_C0);
1219 // Result of filling
1220 TopoDS_Shape aFace = MF.Shape();
1222 // 12.04.2006 for PAL12149 begin
1223 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(aFace));
1224 BRepBuilderAPI_MakeFace MK1 (aGS, theWire);
1226 TopoDS_Shape aFace1 = MK1.Shape();
1228 BRepCheck_Analyzer ana (aFace1, false);
1229 if (!ana.IsValid()) {
1230 TopoDS_Shape aFace2;
1231 ShHealOper_ShapeProcess aHealer;
1232 aHealer.Perform(aFace1, aFace2);
1233 if (aHealer.isDone())
1237 // 12.04.2006 for PAL12149 end
1239 if (theResult.IsNull()) { // try to deal with pure result of filling
1241 Standard_Real aTol = MF.G0Error();
1243 TColgp_Array1OfPnt aPnts (1,nbEdges); // points of the given wire
1244 BRepTools_WireExplorer aWE1 (theWire);
1245 Standard_Integer vi = 1;
1246 for (; aWE1.More() && vi <= nbEdges; aWE1.Next(), vi++) {
1247 aPnts(vi) = BRep_Tool::Pnt(TopoDS::Vertex(aWE1.CurrentVertex()));
1250 // Find maximum deviation in vertices
1251 TopExp_Explorer exp (aFace, TopAbs_VERTEX);
1252 TopTools_MapOfShape mapShape;
1253 for (; exp.More(); exp.Next()) {
1254 if (mapShape.Add(exp.Current())) {
1255 TopoDS_Vertex aV = TopoDS::Vertex(exp.Current());
1256 Standard_Real aTolV = BRep_Tool::Tolerance(aV);
1257 gp_Pnt aP = BRep_Tool::Pnt(aV);
1258 Standard_Real min_dist = aP.Distance(aPnts(1));
1259 for (vi = 2; vi <= nbEdges; vi++) {
1260 min_dist = Min(min_dist, aP.Distance(aPnts(vi)));
1262 aTol = Max(aTol, aTolV);
1263 aTol = Max(aTol, min_dist);
1267 if ((*((Handle(BRep_TFace)*)&aFace.TShape()))->Tolerance() < aTol) {
1268 (*((Handle(BRep_TFace)*)&aFace.TShape()))->Tolerance(aTol);
1274 // try to update wire tolerances to build a planar face
1276 #if 1 //(OCC_VERSION_MAJOR < 6) || (OCC_VERSION_MAJOR == 6 && OCC_VERSION_MINOR <= 1)
1278 Standard_Real aToleranceReached, aTol;
1279 BRepLib_FindSurface aFS;
1280 aFS.Init(theWire, -1., isPlanarWanted);
1281 aToleranceReached = aFS.ToleranceReached();
1282 aTol = aFS.Tolerance();
1285 aFS.Init(theWire, aToleranceReached, isPlanarWanted);
1286 if (!aFS.Found()) return;
1287 aToleranceReached = aFS.ToleranceReached();
1288 aTol = aFS.Tolerance();
1290 aTol = Max(1.2 * aToleranceReached, aTol);
1292 // Copy the wire, bacause it can be updated with very-very big tolerance here
1293 BRepBuilderAPI_Copy aMC (theWire);
1294 if (!aMC.IsDone()) return;
1295 TopoDS_Wire aWire = TopoDS::Wire(aMC.Shape());
1296 // Update tolerances to <aTol>
1298 for (TopExp_Explorer expE (aWire, TopAbs_EDGE); expE.More(); expE.Next()) {
1299 TopoDS_Edge anE = TopoDS::Edge(expE.Current());
1300 B.UpdateEdge(anE, aTol);
1302 for (TopExp_Explorer expV (aWire, TopAbs_VERTEX); expV.More(); expV.Next()) {
1303 TopoDS_Vertex aV = TopoDS::Vertex(expV.Current());
1304 B.UpdateVertex(aV, aTol);
1306 //BRepLib::UpdateTolerances(aWire);
1308 BRepBuilderAPI_MakeFace MK1 (aWire, isPlanarWanted);
1310 theResult = MK1.Shape();
1314 #else // After migration on OCCT version, containing PKV's fix. See bug 8293
1315 BRepLib_MakeFace aBMF;
1316 aBMF.Init(theWire, isPlanarWanted, Standard_True);
1317 if (aBMF.Error() == BRepLib_FaceDone) {
1318 theResult = aBMF.Shape();