2 // Created: Wed Aug 9 16:28:42 1995
3 // Author: Arnaud BOUZY/Odile Olivier
6 #define GER61351 //GG_171199 Enable to set an object RGB color
7 // instead a restricted object NameOfColor.
9 #include <AIS_Axis.ixx>
10 #include <Aspect_TypeOfLine.hxx>
11 #include <Prs3d_Drawer.hxx>
12 #include <Prs3d_LineAspect.hxx>
13 #include <Prs3d_DatumAspect.hxx>
14 #include <Graphic3d_ArrayOfPrimitives.hxx>
15 #include <Graphic3d_AspectLine3d.hxx>
16 #include <Graphic3d_Structure.hxx>
17 #include <TColgp_Array1OfPnt.hxx>
18 #include <SelectMgr_EntityOwner.hxx>
19 #include <SelectBasics_EntityOwner.hxx>
20 #include <Select3D_SensitiveSegment.hxx>
21 #include <StdPrs_Curve.hxx>
23 #include <Geom_Axis1Placement.hxx>
26 #include <Geom_Line.hxx>
27 #include <GeomAdaptor_Curve.hxx>
28 #include <AIS_Drawer.hxx>
29 #include <DsgPrs_XYZAxisPresentation.hxx>
30 #include <UnitsAPI.hxx>
32 //=======================================================================
35 //=======================================================================
36 AIS_Axis::AIS_Axis(const Handle(Geom_Line)& aComponent):
37 myComponent(aComponent),
38 myTypeOfAxis(AIS_TOAX_Unknown),
39 myIsXYZAxis(Standard_False)
41 myDrawer->SetLineAspect(new Prs3d_LineAspect
42 (Quantity_NOC_RED,Aspect_TOL_DOTDASH,1.));
45 gp_Dir thedir = myComponent->Position().Direction();
46 gp_Pnt loc = myComponent->Position().Location();
47 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
48 Standard_Real aLength = UnitsAPI::AnyToLS(250000., "mm");
49 myPfirst = loc.XYZ() + aLength*thedir.XYZ();
50 myPlast = loc.XYZ() - aLength*thedir.XYZ();
53 //=======================================================================
55 //purpose : Xaxis, YAxis, ZAxis
56 //=======================================================================
57 AIS_Axis::AIS_Axis(const Handle(Geom_Axis2Placement)& aComponent,
58 const AIS_TypeOfAxis anAxisType):
60 myTypeOfAxis(anAxisType),
61 myIsXYZAxis(Standard_True)
63 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
64 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (100. ,"LENGTH");
65 Standard_Real aLength;
67 aLength = UnitsAPI::AnyToLS(100. ,"mm");
68 } catch (Standard_Failure) {
71 DA->SetAxisLength(aLength,aLength,aLength);
72 Quantity_NameOfColor col = Quantity_NOC_TURQUOISE;
73 DA->FirstAxisAspect()->SetColor(col);
74 DA->SecondAxisAspect()->SetColor(col);
75 DA->ThirdAxisAspect()->SetColor(col);
76 myDrawer->SetDatumAspect(DA);
81 //=======================================================================
84 //=======================================================================
85 AIS_Axis::AIS_Axis(const Handle(Geom_Axis1Placement)& anAxis)
86 :myComponent(new Geom_Line(anAxis->Ax1())),
87 myTypeOfAxis(AIS_TOAX_Unknown),
88 myIsXYZAxis(Standard_False)
90 myDrawer->SetLineAspect(new Prs3d_LineAspect(Quantity_NOC_RED,Aspect_TOL_DOTDASH,1.));
93 gp_Dir thedir = myComponent->Position().Direction();
94 gp_Pnt loc = myComponent->Position().Location();
95 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
96 Standard_Real aLength = UnitsAPI::AnyToLS(250000. ,"mm");
97 myPfirst = loc.XYZ() + aLength*thedir.XYZ();
98 myPlast = loc.XYZ() - aLength*thedir.XYZ();
102 //=======================================================================
103 //function : SetComponent
105 //=======================================================================
107 void AIS_Axis::SetComponent(const Handle(Geom_Line)& aComponent)
109 myComponent = aComponent;
110 myTypeOfAxis = AIS_TOAX_Unknown;
111 myIsXYZAxis = Standard_False;
114 gp_Dir thedir = myComponent->Position().Direction();
115 gp_Pnt loc = myComponent->Position().Location();
116 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
117 Standard_Real aLength = UnitsAPI::AnyToLS(250000. ,"mm");
118 myPfirst = loc.XYZ() + aLength*thedir.XYZ();
119 myPlast = loc.XYZ() - aLength*thedir.XYZ();
124 //=======================================================================
125 //function : SetAxis2Placement
127 //=======================================================================
129 void AIS_Axis::SetAxis2Placement(const Handle(Geom_Axis2Placement)& aComponent,
130 const AIS_TypeOfAxis anAxisType)
133 myTypeOfAxis = anAxisType;
134 myIsXYZAxis = Standard_True;
138 //=======================================================================
139 //function : SetAxis1Placement
141 //=======================================================================
143 void AIS_Axis::SetAxis1Placement(const Handle(Geom_Axis1Placement)& anAxis)
145 SetComponent(new Geom_Line(anAxis->Ax1()));
148 //=======================================================================
151 //=======================================================================
152 void AIS_Axis::Compute(const Handle(PrsMgr_PresentationManager3d)&,
153 const Handle(Prs3d_Presentation)& aPresentation,
154 const Standard_Integer)
156 aPresentation->Clear();
158 //Pro.... : pas de prise en compte des axes lors du FITALL (jmi)
159 aPresentation->SetInfiniteState (myInfiniteState);
161 aPresentation->SetDisplayPriority(5);
163 GeomAdaptor_Curve curv(myComponent);
164 Standard_Boolean isPrimitiveArraysEnabled = Graphic3d_ArrayOfPrimitives::IsEnable();
165 if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Disable();
166 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
167 if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Enable();
170 DsgPrs_XYZAxisPresentation::Add(aPresentation,myLineAspect,myDir,myVal,myText,myPfirst,myPlast);
175 void AIS_Axis::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
177 // Standard_NotImplemented::Raise("AIS_Axis::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
178 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
181 //=======================================================================
182 //function : ComputeSelection
184 //=======================================================================
186 void AIS_Axis::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
187 const Standard_Integer)
189 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
190 eown -> SelectBasics_EntityOwner::Set(3);
191 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
194 aSelection->Add(seg);
197 //=======================================================================
198 //function : SetColor
200 //=======================================================================
203 void AIS_Axis::SetColor(const Quantity_NameOfColor aCol)
206 SetColor(Quantity_Color(aCol));
209 void AIS_Axis::SetColor(const Quantity_Color &aCol)
212 hasOwnColor=Standard_True;
214 myDrawer->LineAspect()->SetColor(aCol);
216 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
217 DA->FirstAxisAspect()->SetColor(aCol);
218 DA->SecondAxisAspect()->SetColor(aCol);
219 DA->ThirdAxisAspect()->SetColor(aCol);
223 //=======================================================================
224 //function : SetWidth
226 //=======================================================================
227 void AIS_Axis::SetWidth(const Standard_Real aValue)
230 if(aValue<0.0) return;
231 if(aValue==0) UnsetWidth();
233 myDrawer->LineAspect()->SetWidth(aValue);
235 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
236 DA->FirstAxisAspect()->SetWidth(aValue);
237 DA->SecondAxisAspect()->SetWidth(aValue);
238 DA->ThirdAxisAspect()->SetWidth(aValue);
242 //=======================================================================
244 //purpose : to avoid warning
245 //=======================================================================
246 void AIS_Axis::Compute(const Handle(PrsMgr_PresentationManager2d)&,
247 const Handle(Graphic2d_GraphicObject)&,
248 const Standard_Integer)
252 //=======================================================================
254 //purpose : to avoid warning
255 //=======================================================================
256 void AIS_Axis::Compute(const Handle(Prs3d_Projector)&,
257 const Handle(Prs3d_Presentation)&)
261 //=======================================================================
262 //function : ComputeFields
264 //=======================================================================
265 void AIS_Axis::ComputeFields()
268 // calcul de myPFirst,myPlast
269 Handle(Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
270 gp_Pnt Orig = myAx2->Ax2().Location();
271 gp_Dir oX = myAx2->Ax2().XDirection();
272 gp_Dir oY = myAx2->Ax2().YDirection();
273 gp_Dir oZ = myAx2->Ax2().Direction();
274 Quantity_Length xo,yo,zo,x,y,z;
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.);