0022819: Redesign of OpenGl driver Additional integration
[occt.git] / src / OpenGl / OpenGl_GraphicDriver_703.cxx
1 // File:      OpenGl_GraphicDriver_703.cxx
2 // Created:   20 October 2011
3 // Author:    Sergey ZERCHANINOV
4 // Copyright: OPEN CASCADE 2011
5
6 #include <OpenGl_GraphicDriver.hxx>
7
8 #include <Aspect_TypeOfMarker.hxx>
9 #include <OpenGl_Group.hxx>
10 #include <OpenGl_MarkerSet.hxx>
11 #include <Graphic3d_Array1OfVertex.hxx>
12
13 static void OpenGl_CreateMarkers(const Graphic3d_CGroup& ACGroup, const Standard_Integer NbPoints, const Graphic3d_Vertex *Points)
14 {
15   OpenGl_MarkerSet *amarkerset = new OpenGl_MarkerSet( NbPoints, Points );
16   ((OpenGl_Group *)ACGroup.ptrGroup)->AddElement( TelMarkerSet, amarkerset );
17 }
18
19 void OpenGl_GraphicDriver::Marker (const Graphic3d_CGroup& ACGroup, const Graphic3d_Vertex& APoint, const Standard_Boolean )
20 {
21   if (!ACGroup.ptrGroup)
22     return;
23
24   const Aspect_TypeOfMarker AType = Aspect_TypeOfMarker (ACGroup.ContextMarker.MarkerType);
25
26   switch (AType) 
27   {
28     case Aspect_TOM_POINT :
29     case Aspect_TOM_PLUS :
30     case Aspect_TOM_STAR :
31     case Aspect_TOM_O :
32     case Aspect_TOM_X :
33     case Aspect_TOM_O_POINT :
34     case Aspect_TOM_O_PLUS :
35     case Aspect_TOM_O_STAR :
36     case Aspect_TOM_O_X :
37     case Aspect_TOM_RING1 :
38     case Aspect_TOM_RING2 :
39     case Aspect_TOM_RING3 :
40     case Aspect_TOM_USERDEFINED:
41       OpenGl_CreateMarkers(ACGroup, 1, &APoint);
42       break;
43
44     case Aspect_TOM_BALL :
45     {
46       const Standard_Real Delta = 0.1;
47
48       Standard_Real R, G, B, H, L, S, AScale;
49       R = Standard_Real (ACGroup.ContextMarker.Color.r);
50       G = Standard_Real (ACGroup.ContextMarker.Color.g);
51       B = Standard_Real (ACGroup.ContextMarker.Color.b);
52       AScale = Standard_Real (ACGroup.ContextMarker.Scale);
53
54       // we draw a set of circles
55           CALL_DEF_CONTEXTMARKER AContext;
56       AContext.MarkerType = int (Aspect_TOM_O);
57       while (AScale >= 1.0)
58       {
59         Quantity_Color::RgbHls (R, G, B, H, L, S);
60         // Modification de la saturation de 5 %
61         S *= 0.95;
62         Quantity_Color::HlsRgb (H, L, S, R, G, B);
63         AContext.Color.r  = float (R);
64         AContext.Color.g  = float (G);
65         AContext.Color.b  = float (B);
66         AContext.Scale  = float (AScale);
67         ((OpenGl_Group *)ACGroup.ptrGroup)->SetAspectMarker(AContext, Standard_False);
68         OpenGl_CreateMarkers(ACGroup, 1, &APoint);
69         AScale -= Delta;
70       }
71       break;
72     }
73     default:
74       break;
75   }
76 }
77
78 void OpenGl_GraphicDriver::MarkerSet (const Graphic3d_CGroup& ACGroup,
79                                      const Graphic3d_Array1OfVertex& ListVertex,
80                                      const Standard_Boolean )
81 {
82   if (!ACGroup.ptrGroup)
83     return;
84
85   const Standard_Integer nb = ListVertex.Length();
86   const Graphic3d_Vertex *arr = &ListVertex( ListVertex.Lower() );
87
88   const Aspect_TypeOfMarker AType = Aspect_TypeOfMarker (ACGroup.ContextMarker.MarkerType);
89
90   switch (AType)
91   {
92     case Aspect_TOM_POINT :
93     case Aspect_TOM_PLUS :
94     case Aspect_TOM_STAR :
95     case Aspect_TOM_O :
96     case Aspect_TOM_X :
97     case Aspect_TOM_O_POINT :
98     case Aspect_TOM_O_PLUS :
99     case Aspect_TOM_O_STAR :
100     case Aspect_TOM_O_X :
101     case Aspect_TOM_RING1 :
102     case Aspect_TOM_RING2 :
103     case Aspect_TOM_RING3 :
104     case Aspect_TOM_USERDEFINED:
105       OpenGl_CreateMarkers(ACGroup, nb, arr);
106       break;
107
108     case Aspect_TOM_BALL :
109     {
110       const Standard_Real Delta = 0.1;
111
112       Standard_Real R, G, B, H, L, S, AScale;
113       R = Standard_Real (ACGroup.ContextMarker.Color.r);
114       G = Standard_Real (ACGroup.ContextMarker.Color.g);
115       B = Standard_Real (ACGroup.ContextMarker.Color.b);
116       AScale = Standard_Real (ACGroup.ContextMarker.Scale);
117
118       // we draw a set of circles
119           CALL_DEF_CONTEXTMARKER AContext;
120       AContext.MarkerType = int (Aspect_TOM_O);
121       while (AScale >= 1.0)
122       {
123         Quantity_Color::RgbHls (R, G, B, H, L, S);
124         // Modification de la saturation de 5 %
125         S *= 0.95;
126         Quantity_Color::HlsRgb (H, L, S, R, G, B);
127         AContext.Color.r  = float (R);
128         AContext.Color.g  = float (G);
129         AContext.Color.b  = float (B);
130         AContext.Scale  = float (AScale);
131         ((OpenGl_Group *)ACGroup.ptrGroup)->SetAspectMarker(AContext, Standard_False);
132         OpenGl_CreateMarkers(ACGroup, nb, arr);
133         AScale -= Delta;
134       }
135       break;
136     }
137     default:
138       break;
139   }
140 }