0031459: Visualization, AIS_TextLabel - add missing getters
[occt.git] / src / AIS / AIS_PlaneTrihedron.cxx
1 // Created on: 1996-12-13
2 // Created by: Jean-Pierre COMBE
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 // + X/YAxis() returns AIS_Line instead of AIS_Axis
18 // + (-1) selection mode token into account 
19 // (SAMTECH specific)
20
21 #include <AIS_InteractiveObject.hxx>
22 #include <AIS_Line.hxx>
23 #include <AIS_PlaneTrihedron.hxx>
24 #include <AIS_Point.hxx>
25 #include <Aspect_TypeOfLine.hxx>
26 #include <DsgPrs_XYZAxisPresentation.hxx>
27 #include <Geom_Axis1Placement.hxx>
28 #include <Geom_Axis2Placement.hxx>
29 #include <Geom_CartesianPoint.hxx>
30 #include <Geom_Line.hxx>
31 #include <Geom_Plane.hxx>
32 #include <Geom_Transformation.hxx>
33 #include <gp_Ax2.hxx>
34 #include <gp_Pln.hxx>
35 #include <gp_Pnt.hxx>
36 #include <gp_Vec.hxx>
37 #include <Graphic3d_AspectFillArea3d.hxx>
38 #include <Graphic3d_AspectLine3d.hxx>
39 #include <Graphic3d_MaterialAspect.hxx>
40 #include <Graphic3d_Structure.hxx>
41 #include <Prs3d_DatumAspect.hxx>
42 #include <Prs3d_Drawer.hxx>
43 #include <Prs3d_LineAspect.hxx>
44 #include <Prs3d_Presentation.hxx>
45 #include <Quantity_Color.hxx>
46 #include <Select3D_SensitivePoint.hxx>
47 #include <Select3D_SensitiveSegment.hxx>
48 #include <SelectMgr_EntityOwner.hxx>
49 #include <SelectMgr_Selection.hxx>
50 #include <Standard_Type.hxx>
51 #include <TColgp_Array1OfPnt.hxx>
52 #include <TCollection_AsciiString.hxx>
53 #include <UnitsAPI.hxx>
54
55 IMPLEMENT_STANDARD_RTTIEXT(AIS_PlaneTrihedron,AIS_InteractiveObject)
56
57 void  ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer);
58
59 //=======================================================================
60 //function : AIS_PlaneTrihedron
61 //purpose  : 
62 //=======================================================================
63 AIS_PlaneTrihedron::AIS_PlaneTrihedron(const Handle(Geom_Plane)& aPlane)
64 :myPlane(aPlane)
65 {
66   Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
67 //POP  Standard_Real aLength = UnitsAPI::CurrentFromLS (100. ,"LENGTH");
68   Standard_Real aLength = UnitsAPI::AnyToLS (100. ,"mm");
69   DA->SetAxisLength(aLength,aLength,aLength);
70   Quantity_Color col (Quantity_NOC_ROYALBLUE1);
71   DA->LineAspect(Prs3d_DP_XAxis)->SetColor(col);
72   DA->LineAspect(Prs3d_DP_YAxis)->SetColor(col);
73   DA->SetDrawDatumAxes(Prs3d_DA_XYAxis);
74   myDrawer->SetDatumAspect(DA); // odl - specific is created because it is modified
75   myShapes[0] = Position();
76   myShapes[1] = XAxis();
77   myShapes[2] = YAxis();
78
79   myXLabel = TCollection_AsciiString( "X" );
80   myYLabel = TCollection_AsciiString( "Y" );
81 }
82
83 //=======================================================================
84 //function : Component
85 //purpose  : 
86 //=======================================================================
87
88  Handle(Geom_Plane) AIS_PlaneTrihedron::Component()
89 {
90   return myPlane;
91 }
92
93
94 //=======================================================================
95 //function : SetComponent
96 //purpose  : 
97 //=======================================================================
98
99  void AIS_PlaneTrihedron::SetComponent(const Handle(Geom_Plane)& aPlane)
100 {
101   myPlane = aPlane;
102 }
103
104 //=======================================================================
105 //function : XAxis
106 //purpose  : 
107 //=======================================================================
108 Handle(AIS_Line) AIS_PlaneTrihedron::XAxis() const 
109 {
110   Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().XAxis());
111   Handle(AIS_Line) aLine = new AIS_Line (aGLine);
112   aLine->SetColor(Quantity_NOC_ROYALBLUE1);
113   return aLine;
114 }
115
116 //=======================================================================
117 //function : YAxis
118 //purpose  : 
119 //=======================================================================
120 Handle(AIS_Line) AIS_PlaneTrihedron::YAxis() const 
121 {
122   Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().YAxis());
123   Handle(AIS_Line) aLine = new AIS_Line (aGLine);
124   aLine->SetColor(Quantity_NOC_ROYALBLUE1);
125   return aLine;
126 }
127
128 //=======================================================================
129 //function : Position
130 //purpose  : 
131 //=======================================================================
132 Handle(AIS_Point) AIS_PlaneTrihedron::Position() const 
133 {
134   gp_Pnt aPnt = myPlane->Pln().Location();
135   Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
136   Handle(AIS_Point) aPt = new AIS_Point (aPoint);
137   return aPt;
138 }
139
140 void AIS_PlaneTrihedron::SetLength(const Standard_Real theLength) {
141   myDrawer->DatumAspect()->SetAxisLength(theLength, theLength, theLength);
142   SetToUpdate();
143 }
144
145 Standard_Real AIS_PlaneTrihedron::GetLength() const {
146   return myDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis);
147 }
148
149 //=======================================================================
150 //function : Compute
151 //purpose  : 
152 //=======================================================================
153 void AIS_PlaneTrihedron::Compute(const Handle(PrsMgr_PresentationManager3d)&,
154                                     const Handle(Prs3d_Presentation)& aPresentation, 
155                                     const Standard_Integer)
156 {
157   aPresentation->SetDisplayPriority(5);
158   // drawing axis in X direction
159   gp_Pnt first, last;
160   Standard_Real value = myDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis);
161   gp_Dir xDir = myPlane->Position().Ax2().XDirection();
162
163   gp_Pnt orig = myPlane->Position().Ax2().Location();
164   Standard_Real xo,yo,zo,x,y,z;
165   orig.Coord( xo, yo, zo );
166   xDir.Coord( x, y, z );
167   first.SetCoord( xo, yo, zo );
168   last.SetCoord( xo + x * value, yo + y * value, zo + z * value );
169   
170   DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->LineAspect(Prs3d_DP_XAxis), myDrawer->ArrowAspect(), myDrawer->TextAspect(), xDir, value, myXLabel.ToCString(), first, last );
171   
172   // drawing axis in Y direction
173   value = myDrawer->DatumAspect()->AxisLength(Prs3d_DP_YAxis);
174   gp_Dir yDir = myPlane->Position().Ax2().YDirection();
175
176   yDir.Coord( x, y, z );
177   last.SetCoord( xo + x * value, yo + y * value, zo + z * value );
178   DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->LineAspect(Prs3d_DP_XAxis), myDrawer->ArrowAspect(), myDrawer->TextAspect(), yDir, value, myYLabel.ToCString(), first, last );
179
180   aPresentation->SetInfiniteState (Standard_True);
181 }
182
183 //=======================================================================
184 //function : ComputeSelection
185 //purpose  : 
186 //=======================================================================
187
188 void AIS_PlaneTrihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
189                                              const Standard_Integer aMode)
190 {
191   Standard_Integer Prior;
192   Handle(SelectMgr_EntityOwner) eown;
193   TColgp_Array1OfPnt PP(1,4),PO(1,4);
194 //  ExtremityPoints(PP);
195   ExtremityPoints(PP,myPlane,myDrawer);
196   switch (aMode) {
197   case 0:
198     {   // triedre complet
199       Prior = 5;
200 //      gp_Ax2 theax = gp_Ax2(myPlane->Position().Ax2());
201 //      gp_Pnt p1 = theax.Location();
202       
203       eown = new SelectMgr_EntityOwner(this,Prior);
204       for (Standard_Integer i=1; i<=2;i++)
205         aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
206       
207       break;
208     }
209   case 1:
210     {  //origine
211       Prior = 8;
212       const Handle(SelectMgr_SelectableObject)& anObj = myShapes[0]; // to avoid ambiguity
213       eown= new SelectMgr_EntityOwner(anObj,Prior);
214       aSelection->Add(new Select3D_SensitivePoint(eown,myPlane->Location()));
215
216       break;
217     }
218   case 2:
219     { //axes ... priorite 7
220       Prior = 7;
221       for (Standard_Integer i=1; i<=2;i++){
222         const Handle(SelectMgr_SelectableObject)& anObj = myShapes[i]; // to avoid ambiguity
223         eown= new SelectMgr_EntityOwner(anObj,Prior);
224         aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
225
226       }
227       break;
228     }
229   case -1:
230     {
231       Prior = 5;
232       aSelection->Clear();
233       break;
234     }
235   }
236 }
237
238 void AIS_PlaneTrihedron::SetColor(const Quantity_Color &aCol)
239 {
240   hasOwnColor=Standard_True;
241   myDrawer->SetColor (aCol);
242   myDrawer->DatumAspect()->LineAspect(Prs3d_DP_XAxis)->SetColor(aCol);
243   myDrawer->DatumAspect()->LineAspect(Prs3d_DP_YAxis)->SetColor(aCol);
244   SynchronizeAspects();
245 }
246
247 //=======================================================================
248 //function : ExtremityPoints
249 //purpose  : to avoid warning
250 //=======================================================================
251 //void  AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const 
252 void  ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer )
253 {
254 //  gp_Ax2 theax(myPlane->Ax2());
255   gp_Ax2 theax(myPlane->Position().Ax2());
256   PP(1) = theax.Location();
257
258   Standard_Real len = myDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis);
259   gp_Vec vec = theax.XDirection();
260   vec *= len;
261   PP(2) = PP(1).Translated(vec);
262   
263   len = myDrawer->DatumAspect()->AxisLength(Prs3d_DP_YAxis);
264   vec = theax.YDirection();
265   vec *= len;
266   PP(3) = PP(1).Translated(vec);
267
268 }
269
270 //=======================================================================
271 //function : AcceptDisplayMode
272 //purpose  : 
273 //=======================================================================
274 Standard_Boolean  AIS_PlaneTrihedron::AcceptDisplayMode(const Standard_Integer aMode) const
275 {return aMode == 0;}
276