1 // Created on: 1998-01-24
2 // Created by: Julia GERASIMOVA
3 // Copyright (c) 1998-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 <Standard_NotImplemented.hxx>
19 #include <AIS_EqualDistanceRelation.ixx>
21 #include <DsgPrs_EqualDistancePresentation.hxx>
22 #include <AIS_LengthDimension.hxx>
24 #include <DsgPrs_EqualDistancePresentation.hxx>
25 #include <SelectMgr_EntityOwner.hxx>
26 #include <Select3D_SensitiveSegment.hxx>
27 #include <Select3D_SensitiveBox.hxx>
28 #include <Select3D_SensitiveCircle.hxx>
29 #include <Precision.hxx>
30 #include <BRepAdaptor_Curve.hxx>
31 #include <BRepBuilderAPI_MakeEdge.hxx>
32 #include <BRepBuilderAPI_MakeVertex.hxx>
33 #include <TopoDS_Vertex.hxx>
34 #include <BRepBuilderAPI_MakeVertex.hxx>
35 #include <BRep_Tool.hxx>
36 #include <GeomAPI_ProjectPointOnCurve.hxx>
37 #include <GeomAPI_ProjectPointOnSurf.hxx>
38 #include <Prs3d_DimensionAspect.hxx>
39 #include <Prs3d_ArrowAspect.hxx>
40 #include <Geom_Line.hxx>
41 #include <Geom_Circle.hxx>
42 #include <Prs3d_Drawer.hxx>
44 //=======================================================================
45 //function : AIS_EqualDistanceRelation
47 //=======================================================================
49 AIS_EqualDistanceRelation::AIS_EqualDistanceRelation( const TopoDS_Shape& aShape1,
50 const TopoDS_Shape& aShape2,
51 const TopoDS_Shape& aShape3,
52 const TopoDS_Shape& aShape4,
53 const Handle( Geom_Plane )& aPlane )
63 myArrowSize = 3.0; //set the concrete value
64 mySymbolPrs = DsgPrs_AS_BOTHAR;
67 //=======================================================================
70 //=======================================================================
72 void AIS_EqualDistanceRelation::Compute( const Handle( PrsMgr_PresentationManager3d )&,
73 const Handle( Prs3d_Presentation )& aPresentation,
74 const Standard_Integer )
77 aPresentation->Clear();
79 gp_Pnt Position12 = myPosition, Position34 = myPosition;
81 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
82 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
83 arr->SetLength(myArrowSize);
85 if (!myAutomaticPosition ){
86 gp_Pnt aMiddle12 ((myPoint1.XYZ() + myPoint2.XYZ())*0.5);
87 gp_Pnt aMiddle34 ((myPoint3.XYZ() + myPoint4.XYZ())*0.5);
89 if (myPosition.Distance(aMiddle12) > myPosition.Distance(aMiddle34))
90 Position12.SetXYZ((myPoint1.XYZ() + myPoint2.XYZ())*0.5);
92 Position34.SetXYZ((myPoint3.XYZ() + myPoint4.XYZ())*0.5);
96 if (myFShape.ShapeType() == TopAbs_EDGE && mySShape.ShapeType() == TopAbs_EDGE)
97 AIS_EqualDistanceRelation::ComputeTwoEdgesLength(aPresentation,
100 TopoDS::Edge(myFShape),
101 TopoDS::Edge(mySShape),
114 else if (myFShape.ShapeType() == TopAbs_VERTEX && mySShape.ShapeType() == TopAbs_VERTEX)
115 AIS_EqualDistanceRelation::ComputeTwoVerticesLength( aPresentation,
118 TopoDS::Vertex(myFShape),
119 TopoDS::Vertex(mySShape),
132 AIS_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( aPresentation,
148 if (myShape3.ShapeType() == TopAbs_EDGE && myShape4.ShapeType() == TopAbs_EDGE)
149 AIS_EqualDistanceRelation::ComputeTwoEdgesLength(aPresentation,
152 TopoDS::Edge(myShape3),
153 TopoDS::Edge(myShape4),
165 else if (myShape3.ShapeType() == TopAbs_VERTEX && myShape4.ShapeType() == TopAbs_VERTEX)
166 AIS_EqualDistanceRelation::ComputeTwoVerticesLength( aPresentation,
169 TopoDS::Vertex(myShape3),
170 TopoDS::Vertex(myShape4),
184 AIS_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( aPresentation,
200 DsgPrs_EqualDistancePresentation::Add( aPresentation, myDrawer,
201 myPoint1, myPoint2, myPoint3, myPoint4, myPlane );
205 //=======================================================================
207 //purpose : to avoid warning at compilation (SUN)
208 //=======================================================================
210 void AIS_EqualDistanceRelation::Compute( const Handle( Prs3d_Projector )& /*aProjector*/,
211 const Handle( Prs3d_Presentation )& /*aPresentation*/)
213 // Standard_NotImplemented::Raise("AIS_EqualDistanceRelation::Compute( const Handle( Prs3d_Projector )&,
214 // const Handle( Prs3d_Presentation )& )");
215 // PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
218 //=======================================================================
220 //purpose : to avoid warning at compilation (SUN)
221 //=======================================================================
222 void AIS_EqualDistanceRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
223 const Handle(Geom_Transformation)& aTransformation,
224 const Handle(Prs3d_Presentation)& aPresentation)
226 // Standard_NotImplemented::Raise("AIS_EqualDistanceRelation::Compute(const Handle(Prs3d_Projector)&,
227 // const Handle(Geom_Transformation)&,const Handle(Prs3d_Presentation)&)");
228 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
231 //=======================================================================
232 //function : ComputeSelection
234 //=======================================================================
236 void AIS_EqualDistanceRelation::ComputeSelection( const Handle( SelectMgr_Selection )& aSelection,
237 const Standard_Integer )
239 Handle( SelectMgr_EntityOwner ) own = new SelectMgr_EntityOwner( this, 7 );
240 Handle( Select3D_SensitiveSegment ) seg;
242 seg = new Select3D_SensitiveSegment( own, myPoint1, myPoint2 );
243 aSelection->Add( seg );
245 seg = new Select3D_SensitiveSegment( own, myPoint3, myPoint4 );
246 aSelection->Add( seg );
248 // Line between two middles
249 gp_Pnt Middle12( (myPoint1.XYZ() + myPoint2.XYZ()) * 0.5 ),
250 Middle34( (myPoint3.XYZ() + myPoint4.XYZ()) *0.5 );
251 seg = new Select3D_SensitiveSegment( own, Middle12, Middle34 );
252 aSelection->Add( seg );
254 gp_Pnt Middle((Middle12.XYZ() + Middle34.XYZ())*0.5);
255 Standard_Real SmallDist = .001;
256 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
257 Middle.X() - SmallDist,
258 Middle.Y() - SmallDist,
259 Middle.Z() - SmallDist,
260 Middle.X() + SmallDist,
261 Middle.Y() + SmallDist,
262 Middle.Z() + SmallDist );
263 aSelection->Add(box);
265 if (myFShape.ShapeType() == TopAbs_EDGE){
266 BRepAdaptor_Curve aCurve(TopoDS::Edge(myFShape));
267 if (aCurve.GetType() == GeomAbs_Line){
268 //add sensetive element - line
269 seg = new Select3D_SensitiveSegment( own, myAttachPoint1, myPoint1);
270 aSelection->Add( seg );
272 else if (aCurve.GetType() == GeomAbs_Circle){
273 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
274 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint1),
275 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint1);
276 if (LastPar < FirstPar ) LastPar+=M_PI*2;
278 Handle(Select3D_SensitiveCircle) circ =
279 new Select3D_SensitiveCircle( own, aCircle, FirstPar, LastPar);
280 aSelection->Add( circ );
284 seg = new Select3D_SensitiveSegment( own, myAttachPoint1, myPoint1);
285 aSelection->Add( seg );
288 if (mySShape.ShapeType() == TopAbs_EDGE){
289 BRepAdaptor_Curve aCurve(TopoDS::Edge(mySShape));
290 if (aCurve.GetType() == GeomAbs_Line) {
291 //add sensetive element - line
292 seg = new Select3D_SensitiveSegment( own, myAttachPoint2, myPoint2);
293 aSelection->Add( seg );
295 else if (aCurve.GetType() == GeomAbs_Circle){
296 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
297 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint2),
298 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint2);
299 if (LastPar < FirstPar ) LastPar+=M_PI*2;
301 Handle(Select3D_SensitiveCircle) circ =
302 new Select3D_SensitiveCircle( own,aCircle, FirstPar, LastPar);
303 aSelection->Add( circ );
307 seg = new Select3D_SensitiveSegment( own, myAttachPoint2, myPoint2);
308 aSelection->Add( seg );
311 if (myShape3.ShapeType() == TopAbs_EDGE){
312 BRepAdaptor_Curve aCurve(TopoDS::Edge(myShape3));
313 if (aCurve.GetType() == GeomAbs_Line) {
314 //add sensetive element - line
315 seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
316 aSelection->Add( seg );
318 else if (aCurve.GetType() == GeomAbs_Circle){
319 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
320 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint3),
321 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint3);
322 if (LastPar < FirstPar ) LastPar+=M_PI*2;
323 Handle(Select3D_SensitiveCircle) circ =
324 new Select3D_SensitiveCircle( own, aCircle, FirstPar, LastPar);
325 aSelection->Add( circ );
328 seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
329 aSelection->Add( seg );
333 seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
334 aSelection->Add( seg );
337 if (myShape4.ShapeType() == TopAbs_EDGE){
338 BRepAdaptor_Curve aCurve(TopoDS::Edge(myShape4));
339 if (aCurve.GetType() == GeomAbs_Line) {
340 //add sensetive element - line
341 seg = new Select3D_SensitiveSegment( own, myAttachPoint4, myPoint4);
342 aSelection->Add( seg );
344 else if (aCurve.GetType() == GeomAbs_Circle){
345 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
346 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint4),
347 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint4);
348 if (LastPar < FirstPar ) LastPar+=M_PI*2;
350 Handle(Select3D_SensitiveCircle) circ =
351 new Select3D_SensitiveCircle( own,aCircle, FirstPar, LastPar);
352 aSelection->Add( circ );
356 seg = new Select3D_SensitiveSegment( own, myAttachPoint4, myPoint4);
357 aSelection->Add( seg );
361 //=======================================================================
362 //function : ComputeTwoEdgesLength
364 //=======================================================================
365 void AIS_EqualDistanceRelation::ComputeTwoEdgesLength( const Handle( Prs3d_Presentation )& aPresentation,
366 const Handle( Prs3d_Drawer )& aDrawer,
367 const Standard_Real ArrowSize,
368 const TopoDS_Edge & FirstEdge,
369 const TopoDS_Edge & SecondEdge,
370 const Handle( Geom_Plane )& Plane,
371 const Standard_Boolean AutomaticPos,
372 const Standard_Boolean IsSetBndBox,
373 const Bnd_Box & BndBox,
376 gp_Pnt& SecondAttach,
377 gp_Pnt& FirstExtreme,
378 gp_Pnt& SecondExtreme,
379 DsgPrs_ArrowSide & SymbolPrs )
382 BRepAdaptor_Curve cu1( FirstEdge );
383 BRepAdaptor_Curve cu2( SecondEdge );
386 Handle(Geom_Curve) geom1,geom2;
387 gp_Pnt ptat11,ptat12,ptat21,ptat22;
389 Standard_Boolean isInfinite1(Standard_False),isInfinite2(Standard_False);
390 Handle(Geom_Curve) extCurv;
391 Standard_Real arrsize = ArrowSize;// size
392 Standard_Real Val=0.;
393 Standard_Boolean isInPlane1, isInPlane2;
395 if(!AIS::ComputeGeometry(FirstEdge,geom1, ptat11, ptat12,extCurv,isInfinite1,isInPlane1, Plane ))
397 if(!AIS::ComputeGeometry(SecondEdge, geom2, ptat21, ptat22, extCurv, isInfinite2,isInPlane2, Plane))
400 aPresentation->SetInfiniteState(isInfinite1 || isInfinite2);
402 if (cu1.GetType() == GeomAbs_Line && cu2.GetType() == GeomAbs_Line)
404 const Handle(Geom_Line)& geom_lin1 = (Handle(Geom_Line)&) geom1;
405 const Handle(Geom_Line)& geom_lin2 = (Handle(Geom_Line)&) geom2;
406 const gp_Lin& l1 = geom_lin1->Lin();
407 const gp_Lin& l2 = geom_lin2->Lin();
410 Val = l1.Distance( l2 );
412 DirAttach = l1.Direction();
415 // compute position of offset point
417 Standard_Real par1=0., par2=0.;
418 if(!(isInfinite1 || isInfinite2))
420 par1 = ElCLib::Parameter(l1,ptat11);
421 par2 = ElCLib::Parameter(l1,ptat21);
422 if (par1 <par2){//project ptat11 on l2
423 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
424 curpos.SetXYZ((ptat11.XYZ()+p2.XYZ())*0.5);
426 else {//project ptat21 on l1
427 gp_Pnt p2 = ElCLib::Value(par2, l1);
428 curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())*0.5);
431 else if (!isInfinite1){
432 par2 = ElCLib::Parameter(l1,ptat21);
433 gp_Pnt p2 = ElCLib::Value(par2,l1);
434 curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())/2.);
436 else if (!isInfinite2) {
437 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
438 curpos.SetXYZ((ptat11.XYZ()+p2.XYZ())*0.5);
441 curpos.SetXYZ((l1.Location().XYZ()+l2.Location().XYZ())*0.5);
444 gp_Vec offset(DirAttach);
445 offset = offset*ArrowSize*(-10.);
446 curpos.Translate(offset);
449 else { // project point on the plane
450 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
453 // find attach points
455 if (Position.Distance(ptat11) > Position.Distance(ptat12)) FirstAttach = ptat12;
456 else FirstAttach = ptat11;
459 FirstAttach = ElCLib::Value(ElCLib::Parameter(l1,Position),l1);
463 if (Position.Distance(ptat21) > Position.Distance(ptat22)) SecondAttach = ptat22;
464 else SecondAttach = ptat21;
467 SecondAttach = ElCLib::Value(ElCLib::Parameter(l2,Position),l2);
470 Standard_Real confusion(Precision::Confusion());
471 if (arrsize < confusion) arrsize = Val*0.1;
472 if (Abs(Val) <= confusion) {arrsize = 0.;}
474 Handle(Prs3d_DimensionAspect) la = aDrawer->DimensionAspect();
475 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
476 arr->SetLength(arrsize);
477 arr = la->ArrowAspect();
478 arr->SetLength(arrsize);
480 if (AutomaticPos && IsSetBndBox)
481 Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );
483 DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
495 if (cu1.GetType() == GeomAbs_Circle && cu2.GetType() == GeomAbs_Circle){
496 //Get first and last points of circles
497 const Handle(Geom_Circle)& aCir1 = Handle(Geom_Circle)::DownCast(geom1);
498 const Handle(Geom_Circle)& aCir2 = Handle(Geom_Circle)::DownCast(geom2);
499 gp_Circ aCirc1 = aCir1->Circ();
500 gp_Circ aCirc2 = aCir2->Circ();
502 //To avoid circles with different orientaion
503 Standard_Real aTol = Precision::Confusion();
504 if(aCirc2.Axis().IsOpposite(aCirc1.Axis(), aTol) ||
505 aCirc2.XAxis().IsOpposite(aCirc1.XAxis(), aTol) ||
506 aCirc2.YAxis().IsOpposite(aCirc1.YAxis(), aTol) )
508 aCirc2.SetPosition(aCirc1.Position());
509 aCirc2.SetAxis(aCirc1.Axis());
513 Standard_Real par1 = 0, par2 = 0;
514 gp_Pln aPln = Plane->Pln();
515 //Project ptat12 and ptat22 on constraint plane
516 gp_Pnt PrPnt12 = AIS::ProjectPointOnPlane(ptat12, aPln);
517 gp_Pnt PrPnt22 = AIS::ProjectPointOnPlane(ptat22, aPln);
518 //Project circles center on constraint plane
519 gp_Pnt PrCenter = AIS::ProjectPointOnPlane(aCirc1.Location(), aPln);
521 gp_Dir XDir = aPln.XAxis().Direction();
522 gp_Dir YDir = aPln.YAxis().Direction();
525 if (PrPnt12.Distance(PrCenter) >Precision::Confusion())
527 gp_Dir aDir1(PrPnt12.XYZ() - PrCenter.XYZ());
528 Standard_Real anAngle = aDir1.Angle(XDir); //Get the angle in range [0, M_PI]
529 if (aDir1.Dot(YDir) < 0)
530 anAngle = 2 * M_PI - anAngle;
534 if (PrPnt22.Distance(PrCenter) >Precision::Confusion())
536 gp_Dir aDir2(PrPnt22.XYZ() - PrCenter.XYZ());
537 Standard_Real anAngle = aDir2.Angle(XDir); //Get the angle in range [0, M_PI]
538 if (aDir2.Dot(YDir) < 0)
539 anAngle = 2 * M_PI - anAngle;
545 FirstExtreme = ptat12;
546 Standard_Real aPar1 = ElCLib::Parameter(aCirc2, ptat12);
547 SecondExtreme = ElCLib::Value(aPar1, aCirc2);
550 Standard_Real aPar2 = ElCLib::Parameter(aCirc1, ptat22);
551 FirstExtreme = ElCLib::Value(aPar2, aCirc1);
552 SecondExtreme = ptat22;
556 Standard_Real pospar = ElCLib::Parameter(aCirc1, Position);
557 FirstExtreme = ElCLib::Value(pospar, aCirc1);
558 pospar = ElCLib::Parameter(aCirc2, Position);
559 SecondExtreme = ElCLib::Value(pospar, aCirc2);
562 DsgPrs_EqualDistancePresentation::AddIntervalBetweenTwoArcs(aPresentation,
572 FirstAttach = ptat12; SecondAttach = ptat22; //assign attach points
573 Position.SetXYZ( (FirstAttach.XYZ() + SecondAttach.XYZ())*0.5);
576 if (arrsize < Precision::Confusion()) arrsize = Val*0.1;
577 if (Abs(Val) <= Precision::Confusion()) {arrsize = 0.;}
581 AIS::ComputeProjEdgePresentation( aPresentation, aDrawer, FirstEdge, geom1, ptat11, ptat12);
584 AIS::ComputeProjEdgePresentation( aPresentation, aDrawer, SecondEdge, geom2, ptat21, ptat22);
588 //=======================================================================
589 //function : ComputeTwoVerticesLength
591 //=======================================================================
593 void AIS_EqualDistanceRelation::ComputeTwoVerticesLength( const Handle( Prs3d_Presentation )& aPresentation,
594 const Handle( Prs3d_Drawer )& aDrawer,
595 const Standard_Real ArrowSize,
596 const TopoDS_Vertex& FirstVertex,
597 const TopoDS_Vertex& SecondVertex,
598 const Handle( Geom_Plane )& Plane,
599 const Standard_Boolean AutomaticPos,
600 const Standard_Boolean IsSetBndBox,
601 const Bnd_Box& BndBox,
602 const AIS_TypeOfDist TypeDist,
605 gp_Pnt& SecondAttach,
606 gp_Pnt& FirstExtreme,
607 gp_Pnt& SecondExtreme,
608 DsgPrs_ArrowSide& SymbolPrs )
610 Standard_Boolean isOnPlane1, isOnPlane2;
612 AIS::ComputeGeometry( FirstVertex, FirstAttach, Plane, isOnPlane1);
613 AIS::ComputeGeometry( SecondVertex, SecondAttach, Plane, isOnPlane2);
615 Standard_Real confusion(Precision::Confusion());
616 Standard_Boolean samePoint(FirstAttach.IsEqual(SecondAttach,confusion));
618 if (TypeDist == AIS_TOD_Vertical) DirAttach = Plane->Pln().XAxis().Direction();
619 else if (TypeDist == AIS_TOD_Horizontal) DirAttach = Plane->Pln().YAxis().Direction();
622 DirAttach.SetXYZ(SecondAttach.XYZ() - FirstAttach.XYZ());
623 DirAttach.Rotate(Plane->Pln().Axis(),M_PI/2.);
630 gp_Pnt curpos((FirstAttach.XYZ()+SecondAttach.XYZ())*0.5);
631 // make offset of curpos
632 gp_Vec offset(DirAttach);
633 offset = offset*ArrowSize*(-10.);
634 curpos.Translate(offset);
638 const gp_Dir& aDir = Plane->Pln().Axis().Direction();
639 gp_Vec aVec (aDir.XYZ()*10*ArrowSize);
640 //Position = gp_Pnt(FirstAttach.XYZ()+gp_XYZ(1.,1.,1.)); // not correct
641 Position = FirstAttach.Translated(aVec);
642 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );//not needed really
643 DirAttach.SetXYZ(Position.XYZ() - FirstAttach.XYZ());
647 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
651 Handle(Prs3d_DimensionAspect) la = aDrawer->DimensionAspect();
652 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
653 arr->SetLength(ArrowSize);
654 arr = la->ArrowAspect();
655 arr->SetLength(ArrowSize);
657 if (AutomaticPos && IsSetBndBox)
658 Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );
660 DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
667 FirstExtreme, //returned
668 SecondExtreme); //returned
670 // Compute projection
672 AIS::ComputeProjVertexPresentation(aPresentation, aDrawer, FirstVertex, FirstAttach);
674 AIS::ComputeProjVertexPresentation(aPresentation, aDrawer, SecondVertex, SecondAttach);
679 //=======================================================================
680 //function : ComputeOneEdgeOneVertexLength
682 //=======================================================================
684 void AIS_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( const Handle( Prs3d_Presentation )& aPresentation,
685 const Handle( Prs3d_Drawer )& aDrawer,
686 const Standard_Real ArrowSize,
687 const TopoDS_Shape & FirstShape,
688 const TopoDS_Shape & SecondShape,
689 const Handle( Geom_Plane )& Plane,
690 const Standard_Boolean AutomaticPos,
691 const Standard_Boolean IsSetBndBox,
692 const Bnd_Box & BndBox,
694 gp_Pnt & FirstAttach,
695 gp_Pnt & SecondAttach,
696 gp_Pnt& FirstExtreme,
697 gp_Pnt& SecondExtreme,
698 DsgPrs_ArrowSide & SymbolPrs )
700 TopoDS_Vertex thevertex;
703 gp_Pnt ptonedge1,ptonedge2;
704 Handle(Geom_Curve) aCurve;
705 Handle(Geom_Curve) extCurv;
706 Standard_Boolean isInfinite;
708 Standard_Boolean isOnPlanEdge, isOnPlanVertex;
709 Standard_Integer edgenum ;
711 if (FirstShape.ShapeType() == TopAbs_VERTEX) {
712 thevertex = TopoDS::Vertex(FirstShape);
713 theedge = TopoDS::Edge(SecondShape);
714 edgenum = 2; //edge is the second shape
717 thevertex = TopoDS::Vertex(SecondShape);
718 theedge = TopoDS::Edge(FirstShape);
719 edgenum = 1;//edge is the first shape
721 if (!AIS::ComputeGeometry(theedge,aCurve,ptonedge1,ptonedge2,extCurv,isInfinite,isOnPlanEdge,Plane))
723 aPresentation->SetInfiniteState(isInfinite);
724 AIS::ComputeGeometry(thevertex, FirstAttach, Plane, isOnPlanVertex);
726 if ( aCurve->IsInstance(STANDARD_TYPE(Geom_Line)) )
728 const Handle(Geom_Line)& geom_lin = (Handle(Geom_Line)&) aCurve;
729 const gp_Lin& l = geom_lin->Lin();
731 // computation of Val
732 Val = l.Distance( FirstAttach );
734 gp_Dir DirAttach = l.Direction();
736 Standard_Real arrsize = ArrowSize;
737 if (Abs(Val) <= Precision::Confusion()) {arrsize = 0.;}
740 gp_Pnt p = ElCLib::Value(ElCLib::Parameter(l,FirstAttach),l);
741 gp_Pnt curpos((FirstAttach.XYZ()+p.XYZ())*0.5);
743 gp_Vec offset(DirAttach);
744 offset = offset*ArrowSize*(-10.);
745 curpos.Translate(offset);
748 else { // project point on the plane
749 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
753 if (Position.Distance(ptonedge1) > Position.Distance(ptonedge2)) SecondAttach = ptonedge2;
754 else SecondAttach = ptonedge1;
757 SecondAttach = ElCLib::Value(ElCLib::Parameter(l,Position),l);
760 Handle(Prs3d_DimensionAspect) la = aDrawer->DimensionAspect();
761 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
762 arr->SetLength(arrsize);
763 arr = la->ArrowAspect();
764 arr->SetLength(arrsize);
766 if (AutomaticPos && IsSetBndBox)
767 Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );
768 DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
779 if (aCurve->IsInstance(STANDARD_TYPE(Geom_Circle))){
780 gp_Circ aCirc1 = (Handle(Geom_Circle)::DownCast(aCurve))->Circ();
781 gp_Circ aCirc2(aCirc1); aCirc2.SetRadius(0); //create the second formal circle
784 SecondAttach = ptonedge2; //a vertex
785 Position.SetXYZ((SecondAttach.XYZ() + aCirc1.Location().XYZ())*0.5);
788 Standard_Real aPar = ElCLib::Parameter(aCirc1, Position);
789 SecondAttach = ElCLib::Value(aPar, aCirc1);
792 Handle(Geom_Circle) aCurve2 = new Geom_Circle(aCirc2);
793 DsgPrs_EqualDistancePresentation::AddIntervalBetweenTwoArcs(aPresentation,
795 aCirc1, //circle or arc
796 aCirc2, //really vertex
797 ptonedge2, //last point of aCirc1
799 FirstAttach, //vertex really
805 FirstExtreme = SecondAttach; SecondExtreme = FirstAttach;
806 SecondAttach = FirstAttach; FirstAttach = ptonedge2;
807 } else { //vertex is the first shape, circle is sthe last.
808 FirstExtreme = FirstAttach; SecondExtreme = SecondAttach;
809 SecondAttach = ptonedge2;
813 // computation of Val
814 Val = FirstAttach.Distance(SecondAttach);
816 //Display the pieces of attached to the curve if it is not
818 if (!isOnPlanEdge) { // add presentation of projection of the edge in WP
819 AIS::ComputeProjEdgePresentation(aPresentation,aDrawer,theedge,aCurve,ptonedge1,ptonedge2);
821 if (!isOnPlanVertex) { // add presentation of projection of the vertex in WP
822 AIS::ComputeProjVertexPresentation(aPresentation,aDrawer,thevertex,FirstAttach);