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