0024428: Implementation of LGPL license
[occt.git] / src / AIS / AIS_Drawer.cxx
1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and / or modify it
7 // under the terms of the GNU Lesser General Public version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <AIS_Drawer.ixx>
16 #include <Standard_ProgramError.hxx>
17
18 // =======================================================================
19 // function : AIS_Drawer
20 // purpose  :
21 // =======================================================================
22 AIS_Drawer::AIS_Drawer()
23 : myLink (new Prs3d_Drawer()),
24   hasLocalAttributes (Standard_False),
25   myhasOwnDeviationCoefficient (Standard_False),
26   myPreviousDeviationCoefficient (0.1),
27   myhasOwnHLRDeviationCoefficient (Standard_False),
28   myhasOwnDeviationAngle (Standard_False),
29   myhasOwnHLRDeviationAngle (Standard_False),
30   myHasOwnFaceBoundaryDraw (Standard_False)
31 {
32   SetMaximalParameterValue (500000.0);
33   myLink->SetMaximalParameterValue (500000.0);
34   SetTypeOfHLR (Prs3d_TOH_NotSet);
35 }
36
37 Aspect_TypeOfDeflection AIS_Drawer::TypeOfDeflection () const 
38 {
39   return myLink->TypeOfDeflection();
40 }
41
42 Standard_Boolean AIS_Drawer::IsoOnPlane() const 
43 {
44     return myLink->IsoOnPlane();
45 }
46
47 Standard_Integer AIS_Drawer::Discretisation() const 
48 {
49   return myLink->Discretisation();
50 }
51
52 Quantity_Length AIS_Drawer::MaximalChordialDeviation() const 
53 {
54   return myLink->MaximalChordialDeviation();
55 }
56
57
58 //=======================================================================
59 //function : SetDeviationCoefficient
60 //purpose  : 
61 //=======================================================================
62
63 void AIS_Drawer::SetDeviationCoefficient ( const Standard_Real  aCoefficient )
64 {
65   myPreviousDeviationCoefficient = DeviationCoefficient() ;
66   myOwnDeviationCoefficient     = aCoefficient ;
67   myhasOwnDeviationCoefficient    = Standard_True; 
68 }
69
70
71 //=======================================================================
72 //function : SetHLRDeviationCoefficient
73 //purpose  : 
74 //=======================================================================
75
76 void AIS_Drawer::SetHLRDeviationCoefficient ( const Standard_Real  aCoefficient ) 
77 {
78   myPreviousHLRDeviationCoefficient = HLRDeviationCoefficient() ;
79   myOwnHLRDeviationCoefficient     = aCoefficient ;
80   myhasOwnHLRDeviationCoefficient    = Standard_True; 
81 }
82
83 //=======================================================================
84 //function : SetDeviationAngle
85 //purpose  : 
86 //=======================================================================
87
88 void AIS_Drawer::SetDeviationAngle ( const Standard_Real anAngle ) 
89 {
90   myPreviousDeviationAngle = DeviationAngle() ;
91   myOwnDeviationAngle     = anAngle ;
92   myhasOwnDeviationAngle    = Standard_True;   
93 }
94
95 //=======================================================================
96 //function : SetHLRAngle
97 //purpose  : 
98 //=======================================================================
99
100 void AIS_Drawer::SetHLRAngle ( const Standard_Real anAngle ) 
101 {
102   myPreviousHLRDeviationAngle = HLRAngle() ;
103   myOwnHLRDeviationAngle     = anAngle ;
104   myhasOwnHLRDeviationAngle    = Standard_True;   
105 }
106
107 /////// Get
108 //=======================================================================
109 //function : DeviationCoefficient
110 //purpose  : 
111 //=======================================================================
112
113 Standard_Real AIS_Drawer::DeviationCoefficient ()  const 
114 {
115   return myhasOwnDeviationCoefficient? myOwnDeviationCoefficient :myLink->DeviationCoefficient();
116 }
117
118 //=======================================================================
119 //function : HLRDeviationCoefficient
120 //purpose  : 
121 //=======================================================================
122
123 Standard_Real AIS_Drawer::HLRDeviationCoefficient ()  const 
124 {
125   return myhasOwnHLRDeviationCoefficient?myOwnHLRDeviationCoefficient : myLink->HLRDeviationCoefficient() ;
126 }
127
128 //=======================================================================
129 //function : DeviationAngle
130 //purpose  : 
131 //=======================================================================
132
133 Standard_Real AIS_Drawer::DeviationAngle ()  const 
134 {
135   return myhasOwnDeviationAngle ? myOwnDeviationAngle :  myLink->DeviationAngle();
136 }
137
138 //=======================================================================
139 //function : HLRAngle
140 //purpose  : 
141 //=======================================================================
142
143 Standard_Real AIS_Drawer::HLRAngle ()  const 
144 {
145   
146   return myhasOwnHLRDeviationAngle ?  myOwnHLRDeviationAngle : myLink->HLRAngle();
147 }
148
149 Standard_Real AIS_Drawer::MaximalParameterValue () const 
150 { return myLink->MaximalParameterValue();}
151
152 Handle (Prs3d_IsoAspect) AIS_Drawer::UIsoAspect ()  
153 { return myUIsoAspect.IsNull() ? myLink->UIsoAspect (): myUIsoAspect;}
154
155 Handle (Prs3d_IsoAspect) AIS_Drawer::VIsoAspect () 
156 { return myVIsoAspect.IsNull() ? myLink->VIsoAspect (): myVIsoAspect;}
157
158 Handle (Prs3d_LineAspect) AIS_Drawer::FreeBoundaryAspect () 
159 {return myFreeBoundaryAspect.IsNull() ? myLink->FreeBoundaryAspect (): myFreeBoundaryAspect;}
160
161 Standard_Boolean AIS_Drawer::FreeBoundaryDraw () const 
162 {return myLink->FreeBoundaryDraw();}
163
164 Handle (Prs3d_LineAspect) AIS_Drawer::UnFreeBoundaryAspect ()  
165 {return myUnFreeBoundaryAspect.IsNull() ? myLink->UnFreeBoundaryAspect (): myUnFreeBoundaryAspect;}
166
167 Standard_Boolean AIS_Drawer::UnFreeBoundaryDraw ()  const  
168 {return myLink->UnFreeBoundaryDraw ();}
169
170 Handle (Prs3d_LineAspect) AIS_Drawer::WireAspect ()
171 {  return myWireAspect.IsNull()? myLink->WireAspect (): myWireAspect;}
172
173 Standard_Boolean AIS_Drawer::WireDraw ()  const 
174 { return myLink->WireDraw();}
175
176 Handle (Prs3d_LineAspect) AIS_Drawer::LineAspect ()  
177 { return myLineAspect.IsNull() ? myLink->LineAspect (): myLineAspect;}
178
179 Handle (Prs3d_TextAspect) AIS_Drawer::TextAspect ()  
180 { return myTextAspect.IsNull() ? myLink->TextAspect () : myTextAspect ;}
181
182 Handle (Prs3d_ShadingAspect) AIS_Drawer::ShadingAspect ()
183 {
184 return myShadingAspect.IsNull() ? myLink->ShadingAspect ()  : myShadingAspect ;
185 }
186
187 Standard_Boolean AIS_Drawer::ShadingAspectGlobal()  const 
188 { return myLink->ShadingAspectGlobal();}
189  
190
191 Standard_Boolean AIS_Drawer::LineArrowDraw ()  const 
192 { return myLink->LineArrowDraw();}
193
194 Handle (Prs3d_ArrowAspect) AIS_Drawer::ArrowAspect() 
195 {return myArrowAspect.IsNull()?  myLink->ArrowAspect () :  myArrowAspect;}
196
197 Handle (Prs3d_PointAspect) AIS_Drawer::PointAspect() 
198 {return myPointAspect.IsNull()?  myLink->PointAspect () :  myPointAspect;}
199
200 Standard_Boolean AIS_Drawer::DrawHiddenLine ()  const 
201 {return myLink->DrawHiddenLine();}
202
203 Handle (Prs3d_LineAspect) AIS_Drawer::HiddenLineAspect ()  
204 {return  myHiddenLineAspect.IsNull()?  myLink->HiddenLineAspect () : myHiddenLineAspect;}
205
206 Handle (Prs3d_LineAspect) AIS_Drawer::SeenLineAspect ()  
207 { return mySeenLineAspect.IsNull() ? myLink->SeenLineAspect (): mySeenLineAspect ;}
208
209 Handle (Prs3d_LineAspect) AIS_Drawer::VectorAspect ()  
210 {return myVectorAspect.IsNull()?  myLink->VectorAspect () : myVectorAspect;}
211
212 Handle (Prs3d_DatumAspect) AIS_Drawer::DatumAspect () 
213 {return myDatumAspect.IsNull()?  myLink->DatumAspect () : myDatumAspect; }
214
215 Handle (Prs3d_PlaneAspect) AIS_Drawer::PlaneAspect () 
216 {return myPlaneAspect.IsNull() ? myLink->PlaneAspect (): myPlaneAspect;}
217
218 // =======================================================================
219 // function : DimensionAspect
220 // purpose  :
221 // =======================================================================
222 Handle (Prs3d_DimensionAspect) AIS_Drawer::DimensionAspect()
223 {
224   return myDimensionAspect.IsNull()? myLink->DimensionAspect () : myDimensionAspect;
225 }
226
227 // =======================================================================
228 // function : DimAngleModelUnits
229 // purpose  :
230 // =======================================================================
231 const TCollection_AsciiString& AIS_Drawer::DimAngleModelUnits() const
232 {
233   return myHasOwnDimAngleModelUnits
234     ? Prs3d_Drawer::DimAngleModelUnits()
235     : myLink->DimAngleModelUnits();
236 }
237
238 // =======================================================================
239 // function : DimensionModelUnits
240 // purpose  :
241 // =======================================================================
242 const TCollection_AsciiString& AIS_Drawer::DimLengthModelUnits() const
243 {
244   return myHasOwnDimLengthModelUnits
245     ? Prs3d_Drawer::DimLengthModelUnits()
246     : myLink->DimLengthModelUnits();
247 }
248 // =======================================================================
249 // function : SetDimLengthModelUnits
250 // purpose  :
251 // =======================================================================
252 void AIS_Drawer::SetDimLengthModelUnits (const TCollection_AsciiString& theUnits)
253 {
254   myHasOwnDimLengthModelUnits = Standard_True;
255   Prs3d_Drawer::SetDimLengthDisplayUnits (theUnits);
256 }
257
258 // =======================================================================
259 // function : SetDimAngleModelUnits
260 // purpose  :
261 // =======================================================================
262 void AIS_Drawer::SetDimAngleModelUnits (const TCollection_AsciiString& theUnits)
263 {
264   myHasOwnDimAngleModelUnits = Standard_True;
265   Prs3d_Drawer::SetDimAngleDisplayUnits (theUnits);
266 }
267
268 // =======================================================================
269 // function : DimAngleDisplayUnits
270 // purpose  :
271 // =======================================================================
272 const TCollection_AsciiString& AIS_Drawer::DimAngleDisplayUnits() const
273 {
274   return myHasOwnDimAngleDisplayUnits
275     ? Prs3d_Drawer::DimAngleDisplayUnits()
276     : myLink->DimAngleDisplayUnits();
277 }
278
279 // =======================================================================
280 // function : DimLengthDisplayUnits
281 // purpose  :
282 // =======================================================================
283 const TCollection_AsciiString& AIS_Drawer::DimLengthDisplayUnits() const
284 {
285   return myHasOwnDimLengthDisplayUnits
286     ? Prs3d_Drawer::DimLengthDisplayUnits()
287     : myLink->DimLengthDisplayUnits();
288 }
289
290 // =======================================================================
291 // function : SetDimLengthDisplayUnits
292 // purpose  :
293 // =======================================================================
294 void AIS_Drawer::SetDimLengthDisplayUnits (const TCollection_AsciiString& theUnits)
295 {
296   myHasOwnDimLengthDisplayUnits = Standard_True;
297   Prs3d_Drawer::SetDimLengthDisplayUnits (theUnits);
298 }
299
300 // =======================================================================
301 // function : SetDimAngleDisplayUnits
302 // purpose  :
303 // =======================================================================
304 void AIS_Drawer::SetDimAngleDisplayUnits (const TCollection_AsciiString& theUnits)
305 {
306   myHasOwnDimAngleDisplayUnits = Standard_True;
307   Prs3d_Drawer::SetDimAngleDisplayUnits (theUnits);
308 }
309
310 Handle (Prs3d_LineAspect) AIS_Drawer::SectionAspect ()
311 {return mySectionAspect.IsNull()? myLink->SectionAspect (): mySectionAspect;}
312
313 const Handle (Prs3d_Drawer)& AIS_Drawer::Link()  
314
315   if(myLink.IsNull()) myLink =  new Prs3d_Drawer();
316   return myLink;
317  }
318
319 void AIS_Drawer::ClearLocalAttributes()
320 {
321   if(myLink.IsNull()) return;
322 // attention pas beau....
323 // The Handles
324
325   if(!myUIsoAspect.IsNull()) myUIsoAspect.Nullify();
326   if(!myVIsoAspect.IsNull()) myVIsoAspect.Nullify();
327   if(!myFreeBoundaryAspect.IsNull())  myFreeBoundaryAspect.Nullify();  
328   if(!myUnFreeBoundaryAspect.IsNull())  myUnFreeBoundaryAspect.Nullify();
329   if(!myWireAspect.IsNull())  myWireAspect.Nullify();          
330   if(!myLineAspect.IsNull())  myLineAspect.Nullify();          
331   if(!myTextAspect.IsNull())  myTextAspect.Nullify();   
332   if(!myShadingAspect.IsNull())  myShadingAspect.Nullify();
333   if(!myPointAspect.IsNull())  myPointAspect.Nullify();  
334   if(!myPlaneAspect.IsNull())  myPlaneAspect.Nullify();  
335   if(!myArrowAspect.IsNull())  myArrowAspect.Nullify();  
336   if(!myHiddenLineAspect.IsNull())  myHiddenLineAspect.Nullify();
337   if(!mySeenLineAspect.IsNull())  mySeenLineAspect.Nullify();  
338   if(!myVectorAspect.IsNull())  myVectorAspect .Nullify();   
339   if(!myDatumAspect.IsNull())  myDatumAspect.Nullify();     
340   if(!myDimensionAspect.IsNull())  myDimensionAspect.Nullify();    
341   if(!mySectionAspect.IsNull())  mySectionAspect.Nullify();   
342   if( myhasOwnHLRDeviationCoefficient )  myhasOwnHLRDeviationCoefficient = Standard_False;   
343   if(myhasOwnHLRDeviationAngle ) myhasOwnHLRDeviationAngle  = Standard_False;
344   if (!myFaceBoundaryAspect.IsNull()) myFaceBoundaryAspect.Nullify();
345   
346   myHasOwnFaceBoundaryDraw = Standard_False;
347   myHasOwnDimLengthModelUnits = Standard_False;
348   myHasOwnDimLengthDisplayUnits = Standard_False;
349   myHasOwnDimAngleModelUnits = Standard_False;
350   myHasOwnDimAngleDisplayUnits = Standard_False;
351
352   hasLocalAttributes = Standard_False;
353
354 }
355
356 // =======================================================================
357 // function : SetFaceBoundaryDraw
358 // purpose  :
359 // =======================================================================
360 void AIS_Drawer::SetFaceBoundaryDraw (const Standard_Boolean theIsEnabled)
361 {
362   myHasOwnFaceBoundaryDraw = Standard_True;
363   myFaceBoundaryDraw       = theIsEnabled;
364 }
365
366 // =======================================================================
367 // function : IsFaceBoundaryDraw
368 // purpose  :
369 // =======================================================================
370 Standard_Boolean AIS_Drawer::IsFaceBoundaryDraw() const
371 {
372   if (!IsOwnFaceBoundaryDraw ())
373   {
374     return myLink->IsFaceBoundaryDraw ();
375   }
376
377   return myFaceBoundaryDraw;
378 }
379
380 // =======================================================================
381 // function : SetFaceBoundaryAspect
382 // purpose  :
383 // =======================================================================
384 void AIS_Drawer::SetFaceBoundaryAspect (const Handle(Prs3d_LineAspect)& theAspect)
385 {
386   myFaceBoundaryAspect = theAspect;
387 }
388
389 // =======================================================================
390 // function : FaceBoundaryAspect
391 // purpose  :
392 // =======================================================================
393 Handle_Prs3d_LineAspect AIS_Drawer::FaceBoundaryAspect()
394 {
395   if (!IsOwnFaceBoundaryAspect ())
396   {
397     return myLink->FaceBoundaryAspect ();
398   }
399
400   return myFaceBoundaryAspect;
401 }