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