0025576: Visualization - implement AIS_ConnectedInteractive::AcceptDisplayMode()
[occt.git] / src / AIS / AIS_EqualDistanceRelation.cxx
CommitLineData
b311480e 1// Created on: 1998-01-24
2// Created by: Julia GERASIMOVA
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
42cf5bc1 18#include <AIS_EqualDistanceRelation.hxx>
7fd59977 19#include <AIS_LengthDimension.hxx>
42cf5bc1 20#include <Bnd_Box.hxx>
21#include <BRep_Tool.hxx>
7fd59977 22#include <BRepAdaptor_Curve.hxx>
23#include <BRepBuilderAPI_MakeEdge.hxx>
24#include <BRepBuilderAPI_MakeVertex.hxx>
42cf5bc1 25#include <DsgPrs_EqualDistancePresentation.hxx>
26#include <ElCLib.hxx>
27#include <Geom_Circle.hxx>
28#include <Geom_Line.hxx>
29#include <Geom_Plane.hxx>
30#include <Geom_Transformation.hxx>
7fd59977 31#include <GeomAPI_ProjectPointOnCurve.hxx>
32#include <GeomAPI_ProjectPointOnSurf.hxx>
42cf5bc1 33#include <gp_Lin.hxx>
34#include <gp_Pnt.hxx>
35#include <Precision.hxx>
7fd59977 36#include <Prs3d_ArrowAspect.hxx>
42cf5bc1 37#include <Prs3d_DimensionAspect.hxx>
6262338c 38#include <Prs3d_Drawer.hxx>
42cf5bc1 39#include <Prs3d_Presentation.hxx>
40#include <Prs3d_Projector.hxx>
41#include <Select3D_SensitiveBox.hxx>
42#include <Select3D_SensitiveCircle.hxx>
43#include <Select3D_SensitiveSegment.hxx>
44#include <SelectMgr_EntityOwner.hxx>
45#include <Standard_NotImplemented.hxx>
46#include <Standard_Type.hxx>
47#include <TopoDS_Edge.hxx>
48#include <TopoDS_Shape.hxx>
49#include <TopoDS_Vertex.hxx>
50
92efcf78 51IMPLEMENT_STANDARD_RTTIEXT(AIS_EqualDistanceRelation,AIS_Relation)
52
7fd59977 53//=======================================================================
54//function : AIS_EqualDistanceRelation
55//purpose :
56//=======================================================================
7fd59977 57AIS_EqualDistanceRelation::AIS_EqualDistanceRelation( const TopoDS_Shape& aShape1,
58 const TopoDS_Shape& aShape2,
59 const TopoDS_Shape& aShape3,
60 const TopoDS_Shape& aShape4,
61 const Handle( Geom_Plane )& aPlane )
62 :AIS_Relation()
63{
64 myFShape = aShape1;
65 mySShape = aShape2;
66 myShape3 = aShape3;
67 myShape4 = aShape4;
68 myPlane = aPlane;
69
70 //Temporary
71 myArrowSize = 3.0; //set the concrete value
72 mySymbolPrs = DsgPrs_AS_BOTHAR;
73}
74
75//=======================================================================
76//function : Compute
77//purpose :
78//=======================================================================
79
80void AIS_EqualDistanceRelation::Compute( const Handle( PrsMgr_PresentationManager3d )&,
81 const Handle( Prs3d_Presentation )& aPresentation,
82 const Standard_Integer )
83{
84
85 aPresentation->Clear();
86
87 gp_Pnt Position12 = myPosition, Position34 = myPosition;
88
a6eb515f 89 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
90 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 91 arr->SetLength(myArrowSize);
92// -- ota -- begin
93 if (!myAutomaticPosition ){
94 gp_Pnt aMiddle12 ((myPoint1.XYZ() + myPoint2.XYZ())*0.5);
95 gp_Pnt aMiddle34 ((myPoint3.XYZ() + myPoint4.XYZ())*0.5);
96
97 if (myPosition.Distance(aMiddle12) > myPosition.Distance(aMiddle34))
98 Position12.SetXYZ((myPoint1.XYZ() + myPoint2.XYZ())*0.5);
99 else
100 Position34.SetXYZ((myPoint3.XYZ() + myPoint4.XYZ())*0.5);
101
102 }
103
104 if (myFShape.ShapeType() == TopAbs_EDGE && mySShape.ShapeType() == TopAbs_EDGE)
105 AIS_EqualDistanceRelation::ComputeTwoEdgesLength(aPresentation,
106 myDrawer,
107 myArrowSize,
108 TopoDS::Edge(myFShape),
109 TopoDS::Edge(mySShape),
110 myPlane,
111 myAutomaticPosition,
112 myIsSetBndBox,
113 myBndBox,
114 Position12,
115 myAttachPoint1,
116 myAttachPoint2,
117 myPoint1,
118 myPoint2,
119 mySymbolPrs );
120
121
122 else if (myFShape.ShapeType() == TopAbs_VERTEX && mySShape.ShapeType() == TopAbs_VERTEX)
123 AIS_EqualDistanceRelation::ComputeTwoVerticesLength( aPresentation,
124 myDrawer,
125 myArrowSize,
126 TopoDS::Vertex(myFShape),
127 TopoDS::Vertex(mySShape),
128 myPlane,
129 myAutomaticPosition,
130 myIsSetBndBox,
131 myBndBox,
132 AIS_TOD_Unknown,
133 Position12,
134 myAttachPoint1,
135 myAttachPoint2,
136 myPoint1,
137 myPoint2,
138 mySymbolPrs );
139 else
140 AIS_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( aPresentation,
141 myDrawer,
142 myArrowSize,
143 myFShape,
144 mySShape,
145 myPlane,
146 myAutomaticPosition,
147 myIsSetBndBox,
148 myBndBox,
149 Position12,
150 myAttachPoint1,
151 myAttachPoint2,
152 myPoint1,
153 myPoint2,
154 mySymbolPrs );
155
156 if (myShape3.ShapeType() == TopAbs_EDGE && myShape4.ShapeType() == TopAbs_EDGE)
157 AIS_EqualDistanceRelation::ComputeTwoEdgesLength(aPresentation,
158 myDrawer,
159 myArrowSize,
160 TopoDS::Edge(myShape3),
161 TopoDS::Edge(myShape4),
162 myPlane,
163 myAutomaticPosition,
164 myIsSetBndBox,
165 myBndBox,
166 Position34,
167 myAttachPoint3,
168 myAttachPoint4,
169 myPoint3,
170 myPoint4,
171 mySymbolPrs );
172
173 else if (myShape3.ShapeType() == TopAbs_VERTEX && myShape4.ShapeType() == TopAbs_VERTEX)
174 AIS_EqualDistanceRelation::ComputeTwoVerticesLength( aPresentation,
175 myDrawer,
176 myArrowSize,
177 TopoDS::Vertex(myShape3),
178 TopoDS::Vertex(myShape4),
179 myPlane,
180 myAutomaticPosition,
181 myIsSetBndBox,
182 myBndBox,
183 AIS_TOD_Unknown,
184 Position34,
185 myAttachPoint3,
186 myAttachPoint4,
187 myPoint3,
188 myPoint4,
189 mySymbolPrs );
190
191 else
192 AIS_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( aPresentation,
193 myDrawer,
194 myArrowSize,
195 myShape3,
196 myShape4,
197 myPlane,
198 myAutomaticPosition,
199 myIsSetBndBox,
200 myBndBox,
201 Position34,
202 myAttachPoint3,
203 myAttachPoint4,
204 myPoint3,
205 myPoint4,
206 mySymbolPrs );
207
208 DsgPrs_EqualDistancePresentation::Add( aPresentation, myDrawer,
209 myPoint1, myPoint2, myPoint3, myPoint4, myPlane );
210}
211
212
213//=======================================================================
214//function : Compute
215//purpose : to avoid warning at compilation (SUN)
216//=======================================================================
217
35e08fe8 218void AIS_EqualDistanceRelation::Compute( const Handle( Prs3d_Projector )& /*aProjector*/,
219 const Handle( Prs3d_Presentation )& /*aPresentation*/)
7fd59977 220{
221// Standard_NotImplemented::Raise("AIS_EqualDistanceRelation::Compute( const Handle( Prs3d_Projector )&,
222 // const Handle( Prs3d_Presentation )& )");
223// PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
224}
225
7fd59977 226//=======================================================================
227//function : Compute
228//purpose : to avoid warning at compilation (SUN)
229//=======================================================================
230void AIS_EqualDistanceRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
231 const Handle(Geom_Transformation)& aTransformation,
232 const Handle(Prs3d_Presentation)& aPresentation)
233{
234// Standard_NotImplemented::Raise("AIS_EqualDistanceRelation::Compute(const Handle(Prs3d_Projector)&,
235// const Handle(Geom_Transformation)&,const Handle(Prs3d_Presentation)&)");
236 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
237}
238
239//=======================================================================
240//function : ComputeSelection
241//purpose :
242//=======================================================================
243
244void AIS_EqualDistanceRelation::ComputeSelection( const Handle( SelectMgr_Selection )& aSelection,
245 const Standard_Integer )
246{
247 Handle( SelectMgr_EntityOwner ) own = new SelectMgr_EntityOwner( this, 7 );
248 Handle( Select3D_SensitiveSegment ) seg;
249
250 seg = new Select3D_SensitiveSegment( own, myPoint1, myPoint2 );
251 aSelection->Add( seg );
252
253 seg = new Select3D_SensitiveSegment( own, myPoint3, myPoint4 );
254 aSelection->Add( seg );
255
256 // Line between two middles
257 gp_Pnt Middle12( (myPoint1.XYZ() + myPoint2.XYZ()) * 0.5 ),
258 Middle34( (myPoint3.XYZ() + myPoint4.XYZ()) *0.5 );
259 seg = new Select3D_SensitiveSegment( own, Middle12, Middle34 );
260 aSelection->Add( seg );
261
262 gp_Pnt Middle((Middle12.XYZ() + Middle34.XYZ())*0.5);
263 Standard_Real SmallDist = .001;
264 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
265 Middle.X() - SmallDist,
266 Middle.Y() - SmallDist,
267 Middle.Z() - SmallDist,
268 Middle.X() + SmallDist,
269 Middle.Y() + SmallDist,
270 Middle.Z() + SmallDist );
271 aSelection->Add(box);
272
273 if (myFShape.ShapeType() == TopAbs_EDGE){
274 BRepAdaptor_Curve aCurve(TopoDS::Edge(myFShape));
275 if (aCurve.GetType() == GeomAbs_Line){
276 //add sensetive element - line
277 seg = new Select3D_SensitiveSegment( own, myAttachPoint1, myPoint1);
278 aSelection->Add( seg );
279 }
280 else if (aCurve.GetType() == GeomAbs_Circle){
281 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
282 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint1),
283 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint1);
c6541a0c 284 if (LastPar < FirstPar ) LastPar+=M_PI*2;
7fd59977 285 //add sensetive arc
286 Handle(Select3D_SensitiveCircle) circ =
287 new Select3D_SensitiveCircle( own, aCircle, FirstPar, LastPar);
288 aSelection->Add( circ );
289 }
290 }
291 else {
292 seg = new Select3D_SensitiveSegment( own, myAttachPoint1, myPoint1);
293 aSelection->Add( seg );
294 }
295
296 if (mySShape.ShapeType() == TopAbs_EDGE){
297 BRepAdaptor_Curve aCurve(TopoDS::Edge(mySShape));
298 if (aCurve.GetType() == GeomAbs_Line) {
299 //add sensetive element - line
300 seg = new Select3D_SensitiveSegment( own, myAttachPoint2, myPoint2);
301 aSelection->Add( seg );
302 }
303 else if (aCurve.GetType() == GeomAbs_Circle){
304 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
305 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint2),
306 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint2);
c6541a0c 307 if (LastPar < FirstPar ) LastPar+=M_PI*2;
7fd59977 308 //add sensetive arc
309 Handle(Select3D_SensitiveCircle) circ =
310 new Select3D_SensitiveCircle( own,aCircle, FirstPar, LastPar);
311 aSelection->Add( circ );
312 }
313 }
314 else {
315 seg = new Select3D_SensitiveSegment( own, myAttachPoint2, myPoint2);
316 aSelection->Add( seg );
317 }
318
319 if (myShape3.ShapeType() == TopAbs_EDGE){
320 BRepAdaptor_Curve aCurve(TopoDS::Edge(myShape3));
321 if (aCurve.GetType() == GeomAbs_Line) {
322 //add sensetive element - line
323 seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
324 aSelection->Add( seg );
325 }
326 else if (aCurve.GetType() == GeomAbs_Circle){
327 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
328 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint3),
329 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint3);
c6541a0c 330 if (LastPar < FirstPar ) LastPar+=M_PI*2;
7fd59977 331 Handle(Select3D_SensitiveCircle) circ =
332 new Select3D_SensitiveCircle( own, aCircle, FirstPar, LastPar);
333 aSelection->Add( circ );
334 }
335 else {
336 seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
337 aSelection->Add( seg );
338 }
339 }
340 else {
341 seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
342 aSelection->Add( seg );
343 }
344
345 if (myShape4.ShapeType() == TopAbs_EDGE){
346 BRepAdaptor_Curve aCurve(TopoDS::Edge(myShape4));
347 if (aCurve.GetType() == GeomAbs_Line) {
348 //add sensetive element - line
349 seg = new Select3D_SensitiveSegment( own, myAttachPoint4, myPoint4);
350 aSelection->Add( seg );
351 }
352 else if (aCurve.GetType() == GeomAbs_Circle){
353 Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
354 Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint4),
355 LastPar = ElCLib::Parameter(aCircle->Circ(), myPoint4);
c6541a0c 356 if (LastPar < FirstPar ) LastPar+=M_PI*2;
7fd59977 357 //add sensetive arc
358 Handle(Select3D_SensitiveCircle) circ =
359 new Select3D_SensitiveCircle( own,aCircle, FirstPar, LastPar);
360 aSelection->Add( circ );
361 }
362 }
363 else {
364 seg = new Select3D_SensitiveSegment( own, myAttachPoint4, myPoint4);
365 aSelection->Add( seg );
366 }
367}
368
369//=======================================================================
370//function : ComputeTwoEdgesLength
371//purpose :
372//=======================================================================
373void AIS_EqualDistanceRelation::ComputeTwoEdgesLength( const Handle( Prs3d_Presentation )& aPresentation,
6262338c 374 const Handle( Prs3d_Drawer )& aDrawer,
7fd59977 375 const Standard_Real ArrowSize,
376 const TopoDS_Edge & FirstEdge,
377 const TopoDS_Edge & SecondEdge,
378 const Handle( Geom_Plane )& Plane,
379 const Standard_Boolean AutomaticPos,
380 const Standard_Boolean IsSetBndBox,
381 const Bnd_Box & BndBox,
382 gp_Pnt& Position,
383 gp_Pnt& FirstAttach,
384 gp_Pnt& SecondAttach,
385 gp_Pnt& FirstExtreme,
386 gp_Pnt& SecondExtreme,
387 DsgPrs_ArrowSide & SymbolPrs )
388{
389 gp_Dir DirAttach;
390 BRepAdaptor_Curve cu1( FirstEdge );
391 BRepAdaptor_Curve cu2( SecondEdge );
392
393 // 3d lines
394 Handle(Geom_Curve) geom1,geom2;
395 gp_Pnt ptat11,ptat12,ptat21,ptat22;
396
397 Standard_Boolean isInfinite1(Standard_False),isInfinite2(Standard_False);
398 Handle(Geom_Curve) extCurv;
399 Standard_Real arrsize = ArrowSize;// size
400 Standard_Real Val=0.;
401 Standard_Boolean isInPlane1, isInPlane2;
402
403 if(!AIS::ComputeGeometry(FirstEdge,geom1, ptat11, ptat12,extCurv,isInfinite1,isInPlane1, Plane ))
404 return;
405 if(!AIS::ComputeGeometry(SecondEdge, geom2, ptat21, ptat22, extCurv, isInfinite2,isInPlane2, Plane))
406 return;
407
408 aPresentation->SetInfiniteState(isInfinite1 || isInfinite2);
409
410 if (cu1.GetType() == GeomAbs_Line && cu2.GetType() == GeomAbs_Line)
411 {
c5f3a425 412 Handle(Geom_Line) geom_lin1 (Handle(Geom_Line)::DownCast (geom1));
413 Handle(Geom_Line) geom_lin2 (Handle(Geom_Line)::DownCast (geom2));
7fd59977 414 const gp_Lin& l1 = geom_lin1->Lin();
415 const gp_Lin& l2 = geom_lin2->Lin();
416
417 //Get Val value
418 Val = l1.Distance( l2 );
419
420 DirAttach = l1.Direction();
421
422 if (AutomaticPos) {
423 // compute position of offset point
424 gp_Pnt curpos;
425 Standard_Real par1=0., par2=0.;
426 if(!(isInfinite1 || isInfinite2))
427 {
428 par1 = ElCLib::Parameter(l1,ptat11);
429 par2 = ElCLib::Parameter(l1,ptat21);
430 if (par1 <par2){//project ptat11 on l2
431 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
432 curpos.SetXYZ((ptat11.XYZ()+p2.XYZ())*0.5);
433 }
434 else {//project ptat21 on l1
435 gp_Pnt p2 = ElCLib::Value(par2, l1);
436 curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())*0.5);
437 }
438 }
439 else if (!isInfinite1){
440 par2 = ElCLib::Parameter(l1,ptat21);
441 gp_Pnt p2 = ElCLib::Value(par2,l1);
442 curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())/2.);
443 }
444 else if (!isInfinite2) {
445 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
446 curpos.SetXYZ((ptat11.XYZ()+p2.XYZ())*0.5);
447 }
448 else
449 curpos.SetXYZ((l1.Location().XYZ()+l2.Location().XYZ())*0.5);
450
451 // compute offset
452 gp_Vec offset(DirAttach);
453 offset = offset*ArrowSize*(-10.);
454 curpos.Translate(offset);
455 Position = curpos;
456 }
457 else { // project point on the plane
458 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
459 }
460
81bba717 461 // find attach points
7fd59977 462 if (!isInfinite1) {
463 if (Position.Distance(ptat11) > Position.Distance(ptat12)) FirstAttach = ptat12;
464 else FirstAttach = ptat11;
465 }
466 else {
467 FirstAttach = ElCLib::Value(ElCLib::Parameter(l1,Position),l1);
468 }
469
470 if (!isInfinite2) {
471 if (Position.Distance(ptat21) > Position.Distance(ptat22)) SecondAttach = ptat22;
472 else SecondAttach = ptat21;
473 }
474 else {
475 SecondAttach = ElCLib::Value(ElCLib::Parameter(l2,Position),l2);
476 }
477
478 Standard_Real confusion(Precision::Confusion());
479 if (arrsize < confusion) arrsize = Val*0.1;
480 if (Abs(Val) <= confusion) {arrsize = 0.;}
481
a6eb515f 482 Handle(Prs3d_DimensionAspect) la = aDrawer->DimensionAspect();
483 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 484 arr->SetLength(arrsize);
a6eb515f 485 arr = la->ArrowAspect();
7fd59977 486 arr->SetLength(arrsize);
487
488 if (AutomaticPos && IsSetBndBox)
489 Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );
490
491 DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
492 aDrawer,
493 FirstAttach,
494 SecondAttach,
495 DirAttach,
496 Position,
497 SymbolPrs,
498 FirstExtreme,
499 SecondExtreme);
500
501
502}
503 if (cu1.GetType() == GeomAbs_Circle && cu2.GetType() == GeomAbs_Circle){
504 //Get first and last points of circles
c5f3a425 505 Handle(Geom_Circle) aCir1 (Handle(Geom_Circle)::DownCast(geom1));
506 Handle(Geom_Circle) aCir2 (Handle(Geom_Circle)::DownCast(geom2));
7fd59977 507 gp_Circ aCirc1 = aCir1->Circ();
508 gp_Circ aCirc2 = aCir2->Circ();
509
510 //To avoid circles with different orientaion
511 Standard_Real aTol = Precision::Confusion();
512 if(aCirc2.Axis().IsOpposite(aCirc1.Axis(), aTol) ||
513 aCirc2.XAxis().IsOpposite(aCirc1.XAxis(), aTol) ||
514 aCirc2.YAxis().IsOpposite(aCirc1.YAxis(), aTol) )
515 {
516 aCirc2.SetPosition(aCirc1.Position());
517 aCirc2.SetAxis(aCirc1.Axis());
518 }
519
520 if (AutomaticPos){
521 Standard_Real par1 = 0, par2 = 0;
522 gp_Pln aPln = Plane->Pln();
523 //Project ptat12 and ptat22 on constraint plane
524 gp_Pnt PrPnt12 = AIS::ProjectPointOnPlane(ptat12, aPln);
525 gp_Pnt PrPnt22 = AIS::ProjectPointOnPlane(ptat22, aPln);
526 //Project circles center on constraint plane
527 gp_Pnt PrCenter = AIS::ProjectPointOnPlane(aCirc1.Location(), aPln);
528
529 gp_Dir XDir = aPln.XAxis().Direction();
530 gp_Dir YDir = aPln.YAxis().Direction();
531
532
533 if (PrPnt12.Distance(PrCenter) >Precision::Confusion())
534 {
535 gp_Dir aDir1(PrPnt12.XYZ() - PrCenter.XYZ());
c6541a0c 536 Standard_Real anAngle = aDir1.Angle(XDir); //Get the angle in range [0, M_PI]
7fd59977 537 if (aDir1.Dot(YDir) < 0)
c6541a0c 538 anAngle = 2 * M_PI - anAngle;
7fd59977 539 par1 = anAngle;
540 }
541
542 if (PrPnt22.Distance(PrCenter) >Precision::Confusion())
543 {
544 gp_Dir aDir2(PrPnt22.XYZ() - PrCenter.XYZ());
c6541a0c 545 Standard_Real anAngle = aDir2.Angle(XDir); //Get the angle in range [0, M_PI]
7fd59977 546 if (aDir2.Dot(YDir) < 0)
c6541a0c 547 anAngle = 2 * M_PI - anAngle;
7fd59977 548 par2 = anAngle;
549 }
550
551
552 if(par1 > par2 ){
553 FirstExtreme = ptat12;
554 Standard_Real aPar1 = ElCLib::Parameter(aCirc2, ptat12);
555 SecondExtreme = ElCLib::Value(aPar1, aCirc2);
556 }
557 else {
558 Standard_Real aPar2 = ElCLib::Parameter(aCirc1, ptat22);
559 FirstExtreme = ElCLib::Value(aPar2, aCirc1);
560 SecondExtreme = ptat22;
561 }
562 }
563 else {
564 Standard_Real pospar = ElCLib::Parameter(aCirc1, Position);
565 FirstExtreme = ElCLib::Value(pospar, aCirc1);
566 pospar = ElCLib::Parameter(aCirc2, Position);
567 SecondExtreme = ElCLib::Value(pospar, aCirc2);
568 }
569
570 DsgPrs_EqualDistancePresentation::AddIntervalBetweenTwoArcs(aPresentation,
571 aDrawer,
572 aCirc1,
573 aCirc2,
574 ptat12,
575 FirstExtreme,
576 ptat22,
577 SecondExtreme,
578 SymbolPrs);
579
580 FirstAttach = ptat12; SecondAttach = ptat22; //assign attach points
581 Position.SetXYZ( (FirstAttach.XYZ() + SecondAttach.XYZ())*0.5);
582 }
583
584 if (arrsize < Precision::Confusion()) arrsize = Val*0.1;
585 if (Abs(Val) <= Precision::Confusion()) {arrsize = 0.;}
586
587// gp_Pnt pf, pl;
588 if (!isInPlane1) {
589 AIS::ComputeProjEdgePresentation( aPresentation, aDrawer, FirstEdge, geom1, ptat11, ptat12);
590 }
591 if(!isInPlane2) {
592 AIS::ComputeProjEdgePresentation( aPresentation, aDrawer, SecondEdge, geom2, ptat21, ptat22);
593 }
594}
595
596//=======================================================================
597//function : ComputeTwoVerticesLength
598//purpose :
599//=======================================================================
600
601void AIS_EqualDistanceRelation::ComputeTwoVerticesLength( const Handle( Prs3d_Presentation )& aPresentation,
6262338c 602 const Handle( Prs3d_Drawer )& aDrawer,
7fd59977 603 const Standard_Real ArrowSize,
604 const TopoDS_Vertex& FirstVertex,
605 const TopoDS_Vertex& SecondVertex,
606 const Handle( Geom_Plane )& Plane,
607 const Standard_Boolean AutomaticPos,
608 const Standard_Boolean IsSetBndBox,
609 const Bnd_Box& BndBox,
610 const AIS_TypeOfDist TypeDist,
611 gp_Pnt& Position,
612 gp_Pnt& FirstAttach,
613 gp_Pnt& SecondAttach,
614 gp_Pnt& FirstExtreme,
615 gp_Pnt& SecondExtreme,
616 DsgPrs_ArrowSide& SymbolPrs )
617{
618 Standard_Boolean isOnPlane1, isOnPlane2;
619 gp_Dir DirAttach;
620 AIS::ComputeGeometry( FirstVertex, FirstAttach, Plane, isOnPlane1);
621 AIS::ComputeGeometry( SecondVertex, SecondAttach, Plane, isOnPlane2);
622
7fd59977 623 Standard_Real confusion(Precision::Confusion());
624 Standard_Boolean samePoint(FirstAttach.IsEqual(SecondAttach,confusion));
625
626 if (TypeDist == AIS_TOD_Vertical) DirAttach = Plane->Pln().XAxis().Direction();
627 else if (TypeDist == AIS_TOD_Horizontal) DirAttach = Plane->Pln().YAxis().Direction();
628 else {
629 if (!samePoint) {
630 DirAttach.SetXYZ(SecondAttach.XYZ() - FirstAttach.XYZ());
c6541a0c 631 DirAttach.Rotate(Plane->Pln().Axis(),M_PI/2.);
7fd59977 632 }
633 }
634
635 // size
7fd59977 636 if (AutomaticPos) {
637 if (!samePoint) {
638 gp_Pnt curpos((FirstAttach.XYZ()+SecondAttach.XYZ())*0.5);
639 // make offset of curpos
640 gp_Vec offset(DirAttach);
641 offset = offset*ArrowSize*(-10.);
642 curpos.Translate(offset);
643 Position = curpos;
644 }
645 else {
646 const gp_Dir& aDir = Plane->Pln().Axis().Direction();
647 gp_Vec aVec (aDir.XYZ()*10*ArrowSize);
648 //Position = gp_Pnt(FirstAttach.XYZ()+gp_XYZ(1.,1.,1.)); // not correct
649 Position = FirstAttach.Translated(aVec);
650 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );//not needed really
651 DirAttach.SetXYZ(Position.XYZ() - FirstAttach.XYZ());
652 }
653 }
654 else {
655 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
656 }
657
658
a6eb515f 659 Handle(Prs3d_DimensionAspect) la = aDrawer->DimensionAspect();
660 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 661 arr->SetLength(ArrowSize);
a6eb515f 662 arr = la->ArrowAspect();
7fd59977 663 arr->SetLength(ArrowSize);
664
665 if (AutomaticPos && IsSetBndBox)
666 Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );
667
668 DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
669 aDrawer,
670 FirstAttach,
671 SecondAttach,
672 DirAttach,
673 Position,
674 SymbolPrs,
675 FirstExtreme, //returned
676 SecondExtreme); //returned
677
678 // Compute projection
679 if ( !isOnPlane1)
680 AIS::ComputeProjVertexPresentation(aPresentation, aDrawer, FirstVertex, FirstAttach);
681 if ( !isOnPlane2)
682 AIS::ComputeProjVertexPresentation(aPresentation, aDrawer, SecondVertex, SecondAttach);
683
684}
685
686
687//=======================================================================
688//function : ComputeOneEdgeOneVertexLength
689//purpose :
690//=======================================================================
691
692void AIS_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( const Handle( Prs3d_Presentation )& aPresentation,
6262338c 693 const Handle( Prs3d_Drawer )& aDrawer,
7fd59977 694 const Standard_Real ArrowSize,
695 const TopoDS_Shape & FirstShape,
696 const TopoDS_Shape & SecondShape,
697 const Handle( Geom_Plane )& Plane,
698 const Standard_Boolean AutomaticPos,
699 const Standard_Boolean IsSetBndBox,
700 const Bnd_Box & BndBox,
701 gp_Pnt & Position,
702 gp_Pnt & FirstAttach,
703 gp_Pnt & SecondAttach,
704 gp_Pnt& FirstExtreme,
705 gp_Pnt& SecondExtreme,
706 DsgPrs_ArrowSide & SymbolPrs )
707{
708 TopoDS_Vertex thevertex;
709 TopoDS_Edge theedge;
710
711 gp_Pnt ptonedge1,ptonedge2;
712 Handle(Geom_Curve) aCurve;
713 Handle(Geom_Curve) extCurv;
714 Standard_Boolean isInfinite;
715 Standard_Real Val;
716 Standard_Boolean isOnPlanEdge, isOnPlanVertex;
717 Standard_Integer edgenum ;
718
719 if (FirstShape.ShapeType() == TopAbs_VERTEX) {
720 thevertex = TopoDS::Vertex(FirstShape);
721 theedge = TopoDS::Edge(SecondShape);
722 edgenum = 2; //edge is the second shape
723 }
724 else {
725 thevertex = TopoDS::Vertex(SecondShape);
726 theedge = TopoDS::Edge(FirstShape);
727 edgenum = 1;//edge is the first shape
728 }
729 if (!AIS::ComputeGeometry(theedge,aCurve,ptonedge1,ptonedge2,extCurv,isInfinite,isOnPlanEdge,Plane))
730 return;
731 aPresentation->SetInfiniteState(isInfinite);
732 AIS::ComputeGeometry(thevertex, FirstAttach, Plane, isOnPlanVertex);
733
734 if ( aCurve->IsInstance(STANDARD_TYPE(Geom_Line)) )
735 {
c5f3a425 736 Handle(Geom_Line) geom_lin (Handle(Geom_Line)::DownCast (aCurve));
7fd59977 737 const gp_Lin& l = geom_lin->Lin();
738
739 // computation of Val
740 Val = l.Distance( FirstAttach );
741
742 gp_Dir DirAttach = l.Direction();
743 // size
744 Standard_Real arrsize = ArrowSize;
745 if (Abs(Val) <= Precision::Confusion()) {arrsize = 0.;}
746
747 if (AutomaticPos) {
748 gp_Pnt p = ElCLib::Value(ElCLib::Parameter(l,FirstAttach),l);
749 gp_Pnt curpos((FirstAttach.XYZ()+p.XYZ())*0.5);
750 // make offset
751 gp_Vec offset(DirAttach);
752 offset = offset*ArrowSize*(-10.);
753 curpos.Translate(offset);
754 Position = curpos;
755 }
756 else { // project point on the plane
757 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
758 }
759
760 if (!isInfinite) {
761 if (Position.Distance(ptonedge1) > Position.Distance(ptonedge2)) SecondAttach = ptonedge2;
762 else SecondAttach = ptonedge1;
763 }
764 else {
765 SecondAttach = ElCLib::Value(ElCLib::Parameter(l,Position),l);
766 }
767
a6eb515f 768 Handle(Prs3d_DimensionAspect) la = aDrawer->DimensionAspect();
769 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 770 arr->SetLength(arrsize);
a6eb515f 771 arr = la->ArrowAspect();
7fd59977 772 arr->SetLength(arrsize);
773
774 if (AutomaticPos && IsSetBndBox)
775 Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );
776 DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
777 aDrawer,
778 FirstAttach,
779 SecondAttach,
780 DirAttach,
781 Position,
782 SymbolPrs,
783 FirstExtreme,
784 SecondExtreme);
785
786}
787 if (aCurve->IsInstance(STANDARD_TYPE(Geom_Circle))){
788 gp_Circ aCirc1 = (Handle(Geom_Circle)::DownCast(aCurve))->Circ();
789 gp_Circ aCirc2(aCirc1); aCirc2.SetRadius(0); //create the second formal circle
790 if(AutomaticPos)
791 {
792 SecondAttach = ptonedge2; //a vertex
793 Position.SetXYZ((SecondAttach.XYZ() + aCirc1.Location().XYZ())*0.5);
794 }
795 else {
796 Standard_Real aPar = ElCLib::Parameter(aCirc1, Position);
797 SecondAttach = ElCLib::Value(aPar, aCirc1);
798 }
799
800 Handle(Geom_Circle) aCurve2 = new Geom_Circle(aCirc2);
801 DsgPrs_EqualDistancePresentation::AddIntervalBetweenTwoArcs(aPresentation,
802 aDrawer,
803 aCirc1, //circle or arc
804 aCirc2, //really vertex
805 ptonedge2, //last point of aCirc1
806 SecondAttach,
807 FirstAttach, //vertex really
808 FirstAttach,
809 SymbolPrs);
810
811 //Assign arc points
812 if (edgenum == 1){
813 FirstExtreme = SecondAttach; SecondExtreme = FirstAttach;
814 SecondAttach = FirstAttach; FirstAttach = ptonedge2;
815 } else { //vertex is the first shape, circle is sthe last.
816 FirstExtreme = FirstAttach; SecondExtreme = SecondAttach;
817 SecondAttach = ptonedge2;
818 }
819 }
820
821 // computation of Val
822 Val = FirstAttach.Distance(SecondAttach);
823
81bba717 824 //Display the pieces of attached to the curve if it is not
825 // in the WP
7fd59977 826 if (!isOnPlanEdge) { // add presentation of projection of the edge in WP
827 AIS::ComputeProjEdgePresentation(aPresentation,aDrawer,theedge,aCurve,ptonedge1,ptonedge2);
828 }
829 if (!isOnPlanVertex) { // add presentation of projection of the vertex in WP
830 AIS::ComputeProjVertexPresentation(aPresentation,aDrawer,thevertex,FirstAttach);
831 }
832
833}
834// -- ota -- end