Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2007-07-06 |
2 | // Created by: Alexander GRIGORIEV | |
973c2be1 | 3 | // Copyright (c) 2007-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
7fd59977 | 15 | |
16 | #ifndef NIS_Drawer_HeaderFile | |
17 | #define NIS_Drawer_HeaderFile | |
18 | ||
19 | #include <Standard_Transient.hxx> | |
20 | #include <NCollection_List.hxx> | |
21 | #include <TColStd_PackedMapOfInteger.hxx> | |
22 | #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx> | |
23 | #include <NIS_DrawList.hxx> | |
24 | #include <Bnd_B3f.hxx> | |
25 | ||
26 | #ifdef WNT | |
7fd59977 | 27 | #pragma warning (push) |
1c35b92f | 28 | // Disable warning 4480: nonstandard extension used: specifying underlying type for enum 'enum' |
7fd59977 | 29 | #pragma warning (disable:4480) |
30 | #endif | |
31 | ||
857ffd5e | 32 | class Handle(NIS_InteractiveObject); |
33 | class Handle(NIS_View); | |
34 | class Handle(NIS_Drawer); | |
7fd59977 | 35 | class NIS_InteractiveContext; |
36 | class NIS_View; | |
37 | template <class A> class NCollection_Vector; | |
38 | ||
39 | /** | |
ffe2bea7 A |
40 | * Abstract Drawer type. |
41 | * Drawer provides the immediate OpenGL drawing for every NIS_InteractiveObject | |
42 | * maneged by the given Drawer instance. Each Drawer instance has reciprocal | |
43 | * link with a number of NIS_InteractiveObject instances of the same | |
44 | * (corresponding to Drawer) type. The idea is to group the drawing for all | |
45 | * referred interactive objects using the same pre- and post-treatment like | |
46 | * color setting, matrix, polygon offset, line thickness and what not. | |
47 | * | |
48 | * @section nis_drawer_visualprop Visual properties of Drawer | |
49 | * Normally visual properties of any NIS_InteractiveObject are stored in its | |
50 | * Drawer instance, but not in an object. For example, if an interactive object | |
51 | * has method SetColor() then the color is stored in the corresponding Drawer | |
52 | * rather than in the interactive object itself. This scheme avoid useless | |
53 | * duplication when a lot of objects have similar properties like color. Please | |
54 | * see @see nis_interactiveobject_drawer to learn how this mechanism | |
55 | * works from the side of NIS_InteractiveObject. | |
56 | * | |
57 | * @section nis_drawer_drawing Drawing | |
58 | * There are 3 virtual methods to implement OpenGL drawing in this API. They | |
59 | * define the drawing cycle that consists of filling the internal OpenGL draw | |
60 | * list with commands. This drawing cycle is triggered when the corresponding | |
61 | * internal instance of NIS_DrawList has 'IsUpdated' flag (you can set this | |
62 | * flag by means of public methods NIS_Drawer::SetUpdated()). | |
63 | * <ul> | |
64 | * <li><b>BeforeDraw()</b> : contains all OpenGL commands that define the | |
65 | * common set of visual properties for all managed interactive objects. | |
66 | * This method is called once in the beginning of drawing cycle for the | |
67 | * Drawer instance</li> | |
68 | * <li><b>Draw()</b> : all OpenGL commands that are specific to a given | |
69 | * interactive object, usually definition of vertices, triangles, lines, | |
70 | * or their arrays.</li> | |
71 | * <li><b>AfterDraw()</b> : commands that revert the status of OpenGL context | |
72 | * to the state before execution of BeforeDraw(). This method is called | |
73 | * once in the end of drawing cycle.</li> | |
74 | * </ul> | |
75 | * Each of these methods receives NIS_DrawList and DrawType, both identify the | |
76 | * OpenGL draw list that should be filled with commands. Based on DrawType | |
77 | * you will be able to define different presentation - the most important case | |
78 | * is how hilighted (selected) interactive object is presented. | |
79 | * <p> | |
80 | * For advanced purposes you also can redefine the virtual method redraw(), it | |
81 | * is dedicated to higher-level management of draw lists and ordering of | |
82 | * their update when necessary. | |
83 | * | |
84 | * @section nis_drawer_distinction Distinction of Drawer instances | |
85 | * Every Drawer should define which interactive objects it may manage and | |
86 | * which - may not. The same idea could be shaped alternatively: every | |
87 | * interactive object should understand to what Drawer it can attach itself. | |
88 | * This question is answerd by special virtual method IsEqual() that compares | |
89 | * two Drawers of the same type. <b>Two instances of Drawer are equal if they | |
90 | * have the same set of visual properties that are implemented in BeforeDraw(). | |
91 | * </b> The method IsEqual() is the core of Drawer architecture and it must | |
92 | * be implemented very carefully for any new type. Particularly, for any | |
93 | * derived class the method IsEqual() should first call the same method of | |
94 | * its superclass. | |
95 | * <p> | |
96 | * For the optimal efficiency of OpenGL drawing it is better to keep the size | |
97 | * of draw list (i.e., the number of interactive objects in a Drawer instance) | |
98 | * not too small and not too big. The latter limitation is entered by the | |
99 | * protected field myObjPerDrawer. It is used in method IsEqual() of the base | |
100 | * Drawer class: two Drawers are not equal if they are initialized on objects | |
101 | * that have too different IDs -- even if all visual properties of these two | |
102 | * Drawer instances coincide. | |
103 | * <p> | |
104 | * @section nis_drawer_cloning Cloning Drawer instances | |
105 | * It is possible to clone a Drawer instance with the viryual method Assign(). | |
106 | * This method copies all visual properties and other important data from the | |
107 | * Drawer provided as parameter. Method Clone() also should be very carefully | |
108 | * implemented for any new Drawer type, to make sure that all necessary data | |
109 | * fields and structures are properly copied. | |
7fd59977 | 110 | */ |
111 | ||
112 | class NIS_Drawer : public Standard_Transient | |
113 | { | |
114 | public: | |
ffe2bea7 A |
115 | #if defined(WNT) && (_MSC_VER >= 1400) |
116 | enum DrawType : unsigned int { | |
7fd59977 | 117 | #else |
ffe2bea7 | 118 | enum DrawType { |
7fd59977 | 119 | #endif |
120 | Draw_Normal = 0, | |
ffe2bea7 A |
121 | Draw_Top = 1, |
122 | Draw_Transparent = 2, | |
123 | Draw_Hilighted = 3, | |
124 | Draw_DynHilighted = 4 | |
7fd59977 | 125 | }; |
126 | ||
127 | public: | |
128 | // ---------- PUBLIC METHODS ---------- | |
129 | ||
130 | ||
131 | /** | |
132 | * Empty constructor. | |
133 | */ | |
ffe2bea7 A |
134 | inline NIS_Drawer () |
135 | : myTransparency (0.f), | |
136 | myIniId (0), | |
137 | myObjPerDrawer (1024), | |
138 | myCtx (0L) | |
139 | {} | |
7fd59977 | 140 | |
141 | /** | |
142 | * Destructor. | |
143 | */ | |
144 | Standard_EXPORT virtual ~NIS_Drawer (); | |
145 | ||
146 | /** | |
147 | * Query the Interactive Context. | |
148 | */ | |
149 | inline NIS_InteractiveContext * GetContext () const | |
150 | { return myCtx; } | |
151 | ||
152 | /** | |
153 | * Copy the relevant information from another instance of Drawer. | |
154 | * raises exception if theOther has incompatible type (test IsKind). | |
155 | */ | |
857ffd5e | 156 | Standard_EXPORT virtual void Assign (const Handle(NIS_Drawer)& theOther); |
7fd59977 | 157 | |
158 | /** | |
159 | * Create a3D bounding box of drawn objects. | |
160 | * @param pView | |
161 | * In not NULL, only objects visible in this view are taken. | |
162 | */ | |
163 | Standard_EXPORT virtual const Bnd_B3f& | |
164 | GetBox (const NIS_View * pView = 0L) const; | |
165 | ||
166 | /** | |
167 | * Mark all draw lists for update | |
168 | */ | |
169 | Standard_EXPORT void SetUpdated (const DrawType theType) const; | |
170 | ||
171 | Standard_EXPORT void SetUpdated (const DrawType theType1, | |
172 | const DrawType theType2) const; | |
173 | ||
174 | Standard_EXPORT void SetUpdated (const DrawType theType1, | |
175 | const DrawType theType2, | |
176 | const DrawType theType3) const; | |
177 | ||
ffe2bea7 A |
178 | Standard_EXPORT void SetUpdated (const DrawType theType1, |
179 | const DrawType theType2, | |
180 | const DrawType theType3, | |
181 | const DrawType theType4) const; | |
182 | ||
7fd59977 | 183 | /** |
184 | * Switch on/off the dynamic hilight of the given object in the | |
185 | * given view. | |
186 | * @param isHilighted | |
187 | * True if the object should be hilighted, False - if not hilighted | |
188 | * @param theObj | |
189 | * Object instance that should be hilighted or unhilighted. | |
190 | * @param theView | |
191 | * View where the status of object must be changed. If NULL, the object | |
192 | * is hilighted/unhilighted in all views. | |
193 | */ | |
194 | Standard_EXPORT void SetDynamicHilighted | |
195 | (const Standard_Boolean isHilighted, | |
857ffd5e | 196 | const Handle(NIS_InteractiveObject)& theObj, |
197 | const Handle(NIS_View)& theView = 0L); | |
7fd59977 | 198 | |
199 | /** | |
200 | * Hash value, for Map interface. | |
201 | */ | |
202 | Standard_EXPORT virtual Standard_Integer | |
203 | HashCode(const Standard_Integer theN) const; | |
204 | ||
205 | /** | |
206 | * Matching two instances, for Map interface. | |
207 | */ | |
208 | Standard_EXPORT virtual Standard_Boolean | |
857ffd5e | 209 | IsEqual (const Handle(NIS_Drawer)& theOth) const; |
7fd59977 | 210 | |
211 | /** | |
212 | * Obtain the iterator of IDs of associated objects. | |
213 | */ | |
214 | inline TColStd_MapIteratorOfPackedMapOfInteger | |
215 | ObjectIterator () const | |
216 | { return TColStd_MapIteratorOfPackedMapOfInteger (myMapID); } | |
217 | ||
ffe2bea7 A |
218 | /** |
219 | * Query associated draw lists. | |
220 | */ | |
221 | inline NCollection_List<NIS_DrawList *> | |
222 | GetLists() const | |
223 | { return myLists; } | |
224 | ||
7fd59977 | 225 | protected: |
ffe2bea7 A |
226 | /** |
227 | * Called to add draw list IDs to ex-list Ids of view. These draw lists are | |
228 | * eventually released in the callback function, before anything is displayed | |
229 | */ | |
857ffd5e | 230 | Standard_EXPORT void UpdateExListId (const Handle(NIS_View)& theView) const; |
ffe2bea7 | 231 | |
7fd59977 | 232 | // ---------- PROTECTED METHODS ---------- |
233 | ||
234 | /** | |
235 | * Called before execution of Draw(), once per group of interactive objects. | |
236 | */ | |
237 | Standard_EXPORT virtual void BeforeDraw | |
238 | (const DrawType theType, | |
239 | const NIS_DrawList& theDrawList ); | |
240 | ||
241 | /** | |
242 | * Called after execution of Draw(), once per group of interactive objects. | |
243 | */ | |
244 | Standard_EXPORT virtual void AfterDraw | |
245 | (const DrawType theType, | |
246 | const NIS_DrawList& theDrawList); | |
247 | ||
248 | /** | |
249 | * Main function: display the given interactive object in the given view. | |
250 | */ | |
857ffd5e | 251 | Standard_EXPORT virtual void Draw (const Handle(NIS_InteractiveObject)&, |
7fd59977 | 252 | const DrawType theType, |
253 | const NIS_DrawList& theDrawList)= 0; | |
254 | ||
255 | Standard_EXPORT virtual void redraw (const DrawType theType, | |
857ffd5e | 256 | const Handle(NIS_View)& theView); |
7fd59977 | 257 | |
258 | Standard_EXPORT void addObject (const NIS_InteractiveObject * theObj, | |
ffe2bea7 A |
259 | const Standard_Boolean isShareList, |
260 | const Standard_Boolean isUpVws); | |
7fd59977 | 261 | |
262 | Standard_EXPORT void removeObject (const NIS_InteractiveObject * theObj, | |
263 | const Standard_Boolean isUpVws); | |
264 | ||
265 | Standard_EXPORT virtual NIS_DrawList* | |
857ffd5e | 266 | createDefaultList (const Handle(NIS_View)&) const; |
7fd59977 | 267 | |
ffe2bea7 A |
268 | protected: |
269 | //! Get the number of interactive objects in this drawer | |
270 | inline Standard_Integer NObjects() const | |
271 | { return myMapID.Extent(); } | |
272 | ||
7fd59977 | 273 | private: |
274 | // ---------- PRIVATE (PROHIBITED) METHODS ---------- | |
275 | ||
276 | NIS_Drawer (const NIS_Drawer& theOther); | |
277 | NIS_Drawer& operator = (const NIS_Drawer& theOther); | |
278 | ||
279 | // ---------- PRIVATE METHODS ---------- | |
ffe2bea7 A |
280 | void prepareList (const NIS_Drawer::DrawType theType, |
281 | const NIS_DrawList& theDrawLst, | |
282 | const TColStd_PackedMapOfInteger& mapObj); | |
7fd59977 | 283 | |
284 | protected: | |
285 | // ---------- PROTECTED FIELDS ---------- | |
286 | NCollection_List<NIS_DrawList*> myLists; | |
ffe2bea7 A |
287 | Standard_ShortReal myTransparency; |
288 | //! ID of the initializing InteractiveObject. It is never changed, can be | |
289 | //! used to compute hash code of the Drawer instance. | |
290 | Standard_Integer myIniId; | |
291 | //! Maximal range of IDs of objects in one drawer. Limits the size of | |
292 | //! draw lists. Can be initialized only in constructor (default 1024). It is | |
293 | //! strictly prohibited to change this value outside the constructor. | |
294 | Standard_Integer myObjPerDrawer; | |
7fd59977 | 295 | |
296 | private: | |
297 | // ---------- PRIVATE FIELDS ---------- | |
298 | ||
299 | NIS_InteractiveContext * myCtx; | |
300 | TColStd_PackedMapOfInteger myMapID; | |
301 | Bnd_B3f myBox; | |
302 | ||
303 | friend class NIS_InteractiveContext; | |
304 | friend class NIS_InteractiveObject; | |
ffe2bea7 | 305 | friend class NIS_View; |
7fd59977 | 306 | |
307 | public: | |
308 | // Declaration of CASCADE RTTI | |
309 | DEFINE_STANDARD_RTTI (NIS_Drawer) | |
310 | }; | |
311 | ||
312 | // Definition of HANDLE object using Standard_DefineHandle.hxx | |
313 | DEFINE_STANDARD_HANDLE (NIS_Drawer, Standard_Transient) | |
314 | ||
315 | //======================================================================= | |
316 | //function : HashCode | |
317 | //purpose : | |
318 | //======================================================================= | |
319 | ||
857ffd5e | 320 | inline Standard_Integer HashCode (const Handle(NIS_Drawer)& theDrawer, |
7fd59977 | 321 | const Standard_Integer theN) |
322 | { return theDrawer.IsNull() ? 0 : theDrawer->HashCode (theN); } | |
323 | ||
324 | //======================================================================= | |
325 | //function : IsEqual | |
326 | //purpose : | |
327 | //======================================================================= | |
328 | ||
857ffd5e | 329 | inline Standard_Boolean IsEqual (const Handle(NIS_Drawer)& theDrawer1, |
330 | const Handle(NIS_Drawer)& theDrawer2) | |
7fd59977 | 331 | { return theDrawer1.IsNull()? Standard_False: theDrawer1->IsEqual(theDrawer2); } |
332 | ||
333 | #ifdef WNT | |
334 | #pragma warning (pop) | |
335 | #endif | |
336 | ||
337 | #endif |