1 // Created on: 1994-12-02
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Adaptor3d_CurveOnSurface.hxx>
18 #include <Adaptor3d_HCurveOnSurface.hxx>
19 #include <Adaptor3d_SurfaceOfLinearExtrusion.hxx>
20 #include <Approx_CurveOnSurface.hxx>
21 #include <BRep_Builder.hxx>
22 #include <BRep_Tool.hxx>
23 #include <BRepExtrema_ExtCF.hxx>
24 #include <BRepExtrema_ExtPC.hxx>
25 #include <BRepLib_MakeFace.hxx>
26 #include <BRepTools.hxx>
27 #include <Draft_EdgeInfo.hxx>
28 #include <Draft_FaceInfo.hxx>
29 #include <Draft_Modification.hxx>
30 #include <Draft_VertexInfo.hxx>
33 #include <Extrema_ExtPC.hxx>
34 #include <Geom2d_BezierCurve.hxx>
35 #include <Geom2d_BSplineCurve.hxx>
36 #include <Geom2d_Curve.hxx>
37 #include <Geom2d_Line.hxx>
38 #include <Geom2d_TrimmedCurve.hxx>
39 #include <Geom2dAdaptor_HCurve.hxx>
40 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
41 #include <Geom2dConvert.hxx>
42 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
43 #include <Geom_BSplineCurve.hxx>
44 #include <Geom_Circle.hxx>
45 #include <Geom_Conic.hxx>
46 #include <Geom_ConicalSurface.hxx>
47 #include <Geom_Curve.hxx>
48 #include <Geom_CylindricalSurface.hxx>
49 #include <Geom_ElementarySurface.hxx>
50 #include <Geom_Ellipse.hxx>
51 #include <Geom_Hyperbola.hxx>
52 #include <Geom_Line.hxx>
53 #include <Geom_Parabola.hxx>
54 #include <Geom_Plane.hxx>
55 #include <Geom_RectangularTrimmedSurface.hxx>
56 #include <Geom_Surface.hxx>
57 #include <Geom_SurfaceOfLinearExtrusion.hxx>
58 #include <Geom_TrimmedCurve.hxx>
59 #include <GeomAdaptor_Curve.hxx>
60 #include <GeomAdaptor_HCurve.hxx>
61 #include <GeomAdaptor_HSurface.hxx>
62 #include <GeomAdaptor_Surface.hxx>
63 #include <GeomAPI_ProjectPointOnCurve.hxx>
64 #include <GeomAPI_ProjectPointOnSurf.hxx>
65 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
66 #include <GeomInt_IntSS.hxx>
67 #include <GeomProjLib.hxx>
69 #include <gp_Circ.hxx>
71 #include <gp_Elips.hxx>
72 #include <gp_Hypr.hxx>
74 #include <gp_Parab.hxx>
78 #include <IntAna_IntConicQuad.hxx>
79 #include <IntAna_QuadQuadGeo.hxx>
80 #include <IntCurveSurface_HInter.hxx>
81 #include <IntCurveSurface_IntersectionPoint.hxx>
82 #include <Precision.hxx>
83 #include <ProjLib_CompProjectedCurve.hxx>
84 #include <ProjLib_HCompProjectedCurve.hxx>
85 #include <Standard_ConstructionError.hxx>
86 #include <Standard_DomainError.hxx>
87 #include <Standard_Failure.hxx>
88 #include <Standard_NoSuchObject.hxx>
89 #include <Standard_NotImplemented.hxx>
90 #include <StdFail_NotDone.hxx>
91 #include <TColgp_Array1OfPnt2d.hxx>
93 #include <TopExp_Explorer.hxx>
94 #include <TopLoc_Location.hxx>
96 #include <TopoDS_Edge.hxx>
97 #include <TopoDS_Face.hxx>
98 #include <TopoDS_Shape.hxx>
99 #include <TopoDS_Vertex.hxx>
100 #include <TopTools_ListIteratorOfListOfShape.hxx>
101 #include <TopTools_MapIteratorOfMapOfShape.hxx>
102 #include <TopTools_MapOfShape.hxx>
104 static Standard_Boolean Choose(const Draft_IndexedDataMapOfFaceFaceInfo&,
105 Draft_IndexedDataMapOfEdgeEdgeInfo&,
106 const TopoDS_Vertex&,
109 GeomAdaptor_Surface&);
111 static Standard_Real Parameter(const Handle(Geom_Curve)&,
115 static Standard_Real SmartParameter(Draft_EdgeInfo&,
116 const Standard_Real EdgeTol,
118 const Standard_Integer,
119 const Handle(Geom_Surface)&,
120 const Handle(Geom_Surface)&);
122 static TopAbs_Orientation Orientation(const TopoDS_Shape&,
125 static Standard_Boolean FindRotation(const gp_Pln&,
126 const TopAbs_Orientation,
134 //=======================================================================
135 //function : InternalAdd
137 //=======================================================================
139 Standard_Boolean Draft_Modification::InternalAdd(const TopoDS_Face& F,
140 const gp_Dir& Direction,
141 const Standard_Real Angle,
142 const gp_Pln& NeutralPlane,
143 const Standard_Boolean Flag)
146 if (myFMap.Contains(F)) {
147 return (badShape.IsNull());
150 TopAbs_Orientation oris = Orientation(myShape,F);
152 //gp_Dir NewDirection = Direction;
153 //Standard_Real NewAngle = Angle;
154 Handle(Geom_Surface) S = BRep_Tool::Surface(F,Lo);
155 S = Handle(Geom_Surface)::DownCast(S->Transformed(Lo.Transformation()));
156 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
157 S = Handle(Geom_RectangularTrimmedSurface)::DownCast(S)->BasisSurface();
159 Handle(Geom_Surface) NewS;
160 Handle(Geom_Circle) theCircle;
162 Standard_Boolean postponed = (Flag == Standard_False);
164 Handle(Standard_Type) typS = S->DynamicType();
165 if (typS == STANDARD_TYPE(Geom_CylindricalSurface) ||
166 typS == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) {
168 if (typS == STANDARD_TYPE(Geom_CylindricalSurface)) {
170 Handle(Geom_CylindricalSurface)::DownCast(S)->Cylinder();
171 gp_Ax1 axcyl = cyl.Axis();
172 Cir = ElSLib::CylinderVIso( cyl.Position(), cyl.Radius(), 0.);
173 gp_Vec VV(cyl.Location(),NeutralPlane.Location());
174 Cir.Translate(VV.Dot(axcyl.Direction())*axcyl.Direction());
177 Handle(Geom_Curve) Cbas =
178 Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(S)->BasisCurve();
180 Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(S)->Direction();
182 if (Cbas->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
183 Cbas = Handle(Geom_TrimmedCurve)::DownCast(Cbas)->BasisCurve();
185 if (Cbas->IsKind(STANDARD_TYPE(Geom_Circle))) {
186 Cir = Handle(Geom_Circle)::DownCast(Cbas)->Circ();
187 gp_Dir dircir = Cir.Axis().Direction();
188 if (!Direction.IsParallel(dircir,Precision::Angular())) {
190 errStat = Draft_FaceRecomputation;
191 return Standard_False;
196 errStat = Draft_FaceRecomputation;
197 return Standard_False;
200 gp_Ax3 Axis = NeutralPlane.Position();
202 gp_Vec(Cir.Location(),Axis.Location()).
203 Dot(Axis.Direction());
204 Standard_Real Cos = theDirextr.Dot(Axis.Direction());
205 gp_Vec VV = ( L / Cos) * theDirextr;
209 theCircle = new Geom_Circle(Cir);
213 postponed = Standard_False;
219 NewS = NewSurface(S,oris,Direction,Angle,NeutralPlane);
222 errStat = Draft_FaceRecomputation;
223 return Standard_False;
225 // To avoid some problems with infinite restrictions
226 const Handle(Standard_Type)& typs = NewS->DynamicType();
227 if (typs == STANDARD_TYPE(Geom_CylindricalSurface) ||
228 typs == STANDARD_TYPE(Geom_ConicalSurface)) {
229 Standard_Real umin,umax,vmin,vmax;
230 BRepTools::UVBounds(F,umin,umax,vmin,vmax);
231 if (!Precision::IsNegativeInfinite(vmin) &&
232 !Precision::IsPositiveInfinite(vmax)) {
233 Standard_Real deltav = 10.*(vmax-vmin);
234 if(typs == STANDARD_TYPE(Geom_CylindricalSurface)) {
235 vmin = vmin - deltav;
236 vmax = vmax + deltav;
239 gp_Cone Co = Handle(Geom_ConicalSurface)::DownCast(NewS)->Cone();
240 Standard_Real Vapex = - Co.RefRadius()/Sin(Co.SemiAngle());
241 if (vmin < Vapex) { // vmax should not exceed Vapex
242 if (vmax + deltav > Vapex) {
244 vmin = vmin - 10.*(vmax - vmin);
245 // JAG debug to avoid apex
246 vmax = vmax-Precision::Confusion();
249 vmin = vmin - deltav;
250 vmax = vmax + deltav;
253 else { // Vapex <= vmin < vmax
254 if (vmin - deltav < Vapex) {
256 vmax = vmax + 10.*(vmax - vmin);
257 // JAG debug to avoid apex
258 vmin = vmin+Precision::Confusion();
261 vmin = vmin - deltav;
262 vmax = vmax + deltav;
266 NewS = new Geom_RectangularTrimmedSurface(NewS,0.,2.*M_PI,vmin,vmax);
271 if (postponed || S != NewS) {
272 Draft_FaceInfo FI(NewS,Standard_True);
273 FI.RootFace(curFace);
276 myFMap.ChangeFromKey(F).ChangeCurve() = theCircle;
280 TopExp_Explorer expl(F,TopAbs_EDGE);
281 TopTools_MapOfShape MapOfE;
282 while (expl.More() && badShape.IsNull()) {
283 const TopoDS_Edge& edg = TopoDS::Edge(expl.Current());
284 if (!myEMap.Contains(edg)) {
285 Standard_Boolean addedg = Standard_False;
286 Standard_Boolean addface = Standard_False;
288 //if (BRep_Tool::IsClosed(edg,F)) {
289 if (BRepTools::IsReallyClosed(edg,F)) {
290 addedg = Standard_True;
291 addface = Standard_False;
294 // Find the other face containing the edge.
295 TopTools_ListIteratorOfListOfShape it;
296 it.Initialize(myEFMap.FindFromKey(edg));
297 Standard_Integer nbother = 0;
299 if (!it.Value().IsSame(F)) {
300 if (OtherF.IsNull()) {
301 OtherF = TopoDS::Face(it.Value());
309 errStat = Draft_EdgeRecomputation;
311 else if (! OtherF.IsNull() &&
312 BRep_Tool::Continuity(edg,F,OtherF) >= GeomAbs_G1) {
313 addface= Standard_True;
314 addedg = Standard_True;
316 else if (nbother == 0) {
322 myFMap.ChangeFromKey(F).Add(OtherF);
326 Handle(Geom_Curve) C = BRep_Tool::Curve(edg,L,f,l);
327 C = Handle(Geom_Curve)::DownCast(C->Transformed(L));
328 if (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
329 C = Handle(Geom_TrimmedCurve)::DownCast(C)->BasisCurve();
331 Handle(Geom_Curve) NewC;
332 Draft_EdgeInfo EInf(Standard_True);
338 Handle(Geom_Line) aLocalGeom = Handle(Geom_Line)::DownCast(C);
339 if (aLocalGeom.IsNull()) {
341 errStat = Draft_EdgeRecomputation;
344 gp_Lin lin = aLocalGeom->Lin();
345 IntAna_IntConicQuad ilipl(lin,NeutralPlane,Precision::Angular());
346 if (ilipl.IsDone() && ilipl.NbPoints() != 0){
347 EInf.Tangent(ilipl.Point(1));
351 errStat = Draft_EdgeRecomputation;
356 NewC = NewCurve(C,S,oris,Direction,Angle,NeutralPlane, Flag);
359 errStat = Draft_EdgeRecomputation;
363 Handle(Geom_TrimmedCurve) T = Handle(Geom_TrimmedCurve)::DownCast(NewC);
364 if (!T.IsNull()) NewC = T->BasisCurve();
365 EInf.ChangeGeometry() = NewC;
367 EInf.RootFace(curFace);
368 myEMap.Add(edg,EInf);
371 Standard_Boolean Fl = Flag;
372 Handle(Geom_Surface) alocalSurface = BRep_Tool::Surface(OtherF,Lo);
373 if (alocalSurface->DynamicType() ==
374 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
375 alocalSurface = Handle(Geom_RectangularTrimmedSurface)::
376 DownCast(alocalSurface)->BasisSurface();
378 Handle(Standard_Type) typS = alocalSurface->DynamicType();
379 if (typS == STANDARD_TYPE(Geom_CylindricalSurface) ||
380 typS == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) {
381 if ( myFMap.Contains(F)) {
382 if ( Flag == Standard_False && !postponed) {
383 Standard_Integer IndToReplace = myFMap.FindIndex(F);
385 Standard_Integer LInd = myFMap.Extent();
386 TopoDS_Face LF = myFMap.FindKey(LInd);
387 Draft_FaceInfo LFInfo = myFMap.FindFromIndex(LInd);
390 if (IndToReplace != LInd)
391 myFMap.Substitute(IndToReplace, LF, LFInfo);
393 TopTools_MapIteratorOfMapOfShape itm(MapOfE);
394 for ( ; itm.More(); itm.Next())
396 IndToReplace = myEMap.FindIndex(TopoDS::Edge(itm.Key()));
399 Standard_Integer LInd = myEMap.Extent();
400 TopoDS_Edge LE = myEMap.FindKey(LInd);
401 Draft_EdgeInfo LEInfo = myEMap.FindFromIndex(LInd);
404 if (IndToReplace != LInd)
405 myEMap.Substitute(IndToReplace, LE, LEInfo);
411 InternalAdd(OtherF,Direction,Angle,NeutralPlane, Fl);
417 return (badShape.IsNull());
421 //=======================================================================
422 //function : Propagate
424 //=======================================================================
426 Standard_Boolean Draft_Modification::Propagate ()
429 if (!badShape.IsNull()) return Standard_False;
431 // Set all edges and vertices of modified faces
435 TopExp_Explorer editer;
436 TopExp_Explorer vtiter;
438 for (Standard_Integer i = 1; i <= myFMap.Extent(); i++)
440 const TopoDS_Face& Fc = myFMap.FindKey(i);
442 // Exploration of the edges of the face
443 editer.Init(Fc,TopAbs_EDGE);
444 while (editer.More()) {
445 E = TopoDS::Edge(editer.Current());
447 if (!myEMap.Contains(E)) {
448 Draft_EdgeInfo EInf(Standard_True);
451 myEMap.ChangeFromKey(E).Add(Fc);
453 // Exploration of the vertices of the edge
454 vtiter.Init(E,TopAbs_VERTEX);
455 while (vtiter.More()) {
456 V = TopoDS::Vertex(vtiter.Current());
457 if (!myVMap.Contains(V)) {
458 Draft_VertexInfo VInf;
462 myVMap.ChangeFromKey(V).Add(E);
463 myVMap.ChangeFromKey(V).ChangeParameter(E) = BRep_Tool::Parameter(V, E);
472 Standard_Boolean found;
474 // Set edges containing modified vertices.
476 for (Standard_Integer i = 1; i <= myVMap.Extent(); i++)
478 const TopoDS_Vertex& Vt = myVMap.FindKey(i);
480 // Exploration of the ancestors of the vertex
481 anc.Init(myShape,TopAbs_EDGE);
484 E = TopoDS::Edge(anc.Current());
485 vtiter.Init(E,TopAbs_VERTEX);
486 found = Standard_False;
487 while (vtiter.More()) {
488 if (Vt.IsSame(TopoDS::Vertex(vtiter.Current()))) {
489 found = Standard_True;
495 if (!myEMap.Contains(E)) {
496 Draft_EdgeInfo EInf(Standard_False);
499 myVMap.ChangeFromKey(Vt).Add(E);
500 myVMap.ChangeFromKey(Vt).ChangeParameter(E) = BRep_Tool::Parameter(Vt, E);
507 // Set faces containing modified edges
508 for (Standard_Integer i = 1; i <= myEMap.Extent(); i++)
510 const TopoDS_Edge& Ed = myEMap.FindKey(i);
511 TopTools_ListIteratorOfListOfShape it;
512 for (it.Initialize(myEFMap.FindFromKey(Ed)); it.More(); it.Next()) {
513 F = TopoDS::Face(it.Value());
514 if (!myFMap.Contains(F)) {
516 Handle(Geom_Surface) S = BRep_Tool::Surface(F,L);
517 Handle(Geom_Surface) NewS =
518 Handle(Geom_Surface)::DownCast(S->Transformed(L.Transformation()));
520 const Handle(Standard_Type)& typs = S->DynamicType();
521 if (typs == STANDARD_TYPE(Geom_CylindricalSurface) ||
522 typs == STANDARD_TYPE(Geom_ConicalSurface)) {
523 Standard_Real umin,umax,vmin,vmax;
524 BRepTools::UVBounds(F,umin,umax,vmin,vmax);
525 if (!Precision::IsNegativeInfinite(vmin) &&
526 !Precision::IsPositiveInfinite(vmax)) {
527 Standard_Real deltav = 10.*(vmax-vmin);
528 vmin = vmin - deltav;
529 vmax = vmax + deltav;
530 NewS = new Geom_RectangularTrimmedSurface(NewS,0.,2.*M_PI,vmin,vmax);
534 Draft_FaceInfo FInf(NewS,Standard_False);
537 myEMap.ChangeFromKey(Ed).Add(F);
541 // Try to add faces for free borders...
543 for (Standard_Integer i = 1; i <= myEMap.Extent(); i++)
545 Draft_EdgeInfo& Einf = myEMap.ChangeFromIndex(i);
546 if (Einf.NewGeometry() &&
547 Einf.Geometry().IsNull() &&
548 Einf.SecondFace().IsNull()) {
551 Handle(Geom_Surface) S1 = BRep_Tool::Surface(Einf.FirstFace(),Loc);
552 S1 = Handle(Geom_Surface)::
553 DownCast(S1->Transformed(Loc.Transformation()));
554 Handle(Geom_Surface) S2;
557 const TopoDS_Edge& EK = myEMap.FindKey(i);
558 Handle(Geom_Curve) C = BRep_Tool::Curve(EK,Loc,f,l);
559 C = Handle(Geom_Curve)::DownCast(C->Transformed(Loc.Transformation()));
560 if (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
561 C = Handle(Geom_TrimmedCurve)::DownCast(C)->BasisCurve();
563 if (!S1->IsKind(STANDARD_TYPE(Geom_Plane))) {
564 if (C->IsKind(STANDARD_TYPE(Geom_Conic))) {
565 gp_Ax3 thePl(Handle(Geom_Conic)::DownCast(C)->Position());
566 S2 = new Geom_Plane(thePl);
568 else if (C->DynamicType() == STANDARD_TYPE(Geom_Line)) {
570 if (S1->DynamicType()== STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
571 axis = Handle(Geom_ElementarySurface)::DownCast
572 (Handle(Geom_RectangularTrimmedSurface)::DownCast(S1)->
573 BasisSurface())->Axis();
576 axis = Handle(Geom_ElementarySurface)::DownCast(S1)->Axis();
578 gp_Vec they(axis.Location(), C->Value(0.));
579 gp_Dir axz(axis.Direction().Crossed(they));
580 S2=new Geom_Plane(gp_Ax3(axis.Location(),axz,axis.Direction()));
585 errStat = Draft_EdgeRecomputation;
586 break; // leave from for
589 else { // on the plane
590 for (Standard_Integer j = 1; j <= myVMap.Extent(); j++)
592 Draft_VertexInfo& Vinf = myVMap.ChangeFromIndex(j);
593 for (Vinf.InitEdgeIterator();Vinf.MoreEdge();Vinf.NextEdge()) {
594 if (Vinf.Edge().IsSame(EK)) {
598 if (Vinf.MoreEdge()) {
599 for (Vinf.InitEdgeIterator();Vinf.MoreEdge();Vinf.NextEdge()) {
600 const TopoDS_Edge& edg = Vinf.Edge();
601 if (!edg.IsSame(EK)) {
602 const Draft_EdgeInfo& EI = myEMap.FindFromKey(edg);
603 if (!EI.FirstFace().IsSame(Einf.FirstFace()) &&
604 (EI.SecondFace().IsNull() ||
605 !EI.SecondFace().IsSame(Einf.FirstFace()))) {
610 if (Vinf.MoreEdge()) {
611 Handle(Geom_Curve) C2 = BRep_Tool::Curve(Vinf.Edge(), Loc,f,l);
612 Handle(GeomAdaptor_HCurve) HCur;
614 C2 = Handle(Geom_Curve)::DownCast
615 (C2->Transformed(Loc.Transformation()));
616 if (C2->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
617 C2 = Handle(Geom_TrimmedCurve)::DownCast(C2)->BasisCurve();
619 if (C->DynamicType() == STANDARD_TYPE(Geom_Line)) {
620 Direc = Handle(Geom_Line)::DownCast(C)->Lin().Direction();
621 HCur = new GeomAdaptor_HCurve(C2);
624 else if (C2->DynamicType() == STANDARD_TYPE(Geom_Line)) {
625 Direc = Handle(Geom_Line)::DownCast(C2)->Lin().Direction();
626 HCur = new GeomAdaptor_HCurve(C);
630 errStat = Draft_EdgeRecomputation;
631 break; // leave from while
633 Adaptor3d_SurfaceOfLinearExtrusion SLE(HCur,Direc);
634 switch(SLE.GetType()){
638 S2 = new Geom_Plane(SLE.Plane());
641 case GeomAbs_Cylinder :
643 S2 = new Geom_CylindricalSurface(SLE.Cylinder());
648 S2 = new Geom_SurfaceOfLinearExtrusion(HCur->ChangeCurve().
658 errStat = Draft_EdgeRecomputation;
659 break; // leave from while
667 if (badShape.IsNull()) {
669 TopoDS_Face TheNewFace;
670 B.MakeFace(TheNewFace,S2,Precision::Confusion());
671 Einf.Add(TheNewFace);
672 Draft_FaceInfo FI(S2,Standard_False);
673 myFMap.Add(TheNewFace,FI);
676 break; // leave from for
681 return (badShape.IsNull());
687 //=======================================================================
690 //=======================================================================
692 void Draft_Modification::Perform ()
694 if (!badShape.IsNull()) Standard_ConstructionError::Raise();
697 myComp = Standard_True;
702 // Calculate eventual faces
704 for (Standard_Integer i = 1; i <= myFMap.Extent(); i++)
706 const TopoDS_Face& FK = myFMap.FindKey(i);
707 Draft_FaceInfo& Finf = myFMap.ChangeFromIndex(i);
708 if (Finf.NewGeometry() && Finf.Geometry().IsNull()) {
709 const TopoDS_Face& F1 = Finf.FirstFace();
710 const TopoDS_Face& F2 = Finf.SecondFace();
712 if (F1.IsNull() || F2.IsNull()) {
713 errStat = Draft_FaceRecomputation;
717 Handle(Geom_Surface) S1 = myFMap.FindFromKey(F1).Geometry();
718 Handle(Geom_Surface) S2 = myFMap.FindFromKey(F2).Geometry();
719 if (S1.IsNull() || S2.IsNull()) {
720 errStat = Draft_FaceRecomputation;
724 if (S1->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
725 S1 = Handle(Geom_RectangularTrimmedSurface)::
726 DownCast(S1)->BasisSurface();
728 if (S2->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
729 S2 = Handle(Geom_RectangularTrimmedSurface)::
730 DownCast(S2)->BasisSurface();
732 Handle(Geom_Plane) P1 = Handle(Geom_Plane)::DownCast(S1);
733 Handle(Geom_Plane) P2 = Handle(Geom_Plane)::DownCast(S2);
734 if (P1.IsNull() || P2.IsNull()) {
735 errStat = Draft_FaceRecomputation;
739 gp_Pln pp1 = P1->Pln();
740 gp_Pln pp2 = P2->Pln();
741 IntAna_QuadQuadGeo i2p(pp1,pp2,
742 Precision::Angular(),Precision::Confusion());
743 if (!i2p.IsDone() || i2p.TypeInter() != IntAna_Line) {
744 errStat = Draft_FaceRecomputation;
749 gp_Dir extrdir = i2p.Line(1).Direction();
751 // Preserve the same direction as the base face
752 Handle(Geom_Surface) RefSurf =
753 BRep_Tool::Surface(FK);
754 if (RefSurf->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
756 Handle(Geom_RectangularTrimmedSurface)::DownCast(RefSurf)
761 if ( RefSurf->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
763 Handle(Geom_CylindricalSurface)::DownCast(RefSurf)
764 ->Cylinder().Position();
765 DirRef = AxeRef.Direction();
767 else if (RefSurf->DynamicType() ==
768 STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) {
770 Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(RefSurf)->Direction();
773 if (extrdir.Dot(DirRef) < 0.) extrdir.Reverse();
775 // it is possible to accelerate speed by storing the info during
776 // InternalAdd --> modification of FaceInfo to preserve the circle
778 Handle(Geom_Circle) CCir =
779 Handle(Geom_Circle)::DownCast(Finf.Curve());
780 Handle(Geom_Surface) NewS =
781 new Geom_SurfaceOfLinearExtrusion(CCir, extrdir);
783 Standard_Real umin, umax, vmin, vmax;
784 BRepTools::UVBounds(FK,umin,umax,vmin,vmax);
785 if (!Precision::IsNegativeInfinite(vmin) &&
786 !Precision::IsPositiveInfinite(vmax)) {
787 Standard_Real deltav = 2.*(vmax-vmin);
788 vmin = vmin - deltav;
789 vmax = vmax + deltav;
798 NewS = new Geom_RectangularTrimmedSurface(NewS,0.,1.9*M_PI,vmin,vmax);
799 Finf.ChangeGeometry() = NewS;
803 // Calculate new edges.
805 Handle(Geom_Surface) S1,S2;
806 Handle(Geom_Curve) C, newC;
810 for (Standard_Integer ii = 1; ii <= myEMap.Extent(); ii++)
812 Draft_EdgeInfo& Einf = myEMap.ChangeFromIndex(ii);
814 const TopoDS_Edge& theEdge = TopoDS::Edge(myEMap.FindKey(ii));
816 C = BRep_Tool::Curve(theEdge,L,f,l);
817 C = Handle(Geom_Curve)::DownCast(C->Transformed(L.Transformation()));
819 if (Einf.NewGeometry() && Einf.Geometry().IsNull()) {
821 if (!Einf.IsTangent(ptfixe)) {
822 const TopoDS_Face& FirstFace = Einf.FirstFace();
823 const TopoDS_Face& SecondFace = Einf.SecondFace();
825 S1 = myFMap.FindFromKey(FirstFace).Geometry();
826 S2 = myFMap.FindFromKey(SecondFace).Geometry();
828 Standard_Integer detrompeur = 0;
830 // Return FirstVertex and the tangent at this point.
831 TopoDS_Vertex FV = TopExp::FirstVertex(theEdge);
832 TopoDS_Vertex LV = TopExp::LastVertex(theEdge);
833 Standard_Real pmin = 0.;
834 Standard_Real prmfv = BRep_Tool::Parameter(FV, theEdge);
835 Standard_Real prmlv = BRep_Tool::Parameter(LV, theEdge);
837 gp_Vec d1fv,d1lv, newd1;
838 C->D1(prmfv,pfv,d1fv);
839 C->D1(prmlv,plv,d1lv);
841 Standard_Real TolF1 = BRep_Tool::Tolerance (FirstFace);
842 Standard_Real TolF2 = BRep_Tool::Tolerance (SecondFace);
844 //Pass the tolerance of the face to project
845 GeomAPI_ProjectPointOnSurf proj1 (pfv, S1, TolF1);
846 GeomAPI_ProjectPointOnSurf proj2 (plv, S1, TolF1);
847 GeomAPI_ProjectPointOnSurf proj3 (pfv, S2, TolF2);
848 GeomAPI_ProjectPointOnSurf proj4 (plv, S2, TolF2);
850 if (proj1.IsDone () && proj2.IsDone ()) {
851 if(proj1.LowerDistance()<= Precision::Confusion() &&
852 proj2.LowerDistance()<= Precision::Confusion()) {
857 if (proj3.IsDone () && proj4.IsDone ()) {
858 if(proj3.LowerDistance() <= Precision::Confusion() &&
859 proj4.LowerDistance() <= Precision::Confusion()) {
866 Handle(Geom_Curve) TheNewCurve;
867 Standard_Boolean KPart = Standard_False;
869 if ( S1->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
870 S1 = Handle(Geom_RectangularTrimmedSurface)::
871 DownCast(S1)->BasisSurface();
873 if ( S2->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
874 S2 = Handle(Geom_RectangularTrimmedSurface)::
875 DownCast(S2)->BasisSurface();
878 Standard_Boolean PC1 = Standard_True; // KPart on S1
879 if (S1->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion) &&
880 S2->DynamicType() == STANDARD_TYPE(Geom_Plane) ) {
881 KPart = Standard_True;
882 Axis = Handle(Geom_Plane)::DownCast(S2)->Position();
883 TheNewCurve = Handle(Geom_SurfaceOfLinearExtrusion)::
884 DownCast(S1)->BasisCurve();
885 TheDirExtr = Handle(Geom_SurfaceOfLinearExtrusion)::
886 DownCast(S1)->Direction();
888 else if (S2->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion) &&
889 S1->DynamicType() == STANDARD_TYPE(Geom_Plane) ) {
890 KPart = Standard_True;
891 PC1 = Standard_False;
892 Axis = Handle(Geom_Plane)::DownCast(S1)->Position();
893 TheNewCurve = Handle(Geom_SurfaceOfLinearExtrusion)::
894 DownCast(S2)->BasisCurve();
895 TheDirExtr = Handle(Geom_SurfaceOfLinearExtrusion)::
896 DownCast(S2)->Direction();
898 Handle(Geom_Circle) aCirc ;
899 if ( KPart) { // very temporary on circles !!!
900 aCirc = Handle(Geom_Circle)::DownCast(TheNewCurve);
902 KPart = Standard_False;
905 gp_Dir AxofCirc = aCirc->Position().Direction();
906 if (AxofCirc.IsParallel(Axis.Direction(),Precision::Angular()))
907 KPart = Standard_True;
909 KPart = Standard_False;
913 Standard_Integer imin;
916 // direct calculation of NewC
917 Standard_Real aLocalReal =
918 gp_Vec(aCirc->Circ().Location(),Axis.Location()).
919 Dot(Axis.Direction());
920 Standard_Real Cos = TheDirExtr.Dot(Axis.Direction());
921 gp_Vec VV = ( aLocalReal / Cos) * TheDirExtr;
922 newC = Handle(Geom_Curve)::DownCast(TheNewCurve->Translated(VV));
923 // it is possible to calculate PCurve
924 Handle(Geom2d_Line) L2d
925 = new Geom2d_Line(gp_Pnt2d(0.,aLocalReal/Cos),
929 Einf.ChangeFirstPC() = L2d;
931 Einf.ChangeSecondPC() = L2d;
934 S1 = myFMap.FindFromKey(Einf.FirstFace()).Geometry();
935 S2 = myFMap.FindFromKey(Einf.SecondFace()).Geometry();
938 // PCurves are not calculated immediately for 2 reasons:
939 // 1 - If ProjLib should make an Approx, it is stupid to approximate the
940 // entire intersection curve.
941 // 2 - Additionally, if YaRev, there is a risk to not be SameRange.
942 i2s.Perform(S1,S2,Precision::Confusion(),
943 Standard_True,Standard_False,Standard_False);
945 if (!i2s.IsDone() || i2s.NbLines() <= 0) {
946 errStat = Draft_EdgeRecomputation;
951 Standard_Real Dist2, Dist2Min = 0., Glob2Min = RealLast();
952 GeomAdaptor_Curve TheCurve;
954 Standard_Integer i,j; //,jmin;
956 if (i2s.Line(1)->DynamicType() != STANDARD_TYPE(Geom_BSplineCurve))
959 for (i=1; i<= i2s.NbLines(); i++) {
960 TheCurve.Load(i2s.Line(i));
961 Extrema_ExtPC myExtPC(pfv,TheCurve);
963 Standard_Real locpmin = 0.;
964 if (myExtPC.IsDone()) {
965 if(myExtPC.NbExt() >= 1) {
966 Dist2Min = myExtPC.SquareDistance(1);
967 locpmin = myExtPC.Point(1).Parameter();
969 if(myExtPC.NbExt() == 2 && Dist2Min > Precision::SquareConfusion()) {
970 //to avoid incorrectly choosing the image
971 //of the first vertex of the initial edge
972 Standard_Real d1_2 = myExtPC.SquareDistance(1);
973 Standard_Real d2_2 = myExtPC.SquareDistance(2);
974 if(d1_2 > 1.21*d2_2) {
975 Dist2Min = myExtPC.SquareDistance(2);
976 locpmin = myExtPC.Point(2).Parameter();
978 else if(d2_2 > 1.21*d1_2) {
979 Dist2Min = myExtPC.SquareDistance(1);
980 locpmin = myExtPC.Point(1).Parameter();
983 Standard_Real pfvpar = myExtPC.Point(1).Parameter();
984 Standard_Real plvpar = myExtPC.Point(2).Parameter();
987 gp_Pnt pfvprim, plvprim;
989 newC->D0(pfvpar,pfvprim);
990 newC->D0(plvpar,plvprim);
992 Handle(Geom_Surface) theSurf;
993 if(detrompeur == 1) {
994 if(S1->DynamicType() ==
995 STANDARD_TYPE(Geom_RectangularTrimmedSurface))
996 S1 = Handle(Geom_RectangularTrimmedSurface)::
997 DownCast(S1)->BasisSurface();
1001 else if(detrompeur == 2) {
1002 if(S2->DynamicType() ==
1003 STANDARD_TYPE(Geom_RectangularTrimmedSurface))
1004 S2 = Handle(Geom_RectangularTrimmedSurface)::
1005 DownCast(S2)->BasisSurface();
1008 if(detrompeur != 0 && detrompeur != 4) {
1009 Standard_Real ul = 0., vl = 0., uf = 0., vf = 0.;
1010 Standard_Real ufprim = 0., ulprim = 0., vfprim = 0., vlprim = 0.;
1012 if(theSurf->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
1013 gp_Pln pl = Handle(Geom_Plane)::DownCast(S2)->Pln();
1014 ElSLib::Parameters(pl, plv, ul, vl);
1015 ElSLib::Parameters(pl, pfv, uf, vf);
1016 ElSLib::Parameters(pl, plvprim, ulprim, vlprim);
1017 ElSLib::Parameters(pl, pfvprim, ufprim, vfprim);
1019 else if(theSurf->DynamicType() ==
1020 STANDARD_TYPE(Geom_CylindricalSurface)) {
1021 gp_Cylinder cy = Handle(Geom_CylindricalSurface)
1022 ::DownCast(S2)->Cylinder();
1023 ElSLib::Parameters(cy, plv, ul, vl);
1024 ElSLib::Parameters(cy, pfv, uf, vf);
1025 ElSLib::Parameters(cy, plvprim, ulprim, vlprim);
1026 ElSLib::Parameters(cy, pfvprim, ufprim, vfprim);
1028 else detrompeur = 4;
1030 if(detrompeur == 1 || detrompeur == 2) {
1031 gp_Vec2d v1((ul-ufprim), (vl-vfprim));
1032 gp_Vec2d norm((vf-vfprim), (ufprim-uf));
1033 gp_Vec2d v2((ulprim-ufprim), (vlprim-vfprim));
1034 if( (v1.Dot(norm))*(v2.Dot(norm)) < 0) {
1035 Dist2Min = myExtPC.SquareDistance(2);
1036 locpmin = myExtPC.Point(2).Parameter();
1042 if (myExtPC.NbExt() == 1 || myExtPC.NbExt() > 2 || detrompeur ==4) {
1043 Dist2Min = myExtPC.SquareDistance(1);
1044 locpmin = myExtPC.Point(1).Parameter();
1045 for (j=2; j<=myExtPC.NbExt(); j++) {
1046 Dist2 = myExtPC.SquareDistance(j);
1047 if (Dist2 < Dist2Min) {
1049 locpmin = myExtPC.Point(j).Parameter();
1053 else if(myExtPC.NbExt() < 1){
1054 Standard_Real dist1_2,dist2_2;
1056 myExtPC.TrimmedSquareDistances(dist1_2,dist2_2,p1b,p2b);
1057 if (dist1_2 < dist2_2) {
1059 locpmin = TheCurve.FirstParameter();
1063 locpmin = TheCurve.LastParameter();
1067 if (Dist2Min < Glob2Min) {
1068 Glob2Min = Dist2Min;
1075 errStat = Draft_EdgeRecomputation;
1080 newC = i2s.Line(imin);
1082 newC->D1(pmin,pfv,newd1);
1083 Standard_Boolean YaRev = d1fv.Dot(newd1) <0.;
1088 if (i2s.HasLineOnS1(imin)) {
1089 Einf.ChangeFirstPC() = i2s.LineOnS1(imin);
1091 Einf.ChangeFirstPC()->Reverse();
1094 if (i2s.HasLineOnS2(imin)) {
1095 Einf.ChangeSecondPC() = i2s.LineOnS2(imin);
1097 Einf.ChangeSecondPC()->Reverse();
1099 } // if (i2s.Line(1)->DynamicType() != STANDARD_TYPE(Geom_BSplineCurve))
1100 else // i2s.Line(1) is BSplineCurve
1102 //Find the first curve to glue
1103 TColGeom_SequenceOfCurve Candidates;
1104 if (S1->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface) ||
1105 S1->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface))
1107 for (i = 1; i <= i2s.NbLines(); i++)
1109 Handle( Geom_Curve ) aCurve = i2s.Line(i);
1110 gp_Pnt Pnt = aCurve->Value( aCurve->FirstParameter() );
1111 GeomAPI_ProjectPointOnSurf projector( Pnt, S1, Precision::Confusion() );
1113 projector.LowerDistanceParameters( U, V );
1114 if (Abs(U) <= Precision::Confusion() || Abs(U-2.*M_PI) <= Precision::Confusion())
1115 Candidates.Append( aCurve );
1118 Pnt = aCurve->Value( aCurve->LastParameter() );
1119 projector.Init( Pnt, S1, Precision::Confusion() );
1120 projector.LowerDistanceParameters( U, V );
1121 if (Abs(U) <= Precision::Confusion() || Abs(U-2.*M_PI) <= Precision::Confusion())
1124 Candidates.Append( aCurve );
1129 if(Candidates.Length() == 0)
1131 //errStat = Draft_EdgeRecomputation;
1132 //badShape = TopoDS::Edge(ite.Key());
1134 for (i = 1; i <= i2s.NbLines(); i++)
1135 Candidates.Append( i2s.Line(i) );
1140 for (i = 1; i <= i2s.NbLines(); i++)
1141 Candidates.Append( i2s.Line(i) );
1144 Handle( Geom_Curve ) FirstCurve;
1145 if (Candidates.Length() > 1)
1147 Dist2Min = RealLast();
1148 for (i = 1; i <= Candidates.Length(); i++)
1150 Handle( Geom_Curve ) aCurve = Candidates(i);
1151 gp_Pnt Pnt = aCurve->Value( aCurve->FirstParameter() );
1152 Dist2 = Pnt.SquareDistance( pfv );
1153 if (Dist2 < Dist2Min)
1156 FirstCurve = aCurve;
1161 FirstCurve = Candidates(1);
1164 TColGeom_SequenceOfCurve Curves;
1165 for (i = 1; i <= i2s.NbLines(); i++)
1166 if (FirstCurve != i2s.Line(i))
1167 Curves.Append( i2s.Line(i) );
1169 TColGeom_SequenceOfCurve ToGlue;
1170 gp_Pnt EndPoint = FirstCurve->Value( FirstCurve->LastParameter() );
1171 Standard_Boolean added = Standard_True;
1174 added = Standard_False;
1175 for (i = 1; i <= Curves.Length(); i++)
1177 Handle( Geom_Curve ) aCurve = Curves(i);
1178 gp_Pnt pfirst, plast;
1179 pfirst = aCurve->Value( aCurve->FirstParameter() );
1180 plast = aCurve->Value( aCurve->LastParameter() );
1181 if (pfirst.Distance( EndPoint ) <= Precision::Confusion())
1183 ToGlue.Append( aCurve );
1186 added = Standard_True;
1189 if (plast.Distance( EndPoint ) <= Precision::Confusion())
1192 ToGlue.Append( aCurve );
1195 added = Standard_True;
1201 if (FirstCurve.IsNull()) {
1202 errStat = Draft_EdgeRecomputation;
1207 GeomConvert_CompCurveToBSplineCurve Concat( Handle(Geom_BSplineCurve)::DownCast(FirstCurve) );
1208 for (i = 1; i <= ToGlue.Length(); i++)
1209 Concat.Add( Handle(Geom_BSplineCurve)::DownCast(ToGlue(i)), Precision::Confusion(), Standard_True );
1211 newC = Concat.BSplineCurve();
1213 TheCurve.Load( newC );
1214 Extrema_ExtPC myExtPC( pfv, TheCurve );
1215 Dist2Min = RealLast();
1216 for (i = 1; i <= myExtPC.NbExt(); i++)
1218 if (myExtPC.IsMin(i))
1220 Dist2 = myExtPC.SquareDistance(i);
1221 if (Dist2 < Dist2Min)
1224 pmin = myExtPC.Point(i).Parameter();
1228 newC->D1(pmin,pfv,newd1);
1229 Standard_Boolean YaRev = d1fv.Dot(newd1) < 0.;
1234 if (i2s.HasLineOnS1(imin)) {
1235 Einf.ChangeFirstPC() = i2s.LineOnS1(imin);
1237 Einf.ChangeFirstPC()->Reverse();
1240 if (i2s.HasLineOnS2(imin)) {
1241 Einf.ChangeSecondPC() = i2s.LineOnS2(imin);
1243 Einf.ChangeSecondPC()->Reverse();
1246 } // else: i2s.NbLines() > 2 && S1 is Cylinder or Cone
1248 Einf.Tolerance(Max(Einf.Tolerance(), i2s.TolReached3d()));
1251 else { // case of tangency
1252 const TopoDS_Face& F1 = Einf.FirstFace();
1253 const TopoDS_Face& F2 = Einf.SecondFace();
1255 Handle(Geom_Surface) aLocalS1 = myFMap.FindFromKey(F1).Geometry();
1256 Handle(Geom_Surface) aLocalS2 = myFMap.FindFromKey(F2).Geometry();
1257 if (aLocalS1.IsNull() || aLocalS2.IsNull()) {
1258 errStat = Draft_EdgeRecomputation;
1262 if (aLocalS1->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1263 aLocalS1 = Handle(Geom_RectangularTrimmedSurface)::
1264 DownCast(aLocalS1)->BasisSurface();
1266 if (aLocalS2->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1267 aLocalS2 = Handle(Geom_RectangularTrimmedSurface)::
1268 DownCast(aLocalS2)->BasisSurface();
1272 //Standard_Boolean dirfound = Standard_False;
1273 if (aLocalS1->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
1275 Handle(Geom_CylindricalSurface)::DownCast(aLocalS1)->Cylinder();
1276 dirextr = cyl.Axis().Direction();
1277 //dirfound = Standard_True;
1281 else if (aLocalS1->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) {
1282 dirextr = Handle(Geom_SurfaceOfLinearExtrusion)::
1283 DownCast(aLocalS1)->Direction();
1284 //dirfound = Standard_True;
1287 // Here it is possible to calculate PCurve.
1288 Handle(Geom_SurfaceOfLinearExtrusion) SEL =
1289 Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(aLocalS1);
1290 Handle(Geom_Circle) GCir =
1291 Handle(Geom_Circle)::DownCast(SEL->BasisCurve());
1292 if ( !GCir.IsNull()) {
1293 Standard_Real U = ElCLib::Parameter(GCir->Circ(),ptfixe);
1294 Handle(Geom2d_Line) PC1 =
1295 new Geom2d_Line(gp_Pnt2d(U,0.),gp::DY2d());
1296 Einf.ChangeFirstPC() = PC1;
1300 else if (aLocalS2->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
1302 Handle(Geom_CylindricalSurface)::DownCast(aLocalS2)->Cylinder();
1303 dirextr = cyl.Axis().Direction();
1304 // dirfound = Standard_True;
1308 else if (aLocalS2->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) {
1309 dirextr = Handle(Geom_SurfaceOfLinearExtrusion)::
1310 DownCast(aLocalS2)->Direction();
1311 // dirfound = Standard_True;
1314 // Here it is possible to calculate PCurve.
1315 Handle(Geom_SurfaceOfLinearExtrusion) SEL =
1316 Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(aLocalS2);
1317 Handle(Geom_Circle) GCir =
1318 Handle(Geom_Circle)::DownCast(SEL->BasisCurve());
1319 if ( !GCir.IsNull()) {
1320 Standard_Real U = ElCLib::Parameter(GCir->Circ(),ptfixe);
1321 Handle(Geom2d_Line) PC2 =
1322 new Geom2d_Line(gp_Pnt2d(U,0.),gp::DY2d());
1323 Einf.ChangeSecondPC() = PC2;
1326 newC = new Geom_Line(ptfixe,dirextr);
1331 newC->D1(0.,pfv,newd1);
1332 Standard_Boolean YaRev = d1fv.Dot(newd1) <0.;
1335 if(!Einf.FirstPC().IsNull()) {
1336 Einf.ChangeFirstPC()->Reverse();
1338 if(!Einf.SecondPC().IsNull()) {
1339 Einf.ChangeSecondPC()->Reverse();
1344 Handle(Geom_TrimmedCurve) T = Handle(Geom_TrimmedCurve)::DownCast(newC);
1345 if (!T.IsNull()) newC = T->BasisCurve();
1346 Einf.ChangeGeometry() = newC;
1348 else if (!Einf.NewGeometry()){
1349 // set existing curve 3D
1350 Handle(Geom_TrimmedCurve) T = Handle(Geom_TrimmedCurve)::DownCast(C);
1351 if (!T.IsNull()) C = T->BasisCurve();
1352 Einf.ChangeGeometry() = C;
1356 // Calculate new vertices.
1358 Handle(GeomAdaptor_HCurve) HAC = new GeomAdaptor_HCurve;
1359 Handle(GeomAdaptor_HSurface) HAS = new GeomAdaptor_HSurface;
1361 for (Standard_Integer ii = 1; ii <= myVMap.Extent(); ii++)
1363 GeomAdaptor_Curve AC;
1364 GeomAdaptor_Surface AS;
1366 const TopoDS_Vertex& TVV = myVMap.FindKey(ii);
1367 Draft_VertexInfo& Vinf = myVMap.ChangeFromIndex(ii);
1368 if (!Choose(myFMap,myEMap,TVV,Vinf,AC,AS)) {
1370 // no concerted edge => alignment of two consecutive edges.
1372 Vinf.ChangeGeometry() = pvt;
1373 Vinf.InitEdgeIterator();
1374 if (Vinf.MoreEdge()) {
1375 const TopoDS_Edge& Edg1 = Vinf.Edge();
1376 //const Draft_EdgeInfo& Einf1 = myEMap(Edg1);
1377 Draft_EdgeInfo& Einf1 = myEMap.ChangeFromKey(Edg1);
1378 gp_Pnt vtori = BRep_Tool::Pnt(TVV);
1379 //Einf1.Geometry()->D0(Vinf.Parameter(Edg1), pvt);
1380 GeomAPI_ProjectPointOnCurve Projector( vtori, Einf1.Geometry() ); //patch
1381 pvt = Projector.NearestPoint();
1384 static Standard_Integer VertexRecomp = 1;
1385 if (VertexRecomp!=0) {
1386 cout << "pori :" << vtori.X() << " " << vtori.Y() << " " << vtori.Z() << endl;
1387 cout << " Edg 1 :" << Vinf.Parameter(Edg1) << endl;
1388 cout << "pvt :" << pvt.X() << " " << pvt.Y() << " " << pvt.Z() << endl;
1392 Standard_Real dion=pvt.SquareDistance(vtori);
1394 if (Vinf.MoreEdge()) {
1395 const TopoDS_Edge& Edg2 = Vinf.Edge();
1396 //const Draft_EdgeInfo& Einf2 = myEMap(Edg2);
1397 Draft_EdgeInfo& Einf2 = myEMap.ChangeFromKey(Edg2);
1400 Einf2.Geometry()->D0(Vinf.Parameter(Edg2), opvt);
1403 if (VertexRecomp!=0) {
1404 cout << " Edg 2 :" << Vinf.Parameter(Vinf.Edge()) << endl;
1405 cout << "opvt " << opvt.X() << " " << opvt.Y() << " " << opvt.Z() << endl;
1409 if (opvt.SquareDistance(vtori) < dion) {
1412 //Vinf.ChangeParameter(Edg2) = Parameter(Einf2.Geometry(), pvt);
1413 Standard_Integer done;
1414 Standard_Real param = Parameter(Einf2.Geometry(), pvt, done);
1417 S1 = myFMap.FindFromKey(Einf2.FirstFace()).Geometry();
1418 S2 = myFMap.FindFromKey(Einf2.SecondFace()).Geometry();
1419 Vinf.ChangeParameter(Edg2) = SmartParameter( Einf2, BRep_Tool::Tolerance(Edg2), pvt, done, S1, S2 );
1422 Vinf.ChangeParameter(Edg2) = param;
1425 Vinf.ChangeGeometry() = pvt;
1426 //Vinf.ChangeParameter(Edg1) = Parameter(Einf1.Geometry(), pvt);
1427 Standard_Integer done;
1428 Standard_Real param = Parameter(Einf1.Geometry(), pvt, done);
1431 S1 = myFMap.FindFromKey(Einf1.FirstFace()).Geometry();
1432 S2 = myFMap.FindFromKey(Einf1.SecondFace()).Geometry();
1433 Vinf.ChangeParameter(Edg1) = SmartParameter( Einf1, BRep_Tool::Tolerance(Edg1), pvt, done, S1, S2 );
1436 Vinf.ChangeParameter(Edg1) = param;
1441 errStat = Draft_VertexRecomputation;
1446 IntCurveSurface_HInter myintcs;
1450 myintcs.Perform(HAC,HAS);
1453 if (!myintcs.IsDone()) {
1454 errStat = Draft_VertexRecomputation;
1459 gp_Pnt vtori = BRep_Tool::Pnt(TVV);
1462 Standard_Integer nbsol = myintcs.NbPoints();
1465 Extrema_ExtCS extr( AC, AS, Precision::PConfusion(), Precision::PConfusion() );
1467 if(!extr.IsDone() || extr.NbExt() == 0) {
1468 errStat = Draft_VertexRecomputation;
1474 Standard_Real disref = RealLast();
1475 Standard_Integer iref = 0;
1478 for (Standard_Integer i = 1; i <= extr.NbExt(); i++)
1480 extr.Points( i, Pc, Ps );
1481 Standard_Real distemp = Pc.Value().SquareDistance(vtori);
1482 if ( distemp < disref)
1488 extr.Points( iref, Pc, Ps );
1493 Standard_Real disref = RealLast();
1494 Standard_Integer iref = 0;
1495 for (Standard_Integer i = 1; i <= nbsol; i++)
1497 Standard_Real distemp = myintcs.Point(i).Pnt().SquareDistance(vtori);
1498 if ( distemp < disref)
1504 pvt = myintcs.Point(iref).Pnt();
1507 Vinf.ChangeGeometry() = pvt;
1509 for (Vinf.InitEdgeIterator();Vinf.MoreEdge(); Vinf.NextEdge()) {
1510 const TopoDS_Edge& Edg = Vinf.Edge();
1511 //const Draft_EdgeInfo& Einf = myEMap(Edg);
1512 Draft_EdgeInfo& Einf = myEMap.ChangeFromKey(Edg);
1513 //Vinf.ChangeParameter(Edg) = Parameter(Einf.Geometry(),pvt);
1514 Standard_Integer done;
1515 Standard_Real param = Parameter(Einf.Geometry(), pvt, done);
1518 S1 = myFMap.FindFromKey(Einf.FirstFace()).Geometry();
1519 S2 = myFMap.FindFromKey(Einf.SecondFace()).Geometry();
1520 Vinf.ChangeParameter(Edg) = SmartParameter( Einf, BRep_Tool::Tolerance(Edg), pvt, done, S1, S2 );
1523 Vinf.ChangeParameter(Edg) = param;
1528 // small loop of validation/protection
1530 for (Standard_Integer i = 1; i <= myEMap.Extent(); i++)
1532 const TopoDS_Edge& edg = TopoDS::Edge(myEMap.FindKey(i));
1534 TopoDS_Vertex Vf,Vl;
1535 TopExp::Vertices(edg,Vf,Vl);
1536 if (edg.Orientation() == TopAbs_REVERSED) {
1540 Standard_Real pf,pl,tolerance;
1541 if (!NewParameter(Vf,edg,pf,tolerance)) {
1542 pf = BRep_Tool::Parameter(Vf,edg);
1544 if (!NewParameter(Vl,edg,pl,tolerance)) {
1545 pl = BRep_Tool::Parameter(Vl,edg);
1548 // const Handle(Geom_Curve) gc=ite.Value().Geometry();
1549 // if (!gc.IsNull()) {
1550 // pl = gc->LastParameter();
1551 // pf = gc->FirstParameter();
1553 Handle( Geom_Curve ) theCurve = myEMap.FindFromKey(edg).Geometry();
1554 if (theCurve->IsClosed())
1557 Standard_Real FirstPar = theCurve->FirstParameter(), LastPar = theCurve->LastParameter();
1558 Standard_Real pconf = Precision::PConfusion();
1559 if (Abs( pf - LastPar ) <= pconf)
1561 else if (Abs( pl - FirstPar ) <= pconf)
1565 pl += (LastPar-FirstPar);
1570 errStat = Draft_EdgeRecomputation;
1575 if (myVMap.Contains( Vf ))
1576 myVMap.ChangeFromKey(Vf).ChangeParameter(edg) = pf;
1577 if (myVMap.Contains( Vl ))
1578 myVMap.ChangeFromKey(Vl).ChangeParameter(edg) = pl;
1584 //=======================================================================
1585 //function : NewSurface
1587 //=======================================================================
1589 Handle(Geom_Surface) Draft_Modification::NewSurface
1590 (const Handle(Geom_Surface)& S,
1591 const TopAbs_Orientation Oris,
1592 const gp_Dir& Direction,
1593 const Standard_Real Angle,
1594 const gp_Pln& NeutralPlane)
1596 Handle(Geom_Surface) NewS;
1598 Handle(Standard_Type) TypeS = S->DynamicType();
1600 if (TypeS == STANDARD_TYPE(Geom_Plane)) {
1601 gp_Pln Pl = Handle(Geom_Plane)::DownCast(S)->Pln();
1603 Standard_Real Theta;
1604 if (FindRotation(Pl,Oris,Direction,Angle,NeutralPlane,Axe,Theta)) {
1605 if ( Abs(Theta) > Precision::Angular()) {
1606 NewS = Handle(Geom_Surface)::DownCast(S->Rotated(Axe,Theta));
1613 else if (TypeS == STANDARD_TYPE(Geom_CylindricalSurface)) {
1614 Standard_Real testdir = Direction.Dot(NeutralPlane.Axis().Direction());
1615 if (Abs(testdir) <= 1.-Precision::Angular()) {
1617 cout << "NewSurfaceCyl:Draft_Direction_and_Neutral_Perpendicular" << endl;
1621 gp_Cylinder Cy = Handle(Geom_CylindricalSurface)::DownCast(S)->Cylinder();
1622 testdir = Direction.Dot(Cy.Axis().Direction());
1623 if (Abs(testdir) <= 1.-Precision::Angular()) {
1625 cout << "NewSurfaceCyl:Draft_Direction_and_Cylinder_Perpendicular" << endl;
1629 if (Abs(Angle) > Precision::Angular())
1631 IntAna_QuadQuadGeo i2s;
1632 i2s.Perform(NeutralPlane,Cy,Precision::Angular(),Precision::Confusion());
1633 Standard_Boolean isIntDone = i2s.IsDone();
1635 if(i2s.TypeInter() == IntAna_Ellipse)
1637 const gp_Elips anEl = i2s.Ellipse(1);
1638 const Standard_Real aMajorR = anEl.MajorRadius();
1639 const Standard_Real aMinorR = anEl.MinorRadius();
1640 isIntDone = (aMajorR < 100000.0 * aMinorR);
1643 if (!isIntDone || i2s.TypeInter() != IntAna_Circle) {
1645 cout << "NewSurfaceCyl:Draft_Intersection_Neutral_Cylinder_NotDone" << endl;
1649 gp_Ax3 axcone = Cy.Position();
1650 // Pb : Where is the material???
1651 Standard_Real alpha = Angle;
1652 Standard_Boolean direct(axcone.Direct());
1653 if ((direct && Oris == TopAbs_REVERSED) ||
1654 (!direct && Oris == TopAbs_FORWARD)) {
1658 gp_Pnt Center = i2s.Circle(1).Location();
1662 Standard_Real Z = ElCLib::LineParameter(Cy.Axis(),Center);
1663 Standard_Real Rad = Cy.Radius()+Z*Tan(alpha);
1670 gp_Cone co(axcone,alpha,Rad);
1671 NewS = new Geom_ConicalSurface(co);
1677 else if (TypeS == STANDARD_TYPE(Geom_ConicalSurface)) {
1679 Standard_Real testdir = Direction.Dot(NeutralPlane.Axis().Direction());
1680 if (Abs(testdir) <= 1.-Precision::Angular()) {
1682 cout << "NewSurfaceCone:Draft_Direction_and_Neutral_Perpendicular" << endl;
1687 gp_Cone Co1 = Handle(Geom_ConicalSurface)::DownCast(S)->Cone();
1689 testdir = Direction.Dot(Co1.Axis().Direction());
1690 if (Abs(testdir) <= 1.-Precision::Angular()) {
1692 cout << "NewSurfaceCone:Draft_Direction_and_Cone_Perpendicular" << endl;
1698 IntAna_QuadQuadGeo i2s;
1699 i2s.Perform(NeutralPlane,Co1,Precision::Angular(),Precision::Confusion());
1700 if (!i2s.IsDone() || i2s.TypeInter() != IntAna_Circle) {
1702 cout << "NewSurfaceCone:Draft_Intersection_Neutral_Conical_NotDone" << endl;
1706 gp_Ax3 axcone = Co1.Position();
1707 // Pb : Where is the material???
1708 Standard_Real alpha = Angle;
1709 Standard_Boolean direct(axcone.Direct());
1710 if ((direct && Oris == TopAbs_REVERSED) ||
1711 (!direct && Oris == TopAbs_FORWARD)) {
1715 gp_Pnt Center = i2s.Circle(1).Location();
1716 if (Abs(Angle) > Precision::Angular()) {
1720 Standard_Real Z = ElCLib::LineParameter(Co1.Axis(),Center);
1721 Standard_Real Rad = i2s.Circle(1).Radius()+Z*Tan(alpha);
1728 if (Abs(alpha-Co1.SemiAngle()) < Precision::Angular()) {
1732 gp_Cone co(axcone,alpha,Rad);
1733 NewS = new Geom_ConicalSurface(co);
1738 Geom_CylindricalSurface(gp_Cylinder(axcone,i2s.Circle(1).Radius()));
1743 cout << "NewSurface:Draft_SurfNotYetImplemented" << endl;
1750 //=======================================================================
1751 //function : NewCurve
1753 //=======================================================================
1755 Handle(Geom_Curve) Draft_Modification::NewCurve
1756 (const Handle(Geom_Curve)& C,
1757 const Handle(Geom_Surface)& S,
1758 const TopAbs_Orientation Oris,
1759 const gp_Dir& Direction,
1760 const Standard_Real Angle,
1761 const gp_Pln& NeutralPlane,
1762 const Standard_Boolean )
1765 Handle(Geom_Curve) NewC;
1767 Handle(Standard_Type) TypeS = S->DynamicType();
1769 if (TypeS == STANDARD_TYPE(Geom_Plane)) {
1770 gp_Pln Pl = Handle(Geom_Plane)::DownCast(S)->Pln();
1772 Standard_Real Theta;
1773 if (FindRotation(Pl,Oris,Direction,Angle,NeutralPlane,Axe,Theta)) {
1774 if ( Abs(Theta) > Precision::Angular()) {
1775 NewC = Handle(Geom_Curve)::DownCast(C->Rotated(Axe,Theta));
1785 if (C->DynamicType() != STANDARD_TYPE(Geom_Line)) {
1790 gp_Lin lin = Handle(Geom_Line)::DownCast(C)->Lin();
1791 // Standard_Real testdir = Direction.Dot(lin.Direction());
1792 // if (Abs(testdir) <= 1.-Precision::Angular()) {
1796 if (TypeS == STANDARD_TYPE(Geom_CylindricalSurface)) {
1800 gp_Cylinder Cy = Handle(Geom_CylindricalSurface)::DownCast(S)->Cylinder();
1801 ElSLib::Parameters(Cy,lin.Location(),U,V);
1802 ElSLib::D1(U,V,Cy,pbid,d1u,d1v);
1803 Norm = d1u.Crossed(d1v);
1805 else if (TypeS == STANDARD_TYPE(Geom_ConicalSurface)) {
1809 gp_Cone Co = Handle(Geom_ConicalSurface)::DownCast(S)->Cone();
1810 ElSLib::Parameters(Co,lin.Location(),U,V);
1811 ElSLib::D1(U,V,Co,pbid,d1u,d1v);
1812 Norm = d1u.Crossed(d1v);
1815 IntAna_IntConicQuad ilipl(lin,NeutralPlane,Precision::Angular());
1816 if (ilipl.IsDone() && ilipl.NbPoints() != 0){
1817 if (Oris == TopAbs_REVERSED) {
1820 gp_Ax1 axrot(ilipl.Point(1), Norm.Crossed(Direction));
1821 gp_Lin lires = gp_Lin(gp_Ax1(ilipl.Point(1),Direction)).
1822 Rotated(axrot,Angle);
1823 if (lires.Direction().Dot(lin.Direction()) < 0.) {
1826 NewC = new Geom_Line(lires);
1832 //=======================================================================
1835 //=======================================================================
1837 static Standard_Boolean Choose(const Draft_IndexedDataMapOfFaceFaceInfo& theFMap,
1838 Draft_IndexedDataMapOfEdgeEdgeInfo& theEMap,
1839 const TopoDS_Vertex& Vtx,
1840 Draft_VertexInfo& Vinf,
1841 GeomAdaptor_Curve& AC,
1842 GeomAdaptor_Surface& AS)
1845 Vinf.InitEdgeIterator();
1847 // Find a regular edge with null SecondFace
1848 while (Vinf.MoreEdge()) {
1849 const TopoDS_Edge& E1 = Vinf.Edge();
1850 const Draft_EdgeInfo& Einf1 = theEMap.FindFromKey(E1);
1851 if (Einf1.SecondFace().IsNull()) {
1855 GeomAbs_Shape te = BRep_Tool::Continuity(E1,Einf1.FirstFace(),
1856 Einf1.SecondFace());
1857 if (te >= GeomAbs_G1) {
1863 if (!Vinf.MoreEdge()) { // take the first edge
1864 Vinf.InitEdgeIterator();
1867 const TopoDS_Edge& Eref = Vinf.Edge();
1868 //const Draft_EdgeInfo& Einf = theEMap(Eref);
1869 Draft_EdgeInfo& Einf = theEMap.ChangeFromKey(Eref);
1871 AC.Load(Einf.Geometry());
1873 Standard_Real f,l,prm;
1874 TopLoc_Location Loc;
1875 Handle(Geom_Curve) C = BRep_Tool::Curve(Eref,Loc,f,l);
1876 C = Handle(Geom_Curve)::DownCast(C->Transformed(Loc.Transformation()));
1878 //prm = Parameter(C,BRep_Tool::Pnt(Vtx));
1879 Standard_Integer done;
1880 Standard_Real param = Parameter( C, BRep_Tool::Pnt(Vtx), done );
1883 Handle( Geom_Surface ) S1 = theFMap.FindFromKey(Einf.FirstFace()).Geometry();
1884 Handle( Geom_Surface ) S2 = theFMap.FindFromKey(Einf.SecondFace()).Geometry();
1885 prm = SmartParameter( Einf, BRep_Tool::Tolerance(Eref), BRep_Tool::Pnt(Vtx), done, S1, S2 );
1889 C->D1(prm,ptbid,tgref);
1892 Vinf.InitEdgeIterator();
1893 while (Vinf.MoreEdge()) {
1894 // Find a non tangent edge
1895 const TopoDS_Edge& Edg = Vinf.Edge();
1896 if (!Edg.IsSame(Eref)) {
1897 //const Draft_EdgeInfo& Einfo = theEMap(Edg);
1898 Draft_EdgeInfo& Einfo = theEMap.ChangeFromKey(Edg);
1899 if (!Einfo.SecondFace().IsNull() &&
1900 BRep_Tool::Continuity(Edg,Einfo.FirstFace(),Einfo.SecondFace())
1902 C = BRep_Tool::Curve(Edg,Loc,f,l);
1903 C = Handle(Geom_Curve)::DownCast(C->Transformed(Loc.Transformation()));
1904 //prm = Parameter(C,BRep_Tool::Pnt(Vtx));
1905 Standard_Integer anewdone;
1906 Standard_Real anewparam = Parameter( C, BRep_Tool::Pnt(Vtx), anewdone );
1909 Handle( Geom_Surface ) S1 = theFMap.FindFromKey(Einfo.FirstFace()).Geometry();
1910 Handle( Geom_Surface ) S2 = theFMap.FindFromKey(Einfo.SecondFace()).Geometry();
1911 prm = SmartParameter( Einfo, BRep_Tool::Tolerance(Edg), BRep_Tool::Pnt(Vtx), anewdone, S1, S2 );
1916 C->D1(prm,ptbid,tg);
1917 if (tg.CrossMagnitude(tgref) > Precision::Confusion()) {
1924 if (!Vinf.MoreEdge()) {
1925 return Standard_False;
1928 const Draft_EdgeInfo& Einf2 = theEMap.FindFromKey(Vinf.Edge());
1929 if (!Einf.SecondFace().IsNull()) {
1931 if (Einf2.FirstFace().IsSame(Einf.FirstFace()) ||
1932 Einf2.FirstFace().IsSame(Einf.SecondFace())) {
1933 AS.Load(theFMap.FindFromKey(Einf2.SecondFace()).Geometry());
1936 AS.Load(theFMap.FindFromKey(Einf2.FirstFace()).Geometry());
1940 if (Einf2.FirstFace().IsSame(Einf.FirstFace())) {
1941 AS.Load(theFMap.FindFromKey(Einf2.SecondFace()).Geometry());
1944 AS.Load(theFMap.FindFromKey(Einf2.FirstFace()).Geometry());
1947 return Standard_True;
1951 //=======================================================================
1952 //function : Parameter
1954 //=======================================================================
1956 static Standard_Real Parameter(const Handle(Geom_Curve)& C,
1958 Standard_Integer& done)
1961 Handle(Geom_Curve) cbase = C;
1962 Handle(Standard_Type) ctyp = C->DynamicType();
1963 if (ctyp == STANDARD_TYPE(Geom_TrimmedCurve)) {
1964 cbase = Handle(Geom_TrimmedCurve)::DownCast(C)->BasisCurve();
1965 ctyp = cbase->DynamicType();
1967 Standard_Real param;
1968 if (ctyp == STANDARD_TYPE(Geom_Line)) {
1969 param = ElCLib::Parameter(Handle(Geom_Line)::DownCast(cbase)->Lin(),P);
1971 else if (ctyp == STANDARD_TYPE(Geom_Circle)) {
1972 param = ElCLib::Parameter(Handle(Geom_Circle)::DownCast(cbase)->Circ(),P);
1973 if (Abs(2.*M_PI-param) <=Epsilon(2.*M_PI)) {
1977 else if (ctyp == STANDARD_TYPE(Geom_Ellipse)) {
1978 param = ElCLib::Parameter(Handle(Geom_Ellipse)::DownCast(cbase)->Elips(),P);
1979 if (Abs(2.*M_PI-param) <=Epsilon(2.*M_PI)) {
1983 else if (ctyp == STANDARD_TYPE(Geom_Parabola)) {
1984 param = ElCLib::Parameter(Handle(Geom_Parabola)::DownCast(cbase)->Parab(),P);
1986 else if (ctyp == STANDARD_TYPE(Geom_Hyperbola)) {
1987 param = ElCLib::Parameter(Handle(Geom_Hyperbola)::DownCast(cbase)->Hypr(),P);
1990 GeomAdaptor_Curve TheCurve(C);
1991 Extrema_ExtPC myExtPC(P,TheCurve);
1992 if (!myExtPC.IsDone()) {
1993 Standard_Failure::Raise("Draft_Modification_1::Parameter: ExtremaPC not done.");
1995 if (myExtPC.NbExt() >= 1) {
1996 Standard_Real Dist2, Dist2Min = myExtPC.SquareDistance(1);
1997 Standard_Integer j, jmin = 1;
1998 for (j = 2; j <= myExtPC.NbExt(); j++) {
1999 Dist2 = myExtPC.SquareDistance(j);
2000 if (Dist2 < Dist2Min) {
2005 param = myExtPC.Point(jmin).Parameter();
2008 Standard_Real dist1_2,dist2_2;
2010 myExtPC.TrimmedSquareDistances(dist1_2,dist2_2,p1b,p2b);
2011 if (dist1_2 < dist2_2) {
2013 param = TheCurve.FirstParameter();
2017 param = TheCurve.LastParameter();
2021 if (cbase->IsPeriodic()) {
2022 Standard_Real Per = cbase->Period();
2023 Standard_Real Tolp = Precision::Parametric(Precision::Confusion());
2024 if (Abs(Per-param) <= Tolp) {
2032 //=======================================================================
2033 //function : SmartParameter
2035 //=======================================================================
2037 static Standard_Real SmartParameter(Draft_EdgeInfo& Einf,
2038 const Standard_Real EdgeTol,
2040 const Standard_Integer sign,
2041 const Handle(Geom_Surface)& S1,
2042 const Handle(Geom_Surface)& S2)
2044 Handle( Geom2d_Curve ) NewC2d;
2045 Standard_Real Tol = Precision::Confusion();
2046 Standard_Real Etol = EdgeTol;
2048 Handle( Geom2d_Curve ) pcu1 = Einf.FirstPC();
2049 Handle( Geom2d_Curve ) pcu2 = Einf.SecondPC();
2053 Handle( Geom_Curve ) theCurve = Einf.Geometry();
2054 pcu1 = GeomProjLib::Curve2d( theCurve, theCurve->FirstParameter(), theCurve->LastParameter(), S1, Etol );
2055 Einf.ChangeFirstPC() = pcu1;
2059 Handle( Geom_Curve ) theCurve = Einf.Geometry();
2060 pcu2 = GeomProjLib::Curve2d( theCurve, theCurve->FirstParameter(), theCurve->LastParameter(), S2, Etol );
2061 Einf.ChangeSecondPC() = pcu2;
2064 GeomAPI_ProjectPointOnSurf Projector( Pnt, S1 );
2066 Projector.LowerDistanceParameters( U, V );
2068 NewC2d = Einf.FirstPC();
2069 if (NewC2d->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve))
2070 NewC2d = (Handle(Geom2d_TrimmedCurve)::DownCast(NewC2d))->BasisCurve();
2072 gp_Pnt2d P2d( U, V );
2073 Geom2dAPI_ProjectPointOnCurve Projector2d( P2d, NewC2d );
2074 if (Projector2d.NbPoints() == 0 || Projector2d.LowerDistance() > Tol)
2076 Handle( Geom2d_BSplineCurve ) BCurve;
2077 if (NewC2d->DynamicType() != STANDARD_TYPE(Geom2d_BSplineCurve))
2078 BCurve = Geom2dConvert::CurveToBSplineCurve( NewC2d );
2080 BCurve = Handle( Geom2d_BSplineCurve )::DownCast( NewC2d );
2083 TColgp_Array1OfPnt2d PntArray( 1, 2 );
2085 PntArray(2) = BCurve->Pole(1);
2086 Handle( Geom2d_BezierCurve ) Patch = new Geom2d_BezierCurve( PntArray );
2087 Geom2dConvert_CompCurveToBSplineCurve Concat( BCurve, Convert_QuasiAngular );
2088 Concat.Add( Patch, Tol, Standard_False );
2089 BCurve = Concat.BSplineCurve();
2093 TColgp_Array1OfPnt2d PntArray( 1, 2 );
2094 PntArray(1) = BCurve->Pole( BCurve->NbPoles() );
2096 Handle( Geom2d_BezierCurve ) Patch = new Geom2d_BezierCurve( PntArray );
2097 Geom2dConvert_CompCurveToBSplineCurve Concat( BCurve, Convert_QuasiAngular );
2098 Concat.Add( Patch, Tol, Standard_True );
2099 BCurve = Concat.BSplineCurve();
2103 Einf.ChangeFirstPC() = NewC2d;
2104 Handle( Geom2dAdaptor_HCurve ) hcur = new Geom2dAdaptor_HCurve( NewC2d );
2105 Handle( GeomAdaptor_HSurface ) hsur = new GeomAdaptor_HSurface( S1 );
2106 Adaptor3d_CurveOnSurface cons( hcur, hsur );
2107 Handle( Adaptor3d_HCurveOnSurface ) hcons = new Adaptor3d_HCurveOnSurface( cons );
2108 Handle( GeomAdaptor_HSurface ) hsur2 = new GeomAdaptor_HSurface( S2 );
2109 ProjLib_CompProjectedCurve ProjCurve( hsur2, hcons, Tol, Tol );
2110 Handle(ProjLib_HCompProjectedCurve) HProjector = new ProjLib_HCompProjectedCurve();
2111 HProjector->Set( ProjCurve );
2112 Standard_Real Udeb, Ufin;
2113 ProjCurve.Bounds(1, Udeb, Ufin);
2114 Standard_Integer MaxSeg = 20 + HProjector->NbIntervals(GeomAbs_C3);
2115 Approx_CurveOnSurface appr( HProjector, hsur2, Udeb, Ufin, Tol,
2116 GeomAbs_C1, 10, MaxSeg,
2117 Standard_False, Standard_False );
2118 Einf.ChangeSecondPC() = appr.Curve2d();
2119 Einf.ChangeGeometry() = appr.Curve3d();
2120 Einf.SetNewGeometry( Standard_True );
2123 return Einf.Geometry()->FirstParameter();
2125 return Einf.Geometry()->LastParameter();
2129 //=======================================================================
2130 //function : Orientation
2132 //=======================================================================
2134 static TopAbs_Orientation Orientation(const TopoDS_Shape& S,
2135 const TopoDS_Face& F)
2138 // change porting NT
2140 TopExp_Explorer expl ;
2143 while (expl.More()) {
2144 if (TopoDS::Face(expl.Current()).IsSame(F)) {
2145 return expl.Current().Orientation();
2149 return TopAbs_FORWARD;
2153 //=======================================================================
2154 //function : FindRotation
2156 //=======================================================================
2158 static Standard_Boolean FindRotation(const gp_Pln& Pl,
2159 const TopAbs_Orientation Oris,
2160 const gp_Dir& Direction,
2161 const Standard_Real Angle,
2162 const gp_Pln& NeutralPlane,
2164 Standard_Real& theta)
2166 IntAna_QuadQuadGeo i2pl(Pl,NeutralPlane,
2167 Precision::Angular(),Precision::Confusion());
2169 if (i2pl.IsDone() && i2pl.TypeInter() == IntAna_Line) {
2170 gp_Lin li = i2pl.Line(1);
2171 // Try to turn around this line
2172 gp_Dir nx = li.Direction();
2173 gp_Dir ny = Pl.Axis().Direction().Crossed(nx);
2174 Standard_Real a = Direction.Dot(nx);
2175 if (Abs(a) <=1-Precision::Angular()) {
2176 Standard_Real b = Direction.Dot(ny);
2177 Standard_Real c = Direction.Dot(Pl.Axis().Direction());
2178 Standard_Boolean direct(Pl.Position().Direct());
2179 if ((direct && Oris == TopAbs_REVERSED) ||
2180 (!direct && Oris == TopAbs_FORWARD)) {
2184 Standard_Real denom = Sqrt(1-a*a);
2185 Standard_Real Sina = Sin(Angle);
2186 if (denom>Abs(Sina)) {
2187 Standard_Real phi = ATan2(b/denom,c/denom);
2188 Standard_Real theta0 = ACos(Sina/denom);
2189 theta = theta0 - phi;
2190 if (Cos(theta) <0.) {
2191 theta = -theta0 -phi;
2193 // modified by NIZHNY-EAP Tue Nov 16 15:51:38 1999 ___BEGIN___
2194 while (Abs(theta)>M_PI) {
2195 theta = theta + M_PI*(theta<0 ? 1 : -1);
2197 // modified by NIZHNY-EAP Tue Nov 16 15:53:32 1999 ___END___
2198 Axe = li.Position();
2199 return Standard_True;
2203 return Standard_False;