0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / NIS / NIS_DrawList.cxx
1 // Created on: 2007-07-09
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <NIS_Drawer.hxx>
17 #include <NIS_View.hxx>
18
19 #include <OpenGl_GlCore11.hxx>
20
21 //=======================================================================
22 //function : NIS_DrawList()
23 //purpose  : Empty Constructor
24 //=======================================================================
25
26 NIS_DrawList::NIS_DrawList ()
27 {
28 #ifdef ARRAY_LISTS
29   myListID = 0;
30 #else
31   myListID[0] = 0;
32   myListID[1] = 0;
33   myListID[2] = 0;
34   myListID[3] = 0;
35   myListID[4] = 0;
36 #endif
37   myIsUpdated[0] = Standard_True;
38   myIsUpdated[1] = Standard_True;
39   myIsUpdated[2] = Standard_True;
40   myIsUpdated[3] = Standard_True;
41   myIsUpdated[4] = Standard_True;
42 }
43
44 //=======================================================================
45 //function : NIS_DrawList()
46 //purpose  : Constructor
47 //=======================================================================
48
49 NIS_DrawList::NIS_DrawList (const Handle_NIS_View& theView)
50   : myView      (theView)
51 {
52 #ifdef ARRAY_LISTS
53   myListID = 0;
54 #else
55   myListID[0] = 0;
56   myListID[1] = 0;
57   myListID[2] = 0;
58   myListID[3] = 0;
59   myListID[4] = 0;
60 #endif
61   myIsUpdated[0] = Standard_True;
62   myIsUpdated[1] = Standard_True;
63   myIsUpdated[2] = Standard_True;
64   myIsUpdated[3] = Standard_True;
65   myIsUpdated[4] = Standard_True;
66 }
67
68 //=======================================================================
69 //function : ~NIS_DrawList
70 //purpose  :
71 //=======================================================================
72
73 NIS_DrawList::~NIS_DrawList ()
74 {
75   //if (myListID != 0)
76     //glDeleteLists (myListID, 5);
77 }
78
79 //=======================================================================
80 //function : ClearListID
81 //purpose  : Set myListID to 0.
82 //=======================================================================
83
84 void NIS_DrawList::ClearListID (const Standard_Integer theType)
85 {
86 #ifndef ARRAY_LISTS
87   if (theType >= 0) {
88     // To be called only in Callback context (i.e. when GL context is active)
89     if (myListID[theType] > 0) {
90       glDeleteLists(myListID[theType], 1);
91       myListID[theType] = 0;
92     }
93     myIsUpdated[theType] = Standard_False;
94   }
95 #endif
96 }
97
98 //=======================================================================
99 //function : ClearListID
100 //purpose  : Set myListID to 0.
101 //=======================================================================
102
103 void NIS_DrawList::ClearListID (const Handle_NIS_View& theView)
104 {
105 #ifdef ARRAY_LISTS
106   if (myListID > 0)
107     myView->GetExListId().Add(myListID);
108   myListID = 0;
109 #else
110   NIS_View * pView = (myView.IsNull()) ?
111     theView.operator->() : myView.operator->();
112   if (pView) {
113     if (myListID[0] > 0)
114       pView->GetExListId().Add(myListID[0]);
115     myListID[0] = 0;
116     if (myListID[1] > 0)
117       pView->GetExListId().Add(myListID[1]);
118     myListID[1] = 0;
119     if (myListID[2] > 0)
120       pView->GetExListId().Add(myListID[2]);
121     myListID[2] = 0;
122     if (myListID[3] > 0)
123       pView->GetExListId().Add(myListID[3]);
124     myListID[3] = 0;
125     if (myListID[4] > 0)
126       pView->GetExListId().Add(myListID[4]);
127     myListID[4] = 0;
128   }
129
130 #endif
131   myIsUpdated[0] = Standard_False;
132   myIsUpdated[1] = Standard_False;
133   myIsUpdated[2] = Standard_False;
134   myIsUpdated[3] = Standard_False;
135   myIsUpdated[4] = Standard_False;
136 }
137
138 //=======================================================================
139 //function : BeginPrepare
140 //purpose  :
141 //=======================================================================
142
143 void NIS_DrawList::BeginPrepare (const Standard_Integer theType)
144 {
145 #ifdef ARRAY_LISTS
146   if (myListID == 0)
147     myListID = glGenLists(5);
148 #else
149   if (GetListID(theType) == 0)
150     myListID[theType] = glGenLists(1);
151 #endif
152   glNewList (GetListID(theType), GL_COMPILE);
153 }
154
155 //=======================================================================
156 //function : EndPrepare
157 //purpose  :
158 //=======================================================================
159
160 void NIS_DrawList::EndPrepare (const Standard_Integer theType)
161 {
162   glEndList ();
163   myIsUpdated[theType] = Standard_False;
164 }
165
166 //=======================================================================
167 //function : Call
168 //purpose  :
169 //=======================================================================
170
171 void NIS_DrawList::Call (const Standard_Integer theType)
172 {
173   glCallList (GetListID (theType));
174 }
175
176 //=======================================================================
177 //function : SetDynHilighted
178 //purpose  :
179 //=======================================================================
180
181 Standard_Boolean NIS_DrawList::SetDynHilighted
182                                 (const Standard_Boolean              isHili,
183                                  const Handle_NIS_InteractiveObject& theObj)
184 {
185   Standard_Boolean aResult (Standard_False);
186   NCollection_List<Handle_NIS_InteractiveObject>::Iterator anIt(myDynHilighted);
187   for (; anIt.More(); anIt.Next())
188     if (anIt.Value() == theObj)
189       break;
190   if (anIt.More()) {
191     if (isHili == Standard_False) {
192       myIsUpdated[NIS_Drawer::Draw_DynHilighted] = Standard_True;
193       myDynHilighted.Remove (anIt);
194       aResult = Standard_True;
195     }
196   } else
197     if (isHili == Standard_True) {
198       myIsUpdated[NIS_Drawer::Draw_DynHilighted] = Standard_True;
199       myDynHilighted.Append (theObj);
200       aResult = Standard_True;
201     }
202   return aResult;
203 }
204
205 //=======================================================================
206 //function : SetUpdated
207 //purpose  :
208 //=======================================================================
209
210 void NIS_DrawList::SetUpdated (const Standard_Integer theType,
211                                const Standard_Boolean theFlag)
212 {
213   if (theFlag)
214     SetUpdated(theType);
215   else
216     myIsUpdated [theType] = Standard_False;
217 }
218
219 //=======================================================================
220 //function : SetUpdated
221 //purpose  :
222 //=======================================================================
223
224 void NIS_DrawList::SetUpdated (const Standard_Integer theType)
225 {
226   myIsUpdated [theType] = Standard_True;
227   if (theType == NIS_Drawer::Draw_Hilighted)
228     myDynHilighted.Clear();
229 }