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