0026195: Visualization - optimize selection algorithms
[occt.git] / src / ShapeUpgrade / ShapeUpgrade_UnifySameDomain.cxx
CommitLineData
973c2be1 1// Created on: 2012-06-09
2// Created by: jgv@ROLEX
3// Copyright (c) 2012-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
d5f74e42 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
973c2be1 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.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
2277323d 15
42cf5bc1 16
2277323d 17#include <BRep_Builder.hxx>
42cf5bc1 18#include <BRep_CurveRepresentation.hxx>
2277323d 19#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
20#include <BRep_TEdge.hxx>
42cf5bc1 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>
2277323d 27#include <Geom2d_TrimmedCurve.hxx>
2277323d 28#include <Geom2dConvert.hxx>
2277323d 29#include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
2277323d 30#include <Geom_BezierCurve.hxx>
42cf5bc1 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>
48#include <gp_Dir.hxx>
49#include <gp_Lin.hxx>
50#include <IntPatch_ImpImpIntersection.hxx>
51#include <ShapeAnalysis_Edge.hxx>
2277323d 52#include <ShapeAnalysis_WireOrder.hxx>
53#include <ShapeBuild_Edge.hxx>
42cf5bc1 54#include <ShapeBuild_ReShape.hxx>
2277323d 55#include <ShapeExtend_CompositeSurface.hxx>
56#include <ShapeFix_ComposeShell.hxx>
2277323d 57#include <ShapeFix_Edge.hxx>
42cf5bc1 58#include <ShapeFix_Face.hxx>
59#include <ShapeFix_SequenceOfWireSegment.hxx>
2277323d 60#include <ShapeFix_Shell.hxx>
42cf5bc1 61#include <ShapeFix_Wire.hxx>
62#include <ShapeFix_WireSegment.hxx>
2277323d 63#include <ShapeUpgrade_RemoveLocations.hxx>
42cf5bc1 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>
75#include <TopExp.hxx>
76#include <TopExp_Explorer.hxx>
77#include <TopoDS.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>
b4d4dbe8 84#include <TopTools_MapOfShape.hxx>
42cf5bc1 85#include <TopTools_SequenceOfShape.hxx>
f7d70540 86#include <gp_Circ.hxx>
87#include <BRepAdaptor_Curve.hxx>
88
89struct SubSequenceOfEdges
90{
91 TopTools_SequenceOfShape SeqsEdges;
92 TopoDS_Edge UnionEdges;
93};
94
2277323d 95
96//=======================================================================
97//function : AddOrdinaryEdges
98//purpose : auxilary
99//=======================================================================
100// adds edges from the shape to the sequence
101// seams and equal edges are dropped
102// Returns true if one of original edges dropped
103static Standard_Boolean AddOrdinaryEdges(TopTools_SequenceOfShape& edges,
104 const TopoDS_Shape aShape,
105 Standard_Integer& anIndex)
106{
107 //map of edges
108 TopTools_IndexedMapOfShape aNewEdges;
109 //add edges without seams
110 for(TopExp_Explorer exp(aShape,TopAbs_EDGE); exp.More(); exp.Next()) {
111 TopoDS_Shape edge = exp.Current();
112 if(aNewEdges.Contains(edge))
113 {
114 //aNewEdges.Remove(edge);
115 TopoDS_Shape LastEdge = aNewEdges(aNewEdges.Extent());
116 aNewEdges.RemoveLast();
117 if (aNewEdges.FindIndex(edge) != 0)
118 aNewEdges.Substitute(aNewEdges.FindIndex(edge), LastEdge);
119 /////////////////////////
120 }
121 else
122 aNewEdges.Add(edge);
123 }
124
125 Standard_Boolean isDropped = Standard_False;
126 //merge edges and drop seams
127 Standard_Integer i;
128 for (i = 1; i <= edges.Length(); i++) {
129 TopoDS_Shape current = edges(i);
130 if(aNewEdges.Contains(current)) {
131
132 //aNewEdges.Remove(current);
133 TopoDS_Shape LastEdge = aNewEdges(aNewEdges.Extent());
134 aNewEdges.RemoveLast();
135 if (aNewEdges.FindIndex(current) != 0)
136 aNewEdges.Substitute(aNewEdges.FindIndex(current), LastEdge);
137 /////////////////////////
138 edges.Remove(i);
139 i--;
140
141 if(!isDropped) {
142 isDropped = Standard_True;
143 anIndex = i;
144 }
145 }
146 }
147
148 //add edges to the sequemce
149 for (i = 1; i <= aNewEdges.Extent(); i++)
150 edges.Append(aNewEdges(i));
151
152 return isDropped;
153}
154
155//=======================================================================
156//function : getCylinder
157//purpose : auxilary
158//=======================================================================
159static Standard_Boolean getCylinder(Handle(Geom_Surface)& theInSurface,
160 gp_Cylinder& theOutCylinder)
161{
162 Standard_Boolean isCylinder = Standard_False;
163
164 if (theInSurface->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
165 Handle(Geom_CylindricalSurface) aGC = Handle(Geom_CylindricalSurface)::DownCast(theInSurface);
166
167 theOutCylinder = aGC->Cylinder();
168 isCylinder = Standard_True;
169 }
170 else if (theInSurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
171 Handle(Geom_SurfaceOfRevolution) aRS =
172 Handle(Geom_SurfaceOfRevolution)::DownCast(theInSurface);
173 Handle(Geom_Curve) aBasis = aRS->BasisCurve();
174 if (aBasis->IsKind(STANDARD_TYPE(Geom_Line))) {
175 Handle(Geom_Line) aBasisLine = Handle(Geom_Line)::DownCast(aBasis);
176 gp_Dir aDir = aRS->Direction();
177 gp_Dir aBasisDir = aBasisLine->Position().Direction();
178 if (aBasisDir.IsParallel(aDir, Precision::Angular())) {
179 // basis line is parallel to the revolution axis: it is a cylinder
180 gp_Pnt aLoc = aRS->Location();
181 Standard_Real aR = aBasisLine->Lin().Distance(aLoc);
182 gp_Ax3 aCylAx (aLoc, aDir);
183
184 theOutCylinder = gp_Cylinder(aCylAx, aR);
185 isCylinder = Standard_True;
186 }
187 }
188 }
189 else if (theInSurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) {
190 Handle(Geom_SurfaceOfLinearExtrusion) aLES =
191 Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(theInSurface);
192 Handle(Geom_Curve) aBasis = aLES->BasisCurve();
193 if (aBasis->IsKind(STANDARD_TYPE(Geom_Circle))) {
194 Handle(Geom_Circle) aBasisCircle = Handle(Geom_Circle)::DownCast(aBasis);
195 gp_Dir aDir = aLES->Direction();
196 gp_Dir aBasisDir = aBasisCircle->Position().Direction();
197 if (aBasisDir.IsParallel(aDir, Precision::Angular())) {
198 // basis circle is normal to the extrusion axis: it is a cylinder
199 gp_Pnt aLoc = aBasisCircle->Location();
200 Standard_Real aR = aBasisCircle->Radius();
201 gp_Ax3 aCylAx (aLoc, aDir);
202
203 theOutCylinder = gp_Cylinder(aCylAx, aR);
204 isCylinder = Standard_True;
205 }
206 }
207 }
208 else {
209 }
210
211 return isCylinder;
212}
213
214//=======================================================================
215//function : ClearRts
216//purpose : auxilary
217//=======================================================================
218static Handle(Geom_Surface) ClearRts(const Handle(Geom_Surface)& aSurface)
219{
220 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
221 Handle(Geom_RectangularTrimmedSurface) rts =
222 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
223 return rts->BasisSurface();
224 }
225 return aSurface;
226}
227
228//=======================================================================
229//function : IsSameDomain
230//purpose :
231//=======================================================================
232static Standard_Boolean IsSameDomain(const TopoDS_Face& aFace,
233 const TopoDS_Face& aCheckedFace)
234{
235 //checking the same handles
236 TopLoc_Location L1, L2;
237 Handle(Geom_Surface) S1, S2;
238
239 S1 = BRep_Tool::Surface(aFace,L1);
240 S2 = BRep_Tool::Surface(aCheckedFace,L2);
241
242 if (S1 == S2 && L1 == L2)
243 return Standard_True;
244
245 // planar and cylindrical cases (IMP 20052)
246 Standard_Real aPrec = Precision::Confusion();
247
248 S1 = BRep_Tool::Surface(aFace);
249 S2 = BRep_Tool::Surface(aCheckedFace);
250
251 S1 = ClearRts(S1);
252 S2 = ClearRts(S2);
253
254 //Handle(Geom_OffsetSurface) aGOFS1, aGOFS2;
255 //aGOFS1 = Handle(Geom_OffsetSurface)::DownCast(S1);
256 //aGOFS2 = Handle(Geom_OffsetSurface)::DownCast(S2);
257 //if (!aGOFS1.IsNull()) S1 = aGOFS1->BasisSurface();
258 //if (!aGOFS2.IsNull()) S2 = aGOFS2->BasisSurface();
259
260 // case of two elementary surfaces: use OCCT tool
261 // elementary surfaces: ConicalSurface, CylindricalSurface,
262 // Plane, SphericalSurface and ToroidalSurface
263 if (S1->IsKind(STANDARD_TYPE(Geom_ElementarySurface)) &&
264 S2->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
265 {
266 Handle(GeomAdaptor_HSurface) aGA1 = new GeomAdaptor_HSurface(S1);
267 Handle(GeomAdaptor_HSurface) aGA2 = new GeomAdaptor_HSurface(S2);
268
269 Handle(BRepTopAdaptor_TopolTool) aTT1 = new BRepTopAdaptor_TopolTool();
270 Handle(BRepTopAdaptor_TopolTool) aTT2 = new BRepTopAdaptor_TopolTool();
271
272 try {
273 IntPatch_ImpImpIntersection anIIInt (aGA1, aTT1, aGA2, aTT2, aPrec, aPrec);
274 if (!anIIInt.IsDone() || anIIInt.IsEmpty())
275 return Standard_False;
276
277 return anIIInt.TangentFaces();
278 }
279 catch (Standard_Failure) {
280 return Standard_False;
281 }
282 }
283
284 // case of two planar surfaces:
285 // all kinds of surfaces checked, including b-spline and bezier
286 GeomLib_IsPlanarSurface aPlanarityChecker1 (S1, aPrec);
287 if (aPlanarityChecker1.IsPlanar()) {
288 GeomLib_IsPlanarSurface aPlanarityChecker2 (S2, aPrec);
289 if (aPlanarityChecker2.IsPlanar()) {
290 gp_Pln aPln1 = aPlanarityChecker1.Plan();
291 gp_Pln aPln2 = aPlanarityChecker2.Plan();
292
293 if (aPln1.Position().Direction().IsParallel(aPln2.Position().Direction(),Precision::Angular()) &&
294 aPln1.Distance(aPln2) < aPrec) {
295 return Standard_True;
296 }
297 }
298 }
299
300 // case of two cylindrical surfaces, at least one of which is a swept surface
301 // swept surfaces: SurfaceOfLinearExtrusion, SurfaceOfRevolution
302 if ((S1->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ||
303 S1->IsKind(STANDARD_TYPE(Geom_SweptSurface))) &&
304 (S2->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ||
305 S2->IsKind(STANDARD_TYPE(Geom_SweptSurface))))
306 {
307 gp_Cylinder aCyl1, aCyl2;
308 if (getCylinder(S1, aCyl1) && getCylinder(S2, aCyl2)) {
309 if (fabs(aCyl1.Radius() - aCyl2.Radius()) < aPrec) {
310 gp_Dir aDir1 = aCyl1.Position().Direction();
311 gp_Dir aDir2 = aCyl2.Position().Direction();
312 if (aDir1.IsParallel(aDir2, Precision::Angular())) {
313 gp_Pnt aLoc1 = aCyl1.Location();
314 gp_Pnt aLoc2 = aCyl2.Location();
315 gp_Vec aVec12 (aLoc1, aLoc2);
316 if (aVec12.SquareMagnitude() < aPrec*aPrec ||
317 aVec12.IsParallel(aDir1, Precision::Angular())) {
318 return Standard_True;
319 }
320 }
321 }
322 }
323 }
324
325 return Standard_False;
326}
327
328//=======================================================================
329//function : MovePCurves
330//purpose :
331//=======================================================================
332static void MovePCurves(TopoDS_Face& aTarget,
333 const TopoDS_Face& aSource)
334{
335 BRep_Builder B;
336 for(TopExp_Explorer wexp(aSource,TopAbs_WIRE);wexp.More();wexp.Next()) {
337 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(TopoDS::Wire(wexp.Current()),
338 aTarget, Precision::Confusion());
339 sfw->FixReorder();
340 Standard_Boolean isReoredFailed = sfw->StatusReorder ( ShapeExtend_FAIL );
341 sfw->FixEdgeCurves();
342 if(isReoredFailed)
343 continue;
344
345 sfw->FixShifted();
346 sfw->FixDegenerated();
347
348 // remove degenerated edges from not degenerated points
349 ShapeAnalysis_Edge sae;
350 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
351 for(Standard_Integer i = 1; i<=sewd->NbEdges();i++) {
352 TopoDS_Edge E = sewd->Edge(i);
353 if(BRep_Tool::Degenerated(E)&&!sae.HasPCurve(E,aTarget)) {
354 sewd->Remove(i);
355 i--;
356 }
357 }
358
359 TopoDS_Wire ResWire = sfw->Wire();
360 B.Add(aTarget,ResWire);
361 }
362}
363
364//=======================================================================
365//function : GlueEdgesWithPCurves
366//purpose : Glues the pcurves of the sequence of edges
367// and glues their 3d curves
368//=======================================================================
369static TopoDS_Edge GlueEdgesWithPCurves(const TopTools_SequenceOfShape& aChain,
370 const TopoDS_Vertex& FirstVertex,
371 const TopoDS_Vertex& LastVertex)
372{
373 Standard_Integer i, j;
374
375 TopoDS_Edge FirstEdge = TopoDS::Edge(aChain(1));
376 //TColGeom2d_SequenceOfCurve PCurveSeq;
377 TColGeom_SequenceOfSurface SurfSeq;
378 //TopTools_SequenceOfShape LocSeq;
379
380 BRep_ListIteratorOfListOfCurveRepresentation itr( (Handle(BRep_TEdge)::DownCast(FirstEdge.TShape()))->Curves() );
381 for (; itr.More(); itr.Next())
382 {
383 Handle(BRep_CurveRepresentation) CurveRep = itr.Value();
384 if (CurveRep->IsCurveOnSurface())
385 {
386 //PCurveSeq.Append(CurveRep->PCurve());
387 SurfSeq.Append(CurveRep->Surface());
388 /*
389 TopoDS_Shape aLocShape;
390 aLocShape.Location(CurveRep->Location());
391 LocSeq.Append(aLocShape);
392 */
393 }
394 }
395
396 Standard_Real fpar, lpar;
397 BRep_Tool::Range(FirstEdge, fpar, lpar);
398 TopoDS_Edge PrevEdge = FirstEdge;
399 TopoDS_Vertex CV;
400 Standard_Real MaxTol = 0.;
401
402 TopoDS_Edge ResEdge;
403 BRep_Builder BB;
404
405 Standard_Integer nb_curve = aChain.Length(); //number of curves
406 TColGeom_Array1OfBSplineCurve tab_c3d(0,nb_curve-1); //array of the curves
407 TColStd_Array1OfReal tabtolvertex(0,nb_curve-1); //(0,nb_curve-2); //array of the tolerances
408
409 TopoDS_Vertex PrevVertex = FirstVertex;
410 for (i = 1; i <= nb_curve; i++)
411 {
412 TopoDS_Edge anEdge = TopoDS::Edge(aChain(i));
413 TopoDS_Vertex VF, VL;
414 TopExp::Vertices(anEdge, VF, VL);
415 Standard_Boolean ToReverse = (!VF.IsSame(PrevVertex));
416
417 Standard_Real Tol1 = BRep_Tool::Tolerance(VF);
418 Standard_Real Tol2 = BRep_Tool::Tolerance(VL);
419 if (Tol1 > MaxTol)
420 MaxTol = Tol1;
421 if (Tol2 > MaxTol)
422 MaxTol = Tol2;
423
424 if (i > 1)
425 {
426 TopExp::CommonVertex(PrevEdge, anEdge, CV);
427 Standard_Real Tol = BRep_Tool::Tolerance(CV);
428 tabtolvertex(i-2) = Tol;
429 }
430
431 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, fpar, lpar);
432 Handle(Geom_TrimmedCurve) aTrCurve = new Geom_TrimmedCurve(aCurve, fpar, lpar);
433 tab_c3d(i-1) = GeomConvert::CurveToBSplineCurve(aTrCurve);
434 GeomConvert::C0BSplineToC1BSplineCurve(tab_c3d(i-1), Precision::Confusion());
435 if (ToReverse)
436 tab_c3d(i-1)->Reverse();
437 PrevVertex = (ToReverse)? VF : VL;
438 PrevEdge = anEdge;
439 }
440 Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves
441 Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex
442 GeomConvert::ConcatC1(tab_c3d,
443 tabtolvertex,
444 ArrayOfIndices,
445 concatcurve,
446 Standard_False,
447 Precision::Confusion()); //C1 concatenation
448
449 if (concatcurve->Length() > 1)
450 {
451 GeomConvert_CompCurveToBSplineCurve Concat(concatcurve->Value(concatcurve->Lower()));
452
453 for (i = concatcurve->Lower()+1; i <= concatcurve->Upper(); i++)
454 Concat.Add( concatcurve->Value(i), MaxTol, Standard_True );
455
456 concatcurve->SetValue(concatcurve->Lower(), Concat.BSplineCurve());
457 }
458 Handle(Geom_BSplineCurve) ResCurve = concatcurve->Value(concatcurve->Lower());
459
460 TColGeom2d_SequenceOfBoundedCurve ResPCurves;
461 TopLoc_Location aLoc;
462 for (j = 1; j <= SurfSeq.Length(); j++)
463 {
464 TColGeom2d_Array1OfBSplineCurve tab_c2d(0,nb_curve-1); //array of the pcurves
465
466 PrevVertex = FirstVertex;
467 PrevEdge = FirstEdge;
468 //TopLoc_Location theLoc = LocSeq(j).Location();
469 for (i = 1; i <= nb_curve; i++)
470 {
471 TopoDS_Edge anEdge = TopoDS::Edge(aChain(i));
472 TopoDS_Vertex VF, VL;
473 TopExp::Vertices(anEdge, VF, VL);
474 Standard_Boolean ToReverse = (!VF.IsSame(PrevVertex));
475
476 /*
477 Handle(Geom2d_Curve) aPCurve =
478 BRep_Tool::CurveOnSurface(anEdge, SurfSeq(j), anEdge.Location()*theLoc, fpar, lpar);
479 */
480 Handle(Geom2d_Curve) aPCurve =
481 BRep_Tool::CurveOnSurface(anEdge, SurfSeq(j), aLoc, fpar, lpar);
482 Handle(Geom2d_TrimmedCurve) aTrPCurve = new Geom2d_TrimmedCurve(aPCurve, fpar, lpar);
483 tab_c2d(i-1) = Geom2dConvert::CurveToBSplineCurve(aTrPCurve);
484 Geom2dConvert::C0BSplineToC1BSplineCurve(tab_c2d(i-1), Precision::Confusion());
485 if (ToReverse)
486 tab_c2d(i-1)->Reverse();
487 PrevVertex = (ToReverse)? VF : VL;
488 PrevEdge = anEdge;
489 }
490 Handle(TColGeom2d_HArray1OfBSplineCurve) concatc2d; //array of the concatenated curves
491 Handle(TColStd_HArray1OfInteger) ArrayOfInd2d; //array of the remining Vertex
492 Geom2dConvert::ConcatC1(tab_c2d,
493 tabtolvertex,
494 ArrayOfInd2d,
495 concatc2d,
496 Standard_False,
497 Precision::Confusion()); //C1 concatenation
498
499 if (concatc2d->Length() > 1)
500 {
501 Geom2dConvert_CompCurveToBSplineCurve Concat2d(concatc2d->Value(concatc2d->Lower()));
502
503 for (i = concatc2d->Lower()+1; i <= concatc2d->Upper(); i++)
504 Concat2d.Add( concatc2d->Value(i), MaxTol, Standard_True );
505
506 concatc2d->SetValue(concatc2d->Lower(), Concat2d.BSplineCurve());
507 }
508 Handle(Geom2d_BSplineCurve) aResPCurve = concatc2d->Value(concatc2d->Lower());
509 ResPCurves.Append(aResPCurve);
510 }
511
512 ResEdge = BRepLib_MakeEdge(ResCurve,
513 FirstVertex, LastVertex,
514 ResCurve->FirstParameter(), ResCurve->LastParameter());
515 BB.SameRange(ResEdge, Standard_False);
516 BB.SameParameter(ResEdge, Standard_False);
517 for (j = 1; j <= ResPCurves.Length(); j++)
518 {
519 BB.UpdateEdge(ResEdge, ResPCurves(j), SurfSeq(j), aLoc, MaxTol);
520 BB.Range(ResEdge, SurfSeq(j), aLoc, ResPCurves(j)->FirstParameter(), ResPCurves(j)->LastParameter());
521 }
522
523 BRepLib::SameParameter(ResEdge, MaxTol, Standard_True);
524
525 return ResEdge;
526}
527
f7d70540 528static Standard_Boolean MergeSubSeq(const TopTools_SequenceOfShape& aChain, TopoDS_Edge& OutEdge, double Tol, Standard_Boolean ConcatBSplines)
2277323d 529{
2277323d 530 ShapeAnalysis_Edge sae;
f7d70540 531 BRep_Builder B;
2277323d 532 // union edges in chain
f7d70540 533 int j;
2277323d 534 Standard_Real fp1,lp1,fp2,lp2;
f7d70540 535 Standard_Boolean IsUnionOfLinesPossible = Standard_True;
536 Standard_Boolean IsUnionOfCirclesPossible = Standard_True;
537 Handle(Geom_Curve) c3d1, c3d2;
538 for(j=1; j<aChain.Length(); j++)
539 {
2277323d 540 TopoDS_Edge edge1 = TopoDS::Edge(aChain.Value(j));
f7d70540 541 c3d1 = BRep_Tool::Curve(edge1,fp1,lp1);
542
543 TopoDS_Edge edge2 = TopoDS::Edge(aChain.Value(j+1));
544 c3d2 = BRep_Tool::Curve(edge2,fp2,lp2);
545
546 if(c3d1.IsNull() || c3d2.IsNull())
547 return Standard_False;
b4d4dbe8 548
2277323d 549 while(c3d1->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
550 Handle(Geom_TrimmedCurve) tc =
551 Handle(Geom_TrimmedCurve)::DownCast(c3d1);
552 c3d1 = tc->BasisCurve();
553 }
2277323d 554 while(c3d2->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
555 Handle(Geom_TrimmedCurve) tc =
556 Handle(Geom_TrimmedCurve)::DownCast(c3d2);
557 c3d2 = tc->BasisCurve();
558 }
559 if( c3d1->IsKind(STANDARD_TYPE(Geom_Line)) && c3d2->IsKind(STANDARD_TYPE(Geom_Line)) ) {
2277323d 560 Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(c3d1);
561 Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(c3d2);
562 gp_Dir Dir1 = L1->Position().Direction();
563 gp_Dir Dir2 = L2->Position().Direction();
f7d70540 564 if(!Dir1.IsParallel(Dir2,Tol))
565 IsUnionOfLinesPossible = Standard_False;
2277323d 566 }
f7d70540 567 else
568 IsUnionOfLinesPossible = Standard_False;
2277323d 569 if( c3d1->IsKind(STANDARD_TYPE(Geom_Circle)) && c3d2->IsKind(STANDARD_TYPE(Geom_Circle)) ) {
2277323d 570 Handle(Geom_Circle) C1 = Handle(Geom_Circle)::DownCast(c3d1);
571 Handle(Geom_Circle) C2 = Handle(Geom_Circle)::DownCast(c3d2);
572 gp_Pnt P01 = C1->Location();
573 gp_Pnt P02 = C2->Location();
b4d4dbe8 574 if (P01.Distance(P02) > Precision::Confusion())
f7d70540 575 IsUnionOfCirclesPossible = Standard_False;
576 }
577 else
578 IsUnionOfCirclesPossible = Standard_False;
579 }
580 if (IsUnionOfLinesPossible && IsUnionOfCirclesPossible)
581 return Standard_False;
582
583 //union of lines is possible
584 if (IsUnionOfLinesPossible)
585 {
586 TopoDS_Vertex V1 = sae.FirstVertex(TopoDS::Edge(aChain.First()));
587 gp_Pnt PV1 = BRep_Tool::Pnt(V1);
588 TopoDS_Vertex V2 = sae.LastVertex(TopoDS::Edge(aChain.Last()));
589 gp_Pnt PV2 = BRep_Tool::Pnt(V2);
590 gp_Vec Vec(PV1, PV2);
591 Handle(Geom_Line) L = new Geom_Line(gp_Ax1(PV1,Vec));
592 Standard_Real dist = PV1.Distance(PV2);
593 Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(L,0.0,dist);
594 TopoDS_Edge E;
595 B.MakeEdge (E, tc ,Precision::Confusion());
596 B.Add (E,V1); B.Add (E,V2);
597 B.UpdateVertex(V1, 0., E, 0.);
598 B.UpdateVertex(V2, dist, E, 0.);
599 OutEdge = E;
600 return Standard_True;
601 }
602
603 if (IsUnionOfCirclesPossible)
604 {
605 double f,l;
606 TopoDS_Edge FE = TopoDS::Edge(aChain.First());
607 Handle(Geom_Curve) c3d = BRep_Tool::Curve(FE,f,l);
608
609 while(c3d->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
610 Handle(Geom_TrimmedCurve) tc =
611 Handle(Geom_TrimmedCurve)::DownCast(c3d);
612 c3d = tc->BasisCurve();
613 }
614 Handle(Geom_Circle) Cir = Handle(Geom_Circle)::DownCast(c3d);
615
616 TopoDS_Vertex V1 = sae.FirstVertex(FE);
f7d70540 617 TopoDS_Vertex V2 = sae.LastVertex(TopoDS::Edge(aChain.Last()));
f7d70540 618 TopoDS_Edge E;
dd2f1b75 619 if (V1.IsSame(V2)) {
f7d70540 620 // closed chain
dd2f1b75 621 BRepAdaptor_Curve adef(FE);
622 Handle(Geom_Circle) Cir1;
623 double FP, LP;
624 if ( FE.Orientation() == TopAbs_FORWARD)
625 {
626 FP = adef.FirstParameter();
627 LP = adef.LastParameter();
628 }
629 else
630 {
631 FP = adef.LastParameter();
632 LP = adef.FirstParameter();
633 }
634 if (Abs(FP) < Precision::PConfusion())
635 {
636 B.MakeEdge (E,Cir, Precision::Confusion());
637 B.Add(E,V1);
638 B.Add(E,V2);
639 E.Orientation(FE.Orientation());
640 }
641 else
642 {
643 GC_MakeCircle MC1 (adef.Value(FP), adef.Value((FP + LP) * 0.5), adef.Value(LP));
644 if (MC1.IsDone())
645 Cir1 = MC1.Value();
646 else
647 return Standard_False;
648 B.MakeEdge (E, Cir1, Precision::Confusion());
649 B.Add(E,V1);
650 B.Add(E,V2);
651 }
f7d70540 652 }
653 else {
dd2f1b75 654 gp_Pnt PV1 = BRep_Tool::Pnt(V1);
655 gp_Pnt PV2 = BRep_Tool::Pnt(V2);
656 TopoDS_Vertex VM = sae.LastVertex(FE);
657 gp_Pnt PVM = BRep_Tool::Pnt(VM);
658 GC_MakeCircle MC (PV1,PVM,PV2);
f7d70540 659 Handle(Geom_Circle) C = MC.Value();
660 gp_Pnt P0 = C->Location();
661 gp_Dir D1(gp_Vec(P0,PV1));
662 gp_Dir D2(gp_Vec(P0,PV2));
663 Standard_Real fpar = C->XAxis().Direction().Angle(D1);
664 if(fabs(fpar)>Precision::Confusion()) {
665 // check orientation
666 gp_Dir ND = C->XAxis().Direction().Crossed(D1);
667 if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) {
668 fpar = -fpar;
2277323d 669 }
f7d70540 670 }
671 Standard_Real lpar = C->XAxis().Direction().Angle(D2);
672 if(fabs(lpar)>Precision::Confusion()) {
673 // check orientation
674 gp_Dir ND = C->XAxis().Direction().Crossed(D2);
675 if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) {
676 lpar = -lpar;
2277323d 677 }
2277323d 678 }
f7d70540 679 if (lpar < fpar) lpar += 2*M_PI;
680 Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(C,fpar,lpar);
681 B.MakeEdge (E,tc,Precision::Confusion());
682 B.Add(E,V1);
683 B.Add(E,V2);
684 B.UpdateVertex(V1, fpar, E, 0.);
685 B.UpdateVertex(V2, lpar, E, 0.);
2277323d 686 }
f7d70540 687 OutEdge = E;
688 return Standard_True;
2277323d 689 }
690 if (aChain.Length() > 1 && ConcatBSplines) {
691 // second step: union edges with various curves
692 // skl for bug 0020052 from Mantis: perform such unions
693 // only if curves are bspline or bezier
f7d70540 694
695 TopoDS_Vertex VF = sae.FirstVertex(TopoDS::Edge(aChain.First()));
696 TopoDS_Vertex VL = sae.LastVertex(TopoDS::Edge(aChain.Last()));
697 Standard_Boolean NeedUnion = Standard_True;
2277323d 698 for(j=1; j<=aChain.Length(); j++) {
699 TopoDS_Edge edge = TopoDS::Edge(aChain.Value(j));
b4d4dbe8 700 TopLoc_Location Loc;
2277323d 701 Handle(Geom_Curve) c3d = BRep_Tool::Curve(edge,Loc,fp1,lp1);
702 if(c3d.IsNull()) continue;
703 while(c3d->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
704 Handle(Geom_TrimmedCurve) tc =
705 Handle(Geom_TrimmedCurve)::DownCast(c3d);
706 c3d = tc->BasisCurve();
707 }
708 if( ( c3d->IsKind(STANDARD_TYPE(Geom_BSplineCurve)) ||
709 c3d->IsKind(STANDARD_TYPE(Geom_BezierCurve)) ) ) continue;
f7d70540 710 NeedUnion = Standard_False;
2277323d 711 break;
712 }
713 if(NeedUnion) {
0797d9d3 714#ifdef OCCT_DEBUG
2277323d 715 cout<<"can not make analitical union => make approximation"<<endl;
716#endif
717 TopoDS_Edge E = GlueEdgesWithPCurves(aChain, VF, VL);
f7d70540 718 OutEdge = E;
719 return Standard_True;
2277323d 720 }
721 else {
0797d9d3 722#ifdef OCCT_DEBUG
2277323d 723 cout<<"can not make approximation for such types of curves"<<endl;
724#endif
725 return Standard_False;
726 }
727 }
f7d70540 728 return Standard_False;
729}
730
731static Standard_Boolean IsMergingPossible(const TopoDS_Edge& edge1, const TopoDS_Edge& edge2,
732 double Tol, const TopTools_MapOfShape& DegEdgeVrt)
733{
734 TopoDS_Vertex CV = TopExp::LastVertex(edge1, Standard_True);
735 if (CV.IsNull() || DegEdgeVrt.Contains(CV))
736 return Standard_False;
737
738 BRepAdaptor_Curve ade1(edge1);
739 BRepAdaptor_Curve ade2(edge2);
740
741 GeomAbs_CurveType t1 = ade1.GetType();
742 GeomAbs_CurveType t2 = ade2.GetType();
743
744 if( t1 == GeomAbs_Circle && t2 == GeomAbs_Circle)
745 {
746 if (ade1.Circle().Location().Distance(ade2.Circle().Location()) > Precision::Confusion())
747 return Standard_False;
748 }
749
750 if( ( (t1 != GeomAbs_BezierCurve && t1 != GeomAbs_BSplineCurve) ||
751 (t2 != GeomAbs_BezierCurve && t2 != GeomAbs_BSplineCurve)) && t1 != t2)
752 return Standard_False;
753
754 gp_Vec Diff1, Diff2;
755 gp_Pnt P1, P2;
756 if (edge1.Orientation() == TopAbs_FORWARD)
757 ade1.D1(ade1.LastParameter(), P1, Diff1);
758 else
759 {
760 ade1.D1(ade1.FirstParameter(), P1, Diff1);
761 Diff1 = -Diff1;
762 }
763
764 if (edge2.Orientation() == TopAbs_FORWARD)
765 ade2.D1(ade2.FirstParameter(), P2, Diff2);
766 else
767 {
768 ade2.D1(ade2.LastParameter(), P2, Diff2);
769 Diff2 = -Diff2;
770 }
771
772 if (Diff1.Angle(Diff2) > Tol)
773 return Standard_False;
774
775 return Standard_True;
776}
777
778static void GenerateSubSeq (const TopTools_SequenceOfShape& anInpEdgeSeq,
779 NCollection_Sequence<SubSequenceOfEdges>& SeqOfSubSeqOfEdges,
780 Standard_Boolean IsClosed, double Tol, const TopTools_MapOfShape& DegEdgeVrt )
781{
782 Standard_Boolean isOk = Standard_False;
783 TopoDS_Edge edge1, edge2;
784
785 SubSequenceOfEdges SubSeq;
786 SubSeq.SeqsEdges.Append(TopoDS::Edge(anInpEdgeSeq(1)));
787 SeqOfSubSeqOfEdges.Append(SubSeq);
788
789 for (int i = 1; i < anInpEdgeSeq.Length(); i++)
790 {
791 edge1 = TopoDS::Edge(anInpEdgeSeq(i));
792 edge2 = TopoDS::Edge(anInpEdgeSeq(i+1));
793 isOk = IsMergingPossible(edge1, edge2, Tol, DegEdgeVrt);
794 if (!isOk)
795 {
796 SubSequenceOfEdges SubSeq;
797 SubSeq.SeqsEdges.Append(edge2);
798 SeqOfSubSeqOfEdges.Append(SubSeq);
799 }
800 else
801 SeqOfSubSeqOfEdges.ChangeLast().SeqsEdges.Append(edge2);
802 }
803 /// check first and last chain segments
804 if (IsClosed && SeqOfSubSeqOfEdges.Length() > 1)
805 {
806 edge1 = TopoDS::Edge(anInpEdgeSeq.Last());
807 edge2 = TopoDS::Edge(anInpEdgeSeq.First());
808 if (IsMergingPossible(edge1, edge2, Tol, DegEdgeVrt))
809 {
810 SeqOfSubSeqOfEdges.ChangeLast().SeqsEdges.Append(SeqOfSubSeqOfEdges.ChangeFirst().SeqsEdges);
811 SeqOfSubSeqOfEdges.Remove(1);
812 }
813 }
814}
815
816
817//=======================================================================
818//function : MergeEdges
819//purpose : auxilary
820//=======================================================================
821static Standard_Boolean MergeEdges(const TopTools_SequenceOfShape& SeqEdges,
822 const Standard_Real Tol,
823 const Standard_Boolean ConcatBSplines,
824 NCollection_Sequence<SubSequenceOfEdges>& SeqOfSubSeqOfEdges,
825 const TopTools_MapOfShape& NonMergVrt )
826{
827 // make chain for union
828 //BRep_Builder B;
829 ShapeAnalysis_Edge sae;
830 TopoDS_Edge FirstE = TopoDS::Edge(SeqEdges.Value(1));
831 TopoDS_Edge LastE = FirstE;
832 TopoDS_Vertex VF = sae.FirstVertex(FirstE);
833 TopoDS_Vertex VL = sae.LastVertex(LastE);
834 TopTools_SequenceOfShape aChain;
835 aChain.Append(FirstE);
836 TColStd_MapOfInteger IndUsedEdges;
837 IndUsedEdges.Add(1);
838 Standard_Integer j;
839 TopTools_MapOfShape VerticesToAvoid;
840 TopTools_SequenceOfShape SeqEdges1;
841 for (j = 1; j <= SeqEdges.Length(); j++)
842 {
843 TopoDS_Edge anEdge = TopoDS::Edge(SeqEdges(j));
844 if (BRep_Tool::Degenerated(anEdge))
845 {
846 TopoDS_Vertex V1, V2;
847 TopExp::Vertices(anEdge, V1, V2);
848 VerticesToAvoid.Add(V1);
849 VerticesToAvoid.Add(V2);
850 continue;
851 }
852 SeqEdges1.Append(anEdge);
853 }
854
855 for(j=2; j<=SeqEdges1.Length(); j++) {
856 for(Standard_Integer k=2; k<=SeqEdges1.Length(); k++) {
857 if(IndUsedEdges.Contains(k)) continue;
858 TopoDS_Edge edge = TopoDS::Edge(SeqEdges1.Value(k));
859 TopoDS_Vertex VF2 = sae.FirstVertex(edge);
860 TopoDS_Vertex VL2 = sae.LastVertex(edge);
861 if(VF2.IsSame(VL)) {
862 aChain.Append(edge);
863 LastE = edge;
864 VL = sae.LastVertex(LastE);
865 IndUsedEdges.Add(k);
866 }
867 else if(VL2.IsSame(VF)) {
868 aChain.Prepend(edge);
869 FirstE = edge;
870 VF = sae.FirstVertex(FirstE);
871 IndUsedEdges.Add(k);
872 }
873 }
874 }
f7d70540 875
876 Standard_Boolean IsClosed = Standard_False;
877 if (VF.IsSame ( VL ))
878 IsClosed = Standard_True;
2277323d 879
f7d70540 880 VerticesToAvoid.Unite(NonMergVrt);
881 GenerateSubSeq(aChain, SeqOfSubSeqOfEdges, IsClosed, Tol, VerticesToAvoid);
882
883 for (int i = 1; i <= SeqOfSubSeqOfEdges.Length(); i++)
884 {
885 TopoDS_Edge UE;
886 if (SeqOfSubSeqOfEdges(i).SeqsEdges.Length() < 2)
887 continue;
888 if (MergeSubSeq(SeqOfSubSeqOfEdges(i).SeqsEdges, UE, Tol, ConcatBSplines))
889 SeqOfSubSeqOfEdges(i).UnionEdges = UE;
890 }
2277323d 891 return Standard_True;
892}
893
f7d70540 894static Standard_Boolean MergeSeq (const TopTools_SequenceOfShape& SeqEdges,
895 const Standard_Real Tol,
896 const Standard_Boolean ConcatBSplines,
897 Handle(ShapeBuild_ReShape)& theContext,
898 TopTools_DataMapOfShapeShape& theOldShapes,
899 const TopTools_MapOfShape& nonMergVert,
900 const TopTools_DataMapOfShapeShape& NewEdges2OldEdges)
901{
902 NCollection_Sequence<SubSequenceOfEdges> SeqOfSubsSeqOfEdges;
903 int k = 1;
904 if ( MergeEdges(SeqEdges, Tol, ConcatBSplines, SeqOfSubsSeqOfEdges, nonMergVert) )
905 {
906 for (Standard_Integer i = 1; i <= SeqOfSubsSeqOfEdges.Length(); i++ )
907 {
908 if (SeqOfSubsSeqOfEdges(i).UnionEdges.IsNull())
909 continue;
910 theContext->Replace(SeqOfSubsSeqOfEdges(i).SeqsEdges(1), SeqOfSubsSeqOfEdges(i).UnionEdges);
911 k++;
912 for (Standard_Integer j = 2; j <= SeqOfSubsSeqOfEdges(i).SeqsEdges.Length(); j++)
913 {
914 TopoDS_Shape OldEdge = NewEdges2OldEdges(SeqOfSubsSeqOfEdges(i).SeqsEdges(j));
915 theOldShapes.Bind(OldEdge, SeqOfSubsSeqOfEdges(i).UnionEdges);
916 theContext->Remove(SeqOfSubsSeqOfEdges(i).SeqsEdges(j));
917 }
918 }
919 return Standard_True;
920 }
921 else
922 return Standard_False;
923}
924
925static void CheckSharedVertices(const TopTools_SequenceOfShape& theSeqEdges,
926 const TopTools_IndexedDataMapOfShapeListOfShape& theMapEdgesVertex,
927 TopTools_MapOfShape& theShareVertMap)
928{
929 ShapeAnalysis_Edge sae;
930 TopTools_SequenceOfShape SeqVertexes;
931 TopTools_MapOfShape MapVertexes;
932 for (Standard_Integer k = 1; k <= theSeqEdges.Length(); k++ )
933 {
934 TopoDS_Vertex aV1 = sae.FirstVertex(TopoDS::Edge(theSeqEdges(k)));
935 TopoDS_Vertex aV2 = sae.LastVertex(TopoDS::Edge(theSeqEdges(k)));
936 if (!MapVertexes.Add(aV1))
937 SeqVertexes.Append(aV1);
938 if (!MapVertexes.Add(aV2))
939 SeqVertexes.Append(aV2);
940 }
941
942 for (Standard_Integer k = 1; k <= SeqVertexes.Length()/* && !IsSharedVertexPresent*/; k++ )
943 {
944 const TopTools_ListOfShape& ListEdgesV1 = theMapEdgesVertex.FindFromKey(SeqVertexes(k));
945 TopTools_MapOfShape aMapOfEdges;
946 TopTools_ListIteratorOfListOfShape iter(ListEdgesV1);
947 for (; iter.More(); iter.Next())
948 aMapOfEdges.Add(iter.Value());
949 if (aMapOfEdges.Extent() > 2)
950 theShareVertMap.Add(SeqVertexes(k));
951 }
952 //return theShareVertMap.IsEmpty() ? false : true;
953}
954
2277323d 955//=======================================================================
956//function : ShapeUpgrade_UnifySameDomain
957//purpose : Constructor
958//=======================================================================
959
960ShapeUpgrade_UnifySameDomain::ShapeUpgrade_UnifySameDomain()
961{
962 myUnifyEdges = Standard_True;
963 myUnifyFaces = Standard_True;
964 myConcatBSplines = Standard_False;
965
966 myContext = new ShapeBuild_ReShape;
967}
968
969//=======================================================================
970//function : ShapeUpgrade_UnifySameDomain
971//purpose : Constructor
972//=======================================================================
973
974ShapeUpgrade_UnifySameDomain::ShapeUpgrade_UnifySameDomain(const TopoDS_Shape& aShape,
975 const Standard_Boolean UnifyEdges,
976 const Standard_Boolean UnifyFaces,
977 const Standard_Boolean ConcatBSplines)
978{
979 myInitShape = aShape;
980 myShape = aShape;
981 myUnifyEdges = UnifyEdges;
982 myUnifyFaces = UnifyFaces;
983 myConcatBSplines = ConcatBSplines;
984
985 myContext = new ShapeBuild_ReShape;
986}
987
988//=======================================================================
989//function : Initialize
990//purpose :
991//=======================================================================
992
993void ShapeUpgrade_UnifySameDomain::Initialize(const TopoDS_Shape& aShape,
994 const Standard_Boolean UnifyEdges,
995 const Standard_Boolean UnifyFaces,
996 const Standard_Boolean ConcatBSplines)
997{
998 myInitShape = aShape;
999 myShape = aShape;
1000 myUnifyEdges = UnifyEdges;
1001 myUnifyFaces = UnifyFaces;
1002 myConcatBSplines = ConcatBSplines;
1003
1004 myContext->Clear();
f7d70540 1005 myOldShapes.Clear();
2277323d 1006 //myGenerated.Clear();
1007}
1008
1009//=======================================================================
1010//function : UnifyFaces
1011//purpose :
1012//=======================================================================
1013
1014void ShapeUpgrade_UnifySameDomain::UnifyFaces()
1015{
1016 //Handle(ShapeBuild_ReShape) myContext = new ShapeBuild_ReShape;
1017 TopoDS_Shape aResShape = myContext->Apply(myShape);
1018
1019 // processing each shell
1020 TopExp_Explorer exps;
1021 for (exps.Init(myShape, TopAbs_SHELL); exps.More(); exps.Next()) {
1022 TopoDS_Shell aShell = TopoDS::Shell(exps.Current());
1023
1024 // creating map of edge faces
1025 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
1026 TopExp::MapShapesAndAncestors(aShell, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
1027
1028 // map of processed shapes
1029 TopTools_MapOfShape aProcessed;
1030
1031 //Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
1032
1033 Standard_Integer NbModif = 0;
1034 Standard_Boolean hasFailed = Standard_False;
1035 Standard_Real tol = Precision::Confusion();
1036
1037 // count faces
1038 Standard_Integer nbf = 0;
1039 TopExp_Explorer exp;
1040 TopTools_MapOfShape mapF;
1041 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
1042 if (mapF.Add(exp.Current()))
1043 nbf++;
1044 }
1045
1046 // processing each face
1047 mapF.Clear();
1048 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
1049 TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
1050
1051 if (aProcessed.Contains(aFace))
1052 continue;
1053
1054 Standard_Integer dummy;
1055 TopTools_SequenceOfShape edges;
1056 AddOrdinaryEdges(edges,aFace,dummy);
1057
1058 TopTools_SequenceOfShape faces;
1059 faces.Append(aFace);
1060
1061 //surface and location to construct result
1062 TopLoc_Location aBaseLocation;
1063 Handle(Geom_Surface) aBaseSurface = BRep_Tool::Surface(aFace,aBaseLocation);
1064 aBaseSurface = ClearRts(aBaseSurface);
1065
1066 // find adjacent faces to union
1067 Standard_Integer i;
1068 for (i = 1; i <= edges.Length(); i++) {
1069 TopoDS_Edge edge = TopoDS::Edge(edges(i));
1070 if (BRep_Tool::Degenerated(edge))
1071 continue;
1072
1073 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
1074 TopTools_ListIteratorOfListOfShape anIter(aList);
1075 for (; anIter.More(); anIter.Next()) {
1076 TopoDS_Face anCheckedFace = TopoDS::Face(anIter.Value().Oriented(TopAbs_FORWARD));
1077 if (anCheckedFace.IsSame(aFace))
1078 continue;
1079
1080 if (aProcessed.Contains(anCheckedFace))
1081 continue;
1082
1083 if (IsSameDomain(aFace,anCheckedFace)) {
1084
1085 if (aList.Extent() != 2) {
1086 // non mainfold case is not processed
1087 continue;
1088 }
1089
1090 // replacing pcurves
1091 TopoDS_Face aMockUpFace;
1092 BRep_Builder B;
1093 B.MakeFace(aMockUpFace,aBaseSurface,aBaseLocation,0.);
1094 MovePCurves(aMockUpFace,anCheckedFace);
1095
1096 if (AddOrdinaryEdges(edges,aMockUpFace,dummy)) {
1097 // sequence edges is modified
1098 i = dummy;
1099 }
1100
1101 faces.Append(anCheckedFace);
1102 aProcessed.Add(anCheckedFace);
1103 break;
1104 }
1105 }
1106 }
1107
1108 // all faces collected in the sequence. Perform union of faces
1109 if (faces.Length() > 1) {
1110 NbModif++;
1111 TopoDS_Face aResult;
1112 BRep_Builder B;
1113 B.MakeFace(aResult,aBaseSurface,aBaseLocation,0);
1114 Standard_Integer nbWires = 0;
1115
1116 // connecting wires
1117 while (edges.Length()>0) {
1118
1119 Standard_Boolean isEdge3d = Standard_False;
1120 nbWires++;
1121 TopTools_MapOfShape aVertices;
1122 TopoDS_Wire aWire;
1123 B.MakeWire(aWire);
1124
1125 TopoDS_Edge anEdge = TopoDS::Edge(edges(1));
1126 edges.Remove(1);
1127
1128 isEdge3d |= !BRep_Tool::Degenerated(anEdge);
1129 B.Add(aWire,anEdge);
1130 TopoDS_Vertex V1,V2;
1131 TopExp::Vertices(anEdge,V1,V2);
1132 aVertices.Add(V1);
1133 aVertices.Add(V2);
1134
1135 Standard_Boolean isNewFound = Standard_False;
1136 do {
1137 isNewFound = Standard_False;
1138 for(Standard_Integer j = 1; j <= edges.Length(); j++) {
1139 anEdge = TopoDS::Edge(edges(j));
1140 TopExp::Vertices(anEdge,V1,V2);
1141 if(aVertices.Contains(V1) || aVertices.Contains(V2)) {
1142 isEdge3d |= !BRep_Tool::Degenerated(anEdge);
1143 aVertices.Add(V1);
1144 aVertices.Add(V2);
1145 B.Add(aWire,anEdge);
1146 edges.Remove(j);
1147 j--;
1148 isNewFound = Standard_True;
1149 }
1150 }
1151 } while (isNewFound);
1152
1153 // sorting any type of edges
ab860031 1154 aWire.Closed (BRep_Tool::IsClosed (aWire));
2277323d 1155 aWire = TopoDS::Wire(myContext->Apply(aWire));
1156
2277323d 1157 TopoDS_Face tmpF = TopoDS::Face(myContext->Apply(faces(1).Oriented(TopAbs_FORWARD)));
1158 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(aWire,tmpF,Precision::Confusion());
1159 sfw->FixReorder();
1160 Standard_Boolean isDegRemoved = Standard_False;
1161 if(!sfw->StatusReorder ( ShapeExtend_FAIL )) {
1162 // clear degenerated edges if at least one with 3d curve exist
1163 if(isEdge3d) {
1164 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
1165 for(Standard_Integer j = 1; j<=sewd->NbEdges();j++) {
1166 TopoDS_Edge E = sewd->Edge(j);
1167 if(BRep_Tool::Degenerated(E)) {
1168 sewd->Remove(j);
1169 isDegRemoved = Standard_True;
1170 j--;
1171 }
1172 }
1173 }
1174 sfw->FixShifted();
1175 if(isDegRemoved)
1176 sfw->FixDegenerated();
1177 }
1178 TopoDS_Wire aWireFixed = sfw->Wire();
1179 //aContext->Replace(aWire,aWireFixed);
1180 myContext->Replace(aWire,aWireFixed);
1181 //for history
1182 /*
1183 if (!myOldNewMap.IsBound(aWire))
1184 {
1185 TopTools_ListOfShape EmptyList;
1186 myOldNewMap.Bind(aWire, EmptyList);
1187 }
1188 myOldNewMap(aWire).Clear();
1189 myOldNewMap(aWire).Append(aWireFixed);
1190 */
1191 /////////////
1192
1193 // add resulting wire
1194 if(isEdge3d) {
1195 B.Add(aResult,aWireFixed);
1196 }
1197 else {
1198 // sorting edges
1199 Handle(ShapeExtend_WireData) sbwd = sfw->WireData();
1200 Standard_Integer nbEdges = sbwd->NbEdges();
1201 // sort degenerated edges and create one edge instead of several ones
1202 ShapeAnalysis_WireOrder sawo(Standard_False, 0);
1203 ShapeAnalysis_Edge sae;
1204 Standard_Integer aLastEdge = nbEdges;
1205 for(Standard_Integer j = 1; j <= nbEdges; j++) {
1206 Standard_Real f,l;
1207 //smh protection on NULL pcurve
1208 Handle(Geom2d_Curve) c2d;
1209 if(!sae.PCurve(sbwd->Edge(j),tmpF,c2d,f,l)) {
1210 aLastEdge--;
1211 continue;
1212 }
1213 sawo.Add(c2d->Value(f).XY(),c2d->Value(l).XY());
1214 }
1215 sawo.Perform();
1216
1217 // constructind one degenerative edge
1218 gp_XY aStart, anEnd, tmp;
1219 Standard_Integer nbFirst = sawo.Ordered(1);
1220 TopoDS_Edge anOrigE = TopoDS::Edge(sbwd->Edge(nbFirst).Oriented(TopAbs_FORWARD));
1221 ShapeBuild_Edge sbe;
1222 TopoDS_Vertex aDummyV;
1223 TopoDS_Edge E = sbe.CopyReplaceVertices(anOrigE,aDummyV,aDummyV);
1224 sawo.XY(nbFirst,aStart,tmp);
1225 sawo.XY(sawo.Ordered(aLastEdge),tmp,anEnd);
1226
1227 gp_XY aVec = anEnd-aStart;
1228 Handle(Geom2d_Line) aLine = new Geom2d_Line(aStart,gp_Dir2d(anEnd-aStart));
1229
1230 B.UpdateEdge(E,aLine,tmpF,0.);
1231 B.Range(E,tmpF,0.,aVec.Modulus());
1232 Handle(Geom_Curve) C3d;
1233 B.UpdateEdge(E,C3d,0.);
1234 B.Degenerated(E,Standard_True);
1235 TopoDS_Wire aW;
1236 B.MakeWire(aW);
1237 B.Add(aW,E);
ab860031 1238 aW.Closed (Standard_True);
2277323d 1239 B.Add(aResult,aW);
1240 }
1241 }
1242
1243 // perform substitution of face
1244 //aContext->Replace(aContext->Apply(aFace),aResult);
1245 myContext->Replace(myContext->Apply(aFace),aResult);
1246 //for history
1247 /*
1248 if (!myOldNewMap.IsBound(aFace))
1249 {
1250 TopTools_ListOfShape EmptyList;
1251 myOldNewMap.Bind(aFace, EmptyList);
1252 }
1253 myOldNewMap(aFace).Clear();
1254 myOldNewMap(aFace).Append(aResult);
1255 */
1256 /////////////
1257
1258 ShapeFix_Face sff (aResult);
1259 //Intializing by tolerances
1260 sff.SetPrecision(Precision::Confusion());
1261 sff.SetMinTolerance(tol);
1262 sff.SetMaxTolerance(1.);
1263 //Setting modes
1264 sff.FixOrientationMode() = 0;
1265 //sff.FixWireMode() = 0;
1266 //sff.SetContext(aContext);
1267 sff.SetContext(myContext);
1268 // Applying the fixes
1269 sff.Perform();
1270 if(sff.Status(ShapeExtend_FAIL))
1271 hasFailed = Standard_True;
1272
1273 // breaking down to several faces
1274 //TopoDS_Shape theResult = aContext->Apply(aResult);
1275 TopoDS_Shape theResult = myContext->Apply(aResult);
1276 for (TopExp_Explorer aFaceExp (theResult,TopAbs_FACE); aFaceExp.More(); aFaceExp.Next()) {
1277 TopoDS_Face aCurrent = TopoDS::Face(aFaceExp.Current().Oriented(TopAbs_FORWARD));
1278 Handle(TColGeom_HArray2OfSurface) grid = new TColGeom_HArray2OfSurface ( 1, 1, 1, 1 );
1279 grid->SetValue ( 1, 1, aBaseSurface );
1280 Handle(ShapeExtend_CompositeSurface) G = new ShapeExtend_CompositeSurface ( grid );
1281 ShapeFix_ComposeShell CompShell;
1282 CompShell.Init ( G, aBaseLocation, aCurrent, ::Precision::Confusion() );//myPrecision
1283 //CompShell.SetContext( aContext );
1284 CompShell.SetContext( myContext );
1285
1286 TopTools_SequenceOfShape parts;
1287 ShapeFix_SequenceOfWireSegment wires;
1288 for(TopExp_Explorer W_Exp(aCurrent,TopAbs_WIRE);W_Exp.More();W_Exp.Next()) {
1289 Handle(ShapeExtend_WireData) sbwd =
1290 new ShapeExtend_WireData ( TopoDS::Wire(W_Exp.Current() ));
1291 ShapeFix_WireSegment seg ( sbwd, TopAbs_REVERSED );
1292 wires.Append(seg);
1293 }
1294
1295 CompShell.DispatchWires ( parts,wires );
1296 for (Standard_Integer j=1; j <= parts.Length(); j++ ) {
1297 ShapeFix_Face aFixOrient(TopoDS::Face(parts(j)));
1298 //aFixOrient.SetContext(aContext);
1299 aFixOrient.SetContext(myContext);
1300 aFixOrient.FixOrientation();
1301 }
1302
1303 TopoDS_Shape CompRes;
1304 if ( faces.Length() !=1 ) {
1305 TopoDS_Shell S;
1306 B.MakeShell ( S );
1307 for ( i=1; i <= parts.Length(); i++ )
1308 B.Add ( S, parts(i) );
ab860031 1309 S.Closed (BRep_Tool::IsClosed (S));
2277323d 1310 CompRes = S;
1311 }
1312 else CompRes = parts(1);
1313
1314 //aContext->Replace(aCurrent,CompRes);
1315 myContext->Replace(aCurrent,CompRes);
1316 //for history
1317 /*
1318 if (!myOldNewMap.IsBound(aCurrent))
1319 {
1320 TopTools_ListOfShape EmptyList;
1321 myOldNewMap.Bind(aCurrent, EmptyList);
1322 }
1323 myOldNewMap(aCurrent).Clear();
1324 myOldNewMap(aCurrent).Append(CompRes);
1325 */
1326 /////////////
1327 }
1328
1329 // remove the remaining faces
1330 for(i = 2; i <= faces.Length(); i++)
f7d70540 1331 {
1332 myOldShapes.Bind(faces(i), theResult);
2277323d 1333 myContext->Remove(faces(i));
f7d70540 1334 }
2277323d 1335 }
1336 } // end processing each face
1337
1338 //TopoDS_Shape aResult = Shape;
1339 if (NbModif > 0 && !hasFailed) {
1340 //TopoDS_Shape aResult = aContext->Apply(aShell);
1341 TopoDS_Shape aResult = myContext->Apply(aShell);
1342
1343 ShapeFix_Edge sfe;
1344 for (exp.Init(aResult,TopAbs_EDGE); exp.More(); exp.Next()) {
1345 TopoDS_Edge E = TopoDS::Edge(exp.Current());
1346 sfe.FixVertexTolerance (E);
1347 // ptv add fix same parameter
1348 sfe.FixSameParameter(E, Precision::Confusion());
1349 }
1350
1351 myContext->Replace(aShell, aResult);
1352 //for history
1353 /*
1354 if (!myOldNewMap.IsBound(aShell))
1355 {
1356 TopTools_ListOfShape EmptyList;
1357 myOldNewMap.Bind(aShell, EmptyList);
1358 }
1359 myOldNewMap(aShell).Clear();
1360 myOldNewMap(aShell).Append(aResult);
1361 */
1362 /////////////
1363 }
1364 //else
1365 {
1366 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
1367 TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
1368 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
1369 sfw->SetContext(myContext);
1370 sfw->SetPrecision(Precision::Confusion());
1371 sfw->SetMinTolerance(Precision::Confusion());
1372 sfw->SetMaxTolerance(1.);
1373 sfw->SetFace(aFace);
1374 for (TopoDS_Iterator iter (aFace,Standard_False); iter.More(); iter.Next()) {
1375 TopoDS_Wire wire = TopoDS::Wire(iter.Value());
1376 sfw->Load(wire);
1377 sfw->FixReorder();
1378 sfw->FixShifted();
1379 }
1380 }
1381 }
1382 } // end processing each shell
1383
1384 myShape = myContext->Apply(myShape);
1385}
1386
1387//=======================================================================
1388//function : UnifyEdges
1389//purpose :
1390//=======================================================================
2277323d 1391void ShapeUpgrade_UnifySameDomain::UnifyEdges()
1392{
1393 Standard_Real Tol = Precision::Confusion();
1394
1395 //Handle(ShapeBuild_ReShape) myContext = new ShapeBuild_ReShape;
1396 Standard_Real myTolerance = Precision::Confusion();
1397 TopoDS_Shape aResult = myContext->Apply(myShape);
1398
ce41efde 1399 TopTools_IndexedMapOfShape ChangedFaces;
2277323d 1400
ce41efde 1401 // creating map of edge faces
1402 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
1403 TopExp::MapShapesAndAncestors(myShape, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
1404
1405 // creating map of vertex edges
1406 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgesVertex;
1407 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMapEdgesVertex);
1408
1409 //Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
1410 TopoDS_Shape aRes = myShape;
1411 //aRes = aContext->Apply(aSolid);
1412 aRes = myContext->Apply(myShape);
f7d70540 1413
1414 TopTools_MapOfShape SharedVert;
1415
1416
1417 TopTools_IndexedMapOfShape anOldEdges;
1418 TopExp::MapShapes(myInitShape, TopAbs_EDGE, anOldEdges);
1419
1420 TopTools_DataMapOfShapeShape NewEdges2OldEdges;
1421 for (int i = 1; i <= anOldEdges.Extent(); i++)
1422 {
1423 TopoDS_Shape NewEdge = myContext->Apply(anOldEdges(i));
1424 if (!NewEdge.IsNull())
1425 NewEdges2OldEdges.Bind(NewEdge, anOldEdges(i));
1426 }
ce41efde 1427
ce41efde 1428 TopExp_Explorer exp;
f7d70540 1429 // processing separate wires
1430 for (exp.Init(aRes, TopAbs_WIRE, TopAbs_FACE); exp.More(); exp.Next())
1431 {
1432 TopTools_SequenceOfShape SeqEdges;
1433 TopExp_Explorer expE(exp.Current(), TopAbs_EDGE);
1434 for (; expE.More(); expE.Next())
1435 SeqEdges.Append(expE.Current());
1436 SharedVert.Clear();
1437 CheckSharedVertices(SeqEdges, aMapEdgesVertex, SharedVert);
1438 MergeSeq(SeqEdges, Tol, myConcatBSplines, myContext, myOldShapes, SharedVert, NewEdges2OldEdges);
1439 }
1440
1441 // processing each face
ce41efde 1442 for (exp.Init(aRes, TopAbs_FACE); exp.More(); exp.Next()) {
1443 //TopoDS_Face aFace = TopoDS::Face(aContext->Apply(exp.Current().Oriented(TopAbs_FORWARD)));
1444 TopoDS_Face aFace = TopoDS::Face(myContext->Apply(exp.Current().Oriented(TopAbs_FORWARD)));
1445 TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
f7d70540 1446 TopTools_SequenceOfShape aNonSharedEdges;
ce41efde 1447 for (TopExp_Explorer expe(aFace,TopAbs_EDGE); expe.More(); expe.Next()) {
1448 TopoDS_Edge edge = TopoDS::Edge(expe.Current());
1449 if (!aMapEdgeFaces.Contains(edge)) continue;
1450 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
1451 TopTools_ListIteratorOfListOfShape anIter(aList);
f7d70540 1452 Standard_Integer NbFacesPerEdge = aList.Extent();
ce41efde 1453 for ( ; anIter.More(); anIter.Next()) {
1454 TopoDS_Face face = TopoDS::Face(anIter.Value());
ce41efde 1455 TopoDS_Face face1 = TopoDS::Face(myContext->Apply(anIter.Value()));
f7d70540 1456 if (face1.IsSame(aFace) && NbFacesPerEdge != 1)
1457 continue;
1458 if (NbFacesPerEdge == 1)
1459 //store non-shared edges separately
1460 aNonSharedEdges.Append(edge);
1461 else
1462 {
1463 if (aMapFacesEdges.Contains(face))
1464 aMapFacesEdges.ChangeFromKey(face).Append(edge);
1465 else
1466 {
1467 TopTools_ListOfShape ListEdges;
1468 ListEdges.Append(edge);
1469 aMapFacesEdges.Add(face,ListEdges);
1470 }
2277323d 1471 }
1472 }
ce41efde 1473 }
f7d70540 1474
1475 for (Standard_Integer i=1; i<=aMapFacesEdges.Extent(); i++)
1476 {
ce41efde 1477 const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
1478 TopTools_SequenceOfShape SeqEdges;
ce41efde 1479 TopTools_ListIteratorOfListOfShape anIter(ListEdges);
ce41efde 1480 for ( ; anIter.More(); anIter.Next())
1481 SeqEdges.Append(anIter.Value());
1482 if (SeqEdges.Length()==1)
1483 continue;
2277323d 1484
f7d70540 1485 SharedVert.Clear();
1486 CheckSharedVertices(SeqEdges, aMapEdgesVertex, SharedVert);
1487 //if (!SharedVert.IsEmpty())
1488 // continue;
1489 if ( MergeSeq(SeqEdges,Tol,myConcatBSplines, myContext, myOldShapes, SharedVert, NewEdges2OldEdges) )
2277323d 1490 {
2277323d 1491 //for history
1492 /*
ce41efde 1493 for (j = 1; j <= SeqEdges.Length(); j++)
2277323d 1494 {
ce41efde 1495 if (!myOldNewMap.IsBound(SeqEdges(j)))
1496 {
1497 TopTools_ListOfShape EmptyList;
1498 myOldNewMap.Bind(SeqEdges(j), EmptyList);
1499 }
1500 myOldNewMap(SeqEdges(j)).Clear();
1501 myOldNewMap(SeqEdges(j)).Append(E);
2277323d 1502 }
2277323d 1503 */
1504 /////////////
ce41efde 1505
1506 TopoDS_Face tmpF = TopoDS::Face(exp.Current());
1507 if ( !ChangedFaces.Contains(tmpF) )
1508 ChangedFaces.Add(tmpF);
1509 tmpF = TopoDS::Face(aMapFacesEdges.FindKey(i));
1510 if ( !ChangedFaces.Contains(tmpF) )
1511 ChangedFaces.Add(tmpF);
2277323d 1512 }
ce41efde 1513 }
f7d70540 1514
1515 if ( aNonSharedEdges.Length() > 1 )
1516 {
1517 SharedVert.Clear();
1518 CheckSharedVertices(aNonSharedEdges, aMapEdgesVertex, SharedVert);
1519 if ( MergeSeq(aNonSharedEdges, Tol, myConcatBSplines, myContext, myOldShapes, SharedVert, NewEdges2OldEdges) )
1520 {
1521 TopoDS_Face tmpF = TopoDS::Face(exp.Current());
1522 if ( !ChangedFaces.Contains(tmpF) )
1523 ChangedFaces.Add(tmpF);
1524 }
1525 }
ce41efde 1526
1527 } // end processing each face
1528
1529 // fix changed faces and replace them in the local context
1530 for (Standard_Integer i=1; i<=ChangedFaces.Extent(); i++) {
1531 //TopoDS_Face aFace = TopoDS::Face(aContext->Apply(ChangedFaces.FindKey(i)));
1532 TopoDS_Face aFace = TopoDS::Face(myContext->Apply(ChangedFaces.FindKey(i)));
f7d70540 1533 if (aFace.IsNull())
1534 continue;
ce41efde 1535 Handle(ShapeFix_Face) sff = new ShapeFix_Face(aFace);
1536 sff->SetContext(myContext);
1537 sff->SetPrecision(myTolerance);
1538 sff->SetMinTolerance(myTolerance);
1539 sff->SetMaxTolerance(Max(1.,myTolerance*1000.));
1540 sff->Perform();
1541 TopoDS_Shape aNewFace = sff->Face();
1542 //aContext->Replace(aFace,aNewFace);
1543 myContext->Replace(aFace,aNewFace);
1544 //for history
1545 /*
1546 if (!myOldNewMap.IsBound(aFace))
1547 {
1548 TopTools_ListOfShape EmptyList;
1549 myOldNewMap.Bind(aFace, EmptyList);
1550 }
1551 myOldNewMap(aFace).Clear();
1552 myOldNewMap(aFace).Append(aNewFace);
1553 */
1554 /////////////
1555 }
1556
1557 if (ChangedFaces.Extent() > 0) {
1558 // fix changed shell and replace it in the local context
1559 //TopoDS_Shape aRes1 = aContext->Apply(aRes);
1560 TopoDS_Shape aRes1 = myContext->Apply(aRes);
1561 TopExp_Explorer expsh;
1562 for (expsh.Init(aRes1, TopAbs_SHELL); expsh.More(); expsh.Next()) {
1563 TopoDS_Shell aShell = TopoDS::Shell(expsh.Current());
1564 Handle(ShapeFix_Shell) sfsh = new ShapeFix_Shell;
1565 sfsh->FixFaceOrientation(aShell);
1566 TopoDS_Shape aNewShell = sfsh->Shell();
1567 //aContext->Replace(aShell,aNewShell);
1568 myContext->Replace(aShell,aNewShell);
2277323d 1569 //for history
1570 /*
ce41efde 1571 if (!myOldNewMap.IsBound(aShell))
2277323d 1572 {
1573 TopTools_ListOfShape EmptyList;
ce41efde 1574 myOldNewMap.Bind(aShell, EmptyList);
2277323d 1575 }
ce41efde 1576 myOldNewMap(aShell).Clear();
1577 myOldNewMap(aShell).Append(aNewShell);
2277323d 1578 */
1579 /////////////
1580 }
ce41efde 1581 //TopoDS_Shape aRes2 = aContext->Apply(aRes1);
1582 TopoDS_Shape aRes2 = myContext->Apply(aRes1);
1583 myContext->Replace(myShape,aRes2);
1584 //for history
1585 /*
1586 if (!myOldNewMap.IsBound(aSolid))
1587 {
1588 TopTools_ListOfShape EmptyList;
1589 myOldNewMap.Bind(aSolid, EmptyList);
1590 }
1591 myOldNewMap(aSolid).Clear();
1592 myOldNewMap(aSolid).Append(aRes2);
1593 */
1594 /////////////
1595 }
2277323d 1596
1597 myShape = myContext->Apply(myShape);
1598}
1599
1600//=======================================================================
1601//function : UnifyFacesAndEdges
1602//purpose :
1603//=======================================================================
1604
1605void ShapeUpgrade_UnifySameDomain::UnifyFacesAndEdges()
1606{
1607 UnifyFaces();
1608
1609 /*
1610 ShapeUpgrade_RemoveLocations RemLoc;
1611 RemLoc.Remove(myShape);
1612 myShape = RemLoc.GetResult();
1613 */
1614
1615 UnifyEdges();
1616}
1617
1618//=======================================================================
1619//function : Build
1620//purpose : builds the resulting shape
1621//======================================================================
1622void ShapeUpgrade_UnifySameDomain::Build()
1623{
1624 if (myUnifyFaces && myUnifyEdges)
1625 UnifyFacesAndEdges();
1626
1627 else if (myUnifyEdges)
1628 UnifyEdges();
1629 else if (myUnifyFaces)
1630 UnifyFaces();
1631
1632 //Done();
1633}
1634
1635//=======================================================================
1636//function : Shape
1637//purpose : give the resulting shape
1638//=======================================================================
1639const TopoDS_Shape& ShapeUpgrade_UnifySameDomain::Shape() const
1640{
1641 return myShape;
1642}
1643
1644//=======================================================================
1645//function : Generated
1646//purpose : returns the new shape from the old one
1647//=======================================================================
1648TopoDS_Shape ShapeUpgrade_UnifySameDomain::Generated(const TopoDS_Shape& aShape) const
1649{
1650 TopoDS_Shape aNewShape = myContext->Apply(aShape);
f7d70540 1651
2277323d 1652 if (aNewShape.IsNull())
f7d70540 1653 aNewShape = myContext->Apply(myOldShapes(aShape));
2277323d 1654
1655 return aNewShape;
1656}