0023634: Eliminate Polyline and Polygon usage in drawers
[occt.git] / src / OpenGl / OpenGl_GraphicDriver_703.cxx
1 // Created on: 2011-10-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21 #include <OpenGl_GraphicDriver.hxx>
22
23 #include <Aspect_TypeOfMarker.hxx>
24 #include <OpenGl_Group.hxx>
25 #include <OpenGl_MarkerSet.hxx>
26 #include <Graphic3d_Array1OfVertex.hxx>
27
28 static void OpenGl_CreateMarkers(const Graphic3d_CGroup& ACGroup, const Standard_Integer NbPoints, const Graphic3d_Vertex *Points)
29 {
30   OpenGl_MarkerSet *amarkerset = new OpenGl_MarkerSet( NbPoints, Points );
31   ((OpenGl_Group *)ACGroup.ptrGroup)->AddElement( TelMarkerSet, amarkerset );
32 }
33
34 void OpenGl_GraphicDriver::Marker (const Graphic3d_CGroup& ACGroup, const Graphic3d_Vertex &APoint)
35 {
36   if (!ACGroup.ptrGroup)
37     return;
38
39   const Aspect_TypeOfMarker AType = Aspect_TypeOfMarker (ACGroup.ContextMarker.MarkerType);
40
41   switch (AType) 
42   {
43     case Aspect_TOM_POINT :
44     case Aspect_TOM_PLUS :
45     case Aspect_TOM_STAR :
46     case Aspect_TOM_O :
47     case Aspect_TOM_X :
48     case Aspect_TOM_O_POINT :
49     case Aspect_TOM_O_PLUS :
50     case Aspect_TOM_O_STAR :
51     case Aspect_TOM_O_X :
52     case Aspect_TOM_RING1 :
53     case Aspect_TOM_RING2 :
54     case Aspect_TOM_RING3 :
55     case Aspect_TOM_USERDEFINED:
56       OpenGl_CreateMarkers(ACGroup, 1, &APoint);
57       break;
58
59     case Aspect_TOM_BALL :
60     {
61       const Standard_Real Delta = 0.1;
62
63       Standard_Real R, G, B, H, L, S, AScale;
64       R = Standard_Real (ACGroup.ContextMarker.Color.r);
65       G = Standard_Real (ACGroup.ContextMarker.Color.g);
66       B = Standard_Real (ACGroup.ContextMarker.Color.b);
67       AScale = Standard_Real (ACGroup.ContextMarker.Scale);
68
69       // we draw a set of circles
70           CALL_DEF_CONTEXTMARKER AContext;
71       AContext.MarkerType = int (Aspect_TOM_O);
72       while (AScale >= 1.0)
73       {
74         Quantity_Color::RgbHls (R, G, B, H, L, S);
75         // Modification de la saturation de 5 %
76         S *= 0.95;
77         Quantity_Color::HlsRgb (H, L, S, R, G, B);
78         AContext.Color.r  = float (R);
79         AContext.Color.g  = float (G);
80         AContext.Color.b  = float (B);
81         AContext.Scale  = float (AScale);
82         ((OpenGl_Group *)ACGroup.ptrGroup)->SetAspectMarker(AContext, Standard_False);
83         OpenGl_CreateMarkers(ACGroup, 1, &APoint);
84         AScale -= Delta;
85       }
86       break;
87     }
88     default:
89       break;
90   }
91 }
92
93 void OpenGl_GraphicDriver::MarkerSet (const Graphic3d_CGroup& ACGroup,
94                                       const Graphic3d_Array1OfVertex& ListVertex)
95 {
96   if (!ACGroup.ptrGroup)
97     return;
98
99   const Standard_Integer nb = ListVertex.Length();
100   const Graphic3d_Vertex *arr = &ListVertex( ListVertex.Lower() );
101
102   const Aspect_TypeOfMarker AType = Aspect_TypeOfMarker (ACGroup.ContextMarker.MarkerType);
103
104   switch (AType)
105   {
106     case Aspect_TOM_POINT :
107     case Aspect_TOM_PLUS :
108     case Aspect_TOM_STAR :
109     case Aspect_TOM_O :
110     case Aspect_TOM_X :
111     case Aspect_TOM_O_POINT :
112     case Aspect_TOM_O_PLUS :
113     case Aspect_TOM_O_STAR :
114     case Aspect_TOM_O_X :
115     case Aspect_TOM_RING1 :
116     case Aspect_TOM_RING2 :
117     case Aspect_TOM_RING3 :
118     case Aspect_TOM_USERDEFINED:
119       OpenGl_CreateMarkers(ACGroup, nb, arr);
120       break;
121
122     case Aspect_TOM_BALL :
123     {
124       const Standard_Real Delta = 0.1;
125
126       Standard_Real R, G, B, H, L, S, AScale;
127       R = Standard_Real (ACGroup.ContextMarker.Color.r);
128       G = Standard_Real (ACGroup.ContextMarker.Color.g);
129       B = Standard_Real (ACGroup.ContextMarker.Color.b);
130       AScale = Standard_Real (ACGroup.ContextMarker.Scale);
131
132       // we draw a set of circles
133           CALL_DEF_CONTEXTMARKER AContext;
134       AContext.MarkerType = int (Aspect_TOM_O);
135       while (AScale >= 1.0)
136       {
137         Quantity_Color::RgbHls (R, G, B, H, L, S);
138         // Modification de la saturation de 5 %
139         S *= 0.95;
140         Quantity_Color::HlsRgb (H, L, S, R, G, B);
141         AContext.Color.r  = float (R);
142         AContext.Color.g  = float (G);
143         AContext.Color.b  = float (B);
144         AContext.Scale  = float (AScale);
145         ((OpenGl_Group *)ACGroup.ptrGroup)->SetAspectMarker(AContext, Standard_False);
146         OpenGl_CreateMarkers(ACGroup, nb, arr);
147         AScale -= Delta;
148       }
149       break;
150     }
151     default:
152       break;
153   }
154 }