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>
21 #include <Bnd_Box.hxx>
22 #include <BRep_Tool.hxx>
23 #include <BRepAdaptor_Curve.hxx>
24 #include <BRepAdaptor_HSurface.hxx>
25 #include <BRepAdaptor_Surface.hxx>
26 #include <BRepBuilderAPI_MakeEdge.hxx>
27 #include <BRepBuilderAPI_MakeVertex.hxx>
28 #include <BRepTools.hxx>
29 #include <BRepTopAdaptor_FClass2d.hxx>
32 #include <GccEnt_QualifiedLin.hxx>
33 #include <gce_MakeDir.hxx>
34 #include <gce_MakeLin.hxx>
35 #include <Geom2d_Circle.hxx>
36 #include <Geom_CartesianPoint.hxx>
37 #include <Geom_Circle.hxx>
38 #include <Geom_ConicalSurface.hxx>
39 #include <Geom_Curve.hxx>
40 #include <Geom_CylindricalSurface.hxx>
41 #include <Geom_Ellipse.hxx>
42 #include <Geom_Line.hxx>
43 #include <Geom_OffsetSurface.hxx>
44 #include <Geom_Plane.hxx>
45 #include <Geom_SphericalSurface.hxx>
46 #include <Geom_Surface.hxx>
47 #include <Geom_SurfaceOfLinearExtrusion.hxx>
48 #include <Geom_SurfaceOfRevolution.hxx>
49 #include <Geom_ToroidalSurface.hxx>
50 #include <Geom_TrimmedCurve.hxx>
51 #include <GeomAPI_ExtremaCurveCurve.hxx>
52 #include <GeomAPI_IntSS.hxx>
53 #include <GeomAPI_ProjectPointOnCurve.hxx>
54 #include <GeomAPI_ProjectPointOnSurf.hxx>
55 #include <GeomLib.hxx>
56 #include <GeomProjLib.hxx>
60 #include <gp_Elips.hxx>
66 #include <Precision.hxx>
67 #include <Prs3d_LineAspect.hxx>
68 #include <Prs3d_PointAspect.hxx>
69 #include <Prs3d_Presentation.hxx>
70 #include <StdPrs_Point.hxx>
71 #include <StdPrs_WFShape.hxx>
72 #include <TColStd_Array1OfReal.hxx>
73 #include <TColStd_Array2OfReal.hxx>
75 #include <TopExp_Explorer.hxx>
77 #include <TopoDS_Edge.hxx>
78 #include <TopoDS_Face.hxx>
79 #include <TopoDS_Shape.hxx>
80 #include <TopoDS_Vertex.hxx>
81 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
83 const Standard_Real SquareTolerance = Precision::SquareConfusion();
85 //=======================================================================
88 //=======================================================================
89 gp_Pnt AIS::Nearest(const TopoDS_Shape& ashape, const gp_Pnt& apoint)
91 Standard_Real dist2 = RealLast();
92 Standard_Real curdist2;
93 gp_Pnt result(0.0,0.0,0.0);
94 gp_Pnt curpnt(0.0,0.0,0.0);
95 TopExp_Explorer explo(ashape,TopAbs_VERTEX);
98 curpnt = BRep_Tool::Pnt(TopoDS::Vertex(explo.Current()));
99 curdist2 = apoint.SquareDistance(curpnt);
100 if (curdist2 < dist2)
110 //=======================================================================
112 //purpose : For <thePoint> finds the nearest point on <theLine>.
113 //=======================================================================
114 gp_Pnt AIS::Nearest (const gp_Lin& theLine, const gp_Pnt& thePoint)
116 Handle(Geom_Line) aLine = new Geom_Line (theLine);
118 GeomAPI_ProjectPointOnCurve aPointProj (thePoint, aLine);
119 return aPointProj.Point (1);
122 //=======================================================================
124 //purpose : For the given point finds nearest point on the curve,
125 // return TRUE if found point is belongs to curve
126 // and FALSE otherwise.
127 //=======================================================================
128 Standard_Boolean AIS::Nearest (const Handle(Geom_Curve)& theCurve,
129 const gp_Pnt& thePoint,
130 const gp_Pnt& theFirstPoint,
131 const gp_Pnt& theLastPoint,
132 gp_Pnt& theNearestPoint)
134 GeomAPI_ProjectPointOnCurve aPointProj (thePoint, theCurve);
135 theNearestPoint = theCurve->Value (aPointProj.LowerDistanceParameter());
137 Standard_Real aLength = theFirstPoint.Distance (theLastPoint);
139 if (theNearestPoint.Distance (theFirstPoint) > aLength
140 || theNearestPoint.Distance (theLastPoint) >aLength)
142 return Standard_False;
145 return Standard_True;
148 //=======================================================================
151 //=======================================================================
152 gp_Pnt AIS::Farest( const TopoDS_Shape& aShape, const gp_Pnt& aPoint )
154 Standard_Real MaxDist2 = 0.0e0, curdist2;
155 gp_Pnt Result(0.0,0.0,0.0);
156 gp_Pnt curpnt(0.0,0.0,0.0);
157 TopExp_Explorer Explo( aShape, TopAbs_VERTEX );
158 for (; Explo.More(); Explo.Next())
160 curpnt = BRep_Tool::Pnt( TopoDS::Vertex( Explo.Current() ) );
161 curdist2 = aPoint.SquareDistance( curpnt );
162 if (curdist2 > MaxDist2)
172 //=======================================================================
173 //function : ComputeGeometry
174 //purpose : for line, circle, ellipse.
175 //=======================================================================
176 Standard_Boolean AIS::ComputeGeometry (const TopoDS_Edge& theEdge,
177 Handle(Geom_Curve)& theCurve,
181 TopLoc_Location anEdgeLoc;
182 Standard_Real aFirst, aLast;
183 theCurve = BRep_Tool::Curve (theEdge, anEdgeLoc, aFirst, aLast);
184 if (theCurve.IsNull())
186 return Standard_False;
189 if (!anEdgeLoc.IsIdentity())
191 Handle(Geom_Geometry) aGeometry = theCurve->Transformed (anEdgeLoc.Transformation());
192 theCurve = Handle(Geom_Curve)::DownCast (aGeometry);
195 if (theCurve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
197 theCurve = Handle(Geom_TrimmedCurve)::DownCast (theCurve)->BasisCurve();
200 if (theCurve->IsInstance (STANDARD_TYPE (Geom_Line)))
202 Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast (theCurve);
203 theFirstPnt = ElCLib::Value (aFirst, aLine->Lin());
204 theLastPnt = ElCLib::Value (aLast, aLine->Lin());
206 else if (theCurve->IsInstance (STANDARD_TYPE (Geom_Circle)))
208 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast (theCurve);
210 theFirstPnt = ElCLib::Value (aFirst, aCirc->Circ());
211 theLastPnt = ElCLib::Value (aLast, aCirc->Circ());
213 else if (theCurve->IsInstance (STANDARD_TYPE (Geom_Ellipse)))
215 Handle(Geom_Ellipse) anEllipse = Handle(Geom_Ellipse)::DownCast (theCurve);
216 theFirstPnt = ElCLib::Value (aFirst, anEllipse->Elips());
217 theLastPnt = ElCLib::Value (aLast, anEllipse->Elips());
221 return Standard_False;
224 return Standard_True;
227 //=======================================================================
228 //function : ComputeGeometry
229 //purpose : for line, circle, ellipse.
230 //=======================================================================
231 Standard_Boolean AIS::ComputeGeometry (const TopoDS_Edge& theEdge,
232 Handle(Geom_Curve)& theCurve,
235 Standard_Boolean& theIsInfinite)
237 Standard_Real aFirst, aLast;
239 BRepAdaptor_Curve anAdaptor (theEdge);
241 theCurve = Handle(Geom_Curve)::DownCast
242 (anAdaptor.Curve().Curve()->Transformed (anAdaptor.Trsf()));
244 if (theCurve.IsNull())
246 return Standard_False;
249 aFirst = anAdaptor.FirstParameter();
250 aLast = anAdaptor.LastParameter();
252 theIsInfinite = (Precision::IsInfinite (aFirst) || Precision::IsInfinite (aLast));
254 if (theCurve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
256 theCurve = Handle(Geom_TrimmedCurve)::DownCast (theCurve)->BasisCurve();
261 theFirstPnt = theCurve->Value (aFirst);
262 theLastPnt = theCurve->Value (aLast);
266 theFirstPnt = gp::Origin();
267 theLastPnt = gp::Origin();
270 return Standard_True;
273 //=======================================================================
274 //function : ComputeGeometry
276 //=======================================================================
278 Standard_Boolean AIS::ComputeGeometry (const TopoDS_Edge& theEdge,
279 Handle(Geom_Curve)& theCurve,
282 Handle(Geom_Curve)& theExtCurve,
283 Standard_Boolean& theIsInfinite,
284 Standard_Boolean& theIsOnPlane,
285 const Handle(Geom_Plane)& thePlane)
287 if (thePlane.IsNull())
289 return Standard_False;
292 Standard_Real aFirst, aLast;
293 BRepAdaptor_Curve aCurveAdaptor (theEdge);
294 theCurve = Handle(Geom_Curve)::DownCast (aCurveAdaptor.Curve().Curve()->Transformed (aCurveAdaptor.Trsf()));
295 aFirst = aCurveAdaptor.FirstParameter();
296 aLast = aCurveAdaptor.LastParameter();
298 if (theCurve.IsNull())
300 return Standard_False;
303 theExtCurve = theCurve;
304 theIsInfinite = (Precision::IsInfinite (aFirst) || Precision::IsInfinite (aLast));
306 // Checks that the projected curve is not in the plane.
307 theIsOnPlane = Standard_True;
308 if (theExtCurve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
310 theExtCurve = Handle(Geom_TrimmedCurve)::DownCast (theExtCurve)->BasisCurve();
313 if (theExtCurve->IsInstance (STANDARD_TYPE (Geom_Line)))
315 Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast (theExtCurve);
316 theIsOnPlane = thePlane->Pln().Contains (aLine->Lin(),
317 Precision::Confusion(),
318 Precision::Angular());
320 else if (theExtCurve->IsInstance (STANDARD_TYPE (Geom_Circle)))
322 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast (theExtCurve);
324 gp_Ax3 aCircPos (aCircle->Position());
325 theIsOnPlane = aCircPos.IsCoplanar (thePlane->Pln().Position(),
326 Precision::Confusion(),
327 Precision::Angular());
332 theExtCurve.Nullify();
335 theCurve = GeomProjLib::ProjectOnPlane (theCurve, thePlane,
336 thePlane->Pln().Axis().Direction(),
339 if (theCurve->IsInstance (STANDARD_TYPE (Geom_Line)))
341 Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast (theCurve);
344 theFirstPnt = ElCLib::Value (aFirst, aLine->Lin());
345 theLastPnt = ElCLib::Value (aLast, aLine->Lin());
348 else if (theCurve->IsInstance (STANDARD_TYPE (Geom_Circle)))
350 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast (theCurve);
352 theFirstPnt = ElCLib::Value (aFirst, aCirc->Circ());
353 theLastPnt = ElCLib::Value (aLast, aCirc->Circ());
355 else if (theCurve->IsInstance (STANDARD_TYPE (Geom_Ellipse)))
357 Handle(Geom_Ellipse) anEllipse = Handle(Geom_Ellipse)::DownCast (theCurve);
359 theFirstPnt = ElCLib::Value (aFirst, anEllipse->Elips());
360 theLastPnt = ElCLib::Value (aLast, anEllipse->Elips());
364 return Standard_False;
367 return Standard_True;
370 //=======================================================================
371 //function : ComputeGeometry
373 //=======================================================================
374 Standard_Boolean AIS::ComputeGeometry (const TopoDS_Edge& theFirstEdge,
375 const TopoDS_Edge& theSecondEdge,
376 Handle(Geom_Curve)& theFirstCurve,
377 Handle(Geom_Curve)& theSecondCurve,
378 gp_Pnt& theFirstPnt1,
380 gp_Pnt& theFirstPnt2,
382 const Handle(Geom_Plane)& thePlane)
384 if (thePlane.IsNull())
386 return Standard_False;
389 TopLoc_Location aFirstEdgeLoc, aSecondEdgeLoc;
390 Standard_Real aFirst1, aLast1, aFirst2, aLast2;
392 theFirstCurve = BRep_Tool::Curve (theFirstEdge, aFirstEdgeLoc, aFirst1, aLast1);
393 theSecondCurve = BRep_Tool::Curve (theSecondEdge, aSecondEdgeLoc, aFirst2, aLast2);
395 if (theFirstCurve.IsNull())
397 return Standard_False;
400 if (theSecondCurve.IsNull())
402 return Standard_False;
405 if (!aFirstEdgeLoc.IsIdentity())
407 Handle(Geom_Geometry) aGeomGeometry = theFirstCurve->Transformed (aFirstEdgeLoc.Transformation());
408 theFirstCurve = Handle(Geom_Curve)::DownCast (aGeomGeometry);
411 if (!aSecondEdgeLoc.IsIdentity())
413 Handle(Geom_Geometry) aGeomGeometry = theSecondCurve->Transformed (aSecondEdgeLoc.Transformation());
414 theSecondCurve = Handle(Geom_Curve)::DownCast (aGeomGeometry);
417 theFirstCurve = GeomProjLib::ProjectOnPlane (theFirstCurve, thePlane,
418 thePlane->Pln().Axis().Direction(),
422 theSecondCurve = GeomProjLib::ProjectOnPlane (theSecondCurve, thePlane,
423 thePlane->Pln().Axis().Direction(),
427 if (theFirstCurve->IsInstance (STANDARD_TYPE(Geom_TrimmedCurve)))
429 theFirstCurve = Handle(Geom_TrimmedCurve)::DownCast (theFirstCurve)->BasisCurve();
432 if (theSecondCurve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
434 theSecondCurve = Handle(Geom_TrimmedCurve)::DownCast (theSecondCurve)->BasisCurve();
437 if (theFirstCurve->IsInstance(STANDARD_TYPE(Geom_Line)))
439 Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast (theFirstCurve);
441 theFirstPnt1 = ElCLib::Value (aFirst1, aLine->Lin());
442 theLastPnt1 = ElCLib::Value (aLast1, aLine->Lin());
444 else if (theFirstCurve->IsInstance(STANDARD_TYPE(Geom_Circle)))
446 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast (theFirstCurve);
448 theFirstPnt1 = ElCLib::Value (aFirst1, aCirc->Circ());
449 theLastPnt1 = ElCLib::Value (aLast1, aCirc->Circ());
453 return Standard_False;
456 if (theSecondCurve->IsInstance (STANDARD_TYPE (Geom_Line)))
458 Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast (theSecondCurve);
460 theFirstPnt2 = ElCLib::Value (aFirst2, aLine->Lin());
461 theLastPnt2 = ElCLib::Value (aLast2, aLine->Lin());
463 else if (theSecondCurve->IsInstance (STANDARD_TYPE (Geom_Circle)))
465 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast (theSecondCurve);
467 theFirstPnt2 = ElCLib::Value (aFirst2, aCirc->Circ());
468 theLastPnt2 = ElCLib::Value (aLast2, aCirc->Circ());
472 return Standard_False;
475 return Standard_True;
478 //=======================================================================
479 //function : ComputeGeometry
480 //purpose : Computes the geometry of the 2 edges.
481 //=======================================================================
482 Standard_Boolean AIS::ComputeGeometry (const TopoDS_Edge& theFirstEdge,
483 const TopoDS_Edge& theSecondEdge,
484 Handle(Geom_Curve)& theFirstCurve,
485 Handle(Geom_Curve)& theSecondCurve,
486 gp_Pnt& theFirstPnt1,
488 gp_Pnt& theFirstPnt2,
490 Standard_Boolean& theIsInfinite1,
491 Standard_Boolean& theIsInfinite2)
493 theIsInfinite1 = theIsInfinite2 = Standard_False;
495 if (!AIS::ComputeGeometry (theFirstEdge, theFirstCurve,theFirstPnt1, theLastPnt1, theIsInfinite1))
497 return Standard_False;
500 if (!AIS::ComputeGeometry (theSecondEdge, theSecondCurve,theFirstPnt2, theLastPnt2, theIsInfinite2))
502 return Standard_False;
505 if (theIsInfinite1 || theIsInfinite2)
507 if (theFirstCurve->DynamicType() == theSecondCurve->DynamicType())
509 gp_Lin aLin1 = Handle(Geom_Line)::DownCast (theFirstCurve)->Lin();
510 gp_Lin aLin2 = Handle(Geom_Line)::DownCast (theSecondCurve)->Lin();
514 theFirstPnt1 = ElCLib::Value (ElCLib::Parameter (aLin2, theFirstPnt2), aLin1);
515 theLastPnt1 = ElCLib::Value (ElCLib::Parameter (aLin2, theLastPnt2), aLin1);
517 else if (theIsInfinite2)
519 theFirstPnt2 = ElCLib::Value (ElCLib::Parameter (aLin1, theFirstPnt1), aLin2);
520 theLastPnt2 = ElCLib::Value (ElCLib::Parameter (aLin1, theLastPnt1), aLin2);
525 if (theIsInfinite1 && !theIsInfinite2)
527 GeomAPI_ProjectPointOnCurve aProjector (theFirstPnt2, theFirstCurve);
528 theFirstPnt1 = theFirstCurve->Value (aProjector.LowerDistanceParameter ());
530 aProjector.Init (theLastPnt2, theFirstCurve);
531 theLastPnt1 = theFirstCurve->Value (aProjector.LowerDistanceParameter ());
533 else if (!theIsInfinite1 && theIsInfinite2)
535 GeomAPI_ProjectPointOnCurve aProjector (theFirstPnt1, theSecondCurve);
536 theFirstPnt2 = theSecondCurve->Value (aProjector.LowerDistanceParameter ());
538 aProjector.Init (theLastPnt1, theSecondCurve);
539 theLastPnt2 = theSecondCurve->Value (aProjector.LowerDistanceParameter ());
543 return Standard_False;
548 return Standard_True;
551 //=======================================================================
552 //function : ComputeGeometry
553 //purpose : Computes the geometry of the 2 edges in the current wp
554 // and the 'right' geometry of the edges if one doesn't
555 // belong to the current working plane.
556 // There may be only one curve that can't belong to the
557 // current working plane ( attachement constraint)
558 // if the 2 edges belong to the current WP, <WhatProj> = 0
560 // indexExt = 0 2 edges are in the current wp
561 // indexExt = 1 first edge is not in the current wp
562 // indexExt = 2 second edge is not in the current wp
563 // if none of the two edges is in the current wp ,
564 // it returns Standard_False
565 //=======================================================================
566 Standard_Boolean AIS::ComputeGeometry (const TopoDS_Edge& theFirstEdge,
567 const TopoDS_Edge& theSecondEdge,
568 Standard_Integer& theExtIndex,
569 Handle(Geom_Curve)& theFirstCurve,
570 Handle(Geom_Curve)& theSecondCurve,
571 gp_Pnt& theFirstPnt1,
573 gp_Pnt& theFirstPnt2,
575 Handle(Geom_Curve)& theExtCurve,
576 Standard_Boolean& theIsInfinite1,
577 Standard_Boolean& theIsInfinite2,
578 const Handle(Geom_Plane)& thePlane)
580 if (thePlane.IsNull())
582 return Standard_False;
585 theExtCurve.Nullify();
588 Standard_Real aFirst1, aLast1, aFirst2, aLast2;
589 theIsInfinite1 = theIsInfinite2 = Standard_False;
591 BRepAdaptor_Curve aFirstAdaptor (theFirstEdge);
592 BRepAdaptor_Curve aSecondAdaptor (theSecondEdge);
594 theFirstCurve = Handle(Geom_Curve)::DownCast
595 (aFirstAdaptor.Curve().Curve()->Transformed (aFirstAdaptor.Trsf()));
596 theSecondCurve = Handle(Geom_Curve)::DownCast
597 (aSecondAdaptor.Curve().Curve()->Transformed (aSecondAdaptor.Trsf()));
599 if (theFirstCurve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
601 theFirstCurve = Handle(Geom_TrimmedCurve)::DownCast (theFirstCurve)->BasisCurve();
603 if (theSecondCurve->IsInstance (STANDARD_TYPE (Geom_TrimmedCurve)))
605 theSecondCurve = Handle(Geom_TrimmedCurve)::DownCast (theSecondCurve)->BasisCurve();
608 aFirst1 = aFirstAdaptor.FirstParameter();
609 aLast1 = aFirstAdaptor.LastParameter();
611 aFirst2 = aSecondAdaptor.FirstParameter();
612 aLast2 = aSecondAdaptor.LastParameter();
614 if (theFirstCurve.IsNull() || theSecondCurve.IsNull())
616 return Standard_False;
619 Handle(Geom_Curve) aFirstSaved = theFirstCurve;
620 Handle(Geom_Curve) aSecondSaved = theSecondCurve;
622 // Checks that the projected curve is not in the plane
623 Standard_Boolean isFirstOnPlane,isSecondOnPlane;
625 if ((!ComputeGeomCurve (theFirstCurve, aFirst1, aLast1, theFirstPnt1, theLastPnt1, thePlane, isFirstOnPlane))
626 || (!ComputeGeomCurve( theSecondCurve, aFirst2, aLast2, theFirstPnt2, theLastPnt2, thePlane,isSecondOnPlane)))
628 return Standard_False;
631 if (Precision::IsInfinite (aFirst1) || Precision::IsInfinite (aLast1))
633 theIsInfinite1 = Standard_True;
636 if (Precision::IsInfinite (aFirst2) || Precision::IsInfinite (aLast2))
638 theIsInfinite2 = Standard_True;
641 if (theIsInfinite1 && theIsInfinite2)
646 if (theIsInfinite1 || theIsInfinite2)
648 if (theFirstCurve->DynamicType() == theSecondCurve->DynamicType())
650 gp_Lin aLin1 = Handle(Geom_Line)::DownCast (theFirstCurve)->Lin();
651 gp_Lin aLin2 = Handle(Geom_Line)::DownCast (theSecondCurve)->Lin();
653 if (theExtIndex == 1)
655 theFirstPnt1 = ElCLib::Value (ElCLib::Parameter (aLin2, theFirstPnt2), aLin1);
656 theLastPnt1 = ElCLib::Value (ElCLib::Parameter (aLin2, theLastPnt2), aLin1);
658 else if (theExtIndex == 2)
660 theFirstPnt2 = ElCLib::Value (ElCLib::Parameter (aLin1, theFirstPnt1), aLin2);
661 theLastPnt2 = ElCLib::Value (ElCLib::Parameter (aLin1, theLastPnt1), aLin2);
666 if (isFirstOnPlane && isSecondOnPlane)
668 return Standard_True;
671 if (!isFirstOnPlane && isSecondOnPlane)
672 {// curve 2 only in the plane
674 theExtCurve = aFirstSaved;
676 else if (isFirstOnPlane && !isSecondOnPlane)
677 {// curve 1 only in the plane
679 theExtCurve = aSecondSaved;
683 return Standard_False;
686 return Standard_True;
689 //=======================================================================
690 //function : ComputeGeomCurve
691 //purpose : Checks if aCurve belongs to aPlane; if not, projects aCurve in aPlane
692 // and returns aCurveproj;
694 //=======================================================================
695 Standard_Boolean AIS::ComputeGeomCurve (Handle(Geom_Curve)& aCurve,
696 const Standard_Real first1,
697 const Standard_Real last1,
700 const Handle(Geom_Plane)& aPlane,
701 Standard_Boolean& isOnPlane)
703 isOnPlane = Standard_True;
704 const Standard_Integer NodeNumber = 20;
705 Standard_Real Delta = (last1 - first1) / (NodeNumber - 1);
706 if (Delta <= Precision::PConfusion())
708 Delta = last1 - first1;
711 gp_Pnt CurPnt(0.0, 0.0, 0.0);
712 Standard_Real CurPar = first1;
713 for (Standard_Integer i = 1; i <= NodeNumber; i++)
715 CurPnt = aCurve->Value( CurPar );
716 if (aPlane->Pln().SquareDistance( CurPnt ) > SquareTolerance)
718 isOnPlane = Standard_False;
724 if (!Precision::IsInfinite(first1) && !Precision::IsInfinite(last1))
726 FirstPnt1 = aCurve->Value (first1);
727 LastPnt1 = aCurve->Value (last1);
732 Handle(Geom_Curve) aGeomCurve = GeomProjLib::ProjectOnPlane (aCurve,
734 aPlane->Pln().Axis().Direction(),
737 if (aCurve->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
739 aCurve = Handle(Geom_TrimmedCurve)::DownCast (aCurve)->BasisCurve();
741 if (! Precision::IsInfinite(first1) && ! Precision::IsInfinite(last1))
743 FirstPnt1 = AIS::ProjectPointOnPlane( FirstPnt1, aPlane->Pln() );
744 LastPnt1 = AIS::ProjectPointOnPlane( LastPnt1, aPlane->Pln() );
747 return Standard_True;
750 //=======================================================================
751 //function : ComputeGeometry
752 //purpose : computes the point corresponding to the vertex <aVertex>
753 // in the plane <aPlane>. If the vertex is already in the plane
754 // <isOnPlane>, <isOnPlane> = true.
755 // <point> is the projected vertex in the plane.
756 //=======================================================================
757 Standard_Boolean AIS::ComputeGeometry(const TopoDS_Vertex& aVertex,
759 const Handle(Geom_Plane)& aPlane,
760 Standard_Boolean& isOnPlane)
762 point = BRep_Tool::Pnt(aVertex);
763 isOnPlane = aPlane->Pln().Contains(point, Precision::Confusion());
765 point = AIS::ProjectPointOnPlane( point, aPlane->Pln() );
767 return Standard_True;
770 //=======================================================================
771 //function : GetPlaneFromFace
773 // Returns type of surface which can be Plane or OtherSurface
774 //=======================================================================
775 Standard_Boolean AIS::GetPlaneFromFace(const TopoDS_Face& aFace,
777 Handle( Geom_Surface )& aSurf,
778 AIS_KindOfSurface & aSurfType,
779 Standard_Real & Offset)
782 Standard_Boolean Result = Standard_False;
783 BRepAdaptor_Surface surf1( aFace );
784 Handle( Adaptor3d_HSurface ) surf2;
785 Standard_Boolean isOffset = Standard_False;
788 if (surf1.GetType() == GeomAbs_OffsetSurface)
790 // Extracting Basis Surface
791 surf2 = surf1.BasisSurface();
792 isOffset = Standard_True;
795 surf2 = new BRepAdaptor_HSurface( surf1 );
797 aSurf = surf1.Surface().Surface();
798 // aSurf->Transform(surf1.Trsf()) ;
799 aSurf = Handle( Geom_Surface )::DownCast( aSurf->Transformed( surf1.Trsf() ) );
801 if (surf2->GetType() == GeomAbs_Plane)
803 aPlane = surf2->Plane();
804 aSurfType = AIS_KOS_Plane;
805 Result = Standard_True;
808 else if (surf2->GetType() == GeomAbs_SurfaceOfExtrusion)
810 Handle( Adaptor3d_HCurve ) BasisCurve = surf2->BasisCurve();
811 gp_Dir ExtrusionDir = surf2->Direction();
812 if (BasisCurve->GetType() == GeomAbs_Line)
814 gp_Lin BasisLine = BasisCurve->Line();
815 gp_Dir LineDir = BasisLine.Direction();
816 gp_Pnt LinePos = BasisLine.Location();
817 gp_Pln thePlane( LinePos, LineDir ^ ExtrusionDir);
819 aSurfType = AIS_KOS_Plane;
820 Result = Standard_True;
824 if (Result == Standard_True && isOffset)
826 aSurf = (Handle( Geom_OffsetSurface )::DownCast( aSurf ))->Surface();
827 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();
843 Offset = (Handle( Geom_OffsetSurface )::DownCast( aSurf ))->Offset();
844 aSurf = (Handle( Geom_OffsetSurface )::DownCast( aSurf ))->BasisSurface();
847 Handle( Standard_Type ) TheType = aSurf->DynamicType();
848 if (TheType == STANDARD_TYPE(Geom_CylindricalSurface))
849 aSurfType = AIS_KOS_Cylinder;
850 else if (TheType == STANDARD_TYPE(Geom_ConicalSurface))
851 aSurfType = AIS_KOS_Cone;
852 else if (TheType == STANDARD_TYPE(Geom_SphericalSurface))
853 aSurfType = AIS_KOS_Sphere;
854 else if (TheType == STANDARD_TYPE(Geom_ToroidalSurface))
855 aSurfType = AIS_KOS_Torus;
856 else if (TheType == STANDARD_TYPE(Geom_SurfaceOfRevolution))
857 aSurfType = AIS_KOS_Revolution;
858 else if (TheType == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))
859 aSurfType = AIS_KOS_Extrusion;
861 aSurfType = AIS_KOS_OtherSurface;
867 //=======================================================================
868 //function : ProjectPointOnPlane
870 //=======================================================================
872 gp_Pnt AIS::ProjectPointOnPlane( const gp_Pnt & aPoint, const gp_Pln & aPlane )
874 gp_Vec aVec( aPlane.Location(), aPoint );
875 gp_Vec Normal = aPlane.Axis().Direction();
876 Normal = (aVec * Normal) * Normal;
878 return ( aPoint.Translated( -Normal ) );
881 //=======================================================================
882 //function : ProjectPointOnLine
884 //=======================================================================
886 gp_Pnt AIS::ProjectPointOnLine( const gp_Pnt & aPoint, const gp_Lin & aLine )
888 gp_XYZ LinLoc = aLine.Location().XYZ();
889 gp_XYZ LinDir = aLine.Direction().XYZ();
890 Standard_Real Parameter = (aPoint.XYZ() - LinLoc) * LinDir;
891 gp_Pnt Result( LinLoc + Parameter * LinDir );
895 //=======================================================================
896 //function : InitFaceLength
898 //=======================================================================
899 void AIS::InitFaceLength (const TopoDS_Face& theFace,
901 Handle(Geom_Surface)& theSurface,
902 AIS_KindOfSurface& theSurfaceType,
903 Standard_Real& theOffset)
905 if (AIS::GetPlaneFromFace (theFace, thePlane, theSurface, theSurfaceType, theOffset)
906 && Abs (theOffset) > Precision::Confusion())
908 theSurface = new Geom_OffsetSurface (theSurface, theOffset);
913 //=======================================================================
914 //function : InitAngleBetweenPlanarFaces
916 //=======================================================================
917 Standard_Boolean AIS::InitAngleBetweenPlanarFaces (const TopoDS_Face& theFirstFace,
918 const TopoDS_Face& theSecondFace,
920 gp_Pnt & theFirstAttach,
921 gp_Pnt & theSecondAttach,
922 const Standard_Boolean theIsFirstPointSet)
924 Handle(Geom_Plane) aFirstPlane = Handle(Geom_Plane)::DownCast (BRep_Tool::Surface (theFirstFace));
925 Handle(Geom_Plane) aSecondPlane = Handle(Geom_Plane)::DownCast (BRep_Tool::Surface (theSecondFace));
927 GeomAPI_IntSS aPlaneIntersector (aFirstPlane, aSecondPlane, Precision::Confusion());
929 // Fails if two planes haven't only one intersection line.
930 if (!aPlaneIntersector.IsDone())
932 return Standard_False;
935 if (aPlaneIntersector.NbLines() != 1)
937 return Standard_False;
940 // Get intersect line.
941 Handle(Geom_Curve) anIntersectCurve = aPlaneIntersector.Line (1);
943 Handle(Geom_Line) anIntersectLine = Handle(Geom_Line)::DownCast (anIntersectCurve);
945 if (anIntersectLine.IsNull())
947 return Standard_False;
950 gp_Lin anIntersectLin = anIntersectLine->Lin();
952 gp_Pnt aFirstCenter, aSecondCenter;
953 Standard_Real anU1Min, anU1Max, aV1Min, aV1Max;
954 Standard_Real anU2Min, anU2Max, aV2Min, aV2Max;
956 BRepTools::UVBounds (theFirstFace, anU1Min, anU1Max, aV1Min, aV1Max);
957 BRepTools::UVBounds (theSecondFace, anU2Min, anU2Max, aV2Min, aV2Max);
959 // Get first and second attach.
960 if (theIsFirstPointSet)
962 GeomAPI_ProjectPointOnSurf aProjector (theFirstAttach, aFirstPlane);
963 if (!aProjector.IsDone())
965 return Standard_False;
968 aFirstCenter = aProjector.Point (1);
972 aFirstCenter = aFirstPlane->Value ((anU1Min + anU1Max) * 0.5, (aV1Min + aV1Max) * 0.5);
975 aSecondCenter = aSecondPlane->Value ((anU2Min + anU2Max) * 0.5, (aV2Min + aV2Max) * 0.5);
977 GeomAPI_ProjectPointOnCurve aProj (aFirstCenter, anIntersectCurve);
978 theCenter = aProj.NearestPoint();
980 gp_Vec aFirstNormal = anIntersectLin.Direction() ^ aFirstPlane->Pln().Axis().Direction();
981 if (aFirstNormal * gp_Vec (theCenter, aFirstCenter) < 0.0)
983 aFirstNormal.Reverse();
985 theFirstAttach = theCenter.Translated (aFirstNormal);
987 gp_Vec aSecondNormal = anIntersectLin.Direction() ^ aSecondPlane->Pln().Axis().Direction();
988 if (aSecondNormal * gp_Vec (theCenter, aSecondCenter) < 0.0)
990 aSecondNormal.Reverse();
992 theSecondAttach = theCenter.Translated (aSecondNormal);
994 return Standard_True;
997 //=======================================================================
998 //function : InitAngleBetweenCurvilinearFaces
1000 //=======================================================================
1001 Standard_Boolean AIS::InitAngleBetweenCurvilinearFaces (const TopoDS_Face& theFirstFace,
1002 const TopoDS_Face& theSecondFace,
1003 const AIS_KindOfSurface theFirstSurfType,
1004 const AIS_KindOfSurface theSecondSurfType,
1006 gp_Pnt& theFirstAttach,
1007 gp_Pnt& theSecondAttach,
1008 const Standard_Boolean theIsFirstPointSet)
1010 Handle(Geom_Surface) aFirstSurf = BRep_Tool::Surface (theFirstFace);
1011 Handle(Geom_Surface) aSecondSurf = BRep_Tool::Surface (theSecondFace);
1013 // Find intersection curve between two surfaces.
1014 GeomAPI_IntSS aSurfaceIntersector (aFirstSurf, aSecondSurf, Precision::Confusion());
1016 // Fails if two planes haven't only one intersection line.
1017 if (!aSurfaceIntersector.IsDone())
1019 return Standard_False;
1022 if (aSurfaceIntersector.NbLines() != 1)
1024 return Standard_False;
1027 // Get intersect line.
1028 Handle(Geom_Curve) anIntersectCurve = aSurfaceIntersector.Line (1);
1030 Handle(Geom_Line) aFirstLine, aSecondLine;
1031 Standard_Real aFirstU = 0.0;
1032 Standard_Real aFirstV = 0.0;
1034 if (theIsFirstPointSet)
1036 GeomAPI_ProjectPointOnSurf aProjector (theFirstAttach, aFirstSurf);
1037 if (!aProjector.IsDone())
1039 return Standard_False;
1042 theFirstAttach = aProjector.Point (1);
1046 theFirstAttach = aFirstSurf->Value (aFirstU, aFirstV);
1049 aFirstLine = Handle(Geom_Line)::DownCast (aFirstSurf->UIso (aFirstU));
1051 if (theSecondSurfType == AIS_KOS_Cylinder)
1053 Handle(Geom_CylindricalSurface) aCylinder = Handle(Geom_CylindricalSurface)::DownCast (aSecondSurf);
1055 Standard_Real aSecondU = aCylinder->Cylinder().XAxis().Direction().Angle(
1056 gce_MakeDir (ProjectPointOnLine (theFirstAttach,
1057 gp_Lin (aCylinder->Cylinder().Axis())),
1060 aSecondLine = Handle(Geom_Line)::DownCast (aCylinder->UIso (aSecondU));
1062 else if (theSecondSurfType == AIS_KOS_Cone)
1064 Handle(Geom_ConicalSurface) aCone = Handle(Geom_ConicalSurface)::DownCast (aSecondSurf);
1066 gp_Dir anXdirection = aCone->Cone().XAxis().Direction();
1068 gp_Dir aToFirstAttach = gce_MakeDir (ProjectPointOnLine (theFirstAttach,
1069 gp_Lin (aCone->Cone().Axis())),
1072 Standard_Real aSecondU = anXdirection.Angle (aToFirstAttach);
1075 if (!anXdirection.IsEqual (aToFirstAttach, Precision::Angular()) &&
1076 !anXdirection.IsOpposite (aToFirstAttach, Precision::Angular()) &&
1077 (anXdirection ^ aToFirstAttach) * aCone->Cone().Axis().Direction() < 0.0)
1079 aSecondU = 2*M_PI - aSecondU;
1081 aSecondLine = Handle( Geom_Line )::DownCast (aCone->UIso(aSecondU));
1085 return Standard_False;
1088 // If angle can be computed between two lines.
1089 if (!(aFirstLine->Lin().Direction().IsEqual (aSecondLine->Lin().Direction(), Precision::Angular() )) &&
1090 !(aFirstLine->Lin().Direction().IsOpposite (aSecondLine->Lin().Direction(), Precision::Angular())))
1092 GeomAPI_ExtremaCurveCurve anIntersector (aFirstLine, aSecondLine);
1093 anIntersector.Points (1, theCenter, theCenter);
1095 // Move theFirstAttach on aFirstLine if it is on theCenter.
1096 if (theCenter.SquareDistance(theFirstAttach ) <= SquareTolerance)
1098 gp_Vec aDir (aFirstLine->Lin().Direction());
1099 theFirstAttach = theCenter.Translated (aDir);
1101 // theFirstAttach should be on theFirstSurf.
1102 Standard_Real anU, aV;
1103 if (theFirstSurfType == AIS_KOS_Cylinder)
1105 ElSLib::Parameters ((Handle(Geom_CylindricalSurface)::DownCast (aFirstSurf))->Cylinder(),
1106 theFirstAttach, anU, aV);
1108 theFirstAttach = ElSLib::Value (aFirstU, aV,
1109 (Handle( Geom_CylindricalSurface )::DownCast (aFirstSurf))->Cylinder() );
1111 else if (theFirstSurfType == AIS_KOS_Cone)
1113 ElSLib::Parameters ((Handle(Geom_ConicalSurface)::DownCast (aFirstSurf))->Cone(),
1114 theFirstAttach, anU, aV);
1115 theFirstAttach = ElSLib::Value (aFirstU, aV,
1116 (Handle(Geom_ConicalSurface)::DownCast (aFirstSurf))->Cone());
1120 return Standard_False;
1124 // Find theSecondAttach
1125 GeomAPI_ProjectPointOnSurf aProjector (theFirstAttach, aSecondSurf);
1126 if (!aProjector.IsDone())
1128 return Standard_False;
1130 Standard_Real anU, aV;
1131 aProjector.LowerDistanceParameters (anU, aV);
1132 theSecondAttach = aSecondSurf->Value (anU, aV);
1134 else // aFirstLine and aSecondLine are coincident
1136 gp_Vec aDir (aFirstLine->Lin().Direction());
1137 theFirstAttach = theCenter.Translated (aDir);
1138 theSecondAttach = theCenter.Translated (-aDir);
1140 return Standard_True;
1143 //=======================================================================
1144 //function : ComputeLengthBetweenCurvilinearFaces
1146 //=======================================================================
1147 void AIS::InitLengthBetweenCurvilinearFaces (const TopoDS_Face& theFirstFace,
1148 const TopoDS_Face& theSecondFace,
1149 Handle(Geom_Surface)& theFirstSurf,
1150 Handle(Geom_Surface)& theSecondSurf,
1151 gp_Pnt& theFirstAttach,
1152 gp_Pnt& theSecondAttach,
1153 gp_Dir& theDirOnPlane)
1155 GeomAPI_ProjectPointOnSurf aProjector;
1156 Standard_Real aPU, aPV;
1158 TopExp_Explorer anExplorer (theFirstFace, TopAbs_VERTEX);
1160 theFirstAttach = BRep_Tool::Pnt (TopoDS::Vertex (anExplorer.Current()));
1161 aProjector.Init (theFirstAttach, theFirstSurf);
1163 theFirstAttach = aProjector.NearestPoint();
1164 aProjector.LowerDistanceParameters (aPU, aPV);
1167 theFirstSurf->D1 (aPU, aPV, theFirstAttach, aD1U, aD1V);
1169 if (aD1U.SquareMagnitude() <= SquareTolerance || aD1V.SquareMagnitude() <= SquareTolerance)
1171 theFirstAttach = AIS::Farest (theFirstFace, theFirstAttach);
1172 aProjector.Init (theFirstAttach, theFirstSurf);
1173 aProjector.LowerDistanceParameters (aPU, aPV);
1174 theFirstSurf->D1 (aPU, aPV, theFirstAttach, aD1U, aD1V);
1180 theDirOnPlane = gp_Dir (aD1U);
1182 gp_Dir aFirstSurfN = gp_Dir (aD1U ^ aD1V);
1184 aProjector.Init (theFirstAttach, theSecondSurf);
1186 Standard_Integer aBestPointIndex = 0;
1187 Standard_Real aMinDist = RealLast();
1190 for (Standard_Integer aPointIt = 1; aPointIt <= aProjector.NbPoints(); aPointIt++)
1192 aProjector.Parameters (aPointIt, aPU, aPV);
1194 theSecondSurf->D1 (aPU, aPV, theSecondAttach, aD1U, aD1V);
1196 aLocalDir = aD1U.SquareMagnitude() <= SquareTolerance || aD1V.SquareMagnitude() <= SquareTolerance
1197 ? gp_Dir (gp_Vec (theFirstAttach, aProjector.Point (aPointIt)))
1198 : gp_Dir (aD1U ^ aD1V);
1200 if (aFirstSurfN.IsParallel (aLocalDir, Precision::Angular()) && aProjector.Distance (aPointIt) < aMinDist)
1202 aBestPointIndex = aPointIt;
1203 aMinDist = aProjector.Distance (aPointIt);
1207 if (aBestPointIndex == 0)
1209 theSecondAttach = theFirstAttach;
1213 theSecondAttach = aProjector.Point (aBestPointIndex);
1214 aProjector.Parameters (aBestPointIndex, aPU, aPV);
1216 // Now there is projection of FirstAttach onto SecondSurf in aProjector
1217 BRepTopAdaptor_FClass2d aClassifier (theSecondFace, Precision::Confusion());
1219 TopAbs_State aState =
1220 aClassifier.Perform (gp_Pnt2d (aPU, aPV), theSecondSurf->IsUPeriodic() || theSecondSurf->IsVPeriodic());
1222 if (aState == TopAbs_OUT || aState == TopAbs_UNKNOWN)
1224 theSecondAttach = AIS::Nearest (theSecondFace, theSecondAttach);
1229 gp_Pnt AIS::TranslatePointToBound( const gp_Pnt & aPoint, const gp_Dir & aDir, const Bnd_Box & aBndBox )
1231 if (aBndBox.IsOut( aPoint ))
1235 gp_Pnt Result(0.0,0.0,0.0);
1236 TColStd_Array2OfReal Bound( 1, 3, 1, 2 );
1237 TColStd_Array1OfReal Origin( 1, 3 );
1238 TColStd_Array1OfReal Dir( 1, 3 );
1241 aBndBox.Get( Bound(1,1), Bound(2,1), Bound(3,1), Bound(1,2), Bound(2,2), Bound(3,2) );
1242 aPoint.Coord( Origin(1), Origin(2), Origin(3) );
1243 aDir.Coord( Dir(1), Dir(2), Dir(3) );
1245 Bnd_Box EnlargedBox = aBndBox;
1246 EnlargedBox.Enlarge( aBndBox.GetGap() + Precision::Confusion() );
1248 Standard_Boolean IsFound = Standard_False;
1249 for (Standard_Integer i = 1; i <= 3; i++)
1251 if (Abs( Dir( i ) ) <= gp::Resolution())
1253 for (Standard_Integer j = 1; j <= 2; j++)
1255 t = (Bound( i, j ) - Origin( i )) / Dir( i );
1258 Result = aPoint.Translated( gp_Vec( aDir ) * t );
1259 if (! EnlargedBox.IsOut( Result ))
1261 IsFound = Standard_True;
1272 //=======================================================================
1273 //function : InDomain
1275 //=======================================================================
1277 Standard_Boolean AIS::InDomain(const Standard_Real fpar,
1278 const Standard_Real lpar,
1279 const Standard_Real para)
1283 return ((para >= fpar) && (para <= lpar));
1284 else { // fpar > lpar
1285 Standard_Real delta = 2*M_PI-fpar;
1286 Standard_Real lp, par, fp;
1289 while(lp > 2*M_PI) lp-=2*M_PI;
1290 while(par > 2*M_PI) par-=2*M_PI;
1292 return ((par >= fp) && (par <= lp));
1296 if (para >= (fpar+2*M_PI)) return Standard_True;
1297 if (para <= lpar) return Standard_True;
1298 return Standard_False;
1301 //=======================================================================
1302 //function : DistanceFromApex
1303 //purpose : calculates parametric length arc of ellipse
1304 //=======================================================================
1306 Standard_Real AIS::DistanceFromApex(const gp_Elips & elips,
1307 const gp_Pnt & Apex,
1308 const Standard_Real par)
1311 Standard_Real parApex = ElCLib::Parameter ( elips, Apex );
1312 if(parApex == 0.0 || parApex == M_PI)
1314 if(parApex == 0.0) //pos Apex
1315 dist = (par < M_PI) ? par : (2*M_PI - par);
1317 dist = (par < M_PI) ? ( M_PI - par) : ( par - M_PI );
1321 if(parApex == M_PI / 2) //pos Apex
1323 if(par <= parApex + M_PI && par > parApex) // 3/2*M_PI < par < M_PI/2
1324 dist = par - parApex;
1327 if(par > parApex + M_PI) // 3/2*M_PI < par < 2*M_PI
1328 dist = 2*M_PI - par + parApex;
1330 dist = parApex - par;
1333 else //neg Apex == 3/2*M_PI
1335 if(par <= parApex && par >= M_PI/2) // M_PI/2 < par < 3/2*M_PI
1336 dist = parApex - par;
1339 if(par > parApex) // 3/2*M_PI < par < 2*M_PI
1340 dist = par - parApex;
1342 dist = par + M_PI/2; // 0 < par < M_PI/2
1349 //=======================================================================
1350 //function : NearestApex
1352 //=======================================================================
1354 gp_Pnt AIS::NearestApex(const gp_Elips & elips,
1355 const gp_Pnt & pApex,
1356 const gp_Pnt & nApex,
1357 const Standard_Real fpara,
1358 const Standard_Real lpara,
1359 Standard_Boolean & IsInDomain)
1361 Standard_Real parP, parN;
1362 gp_Pnt EndOfArrow(0.0,0.0,0.0);
1363 IsInDomain = Standard_True;
1364 parP = ElCLib::Parameter ( elips, pApex );
1365 if(InDomain(fpara, lpara, parP)) EndOfArrow = pApex;
1368 parN = ElCLib::Parameter ( elips, nApex );
1369 if(InDomain(fpara, lpara, parN)) EndOfArrow = nApex;
1371 IsInDomain = Standard_False;
1372 Standard_Real posd = Min(DistanceFromApex (elips,pApex, fpara),
1373 DistanceFromApex (elips,pApex, lpara));
1374 Standard_Real negd = Min(DistanceFromApex (elips,nApex, fpara),
1375 DistanceFromApex (elips,nApex, lpara));
1385 //=======================================================================
1386 //function : ComputeProjEdgePresentation
1388 //=======================================================================
1390 void AIS::ComputeProjEdgePresentation (const Handle(Prs3d_Presentation)& aPresentation,
1391 const Handle(Prs3d_Drawer)& aDrawer,
1392 const TopoDS_Edge& anEdge,
1393 const Handle(Geom_Curve)& ProjCurve,
1394 const gp_Pnt& FirstP,
1395 const gp_Pnt& LastP,
1396 const Quantity_NameOfColor aColor,
1397 const Standard_Real aWidth,
1398 const Aspect_TypeOfLine aProjTOL,
1399 const Aspect_TypeOfLine aCallTOL)
1401 if (!aDrawer->HasOwnWireAspect()){
1402 aDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aProjTOL,2.));}
1405 // const Handle(Prs3d_LineAspect)& li = aDrawer->WireAspect();
1406 Handle(Prs3d_LineAspect) li = aDrawer->WireAspect();
1408 li->SetColor(aColor);
1409 li->SetTypeOfLine(aProjTOL);
1410 li->SetWidth(aWidth);
1413 Standard_Real pf, pl;
1414 TopLoc_Location loc;
1415 Handle(Geom_Curve) curve;
1416 Standard_Boolean isInfinite;
1417 curve = BRep_Tool::Curve(anEdge,loc,pf,pl);
1418 isInfinite = (Precision::IsInfinite(pf) || Precision::IsInfinite(pl));
1422 // Calculate presentation of the edge
1423 if (ProjCurve->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
1425 // Handle(Geom_Line) gl (Handle(Geom_Line)::DownCast (ProjCurve));
1426 Handle(Geom_Line) gl = Handle(Geom_Line)::DownCast (ProjCurve);
1429 pf = ElCLib::Parameter(gl->Lin(),FirstP);
1430 pl = ElCLib::Parameter(gl->Lin(),LastP);
1431 BRepBuilderAPI_MakeEdge MakEd(gl->Lin(), pf, pl);
1435 BRepBuilderAPI_MakeEdge MakEd(gl->Lin());
1439 else if (ProjCurve->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
1441 // Handle(Geom_Circle) gc (Handle(Geom_Circle)::DownCast (ProjCurve));
1442 Handle(Geom_Circle) gc = Handle(Geom_Circle)::DownCast (ProjCurve);
1444 pf = ElCLib::Parameter(gc->Circ(),FirstP);
1445 pl = ElCLib::Parameter(gc->Circ(),LastP);
1446 BRepBuilderAPI_MakeEdge MakEd(gc->Circ(),pf, pl);
1449 StdPrs_WFShape::Add (aPresentation, E, aDrawer);
1451 //Calculate the presentation of line connections
1452 aDrawer->WireAspect()->SetTypeOfLine(aCallTOL);
1454 gp_Pnt ppf(0.0,0.0,0.0), ppl(0.0,0.0,0.0);
1455 ppf = BRep_Tool::Pnt( TopExp::FirstVertex(TopoDS::Edge(anEdge)));
1456 ppl = BRep_Tool::Pnt( TopExp::LastVertex(TopoDS::Edge(anEdge)));
1459 if (FirstP.SquareDistance (ppf) > SquareTolerance)
1461 BRepBuilderAPI_MakeEdge MakEd1 (FirstP, ppf);
1462 StdPrs_WFShape::Add (aPresentation, MakEd1.Edge(), aDrawer);
1466 BRepBuilderAPI_MakeVertex MakVert1 (FirstP);
1467 StdPrs_WFShape::Add (aPresentation, MakVert1.Vertex(), aDrawer);
1469 if (LastP.SquareDistance (ppl) > SquareTolerance)
1471 BRepBuilderAPI_MakeEdge MakEd2 (LastP, ppl);
1472 StdPrs_WFShape::Add (aPresentation, MakEd2.Edge(), aDrawer);
1476 BRepBuilderAPI_MakeVertex MakVert2 (LastP);
1477 StdPrs_WFShape::Add (aPresentation, MakVert2.Vertex(), aDrawer);
1480 BRepBuilderAPI_MakeEdge MakEd1 (FirstP, ppf);
1481 StdPrs_WFShape::Add (aPresentation, MakEd1.Edge(), aDrawer);
1482 BRepBuilderAPI_MakeEdge MakEd2 (LastP, ppl);
1483 StdPrs_WFShape::Add (aPresentation, MakEd2.Edge(), aDrawer);
1488 //=======================================================================
1489 //function : ComputeProjVertexPresentation
1491 //=======================================================================
1493 void AIS::ComputeProjVertexPresentation (const Handle( Prs3d_Presentation )& aPresentation,
1494 const Handle( Prs3d_Drawer )& aDrawer,
1495 const TopoDS_Vertex& aVertex,
1496 const gp_Pnt& ProjPoint,
1497 const Quantity_NameOfColor aColor,
1498 const Standard_Real aWidth,
1499 const Aspect_TypeOfMarker aProjTOM,
1500 const Aspect_TypeOfLine aCallTOL)
1502 if (!aDrawer->HasOwnPointAspect()){
1503 aDrawer->SetPointAspect(new Prs3d_PointAspect(aProjTOM, aColor,1));}
1506 // const Handle(Prs3d_PointAspect)& pa = aDrawer->PointAspect();
1507 Handle(Prs3d_PointAspect) pa = aDrawer->PointAspect();
1509 pa->SetColor(aColor);
1510 pa->SetTypeOfMarker(aProjTOM);
1513 // calculate the projection
1514 StdPrs_Point::Add(aPresentation, new Geom_CartesianPoint(ProjPoint), aDrawer);
1516 if (!aDrawer->HasOwnWireAspect()){
1517 aDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aCallTOL,2.));}
1520 // const Handle(Prs3d_LineAspect)& li = aDrawer->WireAspect();
1521 Handle(Prs3d_LineAspect) li = aDrawer->WireAspect();
1523 li->SetColor(aColor);
1524 li->SetTypeOfLine(aCallTOL);
1525 li->SetWidth(aWidth);
1528 // If the points are not mixed...
1529 if (!ProjPoint.IsEqual (BRep_Tool::Pnt (aVertex), Precision::Confusion()))
1531 // calculate the lines of recall
1532 BRepBuilderAPI_MakeEdge MakEd (ProjPoint, BRep_Tool::Pnt (aVertex));
1533 StdPrs_WFShape::Add (aPresentation, MakEd.Edge(), aDrawer);