Commit | Line | Data |
---|---|---|
973c2be1 | 1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 2 | // |
973c2be1 | 3 | // This file is part of Open CASCADE Technology software library. |
b311480e | 4 | // |
d5f74e42 | 5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
9 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 10 | // |
973c2be1 | 11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. | |
b311480e | 13 | |
7fd59977 | 14 | // abv 30 Dec 98: code optimizations |
15 | //:o1 abv 16.02.99: updating vertices tolerance when edge is updated | |
16 | // rln 03.03.99 S4135: removed unnecessary check for Geom_SphericalSurface (as not V-closed) | |
17 | //:q8 abv 23.03.99: bm4_al_eye.stp #53710: avoid shifting pcurves for pseudo-seam | |
18 | //#78 rln 12.03.99 S4135: checking spatial closure with prec | |
19 | //#81 rln 15.03.99 S4135: for not SP edge chose the best result (either BRepLib or deviation only) | |
20 | //#82 rln 16.03.99 S4135: avoiding setting input precision into the edge in FixAddPCurve | |
21 | //:r4 abv 02.04.99 improving method FixSameParameter() | |
22 | //:s5 abv 22.04.99 Adding debug printouts in catch {} blocks | |
23 | // abv 05.05.99 S4137: method CopyPCurves moved to ShapeBuild_Edge | |
24 | #include <ShapeFix_Edge.ixx> | |
25 | ||
26 | #include <Standard_ErrorHandler.hxx> | |
27 | #include <Standard_Failure.hxx> | |
28 | ||
29 | #include <BRep_Builder.hxx> | |
30 | #include <BRep_GCurve.hxx> | |
31 | #include <BRep_TEdge.hxx> | |
32 | #include <BRep_Tool.hxx> | |
33 | #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx> | |
34 | #include <BRep_ListOfCurveRepresentation.hxx> | |
35 | #include <BRepLib.hxx> | |
36 | ||
37 | #include <Geom2d_Curve.hxx> | |
38 | #include <Geom2d_Line.hxx> | |
39 | #include <Geom2d_BSplineCurve.hxx> | |
40 | #include <Geom2d_TrimmedCurve.hxx> | |
41 | #include <Geom2d_BezierCurve.hxx> | |
42 | ||
43 | #include <Geom_Curve.hxx> | |
44 | #include <GeomLib.hxx> | |
45 | ||
46 | #include <Precision.hxx> | |
47 | #include <TopExp.hxx> | |
48 | #include <TopoDS_Vertex.hxx> | |
49 | #include <TopoDS.hxx> | |
50 | ||
51 | #include <ShapeAnalysis_Edge.hxx> | |
52 | #include <ShapeExtend.hxx> | |
53 | #include <ShapeBuild_Edge.hxx> | |
54 | #include <ShapeFix_ShapeTolerance.hxx> | |
55 | #include <Geom2d_OffsetCurve.hxx> | |
56 | #include <ShapeAnalysis_Curve.hxx> | |
57 | ||
58 | ||
59 | //======================================================================= | |
60 | //function : ShapeFix_Edge | |
61 | //purpose : | |
62 | //======================================================================= | |
63 | ||
64 | ShapeFix_Edge::ShapeFix_Edge() | |
65 | { | |
66 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
67 | myProjector = new ShapeConstruct_ProjectCurveOnSurface; | |
68 | } | |
69 | ||
70 | //======================================================================= | |
71 | //function : Projector | |
72 | //purpose : | |
73 | //======================================================================= | |
74 | ||
75 | Handle(ShapeConstruct_ProjectCurveOnSurface) ShapeFix_Edge::Projector() | |
76 | { | |
77 | return myProjector; | |
78 | } | |
79 | ||
80 | ||
81 | //======================================================================= | |
82 | //function : FixRemovePCurve | |
83 | //purpose : | |
84 | //======================================================================= | |
85 | ||
86 | Standard_Boolean ShapeFix_Edge::FixRemovePCurve (const TopoDS_Edge& edge, | |
87 | const TopoDS_Face& face) | |
88 | { | |
89 | TopLoc_Location L; | |
90 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(face, L); | |
91 | return FixRemovePCurve (edge, S, L); | |
92 | } | |
93 | ||
94 | //======================================================================= | |
95 | //function : FixRemovePCurve | |
96 | //purpose : | |
97 | //======================================================================= | |
98 | ||
99 | Standard_Boolean ShapeFix_Edge::FixRemovePCurve (const TopoDS_Edge& edge, | |
100 | const Handle(Geom_Surface)& surface, | |
101 | const TopLoc_Location& location) | |
102 | { | |
103 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
104 | ShapeAnalysis_Edge EA; | |
105 | Standard_Boolean result = EA.CheckVerticesWithPCurve (edge, surface, location); | |
106 | if (result) ShapeBuild_Edge().RemovePCurve (edge, surface, location); | |
107 | return result; | |
108 | } | |
109 | ||
110 | //======================================================================= | |
111 | //function : FixRemoveCurve3d | |
112 | //purpose : | |
113 | //======================================================================= | |
114 | ||
115 | Standard_Boolean ShapeFix_Edge::FixRemoveCurve3d (const TopoDS_Edge& edge) | |
116 | { | |
117 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
118 | ShapeAnalysis_Edge EA; | |
119 | Standard_Boolean result = EA.CheckVerticesWithCurve3d (edge); | |
120 | if (result) ShapeBuild_Edge().RemoveCurve3d (edge); | |
121 | return result; | |
122 | } | |
123 | ||
124 | //======================================================================= | |
125 | //function : FixAddPCurve | |
126 | //purpose : | |
127 | //======================================================================= | |
128 | ||
129 | Standard_Boolean ShapeFix_Edge::FixAddPCurve (const TopoDS_Edge& edge, | |
130 | const TopoDS_Face& face, | |
131 | const Standard_Boolean isSeam, | |
132 | const Standard_Real prec) | |
133 | { | |
134 | TopLoc_Location L; | |
135 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(face, L); | |
136 | return FixAddPCurve (edge, S, L, isSeam, prec); | |
137 | } | |
138 | ||
139 | //======================================================================= | |
140 | //function : FixAddPCurve | |
141 | //purpose : | |
142 | //======================================================================= | |
143 | ||
144 | Standard_Boolean ShapeFix_Edge::FixAddPCurve (const TopoDS_Edge& edge, | |
145 | const Handle(Geom_Surface)& surface, | |
146 | const TopLoc_Location& location, | |
147 | const Standard_Boolean isSeam, | |
148 | const Standard_Real prec) | |
149 | { | |
150 | Handle(ShapeAnalysis_Surface) sas = new ShapeAnalysis_Surface (surface); | |
151 | return FixAddPCurve (edge, surface, location, isSeam, sas, prec); | |
152 | } | |
153 | ||
154 | //======================================================================= | |
155 | //function : FixAddPCurve | |
156 | //purpose : | |
157 | //======================================================================= | |
158 | ||
159 | Standard_Boolean ShapeFix_Edge::FixAddPCurve (const TopoDS_Edge& edge, | |
160 | const TopoDS_Face& face, | |
161 | const Standard_Boolean isSeam, | |
162 | const Handle(ShapeAnalysis_Surface)& surfana, | |
163 | const Standard_Real prec) | |
164 | { | |
165 | TopLoc_Location L; | |
166 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(face, L); | |
167 | return FixAddPCurve (edge, S, L, isSeam, surfana, prec); | |
168 | } | |
169 | ||
170 | //======================================================================= | |
171 | //function : FixAddPCurve | |
172 | //purpose : | |
173 | //======================================================================= | |
174 | ||
175 | //#12 rln 17/03/98 making this method to be more general : if a curve is | |
176 | //parallel to one iso let us translate it parallely in the direction to another | |
177 | //iso (which is located farther from aC2d). Thus, the requirement for closeness | |
178 | //to the surface bounds may be avoid. | |
179 | //For example, instead of Abs(theLoc.X()-uf) <= Tol) ... elseif (...-ul..)... | |
180 | //the comparison if (Abs(theLoc.X()-uf) <= Abs(theLoc.X()-ul)) .... can be used. | |
181 | ||
182 | //The reason of this fix #12 is that seam is not sure to lie on the bound : | |
183 | //if a surface is periodic the whole contour may be shifted (e.g. ProSTEP, | |
184 | //file ug_exhaust-A.stp entity #284920) | |
185 | ||
186 | static Handle(Geom2d_Curve) TranslatePCurve (const Handle(Geom_Surface)& aSurf, | |
187 | Handle(Geom2d_Curve)& aC2d, | |
188 | const Standard_Real& aTol) | |
189 | { | |
190 | Standard_Real uf,ul,vf,vl; | |
191 | aSurf->Bounds(uf,ul,vf,vl); | |
192 | ||
193 | // cas d une ligne | |
194 | Handle(Geom2d_Line) theL2d = Handle(Geom2d_Line)::DownCast(aC2d); | |
195 | if (!theL2d.IsNull()) { | |
196 | gp_Pnt2d theLoc = theL2d->Location(); | |
197 | gp_Dir2d theDir = theL2d->Direction(); | |
198 | ||
199 | gp_Pnt2d newLoc; | |
200 | Handle(Geom2d_Line) theNewL2d = theL2d; | |
201 | ||
202 | //case UClosed | |
203 | if (Abs(theDir.X()) <= aTol && Abs(theDir.Y()) >= aTol) { | |
204 | if (Abs(theLoc.X() - uf) < Abs(theLoc.X() - ul)) | |
205 | newLoc.SetCoord (theLoc.X() + (ul - uf), theLoc.Y()); | |
206 | else | |
207 | newLoc.SetCoord (theLoc.X() - (ul - uf), theLoc.Y()); | |
208 | theNewL2d = new Geom2d_Line(newLoc, theDir); | |
209 | } | |
210 | /* // case UClosed and line in U = UFirst | |
211 | if ((Abs(theLoc.X() - uf) <= aTol) && | |
212 | (Abs(theDir.X()) <= aTol) && | |
213 | (Abs(theDir.Y()) >= aTol)) { | |
214 | // on translate en ul | |
215 | gp_Pnt2d newLoc(ul, theLoc.Y()); | |
216 | Handle(Geom2d_Line) theNewL2d = new Geom2d_Line(newLoc, theDir); | |
217 | return theNewL2d; | |
218 | } | |
219 | // cas UClosed and line in U = ULast | |
220 | if ((Abs(theLoc.X() - ul) <= aTol) && | |
221 | (Abs(theDir.X()) <= aTol) && | |
222 | (Abs(theDir.Y()) >= aTol)) { | |
223 | // on translate en uf | |
224 | gp_Pnt2d newLoc(uf, theLoc.Y()); | |
225 | Handle(Geom2d_Line) theNewL2d = new Geom2d_Line(newLoc, theDir); | |
226 | return theNewL2d; | |
227 | } | |
228 | */ | |
229 | //case VClosed | |
230 | if (Abs(theDir.X()) >= aTol && Abs(theDir.Y()) <= aTol) { | |
231 | if (Abs(theLoc.Y() - vf) < Abs(theLoc.Y() - vl)) | |
232 | newLoc.SetCoord (theLoc.X(), theLoc.Y() + (vl - vf)); | |
233 | else | |
234 | newLoc.SetCoord (theLoc.X(), theLoc.Y() - (vl - vf)); | |
235 | theNewL2d = new Geom2d_Line(newLoc, theDir); | |
236 | } | |
237 | /* // case VClosed and line in V = VFirst | |
238 | if ((Abs(theLoc.Y() - vf) <= aTol) && | |
239 | (Abs(theDir.X()) >= aTol) && | |
240 | (Abs(theDir.Y()) <= aTol)) { | |
241 | // on translate en vl | |
242 | gp_Pnt2d newLoc(theLoc.X(), vl); | |
243 | Handle(Geom2d_Line) theNewL2d = new Geom2d_Line(newLoc, theDir); | |
244 | return theNewL2d; | |
245 | } | |
246 | // cas VClosed and line in V = VLast | |
247 | if ((Abs(theLoc.Y() - vl) <= aTol) && | |
248 | (Abs(theDir.X()) >= aTol) && | |
249 | (Abs(theDir.Y()) <= aTol)) { | |
250 | // on translate en vf | |
251 | gp_Pnt2d newLoc(theLoc.X(), vf); | |
252 | Handle(Geom2d_Line) theNewL2d = new Geom2d_Line(newLoc, theDir); | |
253 | return theNewL2d; | |
254 | } | |
255 | */ | |
256 | // Other case not yet implemented | |
0797d9d3 | 257 | #ifdef OCCT_DEBUG |
7fd59977 | 258 | cout << "TranslatePCurve not performed" << endl; |
259 | #endif | |
260 | return theNewL2d;//*theL2d; | |
261 | } | |
262 | else { | |
263 | // cas bspline curve | |
264 | Handle(Geom2d_BSplineCurve) | |
265 | aBC = Handle(Geom2d_BSplineCurve)::DownCast(aC2d); | |
266 | if (aBC.IsNull()) { | |
0797d9d3 | 267 | #ifdef OCCT_DEBUG |
7fd59977 | 268 | cout << "Untreated curve type in TranslatePCurve" << endl; |
269 | #endif | |
270 | return aC2d; | |
271 | } | |
272 | Handle(Geom2d_BSplineCurve) newC = | |
273 | Handle(Geom2d_BSplineCurve)::DownCast(aBC->Copy()); | |
274 | gp_Pnt2d FirstPoint = aBC->StartPoint(); | |
275 | gp_Pnt2d LastPoint = aBC->EndPoint(); | |
276 | gp_Vec2d theVector (FirstPoint, LastPoint); | |
277 | gp_Pnt2d p00(uf, vf), p01(uf,vl), p10(ul,vf); | |
278 | gp_Vec2d VectIsoUF(p00, p01); | |
279 | gp_Vec2d VectIsoVF(p00, p10); | |
280 | ||
281 | gp_Trsf2d T; | |
282 | if (theVector.IsParallel(VectIsoUF, aTol)) { | |
283 | if (Abs(FirstPoint.X() - uf) < Abs(FirstPoint.X() - ul)) T.SetTranslation(p00, p10); | |
284 | else T.SetTranslation(p10, p00); | |
285 | newC->Transform(T); | |
286 | return newC; | |
287 | } | |
288 | /* // case UClosed and line in U = UFirst | |
289 | if (Abs(FirstPoint.X() - uf) <= aTol) { | |
290 | gp_Trsf2d T; | |
291 | T.SetTranslation(p00, p10); | |
292 | newC->Transform(T); | |
293 | return newC; | |
294 | } | |
295 | // case UClosed and line in U = ULast | |
296 | else if (Abs(FirstPoint.X() - ul) <= aTol) { | |
297 | gp_Trsf2d T; | |
298 | T.SetTranslation(p10, p00); | |
299 | newC->Transform(T); | |
300 | return newC; | |
301 | } | |
302 | else { // les courbes ne sont pas sur la couture | |
303 | return aC2d; | |
304 | } | |
305 | */ | |
306 | else if (theVector.IsParallel(VectIsoVF, aTol)) { | |
7fd59977 | 307 | if (Abs(FirstPoint.Y() - vf) < Abs(FirstPoint.Y() - vl)) T.SetTranslation(p00, p01); |
308 | else T.SetTranslation(p01, p00); | |
309 | newC->Transform(T); | |
310 | return newC; | |
311 | } | |
312 | } | |
313 | // les courbes ne sont pas sur la couture | |
314 | return aC2d; | |
315 | } | |
316 | ||
7fd59977 | 317 | //======================================================================= |
318 | //function : SameRange (Temp) | |
319 | //purpose : | |
320 | //======================================================================= | |
321 | //:b0 abv 16 Feb 98: This is a copy of BRepLib::SameRange() | |
322 | // modified in order to be able to fix seam edges | |
323 | // NOTE: It is to be removed when is fixed either BRepLib::SameRange() | |
324 | // (concerning seam edges) or BRepLib::SameParameter() (concerning call | |
325 | // to GeomLib::SameRange() with 3d tolerance) | |
326 | ||
327 | static void TempSameRange(const TopoDS_Edge& AnEdge, | |
328 | const Standard_Real Tolerance) | |
329 | { | |
330 | BRep_ListIteratorOfListOfCurveRepresentation an_Iterator | |
331 | ((*((Handle(BRep_TEdge)*)&AnEdge.TShape()))->ChangeCurves()); | |
332 | ||
333 | Handle(Geom2d_Curve) Curve2dPtr, NewCurve2dPtr; | |
334 | Handle(Geom2d_Curve) Curve2dPtr2, NewCurve2dPtr2; | |
335 | TopLoc_Location LocalLoc ; | |
336 | ||
337 | //Standard_Boolean IsSameRange = Standard_True //skl | |
338 | Standard_Boolean first_time_in = Standard_True, has_curve, has_closed_curve; | |
339 | Handle(BRep_GCurve) geometric_representation_ptr; | |
340 | Standard_Real first, current_first, last, current_last; | |
341 | ||
342 | const Handle(Geom_Curve) C = BRep_Tool::Curve(AnEdge, LocalLoc, | |
343 | current_first, current_last); | |
344 | if (!C.IsNull()) first_time_in = Standard_False; | |
345 | ||
346 | while (an_Iterator.More()) { | |
347 | geometric_representation_ptr = | |
348 | Handle(BRep_GCurve)::DownCast(an_Iterator.Value()); | |
349 | if (! geometric_representation_ptr.IsNull()) { | |
350 | has_closed_curve = has_curve = Standard_False; | |
351 | first = geometric_representation_ptr->First(); | |
352 | last = geometric_representation_ptr->Last(); | |
353 | if (geometric_representation_ptr->IsCurveOnSurface()) { | |
354 | Curve2dPtr = geometric_representation_ptr->PCurve() ; | |
355 | has_curve = Standard_True ; | |
356 | } | |
357 | if (geometric_representation_ptr->IsCurveOnClosedSurface()) { | |
358 | Curve2dPtr2 = geometric_representation_ptr->PCurve2() ; | |
359 | has_closed_curve = Standard_True ; | |
360 | } | |
361 | if (has_curve || has_closed_curve) { | |
362 | if (first_time_in) { | |
363 | current_first = first; | |
364 | current_last = last; | |
365 | first_time_in = Standard_False; | |
366 | } | |
367 | ||
368 | if (Abs(first - current_first) > Precision::PConfusion() || //:b8 abv 20 Feb 98: Confusion -> PConfusion | |
369 | Abs(last - current_last) > Precision::PConfusion() ) { //:b8 | |
370 | Standard_Real oldFirst=0., oldLast=0.; //skl | |
371 | if (has_curve) { | |
372 | //pdn 20.05.99 Work around | |
373 | oldFirst = geometric_representation_ptr->First(); | |
374 | oldLast = geometric_representation_ptr->Last(); | |
375 | // 15.11.2002 PTV OCC966 | |
376 | if(ShapeAnalysis_Curve::IsPeriodic(Curve2dPtr)) { | |
377 | Handle(Geom2d_TrimmedCurve) tc = new Geom2d_TrimmedCurve(Curve2dPtr,oldFirst,oldLast); | |
378 | Standard_Real shift = tc->FirstParameter()-oldFirst; | |
379 | oldFirst += shift; | |
380 | oldLast += shift; | |
381 | } | |
382 | //pdn 30.06.2000 work arounf on beziers | |
383 | Standard_Real oldFirstCurve1 = oldFirst, oldLastCurve1 = oldLast; | |
384 | if(Curve2dPtr->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))) { | |
385 | ||
386 | Standard_Real preci = Precision::PConfusion(); | |
387 | if ( Abs(oldFirst) > preci || Abs(oldLast-1) > preci ) { | |
388 | Handle(Geom2d_BezierCurve) bezier = Handle(Geom2d_BezierCurve)::DownCast(Curve2dPtr->Copy()); | |
389 | bezier->Segment(oldFirst,oldLast); | |
390 | Curve2dPtr = bezier; | |
391 | } | |
392 | oldFirstCurve1 = 0; | |
393 | oldLastCurve1 = 1; | |
394 | } | |
395 | ||
396 | GeomLib::SameRange(Tolerance, Curve2dPtr, | |
397 | oldFirstCurve1, | |
398 | oldLastCurve1, | |
399 | current_first, current_last, NewCurve2dPtr); | |
400 | geometric_representation_ptr->PCurve(NewCurve2dPtr) ; | |
401 | } | |
402 | if (has_closed_curve) { | |
403 | ||
404 | Standard_Real oldFirstCurve2 = oldFirst, oldLastCurve2 = oldLast; | |
405 | ||
406 | if(Curve2dPtr2->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))) { | |
407 | ||
408 | Standard_Real preci = Precision::PConfusion(); | |
409 | if ( Abs(oldFirst) > preci || Abs(oldLast-1) > preci ) { | |
410 | Handle(Geom2d_BezierCurve) bezier = Handle(Geom2d_BezierCurve)::DownCast(Curve2dPtr2->Copy()); | |
411 | bezier->Segment(oldFirst,oldLast); | |
412 | Curve2dPtr2 = bezier; | |
413 | } | |
414 | oldFirstCurve2 = 0; | |
415 | oldLastCurve2 = 1; | |
416 | } | |
417 | ||
418 | GeomLib::SameRange(Tolerance, Curve2dPtr2, | |
419 | oldFirstCurve2, | |
420 | oldLastCurve2, | |
421 | current_first, current_last, NewCurve2dPtr2); | |
422 | geometric_representation_ptr->PCurve2(NewCurve2dPtr2); | |
423 | } | |
424 | } | |
425 | } | |
426 | } | |
427 | an_Iterator.Next(); | |
428 | } | |
429 | BRep_Builder B; | |
430 | B.Range(TopoDS::Edge(AnEdge), current_first, current_last); | |
431 | B.SameRange(AnEdge, Standard_True); | |
432 | } | |
433 | ||
434 | //======================================================================= | |
435 | //function : FixAddPCurve | |
436 | //======================================================================= | |
437 | ||
438 | Standard_Boolean ShapeFix_Edge::FixAddPCurve (const TopoDS_Edge& edge, | |
439 | const Handle(Geom_Surface)& surf, | |
440 | const TopLoc_Location& location, | |
441 | const Standard_Boolean isSeam, | |
442 | const Handle(ShapeAnalysis_Surface)& sas, | |
443 | const Standard_Real prec) | |
444 | { | |
445 | ShapeAnalysis_Edge sae; | |
446 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
447 | if ( (!isSeam && sae.HasPCurve (edge, surf, location))|| | |
448 | ( isSeam && sae.IsSeam(edge, surf, location))) return Standard_False; | |
449 | ||
450 | // PCurve on Plane not computed | |
451 | if (surf->IsKind(STANDARD_TYPE(Geom_Plane))) return Standard_False; | |
452 | ||
453 | // Standard_Real step = 0; | |
454 | try { | |
455 | OCC_CATCH_SIGNALS | |
456 | Standard_Real First, Last; | |
457 | ||
458 | BRep_Builder B; | |
459 | ||
460 | Standard_Real preci = ( prec >0. ? prec : BRep_Tool::Tolerance(edge) ); | |
461 | Handle(Geom_Curve) c3d = BRep_Tool::Curve(edge, /*Loc,*/ First, Last); | |
462 | // Handle(Geom_Curve) c3d = BRep_Tool::Curve(E, First, Last); | |
463 | if (c3d.IsNull() || (Abs(Last-First) <Precision::PConfusion())) { | |
464 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
465 | return Standard_False; | |
466 | } | |
467 | ||
468 | // Trim the curve to avoid problem ?? | |
469 | // c3d = Handle(Geom_Curve)::DownCast(c3d->Transformed(Loc.Transformation())); | |
470 | // Handle(Geom_TrimmedCurve) theTrimmed = new Geom_TrimmedCurve(c3d, First, Last); | |
471 | // c3d = theTrimmed; | |
472 | ||
473 | // step = 1; | |
474 | ||
475 | // A present, on projette | |
476 | // stat : 0 pas pu faire, 1 analytique, 2 approx | |
477 | Handle(Geom2d_Curve) c2d; | |
478 | Standard_Real a1, b1; | |
479 | if ( ! sae.HasPCurve (edge, surf, location)) { | |
480 | myProjector->Init ( sas, preci ); | |
481 | myProjector->Perform (c3d,First,Last,c2d); | |
482 | // stat = 2 : reinterpoler la c3d ? | |
483 | if ( myProjector->Status ( ShapeExtend_DONE4 ) ) | |
484 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE2); | |
485 | a1 = First; | |
486 | b1 = Last; | |
487 | } | |
488 | else { | |
489 | sae.PCurve ( edge, surf, location, c2d, a1, b1, Standard_False ); | |
490 | } | |
491 | ||
492 | // step = 2; | |
493 | ||
494 | // adding by skl 28.03.2003 for usung Line instead of BSpline | |
495 | Standard_Real fp=0.,lp=0.; | |
496 | Standard_Boolean isLine=Standard_False; | |
497 | if(c2d->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) { | |
498 | Handle(Geom2d_TrimmedCurve) tc = Handle(Geom2d_TrimmedCurve)::DownCast(c2d); | |
499 | if(tc->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Line))) { | |
500 | fp = tc->FirstParameter(); | |
501 | lp = tc->LastParameter(); | |
502 | isLine = Standard_True; | |
503 | } | |
504 | } | |
505 | ||
506 | if (isSeam) { | |
507 | // On ne sait pas laquelle est Forward. Au PIF. La geometrie Forward | |
508 | // sera mise a jour dans ComputeWire | |
509 | Handle(Geom2d_Curve) c2d2 = Handle(Geom2d_Curve)::DownCast(c2d->Copy()); | |
510 | // ATTENTION : TranslatePCurve reconstruit une Line // bords, en | |
511 | // intuitant U ou V ... | |
512 | // Ici, on exploite les infos deja connues | |
513 | Standard_Real uf,ul,vf,vl; | |
514 | surf->Bounds (uf,ul,vf,vl); | |
515 | //#4 rln 19/02/98 ProSTEP ug_exhaust-A.stp entity #284920 (thoroidal surface) | |
516 | //#13 rln 17/03/98 (updating fix #4) call to TranslatePCurve in the case | |
517 | //when a surface is either u- and vclosed or neither u- nor vclosed | |
518 | //#78 rln 12.03.99 S4135: checking spatial closure with prec | |
519 | if (sas->IsUClosed(prec) && ! sas->IsVClosed(prec) //rln S4135 sphere is not considered as V-closed anymore || | |
520 | /* rln S4135 sas->Surface()->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) */ ) {//:d9 abv 17 Mar 98: any sphere | |
521 | gp_Vec2d tranvec (ul-uf,0); | |
522 | c2d2->Translate (tranvec); | |
523 | } | |
524 | else if (sas->IsVClosed(prec) && ! sas->IsUClosed(prec) ) { | |
525 | gp_Vec2d tranvec (0,vl-vf); | |
526 | c2d2->Translate (tranvec); | |
527 | } | |
528 | else if ( sas->IsUClosed() && sas->IsVClosed() ) { //:q8 abv 23 Mar 99: bm4_al_eye.stp #53710: avoid shifting pcurves for pseudo-seam | |
529 | // Doublement fermee (ex tore) : on lance la charge | |
530 | c2d2 = TranslatePCurve(sas->Surface(), c2d2, prec); | |
531 | } | |
532 | B.UpdateEdge (edge,c2d,c2d2,surf,location, 0.); //#82 rln 16.03.99: preci | |
533 | // if ( c2d->IsKind (STANDARD_TYPE(Geom2d_BoundedCurve)) ) | |
534 | // B.Range (edge,surf,location,c2d->FirstParameter(),c2d->LastParameter()); | |
535 | B.Range (edge,surf,location,a1,b1); | |
536 | } | |
537 | else { | |
538 | B.UpdateEdge (edge,c2d,surf,location, 0.); //#82 rln 16.03.99: preci | |
539 | } | |
540 | ||
541 | if ( isLine ) { | |
542 | B.Range(edge,surf,location,fp,lp); | |
543 | B.SameParameter(edge,Standard_False); | |
544 | B.SameRange(edge,Standard_False); | |
545 | } | |
546 | ||
547 | // Conclusion | |
548 | // step = 3; | |
549 | if ( myProjector->Status ( ShapeExtend_DONE3 ) ) { | |
550 | Standard_Real G3dCFirst = c3d->FirstParameter(); | |
551 | Standard_Real G3dCLast = c3d->LastParameter(); | |
552 | B.UpdateEdge(edge, c3d, 0.); | |
da72a17c | 553 | B.Range(edge, G3dCFirst, G3dCLast, Standard_True); |
7fd59977 | 554 | } |
555 | } // end try | |
556 | catch(Standard_Failure) { | |
557 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
0797d9d3 | 558 | #ifdef OCCT_DEBUG //:s5 |
7fd59977 | 559 | cout << "Warning: ShapeFix_Edge::FixAddPCurve(): Exception: "; |
560 | Standard_Failure::Caught()->Print(cout); cout << endl; | |
561 | #endif | |
562 | } | |
563 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
564 | return Standard_True; | |
565 | } | |
566 | ||
567 | //======================================================================= | |
568 | //function : FixAddCurve3d | |
569 | //purpose : | |
570 | //======================================================================= | |
571 | ||
572 | Standard_Boolean ShapeFix_Edge::FixAddCurve3d(const TopoDS_Edge& edge) | |
573 | { | |
574 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
575 | ShapeAnalysis_Edge EA; | |
576 | if ( BRep_Tool::Degenerated ( edge ) || EA.HasCurve3d (edge) ) return Standard_False; | |
577 | if(!BRep_Tool::SameRange(edge)) | |
578 | TempSameRange(edge,Precision::PConfusion()); | |
579 | ||
580 | if (!ShapeBuild_Edge().BuildCurve3d(edge)) { | |
581 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
582 | return Standard_False; | |
583 | } | |
584 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
585 | return Standard_True; | |
586 | } | |
587 | ||
588 | //======================================================================= | |
589 | //function : FixVertexTolerance | |
590 | //purpose : | |
591 | //======================================================================= | |
592 | ||
593 | Standard_Boolean ShapeFix_Edge::FixVertexTolerance(const TopoDS_Edge& edge, | |
594 | const TopoDS_Face& face) | |
595 | { | |
596 | myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); | |
597 | ShapeAnalysis_Edge sae; | |
598 | Standard_Real toler1, toler2; | |
599 | if (!sae.CheckVertexTolerance (edge, face, toler1, toler2)) return Standard_False; | |
600 | if (sae.Status (ShapeExtend_DONE1)) | |
601 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
602 | if (sae.Status (ShapeExtend_DONE2)) | |
603 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2); | |
604 | BRep_Builder B; | |
605 | TopoDS_Vertex V1 = sae.FirstVertex(edge); | |
606 | TopoDS_Vertex V2 = sae.LastVertex(edge); | |
607 | B.UpdateVertex (V1, toler1); | |
608 | B.UpdateVertex (V2, toler2); | |
609 | return Standard_True; | |
610 | } | |
611 | ||
612 | //======================================================================= | |
613 | //function : FixVertexTolerance | |
614 | //purpose : | |
615 | //======================================================================= | |
616 | ||
617 | Standard_Boolean ShapeFix_Edge::FixVertexTolerance(const TopoDS_Edge& edge) | |
618 | { | |
619 | myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); | |
620 | ShapeAnalysis_Edge sae; | |
621 | Standard_Real toler1, toler2; | |
622 | if (!sae.CheckVertexTolerance (edge, toler1, toler2)) return Standard_False; | |
623 | if (sae.Status (ShapeExtend_DONE1)) | |
624 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
625 | if (sae.Status (ShapeExtend_DONE2)) | |
626 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2); | |
627 | BRep_Builder B; | |
628 | TopoDS_Vertex V1 = sae.FirstVertex(edge); | |
629 | TopoDS_Vertex V2 = sae.LastVertex(edge); | |
630 | B.UpdateVertex (V1, toler1); | |
631 | B.UpdateVertex (V2, toler2); | |
632 | return Standard_True; | |
633 | } | |
634 | ||
635 | //======================================================================= | |
636 | //function : FixReversed2d | |
637 | //purpose : | |
638 | //======================================================================= | |
639 | ||
640 | Standard_Boolean ShapeFix_Edge::FixReversed2d (const TopoDS_Edge& edge, | |
641 | const TopoDS_Face& face) | |
642 | { | |
643 | TopLoc_Location L; | |
644 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(face, L); | |
645 | return FixReversed2d (edge, S, L); | |
646 | } | |
647 | ||
648 | //======================================================================= | |
649 | //function : FixReversed2d | |
650 | //purpose : | |
651 | //======================================================================= | |
652 | ||
653 | Standard_Boolean ShapeFix_Edge::FixReversed2d (const TopoDS_Edge& edge, | |
654 | const Handle(Geom_Surface)& surface, | |
655 | const TopLoc_Location& location) | |
656 | { | |
657 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK); | |
658 | ||
659 | ShapeAnalysis_Edge EA; | |
660 | EA.CheckCurve3dWithPCurve (edge, surface, location); | |
661 | if (EA.Status (ShapeExtend_FAIL1)) | |
662 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1); | |
663 | if (EA.Status (ShapeExtend_FAIL2)) | |
664 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2); | |
665 | if ( ! EA.Status (ShapeExtend_DONE) ) return Standard_False; | |
666 | ||
667 | Handle(Geom2d_Curve) c2d; | |
668 | Standard_Real f,l; | |
669 | EA.PCurve (edge, surface, location, c2d, f, l, Standard_False); | |
670 | //#46 rln 01.12.98 buc40130, entity 272 (4-th curve) | |
671 | Standard_Real newf = c2d->ReversedParameter (l), newl = c2d->ReversedParameter (f); | |
672 | c2d->Reverse(); | |
673 | BRep_Builder B; | |
674 | //will break seams! B.UpdateEdge (edge, c2d, surface, location, Precision::Confusion()); | |
675 | B.Range (edge, surface, location, newf, newl); | |
676 | //#51 rln 15.12.98 pro6562 entity 2788 | |
677 | //Because of numerical accuracy the range on B-Splines (moreover, on any curve!) | |
678 | //the range is changed | |
679 | Standard_Real first, last; | |
680 | BRep_Tool::Range (edge, first, last); | |
681 | if (first != newf || last != newl) { | |
682 | B.SameRange (edge, Standard_False); | |
683 | B.SameParameter (edge, Standard_False); | |
684 | } | |
685 | myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1); | |
686 | return Standard_True; | |
687 | } | |
688 | ||
689 | ||
690 | //======================================================================= | |
691 | //function : FixSameParameter | |
692 | //purpose : | |
693 | //======================================================================= | |
694 | ||
695 | Standard_Boolean ShapeFix_Edge::FixSameParameter(const TopoDS_Edge& edge, | |
696 | const Standard_Real tolerance) | |
697 | { | |
698 | myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); | |
699 | ||
700 | if ( BRep_Tool::Degenerated ( edge ) ) { | |
701 | BRep_Builder B; | |
702 | if ( ! BRep_Tool::SameRange (edge) ) | |
703 | TempSameRange ( edge, Precision::PConfusion() ); | |
704 | B.SameParameter ( edge, Standard_True ); | |
705 | return Standard_False; | |
706 | } | |
707 | ShapeFix_ShapeTolerance SFST; | |
708 | ShapeAnalysis_Edge sae; | |
709 | BRep_Builder B; | |
710 | ||
711 | TopoDS_Edge copyedge; | |
712 | TopoDS_Vertex V1 = sae.FirstVertex (edge); | |
713 | TopoDS_Vertex V2 = sae.LastVertex (edge); | |
714 | Standard_Real TolFV = ( V1.IsNull() ? 0. : BRep_Tool::Tolerance ( V1 ) ); | |
715 | Standard_Real TolLV = ( V2.IsNull() ? 0. : BRep_Tool::Tolerance ( V2 ) ); | |
716 | Standard_Real tol = BRep_Tool::Tolerance (edge); | |
717 | ||
718 | Standard_Boolean wasSP = BRep_Tool::SameParameter ( edge ), SP = Standard_False; | |
719 | { | |
720 | try { | |
721 | OCC_CATCH_SIGNALS | |
722 | if ( ! BRep_Tool::SameRange (edge) ) | |
723 | TempSameRange ( edge, Precision::PConfusion() ); | |
724 | //#81 rln 15.03.99 S4135: for not SP edge choose the best result (either BRepLib or deviation only) | |
725 | if ( ! wasSP ) { | |
726 | //create copyedge as copy of edge with the same vertices and copy of pcurves on the same surface(s) | |
727 | copyedge = ShapeBuild_Edge().Copy ( edge, Standard_False ); | |
728 | B.SameParameter ( copyedge, Standard_False ); | |
31c3b8f0 SK |
729 | // ShapeBuild_Edge::Copy() may change 3D curve range (if it's outside of its period). |
730 | // In this case pcurves in BRepLib::SameParameter() will be changed as well | |
731 | // and later ShapeBuild_Edge::CopyPCurves() will copy pcurves keeping original range. | |
732 | // To prevent this discrepancy we enforce original 3D range. | |
733 | Standard_Real aF, aL; | |
734 | BRep_Tool::Range (edge, aF, aL); | |
735 | B.Range (copyedge, aF, aL, Standard_True); // only 3D | |
7fd59977 | 736 | BRepLib::SameParameter ( copyedge, ( tolerance >= Precision::Confusion() ? |
737 | tolerance : tol ) ); | |
738 | SP = BRep_Tool::SameParameter ( copyedge ); | |
739 | if ( ! SP ) myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 ); | |
740 | } | |
741 | } | |
742 | catch(Standard_Failure) { | |
0797d9d3 | 743 | #ifdef OCCT_DEBUG |
7fd59977 | 744 | cout << "\nWarning: ShapeFix_Edge: Exception in SameParameter: "; |
745 | Standard_Failure::Caught()->Print(cout); cout << endl; | |
746 | #endif | |
747 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 ); | |
748 | } | |
749 | } | |
750 | ||
751 | // compute deviation on the original pcurves | |
752 | Standard_Real maxdev; | |
753 | B.SameParameter ( edge, Standard_True ); | |
754 | sae.CheckSameParameter ( edge, maxdev ); | |
755 | if ( sae.Status ( ShapeExtend_FAIL2 ) ) | |
756 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 ); | |
757 | ||
758 | // if BRepLib was OK, compare and select the best variant | |
759 | if ( SP ) { | |
760 | Standard_Real BRLTol = BRep_Tool::Tolerance ( copyedge ), BRLDev; | |
761 | sae.CheckSameParameter ( copyedge, BRLDev ); | |
762 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 ); | |
763 | if ( BRLTol < BRLDev ) BRLTol = BRLDev; | |
764 | ||
765 | //chose the best result | |
766 | if ( BRLTol < maxdev ) { | |
767 | if ( sae.Status ( ShapeExtend_FAIL2 ) ) | |
768 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 ); | |
769 | //copy pcurves and tolerances from copyedge | |
770 | ShapeBuild_Edge().CopyPCurves ( edge, copyedge ); | |
771 | maxdev = BRLTol; | |
772 | SFST.SetTolerance (edge, BRLTol, TopAbs_EDGE); | |
773 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE5 ); | |
774 | } | |
775 | } | |
776 | //restore tolerances because they could be modified by BRepLib | |
777 | if ( ! V1.IsNull() ) SFST.SetTolerance ( V1, Max (maxdev, TolFV), TopAbs_VERTEX); | |
778 | if ( ! V2.IsNull() ) SFST.SetTolerance ( V2, Max (maxdev, TolLV), TopAbs_VERTEX); | |
779 | ||
780 | if ( maxdev > tol ) { | |
781 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 ); | |
782 | B.UpdateEdge ( edge, maxdev ); | |
783 | FixVertexTolerance(edge); | |
784 | } | |
785 | ||
786 | if ( ! wasSP && ! SP ) myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 ); | |
787 | return Status ( ShapeExtend_DONE ); | |
788 | } | |
789 | ||
790 | //======================================================================= | |
791 | //function : Status | |
792 | //purpose : | |
793 | //======================================================================= | |
794 | ||
795 | Standard_Boolean ShapeFix_Edge::Status(const ShapeExtend_Status status) const | |
796 | { | |
797 | return ShapeExtend::DecodeStatus (myStatus, status); | |
798 | } |