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