0023024: Update headers of OCCT files
[occt.git] / src / AIS / AIS_PlaneTrihedron.cxx
CommitLineData
b311480e 1// Created on: 1996-12-13
2// Created by: Jean-Pierre COMBE
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22#define GER61351 //GG_171199 Enable to set an object RGB color
23// instead a restricted object NameOfColor.
24
25#define OCC218 //SAV using DsgPrs_XYZAxisPresentation to draw axes.
b311480e 26// + X/YAxis() returns AIS_Line instead of AIS_Axis
27// + (-1) selection mode token into account
28// (SAMTECH specific)
7fd59977 29
30#ifdef OCC218
31#include <DsgPrs_XYZAxisPresentation.hxx>
32#include <AIS_Line.hxx>
33#include <Geom_Line.hxx>
34#endif
35
36#include <AIS_PlaneTrihedron.ixx>
37
38#include <DsgPrs_DatumPrs.hxx>
39#include <SelectMgr_EntityOwner.hxx>
40#include <Select3D_SensitiveSegment.hxx>
41#include <Select3D_SensitivePoint.hxx>
42#include <Geom_Axis1Placement.hxx>
43#include <Geom_Axis2Placement.hxx>
44#include <Geom_CartesianPoint.hxx>
45#include <gp_Ax2.hxx>
46#include <gp_Pln.hxx>
47#include <gp_Pnt.hxx>
48#include <gp_Vec.hxx>
49#include <Prs3d_Drawer.hxx>
50#include <Prs3d_LineAspect.hxx>
51#include <Prs3d_DatumAspect.hxx>
52#include <Graphic3d_AspectLine3d.hxx>
53#include <Graphic3d_Structure.hxx>
54#include <Graphic3d_MaterialAspect.hxx>
55#include <Graphic3d_AspectFillArea3d.hxx>
56#include <Aspect_TypeOfLine.hxx>
57#include <AIS_Drawer.hxx>
58#include <UnitsAPI.hxx>
59#include <TColgp_Array1OfPnt.hxx>
60
61#include <Select3D_SensitiveFace.hxx>
62
63#define OCC10
64
65void ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer);
66
67//=======================================================================
68//function : AIS_PlaneTrihedron
69//purpose :
70//=======================================================================
71AIS_PlaneTrihedron::AIS_PlaneTrihedron(const Handle(Geom_Plane)& aPlane)
72:myPlane(aPlane)
73{
74 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
75//POP Standard_Real aLength = UnitsAPI::CurrentFromLS (100. ,"LENGTH");
76 Standard_Real aLength = UnitsAPI::AnyToLS (100. ,"mm");
77 DA->SetAxisLength(aLength,aLength,aLength);
78 Quantity_NameOfColor col = Quantity_NOC_ROYALBLUE1;
79 DA->FirstAxisAspect()->SetColor(col);
80 DA->SecondAxisAspect()->SetColor(col);
81 DA->SetDrawFirstAndSecondAxis(Standard_True);
82 DA->SetDrawThirdAxis(Standard_False);
81bba717 83 myDrawer->SetDatumAspect(DA); // odl - specific is created because it is modified
7fd59977 84 myShapes[0] = Position();
85 myShapes[1] = XAxis();
86 myShapes[2] = YAxis();
87
88#ifdef OCC218
89 myXLabel = TCollection_AsciiString( "X" );
90 myYLabel = TCollection_AsciiString( "Y" );
91#endif
92}
93
94//=======================================================================
95//function : Component
96//purpose :
97//=======================================================================
98
99 Handle(Geom_Plane) AIS_PlaneTrihedron::Component()
100{
101 return myPlane;
102}
103
104
105//=======================================================================
106//function : SetComponent
107//purpose :
108//=======================================================================
109
110 void AIS_PlaneTrihedron::SetComponent(const Handle(Geom_Plane)& aPlane)
111{
112 myPlane = aPlane;
113}
114
115//=======================================================================
116//function : XAxis
117//purpose :
118//=======================================================================
119#ifdef OCC218
120Handle(AIS_Line) AIS_PlaneTrihedron::XAxis() const
121{
122 Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().XAxis());
123 Handle(AIS_Line) aLine = new AIS_Line (aGLine);
124 aLine->SetColor(Quantity_NOC_ROYALBLUE1);
125 return aLine;
126}
127#else
128Handle(AIS_Axis) AIS_PlaneTrihedron::XAxis() const
129{
130 Handle(Geom_Axis1Placement) anAx1 = new Geom_Axis1Placement(myPlane->Pln().XAxis());
131 Handle(AIS_Axis) anAxis = new AIS_Axis (anAx1);
132 anAxis->SetTypeOfAxis(AIS_TOAX_XAxis);
133 return anAxis;
134}
135#endif
136
137//=======================================================================
138//function : YAxis
139//purpose :
140//=======================================================================
141#ifdef OCC218
142Handle(AIS_Line) AIS_PlaneTrihedron::YAxis() const
143{
144 Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().YAxis());
145 Handle(AIS_Line) aLine = new AIS_Line (aGLine);
146 aLine->SetColor(Quantity_NOC_ROYALBLUE1);
147 return aLine;
148}
149#else
150Handle(AIS_Axis) AIS_PlaneTrihedron::YAxis() const
151{
152 Handle(Geom_Axis1Placement) anAx1 = new Geom_Axis1Placement(myPlane->Pln().YAxis());
153 Handle(AIS_Axis) anAxis = new AIS_Axis (anAx1);
154 anAxis->SetTypeOfAxis(AIS_TOAX_YAxis);
155 return anAxis;
156}
157#endif
158
159//=======================================================================
160//function : Position
161//purpose :
162//=======================================================================
163Handle(AIS_Point) AIS_PlaneTrihedron::Position() const
164{
165 gp_Pnt aPnt = myPlane->Pln().Location();
166 Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
167 Handle(AIS_Point) aPt = new AIS_Point (aPoint);
168 return aPt;
169}
170
171#ifdef OCC10
172void AIS_PlaneTrihedron::SetLength(const Standard_Real theLength) {
173 myDrawer->DatumAspect()->SetAxisLength(theLength, theLength, theLength);
174 SetToUpdate();
175}
176
177Standard_Real AIS_PlaneTrihedron::GetLength() const {
178 return myDrawer->DatumAspect()->FirstAxisLength();
179}
180#endif
181
182//=======================================================================
183//function : Compute
184//purpose :
185//=======================================================================
186void AIS_PlaneTrihedron::Compute(const Handle(PrsMgr_PresentationManager3d)&,
187 const Handle(Prs3d_Presentation)& aPresentation,
188 const Standard_Integer)
189{
190 aPresentation->Clear();
191 aPresentation->SetDisplayPriority(5);
192#ifndef OCC218
193 DsgPrs_DatumPrs::Add(aPresentation,myPlane->Position().Ax2(),myDrawer);
194#else
195 // drawing axis in X direction
196 gp_Pnt first, last;
197 Standard_Real value = myDrawer->DatumAspect()->FirstAxisLength();
198 gp_Dir xDir = myPlane->Position().Ax2().XDirection();
199
200 gp_Pnt orig = myPlane->Position().Ax2().Location();
201 Quantity_Length xo,yo,zo,x,y,z;
202 orig.Coord( xo, yo, zo );
203 xDir.Coord( x, y, z );
204 first.SetCoord( xo, yo, zo );
205 last.SetCoord( xo + x * value, yo + y * value, zo + z * value );
206
207 DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->FirstAxisAspect(), myDrawer->ArrowAspect(), myDrawer->TextAspect(), xDir, value, myXLabel.ToCString(), first, last );
208
209 // drawing axis in Y direction
210 value = myDrawer->DatumAspect()->SecondAxisLength();
211 gp_Dir yDir = myPlane->Position().Ax2().YDirection();
212
213 yDir.Coord( x, y, z );
214 last.SetCoord( xo + x * value, yo + y * value, zo + z * value );
215 DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->FirstAxisAspect(), myDrawer->ArrowAspect(), myDrawer->TextAspect(), yDir, value, myYLabel.ToCString(), first, last );
216
217#endif
218 aPresentation->SetInfiniteState (Standard_True);
219}
220
221void AIS_PlaneTrihedron::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
222{
223// Standard_NotImplemented::Raise("AIS_PlaneTrihedron::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
224 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
225}
226
227//=======================================================================
228//function : ComputeSelection
229//purpose :
230//=======================================================================
231
232void AIS_PlaneTrihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
233 const Standard_Integer aMode)
234{
235 Standard_Integer Prior;
236 Handle(SelectMgr_EntityOwner) eown;
237 TColgp_Array1OfPnt PP(1,4),PO(1,4);
238// ExtremityPoints(PP);
239 ExtremityPoints(PP,myPlane,myDrawer);
240 switch (aMode) {
241 case 0:
242 { // triedre complet
243 Prior = 5;
244// gp_Ax2 theax = gp_Ax2(myPlane->Position().Ax2());
245// gp_Pnt p1 = theax.Location();
246
247 eown = new SelectMgr_EntityOwner(this,Prior);
248 for (Standard_Integer i=1; i<=2;i++)
249 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
250
251 break;
252 }
253 case 1:
254 { //origine
255 Prior = 8;
256 eown= new SelectMgr_EntityOwner(myShapes[0],Prior);
257 aSelection->Add(new Select3D_SensitivePoint(eown,myPlane->Location()));
258
259 break;
260 }
261 case 2:
262 { //axes ... priorite 7
263 Prior = 7;
264 for (Standard_Integer i=1; i<=2;i++){
265 eown= new SelectMgr_EntityOwner(myShapes[i],Prior);
266 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
267
268 }
269 break;
270 }
271#ifdef OCC218
272 case -1:
273 {
274 Prior = 5;
275 aSelection->Clear();
276 break;
277 }
278#endif
279 }
280}
281
282void AIS_PlaneTrihedron::SetColor(const Quantity_NameOfColor aCol)
283#ifdef GER61351
284{
285 SetColor(Quantity_Color(aCol));
286}
287
288void AIS_PlaneTrihedron::SetColor(const Quantity_Color &aCol)
289#endif
290{
291 hasOwnColor=Standard_True;
292 myOwnColor = aCol;
293 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
294 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
295}
296
297//=======================================================================
298//function : Compute
299//purpose : to avoid warning
300//=======================================================================
301void AIS_PlaneTrihedron::Compute(const Handle(PrsMgr_PresentationManager2d)&,
302 const Handle(Graphic2d_GraphicObject)&,
303 const Standard_Integer)
304{
305}
306
307void AIS_PlaneTrihedron::Compute(const Handle(Prs3d_Projector)&,
308 const Handle(Prs3d_Presentation)&)
309{
310}
311
312
313//=======================================================================
314//function : ExtremityPoints
315//purpose : to avoid warning
316//=======================================================================
317//void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const
318void ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer )
319{
320// gp_Ax2 theax(myPlane->Ax2());
321 gp_Ax2 theax(myPlane->Position().Ax2());
322 PP(1) = theax.Location();
323
324 Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
325 gp_Vec vec = theax.XDirection();
326 vec *= len;
327 PP(2) = PP(1).Translated(vec);
328
329 len = myDrawer->DatumAspect()->SecondAxisLength();
330 vec = theax.YDirection();
331 vec *= len;
332 PP(3) = PP(1).Translated(vec);
333
334}
335
336//=======================================================================
337//function : AcceptDisplayMode
338//purpose :
339//=======================================================================
340Standard_Boolean AIS_PlaneTrihedron::AcceptDisplayMode(const Standard_Integer aMode) const
341{return aMode == 0;}
342