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 <PrsDim_EqualDistanceRelation.hxx>
20 #include <PrsDim_LengthDimension.hxx>
21 #include <Bnd_Box.hxx>
22 #include <BRep_Tool.hxx>
23 #include <BRepAdaptor_Curve.hxx>
24 #include <BRepBuilderAPI_MakeEdge.hxx>
25 #include <BRepBuilderAPI_MakeVertex.hxx>
26 #include <DsgPrs_EqualDistancePresentation.hxx>
28 #include <Geom_Circle.hxx>
29 #include <Geom_Line.hxx>
30 #include <Geom_Plane.hxx>
31 #include <GeomAPI_ProjectPointOnCurve.hxx>
32 #include <GeomAPI_ProjectPointOnSurf.hxx>
35 #include <Precision.hxx>
36 #include <Prs3d_ArrowAspect.hxx>
37 #include <Prs3d_DimensionAspect.hxx>
38 #include <Prs3d_Drawer.hxx>
39 #include <Prs3d_Presentation.hxx>
40 #include <Select3D_SensitiveBox.hxx>
41 #include <Select3D_SensitiveCircle.hxx>
42 #include <Select3D_SensitiveSegment.hxx>
43 #include <SelectMgr_EntityOwner.hxx>
44 #include <Standard_NotImplemented.hxx>
45 #include <TopoDS_Edge.hxx>
46 #include <TopoDS_Shape.hxx>
47 #include <TopoDS_Vertex.hxx>
49 IMPLEMENT_STANDARD_RTTIEXT(PrsDim_EqualDistanceRelation, PrsDim_Relation)
51 //=======================================================================
52 //function : PrsDim_EqualDistanceRelation
54 //=======================================================================
55 PrsDim_EqualDistanceRelation::PrsDim_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 PrsDim_EqualDistanceRelation::Compute( const Handle( PrsMgr_PresentationManager3d )&,
79 const Handle( Prs3d_Presentation )& aPresentation,
80 const Standard_Integer )
82 gp_Pnt Position12 = myPosition, Position34 = myPosition;
84 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
85 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
86 arr->SetLength(myArrowSize);
88 if (!myAutomaticPosition ){
89 gp_Pnt aMiddle12 ((myPoint1.XYZ() + myPoint2.XYZ())*0.5);
90 gp_Pnt aMiddle34 ((myPoint3.XYZ() + myPoint4.XYZ())*0.5);
92 if (myPosition.Distance(aMiddle12) > myPosition.Distance(aMiddle34))
93 Position12.SetXYZ((myPoint1.XYZ() + myPoint2.XYZ())*0.5);
95 Position34.SetXYZ((myPoint3.XYZ() + myPoint4.XYZ())*0.5);
99 if (myFShape.ShapeType() == TopAbs_EDGE && mySShape.ShapeType() == TopAbs_EDGE)
100 PrsDim_EqualDistanceRelation::ComputeTwoEdgesLength(aPresentation,
103 TopoDS::Edge(myFShape),
104 TopoDS::Edge(mySShape),
117 else if (myFShape.ShapeType() == TopAbs_VERTEX && mySShape.ShapeType() == TopAbs_VERTEX)
118 PrsDim_EqualDistanceRelation::ComputeTwoVerticesLength( aPresentation,
121 TopoDS::Vertex(myFShape),
122 TopoDS::Vertex(mySShape),
127 PrsDim_TypeOfDist_Unknown,
135 PrsDim_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( aPresentation,
151 if (myShape3.ShapeType() == TopAbs_EDGE && myShape4.ShapeType() == TopAbs_EDGE)
152 PrsDim_EqualDistanceRelation::ComputeTwoEdgesLength(aPresentation,
155 TopoDS::Edge(myShape3),
156 TopoDS::Edge(myShape4),
168 else if (myShape3.ShapeType() == TopAbs_VERTEX && myShape4.ShapeType() == TopAbs_VERTEX)
169 PrsDim_EqualDistanceRelation::ComputeTwoVerticesLength( aPresentation,
172 TopoDS::Vertex(myShape3),
173 TopoDS::Vertex(myShape4),
178 PrsDim_TypeOfDist_Unknown,
187 PrsDim_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( aPresentation,
203 DsgPrs_EqualDistancePresentation::Add( aPresentation, myDrawer,
204 myPoint1, myPoint2, myPoint3, myPoint4, myPlane );
207 //=======================================================================
208 //function : ComputeSelection
210 //=======================================================================
212 void PrsDim_EqualDistanceRelation::ComputeSelection( const Handle( SelectMgr_Selection )& aSelection,
213 const Standard_Integer )
215 Handle( SelectMgr_EntityOwner ) own = new SelectMgr_EntityOwner( this, 7 );
216 Handle( Select3D_SensitiveSegment ) seg;
218 seg = new Select3D_SensitiveSegment( own, myPoint1, myPoint2 );
219 aSelection->Add( seg );
221 seg = new Select3D_SensitiveSegment( own, myPoint3, myPoint4 );
222 aSelection->Add( seg );
224 // Line between two middles
225 gp_Pnt Middle12( (myPoint1.XYZ() + myPoint2.XYZ()) * 0.5 ),
226 Middle34( (myPoint3.XYZ() + myPoint4.XYZ()) *0.5 );
227 seg = new Select3D_SensitiveSegment( own, Middle12, Middle34 );
228 aSelection->Add( seg );
230 gp_Pnt Middle((Middle12.XYZ() + Middle34.XYZ())*0.5);
231 Standard_Real SmallDist = .001;
232 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
233 Middle.X() - SmallDist,
234 Middle.Y() - SmallDist,
235 Middle.Z() - SmallDist,
236 Middle.X() + SmallDist,
237 Middle.Y() + SmallDist,
238 Middle.Z() + SmallDist );
239 aSelection->Add(box);
241 if (myFShape.ShapeType() == TopAbs_EDGE){
242 BRepAdaptor_Curve aCurve(TopoDS::Edge(myFShape));
243 if (aCurve.GetType() == GeomAbs_Line){
244 //add sensetive element - line
245 seg = new Select3D_SensitiveSegment( own, myAttachPoint1, myPoint1);
246 aSelection->Add( seg );
248 else if (aCurve.GetType() == GeomAbs_Circle){
249 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
250 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint1),
251 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint1);
252 if (LastPar < FirstPar ) LastPar+=M_PI*2;
253 Handle(Select3D_SensitiveCircle) circ = new Select3D_SensitiveCircle (own, aCircle->Circ(), FirstPar, LastPar);
254 aSelection->Add( circ );
258 seg = new Select3D_SensitiveSegment( own, myAttachPoint1, myPoint1);
259 aSelection->Add( seg );
262 if (mySShape.ShapeType() == TopAbs_EDGE){
263 BRepAdaptor_Curve aCurve(TopoDS::Edge(mySShape));
264 if (aCurve.GetType() == GeomAbs_Line) {
265 //add sensetive element - line
266 seg = new Select3D_SensitiveSegment( own, myAttachPoint2, myPoint2);
267 aSelection->Add( seg );
269 else if (aCurve.GetType() == GeomAbs_Circle){
270 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
271 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint2),
272 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint2);
273 if (LastPar < FirstPar ) LastPar+=M_PI*2;
274 Handle(Select3D_SensitiveCircle) circ = new Select3D_SensitiveCircle (own, aCircle->Circ(), FirstPar, LastPar);
275 aSelection->Add( circ );
279 seg = new Select3D_SensitiveSegment( own, myAttachPoint2, myPoint2);
280 aSelection->Add( seg );
283 if (myShape3.ShapeType() == TopAbs_EDGE){
284 BRepAdaptor_Curve aCurve(TopoDS::Edge(myShape3));
285 if (aCurve.GetType() == GeomAbs_Line) {
286 //add sensetive element - line
287 seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
288 aSelection->Add( seg );
290 else if (aCurve.GetType() == GeomAbs_Circle){
291 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
292 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint3),
293 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint3);
294 if (LastPar < FirstPar ) LastPar+=M_PI*2;
295 Handle(Select3D_SensitiveCircle) circ = new Select3D_SensitiveCircle (own, aCircle->Circ(), FirstPar, LastPar);
296 aSelection->Add( circ );
299 seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
300 aSelection->Add( seg );
304 seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
305 aSelection->Add( seg );
308 if (myShape4.ShapeType() == TopAbs_EDGE){
309 BRepAdaptor_Curve aCurve(TopoDS::Edge(myShape4));
310 if (aCurve.GetType() == GeomAbs_Line) {
311 //add sensetive element - line
312 seg = new Select3D_SensitiveSegment( own, myAttachPoint4, myPoint4);
313 aSelection->Add( seg );
315 else if (aCurve.GetType() == GeomAbs_Circle){
316 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
317 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint4),
318 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint4);
319 if (LastPar < FirstPar ) LastPar+=M_PI*2;
320 Handle(Select3D_SensitiveCircle) circ = new Select3D_SensitiveCircle (own, aCircle->Circ(), FirstPar, LastPar);
321 aSelection->Add( circ );
325 seg = new Select3D_SensitiveSegment( own, myAttachPoint4, myPoint4);
326 aSelection->Add( seg );
330 //=======================================================================
331 //function : ComputeTwoEdgesLength
333 //=======================================================================
334 void PrsDim_EqualDistanceRelation::ComputeTwoEdgesLength( const Handle( Prs3d_Presentation )& aPresentation,
335 const Handle( Prs3d_Drawer )& aDrawer,
336 const Standard_Real ArrowSize,
337 const TopoDS_Edge & FirstEdge,
338 const TopoDS_Edge & SecondEdge,
339 const Handle( Geom_Plane )& Plane,
340 const Standard_Boolean AutomaticPos,
341 const Standard_Boolean IsSetBndBox,
342 const Bnd_Box & BndBox,
345 gp_Pnt& SecondAttach,
346 gp_Pnt& FirstExtreme,
347 gp_Pnt& SecondExtreme,
348 DsgPrs_ArrowSide & SymbolPrs )
351 BRepAdaptor_Curve cu1( FirstEdge );
352 BRepAdaptor_Curve cu2( SecondEdge );
355 Handle(Geom_Curve) geom1,geom2;
356 gp_Pnt ptat11,ptat12,ptat21,ptat22;
358 Standard_Boolean isInfinite1(Standard_False),isInfinite2(Standard_False);
359 Handle(Geom_Curve) extCurv;
360 Standard_Real arrsize = ArrowSize;// size
361 Standard_Real Val=0.;
362 Standard_Boolean isInPlane1, isInPlane2;
364 if(!PrsDim::ComputeGeometry(FirstEdge,geom1, ptat11, ptat12,extCurv,isInfinite1,isInPlane1, Plane ))
366 if(!PrsDim::ComputeGeometry(SecondEdge, geom2, ptat21, ptat22, extCurv, isInfinite2,isInPlane2, Plane))
369 aPresentation->SetInfiniteState(isInfinite1 || isInfinite2);
371 if (cu1.GetType() == GeomAbs_Line && cu2.GetType() == GeomAbs_Line)
373 Handle(Geom_Line) geom_lin1 (Handle(Geom_Line)::DownCast (geom1));
374 Handle(Geom_Line) geom_lin2 (Handle(Geom_Line)::DownCast (geom2));
375 const gp_Lin& l1 = geom_lin1->Lin();
376 const gp_Lin& l2 = geom_lin2->Lin();
379 Val = l1.Distance( l2 );
381 DirAttach = l1.Direction();
384 // compute position of offset point
386 Standard_Real par1=0., par2=0.;
387 if(!(isInfinite1 || isInfinite2))
389 par1 = ElCLib::Parameter(l1,ptat11);
390 par2 = ElCLib::Parameter(l1,ptat21);
391 if (par1 <par2){//project ptat11 on l2
392 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
393 curpos.SetXYZ((ptat11.XYZ()+p2.XYZ())*0.5);
395 else {//project ptat21 on l1
396 gp_Pnt p2 = ElCLib::Value(par2, l1);
397 curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())*0.5);
400 else if (!isInfinite1){
401 par2 = ElCLib::Parameter(l1,ptat21);
402 gp_Pnt p2 = ElCLib::Value(par2,l1);
403 curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())/2.);
405 else if (!isInfinite2) {
406 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
407 curpos.SetXYZ((ptat11.XYZ()+p2.XYZ())*0.5);
410 curpos.SetXYZ((l1.Location().XYZ()+l2.Location().XYZ())*0.5);
413 gp_Vec offset(DirAttach);
414 offset = offset*ArrowSize*(-10.);
415 curpos.Translate(offset);
418 else { // project point on the plane
419 Position = PrsDim::ProjectPointOnPlane( Position, Plane->Pln() );
422 // find attach points
424 if (Position.Distance(ptat11) > Position.Distance(ptat12)) FirstAttach = ptat12;
425 else FirstAttach = ptat11;
428 FirstAttach = ElCLib::Value(ElCLib::Parameter(l1,Position),l1);
432 if (Position.Distance(ptat21) > Position.Distance(ptat22)) SecondAttach = ptat22;
433 else SecondAttach = ptat21;
436 SecondAttach = ElCLib::Value(ElCLib::Parameter(l2,Position),l2);
439 Standard_Real confusion(Precision::Confusion());
440 if (arrsize < confusion) arrsize = Val*0.1;
441 if (Abs(Val) <= confusion) {arrsize = 0.;}
443 Handle(Prs3d_DimensionAspect) la = aDrawer->DimensionAspect();
444 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
445 arr->SetLength(arrsize);
446 arr = la->ArrowAspect();
447 arr->SetLength(arrsize);
449 if (AutomaticPos && IsSetBndBox)
450 Position = PrsDim::TranslatePointToBound( Position, DirAttach, BndBox );
452 DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
464 if (cu1.GetType() == GeomAbs_Circle && cu2.GetType() == GeomAbs_Circle){
465 //Get first and last points of circles
466 Handle(Geom_Circle) aCir1 (Handle(Geom_Circle)::DownCast(geom1));
467 Handle(Geom_Circle) aCir2 (Handle(Geom_Circle)::DownCast(geom2));
468 gp_Circ aCirc1 = aCir1->Circ();
469 gp_Circ aCirc2 = aCir2->Circ();
471 //To avoid circles with different orientaion
472 Standard_Real aTol = Precision::Confusion();
473 if(aCirc2.Axis().IsOpposite(aCirc1.Axis(), aTol) ||
474 aCirc2.XAxis().IsOpposite(aCirc1.XAxis(), aTol) ||
475 aCirc2.YAxis().IsOpposite(aCirc1.YAxis(), aTol) )
477 aCirc2.SetPosition(aCirc1.Position());
478 aCirc2.SetAxis(aCirc1.Axis());
482 Standard_Real par1 = 0, par2 = 0;
483 gp_Pln aPln = Plane->Pln();
484 //Project ptat12 and ptat22 on constraint plane
485 gp_Pnt PrPnt12 = PrsDim::ProjectPointOnPlane(ptat12, aPln);
486 gp_Pnt PrPnt22 = PrsDim::ProjectPointOnPlane(ptat22, aPln);
487 //Project circles center on constraint plane
488 gp_Pnt PrCenter = PrsDim::ProjectPointOnPlane(aCirc1.Location(), aPln);
490 gp_Dir XDir = aPln.XAxis().Direction();
491 gp_Dir YDir = aPln.YAxis().Direction();
494 if (PrPnt12.Distance(PrCenter) >Precision::Confusion())
496 gp_Dir aDir1(PrPnt12.XYZ() - PrCenter.XYZ());
497 Standard_Real anAngle = aDir1.Angle(XDir); //Get the angle in range [0, M_PI]
498 if (aDir1.Dot(YDir) < 0)
499 anAngle = 2 * M_PI - anAngle;
503 if (PrPnt22.Distance(PrCenter) >Precision::Confusion())
505 gp_Dir aDir2(PrPnt22.XYZ() - PrCenter.XYZ());
506 Standard_Real anAngle = aDir2.Angle(XDir); //Get the angle in range [0, M_PI]
507 if (aDir2.Dot(YDir) < 0)
508 anAngle = 2 * M_PI - anAngle;
514 FirstExtreme = ptat12;
515 Standard_Real aPar1 = ElCLib::Parameter(aCirc2, ptat12);
516 SecondExtreme = ElCLib::Value(aPar1, aCirc2);
519 Standard_Real aPar2 = ElCLib::Parameter(aCirc1, ptat22);
520 FirstExtreme = ElCLib::Value(aPar2, aCirc1);
521 SecondExtreme = ptat22;
525 Standard_Real pospar = ElCLib::Parameter(aCirc1, Position);
526 FirstExtreme = ElCLib::Value(pospar, aCirc1);
527 pospar = ElCLib::Parameter(aCirc2, Position);
528 SecondExtreme = ElCLib::Value(pospar, aCirc2);
531 DsgPrs_EqualDistancePresentation::AddIntervalBetweenTwoArcs(aPresentation,
541 FirstAttach = ptat12; SecondAttach = ptat22; //assign attach points
542 Position.SetXYZ( (FirstAttach.XYZ() + SecondAttach.XYZ())*0.5);
545 if (arrsize < Precision::Confusion()) arrsize = Val*0.1;
546 if (Abs(Val) <= Precision::Confusion()) {arrsize = 0.;}
550 PrsDim::ComputeProjEdgePresentation( aPresentation, aDrawer, FirstEdge, geom1, ptat11, ptat12);
553 PrsDim::ComputeProjEdgePresentation( aPresentation, aDrawer, SecondEdge, geom2, ptat21, ptat22);
557 //=======================================================================
558 //function : ComputeTwoVerticesLength
560 //=======================================================================
562 void PrsDim_EqualDistanceRelation::ComputeTwoVerticesLength( const Handle( Prs3d_Presentation )& aPresentation,
563 const Handle( Prs3d_Drawer )& aDrawer,
564 const Standard_Real ArrowSize,
565 const TopoDS_Vertex& FirstVertex,
566 const TopoDS_Vertex& SecondVertex,
567 const Handle( Geom_Plane )& Plane,
568 const Standard_Boolean AutomaticPos,
569 const Standard_Boolean IsSetBndBox,
570 const Bnd_Box& BndBox,
571 const PrsDim_TypeOfDist TypeDist,
574 gp_Pnt& SecondAttach,
575 gp_Pnt& FirstExtreme,
576 gp_Pnt& SecondExtreme,
577 DsgPrs_ArrowSide& SymbolPrs )
579 Standard_Boolean isOnPlane1, isOnPlane2;
581 PrsDim::ComputeGeometry( FirstVertex, FirstAttach, Plane, isOnPlane1);
582 PrsDim::ComputeGeometry( SecondVertex, SecondAttach, Plane, isOnPlane2);
584 Standard_Real confusion(Precision::Confusion());
585 Standard_Boolean samePoint(FirstAttach.IsEqual(SecondAttach,confusion));
587 if (TypeDist == PrsDim_TypeOfDist_Vertical) DirAttach = Plane->Pln().XAxis().Direction();
588 else if (TypeDist == PrsDim_TypeOfDist_Horizontal) DirAttach = Plane->Pln().YAxis().Direction();
591 DirAttach.SetXYZ(SecondAttach.XYZ() - FirstAttach.XYZ());
592 DirAttach.Rotate(Plane->Pln().Axis(),M_PI/2.);
599 gp_Pnt curpos((FirstAttach.XYZ()+SecondAttach.XYZ())*0.5);
600 // make offset of curpos
601 gp_Vec offset(DirAttach);
602 offset = offset*ArrowSize*(-10.);
603 curpos.Translate(offset);
607 gp_Dir aDir = Plane->Pln().Axis().Direction();
608 gp_Vec aVec (aDir.XYZ()*10*ArrowSize);
609 //Position = gp_Pnt(FirstAttach.XYZ()+gp_XYZ(1.,1.,1.)); // not correct
610 Position = FirstAttach.Translated(aVec);
611 Position = PrsDim::ProjectPointOnPlane( Position, Plane->Pln() );//not needed really
612 DirAttach.SetXYZ(Position.XYZ() - FirstAttach.XYZ());
616 Position = PrsDim::ProjectPointOnPlane( Position, Plane->Pln() );
620 Handle(Prs3d_DimensionAspect) la = aDrawer->DimensionAspect();
621 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
622 arr->SetLength(ArrowSize);
623 arr = la->ArrowAspect();
624 arr->SetLength(ArrowSize);
626 if (AutomaticPos && IsSetBndBox)
627 Position = PrsDim::TranslatePointToBound( Position, DirAttach, BndBox );
629 DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
636 FirstExtreme, //returned
637 SecondExtreme); //returned
639 // Compute projection
641 PrsDim::ComputeProjVertexPresentation(aPresentation, aDrawer, FirstVertex, FirstAttach);
643 PrsDim::ComputeProjVertexPresentation(aPresentation, aDrawer, SecondVertex, SecondAttach);
648 //=======================================================================
649 //function : ComputeOneEdgeOneVertexLength
651 //=======================================================================
653 void PrsDim_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( const Handle( Prs3d_Presentation )& aPresentation,
654 const Handle( Prs3d_Drawer )& aDrawer,
655 const Standard_Real ArrowSize,
656 const TopoDS_Shape & FirstShape,
657 const TopoDS_Shape & SecondShape,
658 const Handle( Geom_Plane )& Plane,
659 const Standard_Boolean AutomaticPos,
660 const Standard_Boolean IsSetBndBox,
661 const Bnd_Box & BndBox,
663 gp_Pnt & FirstAttach,
664 gp_Pnt & SecondAttach,
665 gp_Pnt& FirstExtreme,
666 gp_Pnt& SecondExtreme,
667 DsgPrs_ArrowSide & SymbolPrs )
669 TopoDS_Vertex thevertex;
672 gp_Pnt ptonedge1,ptonedge2;
673 Handle(Geom_Curve) aCurve;
674 Handle(Geom_Curve) extCurv;
675 Standard_Boolean isInfinite;
677 Standard_Boolean isOnPlanEdge, isOnPlanVertex;
678 Standard_Integer edgenum ;
680 if (FirstShape.ShapeType() == TopAbs_VERTEX) {
681 thevertex = TopoDS::Vertex(FirstShape);
682 theedge = TopoDS::Edge(SecondShape);
683 edgenum = 2; //edge is the second shape
686 thevertex = TopoDS::Vertex(SecondShape);
687 theedge = TopoDS::Edge(FirstShape);
688 edgenum = 1;//edge is the first shape
690 if (!PrsDim::ComputeGeometry(theedge,aCurve,ptonedge1,ptonedge2,extCurv,isInfinite,isOnPlanEdge,Plane))
692 aPresentation->SetInfiniteState(isInfinite);
693 PrsDim::ComputeGeometry(thevertex, FirstAttach, Plane, isOnPlanVertex);
695 if ( aCurve->IsInstance(STANDARD_TYPE(Geom_Line)) )
697 Handle(Geom_Line) geom_lin (Handle(Geom_Line)::DownCast (aCurve));
698 const gp_Lin& l = geom_lin->Lin();
700 // computation of Val
701 Val = l.Distance( FirstAttach );
703 gp_Dir DirAttach = l.Direction();
705 Standard_Real arrsize = ArrowSize;
706 if (Abs(Val) <= Precision::Confusion()) {arrsize = 0.;}
709 gp_Pnt p = ElCLib::Value(ElCLib::Parameter(l,FirstAttach),l);
710 gp_Pnt curpos((FirstAttach.XYZ()+p.XYZ())*0.5);
712 gp_Vec offset(DirAttach);
713 offset = offset*ArrowSize*(-10.);
714 curpos.Translate(offset);
717 else { // project point on the plane
718 Position = PrsDim::ProjectPointOnPlane( Position, Plane->Pln() );
722 if (Position.Distance(ptonedge1) > Position.Distance(ptonedge2)) SecondAttach = ptonedge2;
723 else SecondAttach = ptonedge1;
726 SecondAttach = ElCLib::Value(ElCLib::Parameter(l,Position),l);
729 Handle(Prs3d_DimensionAspect) la = aDrawer->DimensionAspect();
730 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
731 arr->SetLength(arrsize);
732 arr = la->ArrowAspect();
733 arr->SetLength(arrsize);
735 if (AutomaticPos && IsSetBndBox)
736 Position = PrsDim::TranslatePointToBound( Position, DirAttach, BndBox );
737 DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
748 if (aCurve->IsInstance(STANDARD_TYPE(Geom_Circle))){
749 gp_Circ aCirc1 = (Handle(Geom_Circle)::DownCast(aCurve))->Circ();
750 gp_Circ aCirc2(aCirc1); aCirc2.SetRadius(0); //create the second formal circle
753 SecondAttach = ptonedge2; //a vertex
754 Position.SetXYZ((SecondAttach.XYZ() + aCirc1.Location().XYZ())*0.5);
757 Standard_Real aPar = ElCLib::Parameter(aCirc1, Position);
758 SecondAttach = ElCLib::Value(aPar, aCirc1);
761 Handle(Geom_Circle) aCurve2 = new Geom_Circle(aCirc2);
762 DsgPrs_EqualDistancePresentation::AddIntervalBetweenTwoArcs(aPresentation,
764 aCirc1, //circle or arc
765 aCirc2, //really vertex
766 ptonedge2, //last point of aCirc1
768 FirstAttach, //vertex really
774 FirstExtreme = SecondAttach; SecondExtreme = FirstAttach;
775 SecondAttach = FirstAttach; FirstAttach = ptonedge2;
776 } else { //vertex is the first shape, circle is sthe last.
777 FirstExtreme = FirstAttach; SecondExtreme = SecondAttach;
778 SecondAttach = ptonedge2;
782 // computation of Val
783 Val = FirstAttach.Distance(SecondAttach);
785 //Display the pieces of attached to the curve if it is not
787 if (!isOnPlanEdge) { // add presentation of projection of the edge in WP
788 PrsDim::ComputeProjEdgePresentation(aPresentation,aDrawer,theedge,aCurve,ptonedge1,ptonedge2);
790 if (!isOnPlanVertex) { // add presentation of projection of the vertex in WP
791 PrsDim::ComputeProjVertexPresentation(aPresentation,aDrawer,thevertex,FirstAttach);