1 // Created on: 2012-06-09
2 // Created by: jgv@ROLEX
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BRep_Builder.hxx>
18 #include <BRep_CurveRepresentation.hxx>
19 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
20 #include <BRep_TEdge.hxx>
21 #include <BRep_Tool.hxx>
22 #include <BRepLib.hxx>
23 #include <BRepLib_MakeEdge.hxx>
24 #include <BRepTopAdaptor_TopolTool.hxx>
25 #include <GC_MakeCircle.hxx>
26 #include <Geom2d_Line.hxx>
27 #include <Geom2d_TrimmedCurve.hxx>
28 #include <Geom2dConvert.hxx>
29 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
30 #include <Geom_BezierCurve.hxx>
31 #include <Geom_BSplineCurve.hxx>
32 #include <Geom_Circle.hxx>
33 #include <Geom_CylindricalSurface.hxx>
34 #include <Geom_ElementarySurface.hxx>
35 #include <Geom_Line.hxx>
36 #include <Geom_OffsetSurface.hxx>
37 #include <Geom_RectangularTrimmedSurface.hxx>
38 #include <Geom_Surface.hxx>
39 #include <Geom_SurfaceOfLinearExtrusion.hxx>
40 #include <Geom_SurfaceOfRevolution.hxx>
41 #include <Geom_SweptSurface.hxx>
42 #include <Geom_TrimmedCurve.hxx>
43 #include <GeomAdaptor_HSurface.hxx>
44 #include <GeomConvert.hxx>
45 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
46 #include <GeomLib_IsPlanarSurface.hxx>
47 #include <gp_Cylinder.hxx>
50 #include <IntPatch_ImpImpIntersection.hxx>
51 #include <ShapeAnalysis_Edge.hxx>
52 #include <ShapeAnalysis_WireOrder.hxx>
53 #include <ShapeBuild_Edge.hxx>
54 #include <ShapeBuild_ReShape.hxx>
55 #include <ShapeExtend_CompositeSurface.hxx>
56 #include <ShapeFix_ComposeShell.hxx>
57 #include <ShapeFix_Edge.hxx>
58 #include <ShapeFix_Face.hxx>
59 #include <ShapeFix_SequenceOfWireSegment.hxx>
60 #include <ShapeFix_Shell.hxx>
61 #include <ShapeFix_Wire.hxx>
62 #include <ShapeFix_WireSegment.hxx>
63 #include <ShapeUpgrade_RemoveLocations.hxx>
64 #include <ShapeUpgrade_UnifySameDomain.hxx>
65 #include <Standard_Type.hxx>
66 #include <TColGeom2d_Array1OfBSplineCurve.hxx>
67 #include <TColGeom2d_HArray1OfBSplineCurve.hxx>
68 #include <TColGeom2d_SequenceOfBoundedCurve.hxx>
69 #include <TColGeom_Array1OfBSplineCurve.hxx>
70 #include <TColGeom_HArray1OfBSplineCurve.hxx>
71 #include <TColGeom_HArray2OfSurface.hxx>
72 #include <TColGeom_SequenceOfSurface.hxx>
73 #include <TColStd_Array1OfReal.hxx>
74 #include <TColStd_MapOfInteger.hxx>
76 #include <TopExp_Explorer.hxx>
78 #include <TopoDS_Edge.hxx>
79 #include <TopoDS_Face.hxx>
80 #include <TopoDS_Shape.hxx>
81 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
82 #include <TopTools_IndexedMapOfShape.hxx>
83 #include <TopTools_ListIteratorOfListOfShape.hxx>
84 #include <TopTools_MapOfShape.hxx>
85 #include <TopTools_SequenceOfShape.hxx>
86 #include <gp_Circ.hxx>
87 #include <BRepAdaptor_Curve.hxx>
88 #include <BRepClass_FaceClassifier.hxx>
89 #include <BRepAdaptor_Curve2d.hxx>
90 #include <gp_Vec2d.hxx>
92 IMPLEMENT_STANDARD_RTTIEXT(ShapeUpgrade_UnifySameDomain,MMgt_TShared)
94 struct SubSequenceOfEdges
96 TopTools_SequenceOfShape SeqsEdges;
97 TopoDS_Edge UnionEdges;
100 static Standard_Boolean IsLikeSeam(const TopoDS_Edge& anEdge,
101 const TopoDS_Face& aFace,
102 const Handle(Geom_Surface)& aBaseSurface)
104 if (!aBaseSurface->IsUPeriodic() && !aBaseSurface->IsVPeriodic())
105 return Standard_False;
107 BRepAdaptor_Curve2d BAcurve2d(anEdge, aFace);
108 gp_Pnt2d FirstPoint, LastPoint;
109 gp_Vec2d FirstDir, LastDir;
110 BAcurve2d.D1(BAcurve2d.FirstParameter(), FirstPoint, FirstDir);
111 BAcurve2d.D1(BAcurve2d.LastParameter(), LastPoint, LastDir);
112 Standard_Real Length = FirstDir.Magnitude();
113 if (Length <= gp::Resolution())
114 return Standard_False;
117 Length = LastDir.Magnitude();
118 if (Length <= gp::Resolution())
119 return Standard_False;
123 Standard_Real Tol = 1.e-7;
124 if (aBaseSurface->IsUPeriodic() &&
125 (Abs(FirstDir.X()) < Tol) &&
126 (Abs(LastDir.X()) < Tol))
127 return Standard_True;
129 if (aBaseSurface->IsVPeriodic() &&
130 (Abs(FirstDir.Y()) < Tol) &&
131 (Abs(LastDir.Y()) < Tol))
132 return Standard_True;
134 return Standard_False;
137 //=======================================================================
138 //function : AddOrdinaryEdges
140 //=======================================================================
141 // adds edges from the shape to the sequence
142 // seams and equal edges are dropped
143 // Returns true if one of original edges dropped
144 static Standard_Boolean AddOrdinaryEdges(TopTools_SequenceOfShape& edges,
145 const TopoDS_Shape aShape,
146 Standard_Integer& anIndex)
149 TopTools_IndexedMapOfShape aNewEdges;
150 //add edges without seams
151 for(TopExp_Explorer exp(aShape,TopAbs_EDGE); exp.More(); exp.Next()) {
152 TopoDS_Shape edge = exp.Current();
153 if(aNewEdges.Contains(edge))
155 //aNewEdges.Remove(edge);
156 TopoDS_Shape LastEdge = aNewEdges(aNewEdges.Extent());
157 aNewEdges.RemoveLast();
158 if (aNewEdges.FindIndex(edge) != 0)
159 aNewEdges.Substitute(aNewEdges.FindIndex(edge), LastEdge);
160 /////////////////////////
166 Standard_Boolean isDropped = Standard_False;
167 //merge edges and drop seams
169 for (i = 1; i <= edges.Length(); i++) {
170 TopoDS_Shape current = edges(i);
171 if(aNewEdges.Contains(current)) {
173 //aNewEdges.Remove(current);
174 TopoDS_Shape LastEdge = aNewEdges(aNewEdges.Extent());
175 aNewEdges.RemoveLast();
176 if (aNewEdges.FindIndex(current) != 0)
177 aNewEdges.Substitute(aNewEdges.FindIndex(current), LastEdge);
178 /////////////////////////
183 isDropped = Standard_True;
189 //add edges to the sequemce
190 for (i = 1; i <= aNewEdges.Extent(); i++)
191 edges.Append(aNewEdges(i));
196 //=======================================================================
197 //function : getCylinder
199 //=======================================================================
200 static Standard_Boolean getCylinder(Handle(Geom_Surface)& theInSurface,
201 gp_Cylinder& theOutCylinder)
203 Standard_Boolean isCylinder = Standard_False;
205 if (theInSurface->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
206 Handle(Geom_CylindricalSurface) aGC = Handle(Geom_CylindricalSurface)::DownCast(theInSurface);
208 theOutCylinder = aGC->Cylinder();
209 isCylinder = Standard_True;
211 else if (theInSurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
212 Handle(Geom_SurfaceOfRevolution) aRS =
213 Handle(Geom_SurfaceOfRevolution)::DownCast(theInSurface);
214 Handle(Geom_Curve) aBasis = aRS->BasisCurve();
215 if (aBasis->IsKind(STANDARD_TYPE(Geom_Line))) {
216 Handle(Geom_Line) aBasisLine = Handle(Geom_Line)::DownCast(aBasis);
217 gp_Dir aDir = aRS->Direction();
218 gp_Dir aBasisDir = aBasisLine->Position().Direction();
219 if (aBasisDir.IsParallel(aDir, Precision::Angular())) {
220 // basis line is parallel to the revolution axis: it is a cylinder
221 gp_Pnt aLoc = aRS->Location();
222 Standard_Real aR = aBasisLine->Lin().Distance(aLoc);
223 gp_Ax3 aCylAx (aLoc, aDir);
225 theOutCylinder = gp_Cylinder(aCylAx, aR);
226 isCylinder = Standard_True;
230 else if (theInSurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) {
231 Handle(Geom_SurfaceOfLinearExtrusion) aLES =
232 Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(theInSurface);
233 Handle(Geom_Curve) aBasis = aLES->BasisCurve();
234 if (aBasis->IsKind(STANDARD_TYPE(Geom_Circle))) {
235 Handle(Geom_Circle) aBasisCircle = Handle(Geom_Circle)::DownCast(aBasis);
236 gp_Dir aDir = aLES->Direction();
237 gp_Dir aBasisDir = aBasisCircle->Position().Direction();
238 if (aBasisDir.IsParallel(aDir, Precision::Angular())) {
239 // basis circle is normal to the extrusion axis: it is a cylinder
240 gp_Pnt aLoc = aBasisCircle->Location();
241 Standard_Real aR = aBasisCircle->Radius();
242 gp_Ax3 aCylAx (aLoc, aDir);
244 theOutCylinder = gp_Cylinder(aCylAx, aR);
245 isCylinder = Standard_True;
255 //=======================================================================
256 //function : ClearRts
258 //=======================================================================
259 static Handle(Geom_Surface) ClearRts(const Handle(Geom_Surface)& aSurface)
261 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
262 Handle(Geom_RectangularTrimmedSurface) rts =
263 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
264 return rts->BasisSurface();
269 //=======================================================================
270 //function : IsSameDomain
272 //=======================================================================
273 static Standard_Boolean IsSameDomain(const TopoDS_Face& aFace,
274 const TopoDS_Face& aCheckedFace)
276 //checking the same handles
277 TopLoc_Location L1, L2;
278 Handle(Geom_Surface) S1, S2;
280 S1 = BRep_Tool::Surface(aFace,L1);
281 S2 = BRep_Tool::Surface(aCheckedFace,L2);
283 if (S1 == S2 && L1 == L2)
284 return Standard_True;
286 // planar and cylindrical cases (IMP 20052)
287 Standard_Real aPrec = Precision::Confusion();
289 S1 = BRep_Tool::Surface(aFace);
290 S2 = BRep_Tool::Surface(aCheckedFace);
295 //Handle(Geom_OffsetSurface) aGOFS1, aGOFS2;
296 //aGOFS1 = Handle(Geom_OffsetSurface)::DownCast(S1);
297 //aGOFS2 = Handle(Geom_OffsetSurface)::DownCast(S2);
298 //if (!aGOFS1.IsNull()) S1 = aGOFS1->BasisSurface();
299 //if (!aGOFS2.IsNull()) S2 = aGOFS2->BasisSurface();
301 // case of two elementary surfaces: use OCCT tool
302 // elementary surfaces: ConicalSurface, CylindricalSurface,
303 // Plane, SphericalSurface and ToroidalSurface
304 if (S1->IsKind(STANDARD_TYPE(Geom_ElementarySurface)) &&
305 S2->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
307 Handle(GeomAdaptor_HSurface) aGA1 = new GeomAdaptor_HSurface(S1);
308 Handle(GeomAdaptor_HSurface) aGA2 = new GeomAdaptor_HSurface(S2);
310 Handle(BRepTopAdaptor_TopolTool) aTT1 = new BRepTopAdaptor_TopolTool();
311 Handle(BRepTopAdaptor_TopolTool) aTT2 = new BRepTopAdaptor_TopolTool();
314 IntPatch_ImpImpIntersection anIIInt (aGA1, aTT1, aGA2, aTT2, aPrec, aPrec);
315 if (!anIIInt.IsDone() || anIIInt.IsEmpty())
316 return Standard_False;
318 return anIIInt.TangentFaces();
320 catch (Standard_Failure) {
321 return Standard_False;
325 // case of two planar surfaces:
326 // all kinds of surfaces checked, including b-spline and bezier
327 GeomLib_IsPlanarSurface aPlanarityChecker1 (S1, aPrec);
328 if (aPlanarityChecker1.IsPlanar()) {
329 GeomLib_IsPlanarSurface aPlanarityChecker2 (S2, aPrec);
330 if (aPlanarityChecker2.IsPlanar()) {
331 gp_Pln aPln1 = aPlanarityChecker1.Plan();
332 gp_Pln aPln2 = aPlanarityChecker2.Plan();
334 if (aPln1.Position().Direction().IsParallel(aPln2.Position().Direction(),Precision::Angular()) &&
335 aPln1.Distance(aPln2) < aPrec) {
336 return Standard_True;
341 // case of two cylindrical surfaces, at least one of which is a swept surface
342 // swept surfaces: SurfaceOfLinearExtrusion, SurfaceOfRevolution
343 if ((S1->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ||
344 S1->IsKind(STANDARD_TYPE(Geom_SweptSurface))) &&
345 (S2->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ||
346 S2->IsKind(STANDARD_TYPE(Geom_SweptSurface))))
348 gp_Cylinder aCyl1, aCyl2;
349 if (getCylinder(S1, aCyl1) && getCylinder(S2, aCyl2)) {
350 if (fabs(aCyl1.Radius() - aCyl2.Radius()) < aPrec) {
351 gp_Dir aDir1 = aCyl1.Position().Direction();
352 gp_Dir aDir2 = aCyl2.Position().Direction();
353 if (aDir1.IsParallel(aDir2, Precision::Angular())) {
354 gp_Pnt aLoc1 = aCyl1.Location();
355 gp_Pnt aLoc2 = aCyl2.Location();
356 gp_Vec aVec12 (aLoc1, aLoc2);
357 if (aVec12.SquareMagnitude() < aPrec*aPrec ||
358 aVec12.IsParallel(aDir1, Precision::Angular())) {
359 return Standard_True;
366 return Standard_False;
369 //=======================================================================
370 //function : MovePCurves
372 //=======================================================================
373 static void MovePCurves(TopoDS_Face& aTarget,
374 const TopoDS_Face& aSource)
377 for(TopExp_Explorer wexp(aSource,TopAbs_WIRE);wexp.More();wexp.Next()) {
378 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(TopoDS::Wire(wexp.Current()),
379 aTarget, Precision::Confusion());
381 Standard_Boolean isReoredFailed = sfw->StatusReorder ( ShapeExtend_FAIL );
382 sfw->FixEdgeCurves();
387 sfw->FixDegenerated();
389 // remove degenerated edges from not degenerated points
390 ShapeAnalysis_Edge sae;
391 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
392 for(Standard_Integer i = 1; i<=sewd->NbEdges();i++) {
393 TopoDS_Edge E = sewd->Edge(i);
394 if(BRep_Tool::Degenerated(E)&&!sae.HasPCurve(E,aTarget)) {
400 TopoDS_Wire ResWire = sfw->Wire();
401 B.Add(aTarget,ResWire);
405 //=======================================================================
406 //function : GlueEdgesWithPCurves
407 //purpose : Glues the pcurves of the sequence of edges
408 // and glues their 3d curves
409 //=======================================================================
410 static TopoDS_Edge GlueEdgesWithPCurves(const TopTools_SequenceOfShape& aChain,
411 const TopoDS_Vertex& FirstVertex,
412 const TopoDS_Vertex& LastVertex)
414 Standard_Integer i, j;
416 TopoDS_Edge FirstEdge = TopoDS::Edge(aChain(1));
417 //TColGeom2d_SequenceOfCurve PCurveSeq;
418 TColGeom_SequenceOfSurface SurfSeq;
419 //TopTools_SequenceOfShape LocSeq;
421 BRep_ListIteratorOfListOfCurveRepresentation itr( (Handle(BRep_TEdge)::DownCast(FirstEdge.TShape()))->Curves() );
422 for (; itr.More(); itr.Next())
424 Handle(BRep_CurveRepresentation) CurveRep = itr.Value();
425 if (CurveRep->IsCurveOnSurface())
427 //PCurveSeq.Append(CurveRep->PCurve());
428 SurfSeq.Append(CurveRep->Surface());
430 TopoDS_Shape aLocShape;
431 aLocShape.Location(CurveRep->Location());
432 LocSeq.Append(aLocShape);
437 Standard_Real fpar, lpar;
438 BRep_Tool::Range(FirstEdge, fpar, lpar);
439 TopoDS_Edge PrevEdge = FirstEdge;
441 Standard_Real MaxTol = 0.;
446 Standard_Integer nb_curve = aChain.Length(); //number of curves
447 TColGeom_Array1OfBSplineCurve tab_c3d(0,nb_curve-1); //array of the curves
448 TColStd_Array1OfReal tabtolvertex(0,nb_curve-1); //(0,nb_curve-2); //array of the tolerances
450 TopoDS_Vertex PrevVertex = FirstVertex;
451 for (i = 1; i <= nb_curve; i++)
453 TopoDS_Edge anEdge = TopoDS::Edge(aChain(i));
454 TopoDS_Vertex VF, VL;
455 TopExp::Vertices(anEdge, VF, VL);
456 Standard_Boolean ToReverse = (!VF.IsSame(PrevVertex));
458 Standard_Real Tol1 = BRep_Tool::Tolerance(VF);
459 Standard_Real Tol2 = BRep_Tool::Tolerance(VL);
467 TopExp::CommonVertex(PrevEdge, anEdge, CV);
468 Standard_Real Tol = BRep_Tool::Tolerance(CV);
469 tabtolvertex(i-2) = Tol;
472 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, fpar, lpar);
473 Handle(Geom_TrimmedCurve) aTrCurve = new Geom_TrimmedCurve(aCurve, fpar, lpar);
474 tab_c3d(i-1) = GeomConvert::CurveToBSplineCurve(aTrCurve);
475 GeomConvert::C0BSplineToC1BSplineCurve(tab_c3d(i-1), Precision::Confusion());
477 tab_c3d(i-1)->Reverse();
478 PrevVertex = (ToReverse)? VF : VL;
481 Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves
482 Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex
483 GeomConvert::ConcatC1(tab_c3d,
488 Precision::Confusion()); //C1 concatenation
490 if (concatcurve->Length() > 1)
492 GeomConvert_CompCurveToBSplineCurve Concat(concatcurve->Value(concatcurve->Lower()));
494 for (i = concatcurve->Lower()+1; i <= concatcurve->Upper(); i++)
495 Concat.Add( concatcurve->Value(i), MaxTol, Standard_True );
497 concatcurve->SetValue(concatcurve->Lower(), Concat.BSplineCurve());
499 Handle(Geom_BSplineCurve) ResCurve = concatcurve->Value(concatcurve->Lower());
501 TColGeom2d_SequenceOfBoundedCurve ResPCurves;
502 TopLoc_Location aLoc;
503 for (j = 1; j <= SurfSeq.Length(); j++)
505 TColGeom2d_Array1OfBSplineCurve tab_c2d(0,nb_curve-1); //array of the pcurves
507 PrevVertex = FirstVertex;
508 PrevEdge = FirstEdge;
509 //TopLoc_Location theLoc = LocSeq(j).Location();
510 for (i = 1; i <= nb_curve; i++)
512 TopoDS_Edge anEdge = TopoDS::Edge(aChain(i));
513 TopoDS_Vertex VF, VL;
514 TopExp::Vertices(anEdge, VF, VL);
515 Standard_Boolean ToReverse = (!VF.IsSame(PrevVertex));
518 Handle(Geom2d_Curve) aPCurve =
519 BRep_Tool::CurveOnSurface(anEdge, SurfSeq(j), anEdge.Location()*theLoc, fpar, lpar);
521 Handle(Geom2d_Curve) aPCurve =
522 BRep_Tool::CurveOnSurface(anEdge, SurfSeq(j), aLoc, fpar, lpar);
523 Handle(Geom2d_TrimmedCurve) aTrPCurve = new Geom2d_TrimmedCurve(aPCurve, fpar, lpar);
524 tab_c2d(i-1) = Geom2dConvert::CurveToBSplineCurve(aTrPCurve);
525 Geom2dConvert::C0BSplineToC1BSplineCurve(tab_c2d(i-1), Precision::Confusion());
527 tab_c2d(i-1)->Reverse();
528 PrevVertex = (ToReverse)? VF : VL;
531 Handle(TColGeom2d_HArray1OfBSplineCurve) concatc2d; //array of the concatenated curves
532 Handle(TColStd_HArray1OfInteger) ArrayOfInd2d; //array of the remining Vertex
533 Geom2dConvert::ConcatC1(tab_c2d,
538 Precision::Confusion()); //C1 concatenation
540 if (concatc2d->Length() > 1)
542 Geom2dConvert_CompCurveToBSplineCurve Concat2d(concatc2d->Value(concatc2d->Lower()));
544 for (i = concatc2d->Lower()+1; i <= concatc2d->Upper(); i++)
545 Concat2d.Add( concatc2d->Value(i), MaxTol, Standard_True );
547 concatc2d->SetValue(concatc2d->Lower(), Concat2d.BSplineCurve());
549 Handle(Geom2d_BSplineCurve) aResPCurve = concatc2d->Value(concatc2d->Lower());
550 ResPCurves.Append(aResPCurve);
553 ResEdge = BRepLib_MakeEdge(ResCurve,
554 FirstVertex, LastVertex,
555 ResCurve->FirstParameter(), ResCurve->LastParameter());
556 BB.SameRange(ResEdge, Standard_False);
557 BB.SameParameter(ResEdge, Standard_False);
558 for (j = 1; j <= ResPCurves.Length(); j++)
560 BB.UpdateEdge(ResEdge, ResPCurves(j), SurfSeq(j), aLoc, MaxTol);
561 BB.Range(ResEdge, SurfSeq(j), aLoc, ResPCurves(j)->FirstParameter(), ResPCurves(j)->LastParameter());
564 BRepLib::SameParameter(ResEdge, MaxTol, Standard_True);
569 //=======================================================================
570 //function : MergeSubSeq
571 //purpose : Merges a sequence of edges into one edge if possible
572 //=======================================================================
574 static Standard_Boolean MergeSubSeq(const TopTools_SequenceOfShape& aChain, TopoDS_Edge& OutEdge, double Tol, Standard_Boolean ConcatBSplines)
576 ShapeAnalysis_Edge sae;
578 // union edges in chain
580 Standard_Real fp1,lp1,fp2,lp2;
581 Standard_Boolean IsUnionOfLinesPossible = Standard_True;
582 Standard_Boolean IsUnionOfCirclesPossible = Standard_True;
583 Handle(Geom_Curve) c3d1, c3d2;
584 for(j=1; j<aChain.Length(); j++)
586 TopoDS_Edge edge1 = TopoDS::Edge(aChain.Value(j));
587 c3d1 = BRep_Tool::Curve(edge1,fp1,lp1);
589 TopoDS_Edge edge2 = TopoDS::Edge(aChain.Value(j+1));
590 c3d2 = BRep_Tool::Curve(edge2,fp2,lp2);
592 if(c3d1.IsNull() || c3d2.IsNull())
593 return Standard_False;
595 while(c3d1->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
596 Handle(Geom_TrimmedCurve) tc =
597 Handle(Geom_TrimmedCurve)::DownCast(c3d1);
598 c3d1 = tc->BasisCurve();
600 while(c3d2->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
601 Handle(Geom_TrimmedCurve) tc =
602 Handle(Geom_TrimmedCurve)::DownCast(c3d2);
603 c3d2 = tc->BasisCurve();
605 if( c3d1->IsKind(STANDARD_TYPE(Geom_Line)) && c3d2->IsKind(STANDARD_TYPE(Geom_Line)) ) {
606 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(c3d1);
607 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(c3d2);
608 gp_Dir Dir1 = L1->Position().Direction();
609 gp_Dir Dir2 = L2->Position().Direction();
610 if(!Dir1.IsParallel(Dir2,Tol))
611 IsUnionOfLinesPossible = Standard_False;
614 IsUnionOfLinesPossible = Standard_False;
615 if( c3d1->IsKind(STANDARD_TYPE(Geom_Circle)) && c3d2->IsKind(STANDARD_TYPE(Geom_Circle)) ) {
616 Handle(Geom_Circle) C1 = Handle(Geom_Circle)::DownCast(c3d1);
617 Handle(Geom_Circle) C2 = Handle(Geom_Circle)::DownCast(c3d2);
618 gp_Pnt P01 = C1->Location();
619 gp_Pnt P02 = C2->Location();
620 if (P01.Distance(P02) > Precision::Confusion())
621 IsUnionOfCirclesPossible = Standard_False;
624 IsUnionOfCirclesPossible = Standard_False;
626 if (IsUnionOfLinesPossible && IsUnionOfCirclesPossible)
627 return Standard_False;
629 //union of lines is possible
630 if (IsUnionOfLinesPossible)
632 TopoDS_Vertex V1 = sae.FirstVertex(TopoDS::Edge(aChain.First()));
633 gp_Pnt PV1 = BRep_Tool::Pnt(V1);
634 TopoDS_Vertex V2 = sae.LastVertex(TopoDS::Edge(aChain.Last()));
635 gp_Pnt PV2 = BRep_Tool::Pnt(V2);
636 gp_Vec Vec(PV1, PV2);
637 Handle(Geom_Line) L = new Geom_Line(gp_Ax1(PV1,Vec));
638 Standard_Real dist = PV1.Distance(PV2);
639 Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(L,0.0,dist);
641 B.MakeEdge (E, tc ,Precision::Confusion());
642 B.Add (E,V1); B.Add (E,V2);
643 B.UpdateVertex(V1, 0., E, 0.);
644 B.UpdateVertex(V2, dist, E, 0.);
646 return Standard_True;
649 if (IsUnionOfCirclesPossible)
652 TopoDS_Edge FE = TopoDS::Edge(aChain.First());
653 Handle(Geom_Curve) c3d = BRep_Tool::Curve(FE,f,l);
655 while(c3d->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
656 Handle(Geom_TrimmedCurve) tc =
657 Handle(Geom_TrimmedCurve)::DownCast(c3d);
658 c3d = tc->BasisCurve();
660 Handle(Geom_Circle) Cir = Handle(Geom_Circle)::DownCast(c3d);
662 TopoDS_Vertex V1 = sae.FirstVertex(FE);
663 TopoDS_Vertex V2 = sae.LastVertex(TopoDS::Edge(aChain.Last()));
667 BRepAdaptor_Curve adef(FE);
668 Handle(Geom_Circle) Cir1;
670 if ( FE.Orientation() == TopAbs_FORWARD)
672 FP = adef.FirstParameter();
673 LP = adef.LastParameter();
677 FP = adef.LastParameter();
678 LP = adef.FirstParameter();
680 if (Abs(FP) < Precision::PConfusion())
682 B.MakeEdge (E,Cir, Precision::Confusion());
685 E.Orientation(FE.Orientation());
689 GC_MakeCircle MC1 (adef.Value(FP), adef.Value((FP + LP) * 0.5), adef.Value(LP));
693 return Standard_False;
694 B.MakeEdge (E, Cir1, Precision::Confusion());
700 gp_Pnt PV1 = BRep_Tool::Pnt(V1);
701 gp_Pnt PV2 = BRep_Tool::Pnt(V2);
702 TopoDS_Vertex VM = sae.LastVertex(FE);
703 gp_Pnt PVM = BRep_Tool::Pnt(VM);
704 GC_MakeCircle MC (PV1,PVM,PV2);
705 Handle(Geom_Circle) C = MC.Value();
706 gp_Pnt P0 = C->Location();
707 gp_Dir D1(gp_Vec(P0,PV1));
708 gp_Dir D2(gp_Vec(P0,PV2));
709 Standard_Real fpar = C->XAxis().Direction().Angle(D1);
710 if(fabs(fpar)>Precision::Confusion()) {
712 gp_Dir ND = C->XAxis().Direction().Crossed(D1);
713 if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) {
717 Standard_Real lpar = C->XAxis().Direction().Angle(D2);
718 if(fabs(lpar)>Precision::Confusion()) {
720 gp_Dir ND = C->XAxis().Direction().Crossed(D2);
721 if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) {
725 if (lpar < fpar) lpar += 2*M_PI;
726 Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(C,fpar,lpar);
727 B.MakeEdge (E,tc,Precision::Confusion());
730 B.UpdateVertex(V1, fpar, E, 0.);
731 B.UpdateVertex(V2, lpar, E, 0.);
734 return Standard_True;
736 if (aChain.Length() > 1 && ConcatBSplines) {
737 // second step: union edges with various curves
738 // skl for bug 0020052 from Mantis: perform such unions
739 // only if curves are bspline or bezier
741 TopoDS_Vertex VF = sae.FirstVertex(TopoDS::Edge(aChain.First()));
742 TopoDS_Vertex VL = sae.LastVertex(TopoDS::Edge(aChain.Last()));
743 Standard_Boolean NeedUnion = Standard_True;
744 for(j=1; j<=aChain.Length(); j++) {
745 TopoDS_Edge edge = TopoDS::Edge(aChain.Value(j));
747 Handle(Geom_Curve) c3d = BRep_Tool::Curve(edge,Loc,fp1,lp1);
748 if(c3d.IsNull()) continue;
749 while(c3d->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
750 Handle(Geom_TrimmedCurve) tc =
751 Handle(Geom_TrimmedCurve)::DownCast(c3d);
752 c3d = tc->BasisCurve();
754 if( ( c3d->IsKind(STANDARD_TYPE(Geom_BSplineCurve)) ||
755 c3d->IsKind(STANDARD_TYPE(Geom_BezierCurve)) ) ) continue;
756 NeedUnion = Standard_False;
761 cout<<"can not make analitical union => make approximation"<<endl;
763 TopoDS_Edge E = GlueEdgesWithPCurves(aChain, VF, VL);
765 return Standard_True;
769 cout<<"can not make approximation for such types of curves"<<endl;
771 return Standard_False;
774 return Standard_False;
777 //=======================================================================
778 //function : IsMergingPossible
779 //purpose : Checks if merging of two edges is possible
780 //=======================================================================
782 static Standard_Boolean IsMergingPossible(const TopoDS_Edge& edge1, const TopoDS_Edge& edge2,
783 double Tol, const TopTools_MapOfShape& DegEdgeVrt)
785 TopoDS_Vertex CV = TopExp::LastVertex(edge1, Standard_True);
786 if (CV.IsNull() || DegEdgeVrt.Contains(CV))
787 return Standard_False;
789 BRepAdaptor_Curve ade1(edge1);
790 BRepAdaptor_Curve ade2(edge2);
792 GeomAbs_CurveType t1 = ade1.GetType();
793 GeomAbs_CurveType t2 = ade2.GetType();
795 if( t1 == GeomAbs_Circle && t2 == GeomAbs_Circle)
797 if (ade1.Circle().Location().Distance(ade2.Circle().Location()) > Precision::Confusion())
798 return Standard_False;
801 if( ( (t1 != GeomAbs_BezierCurve && t1 != GeomAbs_BSplineCurve) ||
802 (t2 != GeomAbs_BezierCurve && t2 != GeomAbs_BSplineCurve)) && t1 != t2)
803 return Standard_False;
807 if (edge1.Orientation() == TopAbs_FORWARD)
808 ade1.D1(ade1.LastParameter(), P1, Diff1);
811 ade1.D1(ade1.FirstParameter(), P1, Diff1);
815 if (edge2.Orientation() == TopAbs_FORWARD)
816 ade2.D1(ade2.FirstParameter(), P2, Diff2);
819 ade2.D1(ade2.LastParameter(), P2, Diff2);
823 if (Diff1.Angle(Diff2) > Tol)
824 return Standard_False;
826 return Standard_True;
829 //=======================================================================
830 //function : GenerateSubSeq
831 //purpose : Generates sub-sequences of edges from sequence of edges
832 //Edges from each subsequences can be merged into the one edge
833 //=======================================================================
835 static void GenerateSubSeq (const TopTools_SequenceOfShape& anInpEdgeSeq,
836 NCollection_Sequence<SubSequenceOfEdges>& SeqOfSubSeqOfEdges,
837 Standard_Boolean IsClosed, double Tol, const TopTools_MapOfShape& DegEdgeVrt )
839 Standard_Boolean isOk = Standard_False;
840 TopoDS_Edge edge1, edge2;
842 SubSequenceOfEdges SubSeq;
843 SubSeq.SeqsEdges.Append(TopoDS::Edge(anInpEdgeSeq(1)));
844 SeqOfSubSeqOfEdges.Append(SubSeq);
846 for (int i = 1; i < anInpEdgeSeq.Length(); i++)
848 edge1 = TopoDS::Edge(anInpEdgeSeq(i));
849 edge2 = TopoDS::Edge(anInpEdgeSeq(i+1));
850 isOk = IsMergingPossible(edge1, edge2, Tol, DegEdgeVrt);
853 SubSequenceOfEdges aSubSeq;
854 aSubSeq.SeqsEdges.Append(edge2);
855 SeqOfSubSeqOfEdges.Append(aSubSeq);
858 SeqOfSubSeqOfEdges.ChangeLast().SeqsEdges.Append(edge2);
860 /// check first and last chain segments
861 if (IsClosed && SeqOfSubSeqOfEdges.Length() > 1)
863 edge1 = TopoDS::Edge(anInpEdgeSeq.Last());
864 edge2 = TopoDS::Edge(anInpEdgeSeq.First());
865 if (IsMergingPossible(edge1, edge2, Tol, DegEdgeVrt))
867 SeqOfSubSeqOfEdges.ChangeLast().SeqsEdges.Append(SeqOfSubSeqOfEdges.ChangeFirst().SeqsEdges);
868 SeqOfSubSeqOfEdges.Remove(1);
874 //=======================================================================
875 //function : MergeEdges
877 //=======================================================================
878 static Standard_Boolean MergeEdges(TopTools_SequenceOfShape& SeqEdges,
879 const Standard_Real Tol,
880 const Standard_Boolean ConcatBSplines,
881 NCollection_Sequence<SubSequenceOfEdges>& SeqOfSubSeqOfEdges,
882 const TopTools_MapOfShape& NonMergVrt )
884 // skip degenerated edges, and forbid merging through them
885 TopTools_IndexedDataMapOfShapeListOfShape aMapVE;
887 TopTools_MapOfShape VerticesToAvoid;
888 for (j = 1; j <= SeqEdges.Length(); j++)
890 TopoDS_Edge anEdge = TopoDS::Edge(SeqEdges(j));
891 if (BRep_Tool::Degenerated(anEdge))
893 TopoDS_Vertex V1, V2;
894 TopExp::Vertices(anEdge, V1, V2);
895 VerticesToAvoid.Add(V1);
896 VerticesToAvoid.Add(V2);
897 SeqEdges.Remove(j--);
901 // fill in the map V-E
902 for (TopoDS_Iterator it(anEdge.Oriented(TopAbs_FORWARD)); it.More(); it.Next())
904 TopoDS_Shape aV = it.Value();
905 if (aV.Orientation() == TopAbs_FORWARD || aV.Orientation() == TopAbs_REVERSED)
907 if (!aMapVE.Contains(aV))
908 aMapVE.Add(aV, TopTools_ListOfShape());
909 aMapVE.ChangeFromKey(aV).Append(anEdge);
914 VerticesToAvoid.Unite(NonMergVrt);
916 // do loop while there are unused edges
917 TopTools_MapOfShape aUsedEdges;
921 for(j=1; j <= SeqEdges.Length(); j++)
923 edge = TopoDS::Edge(SeqEdges.Value(j));
924 if (!aUsedEdges.Contains(edge))
927 if (j > SeqEdges.Length())
928 break; // all edges have been used
930 // make chain for unite
931 TopTools_SequenceOfShape aChain;
933 aUsedEdges.Add(edge);
935 TopExp::Vertices(edge, V[0], V[1], Standard_True);
937 // connect more edges to the chain in both directions
938 for (j = 0; j < 2; j++)
940 Standard_Boolean isAdded = Standard_True;
943 isAdded = Standard_False;
946 const TopTools_ListOfShape& aLE = aMapVE.FindFromKey(V[j]);
947 for (TopTools_ListIteratorOfListOfShape itL(aLE); itL.More(); itL.Next())
949 edge = TopoDS::Edge(itL.Value());
950 if (!aUsedEdges.Contains(edge))
953 TopExp::Vertices(edge, V2[0], V2[1], Standard_True);
954 // the neighboring edge must have V[j] reversed and located on the opposite end
955 if (V2[1 - j].IsEqual(V[j].Reversed()))
958 aChain.Prepend(edge);
961 aUsedEdges.Add(edge);
963 isAdded = Standard_True;
971 if (aChain.Length() < 2)
974 Standard_Boolean IsClosed = Standard_False;
975 if (V[0].IsSame ( V[1] ))
976 IsClosed = Standard_True;
978 // split chain by vertices at which merging is not possible
979 NCollection_Sequence<SubSequenceOfEdges> aOneSeq;
980 GenerateSubSeq(aChain, aOneSeq, IsClosed, Tol, VerticesToAvoid);
982 // put sub-chains in the result
983 SeqOfSubSeqOfEdges.Append(aOneSeq);
986 for (int i = 1; i <= SeqOfSubSeqOfEdges.Length(); i++)
989 if (SeqOfSubSeqOfEdges(i).SeqsEdges.Length() < 2)
991 if (MergeSubSeq(SeqOfSubSeqOfEdges(i).SeqsEdges, UE, Tol, ConcatBSplines))
992 SeqOfSubSeqOfEdges(i).UnionEdges = UE;
994 return Standard_True;
997 //=======================================================================
998 //function : MergeSeq
999 //purpose : Tries to unify the sequence of edges with the set of another edges
1000 //which lies on the same geometry
1001 //=======================================================================
1003 static Standard_Boolean MergeSeq (TopTools_SequenceOfShape& SeqEdges,
1004 const Standard_Real Tol,
1005 const Standard_Boolean ConcatBSplines,
1006 Handle(ShapeBuild_ReShape)& theContext,
1007 TopTools_DataMapOfShapeShape& theOldShapes,
1008 const TopTools_MapOfShape& nonMergVert,
1009 const TopTools_DataMapOfShapeShape& NewEdges2OldEdges)
1011 NCollection_Sequence<SubSequenceOfEdges> SeqOfSubsSeqOfEdges;
1013 if ( MergeEdges(SeqEdges, Tol, ConcatBSplines, SeqOfSubsSeqOfEdges, nonMergVert) )
1015 for (Standard_Integer i = 1; i <= SeqOfSubsSeqOfEdges.Length(); i++ )
1017 if (SeqOfSubsSeqOfEdges(i).UnionEdges.IsNull())
1019 theContext->Replace(SeqOfSubsSeqOfEdges(i).SeqsEdges(1), SeqOfSubsSeqOfEdges(i).UnionEdges);
1021 for (Standard_Integer j = 2; j <= SeqOfSubsSeqOfEdges(i).SeqsEdges.Length(); j++)
1023 TopoDS_Shape OldEdge = NewEdges2OldEdges(SeqOfSubsSeqOfEdges(i).SeqsEdges(j));
1024 theOldShapes.Bind(OldEdge, SeqOfSubsSeqOfEdges(i).UnionEdges);
1025 theContext->Remove(SeqOfSubsSeqOfEdges(i).SeqsEdges(j));
1028 return Standard_True;
1031 return Standard_False;
1034 //=======================================================================
1035 //function : CheckSharedVertices
1036 //purpose : Checks the sequence of edges on the presence of shared vertex
1037 //=======================================================================
1039 static void CheckSharedVertices(const TopTools_SequenceOfShape& theSeqEdges,
1040 const TopTools_IndexedDataMapOfShapeListOfShape& theMapEdgesVertex,
1041 TopTools_MapOfShape& theShareVertMap)
1043 ShapeAnalysis_Edge sae;
1044 TopTools_SequenceOfShape SeqVertexes;
1045 TopTools_MapOfShape MapVertexes;
1046 for (Standard_Integer k = 1; k <= theSeqEdges.Length(); k++ )
1048 TopoDS_Vertex aV1 = sae.FirstVertex(TopoDS::Edge(theSeqEdges(k)));
1049 TopoDS_Vertex aV2 = sae.LastVertex(TopoDS::Edge(theSeqEdges(k)));
1050 if (!MapVertexes.Add(aV1))
1051 SeqVertexes.Append(aV1);
1052 if (!MapVertexes.Add(aV2))
1053 SeqVertexes.Append(aV2);
1056 for (Standard_Integer k = 1; k <= SeqVertexes.Length()/* && !IsSharedVertexPresent*/; k++ )
1058 const TopTools_ListOfShape& ListEdgesV1 = theMapEdgesVertex.FindFromKey(SeqVertexes(k));
1059 TopTools_MapOfShape aMapOfEdges;
1060 TopTools_ListIteratorOfListOfShape iter(ListEdgesV1);
1061 for (; iter.More(); iter.Next())
1062 aMapOfEdges.Add(iter.Value());
1063 if (aMapOfEdges.Extent() > 2)
1064 theShareVertMap.Add(SeqVertexes(k));
1066 //return theShareVertMap.IsEmpty() ? false : true;
1069 //=======================================================================
1070 //function : ShapeUpgrade_UnifySameDomain
1071 //purpose : Constructor
1072 //=======================================================================
1074 ShapeUpgrade_UnifySameDomain::ShapeUpgrade_UnifySameDomain()
1075 : myUnifyFaces (Standard_True),
1076 myUnifyEdges (Standard_True),
1077 myConcatBSplines (Standard_False),
1078 myAllowInternal (Standard_False)
1080 myContext = new ShapeBuild_ReShape;
1083 //=======================================================================
1084 //function : ShapeUpgrade_UnifySameDomain
1085 //purpose : Constructor
1086 //=======================================================================
1088 ShapeUpgrade_UnifySameDomain::ShapeUpgrade_UnifySameDomain(const TopoDS_Shape& aShape,
1089 const Standard_Boolean UnifyEdges,
1090 const Standard_Boolean UnifyFaces,
1091 const Standard_Boolean ConcatBSplines)
1092 : myInitShape (aShape),
1093 myUnifyFaces (UnifyFaces),
1094 myUnifyEdges (UnifyEdges),
1095 myConcatBSplines (ConcatBSplines),
1096 myAllowInternal (Standard_False),
1099 myContext = new ShapeBuild_ReShape;
1102 //=======================================================================
1103 //function : Initialize
1105 //=======================================================================
1107 void ShapeUpgrade_UnifySameDomain::Initialize(const TopoDS_Shape& aShape,
1108 const Standard_Boolean UnifyEdges,
1109 const Standard_Boolean UnifyFaces,
1110 const Standard_Boolean ConcatBSplines)
1112 myInitShape = aShape;
1114 myUnifyEdges = UnifyEdges;
1115 myUnifyFaces = UnifyFaces;
1116 myConcatBSplines = ConcatBSplines;
1119 myOldShapes.Clear();
1122 //=======================================================================
1123 //function : AllowInternalEdges
1125 //=======================================================================
1127 void ShapeUpgrade_UnifySameDomain::AllowInternalEdges (const Standard_Boolean theValue)
1129 myAllowInternal = theValue;
1132 //=======================================================================
1133 //function : putIntWires
1134 //purpose : Add internal wires that are classified inside the face as a subshape,
1135 // and remove them from the sequence
1136 //=======================================================================
1137 static void putIntWires(TopoDS_Shape& theFace, TopTools_SequenceOfShape& theWires)
1139 TopoDS_Face& aFace = TopoDS::Face(theFace);
1140 for (Standard_Integer i=1; i <= theWires.Length(); i++)
1142 TopoDS_Shape aWire = theWires(i);
1144 Standard_Boolean isP2d = Standard_False;
1145 for (TopoDS_Iterator it(aWire); it.More() && !isP2d; it.Next())
1147 const TopoDS_Edge& anEdge = TopoDS::Edge(it.Value());
1148 Standard_Real aFirst, aLast;
1149 Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface(anEdge, aFace, aFirst, aLast);
1150 aC2d->D0((aFirst + aLast) * 0.5, aP2d);
1151 isP2d = Standard_True;
1153 BRepClass_FaceClassifier aClass(aFace, aP2d, Precision::PConfusion());
1154 if (aClass.State() == TopAbs_IN)
1156 BRep_Builder().Add(aFace, aWire);
1163 //=======================================================================
1164 //function : UnifyFaces
1166 //=======================================================================
1168 void ShapeUpgrade_UnifySameDomain::UnifyFaces()
1170 // creating map of edge faces for the whole shape
1171 TopTools_IndexedDataMapOfShapeListOfShape aGMapEdgeFaces;
1172 TopExp::MapShapesAndAncestors(myShape, TopAbs_EDGE, TopAbs_FACE, aGMapEdgeFaces);
1174 // processing each shell
1175 TopExp_Explorer exps;
1176 for (exps.Init(myShape, TopAbs_SHELL); exps.More(); exps.Next()) {
1177 TopoDS_Shell aShell = TopoDS::Shell(exps.Current());
1179 // creating map of edge faces for the shell
1180 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
1181 TopExp::MapShapesAndAncestors(aShell, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
1183 // map of processed shapes
1184 TopTools_MapOfShape aProcessed;
1186 Standard_Integer NbModif = 0;
1187 Standard_Boolean hasFailed = Standard_False;
1188 Standard_Real tol = Precision::Confusion();
1191 Standard_Integer nbf = 0;
1192 TopExp_Explorer exp;
1193 TopTools_MapOfShape mapF;
1194 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
1195 if (mapF.Add(exp.Current()))
1199 // processing each face
1201 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
1202 TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
1204 if (aProcessed.Contains(aFace))
1207 Standard_Integer dummy;
1208 TopTools_SequenceOfShape edges;
1209 AddOrdinaryEdges(edges,aFace,dummy);
1211 TopTools_SequenceOfShape faces;
1212 faces.Append(aFace);
1214 //surface and location to construct result
1215 TopLoc_Location aBaseLocation;
1216 Handle(Geom_Surface) aBaseSurface = BRep_Tool::Surface(aFace,aBaseLocation);
1217 aBaseSurface = ClearRts(aBaseSurface);
1219 // find adjacent faces to union
1221 for (i = 1; i <= edges.Length(); i++) {
1222 TopoDS_Edge edge = TopoDS::Edge(edges(i));
1223 if (BRep_Tool::Degenerated(edge))
1226 // get connectivity of the edge in the global shape
1227 const TopTools_ListOfShape& aGList = aGMapEdgeFaces.FindFromKey(edge);
1228 if (!myAllowInternal && aGList.Extent() != 2) {
1229 // non mainfold case is not processed unless myAllowInternal
1232 // process faces connected through the edge in the current shell
1233 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
1234 TopTools_ListIteratorOfListOfShape anIter(aList);
1235 for (; anIter.More(); anIter.Next()) {
1236 TopoDS_Face anCheckedFace = TopoDS::Face(anIter.Value().Oriented(TopAbs_FORWARD));
1237 if (anCheckedFace.IsSame(aFace))
1240 if (aProcessed.Contains(anCheckedFace))
1243 if (IsSameDomain(aFace,anCheckedFace)) {
1245 // hotfix for 27271: prevent merging along periodic direction.
1246 if (IsLikeSeam(edge, aFace, aBaseSurface))
1249 // replacing pcurves
1250 TopoDS_Face aMockUpFace;
1252 B.MakeFace(aMockUpFace,aBaseSurface,aBaseLocation,0.);
1253 MovePCurves(aMockUpFace,anCheckedFace);
1255 if (AddOrdinaryEdges(edges,aMockUpFace,dummy)) {
1256 // sequence edges is modified
1260 faces.Append(anCheckedFace);
1261 aProcessed.Add(anCheckedFace);
1267 if (faces.Length() > 1) {
1268 // fill in the connectivity map for selected faces
1269 TopTools_IndexedDataMapOfShapeListOfShape aMapEF;
1270 for (i = 1; i <= faces.Length(); i++) {
1271 TopExp::MapShapesAndAncestors(faces(i), TopAbs_EDGE, TopAbs_FACE, aMapEF);
1274 // Collect multiconnected edges, i.e. edges that are internal to
1275 // the set of selected faces and have connections to other faces.
1276 TopTools_ListOfShape aMultEdges;
1277 for (i = 1; i <= aMapEF.Extent(); i++) {
1278 const TopTools_ListOfShape& aLF = aMapEF(i);
1279 if (aLF.Extent() == 2) {
1280 const TopoDS_Shape& aE = aMapEF.FindKey(i);
1281 const TopTools_ListOfShape& aGLF = aGMapEdgeFaces.FindFromKey(aE);
1282 if (aGLF.Extent() > 2) {
1283 aMultEdges.Append(aE);
1287 if (!aMultEdges.IsEmpty()) {
1288 if (!myAllowInternal) {
1289 // Remove from the selection the faces containing multiconnected edges
1290 TopTools_MapOfShape anAvoidFaces;
1291 TopTools_ListIteratorOfListOfShape it(aMultEdges);
1292 for (; it.More(); it.Next()) {
1293 const TopoDS_Shape& aE = it.Value();
1294 const TopTools_ListOfShape& aLF = aMapEF.FindFromKey(aE);
1295 anAvoidFaces.Add(aLF.First());
1296 anAvoidFaces.Add(aLF.Last());
1298 for (i = 1; i <= faces.Length(); ) {
1299 if (anAvoidFaces.Contains(faces(i))) {
1300 // update the boundaries of merged area, for that
1301 // remove from 'edges' the edges of this face and add to 'edges'
1302 // the edges of this face that were not present in 'edges' before
1303 TopExp_Explorer ex(faces(i), TopAbs_EDGE);
1304 for (; ex.More(); ex.Next()) {
1305 TopoDS_Shape aE = ex.Current();
1307 for (j = 1; j <= edges.Length(); j++) {
1308 if (edges(j).IsSame(aE))
1311 if (j <= edges.Length())
1323 // add multiconnected edges as internal in new face
1324 TopTools_ListIteratorOfListOfShape it(aMultEdges);
1325 for (; it.More(); it.Next()) {
1326 const TopoDS_Shape& aE = it.Value();
1327 edges.Append(aE.Oriented(TopAbs_INTERNAL));
1333 // all faces collected in the sequence. Perform union of faces
1334 if (faces.Length() > 1) {
1336 TopoDS_Face aResult;
1338 B.MakeFace(aResult,aBaseSurface,aBaseLocation,0);
1339 Standard_Integer nbWires = 0;
1341 TopoDS_Face tmpF = TopoDS::Face(myContext->Apply(faces(1).Oriented(TopAbs_FORWARD)));
1343 while (edges.Length()>0) {
1345 Standard_Boolean isEdge3d = Standard_False;
1347 TopTools_MapOfShape aVertices;
1351 TopoDS_Edge anEdge = TopoDS::Edge(edges(1));
1353 // collect internal edges in separate wires
1354 Standard_Boolean isInternal = (anEdge.Orientation() == TopAbs_INTERNAL);
1356 isEdge3d |= !BRep_Tool::Degenerated(anEdge);
1357 B.Add(aWire,anEdge);
1358 TopoDS_Vertex V1,V2;
1359 TopExp::Vertices(anEdge,V1,V2);
1363 Standard_Boolean isNewFound = Standard_False;
1365 isNewFound = Standard_False;
1366 for(Standard_Integer j = 1; j <= edges.Length(); j++) {
1367 anEdge = TopoDS::Edge(edges(j));
1368 // check if the current edge orientation corresponds to the first one
1369 Standard_Boolean isCurrInternal = (anEdge.Orientation() == TopAbs_INTERNAL);
1370 if (isCurrInternal != isInternal)
1372 TopExp::Vertices(anEdge,V1,V2);
1373 if(aVertices.Contains(V1) || aVertices.Contains(V2)) {
1374 isEdge3d |= !BRep_Tool::Degenerated(anEdge);
1377 B.Add(aWire,anEdge);
1380 isNewFound = Standard_True;
1383 } while (isNewFound);
1385 // sorting any type of edges
1386 aWire.Closed (BRep_Tool::IsClosed (aWire));
1387 aWire = TopoDS::Wire(myContext->Apply(aWire));
1389 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(aWire,tmpF,Precision::Confusion());
1391 Standard_Boolean isDegRemoved = Standard_False;
1392 if(!sfw->StatusReorder ( ShapeExtend_FAIL )) {
1393 // clear degenerated edges if at least one with 3d curve exist
1395 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
1396 for(Standard_Integer j = 1; j<=sewd->NbEdges();j++) {
1397 TopoDS_Edge E = sewd->Edge(j);
1398 if(BRep_Tool::Degenerated(E)) {
1400 isDegRemoved = Standard_True;
1407 sfw->FixDegenerated();
1409 TopoDS_Wire aWireFixed = sfw->Wire();
1410 //aContext->Replace(aWire,aWireFixed);
1411 myContext->Replace(aWire,aWireFixed);
1414 if (!myOldNewMap.IsBound(aWire))
1416 TopTools_ListOfShape EmptyList;
1417 myOldNewMap.Bind(aWire, EmptyList);
1419 myOldNewMap(aWire).Clear();
1420 myOldNewMap(aWire).Append(aWireFixed);
1424 // add resulting wire
1426 B.Add(aResult,aWireFixed);
1430 Handle(ShapeExtend_WireData) sbwd = sfw->WireData();
1431 Standard_Integer nbEdges = sbwd->NbEdges();
1432 // sort degenerated edges and create one edge instead of several ones
1433 ShapeAnalysis_WireOrder sawo(Standard_False, 0);
1434 ShapeAnalysis_Edge sae;
1435 Standard_Integer aLastEdge = nbEdges;
1436 for(Standard_Integer j = 1; j <= nbEdges; j++) {
1438 //smh protection on NULL pcurve
1439 Handle(Geom2d_Curve) c2d;
1440 if(!sae.PCurve(sbwd->Edge(j),tmpF,c2d,f,l)) {
1444 sawo.Add(c2d->Value(f).XY(),c2d->Value(l).XY());
1448 // constructind one degenerative edge
1449 gp_XY aStart, anEnd, tmp;
1450 Standard_Integer nbFirst = sawo.Ordered(1);
1451 TopoDS_Edge anOrigE = TopoDS::Edge(sbwd->Edge(nbFirst).Oriented(TopAbs_FORWARD));
1452 ShapeBuild_Edge sbe;
1453 TopoDS_Vertex aDummyV;
1454 TopoDS_Edge E = sbe.CopyReplaceVertices(anOrigE,aDummyV,aDummyV);
1455 sawo.XY(nbFirst,aStart,tmp);
1456 sawo.XY(sawo.Ordered(aLastEdge),tmp,anEnd);
1458 gp_XY aVec = anEnd-aStart;
1459 Handle(Geom2d_Line) aLine = new Geom2d_Line(aStart,gp_Dir2d(anEnd-aStart));
1461 B.UpdateEdge(E,aLine,tmpF,0.);
1462 B.Range(E,tmpF,0.,aVec.Modulus());
1463 Handle(Geom_Curve) C3d;
1464 B.UpdateEdge(E,C3d,0.);
1465 B.Degenerated(E,Standard_True);
1469 aW.Closed (Standard_True);
1474 // perform substitution of face
1475 //aContext->Replace(aContext->Apply(aFace),aResult);
1476 myContext->Replace(myContext->Apply(aFace),aResult);
1479 if (!myOldNewMap.IsBound(aFace))
1481 TopTools_ListOfShape EmptyList;
1482 myOldNewMap.Bind(aFace, EmptyList);
1484 myOldNewMap(aFace).Clear();
1485 myOldNewMap(aFace).Append(aResult);
1489 ShapeFix_Face sff (aResult);
1490 //Intializing by tolerances
1491 sff.SetPrecision(Precision::Confusion());
1492 sff.SetMinTolerance(tol);
1493 sff.SetMaxTolerance(1.);
1495 sff.FixOrientationMode() = 0;
1496 //sff.FixWireMode() = 0;
1497 //sff.SetContext(aContext);
1498 sff.SetContext(myContext);
1499 // Applying the fixes
1501 if(sff.Status(ShapeExtend_FAIL))
1502 hasFailed = Standard_True;
1504 // breaking down to several faces
1505 //TopoDS_Shape theResult = aContext->Apply(aResult);
1506 TopoDS_Shape theResult = myContext->Apply(aResult);
1507 for (TopExp_Explorer aFaceExp (theResult,TopAbs_FACE); aFaceExp.More(); aFaceExp.Next()) {
1508 TopoDS_Face aCurrent = TopoDS::Face(aFaceExp.Current().Oriented(TopAbs_FORWARD));
1509 Handle(TColGeom_HArray2OfSurface) grid = new TColGeom_HArray2OfSurface ( 1, 1, 1, 1 );
1510 grid->SetValue ( 1, 1, aBaseSurface );
1511 Handle(ShapeExtend_CompositeSurface) G = new ShapeExtend_CompositeSurface ( grid );
1512 ShapeFix_ComposeShell CompShell;
1513 CompShell.Init ( G, aBaseLocation, aCurrent, ::Precision::Confusion() );//myPrecision
1514 //CompShell.SetContext( aContext );
1515 CompShell.SetContext( myContext );
1517 TopTools_SequenceOfShape parts, anIntWires;
1518 ShapeFix_SequenceOfWireSegment wires;
1519 for(TopExp_Explorer W_Exp(aCurrent,TopAbs_WIRE);W_Exp.More();W_Exp.Next()) {
1520 const TopoDS_Wire& aWire = TopoDS::Wire(W_Exp.Current());
1521 // check if the wire is ordinary (contains non-internal edges)
1522 Standard_Boolean isInternal = Standard_True;
1523 for (TopoDS_Iterator it(aWire); it.More() && isInternal; it.Next())
1524 isInternal = (it.Value().Orientation() == TopAbs_INTERNAL);
1527 // place internal wire separately
1528 anIntWires.Append(aWire);
1532 Handle(ShapeExtend_WireData) sbwd =
1533 new ShapeExtend_WireData (aWire);
1534 ShapeFix_WireSegment seg ( sbwd, TopAbs_REVERSED );
1539 CompShell.DispatchWires ( parts,wires );
1540 for (Standard_Integer j=1; j <= parts.Length(); j++ ) {
1541 ShapeFix_Face aFixOrient(TopoDS::Face(parts(j)));
1542 //aFixOrient.SetContext(aContext);
1543 aFixOrient.SetContext(myContext);
1544 aFixOrient.FixOrientation();
1545 // put internal wires to faces
1546 putIntWires(parts(j), anIntWires);
1549 TopoDS_Shape CompRes;
1550 if ( parts.Length() !=1 ) {
1553 for ( i=1; i <= parts.Length(); i++ )
1554 B.Add ( S, parts(i) );
1555 S.Closed (BRep_Tool::IsClosed (S));
1558 else CompRes = parts(1);
1560 //aContext->Replace(aCurrent,CompRes);
1561 myContext->Replace(aCurrent,CompRes);
1564 if (!myOldNewMap.IsBound(aCurrent))
1566 TopTools_ListOfShape EmptyList;
1567 myOldNewMap.Bind(aCurrent, EmptyList);
1569 myOldNewMap(aCurrent).Clear();
1570 myOldNewMap(aCurrent).Append(CompRes);
1575 // remove the remaining faces
1576 for(i = 2; i <= faces.Length(); i++)
1578 myOldShapes.Bind(faces(i), theResult);
1579 myContext->Remove(faces(i));
1582 } // end processing each face
1584 //TopoDS_Shape aResult = Shape;
1585 if (NbModif > 0 && !hasFailed) {
1586 //TopoDS_Shape aResult = aContext->Apply(aShell);
1587 TopoDS_Shape aResult = myContext->Apply(aShell);
1590 if (!myContext.IsNull()) sfe.SetContext(myContext);
1591 for (exp.Init(aResult,TopAbs_EDGE); exp.More(); exp.Next()) {
1592 TopoDS_Edge E = TopoDS::Edge(exp.Current());
1593 sfe.FixVertexTolerance (E);
1594 // ptv add fix same parameter
1595 sfe.FixSameParameter(E, Precision::Confusion());
1598 myContext->Replace(aShell, aResult);
1601 if (!myOldNewMap.IsBound(aShell))
1603 TopTools_ListOfShape EmptyList;
1604 myOldNewMap.Bind(aShell, EmptyList);
1606 myOldNewMap(aShell).Clear();
1607 myOldNewMap(aShell).Append(aResult);
1613 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
1614 TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
1615 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
1616 sfw->SetContext(myContext);
1617 sfw->SetPrecision(Precision::Confusion());
1618 sfw->SetMinTolerance(Precision::Confusion());
1619 sfw->SetMaxTolerance(1.);
1620 sfw->SetFace(aFace);
1621 for (TopoDS_Iterator iter (aFace,Standard_False); iter.More(); iter.Next()) {
1622 TopoDS_Wire wire = TopoDS::Wire(iter.Value());
1629 } // end processing each shell
1631 myShape = myContext->Apply(myShape);
1634 //=======================================================================
1635 //function : UnifyEdges
1637 //=======================================================================
1638 void ShapeUpgrade_UnifySameDomain::UnifyEdges()
1640 Standard_Real Tol = Precision::Confusion();
1642 //Handle(ShapeBuild_ReShape) myContext = new ShapeBuild_ReShape;
1643 Standard_Real myTolerance = Precision::Confusion();
1644 TopoDS_Shape aResult = myContext->Apply(myShape);
1646 TopTools_IndexedMapOfShape ChangedFaces;
1648 // creating map of edge faces
1649 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
1650 TopExp::MapShapesAndAncestors(myShape, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
1652 // creating map of vertex edges
1653 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgesVertex;
1654 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMapEdgesVertex);
1656 //Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
1657 TopoDS_Shape aRes = myShape;
1658 //aRes = aContext->Apply(aSolid);
1659 aRes = myContext->Apply(myShape);
1661 TopTools_MapOfShape SharedVert;
1664 TopTools_IndexedMapOfShape anOldEdges;
1665 TopExp::MapShapes(myInitShape, TopAbs_EDGE, anOldEdges);
1667 TopTools_DataMapOfShapeShape NewEdges2OldEdges;
1668 for (int i = 1; i <= anOldEdges.Extent(); i++)
1670 TopoDS_Shape NewEdge = myContext->Apply(anOldEdges(i));
1671 if (!NewEdge.IsNull())
1672 NewEdges2OldEdges.Bind(NewEdge, anOldEdges(i));
1675 TopExp_Explorer exp;
1676 // processing separate wires
1677 for (exp.Init(aRes, TopAbs_WIRE, TopAbs_FACE); exp.More(); exp.Next())
1679 TopTools_SequenceOfShape SeqEdges;
1680 TopExp_Explorer expE(exp.Current(), TopAbs_EDGE);
1681 for (; expE.More(); expE.Next())
1682 SeqEdges.Append(expE.Current());
1684 CheckSharedVertices(SeqEdges, aMapEdgesVertex, SharedVert);
1685 MergeSeq(SeqEdges, Tol, myConcatBSplines, myContext, myOldShapes, SharedVert, NewEdges2OldEdges);
1688 TopTools_DataMapOfShapeShape oldFaces2NewFaces;
1689 for (exp.Init(myShape, TopAbs_FACE); exp.More(); exp.Next())
1691 const TopoDS_Face& f = TopoDS::Face(exp.Current());
1692 TopoDS_Face NewF = TopoDS::Face(myContext->Apply(f));
1694 oldFaces2NewFaces.Bind(f, NewF);
1697 // processing each face
1698 for (exp.Init(aRes, TopAbs_FACE); exp.More(); exp.Next()) {
1699 //TopoDS_Face aFace = TopoDS::Face(aContext->Apply(exp.Current().Oriented(TopAbs_FORWARD)));
1700 TopoDS_Face aFace = TopoDS::Face(myContext->Apply(exp.Current().Oriented(TopAbs_FORWARD)));
1701 TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
1702 TopTools_SequenceOfShape aNonSharedEdges;
1703 for (TopExp_Explorer expe(aFace,TopAbs_EDGE); expe.More(); expe.Next()) {
1704 TopoDS_Edge edge = TopoDS::Edge(expe.Current());
1705 if (!aMapEdgeFaces.Contains(edge)) continue;
1706 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
1707 TopTools_ListIteratorOfListOfShape anIter(aList);
1708 Standard_Integer NbFacesPerEdge = aList.Extent();
1709 for ( ; anIter.More(); anIter.Next()) {
1710 TopoDS_Face face = TopoDS::Face(anIter.Value());
1711 TopoDS_Face face1 = TopoDS::Face(oldFaces2NewFaces(anIter.Value()));
1712 if (face1.IsSame(aFace) && NbFacesPerEdge != 1)
1714 if (NbFacesPerEdge == 1)
1715 //store non-shared edges separately
1716 aNonSharedEdges.Append(edge);
1719 if (aMapFacesEdges.Contains(face))
1720 aMapFacesEdges.ChangeFromKey(face).Append(edge);
1723 TopTools_ListOfShape ListEdges;
1724 ListEdges.Append(edge);
1725 aMapFacesEdges.Add(face,ListEdges);
1731 for (Standard_Integer i=1; i<=aMapFacesEdges.Extent(); i++)
1733 const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
1734 TopTools_SequenceOfShape SeqEdges;
1735 TopTools_ListIteratorOfListOfShape anIter(ListEdges);
1736 for ( ; anIter.More(); anIter.Next())
1737 SeqEdges.Append(anIter.Value());
1738 if (SeqEdges.Length()==1)
1742 CheckSharedVertices(SeqEdges, aMapEdgesVertex, SharedVert);
1743 //if (!SharedVert.IsEmpty())
1745 if ( MergeSeq(SeqEdges,Tol,myConcatBSplines, myContext, myOldShapes, SharedVert, NewEdges2OldEdges) )
1749 for (j = 1; j <= SeqEdges.Length(); j++)
1751 if (!myOldNewMap.IsBound(SeqEdges(j)))
1753 TopTools_ListOfShape EmptyList;
1754 myOldNewMap.Bind(SeqEdges(j), EmptyList);
1756 myOldNewMap(SeqEdges(j)).Clear();
1757 myOldNewMap(SeqEdges(j)).Append(E);
1762 TopoDS_Face tmpF = TopoDS::Face(exp.Current());
1763 if ( !ChangedFaces.Contains(tmpF) )
1764 ChangedFaces.Add(tmpF);
1765 tmpF = TopoDS::Face(aMapFacesEdges.FindKey(i));
1766 if ( !ChangedFaces.Contains(tmpF) )
1767 ChangedFaces.Add(tmpF);
1771 if ( aNonSharedEdges.Length() > 1 )
1774 CheckSharedVertices(aNonSharedEdges, aMapEdgesVertex, SharedVert);
1775 if ( MergeSeq(aNonSharedEdges, Tol, myConcatBSplines, myContext, myOldShapes, SharedVert, NewEdges2OldEdges) )
1777 TopoDS_Face tmpF = TopoDS::Face(exp.Current());
1778 if ( !ChangedFaces.Contains(tmpF) )
1779 ChangedFaces.Add(tmpF);
1783 } // end processing each face
1785 // fix changed faces and replace them in the local context
1786 for (Standard_Integer i=1; i<=ChangedFaces.Extent(); i++) {
1787 //TopoDS_Face aFace = TopoDS::Face(aContext->Apply(ChangedFaces.FindKey(i)));
1788 TopoDS_Face aFace = TopoDS::Face(myContext->Apply(ChangedFaces.FindKey(i)));
1791 Handle(ShapeFix_Face) sff = new ShapeFix_Face(aFace);
1792 sff->SetContext(myContext);
1793 sff->SetPrecision(myTolerance);
1794 sff->SetMinTolerance(myTolerance);
1795 sff->SetMaxTolerance(Max(1.,myTolerance*1000.));
1797 TopoDS_Shape aNewFace = sff->Face();
1798 //aContext->Replace(aFace,aNewFace);
1799 myContext->Replace(aFace,aNewFace);
1802 if (!myOldNewMap.IsBound(aFace))
1804 TopTools_ListOfShape EmptyList;
1805 myOldNewMap.Bind(aFace, EmptyList);
1807 myOldNewMap(aFace).Clear();
1808 myOldNewMap(aFace).Append(aNewFace);
1813 if (ChangedFaces.Extent() > 0) {
1814 // fix changed shell and replace it in the local context
1815 //TopoDS_Shape aRes1 = aContext->Apply(aRes);
1816 TopoDS_Shape aRes1 = myContext->Apply(aRes);
1817 TopExp_Explorer expsh;
1818 for (expsh.Init(aRes1, TopAbs_SHELL); expsh.More(); expsh.Next()) {
1819 TopoDS_Shell aShell = TopoDS::Shell(expsh.Current());
1820 Handle(ShapeFix_Shell) sfsh = new ShapeFix_Shell;
1821 sfsh->FixFaceOrientation(aShell);
1822 TopoDS_Shape aNewShell = sfsh->Shell();
1823 //aContext->Replace(aShell,aNewShell);
1824 myContext->Replace(aShell,aNewShell);
1827 if (!myOldNewMap.IsBound(aShell))
1829 TopTools_ListOfShape EmptyList;
1830 myOldNewMap.Bind(aShell, EmptyList);
1832 myOldNewMap(aShell).Clear();
1833 myOldNewMap(aShell).Append(aNewShell);
1837 //TopoDS_Shape aRes2 = aContext->Apply(aRes1);
1838 TopoDS_Shape aRes2 = myContext->Apply(aRes1);
1839 myContext->Replace(myShape,aRes2);
1842 if (!myOldNewMap.IsBound(aSolid))
1844 TopTools_ListOfShape EmptyList;
1845 myOldNewMap.Bind(aSolid, EmptyList);
1847 myOldNewMap(aSolid).Clear();
1848 myOldNewMap(aSolid).Append(aRes2);
1853 myShape = myContext->Apply(myShape);
1856 //=======================================================================
1857 //function : UnifyFacesAndEdges
1859 //=======================================================================
1861 void ShapeUpgrade_UnifySameDomain::UnifyFacesAndEdges()
1866 ShapeUpgrade_RemoveLocations RemLoc;
1867 RemLoc.Remove(myShape);
1868 myShape = RemLoc.GetResult();
1874 //=======================================================================
1876 //purpose : builds the resulting shape
1877 //======================================================================
1878 void ShapeUpgrade_UnifySameDomain::Build()
1880 if (myUnifyFaces && myUnifyEdges)
1881 UnifyFacesAndEdges();
1883 else if (myUnifyEdges)
1885 else if (myUnifyFaces)
1891 //=======================================================================
1893 //purpose : give the resulting shape
1894 //=======================================================================
1895 const TopoDS_Shape& ShapeUpgrade_UnifySameDomain::Shape() const
1900 //=======================================================================
1901 //function : Generated
1902 //purpose : returns the new shape from the old one
1903 //=======================================================================
1904 TopoDS_Shape ShapeUpgrade_UnifySameDomain::Generated(const TopoDS_Shape& aShape) const
1906 TopoDS_Shape aNewShape = myContext->Apply(aShape);
1908 if (aNewShape.IsNull())
1909 aNewShape = myContext->Apply(myOldShapes(aShape));