0025773: Visualization - remove AIS_Drawer class and transfer its Link() logic to...
[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 under
7 // the terms of the GNU Lesser General Public License 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   myHasOwnDimLengthModelUnits (Standard_False),
32   myHasOwnDimLengthDisplayUnits (Standard_False),
33   myHasOwnDimAngleModelUnits (Standard_False),
34   myHasOwnDimAngleDisplayUnits (Standard_False)
35 {
36   SetMaximalParameterValue (500000.0);
37   myLink->SetMaximalParameterValue (500000.0);
38   SetTypeOfHLR (Prs3d_TOH_NotSet);
39   SetVertexDrawMode (Prs3d_VDM_Inherited);
40 }
41
42 Aspect_TypeOfDeflection AIS_Drawer::TypeOfDeflection () const 
43 {
44   return myLink->TypeOfDeflection();
45 }
46
47 Standard_Boolean AIS_Drawer::IsoOnPlane() const 
48 {
49     return myLink->IsoOnPlane();
50 }
51
52 Standard_Integer AIS_Drawer::Discretisation() const 
53 {
54   return myLink->Discretisation();
55 }
56
57 Quantity_Length AIS_Drawer::MaximalChordialDeviation() const 
58 {
59   return myLink->MaximalChordialDeviation();
60 }
61
62
63 //=======================================================================
64 //function : SetDeviationCoefficient
65 //purpose  : 
66 //=======================================================================
67
68 void AIS_Drawer::SetDeviationCoefficient ( const Standard_Real  aCoefficient )
69 {
70   myPreviousDeviationCoefficient = DeviationCoefficient() ;
71   myOwnDeviationCoefficient     = aCoefficient ;
72   myhasOwnDeviationCoefficient    = Standard_True; 
73 }
74
75
76 //=======================================================================
77 //function : SetHLRDeviationCoefficient
78 //purpose  : 
79 //=======================================================================
80
81 void AIS_Drawer::SetHLRDeviationCoefficient ( const Standard_Real  aCoefficient ) 
82 {
83   myPreviousHLRDeviationCoefficient = HLRDeviationCoefficient() ;
84   myOwnHLRDeviationCoefficient     = aCoefficient ;
85   myhasOwnHLRDeviationCoefficient    = Standard_True; 
86 }
87
88 //=======================================================================
89 //function : SetDeviationAngle
90 //purpose  : 
91 //=======================================================================
92
93 void AIS_Drawer::SetDeviationAngle ( const Standard_Real anAngle ) 
94 {
95   myPreviousDeviationAngle = DeviationAngle() ;
96   myOwnDeviationAngle     = anAngle ;
97   myhasOwnDeviationAngle    = Standard_True;   
98 }
99
100 //=======================================================================
101 //function : SetHLRAngle
102 //purpose  : 
103 //=======================================================================
104
105 void AIS_Drawer::SetHLRAngle ( const Standard_Real anAngle ) 
106 {
107   myPreviousHLRDeviationAngle = HLRAngle() ;
108   myOwnHLRDeviationAngle     = anAngle ;
109   myhasOwnHLRDeviationAngle    = Standard_True;   
110 }
111
112 /////// Get
113 //=======================================================================
114 //function : DeviationCoefficient
115 //purpose  : 
116 //=======================================================================
117
118 Standard_Real AIS_Drawer::DeviationCoefficient ()  const 
119 {
120   return myhasOwnDeviationCoefficient? myOwnDeviationCoefficient :myLink->DeviationCoefficient();
121 }
122
123 //=======================================================================
124 //function : HLRDeviationCoefficient
125 //purpose  : 
126 //=======================================================================
127
128 Standard_Real AIS_Drawer::HLRDeviationCoefficient ()  const 
129 {
130   return myhasOwnHLRDeviationCoefficient?myOwnHLRDeviationCoefficient : myLink->HLRDeviationCoefficient() ;
131 }
132
133 //=======================================================================
134 //function : DeviationAngle
135 //purpose  : 
136 //=======================================================================
137
138 Standard_Real AIS_Drawer::DeviationAngle ()  const 
139 {
140   return myhasOwnDeviationAngle ? myOwnDeviationAngle :  myLink->DeviationAngle();
141 }
142
143 //=======================================================================
144 //function : HLRAngle
145 //purpose  : 
146 //=======================================================================
147
148 Standard_Real AIS_Drawer::HLRAngle ()  const 
149 {
150   
151   return myhasOwnHLRDeviationAngle ?  myOwnHLRDeviationAngle : myLink->HLRAngle();
152 }
153
154 Standard_Real AIS_Drawer::MaximalParameterValue () const 
155 { return myLink->MaximalParameterValue();}
156
157 Handle (Prs3d_IsoAspect) AIS_Drawer::UIsoAspect ()  
158 { return myUIsoAspect.IsNull() ? myLink->UIsoAspect (): myUIsoAspect;}
159
160 Handle (Prs3d_IsoAspect) AIS_Drawer::VIsoAspect () 
161 { return myVIsoAspect.IsNull() ? myLink->VIsoAspect (): myVIsoAspect;}
162
163 Handle (Prs3d_LineAspect) AIS_Drawer::FreeBoundaryAspect () 
164 {return myFreeBoundaryAspect.IsNull() ? myLink->FreeBoundaryAspect (): myFreeBoundaryAspect;}
165
166 Standard_Boolean AIS_Drawer::FreeBoundaryDraw () const 
167 {return myLink->FreeBoundaryDraw();}
168
169 Handle (Prs3d_LineAspect) AIS_Drawer::UnFreeBoundaryAspect ()  
170 {return myUnFreeBoundaryAspect.IsNull() ? myLink->UnFreeBoundaryAspect (): myUnFreeBoundaryAspect;}
171
172 Standard_Boolean AIS_Drawer::UnFreeBoundaryDraw ()  const  
173 {return myLink->UnFreeBoundaryDraw ();}
174
175 Handle (Prs3d_LineAspect) AIS_Drawer::WireAspect ()
176 {  return myWireAspect.IsNull()? myLink->WireAspect (): myWireAspect;}
177
178 Standard_Boolean AIS_Drawer::WireDraw ()  const 
179 { return myLink->WireDraw();}
180
181 Handle (Prs3d_LineAspect) AIS_Drawer::LineAspect ()  
182 { return myLineAspect.IsNull() ? myLink->LineAspect (): myLineAspect;}
183
184 Handle (Prs3d_TextAspect) AIS_Drawer::TextAspect ()  
185 { return myTextAspect.IsNull() ? myLink->TextAspect () : myTextAspect ;}
186
187 Handle (Prs3d_ShadingAspect) AIS_Drawer::ShadingAspect ()
188 {
189 return myShadingAspect.IsNull() ? myLink->ShadingAspect ()  : myShadingAspect ;
190 }
191
192 Standard_Boolean AIS_Drawer::ShadingAspectGlobal()  const 
193 { return myLink->ShadingAspectGlobal();}
194  
195
196 Standard_Boolean AIS_Drawer::LineArrowDraw ()  const 
197 { return myLink->LineArrowDraw();}
198
199 Handle (Prs3d_ArrowAspect) AIS_Drawer::ArrowAspect() 
200 {return myArrowAspect.IsNull()?  myLink->ArrowAspect () :  myArrowAspect;}
201
202 Handle (Prs3d_PointAspect) AIS_Drawer::PointAspect() 
203 {return myPointAspect.IsNull()?  myLink->PointAspect () :  myPointAspect;}
204
205 void AIS_Drawer::SetVertexDrawMode (const Prs3d_VertexDrawMode theMode)
206 {
207   // Assuming that myLink always exists --> Prs3d_VDM_Inherited value is acceptable.
208   // So we simply store the new mode, as opposed to Prs3d_Drawer::SetVertexDrawMode()
209   myVertexDrawMode = theMode;
210 }
211
212 Prs3d_VertexDrawMode AIS_Drawer::VertexDrawMode () const
213 {
214   return IsOwnVertexDrawMode() ? myVertexDrawMode : myLink->VertexDrawMode();
215 }
216
217 Standard_Boolean AIS_Drawer::DrawHiddenLine ()  const 
218 {return myLink->DrawHiddenLine();}
219
220 Handle (Prs3d_LineAspect) AIS_Drawer::HiddenLineAspect ()  
221 {return  myHiddenLineAspect.IsNull()?  myLink->HiddenLineAspect () : myHiddenLineAspect;}
222
223 Handle (Prs3d_LineAspect) AIS_Drawer::SeenLineAspect ()  
224 { return mySeenLineAspect.IsNull() ? myLink->SeenLineAspect (): mySeenLineAspect ;}
225
226 Handle (Prs3d_LineAspect) AIS_Drawer::VectorAspect ()  
227 {return myVectorAspect.IsNull()?  myLink->VectorAspect () : myVectorAspect;}
228
229 Handle (Prs3d_DatumAspect) AIS_Drawer::DatumAspect () 
230 {return myDatumAspect.IsNull()?  myLink->DatumAspect () : myDatumAspect; }
231
232 Handle (Prs3d_PlaneAspect) AIS_Drawer::PlaneAspect () 
233 {return myPlaneAspect.IsNull() ? myLink->PlaneAspect (): myPlaneAspect;}
234
235 // =======================================================================
236 // function : DimensionAspect
237 // purpose  :
238 // =======================================================================
239 Handle (Prs3d_DimensionAspect) AIS_Drawer::DimensionAspect()
240 {
241   return myDimensionAspect.IsNull()? myLink->DimensionAspect () : myDimensionAspect;
242 }
243
244 // =======================================================================
245 // function : DimAngleModelUnits
246 // purpose  :
247 // =======================================================================
248 const TCollection_AsciiString& AIS_Drawer::DimAngleModelUnits() const
249 {
250   return myHasOwnDimAngleModelUnits
251     ? Prs3d_Drawer::DimAngleModelUnits()
252     : myLink->DimAngleModelUnits();
253 }
254
255 // =======================================================================
256 // function : DimensionModelUnits
257 // purpose  :
258 // =======================================================================
259 const TCollection_AsciiString& AIS_Drawer::DimLengthModelUnits() const
260 {
261   return myHasOwnDimLengthModelUnits
262     ? Prs3d_Drawer::DimLengthModelUnits()
263     : myLink->DimLengthModelUnits();
264 }
265 // =======================================================================
266 // function : SetDimLengthModelUnits
267 // purpose  :
268 // =======================================================================
269 void AIS_Drawer::SetDimLengthModelUnits (const TCollection_AsciiString& theUnits)
270 {
271   myHasOwnDimLengthModelUnits = Standard_True;
272   Prs3d_Drawer::SetDimLengthModelUnits (theUnits);
273 }
274
275 // =======================================================================
276 // function : SetDimAngleModelUnits
277 // purpose  :
278 // =======================================================================
279 void AIS_Drawer::SetDimAngleModelUnits (const TCollection_AsciiString& theUnits)
280 {
281   myHasOwnDimAngleModelUnits = Standard_True;
282   Prs3d_Drawer::SetDimAngleModelUnits (theUnits);
283 }
284
285 // =======================================================================
286 // function : DimAngleDisplayUnits
287 // purpose  :
288 // =======================================================================
289 const TCollection_AsciiString& AIS_Drawer::DimAngleDisplayUnits() const
290 {
291   return myHasOwnDimAngleDisplayUnits
292     ? Prs3d_Drawer::DimAngleDisplayUnits()
293     : myLink->DimAngleDisplayUnits();
294 }
295
296 // =======================================================================
297 // function : DimLengthDisplayUnits
298 // purpose  :
299 // =======================================================================
300 const TCollection_AsciiString& AIS_Drawer::DimLengthDisplayUnits() const
301 {
302   return myHasOwnDimLengthDisplayUnits
303     ? Prs3d_Drawer::DimLengthDisplayUnits()
304     : myLink->DimLengthDisplayUnits();
305 }
306
307 // =======================================================================
308 // function : SetDimLengthDisplayUnits
309 // purpose  :
310 // =======================================================================
311 void AIS_Drawer::SetDimLengthDisplayUnits (const TCollection_AsciiString& theUnits)
312 {
313   myHasOwnDimLengthDisplayUnits = Standard_True;
314   Prs3d_Drawer::SetDimLengthDisplayUnits (theUnits);
315 }
316
317 // =======================================================================
318 // function : SetDimAngleDisplayUnits
319 // purpose  :
320 // =======================================================================
321 void AIS_Drawer::SetDimAngleDisplayUnits (const TCollection_AsciiString& theUnits)
322 {
323   myHasOwnDimAngleDisplayUnits = Standard_True;
324   Prs3d_Drawer::SetDimAngleDisplayUnits (theUnits);
325 }
326
327 Handle (Prs3d_LineAspect) AIS_Drawer::SectionAspect ()
328 {return mySectionAspect.IsNull()? myLink->SectionAspect (): mySectionAspect;}
329
330 const Handle (Prs3d_Drawer)& AIS_Drawer::Link()  
331
332   if(myLink.IsNull()) myLink =  new Prs3d_Drawer();
333   return myLink;
334  }
335
336 void AIS_Drawer::ClearLocalAttributes()
337 {
338   if(myLink.IsNull()) return;
339 // attention pas beau....
340 // The Handles
341
342   if(!myUIsoAspect.IsNull()) myUIsoAspect.Nullify();
343   if(!myVIsoAspect.IsNull()) myVIsoAspect.Nullify();
344   if(!myFreeBoundaryAspect.IsNull())  myFreeBoundaryAspect.Nullify();  
345   if(!myUnFreeBoundaryAspect.IsNull())  myUnFreeBoundaryAspect.Nullify();
346   if(!myWireAspect.IsNull())  myWireAspect.Nullify();          
347   if(!myLineAspect.IsNull())  myLineAspect.Nullify();          
348   if(!myTextAspect.IsNull())  myTextAspect.Nullify();   
349   if(!myShadingAspect.IsNull())  myShadingAspect.Nullify();
350   if(!myPointAspect.IsNull())  myPointAspect.Nullify();  
351   if(!myPlaneAspect.IsNull())  myPlaneAspect.Nullify();  
352   if(!myArrowAspect.IsNull())  myArrowAspect.Nullify();  
353   if(!myHiddenLineAspect.IsNull())  myHiddenLineAspect.Nullify();
354   if(!mySeenLineAspect.IsNull())  mySeenLineAspect.Nullify();  
355   if(!myVectorAspect.IsNull())  myVectorAspect .Nullify();   
356   if(!myDatumAspect.IsNull())  myDatumAspect.Nullify();     
357   if(!myDimensionAspect.IsNull())  myDimensionAspect.Nullify();    
358   if(!mySectionAspect.IsNull())  mySectionAspect.Nullify();   
359   if( myhasOwnHLRDeviationCoefficient )  myhasOwnHLRDeviationCoefficient = Standard_False;   
360   if(myhasOwnHLRDeviationAngle ) myhasOwnHLRDeviationAngle  = Standard_False;
361   if (!myFaceBoundaryAspect.IsNull()) myFaceBoundaryAspect.Nullify();
362   
363   myHasOwnFaceBoundaryDraw = Standard_False;
364   myHasOwnDimLengthModelUnits = Standard_False;
365   myHasOwnDimLengthDisplayUnits = Standard_False;
366   myHasOwnDimAngleModelUnits = Standard_False;
367   myHasOwnDimAngleDisplayUnits = Standard_False;
368
369   hasLocalAttributes = Standard_False;
370
371 }
372
373 // =======================================================================
374 // function : SetFaceBoundaryDraw
375 // purpose  :
376 // =======================================================================
377 void AIS_Drawer::SetFaceBoundaryDraw (const Standard_Boolean theIsEnabled)
378 {
379   myHasOwnFaceBoundaryDraw = Standard_True;
380   myFaceBoundaryDraw       = theIsEnabled;
381 }
382
383 // =======================================================================
384 // function : IsFaceBoundaryDraw
385 // purpose  :
386 // =======================================================================
387 Standard_Boolean AIS_Drawer::IsFaceBoundaryDraw() const
388 {
389   if (!IsOwnFaceBoundaryDraw ())
390   {
391     return myLink->IsFaceBoundaryDraw ();
392   }
393
394   return myFaceBoundaryDraw;
395 }
396
397 // =======================================================================
398 // function : SetFaceBoundaryAspect
399 // purpose  :
400 // =======================================================================
401 void AIS_Drawer::SetFaceBoundaryAspect (const Handle(Prs3d_LineAspect)& theAspect)
402 {
403   myFaceBoundaryAspect = theAspect;
404 }
405
406 // =======================================================================
407 // function : FaceBoundaryAspect
408 // purpose  :
409 // =======================================================================
410 Handle(Prs3d_LineAspect) AIS_Drawer::FaceBoundaryAspect()
411 {
412   if (!IsOwnFaceBoundaryAspect ())
413   {
414     return myLink->FaceBoundaryAspect ();
415   }
416
417   return myFaceBoundaryAspect;
418 }