1 // Created on: 1995-08-09
2 // Created by: Arnaud BOUZY/Odile Olivier
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #define GER61351 //GG_171199 Enable to set an object RGB color
23 // instead a restricted object NameOfColor.
25 #include <AIS_Axis.ixx>
26 #include <Aspect_TypeOfLine.hxx>
27 #include <Prs3d_Drawer.hxx>
28 #include <Prs3d_LineAspect.hxx>
29 #include <Prs3d_DatumAspect.hxx>
30 #include <Graphic3d_ArrayOfPrimitives.hxx>
31 #include <Graphic3d_AspectLine3d.hxx>
32 #include <Graphic3d_Structure.hxx>
33 #include <TColgp_Array1OfPnt.hxx>
34 #include <SelectMgr_EntityOwner.hxx>
35 #include <SelectBasics_EntityOwner.hxx>
36 #include <Select3D_SensitiveSegment.hxx>
37 #include <StdPrs_Curve.hxx>
39 #include <Geom_Axis1Placement.hxx>
42 #include <Geom_Line.hxx>
43 #include <GeomAdaptor_Curve.hxx>
44 #include <AIS_Drawer.hxx>
45 #include <DsgPrs_XYZAxisPresentation.hxx>
46 #include <UnitsAPI.hxx>
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 Standard_Boolean isPrimitiveArraysEnabled = Graphic3d_ArrayOfPrimitives::IsEnable();
181 if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Disable();
182 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
183 if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Enable();
186 DsgPrs_XYZAxisPresentation::Add(aPresentation,myLineAspect,myDir,myVal,myText,myPfirst,myPlast);
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)
222 SetColor(Quantity_Color(aCol));
225 void AIS_Axis::SetColor(const Quantity_Color &aCol)
228 hasOwnColor=Standard_True;
230 myDrawer->LineAspect()->SetColor(aCol);
232 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
233 DA->FirstAxisAspect()->SetColor(aCol);
234 DA->SecondAxisAspect()->SetColor(aCol);
235 DA->ThirdAxisAspect()->SetColor(aCol);
239 //=======================================================================
240 //function : SetWidth
242 //=======================================================================
243 void AIS_Axis::SetWidth(const Standard_Real aValue)
246 if(aValue<0.0) return;
247 if(aValue==0) UnsetWidth();
249 myDrawer->LineAspect()->SetWidth(aValue);
251 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
252 DA->FirstAxisAspect()->SetWidth(aValue);
253 DA->SecondAxisAspect()->SetWidth(aValue);
254 DA->ThirdAxisAspect()->SetWidth(aValue);
258 //=======================================================================
260 //purpose : to avoid warning
261 //=======================================================================
262 void AIS_Axis::Compute(const Handle(PrsMgr_PresentationManager2d)&,
263 const Handle(Graphic2d_GraphicObject)&,
264 const Standard_Integer)
268 //=======================================================================
270 //purpose : to avoid warning
271 //=======================================================================
272 void AIS_Axis::Compute(const Handle(Prs3d_Projector)&,
273 const Handle(Prs3d_Presentation)&)
277 //=======================================================================
278 //function : ComputeFields
280 //=======================================================================
281 void AIS_Axis::ComputeFields()
284 // calcul de myPFirst,myPlast
285 Handle(Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
286 gp_Pnt Orig = myAx2->Ax2().Location();
287 gp_Dir oX = myAx2->Ax2().XDirection();
288 gp_Dir oY = myAx2->Ax2().YDirection();
289 gp_Dir oZ = myAx2->Ax2().Direction();
290 Quantity_Length xo,yo,zo,x,y,z;
291 Orig.Coord(xo,yo,zo);
292 myPfirst.SetCoord(xo,yo,zo);
294 switch (myTypeOfAxis) {
298 myVal = DA->FirstAxisLength();
300 myLineAspect = DA->FirstAxisAspect();
301 myText = Standard_CString ("X");
307 myVal = DA->SecondAxisLength();
309 myLineAspect = DA->SecondAxisAspect();
310 myText = Standard_CString ("Y");
316 myVal = DA->ThirdAxisLength();
318 myLineAspect = DA->ThirdAxisAspect();
319 myText = Standard_CString ("Z");
326 myComponent = new Geom_Line(Orig,myDir);
327 x = xo + x*myVal; y = yo + y*myVal; z = zo + z*myVal;
328 myPlast.SetCoord(x,y,z);
333 //=======================================================================
334 //function : AcceptDisplayMode
336 //=======================================================================
338 Standard_Boolean AIS_Axis::
339 AcceptDisplayMode(const Standard_Integer aMode) const
342 //=======================================================================
343 //function : UnsetColor
345 //=======================================================================
346 void AIS_Axis::UnsetColor()
349 myDrawer->LineAspect()->SetColor(Quantity_NOC_RED);
351 hasOwnColor=Standard_False;
353 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
354 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
355 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
357 //=======================================================================
358 //function : UnsetWidth
360 //=======================================================================
362 void AIS_Axis::UnsetWidth()
365 myDrawer->LineAspect()->SetWidth(1.);
366 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
367 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
368 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);