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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <AIS_Axis.hxx>
19 #include <Aspect_TypeOfLine.hxx>
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>
28 #include <Graphic3d_AspectLine3d.hxx>
29 #include <Graphic3d_Structure.hxx>
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>
38 #include <SelectMgr_EntityOwner.hxx>
39 #include <SelectMgr_Selection.hxx>
40 #include <Standard_Type.hxx>
41 #include <StdPrs_Curve.hxx>
42 #include <TColgp_Array1OfPnt.hxx>
44 #include <UnitsAPI.hxx>
46 //=======================================================================
49 //=======================================================================
50 AIS_Axis::AIS_Axis(const Handle(Geom_Line)& aComponent):
51 myComponent(aComponent),
52 myTypeOfAxis(AIS_TOAX_Unknown),
53 myIsXYZAxis(Standard_False)
55 myDrawer->SetLineAspect(new Prs3d_LineAspect
56 (Quantity_NOC_RED,Aspect_TOL_DOTDASH,1.));
59 gp_Dir thedir = myComponent->Position().Direction();
60 gp_Pnt loc = myComponent->Position().Location();
61 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
62 Standard_Real aLength = UnitsAPI::AnyToLS(250000., "mm");
63 myPfirst = loc.XYZ() + aLength*thedir.XYZ();
64 myPlast = loc.XYZ() - aLength*thedir.XYZ();
67 //=======================================================================
69 //purpose : Xaxis, YAxis, ZAxis
70 //=======================================================================
71 AIS_Axis::AIS_Axis(const Handle(Geom_Axis2Placement)& aComponent,
72 const AIS_TypeOfAxis anAxisType):
74 myTypeOfAxis(anAxisType),
75 myIsXYZAxis(Standard_True)
77 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
78 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (100. ,"LENGTH");
79 Standard_Real aLength;
81 aLength = UnitsAPI::AnyToLS(100. ,"mm");
82 } catch (Standard_Failure) {
85 DA->SetAxisLength(aLength,aLength,aLength);
86 Quantity_NameOfColor col = Quantity_NOC_TURQUOISE;
87 DA->FirstAxisAspect()->SetColor(col);
88 DA->SecondAxisAspect()->SetColor(col);
89 DA->ThirdAxisAspect()->SetColor(col);
90 myDrawer->SetDatumAspect(DA);
95 //=======================================================================
98 //=======================================================================
99 AIS_Axis::AIS_Axis(const Handle(Geom_Axis1Placement)& anAxis)
100 :myComponent(new Geom_Line(anAxis->Ax1())),
101 myTypeOfAxis(AIS_TOAX_Unknown),
102 myIsXYZAxis(Standard_False)
104 myDrawer->SetLineAspect(new Prs3d_LineAspect(Quantity_NOC_RED,Aspect_TOL_DOTDASH,1.));
107 gp_Dir thedir = myComponent->Position().Direction();
108 gp_Pnt loc = myComponent->Position().Location();
109 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
110 Standard_Real aLength = UnitsAPI::AnyToLS(250000. ,"mm");
111 myPfirst = loc.XYZ() + aLength*thedir.XYZ();
112 myPlast = loc.XYZ() - aLength*thedir.XYZ();
116 //=======================================================================
117 //function : SetComponent
119 //=======================================================================
121 void AIS_Axis::SetComponent(const Handle(Geom_Line)& aComponent)
123 myComponent = aComponent;
124 myTypeOfAxis = AIS_TOAX_Unknown;
125 myIsXYZAxis = Standard_False;
128 gp_Dir thedir = myComponent->Position().Direction();
129 gp_Pnt loc = myComponent->Position().Location();
130 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
131 Standard_Real aLength = UnitsAPI::AnyToLS(250000. ,"mm");
132 myPfirst = loc.XYZ() + aLength*thedir.XYZ();
133 myPlast = loc.XYZ() - aLength*thedir.XYZ();
138 //=======================================================================
139 //function : SetAxis2Placement
141 //=======================================================================
143 void AIS_Axis::SetAxis2Placement(const Handle(Geom_Axis2Placement)& aComponent,
144 const AIS_TypeOfAxis anAxisType)
147 myTypeOfAxis = anAxisType;
148 myIsXYZAxis = Standard_True;
152 //=======================================================================
153 //function : SetAxis1Placement
155 //=======================================================================
157 void AIS_Axis::SetAxis1Placement(const Handle(Geom_Axis1Placement)& anAxis)
159 SetComponent(new Geom_Line(anAxis->Ax1()));
162 //=======================================================================
165 //=======================================================================
166 void AIS_Axis::Compute(const Handle(PrsMgr_PresentationManager3d)&,
167 const Handle(Prs3d_Presentation)& aPresentation,
168 const Standard_Integer)
170 aPresentation->Clear();
172 //Pro.... : pas de prise en compte des axes lors du FITALL (jmi)
173 aPresentation->SetInfiniteState (myInfiniteState);
175 aPresentation->SetDisplayPriority(5);
177 GeomAdaptor_Curve curv(myComponent);
178 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
181 DsgPrs_XYZAxisPresentation::Add(aPresentation,myLineAspect,myDir,myVal,myText,myPfirst,myPlast);
186 void AIS_Axis::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
188 // Standard_NotImplemented::Raise("AIS_Axis::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
189 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
192 //=======================================================================
193 //function : ComputeSelection
195 //=======================================================================
197 void AIS_Axis::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
198 const Standard_Integer)
200 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
201 eown -> SelectBasics_EntityOwner::Set(3);
202 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
205 aSelection->Add(seg);
208 //=======================================================================
209 //function : SetColor
211 //=======================================================================
214 void AIS_Axis::SetColor(const Quantity_NameOfColor aCol)
216 SetColor(Quantity_Color(aCol));
219 void AIS_Axis::SetColor(const Quantity_Color &aCol)
221 hasOwnColor=Standard_True;
223 myDrawer->LineAspect()->SetColor(aCol);
225 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
226 DA->FirstAxisAspect()->SetColor(aCol);
227 DA->SecondAxisAspect()->SetColor(aCol);
228 DA->ThirdAxisAspect()->SetColor(aCol);
232 //=======================================================================
233 //function : SetWidth
235 //=======================================================================
236 void AIS_Axis::SetWidth(const Standard_Real aValue)
239 if(aValue<0.0) return;
240 if(aValue==0) UnsetWidth();
242 myDrawer->LineAspect()->SetWidth(aValue);
244 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
245 DA->FirstAxisAspect()->SetWidth(aValue);
246 DA->SecondAxisAspect()->SetWidth(aValue);
247 DA->ThirdAxisAspect()->SetWidth(aValue);
251 //=======================================================================
253 //purpose : to avoid warning
254 //=======================================================================
255 void AIS_Axis::Compute(const Handle(Prs3d_Projector)&,
256 const Handle(Prs3d_Presentation)&)
260 //=======================================================================
261 //function : ComputeFields
263 //=======================================================================
264 void AIS_Axis::ComputeFields()
267 // calcul de myPFirst,myPlast
268 Handle(Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
269 gp_Ax2 anAxis = myAx2->Ax2();
270 const gp_Pnt& Orig = anAxis.Location();
271 const gp_Dir& oX = anAxis.XDirection();
272 const gp_Dir& oY = anAxis.YDirection();
273 const gp_Dir& oZ = anAxis.Direction();
274 Quantity_Length xo,yo,zo,x = 0.,y = 0.,z = 0.;
275 Orig.Coord(xo,yo,zo);
276 myPfirst.SetCoord(xo,yo,zo);
278 switch (myTypeOfAxis) {
282 myVal = DA->FirstAxisLength();
284 myLineAspect = DA->FirstAxisAspect();
285 myText = Standard_CString ("X");
291 myVal = DA->SecondAxisLength();
293 myLineAspect = DA->SecondAxisAspect();
294 myText = Standard_CString ("Y");
300 myVal = DA->ThirdAxisLength();
302 myLineAspect = DA->ThirdAxisAspect();
303 myText = Standard_CString ("Z");
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);
317 //=======================================================================
318 //function : AcceptDisplayMode
320 //=======================================================================
322 Standard_Boolean AIS_Axis::
323 AcceptDisplayMode(const Standard_Integer aMode) const
326 //=======================================================================
327 //function : UnsetColor
329 //=======================================================================
330 void AIS_Axis::UnsetColor()
333 myDrawer->LineAspect()->SetColor(Quantity_NOC_RED);
335 hasOwnColor=Standard_False;
337 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
338 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
339 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
341 //=======================================================================
342 //function : UnsetWidth
344 //=======================================================================
346 void AIS_Axis::UnsetWidth()
349 myDrawer->LineAspect()->SetWidth(1.);
350 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
351 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
352 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);