HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP3D_SelectionManager.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: OP3D_SelectionManager.h ( OP3D Library, C++)
7  *
8  * COMMENTS:
9  * An OP3D_SelectionManager stores and manages selections that need to
10  * persist beyond the lifetime of an individual selector. This may be
11  * because the selection is needed to bootstrap another selector later,
12  * or because we want the selection to be saved for when we next select
13  * from that geometry.
14  *
15  * Each viewer has its instance of this selection manager.
16  *
17  */
18 
19 #ifndef __OP3D_SelectionManager__
20 #define __OP3D_SelectionManager__
21 
22 #include "OP3D_API.h"
23 
24 #include <UT/UT_NonCopyable.h>
25 #include <UT/UT_SharedPtr.h>
26 #include <UT/UT_Map.h>
27 #include <UT/UT_IntArray.h>
28 #include "OP3D_SelectionCache.h"
29 
30 class UT_JSONWriter;
31 class UT_JSONParser;
32 class OP_Node;
33 
35 {
36 public:
38 
40 
41  class ComponentScopeKey;
42 
43  static ComponentScopeKey getComponentSelectionScope(OP_Node *node);
44  static ComponentScopeKey getComponentSelectionScopeOfChildren(
45  OP_Node *node);
46  static bool isObject(const ComponentScopeKey &scope);
47 
48  /// Component selectors (OP3D_InputSelector) can be divided into two
49  /// categories based on the lifetime of the temporary selections they
50  // create.
51  /// 1. Selectors that save their temporary selections on exit. These
52  /// selections persist until they are consumed (either by the next
53  /// selector or by a state explicitly consuming them to perform an
54  /// operation) or explicitly cleared.
55  /// 2. Selectors with completely local temporary selections. These
56  /// selections cease to exist with the selectors that created them
57  /// and generally do not intefere with any other selections (saved
58  /// or live).
59  ///
60  /// Component selectors of the second type cannot interfere with any
61  /// other selector, but selectors of the first type, by far the more
62  /// common, require careful synchronization and storage when multiple
63  /// instances are active simultaneously (each, of course, in a different
64  /// viewer) or for successive instances to pass selections between them.
65  /// We choose to use an independent selection manager (and hence set of
66  /// caches) for each viewer, sidestepping the first issue entirely. To
67  /// address the passing of selections from one selector to the next, we
68  /// implement a set of caches.
69  ///
70  /// The first simplifying decision we make for selectors that save their
71  /// temporary selections on exit is to distinguish these saved selections
72  /// by the network (abstracted to a ComponentScopeKey) at which they are
73  /// made. Selections made at /obj/A will generally not intefere with
74  /// ones made at /obj/B, even if the selectors allow selecting from other
75  /// objects (and connecting them with Object Merge SOPs). This is made
76  /// possible by each OP3D_SelectionCache being able to store selections
77  /// for nodes external to that scope.
78 
79  OP3D_SelectionCacheHandle getUserSelectionCache(
80  ComponentScopeKey scope);
81  OP3D_SelectionCacheHandle getOrCreateUserSelectionCache(
82  ComponentScopeKey scope);
83 
84  /// Return the total memory used by the user selection caches in bytes.
85  int64 getUserSelectionCacheTotalMem() const;
86 
87  /// Attempt to reduce the memory used by the user selection caches by a
88  /// specified amount, returning the actual number of bytes freed.
89  int64 reduceUserSelectionCacheMem(int64 amount);
90 
91  /// Flag enabled when geometry selection is set by the select state.
92  void setSopSelectionStashed(bool v);
93  bool getSopSelectionStashed();
94 
95  /// Node IDs of most recent object selection.
96  void setObjSelection(const UT_IntArray &nodes);
97  void getObjSelection(UT_IntArray &nodes);
98 
99 private:
100  UT_Map<int, OP3D_SelectionCacheHandle> myUserComponentSelections;
101  UT_IntArray myObjSelection;
102  bool mySelectionStashed;
103 };
104 
105 class OP3D_API OP3D_SelectionManager::ComponentScopeKey
106 {
107 public:
108  ComponentScopeKey() : myNodeId(-1)
109  {
110  }
111 
112  bool isValid() const { return myNodeId >= 0; }
113  bool operator==(const ComponentScopeKey &src) const
114  { return myNodeId == src.myNodeId; }
115  bool operator!=(const ComponentScopeKey &src) const
116  { return myNodeId != src.myNodeId; }
117 
118  bool save(UT_JSONWriter &w) const;
119  bool load(UT_JSONParser &p);
120 private:
121  ComponentScopeKey(int node_id)
122  : myNodeId(node_id)
123  {
124  }
125 
126  int myNodeId;
127  friend class OP3D_SelectionManager;
128 };
129 
131 
132 #endif // __OP3D_SelectionManager__
const GLdouble * v
Definition: glcorearb.h:837
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
bool operator!=(const ComponentScopeKey &src) const
UT_SharedPtr< OP3D_SelectionCache > OP3D_SelectionCacheHandle
long long int64
Definition: SYS_Types.h:116
bool operator==(const ComponentScopeKey &src) const
#define OP3D_API
Definition: OP3D_API.h:10
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
OP3D_API OP3D_SelectionManager * OP3DgetSelectionManager()
GLenum src
Definition: glcorearb.h:1793