0024624: Lost word in license statement in source 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
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
b8ddfc2f 17//GER61351 //GG_171199 Enable to set an object RGB color instead a restricted object NameOfColor.
7fd59977 18
19#define OCC218 //SAV using DsgPrs_XYZAxisPresentation to draw axes.
b311480e 20// + X/YAxis() returns AIS_Line instead of AIS_Axis
21// + (-1) selection mode token into account
22// (SAMTECH specific)
7fd59977 23
24#ifdef OCC218
25#include <DsgPrs_XYZAxisPresentation.hxx>
26#include <AIS_Line.hxx>
27#include <Geom_Line.hxx>
28#endif
29
30#include <AIS_PlaneTrihedron.ixx>
31
32#include <DsgPrs_DatumPrs.hxx>
33#include <SelectMgr_EntityOwner.hxx>
34#include <Select3D_SensitiveSegment.hxx>
35#include <Select3D_SensitivePoint.hxx>
36#include <Geom_Axis1Placement.hxx>
37#include <Geom_Axis2Placement.hxx>
38#include <Geom_CartesianPoint.hxx>
39#include <gp_Ax2.hxx>
40#include <gp_Pln.hxx>
41#include <gp_Pnt.hxx>
42#include <gp_Vec.hxx>
43#include <Prs3d_Drawer.hxx>
44#include <Prs3d_LineAspect.hxx>
45#include <Prs3d_DatumAspect.hxx>
46#include <Graphic3d_AspectLine3d.hxx>
47#include <Graphic3d_Structure.hxx>
48#include <Graphic3d_MaterialAspect.hxx>
49#include <Graphic3d_AspectFillArea3d.hxx>
50#include <Aspect_TypeOfLine.hxx>
51#include <AIS_Drawer.hxx>
52#include <UnitsAPI.hxx>
53#include <TColgp_Array1OfPnt.hxx>
54
55#include <Select3D_SensitiveFace.hxx>
56
57#define OCC10
58
59void ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer);
60
61//=======================================================================
62//function : AIS_PlaneTrihedron
63//purpose :
64//=======================================================================
65AIS_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);
81bba717 77 myDrawer->SetDatumAspect(DA); // odl - specific is created because it is modified
7fd59977 78 myShapes[0] = Position();
79 myShapes[1] = XAxis();
80 myShapes[2] = YAxis();
81
82#ifdef OCC218
83 myXLabel = TCollection_AsciiString( "X" );
84 myYLabel = TCollection_AsciiString( "Y" );
85#endif
86}
87
88//=======================================================================
89//function : Component
90//purpose :
91//=======================================================================
92
93 Handle(Geom_Plane) AIS_PlaneTrihedron::Component()
94{
95 return myPlane;
96}
97
98
99//=======================================================================
100//function : SetComponent
101//purpose :
102//=======================================================================
103
104 void AIS_PlaneTrihedron::SetComponent(const Handle(Geom_Plane)& aPlane)
105{
106 myPlane = aPlane;
107}
108
109//=======================================================================
110//function : XAxis
111//purpose :
112//=======================================================================
113#ifdef OCC218
114Handle(AIS_Line) AIS_PlaneTrihedron::XAxis() const
115{
116 Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().XAxis());
117 Handle(AIS_Line) aLine = new AIS_Line (aGLine);
118 aLine->SetColor(Quantity_NOC_ROYALBLUE1);
119 return aLine;
120}
121#else
122Handle(AIS_Axis) AIS_PlaneTrihedron::XAxis() const
123{
124 Handle(Geom_Axis1Placement) anAx1 = new Geom_Axis1Placement(myPlane->Pln().XAxis());
125 Handle(AIS_Axis) anAxis = new AIS_Axis (anAx1);
126 anAxis->SetTypeOfAxis(AIS_TOAX_XAxis);
127 return anAxis;
128}
129#endif
130
131//=======================================================================
132//function : YAxis
133//purpose :
134//=======================================================================
135#ifdef OCC218
136Handle(AIS_Line) AIS_PlaneTrihedron::YAxis() const
137{
138 Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().YAxis());
139 Handle(AIS_Line) aLine = new AIS_Line (aGLine);
140 aLine->SetColor(Quantity_NOC_ROYALBLUE1);
141 return aLine;
142}
143#else
144Handle(AIS_Axis) AIS_PlaneTrihedron::YAxis() const
145{
146 Handle(Geom_Axis1Placement) anAx1 = new Geom_Axis1Placement(myPlane->Pln().YAxis());
147 Handle(AIS_Axis) anAxis = new AIS_Axis (anAx1);
148 anAxis->SetTypeOfAxis(AIS_TOAX_YAxis);
149 return anAxis;
150}
151#endif
152
153//=======================================================================
154//function : Position
155//purpose :
156//=======================================================================
157Handle(AIS_Point) AIS_PlaneTrihedron::Position() const
158{
159 gp_Pnt aPnt = myPlane->Pln().Location();
160 Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
161 Handle(AIS_Point) aPt = new AIS_Point (aPoint);
162 return aPt;
163}
164
165#ifdef OCC10
166void AIS_PlaneTrihedron::SetLength(const Standard_Real theLength) {
167 myDrawer->DatumAspect()->SetAxisLength(theLength, theLength, theLength);
168 SetToUpdate();
169}
170
171Standard_Real AIS_PlaneTrihedron::GetLength() const {
172 return myDrawer->DatumAspect()->FirstAxisLength();
173}
174#endif
175
176//=======================================================================
177//function : Compute
178//purpose :
179//=======================================================================
180void AIS_PlaneTrihedron::Compute(const Handle(PrsMgr_PresentationManager3d)&,
181 const Handle(Prs3d_Presentation)& aPresentation,
182 const Standard_Integer)
183{
184 aPresentation->Clear();
185 aPresentation->SetDisplayPriority(5);
186#ifndef OCC218
187 DsgPrs_DatumPrs::Add(aPresentation,myPlane->Position().Ax2(),myDrawer);
188#else
189 // drawing axis in X direction
190 gp_Pnt first, last;
191 Standard_Real value = myDrawer->DatumAspect()->FirstAxisLength();
192 gp_Dir xDir = myPlane->Position().Ax2().XDirection();
193
194 gp_Pnt orig = myPlane->Position().Ax2().Location();
195 Quantity_Length xo,yo,zo,x,y,z;
196 orig.Coord( xo, yo, zo );
197 xDir.Coord( x, y, z );
198 first.SetCoord( xo, yo, zo );
199 last.SetCoord( xo + x * value, yo + y * value, zo + z * value );
200
201 DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->FirstAxisAspect(), myDrawer->ArrowAspect(), myDrawer->TextAspect(), xDir, value, myXLabel.ToCString(), first, last );
202
203 // drawing axis in Y direction
204 value = myDrawer->DatumAspect()->SecondAxisLength();
205 gp_Dir yDir = myPlane->Position().Ax2().YDirection();
206
207 yDir.Coord( x, y, z );
208 last.SetCoord( xo + x * value, yo + y * value, zo + z * value );
209 DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->FirstAxisAspect(), myDrawer->ArrowAspect(), myDrawer->TextAspect(), yDir, value, myYLabel.ToCString(), first, last );
210
211#endif
212 aPresentation->SetInfiniteState (Standard_True);
213}
214
215void AIS_PlaneTrihedron::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
216{
217// Standard_NotImplemented::Raise("AIS_PlaneTrihedron::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
218 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
219}
220
221//=======================================================================
222//function : ComputeSelection
223//purpose :
224//=======================================================================
225
226void AIS_PlaneTrihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
227 const Standard_Integer aMode)
228{
229 Standard_Integer Prior;
230 Handle(SelectMgr_EntityOwner) eown;
231 TColgp_Array1OfPnt PP(1,4),PO(1,4);
232// ExtremityPoints(PP);
233 ExtremityPoints(PP,myPlane,myDrawer);
234 switch (aMode) {
235 case 0:
236 { // triedre complet
237 Prior = 5;
238// gp_Ax2 theax = gp_Ax2(myPlane->Position().Ax2());
239// gp_Pnt p1 = theax.Location();
240
241 eown = new SelectMgr_EntityOwner(this,Prior);
242 for (Standard_Integer i=1; i<=2;i++)
243 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
244
245 break;
246 }
247 case 1:
248 { //origine
249 Prior = 8;
250 eown= new SelectMgr_EntityOwner(myShapes[0],Prior);
251 aSelection->Add(new Select3D_SensitivePoint(eown,myPlane->Location()));
252
253 break;
254 }
255 case 2:
256 { //axes ... priorite 7
257 Prior = 7;
258 for (Standard_Integer i=1; i<=2;i++){
259 eown= new SelectMgr_EntityOwner(myShapes[i],Prior);
260 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
261
262 }
263 break;
264 }
265#ifdef OCC218
266 case -1:
267 {
268 Prior = 5;
269 aSelection->Clear();
270 break;
271 }
272#endif
273 }
274}
275
276void AIS_PlaneTrihedron::SetColor(const Quantity_NameOfColor aCol)
7fd59977 277{
278 SetColor(Quantity_Color(aCol));
279}
280
281void AIS_PlaneTrihedron::SetColor(const Quantity_Color &aCol)
7fd59977 282{
283 hasOwnColor=Standard_True;
284 myOwnColor = aCol;
285 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
286 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
287}
288
7fd59977 289
290void AIS_PlaneTrihedron::Compute(const Handle(Prs3d_Projector)&,
291 const Handle(Prs3d_Presentation)&)
292{
293}
294
295
296//=======================================================================
297//function : ExtremityPoints
298//purpose : to avoid warning
299//=======================================================================
300//void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const
301void ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer )
302{
303// gp_Ax2 theax(myPlane->Ax2());
304 gp_Ax2 theax(myPlane->Position().Ax2());
305 PP(1) = theax.Location();
306
307 Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
308 gp_Vec vec = theax.XDirection();
309 vec *= len;
310 PP(2) = PP(1).Translated(vec);
311
312 len = myDrawer->DatumAspect()->SecondAxisLength();
313 vec = theax.YDirection();
314 vec *= len;
315 PP(3) = PP(1).Translated(vec);
316
317}
318
319//=======================================================================
320//function : AcceptDisplayMode
321//purpose :
322//=======================================================================
323Standard_Boolean AIS_PlaneTrihedron::AcceptDisplayMode(const Standard_Integer aMode) const
324{return aMode == 0;}
325