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 //GER61351 //GG_171199 Enable to set an object RGB color instead a restricted object NameOfColor.
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>
32 #include <Geom_Axis1Placement.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>
41 //=======================================================================
44 //=======================================================================
45 AIS_Axis::AIS_Axis(const Handle(Geom_Line)& aComponent):
46 myComponent(aComponent),
47 myTypeOfAxis(AIS_TOAX_Unknown),
48 myIsXYZAxis(Standard_False)
50 myDrawer->SetLineAspect(new Prs3d_LineAspect
51 (Quantity_NOC_RED,Aspect_TOL_DOTDASH,1.));
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();
62 //=======================================================================
64 //purpose : Xaxis, YAxis, ZAxis
65 //=======================================================================
66 AIS_Axis::AIS_Axis(const Handle(Geom_Axis2Placement)& aComponent,
67 const AIS_TypeOfAxis anAxisType):
69 myTypeOfAxis(anAxisType),
70 myIsXYZAxis(Standard_True)
72 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
73 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (100. ,"LENGTH");
74 Standard_Real aLength;
76 aLength = UnitsAPI::AnyToLS(100. ,"mm");
77 } catch (Standard_Failure) {
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);
90 //=======================================================================
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)
99 myDrawer->SetLineAspect(new Prs3d_LineAspect(Quantity_NOC_RED,Aspect_TOL_DOTDASH,1.));
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();
111 //=======================================================================
112 //function : SetComponent
114 //=======================================================================
116 void AIS_Axis::SetComponent(const Handle(Geom_Line)& aComponent)
118 myComponent = aComponent;
119 myTypeOfAxis = AIS_TOAX_Unknown;
120 myIsXYZAxis = Standard_False;
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();
133 //=======================================================================
134 //function : SetAxis2Placement
136 //=======================================================================
138 void AIS_Axis::SetAxis2Placement(const Handle(Geom_Axis2Placement)& aComponent,
139 const AIS_TypeOfAxis anAxisType)
142 myTypeOfAxis = anAxisType;
143 myIsXYZAxis = Standard_True;
147 //=======================================================================
148 //function : SetAxis1Placement
150 //=======================================================================
152 void AIS_Axis::SetAxis1Placement(const Handle(Geom_Axis1Placement)& anAxis)
154 SetComponent(new Geom_Line(anAxis->Ax1()));
157 //=======================================================================
160 //=======================================================================
161 void AIS_Axis::Compute(const Handle(PrsMgr_PresentationManager3d)&,
162 const Handle(Prs3d_Presentation)& aPresentation,
163 const Standard_Integer)
165 aPresentation->Clear();
167 //Pro.... : pas de prise en compte des axes lors du FITALL (jmi)
168 aPresentation->SetInfiniteState (myInfiniteState);
170 aPresentation->SetDisplayPriority(5);
172 GeomAdaptor_Curve curv(myComponent);
173 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
176 DsgPrs_XYZAxisPresentation::Add(aPresentation,myLineAspect,myDir,myVal,myText,myPfirst,myPlast);
181 void AIS_Axis::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
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 ) ;
187 //=======================================================================
188 //function : ComputeSelection
190 //=======================================================================
192 void AIS_Axis::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
193 const Standard_Integer)
195 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
196 eown -> SelectBasics_EntityOwner::Set(3);
197 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
200 aSelection->Add(seg);
203 //=======================================================================
204 //function : SetColor
206 //=======================================================================
209 void AIS_Axis::SetColor(const Quantity_NameOfColor aCol)
211 SetColor(Quantity_Color(aCol));
214 void AIS_Axis::SetColor(const Quantity_Color &aCol)
216 hasOwnColor=Standard_True;
218 myDrawer->LineAspect()->SetColor(aCol);
220 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
221 DA->FirstAxisAspect()->SetColor(aCol);
222 DA->SecondAxisAspect()->SetColor(aCol);
223 DA->ThirdAxisAspect()->SetColor(aCol);
227 //=======================================================================
228 //function : SetWidth
230 //=======================================================================
231 void AIS_Axis::SetWidth(const Standard_Real aValue)
234 if(aValue<0.0) return;
235 if(aValue==0) UnsetWidth();
237 myDrawer->LineAspect()->SetWidth(aValue);
239 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
240 DA->FirstAxisAspect()->SetWidth(aValue);
241 DA->SecondAxisAspect()->SetWidth(aValue);
242 DA->ThirdAxisAspect()->SetWidth(aValue);
246 //=======================================================================
248 //purpose : to avoid warning
249 //=======================================================================
250 void AIS_Axis::Compute(const Handle(Prs3d_Projector)&,
251 const Handle(Prs3d_Presentation)&)
255 //=======================================================================
256 //function : ComputeFields
258 //=======================================================================
259 void AIS_Axis::ComputeFields()
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);
273 switch (myTypeOfAxis) {
277 myVal = DA->FirstAxisLength();
279 myLineAspect = DA->FirstAxisAspect();
280 myText = Standard_CString ("X");
286 myVal = DA->SecondAxisLength();
288 myLineAspect = DA->SecondAxisAspect();
289 myText = Standard_CString ("Y");
295 myVal = DA->ThirdAxisLength();
297 myLineAspect = DA->ThirdAxisAspect();
298 myText = Standard_CString ("Z");
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);
312 //=======================================================================
313 //function : AcceptDisplayMode
315 //=======================================================================
317 Standard_Boolean AIS_Axis::
318 AcceptDisplayMode(const Standard_Integer aMode) const
321 //=======================================================================
322 //function : UnsetColor
324 //=======================================================================
325 void AIS_Axis::UnsetColor()
328 myDrawer->LineAspect()->SetColor(Quantity_NOC_RED);
330 hasOwnColor=Standard_False;
332 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
333 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
334 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
336 //=======================================================================
337 //function : UnsetWidth
339 //=======================================================================
341 void AIS_Axis::UnsetWidth()
344 myDrawer->LineAspect()->SetWidth(1.);
345 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
346 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
347 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);