0024339: Vectors not displayed correctly in MFC samples [6.7.0 Beta]: ISession_Direct...
[occt.git] / samples / mfc / standard / 01_Geometry / src / ISession2D / ISession_Direction.cpp
1 // ISession_Direction.cpp: implementation of the ISession_Direction class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #include "stdafx.h"
6 #include "..\\GeometryApp.h"
7 #include "ISession_Direction.h"
8 #include <Prs3d_ArrowAspect.hxx>
9 #include <DsgPrs_LengthPresentation.hxx>
10
11 #ifdef _DEBUG
12 #undef THIS_FILE
13 static char THIS_FILE[]=__FILE__;
14 #endif
15
16 IMPLEMENT_STANDARD_HANDLE(ISession_Direction,AIS_InteractiveObject)
17 IMPLEMENT_STANDARD_RTTIEXT(ISession_Direction,AIS_InteractiveObject)
18
19 //////////////////////////////////////////////////////////////////////
20 // Construction/Destruction
21 //////////////////////////////////////////////////////////////////////
22
23 ISession_Direction::ISession_Direction()
24 {
25
26 }
27
28 ISession_Direction::ISession_Direction (const gp_Pnt& aPnt,
29                                         const gp_Dir& aDir,
30                                         Standard_Real aLength,
31                                         Standard_Real anArrowLength)
32 : myPnt (aPnt),
33   myDir (aDir),
34   myLength (aLength),
35   myArrowLength (anArrowLength)
36 {}
37
38 ISession_Direction::ISession_Direction (const gp_Pnt& aPnt,
39                                         const gp_Vec& aVec,
40                                         Standard_Real anArrowLength)
41 : myPnt (aPnt),
42   myDir (aVec),
43   myArrowLength (anArrowLength)
44 {
45   myLength = aVec.Magnitude();
46 }
47
48 ISession_Direction::ISession_Direction (const gp_Pnt2d& aPnt2d,
49                                         const gp_Dir2d& aDir2d,
50                                         Standard_Real aLength)
51 : myPnt (gp_Pnt(aPnt2d.X(),aPnt2d.Y(),0.0)),
52   myDir (gp_Dir(aDir2d.X(),aDir2d.Y(),0.0)),
53   myLength (aLength)
54 {
55   myArrowLength = myDrawer->ArrowAspect()->Length();
56 }
57
58 ISession_Direction::ISession_Direction (const gp_Pnt2d& aPnt2d,
59                                         const gp_Vec2d& aVec2d)
60 : myPnt (gp_Pnt (aPnt2d.X(), aPnt2d.Y(), 0.0)),
61   myDir (gp_Dir(aVec2d.X(), aVec2d.Y(), 0.0))
62 {
63   myLength = aVec2d.Magnitude();
64   myArrowLength = myDrawer->ArrowAspect()->Length();
65 }
66
67
68 ISession_Direction::~ISession_Direction()
69 {
70
71 }
72
73 void ISession_Direction::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
74                                   const Handle(Prs3d_Presentation)& aPresentation,
75                                   const Standard_Integer /*aMode*/)
76 {
77   // Set style for arrow
78   Handle(Prs3d_ArrowAspect) anArrowAspect = myDrawer->ArrowAspect();
79   anArrowAspect->SetLength (myArrowLength);
80
81   gp_Pnt aLastPoint = myPnt;
82   aLastPoint.Translate (myLength*gp_Vec(myDir));
83
84   // Draw Line
85   Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments (2);
86   aPrims->AddVertex (myPnt);
87   aPrims->AddVertex (aLastPoint);
88   Prs3d_Root::CurrentGroup (aPresentation)->SetPrimitivesAspect (myDrawer->LineAspect()->Aspect());
89   Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (aPrims);
90   // Draw arrow
91   Prs3d_Arrow::Draw (aPresentation,
92                      aLastPoint,
93                      myDir,
94                      anArrowAspect->Angle(),
95                      anArrowAspect->Length());
96
97   // Draw text
98   if (myText.Length() != 0)
99   {
100     gp_Pnt aTextPosition = aLastPoint;
101     Prs3d_Text::Draw (aPresentation,
102                       myDrawer->TextAspect(),
103                       myText,
104                       aTextPosition);
105   }
106 }
107
108
109 void ISession_Direction::Compute (const Handle(Prs3d_Projector)& /*aProjector*/,
110                                   const Handle(Prs3d_Presentation)& /*aPresentation*/) 
111 {
112 }
113
114 void ISession_Direction::ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
115                                            const Standard_Integer /*aMode*/) 
116 {
117 }
118
119 void ISession_Direction::SetText (TCollection_ExtendedString & theText)
120 {
121   myText = theText;
122 }
123
124 void ISession_Direction::SetText (Standard_CString theText)
125 {
126   myText = theText;
127 }
128
129 void ISession_Direction::SetLineAspect (const Handle(Prs3d_LineAspect)& theAspect)
130 {
131   myDrawer->SetLineAspect (theAspect);
132 }