0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[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_DatumPrs.hxx>
27 #include <DsgPrs_XYZAxisPresentation.hxx>
28 #include <Geom_Axis1Placement.hxx>
29 #include <Geom_Axis2Placement.hxx>
30 #include <Geom_CartesianPoint.hxx>
31 #include <Geom_Line.hxx>
32 #include <Geom_Plane.hxx>
33 #include <Geom_Transformation.hxx>
34 #include <gp_Ax2.hxx>
35 #include <gp_Pln.hxx>
36 #include <gp_Pnt.hxx>
37 #include <gp_Vec.hxx>
38 #include <Graphic3d_AspectFillArea3d.hxx>
39 #include <Graphic3d_AspectLine3d.hxx>
40 #include <Graphic3d_MaterialAspect.hxx>
41 #include <Graphic3d_Structure.hxx>
42 #include <Prs3d_DatumAspect.hxx>
43 #include <Prs3d_Drawer.hxx>
44 #include <Prs3d_LineAspect.hxx>
45 #include <Prs3d_Presentation.hxx>
46 #include <Prs3d_Projector.hxx>
47 #include <Quantity_Color.hxx>
48 #include <Select3D_SensitivePoint.hxx>
49 #include <Select3D_SensitiveSegment.hxx>
50 #include <SelectMgr_EntityOwner.hxx>
51 #include <SelectMgr_Selection.hxx>
52 #include <Standard_Type.hxx>
53 #include <TColgp_Array1OfPnt.hxx>
54 #include <TCollection_AsciiString.hxx>
55 #include <UnitsAPI.hxx>
56
57 IMPLEMENT_STANDARD_RTTIEXT(AIS_PlaneTrihedron,AIS_InteractiveObject)
58
59 void  ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer);
60
61 //=======================================================================
62 //function : AIS_PlaneTrihedron
63 //purpose  : 
64 //=======================================================================
65 AIS_PlaneTrihedron::AIS_PlaneTrihedron(const Handle(Geom_Plane)& aPlane)
66 :myPlane(aPlane)
67 {
68   Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
69 //POP  Standard_Real aLength = UnitsAPI::CurrentFromLS (100. ,"LENGTH");
70   Standard_Real aLength = UnitsAPI::AnyToLS (100. ,"mm");
71   DA->SetAxisLength(aLength,aLength,aLength);
72   Quantity_NameOfColor col = Quantity_NOC_ROYALBLUE1;
73   DA->FirstAxisAspect()->SetColor(col);
74   DA->SecondAxisAspect()->SetColor(col);
75   DA->SetDrawFirstAndSecondAxis(Standard_True);
76   DA->SetDrawThirdAxis(Standard_False);
77   myDrawer->SetDatumAspect(DA); // odl - specific is created because it is modified
78   myShapes[0] = Position();
79   myShapes[1] = XAxis();
80   myShapes[2] = YAxis();
81
82   myXLabel = TCollection_AsciiString( "X" );
83   myYLabel = TCollection_AsciiString( "Y" );
84 }
85
86 //=======================================================================
87 //function : Component
88 //purpose  : 
89 //=======================================================================
90
91  Handle(Geom_Plane) AIS_PlaneTrihedron::Component()
92 {
93   return myPlane;
94 }
95
96
97 //=======================================================================
98 //function : SetComponent
99 //purpose  : 
100 //=======================================================================
101
102  void AIS_PlaneTrihedron::SetComponent(const Handle(Geom_Plane)& aPlane)
103 {
104   myPlane = aPlane;
105 }
106
107 //=======================================================================
108 //function : XAxis
109 //purpose  : 
110 //=======================================================================
111 Handle(AIS_Line) AIS_PlaneTrihedron::XAxis() const 
112 {
113   Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().XAxis());
114   Handle(AIS_Line) aLine = new AIS_Line (aGLine);
115   aLine->SetColor(Quantity_NOC_ROYALBLUE1);
116   return aLine;
117 }
118
119 //=======================================================================
120 //function : YAxis
121 //purpose  : 
122 //=======================================================================
123 Handle(AIS_Line) AIS_PlaneTrihedron::YAxis() const 
124 {
125   Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().YAxis());
126   Handle(AIS_Line) aLine = new AIS_Line (aGLine);
127   aLine->SetColor(Quantity_NOC_ROYALBLUE1);
128   return aLine;
129 }
130
131 //=======================================================================
132 //function : Position
133 //purpose  : 
134 //=======================================================================
135 Handle(AIS_Point) AIS_PlaneTrihedron::Position() const 
136 {
137   gp_Pnt aPnt = myPlane->Pln().Location();
138   Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
139   Handle(AIS_Point) aPt = new AIS_Point (aPoint);
140   return aPt;
141 }
142
143 void AIS_PlaneTrihedron::SetLength(const Standard_Real theLength) {
144   myDrawer->DatumAspect()->SetAxisLength(theLength, theLength, theLength);
145   SetToUpdate();
146 }
147
148 Standard_Real AIS_PlaneTrihedron::GetLength() const {
149   return myDrawer->DatumAspect()->FirstAxisLength();
150 }
151
152 //=======================================================================
153 //function : Compute
154 //purpose  : 
155 //=======================================================================
156 void AIS_PlaneTrihedron::Compute(const Handle(PrsMgr_PresentationManager3d)&,
157                                     const Handle(Prs3d_Presentation)& aPresentation, 
158                                     const Standard_Integer)
159 {
160   aPresentation->Clear();
161   aPresentation->SetDisplayPriority(5);
162   // drawing axis in X direction
163   gp_Pnt first, last;
164   Standard_Real value = myDrawer->DatumAspect()->FirstAxisLength();
165   gp_Dir xDir = myPlane->Position().Ax2().XDirection();
166
167   gp_Pnt orig = myPlane->Position().Ax2().Location();
168   Quantity_Length xo,yo,zo,x,y,z;
169   orig.Coord( xo, yo, zo );
170   xDir.Coord( x, y, z );
171   first.SetCoord( xo, yo, zo );
172   last.SetCoord( xo + x * value, yo + y * value, zo + z * value );
173   
174   DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->FirstAxisAspect(), myDrawer->ArrowAspect(), myDrawer->TextAspect(), xDir, value, myXLabel.ToCString(), first, last );
175   
176   // drawing axis in Y direction
177   value = myDrawer->DatumAspect()->SecondAxisLength();
178   gp_Dir yDir = myPlane->Position().Ax2().YDirection();
179
180   yDir.Coord( x, y, z );
181   last.SetCoord( xo + x * value, yo + y * value, zo + z * value );
182   DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->FirstAxisAspect(), myDrawer->ArrowAspect(), myDrawer->TextAspect(), yDir, value, myYLabel.ToCString(), first, last );
183
184   aPresentation->SetInfiniteState (Standard_True);
185 }
186
187 void AIS_PlaneTrihedron::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
188 {
189 // Standard_NotImplemented::Raise("AIS_PlaneTrihedron::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
190  PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
191 }
192
193 //=======================================================================
194 //function : ComputeSelection
195 //purpose  : 
196 //=======================================================================
197
198 void AIS_PlaneTrihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
199                                              const Standard_Integer aMode)
200 {
201   Standard_Integer Prior;
202   Handle(SelectMgr_EntityOwner) eown;
203   TColgp_Array1OfPnt PP(1,4),PO(1,4);
204 //  ExtremityPoints(PP);
205   ExtremityPoints(PP,myPlane,myDrawer);
206   switch (aMode) {
207   case 0:
208     {   // triedre complet
209       Prior = 5;
210 //      gp_Ax2 theax = gp_Ax2(myPlane->Position().Ax2());
211 //      gp_Pnt p1 = theax.Location();
212       
213       eown = new SelectMgr_EntityOwner(this,Prior);
214       for (Standard_Integer i=1; i<=2;i++)
215         aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
216       
217       break;
218     }
219   case 1:
220     {  //origine
221       Prior = 8;
222       const Handle(SelectMgr_SelectableObject)& anObj = myShapes[0]; // to avoid ambiguity
223       eown= new SelectMgr_EntityOwner(anObj,Prior);
224       aSelection->Add(new Select3D_SensitivePoint(eown,myPlane->Location()));
225
226       break;
227     }
228   case 2:
229     { //axes ... priorite 7
230       Prior = 7;
231       for (Standard_Integer i=1; i<=2;i++){
232         const Handle(SelectMgr_SelectableObject)& anObj = myShapes[i]; // to avoid ambiguity
233         eown= new SelectMgr_EntityOwner(anObj,Prior);
234         aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
235
236       }
237       break;
238     }
239   case -1:
240     {
241       Prior = 5;
242       aSelection->Clear();
243       break;
244     }
245   }
246 }
247
248 void AIS_PlaneTrihedron::SetColor(const Quantity_NameOfColor aCol)
249 {
250   SetColor(Quantity_Color(aCol));
251 }
252
253 void AIS_PlaneTrihedron::SetColor(const Quantity_Color &aCol)
254 {
255   hasOwnColor=Standard_True;
256   myOwnColor = aCol;
257   myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
258   myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
259 }
260
261
262 void AIS_PlaneTrihedron::Compute(const Handle(Prs3d_Projector)&, 
263                                const Handle(Prs3d_Presentation)&)
264 {
265 }
266
267
268 //=======================================================================
269 //function : ExtremityPoints
270 //purpose  : to avoid warning
271 //=======================================================================
272 //void  AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const 
273 void  ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer )
274 {
275 //  gp_Ax2 theax(myPlane->Ax2());
276   gp_Ax2 theax(myPlane->Position().Ax2());
277   PP(1) = theax.Location();
278
279   Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
280   gp_Vec vec = theax.XDirection();
281   vec *= len;
282   PP(2) = PP(1).Translated(vec);
283   
284   len = myDrawer->DatumAspect()->SecondAxisLength();
285   vec = theax.YDirection();
286   vec *= len;
287   PP(3) = PP(1).Translated(vec);
288
289 }
290
291 //=======================================================================
292 //function : AcceptDisplayMode
293 //purpose  : 
294 //=======================================================================
295 Standard_Boolean  AIS_PlaneTrihedron::AcceptDisplayMode(const Standard_Integer aMode) const
296 {return aMode == 0;}
297