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 IMPLEMENT_STANDARD_RTTIEXT(AIS_Axis,AIS_InteractiveObject)
48 //=======================================================================
51 //=======================================================================
52 AIS_Axis::AIS_Axis(const Handle(Geom_Line)& aComponent):
53 myComponent(aComponent),
54 myTypeOfAxis(AIS_TOAX_Unknown),
55 myIsXYZAxis(Standard_False)
57 myDrawer->SetLineAspect(new Prs3d_LineAspect
58 (Quantity_NOC_RED,Aspect_TOL_DOTDASH,1.));
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();
69 //=======================================================================
71 //purpose : Xaxis, YAxis, ZAxis
72 //=======================================================================
73 AIS_Axis::AIS_Axis(const Handle(Geom_Axis2Placement)& aComponent,
74 const AIS_TypeOfAxis anAxisType):
76 myTypeOfAxis(anAxisType),
77 myIsXYZAxis(Standard_True)
79 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
80 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (100. ,"LENGTH");
81 Standard_Real aLength;
83 aLength = UnitsAPI::AnyToLS(100. ,"mm");
84 } catch (Standard_Failure) {
87 DA->SetAxisLength(aLength,aLength,aLength);
88 Quantity_NameOfColor col = Quantity_NOC_TURQUOISE;
89 DA->FirstAxisAspect()->SetColor(col);
90 DA->SecondAxisAspect()->SetColor(col);
91 DA->ThirdAxisAspect()->SetColor(col);
92 myDrawer->SetDatumAspect(DA);
97 //=======================================================================
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)
106 myDrawer->SetLineAspect(new Prs3d_LineAspect(Quantity_NOC_RED,Aspect_TOL_DOTDASH,1.));
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();
118 //=======================================================================
119 //function : SetComponent
121 //=======================================================================
123 void AIS_Axis::SetComponent(const Handle(Geom_Line)& aComponent)
125 myComponent = aComponent;
126 myTypeOfAxis = AIS_TOAX_Unknown;
127 myIsXYZAxis = Standard_False;
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();
140 //=======================================================================
141 //function : SetAxis2Placement
143 //=======================================================================
145 void AIS_Axis::SetAxis2Placement(const Handle(Geom_Axis2Placement)& aComponent,
146 const AIS_TypeOfAxis anAxisType)
149 myTypeOfAxis = anAxisType;
150 myIsXYZAxis = Standard_True;
154 //=======================================================================
155 //function : SetAxis1Placement
157 //=======================================================================
159 void AIS_Axis::SetAxis1Placement(const Handle(Geom_Axis1Placement)& anAxis)
161 SetComponent(new Geom_Line(anAxis->Ax1()));
164 //=======================================================================
167 //=======================================================================
168 void AIS_Axis::Compute(const Handle(PrsMgr_PresentationManager3d)&,
169 const Handle(Prs3d_Presentation)& aPresentation,
170 const Standard_Integer)
172 aPresentation->Clear();
174 //Pro.... : pas de prise en compte des axes lors du FITALL (jmi)
175 aPresentation->SetInfiniteState (myInfiniteState);
177 aPresentation->SetDisplayPriority(5);
179 GeomAdaptor_Curve curv(myComponent);
180 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
184 DsgPrs_XYZAxisPresentation::Add (aPresentation,myLineAspect,myDir,myVal,
185 myDrawer->DatumAspect()->ToDrawLabels() ? myText : "",
191 void AIS_Axis::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
193 // Standard_NotImplemented::Raise("AIS_Axis::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
194 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
197 //=======================================================================
198 //function : ComputeSelection
200 //=======================================================================
202 void AIS_Axis::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
203 const Standard_Integer)
205 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
206 eown -> SelectBasics_EntityOwner::Set(3);
207 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
210 aSelection->Add(seg);
213 //=======================================================================
214 //function : SetColor
216 //=======================================================================
219 void AIS_Axis::SetColor(const Quantity_NameOfColor aCol)
221 SetColor(Quantity_Color(aCol));
224 void AIS_Axis::SetColor(const Quantity_Color &aCol)
226 hasOwnColor=Standard_True;
228 myDrawer->LineAspect()->SetColor(aCol);
230 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
231 DA->FirstAxisAspect()->SetColor(aCol);
232 DA->SecondAxisAspect()->SetColor(aCol);
233 DA->ThirdAxisAspect()->SetColor(aCol);
237 //=======================================================================
238 //function : SetWidth
240 //=======================================================================
241 void AIS_Axis::SetWidth(const Standard_Real aValue)
244 if(aValue<0.0) return;
245 if(aValue==0) UnsetWidth();
247 myDrawer->LineAspect()->SetWidth(aValue);
249 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
250 DA->FirstAxisAspect()->SetWidth(aValue);
251 DA->SecondAxisAspect()->SetWidth(aValue);
252 DA->ThirdAxisAspect()->SetWidth(aValue);
256 //=======================================================================
258 //purpose : to avoid warning
259 //=======================================================================
260 void AIS_Axis::Compute(const Handle(Prs3d_Projector)&,
261 const Handle(Prs3d_Presentation)&)
265 //=======================================================================
266 //function : ComputeFields
268 //=======================================================================
269 void AIS_Axis::ComputeFields()
272 // calcul de myPFirst,myPlast
273 Handle(Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
274 gp_Ax2 anAxis = myAx2->Ax2();
275 const gp_Pnt& Orig = anAxis.Location();
276 const gp_Dir& oX = anAxis.XDirection();
277 const gp_Dir& oY = anAxis.YDirection();
278 const gp_Dir& oZ = anAxis.Direction();
279 Quantity_Length xo,yo,zo,x = 0.,y = 0.,z = 0.;
280 Orig.Coord(xo,yo,zo);
281 myPfirst.SetCoord(xo,yo,zo);
283 switch (myTypeOfAxis) {
287 myVal = DA->FirstAxisLength();
289 myLineAspect = DA->FirstAxisAspect();
290 myText = Standard_CString ("X");
296 myVal = DA->SecondAxisLength();
298 myLineAspect = DA->SecondAxisAspect();
299 myText = Standard_CString ("Y");
305 myVal = DA->ThirdAxisLength();
307 myLineAspect = DA->ThirdAxisAspect();
308 myText = Standard_CString ("Z");
315 myComponent = new Geom_Line(Orig,myDir);
316 x = xo + x*myVal; y = yo + y*myVal; z = zo + z*myVal;
317 myPlast.SetCoord(x,y,z);
322 //=======================================================================
323 //function : AcceptDisplayMode
325 //=======================================================================
327 Standard_Boolean AIS_Axis::
328 AcceptDisplayMode(const Standard_Integer aMode) const
331 //=======================================================================
332 //function : UnsetColor
334 //=======================================================================
335 void AIS_Axis::UnsetColor()
338 myDrawer->LineAspect()->SetColor(Quantity_NOC_RED);
340 hasOwnColor=Standard_False;
342 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
343 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
344 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
346 //=======================================================================
347 //function : UnsetWidth
349 //=======================================================================
351 void AIS_Axis::UnsetWidth()
354 myDrawer->LineAspect()->SetWidth(1.);
355 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
356 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
357 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);