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