Test for 0022778: Bug in BRepMesh
[occt.git] / src / AIS / AIS_Axis.cxx
CommitLineData
b311480e 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
5//
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.
10//
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.
13//
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.
20
7fd59977 21
22#define GER61351 //GG_171199 Enable to set an object RGB color
23// instead a restricted object NameOfColor.
24
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>
38#include <TopoDS.hxx>
39#include <Geom_Axis1Placement.hxx>
40#include <gp_Ax1.hxx>
41#include <gp_Ax2.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>
47
48//=======================================================================
49//function : AIS_Axis
50//purpose :
51//=======================================================================
52AIS_Axis::AIS_Axis(const Handle(Geom_Line)& aComponent):
53myComponent(aComponent),
54myTypeOfAxis(AIS_TOAX_Unknown),
55myIsXYZAxis(Standard_False)
56{
57 myDrawer->SetLineAspect(new Prs3d_LineAspect
58 (Quantity_NOC_RED,Aspect_TOL_DOTDASH,1.));
59 SetInfiniteState();
60
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();
67}
68
69//=======================================================================
70//function : AIS_Axis
71//purpose : Xaxis, YAxis, ZAxis
72//=======================================================================
73AIS_Axis::AIS_Axis(const Handle(Geom_Axis2Placement)& aComponent,
74 const AIS_TypeOfAxis anAxisType):
75myAx2(aComponent),
76myTypeOfAxis(anAxisType),
77myIsXYZAxis(Standard_True)
78{
79 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
80//POP Standard_Real aLength = UnitsAPI::CurrentToLS (100. ,"LENGTH");
81 Standard_Real aLength;
82 try {
83 aLength = UnitsAPI::AnyToLS(100. ,"mm");
84 } catch (Standard_Failure) {
85 aLength = 0.1;
86 }
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);
93
94 ComputeFields();
95}
96
97//=======================================================================
98//function : AIS_Axis
99//purpose :
100//=======================================================================
101AIS_Axis::AIS_Axis(const Handle(Geom_Axis1Placement)& anAxis)
102:myComponent(new Geom_Line(anAxis->Ax1())),
103 myTypeOfAxis(AIS_TOAX_Unknown),
104 myIsXYZAxis(Standard_False)
105{
106 myDrawer->SetLineAspect(new Prs3d_LineAspect(Quantity_NOC_RED,Aspect_TOL_DOTDASH,1.));
107 SetInfiniteState();
108
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();
115}
116
117
118//=======================================================================
119//function : SetComponent
120//purpose :
121//=======================================================================
122
123void AIS_Axis::SetComponent(const Handle(Geom_Line)& aComponent)
124{
125 myComponent = aComponent;
126 myTypeOfAxis = AIS_TOAX_Unknown;
127 myIsXYZAxis = Standard_False;
128 SetInfiniteState();
129
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();
136}
137
138
139
140//=======================================================================
141//function : SetAxis2Placement
142//purpose :
143//=======================================================================
144
145void AIS_Axis::SetAxis2Placement(const Handle(Geom_Axis2Placement)& aComponent,
146 const AIS_TypeOfAxis anAxisType)
147{
148 myAx2 = aComponent;
149 myTypeOfAxis = anAxisType;
150 myIsXYZAxis = Standard_True;
151 ComputeFields();
152}
153
154//=======================================================================
155//function : SetAxis1Placement
156//purpose :
157//=======================================================================
158
159void AIS_Axis::SetAxis1Placement(const Handle(Geom_Axis1Placement)& anAxis)
160{
161 SetComponent(new Geom_Line(anAxis->Ax1()));
162}
163
164//=======================================================================
165//function : Compute
166//purpose :
167//=======================================================================
168void AIS_Axis::Compute(const Handle(PrsMgr_PresentationManager3d)&,
169 const Handle(Prs3d_Presentation)& aPresentation,
170 const Standard_Integer)
171{
172 aPresentation->Clear();
173
174 //Pro.... : pas de prise en compte des axes lors du FITALL (jmi)
175 aPresentation->SetInfiniteState (myInfiniteState);
176
177 aPresentation->SetDisplayPriority(5);
178 if (!myIsXYZAxis ){
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();
184 }
185 else {
186 DsgPrs_XYZAxisPresentation::Add(aPresentation,myLineAspect,myDir,myVal,myText,myPfirst,myPlast);
187 }
188
189}
190
191void AIS_Axis::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
192{
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 ) ;
195}
196
197//=======================================================================
198//function : ComputeSelection
199//purpose :
200//=======================================================================
201
202void AIS_Axis::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
203 const Standard_Integer)
204{
205 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
206 eown -> SelectBasics_EntityOwner::Set(3);
207 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
208 myPfirst,
209 myPlast);
210 aSelection->Add(seg);
211}
212
213//=======================================================================
214//function : SetColor
215//purpose :
216//=======================================================================
217
218
219void AIS_Axis::SetColor(const Quantity_NameOfColor aCol)
220#ifdef GER61351
221{
222 SetColor(Quantity_Color(aCol));
223}
224
225void AIS_Axis::SetColor(const Quantity_Color &aCol)
226#endif
227{
228 hasOwnColor=Standard_True;
229 myOwnColor=aCol;
230 myDrawer->LineAspect()->SetColor(aCol);
231
232 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
233 DA->FirstAxisAspect()->SetColor(aCol);
234 DA->SecondAxisAspect()->SetColor(aCol);
235 DA->ThirdAxisAspect()->SetColor(aCol);
236
237}
238
239//=======================================================================
240//function : SetWidth
241//purpose :
242//=======================================================================
243void AIS_Axis::SetWidth(const Standard_Real aValue)
244{
245
246 if(aValue<0.0) return;
247 if(aValue==0) UnsetWidth();
248
249 myDrawer->LineAspect()->SetWidth(aValue);
250
251 const Handle(Prs3d_DatumAspect)& DA = myDrawer->DatumAspect();
252 DA->FirstAxisAspect()->SetWidth(aValue);
253 DA->SecondAxisAspect()->SetWidth(aValue);
254 DA->ThirdAxisAspect()->SetWidth(aValue);
255}
256
257
258//=======================================================================
259//function : Compute
260//purpose : to avoid warning
261//=======================================================================
262void AIS_Axis::Compute(const Handle(PrsMgr_PresentationManager2d)&,
263 const Handle(Graphic2d_GraphicObject)&,
264 const Standard_Integer)
265{
266}
267
268//=======================================================================
269//function : Compute
270//purpose : to avoid warning
271//=======================================================================
272void AIS_Axis::Compute(const Handle(Prs3d_Projector)&,
273 const Handle(Prs3d_Presentation)&)
274{
275}
276
277//=======================================================================
278//function : ComputeFields
279//purpose :
280//=======================================================================
281void AIS_Axis::ComputeFields()
282{
283 if (myIsXYZAxis){
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);
293
294 switch (myTypeOfAxis) {
295 case AIS_TOAX_XAxis:
296 {
297 oX.Coord(x,y,z);
298 myVal = DA->FirstAxisLength();
299 myDir = oX;
300 myLineAspect = DA->FirstAxisAspect();
301 myText = Standard_CString ("X");
302 break;
303 }
304 case AIS_TOAX_YAxis:
305 {
306 oY.Coord(x,y,z);
307 myVal = DA->SecondAxisLength();
308 myDir = oY;
309 myLineAspect = DA->SecondAxisAspect();
310 myText = Standard_CString ("Y");
311 break;
312 }
313 case AIS_TOAX_ZAxis:
314 {
315 oZ.Coord(x,y,z);
316 myVal = DA->ThirdAxisLength();
317 myDir = oZ;
318 myLineAspect = DA->ThirdAxisAspect();
319 myText = Standard_CString ("Z");
320 break;
321 }
322 default:
323 break;
324 }
325
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);
329 SetInfiniteState();
330 }
331}
332
333//=======================================================================
334//function : AcceptDisplayMode
335//purpose :
336//=======================================================================
337
338 Standard_Boolean AIS_Axis::
339AcceptDisplayMode(const Standard_Integer aMode) const
340{return aMode == 0;}
341
342//=======================================================================
343//function : UnsetColor
344//purpose :
345//=======================================================================
346void AIS_Axis::UnsetColor()
347{
348
349 myDrawer->LineAspect()->SetColor(Quantity_NOC_RED);
350
351 hasOwnColor=Standard_False;
352
353 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
354 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
355 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(Quantity_NOC_TURQUOISE);
356}
357//=======================================================================
358//function : UnsetWidth
359//purpose :
360//=======================================================================
361
362void AIS_Axis::UnsetWidth()
363{
364 myOwnWidth = 0.0;
365 myDrawer->LineAspect()->SetWidth(1.);
366 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
367 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
368 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);
369}
370