1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 //#4 szv S4163: optimizing
15 // pdn 20.04.99 S4181 Moving algorithm for transforming pcurves from IGES processor
16 // abv 05.05.99 S4137: adding methods for copying ranges, reassigning pcurves etc.
18 #include <BRep_Builder.hxx>
19 #include <BRep_Curve3D.hxx>
20 #include <BRep_CurveOnSurface.hxx>
21 #include <BRep_GCurve.hxx>
22 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
23 #include <BRep_TEdge.hxx>
24 #include <BRep_Tool.hxx>
25 #include <BRepBuilderAPI_MakeEdge.hxx>
26 #include <BRepLib.hxx>
28 #include <Geom2d_BezierCurve.hxx>
29 #include <Geom2d_BSplineCurve.hxx>
30 #include <Geom2d_Conic.hxx>
31 #include <Geom2d_Curve.hxx>
32 #include <Geom2d_Line.hxx>
33 #include <Geom2d_OffsetCurve.hxx>
34 #include <Geom2d_TrimmedCurve.hxx>
35 #include <Geom2dConvert.hxx>
36 #include <Geom2dConvert_ApproxCurve.hxx>
37 #include <Geom_Curve.hxx>
38 #include <Geom_OffsetCurve.hxx>
39 #include <Geom_Surface.hxx>
40 #include <Geom_TrimmedCurve.hxx>
41 #include <GeomAPI.hxx>
42 #include <gp_GTrsf2d.hxx>
43 #include <gp_Lin2d.hxx>
46 #include <gp_Trsf2d.hxx>
47 #include <Precision.hxx>
48 #include <ShapeBuild_Edge.hxx>
49 #include <Standard_ErrorHandler.hxx>
50 #include <Standard_Failure.hxx>
52 #include <TopLoc_Location.hxx>
54 #include <TopoDS_Edge.hxx>
55 #include <TopoDS_Face.hxx>
56 #include <TopoDS_Iterator.hxx>
57 #include <TopoDS_Vertex.hxx>
58 #include <TopTools_SequenceOfShape.hxx>
60 //=======================================================================
61 //function : CopyReplaceVertices
63 //=======================================================================
64 TopoDS_Edge ShapeBuild_Edge::CopyReplaceVertices (const TopoDS_Edge& edge,
65 const TopoDS_Vertex& V1,
66 const TopoDS_Vertex& V2) const
68 TopTools_SequenceOfShape aNMVertices;
69 TopoDS_Vertex newV1 = V1, newV2 = V2;
70 if ( newV1.IsNull() || newV2.IsNull() ) {
72 if(edge.Orientation() == TopAbs_FORWARD ||
73 edge.Orientation() == TopAbs_REVERSED)
75 it.Initialize(edge, Standard_True, Standard_True);
79 it.Initialize(edge, Standard_False, Standard_True);
81 for ( ; it.More(); it.Next() ) {
82 TopoDS_Vertex V = TopoDS::Vertex ( it.Value() );
83 if ( V.Orientation() == TopAbs_FORWARD ) {
84 if ( newV1.IsNull() ) newV1 = V;
86 else if ( V.Orientation() == TopAbs_REVERSED ) {
87 if ( newV2.IsNull() ) newV2 = V;
89 else if(V1.IsNull() && V2.IsNull())
90 aNMVertices.Append(V);
93 newV1.Orientation ( TopAbs_FORWARD );
94 newV2.Orientation ( TopAbs_REVERSED );
96 //szv#4:S4163:12Mar99 SGI warns
97 TopoDS_Shape sh = edge.EmptyCopied();
98 TopoDS_Edge E = TopoDS::Edge( sh );
101 if ( ! newV1.IsNull() ) B.Add ( E, newV1 );
102 if ( ! newV2.IsNull() ) B.Add ( E, newV2 );
104 //addition of the internal or external vertices to edge
105 Standard_Integer i =1;
106 for( ; i <= aNMVertices.Length(); i++)
107 B.Add ( E,TopoDS::Vertex(aNMVertices.Value(i)));
109 //S4054, rln 17.11.98 annie_surf.igs entity D77, 3D and pcurve have different
110 //ranges, after B.Range all the ranges become as 3D
111 CopyRanges ( E, edge );
113 for (BRep_ListIteratorOfListOfCurveRepresentation itcr
114 ((*((Handle(BRep_TEdge)*)&edge.TShape()))->ChangeCurves()); itcr.More(); itcr.Next()) {
115 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
116 if ( GC.IsNull() ) continue;
117 Standard_Real first, last;
118 GC->Range ( first, last );
119 if ( GC->IsCurve3D() )
120 B.Range ( E, first, last );
121 else if ( GC->IsCurveOnSurface() )
122 B.Range (E, GC->Surface(), edge.Location().Multiplied (GC->Location()), first, last);//BUC50003 entity 132 edge 1
128 //=======================================================================
129 //function : CopyRanges
131 //=======================================================================
133 // Added, cause invoke ShapeAnalysis leads to cyclic dependancy.
134 static Standard_Real AdjustByPeriod(const Standard_Real Val,
135 const Standard_Real ToVal,
136 const Standard_Real Period)
138 Standard_Real diff = Val - ToVal;
139 Standard_Real D = Abs ( diff );
140 Standard_Real P = Abs ( Period );
141 if ( D <= 0.5 * P ) return 0.;
142 if ( P < 1e-100 ) return diff;
143 return ( diff >0 ? -P : P ) * (Standard_Integer)( D / P + 0.5 );
146 static Standard_Boolean IsPeriodic(const Handle(Geom_Curve)& theCurve)
148 // 15.11.2002 PTV OCC966
149 // remove regressions in DE tests (diva, divb, divc, toe3) in KAS:dev
150 // ask IsPeriodic on BasisCurve
151 Handle(Geom_Curve) aTmpCurve = theCurve;
152 while ( (aTmpCurve->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) ||
153 (aTmpCurve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) ) {
154 if (aTmpCurve->IsKind(STANDARD_TYPE(Geom_OffsetCurve)))
155 aTmpCurve = Handle(Geom_OffsetCurve)::DownCast(aTmpCurve)->BasisCurve();
156 if (aTmpCurve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve)))
157 aTmpCurve = Handle(Geom_TrimmedCurve)::DownCast(aTmpCurve)->BasisCurve();
159 return aTmpCurve->IsPeriodic();
162 Standard_Boolean IsPeriodic(const Handle(Geom2d_Curve)& theCurve)
164 // 15.11.2002 PTV OCC966
165 // remove regressions in DE tests (diva, divb, divc, toe3) in KAS:dev
166 // ask IsPeriodic on BasisCurve
167 Handle(Geom2d_Curve) aTmpCurve = theCurve;
168 while ( (aTmpCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve))) ||
169 (aTmpCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) ) {
170 if (aTmpCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve)))
171 aTmpCurve = Handle(Geom2d_OffsetCurve)::DownCast(aTmpCurve)->BasisCurve();
172 if (aTmpCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve)))
173 aTmpCurve = Handle(Geom2d_TrimmedCurve)::DownCast(aTmpCurve)->BasisCurve();
175 return aTmpCurve->IsPeriodic();
178 void ShapeBuild_Edge::CopyRanges (const TopoDS_Edge& toedge,
179 const TopoDS_Edge& fromedge,
180 const Standard_Real alpha,
181 const Standard_Real beta) const
184 for (BRep_ListIteratorOfListOfCurveRepresentation itcr
185 ((*((Handle(BRep_TEdge)*)&fromedge.TShape()))->ChangeCurves()); itcr.More(); itcr.Next()) {
186 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
187 if ( GC.IsNull() ) continue;
188 Standard_Real first, last;
189 GC->Range ( first, last );
190 if ( GC->IsCurve3D() )
191 B.Range ( toedge, first, last );
192 else if ( GC->IsCurveOnSurface() )
193 B.Range ( toedge, GC->Surface(), fromedge.Location().Multiplied (GC->Location()), first, last);
196 for (BRep_ListIteratorOfListOfCurveRepresentation fromitcr
197 ((*((Handle(BRep_TEdge)*)&fromedge.TShape()))->ChangeCurves()); fromitcr.More(); fromitcr.Next()) {
198 Handle(BRep_GCurve) fromGC = Handle(BRep_GCurve)::DownCast(fromitcr.Value());
199 if ( fromGC.IsNull() ) continue;
200 Standard_Boolean isC3d = fromGC->IsCurve3D();
202 if(fromGC->Curve3D().IsNull()) continue; }
204 if(fromGC->PCurve().IsNull()) continue; }
206 if ( ! isC3d && ! fromGC->IsCurveOnSurface()) continue; // only 3d curves and pcurves are treated
208 Handle(Geom_Surface) surface;
211 surface = fromGC->Surface();
212 L = fromGC->Location();
215 BRep_ListOfCurveRepresentation& tolist = (*((Handle(BRep_TEdge)*)&toedge.TShape()))->ChangeCurves();
216 Handle(BRep_GCurve) toGC;
217 for (BRep_ListIteratorOfListOfCurveRepresentation toitcr (tolist); toitcr.More(); toitcr.Next()) {
218 toGC = Handle(BRep_GCurve)::DownCast(toitcr.Value());
219 if ( toGC.IsNull() ) continue;
221 if ( ! toGC->IsCurve3D() ) continue;
223 else if ( ! toGC->IsCurveOnSurface() ||
224 surface != toGC->Surface() || L != toGC->Location() ) continue;
225 Standard_Real first = fromGC->First();
226 Standard_Real last = fromGC->Last();
227 Standard_Real len = last - first;
228 Standard_Real newF = first+alpha*len;
229 Standard_Real newL = first+beta*len;
231 // PTV: 22.03.2002 fix for edge range.
232 // file test-m020306-v2.step Shell #665 (Faces #40110. #40239).
233 Standard_Real aPeriod=1., aCrvF=0., aCrvL=1.;
234 Standard_Boolean doCheck = Standard_False;
235 if (toGC->IsKind(STANDARD_TYPE(BRep_Curve3D))) {
236 Handle(Geom_Curve) aCrv3d = Handle(BRep_Curve3D)::DownCast(toGC)->Curve3D();
237 // 15.11.2002 PTV OCC966
238 if ( ! aCrv3d.IsNull() && IsPeriodic(aCrv3d) ) {
239 aPeriod = aCrv3d->Period();
240 aCrvF = aCrv3d->FirstParameter();
241 aCrvL = aCrv3d->LastParameter();
242 doCheck = Standard_True;
245 else if (toGC->IsKind(STANDARD_TYPE(BRep_CurveOnSurface))) {
246 Handle(Geom2d_Curve) aCrv2d = Handle(BRep_CurveOnSurface)::DownCast(toGC)->PCurve();
247 // 15.11.2002 PTV OCC966
248 if (!aCrv2d.IsNull() && IsPeriodic(aCrv2d)) {
249 aPeriod = aCrv2d->Period();
250 aCrvF = aCrv2d->FirstParameter();
251 aCrvL = aCrv2d->LastParameter();
252 doCheck = Standard_True;
255 if ( doCheck && ( (fabs(newF -aCrvF ) > Precision::PConfusion() && newF < aCrvF) || newF >= aCrvL ) ) {
256 Standard_Real aShift = AdjustByPeriod(newF, 0.5*(aCrvF+aCrvL), aPeriod);
259 BRep_Builder().SameRange(toedge,Standard_False);
260 BRep_Builder().SameParameter(toedge,Standard_False);
263 toGC->SetRange ( newF, newL );
269 //=======================================================================
270 //function : SetRange3d
272 //=======================================================================
274 void ShapeBuild_Edge::SetRange3d (const TopoDS_Edge& edge,
275 const Standard_Real first,
276 const Standard_Real last) const
279 for (BRep_ListIteratorOfListOfCurveRepresentation itcr
280 ((*((Handle(BRep_TEdge)*)&edge.TShape()))->ChangeCurves()); itcr.More(); itcr.Next()) {
281 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
282 if ( GC.IsNull() || !GC->IsCurve3D() ) continue;
283 GC->SetRange ( first, last );
288 //=======================================================================
289 //function : CopyPCurves
291 //=======================================================================
293 void ShapeBuild_Edge::CopyPCurves (const TopoDS_Edge& toedge, const TopoDS_Edge& fromedge) const
295 TopLoc_Location fromLoc = fromedge.Location();
296 TopLoc_Location toLoc = toedge.Location();
297 for (BRep_ListIteratorOfListOfCurveRepresentation fromitcr
298 ((*((Handle(BRep_TEdge)*)&fromedge.TShape()))->ChangeCurves()); fromitcr.More(); fromitcr.Next()) {
299 Handle(BRep_GCurve) fromGC = Handle(BRep_GCurve)::DownCast(fromitcr.Value());
300 if ( fromGC.IsNull() ) continue;
301 if ( fromGC->IsCurveOnSurface() ) {
302 Handle(Geom_Surface) surface = fromGC->Surface();
303 TopLoc_Location L = fromGC->Location();
304 Standard_Boolean found = Standard_False;
305 BRep_ListOfCurveRepresentation& tolist = (*((Handle(BRep_TEdge)*)&toedge.TShape()))->ChangeCurves();
306 Handle(BRep_GCurve) toGC;
307 for (BRep_ListIteratorOfListOfCurveRepresentation toitcr (tolist); toitcr.More() && !found; toitcr.Next()) {
308 toGC = Handle(BRep_GCurve)::DownCast(toitcr.Value());
309 if ( toGC.IsNull() || !toGC->IsCurveOnSurface() ||
310 surface != toGC->Surface() || L != toGC->Location() ) continue;
311 found = Standard_True;
315 toGC = Handle(BRep_GCurve)::DownCast(fromGC->Copy());
316 tolist.Append (toGC);
318 Handle(Geom2d_Curve) pcurve = fromGC->PCurve();
319 toGC->PCurve(Handle(Geom2d_Curve)::DownCast(pcurve->Copy()));
321 //bug OCC209 invalid location of pcurve in the edge after copying
322 TopLoc_Location newLoc = (fromLoc*L).Predivided(toLoc);//(L * fromLoc).Predivided(toLoc);
323 toGC->Location(newLoc);
324 if ( fromGC->IsCurveOnClosedSurface() ) {
325 pcurve = fromGC->PCurve2();
326 toGC->PCurve2(Handle(Geom2d_Curve)::DownCast(pcurve->Copy()));
331 //=======================================================================
334 //=======================================================================
336 TopoDS_Edge ShapeBuild_Edge::Copy (const TopoDS_Edge &edge,
337 const Standard_Boolean sharepcurves) const
339 TopoDS_Vertex dummy1, dummy2;
340 TopoDS_Edge newedge = CopyReplaceVertices ( edge, dummy1, dummy2 );
341 if ( ! sharepcurves ) CopyPCurves ( newedge, edge );
345 //=======================================================================
346 //function : RemovePCurve
348 //=======================================================================
350 void ShapeBuild_Edge::RemovePCurve (const TopoDS_Edge& edge,
351 const TopoDS_Face& face) const
354 Handle(Geom2d_Curve) c2dNull;
355 //:S4136 Standard_Real tol = BRep_Tool::Tolerance ( edge );
356 if ( BRep_Tool::IsClosed ( edge, face ) )
357 B.UpdateEdge ( edge, c2dNull, c2dNull, face, 0. ); //:S4136: tol
358 else B.UpdateEdge ( edge, c2dNull, face, 0. ); //:S4136: tol
361 //=======================================================================
362 //function : RemovePCurve
364 //=======================================================================
366 void ShapeBuild_Edge::RemovePCurve (const TopoDS_Edge& edge,
367 const Handle(Geom_Surface)& surf) const
369 RemovePCurve ( edge, surf, TopLoc_Location() );
372 //=======================================================================
373 //function : RemovePCurve
375 //=======================================================================
377 void ShapeBuild_Edge::RemovePCurve (const TopoDS_Edge& edge,
378 const Handle(Geom_Surface)& surf,
379 const TopLoc_Location &loc) const
382 Handle(Geom2d_Curve) c2dNull;
383 //:S4136 Standard_Real tol = BRep_Tool::Tolerance ( edge );
384 if ( BRep_Tool::IsClosed ( edge, surf, loc ) )
385 B.UpdateEdge ( edge, c2dNull, c2dNull, surf, loc, 0. ); //:S4136: tol
386 else B.UpdateEdge ( edge, c2dNull, surf, loc, 0. ); //:S4136: tol
389 //=======================================================================
390 //function : ReplacePCurve
392 //=======================================================================
394 void ShapeBuild_Edge::ReplacePCurve (const TopoDS_Edge& edge,
395 const Handle(Geom2d_Curve)& pcurve,
396 const TopoDS_Face& face) const
400 TopoDS_Shape dummy = edge.Reversed();
401 TopoDS_Edge edgerev = TopoDS::Edge(dummy);
402 // reverse face to take second pcurve for seams like SA_Edge::PCurve() does
403 TopoDS_Face F = TopoDS::Face(face.Oriented ( TopAbs_FORWARD ) );
404 Handle(Geom2d_Curve) pcurve0 = BRep_Tool::CurveOnSurface(edge,F,f,l);
405 Handle(Geom2d_Curve) c2d = BRep_Tool::CurveOnSurface(edgerev,F,f,l);
406 // Add pcurve to edge (either as single, or as seam)
407 if ( c2d.IsNull() || c2d == pcurve0 ) { // non-seam
408 B.UpdateEdge(edge,pcurve,face,0);
411 if(edge.Orientation()==TopAbs_FORWARD)
412 B.UpdateEdge(edge,pcurve,c2d,face,0);
414 B.UpdateEdge(edge,c2d,pcurve,face,0);
416 B.Range ( edge, face, f, l );
419 //=======================================================================
420 //function : ReassignPCurve
422 //=======================================================================
424 // Count exact number of pcurves STORED in edge for face
425 // This makes difference for faces based on plane surfaces where pcurves can be
426 // not stored but returned by BRep_Tools::CurveOnSurface
427 static Standard_Integer CountPCurves (const TopoDS_Edge &edge,
428 const TopoDS_Face &face)
431 Handle(Geom_Surface) S = BRep_Tool::Surface ( face, L );
432 TopLoc_Location l = L.Predivided(edge.Location());
434 for (BRep_ListIteratorOfListOfCurveRepresentation itcr
435 ((*((Handle(BRep_TEdge)*)&edge.TShape()))->ChangeCurves()); itcr.More(); itcr.Next()) {
436 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
437 if ( ! GC.IsNull() && GC->IsCurveOnSurface ( S, l ) )
438 return ( GC->IsCurveOnClosedSurface() ? 2 : 1 );
443 Standard_Boolean ShapeBuild_Edge::ReassignPCurve (const TopoDS_Edge& edge,
444 const TopoDS_Face& old,
445 const TopoDS_Face& sub) const
447 Standard_Integer npcurves = CountPCurves ( edge, old );
448 //if ( npcurves <1 ) return Standard_False; //gka
451 Handle(Geom2d_Curve) pc;
452 pc = BRep_Tool::CurveOnSurface ( edge, old, f, l );
453 if ( pc.IsNull() ) return Standard_False;
454 else if( npcurves == 0) npcurves =1; //gka
459 // if the pcurve was only one, remove; else leave second one
462 TopoDS_Shape tmpshape = edge.Reversed();
463 TopoDS_Edge erev = TopoDS::Edge (tmpshape);
464 Handle(Geom2d_Curve) pc2 = BRep_Tool::CurveOnSurface ( erev, old, f, l );
465 B.UpdateEdge ( edge, pc2, old, 0. );
466 B.Range ( edge, old, f, l );
468 else RemovePCurve ( edge, old );
470 // if edge does not have yet pcurves on sub, just add; else add as first
471 Standard_Integer npcs = CountPCurves ( edge, sub );
472 if ( npcs <1 ) B.UpdateEdge ( edge, pc, sub, 0. );
475 TopoDS_Shape tmpshape = edge.Reversed();
476 TopoDS_Edge erev = TopoDS::Edge (tmpshape);
477 Standard_Real cf, cl;
478 Handle(Geom2d_Curve) pcs = BRep_Tool::CurveOnSurface ( erev, sub, cf, cl );
479 if ( edge.Orientation() == TopAbs_REVERSED ) // because B.UpdateEdge does not check edge orientation
480 B.UpdateEdge ( edge, pcs, pc, sub, 0. );
481 else B.UpdateEdge ( edge, pc, pcs, sub, 0. );
484 B.Range ( edge, sub, f, l );
486 return Standard_True;
489 //=======================================================================
490 //function : TransformPCurve
492 //=======================================================================
494 Handle(Geom2d_Curve) ShapeBuild_Edge::TransformPCurve(const Handle(Geom2d_Curve)& pcurve,
495 const gp_Trsf2d& trans,
496 const Standard_Real uFact,
497 Standard_Real& aFirst,
498 Standard_Real& aLast) const
500 Handle(Geom2d_Curve) result = Handle(Geom2d_Curve)::DownCast(pcurve->Copy());
501 if(trans.Form()!=gp_Identity) {
502 result->Transform (trans);
503 aFirst = result->TransformedParameter(aFirst,trans);
504 aLast = result->TransformedParameter(aLast, trans);
509 if (result->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
510 Handle(Geom2d_TrimmedCurve) thecurve = Handle(Geom2d_TrimmedCurve)::DownCast(result);
511 result = thecurve->BasisCurve();
515 tMatu.SetAffinity(gp::OY2d(), uFact);
518 if (result->IsKind(STANDARD_TYPE(Geom2d_Line))) {
519 Handle(Geom2d_Line) aLine2d = Handle(Geom2d_Line)::DownCast(result);
521 aLine2d->D0(aFirst,Pf);
523 tMatu.Transforms(pXY);
525 aLine2d->D0(aLast, Pl);
527 tMatu.Transforms(pXY);
529 gp_Lin2d line2d(Pf, gp_Dir2d(gp_Vec2d(Pf,Pl)));
530 aFirst = ElCLib::Parameter(line2d, Pf);
531 aLast = ElCLib::Parameter(line2d, Pl);
532 Handle(Geom2d_Line) Gline2d = new Geom2d_Line(line2d);
535 else if(result->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))) {
536 Handle(Geom2d_BezierCurve) bezier = Handle(Geom2d_BezierCurve)::DownCast(result);
537 // transform the Poles of the BSplineCurve
538 Standard_Integer nbPol = bezier->NbPoles();
540 for (Standard_Integer i = 1; i<=nbPol ; i++) {
541 pXY = bezier->Pole(i).XY();
542 tMatu.Transforms(pXY);
544 bezier->SetPole(i, Pt1);
548 Handle(Geom2d_BSplineCurve) aBSpline2d;
549 if(result->IsKind(STANDARD_TYPE(Geom2d_Conic))) {
550 //gp_Pln pln(gp_Pnt(0,0,0),gp_Dir(0,0,1));
551 //Handle(Geom_Curve) curve = GeomAPI::To3d(result,pln);
552 Handle(Geom2d_Curve) tcurve = new Geom2d_TrimmedCurve(result,aFirst,aLast); //protection agains parabols ets
553 Geom2dConvert_ApproxCurve approx (tcurve, Precision::Approximation(),
554 GeomAbs_C1, 100, 6 );
555 if ( approx.HasResult() )
556 aBSpline2d = Handle(Geom2d_BSplineCurve)::DownCast(approx.Curve());
558 aBSpline2d = Geom2dConvert::CurveToBSplineCurve(tcurve,Convert_QuasiAngular);
559 aFirst = aBSpline2d->FirstParameter();
560 aLast = aBSpline2d->LastParameter();
562 else if(!result->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve))) {
563 aBSpline2d = Geom2dConvert::CurveToBSplineCurve(result,Convert_QuasiAngular);
566 aBSpline2d = Handle(Geom2d_BSplineCurve)::DownCast(result);
568 // transform the Poles of the BSplineCurve
569 Standard_Integer nbPol = aBSpline2d->NbPoles();
571 for (Standard_Integer i = 1; i<=nbPol ; i++) {
572 pXY = aBSpline2d->Pole(i).XY();
573 tMatu.Transforms(pXY);
575 aBSpline2d->SetPole(i, Pt1);
581 //=======================================================================
582 //function : RemoveCurve3d
584 //=======================================================================
586 void ShapeBuild_Edge::RemoveCurve3d (const TopoDS_Edge& edge) const
589 Handle(Geom_Curve) c3dNull;
590 //:S4136 Standard_Real tol = BRep_Tool::Tolerance (edge);
591 B.UpdateEdge (edge, c3dNull, 0. ); //:S4136: tol
594 //=======================================================================
595 //function : BuildCurve3d
597 //=======================================================================
599 Standard_Boolean ShapeBuild_Edge::BuildCurve3d (const TopoDS_Edge& edge) const
603 //#48 rln 10.12.98 S4054 UKI60107-5 entity 365
604 //C0 surface (but curve 3d is required as C1) and tolerance is 1e-07
605 //lets use maximum of tolerance and default parameter 1.e-5
606 //Another solutions: use quite big Tolerance or require C0 curve on C0 surface
607 if ( BRepLib::BuildCurve3d (edge, Max (1.e-5, BRep_Tool::Tolerance(edge) ) ) ) {
608 //#50 S4054 rln 14.12.98 write cylinder in BRep mode into IGES and read back
609 //with 2DUse_Forced - pcurve and removed 3D curves have different ranges
610 if (BRep_Tool::SameRange (edge)) {
611 Standard_Real first, last;
612 BRep_Tool::Range (edge, first, last);
613 BRep_Builder().Range (edge, first, last);//explicit setting for all reps
615 Handle(Geom_Curve) c3d;
617 c3d = BRep_Tool::Curve(edge,f,l);
619 return Standard_False;
620 // 15.11.2002 PTV OCC966
621 if(!IsPeriodic(c3d)) {
622 Standard_Boolean isLess = Standard_False;
623 if(f < c3d->FirstParameter()) {
624 isLess = Standard_True;
625 f = c3d->FirstParameter();
627 if(l > c3d->LastParameter()) {
628 isLess = Standard_True;
629 l = c3d->LastParameter();
632 SetRange3d(edge,f,l);
633 BRep_Builder().SameRange(edge,Standard_False);
637 return Standard_True;
640 catch(Standard_Failure) {
642 cout << "\nWarning: ShapeBuild_Edge: Exception in BuildCurve3d: ";
643 Standard_Failure::Caught()->Print(cout); cout << endl;
646 return Standard_False;
650 //=======================================================================
651 //function : MakeEdge
653 //=======================================================================
655 void ShapeBuild_Edge::MakeEdge(TopoDS_Edge& edge,const Handle(Geom_Curve)& curve,const TopLoc_Location& L) const
657 MakeEdge (edge,curve, L, curve->FirstParameter(), curve->LastParameter());
660 //=======================================================================
661 //function : MakeEdge
663 //=======================================================================
665 void ShapeBuild_Edge::MakeEdge(TopoDS_Edge& edge,const Handle(Geom_Curve)& curve,const TopLoc_Location& L,const Standard_Real p1,const Standard_Real p2) const
667 BRepBuilderAPI_MakeEdge ME (curve, p1, p2);
670 cout << "\nWarning: ShapeBuild_Edge::MakeEdge BRepAPI_NotDone";
674 TopoDS_Edge E = ME.Edge();
675 if (!L.IsIdentity()) {
677 B.UpdateEdge (E, curve, L, 0.);
680 TopoDS_Vertex V1, V2;
681 TopExp::Vertices (E, V1, V2);
682 gp_Pnt P1 = BRep_Tool::Pnt (V1), P2 = BRep_Tool::Pnt (V2);
683 B.UpdateVertex (V1, P1.Transformed (L.Transformation()), 0.);
684 B.UpdateVertex (V2, P2.Transformed (L.Transformation()), 0.);
690 //=======================================================================
691 //function : MakeEdge
693 //=======================================================================
695 void ShapeBuild_Edge::MakeEdge(TopoDS_Edge& edge,const Handle(Geom2d_Curve)& pcurve,const TopoDS_Face& face) const
697 MakeEdge (edge, pcurve, face, pcurve->FirstParameter(), pcurve->LastParameter());
700 //=======================================================================
701 //function : MakeEdge
703 //=======================================================================
705 void ShapeBuild_Edge::MakeEdge(TopoDS_Edge& edge,const Handle(Geom2d_Curve)& pcurve,const TopoDS_Face& face,const Standard_Real p1,const Standard_Real p2) const
708 const Handle(Geom_Surface)& S = BRep_Tool::Surface(face, L);
709 MakeEdge (edge, pcurve, S, L, p1, p2);
712 //=======================================================================
713 //function : MakeEdge
715 //=======================================================================
717 void ShapeBuild_Edge::MakeEdge(TopoDS_Edge& edge,const Handle(Geom2d_Curve)& pcurve,
718 const Handle(Geom_Surface)& S,const TopLoc_Location& L) const
720 MakeEdge(edge, pcurve, S, L, pcurve->FirstParameter(), pcurve->LastParameter());
723 //=======================================================================
724 //function : MakeEdge
726 //=======================================================================
728 void ShapeBuild_Edge::MakeEdge(TopoDS_Edge& edge,const Handle(Geom2d_Curve)& pcurve,
729 const Handle(Geom_Surface)& S,const TopLoc_Location& L,
730 const Standard_Real p1,const Standard_Real p2) const
732 BRepBuilderAPI_MakeEdge ME (pcurve, S, p1, p2);
735 cout << "\nWarning: ShapeBuild_Edge::MakeEdge BRepAPI_NotDone";
739 TopoDS_Edge E = ME.Edge();
740 if (!L.IsIdentity()) {
743 B.UpdateEdge (E, pcurve, S, L, 0.);
744 B.Range (E, S, L, p1, p2);
746 TopoDS_Vertex V1, V2;
747 TopExp::Vertices (E, V1, V2);
748 gp_Pnt P1 = BRep_Tool::Pnt (V1), P2 = BRep_Tool::Pnt (V2);
749 B.UpdateVertex (V1, P1.Transformed (L.Transformation()), 0.);
750 B.UpdateVertex (V2, P2.Transformed (L.Transformation()), 0.);