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