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