0024428: Implementation of LGPL license
[occt.git] / src / AIS / AIS_Axis.cxx
CommitLineData
b311480e 1// Created on: 1995-08-09
2// Created by: Arnaud BOUZY/Odile Olivier
3// Copyright (c) 1995-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//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public 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.
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#include <AIS_Axis.ixx>
20#include <Aspect_TypeOfLine.hxx>
21#include <Prs3d_Drawer.hxx>
22#include <Prs3d_LineAspect.hxx>
23#include <Prs3d_DatumAspect.hxx>
7fd59977 24#include <Graphic3d_AspectLine3d.hxx>
25#include <Graphic3d_Structure.hxx>
26#include <TColgp_Array1OfPnt.hxx>
27#include <SelectMgr_EntityOwner.hxx>
28#include <SelectBasics_EntityOwner.hxx>
29#include <Select3D_SensitiveSegment.hxx>
30#include <StdPrs_Curve.hxx>
31#include <TopoDS.hxx>
32#include <Geom_Axis1Placement.hxx>
33#include <gp_Ax1.hxx>
34#include <gp_Ax2.hxx>
35#include <Geom_Line.hxx>
36#include <GeomAdaptor_Curve.hxx>
37#include <AIS_Drawer.hxx>
38#include <DsgPrs_XYZAxisPresentation.hxx>
39#include <UnitsAPI.hxx>
40
41//=======================================================================
42//function : AIS_Axis
43//purpose :
44//=======================================================================
45AIS_Axis::AIS_Axis(const Handle(Geom_Line)& aComponent):
46myComponent(aComponent),
47myTypeOfAxis(AIS_TOAX_Unknown),
48myIsXYZAxis(Standard_False)
49{
50 myDrawer->SetLineAspect(new Prs3d_LineAspect
51 (Quantity_NOC_RED,Aspect_TOL_DOTDASH,1.));
52 SetInfiniteState();
53
54 gp_Dir thedir = myComponent->Position().Direction();
55 gp_Pnt loc = myComponent->Position().Location();
56//POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
57 Standard_Real aLength = UnitsAPI::AnyToLS(250000., "mm");
58 myPfirst = loc.XYZ() + aLength*thedir.XYZ();
59 myPlast = loc.XYZ() - aLength*thedir.XYZ();
60}
61
62//=======================================================================
63//function : AIS_Axis
64//purpose : Xaxis, YAxis, ZAxis
65//=======================================================================
66AIS_Axis::AIS_Axis(const Handle(Geom_Axis2Placement)& aComponent,
67 const AIS_TypeOfAxis anAxisType):
68myAx2(aComponent),
69myTypeOfAxis(anAxisType),
70myIsXYZAxis(Standard_True)
71{
72 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
73//POP Standard_Real aLength = UnitsAPI::CurrentToLS (100. ,"LENGTH");
74 Standard_Real aLength;
75 try {
76 aLength = UnitsAPI::AnyToLS(100. ,"mm");
77 } catch (Standard_Failure) {
78 aLength = 0.1;
79 }
80 DA->SetAxisLength(aLength,aLength,aLength);
81 Quantity_NameOfColor col = Quantity_NOC_TURQUOISE;
82 DA->FirstAxisAspect()->SetColor(col);
83 DA->SecondAxisAspect()->SetColor(col);
84 DA->ThirdAxisAspect()->SetColor(col);
85 myDrawer->SetDatumAspect(DA);
86
87 ComputeFields();
88}
89
90//=======================================================================
91//function : AIS_Axis
92//purpose :
93//=======================================================================
94AIS_Axis::AIS_Axis(const Handle(Geom_Axis1Placement)& anAxis)
95:myComponent(new Geom_Line(anAxis->Ax1())),
96 myTypeOfAxis(AIS_TOAX_Unknown),
97 myIsXYZAxis(Standard_False)
98{
99 myDrawer->SetLineAspect(new Prs3d_LineAspect(Quantity_NOC_RED,Aspect_TOL_DOTDASH,1.));
100 SetInfiniteState();
101
102 gp_Dir thedir = myComponent->Position().Direction();
103 gp_Pnt loc = myComponent->Position().Location();
104//POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
105 Standard_Real aLength = UnitsAPI::AnyToLS(250000. ,"mm");
106 myPfirst = loc.XYZ() + aLength*thedir.XYZ();
107 myPlast = loc.XYZ() - aLength*thedir.XYZ();
108}
109
110
111//=======================================================================
112//function : SetComponent
113//purpose :
114//=======================================================================
115
116void AIS_Axis::SetComponent(const Handle(Geom_Line)& aComponent)
117{
118 myComponent = aComponent;
119 myTypeOfAxis = AIS_TOAX_Unknown;
120 myIsXYZAxis = Standard_False;
121 SetInfiniteState();
122
123 gp_Dir thedir = myComponent->Position().Direction();
124 gp_Pnt loc = myComponent->Position().Location();
125//POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
126 Standard_Real aLength = UnitsAPI::AnyToLS(250000. ,"mm");
127 myPfirst = loc.XYZ() + aLength*thedir.XYZ();
128 myPlast = loc.XYZ() - aLength*thedir.XYZ();
129}
130
131
132
133//=======================================================================
134//function : SetAxis2Placement
135//purpose :
136//=======================================================================
137
138void AIS_Axis::SetAxis2Placement(const Handle(Geom_Axis2Placement)& aComponent,
139 const AIS_TypeOfAxis anAxisType)
140{
141 myAx2 = aComponent;
142 myTypeOfAxis = anAxisType;
143 myIsXYZAxis = Standard_True;
144 ComputeFields();
145}
146
147//=======================================================================
148//function : SetAxis1Placement
149//purpose :
150//=======================================================================
151
152void AIS_Axis::SetAxis1Placement(const Handle(Geom_Axis1Placement)& anAxis)
153{
154 SetComponent(new Geom_Line(anAxis->Ax1()));
155}
156
157//=======================================================================
158//function : Compute
159//purpose :
160//=======================================================================
161void AIS_Axis::Compute(const Handle(PrsMgr_PresentationManager3d)&,
162 const Handle(Prs3d_Presentation)& aPresentation,
163 const Standard_Integer)
164{
165 aPresentation->Clear();
166
167 //Pro.... : pas de prise en compte des axes lors du FITALL (jmi)
168 aPresentation->SetInfiniteState (myInfiniteState);
169
170 aPresentation->SetDisplayPriority(5);
171 if (!myIsXYZAxis ){
172 GeomAdaptor_Curve curv(myComponent);
7fd59977 173 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
7fd59977 174 }
175 else {
176 DsgPrs_XYZAxisPresentation::Add(aPresentation,myLineAspect,myDir,myVal,myText,myPfirst,myPlast);
177 }
178
179}
180
181void AIS_Axis::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
182{
183// Standard_NotImplemented::Raise("AIS_Axis::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
184 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
185}
186
187//=======================================================================
188//function : ComputeSelection
189//purpose :
190//=======================================================================
191
192void AIS_Axis::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
193 const Standard_Integer)
194{
195 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
196 eown -> SelectBasics_EntityOwner::Set(3);
197 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
198 myPfirst,
199 myPlast);
200 aSelection->Add(seg);
201}
202
203//=======================================================================
204//function : SetColor
205//purpose :
206//=======================================================================
207
208
209void AIS_Axis::SetColor(const Quantity_NameOfColor aCol)
7fd59977 210{
211 SetColor(Quantity_Color(aCol));
212}
213
214void AIS_Axis::SetColor(const Quantity_Color &aCol)
7fd59977 215{
216 hasOwnColor=Standard_True;
217 myOwnColor=aCol;
218 myDrawer->LineAspect()->SetColor(aCol);
219
220 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
221 DA->FirstAxisAspect()->SetColor(aCol);
222 DA->SecondAxisAspect()->SetColor(aCol);
223 DA->ThirdAxisAspect()->SetColor(aCol);
224
225}
226
227//=======================================================================
228//function : SetWidth
229//purpose :
230//=======================================================================
231void AIS_Axis::SetWidth(const Standard_Real aValue)
232{
233
234 if(aValue<0.0) return;
235 if(aValue==0) UnsetWidth();
236
237 myDrawer->LineAspect()->SetWidth(aValue);
238
239 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
240 DA->FirstAxisAspect()->SetWidth(aValue);
241 DA->SecondAxisAspect()->SetWidth(aValue);
242 DA->ThirdAxisAspect()->SetWidth(aValue);
243}
244
245
246//=======================================================================
247//function : Compute
248//purpose : to avoid warning
249//=======================================================================
7fd59977 250void AIS_Axis::Compute(const Handle(Prs3d_Projector)&,
251 const Handle(Prs3d_Presentation)&)
252{
253}
254
255//=======================================================================
256//function : ComputeFields
257//purpose :
258//=======================================================================
259void AIS_Axis::ComputeFields()
260{
261 if (myIsXYZAxis){
262 // calcul de myPFirst,myPlast
263 Handle(Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
264 gp_Pnt Orig = myAx2->Ax2().Location();
265 gp_Dir oX = myAx2->Ax2().XDirection();
266 gp_Dir oY = myAx2->Ax2().YDirection();
267 gp_Dir oZ = myAx2->Ax2().Direction();
1d47d8d0 268 Quantity_Length xo,yo,zo,x = 0.,y = 0.,z = 0.;
7fd59977 269 Orig.Coord(xo,yo,zo);
270 myPfirst.SetCoord(xo,yo,zo);
271
272 switch (myTypeOfAxis) {
273 case AIS_TOAX_XAxis:
274 {
275 oX.Coord(x,y,z);
276 myVal = DA->FirstAxisLength();
277 myDir = oX;
278 myLineAspect = DA->FirstAxisAspect();
279 myText = Standard_CString ("X");
280 break;
281 }
282 case AIS_TOAX_YAxis:
283 {
284 oY.Coord(x,y,z);
285 myVal = DA->SecondAxisLength();
286 myDir = oY;
287 myLineAspect = DA->SecondAxisAspect();
288 myText = Standard_CString ("Y");
289 break;
290 }
291 case AIS_TOAX_ZAxis:
292 {
293 oZ.Coord(x,y,z);
294 myVal = DA->ThirdAxisLength();
295 myDir = oZ;
296 myLineAspect = DA->ThirdAxisAspect();
297 myText = Standard_CString ("Z");
298 break;
299 }
300 default:
301 break;
302 }
303
304 myComponent = new Geom_Line(Orig,myDir);
305 x = xo + x*myVal; y = yo + y*myVal; z = zo + z*myVal;
306 myPlast.SetCoord(x,y,z);
307 SetInfiniteState();
308 }
309}
310
311//=======================================================================
312//function : AcceptDisplayMode
313//purpose :
314//=======================================================================
315
316 Standard_Boolean AIS_Axis::
317AcceptDisplayMode(const Standard_Integer aMode) const
318{return aMode == 0;}
319
320//=======================================================================
321//function : UnsetColor
322//purpose :
323//=======================================================================
324void AIS_Axis::UnsetColor()
325{
326
327 myDrawer->LineAspect()->SetColor(Quantity_NOC_RED);
328
329 hasOwnColor=Standard_False;
330
331 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
332 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
333 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
334}
335//=======================================================================
336//function : UnsetWidth
337//purpose :
338//=======================================================================
339
340void AIS_Axis::UnsetWidth()
341{
342 myOwnWidth = 0.0;
343 myDrawer->LineAspect()->SetWidth(1.);
344 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
345 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
346 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);
347}
348