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.
17 #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 <GeomAdaptor_Curve.hxx>
27 #include <Graphic3d_AspectLine3d.hxx>
28 #include <Graphic3d_Structure.hxx>
29 #include <Prs3d_DatumAspect.hxx>
30 #include <Prs3d_Drawer.hxx>
31 #include <Prs3d_LineAspect.hxx>
32 #include <Prs3d_Presentation.hxx>
33 #include <Quantity_Color.hxx>
34 #include <Select3D_SensitiveSegment.hxx>
35 #include <SelectMgr_EntityOwner.hxx>
36 #include <SelectMgr_Selection.hxx>
37 #include <StdPrs_Curve.hxx>
38 #include <TColgp_Array1OfPnt.hxx>
40 #include <UnitsAPI.hxx>
42 IMPLEMENT_STANDARD_RTTIEXT(AIS_Axis,AIS_InteractiveObject)
44 //=======================================================================
47 //=======================================================================
48 AIS_Axis::AIS_Axis(const Handle(Geom_Line)& aComponent):
49 myComponent(aComponent),
50 myTypeOfAxis(AIS_TOAX_Unknown),
51 myIsXYZAxis(Standard_False)
53 myDrawer->SetLineAspect(new Prs3d_LineAspect
54 (Quantity_NOC_RED,Aspect_TOL_DOTDASH,1.));
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();
65 //=======================================================================
67 //purpose : Xaxis, YAxis, ZAxis
68 //=======================================================================
69 AIS_Axis::AIS_Axis(const Handle(Geom_Axis2Placement)& aComponent,
70 const AIS_TypeOfAxis anAxisType):
72 myTypeOfAxis(anAxisType),
73 myIsXYZAxis(Standard_True)
75 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
76 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (100. ,"LENGTH");
77 Standard_Real aLength;
79 aLength = UnitsAPI::AnyToLS(100. ,"mm");
80 } catch (Standard_Failure const&) {
83 DA->SetAxisLength(aLength,aLength,aLength);
84 Quantity_Color col (Quantity_NOC_TURQUOISE);
85 DA->LineAspect(Prs3d_DP_XAxis)->SetColor(col);
86 DA->LineAspect(Prs3d_DP_YAxis)->SetColor(col);
87 DA->LineAspect(Prs3d_DP_ZAxis)->SetColor(col);
88 myDrawer->SetDatumAspect(DA);
93 //=======================================================================
96 //=======================================================================
97 AIS_Axis::AIS_Axis(const Handle(Geom_Axis1Placement)& anAxis)
98 :myComponent(new Geom_Line(anAxis->Ax1())),
99 myTypeOfAxis(AIS_TOAX_Unknown),
100 myIsXYZAxis(Standard_False)
102 myDrawer->SetLineAspect(new Prs3d_LineAspect(Quantity_NOC_RED,Aspect_TOL_DOTDASH,1.));
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();
114 //=======================================================================
115 //function : SetComponent
117 //=======================================================================
119 void AIS_Axis::SetComponent(const Handle(Geom_Line)& aComponent)
121 myComponent = aComponent;
122 myTypeOfAxis = AIS_TOAX_Unknown;
123 myIsXYZAxis = Standard_False;
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();
136 //=======================================================================
137 //function : SetAxis2Placement
139 //=======================================================================
141 void AIS_Axis::SetAxis2Placement(const Handle(Geom_Axis2Placement)& aComponent,
142 const AIS_TypeOfAxis anAxisType)
145 myTypeOfAxis = anAxisType;
146 myIsXYZAxis = Standard_True;
150 //=======================================================================
151 //function : SetAxis1Placement
153 //=======================================================================
155 void AIS_Axis::SetAxis1Placement(const Handle(Geom_Axis1Placement)& anAxis)
157 SetComponent(new Geom_Line(anAxis->Ax1()));
160 //=======================================================================
163 //=======================================================================
164 void AIS_Axis::Compute(const Handle(PrsMgr_PresentationManager3d)&,
165 const Handle(Prs3d_Presentation)& aPresentation,
166 const Standard_Integer)
168 aPresentation->SetInfiniteState (myInfiniteState);
170 aPresentation->SetDisplayPriority(5);
172 GeomAdaptor_Curve curv(myComponent);
173 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
177 DsgPrs_XYZAxisPresentation::Add (aPresentation,myLineAspect,myDir,myVal,
178 myDrawer->DatumAspect()->ToDrawLabels() ? myText : "",
184 //=======================================================================
185 //function : ComputeSelection
187 //=======================================================================
189 void AIS_Axis::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
190 const Standard_Integer)
192 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner (this, 3);
193 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
196 aSelection->Add(seg);
199 //=======================================================================
200 //function : SetColor
202 //=======================================================================
203 void AIS_Axis::SetColor(const Quantity_Color &aCol)
205 hasOwnColor=Standard_True;
206 myDrawer->SetColor (aCol);
207 myDrawer->LineAspect()->SetColor(aCol);
209 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
210 DA->LineAspect(Prs3d_DP_XAxis)->SetColor(aCol);
211 DA->LineAspect(Prs3d_DP_YAxis)->SetColor(aCol);
212 DA->LineAspect(Prs3d_DP_ZAxis)->SetColor(aCol);
213 SynchronizeAspects();
216 //=======================================================================
217 //function : SetWidth
219 //=======================================================================
220 void AIS_Axis::SetWidth(const Standard_Real aValue)
222 if(aValue<0.0) return;
223 if(aValue==0) UnsetWidth();
225 myDrawer->LineAspect()->SetWidth(aValue);
227 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
228 DA->LineAspect(Prs3d_DP_XAxis)->SetWidth(aValue);
229 DA->LineAspect(Prs3d_DP_YAxis)->SetWidth(aValue);
230 DA->LineAspect(Prs3d_DP_ZAxis)->SetWidth(aValue);
231 SynchronizeAspects();
234 //=======================================================================
235 //function : ComputeFields
237 //=======================================================================
238 void AIS_Axis::ComputeFields()
241 // calcul de myPFirst,myPlast
242 Handle(Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
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();
248 Standard_Real xo,yo,zo,x = 0.,y = 0.,z = 0.;
249 Orig.Coord(xo,yo,zo);
250 myPfirst.SetCoord(xo,yo,zo);
252 switch (myTypeOfAxis) {
256 myVal = DA->AxisLength(Prs3d_DP_XAxis);
258 myLineAspect = DA->LineAspect(Prs3d_DP_XAxis);
259 myText = Standard_CString ("X");
265 myVal = DA->AxisLength(Prs3d_DP_YAxis);
267 myLineAspect = DA->LineAspect(Prs3d_DP_YAxis);
268 myText = Standard_CString ("Y");
274 myVal = DA->AxisLength(Prs3d_DP_ZAxis);
276 myLineAspect = DA->LineAspect(Prs3d_DP_ZAxis);
277 myText = Standard_CString ("Z");
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);
291 //=======================================================================
292 //function : AcceptDisplayMode
294 //=======================================================================
296 Standard_Boolean AIS_Axis::
297 AcceptDisplayMode(const Standard_Integer aMode) const
300 //=======================================================================
301 //function : UnsetColor
303 //=======================================================================
304 void AIS_Axis::UnsetColor()
306 myDrawer->LineAspect()->SetColor(Quantity_NOC_RED);
307 hasOwnColor = Standard_False;
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);
312 SynchronizeAspects();
314 //=======================================================================
315 //function : UnsetWidth
317 //=======================================================================
319 void AIS_Axis::UnsetWidth()
322 myDrawer->LineAspect()->SetWidth(1.);
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.);
326 SynchronizeAspects();