0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / AIS / AIS_Axis.cxx
1 // Created on: 1995-08-09
2 // Created by: Arnaud BOUZY/Odile Olivier
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 //GER61351              //GG_171199     Enable to set an object RGB color instead a restricted object NameOfColor.
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>
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 //=======================================================================
45 AIS_Axis::AIS_Axis(const Handle(Geom_Line)& aComponent):
46 myComponent(aComponent),
47 myTypeOfAxis(AIS_TOAX_Unknown),
48 myIsXYZAxis(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 //=======================================================================
66 AIS_Axis::AIS_Axis(const Handle(Geom_Axis2Placement)& aComponent,
67                    const AIS_TypeOfAxis anAxisType):
68 myAx2(aComponent),
69 myTypeOfAxis(anAxisType),
70 myIsXYZAxis(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 //=======================================================================
94 AIS_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
116 void 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
138 void 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
152 void 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 //=======================================================================
161 void 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);
173     StdPrs_Curve::Add(aPresentation,curv,myDrawer);
174   }
175   else {
176     DsgPrs_XYZAxisPresentation::Add(aPresentation,myLineAspect,myDir,myVal,myText,myPfirst,myPlast);
177   }
178
179 }
180
181 void 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
192 void 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
209 void AIS_Axis::SetColor(const Quantity_NameOfColor aCol)
210 {
211   SetColor(Quantity_Color(aCol));
212 }
213
214 void AIS_Axis::SetColor(const Quantity_Color &aCol)
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 //=======================================================================
231 void 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 //=======================================================================
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();
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();
269     Quantity_Length xo,yo,zo,x = 0.,y = 0.,z = 0.;
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);
277         myVal = DA->FirstAxisLength();
278         myDir = oX;
279         myLineAspect = DA->FirstAxisAspect();
280         myText = Standard_CString ("X");
281         break;
282       }
283     case AIS_TOAX_YAxis:
284       {
285         oY.Coord(x,y,z);
286         myVal = DA->SecondAxisLength();
287         myDir = oY;
288         myLineAspect = DA->SecondAxisAspect();
289         myText = Standard_CString ("Y");
290         break;
291       }
292     case AIS_TOAX_ZAxis:
293       {
294         oZ.Coord(x,y,z); 
295         myVal = DA->ThirdAxisLength();
296         myDir = oZ;
297         myLineAspect = DA->ThirdAxisAspect();
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 {
327   
328   myDrawer->LineAspect()->SetColor(Quantity_NOC_RED);
329
330   hasOwnColor=Standard_False;
331
332   myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
333   myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
334   myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
335 }
336 //=======================================================================
337 //function : UnsetWidth
338 //purpose  : 
339 //=======================================================================
340
341 void AIS_Axis::UnsetWidth()
342 {
343   myOwnWidth = 0.0;
344   myDrawer->LineAspect()->SetWidth(1.);
345   myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
346   myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
347   myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);
348 }
349