0022312: Translation of french commentaries in OCCT files
[occt.git] / src / AIS / AIS_LengthDimension.cxx
CommitLineData
7fd59977 1// File: AIS_LengthDimension.cxx
2// Created: Tue Dec 5 15:09:04 1996
3// Author: Arnaud BOUZY/Odile Olivier
4// <ODL>
5
6#define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
7// if any in all dimensions.
8
9#include <Standard_NotImplemented.hxx>
10
11#include <AIS_LengthDimension.ixx>
12
13#include <AIS.hxx>
14#include <AIS_DimensionOwner.hxx>
15#include <AIS_Drawer.hxx>
16
17#include <BRepAdaptor_Curve.hxx>
18#include <BRepAdaptor_Surface.hxx>
19#include <BRep_Tool.hxx>
20
21#include <DsgPrs.hxx>
22#include <DsgPrs_LengthPresentation.hxx>
23
24#include <ElCLib.hxx>
25#include <ElSLib.hxx>
26
27#include <Geom_Circle.hxx>
28#include <Geom_Curve.hxx>
29#include <Geom_TrimmedCurve.hxx>
30#include <Geom_Line.hxx>
31#include <Geom_Plane.hxx>
32#include <Geom_OffsetSurface.hxx>
33
34#include <Precision.hxx>
35
36#include <ProjLib.hxx>
37
38#include <Prs3d_ArrowAspect.hxx>
39#include <Prs3d_Drawer.hxx>
40#include <Prs3d_LengthAspect.hxx>
41#include <Prs3d_LineAspect.hxx>
42
43#include <Select3D_SensitiveBox.hxx>
44#include <Select3D_SensitiveSegment.hxx>
45#include <Select3D_SensitiveCurve.hxx>
46#include <SelectMgr_EntityOwner.hxx>
47
48#include <Standard_DomainError.hxx>
49
50#include <StdPrs_WFDeflectionShape.hxx>
51
52#include <TCollection_AsciiString.hxx>
53#include <TCollection_ExtendedString.hxx>
54
55#include <TopExp.hxx>
56#include <TopExp_Explorer.hxx>
57#include <TopoDS.hxx>
58
59#include <gce_MakeDir.hxx>
60#include <gce_MakeLin.hxx>
61
62#include <gp_Ax1.hxx>
63#include <gp_Ax2.hxx>
64#include <gp_Dir.hxx>
65#include <gp_Lin.hxx>
66#include <gp_Pln.hxx>
67#include <gp_Pnt.hxx>
68#include <gp_Pnt2d.hxx>
69
70#include <Prs3d_AngleAspect.hxx>
71
72#include <BRepGProp_Face.hxx>
73
74
75//=======================================================================
76//function : Constructor
77//purpose : TwoFacesLength dimension
78//=======================================================================
79
80AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Face& aFirstFace,
81 const TopoDS_Face& aSecondFace,
82 const Standard_Real aVal,
83 const TCollection_ExtendedString& aText)
84:AIS_Relation(),
85 myNbShape(2)
86{
87 SetFirstShape( aFirstFace );
88 SetSecondShape( aSecondFace );
89 myVal = aVal;
90
91 myText = aText;
92 mySymbolPrs = DsgPrs_AS_BOTHAR;
93 myAutomaticPosition = Standard_True;
94
95 myArrowSize = myVal / 10.;
96}
97
98//=======================================================================
99//function : Constructor
81bba717 100//purpose : TwoFacesLength dimension (with position and text)
7fd59977 101//=======================================================================
102
103AIS_LengthDimension::AIS_LengthDimension(const TopoDS_Face& aFirstFace,
104 const TopoDS_Face& aSecondFace,
105 const Standard_Real aVal,
106 const TCollection_ExtendedString& aText,
107 const gp_Pnt& aPosition,
108 const DsgPrs_ArrowSide aSymbolPrs,
109 const Standard_Real anArrowSize)
110:AIS_Relation(),
111 myNbShape(2)
112{
113 SetFirstShape( aFirstFace );
114 SetSecondShape( aSecondFace );
115 myVal = aVal;
116
117 myText = aText;
118 mySymbolPrs = aSymbolPrs;
119 myAutomaticPosition = Standard_False;
120#ifdef BUC60915
121 SetArrowSize( anArrowSize );
122#else
123 myArrowSize = anArrowSize;
124#endif
125 myPosition = aPosition;
126}
127
128
129
130//=======================================================================
131//function : AIS_LengthDimension
81bba717 132//purpose : Distance Face - Edge for chamfer 3D
7fd59977 133//=======================================================================
134
135AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Face& Face,const TopoDS_Edge& Edge,const Standard_Real Val,const TCollection_ExtendedString& Text)
136
137:AIS_Relation (),
138 myNbShape (2)
139{
140 SetFirstShape (Face);
141 SetSecondShape (Edge);
142 myText = Text;
143 myVal = Val;
144 mySymbolPrs = DsgPrs_AS_BOTHAR;
145 myAutomaticPosition = Standard_True;
146 myArrowSize = myVal/10.0;
147}
148
149
150
151//=======================================================================
152//function : Constructor
153//purpose : TwoEdgesLength dimension or OneEdgeOneVertexLength dimension or TwoVerticesLength dimension
154//=======================================================================
155
156AIS_LengthDimension::AIS_LengthDimension(const TopoDS_Shape& aFShape,
157 const TopoDS_Shape& aSShape,
158 const Handle(Geom_Plane)& aPlane,
159 const Standard_Real aVal,
160 const TCollection_ExtendedString& aText)
161:AIS_Relation(),
162 myNbShape(2),
163 myTypeDist(AIS_TOD_Unknown)
164{
165 myFShape = aFShape;
166 mySShape = aSShape;
167 myVal = aVal;
168 myText = aText;
169 mySymbolPrs = DsgPrs_AS_BOTHAR;
170 myAutomaticPosition = Standard_True;
171 myPlane =aPlane;
172 myArrowSize = myVal / 10.;
173}
174
175//=======================================================================
176//function : Constructor
177//purpose : TwoEdgesLength dimension or OneEdgeOneVertexLength dimension or TwoVerticesLength dimension
178//=======================================================================
179
180AIS_LengthDimension::AIS_LengthDimension(const TopoDS_Shape& aFShape,
181 const TopoDS_Shape& aSShape,
182 const Handle(Geom_Plane)& aPlane,
183 const Standard_Real aVal,
184 const TCollection_ExtendedString& aText,
185 const gp_Pnt& aPosition,
186 const DsgPrs_ArrowSide aSymbolPrs,
187 const AIS_TypeOfDist aTypeDist,
188 const Standard_Real anArrowSize)
189:AIS_Relation(),
190 myNbShape(2),
191 myTypeDist(aTypeDist)
192{
193 myFShape = aFShape;
194 mySShape = aSShape;
195 myVal = aVal;
196 myPlane = aPlane;
197 myText = aText;
198 mySymbolPrs = aSymbolPrs;
199 myAutomaticPosition = Standard_False;
200#ifdef BUC60915
201 SetArrowSize( anArrowSize );
202#else
203 myArrowSize = anArrowSize;
204#endif
205 myPosition = aPosition;
206}
207
208
209
210//=======================================================================
211//function : Compute
212//purpose :
213//=======================================================================
214
215void AIS_LengthDimension::Compute(const Handle(PrsMgr_PresentationManager3d)&,
216 const Handle(Prs3d_Presentation)& aPresentation,
217 const Standard_Integer)
218{
219 aPresentation->Clear();
220
221 if (myNbShape == 1) {
222 switch (myFShape.ShapeType()) {
223 case TopAbs_FACE:
224 {
81bba717 225 // case length on a face
7fd59977 226 ComputeOneFaceLength(aPresentation);
227 }
228 break;
229 case TopAbs_EDGE:
230 {
81bba717 231 // case length of an edge
7fd59977 232 ComputeOneEdgeLength(aPresentation);
233 }
234 break;
235 default:
236 break;
237 }
238 }
239 else if (myNbShape == 2) {
240 switch (myFShape.ShapeType()) {
241 case TopAbs_FACE:
242 {
243 if (mySShape.ShapeType () == TopAbs_FACE) {
81bba717 244 // case length between two faces
7fd59977 245 ComputeTwoFacesLength(aPresentation);
246 }
247 else if (mySShape.ShapeType () == TopAbs_EDGE) {
248 ComputeEdgeFaceLength (aPresentation);
249 }
250 }
251 break;
252 case TopAbs_EDGE:
253 {
254 if (mySShape.ShapeType() == TopAbs_VERTEX) {
255#ifdef BUC60915
256 if( !myArrowSizeIsDefined )
257#endif
258 myArrowSize = Abs(myVal)/100.;
259 ComputeOneEdgeOneVertexLength( aPresentation,
260 myDrawer,
261 myText,
262 myArrowSize,
263 myFShape,
264 mySShape,
265 myPlane,
266 myAutomaticPosition,
267 myIsSetBndBox,
268 myBndBox,
269 myExtShape,
270 myVal,
271 myDirAttach,
272 myPosition,
273 myFAttach,
274 mySAttach,
275 mySymbolPrs );
276 }
277 else if (mySShape.ShapeType() == TopAbs_EDGE) {
81bba717 278 // case length between two edges
7fd59977 279#ifdef BUC60915
280 if( !myArrowSizeIsDefined )
281#endif
282 myArrowSize = Abs(myVal)/100.;
283 ComputeTwoEdgesLength( aPresentation,
284 myDrawer,
285 myText,
286 myArrowSize,
287 TopoDS::Edge( myFShape ),
288 TopoDS::Edge( mySShape ),
289 myPlane,
290 myAutomaticPosition,
291 myIsSetBndBox,
292 myBndBox,
293 myExtShape,
294 myVal,
295 myDirAttach,
296 myPosition,
297 myFAttach,
298 mySAttach,
299 mySymbolPrs );
300 }
301 }
302 break;
303
304 case TopAbs_VERTEX:
305 {
306 if (mySShape.ShapeType() == TopAbs_VERTEX) {
307#ifdef BUC60915
308 if( !myArrowSizeIsDefined )
309#endif
310 myArrowSize = Abs(myVal)/100.;
311 ComputeTwoVerticesLength( aPresentation,
312 myDrawer,
313 myText,
314 myArrowSize,
315 TopoDS::Vertex( myFShape ),
316 TopoDS::Vertex( mySShape ),
317 myPlane,
318 myAutomaticPosition,
319 myIsSetBndBox,
320 myBndBox,
321 myTypeDist,
322 myExtShape,
323 myVal,
324 myDirAttach,
325 myPosition,
326 myFAttach,
327 mySAttach,
328 mySymbolPrs );
329 }
330 else if (mySShape.ShapeType() == TopAbs_EDGE) {
331#ifdef BUC60915
332 if( !myArrowSizeIsDefined )
333#endif
334 myArrowSize = Abs(myVal)/100.;
335 ComputeOneEdgeOneVertexLength( aPresentation,
336 myDrawer,
337 myText,
338 myArrowSize,
339 myFShape,
340 mySShape,
341 myPlane,
342 myAutomaticPosition,
343 myIsSetBndBox,
344 myBndBox,
345 myExtShape,
346 myVal,
347 myDirAttach,
348 myPosition,
349 myFAttach,
350 mySAttach,
351 mySymbolPrs );
352 }
353 }
354 break;
355 default:
356 break;
357 }
358 }
359
360}
361
362//=======================================================================
363//function : Compute
364//purpose : to avoid warning
365//=======================================================================
366
367void AIS_LengthDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
368 const Handle(Prs3d_Presentation)& aPresentation)
369{
370// Standard_NotImplemented::Raise("AIS_LengthDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
371 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
372}
373
374//=======================================================================
375//function : Compute
376//purpose : to avoid warning
377//=======================================================================
378
379void AIS_LengthDimension::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager2d,
380 const Handle(Graphic2d_GraphicObject)& aGraphicObject,
381 const Standard_Integer anInteger)
382{
383// Standard_NotImplemented::Raise("AIS_LengthDimension::Compute(const Handle(PrsMgr_PresentationManager2d)&,const Handle(Graphic2d_GraphicObject)&,const Standard_Integer)");
384 PrsMgr_PresentableObject::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ;
385}
386
387void AIS_LengthDimension::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
388{
389// Standard_NotImplemented::Raise("AIS_LengthDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
390 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
391}
392
393//=======================================================================
394//function : ComputeSelection
395//purpose :
396//=======================================================================
397
398void AIS_LengthDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
399 const Standard_Integer)
400{
401 if (myFShape.IsNull() && mySShape.IsNull()) return;
402 if (myFShape.ShapeType() == TopAbs_FACE) ComputeFaceSelection(aSelection);
403 else ComputeEdgeVertexSelection(aSelection);
404
405 // Text
406 Handle( SelectMgr_EntityOwner ) own = new SelectMgr_EntityOwner( this, 7 );
407 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
408 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
409 myPosition.X(),
410 myPosition.Y(),
411 myPosition.Z(),
412 myPosition.X() + size,
413 myPosition.Y() + size,
414 myPosition.Z() + size);
415 aSelection->Add(box);
416}
417
418
419//=======================================================================
420//function : ComputeOneFaceLength
421//purpose :
422//=======================================================================
423
424void AIS_LengthDimension::ComputeOneFaceLength(const Handle(Prs3d_Presentation)&)
425{
426 Standard_DomainError::Raise("AIS_LengthDimension::ComputeOneFaceLength : Not implemented");
427}
428
429//=======================================================================
430//function : ComputeOneOneEdgeLength
431//purpose :
432//=======================================================================
433
434void AIS_LengthDimension::ComputeOneEdgeLength(const Handle(Prs3d_Presentation)&)
435{
436 Standard_DomainError::Raise("AIS_LengthDimension::ComputeOneEdgeLength : Not implemented");
437}
438
439//=======================================================================
440//function : ComputeTwoFacesLength
441//purpose :
442//=======================================================================
443
444void AIS_LengthDimension::ComputeTwoFacesLength( const Handle( Prs3d_Presentation )& aPresentation )
445{
446 if (myFShape.ShapeType() == TopAbs_COMPOUND) { //rob debug from vbu?
447 TopExp_Explorer E (myFShape,TopAbs_FACE);
448 if (E.More()) SetFirstShape(E.Current());
449 }
450 if (mySShape.ShapeType() == TopAbs_COMPOUND) {
451 TopExp_Explorer E (mySShape,TopAbs_FACE);
452 if (E.More()) SetSecondShape(E.Current()); // rob debug from vbu?
453 }
454
455 if (myFirstSurfType == AIS_KOS_Plane)
456 {
457 AIS::ComputeLengthBetweenPlanarFaces( TopoDS::Face(myFShape),
458 TopoDS::Face(mySShape),
459 myFirstPlane,
460 mySecondPlane,
461 myVal,
462 myFAttach,
463 mySAttach,
464 myDirAttach,
465 myAutomaticPosition,
466 myPosition );
467 if (myAutomaticPosition && myIsSetBndBox)
468 myPosition = AIS::TranslatePointToBound( myPosition, myDirAttach, myBndBox );
469
470 myDrawer->LengthAspect()->Arrow1Aspect()->SetLength( myArrowSize );
471 myDrawer->LengthAspect()->Arrow2Aspect()->SetLength( myArrowSize );
472
81bba717 473 // Find text of the face
7fd59977 474
475 DsgPrs_LengthPresentation::Add( aPresentation,
476 myDrawer,
477 myText,
478 myFAttach,
479 mySAttach,
480 myFirstPlane,
481 myDirAttach,
482 myPosition,
483 mySymbolPrs );
484 }
485 else
486 {
487 AIS::ComputeLengthBetweenCurvilinearFaces( TopoDS::Face(myFShape),
488 TopoDS::Face(mySShape),
489 myFirstBasisSurf,
490 mySecondBasisSurf,
491 myAutomaticPosition,
492 myVal,
493 myPosition,
494 myFAttach,
495 mySAttach,
496 myDirAttach );
497 if (myAutomaticPosition && myIsSetBndBox)
498 myPosition = AIS::TranslatePointToBound( myPosition, myDirAttach, myBndBox );
499
500 DsgPrs_LengthPresentation::Add( aPresentation,
501 myDrawer,
502 myText,
503 mySecondBasisSurf,
504 myFAttach,
505 mySAttach,
506 myDirAttach,
507 myPosition,
508 mySymbolPrs );
509 }
510}
511
512
513//=======================================================================
514//function : ComputeEdgeFaceLength
515//purpose : Jean-Claude Vauthier 17/06/98
516// A quick implementation in order to edit the constraint of
517// distance for a chamfer 3D.
518//=======================================================================
519
520void AIS_LengthDimension::ComputeEdgeFaceLength (const Handle(Prs3d_Presentation )& aPresentation )
521{
522
523 //The first attachment point is P1 from the reference Edge
524 //Find the second attachment point which belongs to the reference face
525 //Iterate over the edges of the face and find the point FP1...
526 //....it is the closest point according to P1
527
528 const TopoDS_Edge& E = TopoDS::Edge (mySShape); //The reference edge
529 const TopoDS_Face& F = TopoDS::Face (myFShape); //The reference face
530 TopoDS_Vertex V1, V2;
531 TopExp::Vertices (E, V1, V2);
532 myFAttach = BRep_Tool::Pnt (V1);
533 gp_Pnt P = BRep_Tool::Pnt (V2);
534
535 TopExp_Explorer It (F, TopAbs_EDGE);
536 gp_Pnt2d FP1uv, FP2uv;
537 Standard_Real Dist1 = RealLast ();
538 Standard_Real Dist2 = RealLast ();
539 for (; It.More (); It.Next ()) {
540 const TopoDS_Edge FE = TopoDS::Edge(It.Current ());
541 TopExp::Vertices (FE, V1, V2);
542 gp_Pnt FP1c = BRep_Tool::Pnt (V1);
543 gp_Pnt FP2c = BRep_Tool::Pnt (V2);
544 Standard_Real Dc1 = myFAttach.SquareDistance (FP1c);
545 Standard_Real Dc2 = myFAttach.SquareDistance (FP2c);
546 if (Dc1 <= Dc2) {
547 if (Dc1 <= Dist1) {
548 Dc2 = P.SquareDistance (FP2c);
549 if (Dc2 <= Dist2) {
550 mySAttach = FP1c;
551 Dist1 = Dc1;
552 Dist2 = Dc2;
553 BRep_Tool::UVPoints (FE, F, FP1uv, FP2uv);
554 }
555 }
556 }
557 else {
558 if (Dc2 <= Dist1) {
559 Dc1 = P.SquareDistance (FP1c);
560 if (Dc1 <= Dist2) {
561 mySAttach = FP2c;
562 Dist1 = Dc2;
563 Dist2 = Dc1;
564 BRep_Tool::UVPoints (FE, F, FP2uv, FP1uv);
565 }
566 }
567 }
568 }
569
570 gp_Vec OffsetDirection (0.0, 0.0, 0.0);
571
572 //The offset direction is the normal to the face at the point FP1
573 BRepGProp_Face GF;
574 GF.Load (F);
575 GF.Normal (FP1uv.X(), FP1uv.Y(), P, OffsetDirection);
576
577 if (OffsetDirection.Magnitude () > Precision::Confusion ()) {
578 myDirAttach = gp_Dir (OffsetDirection);
579 }
580 else myDirAttach = gp::DZ ();
581
582
583 gp_Vec Vt (myDirAttach);
584 Vt.Multiply (1.5 * myVal);
585 myPosition = mySAttach.Translated (Vt);
586
587 DsgPrs_LengthPresentation::Add(aPresentation,
588 myDrawer,
589 myText,
590 myFAttach,
591 mySAttach,
592 myDirAttach,
593 myPosition,
594 mySymbolPrs);
595
596}
597
598
599//=======================================================================
600//function : ComputeTwoEdgesLength
601//purpose :
602//=======================================================================
603
604void AIS_LengthDimension::ComputeTwoEdgesLength( const Handle( Prs3d_Presentation )& aPresentation,
605 const Handle( AIS_Drawer )& aDrawer,
606 const TCollection_ExtendedString & aText,
607 const Standard_Real ArrowSize,
608 const TopoDS_Edge & FirstEdge,
609 const TopoDS_Edge & SecondEdge,
610 const Handle( Geom_Plane )& Plane,
611 const Standard_Boolean AutomaticPos,
612 const Standard_Boolean IsSetBndBox,
613 const Bnd_Box & BndBox,
614 Standard_Integer & ExtShape,
615 Standard_Real & Val,
616 gp_Dir & DirAttach,
617 gp_Pnt & Position,
618 gp_Pnt & FirstAttach,
619 gp_Pnt & SecondAttach,
620 DsgPrs_ArrowSide & SymbolPrs )
621{
622 BRepAdaptor_Curve cu1( FirstEdge );
623 if (cu1.GetType() != GeomAbs_Line) return;
624 BRepAdaptor_Curve cu2( SecondEdge );
625 if (cu2.GetType() != GeomAbs_Line) return;
626
627 // 3d lines
628 Handle(Geom_Curve) geom1,geom2;
629 gp_Pnt ptat11,ptat12,ptat21,ptat22;//,pint3d;
630
631 Standard_Boolean isInfinite1(Standard_False),isInfinite2(Standard_False);
632 Standard_Integer ext(ExtShape);
633 Handle(Geom_Curve) extCurv;
634 if (!AIS::ComputeGeometry(FirstEdge,
635 SecondEdge,
636 ExtShape,
637 geom1,
638 geom2,
639 ptat11,
640 ptat12,
641 ptat21,
642 ptat22,
643 extCurv,
644 isInfinite1,
645 isInfinite2,
646 Plane))
647 {
648 return;
649 }
650 ExtShape = ext;
651 aPresentation->SetInfiniteState(isInfinite1 || isInfinite2);
652 const Handle(Geom_Line)& geom_lin1 = (Handle(Geom_Line)&) geom1;
653 const Handle(Geom_Line)& geom_lin2 = (Handle(Geom_Line)&) geom2;
654 const gp_Lin& l1 = geom_lin1->Lin();
655 const gp_Lin& l2 = geom_lin2->Lin();
656
657 // New: computation of myVal
658 Val = l1.Distance( l2 );
659
660 DirAttach = l1.Direction();
661
662 // size
663 Standard_Real arrsize = ArrowSize;
664
665 if (AutomaticPos) {
666 gp_Pnt curpos;
667 if ( !isInfinite1 ) {
668 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
669 curpos.SetXYZ((ptat11.XYZ()+p2.XYZ())/2.);
670 }
671 else if (!isInfinite2) {
672 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l1,ptat21),l1);
673 curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())/2.);
674 }
675 else {
676 curpos.SetXYZ((l1.Location().XYZ()+l2.Location().XYZ())/2.);
677 }
81bba717 678 // offset to avoid confusion Edge and Dimension
7fd59977 679 gp_Vec offset(DirAttach);
680 offset = offset*ArrowSize*(-10.);
681 curpos.Translate(offset);
682 Position = curpos;
683 }
81bba717 684 else { // the point is projected in the plane
7fd59977 685 // it is patch!
686 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
687 }
688
81bba717 689 // find attachment points
7fd59977 690 if (!isInfinite1) {
691 if (Position.Distance(ptat11) > Position.Distance(ptat12)) FirstAttach = ptat12;
692 else FirstAttach = ptat11;
693 }
694 else {
695 FirstAttach = ElCLib::Value(ElCLib::Parameter(l1,Position),l1);
696 }
697
698 if (!isInfinite2) {
699 if (Position.Distance(ptat21) > Position.Distance(ptat22)) SecondAttach = ptat22;
700 else SecondAttach = ptat21;
701 }
702 else {
703 SecondAttach = ElCLib::Value(ElCLib::Parameter(l2,Position),l2);
704 }
705
706 Standard_Real confusion(Precision::Confusion());
707 if (arrsize < confusion) arrsize = Val/10.;
708 if (Abs(Val) <= confusion) {arrsize = 0.;}
709
710 Handle(Prs3d_LengthAspect) la = aDrawer->LengthAspect();
711 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
712 arr->SetLength(arrsize);
713 arr = la->Arrow2Aspect();
714 arr->SetLength(arrsize);
715
716 if ( ExtShape == 1)
717 SymbolPrs = DsgPrs_AS_FIRSTPT_LASTAR;
718 else if ( ExtShape == 2)
719 SymbolPrs = DsgPrs_AS_FIRSTAR_LASTPT;
720
721 if (AutomaticPos && IsSetBndBox)
722 Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );
723
724 DsgPrs_LengthPresentation::Add(aPresentation,
725 aDrawer,
726 aText,
727 FirstAttach,
728 SecondAttach,
729 DirAttach,
730 Position,
731 SymbolPrs);
732
733 if ( (ExtShape != 0) && !extCurv.IsNull()) {
734 gp_Pnt pf, pl;
735 if ( ExtShape == 1 ) {
736 if (!isInfinite1) {
737 pf = ptat11;
738 pl = ptat12;
739 }
740 AIS::ComputeProjEdgePresentation( aPresentation, aDrawer, FirstEdge, geom_lin1, pf, pl );
741 }
742 else {
743 if (!isInfinite2) {
744 pf = ptat21;
745 pl = ptat22;
746 }
747 AIS::ComputeProjEdgePresentation( aPresentation, aDrawer, SecondEdge, geom_lin2, pf, pl );
748 }
749 }
750}
751
752//=======================================================================
753//function : ComputeOneEdgeOneVertexLength
754//purpose :
755//=======================================================================
756
757void AIS_LengthDimension::ComputeOneEdgeOneVertexLength( const Handle( Prs3d_Presentation )& aPresentation,
758 const Handle( AIS_Drawer )& aDrawer,
759 const TCollection_ExtendedString & aText,
760 const Standard_Real ArrowSize,
761 const TopoDS_Shape & FirstShape,
762 const TopoDS_Shape & SecondShape,
763 const Handle( Geom_Plane )& Plane,
764 const Standard_Boolean AutomaticPos,
765 const Standard_Boolean IsSetBndBox,
766 const Bnd_Box & BndBox,
767 Standard_Integer & ExtShape,
768 Standard_Real & Val,
769 gp_Dir & DirAttach,
770 gp_Pnt & Position,
771 gp_Pnt & FirstAttach,
772 gp_Pnt & SecondAttach,
773 DsgPrs_ArrowSide & SymbolPrs )
774{
775 TopoDS_Vertex thevertex;
776 TopoDS_Edge theedge;
777 Standard_Integer numedge;
778
779 if (FirstShape.ShapeType() == TopAbs_VERTEX) {
780 thevertex = TopoDS::Vertex(FirstShape);
781 theedge = TopoDS::Edge(SecondShape);
81bba717 782 numedge = 2;// edge = 2nd shape
7fd59977 783 }
784 else {
785 thevertex = TopoDS::Vertex(SecondShape);
786 theedge = TopoDS::Edge(FirstShape);
81bba717 787 numedge = 1; // edge = 1st shape
7fd59977 788 }
789
790 gp_Pnt ptonedge1,ptonedge2;
791 Handle(Geom_Curve) aCurve;
792 Handle(Geom_Curve) extCurv;
793 Standard_Boolean isInfinite;
794 Standard_Boolean isOnPlanEdge, isOnPlanVertex;
795 if (!AIS::ComputeGeometry(theedge,aCurve,ptonedge1,ptonedge2,extCurv,isInfinite,isOnPlanEdge,Plane))
796 return;
797 aPresentation->SetInfiniteState(isInfinite);
798 AIS::ComputeGeometry(thevertex, FirstAttach, Plane, isOnPlanVertex);
799
81bba717 800 // take into consideration that only the curve can be projected
7fd59977 801 if (!isOnPlanEdge && !isOnPlanVertex)
802 return;
803
804 if (!isOnPlanEdge) {
805 if (numedge == 1) ExtShape = 1;
806 else ExtShape = 2;
807 }
808 else if (!isOnPlanVertex) {
809 if (numedge == 1) ExtShape = 2;
810 else ExtShape = 1;
811 }
812
813
814 const Handle(Geom_Line)& geom_lin = (Handle(Geom_Line)&) aCurve;
815 const gp_Lin& l = geom_lin->Lin();
816
817 // New: computation of Val
818 Val = l.Distance( FirstAttach );
819
820 DirAttach = l.Direction();
821 // size
822 Standard_Real arrsize = ArrowSize;
823 if (Abs(Val) <= Precision::Confusion()) {arrsize = 0.;}
824
825 if (AutomaticPos) {
826 gp_Pnt p = ElCLib::Value(ElCLib::Parameter(l,FirstAttach),l);
827 gp_Pnt curpos((FirstAttach.XYZ()+p.XYZ())/2.);
81bba717 828 // offset to avoid confusion Edge and Dimension
7fd59977 829 gp_Vec offset(DirAttach);
830 offset = offset*ArrowSize*(-10.);
831 curpos.Translate(offset);
832 Position = curpos;
833 }
81bba717 834 else { // the point is projected in the plane
7fd59977 835 // it is patch!
836 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
837
838 /*
839 Standard_Real u,v;
840 ElSLib::Parameters(Plane->Pln() , Position, u, v);
841 Position = ElSLib::Value(u,v,Plane->Pln());
842 */
843 }
844
845 if (!isInfinite) {
846 if (Position.Distance(ptonedge1) > Position.Distance(ptonedge2)) SecondAttach = ptonedge2;
847 else SecondAttach = ptonedge1;
848 }
849 else {
850 SecondAttach = ElCLib::Value(ElCLib::Parameter(l,Position),l);
851 }
852
853 Handle(Prs3d_LengthAspect) la = aDrawer->LengthAspect();
854 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
855 arr->SetLength(arrsize);
856 arr = la->Arrow2Aspect();
857 arr->SetLength(arrsize);
858
859 if (AutomaticPos && IsSetBndBox)
860 Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );
861
862 DsgPrs_LengthPresentation::Add(aPresentation,
863 aDrawer,
864 aText,
865 FirstAttach,
866 SecondAttach,
867 DirAttach,
868 Position,
869 SymbolPrs);
870
871 //Display des morceaux de raccordement vers la curve si elle
872 // n'est pas dans le WP
873 if (ExtShape != 0) {
874
875 if (!extCurv.IsNull()) { // c'est l'edge qui n'est pas dans le WP
876 AIS::ComputeProjEdgePresentation(aPresentation,aDrawer,theedge,geom_lin,ptonedge1,ptonedge2);
877 }
878 else { // c'est le point qui n'est pas dans le WP
879 AIS::ComputeProjVertexPresentation(aPresentation,aDrawer,thevertex,FirstAttach);
880 }
881 }
882}
883
884//=======================================================================
885//function : ComputeTwoVerticesLength
886//purpose :
887//=======================================================================
888
889void AIS_LengthDimension::ComputeTwoVerticesLength( const Handle( Prs3d_Presentation )& aPresentation,
890 const Handle( AIS_Drawer )& aDrawer,
891 const TCollection_ExtendedString& aText,
892 const Standard_Real ArrowSize,
893 const TopoDS_Vertex& FirstVertex,
894 const TopoDS_Vertex& SecondVertex,
895 const Handle( Geom_Plane )& Plane,
896 const Standard_Boolean AutomaticPos,
897 const Standard_Boolean IsSetBndBox,
898 const Bnd_Box& BndBox,
899 const AIS_TypeOfDist TypeDist,
900 Standard_Integer& ExtShape,
901 Standard_Real& Val,
902 gp_Dir& DirAttach,
903 gp_Pnt& Position,
904 gp_Pnt& FirstAttach,
905 gp_Pnt& SecondAttach,
906 DsgPrs_ArrowSide& SymbolPrs )
907{
908 Standard_Boolean isOnPlane1, isOnPlane2;
909
910 AIS::ComputeGeometry( FirstVertex, FirstAttach, Plane, isOnPlane1);
911 AIS::ComputeGeometry( SecondVertex, SecondAttach, Plane, isOnPlane2);
912
913 // New: computation of Val
914 Val = FirstAttach.Distance( SecondAttach );
915
916 if (ExtShape == 0) {
917 if (isOnPlane1 && isOnPlane2)
918 ExtShape = 0;
919 else if ( isOnPlane1 && !isOnPlane2)
920 ExtShape = 2;
921 else if (!isOnPlane1 && isOnPlane2)
922 ExtShape = 1;
923 else
924 return ;
925 }
926 Standard_Real confusion(Precision::Confusion());
927 Standard_Boolean samePoint(FirstAttach.IsEqual(SecondAttach,confusion));
928
929 if (TypeDist == AIS_TOD_Vertical) DirAttach = Plane->Pln().XAxis().Direction();
930 else if (TypeDist == AIS_TOD_Horizontal) DirAttach = Plane->Pln().YAxis().Direction();
931 else {
932 if (!samePoint) {
933 DirAttach = gce_MakeDir(FirstAttach,SecondAttach);
934 DirAttach.Rotate(Plane->Pln().Axis(),PI/2.);
935 }
936 }
937
938 // size
939 //Standard_Real arrsize = ArrowSize;
940 //if (Abs(Val) <= confusion) arrsize =0.;
941
942 if (AutomaticPos) {
943 if (!samePoint) {
944 gp_Pnt curpos((FirstAttach.XYZ()+SecondAttach.XYZ())/2.);
81bba717 945 // offset to avoid confusion Edge and Dimension
7fd59977 946 gp_Vec offset(DirAttach);
947 offset = offset*ArrowSize*(-10.);
948 curpos.Translate(offset);
949 Position = curpos;
950 }
951 else {
952 Position = gp_Pnt(FirstAttach.XYZ()+gp_XYZ(1.,1.,1.));
953 // it is patch!
954 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
955 DirAttach = gce_MakeDir(FirstAttach,Position);
956 }
957 }
958 else {
959 // it is patch!
960 Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
961 }
962
963
964 Handle(Prs3d_LengthAspect) la = aDrawer->LengthAspect();
965 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
966 arr->SetLength(ArrowSize);
967 arr = la->Arrow2Aspect();
968 arr->SetLength(ArrowSize);
969
81bba717 970 // Type of arrows
7fd59977 971 if ( ExtShape == 1) SymbolPrs = DsgPrs_AS_FIRSTPT_LASTAR;
972 else if (ExtShape == 2) SymbolPrs = DsgPrs_AS_FIRSTAR_LASTPT;
973
974 if (AutomaticPos && IsSetBndBox)
975 Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );
976
977 DsgPrs_LengthPresentation::Add(aPresentation,
978 aDrawer,
979 aText,
980 FirstAttach,
981 SecondAttach,
982 DirAttach,
983 Position,
984 SymbolPrs);
985
81bba717 986 // Calculate the projection of the vertex
7fd59977 987 if ( ExtShape == 1)
988 AIS::ComputeProjVertexPresentation(aPresentation, aDrawer, FirstVertex, FirstAttach);
989 else if ( ExtShape == 2)
990 AIS::ComputeProjVertexPresentation(aPresentation, aDrawer, SecondVertex, SecondAttach);
991}
992
993//=======================================================================
994//function : ComputeTwoFaceSelection
995//purpose :
996//=======================================================================
997
998void AIS_LengthDimension::ComputeFaceSelection( const Handle( SelectMgr_Selection )& aSelection )
999{
1000 Handle( SelectMgr_EntityOwner ) own = new SelectMgr_EntityOwner( this, 7 );
1001 Handle( Select3D_SensitiveSegment ) seg;
1002 Handle( Geom_TrimmedCurve ) curve;
1003 Handle( Select3D_SensitiveCurve ) SensCurve;
1004
1005 Standard_Real ArrowLength = myDrawer->AngleAspect()->ArrowAspect()->Length();
1006
1007 gp_Pnt EndOfArrow1, EndOfArrow2;
1008 gp_Dir DirOfArrow1;
1009
1010 if (myFirstSurfType == AIS_KOS_Plane)
1011 {
1012 DsgPrs::ComputePlanarFacesLengthPresentation( ArrowLength,
1013 ArrowLength,
1014 myFAttach,
1015 mySAttach,
1016 myDirAttach,
1017 myPosition,
1018 myFirstPlane,
1019 EndOfArrow1,
1020 EndOfArrow2,
1021 DirOfArrow1 );
1022 //Add attach lines
1023 seg = new Select3D_SensitiveSegment( own, myFAttach, EndOfArrow1 );
1024 aSelection->Add( seg );
1025
1026 seg = new Select3D_SensitiveSegment( own, mySAttach, EndOfArrow2 );
1027 aSelection->Add( seg );
1028 }
1029 else // curvilinear case
1030 {
1031 if(mySecondBasisSurf.IsNull())
1032 return;
1033
1034 Handle( Geom_Curve ) VCurve, UCurve;
1035 Standard_Real FirstU, deltaU = 0.0e0, FirstV, deltaV = 0.0e0;
1036
1037 EndOfArrow1 = myFAttach;
1038 DsgPrs::ComputeCurvilinearFacesLengthPresentation( ArrowLength,
1039 ArrowLength,
1040 mySecondBasisSurf,
1041 myFAttach,
1042 mySAttach,
1043 myDirAttach,
1044 EndOfArrow2,
1045 DirOfArrow1,
1046 VCurve,
1047 UCurve,
1048 FirstU, deltaU,
1049 FirstV, deltaV );
1050 // Add attach curves
1051 if (Abs( deltaU ) > Precision::PConfusion())
1052 {
1053 if (deltaU > 0.0)
1054 curve = new Geom_TrimmedCurve( VCurve, FirstU, FirstU + deltaU );
1055 else
1056 curve = new Geom_TrimmedCurve( VCurve, FirstU + deltaU, FirstU );
1057 SensCurve = new Select3D_SensitiveCurve( own, curve );
1058 aSelection->Add( SensCurve );
1059 }
1060 if (Abs( deltaV ) > Precision::PConfusion())
1061 {
1062 if (deltaV > 0.0)
1063 curve = new Geom_TrimmedCurve( UCurve, FirstV, FirstV + deltaV );
1064 else
1065 curve = new Geom_TrimmedCurve( UCurve, FirstV + deltaV, FirstV );
1066 SensCurve = new Select3D_SensitiveCurve( own, curve );
1067 aSelection->Add( SensCurve );
1068 }
1069 }
1070
1071 // Add the length's line
1072 gp_Pnt FirstPoint, LastPoint; // ends of length's line
1073 gp_Vec ArrowVec( DirOfArrow1 );
1074 ArrowVec *= ArrowLength;
1075 if (myVal <= Precision::Confusion())
1076 {
1077 if (myPosition.SquareDistance( EndOfArrow1 ) > ArrowLength*ArrowLength)
1078 {
1079 FirstPoint = myPosition;
1080 LastPoint = EndOfArrow1.Translated( ArrowVec );
1081 if (myPosition.SquareDistance( LastPoint ) < myPosition.SquareDistance( EndOfArrow1 ))
1082 LastPoint = EndOfArrow1.Translated( -ArrowVec );
1083 }
1084 else
1085 {
1086 FirstPoint = EndOfArrow1.Translated( ArrowVec );
1087 LastPoint = EndOfArrow1.Translated( -ArrowVec );
1088 }
1089 }
1090 else
1091 {
1092 gp_Lin LengthLine( myPosition, DirOfArrow1 );
1093 Standard_Real Par1 = ElCLib::Parameter( LengthLine, EndOfArrow1 );
1094 Standard_Real Par2 = ElCLib::Parameter( LengthLine, EndOfArrow2 );
1095 if (Par1 > 0.0 && Par2 > 0.0 || Par1 < 0.0 && Par2 < 0.0)
1096 {
1097 FirstPoint = myPosition;
1098 LastPoint = (Abs( Par1 ) > Abs( Par2 ))? EndOfArrow1 : EndOfArrow2;
1099 LastPoint.Translate( ((Abs( Par1 ) > Abs( Par2 ))? -ArrowVec : ArrowVec) );
1100 }
1101 else
1102 {
1103 FirstPoint = EndOfArrow1;
1104 LastPoint = EndOfArrow2;
1105 }
1106 }
1107 seg = new Select3D_SensitiveSegment( own, FirstPoint, LastPoint );
1108 aSelection->Add( seg );
1109}
1110
1111//=======================================================================
1112//function : ComputeEdgeVertexSelection
1113//purpose :
1114//=======================================================================
1115
1116void AIS_LengthDimension::ComputeEdgeVertexSelection(const Handle(SelectMgr_Selection)& aSelection)
1117{
1118 // ********** NB ->
81bba717 1119 // in the case of a constraint relatively to the border of a face
1120 // only the shape of this contour is valid
7fd59977 1121
81bba717 1122 // Create 2 owner for edition of constraints
7fd59977 1123 Handle(AIS_DimensionOwner) own1 = new AIS_DimensionOwner(this,7);
1124 Handle(AIS_DimensionOwner) own2 = new AIS_DimensionOwner(this,7);
1125
1126 if (myExtShape != 0) {
1127 if (myExtShape == 1) {
1128 own1->SetShape(mySShape);
1129 own2->SetShape(mySShape);
1130 }
1131 else {
1132 own1->SetShape(myFShape);
1133 own2->SetShape(myFShape);
1134 }
1135 }
1136 else {
1137 own1->SetShape(myFShape);
1138 own2->SetShape(mySShape);
1139 }
1140
1141
1142 gp_Lin L1 (myFAttach,myDirAttach);
1143 gp_Lin L2 (mySAttach,myDirAttach);
1144 gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,myPosition),L1);
1145 gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,myPosition),L2);
1146 gp_Lin L3;
1147
1148 Standard_Real confusion(Precision::Confusion());
1149
1150 if (!Proj1.IsEqual(Proj2,confusion)) L3 = gce_MakeLin(Proj1,Proj2);
1151 else {
81bba717 1152 // cas of zero dimension
1153 // own1 is chosen by default
7fd59977 1154 L3 = gce_MakeLin(Proj1,myDirAttach);
1155 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
1156 Handle(Select3D_SensitiveBox) box = new Select3D_SensitiveBox(own1,myPosition.X(),myPosition.Y(),myPosition.Z(),
1157 myPosition.X()+size,
1158 myPosition.Y()+size,
1159 myPosition.Z()+size);
1160 aSelection->Add(box);
1161 }
1162
1163 Standard_Real parmin,parmax,parcur;
1164 parmin = ElCLib::Parameter(L3,Proj1);
1165 parmax = parmin;
1166
1167 parcur = ElCLib::Parameter(L3,Proj2);
1168 parmin = Min(parmin,parcur);
1169 parmax = Max(parmax,parcur);
1170
1171 parcur = ElCLib::Parameter(L3,myPosition);
1172 parmin = Min(parmin,parcur);
1173 parmax = Max(parmax,parcur);
1174
1175 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
1176 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
1177
1178 Handle(Select3D_SensitiveSegment) seg;
1179
1180 if (myFAttach.IsEqual(mySAttach,confusion) && !myPosition.IsEqual(mySAttach,confusion)) {
1181 seg = new Select3D_SensitiveSegment(own1,mySAttach,myPosition);
1182 aSelection->Add(seg);
1183 }
1184 if (!PointMin.IsEqual(PointMax,confusion)) {
1185 gp_Pnt MiddlePoint( (PointMin.XYZ() + PointMax.XYZ())/2);
1186 seg = new Select3D_SensitiveSegment(own1,PointMin,MiddlePoint);
1187 aSelection->Add(seg);
1188 seg = new Select3D_SensitiveSegment(own2,MiddlePoint, PointMax);
1189 aSelection->Add(seg);
1190 }
1191
1192 if (!myFAttach.IsEqual(Proj1,confusion)) {
1193 seg = new Select3D_SensitiveSegment(own1,myFAttach,Proj1);
1194 aSelection->Add(seg);
1195 }
1196 if (!mySAttach.IsEqual(Proj2,confusion)) {
1197 seg = new Select3D_SensitiveSegment(own2,mySAttach,Proj2);
1198 aSelection->Add(seg);
1199 }
1200}
1201
1202
1203
1204
1205//=======================================================================
1206//function : KindOfDimension
1207//purpose :
1208//=======================================================================
1209 AIS_KindOfDimension AIS_LengthDimension::KindOfDimension() const
1210{
1211 return AIS_KOD_LENGTH;
1212}
1213
1214//=======================================================================
1215//function : IsMovable
1216//purpose :
1217//=======================================================================
1218 Standard_Boolean AIS_LengthDimension::IsMovable() const
1219{
1220 return Standard_True;
1221}
1222
1223//=======================================================================
1224//function : SetFirstShape
1225//purpose :
1226//=======================================================================
1227void AIS_LengthDimension::SetFirstShape( const TopoDS_Shape& aFShape )
1228{
1229 myFShape = aFShape;
1230
1231 if (myFShape.ShapeType() == TopAbs_FACE)
1232 AIS::InitFaceLength( TopoDS::Face( myFShape ), myFirstPlane, myFirstBasisSurf, myFirstSurfType, myFirstOffset );
1233}
1234
1235//=======================================================================
1236//function : SetSecondShape
1237//purpose :
1238//=======================================================================
1239void AIS_LengthDimension::SetSecondShape( const TopoDS_Shape& aSShape )
1240{
1241 mySShape = aSShape;
1242
1243 if (mySShape.ShapeType() == TopAbs_FACE)
1244 AIS::InitFaceLength( TopoDS::Face( mySShape ), mySecondPlane, mySecondBasisSurf, mySecondSurfType, mySecondOffset );
1245}