0023500: MFC texture example is crashed when view closed
[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, const Standard_Boolean )
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                                      const Standard_Boolean )
96 {
97   if (!ACGroup.ptrGroup)
98     return;
99
100   const Standard_Integer nb = ListVertex.Length();
101   const Graphic3d_Vertex *arr = &ListVertex( ListVertex.Lower() );
102
103   const Aspect_TypeOfMarker AType = Aspect_TypeOfMarker (ACGroup.ContextMarker.MarkerType);
104
105   switch (AType)
106   {
107     case Aspect_TOM_POINT :
108     case Aspect_TOM_PLUS :
109     case Aspect_TOM_STAR :
110     case Aspect_TOM_O :
111     case Aspect_TOM_X :
112     case Aspect_TOM_O_POINT :
113     case Aspect_TOM_O_PLUS :
114     case Aspect_TOM_O_STAR :
115     case Aspect_TOM_O_X :
116     case Aspect_TOM_RING1 :
117     case Aspect_TOM_RING2 :
118     case Aspect_TOM_RING3 :
119     case Aspect_TOM_USERDEFINED:
120       OpenGl_CreateMarkers(ACGroup, nb, arr);
121       break;
122
123     case Aspect_TOM_BALL :
124     {
125       const Standard_Real Delta = 0.1;
126
127       Standard_Real R, G, B, H, L, S, AScale;
128       R = Standard_Real (ACGroup.ContextMarker.Color.r);
129       G = Standard_Real (ACGroup.ContextMarker.Color.g);
130       B = Standard_Real (ACGroup.ContextMarker.Color.b);
131       AScale = Standard_Real (ACGroup.ContextMarker.Scale);
132
133       // we draw a set of circles
134           CALL_DEF_CONTEXTMARKER AContext;
135       AContext.MarkerType = int (Aspect_TOM_O);
136       while (AScale >= 1.0)
137       {
138         Quantity_Color::RgbHls (R, G, B, H, L, S);
139         // Modification de la saturation de 5 %
140         S *= 0.95;
141         Quantity_Color::HlsRgb (H, L, S, R, G, B);
142         AContext.Color.r  = float (R);
143         AContext.Color.g  = float (G);
144         AContext.Color.b  = float (B);
145         AContext.Scale  = float (AScale);
146         ((OpenGl_Group *)ACGroup.ptrGroup)->SetAspectMarker(AContext, Standard_False);
147         OpenGl_CreateMarkers(ACGroup, nb, arr);
148         AScale -= Delta;
149       }
150       break;
151     }
152     default:
153       break;
154   }
155 }