1 // Created on: 1998-01-24
2 // Created by: Julia GERASIMOVA
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <Standard_NotImplemented.hxx>
25 #include <AIS_EqualDistanceRelation.ixx>
27 #include <DsgPrs_EqualDistancePresentation.hxx>
28 #include <AIS_LengthDimension.hxx>
30 #include <DsgPrs_EqualDistancePresentation.hxx>
31 #include <SelectMgr_EntityOwner.hxx>
32 #include <Select3D_SensitiveSegment.hxx>
33 #include <Select3D_SensitiveBox.hxx>
34 #include <Select3D_SensitiveCircle.hxx>
35 #include <Precision.hxx>
36 #include <BRepAdaptor_Curve.hxx>
37 #include <BRepBuilderAPI_MakeEdge.hxx>
38 #include <BRepBuilderAPI_MakeVertex.hxx>
39 #include <TopoDS_Vertex.hxx>
40 #include <BRepBuilderAPI_MakeVertex.hxx>
41 #include <BRep_Tool.hxx>
42 #include <GeomAPI_ProjectPointOnCurve.hxx>
43 #include <GeomAPI_ProjectPointOnSurf.hxx>
44 #include <Prs3d_LengthAspect.hxx>
45 #include <Prs3d_ArrowAspect.hxx>
46 #include <Geom_Line.hxx>
47 #include <Geom_Circle.hxx>
48 #include <AIS_Drawer.hxx>
50 //=======================================================================
51 //function : AIS_EqualDistanceRelation
53 //=======================================================================
55 AIS_EqualDistanceRelation::AIS_EqualDistanceRelation( const TopoDS_Shape& aShape1,
56 const TopoDS_Shape& aShape2,
57 const TopoDS_Shape& aShape3,
58 const TopoDS_Shape& aShape4,
59 const Handle( Geom_Plane )& aPlane )
69 myArrowSize = 3.0; //set the concrete value
70 mySymbolPrs = DsgPrs_AS_BOTHAR;
73 //=======================================================================
76 //=======================================================================
78 void AIS_EqualDistanceRelation::Compute( const Handle( PrsMgr_PresentationManager3d )&,
79 const Handle( Prs3d_Presentation )& aPresentation,
80 const Standard_Integer )
83 aPresentation->Clear();
85 gp_Pnt Position12 = myPosition, Position34 = myPosition;
87 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
88 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
89 arr->SetLength(myArrowSize);
91 if (!myAutomaticPosition ){
92 gp_Pnt aMiddle12 ((myPoint1.XYZ() + myPoint2.XYZ())*0.5);
93 gp_Pnt aMiddle34 ((myPoint3.XYZ() + myPoint4.XYZ())*0.5);
95 if (myPosition.Distance(aMiddle12) > myPosition.Distance(aMiddle34))
96 Position12.SetXYZ((myPoint1.XYZ() + myPoint2.XYZ())*0.5);
98 Position34.SetXYZ((myPoint3.XYZ() + myPoint4.XYZ())*0.5);
102 if (myFShape.ShapeType() == TopAbs_EDGE && mySShape.ShapeType() == TopAbs_EDGE)
103 AIS_EqualDistanceRelation::ComputeTwoEdgesLength(aPresentation,
106 TopoDS::Edge(myFShape),
107 TopoDS::Edge(mySShape),
120 else if (myFShape.ShapeType() == TopAbs_VERTEX && mySShape.ShapeType() == TopAbs_VERTEX)
121 AIS_EqualDistanceRelation::ComputeTwoVerticesLength( aPresentation,
124 TopoDS::Vertex(myFShape),
125 TopoDS::Vertex(mySShape),
138 AIS_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( aPresentation,
154 if (myShape3.ShapeType() == TopAbs_EDGE && myShape4.ShapeType() == TopAbs_EDGE)
155 AIS_EqualDistanceRelation::ComputeTwoEdgesLength(aPresentation,
158 TopoDS::Edge(myShape3),
159 TopoDS::Edge(myShape4),
171 else if (myShape3.ShapeType() == TopAbs_VERTEX && myShape4.ShapeType() == TopAbs_VERTEX)
172 AIS_EqualDistanceRelation::ComputeTwoVerticesLength( aPresentation,
175 TopoDS::Vertex(myShape3),
176 TopoDS::Vertex(myShape4),
190 AIS_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( aPresentation,
206 DsgPrs_EqualDistancePresentation::Add( aPresentation, myDrawer,
207 myPoint1, myPoint2, myPoint3, myPoint4, myPlane );
211 //=======================================================================
213 //purpose : to avoid warning at compilation (SUN)
214 //=======================================================================
216 void AIS_EqualDistanceRelation::Compute( const Handle( Prs3d_Projector )& aProjector,
217 const Handle( Prs3d_Presentation )& aPresentation)
219 // Standard_NotImplemented::Raise("AIS_EqualDistanceRelation::Compute( const Handle( Prs3d_Projector )&,
220 // const Handle( Prs3d_Presentation )& )");
221 // PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
224 //=======================================================================
226 //purpose : to avoid warning at compilation (SUN)
227 //=======================================================================
228 void AIS_EqualDistanceRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
229 const Handle(Geom_Transformation)& aTransformation,
230 const Handle(Prs3d_Presentation)& aPresentation)
232 // Standard_NotImplemented::Raise("AIS_EqualDistanceRelation::Compute(const Handle(Prs3d_Projector)&,
233 // const Handle(Geom_Transformation)&,const Handle(Prs3d_Presentation)&)");
234 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
237 //=======================================================================
238 //function : ComputeSelection
240 //=======================================================================
242 void AIS_EqualDistanceRelation::ComputeSelection( const Handle( SelectMgr_Selection )& aSelection,
243 const Standard_Integer )
245 Handle( SelectMgr_EntityOwner ) own = new SelectMgr_EntityOwner( this, 7 );
246 Handle( Select3D_SensitiveSegment ) seg;
248 seg = new Select3D_SensitiveSegment( own, myPoint1, myPoint2 );
249 aSelection->Add( seg );
251 seg = new Select3D_SensitiveSegment( own, myPoint3, myPoint4 );
252 aSelection->Add( seg );
254 // Line between two middles
255 gp_Pnt Middle12( (myPoint1.XYZ() + myPoint2.XYZ()) * 0.5 ),
256 Middle34( (myPoint3.XYZ() + myPoint4.XYZ()) *0.5 );
257 seg = new Select3D_SensitiveSegment( own, Middle12, Middle34 );
258 aSelection->Add( seg );
260 gp_Pnt Middle((Middle12.XYZ() + Middle34.XYZ())*0.5);
261 Standard_Real SmallDist = .001;
262 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
263 Middle.X() - SmallDist,
264 Middle.Y() - SmallDist,
265 Middle.Z() - SmallDist,
266 Middle.X() + SmallDist,
267 Middle.Y() + SmallDist,
268 Middle.Z() + SmallDist );
269 aSelection->Add(box);
271 if (myFShape.ShapeType() == TopAbs_EDGE){
272 BRepAdaptor_Curve aCurve(TopoDS::Edge(myFShape));
273 if (aCurve.GetType() == GeomAbs_Line){
274 //add sensetive element - line
275 seg = new Select3D_SensitiveSegment( own, myAttachPoint1, myPoint1);
276 aSelection->Add( seg );
278 else if (aCurve.GetType() == GeomAbs_Circle){
279 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
280 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint1),
281 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint1);
282 if (LastPar < FirstPar ) LastPar+=M_PI*2;
284 Handle(Select3D_SensitiveCircle) circ =
285 new Select3D_SensitiveCircle( own, aCircle, FirstPar, LastPar);
286 aSelection->Add( circ );
290 seg = new Select3D_SensitiveSegment( own, myAttachPoint1, myPoint1);
291 aSelection->Add( seg );
294 if (mySShape.ShapeType() == TopAbs_EDGE){
295 BRepAdaptor_Curve aCurve(TopoDS::Edge(mySShape));
296 if (aCurve.GetType() == GeomAbs_Line) {
297 //add sensetive element - line
298 seg = new Select3D_SensitiveSegment( own, myAttachPoint2, myPoint2);
299 aSelection->Add( seg );
301 else if (aCurve.GetType() == GeomAbs_Circle){
302 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
303 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint2),
304 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint2);
305 if (LastPar < FirstPar ) LastPar+=M_PI*2;
307 Handle(Select3D_SensitiveCircle) circ =
308 new Select3D_SensitiveCircle( own,aCircle, FirstPar, LastPar);
309 aSelection->Add( circ );
313 seg = new Select3D_SensitiveSegment( own, myAttachPoint2, myPoint2);
314 aSelection->Add( seg );
317 if (myShape3.ShapeType() == TopAbs_EDGE){
318 BRepAdaptor_Curve aCurve(TopoDS::Edge(myShape3));
319 if (aCurve.GetType() == GeomAbs_Line) {
320 //add sensetive element - line
321 seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
322 aSelection->Add( seg );
324 else if (aCurve.GetType() == GeomAbs_Circle){
325 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
326 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint3),
327 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint3);
328 if (LastPar < FirstPar ) LastPar+=M_PI*2;
329 Handle(Select3D_SensitiveCircle) circ =
330 new Select3D_SensitiveCircle( own, aCircle, FirstPar, LastPar);
331 aSelection->Add( circ );
334 seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
335 aSelection->Add( seg );
339 seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
340 aSelection->Add( seg );
343 if (myShape4.ShapeType() == TopAbs_EDGE){
344 BRepAdaptor_Curve aCurve(TopoDS::Edge(myShape4));
345 if (aCurve.GetType() == GeomAbs_Line) {
346 //add sensetive element - line
347 seg = new Select3D_SensitiveSegment( own, myAttachPoint4, myPoint4);
348 aSelection->Add( seg );
350 else if (aCurve.GetType() == GeomAbs_Circle){
351 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
352 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint4),
353 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint4);
354 if (LastPar < FirstPar ) LastPar+=M_PI*2;
356 Handle(Select3D_SensitiveCircle) circ =
357 new Select3D_SensitiveCircle( own,aCircle, FirstPar, LastPar);
358 aSelection->Add( circ );
362 seg = new Select3D_SensitiveSegment( own, myAttachPoint4, myPoint4);
363 aSelection->Add( seg );
367 //=======================================================================
368 //function : ComputeTwoEdgesLength
370 //=======================================================================
371 void AIS_EqualDistanceRelation::ComputeTwoEdgesLength( const Handle( Prs3d_Presentation )& aPresentation,
372 const Handle( AIS_Drawer )& aDrawer,
373 const Standard_Real ArrowSize,
374 const TopoDS_Edge & FirstEdge,
375 const TopoDS_Edge & SecondEdge,
376 const Handle( Geom_Plane )& Plane,
377 const Standard_Boolean AutomaticPos,
378 const Standard_Boolean IsSetBndBox,
379 const Bnd_Box & BndBox,
382 gp_Pnt& SecondAttach,
383 gp_Pnt& FirstExtreme,
384 gp_Pnt& SecondExtreme,
385 DsgPrs_ArrowSide & SymbolPrs )
388 BRepAdaptor_Curve cu1( FirstEdge );
389 BRepAdaptor_Curve cu2( SecondEdge );
392 Handle(Geom_Curve) geom1,geom2;
393 gp_Pnt ptat11,ptat12,ptat21,ptat22;
395 Standard_Boolean isInfinite1(Standard_False),isInfinite2(Standard_False);
396 Handle(Geom_Curve) extCurv;
397 Standard_Real arrsize = ArrowSize;// size
398 Standard_Real Val=0.;
399 Standard_Boolean isInPlane1, isInPlane2;
401 if(!AIS::ComputeGeometry(FirstEdge,geom1, ptat11, ptat12,extCurv,isInfinite1,isInPlane1, Plane ))
403 if(!AIS::ComputeGeometry(SecondEdge, geom2, ptat21, ptat22, extCurv, isInfinite2,isInPlane2, Plane))
406 aPresentation->SetInfiniteState(isInfinite1 || isInfinite2);
408 if (cu1.GetType() == GeomAbs_Line && cu2.GetType() == GeomAbs_Line)
410 const Handle(Geom_Line)& geom_lin1 = (Handle(Geom_Line)&) geom1;
411 const Handle(Geom_Line)& geom_lin2 = (Handle(Geom_Line)&) geom2;
412 const gp_Lin& l1 = geom_lin1->Lin();
413 const gp_Lin& l2 = geom_lin2->Lin();
416 Val = l1.Distance( l2 );
418 DirAttach = l1.Direction();
421 // compute position of offset point
423 Standard_Real par1=0., par2=0.;
424 if(!(isInfinite1 || isInfinite2))
426 par1 = ElCLib::Parameter(l1,ptat11);
427 par2 = ElCLib::Parameter(l1,ptat21);
428 if (par1 <par2){//project ptat11 on l2
429 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
430 curpos.SetXYZ((ptat11.XYZ()+p2.XYZ())*0.5);
432 else {//project ptat21 on l1
433 gp_Pnt p2 = ElCLib::Value(par2, l1);
434 curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())*0.5);
437 else if (!isInfinite1){
438 par2 = ElCLib::Parameter(l1,ptat21);
439 gp_Pnt p2 = ElCLib::Value(par2,l1);
440 curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())/2.);
442 else if (!isInfinite2) {
443 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
444 curpos.SetXYZ((ptat11.XYZ()+p2.XYZ())*0.5);
447 curpos.SetXYZ((l1.Location().XYZ()+l2.Location().XYZ())*0.5);
450 gp_Vec offset(DirAttach);
451 offset = offset*ArrowSize*(-10.);
452 curpos.Translate(offset);
455 else { // project point on the plane
456 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
459 // find attach points
461 if (Position.Distance(ptat11) > Position.Distance(ptat12)) FirstAttach = ptat12;
462 else FirstAttach = ptat11;
465 FirstAttach = ElCLib::Value(ElCLib::Parameter(l1,Position),l1);
469 if (Position.Distance(ptat21) > Position.Distance(ptat22)) SecondAttach = ptat22;
470 else SecondAttach = ptat21;
473 SecondAttach = ElCLib::Value(ElCLib::Parameter(l2,Position),l2);
476 Standard_Real confusion(Precision::Confusion());
477 if (arrsize < confusion) arrsize = Val*0.1;
478 if (Abs(Val) <= confusion) {arrsize = 0.;}
480 Handle(Prs3d_LengthAspect) la = aDrawer->LengthAspect();
481 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
482 arr->SetLength(arrsize);
483 arr = la->Arrow2Aspect();
484 arr->SetLength(arrsize);
486 if (AutomaticPos && IsSetBndBox)
487 Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );
489 DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
501 if (cu1.GetType() == GeomAbs_Circle && cu2.GetType() == GeomAbs_Circle){
502 //Get first and last points of circles
503 const Handle(Geom_Circle)& aCir1 = Handle(Geom_Circle)::DownCast(geom1);
504 const Handle(Geom_Circle)& aCir2 = Handle(Geom_Circle)::DownCast(geom2);
505 gp_Circ aCirc1 = aCir1->Circ();
506 gp_Circ aCirc2 = aCir2->Circ();
508 //To avoid circles with different orientaion
509 Standard_Real aTol = Precision::Confusion();
510 if(aCirc2.Axis().IsOpposite(aCirc1.Axis(), aTol) ||
511 aCirc2.XAxis().IsOpposite(aCirc1.XAxis(), aTol) ||
512 aCirc2.YAxis().IsOpposite(aCirc1.YAxis(), aTol) )
514 aCirc2.SetPosition(aCirc1.Position());
515 aCirc2.SetAxis(aCirc1.Axis());
519 Standard_Real par1 = 0, par2 = 0;
520 gp_Pln aPln = Plane->Pln();
521 //Project ptat12 and ptat22 on constraint plane
522 gp_Pnt PrPnt12 = AIS::ProjectPointOnPlane(ptat12, aPln);
523 gp_Pnt PrPnt22 = AIS::ProjectPointOnPlane(ptat22, aPln);
524 //Project circles center on constraint plane
525 gp_Pnt PrCenter = AIS::ProjectPointOnPlane(aCirc1.Location(), aPln);
527 gp_Dir XDir = aPln.XAxis().Direction();
528 gp_Dir YDir = aPln.YAxis().Direction();
531 if (PrPnt12.Distance(PrCenter) >Precision::Confusion())
533 gp_Dir aDir1(PrPnt12.XYZ() - PrCenter.XYZ());
534 Standard_Real anAngle = aDir1.Angle(XDir); //Get the angle in range [0, M_PI]
535 if (aDir1.Dot(YDir) < 0)
536 anAngle = 2 * M_PI - anAngle;
540 if (PrPnt22.Distance(PrCenter) >Precision::Confusion())
542 gp_Dir aDir2(PrPnt22.XYZ() - PrCenter.XYZ());
543 Standard_Real anAngle = aDir2.Angle(XDir); //Get the angle in range [0, M_PI]
544 if (aDir2.Dot(YDir) < 0)
545 anAngle = 2 * M_PI - anAngle;
551 FirstExtreme = ptat12;
552 Standard_Real aPar1 = ElCLib::Parameter(aCirc2, ptat12);
553 SecondExtreme = ElCLib::Value(aPar1, aCirc2);
556 Standard_Real aPar2 = ElCLib::Parameter(aCirc1, ptat22);
557 FirstExtreme = ElCLib::Value(aPar2, aCirc1);
558 SecondExtreme = ptat22;
562 Standard_Real pospar = ElCLib::Parameter(aCirc1, Position);
563 FirstExtreme = ElCLib::Value(pospar, aCirc1);
564 pospar = ElCLib::Parameter(aCirc2, Position);
565 SecondExtreme = ElCLib::Value(pospar, aCirc2);
568 DsgPrs_EqualDistancePresentation::AddIntervalBetweenTwoArcs(aPresentation,
578 FirstAttach = ptat12; SecondAttach = ptat22; //assign attach points
579 Position.SetXYZ( (FirstAttach.XYZ() + SecondAttach.XYZ())*0.5);
582 if (arrsize < Precision::Confusion()) arrsize = Val*0.1;
583 if (Abs(Val) <= Precision::Confusion()) {arrsize = 0.;}
587 AIS::ComputeProjEdgePresentation( aPresentation, aDrawer, FirstEdge, geom1, ptat11, ptat12);
590 AIS::ComputeProjEdgePresentation( aPresentation, aDrawer, SecondEdge, geom2, ptat21, ptat22);
594 //=======================================================================
595 //function : ComputeTwoVerticesLength
597 //=======================================================================
599 void AIS_EqualDistanceRelation::ComputeTwoVerticesLength( const Handle( Prs3d_Presentation )& aPresentation,
600 const Handle( AIS_Drawer )& aDrawer,
601 const Standard_Real ArrowSize,
602 const TopoDS_Vertex& FirstVertex,
603 const TopoDS_Vertex& SecondVertex,
604 const Handle( Geom_Plane )& Plane,
605 const Standard_Boolean AutomaticPos,
606 const Standard_Boolean IsSetBndBox,
607 const Bnd_Box& BndBox,
608 const AIS_TypeOfDist TypeDist,
611 gp_Pnt& SecondAttach,
612 gp_Pnt& FirstExtreme,
613 gp_Pnt& SecondExtreme,
614 DsgPrs_ArrowSide& SymbolPrs )
616 Standard_Boolean isOnPlane1, isOnPlane2;
618 AIS::ComputeGeometry( FirstVertex, FirstAttach, Plane, isOnPlane1);
619 AIS::ComputeGeometry( SecondVertex, SecondAttach, Plane, isOnPlane2);
622 Standard_Real Val = FirstAttach.Distance( SecondAttach );
623 Standard_Real confusion(Precision::Confusion());
624 Standard_Boolean samePoint(FirstAttach.IsEqual(SecondAttach,confusion));
626 if (TypeDist == AIS_TOD_Vertical) DirAttach = Plane->Pln().XAxis().Direction();
627 else if (TypeDist == AIS_TOD_Horizontal) DirAttach = Plane->Pln().YAxis().Direction();
630 DirAttach.SetXYZ(SecondAttach.XYZ() - FirstAttach.XYZ());
631 DirAttach.Rotate(Plane->Pln().Axis(),M_PI/2.);
636 Standard_Real arrsize = ArrowSize;
637 if (Abs(Val) <= confusion) arrsize =0.;
641 gp_Pnt curpos((FirstAttach.XYZ()+SecondAttach.XYZ())*0.5);
642 // make offset of curpos
643 gp_Vec offset(DirAttach);
644 offset = offset*ArrowSize*(-10.);
645 curpos.Translate(offset);
649 const gp_Dir& aDir = Plane->Pln().Axis().Direction();
650 gp_Vec aVec (aDir.XYZ()*10*ArrowSize);
651 //Position = gp_Pnt(FirstAttach.XYZ()+gp_XYZ(1.,1.,1.)); // not correct
652 Position = FirstAttach.Translated(aVec);
653 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );//not needed really
654 DirAttach.SetXYZ(Position.XYZ() - FirstAttach.XYZ());
658 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
662 Handle(Prs3d_LengthAspect) la = aDrawer->LengthAspect();
663 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
664 arr->SetLength(ArrowSize);
665 arr = la->Arrow2Aspect();
666 arr->SetLength(ArrowSize);
668 if (AutomaticPos && IsSetBndBox)
669 Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );
671 DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
678 FirstExtreme, //returned
679 SecondExtreme); //returned
681 // Compute projection
683 AIS::ComputeProjVertexPresentation(aPresentation, aDrawer, FirstVertex, FirstAttach);
685 AIS::ComputeProjVertexPresentation(aPresentation, aDrawer, SecondVertex, SecondAttach);
690 //=======================================================================
691 //function : ComputeOneEdgeOneVertexLength
693 //=======================================================================
695 void AIS_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( const Handle( Prs3d_Presentation )& aPresentation,
696 const Handle( AIS_Drawer )& aDrawer,
697 const Standard_Real ArrowSize,
698 const TopoDS_Shape & FirstShape,
699 const TopoDS_Shape & SecondShape,
700 const Handle( Geom_Plane )& Plane,
701 const Standard_Boolean AutomaticPos,
702 const Standard_Boolean IsSetBndBox,
703 const Bnd_Box & BndBox,
705 gp_Pnt & FirstAttach,
706 gp_Pnt & SecondAttach,
707 gp_Pnt& FirstExtreme,
708 gp_Pnt& SecondExtreme,
709 DsgPrs_ArrowSide & SymbolPrs )
711 TopoDS_Vertex thevertex;
714 gp_Pnt ptonedge1,ptonedge2;
715 Handle(Geom_Curve) aCurve;
716 Handle(Geom_Curve) extCurv;
717 Standard_Boolean isInfinite;
719 Standard_Boolean isOnPlanEdge, isOnPlanVertex;
720 Standard_Integer edgenum ;
722 if (FirstShape.ShapeType() == TopAbs_VERTEX) {
723 thevertex = TopoDS::Vertex(FirstShape);
724 theedge = TopoDS::Edge(SecondShape);
725 edgenum = 2; //edge is the second shape
728 thevertex = TopoDS::Vertex(SecondShape);
729 theedge = TopoDS::Edge(FirstShape);
730 edgenum = 1;//edge is the first shape
732 if (!AIS::ComputeGeometry(theedge,aCurve,ptonedge1,ptonedge2,extCurv,isInfinite,isOnPlanEdge,Plane))
734 aPresentation->SetInfiniteState(isInfinite);
735 AIS::ComputeGeometry(thevertex, FirstAttach, Plane, isOnPlanVertex);
737 if ( aCurve->IsInstance(STANDARD_TYPE(Geom_Line)) )
739 const Handle(Geom_Line)& geom_lin = (Handle(Geom_Line)&) aCurve;
740 const gp_Lin& l = geom_lin->Lin();
742 // computation of Val
743 Val = l.Distance( FirstAttach );
745 gp_Dir DirAttach = l.Direction();
747 Standard_Real arrsize = ArrowSize;
748 if (Abs(Val) <= Precision::Confusion()) {arrsize = 0.;}
751 gp_Pnt p = ElCLib::Value(ElCLib::Parameter(l,FirstAttach),l);
752 gp_Pnt curpos((FirstAttach.XYZ()+p.XYZ())*0.5);
754 gp_Vec offset(DirAttach);
755 offset = offset*ArrowSize*(-10.);
756 curpos.Translate(offset);
759 else { // project point on the plane
760 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
764 if (Position.Distance(ptonedge1) > Position.Distance(ptonedge2)) SecondAttach = ptonedge2;
765 else SecondAttach = ptonedge1;
768 SecondAttach = ElCLib::Value(ElCLib::Parameter(l,Position),l);
771 Handle(Prs3d_LengthAspect) la = aDrawer->LengthAspect();
772 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
773 arr->SetLength(arrsize);
774 arr = la->Arrow2Aspect();
775 arr->SetLength(arrsize);
777 if (AutomaticPos && IsSetBndBox)
778 Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );
779 DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
790 if (aCurve->IsInstance(STANDARD_TYPE(Geom_Circle))){
791 gp_Circ aCirc1 = (Handle(Geom_Circle)::DownCast(aCurve))->Circ();
792 gp_Circ aCirc2(aCirc1); aCirc2.SetRadius(0); //create the second formal circle
795 SecondAttach = ptonedge2; //a vertex
796 Position.SetXYZ((SecondAttach.XYZ() + aCirc1.Location().XYZ())*0.5);
799 Standard_Real aPar = ElCLib::Parameter(aCirc1, Position);
800 SecondAttach = ElCLib::Value(aPar, aCirc1);
803 Handle(Geom_Circle) aCurve2 = new Geom_Circle(aCirc2);
804 DsgPrs_EqualDistancePresentation::AddIntervalBetweenTwoArcs(aPresentation,
806 aCirc1, //circle or arc
807 aCirc2, //really vertex
808 ptonedge2, //last point of aCirc1
810 FirstAttach, //vertex really
816 FirstExtreme = SecondAttach; SecondExtreme = FirstAttach;
817 SecondAttach = FirstAttach; FirstAttach = ptonedge2;
818 } else { //vertex is the first shape, circle is sthe last.
819 FirstExtreme = FirstAttach; SecondExtreme = SecondAttach;
820 SecondAttach = ptonedge2;
824 // computation of Val
825 Val = FirstAttach.Distance(SecondAttach);
827 //Display the pieces of attached to the curve if it is not
829 if (!isOnPlanEdge) { // add presentation of projection of the edge in WP
830 AIS::ComputeProjEdgePresentation(aPresentation,aDrawer,theedge,aCurve,ptonedge1,ptonedge2);
832 if (!isOnPlanVertex) { // add presentation of projection of the vertex in WP
833 AIS::ComputeProjVertexPresentation(aPresentation,aDrawer,thevertex,FirstAttach);