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.
16 #include <ShapeUpgrade_UnifySameDomain.ixx>
17 #include <ShapeUpgrade_UnifySameDomain.hxx>
18 #include <TopTools_SequenceOfShape.hxx>
19 #include <TopTools_IndexedMapOfShape.hxx>
20 #include <TopExp_Explorer.hxx>
21 #include <Geom_Surface.hxx>
22 #include <Geom_Line.hxx>
24 #include <Geom_CylindricalSurface.hxx>
25 #include <gp_Cylinder.hxx>
26 #include <Geom_SurfaceOfRevolution.hxx>
27 #include <Geom_SurfaceOfLinearExtrusion.hxx>
29 #include <Geom_Circle.hxx>
30 #include <Geom_RectangularTrimmedSurface.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <BRep_Tool.hxx>
33 #include <GeomAdaptor_HSurface.hxx>
34 #include <BRepTopAdaptor_TopolTool.hxx>
35 #include <IntPatch_ImpImpIntersection.hxx>
36 #include <GeomLib_IsPlanarSurface.hxx>
37 #include <BRep_Builder.hxx>
38 #include <ShapeFix_Wire.hxx>
40 #include <ShapeAnalysis_Edge.hxx>
41 #include <TopoDS_Edge.hxx>
42 #include <TColGeom_SequenceOfSurface.hxx>
43 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
44 #include <BRep_TEdge.hxx>
45 #include <BRep_CurveRepresentation.hxx>
46 #include <TColGeom_Array1OfBSplineCurve.hxx>
47 #include <TColGeom_HArray1OfBSplineCurve.hxx>
48 #include <TColGeom2d_Array1OfBSplineCurve.hxx>
49 #include <TColGeom2d_HArray1OfBSplineCurve.hxx>
50 #include <TColStd_Array1OfReal.hxx>
52 #include <Geom_TrimmedCurve.hxx>
53 #include <Geom2d_TrimmedCurve.hxx>
54 #include <GeomConvert.hxx>
55 #include <Geom2dConvert.hxx>
56 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
57 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
58 #include <TColGeom2d_SequenceOfBoundedCurve.hxx>
59 #include <BRepLib_MakeEdge.hxx>
60 #include <TColStd_MapOfInteger.hxx>
61 #include <BRepLib.hxx>
62 #include <GC_MakeCircle.hxx>
63 #include <Geom_BezierCurve.hxx>
64 #include <ShapeBuild_ReShape.hxx>
65 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
66 #include <TopTools_MapOfShape.hxx>
67 #include <TopTools_ListIteratorOfListOfShape.hxx>
68 #include <ShapeAnalysis_WireOrder.hxx>
69 #include <ShapeBuild_Edge.hxx>
70 #include <Geom2d_Line.hxx>
71 #include <ShapeFix_Face.hxx>
72 #include <TColGeom_HArray2OfSurface.hxx>
73 #include <ShapeExtend_CompositeSurface.hxx>
74 #include <ShapeFix_ComposeShell.hxx>
75 #include <ShapeFix_SequenceOfWireSegment.hxx>
76 #include <ShapeFix_WireSegment.hxx>
77 #include <ShapeFix_Edge.hxx>
78 #include <ShapeFix_Shell.hxx>
79 #include <ShapeUpgrade_RemoveLocations.hxx>
82 //=======================================================================
83 //function : AddOrdinaryEdges
85 //=======================================================================
86 // adds edges from the shape to the sequence
87 // seams and equal edges are dropped
88 // Returns true if one of original edges dropped
89 static Standard_Boolean AddOrdinaryEdges(TopTools_SequenceOfShape& edges,
90 const TopoDS_Shape aShape,
91 Standard_Integer& anIndex)
94 TopTools_IndexedMapOfShape aNewEdges;
95 //add edges without seams
96 for(TopExp_Explorer exp(aShape,TopAbs_EDGE); exp.More(); exp.Next()) {
97 TopoDS_Shape edge = exp.Current();
98 if(aNewEdges.Contains(edge))
100 //aNewEdges.Remove(edge);
101 TopoDS_Shape LastEdge = aNewEdges(aNewEdges.Extent());
102 aNewEdges.RemoveLast();
103 if (aNewEdges.FindIndex(edge) != 0)
104 aNewEdges.Substitute(aNewEdges.FindIndex(edge), LastEdge);
105 /////////////////////////
111 Standard_Boolean isDropped = Standard_False;
112 //merge edges and drop seams
114 for (i = 1; i <= edges.Length(); i++) {
115 TopoDS_Shape current = edges(i);
116 if(aNewEdges.Contains(current)) {
118 //aNewEdges.Remove(current);
119 TopoDS_Shape LastEdge = aNewEdges(aNewEdges.Extent());
120 aNewEdges.RemoveLast();
121 if (aNewEdges.FindIndex(current) != 0)
122 aNewEdges.Substitute(aNewEdges.FindIndex(current), LastEdge);
123 /////////////////////////
128 isDropped = Standard_True;
134 //add edges to the sequemce
135 for (i = 1; i <= aNewEdges.Extent(); i++)
136 edges.Append(aNewEdges(i));
141 //=======================================================================
142 //function : getCylinder
144 //=======================================================================
145 static Standard_Boolean getCylinder(Handle(Geom_Surface)& theInSurface,
146 gp_Cylinder& theOutCylinder)
148 Standard_Boolean isCylinder = Standard_False;
150 if (theInSurface->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
151 Handle(Geom_CylindricalSurface) aGC = Handle(Geom_CylindricalSurface)::DownCast(theInSurface);
153 theOutCylinder = aGC->Cylinder();
154 isCylinder = Standard_True;
156 else if (theInSurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
157 Handle(Geom_SurfaceOfRevolution) aRS =
158 Handle(Geom_SurfaceOfRevolution)::DownCast(theInSurface);
159 Handle(Geom_Curve) aBasis = aRS->BasisCurve();
160 if (aBasis->IsKind(STANDARD_TYPE(Geom_Line))) {
161 Handle(Geom_Line) aBasisLine = Handle(Geom_Line)::DownCast(aBasis);
162 gp_Dir aDir = aRS->Direction();
163 gp_Dir aBasisDir = aBasisLine->Position().Direction();
164 if (aBasisDir.IsParallel(aDir, Precision::Angular())) {
165 // basis line is parallel to the revolution axis: it is a cylinder
166 gp_Pnt aLoc = aRS->Location();
167 Standard_Real aR = aBasisLine->Lin().Distance(aLoc);
168 gp_Ax3 aCylAx (aLoc, aDir);
170 theOutCylinder = gp_Cylinder(aCylAx, aR);
171 isCylinder = Standard_True;
175 else if (theInSurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) {
176 Handle(Geom_SurfaceOfLinearExtrusion) aLES =
177 Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(theInSurface);
178 Handle(Geom_Curve) aBasis = aLES->BasisCurve();
179 if (aBasis->IsKind(STANDARD_TYPE(Geom_Circle))) {
180 Handle(Geom_Circle) aBasisCircle = Handle(Geom_Circle)::DownCast(aBasis);
181 gp_Dir aDir = aLES->Direction();
182 gp_Dir aBasisDir = aBasisCircle->Position().Direction();
183 if (aBasisDir.IsParallel(aDir, Precision::Angular())) {
184 // basis circle is normal to the extrusion axis: it is a cylinder
185 gp_Pnt aLoc = aBasisCircle->Location();
186 Standard_Real aR = aBasisCircle->Radius();
187 gp_Ax3 aCylAx (aLoc, aDir);
189 theOutCylinder = gp_Cylinder(aCylAx, aR);
190 isCylinder = Standard_True;
200 //=======================================================================
201 //function : ClearRts
203 //=======================================================================
204 static Handle(Geom_Surface) ClearRts(const Handle(Geom_Surface)& aSurface)
206 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
207 Handle(Geom_RectangularTrimmedSurface) rts =
208 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
209 return rts->BasisSurface();
214 //=======================================================================
215 //function : IsSameDomain
217 //=======================================================================
218 static Standard_Boolean IsSameDomain(const TopoDS_Face& aFace,
219 const TopoDS_Face& aCheckedFace)
221 //checking the same handles
222 TopLoc_Location L1, L2;
223 Handle(Geom_Surface) S1, S2;
225 S1 = BRep_Tool::Surface(aFace,L1);
226 S2 = BRep_Tool::Surface(aCheckedFace,L2);
228 if (S1 == S2 && L1 == L2)
229 return Standard_True;
231 // planar and cylindrical cases (IMP 20052)
232 Standard_Real aPrec = Precision::Confusion();
234 S1 = BRep_Tool::Surface(aFace);
235 S2 = BRep_Tool::Surface(aCheckedFace);
240 //Handle(Geom_OffsetSurface) aGOFS1, aGOFS2;
241 //aGOFS1 = Handle(Geom_OffsetSurface)::DownCast(S1);
242 //aGOFS2 = Handle(Geom_OffsetSurface)::DownCast(S2);
243 //if (!aGOFS1.IsNull()) S1 = aGOFS1->BasisSurface();
244 //if (!aGOFS2.IsNull()) S2 = aGOFS2->BasisSurface();
246 // case of two elementary surfaces: use OCCT tool
247 // elementary surfaces: ConicalSurface, CylindricalSurface,
248 // Plane, SphericalSurface and ToroidalSurface
249 if (S1->IsKind(STANDARD_TYPE(Geom_ElementarySurface)) &&
250 S2->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
252 Handle(GeomAdaptor_HSurface) aGA1 = new GeomAdaptor_HSurface(S1);
253 Handle(GeomAdaptor_HSurface) aGA2 = new GeomAdaptor_HSurface(S2);
255 Handle(BRepTopAdaptor_TopolTool) aTT1 = new BRepTopAdaptor_TopolTool();
256 Handle(BRepTopAdaptor_TopolTool) aTT2 = new BRepTopAdaptor_TopolTool();
259 IntPatch_ImpImpIntersection anIIInt (aGA1, aTT1, aGA2, aTT2, aPrec, aPrec);
260 if (!anIIInt.IsDone() || anIIInt.IsEmpty())
261 return Standard_False;
263 return anIIInt.TangentFaces();
265 catch (Standard_Failure) {
266 return Standard_False;
270 // case of two planar surfaces:
271 // all kinds of surfaces checked, including b-spline and bezier
272 GeomLib_IsPlanarSurface aPlanarityChecker1 (S1, aPrec);
273 if (aPlanarityChecker1.IsPlanar()) {
274 GeomLib_IsPlanarSurface aPlanarityChecker2 (S2, aPrec);
275 if (aPlanarityChecker2.IsPlanar()) {
276 gp_Pln aPln1 = aPlanarityChecker1.Plan();
277 gp_Pln aPln2 = aPlanarityChecker2.Plan();
279 if (aPln1.Position().Direction().IsParallel(aPln2.Position().Direction(),Precision::Angular()) &&
280 aPln1.Distance(aPln2) < aPrec) {
281 return Standard_True;
286 // case of two cylindrical surfaces, at least one of which is a swept surface
287 // swept surfaces: SurfaceOfLinearExtrusion, SurfaceOfRevolution
288 if ((S1->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ||
289 S1->IsKind(STANDARD_TYPE(Geom_SweptSurface))) &&
290 (S2->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ||
291 S2->IsKind(STANDARD_TYPE(Geom_SweptSurface))))
293 gp_Cylinder aCyl1, aCyl2;
294 if (getCylinder(S1, aCyl1) && getCylinder(S2, aCyl2)) {
295 if (fabs(aCyl1.Radius() - aCyl2.Radius()) < aPrec) {
296 gp_Dir aDir1 = aCyl1.Position().Direction();
297 gp_Dir aDir2 = aCyl2.Position().Direction();
298 if (aDir1.IsParallel(aDir2, Precision::Angular())) {
299 gp_Pnt aLoc1 = aCyl1.Location();
300 gp_Pnt aLoc2 = aCyl2.Location();
301 gp_Vec aVec12 (aLoc1, aLoc2);
302 if (aVec12.SquareMagnitude() < aPrec*aPrec ||
303 aVec12.IsParallel(aDir1, Precision::Angular())) {
304 return Standard_True;
311 return Standard_False;
314 //=======================================================================
315 //function : MovePCurves
317 //=======================================================================
318 static void MovePCurves(TopoDS_Face& aTarget,
319 const TopoDS_Face& aSource)
322 for(TopExp_Explorer wexp(aSource,TopAbs_WIRE);wexp.More();wexp.Next()) {
323 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(TopoDS::Wire(wexp.Current()),
324 aTarget, Precision::Confusion());
326 Standard_Boolean isReoredFailed = sfw->StatusReorder ( ShapeExtend_FAIL );
327 sfw->FixEdgeCurves();
332 sfw->FixDegenerated();
334 // remove degenerated edges from not degenerated points
335 ShapeAnalysis_Edge sae;
336 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
337 for(Standard_Integer i = 1; i<=sewd->NbEdges();i++) {
338 TopoDS_Edge E = sewd->Edge(i);
339 if(BRep_Tool::Degenerated(E)&&!sae.HasPCurve(E,aTarget)) {
345 TopoDS_Wire ResWire = sfw->Wire();
346 B.Add(aTarget,ResWire);
350 //=======================================================================
351 //function : GlueEdgesWithPCurves
352 //purpose : Glues the pcurves of the sequence of edges
353 // and glues their 3d curves
354 //=======================================================================
355 static TopoDS_Edge GlueEdgesWithPCurves(const TopTools_SequenceOfShape& aChain,
356 const TopoDS_Vertex& FirstVertex,
357 const TopoDS_Vertex& LastVertex)
359 Standard_Integer i, j;
361 TopoDS_Edge FirstEdge = TopoDS::Edge(aChain(1));
362 //TColGeom2d_SequenceOfCurve PCurveSeq;
363 TColGeom_SequenceOfSurface SurfSeq;
364 //TopTools_SequenceOfShape LocSeq;
366 BRep_ListIteratorOfListOfCurveRepresentation itr( (Handle(BRep_TEdge)::DownCast(FirstEdge.TShape()))->Curves() );
367 for (; itr.More(); itr.Next())
369 Handle(BRep_CurveRepresentation) CurveRep = itr.Value();
370 if (CurveRep->IsCurveOnSurface())
372 //PCurveSeq.Append(CurveRep->PCurve());
373 SurfSeq.Append(CurveRep->Surface());
375 TopoDS_Shape aLocShape;
376 aLocShape.Location(CurveRep->Location());
377 LocSeq.Append(aLocShape);
382 Standard_Real fpar, lpar;
383 BRep_Tool::Range(FirstEdge, fpar, lpar);
384 TopoDS_Edge PrevEdge = FirstEdge;
386 Standard_Real MaxTol = 0.;
391 Standard_Integer nb_curve = aChain.Length(); //number of curves
392 TColGeom_Array1OfBSplineCurve tab_c3d(0,nb_curve-1); //array of the curves
393 TColStd_Array1OfReal tabtolvertex(0,nb_curve-1); //(0,nb_curve-2); //array of the tolerances
395 TopoDS_Vertex PrevVertex = FirstVertex;
396 for (i = 1; i <= nb_curve; i++)
398 TopoDS_Edge anEdge = TopoDS::Edge(aChain(i));
399 TopoDS_Vertex VF, VL;
400 TopExp::Vertices(anEdge, VF, VL);
401 Standard_Boolean ToReverse = (!VF.IsSame(PrevVertex));
403 Standard_Real Tol1 = BRep_Tool::Tolerance(VF);
404 Standard_Real Tol2 = BRep_Tool::Tolerance(VL);
412 TopExp::CommonVertex(PrevEdge, anEdge, CV);
413 Standard_Real Tol = BRep_Tool::Tolerance(CV);
414 tabtolvertex(i-2) = Tol;
417 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, fpar, lpar);
418 Handle(Geom_TrimmedCurve) aTrCurve = new Geom_TrimmedCurve(aCurve, fpar, lpar);
419 tab_c3d(i-1) = GeomConvert::CurveToBSplineCurve(aTrCurve);
420 GeomConvert::C0BSplineToC1BSplineCurve(tab_c3d(i-1), Precision::Confusion());
422 tab_c3d(i-1)->Reverse();
423 PrevVertex = (ToReverse)? VF : VL;
426 Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves
427 Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex
428 GeomConvert::ConcatC1(tab_c3d,
433 Precision::Confusion()); //C1 concatenation
435 if (concatcurve->Length() > 1)
437 GeomConvert_CompCurveToBSplineCurve Concat(concatcurve->Value(concatcurve->Lower()));
439 for (i = concatcurve->Lower()+1; i <= concatcurve->Upper(); i++)
440 Concat.Add( concatcurve->Value(i), MaxTol, Standard_True );
442 concatcurve->SetValue(concatcurve->Lower(), Concat.BSplineCurve());
444 Handle(Geom_BSplineCurve) ResCurve = concatcurve->Value(concatcurve->Lower());
446 TColGeom2d_SequenceOfBoundedCurve ResPCurves;
447 TopLoc_Location aLoc;
448 for (j = 1; j <= SurfSeq.Length(); j++)
450 TColGeom2d_Array1OfBSplineCurve tab_c2d(0,nb_curve-1); //array of the pcurves
452 PrevVertex = FirstVertex;
453 PrevEdge = FirstEdge;
454 //TopLoc_Location theLoc = LocSeq(j).Location();
455 for (i = 1; i <= nb_curve; i++)
457 TopoDS_Edge anEdge = TopoDS::Edge(aChain(i));
458 TopoDS_Vertex VF, VL;
459 TopExp::Vertices(anEdge, VF, VL);
460 Standard_Boolean ToReverse = (!VF.IsSame(PrevVertex));
463 Handle(Geom2d_Curve) aPCurve =
464 BRep_Tool::CurveOnSurface(anEdge, SurfSeq(j), anEdge.Location()*theLoc, fpar, lpar);
466 Handle(Geom2d_Curve) aPCurve =
467 BRep_Tool::CurveOnSurface(anEdge, SurfSeq(j), aLoc, fpar, lpar);
468 Handle(Geom2d_TrimmedCurve) aTrPCurve = new Geom2d_TrimmedCurve(aPCurve, fpar, lpar);
469 tab_c2d(i-1) = Geom2dConvert::CurveToBSplineCurve(aTrPCurve);
470 Geom2dConvert::C0BSplineToC1BSplineCurve(tab_c2d(i-1), Precision::Confusion());
472 tab_c2d(i-1)->Reverse();
473 PrevVertex = (ToReverse)? VF : VL;
476 Handle(TColGeom2d_HArray1OfBSplineCurve) concatc2d; //array of the concatenated curves
477 Handle(TColStd_HArray1OfInteger) ArrayOfInd2d; //array of the remining Vertex
478 Geom2dConvert::ConcatC1(tab_c2d,
483 Precision::Confusion()); //C1 concatenation
485 if (concatc2d->Length() > 1)
487 Geom2dConvert_CompCurveToBSplineCurve Concat2d(concatc2d->Value(concatc2d->Lower()));
489 for (i = concatc2d->Lower()+1; i <= concatc2d->Upper(); i++)
490 Concat2d.Add( concatc2d->Value(i), MaxTol, Standard_True );
492 concatc2d->SetValue(concatc2d->Lower(), Concat2d.BSplineCurve());
494 Handle(Geom2d_BSplineCurve) aResPCurve = concatc2d->Value(concatc2d->Lower());
495 ResPCurves.Append(aResPCurve);
498 ResEdge = BRepLib_MakeEdge(ResCurve,
499 FirstVertex, LastVertex,
500 ResCurve->FirstParameter(), ResCurve->LastParameter());
501 BB.SameRange(ResEdge, Standard_False);
502 BB.SameParameter(ResEdge, Standard_False);
503 for (j = 1; j <= ResPCurves.Length(); j++)
505 BB.UpdateEdge(ResEdge, ResPCurves(j), SurfSeq(j), aLoc, MaxTol);
506 BB.Range(ResEdge, SurfSeq(j), aLoc, ResPCurves(j)->FirstParameter(), ResPCurves(j)->LastParameter());
509 BRepLib::SameParameter(ResEdge, MaxTol, Standard_True);
514 //=======================================================================
515 //function : MergeEdges
517 //=======================================================================
518 static Standard_Boolean MergeEdges(const TopTools_SequenceOfShape& SeqEdges,
519 const TopoDS_Face& /*aFace*/,
520 const Standard_Real Tol,
521 const Standard_Boolean ConcatBSplines,
524 // make chain for union
526 ShapeAnalysis_Edge sae;
527 TopoDS_Edge FirstE = TopoDS::Edge(SeqEdges.Value(1));
528 TopoDS_Edge LastE = FirstE;
529 TopoDS_Vertex VF = sae.FirstVertex(FirstE);
530 TopoDS_Vertex VL = sae.LastVertex(LastE);
531 TopTools_SequenceOfShape aChain;
532 aChain.Append(FirstE);
533 TColStd_MapOfInteger IndUsedEdges;
536 for (j = 1; j <= SeqEdges.Length(); j++)
538 TopoDS_Edge anEdge = TopoDS::Edge(SeqEdges(j));
539 if (BRep_Tool::Degenerated(anEdge))
540 return Standard_False;
543 for(j=2; j<=SeqEdges.Length(); j++) {
544 for(Standard_Integer k=2; k<=SeqEdges.Length(); k++) {
545 if(IndUsedEdges.Contains(k)) continue;
546 TopoDS_Edge edge = TopoDS::Edge(SeqEdges.Value(k));
547 TopoDS_Vertex VF2 = sae.FirstVertex(edge);
548 TopoDS_Vertex VL2 = sae.LastVertex(edge);
549 if(sae.FirstVertex(edge).IsSame(VL)) {
552 VL = sae.LastVertex(LastE);
555 else if(sae.LastVertex(edge).IsSame(VF)) {
556 aChain.Prepend(edge);
558 VF = sae.FirstVertex(FirstE);
563 if(aChain.Length()<SeqEdges.Length()) {
565 cout<<"can not create correct chain..."<<endl;
567 return Standard_False;
569 // union edges in chain
570 // first step: union lines and circles
572 Standard_Real fp1,lp1,fp2,lp2;
573 for(j=1; j<aChain.Length(); j++) {
574 TopoDS_Edge edge1 = TopoDS::Edge(aChain.Value(j));
575 Handle(Geom_Curve) c3d1 = BRep_Tool::Curve(edge1,Loc,fp1,lp1);
576 if(c3d1.IsNull()) break;
577 while(c3d1->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
578 Handle(Geom_TrimmedCurve) tc =
579 Handle(Geom_TrimmedCurve)::DownCast(c3d1);
580 c3d1 = tc->BasisCurve();
582 TopoDS_Edge edge2 = TopoDS::Edge(aChain.Value(j+1));
583 Handle(Geom_Curve) c3d2 = BRep_Tool::Curve(edge2,Loc,fp2,lp2);
584 if(c3d2.IsNull()) break;
585 while(c3d2->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
586 Handle(Geom_TrimmedCurve) tc =
587 Handle(Geom_TrimmedCurve)::DownCast(c3d2);
588 c3d2 = tc->BasisCurve();
590 if( c3d1->IsKind(STANDARD_TYPE(Geom_Line)) && c3d2->IsKind(STANDARD_TYPE(Geom_Line)) ) {
592 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(c3d1);
593 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(c3d2);
594 gp_Dir Dir1 = L1->Position().Direction();
595 gp_Dir Dir2 = L2->Position().Direction();
596 //if(!Dir1.IsEqual(Dir2,Precision::Angular())) {
597 //if(!Dir1.IsParallel(Dir2,Precision::Angular())) {
598 if(!Dir1.IsParallel(Dir2,Tol)) {
601 // can union lines => create new edge
602 TopoDS_Vertex V1 = sae.FirstVertex(edge1);
603 gp_Pnt PV1 = BRep_Tool::Pnt(V1);
604 TopoDS_Vertex V2 = sae.LastVertex(edge2);
605 gp_Pnt PV2 = BRep_Tool::Pnt(V2);
607 Handle(Geom_Line) L = new Geom_Line(gp_Ax1(PV1,Vec));
608 Standard_Real dist = PV1.Distance(PV2);
609 Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(L,0.0,dist);
611 B.MakeEdge (E,tc,Precision::Confusion());
612 B.Add (E,V1); B.Add (E,V2);
613 B.UpdateVertex(V1, 0., E, 0.);
614 B.UpdateVertex(V2, dist, E, 0.);
616 //sfe.FixAddPCurve(E,aFace,Standard_False);
617 //sfe.FixSameParameter(E);
619 aChain.SetValue(j,E);
622 if( c3d1->IsKind(STANDARD_TYPE(Geom_Circle)) && c3d2->IsKind(STANDARD_TYPE(Geom_Circle)) ) {
624 Handle(Geom_Circle) C1 = Handle(Geom_Circle)::DownCast(c3d1);
625 Handle(Geom_Circle) C2 = Handle(Geom_Circle)::DownCast(c3d2);
626 gp_Pnt P01 = C1->Location();
627 gp_Pnt P02 = C2->Location();
628 if (P01.Distance(P02) > Precision::Confusion()) continue;
629 // can union circles => create new edge
630 TopoDS_Vertex V1 = sae.FirstVertex(edge1);
631 gp_Pnt PV1 = BRep_Tool::Pnt(V1);
632 TopoDS_Vertex V2 = sae.LastVertex(edge2);
633 gp_Pnt PV2 = BRep_Tool::Pnt(V2);
634 TopoDS_Vertex VM = sae.LastVertex(edge1);
635 gp_Pnt PVM = BRep_Tool::Pnt(VM);
636 GC_MakeCircle MC (PV1,PVM,PV2);
637 Handle(Geom_Circle) C = MC.Value();
639 if (!MC.IsDone() || C.IsNull()) {
640 // jfa for Mantis issue 0020228
641 if (PV1.Distance(PV2) > Precision::Confusion()) continue;
644 B.MakeEdge (E,C,Precision::Confusion());
649 gp_Pnt P0 = C->Location();
650 gp_Dir D1(gp_Vec(P0,PV1));
651 gp_Dir D2(gp_Vec(P0,PV2));
652 Standard_Real fpar = C->XAxis().Direction().Angle(D1);
653 if(fabs(fpar)>Precision::Confusion()) {
655 gp_Dir ND = C->XAxis().Direction().Crossed(D1);
656 if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) {
660 Standard_Real lpar = C->XAxis().Direction().Angle(D2);
661 if(fabs(lpar)>Precision::Confusion()) {
663 gp_Dir ND = C->XAxis().Direction().Crossed(D2);
664 if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) {
668 if (lpar < fpar) lpar += 2*M_PI;
669 Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(C,fpar,lpar);
670 B.MakeEdge (E,tc,Precision::Confusion());
673 B.UpdateVertex(V1, fpar, E, 0.);
674 B.UpdateVertex(V2, lpar, E, 0.);
677 aChain.SetValue(j,E);
681 if (j < aChain.Length()) {
683 cout<<"null curve3d in edge..."<<endl;
685 return Standard_False;
687 if (aChain.Length() > 1 && ConcatBSplines) {
688 // second step: union edges with various curves
689 // skl for bug 0020052 from Mantis: perform such unions
690 // only if curves are bspline or bezier
691 bool NeedUnion = true;
692 for(j=1; j<=aChain.Length(); j++) {
693 TopoDS_Edge edge = TopoDS::Edge(aChain.Value(j));
694 Handle(Geom_Curve) c3d = BRep_Tool::Curve(edge,Loc,fp1,lp1);
695 if(c3d.IsNull()) continue;
696 while(c3d->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
697 Handle(Geom_TrimmedCurve) tc =
698 Handle(Geom_TrimmedCurve)::DownCast(c3d);
699 c3d = tc->BasisCurve();
701 if( ( c3d->IsKind(STANDARD_TYPE(Geom_BSplineCurve)) ||
702 c3d->IsKind(STANDARD_TYPE(Geom_BezierCurve)) ) ) continue;
708 cout<<"can not make analitical union => make approximation"<<endl;
710 TopoDS_Edge E = GlueEdgesWithPCurves(aChain, VF, VL);
714 for(j=1; j<=aChain.Length(); j++) {
715 TopoDS_Edge edge = TopoDS::Edge(aChain.Value(j));
718 Handle(BRepAdaptor_HCompCurve) Adapt = new BRepAdaptor_HCompCurve(W);
719 Approx_Curve3d Conv(Adapt,Tol,GeomAbs_C1,9,1000);
720 Handle(Geom_BSplineCurve) bc = Conv.Curve();
722 B.MakeEdge (E,bc,Precision::Confusion());
726 aChain.SetValue(1,E);
730 cout<<"can not make approximation for such types of curves"<<endl;
732 return Standard_False;
736 anEdge = TopoDS::Edge(aChain.Value(1));
737 return Standard_True;
740 //=======================================================================
741 //function : ShapeUpgrade_UnifySameDomain
742 //purpose : Constructor
743 //=======================================================================
745 ShapeUpgrade_UnifySameDomain::ShapeUpgrade_UnifySameDomain()
747 myUnifyEdges = Standard_True;
748 myUnifyFaces = Standard_True;
749 myConcatBSplines = Standard_False;
751 myContext = new ShapeBuild_ReShape;
754 //=======================================================================
755 //function : ShapeUpgrade_UnifySameDomain
756 //purpose : Constructor
757 //=======================================================================
759 ShapeUpgrade_UnifySameDomain::ShapeUpgrade_UnifySameDomain(const TopoDS_Shape& aShape,
760 const Standard_Boolean UnifyEdges,
761 const Standard_Boolean UnifyFaces,
762 const Standard_Boolean ConcatBSplines)
764 myInitShape = aShape;
766 myUnifyEdges = UnifyEdges;
767 myUnifyFaces = UnifyFaces;
768 myConcatBSplines = ConcatBSplines;
770 myContext = new ShapeBuild_ReShape;
773 //=======================================================================
774 //function : Initialize
776 //=======================================================================
778 void ShapeUpgrade_UnifySameDomain::Initialize(const TopoDS_Shape& aShape,
779 const Standard_Boolean UnifyEdges,
780 const Standard_Boolean UnifyFaces,
781 const Standard_Boolean ConcatBSplines)
783 myInitShape = aShape;
785 myUnifyEdges = UnifyEdges;
786 myUnifyFaces = UnifyFaces;
787 myConcatBSplines = ConcatBSplines;
790 //myOldNewMap.Clear();
791 //myGenerated.Clear();
794 //=======================================================================
795 //function : UnifyFaces
797 //=======================================================================
799 void ShapeUpgrade_UnifySameDomain::UnifyFaces()
801 //Handle(ShapeBuild_ReShape) myContext = new ShapeBuild_ReShape;
802 TopoDS_Shape aResShape = myContext->Apply(myShape);
804 // processing each shell
805 TopExp_Explorer exps;
806 for (exps.Init(myShape, TopAbs_SHELL); exps.More(); exps.Next()) {
807 TopoDS_Shell aShell = TopoDS::Shell(exps.Current());
809 // creating map of edge faces
810 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
811 TopExp::MapShapesAndAncestors(aShell, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
813 // map of processed shapes
814 TopTools_MapOfShape aProcessed;
816 //Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
818 Standard_Integer NbModif = 0;
819 Standard_Boolean hasFailed = Standard_False;
820 Standard_Real tol = Precision::Confusion();
823 Standard_Integer nbf = 0;
825 TopTools_MapOfShape mapF;
826 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
827 if (mapF.Add(exp.Current()))
831 // processing each face
833 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
834 TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
836 if (aProcessed.Contains(aFace))
839 Standard_Integer dummy;
840 TopTools_SequenceOfShape edges;
841 AddOrdinaryEdges(edges,aFace,dummy);
843 TopTools_SequenceOfShape faces;
846 //surface and location to construct result
847 TopLoc_Location aBaseLocation;
848 Handle(Geom_Surface) aBaseSurface = BRep_Tool::Surface(aFace,aBaseLocation);
849 aBaseSurface = ClearRts(aBaseSurface);
851 // find adjacent faces to union
853 for (i = 1; i <= edges.Length(); i++) {
854 TopoDS_Edge edge = TopoDS::Edge(edges(i));
855 if (BRep_Tool::Degenerated(edge))
858 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
859 TopTools_ListIteratorOfListOfShape anIter(aList);
860 for (; anIter.More(); anIter.Next()) {
861 TopoDS_Face anCheckedFace = TopoDS::Face(anIter.Value().Oriented(TopAbs_FORWARD));
862 if (anCheckedFace.IsSame(aFace))
865 if (aProcessed.Contains(anCheckedFace))
868 if (IsSameDomain(aFace,anCheckedFace)) {
870 if (aList.Extent() != 2) {
871 // non mainfold case is not processed
876 TopoDS_Face aMockUpFace;
878 B.MakeFace(aMockUpFace,aBaseSurface,aBaseLocation,0.);
879 MovePCurves(aMockUpFace,anCheckedFace);
881 if (AddOrdinaryEdges(edges,aMockUpFace,dummy)) {
882 // sequence edges is modified
886 faces.Append(anCheckedFace);
887 aProcessed.Add(anCheckedFace);
893 // all faces collected in the sequence. Perform union of faces
894 if (faces.Length() > 1) {
898 B.MakeFace(aResult,aBaseSurface,aBaseLocation,0);
899 Standard_Integer nbWires = 0;
902 while (edges.Length()>0) {
904 Standard_Boolean isEdge3d = Standard_False;
906 TopTools_MapOfShape aVertices;
910 TopoDS_Edge anEdge = TopoDS::Edge(edges(1));
913 isEdge3d |= !BRep_Tool::Degenerated(anEdge);
916 TopExp::Vertices(anEdge,V1,V2);
920 Standard_Boolean isNewFound = Standard_False;
922 isNewFound = Standard_False;
923 for(Standard_Integer j = 1; j <= edges.Length(); j++) {
924 anEdge = TopoDS::Edge(edges(j));
925 TopExp::Vertices(anEdge,V1,V2);
926 if(aVertices.Contains(V1) || aVertices.Contains(V2)) {
927 isEdge3d |= !BRep_Tool::Degenerated(anEdge);
933 isNewFound = Standard_True;
936 } while (isNewFound);
938 // sorting any type of edges
939 //aWire = TopoDS::Wire(aContext->Apply(aWire));
940 aWire = TopoDS::Wire(myContext->Apply(aWire));
942 //TopoDS_Face tmpF = TopoDS::Face(aContext->Apply(faces(1).Oriented(TopAbs_FORWARD)));
943 TopoDS_Face tmpF = TopoDS::Face(myContext->Apply(faces(1).Oriented(TopAbs_FORWARD)));
944 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(aWire,tmpF,Precision::Confusion());
946 Standard_Boolean isDegRemoved = Standard_False;
947 if(!sfw->StatusReorder ( ShapeExtend_FAIL )) {
948 // clear degenerated edges if at least one with 3d curve exist
950 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
951 for(Standard_Integer j = 1; j<=sewd->NbEdges();j++) {
952 TopoDS_Edge E = sewd->Edge(j);
953 if(BRep_Tool::Degenerated(E)) {
955 isDegRemoved = Standard_True;
962 sfw->FixDegenerated();
964 TopoDS_Wire aWireFixed = sfw->Wire();
965 //aContext->Replace(aWire,aWireFixed);
966 myContext->Replace(aWire,aWireFixed);
969 if (!myOldNewMap.IsBound(aWire))
971 TopTools_ListOfShape EmptyList;
972 myOldNewMap.Bind(aWire, EmptyList);
974 myOldNewMap(aWire).Clear();
975 myOldNewMap(aWire).Append(aWireFixed);
979 // add resulting wire
981 B.Add(aResult,aWireFixed);
985 Handle(ShapeExtend_WireData) sbwd = sfw->WireData();
986 Standard_Integer nbEdges = sbwd->NbEdges();
987 // sort degenerated edges and create one edge instead of several ones
988 ShapeAnalysis_WireOrder sawo(Standard_False, 0);
989 ShapeAnalysis_Edge sae;
990 Standard_Integer aLastEdge = nbEdges;
991 for(Standard_Integer j = 1; j <= nbEdges; j++) {
993 //smh protection on NULL pcurve
994 Handle(Geom2d_Curve) c2d;
995 if(!sae.PCurve(sbwd->Edge(j),tmpF,c2d,f,l)) {
999 sawo.Add(c2d->Value(f).XY(),c2d->Value(l).XY());
1003 // constructind one degenerative edge
1004 gp_XY aStart, anEnd, tmp;
1005 Standard_Integer nbFirst = sawo.Ordered(1);
1006 TopoDS_Edge anOrigE = TopoDS::Edge(sbwd->Edge(nbFirst).Oriented(TopAbs_FORWARD));
1007 ShapeBuild_Edge sbe;
1008 TopoDS_Vertex aDummyV;
1009 TopoDS_Edge E = sbe.CopyReplaceVertices(anOrigE,aDummyV,aDummyV);
1010 sawo.XY(nbFirst,aStart,tmp);
1011 sawo.XY(sawo.Ordered(aLastEdge),tmp,anEnd);
1013 gp_XY aVec = anEnd-aStart;
1014 Handle(Geom2d_Line) aLine = new Geom2d_Line(aStart,gp_Dir2d(anEnd-aStart));
1016 B.UpdateEdge(E,aLine,tmpF,0.);
1017 B.Range(E,tmpF,0.,aVec.Modulus());
1018 Handle(Geom_Curve) C3d;
1019 B.UpdateEdge(E,C3d,0.);
1020 B.Degenerated(E,Standard_True);
1028 // perform substitution of face
1029 //aContext->Replace(aContext->Apply(aFace),aResult);
1030 myContext->Replace(myContext->Apply(aFace),aResult);
1033 if (!myOldNewMap.IsBound(aFace))
1035 TopTools_ListOfShape EmptyList;
1036 myOldNewMap.Bind(aFace, EmptyList);
1038 myOldNewMap(aFace).Clear();
1039 myOldNewMap(aFace).Append(aResult);
1043 ShapeFix_Face sff (aResult);
1044 //Intializing by tolerances
1045 sff.SetPrecision(Precision::Confusion());
1046 sff.SetMinTolerance(tol);
1047 sff.SetMaxTolerance(1.);
1049 sff.FixOrientationMode() = 0;
1050 //sff.FixWireMode() = 0;
1051 //sff.SetContext(aContext);
1052 sff.SetContext(myContext);
1053 // Applying the fixes
1055 if(sff.Status(ShapeExtend_FAIL))
1056 hasFailed = Standard_True;
1058 // breaking down to several faces
1059 //TopoDS_Shape theResult = aContext->Apply(aResult);
1060 TopoDS_Shape theResult = myContext->Apply(aResult);
1061 for (TopExp_Explorer aFaceExp (theResult,TopAbs_FACE); aFaceExp.More(); aFaceExp.Next()) {
1062 TopoDS_Face aCurrent = TopoDS::Face(aFaceExp.Current().Oriented(TopAbs_FORWARD));
1063 Handle(TColGeom_HArray2OfSurface) grid = new TColGeom_HArray2OfSurface ( 1, 1, 1, 1 );
1064 grid->SetValue ( 1, 1, aBaseSurface );
1065 Handle(ShapeExtend_CompositeSurface) G = new ShapeExtend_CompositeSurface ( grid );
1066 ShapeFix_ComposeShell CompShell;
1067 CompShell.Init ( G, aBaseLocation, aCurrent, ::Precision::Confusion() );//myPrecision
1068 //CompShell.SetContext( aContext );
1069 CompShell.SetContext( myContext );
1071 TopTools_SequenceOfShape parts;
1072 ShapeFix_SequenceOfWireSegment wires;
1073 for(TopExp_Explorer W_Exp(aCurrent,TopAbs_WIRE);W_Exp.More();W_Exp.Next()) {
1074 Handle(ShapeExtend_WireData) sbwd =
1075 new ShapeExtend_WireData ( TopoDS::Wire(W_Exp.Current() ));
1076 ShapeFix_WireSegment seg ( sbwd, TopAbs_REVERSED );
1080 CompShell.DispatchWires ( parts,wires );
1081 for (Standard_Integer j=1; j <= parts.Length(); j++ ) {
1082 ShapeFix_Face aFixOrient(TopoDS::Face(parts(j)));
1083 //aFixOrient.SetContext(aContext);
1084 aFixOrient.SetContext(myContext);
1085 aFixOrient.FixOrientation();
1088 TopoDS_Shape CompRes;
1089 if ( faces.Length() !=1 ) {
1092 for ( i=1; i <= parts.Length(); i++ )
1093 B.Add ( S, parts(i) );
1096 else CompRes = parts(1);
1098 //aContext->Replace(aCurrent,CompRes);
1099 myContext->Replace(aCurrent,CompRes);
1102 if (!myOldNewMap.IsBound(aCurrent))
1104 TopTools_ListOfShape EmptyList;
1105 myOldNewMap.Bind(aCurrent, EmptyList);
1107 myOldNewMap(aCurrent).Clear();
1108 myOldNewMap(aCurrent).Append(CompRes);
1113 // remove the remaining faces
1114 for(i = 2; i <= faces.Length(); i++)
1115 //aContext->Remove(faces(i));
1116 myContext->Remove(faces(i));
1118 } // end processing each face
1120 //TopoDS_Shape aResult = Shape;
1121 if (NbModif > 0 && !hasFailed) {
1122 //TopoDS_Shape aResult = aContext->Apply(aShell);
1123 TopoDS_Shape aResult = myContext->Apply(aShell);
1126 for (exp.Init(aResult,TopAbs_EDGE); exp.More(); exp.Next()) {
1127 TopoDS_Edge E = TopoDS::Edge(exp.Current());
1128 sfe.FixVertexTolerance (E);
1129 // ptv add fix same parameter
1130 sfe.FixSameParameter(E, Precision::Confusion());
1133 myContext->Replace(aShell, aResult);
1136 if (!myOldNewMap.IsBound(aShell))
1138 TopTools_ListOfShape EmptyList;
1139 myOldNewMap.Bind(aShell, EmptyList);
1141 myOldNewMap(aShell).Clear();
1142 myOldNewMap(aShell).Append(aResult);
1148 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
1149 TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
1150 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
1151 sfw->SetContext(myContext);
1152 sfw->SetPrecision(Precision::Confusion());
1153 sfw->SetMinTolerance(Precision::Confusion());
1154 sfw->SetMaxTolerance(1.);
1155 sfw->SetFace(aFace);
1156 for (TopoDS_Iterator iter (aFace,Standard_False); iter.More(); iter.Next()) {
1157 TopoDS_Wire wire = TopoDS::Wire(iter.Value());
1164 } // end processing each shell
1166 myShape = myContext->Apply(myShape);
1169 //=======================================================================
1170 //function : UnifyEdges
1172 //=======================================================================
1174 void ShapeUpgrade_UnifySameDomain::UnifyEdges()
1176 Standard_Real Tol = Precision::Confusion();
1178 //Handle(ShapeBuild_ReShape) myContext = new ShapeBuild_ReShape;
1179 Standard_Real myTolerance = Precision::Confusion();
1180 TopoDS_Shape aResult = myContext->Apply(myShape);
1182 // processing each solid
1183 TopAbs_ShapeEnum aType = TopAbs_SOLID;
1184 TopExp_Explorer exps (myShape, aType);
1186 aType = TopAbs_SHELL;
1187 exps.Init(myShape, aType);
1189 for (; exps.More(); exps.Next()) {
1190 //TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
1191 TopoDS_Shape aSolid = exps.Current();
1193 TopTools_IndexedMapOfShape ChangedFaces;
1195 // creating map of edge faces
1196 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
1197 TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
1199 //Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
1200 TopoDS_Shape aRes = aSolid;
1201 //aRes = aContext->Apply(aSolid);
1202 aRes = myContext->Apply(aSolid);
1204 // processing each face
1205 TopExp_Explorer exp;
1206 for (exp.Init(aRes, TopAbs_FACE); exp.More(); exp.Next()) {
1207 //TopoDS_Face aFace = TopoDS::Face(aContext->Apply(exp.Current().Oriented(TopAbs_FORWARD)));
1208 TopoDS_Face aFace = TopoDS::Face(myContext->Apply(exp.Current().Oriented(TopAbs_FORWARD)));
1209 TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
1211 for (TopExp_Explorer expe(aFace,TopAbs_EDGE); expe.More(); expe.Next()) {
1212 TopoDS_Edge edge = TopoDS::Edge(expe.Current());
1213 if (!aMapEdgeFaces.Contains(edge)) continue;
1214 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
1215 TopTools_ListIteratorOfListOfShape anIter(aList);
1216 for ( ; anIter.More(); anIter.Next()) {
1217 TopoDS_Face face = TopoDS::Face(anIter.Value());
1218 //TopoDS_Face face1 = TopoDS::Face(aContext->Apply(anIter.Value()));
1219 TopoDS_Face face1 = TopoDS::Face(myContext->Apply(anIter.Value()));
1220 if (face1.IsSame(aFace)) continue;
1221 if (aMapFacesEdges.Contains(face)) {
1222 aMapFacesEdges.ChangeFromKey(face).Append(edge);
1225 TopTools_ListOfShape ListEdges;
1226 ListEdges.Append(edge);
1227 aMapFacesEdges.Add(face,ListEdges);
1232 for (Standard_Integer i=1; i<=aMapFacesEdges.Extent(); i++) {
1233 const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
1234 TopTools_SequenceOfShape SeqEdges;
1235 TopTools_ListIteratorOfListOfShape anIter(ListEdges);
1236 for ( ; anIter.More(); anIter.Next()) {
1237 SeqEdges.Append(anIter.Value());
1239 if (SeqEdges.Length()==1) continue;
1241 if ( MergeEdges(SeqEdges,aFace,Tol,myConcatBSplines,E) ) {
1242 // now we have only one edge - aChain.Value(1)
1243 // we have to replace old ListEdges with this new edge
1244 //aContext->Replace(SeqEdges(1),E);
1245 myContext->Replace(SeqEdges(1),E);
1247 for (j = 2; j <= SeqEdges.Length(); j++) {
1248 //aContext->Remove(SeqEdges(j));
1249 myContext->Remove(SeqEdges(j));
1250 //myOldNewMap.Bind(SeqEdges(j), E);
1254 for (j = 1; j <= SeqEdges.Length(); j++)
1256 if (!myOldNewMap.IsBound(SeqEdges(j)))
1258 TopTools_ListOfShape EmptyList;
1259 myOldNewMap.Bind(SeqEdges(j), EmptyList);
1261 myOldNewMap(SeqEdges(j)).Clear();
1262 myOldNewMap(SeqEdges(j)).Append(E);
1267 TopoDS_Face tmpF = TopoDS::Face(exp.Current());
1268 if ( !ChangedFaces.Contains(tmpF) )
1269 ChangedFaces.Add(tmpF);
1270 tmpF = TopoDS::Face(aMapFacesEdges.FindKey(i));
1271 if ( !ChangedFaces.Contains(tmpF) )
1272 ChangedFaces.Add(tmpF);
1276 } // end processing each face
1278 // fix changed faces and replace them in the local context
1279 for (Standard_Integer i=1; i<=ChangedFaces.Extent(); i++) {
1280 //TopoDS_Face aFace = TopoDS::Face(aContext->Apply(ChangedFaces.FindKey(i)));
1281 TopoDS_Face aFace = TopoDS::Face(myContext->Apply(ChangedFaces.FindKey(i)));
1282 Handle(ShapeFix_Face) sff = new ShapeFix_Face(aFace);
1283 sff->SetContext(myContext);
1284 sff->SetPrecision(myTolerance);
1285 sff->SetMinTolerance(myTolerance);
1286 sff->SetMaxTolerance(Max(1.,myTolerance*1000.));
1288 TopoDS_Shape aNewFace = sff->Face();
1289 //aContext->Replace(aFace,aNewFace);
1290 myContext->Replace(aFace,aNewFace);
1293 if (!myOldNewMap.IsBound(aFace))
1295 TopTools_ListOfShape EmptyList;
1296 myOldNewMap.Bind(aFace, EmptyList);
1298 myOldNewMap(aFace).Clear();
1299 myOldNewMap(aFace).Append(aNewFace);
1304 if (ChangedFaces.Extent() > 0) {
1305 // fix changed shell and replace it in the local context
1306 //TopoDS_Shape aRes1 = aContext->Apply(aRes);
1307 TopoDS_Shape aRes1 = myContext->Apply(aRes);
1308 TopExp_Explorer expsh;
1309 for (expsh.Init(aRes1, TopAbs_SHELL); expsh.More(); expsh.Next()) {
1310 TopoDS_Shell aShell = TopoDS::Shell(expsh.Current());
1311 Handle(ShapeFix_Shell) sfsh = new ShapeFix_Shell;
1312 sfsh->FixFaceOrientation(aShell);
1313 TopoDS_Shape aNewShell = sfsh->Shell();
1314 //aContext->Replace(aShell,aNewShell);
1315 myContext->Replace(aShell,aNewShell);
1318 if (!myOldNewMap.IsBound(aShell))
1320 TopTools_ListOfShape EmptyList;
1321 myOldNewMap.Bind(aShell, EmptyList);
1323 myOldNewMap(aShell).Clear();
1324 myOldNewMap(aShell).Append(aNewShell);
1328 //TopoDS_Shape aRes2 = aContext->Apply(aRes1);
1329 TopoDS_Shape aRes2 = myContext->Apply(aRes1);
1330 // put new solid into global context
1331 myContext->Replace(aSolid,aRes2);
1334 if (!myOldNewMap.IsBound(aSolid))
1336 TopTools_ListOfShape EmptyList;
1337 myOldNewMap.Bind(aSolid, EmptyList);
1339 myOldNewMap(aSolid).Clear();
1340 myOldNewMap(aSolid).Append(aRes2);
1345 } // end processing each solid
1347 myShape = myContext->Apply(myShape);
1350 //=======================================================================
1351 //function : UnifyFacesAndEdges
1353 //=======================================================================
1355 void ShapeUpgrade_UnifySameDomain::UnifyFacesAndEdges()
1360 ShapeUpgrade_RemoveLocations RemLoc;
1361 RemLoc.Remove(myShape);
1362 myShape = RemLoc.GetResult();
1368 //=======================================================================
1370 //purpose : builds the resulting shape
1371 //======================================================================
1372 void ShapeUpgrade_UnifySameDomain::Build()
1374 if (myUnifyFaces && myUnifyEdges)
1375 UnifyFacesAndEdges();
1377 else if (myUnifyEdges)
1379 else if (myUnifyFaces)
1385 //=======================================================================
1387 //purpose : give the resulting shape
1388 //=======================================================================
1389 const TopoDS_Shape& ShapeUpgrade_UnifySameDomain::Shape() const
1394 //=======================================================================
1395 //function : Generated
1396 //purpose : returns the new shape from the old one
1397 //=======================================================================
1398 TopoDS_Shape ShapeUpgrade_UnifySameDomain::Generated(const TopoDS_Shape& aShape) const
1400 TopoDS_Shape aNewShape = myContext->Apply(aShape);
1402 if (aNewShape.IsNull())
1403 aNewShape = myOldNewMap(aShape);