0024425: Improve usage ergonomics of new dimension presentations
[occt.git] / src / Prs3d / Prs3d_Drawer.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19 #include <Prs3d_Drawer.ixx>
20
21 // =======================================================================
22 // function : Prs3d_Drawer
23 // purpose  :
24 // =======================================================================
25 Prs3d_Drawer::Prs3d_Drawer()
26 : myNbPoints (30),
27   myIsoOnPlane (Standard_False),
28   myFreeBoundaryDraw (Standard_True),
29   myUnFreeBoundaryDraw (Standard_True),
30   myWireDraw (Standard_True),
31   myShadingAspect (new Prs3d_ShadingAspect()),
32   myShadingAspectGlobal (Standard_True),
33   myChordialDeviation (0.0001),
34   myTypeOfDeflection (Aspect_TOD_RELATIVE),
35   myMaximalParameterValue (500000.),
36   myDeviationCoefficient (0.001),
37   myHLRDeviationCoefficient (0.02),
38   myDeviationAngle (12.0 * M_PI / 180.0),
39   myHLRAngle (20.0 * M_PI / 180.0),
40   myLineDrawArrow (Standard_False),
41   myDrawHiddenLine (Standard_False),
42   myFaceBoundaryDraw (Standard_False),
43   myTypeOfHLR (Prs3d_TOH_PolyAlgo)
44 {
45   myDimensionModelUnits.SetLengthUnits ("m");
46   myDimensionModelUnits.SetAngleUnits ("rad");
47   myDimensionDisplayUnits.SetLengthUnits ("m");
48   myDimensionDisplayUnits.SetAngleUnits ("deg");
49 }
50
51 void Prs3d_Drawer::SetTypeOfDeflection(const Aspect_TypeOfDeflection aTypeOfDeflection){
52
53   myTypeOfDeflection = aTypeOfDeflection;}
54
55 Aspect_TypeOfDeflection Prs3d_Drawer::TypeOfDeflection() const {
56
57   return myTypeOfDeflection;
58
59 }
60
61  
62 void Prs3d_Drawer::SetIsoOnPlane(const Standard_Boolean OnOff)
63 {
64   myIsoOnPlane = OnOff;
65 }
66
67  
68 Standard_Boolean Prs3d_Drawer::IsoOnPlane()const
69 {
70   return myIsoOnPlane;
71 }
72
73
74 Standard_Integer Prs3d_Drawer::Discretisation() const
75 {
76   return myNbPoints;
77 }
78
79
80 void Prs3d_Drawer::SetDiscretisation(const Standard_Integer d) 
81 {
82   myNbPoints = d;
83 }
84
85
86 void Prs3d_Drawer::SetMaximalChordialDeviation(
87                                const Quantity_Length aChordialDeviation) {
88   myChordialDeviation = aChordialDeviation;
89 }
90
91 Quantity_Length Prs3d_Drawer::MaximalChordialDeviation() const {
92   return myChordialDeviation;
93 }
94
95 //
96 //=======================================================================
97 //function : SetDeviationCoefficient
98 //purpose  : 
99 //=======================================================================
100
101 void Prs3d_Drawer::SetDeviationCoefficient (const Standard_Real aCoefficient) {
102
103   myDeviationCoefficient = aCoefficient;
104 }
105
106 //=======================================================================
107 //function : DeviationCoefficient
108 //purpose  : 
109 //=======================================================================
110
111 Standard_Real Prs3d_Drawer::DeviationCoefficient () const {
112
113   return myDeviationCoefficient;
114 }
115
116 //=======================================================================
117 //function : SetHLRDeviationCoefficient
118 //purpose  : 
119 //=======================================================================
120
121 void Prs3d_Drawer::SetHLRDeviationCoefficient (const Standard_Real aCoefficient) {
122
123   myHLRDeviationCoefficient = aCoefficient;
124 }
125
126 //=======================================================================
127 //function : HLRDeviationCoefficient
128 //purpose  : 
129 //=======================================================================
130
131 Standard_Real Prs3d_Drawer::HLRDeviationCoefficient () const {
132
133   return myHLRDeviationCoefficient;
134 }
135
136 //=======================================================================
137 //function : SetHLRAngle
138 //purpose  : 
139 //=======================================================================
140
141 void Prs3d_Drawer::SetHLRAngle (const Standard_Real anAngle) {
142
143   myHLRAngle = anAngle;
144 }
145
146 //=======================================================================
147 //function : HLRAngle
148 //purpose  : 
149 //=======================================================================
150
151 Standard_Real Prs3d_Drawer::HLRAngle () const {
152
153   return myHLRAngle;
154 }
155
156 //=======================================================================
157 //function : SetDeviationAngle
158 //purpose  : 
159 //=======================================================================
160
161 void Prs3d_Drawer::SetDeviationAngle (const Standard_Real anAngle)
162 {
163   myDeviationAngle = anAngle;
164 }
165
166 //=======================================================================
167 //function : DeviationAngle
168 //purpose  : 
169 //=======================================================================
170
171 Standard_Real Prs3d_Drawer::DeviationAngle () const 
172 {
173   return myDeviationAngle;
174 }
175
176
177 void Prs3d_Drawer::SetMaximalParameterValue (const Standard_Real Value) {
178   myMaximalParameterValue = Value;
179 }
180
181 Standard_Real Prs3d_Drawer::MaximalParameterValue () const {
182   return myMaximalParameterValue;
183 }
184
185 Handle (Prs3d_IsoAspect) Prs3d_Drawer::UIsoAspect (){
186
187   if (myUIsoAspect.IsNull()) 
188     myUIsoAspect = new Prs3d_IsoAspect
189                    (Quantity_NOC_GRAY75,Aspect_TOL_SOLID,0.5,1);
190
191   return myUIsoAspect;
192 }
193
194 void Prs3d_Drawer::SetUIsoAspect ( const Handle(Prs3d_IsoAspect)& anAspect) {
195  myUIsoAspect = anAspect;
196 }
197
198 Handle (Prs3d_IsoAspect) Prs3d_Drawer::VIsoAspect () {
199   if (myVIsoAspect.IsNull()) 
200     myVIsoAspect = new Prs3d_IsoAspect
201       (Quantity_NOC_GRAY75,Aspect_TOL_SOLID,0.5,1);
202       
203   return myVIsoAspect;
204 }
205
206 void Prs3d_Drawer::SetVIsoAspect ( const Handle(Prs3d_IsoAspect)& anAspect) {
207  myVIsoAspect = anAspect;
208 }
209
210 Handle (Prs3d_LineAspect) Prs3d_Drawer::FreeBoundaryAspect () {
211   if (myFreeBoundaryAspect.IsNull())
212     myFreeBoundaryAspect = new Prs3d_LineAspect
213       (Quantity_NOC_GREEN,Aspect_TOL_SOLID,1.);
214
215   return myFreeBoundaryAspect;
216 }
217
218 void Prs3d_Drawer::SetFreeBoundaryAspect (const Handle(Prs3d_LineAspect)& anAspect) {
219  myFreeBoundaryAspect = anAspect;
220 }
221
222 void Prs3d_Drawer::SetFreeBoundaryDraw ( const Standard_Boolean OnOff ) {
223   myFreeBoundaryDraw = OnOff;
224 }
225
226 Standard_Boolean Prs3d_Drawer::FreeBoundaryDraw () const {
227 return myFreeBoundaryDraw;
228 }
229
230 Handle (Prs3d_LineAspect) Prs3d_Drawer::UnFreeBoundaryAspect (){
231   if  (myUnFreeBoundaryAspect.IsNull())
232     myUnFreeBoundaryAspect = new Prs3d_LineAspect
233       (Quantity_NOC_YELLOW,Aspect_TOL_SOLID,1.);
234   return myUnFreeBoundaryAspect;
235 }
236
237 void Prs3d_Drawer::SetUnFreeBoundaryAspect ( const Handle(Prs3d_LineAspect)& anAspect) {
238  myUnFreeBoundaryAspect = anAspect;
239 }
240
241 void Prs3d_Drawer::SetUnFreeBoundaryDraw ( const Standard_Boolean OnOff ) {
242   myUnFreeBoundaryDraw = OnOff;
243 }
244
245 Standard_Boolean Prs3d_Drawer::UnFreeBoundaryDraw () const {
246   return myUnFreeBoundaryDraw;
247 }
248
249 Handle (Prs3d_LineAspect) Prs3d_Drawer::WireAspect ()  {
250   if (myWireAspect.IsNull())
251    myWireAspect = new Prs3d_LineAspect(Quantity_NOC_RED,Aspect_TOL_SOLID,1.);
252
253   return myWireAspect;
254 }
255
256 void Prs3d_Drawer::SetWireAspect ( const Handle(Prs3d_LineAspect)& anAspect) {
257  myWireAspect = anAspect;
258 }
259 void Prs3d_Drawer::SetWireDraw ( const Standard_Boolean OnOff ) {
260   myWireDraw = OnOff;
261 }
262
263 Standard_Boolean Prs3d_Drawer::WireDraw () const {
264 return myWireDraw;
265 }
266
267
268 Handle (Prs3d_LineAspect) Prs3d_Drawer::LineAspect ()  {
269   if (myLineAspect.IsNull())
270     myLineAspect = new Prs3d_LineAspect
271       (Quantity_NOC_YELLOW,Aspect_TOL_SOLID,1.);
272   return myLineAspect;
273 }
274
275 void Prs3d_Drawer::SetLineAspect ( const Handle(Prs3d_LineAspect)& anAspect) {
276  myLineAspect = anAspect;
277 }
278
279 Handle (Prs3d_TextAspect) Prs3d_Drawer::TextAspect ()  {
280   if (myTextAspect.IsNull())
281     myTextAspect = new Prs3d_TextAspect();
282
283   return myTextAspect;
284 }
285
286 void Prs3d_Drawer::SetTextAspect ( const Handle(Prs3d_TextAspect)& anAspect) {
287  myTextAspect = anAspect;
288 }
289
290 Handle (Prs3d_ShadingAspect) Prs3d_Drawer::ShadingAspect ()  {
291   if (myShadingAspect.IsNull())
292   myShadingAspect = new Prs3d_ShadingAspect();
293
294   return myShadingAspect;
295 }
296
297 void Prs3d_Drawer::SetShadingAspect ( const Handle(Prs3d_ShadingAspect)& anAspect) {
298  myShadingAspect = anAspect;
299 }
300
301 void Prs3d_Drawer::SetShadingAspectGlobal(const Standard_Boolean aValue) {
302  myShadingAspectGlobal = aValue;
303 }
304
305 Standard_Boolean Prs3d_Drawer::ShadingAspectGlobal() const { 
306  
307  return myShadingAspectGlobal;
308
309 }
310  
311 void Prs3d_Drawer::SetLineArrowDraw ( const Standard_Boolean OnOff ) {
312   myLineDrawArrow = OnOff;
313 }
314
315 Standard_Boolean Prs3d_Drawer::LineArrowDraw () const {
316 return myLineDrawArrow;
317 }
318
319 Handle (Prs3d_ArrowAspect) Prs3d_Drawer::ArrowAspect() {
320   if (myArrowAspect.IsNull())
321     myArrowAspect = new Prs3d_ArrowAspect;
322
323   return myArrowAspect;
324 }
325
326 void Prs3d_Drawer::SetArrowAspect ( const Handle(Prs3d_ArrowAspect)& anAspect) {
327  myArrowAspect = anAspect;
328 }
329
330 Handle (Prs3d_PointAspect) Prs3d_Drawer::PointAspect() {
331   if (myPointAspect.IsNull())
332     myPointAspect = new Prs3d_PointAspect 
333       (Aspect_TOM_PLUS,Quantity_NOC_YELLOW,1.);
334
335   return myPointAspect;
336 }
337
338 void Prs3d_Drawer::SetPointAspect ( const Handle(Prs3d_PointAspect)& anAspect) {
339  myPointAspect = anAspect;
340 }
341
342 Standard_Boolean Prs3d_Drawer::DrawHiddenLine () const {return myDrawHiddenLine;}
343
344 void Prs3d_Drawer::EnableDrawHiddenLine () {myDrawHiddenLine=Standard_True;}
345
346 void Prs3d_Drawer::DisableDrawHiddenLine () {myDrawHiddenLine=Standard_False;}
347
348 Handle (Prs3d_LineAspect) Prs3d_Drawer::HiddenLineAspect ()  {
349  if (myHiddenLineAspect.IsNull())
350    myHiddenLineAspect = new Prs3d_LineAspect
351      (Quantity_NOC_YELLOW,Aspect_TOL_DASH,0.5);
352
353   return myHiddenLineAspect;
354 }
355
356 void Prs3d_Drawer::SetHiddenLineAspect ( const Handle(Prs3d_LineAspect)& anAspect) {
357  myHiddenLineAspect = anAspect;
358 }
359
360 Handle (Prs3d_LineAspect) Prs3d_Drawer::SeenLineAspect ()  {
361   if (mySeenLineAspect.IsNull())
362     mySeenLineAspect = new Prs3d_LineAspect
363       (Quantity_NOC_YELLOW,Aspect_TOL_SOLID,1.);
364
365   return mySeenLineAspect;
366 }
367
368 void Prs3d_Drawer::SetSeenLineAspect ( const Handle(Prs3d_LineAspect)& anAspect) {
369  mySeenLineAspect = anAspect;
370 }
371
372 Handle (Prs3d_LineAspect) Prs3d_Drawer::VectorAspect ()  {
373   if (myVectorAspect.IsNull())
374     myVectorAspect = new Prs3d_LineAspect
375       (Quantity_NOC_SKYBLUE,Aspect_TOL_SOLID,1.);
376
377   return myVectorAspect;
378 }
379
380 void Prs3d_Drawer::SetVectorAspect ( const Handle(Prs3d_LineAspect)& anAspect) {
381  myVectorAspect = anAspect;
382 }
383
384 Handle (Prs3d_DatumAspect) Prs3d_Drawer::DatumAspect () {
385   if (myDatumAspect.IsNull())
386     myDatumAspect = new Prs3d_DatumAspect;
387
388   return myDatumAspect;
389 }
390
391 void Prs3d_Drawer::SetDatumAspect ( const Handle(Prs3d_DatumAspect)& anAspect) {
392  myDatumAspect = anAspect;
393 }
394
395 Handle (Prs3d_PlaneAspect) Prs3d_Drawer::PlaneAspect () {
396   if (myPlaneAspect.IsNull())
397     myPlaneAspect = new Prs3d_PlaneAspect;
398
399   return myPlaneAspect;
400 }
401
402 void Prs3d_Drawer::SetPlaneAspect ( const Handle(Prs3d_PlaneAspect)& anAspect) {
403   myPlaneAspect = anAspect;
404 }
405
406 // =======================================================================
407 // function : DimensionAspect
408 // purpose  :
409 // =======================================================================
410 Handle(Prs3d_DimensionAspect) Prs3d_Drawer::DimensionAspect()
411 {
412   if (myDimensionAspect.IsNull())
413   {
414     myDimensionAspect = new Prs3d_DimensionAspect;
415   }
416
417   return myDimensionAspect;
418 }
419
420 // =======================================================================
421 // function : SetDimensionAspect
422 // purpose  :
423 // =======================================================================
424 void Prs3d_Drawer::SetDimensionAspect (const Handle(Prs3d_DimensionAspect)& theAspect)
425 {
426   myDimensionAspect = theAspect;
427 }
428
429 // =======================================================================
430 // function : SetDimLengthModelUnits
431 // purpose  :
432 // =======================================================================
433 void Prs3d_Drawer::SetDimLengthModelUnits (const TCollection_AsciiString& theUnits)
434 {
435   myDimensionModelUnits.SetLengthUnits (theUnits);
436 }
437
438 // =======================================================================
439 // function : SetDimAngleModelUnits
440 // purpose  :
441 // =======================================================================
442 void Prs3d_Drawer::SetDimAngleModelUnits (const TCollection_AsciiString& theUnits)
443 {
444   myDimensionModelUnits.SetAngleUnits (theUnits);
445 }
446
447 // =======================================================================
448 // function : DimLengthModelUnits
449 // purpose  :
450 // =======================================================================
451 const TCollection_AsciiString& Prs3d_Drawer::DimLengthModelUnits() const
452 {
453   return myDimensionModelUnits.GetLengthUnits();
454 }
455
456 // =======================================================================
457 // function : DimAngleModelUnits
458 // purpose  :
459 // =======================================================================
460 const TCollection_AsciiString& Prs3d_Drawer::DimAngleModelUnits() const
461 {
462   return myDimensionModelUnits.GetAngleUnits();
463 }
464
465 // =======================================================================
466 // function : SetDimLengthDisplayUnits
467 // purpose  :
468 // =======================================================================
469 void Prs3d_Drawer::SetDimLengthDisplayUnits (const TCollection_AsciiString& theUnits)
470 {
471   myDimensionDisplayUnits.SetLengthUnits (theUnits);
472 }
473
474 // =======================================================================
475 // function : SetDimAngleDisplayUnits
476 // purpose  :
477 // =======================================================================
478 void Prs3d_Drawer::SetDimAngleDisplayUnits (const TCollection_AsciiString& theUnits)
479 {
480   myDimensionDisplayUnits.SetAngleUnits (theUnits);
481 }
482
483 // =======================================================================
484 // function : DimLengthDisplayUnits
485 // purpose  :
486 // =======================================================================
487 const TCollection_AsciiString& Prs3d_Drawer::DimLengthDisplayUnits() const
488 {
489   return myDimensionDisplayUnits.GetLengthUnits();
490 }
491
492 // =======================================================================
493 // function : DimAngleDisplayUnits
494 // purpose  :
495 // =======================================================================
496 const TCollection_AsciiString& Prs3d_Drawer::DimAngleDisplayUnits() const
497 {
498   return myDimensionDisplayUnits.GetAngleUnits();
499 }
500
501 // =======================================================================
502 // function : SectionAspect
503 // purpose  :
504 // =======================================================================
505 Handle (Prs3d_LineAspect) Prs3d_Drawer::SectionAspect()
506 {
507   if (mySectionAspect.IsNull())
508   {
509     mySectionAspect = new Prs3d_LineAspect (Quantity_NOC_ORANGE, Aspect_TOL_SOLID, 1.0);
510   }
511
512   return mySectionAspect;
513 }
514
515 // =======================================================================
516 // function : SetSectionAspect
517 // purpose  :
518 // =======================================================================
519 void Prs3d_Drawer::SetSectionAspect (const Handle(Prs3d_LineAspect)& theAspect)
520 {
521   mySectionAspect = theAspect;
522 }
523
524 // =======================================================================
525 // function : SetFaceBoundaryDraw
526 // purpose  :
527 // =======================================================================
528 void Prs3d_Drawer::SetFaceBoundaryDraw (const Standard_Boolean theIsEnabled)
529 {
530   myFaceBoundaryDraw = theIsEnabled;
531 }
532
533 // =======================================================================
534 // function : IsFaceBoundaryDraw
535 // purpose  :
536 // =======================================================================
537 Standard_Boolean Prs3d_Drawer::IsFaceBoundaryDraw () const
538 {
539   return myFaceBoundaryDraw;
540 }
541
542 // =======================================================================
543 // function : SetFaceBoundaryAspect
544 // purpose  :
545 // =======================================================================
546 void Prs3d_Drawer::SetFaceBoundaryAspect (const Handle(Prs3d_LineAspect)& theAspect)
547 {
548   myFaceBoundaryAspect = theAspect;
549 }
550
551 // =======================================================================
552 // function : FaceBoundaryAspect
553 // purpose  :
554 // =======================================================================
555 Handle_Prs3d_LineAspect Prs3d_Drawer::FaceBoundaryAspect ()
556 {
557   if (myFaceBoundaryAspect.IsNull ())
558   {
559     myFaceBoundaryAspect = 
560       new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0);
561   }
562
563   return myFaceBoundaryAspect;
564 }
565
566 // =======================================================================
567 // function : SetTypeOfHLR
568 // purpose  : set type of HLR algorithm
569 // =======================================================================
570 void Prs3d_Drawer::SetTypeOfHLR ( const Prs3d_TypeOfHLR theTypeOfHLR) 
571 {
572   myTypeOfHLR = theTypeOfHLR;
573 }
574
575 // =======================================================================
576 // function : TypeOfHLR
577 // purpose  : gets type of HLR algorithm
578 // =======================================================================
579 Prs3d_TypeOfHLR Prs3d_Drawer::TypeOfHLR ( ) const
580 {
581   return myTypeOfHLR;
582 }