0028162: Draw Harness - eliminate usage of deprecated Local Context
[occt.git] / src / Prs3d / Prs3d_Drawer.cxx
1 // Copyright (c) 1995-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 <Prs3d_Drawer.hxx>
16
17 #include <Graphic3d_AspectFillArea3d.hxx>
18 #include <Graphic3d_AspectMarker3d.hxx>
19 #include <Graphic3d_AspectText3d.hxx>
20 #include <Prs3d_ArrowAspect.hxx>
21 #include <Prs3d_DatumAspect.hxx>
22 #include <Prs3d_DimensionAspect.hxx>
23 #include <Prs3d_IsoAspect.hxx>
24 #include <Prs3d_LineAspect.hxx>
25 #include <Prs3d_PlaneAspect.hxx>
26 #include <Prs3d_PointAspect.hxx>
27 #include <Prs3d_ShadingAspect.hxx>
28 #include <Prs3d_TextAspect.hxx>
29
30 IMPLEMENT_STANDARD_RTTIEXT(Prs3d_Drawer,MMgt_TShared)
31
32 // =======================================================================
33 // function : Prs3d_Drawer
34 // purpose  :
35 // =======================================================================
36 Prs3d_Drawer::Prs3d_Drawer()
37 : myNbPoints                      (30),
38   myHasOwnNbPoints                (Standard_False),
39   myMaximalParameterValue         (500000.),
40   myHasOwnMaximalParameterValue   (Standard_False),
41   myChordialDeviation             (0.0001),
42   myHasOwnChordialDeviation       (Standard_False),
43   myTypeOfDeflection              (Aspect_TOD_RELATIVE),
44   myHasOwnTypeOfDeflection        (Standard_False),
45   myTypeOfHLR                     (Prs3d_TOH_NotSet),
46   myDeviationCoefficient          (0.001),
47   myHasOwnDeviationCoefficient    (Standard_False),
48   myHLRDeviationCoefficient       (0.02),
49   myHasOwnHLRDeviationCoefficient (Standard_False),
50   myDeviationAngle                (12.0 * M_PI / 180.0),
51   myHasOwnDeviationAngle          (Standard_False),
52   myHLRAngle                      (20.0 * M_PI / 180.0),
53   myHasOwnHLRDeviationAngle       (Standard_False),
54   myIsoOnPlane                    (Standard_False),
55   myHasOwnIsoOnPlane              (Standard_False),
56   myIsoOnTriangulation            (Standard_False),
57   myHasOwnIsoOnTriangulation      (Standard_False),
58   myIsAutoTriangulated            (Standard_True),
59   myHasOwnIsAutoTriangulated      (Standard_False),
60
61   myHasOwnUIsoAspect          (Standard_False),
62   myHasOwnVIsoAspect          (Standard_False),
63   myHasOwnWireAspect          (Standard_False),
64   myWireDraw                  (Standard_True),
65   myHasOwnWireDraw            (Standard_False),
66   myHasOwnPointAspect         (Standard_False),
67   myHasOwnLineAspect          (Standard_False),
68   myHasOwnTextAspect          (Standard_False),
69   myHasOwnShadingAspect       (Standard_False),
70   myHasOwnPlaneAspect         (Standard_False),
71   myHasOwnSeenLineAspect      (Standard_False),
72   myHasOwnArrowAspect         (Standard_False),
73   myLineArrowDraw             (Standard_False),
74   myHasOwnLineArrowDraw       (Standard_False),
75   myHasOwnHiddenLineAspect    (Standard_False),
76   myDrawHiddenLine            (Standard_False),
77   myHasOwnDrawHiddenLine      (Standard_False),
78   myHasOwnVectorAspect        (Standard_False),
79   myVertexDrawMode            (Prs3d_VDM_Inherited),
80   myHasOwnDatumAspect         (Standard_False),
81   myHasOwnSectionAspect       (Standard_False),
82
83   myHasOwnFreeBoundaryAspect   (Standard_False),
84   myFreeBoundaryDraw           (Standard_True),
85   myHasOwnFreeBoundaryDraw     (Standard_False),
86   myHasOwnUnFreeBoundaryAspect (Standard_False),
87   myUnFreeBoundaryDraw         (Standard_True),
88   myHasOwnUnFreeBoundaryDraw   (Standard_False),
89   myHasOwnFaceBoundaryAspect   (Standard_False),
90   myFaceBoundaryDraw           (Standard_False),
91   myHasOwnFaceBoundaryDraw     (Standard_False),
92
93   myHasOwnDimensionAspect       (Standard_False),
94   myHasOwnDimLengthModelUnits   (Standard_False),
95   myHasOwnDimAngleModelUnits    (Standard_False),
96   myHasOwnDimLengthDisplayUnits (Standard_False),
97   myHasOwnDimAngleDisplayUnits  (Standard_False),
98
99   myHasOwnHighlightStyle        (Standard_False),
100   myHasOwnSelectionStyle        (Standard_False)
101 {
102   myDimensionModelUnits.SetLengthUnits ("m");
103   myDimensionModelUnits.SetAngleUnits ("rad");
104   myDimensionDisplayUnits.SetLengthUnits ("m");
105   myDimensionDisplayUnits.SetAngleUnits ("deg");
106 }
107
108 // =======================================================================
109 // function : SetTypeOfDeflection
110 // purpose  :
111 // =======================================================================
112
113 void Prs3d_Drawer::SetTypeOfDeflection (const Aspect_TypeOfDeflection theTypeOfDeflection)
114 {
115   myHasOwnTypeOfDeflection = Standard_True;
116   myTypeOfDeflection       = theTypeOfDeflection;
117 }
118
119 // =======================================================================
120 // function : SetMaximalChordialDeviation
121 // purpose  :
122 // =======================================================================
123
124 void Prs3d_Drawer::SetMaximalChordialDeviation (const Quantity_Length theChordialDeviation)
125 {
126   myHasOwnChordialDeviation = Standard_True;
127   myChordialDeviation       = theChordialDeviation;
128 }
129
130 // =======================================================================
131 // function : SetTypeOfHLR
132 // purpose  : set type of HLR algorithm
133 // =======================================================================
134
135 void Prs3d_Drawer::SetTypeOfHLR (const Prs3d_TypeOfHLR theTypeOfHLR)
136 {
137   myTypeOfHLR = theTypeOfHLR;
138 }
139
140 // =======================================================================
141 // function : TypeOfHLR
142 // purpose  : gets type of HLR algorithm
143 // =======================================================================
144
145 Prs3d_TypeOfHLR Prs3d_Drawer::TypeOfHLR()
146 {
147   if (!HasOwnTypeOfHLR())
148   {
149     if (!myLink.IsNull())
150     {
151       return myLink->TypeOfHLR();
152     }
153     // Prs3d_TOH_PolyAlgo is default value for this setting.
154     myTypeOfHLR = Prs3d_TOH_PolyAlgo;
155   }
156   return myTypeOfHLR;
157 }
158
159 // =======================================================================
160 // function : SetIsoOnTriangulation
161 // purpose  :
162 // =======================================================================
163 void Prs3d_Drawer::SetIsoOnTriangulation (const Standard_Boolean theToEnable)
164 {
165   myHasOwnIsoOnTriangulation = Standard_True;
166   myIsoOnTriangulation = theToEnable;
167 }
168
169 // =======================================================================
170 // function : SetMaximalParameterValue
171 // purpose  :
172 // =======================================================================
173
174 void Prs3d_Drawer::SetMaximalParameterValue (const Standard_Real theValue)
175 {
176   myHasOwnMaximalParameterValue = Standard_True;
177   myMaximalParameterValue       = theValue;
178 }
179
180 // =======================================================================
181 // function : SetIsoOnPlane
182 // purpose  :
183 // =======================================================================
184
185 void Prs3d_Drawer::SetIsoOnPlane (const Standard_Boolean theIsEnabled)
186 {
187   myHasOwnIsoOnPlane = Standard_True;
188   myIsoOnPlane       = theIsEnabled;
189 }
190
191 // =======================================================================
192 // function : SetDiscretisation
193 // purpose  :
194 // =======================================================================
195
196 void Prs3d_Drawer::SetDiscretisation (const Standard_Integer theValue) 
197 {
198   myHasOwnNbPoints = Standard_True;
199   myNbPoints       = theValue;
200 }
201
202 //=======================================================================
203 //function : SetDeviationCoefficient
204 //purpose  : 
205 //=======================================================================
206
207 void Prs3d_Drawer::SetDeviationCoefficient (const Standard_Real theCoefficient)
208 {
209   myPreviousDeviationCoefficient = DeviationCoefficient();
210   myDeviationCoefficient         = theCoefficient;
211   myHasOwnDeviationCoefficient   = Standard_True;
212 }
213
214 //=======================================================================
215 //function : SetHLRDeviationCoefficient
216 //purpose  : 
217 //=======================================================================
218
219 void Prs3d_Drawer::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
220 {
221   myPreviousHLRDeviationCoefficient = HLRDeviationCoefficient();
222   myHLRDeviationCoefficient         = theCoefficient;
223   myHasOwnHLRDeviationCoefficient   = Standard_True;
224 }
225
226 //=======================================================================
227 //function : SetDeviationAngle
228 //purpose  : 
229 //=======================================================================
230
231 void Prs3d_Drawer::SetDeviationAngle (const Standard_Real theAngle)
232 {
233   myPreviousDeviationAngle = DeviationAngle();
234   myDeviationAngle         = theAngle;
235   myHasOwnDeviationAngle   = Standard_True;
236 }
237
238 //=======================================================================
239 //function : SetHLRAngle
240 //purpose  : 
241 //=======================================================================
242
243 void Prs3d_Drawer::SetHLRAngle (const Standard_Real theAngle)
244 {
245   myPreviousHLRDeviationAngle = HLRAngle();
246   myHLRAngle                  = theAngle;
247   myHasOwnHLRDeviationAngle   = Standard_True;
248 }
249
250 // =======================================================================
251 // function : SetAutoTriangulation
252 // purpose  :
253 // =======================================================================
254
255 void Prs3d_Drawer::SetAutoTriangulation (const Standard_Boolean theIsEnabled)
256 {
257   myHasOwnIsAutoTriangulated = Standard_True;
258   myIsAutoTriangulated       = theIsEnabled;
259 }
260
261 // =======================================================================
262 // function : FreeBoundaryAspect
263 // purpose  :
264 // =======================================================================
265
266 const Handle(Prs3d_LineAspect)& Prs3d_Drawer::FreeBoundaryAspect()
267 {
268   if (!HasOwnFreeBoundaryAspect())
269   {
270     if (!myLink.IsNull())
271     {
272       return myLink->FreeBoundaryAspect();
273     }
274     if (myFreeBoundaryAspect.IsNull())
275     {
276       myFreeBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_GREEN, Aspect_TOL_SOLID, 1.0);
277     }
278   }
279   return myFreeBoundaryAspect;
280 }
281
282 // =======================================================================
283 // function : FreeBoundaryAspect
284 // purpose  :
285 // =======================================================================
286
287 void Prs3d_Drawer::SetFreeBoundaryAspect (const Handle(Prs3d_LineAspect)& theAspect)
288 {
289   myFreeBoundaryAspect = theAspect;
290   myHasOwnFreeBoundaryAspect = !myFreeBoundaryAspect.IsNull();
291 }
292
293 // =======================================================================
294 // function : SetFreeBoundaryDraw
295 // purpose  :
296 // =======================================================================
297
298 void Prs3d_Drawer::SetFreeBoundaryDraw (const Standard_Boolean theIsEnabled)
299 {
300   myHasOwnFreeBoundaryDraw = Standard_True;
301   myFreeBoundaryDraw       = theIsEnabled;
302 }
303
304 // =======================================================================
305 // function : UnFreeBoundaryAspect
306 // purpose  :
307 // =======================================================================
308
309 const Handle(Prs3d_LineAspect)& Prs3d_Drawer::UnFreeBoundaryAspect()
310 {
311   if (!HasOwnUnFreeBoundaryAspect())
312   {
313     if (!myLink.IsNull())
314     {
315       return myLink->UnFreeBoundaryAspect();
316     }
317     if (myUnFreeBoundaryAspect.IsNull())
318     {
319       myUnFreeBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_YELLOW, Aspect_TOL_SOLID, 1.0);
320     }
321   }
322   return myUnFreeBoundaryAspect;
323 }
324
325 // =======================================================================
326 // function : SetUnFreeBoundaryAspect
327 // purpose  :
328 // =======================================================================
329
330 void Prs3d_Drawer::SetUnFreeBoundaryAspect (const Handle(Prs3d_LineAspect)& theAspect)
331 {
332   myUnFreeBoundaryAspect = theAspect;
333   myHasOwnUnFreeBoundaryAspect = !myUnFreeBoundaryAspect.IsNull();
334 }
335
336 // =======================================================================
337 // function : SetUnFreeBoundaryDraw
338 // purpose  :
339 // =======================================================================
340
341 void Prs3d_Drawer::SetUnFreeBoundaryDraw (const Standard_Boolean theIsEnabled)
342 {
343   myHasOwnUnFreeBoundaryDraw = Standard_True;
344   myUnFreeBoundaryDraw       = theIsEnabled;
345 }
346
347 // =======================================================================
348 // function : FaceBoundaryAspect
349 // purpose  :
350 // =======================================================================
351
352 const Handle(Prs3d_LineAspect)& Prs3d_Drawer::FaceBoundaryAspect()
353 {
354   if (!HasOwnFaceBoundaryAspect())
355   {
356     if (!myLink.IsNull())
357     {
358       return myLink->FaceBoundaryAspect();
359     }
360     if (myFaceBoundaryAspect.IsNull())
361     {
362       myFaceBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0);
363     }
364   }
365   return myFaceBoundaryAspect;
366 }
367
368 // =======================================================================
369 // function : SetFaceBoundaryAspect
370 // purpose  :
371 // =======================================================================
372
373 void Prs3d_Drawer::SetFaceBoundaryAspect (const Handle(Prs3d_LineAspect)& theAspect)
374 {
375   myFaceBoundaryAspect = theAspect;
376   myHasOwnFaceBoundaryAspect = !myFaceBoundaryAspect.IsNull();
377 }
378
379 // =======================================================================
380 // function : SetFaceBoundaryDraw
381 // purpose  :
382 // =======================================================================
383
384 void Prs3d_Drawer::SetFaceBoundaryDraw (const Standard_Boolean theIsEnabled)
385 {
386   myHasOwnFaceBoundaryDraw = Standard_True;
387   myFaceBoundaryDraw       = theIsEnabled;
388 }
389
390 // =======================================================================
391 // function : DimensionAspect
392 // purpose  :
393 // =======================================================================
394
395 const Handle(Prs3d_DimensionAspect)& Prs3d_Drawer::DimensionAspect()
396 {
397   if (!HasOwnDimensionAspect())
398   {
399     if (!myLink.IsNull())
400     {
401       return myLink->DimensionAspect();
402     }
403     if (myDimensionAspect.IsNull())
404     {
405       myDimensionAspect = new Prs3d_DimensionAspect;
406     }
407   }
408   return myDimensionAspect;
409 }
410
411 // =======================================================================
412 // function : SetDimensionAspect
413 // purpose  :
414 // =======================================================================
415
416 void Prs3d_Drawer::SetDimensionAspect (const Handle(Prs3d_DimensionAspect)& theAspect)
417 {
418   myDimensionAspect = theAspect;
419   myHasOwnDimensionAspect = !myDimensionAspect.IsNull();
420 }
421
422 // =======================================================================
423 // function : SetDimLengthModelUnits
424 // purpose  :
425 // =======================================================================
426
427 void Prs3d_Drawer::SetDimLengthModelUnits (const TCollection_AsciiString& theUnits)
428 {
429   myHasOwnDimLengthModelUnits = Standard_True;
430   myDimensionModelUnits.SetLengthUnits (theUnits);
431 }
432
433 // =======================================================================
434 // function : SetDimAngleModelUnits
435 // purpose  :
436 // =======================================================================
437
438 void Prs3d_Drawer::SetDimAngleModelUnits (const TCollection_AsciiString& theUnits)
439 {
440   myHasOwnDimAngleModelUnits = Standard_True;
441   myDimensionModelUnits.SetAngleUnits (theUnits);
442 }
443
444 // =======================================================================
445 // function : SetDimLengthDisplayUnits
446 // purpose  :
447 // =======================================================================
448
449 void Prs3d_Drawer::SetDimLengthDisplayUnits (const TCollection_AsciiString& theUnits)
450 {
451   myHasOwnDimLengthDisplayUnits = Standard_True;
452   myDimensionDisplayUnits.SetLengthUnits (theUnits);
453 }
454
455 // =======================================================================
456 // function : SetDimAngleDisplayUnits
457 // purpose  :
458 // =======================================================================
459
460 void Prs3d_Drawer::SetDimAngleDisplayUnits (const TCollection_AsciiString& theUnits)
461 {
462   myHasOwnDimAngleDisplayUnits = Standard_True;
463   myDimensionDisplayUnits.SetAngleUnits (theUnits);
464 }
465
466 // =======================================================================
467 // function : UIsoAspect
468 // purpose  :
469 // =======================================================================
470
471 const Handle(Prs3d_IsoAspect)& Prs3d_Drawer::UIsoAspect()
472 {
473   if (!HasOwnUIsoAspect())
474   {
475     if (!myLink.IsNull())
476     {
477       return myLink->UIsoAspect();
478     }
479     if (myUIsoAspect.IsNull())
480     {
481       myUIsoAspect = new Prs3d_IsoAspect (Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 1.0, 1);
482     }
483   }
484   return myUIsoAspect;
485 }
486
487 // =======================================================================
488 // function : SetUIsoAspect
489 // purpose  :
490 // =======================================================================
491
492 void Prs3d_Drawer::SetUIsoAspect (const Handle(Prs3d_IsoAspect)& theAspect)
493 {
494   myUIsoAspect = theAspect;
495   myHasOwnUIsoAspect = !myUIsoAspect.IsNull();
496 }
497
498 // =======================================================================
499 // function : VIsoAspect
500 // purpose  :
501 // =======================================================================
502
503 const Handle(Prs3d_IsoAspect)& Prs3d_Drawer::VIsoAspect()
504 {
505   if (!HasOwnVIsoAspect())
506   {
507     if (!myLink.IsNull())
508     {
509       return myLink->VIsoAspect();
510     }
511     if (myVIsoAspect.IsNull())
512     {
513       myVIsoAspect = new Prs3d_IsoAspect (Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 1.0, 1);
514     }
515   }
516   return myVIsoAspect;
517 }
518
519 // =======================================================================
520 // function : SetVIsoAspect
521 // purpose  :
522 // =======================================================================
523
524 void Prs3d_Drawer::SetVIsoAspect (const Handle(Prs3d_IsoAspect)& theAspect)
525 {
526   myVIsoAspect = theAspect;
527   myHasOwnVIsoAspect= !myVIsoAspect.IsNull();
528 }
529
530 // =======================================================================
531 // function : WireAspect
532 // purpose  :
533 // =======================================================================
534
535 const Handle(Prs3d_LineAspect)& Prs3d_Drawer::WireAspect()
536 {
537   if (!HasOwnWireAspect())
538   {
539     if (!myLink.IsNull())
540     {
541       return myLink->WireAspect();
542     }
543     if (myWireAspect.IsNull())
544     {
545       myWireAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
546     }
547   }
548   return myWireAspect;
549 }
550
551 // =======================================================================
552 // function : SetWireAspect
553 // purpose  :
554 // =======================================================================
555
556 void Prs3d_Drawer::SetWireAspect (const Handle(Prs3d_LineAspect)& theAspect)
557 {
558   myWireAspect = theAspect;
559   myHasOwnWireAspect = !myWireAspect.IsNull();
560 }
561
562 // =======================================================================
563 // function : SetWireDraw
564 // purpose  :
565 // =======================================================================
566
567 void Prs3d_Drawer::SetWireDraw (const Standard_Boolean theIsEnabled)
568 {
569   myHasOwnWireDraw = Standard_True;
570   myWireDraw       = theIsEnabled;
571 }
572
573 // =======================================================================
574 // function : PointAspect
575 // purpose  :
576 // =======================================================================
577
578 const Handle(Prs3d_PointAspect)& Prs3d_Drawer::PointAspect()
579 {
580   if (!HasOwnPointAspect())
581   {
582     if (!myLink.IsNull())
583     {
584       return myLink->PointAspect();
585     }
586     if (myPointAspect.IsNull())
587     {
588       myPointAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
589     }
590   }
591   return myPointAspect;
592 }
593
594 // =======================================================================
595 // function : SetPointAspect
596 // purpose  :
597 // =======================================================================
598
599 void Prs3d_Drawer::SetPointAspect (const Handle(Prs3d_PointAspect)& theAspect)
600 {
601   myPointAspect = theAspect;
602   myHasOwnPointAspect = !myPointAspect.IsNull();
603 }
604
605 // =======================================================================
606 // function : LineAspect
607 // purpose  :
608 // =======================================================================
609
610 const Handle(Prs3d_LineAspect)& Prs3d_Drawer::LineAspect()
611 {
612   if (!HasOwnLineAspect())
613   {
614     if (!myLink.IsNull())
615     {
616       return myLink->LineAspect();
617     }
618     if (myLineAspect.IsNull())
619     {
620       myLineAspect = new Prs3d_LineAspect (Quantity_NOC_YELLOW, Aspect_TOL_SOLID, 1.0);
621     }
622   }
623   return myLineAspect;
624 }
625
626 // =======================================================================
627 // function : SetLineAspect
628 // purpose  :
629 // =======================================================================
630
631 void Prs3d_Drawer::SetLineAspect (const Handle(Prs3d_LineAspect)& theAspect)
632 {
633   myLineAspect = theAspect;
634   myHasOwnLineAspect = !myLineAspect.IsNull();
635 }
636
637 // =======================================================================
638 // function : TextAspect
639 // purpose  :
640 // =======================================================================
641
642 const Handle(Prs3d_TextAspect)& Prs3d_Drawer::TextAspect()
643 {
644   if (!HasOwnTextAspect())
645   {
646     if (!myLink.IsNull())
647     {
648       return myLink->TextAspect();
649     }
650     if (myTextAspect.IsNull())
651     {
652       myTextAspect = new Prs3d_TextAspect();
653     }
654   }
655   return myTextAspect;
656 }
657
658 // =======================================================================
659 // function : SetTextAspect
660 // purpose  :
661 // =======================================================================
662
663 void Prs3d_Drawer::SetTextAspect (const Handle(Prs3d_TextAspect)& theAspect)
664 {
665   myTextAspect = theAspect;
666   myHasOwnTextAspect = !myTextAspect.IsNull();
667 }
668
669 // =======================================================================
670 // function : ShadingAspect
671 // purpose  :
672 // =======================================================================
673
674 const Handle(Prs3d_ShadingAspect)& Prs3d_Drawer::ShadingAspect()
675 {
676   if (!HasOwnShadingAspect())
677   {
678     if (!myLink.IsNull())
679     {
680       return myLink->ShadingAspect();
681     }
682     if (myShadingAspect.IsNull())
683     {
684       myShadingAspect = new Prs3d_ShadingAspect();
685     }
686   }
687   return myShadingAspect;
688 }
689
690 // =======================================================================
691 // function : SetShadingAspect
692 // purpose  :
693 // =======================================================================
694
695 void Prs3d_Drawer::SetShadingAspect (const Handle(Prs3d_ShadingAspect)& theAspect)
696 {
697   myShadingAspect = theAspect;
698   myHasOwnShadingAspect = !myShadingAspect.IsNull();
699 }
700
701 // =======================================================================
702 // function : PlaneAspect
703 // purpose  :
704 // =======================================================================
705
706 const Handle(Prs3d_PlaneAspect)& Prs3d_Drawer::PlaneAspect()
707 {
708   if (!HasOwnPlaneAspect())
709   {
710     if (!myLink.IsNull())
711     {
712       return myLink->PlaneAspect();
713     }
714     if (myPlaneAspect.IsNull())
715     {
716       myPlaneAspect = new Prs3d_PlaneAspect();
717     }
718   }
719   return myPlaneAspect;
720 }
721
722 // =======================================================================
723 // function : SetPlaneAspect
724 // purpose  :
725 // =======================================================================
726
727 void Prs3d_Drawer::SetPlaneAspect (const Handle(Prs3d_PlaneAspect)& theAspect)
728 {
729   myPlaneAspect = theAspect;
730   myHasOwnPlaneAspect = !myPlaneAspect.IsNull();
731 }
732
733 // =======================================================================
734 // function : SeenLineAspect
735 // purpose  :
736 // =======================================================================
737
738 const Handle(Prs3d_LineAspect)& Prs3d_Drawer::SeenLineAspect()
739 {
740   if (!HasOwnSeenLineAspect())
741   {
742     if (!myLink.IsNull())
743     {
744       return myLink->SeenLineAspect();
745     }
746     if (mySeenLineAspect.IsNull())
747     {
748       mySeenLineAspect = new Prs3d_LineAspect (Quantity_NOC_YELLOW, Aspect_TOL_SOLID, 1.0);
749     }
750   }
751   return mySeenLineAspect;
752 }
753
754 // =======================================================================
755 // function : SetSeenLineAspect
756 // purpose  :
757 // =======================================================================
758
759 void Prs3d_Drawer::SetSeenLineAspect (const Handle(Prs3d_LineAspect)& theAspect)
760 {
761   mySeenLineAspect = theAspect;
762   myHasOwnSeenLineAspect = !mySeenLineAspect.IsNull();
763 }
764
765 // =======================================================================
766 // function : ArrowAspect
767 // purpose  :
768 // =======================================================================
769
770 const Handle(Prs3d_ArrowAspect)& Prs3d_Drawer::ArrowAspect()
771 {
772   if (!HasOwnArrowAspect())
773   {
774     if (!myLink.IsNull())
775     {
776       return myLink->ArrowAspect();
777     }
778     if (myArrowAspect.IsNull())
779     {
780       myArrowAspect = new Prs3d_ArrowAspect();
781     }
782   }
783   return myArrowAspect;
784 }
785
786 // =======================================================================
787 // function : SetArrowAspect
788 // purpose  :
789 // =======================================================================
790
791 void Prs3d_Drawer::SetArrowAspect (const Handle(Prs3d_ArrowAspect)& theAspect)
792 {
793   myArrowAspect = theAspect;
794   myHasOwnArrowAspect = !myArrowAspect.IsNull();
795 }
796
797 // =======================================================================
798 // function : SetLineArrowDraw
799 // purpose  :
800 // =======================================================================
801
802 void Prs3d_Drawer::SetLineArrowDraw (const Standard_Boolean theIsEnabled)
803 {
804   myHasOwnLineArrowDraw = Standard_True;
805   myLineArrowDraw       = theIsEnabled;
806 }
807
808 // =======================================================================
809 // function : HiddenLineAspect
810 // purpose  :
811 // =======================================================================
812
813 const Handle(Prs3d_LineAspect)& Prs3d_Drawer::HiddenLineAspect()
814 {
815   if (!HasOwnHiddenLineAspect())
816   {
817     if (!myLink.IsNull())
818     {
819       return myLink->HiddenLineAspect();
820     }
821     if (myHiddenLineAspect.IsNull())
822     {
823       myHiddenLineAspect = new Prs3d_LineAspect (Quantity_NOC_YELLOW, Aspect_TOL_DASH, 1.0);
824     }
825   }
826   return myHiddenLineAspect;
827 }
828
829 // =======================================================================
830 // function : SetHiddenLineAspect
831 // purpose  :
832 // =======================================================================
833
834 void Prs3d_Drawer::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect)
835 {
836   myHiddenLineAspect = theAspect;
837   myHasOwnHiddenLineAspect = !myHiddenLineAspect.IsNull();
838 }
839
840 // =======================================================================
841 // function : EnableDrawHiddenLineDraw
842 // purpose  :
843 // =======================================================================
844
845 void Prs3d_Drawer::EnableDrawHiddenLine()
846 {
847     myHasOwnDrawHiddenLine = Standard_True;
848     myDrawHiddenLine       = Standard_True;
849 }
850
851 // =======================================================================
852 // function : DisableDrawHiddenLine
853 // purpose  :
854 // =======================================================================
855
856 void Prs3d_Drawer::DisableDrawHiddenLine()
857 {
858     myHasOwnDrawHiddenLine = Standard_True;
859     myDrawHiddenLine       = Standard_False;
860 }
861
862 // =======================================================================
863 // function : VectorAspect
864 // purpose  :
865 // =======================================================================
866
867 const Handle(Prs3d_LineAspect)& Prs3d_Drawer::VectorAspect()
868 {
869   if (!HasOwnVectorAspect())
870   {
871     if (!myLink.IsNull())
872     {
873       return myLink->VectorAspect();
874     }
875     if (myVectorAspect.IsNull())
876     {
877       myVectorAspect = new Prs3d_LineAspect (Quantity_NOC_SKYBLUE, Aspect_TOL_SOLID, 1.0);
878     }
879   }
880   return myVectorAspect;
881 }
882
883 // =======================================================================
884 // function : SetVectorAspect
885 // purpose  :
886 // =======================================================================
887
888 void Prs3d_Drawer::SetVectorAspect (const Handle(Prs3d_LineAspect)& theAspect)
889 {
890   myVectorAspect = theAspect;
891   myHasOwnVectorAspect = !myVectorAspect.IsNull();
892 }
893
894 // =======================================================================
895 // function : SetVertexDrawMode
896 // purpose  :
897 // =======================================================================
898
899 void Prs3d_Drawer::SetVertexDrawMode (const Prs3d_VertexDrawMode theMode)
900 {
901   // Prs3d_VDM_Inherited is default value and means
902   // that correct value should be taken from the Link if it exists.
903   myVertexDrawMode = theMode;
904 }
905
906 // =======================================================================
907 // function : VertexDrawMode
908 // purpose  :
909 // =======================================================================
910
911 Prs3d_VertexDrawMode Prs3d_Drawer::VertexDrawMode()
912 {
913   if (!HasOwnVertexDrawMode())
914   {
915       if (!myLink.IsNull())
916       {
917           return myLink->VertexDrawMode();
918       }
919       // Prs3d_VDM_Isolated is default value for this setting.
920       myVertexDrawMode = Prs3d_VDM_Isolated;
921   }
922   return myVertexDrawMode;
923 }
924
925 // =======================================================================
926 // function : DatumAspect
927 // purpose  :
928 // =======================================================================
929
930 const Handle(Prs3d_DatumAspect)& Prs3d_Drawer::DatumAspect()
931 {
932   if (!HasOwnDatumAspect())
933   {
934     if (!myLink.IsNull())
935     {
936       return myLink->DatumAspect();
937     }
938     if (myDatumAspect.IsNull())
939     {
940       myDatumAspect = new Prs3d_DatumAspect();
941     }
942   }
943   return myDatumAspect;
944 }
945
946 // =======================================================================
947 // function : SetDatumAspect
948 // purpose  :
949 // =======================================================================
950
951 void Prs3d_Drawer::SetDatumAspect (const Handle(Prs3d_DatumAspect)& theAspect)
952 {
953   myDatumAspect = theAspect;
954   myHasOwnDatumAspect = !myDatumAspect.IsNull();
955 }
956
957 // =======================================================================
958 // function : SectionAspect
959 // purpose  :
960 // =======================================================================
961
962 const Handle(Prs3d_LineAspect)& Prs3d_Drawer::SectionAspect()
963 {
964   if (!HasOwnSectionAspect())
965   {
966     if (!myLink.IsNull())
967     {
968       return myLink->SectionAspect();
969     }
970     if (mySectionAspect.IsNull())
971     {
972       mySectionAspect = new Prs3d_LineAspect (Quantity_NOC_ORANGE, Aspect_TOL_SOLID, 1.0);
973     }
974   }
975   return mySectionAspect;
976 }
977
978 // =======================================================================
979 // function : SetSectionAspect
980 // purpose  :
981 // =======================================================================
982
983 void Prs3d_Drawer::SetSectionAspect (const Handle(Prs3d_LineAspect)& theAspect)
984 {
985   mySectionAspect = theAspect;
986   myHasOwnSectionAspect = !mySectionAspect.IsNull();
987 }
988
989 // =======================================================================
990 // function : SetSectionAspect
991 // purpose  :
992 // =======================================================================
993
994 void Prs3d_Drawer::ClearLocalAttributes()
995 {
996   if (myLink.IsNull())
997   {
998     return;
999   }
1000
1001   myUIsoAspect.Nullify();
1002   myVIsoAspect.Nullify();
1003   myFreeBoundaryAspect.Nullify();
1004   myUnFreeBoundaryAspect.Nullify();
1005   myFaceBoundaryAspect.Nullify();
1006   myWireAspect.Nullify();
1007   myLineAspect.Nullify();
1008   myTextAspect.Nullify();
1009   myShadingAspect.Nullify();
1010   myPointAspect.Nullify();
1011   myPlaneAspect.Nullify();
1012   myArrowAspect.Nullify();
1013   myHiddenLineAspect.Nullify();
1014   mySeenLineAspect.Nullify();
1015   myVectorAspect .Nullify();
1016   myDatumAspect.Nullify();
1017   myDimensionAspect.Nullify();
1018   mySectionAspect.Nullify();
1019   myHighlightStyle.Nullify();
1020   mySelectionStyle.Nullify();
1021
1022   myHasOwnUIsoAspect           = Standard_False;
1023   myHasOwnVIsoAspect           = Standard_False;
1024   myHasOwnWireAspect           = Standard_False;
1025   myHasOwnPointAspect          = Standard_False;
1026   myHasOwnLineAspect           = Standard_False;
1027   myHasOwnTextAspect           = Standard_False;
1028   myHasOwnShadingAspect        = Standard_False;
1029   myHasOwnPlaneAspect          = Standard_False;
1030   myHasOwnSeenLineAspect       = Standard_False;
1031   myHasOwnArrowAspect          = Standard_False;
1032   myHasOwnHiddenLineAspect     = Standard_False;
1033   myHasOwnVectorAspect         = Standard_False;
1034   myHasOwnDatumAspect          = Standard_False;
1035   myHasOwnSectionAspect        = Standard_False;
1036   myHasOwnFreeBoundaryAspect   = Standard_False;
1037   myHasOwnUnFreeBoundaryAspect = Standard_False;
1038   myHasOwnFaceBoundaryAspect   = Standard_False;
1039   myHasOwnDimensionAspect      = Standard_False;
1040
1041   myHasOwnNbPoints                = Standard_False;
1042   myHasOwnMaximalParameterValue   = Standard_False;
1043   myHasOwnTypeOfDeflection        = Standard_False;
1044   myHasOwnChordialDeviation       = Standard_False;
1045   myHasOwnDeviationCoefficient    = Standard_False;
1046   myHasOwnHLRDeviationCoefficient = Standard_False;
1047   myHasOwnDeviationAngle          = Standard_False;
1048   myHasOwnHLRDeviationAngle       = Standard_False;
1049   myHasOwnIsoOnPlane              = Standard_False;
1050   myHasOwnIsoOnTriangulation      = Standard_False;
1051   myHasOwnIsAutoTriangulated      = Standard_False;
1052   myHasOwnWireDraw                = Standard_False;
1053   myHasOwnLineArrowDraw           = Standard_False;
1054   myHasOwnDrawHiddenLine          = Standard_False;
1055   myHasOwnFreeBoundaryDraw        = Standard_False;
1056   myHasOwnUnFreeBoundaryDraw      = Standard_False;
1057   myHasOwnFaceBoundaryDraw        = Standard_False;
1058   myHasOwnDimLengthModelUnits     = Standard_False;
1059   myHasOwnDimLengthDisplayUnits   = Standard_False;
1060   myHasOwnDimAngleModelUnits      = Standard_False;
1061   myHasOwnDimAngleDisplayUnits    = Standard_False;
1062   myHasOwnHighlightStyle          = Standard_False;
1063   myHasOwnSelectionStyle          = Standard_False;
1064
1065   myVertexDrawMode = Prs3d_VDM_Inherited;
1066   myTypeOfHLR      = Prs3d_TOH_NotSet;
1067 }
1068
1069 //! Copy line aspect defaults from the Link.
1070 inline void copyLineAspect (const Handle(Prs3d_Drawer)&     theLink,
1071                             Handle(Prs3d_LineAspect)&       theAspect,
1072                             const Handle(Prs3d_LineAspect)& theBaseAspect)
1073 {
1074   Handle(Prs3d_LineAspect) aBaseAspect = theBaseAspect;
1075   if (!theLink.IsNull())
1076   {
1077     theAspect = new Prs3d_LineAspect (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0);
1078     *theAspect->Aspect() = *aBaseAspect->Aspect();
1079   }
1080 }
1081
1082 //! Assign the shader program.
1083 template <typename T>
1084 inline void setAspectProgram (const Handle(Graphic3d_ShaderProgram)& theProgram,
1085                               T thePrsAspect)
1086 {
1087   if (!thePrsAspect.IsNull())
1088   {
1089     thePrsAspect->Aspect()->SetShaderProgram (theProgram);
1090   }
1091 }
1092
1093 // =======================================================================
1094 // function : SetShaderProgram
1095 // purpose  :
1096 // =======================================================================
1097 void Prs3d_Drawer::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram,
1098                                      const Graphic3d_GroupAspect            theAspect,
1099                                      const bool                             theToOverrideDefaults)
1100 {
1101   switch (theAspect)
1102   {
1103     case Graphic3d_ASPECT_LINE:
1104     {
1105       if (theToOverrideDefaults)
1106       {
1107         if (myUIsoAspect.IsNull())
1108         {
1109           Handle(Prs3d_IsoAspect) anAspect = UIsoAspect();
1110           if (!myLink.IsNull())
1111           {
1112             myUIsoAspect = new Prs3d_IsoAspect (Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 1.0, 1);
1113             *myUIsoAspect->Aspect() = *anAspect->Aspect();
1114             myUIsoAspect->SetNumber (anAspect->Number());
1115           }
1116         }
1117         if (myVIsoAspect.IsNull())
1118         {
1119           Handle(Prs3d_IsoAspect) anAspect = VIsoAspect();
1120           if (!myLink.IsNull())
1121           {
1122             myVIsoAspect = new Prs3d_IsoAspect (Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 1.0, 1);
1123             *myVIsoAspect->Aspect() = *anAspect->Aspect();
1124             myUIsoAspect->SetNumber (anAspect->Number());
1125           }
1126         }
1127         if (myWireAspect.IsNull())
1128         {
1129           copyLineAspect (myLink, myWireAspect, WireAspect());
1130         }
1131         if (myLineAspect.IsNull())
1132         {
1133           copyLineAspect (myLink, myLineAspect, LineAspect());
1134         }
1135         if (mySeenLineAspect.IsNull())
1136         {
1137           copyLineAspect (myLink, mySeenLineAspect, SeenLineAspect());
1138         }
1139         if (myHiddenLineAspect.IsNull())
1140         {
1141           copyLineAspect (myLink, myHiddenLineAspect, HiddenLineAspect());
1142         }
1143         if (myVectorAspect.IsNull())
1144         {
1145           copyLineAspect (myLink, myVectorAspect, VectorAspect());
1146         }
1147         if (mySectionAspect.IsNull())
1148         {
1149           copyLineAspect (myLink, mySectionAspect, SectionAspect());
1150         }
1151         if (myFreeBoundaryAspect.IsNull())
1152         {
1153           copyLineAspect (myLink, myFreeBoundaryAspect, FreeBoundaryAspect());
1154         }
1155         if (myUnFreeBoundaryAspect.IsNull())
1156         {
1157           copyLineAspect (myLink, myUnFreeBoundaryAspect, UnFreeBoundaryAspect());
1158         }
1159         if (myFaceBoundaryAspect.IsNull())
1160         {
1161           copyLineAspect (myLink, myFaceBoundaryAspect, FaceBoundaryAspect());
1162         }
1163
1164         if (myPlaneAspect.IsNull())
1165         {
1166           myPlaneAspect = new Prs3d_PlaneAspect();
1167         }
1168         if (myArrowAspect.IsNull())
1169         {
1170           myArrowAspect = new Prs3d_ArrowAspect();
1171         }
1172         if (myDatumAspect.IsNull())
1173         {
1174           myDatumAspect = new Prs3d_DatumAspect();
1175         }
1176       }
1177
1178       setAspectProgram (theProgram, myUIsoAspect);
1179       setAspectProgram (theProgram, myVIsoAspect);
1180       setAspectProgram (theProgram, myWireAspect);
1181       setAspectProgram (theProgram, myLineAspect);
1182       setAspectProgram (theProgram, mySeenLineAspect);
1183       setAspectProgram (theProgram, myHiddenLineAspect);
1184       setAspectProgram (theProgram, myVectorAspect);
1185       setAspectProgram (theProgram, mySectionAspect);
1186       setAspectProgram (theProgram, myFreeBoundaryAspect);
1187       setAspectProgram (theProgram, myUnFreeBoundaryAspect);
1188       setAspectProgram (theProgram, myFaceBoundaryAspect);
1189       if (!myPlaneAspect.IsNull())
1190       {
1191         setAspectProgram (theProgram, myPlaneAspect->EdgesAspect());
1192         setAspectProgram (theProgram, myPlaneAspect->IsoAspect());
1193         setAspectProgram (theProgram, myPlaneAspect->ArrowAspect());
1194       }
1195       if (!myDatumAspect.IsNull())
1196       {
1197         setAspectProgram (theProgram, myDatumAspect->FirstAxisAspect());
1198         setAspectProgram (theProgram, myDatumAspect->SecondAxisAspect());
1199         setAspectProgram (theProgram, myDatumAspect->ThirdAxisAspect());
1200       }
1201       setAspectProgram (theProgram, myArrowAspect);
1202       return;
1203     }
1204     case Graphic3d_ASPECT_TEXT:
1205     {
1206       if (theToOverrideDefaults
1207        && myTextAspect.IsNull())
1208       {
1209         myTextAspect = new Prs3d_TextAspect();
1210         if (!myLink.IsNull())
1211         {
1212           *myTextAspect->Aspect() = *myLink->TextAspect()->Aspect();
1213         }
1214       }
1215
1216       setAspectProgram (theProgram, myTextAspect);
1217       return;
1218     }
1219     case Graphic3d_ASPECT_MARKER:
1220     {
1221       if (theToOverrideDefaults
1222        && myPointAspect.IsNull())
1223       {
1224         myPointAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
1225         if (!myLink.IsNull())
1226         {
1227           *myPointAspect->Aspect() = *myLink->PointAspect()->Aspect();
1228         }
1229       }
1230
1231       setAspectProgram (theProgram, myPointAspect);
1232       return;
1233     }
1234     case Graphic3d_ASPECT_FILL_AREA:
1235     {
1236       if (myShadingAspect.IsNull()
1237        && theToOverrideDefaults)
1238       {
1239         myShadingAspect = new Prs3d_ShadingAspect();
1240         if (!myLink.IsNull())
1241         {
1242           *myShadingAspect->Aspect() = *myLink->ShadingAspect()->Aspect();
1243         }
1244       }
1245       setAspectProgram (theProgram, myShadingAspect);
1246       return;
1247     }
1248   }
1249 }
1250
1251 // =======================================================================
1252 // function : SetHighlightStyle
1253 // purpose  :
1254 // =======================================================================
1255 void Prs3d_Drawer::SetHighlightStyle (const Handle(Graphic3d_HighlightStyle)& theStyle)
1256 {
1257   myHighlightStyle = theStyle;
1258   myHasOwnHighlightStyle = !myHighlightStyle.IsNull();
1259 }
1260
1261 // =======================================================================
1262 // function : SetSelectionStyle
1263 // purpose  :
1264 // =======================================================================
1265 void Prs3d_Drawer::SetSelectionStyle (const Handle(Graphic3d_HighlightStyle)& theStyle)
1266 {
1267   mySelectionStyle = theStyle;
1268   myHasOwnSelectionStyle = !mySelectionStyle.IsNull();
1269 }