0026618: CMake should disable ability to use 3rdparty if there is no any included...
[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);
617 gp_Pnt PV1 = BRep_Tool::Pnt(V1);
618 TopoDS_Vertex V2 = sae.LastVertex(TopoDS::Edge(aChain.Last()));
619 gp_Pnt PV2 = BRep_Tool::Pnt(V2);
620 TopoDS_Vertex VM = sae.LastVertex(FE);
621 gp_Pnt PVM = BRep_Tool::Pnt(VM);
622 GC_MakeCircle MC (PV1,PVM,PV2);
623 TopoDS_Edge E;
624 if (!MC.IsDone() || MC.Value().IsNull()) {
625 // jfa for Mantis issue 0020228
626 if (PV1.Distance(PV2) > Precision::Confusion())
b4d4dbe8 627 return Standard_False;
f7d70540 628 // closed chain
629 B.MakeEdge (E,Cir,Precision::Confusion());
630 B.Add(E,V1);
631 B.Add(E,V2);
632 E.Orientation(FE.Orientation());
633 }
634 else {
635 Handle(Geom_Circle) C = MC.Value();
636 gp_Pnt P0 = C->Location();
637 gp_Dir D1(gp_Vec(P0,PV1));
638 gp_Dir D2(gp_Vec(P0,PV2));
639 Standard_Real fpar = C->XAxis().Direction().Angle(D1);
640 if(fabs(fpar)>Precision::Confusion()) {
641 // check orientation
642 gp_Dir ND = C->XAxis().Direction().Crossed(D1);
643 if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) {
644 fpar = -fpar;
2277323d 645 }
f7d70540 646 }
647 Standard_Real lpar = C->XAxis().Direction().Angle(D2);
648 if(fabs(lpar)>Precision::Confusion()) {
649 // check orientation
650 gp_Dir ND = C->XAxis().Direction().Crossed(D2);
651 if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) {
652 lpar = -lpar;
2277323d 653 }
2277323d 654 }
f7d70540 655 if (lpar < fpar) lpar += 2*M_PI;
656 Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(C,fpar,lpar);
657 B.MakeEdge (E,tc,Precision::Confusion());
658 B.Add(E,V1);
659 B.Add(E,V2);
660 B.UpdateVertex(V1, fpar, E, 0.);
661 B.UpdateVertex(V2, lpar, E, 0.);
2277323d 662 }
f7d70540 663 OutEdge = E;
664 return Standard_True;
2277323d 665 }
666 if (aChain.Length() > 1 && ConcatBSplines) {
667 // second step: union edges with various curves
668 // skl for bug 0020052 from Mantis: perform such unions
669 // only if curves are bspline or bezier
f7d70540 670
671 TopoDS_Vertex VF = sae.FirstVertex(TopoDS::Edge(aChain.First()));
672 TopoDS_Vertex VL = sae.LastVertex(TopoDS::Edge(aChain.Last()));
673 Standard_Boolean NeedUnion = Standard_True;
2277323d 674 for(j=1; j<=aChain.Length(); j++) {
675 TopoDS_Edge edge = TopoDS::Edge(aChain.Value(j));
b4d4dbe8 676 TopLoc_Location Loc;
2277323d 677 Handle(Geom_Curve) c3d = BRep_Tool::Curve(edge,Loc,fp1,lp1);
678 if(c3d.IsNull()) continue;
679 while(c3d->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
680 Handle(Geom_TrimmedCurve) tc =
681 Handle(Geom_TrimmedCurve)::DownCast(c3d);
682 c3d = tc->BasisCurve();
683 }
684 if( ( c3d->IsKind(STANDARD_TYPE(Geom_BSplineCurve)) ||
685 c3d->IsKind(STANDARD_TYPE(Geom_BezierCurve)) ) ) continue;
f7d70540 686 NeedUnion = Standard_False;
2277323d 687 break;
688 }
689 if(NeedUnion) {
0797d9d3 690#ifdef OCCT_DEBUG
2277323d 691 cout<<"can not make analitical union => make approximation"<<endl;
692#endif
693 TopoDS_Edge E = GlueEdgesWithPCurves(aChain, VF, VL);
f7d70540 694 OutEdge = E;
695 return Standard_True;
2277323d 696 }
697 else {
0797d9d3 698#ifdef OCCT_DEBUG
2277323d 699 cout<<"can not make approximation for such types of curves"<<endl;
700#endif
701 return Standard_False;
702 }
703 }
f7d70540 704 return Standard_False;
705}
706
707static Standard_Boolean IsMergingPossible(const TopoDS_Edge& edge1, const TopoDS_Edge& edge2,
708 double Tol, const TopTools_MapOfShape& DegEdgeVrt)
709{
710 TopoDS_Vertex CV = TopExp::LastVertex(edge1, Standard_True);
711 if (CV.IsNull() || DegEdgeVrt.Contains(CV))
712 return Standard_False;
713
714 BRepAdaptor_Curve ade1(edge1);
715 BRepAdaptor_Curve ade2(edge2);
716
717 GeomAbs_CurveType t1 = ade1.GetType();
718 GeomAbs_CurveType t2 = ade2.GetType();
719
720 if( t1 == GeomAbs_Circle && t2 == GeomAbs_Circle)
721 {
722 if (ade1.Circle().Location().Distance(ade2.Circle().Location()) > Precision::Confusion())
723 return Standard_False;
724 }
725
726 if( ( (t1 != GeomAbs_BezierCurve && t1 != GeomAbs_BSplineCurve) ||
727 (t2 != GeomAbs_BezierCurve && t2 != GeomAbs_BSplineCurve)) && t1 != t2)
728 return Standard_False;
729
730 gp_Vec Diff1, Diff2;
731 gp_Pnt P1, P2;
732 if (edge1.Orientation() == TopAbs_FORWARD)
733 ade1.D1(ade1.LastParameter(), P1, Diff1);
734 else
735 {
736 ade1.D1(ade1.FirstParameter(), P1, Diff1);
737 Diff1 = -Diff1;
738 }
739
740 if (edge2.Orientation() == TopAbs_FORWARD)
741 ade2.D1(ade2.FirstParameter(), P2, Diff2);
742 else
743 {
744 ade2.D1(ade2.LastParameter(), P2, Diff2);
745 Diff2 = -Diff2;
746 }
747
748 if (Diff1.Angle(Diff2) > Tol)
749 return Standard_False;
750
751 return Standard_True;
752}
753
754static void GenerateSubSeq (const TopTools_SequenceOfShape& anInpEdgeSeq,
755 NCollection_Sequence<SubSequenceOfEdges>& SeqOfSubSeqOfEdges,
756 Standard_Boolean IsClosed, double Tol, const TopTools_MapOfShape& DegEdgeVrt )
757{
758 Standard_Boolean isOk = Standard_False;
759 TopoDS_Edge edge1, edge2;
760
761 SubSequenceOfEdges SubSeq;
762 SubSeq.SeqsEdges.Append(TopoDS::Edge(anInpEdgeSeq(1)));
763 SeqOfSubSeqOfEdges.Append(SubSeq);
764
765 for (int i = 1; i < anInpEdgeSeq.Length(); i++)
766 {
767 edge1 = TopoDS::Edge(anInpEdgeSeq(i));
768 edge2 = TopoDS::Edge(anInpEdgeSeq(i+1));
769 isOk = IsMergingPossible(edge1, edge2, Tol, DegEdgeVrt);
770 if (!isOk)
771 {
772 SubSequenceOfEdges SubSeq;
773 SubSeq.SeqsEdges.Append(edge2);
774 SeqOfSubSeqOfEdges.Append(SubSeq);
775 }
776 else
777 SeqOfSubSeqOfEdges.ChangeLast().SeqsEdges.Append(edge2);
778 }
779 /// check first and last chain segments
780 if (IsClosed && SeqOfSubSeqOfEdges.Length() > 1)
781 {
782 edge1 = TopoDS::Edge(anInpEdgeSeq.Last());
783 edge2 = TopoDS::Edge(anInpEdgeSeq.First());
784 if (IsMergingPossible(edge1, edge2, Tol, DegEdgeVrt))
785 {
786 SeqOfSubSeqOfEdges.ChangeLast().SeqsEdges.Append(SeqOfSubSeqOfEdges.ChangeFirst().SeqsEdges);
787 SeqOfSubSeqOfEdges.Remove(1);
788 }
789 }
790}
791
792
793//=======================================================================
794//function : MergeEdges
795//purpose : auxilary
796//=======================================================================
797static Standard_Boolean MergeEdges(const TopTools_SequenceOfShape& SeqEdges,
798 const Standard_Real Tol,
799 const Standard_Boolean ConcatBSplines,
800 NCollection_Sequence<SubSequenceOfEdges>& SeqOfSubSeqOfEdges,
801 const TopTools_MapOfShape& NonMergVrt )
802{
803 // make chain for union
804 //BRep_Builder B;
805 ShapeAnalysis_Edge sae;
806 TopoDS_Edge FirstE = TopoDS::Edge(SeqEdges.Value(1));
807 TopoDS_Edge LastE = FirstE;
808 TopoDS_Vertex VF = sae.FirstVertex(FirstE);
809 TopoDS_Vertex VL = sae.LastVertex(LastE);
810 TopTools_SequenceOfShape aChain;
811 aChain.Append(FirstE);
812 TColStd_MapOfInteger IndUsedEdges;
813 IndUsedEdges.Add(1);
814 Standard_Integer j;
815 TopTools_MapOfShape VerticesToAvoid;
816 TopTools_SequenceOfShape SeqEdges1;
817 for (j = 1; j <= SeqEdges.Length(); j++)
818 {
819 TopoDS_Edge anEdge = TopoDS::Edge(SeqEdges(j));
820 if (BRep_Tool::Degenerated(anEdge))
821 {
822 TopoDS_Vertex V1, V2;
823 TopExp::Vertices(anEdge, V1, V2);
824 VerticesToAvoid.Add(V1);
825 VerticesToAvoid.Add(V2);
826 continue;
827 }
828 SeqEdges1.Append(anEdge);
829 }
830
831 for(j=2; j<=SeqEdges1.Length(); j++) {
832 for(Standard_Integer k=2; k<=SeqEdges1.Length(); k++) {
833 if(IndUsedEdges.Contains(k)) continue;
834 TopoDS_Edge edge = TopoDS::Edge(SeqEdges1.Value(k));
835 TopoDS_Vertex VF2 = sae.FirstVertex(edge);
836 TopoDS_Vertex VL2 = sae.LastVertex(edge);
837 if(VF2.IsSame(VL)) {
838 aChain.Append(edge);
839 LastE = edge;
840 VL = sae.LastVertex(LastE);
841 IndUsedEdges.Add(k);
842 }
843 else if(VL2.IsSame(VF)) {
844 aChain.Prepend(edge);
845 FirstE = edge;
846 VF = sae.FirstVertex(FirstE);
847 IndUsedEdges.Add(k);
848 }
849 }
850 }
f7d70540 851
852 Standard_Boolean IsClosed = Standard_False;
853 if (VF.IsSame ( VL ))
854 IsClosed = Standard_True;
2277323d 855
f7d70540 856 VerticesToAvoid.Unite(NonMergVrt);
857 GenerateSubSeq(aChain, SeqOfSubSeqOfEdges, IsClosed, Tol, VerticesToAvoid);
858
859 for (int i = 1; i <= SeqOfSubSeqOfEdges.Length(); i++)
860 {
861 TopoDS_Edge UE;
862 if (SeqOfSubSeqOfEdges(i).SeqsEdges.Length() < 2)
863 continue;
864 if (MergeSubSeq(SeqOfSubSeqOfEdges(i).SeqsEdges, UE, Tol, ConcatBSplines))
865 SeqOfSubSeqOfEdges(i).UnionEdges = UE;
866 }
2277323d 867 return Standard_True;
868}
869
f7d70540 870static Standard_Boolean MergeSeq (const TopTools_SequenceOfShape& SeqEdges,
871 const Standard_Real Tol,
872 const Standard_Boolean ConcatBSplines,
873 Handle(ShapeBuild_ReShape)& theContext,
874 TopTools_DataMapOfShapeShape& theOldShapes,
875 const TopTools_MapOfShape& nonMergVert,
876 const TopTools_DataMapOfShapeShape& NewEdges2OldEdges)
877{
878 NCollection_Sequence<SubSequenceOfEdges> SeqOfSubsSeqOfEdges;
879 int k = 1;
880 if ( MergeEdges(SeqEdges, Tol, ConcatBSplines, SeqOfSubsSeqOfEdges, nonMergVert) )
881 {
882 for (Standard_Integer i = 1; i <= SeqOfSubsSeqOfEdges.Length(); i++ )
883 {
884 if (SeqOfSubsSeqOfEdges(i).UnionEdges.IsNull())
885 continue;
886 theContext->Replace(SeqOfSubsSeqOfEdges(i).SeqsEdges(1), SeqOfSubsSeqOfEdges(i).UnionEdges);
887 k++;
888 for (Standard_Integer j = 2; j <= SeqOfSubsSeqOfEdges(i).SeqsEdges.Length(); j++)
889 {
890 TopoDS_Shape OldEdge = NewEdges2OldEdges(SeqOfSubsSeqOfEdges(i).SeqsEdges(j));
891 theOldShapes.Bind(OldEdge, SeqOfSubsSeqOfEdges(i).UnionEdges);
892 theContext->Remove(SeqOfSubsSeqOfEdges(i).SeqsEdges(j));
893 }
894 }
895 return Standard_True;
896 }
897 else
898 return Standard_False;
899}
900
901static void CheckSharedVertices(const TopTools_SequenceOfShape& theSeqEdges,
902 const TopTools_IndexedDataMapOfShapeListOfShape& theMapEdgesVertex,
903 TopTools_MapOfShape& theShareVertMap)
904{
905 ShapeAnalysis_Edge sae;
906 TopTools_SequenceOfShape SeqVertexes;
907 TopTools_MapOfShape MapVertexes;
908 for (Standard_Integer k = 1; k <= theSeqEdges.Length(); k++ )
909 {
910 TopoDS_Vertex aV1 = sae.FirstVertex(TopoDS::Edge(theSeqEdges(k)));
911 TopoDS_Vertex aV2 = sae.LastVertex(TopoDS::Edge(theSeqEdges(k)));
912 if (!MapVertexes.Add(aV1))
913 SeqVertexes.Append(aV1);
914 if (!MapVertexes.Add(aV2))
915 SeqVertexes.Append(aV2);
916 }
917
918 for (Standard_Integer k = 1; k <= SeqVertexes.Length()/* && !IsSharedVertexPresent*/; k++ )
919 {
920 const TopTools_ListOfShape& ListEdgesV1 = theMapEdgesVertex.FindFromKey(SeqVertexes(k));
921 TopTools_MapOfShape aMapOfEdges;
922 TopTools_ListIteratorOfListOfShape iter(ListEdgesV1);
923 for (; iter.More(); iter.Next())
924 aMapOfEdges.Add(iter.Value());
925 if (aMapOfEdges.Extent() > 2)
926 theShareVertMap.Add(SeqVertexes(k));
927 }
928 //return theShareVertMap.IsEmpty() ? false : true;
929}
930
2277323d 931//=======================================================================
932//function : ShapeUpgrade_UnifySameDomain
933//purpose : Constructor
934//=======================================================================
935
936ShapeUpgrade_UnifySameDomain::ShapeUpgrade_UnifySameDomain()
937{
938 myUnifyEdges = Standard_True;
939 myUnifyFaces = Standard_True;
940 myConcatBSplines = Standard_False;
941
942 myContext = new ShapeBuild_ReShape;
943}
944
945//=======================================================================
946//function : ShapeUpgrade_UnifySameDomain
947//purpose : Constructor
948//=======================================================================
949
950ShapeUpgrade_UnifySameDomain::ShapeUpgrade_UnifySameDomain(const TopoDS_Shape& aShape,
951 const Standard_Boolean UnifyEdges,
952 const Standard_Boolean UnifyFaces,
953 const Standard_Boolean ConcatBSplines)
954{
955 myInitShape = aShape;
956 myShape = aShape;
957 myUnifyEdges = UnifyEdges;
958 myUnifyFaces = UnifyFaces;
959 myConcatBSplines = ConcatBSplines;
960
961 myContext = new ShapeBuild_ReShape;
962}
963
964//=======================================================================
965//function : Initialize
966//purpose :
967//=======================================================================
968
969void ShapeUpgrade_UnifySameDomain::Initialize(const TopoDS_Shape& aShape,
970 const Standard_Boolean UnifyEdges,
971 const Standard_Boolean UnifyFaces,
972 const Standard_Boolean ConcatBSplines)
973{
974 myInitShape = aShape;
975 myShape = aShape;
976 myUnifyEdges = UnifyEdges;
977 myUnifyFaces = UnifyFaces;
978 myConcatBSplines = ConcatBSplines;
979
980 myContext->Clear();
f7d70540 981 myOldShapes.Clear();
2277323d 982 //myGenerated.Clear();
983}
984
985//=======================================================================
986//function : UnifyFaces
987//purpose :
988//=======================================================================
989
990void ShapeUpgrade_UnifySameDomain::UnifyFaces()
991{
992 //Handle(ShapeBuild_ReShape) myContext = new ShapeBuild_ReShape;
993 TopoDS_Shape aResShape = myContext->Apply(myShape);
994
995 // processing each shell
996 TopExp_Explorer exps;
997 for (exps.Init(myShape, TopAbs_SHELL); exps.More(); exps.Next()) {
998 TopoDS_Shell aShell = TopoDS::Shell(exps.Current());
999
1000 // creating map of edge faces
1001 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
1002 TopExp::MapShapesAndAncestors(aShell, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
1003
1004 // map of processed shapes
1005 TopTools_MapOfShape aProcessed;
1006
1007 //Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
1008
1009 Standard_Integer NbModif = 0;
1010 Standard_Boolean hasFailed = Standard_False;
1011 Standard_Real tol = Precision::Confusion();
1012
1013 // count faces
1014 Standard_Integer nbf = 0;
1015 TopExp_Explorer exp;
1016 TopTools_MapOfShape mapF;
1017 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
1018 if (mapF.Add(exp.Current()))
1019 nbf++;
1020 }
1021
1022 // processing each face
1023 mapF.Clear();
1024 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
1025 TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
1026
1027 if (aProcessed.Contains(aFace))
1028 continue;
1029
1030 Standard_Integer dummy;
1031 TopTools_SequenceOfShape edges;
1032 AddOrdinaryEdges(edges,aFace,dummy);
1033
1034 TopTools_SequenceOfShape faces;
1035 faces.Append(aFace);
1036
1037 //surface and location to construct result
1038 TopLoc_Location aBaseLocation;
1039 Handle(Geom_Surface) aBaseSurface = BRep_Tool::Surface(aFace,aBaseLocation);
1040 aBaseSurface = ClearRts(aBaseSurface);
1041
1042 // find adjacent faces to union
1043 Standard_Integer i;
1044 for (i = 1; i <= edges.Length(); i++) {
1045 TopoDS_Edge edge = TopoDS::Edge(edges(i));
1046 if (BRep_Tool::Degenerated(edge))
1047 continue;
1048
1049 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
1050 TopTools_ListIteratorOfListOfShape anIter(aList);
1051 for (; anIter.More(); anIter.Next()) {
1052 TopoDS_Face anCheckedFace = TopoDS::Face(anIter.Value().Oriented(TopAbs_FORWARD));
1053 if (anCheckedFace.IsSame(aFace))
1054 continue;
1055
1056 if (aProcessed.Contains(anCheckedFace))
1057 continue;
1058
1059 if (IsSameDomain(aFace,anCheckedFace)) {
1060
1061 if (aList.Extent() != 2) {
1062 // non mainfold case is not processed
1063 continue;
1064 }
1065
1066 // replacing pcurves
1067 TopoDS_Face aMockUpFace;
1068 BRep_Builder B;
1069 B.MakeFace(aMockUpFace,aBaseSurface,aBaseLocation,0.);
1070 MovePCurves(aMockUpFace,anCheckedFace);
1071
1072 if (AddOrdinaryEdges(edges,aMockUpFace,dummy)) {
1073 // sequence edges is modified
1074 i = dummy;
1075 }
1076
1077 faces.Append(anCheckedFace);
1078 aProcessed.Add(anCheckedFace);
1079 break;
1080 }
1081 }
1082 }
1083
1084 // all faces collected in the sequence. Perform union of faces
1085 if (faces.Length() > 1) {
1086 NbModif++;
1087 TopoDS_Face aResult;
1088 BRep_Builder B;
1089 B.MakeFace(aResult,aBaseSurface,aBaseLocation,0);
1090 Standard_Integer nbWires = 0;
1091
1092 // connecting wires
1093 while (edges.Length()>0) {
1094
1095 Standard_Boolean isEdge3d = Standard_False;
1096 nbWires++;
1097 TopTools_MapOfShape aVertices;
1098 TopoDS_Wire aWire;
1099 B.MakeWire(aWire);
1100
1101 TopoDS_Edge anEdge = TopoDS::Edge(edges(1));
1102 edges.Remove(1);
1103
1104 isEdge3d |= !BRep_Tool::Degenerated(anEdge);
1105 B.Add(aWire,anEdge);
1106 TopoDS_Vertex V1,V2;
1107 TopExp::Vertices(anEdge,V1,V2);
1108 aVertices.Add(V1);
1109 aVertices.Add(V2);
1110
1111 Standard_Boolean isNewFound = Standard_False;
1112 do {
1113 isNewFound = Standard_False;
1114 for(Standard_Integer j = 1; j <= edges.Length(); j++) {
1115 anEdge = TopoDS::Edge(edges(j));
1116 TopExp::Vertices(anEdge,V1,V2);
1117 if(aVertices.Contains(V1) || aVertices.Contains(V2)) {
1118 isEdge3d |= !BRep_Tool::Degenerated(anEdge);
1119 aVertices.Add(V1);
1120 aVertices.Add(V2);
1121 B.Add(aWire,anEdge);
1122 edges.Remove(j);
1123 j--;
1124 isNewFound = Standard_True;
1125 }
1126 }
1127 } while (isNewFound);
1128
1129 // sorting any type of edges
ab860031 1130 aWire.Closed (BRep_Tool::IsClosed (aWire));
2277323d 1131 aWire = TopoDS::Wire(myContext->Apply(aWire));
1132
2277323d 1133 TopoDS_Face tmpF = TopoDS::Face(myContext->Apply(faces(1).Oriented(TopAbs_FORWARD)));
1134 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(aWire,tmpF,Precision::Confusion());
1135 sfw->FixReorder();
1136 Standard_Boolean isDegRemoved = Standard_False;
1137 if(!sfw->StatusReorder ( ShapeExtend_FAIL )) {
1138 // clear degenerated edges if at least one with 3d curve exist
1139 if(isEdge3d) {
1140 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
1141 for(Standard_Integer j = 1; j<=sewd->NbEdges();j++) {
1142 TopoDS_Edge E = sewd->Edge(j);
1143 if(BRep_Tool::Degenerated(E)) {
1144 sewd->Remove(j);
1145 isDegRemoved = Standard_True;
1146 j--;
1147 }
1148 }
1149 }
1150 sfw->FixShifted();
1151 if(isDegRemoved)
1152 sfw->FixDegenerated();
1153 }
1154 TopoDS_Wire aWireFixed = sfw->Wire();
1155 //aContext->Replace(aWire,aWireFixed);
1156 myContext->Replace(aWire,aWireFixed);
1157 //for history
1158 /*
1159 if (!myOldNewMap.IsBound(aWire))
1160 {
1161 TopTools_ListOfShape EmptyList;
1162 myOldNewMap.Bind(aWire, EmptyList);
1163 }
1164 myOldNewMap(aWire).Clear();
1165 myOldNewMap(aWire).Append(aWireFixed);
1166 */
1167 /////////////
1168
1169 // add resulting wire
1170 if(isEdge3d) {
1171 B.Add(aResult,aWireFixed);
1172 }
1173 else {
1174 // sorting edges
1175 Handle(ShapeExtend_WireData) sbwd = sfw->WireData();
1176 Standard_Integer nbEdges = sbwd->NbEdges();
1177 // sort degenerated edges and create one edge instead of several ones
1178 ShapeAnalysis_WireOrder sawo(Standard_False, 0);
1179 ShapeAnalysis_Edge sae;
1180 Standard_Integer aLastEdge = nbEdges;
1181 for(Standard_Integer j = 1; j <= nbEdges; j++) {
1182 Standard_Real f,l;
1183 //smh protection on NULL pcurve
1184 Handle(Geom2d_Curve) c2d;
1185 if(!sae.PCurve(sbwd->Edge(j),tmpF,c2d,f,l)) {
1186 aLastEdge--;
1187 continue;
1188 }
1189 sawo.Add(c2d->Value(f).XY(),c2d->Value(l).XY());
1190 }
1191 sawo.Perform();
1192
1193 // constructind one degenerative edge
1194 gp_XY aStart, anEnd, tmp;
1195 Standard_Integer nbFirst = sawo.Ordered(1);
1196 TopoDS_Edge anOrigE = TopoDS::Edge(sbwd->Edge(nbFirst).Oriented(TopAbs_FORWARD));
1197 ShapeBuild_Edge sbe;
1198 TopoDS_Vertex aDummyV;
1199 TopoDS_Edge E = sbe.CopyReplaceVertices(anOrigE,aDummyV,aDummyV);
1200 sawo.XY(nbFirst,aStart,tmp);
1201 sawo.XY(sawo.Ordered(aLastEdge),tmp,anEnd);
1202
1203 gp_XY aVec = anEnd-aStart;
1204 Handle(Geom2d_Line) aLine = new Geom2d_Line(aStart,gp_Dir2d(anEnd-aStart));
1205
1206 B.UpdateEdge(E,aLine,tmpF,0.);
1207 B.Range(E,tmpF,0.,aVec.Modulus());
1208 Handle(Geom_Curve) C3d;
1209 B.UpdateEdge(E,C3d,0.);
1210 B.Degenerated(E,Standard_True);
1211 TopoDS_Wire aW;
1212 B.MakeWire(aW);
1213 B.Add(aW,E);
ab860031 1214 aW.Closed (Standard_True);
2277323d 1215 B.Add(aResult,aW);
1216 }
1217 }
1218
1219 // perform substitution of face
1220 //aContext->Replace(aContext->Apply(aFace),aResult);
1221 myContext->Replace(myContext->Apply(aFace),aResult);
1222 //for history
1223 /*
1224 if (!myOldNewMap.IsBound(aFace))
1225 {
1226 TopTools_ListOfShape EmptyList;
1227 myOldNewMap.Bind(aFace, EmptyList);
1228 }
1229 myOldNewMap(aFace).Clear();
1230 myOldNewMap(aFace).Append(aResult);
1231 */
1232 /////////////
1233
1234 ShapeFix_Face sff (aResult);
1235 //Intializing by tolerances
1236 sff.SetPrecision(Precision::Confusion());
1237 sff.SetMinTolerance(tol);
1238 sff.SetMaxTolerance(1.);
1239 //Setting modes
1240 sff.FixOrientationMode() = 0;
1241 //sff.FixWireMode() = 0;
1242 //sff.SetContext(aContext);
1243 sff.SetContext(myContext);
1244 // Applying the fixes
1245 sff.Perform();
1246 if(sff.Status(ShapeExtend_FAIL))
1247 hasFailed = Standard_True;
1248
1249 // breaking down to several faces
1250 //TopoDS_Shape theResult = aContext->Apply(aResult);
1251 TopoDS_Shape theResult = myContext->Apply(aResult);
1252 for (TopExp_Explorer aFaceExp (theResult,TopAbs_FACE); aFaceExp.More(); aFaceExp.Next()) {
1253 TopoDS_Face aCurrent = TopoDS::Face(aFaceExp.Current().Oriented(TopAbs_FORWARD));
1254 Handle(TColGeom_HArray2OfSurface) grid = new TColGeom_HArray2OfSurface ( 1, 1, 1, 1 );
1255 grid->SetValue ( 1, 1, aBaseSurface );
1256 Handle(ShapeExtend_CompositeSurface) G = new ShapeExtend_CompositeSurface ( grid );
1257 ShapeFix_ComposeShell CompShell;
1258 CompShell.Init ( G, aBaseLocation, aCurrent, ::Precision::Confusion() );//myPrecision
1259 //CompShell.SetContext( aContext );
1260 CompShell.SetContext( myContext );
1261
1262 TopTools_SequenceOfShape parts;
1263 ShapeFix_SequenceOfWireSegment wires;
1264 for(TopExp_Explorer W_Exp(aCurrent,TopAbs_WIRE);W_Exp.More();W_Exp.Next()) {
1265 Handle(ShapeExtend_WireData) sbwd =
1266 new ShapeExtend_WireData ( TopoDS::Wire(W_Exp.Current() ));
1267 ShapeFix_WireSegment seg ( sbwd, TopAbs_REVERSED );
1268 wires.Append(seg);
1269 }
1270
1271 CompShell.DispatchWires ( parts,wires );
1272 for (Standard_Integer j=1; j <= parts.Length(); j++ ) {
1273 ShapeFix_Face aFixOrient(TopoDS::Face(parts(j)));
1274 //aFixOrient.SetContext(aContext);
1275 aFixOrient.SetContext(myContext);
1276 aFixOrient.FixOrientation();
1277 }
1278
1279 TopoDS_Shape CompRes;
1280 if ( faces.Length() !=1 ) {
1281 TopoDS_Shell S;
1282 B.MakeShell ( S );
1283 for ( i=1; i <= parts.Length(); i++ )
1284 B.Add ( S, parts(i) );
ab860031 1285 S.Closed (BRep_Tool::IsClosed (S));
2277323d 1286 CompRes = S;
1287 }
1288 else CompRes = parts(1);
1289
1290 //aContext->Replace(aCurrent,CompRes);
1291 myContext->Replace(aCurrent,CompRes);
1292 //for history
1293 /*
1294 if (!myOldNewMap.IsBound(aCurrent))
1295 {
1296 TopTools_ListOfShape EmptyList;
1297 myOldNewMap.Bind(aCurrent, EmptyList);
1298 }
1299 myOldNewMap(aCurrent).Clear();
1300 myOldNewMap(aCurrent).Append(CompRes);
1301 */
1302 /////////////
1303 }
1304
1305 // remove the remaining faces
1306 for(i = 2; i <= faces.Length(); i++)
f7d70540 1307 {
1308 myOldShapes.Bind(faces(i), theResult);
2277323d 1309 myContext->Remove(faces(i));
f7d70540 1310 }
2277323d 1311 }
1312 } // end processing each face
1313
1314 //TopoDS_Shape aResult = Shape;
1315 if (NbModif > 0 && !hasFailed) {
1316 //TopoDS_Shape aResult = aContext->Apply(aShell);
1317 TopoDS_Shape aResult = myContext->Apply(aShell);
1318
1319 ShapeFix_Edge sfe;
1320 for (exp.Init(aResult,TopAbs_EDGE); exp.More(); exp.Next()) {
1321 TopoDS_Edge E = TopoDS::Edge(exp.Current());
1322 sfe.FixVertexTolerance (E);
1323 // ptv add fix same parameter
1324 sfe.FixSameParameter(E, Precision::Confusion());
1325 }
1326
1327 myContext->Replace(aShell, aResult);
1328 //for history
1329 /*
1330 if (!myOldNewMap.IsBound(aShell))
1331 {
1332 TopTools_ListOfShape EmptyList;
1333 myOldNewMap.Bind(aShell, EmptyList);
1334 }
1335 myOldNewMap(aShell).Clear();
1336 myOldNewMap(aShell).Append(aResult);
1337 */
1338 /////////////
1339 }
1340 //else
1341 {
1342 for (exp.Init(aShell, TopAbs_FACE); exp.More(); exp.Next()) {
1343 TopoDS_Face aFace = TopoDS::Face(exp.Current().Oriented(TopAbs_FORWARD));
1344 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
1345 sfw->SetContext(myContext);
1346 sfw->SetPrecision(Precision::Confusion());
1347 sfw->SetMinTolerance(Precision::Confusion());
1348 sfw->SetMaxTolerance(1.);
1349 sfw->SetFace(aFace);
1350 for (TopoDS_Iterator iter (aFace,Standard_False); iter.More(); iter.Next()) {
1351 TopoDS_Wire wire = TopoDS::Wire(iter.Value());
1352 sfw->Load(wire);
1353 sfw->FixReorder();
1354 sfw->FixShifted();
1355 }
1356 }
1357 }
1358 } // end processing each shell
1359
1360 myShape = myContext->Apply(myShape);
1361}
1362
1363//=======================================================================
1364//function : UnifyEdges
1365//purpose :
1366//=======================================================================
2277323d 1367void ShapeUpgrade_UnifySameDomain::UnifyEdges()
1368{
1369 Standard_Real Tol = Precision::Confusion();
1370
1371 //Handle(ShapeBuild_ReShape) myContext = new ShapeBuild_ReShape;
1372 Standard_Real myTolerance = Precision::Confusion();
1373 TopoDS_Shape aResult = myContext->Apply(myShape);
1374
ce41efde 1375 TopTools_IndexedMapOfShape ChangedFaces;
2277323d 1376
ce41efde 1377 // creating map of edge faces
1378 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
1379 TopExp::MapShapesAndAncestors(myShape, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
1380
1381 // creating map of vertex edges
1382 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgesVertex;
1383 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMapEdgesVertex);
1384
1385 //Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
1386 TopoDS_Shape aRes = myShape;
1387 //aRes = aContext->Apply(aSolid);
1388 aRes = myContext->Apply(myShape);
f7d70540 1389
1390 TopTools_MapOfShape SharedVert;
1391
1392
1393 TopTools_IndexedMapOfShape anOldEdges;
1394 TopExp::MapShapes(myInitShape, TopAbs_EDGE, anOldEdges);
1395
1396 TopTools_DataMapOfShapeShape NewEdges2OldEdges;
1397 for (int i = 1; i <= anOldEdges.Extent(); i++)
1398 {
1399 TopoDS_Shape NewEdge = myContext->Apply(anOldEdges(i));
1400 if (!NewEdge.IsNull())
1401 NewEdges2OldEdges.Bind(NewEdge, anOldEdges(i));
1402 }
ce41efde 1403
ce41efde 1404 TopExp_Explorer exp;
f7d70540 1405 // processing separate wires
1406 for (exp.Init(aRes, TopAbs_WIRE, TopAbs_FACE); exp.More(); exp.Next())
1407 {
1408 TopTools_SequenceOfShape SeqEdges;
1409 TopExp_Explorer expE(exp.Current(), TopAbs_EDGE);
1410 for (; expE.More(); expE.Next())
1411 SeqEdges.Append(expE.Current());
1412 SharedVert.Clear();
1413 CheckSharedVertices(SeqEdges, aMapEdgesVertex, SharedVert);
1414 MergeSeq(SeqEdges, Tol, myConcatBSplines, myContext, myOldShapes, SharedVert, NewEdges2OldEdges);
1415 }
1416
1417 // processing each face
ce41efde 1418 for (exp.Init(aRes, TopAbs_FACE); exp.More(); exp.Next()) {
1419 //TopoDS_Face aFace = TopoDS::Face(aContext->Apply(exp.Current().Oriented(TopAbs_FORWARD)));
1420 TopoDS_Face aFace = TopoDS::Face(myContext->Apply(exp.Current().Oriented(TopAbs_FORWARD)));
1421 TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
f7d70540 1422 TopTools_SequenceOfShape aNonSharedEdges;
ce41efde 1423 for (TopExp_Explorer expe(aFace,TopAbs_EDGE); expe.More(); expe.Next()) {
1424 TopoDS_Edge edge = TopoDS::Edge(expe.Current());
1425 if (!aMapEdgeFaces.Contains(edge)) continue;
1426 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
1427 TopTools_ListIteratorOfListOfShape anIter(aList);
f7d70540 1428 Standard_Integer NbFacesPerEdge = aList.Extent();
ce41efde 1429 for ( ; anIter.More(); anIter.Next()) {
1430 TopoDS_Face face = TopoDS::Face(anIter.Value());
ce41efde 1431 TopoDS_Face face1 = TopoDS::Face(myContext->Apply(anIter.Value()));
f7d70540 1432 if (face1.IsSame(aFace) && NbFacesPerEdge != 1)
1433 continue;
1434 if (NbFacesPerEdge == 1)
1435 //store non-shared edges separately
1436 aNonSharedEdges.Append(edge);
1437 else
1438 {
1439 if (aMapFacesEdges.Contains(face))
1440 aMapFacesEdges.ChangeFromKey(face).Append(edge);
1441 else
1442 {
1443 TopTools_ListOfShape ListEdges;
1444 ListEdges.Append(edge);
1445 aMapFacesEdges.Add(face,ListEdges);
1446 }
2277323d 1447 }
1448 }
ce41efde 1449 }
f7d70540 1450
1451 for (Standard_Integer i=1; i<=aMapFacesEdges.Extent(); i++)
1452 {
ce41efde 1453 const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
1454 TopTools_SequenceOfShape SeqEdges;
ce41efde 1455 TopTools_ListIteratorOfListOfShape anIter(ListEdges);
ce41efde 1456 for ( ; anIter.More(); anIter.Next())
1457 SeqEdges.Append(anIter.Value());
1458 if (SeqEdges.Length()==1)
1459 continue;
2277323d 1460
f7d70540 1461 SharedVert.Clear();
1462 CheckSharedVertices(SeqEdges, aMapEdgesVertex, SharedVert);
1463 //if (!SharedVert.IsEmpty())
1464 // continue;
1465 if ( MergeSeq(SeqEdges,Tol,myConcatBSplines, myContext, myOldShapes, SharedVert, NewEdges2OldEdges) )
2277323d 1466 {
2277323d 1467 //for history
1468 /*
ce41efde 1469 for (j = 1; j <= SeqEdges.Length(); j++)
2277323d 1470 {
ce41efde 1471 if (!myOldNewMap.IsBound(SeqEdges(j)))
1472 {
1473 TopTools_ListOfShape EmptyList;
1474 myOldNewMap.Bind(SeqEdges(j), EmptyList);
1475 }
1476 myOldNewMap(SeqEdges(j)).Clear();
1477 myOldNewMap(SeqEdges(j)).Append(E);
2277323d 1478 }
2277323d 1479 */
1480 /////////////
ce41efde 1481
1482 TopoDS_Face tmpF = TopoDS::Face(exp.Current());
1483 if ( !ChangedFaces.Contains(tmpF) )
1484 ChangedFaces.Add(tmpF);
1485 tmpF = TopoDS::Face(aMapFacesEdges.FindKey(i));
1486 if ( !ChangedFaces.Contains(tmpF) )
1487 ChangedFaces.Add(tmpF);
2277323d 1488 }
ce41efde 1489 }
f7d70540 1490
1491 if ( aNonSharedEdges.Length() > 1 )
1492 {
1493 SharedVert.Clear();
1494 CheckSharedVertices(aNonSharedEdges, aMapEdgesVertex, SharedVert);
1495 if ( MergeSeq(aNonSharedEdges, Tol, myConcatBSplines, myContext, myOldShapes, SharedVert, NewEdges2OldEdges) )
1496 {
1497 TopoDS_Face tmpF = TopoDS::Face(exp.Current());
1498 if ( !ChangedFaces.Contains(tmpF) )
1499 ChangedFaces.Add(tmpF);
1500 }
1501 }
ce41efde 1502
1503 } // end processing each face
1504
1505 // fix changed faces and replace them in the local context
1506 for (Standard_Integer i=1; i<=ChangedFaces.Extent(); i++) {
1507 //TopoDS_Face aFace = TopoDS::Face(aContext->Apply(ChangedFaces.FindKey(i)));
1508 TopoDS_Face aFace = TopoDS::Face(myContext->Apply(ChangedFaces.FindKey(i)));
f7d70540 1509 if (aFace.IsNull())
1510 continue;
ce41efde 1511 Handle(ShapeFix_Face) sff = new ShapeFix_Face(aFace);
1512 sff->SetContext(myContext);
1513 sff->SetPrecision(myTolerance);
1514 sff->SetMinTolerance(myTolerance);
1515 sff->SetMaxTolerance(Max(1.,myTolerance*1000.));
1516 sff->Perform();
1517 TopoDS_Shape aNewFace = sff->Face();
1518 //aContext->Replace(aFace,aNewFace);
1519 myContext->Replace(aFace,aNewFace);
1520 //for history
1521 /*
1522 if (!myOldNewMap.IsBound(aFace))
1523 {
1524 TopTools_ListOfShape EmptyList;
1525 myOldNewMap.Bind(aFace, EmptyList);
1526 }
1527 myOldNewMap(aFace).Clear();
1528 myOldNewMap(aFace).Append(aNewFace);
1529 */
1530 /////////////
1531 }
1532
1533 if (ChangedFaces.Extent() > 0) {
1534 // fix changed shell and replace it in the local context
1535 //TopoDS_Shape aRes1 = aContext->Apply(aRes);
1536 TopoDS_Shape aRes1 = myContext->Apply(aRes);
1537 TopExp_Explorer expsh;
1538 for (expsh.Init(aRes1, TopAbs_SHELL); expsh.More(); expsh.Next()) {
1539 TopoDS_Shell aShell = TopoDS::Shell(expsh.Current());
1540 Handle(ShapeFix_Shell) sfsh = new ShapeFix_Shell;
1541 sfsh->FixFaceOrientation(aShell);
1542 TopoDS_Shape aNewShell = sfsh->Shell();
1543 //aContext->Replace(aShell,aNewShell);
1544 myContext->Replace(aShell,aNewShell);
2277323d 1545 //for history
1546 /*
ce41efde 1547 if (!myOldNewMap.IsBound(aShell))
2277323d 1548 {
1549 TopTools_ListOfShape EmptyList;
ce41efde 1550 myOldNewMap.Bind(aShell, EmptyList);
2277323d 1551 }
ce41efde 1552 myOldNewMap(aShell).Clear();
1553 myOldNewMap(aShell).Append(aNewShell);
2277323d 1554 */
1555 /////////////
1556 }
ce41efde 1557 //TopoDS_Shape aRes2 = aContext->Apply(aRes1);
1558 TopoDS_Shape aRes2 = myContext->Apply(aRes1);
1559 myContext->Replace(myShape,aRes2);
1560 //for history
1561 /*
1562 if (!myOldNewMap.IsBound(aSolid))
1563 {
1564 TopTools_ListOfShape EmptyList;
1565 myOldNewMap.Bind(aSolid, EmptyList);
1566 }
1567 myOldNewMap(aSolid).Clear();
1568 myOldNewMap(aSolid).Append(aRes2);
1569 */
1570 /////////////
1571 }
2277323d 1572
1573 myShape = myContext->Apply(myShape);
1574}
1575
1576//=======================================================================
1577//function : UnifyFacesAndEdges
1578//purpose :
1579//=======================================================================
1580
1581void ShapeUpgrade_UnifySameDomain::UnifyFacesAndEdges()
1582{
1583 UnifyFaces();
1584
1585 /*
1586 ShapeUpgrade_RemoveLocations RemLoc;
1587 RemLoc.Remove(myShape);
1588 myShape = RemLoc.GetResult();
1589 */
1590
1591 UnifyEdges();
1592}
1593
1594//=======================================================================
1595//function : Build
1596//purpose : builds the resulting shape
1597//======================================================================
1598void ShapeUpgrade_UnifySameDomain::Build()
1599{
1600 if (myUnifyFaces && myUnifyEdges)
1601 UnifyFacesAndEdges();
1602
1603 else if (myUnifyEdges)
1604 UnifyEdges();
1605 else if (myUnifyFaces)
1606 UnifyFaces();
1607
1608 //Done();
1609}
1610
1611//=======================================================================
1612//function : Shape
1613//purpose : give the resulting shape
1614//=======================================================================
1615const TopoDS_Shape& ShapeUpgrade_UnifySameDomain::Shape() const
1616{
1617 return myShape;
1618}
1619
1620//=======================================================================
1621//function : Generated
1622//purpose : returns the new shape from the old one
1623//=======================================================================
1624TopoDS_Shape ShapeUpgrade_UnifySameDomain::Generated(const TopoDS_Shape& aShape) const
1625{
1626 TopoDS_Shape aNewShape = myContext->Apply(aShape);
f7d70540 1627
2277323d 1628 if (aNewShape.IsNull())
f7d70540 1629 aNewShape = myContext->Apply(myOldShapes(aShape));
2277323d 1630
1631 return aNewShape;
1632}