1 // File: ShapeUpgrade_UnifySameDomain.cxx
2 // Created: 09.06.12 14:35:07
4 // Copyright: Open CASCADE 2012
6 #include <ShapeUpgrade_UnifySameDomain.ixx>
7 #include <ShapeUpgrade_UnifySameDomain.hxx>
8 #include <TopTools_SequenceOfShape.hxx>
9 #include <TopTools_IndexedMapOfShape.hxx>
10 #include <TopExp_Explorer.hxx>
11 #include <Geom_Surface.hxx>
12 #include <Geom_Line.hxx>
14 #include <Geom_CylindricalSurface.hxx>
15 #include <gp_Cylinder.hxx>
16 #include <Geom_SurfaceOfRevolution.hxx>
17 #include <Geom_SurfaceOfLinearExtrusion.hxx>
19 #include <Geom_Circle.hxx>
20 #include <Geom_RectangularTrimmedSurface.hxx>
21 #include <TopoDS_Face.hxx>
22 #include <BRep_Tool.hxx>
23 #include <GeomAdaptor_HSurface.hxx>
24 #include <BRepTopAdaptor_TopolTool.hxx>
25 #include <IntPatch_ImpImpIntersection.hxx>
26 #include <GeomLib_IsPlanarSurface.hxx>
27 #include <BRep_Builder.hxx>
28 #include <ShapeFix_Wire.hxx>
30 #include <ShapeAnalysis_Edge.hxx>
31 #include <TopoDS_Edge.hxx>
32 #include <TColGeom_SequenceOfSurface.hxx>
33 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
34 #include <BRep_TEdge.hxx>
35 #include <BRep_CurveRepresentation.hxx>
36 #include <TColGeom_Array1OfBSplineCurve.hxx>
37 #include <TColGeom_HArray1OfBSplineCurve.hxx>
38 #include <TColGeom2d_Array1OfBSplineCurve.hxx>
39 #include <TColGeom2d_HArray1OfBSplineCurve.hxx>
40 #include <TColStd_Array1OfReal.hxx>
42 #include <Geom_TrimmedCurve.hxx>
43 #include <Geom2d_TrimmedCurve.hxx>
44 #include <GeomConvert.hxx>
45 #include <Geom2dConvert.hxx>
46 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
47 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
48 #include <TColGeom2d_SequenceOfBoundedCurve.hxx>
49 #include <BRepLib_MakeEdge.hxx>
50 #include <TColStd_MapOfInteger.hxx>
51 #include <BRepLib.hxx>
52 #include <GC_MakeCircle.hxx>
53 #include <Geom_BezierCurve.hxx>
54 #include <ShapeBuild_ReShape.hxx>
55 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
56 #include <TopTools_MapOfShape.hxx>
57 #include <TopTools_ListIteratorOfListOfShape.hxx>
58 #include <ShapeAnalysis_WireOrder.hxx>
59 #include <ShapeBuild_Edge.hxx>
60 #include <Geom2d_Line.hxx>
61 #include <ShapeFix_Face.hxx>
62 #include <TColGeom_HArray2OfSurface.hxx>
63 #include <ShapeExtend_CompositeSurface.hxx>
64 #include <ShapeFix_ComposeShell.hxx>
65 #include <ShapeFix_SequenceOfWireSegment.hxx>
66 #include <ShapeFix_WireSegment.hxx>
67 #include <ShapeFix_Edge.hxx>
68 #include <ShapeFix_Shell.hxx>
69 #include <ShapeUpgrade_RemoveLocations.hxx>
72 //=======================================================================
73 //function : AddOrdinaryEdges
75 //=======================================================================
76 // adds edges from the shape to the sequence
77 // seams and equal edges are dropped
78 // Returns true if one of original edges dropped
79 static Standard_Boolean AddOrdinaryEdges(TopTools_SequenceOfShape& edges,
80 const TopoDS_Shape aShape,
81 Standard_Integer& anIndex)
84 TopTools_IndexedMapOfShape aNewEdges;
85 //add edges without seams
86 for(TopExp_Explorer exp(aShape,TopAbs_EDGE); exp.More(); exp.Next()) {
87 TopoDS_Shape edge = exp.Current();
88 if(aNewEdges.Contains(edge))
90 //aNewEdges.Remove(edge);
91 TopoDS_Shape LastEdge = aNewEdges(aNewEdges.Extent());
92 aNewEdges.RemoveLast();
93 if (aNewEdges.FindIndex(edge) != 0)
94 aNewEdges.Substitute(aNewEdges.FindIndex(edge), LastEdge);
95 /////////////////////////
101 Standard_Boolean isDropped = Standard_False;
102 //merge edges and drop seams
104 for (i = 1; i <= edges.Length(); i++) {
105 TopoDS_Shape current = edges(i);
106 if(aNewEdges.Contains(current)) {
108 //aNewEdges.Remove(current);
109 TopoDS_Shape LastEdge = aNewEdges(aNewEdges.Extent());
110 aNewEdges.RemoveLast();
111 if (aNewEdges.FindIndex(current) != 0)
112 aNewEdges.Substitute(aNewEdges.FindIndex(current), LastEdge);
113 /////////////////////////
118 isDropped = Standard_True;
124 //add edges to the sequemce
125 for (i = 1; i <= aNewEdges.Extent(); i++)
126 edges.Append(aNewEdges(i));
131 //=======================================================================
132 //function : getCylinder
134 //=======================================================================
135 static Standard_Boolean getCylinder(Handle(Geom_Surface)& theInSurface,
136 gp_Cylinder& theOutCylinder)
138 Standard_Boolean isCylinder = Standard_False;
140 if (theInSurface->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
141 Handle(Geom_CylindricalSurface) aGC = Handle(Geom_CylindricalSurface)::DownCast(theInSurface);
143 theOutCylinder = aGC->Cylinder();
144 isCylinder = Standard_True;
146 else if (theInSurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
147 Handle(Geom_SurfaceOfRevolution) aRS =
148 Handle(Geom_SurfaceOfRevolution)::DownCast(theInSurface);
149 Handle(Geom_Curve) aBasis = aRS->BasisCurve();
150 if (aBasis->IsKind(STANDARD_TYPE(Geom_Line))) {
151 Handle(Geom_Line) aBasisLine = Handle(Geom_Line)::DownCast(aBasis);
152 gp_Dir aDir = aRS->Direction();
153 gp_Dir aBasisDir = aBasisLine->Position().Direction();
154 if (aBasisDir.IsParallel(aDir, Precision::Angular())) {
155 // basis line is parallel to the revolution axis: it is a cylinder
156 gp_Pnt aLoc = aRS->Location();
157 Standard_Real aR = aBasisLine->Lin().Distance(aLoc);
158 gp_Ax3 aCylAx (aLoc, aDir);
160 theOutCylinder = gp_Cylinder(aCylAx, aR);
161 isCylinder = Standard_True;
165 else if (theInSurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) {
166 Handle(Geom_SurfaceOfLinearExtrusion) aLES =
167 Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(theInSurface);
168 Handle(Geom_Curve) aBasis = aLES->BasisCurve();
169 if (aBasis->IsKind(STANDARD_TYPE(Geom_Circle))) {
170 Handle(Geom_Circle) aBasisCircle = Handle(Geom_Circle)::DownCast(aBasis);
171 gp_Dir aDir = aLES->Direction();
172 gp_Dir aBasisDir = aBasisCircle->Position().Direction();
173 if (aBasisDir.IsParallel(aDir, Precision::Angular())) {
174 // basis circle is normal to the extrusion axis: it is a cylinder
175 gp_Pnt aLoc = aBasisCircle->Location();
176 Standard_Real aR = aBasisCircle->Radius();
177 gp_Ax3 aCylAx (aLoc, aDir);
179 theOutCylinder = gp_Cylinder(aCylAx, aR);
180 isCylinder = Standard_True;
190 //=======================================================================
191 //function : ClearRts
193 //=======================================================================
194 static Handle(Geom_Surface) ClearRts(const Handle(Geom_Surface)& aSurface)
196 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
197 Handle(Geom_RectangularTrimmedSurface) rts =
198 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
199 return rts->BasisSurface();
204 //=======================================================================
205 //function : IsSameDomain
207 //=======================================================================
208 static Standard_Boolean IsSameDomain(const TopoDS_Face& aFace,
209 const TopoDS_Face& aCheckedFace)
211 //checking the same handles
212 TopLoc_Location L1, L2;
213 Handle(Geom_Surface) S1, S2;
215 S1 = BRep_Tool::Surface(aFace,L1);
216 S2 = BRep_Tool::Surface(aCheckedFace,L2);
218 if (S1 == S2 && L1 == L2)
219 return Standard_True;
221 // planar and cylindrical cases (IMP 20052)
222 Standard_Real aPrec = Precision::Confusion();
224 S1 = BRep_Tool::Surface(aFace);
225 S2 = BRep_Tool::Surface(aCheckedFace);
230 //Handle(Geom_OffsetSurface) aGOFS1, aGOFS2;
231 //aGOFS1 = Handle(Geom_OffsetSurface)::DownCast(S1);
232 //aGOFS2 = Handle(Geom_OffsetSurface)::DownCast(S2);
233 //if (!aGOFS1.IsNull()) S1 = aGOFS1->BasisSurface();
234 //if (!aGOFS2.IsNull()) S2 = aGOFS2->BasisSurface();
236 // case of two elementary surfaces: use OCCT tool
237 // elementary surfaces: ConicalSurface, CylindricalSurface,
238 // Plane, SphericalSurface and ToroidalSurface
239 if (S1->IsKind(STANDARD_TYPE(Geom_ElementarySurface)) &&
240 S2->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
242 Handle(GeomAdaptor_HSurface) aGA1 = new GeomAdaptor_HSurface(S1);
243 Handle(GeomAdaptor_HSurface) aGA2 = new GeomAdaptor_HSurface(S2);
245 Handle(BRepTopAdaptor_TopolTool) aTT1 = new BRepTopAdaptor_TopolTool();
246 Handle(BRepTopAdaptor_TopolTool) aTT2 = new BRepTopAdaptor_TopolTool();
249 IntPatch_ImpImpIntersection anIIInt (aGA1, aTT1, aGA2, aTT2, aPrec, aPrec);
250 if (!anIIInt.IsDone() || anIIInt.IsEmpty())
251 return Standard_False;
253 return anIIInt.TangentFaces();
255 catch (Standard_Failure) {
256 return Standard_False;
260 // case of two planar surfaces:
261 // all kinds of surfaces checked, including b-spline and bezier
262 GeomLib_IsPlanarSurface aPlanarityChecker1 (S1, aPrec);
263 if (aPlanarityChecker1.IsPlanar()) {
264 GeomLib_IsPlanarSurface aPlanarityChecker2 (S2, aPrec);
265 if (aPlanarityChecker2.IsPlanar()) {
266 gp_Pln aPln1 = aPlanarityChecker1.Plan();
267 gp_Pln aPln2 = aPlanarityChecker2.Plan();
269 if (aPln1.Position().Direction().IsParallel(aPln2.Position().Direction(),Precision::Angular()) &&
270 aPln1.Distance(aPln2) < aPrec) {
271 return Standard_True;
276 // case of two cylindrical surfaces, at least one of which is a swept surface
277 // swept surfaces: SurfaceOfLinearExtrusion, SurfaceOfRevolution
278 if ((S1->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ||
279 S1->IsKind(STANDARD_TYPE(Geom_SweptSurface))) &&
280 (S2->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ||
281 S2->IsKind(STANDARD_TYPE(Geom_SweptSurface))))
283 gp_Cylinder aCyl1, aCyl2;
284 if (getCylinder(S1, aCyl1) && getCylinder(S2, aCyl2)) {
285 if (fabs(aCyl1.Radius() - aCyl2.Radius()) < aPrec) {
286 gp_Dir aDir1 = aCyl1.Position().Direction();
287 gp_Dir aDir2 = aCyl2.Position().Direction();
288 if (aDir1.IsParallel(aDir2, Precision::Angular())) {
289 gp_Pnt aLoc1 = aCyl1.Location();
290 gp_Pnt aLoc2 = aCyl2.Location();
291 gp_Vec aVec12 (aLoc1, aLoc2);
292 if (aVec12.SquareMagnitude() < aPrec*aPrec ||
293 aVec12.IsParallel(aDir1, Precision::Angular())) {
294 return Standard_True;
301 return Standard_False;
304 //=======================================================================
305 //function : MovePCurves
307 //=======================================================================
308 static void MovePCurves(TopoDS_Face& aTarget,
309 const TopoDS_Face& aSource)
312 for(TopExp_Explorer wexp(aSource,TopAbs_WIRE);wexp.More();wexp.Next()) {
313 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(TopoDS::Wire(wexp.Current()),
314 aTarget, Precision::Confusion());
316 Standard_Boolean isReoredFailed = sfw->StatusReorder ( ShapeExtend_FAIL );
317 sfw->FixEdgeCurves();
322 sfw->FixDegenerated();
324 // remove degenerated edges from not degenerated points
325 ShapeAnalysis_Edge sae;
326 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
327 for(Standard_Integer i = 1; i<=sewd->NbEdges();i++) {
328 TopoDS_Edge E = sewd->Edge(i);
329 if(BRep_Tool::Degenerated(E)&&!sae.HasPCurve(E,aTarget)) {
335 TopoDS_Wire ResWire = sfw->Wire();
336 B.Add(aTarget,ResWire);
340 //=======================================================================
341 //function : GlueEdgesWithPCurves
342 //purpose : Glues the pcurves of the sequence of edges
343 // and glues their 3d curves
344 //=======================================================================
345 static TopoDS_Edge GlueEdgesWithPCurves(const TopTools_SequenceOfShape& aChain,
346 const TopoDS_Vertex& FirstVertex,
347 const TopoDS_Vertex& LastVertex)
349 Standard_Integer i, j;
351 TopoDS_Edge FirstEdge = TopoDS::Edge(aChain(1));
352 //TColGeom2d_SequenceOfCurve PCurveSeq;
353 TColGeom_SequenceOfSurface SurfSeq;
354 //TopTools_SequenceOfShape LocSeq;
356 BRep_ListIteratorOfListOfCurveRepresentation itr( (Handle(BRep_TEdge)::DownCast(FirstEdge.TShape()))->Curves() );
357 for (; itr.More(); itr.Next())
359 Handle(BRep_CurveRepresentation) CurveRep = itr.Value();
360 if (CurveRep->IsCurveOnSurface())
362 //PCurveSeq.Append(CurveRep->PCurve());
363 SurfSeq.Append(CurveRep->Surface());
365 TopoDS_Shape aLocShape;
366 aLocShape.Location(CurveRep->Location());
367 LocSeq.Append(aLocShape);
372 Standard_Real fpar, lpar;
373 BRep_Tool::Range(FirstEdge, fpar, lpar);
374 TopoDS_Edge PrevEdge = FirstEdge;
376 Standard_Real MaxTol = 0.;
381 Standard_Integer nb_curve = aChain.Length(); //number of curves
382 TColGeom_Array1OfBSplineCurve tab_c3d(0,nb_curve-1); //array of the curves
383 TColStd_Array1OfReal tabtolvertex(0,nb_curve-1); //(0,nb_curve-2); //array of the tolerances
385 TopoDS_Vertex PrevVertex = FirstVertex;
386 for (i = 1; i <= nb_curve; i++)
388 TopoDS_Edge anEdge = TopoDS::Edge(aChain(i));
389 TopoDS_Vertex VF, VL;
390 TopExp::Vertices(anEdge, VF, VL);
391 Standard_Boolean ToReverse = (!VF.IsSame(PrevVertex));
393 Standard_Real Tol1 = BRep_Tool::Tolerance(VF);
394 Standard_Real Tol2 = BRep_Tool::Tolerance(VL);
402 TopExp::CommonVertex(PrevEdge, anEdge, CV);
403 Standard_Real Tol = BRep_Tool::Tolerance(CV);
404 tabtolvertex(i-2) = Tol;
407 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, fpar, lpar);
408 Handle(Geom_TrimmedCurve) aTrCurve = new Geom_TrimmedCurve(aCurve, fpar, lpar);
409 tab_c3d(i-1) = GeomConvert::CurveToBSplineCurve(aTrCurve);
410 GeomConvert::C0BSplineToC1BSplineCurve(tab_c3d(i-1), Precision::Confusion());
412 tab_c3d(i-1)->Reverse();
413 PrevVertex = (ToReverse)? VF : VL;
416 Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves
417 Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex
418 GeomConvert::ConcatC1(tab_c3d,
423 Precision::Confusion()); //C1 concatenation
425 if (concatcurve->Length() > 1)
427 GeomConvert_CompCurveToBSplineCurve Concat(concatcurve->Value(concatcurve->Lower()));
429 for (i = concatcurve->Lower()+1; i <= concatcurve->Upper(); i++)
430 Concat.Add( concatcurve->Value(i), MaxTol, Standard_True );
432 concatcurve->SetValue(concatcurve->Lower(), Concat.BSplineCurve());
434 Handle(Geom_BSplineCurve) ResCurve = concatcurve->Value(concatcurve->Lower());
436 TColGeom2d_SequenceOfBoundedCurve ResPCurves;
437 TopLoc_Location aLoc;
438 for (j = 1; j <= SurfSeq.Length(); j++)
440 TColGeom2d_Array1OfBSplineCurve tab_c2d(0,nb_curve-1); //array of the pcurves
442 PrevVertex = FirstVertex;
443 PrevEdge = FirstEdge;
444 //TopLoc_Location theLoc = LocSeq(j).Location();
445 for (i = 1; i <= nb_curve; i++)
447 TopoDS_Edge anEdge = TopoDS::Edge(aChain(i));
448 TopoDS_Vertex VF, VL;
449 TopExp::Vertices(anEdge, VF, VL);
450 Standard_Boolean ToReverse = (!VF.IsSame(PrevVertex));
453 Handle(Geom2d_Curve) aPCurve =
454 BRep_Tool::CurveOnSurface(anEdge, SurfSeq(j), anEdge.Location()*theLoc, fpar, lpar);
456 Handle(Geom2d_Curve) aPCurve =
457 BRep_Tool::CurveOnSurface(anEdge, SurfSeq(j), aLoc, fpar, lpar);
458 Handle(Geom2d_TrimmedCurve) aTrPCurve = new Geom2d_TrimmedCurve(aPCurve, fpar, lpar);
459 tab_c2d(i-1) = Geom2dConvert::CurveToBSplineCurve(aTrPCurve);
460 Geom2dConvert::C0BSplineToC1BSplineCurve(tab_c2d(i-1), Precision::Confusion());
462 tab_c2d(i-1)->Reverse();
463 PrevVertex = (ToReverse)? VF : VL;
466 Handle(TColGeom2d_HArray1OfBSplineCurve) concatc2d; //array of the concatenated curves
467 Handle(TColStd_HArray1OfInteger) ArrayOfInd2d; //array of the remining Vertex
468 Geom2dConvert::ConcatC1(tab_c2d,
473 Precision::Confusion()); //C1 concatenation
475 if (concatc2d->Length() > 1)
477 Geom2dConvert_CompCurveToBSplineCurve Concat2d(concatc2d->Value(concatc2d->Lower()));
479 for (i = concatc2d->Lower()+1; i <= concatc2d->Upper(); i++)
480 Concat2d.Add( concatc2d->Value(i), MaxTol, Standard_True );
482 concatc2d->SetValue(concatc2d->Lower(), Concat2d.BSplineCurve());
484 Handle(Geom2d_BSplineCurve) aResPCurve = concatc2d->Value(concatc2d->Lower());
485 ResPCurves.Append(aResPCurve);
488 ResEdge = BRepLib_MakeEdge(ResCurve,
489 FirstVertex, LastVertex,
490 ResCurve->FirstParameter(), ResCurve->LastParameter());
491 BB.SameRange(ResEdge, Standard_False);
492 BB.SameParameter(ResEdge, Standard_False);
493 for (j = 1; j <= ResPCurves.Length(); j++)
495 BB.UpdateEdge(ResEdge, ResPCurves(j), SurfSeq(j), aLoc, MaxTol);
496 BB.Range(ResEdge, SurfSeq(j), aLoc, ResPCurves(j)->FirstParameter(), ResPCurves(j)->LastParameter());
499 BRepLib::SameParameter(ResEdge, MaxTol, Standard_True);
504 //=======================================================================
505 //function : MergeEdges
507 //=======================================================================
508 static Standard_Boolean MergeEdges(const TopTools_SequenceOfShape& SeqEdges,
509 const TopoDS_Face& /*aFace*/,
510 const Standard_Real Tol,
511 const Standard_Boolean ConcatBSplines,
514 // make chain for union
516 ShapeAnalysis_Edge sae;
517 TopoDS_Edge FirstE = TopoDS::Edge(SeqEdges.Value(1));
518 TopoDS_Edge LastE = FirstE;
519 TopoDS_Vertex VF = sae.FirstVertex(FirstE);
520 TopoDS_Vertex VL = sae.LastVertex(LastE);
521 TopTools_SequenceOfShape aChain;
522 aChain.Append(FirstE);
523 TColStd_MapOfInteger IndUsedEdges;
526 for (j = 1; j <= SeqEdges.Length(); j++)
528 TopoDS_Edge anEdge = TopoDS::Edge(SeqEdges(j));
529 if (BRep_Tool::Degenerated(anEdge))
530 return Standard_False;
533 for(j=2; j<=SeqEdges.Length(); j++) {
534 for(Standard_Integer k=2; k<=SeqEdges.Length(); k++) {
535 if(IndUsedEdges.Contains(k)) continue;
536 TopoDS_Edge edge = TopoDS::Edge(SeqEdges.Value(k));
537 TopoDS_Vertex VF2 = sae.FirstVertex(edge);
538 TopoDS_Vertex VL2 = sae.LastVertex(edge);
539 if(sae.FirstVertex(edge).IsSame(VL)) {
542 VL = sae.LastVertex(LastE);
545 else if(sae.LastVertex(edge).IsSame(VF)) {
546 aChain.Prepend(edge);
548 VF = sae.FirstVertex(FirstE);
553 if(aChain.Length()<SeqEdges.Length()) {
555 cout<<"can not create correct chain..."<<endl;
557 return Standard_False;
559 // union edges in chain
560 // first step: union lines and circles
562 Standard_Real fp1,lp1,fp2,lp2;
563 for(j=1; j<aChain.Length(); j++) {
564 TopoDS_Edge edge1 = TopoDS::Edge(aChain.Value(j));
565 Handle(Geom_Curve) c3d1 = BRep_Tool::Curve(edge1,Loc,fp1,lp1);
566 if(c3d1.IsNull()) break;
567 while(c3d1->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
568 Handle(Geom_TrimmedCurve) tc =
569 Handle(Geom_TrimmedCurve)::DownCast(c3d1);
570 c3d1 = tc->BasisCurve();
572 TopoDS_Edge edge2 = TopoDS::Edge(aChain.Value(j+1));
573 Handle(Geom_Curve) c3d2 = BRep_Tool::Curve(edge2,Loc,fp2,lp2);
574 if(c3d2.IsNull()) break;
575 while(c3d2->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
576 Handle(Geom_TrimmedCurve) tc =
577 Handle(Geom_TrimmedCurve)::DownCast(c3d2);
578 c3d2 = tc->BasisCurve();
580 if( c3d1->IsKind(STANDARD_TYPE(Geom_Line)) && c3d2->IsKind(STANDARD_TYPE(Geom_Line)) ) {
582 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(c3d1);
583 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(c3d2);
584 gp_Dir Dir1 = L1->Position().Direction();
585 gp_Dir Dir2 = L2->Position().Direction();
586 //if(!Dir1.IsEqual(Dir2,Precision::Angular())) {
587 //if(!Dir1.IsParallel(Dir2,Precision::Angular())) {
588 if(!Dir1.IsParallel(Dir2,Tol)) {
591 // can union lines => create new edge
592 TopoDS_Vertex V1 = sae.FirstVertex(edge1);
593 gp_Pnt PV1 = BRep_Tool::Pnt(V1);
594 TopoDS_Vertex V2 = sae.LastVertex(edge2);
595 gp_Pnt PV2 = BRep_Tool::Pnt(V2);
597 Handle(Geom_Line) L = new Geom_Line(gp_Ax1(PV1,Vec));
598 Standard_Real dist = PV1.Distance(PV2);
599 Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(L,0.0,dist);
601 B.MakeEdge (E,tc,Precision::Confusion());
602 B.Add (E,V1); B.Add (E,V2);
603 B.UpdateVertex(V1, 0., E, 0.);
604 B.UpdateVertex(V2, dist, E, 0.);
606 //sfe.FixAddPCurve(E,aFace,Standard_False);
607 //sfe.FixSameParameter(E);
609 aChain.SetValue(j,E);
612 if( c3d1->IsKind(STANDARD_TYPE(Geom_Circle)) && c3d2->IsKind(STANDARD_TYPE(Geom_Circle)) ) {
614 Handle(Geom_Circle) C1 = Handle(Geom_Circle)::DownCast(c3d1);
615 Handle(Geom_Circle) C2 = Handle(Geom_Circle)::DownCast(c3d2);
616 gp_Pnt P01 = C1->Location();
617 gp_Pnt P02 = C2->Location();
618 if (P01.Distance(P02) > Precision::Confusion()) continue;
619 // can union circles => create new edge
620 TopoDS_Vertex V1 = sae.FirstVertex(edge1);
621 gp_Pnt PV1 = BRep_Tool::Pnt(V1);
622 TopoDS_Vertex V2 = sae.LastVertex(edge2);
623 gp_Pnt PV2 = BRep_Tool::Pnt(V2);
624 TopoDS_Vertex VM = sae.LastVertex(edge1);
625 gp_Pnt PVM = BRep_Tool::Pnt(VM);
626 GC_MakeCircle MC (PV1,PVM,PV2);
627 Handle(Geom_Circle) C = MC.Value();
629 if (!MC.IsDone() || C.IsNull()) {
630 // jfa for Mantis issue 0020228
631 if (PV1.Distance(PV2) > Precision::Confusion()) continue;
634 B.MakeEdge (E,C,Precision::Confusion());
639 gp_Pnt P0 = C->Location();
640 gp_Dir D1(gp_Vec(P0,PV1));
641 gp_Dir D2(gp_Vec(P0,PV2));
642 Standard_Real fpar = C->XAxis().Direction().Angle(D1);
643 if(fabs(fpar)>Precision::Confusion()) {
645 gp_Dir ND = C->XAxis().Direction().Crossed(D1);
646 if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) {
650 Standard_Real lpar = C->XAxis().Direction().Angle(D2);
651 if(fabs(lpar)>Precision::Confusion()) {
653 gp_Dir ND = C->XAxis().Direction().Crossed(D2);
654 if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) {
658 if (lpar < fpar) lpar += 2*M_PI;
659 Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(C,fpar,lpar);
660 B.MakeEdge (E,tc,Precision::Confusion());
663 B.UpdateVertex(V1, fpar, E, 0.);
664 B.UpdateVertex(V2, lpar, E, 0.);
667 aChain.SetValue(j,E);
671 if (j < aChain.Length()) {
673 cout<<"null curve3d in edge..."<<endl;
675 return Standard_False;
677 if (aChain.Length() > 1 && ConcatBSplines) {
678 // second step: union edges with various curves
679 // skl for bug 0020052 from Mantis: perform such unions
680 // only if curves are bspline or bezier
681 bool NeedUnion = true;
682 for(j=1; j<=aChain.Length(); j++) {
683 TopoDS_Edge edge = TopoDS::Edge(aChain.Value(j));
684 Handle(Geom_Curve) c3d = BRep_Tool::Curve(edge,Loc,fp1,lp1);
685 if(c3d.IsNull()) continue;
686 while(c3d->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
687 Handle(Geom_TrimmedCurve) tc =
688 Handle(Geom_TrimmedCurve)::DownCast(c3d);
689 c3d = tc->BasisCurve();
691 if( ( c3d->IsKind(STANDARD_TYPE(Geom_BSplineCurve)) ||
692 c3d->IsKind(STANDARD_TYPE(Geom_BezierCurve)) ) ) continue;
698 cout<<"can not make analitical union => make approximation"<<endl;
700 TopoDS_Edge E = GlueEdgesWithPCurves(aChain, VF, VL);
704 for(j=1; j<=aChain.Length(); j++) {
705 TopoDS_Edge edge = TopoDS::Edge(aChain.Value(j));
708 Handle(BRepAdaptor_HCompCurve) Adapt = new BRepAdaptor_HCompCurve(W);
709 Approx_Curve3d Conv(Adapt,Tol,GeomAbs_C1,9,1000);
710 Handle(Geom_BSplineCurve) bc = Conv.Curve();
712 B.MakeEdge (E,bc,Precision::Confusion());
716 aChain.SetValue(1,E);
720 cout<<"can not make approximation for such types of curves"<<endl;
722 return Standard_False;
726 anEdge = TopoDS::Edge(aChain.Value(1));
727 return Standard_True;
730 //=======================================================================
731 //function : ShapeUpgrade_UnifySameDomain
732 //purpose : Constructor
733 //=======================================================================
735 ShapeUpgrade_UnifySameDomain::ShapeUpgrade_UnifySameDomain()
737 myUnifyEdges = Standard_True;
738 myUnifyFaces = Standard_True;
739 myConcatBSplines = Standard_False;
741 myContext = new ShapeBuild_ReShape;
744 //=======================================================================
745 //function : ShapeUpgrade_UnifySameDomain
746 //purpose : Constructor
747 //=======================================================================
749 ShapeUpgrade_UnifySameDomain::ShapeUpgrade_UnifySameDomain(const TopoDS_Shape& aShape,
750 const Standard_Boolean UnifyEdges,
751 const Standard_Boolean UnifyFaces,
752 const Standard_Boolean ConcatBSplines)
754 myInitShape = aShape;
756 myUnifyEdges = UnifyEdges;
757 myUnifyFaces = UnifyFaces;
758 myConcatBSplines = ConcatBSplines;
760 myContext = new ShapeBuild_ReShape;
763 //=======================================================================
764 //function : Initialize
766 //=======================================================================
768 void ShapeUpgrade_UnifySameDomain::Initialize(const TopoDS_Shape& aShape,
769 const Standard_Boolean UnifyEdges,
770 const Standard_Boolean UnifyFaces,
771 const Standard_Boolean ConcatBSplines)
773 myInitShape = aShape;
775 myUnifyEdges = UnifyEdges;
776 myUnifyFaces = UnifyFaces;
777 myConcatBSplines = ConcatBSplines;
780 //myOldNewMap.Clear();
781 //myGenerated.Clear();
784 //=======================================================================
785 //function : UnifyFaces
787 //=======================================================================
789 void ShapeUpgrade_UnifySameDomain::UnifyFaces()
791 //Handle(ShapeBuild_ReShape) myContext = new ShapeBuild_ReShape;
792 TopoDS_Shape aResShape = myContext->Apply(myShape);
794 // processing each shell
795 TopExp_Explorer exps;
796 for (exps.Init(myShape, TopAbs_SHELL); exps.More(); exps.Next()) {
797 TopoDS_Shell aShell = TopoDS::Shell(exps.Current());
799 // creating map of edge faces
800 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
801 TopExp::MapShapesAndAncestors(aShell, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
803 // map of processed shapes
804 TopTools_MapOfShape aProcessed;
806 //Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
808 Standard_Integer NbModif = 0;
809 Standard_Boolean hasFailed = Standard_False;
810 Standard_Real tol = Precision::Confusion();
813 Standard_Integer nbf = 0;
815 TopTools_MapOfShape mapF;
816 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
817 if (mapF.Add(exp.Current()))
821 // processing each face
823 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
824 TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
826 if (aProcessed.Contains(aFace))
829 Standard_Integer dummy;
830 TopTools_SequenceOfShape edges;
831 AddOrdinaryEdges(edges,aFace,dummy);
833 TopTools_SequenceOfShape faces;
836 //surface and location to construct result
837 TopLoc_Location aBaseLocation;
838 Handle(Geom_Surface) aBaseSurface = BRep_Tool::Surface(aFace,aBaseLocation);
839 aBaseSurface = ClearRts(aBaseSurface);
841 // find adjacent faces to union
843 for (i = 1; i <= edges.Length(); i++) {
844 TopoDS_Edge edge = TopoDS::Edge(edges(i));
845 if (BRep_Tool::Degenerated(edge))
848 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
849 TopTools_ListIteratorOfListOfShape anIter(aList);
850 for (; anIter.More(); anIter.Next()) {
851 TopoDS_Face anCheckedFace = TopoDS::Face(anIter.Value().Oriented(TopAbs_FORWARD));
852 if (anCheckedFace.IsSame(aFace))
855 if (aProcessed.Contains(anCheckedFace))
858 if (IsSameDomain(aFace,anCheckedFace)) {
860 if (aList.Extent() != 2) {
861 // non mainfold case is not processed
866 TopoDS_Face aMockUpFace;
868 B.MakeFace(aMockUpFace,aBaseSurface,aBaseLocation,0.);
869 MovePCurves(aMockUpFace,anCheckedFace);
871 if (AddOrdinaryEdges(edges,aMockUpFace,dummy)) {
872 // sequence edges is modified
876 faces.Append(anCheckedFace);
877 aProcessed.Add(anCheckedFace);
883 // all faces collected in the sequence. Perform union of faces
884 if (faces.Length() > 1) {
888 B.MakeFace(aResult,aBaseSurface,aBaseLocation,0);
889 Standard_Integer nbWires = 0;
892 while (edges.Length()>0) {
894 Standard_Boolean isEdge3d = Standard_False;
896 TopTools_MapOfShape aVertices;
900 TopoDS_Edge anEdge = TopoDS::Edge(edges(1));
903 isEdge3d |= !BRep_Tool::Degenerated(anEdge);
906 TopExp::Vertices(anEdge,V1,V2);
910 Standard_Boolean isNewFound = Standard_False;
912 isNewFound = Standard_False;
913 for(Standard_Integer j = 1; j <= edges.Length(); j++) {
914 anEdge = TopoDS::Edge(edges(j));
915 TopExp::Vertices(anEdge,V1,V2);
916 if(aVertices.Contains(V1) || aVertices.Contains(V2)) {
917 isEdge3d |= !BRep_Tool::Degenerated(anEdge);
923 isNewFound = Standard_True;
926 } while (isNewFound);
928 // sorting any type of edges
929 //aWire = TopoDS::Wire(aContext->Apply(aWire));
930 aWire = TopoDS::Wire(myContext->Apply(aWire));
932 //TopoDS_Face tmpF = TopoDS::Face(aContext->Apply(faces(1).Oriented(TopAbs_FORWARD)));
933 TopoDS_Face tmpF = TopoDS::Face(myContext->Apply(faces(1).Oriented(TopAbs_FORWARD)));
934 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(aWire,tmpF,Precision::Confusion());
936 Standard_Boolean isDegRemoved = Standard_False;
937 if(!sfw->StatusReorder ( ShapeExtend_FAIL )) {
938 // clear degenerated edges if at least one with 3d curve exist
940 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
941 for(Standard_Integer j = 1; j<=sewd->NbEdges();j++) {
942 TopoDS_Edge E = sewd->Edge(j);
943 if(BRep_Tool::Degenerated(E)) {
945 isDegRemoved = Standard_True;
952 sfw->FixDegenerated();
954 TopoDS_Wire aWireFixed = sfw->Wire();
955 //aContext->Replace(aWire,aWireFixed);
956 myContext->Replace(aWire,aWireFixed);
959 if (!myOldNewMap.IsBound(aWire))
961 TopTools_ListOfShape EmptyList;
962 myOldNewMap.Bind(aWire, EmptyList);
964 myOldNewMap(aWire).Clear();
965 myOldNewMap(aWire).Append(aWireFixed);
969 // add resulting wire
971 B.Add(aResult,aWireFixed);
975 Handle(ShapeExtend_WireData) sbwd = sfw->WireData();
976 Standard_Integer nbEdges = sbwd->NbEdges();
977 // sort degenerated edges and create one edge instead of several ones
978 ShapeAnalysis_WireOrder sawo(Standard_False, 0);
979 ShapeAnalysis_Edge sae;
980 Standard_Integer aLastEdge = nbEdges;
981 for(Standard_Integer j = 1; j <= nbEdges; j++) {
983 //smh protection on NULL pcurve
984 Handle(Geom2d_Curve) c2d;
985 if(!sae.PCurve(sbwd->Edge(j),tmpF,c2d,f,l)) {
989 sawo.Add(c2d->Value(f).XY(),c2d->Value(l).XY());
993 // constructind one degenerative edge
994 gp_XY aStart, anEnd, tmp;
995 Standard_Integer nbFirst = sawo.Ordered(1);
996 TopoDS_Edge anOrigE = TopoDS::Edge(sbwd->Edge(nbFirst).Oriented(TopAbs_FORWARD));
998 TopoDS_Vertex aDummyV;
999 TopoDS_Edge E = sbe.CopyReplaceVertices(anOrigE,aDummyV,aDummyV);
1000 sawo.XY(nbFirst,aStart,tmp);
1001 sawo.XY(sawo.Ordered(aLastEdge),tmp,anEnd);
1003 gp_XY aVec = anEnd-aStart;
1004 Handle(Geom2d_Line) aLine = new Geom2d_Line(aStart,gp_Dir2d(anEnd-aStart));
1006 B.UpdateEdge(E,aLine,tmpF,0.);
1007 B.Range(E,tmpF,0.,aVec.Modulus());
1008 Handle(Geom_Curve) C3d;
1009 B.UpdateEdge(E,C3d,0.);
1010 B.Degenerated(E,Standard_True);
1018 // perform substitution of face
1019 //aContext->Replace(aContext->Apply(aFace),aResult);
1020 myContext->Replace(myContext->Apply(aFace),aResult);
1023 if (!myOldNewMap.IsBound(aFace))
1025 TopTools_ListOfShape EmptyList;
1026 myOldNewMap.Bind(aFace, EmptyList);
1028 myOldNewMap(aFace).Clear();
1029 myOldNewMap(aFace).Append(aResult);
1033 ShapeFix_Face sff (aResult);
1034 //Intializing by tolerances
1035 sff.SetPrecision(Precision::Confusion());
1036 sff.SetMinTolerance(tol);
1037 sff.SetMaxTolerance(1.);
1039 sff.FixOrientationMode() = 0;
1040 //sff.FixWireMode() = 0;
1041 //sff.SetContext(aContext);
1042 sff.SetContext(myContext);
1043 // Applying the fixes
1045 if(sff.Status(ShapeExtend_FAIL))
1046 hasFailed = Standard_True;
1048 // breaking down to several faces
1049 //TopoDS_Shape theResult = aContext->Apply(aResult);
1050 TopoDS_Shape theResult = myContext->Apply(aResult);
1051 for (TopExp_Explorer aFaceExp (theResult,TopAbs_FACE); aFaceExp.More(); aFaceExp.Next()) {
1052 TopoDS_Face aCurrent = TopoDS::Face(aFaceExp.Current().Oriented(TopAbs_FORWARD));
1053 Handle(TColGeom_HArray2OfSurface) grid = new TColGeom_HArray2OfSurface ( 1, 1, 1, 1 );
1054 grid->SetValue ( 1, 1, aBaseSurface );
1055 Handle(ShapeExtend_CompositeSurface) G = new ShapeExtend_CompositeSurface ( grid );
1056 ShapeFix_ComposeShell CompShell;
1057 CompShell.Init ( G, aBaseLocation, aCurrent, ::Precision::Confusion() );//myPrecision
1058 //CompShell.SetContext( aContext );
1059 CompShell.SetContext( myContext );
1061 TopTools_SequenceOfShape parts;
1062 ShapeFix_SequenceOfWireSegment wires;
1063 for(TopExp_Explorer W_Exp(aCurrent,TopAbs_WIRE);W_Exp.More();W_Exp.Next()) {
1064 Handle(ShapeExtend_WireData) sbwd =
1065 new ShapeExtend_WireData ( TopoDS::Wire(W_Exp.Current() ));
1066 ShapeFix_WireSegment seg ( sbwd, TopAbs_REVERSED );
1070 CompShell.DispatchWires ( parts,wires );
1071 for (Standard_Integer j=1; j <= parts.Length(); j++ ) {
1072 ShapeFix_Face aFixOrient(TopoDS::Face(parts(j)));
1073 //aFixOrient.SetContext(aContext);
1074 aFixOrient.SetContext(myContext);
1075 aFixOrient.FixOrientation();
1078 TopoDS_Shape CompRes;
1079 if ( faces.Length() !=1 ) {
1082 for ( i=1; i <= parts.Length(); i++ )
1083 B.Add ( S, parts(i) );
1086 else CompRes = parts(1);
1088 //aContext->Replace(aCurrent,CompRes);
1089 myContext->Replace(aCurrent,CompRes);
1092 if (!myOldNewMap.IsBound(aCurrent))
1094 TopTools_ListOfShape EmptyList;
1095 myOldNewMap.Bind(aCurrent, EmptyList);
1097 myOldNewMap(aCurrent).Clear();
1098 myOldNewMap(aCurrent).Append(CompRes);
1103 // remove the remaining faces
1104 for(i = 2; i <= faces.Length(); i++)
1105 //aContext->Remove(faces(i));
1106 myContext->Remove(faces(i));
1108 } // end processing each face
1110 //TopoDS_Shape aResult = Shape;
1111 if (NbModif > 0 && !hasFailed) {
1112 //TopoDS_Shape aResult = aContext->Apply(aShell);
1113 TopoDS_Shape aResult = myContext->Apply(aShell);
1116 for (exp.Init(aResult,TopAbs_EDGE); exp.More(); exp.Next()) {
1117 TopoDS_Edge E = TopoDS::Edge(exp.Current());
1118 sfe.FixVertexTolerance (E);
1119 // ptv add fix same parameter
1120 sfe.FixSameParameter(E, Precision::Confusion());
1123 myContext->Replace(aShell, aResult);
1126 if (!myOldNewMap.IsBound(aShell))
1128 TopTools_ListOfShape EmptyList;
1129 myOldNewMap.Bind(aShell, EmptyList);
1131 myOldNewMap(aShell).Clear();
1132 myOldNewMap(aShell).Append(aResult);
1138 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
1139 TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
1140 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
1141 sfw->SetContext(myContext);
1142 sfw->SetPrecision(Precision::Confusion());
1143 sfw->SetMinTolerance(Precision::Confusion());
1144 sfw->SetMaxTolerance(1.);
1145 sfw->SetFace(aFace);
1146 for (TopoDS_Iterator iter (aFace,Standard_False); iter.More(); iter.Next()) {
1147 TopoDS_Wire wire = TopoDS::Wire(iter.Value());
1154 } // end processing each shell
1156 myShape = myContext->Apply(myShape);
1159 //=======================================================================
1160 //function : UnifyEdges
1162 //=======================================================================
1164 void ShapeUpgrade_UnifySameDomain::UnifyEdges()
1166 Standard_Real Tol = Precision::Confusion();
1168 //Handle(ShapeBuild_ReShape) myContext = new ShapeBuild_ReShape;
1169 Standard_Real myTolerance = Precision::Confusion();
1170 TopoDS_Shape aResult = myContext->Apply(myShape);
1172 // processing each solid
1173 TopAbs_ShapeEnum aType = TopAbs_SOLID;
1174 TopExp_Explorer exps (myShape, aType);
1176 aType = TopAbs_SHELL;
1177 exps.Init(myShape, aType);
1179 for (; exps.More(); exps.Next()) {
1180 //TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
1181 TopoDS_Shape aSolid = exps.Current();
1183 TopTools_IndexedMapOfShape ChangedFaces;
1185 // creating map of edge faces
1186 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
1187 TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
1189 //Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
1190 TopoDS_Shape aRes = aSolid;
1191 //aRes = aContext->Apply(aSolid);
1192 aRes = myContext->Apply(aSolid);
1194 // processing each face
1195 TopExp_Explorer exp;
1196 for (exp.Init(aRes, TopAbs_FACE); exp.More(); exp.Next()) {
1197 //TopoDS_Face aFace = TopoDS::Face(aContext->Apply(exp.Current().Oriented(TopAbs_FORWARD)));
1198 TopoDS_Face aFace = TopoDS::Face(myContext->Apply(exp.Current().Oriented(TopAbs_FORWARD)));
1199 TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
1201 for (TopExp_Explorer expe(aFace,TopAbs_EDGE); expe.More(); expe.Next()) {
1202 TopoDS_Edge edge = TopoDS::Edge(expe.Current());
1203 if (!aMapEdgeFaces.Contains(edge)) continue;
1204 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
1205 TopTools_ListIteratorOfListOfShape anIter(aList);
1206 for ( ; anIter.More(); anIter.Next()) {
1207 TopoDS_Face face = TopoDS::Face(anIter.Value());
1208 //TopoDS_Face face1 = TopoDS::Face(aContext->Apply(anIter.Value()));
1209 TopoDS_Face face1 = TopoDS::Face(myContext->Apply(anIter.Value()));
1210 if (face1.IsSame(aFace)) continue;
1211 if (aMapFacesEdges.Contains(face)) {
1212 aMapFacesEdges.ChangeFromKey(face).Append(edge);
1215 TopTools_ListOfShape ListEdges;
1216 ListEdges.Append(edge);
1217 aMapFacesEdges.Add(face,ListEdges);
1222 for (Standard_Integer i=1; i<=aMapFacesEdges.Extent(); i++) {
1223 const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
1224 TopTools_SequenceOfShape SeqEdges;
1225 TopTools_ListIteratorOfListOfShape anIter(ListEdges);
1226 for ( ; anIter.More(); anIter.Next()) {
1227 SeqEdges.Append(anIter.Value());
1229 if (SeqEdges.Length()==1) continue;
1231 if ( MergeEdges(SeqEdges,aFace,Tol,myConcatBSplines,E) ) {
1232 // now we have only one edge - aChain.Value(1)
1233 // we have to replace old ListEdges with this new edge
1234 //aContext->Replace(SeqEdges(1),E);
1235 myContext->Replace(SeqEdges(1),E);
1237 for (j = 2; j <= SeqEdges.Length(); j++) {
1238 //aContext->Remove(SeqEdges(j));
1239 myContext->Remove(SeqEdges(j));
1240 //myOldNewMap.Bind(SeqEdges(j), E);
1244 for (j = 1; j <= SeqEdges.Length(); j++)
1246 if (!myOldNewMap.IsBound(SeqEdges(j)))
1248 TopTools_ListOfShape EmptyList;
1249 myOldNewMap.Bind(SeqEdges(j), EmptyList);
1251 myOldNewMap(SeqEdges(j)).Clear();
1252 myOldNewMap(SeqEdges(j)).Append(E);
1257 TopoDS_Face tmpF = TopoDS::Face(exp.Current());
1258 if ( !ChangedFaces.Contains(tmpF) )
1259 ChangedFaces.Add(tmpF);
1260 tmpF = TopoDS::Face(aMapFacesEdges.FindKey(i));
1261 if ( !ChangedFaces.Contains(tmpF) )
1262 ChangedFaces.Add(tmpF);
1266 } // end processing each face
1268 // fix changed faces and replace them in the local context
1269 for (Standard_Integer i=1; i<=ChangedFaces.Extent(); i++) {
1270 //TopoDS_Face aFace = TopoDS::Face(aContext->Apply(ChangedFaces.FindKey(i)));
1271 TopoDS_Face aFace = TopoDS::Face(myContext->Apply(ChangedFaces.FindKey(i)));
1272 Handle(ShapeFix_Face) sff = new ShapeFix_Face(aFace);
1273 sff->SetContext(myContext);
1274 sff->SetPrecision(myTolerance);
1275 sff->SetMinTolerance(myTolerance);
1276 sff->SetMaxTolerance(Max(1.,myTolerance*1000.));
1278 TopoDS_Shape aNewFace = sff->Face();
1279 //aContext->Replace(aFace,aNewFace);
1280 myContext->Replace(aFace,aNewFace);
1283 if (!myOldNewMap.IsBound(aFace))
1285 TopTools_ListOfShape EmptyList;
1286 myOldNewMap.Bind(aFace, EmptyList);
1288 myOldNewMap(aFace).Clear();
1289 myOldNewMap(aFace).Append(aNewFace);
1294 if (ChangedFaces.Extent() > 0) {
1295 // fix changed shell and replace it in the local context
1296 //TopoDS_Shape aRes1 = aContext->Apply(aRes);
1297 TopoDS_Shape aRes1 = myContext->Apply(aRes);
1298 TopExp_Explorer expsh;
1299 for (expsh.Init(aRes1, TopAbs_SHELL); expsh.More(); expsh.Next()) {
1300 TopoDS_Shell aShell = TopoDS::Shell(expsh.Current());
1301 Handle(ShapeFix_Shell) sfsh = new ShapeFix_Shell;
1302 sfsh->FixFaceOrientation(aShell);
1303 TopoDS_Shape aNewShell = sfsh->Shell();
1304 //aContext->Replace(aShell,aNewShell);
1305 myContext->Replace(aShell,aNewShell);
1308 if (!myOldNewMap.IsBound(aShell))
1310 TopTools_ListOfShape EmptyList;
1311 myOldNewMap.Bind(aShell, EmptyList);
1313 myOldNewMap(aShell).Clear();
1314 myOldNewMap(aShell).Append(aNewShell);
1318 //TopoDS_Shape aRes2 = aContext->Apply(aRes1);
1319 TopoDS_Shape aRes2 = myContext->Apply(aRes1);
1320 // put new solid into global context
1321 myContext->Replace(aSolid,aRes2);
1324 if (!myOldNewMap.IsBound(aSolid))
1326 TopTools_ListOfShape EmptyList;
1327 myOldNewMap.Bind(aSolid, EmptyList);
1329 myOldNewMap(aSolid).Clear();
1330 myOldNewMap(aSolid).Append(aRes2);
1335 } // end processing each solid
1337 myShape = myContext->Apply(myShape);
1340 //=======================================================================
1341 //function : UnifyFacesAndEdges
1343 //=======================================================================
1345 void ShapeUpgrade_UnifySameDomain::UnifyFacesAndEdges()
1350 ShapeUpgrade_RemoveLocations RemLoc;
1351 RemLoc.Remove(myShape);
1352 myShape = RemLoc.GetResult();
1358 //=======================================================================
1360 //purpose : builds the resulting shape
1361 //======================================================================
1362 void ShapeUpgrade_UnifySameDomain::Build()
1364 if (myUnifyFaces && myUnifyEdges)
1365 UnifyFacesAndEdges();
1367 else if (myUnifyEdges)
1369 else if (myUnifyFaces)
1375 //=======================================================================
1377 //purpose : give the resulting shape
1378 //=======================================================================
1379 const TopoDS_Shape& ShapeUpgrade_UnifySameDomain::Shape() const
1384 //=======================================================================
1385 //function : Generated
1386 //purpose : returns the new shape from the old one
1387 //=======================================================================
1388 TopoDS_Shape ShapeUpgrade_UnifySameDomain::Generated(const TopoDS_Shape& aShape) const
1390 TopoDS_Shape aNewShape = myContext->Apply(aShape);
1392 if (aNewShape.IsNull())
1393 aNewShape = myOldNewMap(aShape);