1 // Created on: 1996-12-11
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1996-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.
19 #include <Adaptor3d_HCurve.hxx>
20 #include <Adaptor3d_HSurface.hxx>
22 #include <BRepBuilderAPI_MakeEdge.hxx>
23 #include <BRepBuilderAPI_MakeVertex.hxx>
24 #include <BRepAdaptor_Curve.hxx>
25 #include <BRepAdaptor_HSurface.hxx>
26 #include <BRepAdaptor_Surface.hxx>
27 #include <BRepTopAdaptor_FClass2d.hxx>
28 #include <BRep_Tool.hxx>
29 #include <BRepTools.hxx>
30 #include <Bnd_Box.hxx>
35 #include <GccEnt_QualifiedLin.hxx>
36 #include <gce_MakeDir.hxx>
37 #include <gce_MakeLin.hxx>
38 #include <Geom2d_Circle.hxx>
39 #include <GeomAPI_ExtremaCurveCurve.hxx>
40 #include <GeomAPI_IntSS.hxx>
41 #include <GeomAPI_ProjectPointOnCurve.hxx>
42 #include <GeomAPI_ProjectPointOnSurf.hxx>
43 #include <GeomLib.hxx>
44 #include <GeomProjLib.hxx>
45 #include <GeomProjLib.hxx>
46 #include <Geom_CartesianPoint.hxx>
47 #include <Geom_Circle.hxx>
48 #include <Geom_ConicalSurface.hxx>
49 #include <Geom_Curve.hxx>
50 #include <Geom_CylindricalSurface.hxx>
51 #include <Geom_Ellipse.hxx>
52 #include <Geom_Line.hxx>
53 #include <Geom_OffsetSurface.hxx>
54 #include <Geom_Plane.hxx>
55 #include <Geom_SphericalSurface.hxx>
56 #include <Geom_SurfaceOfLinearExtrusion.hxx>
57 #include <Geom_SurfaceOfRevolution.hxx>
58 #include <Geom_ToroidalSurface.hxx>
59 #include <Geom_TrimmedCurve.hxx>
63 #include <gp_Elips.hxx>
69 #include <Precision.hxx>
70 #include <Prs3d_LineAspect.hxx>
71 #include <Prs3d_PointAspect.hxx>
72 #include <StdPrs_Point.hxx>
73 #include <StdPrs_WFDeflectionShape.hxx>
74 #include <TColStd_Array1OfReal.hxx>
75 #include <TColStd_Array2OfReal.hxx>
77 #include <TopExp_Explorer.hxx>
78 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
81 const Standard_Real SquareTolerance = Precision::SquareConfusion();
83 //=======================================================================
86 //=======================================================================
87 gp_Pnt AIS::Nearest(const TopoDS_Shape& ashape, const gp_Pnt& apoint)
89 Standard_Real dist2 = RealLast();
90 Standard_Real curdist2;
91 gp_Pnt result(0.0,0.0,0.0);
92 gp_Pnt curpnt(0.0,0.0,0.0);
93 TopExp_Explorer explo(ashape,TopAbs_VERTEX);
96 curpnt = BRep_Tool::Pnt(TopoDS::Vertex(explo.Current()));
97 curdist2 = apoint.SquareDistance(curpnt);
108 //=======================================================================
110 //purpose : For <thePoint> finds the nearest point on <theLine>.
111 //=======================================================================
112 gp_Pnt AIS::Nearest (const gp_Lin& theLine, const gp_Pnt& thePoint)
114 Handle(Geom_Line) aLine = new Geom_Line (theLine);
116 GeomAPI_ProjectPointOnCurve aPointProj (thePoint, aLine);
117 return aPointProj.Point (1);
120 //=======================================================================
122 //purpose : For the given point finds nearest point on the curve,
123 // return TRUE if found point is belongs to curve
124 // and FALSE otherwise.
125 //=======================================================================
126 Standard_Boolean AIS::Nearest (const Handle(Geom_Curve)& theCurve,
127 const gp_Pnt& thePoint,
128 const gp_Pnt& theFirstPoint,
129 const gp_Pnt& theLastPoint,
130 gp_Pnt& theNearestPoint)
132 GeomAPI_ProjectPointOnCurve aPointProj (thePoint, theCurve);
133 theNearestPoint = theCurve->Value (aPointProj.LowerDistanceParameter());
135 Standard_Real aLength = theFirstPoint.Distance (theLastPoint);
137 if (theNearestPoint.Distance (theFirstPoint) > aLength
138 || theNearestPoint.Distance (theLastPoint) >aLength)
140 return Standard_False;
143 return Standard_True;
146 //=======================================================================
149 //=======================================================================
150 gp_Pnt AIS::Farest( const TopoDS_Shape& aShape, const gp_Pnt& aPoint )
152 Standard_Real MaxDist2 = 0.0e0, curdist2;
153 gp_Pnt Result(0.0,0.0,0.0);
154 gp_Pnt curpnt(0.0,0.0,0.0);
155 TopExp_Explorer Explo( aShape, TopAbs_VERTEX );
156 for (; Explo.More(); Explo.Next())
158 curpnt = BRep_Tool::Pnt( TopoDS::Vertex( Explo.Current() ) );
159 curdist2 = aPoint.SquareDistance( curpnt );
160 if (curdist2 > MaxDist2)
170 //=======================================================================
171 //function : ComputeGeometry
172 //purpose : for line, circle, ellipse.
173 //=======================================================================
174 Standard_Boolean AIS::ComputeGeometry (const TopoDS_Edge& theEdge,
175 Handle(Geom_Curve)& theCurve,
179 TopLoc_Location anEdgeLoc;
180 Standard_Real aFirst, aLast;
181 theCurve = BRep_Tool::Curve (theEdge, anEdgeLoc, aFirst, aLast);
182 if (theCurve.IsNull())
184 return Standard_False;
187 if (!anEdgeLoc.IsIdentity())
189 Handle(Geom_Geometry) aGeometry = theCurve->Transformed (anEdgeLoc.Transformation());
190 theCurve = (Handle(Geom_Curve)&) aGeometry;
193 if (theCurve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
195 theCurve = ((Handle(Geom_TrimmedCurve)&) theCurve)->BasisCurve();
198 if (theCurve->IsInstance (STANDARD_TYPE (Geom_Line)))
200 Handle(Geom_Line) aLine = (Handle(Geom_Line)&) theCurve;
201 theFirstPnt = ElCLib::Value (aFirst, aLine->Lin());
202 theLastPnt = ElCLib::Value (aLast, aLine->Lin());
204 else if (theCurve->IsInstance (STANDARD_TYPE (Geom_Circle)))
206 Handle(Geom_Circle) aCirc = (Handle(Geom_Circle)&) theCurve;
208 theFirstPnt = ElCLib::Value (aFirst, aCirc->Circ());
209 theLastPnt = ElCLib::Value (aLast, aCirc->Circ());
211 else if (theCurve->IsInstance (STANDARD_TYPE (Geom_Ellipse)))
213 Handle(Geom_Ellipse) anEllipse = (Handle(Geom_Ellipse)&) theCurve;
214 theFirstPnt = ElCLib::Value (aFirst, anEllipse->Elips());
215 theLastPnt = ElCLib::Value (aLast, anEllipse->Elips());
219 return Standard_False;
222 return Standard_True;
225 //=======================================================================
226 //function : ComputeGeometry
227 //purpose : for line, circle, ellipse.
228 //=======================================================================
229 Standard_Boolean AIS::ComputeGeometry (const TopoDS_Edge& theEdge,
230 Handle(Geom_Curve)& theCurve,
233 Standard_Boolean& theIsInfinite)
235 Standard_Real aFirst, aLast;
237 BRepAdaptor_Curve anAdaptor (theEdge);
239 theCurve = Handle(Geom_Curve)::DownCast
240 (anAdaptor.Curve().Curve()->Transformed (anAdaptor.Trsf()));
242 if (theCurve.IsNull())
244 return Standard_False;
247 aFirst = anAdaptor.FirstParameter();
248 aLast = anAdaptor.LastParameter();
250 theIsInfinite = (Precision::IsInfinite (aFirst) || Precision::IsInfinite (aLast));
252 if (theCurve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
254 theCurve = ((Handle(Geom_TrimmedCurve)&) theCurve)->BasisCurve();
259 theFirstPnt = theCurve->Value (aFirst);
260 theLastPnt = theCurve->Value (aLast);
264 theFirstPnt = gp::Origin();
265 theLastPnt = gp::Origin();
268 return Standard_True;
271 //=======================================================================
272 //function : ComputeGeometry
274 //=======================================================================
276 Standard_Boolean AIS::ComputeGeometry (const TopoDS_Edge& theEdge,
277 Handle(Geom_Curve)& theCurve,
280 Handle(Geom_Curve)& theExtCurve,
281 Standard_Boolean& theIsInfinite,
282 Standard_Boolean& theIsOnPlane,
283 const Handle(Geom_Plane)& thePlane)
285 if (thePlane.IsNull())
287 return Standard_False;
290 Standard_Real aFirst, aLast;
291 BRepAdaptor_Curve aCurveAdaptor (theEdge);
292 theCurve = Handle(Geom_Curve)::DownCast (aCurveAdaptor.Curve().Curve()->Transformed (aCurveAdaptor.Trsf()));
293 aFirst = aCurveAdaptor.FirstParameter();
294 aLast = aCurveAdaptor.LastParameter();
296 if (theCurve.IsNull())
298 return Standard_False;
301 theExtCurve = theCurve;
302 theIsInfinite = (Precision::IsInfinite (aFirst) || Precision::IsInfinite (aLast));
304 // Checks that the projected curve is not in the plane.
305 theIsOnPlane = Standard_True;
306 if (theExtCurve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
308 theExtCurve = ((Handle(Geom_TrimmedCurve)&) theExtCurve)->BasisCurve();
311 if (theExtCurve->IsInstance (STANDARD_TYPE (Geom_Line)))
313 Handle(Geom_Line) aLine = (Handle(Geom_Line)&) theExtCurve;
314 theIsOnPlane = thePlane->Pln().Contains (aLine->Lin(),
315 Precision::Confusion(),
316 Precision::Angular());
318 else if (theExtCurve->IsInstance (STANDARD_TYPE (Geom_Circle)))
320 Handle(Geom_Circle) aCircle = (Handle(Geom_Circle)&) theExtCurve;
322 gp_Ax3 aCircPos (aCircle->Position());
323 theIsOnPlane = aCircPos.IsCoplanar (thePlane->Pln().Position(),
324 Precision::Confusion(),
325 Precision::Angular());
330 theExtCurve.Nullify();
333 theCurve = GeomProjLib::ProjectOnPlane (theCurve, thePlane,
334 thePlane->Pln().Axis().Direction(),
337 if (theCurve->IsInstance (STANDARD_TYPE (Geom_Line)))
339 Handle(Geom_Line) aLine = (Handle(Geom_Line)&) theCurve;
342 theFirstPnt = ElCLib::Value (aFirst, aLine->Lin());
343 theLastPnt = ElCLib::Value (aLast, aLine->Lin());
346 else if (theCurve->IsInstance (STANDARD_TYPE (Geom_Circle)))
348 Handle(Geom_Circle) aCirc = (Handle(Geom_Circle)&) theCurve;
350 theFirstPnt = ElCLib::Value (aFirst, aCirc->Circ());
351 theLastPnt = ElCLib::Value (aLast, aCirc->Circ());
353 else if (theCurve->IsInstance (STANDARD_TYPE (Geom_Ellipse)))
355 Handle(Geom_Ellipse) anEllipse = (Handle(Geom_Ellipse)&) theCurve;
357 theFirstPnt = ElCLib::Value (aFirst, anEllipse->Elips());
358 theLastPnt = ElCLib::Value (aLast, anEllipse->Elips());
362 return Standard_False;
365 return Standard_True;
368 //=======================================================================
369 //function : ComputeGeometry
371 //=======================================================================
372 Standard_Boolean AIS::ComputeGeometry (const TopoDS_Edge& theFirstEdge,
373 const TopoDS_Edge& theSecondEdge,
374 Handle(Geom_Curve)& theFirstCurve,
375 Handle(Geom_Curve)& theSecondCurve,
376 gp_Pnt& theFirstPnt1,
378 gp_Pnt& theFirstPnt2,
380 const Handle(Geom_Plane)& thePlane)
382 if (thePlane.IsNull())
384 return Standard_False;
387 TopLoc_Location aFirstEdgeLoc, aSecondEdgeLoc;
388 Standard_Real aFirst1, aLast1, aFirst2, aLast2;
390 theFirstCurve = BRep_Tool::Curve (theFirstEdge, aFirstEdgeLoc, aFirst1, aLast1);
391 theSecondCurve = BRep_Tool::Curve (theSecondEdge, aSecondEdgeLoc, aFirst2, aLast2);
393 if (theFirstCurve.IsNull())
395 return Standard_False;
398 if (theSecondCurve.IsNull())
400 return Standard_False;
403 if (!aFirstEdgeLoc.IsIdentity())
405 Handle(Geom_Geometry) aGeomGeometry = theFirstCurve->Transformed (aFirstEdgeLoc.Transformation());
406 theFirstCurve = (Handle(Geom_Curve)&) aGeomGeometry;
409 if (!aSecondEdgeLoc.IsIdentity())
411 Handle(Geom_Geometry) aGeomGeometry = theSecondCurve->Transformed (aSecondEdgeLoc.Transformation());
412 theSecondCurve = (Handle(Geom_Curve)&) aGeomGeometry;
415 theFirstCurve = GeomProjLib::ProjectOnPlane (theFirstCurve, thePlane,
416 thePlane->Pln().Axis().Direction(),
420 theSecondCurve = GeomProjLib::ProjectOnPlane (theSecondCurve, thePlane,
421 thePlane->Pln().Axis().Direction(),
425 if (theFirstCurve->IsInstance (STANDARD_TYPE(Geom_TrimmedCurve)))
427 theFirstCurve = ((Handle(Geom_TrimmedCurve)&) theFirstCurve)->BasisCurve();
430 if (theSecondCurve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
432 theSecondCurve = ((Handle(Geom_TrimmedCurve)&) theSecondCurve)->BasisCurve();
435 if (theFirstCurve->IsInstance(STANDARD_TYPE(Geom_Line)))
437 Handle(Geom_Line) aLine = (Handle(Geom_Line)&) theFirstCurve;
439 theFirstPnt1 = ElCLib::Value (aFirst1, aLine->Lin());
440 theLastPnt1 = ElCLib::Value (aLast1, aLine->Lin());
442 else if (theFirstCurve->IsInstance(STANDARD_TYPE(Geom_Circle)))
444 Handle(Geom_Circle) aCirc = (Handle(Geom_Circle)&) theFirstCurve;
446 theFirstPnt1 = ElCLib::Value (aFirst1, aCirc->Circ());
447 theLastPnt1 = ElCLib::Value (aLast1, aCirc->Circ());
451 return Standard_False;
454 if (theSecondCurve->IsInstance (STANDARD_TYPE (Geom_Line)))
456 Handle(Geom_Line) aLine = (Handle(Geom_Line)&) theSecondCurve;
458 theFirstPnt2 = ElCLib::Value (aFirst2, aLine->Lin());
459 theLastPnt2 = ElCLib::Value (aLast2, aLine->Lin());
461 else if (theSecondCurve->IsInstance (STANDARD_TYPE (Geom_Circle)))
463 Handle(Geom_Circle) aCirc = (Handle(Geom_Circle)&) theSecondCurve;
465 theFirstPnt2 = ElCLib::Value (aFirst2, aCirc->Circ());
466 theLastPnt2 = ElCLib::Value (aLast2, aCirc->Circ());
470 return Standard_False;
473 return Standard_True;
476 //=======================================================================
477 //function : ComputeGeometry
478 //purpose : Computes the geometry of the 2 edges.
479 //=======================================================================
480 Standard_Boolean AIS::ComputeGeometry (const TopoDS_Edge& theFirstEdge,
481 const TopoDS_Edge& theSecondEdge,
482 Handle(Geom_Curve)& theFirstCurve,
483 Handle(Geom_Curve)& theSecondCurve,
484 gp_Pnt& theFirstPnt1,
486 gp_Pnt& theFirstPnt2,
488 Standard_Boolean& theIsInfinite1,
489 Standard_Boolean& theIsInfinite2)
491 theIsInfinite1 = theIsInfinite2 = Standard_False;
493 if (!AIS::ComputeGeometry (theFirstEdge, theFirstCurve,theFirstPnt1, theLastPnt1, theIsInfinite1))
495 return Standard_False;
498 if (!AIS::ComputeGeometry (theSecondEdge, theSecondCurve,theFirstPnt2, theLastPnt2, theIsInfinite2))
500 return Standard_False;
503 if (theIsInfinite1 || theIsInfinite2)
505 if (theFirstCurve->DynamicType() == theSecondCurve->DynamicType())
507 gp_Lin aLin1 = ((Handle(Geom_Line)&) theFirstCurve)->Lin();
508 gp_Lin aLin2 = ((Handle(Geom_Line)&) theSecondCurve)->Lin();
512 theFirstPnt1 = ElCLib::Value (ElCLib::Parameter (aLin2, theFirstPnt2), aLin1);
513 theLastPnt1 = ElCLib::Value (ElCLib::Parameter (aLin2, theLastPnt2), aLin1);
515 else if (theIsInfinite2)
517 theFirstPnt2 = ElCLib::Value (ElCLib::Parameter (aLin1, theFirstPnt1), aLin2);
518 theLastPnt2 = ElCLib::Value (ElCLib::Parameter (aLin1, theLastPnt1), aLin2);
523 if (theIsInfinite1 && !theIsInfinite2)
525 GeomAPI_ProjectPointOnCurve aProjector (theFirstPnt2, theFirstCurve);
526 theFirstPnt1 = theFirstCurve->Value (aProjector.LowerDistanceParameter ());
528 aProjector.Init (theLastPnt2, theFirstCurve);
529 theLastPnt1 = theFirstCurve->Value (aProjector.LowerDistanceParameter ());
531 else if (!theIsInfinite1 && theIsInfinite2)
533 GeomAPI_ProjectPointOnCurve aProjector (theFirstPnt1, theSecondCurve);
534 theFirstPnt2 = theSecondCurve->Value (aProjector.LowerDistanceParameter ());
536 aProjector.Init (theLastPnt1, theSecondCurve);
537 theLastPnt2 = theSecondCurve->Value (aProjector.LowerDistanceParameter ());
541 return Standard_False;
546 return Standard_True;
549 //=======================================================================
550 //function : ComputeGeometry
551 //purpose : Computes the geometry of the 2 edges in the current wp
552 // and the 'right' geometry of the edges if one doesn't
553 // belong to the current working plane.
554 // There may be only one curve that can't belong to the
555 // current working plane ( attachement constraint)
556 // if the 2 edges belong to the current WP, <WhatProj> = 0
558 // indexExt = 0 2 edges are in the current wp
559 // indexExt = 1 first edge is not in the current wp
560 // indexExt = 2 second edge is not in the current wp
561 // if none of the two edges is in the current wp ,
562 // it returns Standard_False
563 //=======================================================================
564 Standard_Boolean AIS::ComputeGeometry (const TopoDS_Edge& theFirstEdge,
565 const TopoDS_Edge& theSecondEdge,
566 Standard_Integer& theExtIndex,
567 Handle(Geom_Curve)& theFirstCurve,
568 Handle(Geom_Curve)& theSecondCurve,
569 gp_Pnt& theFirstPnt1,
571 gp_Pnt& theFirstPnt2,
573 Handle(Geom_Curve)& theExtCurve,
574 Standard_Boolean& theIsInfinite1,
575 Standard_Boolean& theIsInfinite2,
576 const Handle(Geom_Plane)& thePlane)
578 if (thePlane.IsNull())
580 return Standard_False;
583 theExtCurve.Nullify();
586 Standard_Real aFirst1, aLast1, aFirst2, aLast2;
587 theIsInfinite1 = theIsInfinite2 = Standard_False;
589 BRepAdaptor_Curve aFirstAdaptor (theFirstEdge);
590 BRepAdaptor_Curve aSecondAdaptor (theSecondEdge);
592 theFirstCurve = Handle(Geom_Curve)::DownCast
593 (aFirstAdaptor.Curve().Curve()->Transformed (aFirstAdaptor.Trsf()));
594 theSecondCurve = Handle(Geom_Curve)::DownCast
595 (aSecondAdaptor.Curve().Curve()->Transformed (aSecondAdaptor.Trsf()));
597 if (theFirstCurve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
599 theFirstCurve = ((Handle(Geom_TrimmedCurve)&) theFirstCurve)->BasisCurve();
601 if (theSecondCurve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
603 theSecondCurve = ((Handle(Geom_TrimmedCurve)&) theSecondCurve)->BasisCurve();
606 aFirst1 = aFirstAdaptor.FirstParameter();
607 aLast1 = aFirstAdaptor.LastParameter();
609 aFirst2 = aSecondAdaptor.FirstParameter();
610 aLast2 = aSecondAdaptor.LastParameter();
612 if (theFirstCurve.IsNull() || theSecondCurve.IsNull())
614 return Standard_False;
617 Handle(Geom_Curve) aFirstSaved = theFirstCurve;
618 Handle(Geom_Curve) aSecondSaved = theSecondCurve;
620 // Checks that the projected curve is not in the plane
621 Standard_Boolean isFirstOnPlane,isSecondOnPlane;
623 if ((!ComputeGeomCurve (theFirstCurve, aFirst1, aLast1, theFirstPnt1, theLastPnt1, thePlane, isFirstOnPlane))
624 || (!ComputeGeomCurve( theSecondCurve, aFirst2, aLast2, theFirstPnt2, theLastPnt2, thePlane,isSecondOnPlane)))
626 return Standard_False;
629 if (Precision::IsInfinite (aFirst1) || Precision::IsInfinite (aLast1))
631 theIsInfinite1 = Standard_True;
634 if (Precision::IsInfinite (aFirst2) || Precision::IsInfinite (aLast2))
636 theIsInfinite2 = Standard_True;
639 if (theIsInfinite1 && theIsInfinite2)
644 if (theIsInfinite1 || theIsInfinite2)
646 if (theFirstCurve->DynamicType() == theSecondCurve->DynamicType())
648 gp_Lin aLin1 = ((Handle(Geom_Line)&) theFirstCurve)->Lin();
649 gp_Lin aLin2 = ((Handle(Geom_Line)&) theSecondCurve)->Lin();
651 if (theExtIndex == 1)
653 theFirstPnt1 = ElCLib::Value (ElCLib::Parameter (aLin2, theFirstPnt2), aLin1);
654 theLastPnt1 = ElCLib::Value (ElCLib::Parameter (aLin2, theLastPnt2), aLin1);
656 else if (theExtIndex == 2)
658 theFirstPnt2 = ElCLib::Value (ElCLib::Parameter (aLin1, theFirstPnt1), aLin2);
659 theLastPnt2 = ElCLib::Value (ElCLib::Parameter (aLin1, theLastPnt1), aLin2);
664 if (isFirstOnPlane && isSecondOnPlane)
666 return Standard_True;
669 if (!isFirstOnPlane && isSecondOnPlane)
670 {// curve 2 only in the plane
672 theExtCurve = aFirstSaved;
674 else if (isFirstOnPlane && !isSecondOnPlane)
675 {// curve 1 only in the plane
677 theExtCurve = aSecondSaved;
681 return Standard_False;
684 return Standard_True;
687 //=======================================================================
688 //function : ComputeGeomCurve
689 //purpose : Checks if aCurve belongs to aPlane; if not, projects aCurve in aPlane
690 // and returns aCurveproj;
692 //=======================================================================
693 Standard_Boolean AIS::ComputeGeomCurve (Handle(Geom_Curve)& aCurve,
694 const Standard_Real first1,
695 const Standard_Real last1,
698 const Handle(Geom_Plane)& aPlane,
699 Standard_Boolean& isOnPlane)
701 isOnPlane = Standard_True;
702 const Standard_Integer NodeNumber = 20;
703 Standard_Real Delta = (last1 - first1) / (NodeNumber - 1);
704 if (Delta <= Precision::PConfusion())
706 Delta = last1 - first1;
709 gp_Pnt CurPnt(0.0, 0.0, 0.0);
710 Standard_Real CurPar = first1;
711 for (Standard_Integer i = 1; i <= NodeNumber; i++)
713 CurPnt = aCurve->Value( CurPar );
714 if (aPlane->Pln().SquareDistance( CurPnt ) > SquareTolerance)
716 isOnPlane = Standard_False;
722 if (!Precision::IsInfinite(first1) && !Precision::IsInfinite(last1))
724 FirstPnt1 = aCurve->Value (first1);
725 LastPnt1 = aCurve->Value (last1);
730 Handle(Geom_Curve) aGeomCurve = GeomProjLib::ProjectOnPlane (aCurve,
732 aPlane->Pln().Axis().Direction(),
735 if (aCurve->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
737 aCurve = ((Handle(Geom_TrimmedCurve)&) aCurve)->BasisCurve();
739 if (! Precision::IsInfinite(first1) && ! Precision::IsInfinite(last1))
741 FirstPnt1 = AIS::ProjectPointOnPlane( FirstPnt1, aPlane->Pln() );
742 LastPnt1 = AIS::ProjectPointOnPlane( LastPnt1, aPlane->Pln() );
745 return Standard_True;
748 //=======================================================================
749 //function : ComputeGeometry
750 //purpose : computes the point corresponding to the vertex <aVertex>
751 // in the plane <aPlane>. If the vertex is already in the plane
752 // <isOnPlane>, <isOnPlane> = true.
753 // <point> is the projected vertex in the plane.
754 //=======================================================================
755 Standard_Boolean AIS::ComputeGeometry(const TopoDS_Vertex& aVertex,
757 const Handle(Geom_Plane)& aPlane,
758 Standard_Boolean& isOnPlane)
760 point = BRep_Tool::Pnt(aVertex);
761 isOnPlane = aPlane->Pln().Contains(point, Precision::Confusion());
763 point = AIS::ProjectPointOnPlane( point, aPlane->Pln() );
765 return Standard_True;
768 //=======================================================================
769 //function : GetPlaneFromFace
771 // Returns type of surface which can be Plane or OtherSurface
772 //=======================================================================
773 Standard_Boolean AIS::GetPlaneFromFace(const TopoDS_Face& aFace,
775 Handle( Geom_Surface )& aSurf,
776 AIS_KindOfSurface & aSurfType,
777 Standard_Real & Offset)
780 Standard_Boolean Result = Standard_False;
781 BRepAdaptor_Surface surf1( aFace );
782 Handle( Adaptor3d_HSurface ) surf2;
783 Standard_Boolean isOffset = Standard_False;
785 if (surf1.GetType() == GeomAbs_OffsetSurface)
787 // Extracting Basis Surface
788 surf2 = surf1.BasisSurface();
789 isOffset = Standard_True;
792 surf2 = new BRepAdaptor_HSurface( surf1 );
794 aSurf = surf1.Surface().Surface();
795 // aSurf->Transform(surf1.Trsf()) ;
796 aSurf = Handle( Geom_Surface )::DownCast( aSurf->Transformed( surf1.Trsf() ) );
798 if (surf2->GetType() == GeomAbs_Plane)
800 aPlane = surf2->Plane();
801 aSurfType = AIS_KOS_Plane;
803 Result = Standard_True;
806 else if (surf2->GetType() == GeomAbs_SurfaceOfExtrusion)
808 Handle( Adaptor3d_HCurve ) BasisCurve = surf2->BasisCurve();
809 gp_Dir ExtrusionDir = surf2->Direction();
810 if (BasisCurve->GetType() == GeomAbs_Line)
812 gp_Lin BasisLine = BasisCurve->Line();
813 gp_Dir LineDir = BasisLine.Direction();
814 gp_Pnt LinePos = BasisLine.Location();
815 gp_Pln thePlane( LinePos, LineDir ^ ExtrusionDir);
817 aSurfType = AIS_KOS_Plane;
819 Result = Standard_True;
823 if (Result == Standard_True && isOffset)
825 aSurf = (Handle( Geom_OffsetSurface )::DownCast( aSurf ))->Surface();
826 aPlane = (Handle( Geom_Plane )::DownCast( aSurf ))->Pln();
829 if (Result == Standard_False)
833 Handle( Standard_Type ) TheType = aSurf->DynamicType();
834 if (TheType == STANDARD_TYPE(Geom_CylindricalSurface) ||
835 TheType == STANDARD_TYPE(Geom_ConicalSurface) ||
836 TheType == STANDARD_TYPE(Geom_SphericalSurface) ||
837 TheType == STANDARD_TYPE(Geom_ToroidalSurface))
839 aSurf = (Handle( Geom_OffsetSurface )::DownCast( aSurf ))->Surface();
844 Offset = (Handle( Geom_OffsetSurface )::DownCast( aSurf ))->Offset();
845 aSurf = (Handle( Geom_OffsetSurface )::DownCast( aSurf ))->BasisSurface();
848 Handle( Standard_Type ) TheType = aSurf->DynamicType();
849 if (TheType == STANDARD_TYPE(Geom_CylindricalSurface))
850 aSurfType = AIS_KOS_Cylinder;
851 else if (TheType == STANDARD_TYPE(Geom_ConicalSurface))
852 aSurfType = AIS_KOS_Cone;
853 else if (TheType == STANDARD_TYPE(Geom_SphericalSurface))
854 aSurfType = AIS_KOS_Sphere;
855 else if (TheType == STANDARD_TYPE(Geom_ToroidalSurface))
856 aSurfType = AIS_KOS_Torus;
857 else if (TheType == STANDARD_TYPE(Geom_SurfaceOfRevolution))
858 aSurfType = AIS_KOS_Revolution;
859 else if (TheType == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))
860 aSurfType = AIS_KOS_Extrusion;
862 aSurfType = AIS_KOS_OtherSurface;
868 //=======================================================================
869 //function : ProjectPointOnPlane
871 //=======================================================================
873 gp_Pnt AIS::ProjectPointOnPlane( const gp_Pnt & aPoint, const gp_Pln & aPlane )
875 gp_Vec aVec( aPlane.Location(), aPoint );
876 gp_Vec Normal = aPlane.Axis().Direction();
877 Normal = (aVec * Normal) * Normal;
879 return ( aPoint.Translated( -Normal ) );
882 //=======================================================================
883 //function : ProjectPointOnLine
885 //=======================================================================
887 gp_Pnt AIS::ProjectPointOnLine( const gp_Pnt & aPoint, const gp_Lin & aLine )
889 gp_XYZ LinLoc = aLine.Location().XYZ();
890 gp_XYZ LinDir = aLine.Direction().XYZ();
891 Standard_Real Parameter = (aPoint.XYZ() - LinLoc) * LinDir;
892 gp_Pnt Result( LinLoc + Parameter * LinDir );
896 //=======================================================================
897 //function : InitFaceLength
899 //=======================================================================
900 void AIS::InitFaceLength (const TopoDS_Face& aFace,
902 Handle(Geom_Surface) & aSurface,
903 AIS_KindOfSurface & aSurfaceType,
904 Standard_Real & anOffset)
906 AIS::GetPlaneFromFace( aFace, aPlane, aSurface, aSurfaceType, anOffset );
908 if (Abs( anOffset ) > Precision::Confusion())
910 aSurface = new Geom_OffsetSurface( aSurface, anOffset );
916 //=======================================================================
917 //function : InitAngleBetweenPlanarFaces
919 //=======================================================================
920 Standard_Boolean AIS::InitAngleBetweenPlanarFaces (const TopoDS_Face& theFirstFace,
921 const TopoDS_Face& theSecondFace,
923 gp_Pnt & theFirstAttach,
924 gp_Pnt & theSecondAttach,
925 const Standard_Boolean theIsFirstPointSet)
927 Handle(Geom_Plane) aFirstPlane = Handle(Geom_Plane)::DownCast (BRep_Tool::Surface (theFirstFace));
928 Handle(Geom_Plane) aSecondPlane = Handle(Geom_Plane)::DownCast (BRep_Tool::Surface (theSecondFace));
930 GeomAPI_IntSS aPlaneIntersector (aFirstPlane, aSecondPlane, Precision::Confusion());
932 // Fails if two planes haven't only one intersection line.
933 if (!aPlaneIntersector.IsDone())
935 return Standard_False;
938 if (aPlaneIntersector.NbLines() != 1)
940 return Standard_False;
943 // Get intersect line.
944 Handle(Geom_Curve) anIntersectCurve = aPlaneIntersector.Line (1);
946 Handle(Geom_Line) anIntersectLine = Handle(Geom_Line)::DownCast (anIntersectCurve);
948 if (anIntersectLine.IsNull())
950 return Standard_False;
953 gp_Lin anIntersectLin = anIntersectLine->Lin();
955 gp_Pnt aFirstCenter, aSecondCenter;
956 Standard_Real anU1Min, anU1Max, aV1Min, aV1Max;
957 Standard_Real anU2Min, anU2Max, aV2Min, aV2Max;
959 BRepTools::UVBounds (theFirstFace, anU1Min, anU1Max, aV1Min, aV1Max);
960 BRepTools::UVBounds (theSecondFace, anU2Min, anU2Max, aV2Min, aV2Max);
962 // Get first and second attach.
963 if (theIsFirstPointSet)
965 GeomAPI_ProjectPointOnSurf aProjector (theFirstAttach, aFirstPlane);
966 if (!aProjector.IsDone())
968 return Standard_False;
971 aFirstCenter = aProjector.Point (1);
975 aFirstCenter = aFirstPlane->Value ((anU1Min + anU1Max) * 0.5, (aV1Min + aV1Max) * 0.5);
978 aSecondCenter = aSecondPlane->Value ((anU2Min + anU2Max) * 0.5, (aV2Min + aV2Max) * 0.5);
980 GeomAPI_ProjectPointOnCurve aProj (aFirstCenter, anIntersectCurve);
981 theCenter = aProj.NearestPoint();
983 gp_Vec aFirstNormal = anIntersectLin.Direction() ^ aFirstPlane->Pln().Axis().Direction();
984 if (aFirstNormal * gp_Vec (theCenter, aFirstCenter) < 0.0)
986 aFirstNormal.Reverse();
988 theFirstAttach = theCenter.Translated (aFirstNormal);
990 gp_Vec aSecondNormal = anIntersectLin.Direction() ^ aSecondPlane->Pln().Axis().Direction();
991 if (aSecondNormal * gp_Vec (theCenter, aSecondCenter) < 0.0)
993 aSecondNormal.Reverse();
995 theSecondAttach = theCenter.Translated (aSecondNormal);
997 return Standard_True;
1000 //=======================================================================
1001 //function : InitAngleBetweenCurvilinearFaces
1003 //=======================================================================
1004 Standard_Boolean AIS::InitAngleBetweenCurvilinearFaces (const TopoDS_Face& theFirstFace,
1005 const TopoDS_Face& theSecondFace,
1006 const AIS_KindOfSurface theFirstSurfType,
1007 const AIS_KindOfSurface theSecondSurfType,
1009 gp_Pnt& theFirstAttach,
1010 gp_Pnt& theSecondAttach,
1011 const Standard_Boolean theIsFirstPointSet)
1013 Handle(Geom_Surface) aFirstSurf = BRep_Tool::Surface (theFirstFace);
1014 Handle(Geom_Surface) aSecondSurf = BRep_Tool::Surface (theSecondFace);
1016 // Find intersection curve between two surfaces.
1017 GeomAPI_IntSS aSurfaceIntersector (aFirstSurf, aSecondSurf, Precision::Confusion());
1019 // Fails if two planes haven't only one intersection line.
1020 if (!aSurfaceIntersector.IsDone())
1022 return Standard_False;
1025 if (aSurfaceIntersector.NbLines() != 1)
1027 return Standard_False;
1030 // Get intersect line.
1031 Handle(Geom_Curve) anIntersectCurve = aSurfaceIntersector.Line (1);
1033 Handle(Geom_Line) aFirstLine, aSecondLine;
1034 Standard_Real aFirstU = 0.0;
1035 Standard_Real aFirstV = 0.0;
1037 if (theIsFirstPointSet)
1039 GeomAPI_ProjectPointOnSurf aProjector (theFirstAttach, aFirstSurf);
1040 if (!aProjector.IsDone())
1042 return Standard_False;
1045 theFirstAttach = aProjector.Point (1);
1049 theFirstAttach = aFirstSurf->Value (aFirstU, aFirstV);
1052 aFirstLine = Handle(Geom_Line)::DownCast (aFirstSurf->UIso (aFirstU));
1054 if (theSecondSurfType == AIS_KOS_Cylinder)
1056 Handle(Geom_CylindricalSurface) aCylinder = Handle(Geom_CylindricalSurface)::DownCast (aSecondSurf);
1058 Standard_Real aSecondU = aCylinder->Cylinder().XAxis().Direction().Angle(
1059 gce_MakeDir (ProjectPointOnLine (theFirstAttach,
1060 gp_Lin (aCylinder->Cylinder().Axis())),
1063 aSecondLine = Handle(Geom_Line)::DownCast (aCylinder->UIso (aSecondU));
1065 else if (theSecondSurfType == AIS_KOS_Cone)
1067 Handle(Geom_ConicalSurface) aCone = Handle(Geom_ConicalSurface)::DownCast (aSecondSurf);
1069 gp_Dir anXdirection = aCone->Cone().XAxis().Direction();
1071 gp_Dir aToFirstAttach = gce_MakeDir (ProjectPointOnLine (theFirstAttach,
1072 gp_Lin (aCone->Cone().Axis())),
1075 Standard_Real aSecondU = anXdirection.Angle (aToFirstAttach);
1078 if (!anXdirection.IsEqual (aToFirstAttach, Precision::Angular()) &&
1079 !anXdirection.IsOpposite (aToFirstAttach, Precision::Angular()) &&
1080 (anXdirection ^ aToFirstAttach) * aCone->Cone().Axis().Direction() < 0.0)
1082 aSecondU = 2*M_PI - aSecondU;
1084 aSecondLine = Handle( Geom_Line )::DownCast (aCone->UIso(aSecondU));
1088 return Standard_False;
1091 // If angle can be computed between two lines.
1092 if (!(aFirstLine->Lin().Direction().IsEqual (aSecondLine->Lin().Direction(), Precision::Angular() )) &&
1093 !(aFirstLine->Lin().Direction().IsOpposite (aSecondLine->Lin().Direction(), Precision::Angular())))
1095 GeomAPI_ExtremaCurveCurve anIntersector (aFirstLine, aSecondLine);
1096 anIntersector.Points (1, theCenter, theCenter);
1098 // Move theFirstAttach on aFirstLine if it is on theCenter.
1099 if (theCenter.SquareDistance(theFirstAttach ) <= SquareTolerance)
1101 gp_Vec aDir (aFirstLine->Lin().Direction());
1102 theFirstAttach = theCenter.Translated (aDir);
1104 // theFirstAttach should be on theFirstSurf.
1105 Standard_Real anU, aV;
1106 if (theFirstSurfType == AIS_KOS_Cylinder)
1108 ElSLib::Parameters ((Handle(Geom_CylindricalSurface)::DownCast (aFirstSurf))->Cylinder(),
1109 theFirstAttach, anU, aV);
1111 theFirstAttach = ElSLib::Value (aFirstU, aV,
1112 (Handle( Geom_CylindricalSurface )::DownCast (aFirstSurf))->Cylinder() );
1114 else if (theFirstSurfType == AIS_KOS_Cone)
1116 ElSLib::Parameters ((Handle(Geom_ConicalSurface)::DownCast (aFirstSurf))->Cone(),
1117 theFirstAttach, anU, aV);
1118 theFirstAttach = ElSLib::Value (aFirstU, aV,
1119 (Handle(Geom_ConicalSurface)::DownCast (aFirstSurf))->Cone());
1123 return Standard_False;
1127 // Find theSecondAttach
1128 GeomAPI_ProjectPointOnSurf aProjector (theFirstAttach, aSecondSurf);
1129 if (!aProjector.IsDone())
1131 return Standard_False;
1133 Quantity_Parameter anU, aV;
1134 aProjector.LowerDistanceParameters (anU, aV);
1135 theSecondAttach = aSecondSurf->Value (anU, aV);
1137 else // aFirstLine and aSecondLine are coincident
1139 gp_Vec aDir (aFirstLine->Lin().Direction());
1140 theFirstAttach = theCenter.Translated (aDir);
1141 theSecondAttach = theCenter.Translated (-aDir);
1143 return Standard_True;
1146 //=======================================================================
1147 //function : ComputeLengthBetweenCurvilinearFaces
1149 //=======================================================================
1150 void AIS::InitLengthBetweenCurvilinearFaces (const TopoDS_Face& theFirstFace,
1151 const TopoDS_Face& theSecondFace,
1152 Handle(Geom_Surface)& theFirstSurf,
1153 Handle(Geom_Surface)& theSecondSurf,
1154 gp_Pnt& theFirstAttach,
1155 gp_Pnt& theSecondAttach,
1156 gp_Dir& theDirOnPlane)
1158 GeomAPI_ProjectPointOnSurf aProjector;
1159 Quantity_Parameter aPU, aPV;
1161 TopExp_Explorer anExplorer (theFirstFace, TopAbs_VERTEX);
1163 theFirstAttach = BRep_Tool::Pnt (TopoDS::Vertex (anExplorer.Current()));
1164 aProjector.Init (theFirstAttach, theFirstSurf);
1166 theFirstAttach = aProjector.NearestPoint();
1167 aProjector.LowerDistanceParameters (aPU, aPV);
1170 theFirstSurf->D1 (aPU, aPV, theFirstAttach, aD1U, aD1V);
1172 if (aD1U.SquareMagnitude() <= SquareTolerance || aD1V.SquareMagnitude() <= SquareTolerance)
1174 theFirstAttach = AIS::Farest (theFirstFace, theFirstAttach);
1175 aProjector.Init (theFirstAttach, theFirstSurf);
1176 aProjector.LowerDistanceParameters (aPU, aPV);
1177 theFirstSurf->D1 (aPU, aPV, theFirstAttach, aD1U, aD1V);
1183 theDirOnPlane = gp_Dir (aD1U);
1185 gp_Dir aFirstSurfN = gp_Dir (aD1U ^ aD1V);
1187 aProjector.Init (theFirstAttach, theSecondSurf);
1189 Standard_Integer aBestPointIndex = 0;
1190 Quantity_Length aMinDist = RealLast();
1193 for (Standard_Integer aPointIt = 1; aPointIt <= aProjector.NbPoints(); aPointIt++)
1195 aProjector.Parameters (aPointIt, aPU, aPV);
1197 theSecondSurf->D1 (aPU, aPV, theSecondAttach, aD1U, aD1V);
1199 aLocalDir = aD1U.SquareMagnitude() <= SquareTolerance || aD1V.SquareMagnitude() <= SquareTolerance
1200 ? gp_Dir (gp_Vec (theFirstAttach, aProjector.Point (aPointIt)))
1201 : gp_Dir (aD1U ^ aD1V);
1203 if (aFirstSurfN.IsParallel (aLocalDir, Precision::Angular()) && aProjector.Distance (aPointIt) < aMinDist)
1205 aBestPointIndex = aPointIt;
1206 aMinDist = aProjector.Distance (aPointIt);
1210 if (aBestPointIndex == 0)
1212 theSecondAttach = theFirstAttach;
1216 theSecondAttach = aProjector.Point (aBestPointIndex);
1217 aProjector.Parameters (aBestPointIndex, aPU, aPV);
1219 // Now there is projection of FirstAttach onto SecondSurf in aProjector
1220 BRepTopAdaptor_FClass2d aClassifier (theSecondFace, Precision::Confusion());
1222 TopAbs_State aState =
1223 aClassifier.Perform (gp_Pnt2d (aPU, aPV), theSecondSurf->IsUPeriodic() || theSecondSurf->IsVPeriodic());
1225 if (aState == TopAbs_OUT || aState == TopAbs_UNKNOWN)
1227 theSecondAttach = AIS::Nearest (theSecondFace, theSecondAttach);
1232 gp_Pnt AIS::TranslatePointToBound( const gp_Pnt & aPoint, const gp_Dir & aDir, const Bnd_Box & aBndBox )
1234 if (aBndBox.IsOut( aPoint ))
1238 gp_Pnt Result(0.0,0.0,0.0);
1239 TColStd_Array2OfReal Bound( 1, 3, 1, 2 );
1240 TColStd_Array1OfReal Origin( 1, 3 );
1241 TColStd_Array1OfReal Dir( 1, 3 );
1244 aBndBox.Get( Bound(1,1), Bound(2,1), Bound(3,1), Bound(1,2), Bound(2,2), Bound(3,2) );
1245 aPoint.Coord( Origin(1), Origin(2), Origin(3) );
1246 aDir.Coord( Dir(1), Dir(2), Dir(3) );
1248 Bnd_Box EnlargedBox = aBndBox;
1249 EnlargedBox.Enlarge( aBndBox.GetGap() + Precision::Confusion() );
1251 Standard_Boolean IsFound = Standard_False;
1252 for (Standard_Integer i = 1; i <= 3; i++)
1254 if (Abs( Dir( i ) ) <= gp::Resolution())
1256 for (Standard_Integer j = 1; j <= 2; j++)
1258 t = (Bound( i, j ) - Origin( i )) / Dir( i );
1261 Result = aPoint.Translated( gp_Vec( aDir ) * t );
1262 if (! EnlargedBox.IsOut( Result ))
1264 IsFound = Standard_True;
1275 //=======================================================================
1276 //function : InDomain
1278 //=======================================================================
1280 Standard_Boolean AIS::InDomain(const Standard_Real fpar,
1281 const Standard_Real lpar,
1282 const Standard_Real para)
1286 return ((para >= fpar) && (para <= lpar));
1287 else { // fpar > lpar
1288 Standard_Real delta = 2*M_PI-fpar;
1289 Standard_Real lp, par, fp;
1292 while(lp > 2*M_PI) lp-=2*M_PI;
1293 while(par > 2*M_PI) par-=2*M_PI;
1295 return ((par >= fp) && (par <= lp));
1299 if (para >= (fpar+2*M_PI)) return Standard_True;
1300 if (para <= lpar) return Standard_True;
1301 return Standard_False;
1304 //=======================================================================
1305 //function : DistanceFromApex
1306 //purpose : calculates parametric length arc of ellipse
1307 //=======================================================================
1309 Standard_Real AIS::DistanceFromApex(const gp_Elips & elips,
1310 const gp_Pnt & Apex,
1311 const Standard_Real par)
1314 Standard_Real parApex = ElCLib::Parameter ( elips, Apex );
1315 if(parApex == 0.0 || parApex == M_PI)
1317 if(parApex == 0.0) //pos Apex
1318 dist = (par < M_PI) ? par : (2*M_PI - par);
1320 dist = (par < M_PI) ? ( M_PI - par) : ( par - M_PI );
1324 if(parApex == M_PI / 2) //pos Apex
1326 if(par <= parApex + M_PI && par > parApex) // 3/2*M_PI < par < M_PI/2
1327 dist = par - parApex;
1330 if(par > parApex + M_PI) // 3/2*M_PI < par < 2*M_PI
1331 dist = 2*M_PI - par + parApex;
1333 dist = parApex - par;
1336 else //neg Apex == 3/2*M_PI
1338 if(par <= parApex && par >= M_PI/2) // M_PI/2 < par < 3/2*M_PI
1339 dist = parApex - par;
1342 if(par > parApex) // 3/2*M_PI < par < 2*M_PI
1343 dist = par - parApex;
1345 dist = par + M_PI/2; // 0 < par < M_PI/2
1352 //=======================================================================
1353 //function : NearestApex
1355 //=======================================================================
1357 gp_Pnt AIS::NearestApex(const gp_Elips & elips,
1358 const gp_Pnt & pApex,
1359 const gp_Pnt & nApex,
1360 const Standard_Real fpara,
1361 const Standard_Real lpara,
1362 Standard_Boolean & IsInDomain)
1364 Standard_Real parP, parN;
1365 gp_Pnt EndOfArrow(0.0,0.0,0.0);
1366 IsInDomain = Standard_True;
1367 parP = ElCLib::Parameter ( elips, pApex );
1368 if(InDomain(fpara, lpara, parP)) EndOfArrow = pApex;
1371 parN = ElCLib::Parameter ( elips, nApex );
1372 if(InDomain(fpara, lpara, parN)) EndOfArrow = nApex;
1374 IsInDomain = Standard_False;
1375 Standard_Real posd = Min(DistanceFromApex (elips,pApex, fpara),
1376 DistanceFromApex (elips,pApex, lpara));
1377 Standard_Real negd = Min(DistanceFromApex (elips,nApex, fpara),
1378 DistanceFromApex (elips,nApex, lpara));
1388 //=======================================================================
1389 //function : ComputeProjEdgePresentation
1391 //=======================================================================
1393 void AIS::ComputeProjEdgePresentation (const Handle(Prs3d_Presentation)& aPresentation,
1394 const Handle(Prs3d_Drawer)& aDrawer,
1395 const TopoDS_Edge& anEdge,
1396 const Handle(Geom_Curve)& ProjCurve,
1397 const gp_Pnt& FirstP,
1398 const gp_Pnt& LastP,
1399 const Quantity_NameOfColor aColor,
1400 const Standard_Real aWidth,
1401 const Aspect_TypeOfLine aProjTOL,
1402 const Aspect_TypeOfLine aCallTOL)
1404 if (!aDrawer->HasOwnWireAspect()){
1405 aDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aProjTOL,2.));}
1408 // const Handle(Prs3d_LineAspect)& li = aDrawer->WireAspect();
1409 Handle(Prs3d_LineAspect) li = aDrawer->WireAspect();
1411 li->SetColor(aColor);
1412 li->SetTypeOfLine(aProjTOL);
1413 li->SetWidth(aWidth);
1416 Standard_Real pf, pl;
1417 TopLoc_Location loc;
1418 Handle(Geom_Curve) curve;
1419 Standard_Boolean isInfinite;
1420 curve = BRep_Tool::Curve(anEdge,loc,pf,pl);
1421 isInfinite = (Precision::IsInfinite(pf) || Precision::IsInfinite(pl));
1425 // Calculate presentation of the edge
1426 if (ProjCurve->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
1428 // const Handle(Geom_Line) & gl = (Handle(Geom_Line)&) ProjCurve;
1429 Handle(Geom_Line) gl = (Handle(Geom_Line)&) ProjCurve;
1432 pf = ElCLib::Parameter(gl->Lin(),FirstP);
1433 pl = ElCLib::Parameter(gl->Lin(),LastP);
1434 BRepBuilderAPI_MakeEdge MakEd(gl->Lin(), pf, pl);
1438 BRepBuilderAPI_MakeEdge MakEd(gl->Lin());
1442 else if (ProjCurve->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
1444 // const Handle(Geom_Circle) & gc = (Handle(Geom_Circle)&) ProjCurve;
1445 Handle(Geom_Circle) gc = (Handle(Geom_Circle)&) ProjCurve;
1447 pf = ElCLib::Parameter(gc->Circ(),FirstP);
1448 pl = ElCLib::Parameter(gc->Circ(),LastP);
1449 BRepBuilderAPI_MakeEdge MakEd(gc->Circ(),pf, pl);
1452 StdPrs_WFDeflectionShape::Add(aPresentation, E, aDrawer);
1454 //Calculate the presentation of line connections
1455 aDrawer->WireAspect()->SetTypeOfLine(aCallTOL);
1457 gp_Pnt ppf(0.0,0.0,0.0), ppl(0.0,0.0,0.0);
1458 ppf = BRep_Tool::Pnt( TopExp::FirstVertex(TopoDS::Edge(anEdge)));
1459 ppl = BRep_Tool::Pnt( TopExp::LastVertex(TopoDS::Edge(anEdge)));
1462 if (FirstP.SquareDistance( ppf ) > SquareTolerance)
1464 BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf);
1465 StdPrs_WFDeflectionShape::Add(aPresentation, MakEd1.Edge(), aDrawer);
1469 BRepBuilderAPI_MakeVertex MakVert1( FirstP );
1470 StdPrs_WFDeflectionShape::Add(aPresentation, MakVert1.Vertex(), aDrawer);
1472 if (LastP.SquareDistance( ppl ) > SquareTolerance)
1474 BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl);
1475 StdPrs_WFDeflectionShape::Add(aPresentation, MakEd2.Edge(), aDrawer);
1479 BRepBuilderAPI_MakeVertex MakVert2( LastP );
1480 StdPrs_WFDeflectionShape::Add(aPresentation, MakVert2.Vertex(), aDrawer);
1483 BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf);
1484 StdPrs_WFDeflectionShape::Add(aPresentation, MakEd1.Edge(), aDrawer);
1485 BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl);
1486 StdPrs_WFDeflectionShape::Add(aPresentation, MakEd2.Edge(), aDrawer);
1491 //=======================================================================
1492 //function : ComputeProjVertexPresentation
1494 //=======================================================================
1496 void AIS::ComputeProjVertexPresentation (const Handle( Prs3d_Presentation )& aPresentation,
1497 const Handle( Prs3d_Drawer )& aDrawer,
1498 const TopoDS_Vertex& aVertex,
1499 const gp_Pnt& ProjPoint,
1500 const Quantity_NameOfColor aColor,
1501 const Standard_Real aWidth,
1502 const Aspect_TypeOfMarker aProjTOM,
1503 const Aspect_TypeOfLine aCallTOL)
1505 if (!aDrawer->HasOwnPointAspect()){
1506 aDrawer->SetPointAspect(new Prs3d_PointAspect(aProjTOM, aColor,1));}
1509 // const Handle(Prs3d_PointAspect)& pa = aDrawer->PointAspect();
1510 Handle(Prs3d_PointAspect) pa = aDrawer->PointAspect();
1512 pa->SetColor(aColor);
1513 pa->SetTypeOfMarker(aProjTOM);
1516 // calculate the projection
1517 StdPrs_Point::Add(aPresentation, new Geom_CartesianPoint(ProjPoint), aDrawer);
1519 if (!aDrawer->HasOwnWireAspect()){
1520 aDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aCallTOL,2.));}
1523 // const Handle(Prs3d_LineAspect)& li = aDrawer->WireAspect();
1524 Handle(Prs3d_LineAspect) li = aDrawer->WireAspect();
1526 li->SetColor(aColor);
1527 li->SetTypeOfLine(aCallTOL);
1528 li->SetWidth(aWidth);
1531 // If the points are not mixed...
1532 if (!ProjPoint.IsEqual (BRep_Tool::Pnt(aVertex),Precision::Confusion())) {
1533 // calculate the lines of recall
1534 BRepBuilderAPI_MakeEdge MakEd(ProjPoint,BRep_Tool::Pnt(aVertex));
1535 StdPrs_WFDeflectionShape::Add(aPresentation, MakEd.Edge(), aDrawer);