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