0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / Graphic3d / Graphic3d_BoundBuffer.hxx
1 // Copyright (c) 2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _Graphic3d_BoundBuffer_HeaderFile
15 #define _Graphic3d_BoundBuffer_HeaderFile
16
17 #include <Graphic3d_Buffer.hxx>
18
19 //! Bounds buffer.
20 class Graphic3d_BoundBuffer : public NCollection_Buffer
21 {
22 public:
23
24   //! Empty constructor.
25   Graphic3d_BoundBuffer (const Handle(NCollection_BaseAllocator)& theAlloc)
26   : NCollection_Buffer (theAlloc),
27     Colors   (NULL),
28     Bounds   (NULL),
29     NbBounds (0) {}
30
31   //! Allocates new empty array
32   bool Init (const Standard_Integer theNbBounds,
33              const Standard_Boolean theHasColors)
34   {
35     Colors   = NULL;
36     Bounds   = NULL;
37     NbBounds = 0;
38     Free();
39     if (theNbBounds < 1)
40     {
41       return false;
42     }
43
44     const size_t aBoundsSize = sizeof(Standard_Integer) * theNbBounds;
45     const size_t aColorsSize = theHasColors
46                              ? sizeof(Graphic3d_Vec4) * theNbBounds
47                              : 0;
48     if (!Allocate (aColorsSize + aBoundsSize))
49     {
50       Free();
51       return false;
52     }
53
54     NbBounds = theNbBounds;
55     Colors   = theHasColors ? reinterpret_cast<Graphic3d_Vec4* >(myData) : NULL;
56     Bounds   = reinterpret_cast<Standard_Integer* >(theHasColors ? (myData + aColorsSize) : myData);
57     return true;
58   }
59
60 public:
61
62   Graphic3d_Vec4*   Colors;   //!< pointer to facet color values
63   Standard_Integer* Bounds;   //!< pointer to bounds array
64   Standard_Integer  NbBounds; //!< number of bounds
65
66 public:
67
68   DEFINE_STANDARD_RTTI_INLINE(Graphic3d_BoundBuffer,NCollection_Buffer) // Type definition
69
70 };
71
72 DEFINE_STANDARD_HANDLE(Graphic3d_BoundBuffer, NCollection_Buffer)
73
74 #endif // _Graphic3d_BoundBuffer_HeaderFile