0023663: Removing 2D viewer library
[occt.git] / src / AIS / AIS_DiameterDimension.cxx
CommitLineData
b311480e 1// Created on: 1996-12-05
2// Created by: Jacques MINOT/Odile Olivier/Sergey ZARITCHNY
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
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.
10//
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.
13//
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.
20
7fd59977 21// Modified Mon 12-january-98
7fd59977 22// <ODL>, <SZY>
23
24
25#define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
26// if any in all dimensions.
27
28#include <Standard_NotImplemented.hxx>
29
30#include <AIS_DiameterDimension.ixx>
31#include <AIS_DimensionOwner.hxx>
32#include <DsgPrs_DiameterPresentation.hxx>
33#include <DsgPrs_RadiusPresentation.hxx>
34
35#include <TCollection_ExtendedString.hxx>
36
37#include <Prs3d_LengthAspect.hxx>
38#include <Prs3d_ArrowAspect.hxx>
39#include <Prs3d_Drawer.hxx>
40#include <Prs3d_TextAspect.hxx>
41#include <Prs3d_Text.hxx>
42
43#include <Select3D_SensitiveSegment.hxx>
44#include <Select3D_SensitiveBox.hxx>
45#include <SelectMgr_EntityOwner.hxx>
46
47#include <ElCLib.hxx>
48#include <ElSLib.hxx>
49
50#include <TopoDS.hxx>
51
52#include <BRepAdaptor_Surface.hxx>
53#include <BRepAdaptor_Curve.hxx>
54#include <Adaptor3d_HCurve.hxx>
55
56#include <Geom_Circle.hxx>
57#include <Geom_TrimmedCurve.hxx>
58#include <Geom_Plane.hxx>
59#include <Geom_Surface.hxx>
60#include <Geom_CylindricalSurface.hxx>
61#include <Geom_SurfaceOfRevolution.hxx>
62#include <Geom_CylindricalSurface.hxx>
63#include <Geom_SurfaceOfLinearExtrusion.hxx>
64
65#include <gp_Pln.hxx>
66#include <gp_Pnt.hxx>
67#include <gp_Lin.hxx>
68#include <gp_Ax1.hxx>
69#include <gp_Dir.hxx>
70#include <gp_Vec.hxx>
71
72#include <AIS.hxx>
73#include <AIS_Drawer.hxx>
74
75#include <GC_MakeCircle.hxx>
76
77#include <Precision.hxx>
78
79#include <TopExp_Explorer.hxx>
80
81//=======================================================================
82//function : Constructor
83//purpose :
84//=======================================================================
85
86AIS_DiameterDimension::AIS_DiameterDimension(const TopoDS_Shape& aShape,
87 const Standard_Real aVal,
88 const TCollection_ExtendedString& aText)
89:AIS_Relation(),
90 myDiamSymbol(Standard_True)
91{
92 myPosition = gp_Pnt(0.,0.,0.);
93 myFShape = aShape;
94 myVal = aVal;
95 myText = aText;
96 mySymbolPrs = DsgPrs_AS_LASTAR;
97 myAutomaticPosition = Standard_True;
98 myArrowSize = myVal / 100.;
99}
100
101//=======================================================================
102//function : Constructor
103//purpose :
104//=======================================================================
105
106AIS_DiameterDimension::AIS_DiameterDimension(const TopoDS_Shape& aShape,
107 const Standard_Real aVal,
108 const TCollection_ExtendedString& aText,
109 const gp_Pnt& aPosition,
110 const DsgPrs_ArrowSide aSymbolPrs,
111 const Standard_Boolean aDiamSymbol,
112 const Standard_Real anArrowSize)
113:AIS_Relation(),
114 myDiamSymbol(aDiamSymbol)
115{
116 myFShape = aShape;
117 myVal = aVal;
118 myText = aText;
119 mySymbolPrs = aSymbolPrs;
120 myPosition = aPosition;
121 myAutomaticPosition = Standard_False;
122#ifdef BUC60915
123 SetArrowSize( anArrowSize );
124#else
125 myArrowSize = anArrowSize;
126#endif
127}
128
129//=======================================================================
130//function : Compute
131//purpose :
132//=======================================================================
133
134void AIS_DiameterDimension::Compute(
135 const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
136 const Handle(Prs3d_Presentation)& aPresentation,
137 const Standard_Integer /*aMode*/)
138{
139 aPresentation->Clear();
140
141 switch (myFShape.ShapeType()) {
142 case TopAbs_FACE :
143 {
144 // compute one face case
145 ComputeOneFaceDiameter (aPresentation);
146 break;
147 }
148 case TopAbs_EDGE:
149 {
150 ComputeOneEdgeDiameter (aPresentation);
151 break;
152 }
153 default:
154 break;
155 }
156
157}
158
159//=======================================================================
160//function : Compute
161//purpose : to avoid warning
162//=======================================================================
163
164void AIS_DiameterDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
165 const Handle(Prs3d_Presentation)& aPresentation)
166{
167// Standard_NotImplemented::Raise("AIS_DiameterDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation)");
168 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
169}
170
7fd59977 171void AIS_DiameterDimension::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
172{
173// Standard_NotImplemented::Raise("AIS_DiameterDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
174 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
175}
176
177//=======================================================================
178//function : ComputeSelection
179//purpose :
180//=======================================================================
181
182void AIS_DiameterDimension::ComputeSelection(
183 const Handle(SelectMgr_Selection)& aSelection,
184 const Standard_Integer /*aMode*/)
185{
186 Handle(AIS_DimensionOwner) own = new AIS_DimensionOwner(this,7);
187 own->SetShape(myFShape);
188
189 if (!myIsAnArc) {
190 gp_Pnt AttachmentPoint = myPosition;
191 Standard_Real parat = ElCLib::Parameter(myCircle,AttachmentPoint);
192 gp_Pnt ptoncirc = ElCLib::Value (parat,myCircle);
193
194 // ligne de cote
195
196 gp_Pnt center = myCircle.Location();
197 gp_Vec vecrap (ptoncirc,center);
198
199 Standard_Real dist = center.Distance(AttachmentPoint);
200 Standard_Real aRadius = myCircle.Radius();
201 Standard_Real inside = Standard_False;
202
203 gp_Pnt pt1 = AttachmentPoint;
204 if (dist < aRadius) {
205 pt1 = ptoncirc;
206 dist = aRadius;
207 inside = Standard_True;
208 }
209 vecrap.Normalize();
210 vecrap *= (dist+aRadius);
211 gp_Pnt OppositePoint = pt1.Translated(vecrap);
212
213 if ( pt1.Distance(OppositePoint)>=Precision::Confusion()) {
214 Handle(Select3D_SensitiveSegment)
215 seg = new Select3D_SensitiveSegment(own,pt1 ,OppositePoint);
216 aSelection->Add(seg);
217 }
218 }
219 else
220 ComputeArcSelection(aSelection);
221
222 // Text
223 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
224 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
225 myPosition.X(),
226 myPosition.Y(),
227 myPosition.Z(),
228 myPosition.X() + size,
229 myPosition.Y() + size,
230 myPosition.Z() + size);
231 aSelection->Add(box);
232}
233//==========================================================================
234// function : ComputeArcSelection
235// purpose :
236//
237//==========================================================================
238
239void AIS_DiameterDimension::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection)
240{
241
242 Standard_Real fpara;
243 Standard_Real lpara;
244 fpara = myFirstPar;
245 lpara = myLastPar;
246
247 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
248 gp_Pnt theCenter = myCircle.Location();
c6541a0c
D
249 while (lpara > 2*M_PI) {
250 fpara -= 2*M_PI;
251 lpara -= 2*M_PI;
7fd59977 252 }
253 Standard_Real parat = ElCLib::Parameter(myCircle,myPosition);
254 Standard_Boolean otherside(Standard_False);
255 gp_Pnt attpoint = myPosition;
256
257 if (!AIS::InDomain(fpara,lpara,parat)) {
c6541a0c
D
258 Standard_Real otherpar = parat + M_PI;
259 if (otherpar > 2*M_PI) otherpar -= 2*M_PI;
7fd59977 260 if (AIS::InDomain(fpara,lpara,otherpar)) {
261 parat = otherpar;
262 otherside = Standard_True;
263 }
264 else {
265 Standard_Real ecartpar = Min(Abs(fpara-parat),
266 Abs(lpara-parat));
267 Standard_Real ecartoth = Min(Abs(fpara-otherpar),
268 Abs(lpara-otherpar));
269 if (ecartpar <= ecartoth) {
270 if (parat < fpara) parat = fpara;
271 else parat = lpara;
272 }
273 else {
274 otherside = Standard_True;
275 if (otherpar < fpara) parat = fpara;
276 else parat = lpara;
277 }
278 gp_Pnt ptdir = ElCLib::Value(parat,myCircle);
279 gp_Lin lsup(theCenter,
280 gp_Dir(ptdir.XYZ()-theCenter.XYZ()));
281 Standard_Real parpos = ElCLib::Parameter(lsup,myPosition);
282 attpoint = ElCLib::Value(parpos,lsup);
283 }
284 }
285 gp_Pnt ptoncirc = ElCLib::Value(parat,myCircle);
286 gp_Lin L (theCenter,gp_Dir(attpoint.XYZ()-theCenter.XYZ()));
287 gp_Pnt firstpoint = attpoint;
288 gp_Pnt drawtopoint = ptoncirc;
289
290 if (!otherside) {
291 Standard_Real uatt = ElCLib::Parameter(L,attpoint);
292 Standard_Real uptc = ElCLib::Parameter(L,ptoncirc);
293 if (Abs(uatt) > Abs(uptc)) {
294 drawtopoint = theCenter;
295 }
296 else {
297 firstpoint = theCenter;
298 }
299 }
300
301 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,firstpoint,drawtopoint);
302 aSelection->Add(seg);
303}
304
305//=======================================================================
306//function : ComputeOneFaceDiameter
307//purpose :
308//=======================================================================
309
310void AIS_DiameterDimension::ComputeOneFaceDiameter(
311 const Handle(Prs3d_Presentation)& aPresentation)
312{
313 //cout<<"AIS_DiameterDimension::ComputeOneFaceDiameter"<<endl;
314
315 gp_Pln aPln;
316 Handle( Geom_Surface ) aBasisSurf;
f5a6ee3c 317 AIS_KindOfSurface aSurfType = AIS_KOS_OtherSurface;
7fd59977 318 Standard_Real Offset;
319 if( myAutomaticPosition )
320 AIS::GetPlaneFromFace( TopoDS::Face( myFShape),
321 aPln,
322 aBasisSurf,
323 aSurfType,
324 Offset ) ;
325
326 if ( aSurfType == AIS_KOS_Plane )
327 ComputeOnePlanarFaceDiameter( aPresentation );
328 else
329 ComputeOneCylFaceDiameter( aPresentation, aSurfType, aBasisSurf );
330
331}
332
333
334//=======================================================================
335//function : ComputeOneCylFaceDiameter
336//purpose :
337//=======================================================================
338
339void AIS_DiameterDimension::ComputeOneCylFaceDiameter
340 (const Handle(Prs3d_Presentation)& aPresentation,
341 const AIS_KindOfSurface aSurfType,
342 const Handle( Geom_Surface )& aBasisSurf )
343{
344 gp_Pnt curPos;
345 if( myAutomaticPosition )
346 {
347 BRepAdaptor_Surface surf1(TopoDS::Face(myFShape));
348 Standard_Real uFirst, uLast, vFirst, vLast;
349 uFirst = surf1.FirstUParameter();
350 uLast = surf1.LastUParameter();
351 vFirst = surf1.FirstVParameter();
352 vLast = surf1.LastVParameter();
353 Standard_Real uMid = (uFirst + uLast)*0.5;
354 Standard_Real vMid = (vFirst + vLast)*0.5;
355 surf1.D0(uMid, vMid, curPos);
356 Handle( Adaptor3d_HCurve ) BasisCurve;
357 //Standard_Real Param;
358 Standard_Boolean ExpectedType = Standard_False;
359 if (aSurfType == AIS_KOS_Cylinder)
360 {
361 ExpectedType = Standard_True;
362 }
363 else
364 if (aSurfType == AIS_KOS_Revolution)
365 {
366 BasisCurve = surf1.BasisCurve();
367 if (BasisCurve->GetType() == GeomAbs_Line)
368 ExpectedType = Standard_True;
369 }
370 else if (aSurfType == AIS_KOS_Extrusion)
371 {
372 BasisCurve = surf1.BasisCurve();
373 if ( BasisCurve->GetType() == GeomAbs_Circle )
374 ExpectedType = Standard_True;
375 }
376 if(!ExpectedType) {
377 Standard_ConstructionError::Raise("AIS:: Not expected type of surface") ;
378 return;
379 }
380 //
381 Handle(Geom_Curve) aCurve;
382 aCurve = aBasisSurf->VIso(vMid);
383 if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Circle))
384 {
385 myCircle = Handle(Geom_Circle)::DownCast(aCurve)->Circ();//gp_Circ
386 }
387 else if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
388 Handle(Geom_TrimmedCurve) tCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve);
389 aCurve = tCurve->BasisCurve();
390 uFirst = tCurve->FirstParameter();
391 uLast = tCurve->LastParameter();
392 if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Circle))
393 myCircle = Handle(Geom_Circle)::DownCast(aCurve)->Circ();//gp_Circ
394 }
395 else {
396 // compute a circle from 3 points on "aCurve"
397 gp_Pnt P1, P2;
398 surf1.D0(uFirst, vMid, P1);
399 surf1.D0(uLast, vMid, P2);
400 GC_MakeCircle mkCirc(P1, curPos, P2);
401 myCircle = mkCirc.Value()->Circ();
402 }
403 myCircle.SetRadius(myVal/2.);
404 myPlane = new Geom_Plane(gp_Pln(gp_Ax3(myCircle.Position())));//gp_Circ
405 gp_Vec v1(myCircle.Location(), curPos);
406 v1.Normalize();
407 v1 = v1 * myVal*1.2;
408 myPosition = myCircle.Location().Translated(v1);
409// IsArc ?
410 gp_Pnt p1, p2;
411 p1 = ElCLib::Value (uFirst, myCircle);
412 p2 = ElCLib::Value (uLast, myCircle);
413 if ( p1.IsEqual(p2, Precision::Confusion()) )
414 myIsAnArc = Standard_False;
415 else myIsAnArc = Standard_True;
416 myFirstPar = uFirst;
417 myLastPar = uLast;
418// myPosition = curPos;
419 myAutomaticPosition = Standard_True;
420 if ( myIsSetBndBox )
421 myPosition = AIS::TranslatePointToBound( myPosition, gp_Dir( gp_Vec( myCircle.Location(),
422 myPosition ) ), myBndBox );
423 }
424 else { // !AutomaticPosition
425 curPos = myPosition;
426 curPos = AIS::ProjectPointOnPlane( curPos, myPlane->Pln() );
427 myPosition = curPos;
428 }
429
430 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
431 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
432
433 // size
434#ifdef BUC60915
435 if( !myArrowSizeIsDefined ) {
436 myArrowSize = Min(myArrowSize,myCircle.Radius()/5.);
437 }
438 arr->SetLength(myArrowSize);
439#else
440 if (myCircle.Radius()/5. > myArrowSize) {
441 arr->SetLength(myArrowSize);
442 }
443 else {
444 arr->SetLength(myCircle.Radius()/5.);
445 }
446#endif
447
448 //cout<<"AIS_DiameterDimension:: add Prs"<<endl;
449 if( myIsAnArc )
450 DsgPrs_DiameterPresentation::Add(aPresentation, myDrawer, myText, myPosition,
451 myCircle, myFirstPar, myLastPar, mySymbolPrs, myDiamSymbol);
452 else
453 DsgPrs_DiameterPresentation::Add(aPresentation, myDrawer, myText, myPosition,
454 myCircle, DsgPrs_AS_BOTHAR, myDiamSymbol);
455
456
457}
458
459
460//=======================================================================
461//function : ComputeCircleDiameter
462//purpose :
463//=======================================================================
464
465void AIS_DiameterDimension::ComputeCircleDiameter(const Handle(Prs3d_Presentation)& aPresentation)
466{
467 gp_Pnt center = myCircle.Location();
468 Standard_Real rad = myCircle.Radius();
469 gp_Pnt curpos;
470
471 if (myAutomaticPosition) {
472// we compute 1 point on the circle
473 myPlane = new Geom_Plane(gp_Pln(gp_Ax3(myCircle.Position())));//gp_Circ
474 gp_Dir xdir = myCircle.XAxis().Direction();
475 Standard_Real deport = rad *1.2;
476 curpos = center.Translated( gp_Vec(xdir)*deport );
477 SetPosition (curpos);// myPosition = curpos
478 myAutomaticPosition = Standard_True;
479 if (myIsSetBndBox)
480 myPosition = AIS::TranslatePointToBound( myPosition, gp_Dir( gp_Vec( myCircle.Location(),
481 myPosition ) ), myBndBox );
482 }
483 else {
484 curpos = myPosition;
485 // VRO (2007-05-17) inserted this IF.
486 if (myPlane.IsNull())
487 myPlane = new Geom_Plane(gp_Pln(gp_Ax3(myCircle.Position())));
488 myPosition = AIS::ProjectPointOnPlane( curpos, myPlane->Pln() );
489 }
490
491 // size
492 Handle(Prs3d_LengthAspect) LA = myDrawer->LengthAspect();
493 Handle(Prs3d_ArrowAspect) arr = LA->Arrow1Aspect();
494
495#ifdef BUC60915
496 if( !myArrowSizeIsDefined ) {
497 myArrowSize = Min(myArrowSize,myCircle.Radius()/5.);
498 }
499 arr->SetLength(myArrowSize);
500#else
501 if (myCircle.Radius()/5. > myArrowSize) {
502 arr->SetLength(myArrowSize);
503 }
504 else {
505 arr->SetLength(myCircle.Radius()/5.);
506 }
507#endif
508
509 DsgPrs_DiameterPresentation::Add(aPresentation, myDrawer, myText, myPosition, myCircle,
510 DsgPrs_AS_BOTHAR, myDiamSymbol );
511
512}
513
514//==========================================================================
515// function : ComputeArcDiameter
516// purpose :
517//
518//==========================================================================
519
520void AIS_DiameterDimension::ComputeArcDiameter(
521 const Handle(Prs3d_Presentation)& aPresentation,
522 const gp_Pnt& pfirst,
523 const gp_Pnt& pend)
524{
525
526 gp_Pnt center = myCircle.Location();
527 Standard_Real rad = myCircle.Radius();
528
529 gp_Pnt curpos;
530 Standard_Real parfirst, parend;
531
532 parfirst = ElCLib::Parameter(myCircle, pfirst);
533 parend = ElCLib::Parameter(myCircle, pend);
534 myFirstPar = parfirst;
535 myLastPar = parend;
536 if ( parfirst > parend) {
c6541a0c 537 parfirst -= 2*M_PI;
7fd59977 538 }
539 if (myAutomaticPosition) {
540 Standard_Real pcurpos = (parfirst + parend)/2.;
541 curpos = ElCLib::Value(pcurpos, myCircle);
542 myPlane = new Geom_Plane(gp_Pln(gp_Ax3(myCircle.Position())));//gp_Circ
543 gp_Dir vdir(gp_Vec(myCircle.Location(),curpos));
544 Standard_Real deport = rad * 1.2;
545 curpos = center.Translated( gp_Vec(vdir)*deport );
546
547 SetPosition (curpos);
548 myAutomaticPosition = Standard_True;
549
550 if ( myIsSetBndBox )
551 myPosition = AIS::TranslatePointToBound( myPosition, gp_Dir( gp_Vec( myCircle.Location(),
552 myPosition ) ), myBndBox );
553
554 }
555 else {
556 curpos = myPosition;
557 myPosition = AIS::ProjectPointOnPlane( curpos, myPlane->Pln() );
558 }
559
560 // size
561
562 Handle(Prs3d_LengthAspect) LA = myDrawer->LengthAspect();
563 Handle(Prs3d_ArrowAspect) arr = LA->Arrow1Aspect();
564
565#ifdef BUC60915
566 if( !myArrowSizeIsDefined ) {
567 myArrowSize = Min(myArrowSize,myCircle.Radius()/5.);
568 }
569 arr->SetLength(myArrowSize);
570#else
571 if (myCircle.Radius()/5. > myArrowSize) {
572 arr->SetLength(myArrowSize);
573 }
574 else {
575 arr->SetLength(myCircle.Radius()/5.);
576 }
577#endif
578
579 // Display
580 DsgPrs_DiameterPresentation::Add (aPresentation, myDrawer, myText, myPosition, myCircle,
581 parfirst, parend, mySymbolPrs, myDiamSymbol);
582
583}
584
585
586//==========================================================================
587// function : ComputeOneEdgeDiameter
588// purpose :
589//
590//==========================================================================
591
592void AIS_DiameterDimension::ComputeOneEdgeDiameter(const Handle(Prs3d_Presentation)& aPresentation)
593{
594 gp_Pnt ptfirst,ptend;
595 Handle(Geom_Curve) curv;
596 if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),curv,ptfirst,ptend)) return;
597
598 Handle(Geom_Circle) circ = Handle(Geom_Circle)::DownCast(curv);
599 if ( circ.IsNull()) return;
600
601 myCircle = circ->Circ();
602 myCircle.SetRadius(myVal/2.);
603 if ( ptfirst.IsEqual(ptend, Precision::Confusion()) ) {
604 myIsAnArc = Standard_False;
605 ComputeCircleDiameter(aPresentation);
606 }
607 else {
608 myIsAnArc = Standard_True;
609 ComputeArcDiameter(aPresentation,ptfirst,ptend );
610 }
611}
612
613//===================================================================
614//function : CircleFromPlanarFace
615//purpose : if possible computes circle from planar face
616//=======================================================================
617static Standard_Boolean CircleFromPlanarFace(const TopoDS_Face& aFace,
618 Handle(Geom_Curve)& aCurve,
619 gp_Pnt & ptfirst, gp_Pnt & ptend)
620{
621 TopExp_Explorer ExploEd( aFace, TopAbs_EDGE );
622 for ( ; ExploEd.More(); ExploEd.Next())
623 {
624 TopoDS_Edge curedge = TopoDS::Edge( ExploEd.Current() );
625 if (AIS::ComputeGeometry(curedge, aCurve, ptfirst, ptend))
626 if(aCurve->IsInstance(STANDARD_TYPE(Geom_Circle)) &&
627 !Handle(Geom_Circle)::DownCast(aCurve).IsNull())
628 return Standard_True;
629 }
630 return Standard_False;
631}
632
633//=======================================================================
634//function : ComputeOnePlanarFaceDiameter
635//purpose :
636//=======================================================================
637
638void AIS_DiameterDimension::ComputeOnePlanarFaceDiameter(const Handle(Prs3d_Presentation)& aPresentation)
639{
640 gp_Pnt curPos ;
7fd59977 641 Standard_Real parfirst =0., parend =0.;
7fd59977 642 if (myAutomaticPosition) {
643 Handle(Geom_Curve) curv;
644 gp_Pnt ptfirst,ptend;
645
646 if( !CircleFromPlanarFace( TopoDS::Face( myFShape ), curv, ptfirst, ptend) ) {
647 Standard_ConstructionError::Raise("AIS:: Curve is not a circle or is Null") ;
648 return;
649 }
650
651 myCircle = Handle(Geom_Circle)::DownCast(curv)->Circ();
652 if ( ptfirst.IsEqual(ptend, Precision::Confusion()) )
653 myIsAnArc = Standard_False;
654 else
655 myIsAnArc = Standard_True;
656 myCircle.SetRadius(myVal/2.);//
657 BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
658 myPlane = new Geom_Plane(gp_Pln(gp_Ax3(myCircle.Position())));//gp_Circ
659 gp_Pnt center = myCircle.Location();
660 Standard_Real rad = myCircle.Radius();
661 Standard_Real deport = rad * 1.2;
662 if(! myIsAnArc ) { // Circle
663 gp_Dir xdir = myCircle.XAxis().Direction();
664 curPos = center.Translated( gp_Vec(xdir)*deport );
665 }
666 else { // Arc
667 parfirst = ElCLib::Parameter(myCircle, ptfirst);
668 parend = ElCLib::Parameter(myCircle, ptend);
669 if ( parfirst > parend) {
c6541a0c 670 parfirst -= 2*M_PI;
7fd59977 671 }
672 Standard_Real parcurPos = (parfirst + parend) * 0.5;
673 curPos = ElCLib::Value(parcurPos, myCircle);
674 gp_Vec v1( center, curPos );
675 v1.Normalize();
676 curPos = center.Translated( v1 * deport );
677 }
678 myFirstPar = parfirst;
679 myLastPar = parend;
680 myPosition = curPos;
681 myAutomaticPosition = Standard_True;
682 if ( myIsSetBndBox )
683 myPosition = AIS::TranslatePointToBound( myPosition, gp_Dir( gp_Vec( myCircle.Location(),
684 myPosition ) ), myBndBox );
685 } else
686 {
687 // !myAutomaticPosition
688 // Project point on the plane of face
689 curPos = myPosition;
690 curPos = AIS::ProjectPointOnPlane( curPos, myPlane->Pln() );
691 myPosition = curPos;
692 }
693
694
695 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
696 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
697
698 // size
699#ifdef BUC60915
700 if( !myArrowSizeIsDefined ) {
701 myArrowSize = Min(myArrowSize,myCircle.Radius()/5.);
702 }
703 arr->SetLength(myArrowSize);
704#else
705 if (myCircle.Radius()/5. > myArrowSize) {
706 arr->SetLength(myArrowSize);
707 }
708 else {
709 arr->SetLength(myCircle.Radius()/5.);
710 }
711#endif
712
713 if(! myIsAnArc )
714 DsgPrs_DiameterPresentation::Add(aPresentation, myDrawer, myText, myPosition,
715 myCircle, DsgPrs_AS_BOTHAR, myDiamSymbol);
716 else
717 DsgPrs_DiameterPresentation::Add(aPresentation, myDrawer, myText, myPosition,
718 myCircle, myFirstPar, myLastPar, mySymbolPrs, myDiamSymbol );
719}
720