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_DatumParts_XAxis)->SetColor(col);
86 DA->LineAspect(Prs3d_DatumParts_YAxis)->SetColor(col);
87 DA->LineAspect(Prs3d_DatumParts_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_PresentationManager)& ,
165 const Handle(Prs3d_Presentation)& thePrs,
166 const Standard_Integer )
168 thePrs->SetInfiniteState (myInfiniteState);
169 thePrs->SetDisplayPriority(5);
172 GeomAdaptor_Curve curv (myComponent);
173 StdPrs_Curve::Add (thePrs, curv, myDrawer);
177 DsgPrs_XYZAxisPresentation::Add (thePrs, myLineAspect, myDir, myVal,
178 myDrawer->DatumAspect()->ToDrawLabels() ? myText : "",
183 //=======================================================================
184 //function : ComputeSelection
186 //=======================================================================
188 void AIS_Axis::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
189 const Standard_Integer)
191 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner (this, 3);
192 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
195 aSelection->Add(seg);
198 //=======================================================================
199 //function : SetColor
201 //=======================================================================
202 void AIS_Axis::SetColor(const Quantity_Color &aCol)
204 hasOwnColor=Standard_True;
205 myDrawer->SetColor (aCol);
206 myDrawer->LineAspect()->SetColor(aCol);
208 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
209 DA->LineAspect(Prs3d_DatumParts_XAxis)->SetColor(aCol);
210 DA->LineAspect(Prs3d_DatumParts_YAxis)->SetColor(aCol);
211 DA->LineAspect(Prs3d_DatumParts_ZAxis)->SetColor(aCol);
212 SynchronizeAspects();
215 //=======================================================================
216 //function : SetWidth
218 //=======================================================================
219 void AIS_Axis::SetWidth(const Standard_Real aValue)
221 if(aValue<0.0) return;
222 if(aValue==0) UnsetWidth();
224 myDrawer->LineAspect()->SetWidth(aValue);
226 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
227 DA->LineAspect(Prs3d_DatumParts_XAxis)->SetWidth(aValue);
228 DA->LineAspect(Prs3d_DatumParts_YAxis)->SetWidth(aValue);
229 DA->LineAspect(Prs3d_DatumParts_ZAxis)->SetWidth(aValue);
230 SynchronizeAspects();
233 //=======================================================================
234 //function : ComputeFields
236 //=======================================================================
237 void AIS_Axis::ComputeFields()
240 // calcul de myPFirst,myPlast
241 Handle(Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
242 gp_Ax2 anAxis = myAx2->Ax2();
243 const gp_Pnt& Orig = anAxis.Location();
244 const gp_Dir& oX = anAxis.XDirection();
245 const gp_Dir& oY = anAxis.YDirection();
246 const gp_Dir& oZ = anAxis.Direction();
247 Standard_Real xo,yo,zo,x = 0.,y = 0.,z = 0.;
248 Orig.Coord(xo,yo,zo);
249 myPfirst.SetCoord(xo,yo,zo);
251 switch (myTypeOfAxis) {
255 myVal = DA->AxisLength(Prs3d_DatumParts_XAxis);
257 myLineAspect = DA->LineAspect(Prs3d_DatumParts_XAxis);
258 myText = Standard_CString ("X");
264 myVal = DA->AxisLength(Prs3d_DatumParts_YAxis);
266 myLineAspect = DA->LineAspect(Prs3d_DatumParts_YAxis);
267 myText = Standard_CString ("Y");
273 myVal = DA->AxisLength(Prs3d_DatumParts_ZAxis);
275 myLineAspect = DA->LineAspect(Prs3d_DatumParts_ZAxis);
276 myText = Standard_CString ("Z");
283 myComponent = new Geom_Line(Orig,myDir);
284 x = xo + x*myVal; y = yo + y*myVal; z = zo + z*myVal;
285 myPlast.SetCoord(x,y,z);
290 //=======================================================================
291 //function : AcceptDisplayMode
293 //=======================================================================
295 Standard_Boolean AIS_Axis::
296 AcceptDisplayMode(const Standard_Integer aMode) const
299 //=======================================================================
300 //function : UnsetColor
302 //=======================================================================
303 void AIS_Axis::UnsetColor()
305 myDrawer->LineAspect()->SetColor(Quantity_NOC_RED);
306 hasOwnColor = Standard_False;
308 myDrawer->DatumAspect()->LineAspect(Prs3d_DatumParts_XAxis)->SetColor(Quantity_NOC_TURQUOISE);
309 myDrawer->DatumAspect()->LineAspect(Prs3d_DatumParts_YAxis)->SetColor(Quantity_NOC_TURQUOISE);
310 myDrawer->DatumAspect()->LineAspect(Prs3d_DatumParts_ZAxis)->SetColor(Quantity_NOC_TURQUOISE);
311 SynchronizeAspects();
313 //=======================================================================
314 //function : UnsetWidth
316 //=======================================================================
318 void AIS_Axis::UnsetWidth()
321 myDrawer->LineAspect()->SetWidth(1.);
322 myDrawer->DatumAspect()->LineAspect(Prs3d_DatumParts_XAxis)->SetWidth(1.);
323 myDrawer->DatumAspect()->LineAspect(Prs3d_DatumParts_YAxis)->SetWidth(1.);
324 myDrawer->DatumAspect()->LineAspect(Prs3d_DatumParts_ZAxis)->SetWidth(1.);
325 SynchronizeAspects();