HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UN_StickyNoteData.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: UN_StickyNoteData.h ( UN Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UN_StickyNoteData_h__
13 #define __UN_StickyNoteData_h__
14 
15 #include "UN_API.h"
16 #include "UN_Data.h"
17 #include "UN_Utils.h"
18 class UN_GraphData;
19 
20 
21 // ============================================================================
25 
26 // ============================================================================
27 /// Container of data for all the sticky notes in the graph.
28 ///
29 /// NOTE: This class is generally not trivially relocatable, because
30 /// its base class (UN_Data) is not trivially relocatable (see comment there).
31 
33 {
34 public:
35  /// Constructors and destructors.
38  ~UN_StickyNoteData() = default;
39 
42 
43 protected:
44  /// This container can have large data, so generally, forbid
45  /// the costly copy operations to the public.
46  /// Knowledgable friends and derived classes can still use them.
47  friend UN_GraphData;
48  UN_StickyNoteData(const UN_StickyNoteData &) = default;
49  UN_StickyNoteData & operator=(const UN_StickyNoteData &) = default;
50 
51 public:
52  /// Increases the capacity of the data buffer arrays to the given minimum,
53  /// unless the capacity is already greater or equal to that minimum,
54  /// in which case the capacity remains unchanged.
55  void setCapacityIfNeeded( UN_DataSize min_capacity );
56 
57  /// @{ Returns sticky notes's custom data container,
58  /// if one was provided to c-tor.
60  {
62  }
63 
65  {
67  }
68  /// @}
69 
70  /// Merges another sticky data data container into this one.
71  /// Returns a mapping between the sticky data IDs in the merge source
72  /// and destination (this) data buffers.
73  UN_StickyNoteIDRemap merge( const UN_StickyNoteData &src_sticky_note_data );
74 
75  /// Adds a slot for a new sticky note in this container.
76  /// Returns an ID that should be used to refer to this new sticky note
77  /// for accessing its data (eg, source port, destination port, etc).
78  UN_StickyNoteID addStickyNote();
79 
80  /// Clears the data for the given sticky note to the default state.
81  void clearStickyNote(UN_StickyNoteID sticky_note_id );
82 
83  /// Removes the sticky note from this container and frees the
84  /// data slot it occupied. After calling this method,
85  /// the container will have no knowledge of the sticky note by this ID.
86  /// Returns true on successs; false if the sticky note was not found.
87  bool removeStickyNote( UN_StickyNoteID sticky_note_id );
88 
89  /// Frees the data slots occupied by all the sticky notes.
90  /// @param 'reset_next_id' If true, the sticky note ID generator is reset to zero.
91  void removeAllStickyNotes( bool reset_next_id );
92 
93  /// Returns true if the given ID refers to a valid sticky note entry
94  /// in the data buffers. Ie, such a sticky note exists and is valid.
95  bool isValid( UN_StickyNoteID sticky_note_id ) const
96  { return UN_Data::isValid( sticky_note_id ); }
97 
98 
99  /// Iterator for traversing valid sticky note IDs.
101  {
102  public:
103  using value_type = UN_StickyNoteID;
104 
106  : UN_DataIndexMap::IDIterator( id_iterator )
107  {}
108 
110  { return UN_StickyNoteID( UN_DataIndexMap::IDIterator::operator*() ); }
111  };
112 
113  /// Iterator for traversing valid sticky note IDs in an ascending order.
115  {
116  public:
117  using value_type = UN_StickyNoteID;
118 
120  : UN_DataIndexMap::OrderedIDIterator( id_iterator )
121  {}
122 
124  { return UN_StickyNoteID(
125  UN_DataIndexMap::OrderedIDIterator::operator*() ); }
126  };
127 
128 
129  /// Returns a range for iterating valid sticky note IDs.
131  IDRange idRange() const
132  {
133  auto id_range( UN_Data::idRange() );
134  return IDRange( id_range.begin(), id_range.end() );
135  }
136 
137  /// Returns a range for iterating valid sticky note IDs.
140  {
141  auto id_range( UN_Data::orderedIDRange() );
142  return OrderedIDRange( id_range.begin(), id_range.end() );
143  }
144 
145  /// Returns a list of all the valid sticky note IDs in the graph.
146  UN_StickyNoteIDList stickyNoteIDs() const
147  {
148  SYS_STATIC_ASSERT( sizeof(UN_StickyNoteID) == sizeof(UN_DataID) );
149  return reinterpret_cast<UN_StickyNoteIDList&&>( std::move( dataIDs() ));
150  }
151 
152  /// Returns a list of all the valid sticky note IDs in the graph.
153  UN_StickyNoteIDList sortedStickyNoteIDs() const
154  {
155  SYS_STATIC_ASSERT( sizeof(UN_StickyNoteID) == sizeof(UN_DataID) );
156  return reinterpret_cast<UN_StickyNoteIDList&&>(
157  std::move(sortedDataIDs() ));
158  }
159 
160 protected:
161  /// Sets the sticky note name that differentiates it among its siblings.
162  // Only the friend UN_GraphData can call it because it may need to
163  // enforce a unique name.
164  void setName( UN_StickyNoteID note_id, const UT_StringRef &name )
165  {
166  UT_ASSERT( !myCheckValidNames
167  || UN_Utils::isValidGraphItemName( name, myNameSafeChars ));
168  setData( myName, note_id, name );
169  }
170 
171 public:
172  /// Returns the name that identifies the sticky notes among its siblings.
173  const UT_StringHolder & name( UN_StickyNoteID note_id ) const
174  {
175  return getDataRef( myName, note_id, UT_StringHolder::theEmptyString );
176  }
177 
178  /// Sets the sticky note's contents text.
179  void setText( UN_StickyNoteID note_id, const UT_StringRef &text )
180  {
181  setData( myText, note_id, text );
182  }
183 
184  /// Returns the sticky note's contents.
185  const UT_StringHolder & text( UN_StickyNoteID note_id ) const
186  {
187  return getDataRef( myText, note_id, theDefText );
188  }
189 
190  /// Sets the sticky note's location in the graph editor.
191  void setPosition( UN_StickyNoteID note_id, const UT_Vector2D &position )
192  {
193  setData( myPosition, note_id, position );
194  }
195 
196  /// Returns the sticky note's position in the graph editor.
197  const UT_Vector2D & position( UN_StickyNoteID note_id ) const
198  {
199  return getDataRef( myPosition, note_id, theDefPos );
200  }
201 
202  /// Sets the sticky note's width and height.
203  void setDimensions( UN_StickyNoteID note_id, const UT_Vector2D &dimensions )
204  {
205  setData( myDimensions, note_id, dimensions );
206  }
207 
208  /// Returns the sticky note's dimensions (width & height).
209  const UT_Vector2D & dimensions( UN_StickyNoteID note_id ) const
210  {
211  return getDataRef( myDimensions, note_id, theDefDim );
212  }
213 
214  /// Sets the sticky notes's background color in the graph editor.
215  void setColor( UN_StickyNoteID note_id, const UT_Color &color )
216  {
217  setData( myColor, note_id, color );
218  }
219 
220  /// Returns the sticky note's background color in the graph editor.
221  const UT_Color & color( UN_StickyNoteID note_id ) const
222  {
223  return getDataRef( myColor, note_id, theDefColor );
224  }
225 
226  /// Sets the sticky notes's text (foreground) color in the graph editor.
227  void setTextColor( UN_StickyNoteID note_id, const UT_Color &text_color )
228  {
229  setData( myTextColor, note_id, text_color );
230  }
231 
232  /// Returns the sticky note's text (foreground) color in the graph editor.
233  const UT_Color & textColor( UN_StickyNoteID note_id ) const
234  {
235  return getDataRef( myTextColor, note_id, theDefTextColor );
236  }
237 
238  /// Sets the sticky note's text size.
239  void setTextSize( UN_StickyNoteID note_id, float text_size )
240  {
241  setData( myTextSize, note_id, text_size );
242  }
243 
244  /// Returns the sticky note's text size.
245  float textSize( UN_StickyNoteID note_id ) const
246  {
247  return getDataRef( myTextSize, note_id, theDefTextSize );
248  }
249 
250  /// Sets the sticky note's collapsed (minimized) state.
251  void setCollapsed( UN_StickyNoteID note_id, bool is_collapsed )
252  {
253  setData( myIsCollapsed, note_id, is_collapsed );
254  }
255 
256  /// Returns true if the sticky note is collapsed (minimized).
257  bool isCollapsed( UN_StickyNoteID note_id ) const
258  {
259  return getDataVal( myIsCollapsed, note_id, theDefCollapsed );
260  }
261 
262  /// Sets the flag on the sticky note to avoid drawing its background,
263  /// effectively making it transparent.
264  void setBackgroundHidden( UN_StickyNoteID note_id, bool is_hidden )
265  {
266  setData( myIsBackgroundHidden, note_id, is_hidden );
267  }
268 
269  /// Returns true if the background of the sticky note is not drawn,
270  /// effectively making it transparent.
271  bool isBackgroundHidden( UN_StickyNoteID note_id ) const
272  {
273  return getDataVal( myIsBackgroundHidden, note_id,
274  theDefBackgroundHidden);
275  }
276 
277 
278  /// Asserts that the sticky note names are alphanumeric.
280  {
281  myCheckValidNames = flag;
282  }
283 
284  /// A set of additional characters that are legal in sticky note names.
285  void setStickyNoteNameSafeChars( const UT_StringRef &safe_chars )
286  {
287  myNameSafeChars = safe_chars;
288  }
289 
290 protected:
291  /// Returns the sticky note's data index into the data buffer arrays.
292  UN_StickyNoteIndex stickyNoteIndex( UN_StickyNoteID id ) const
293  {
294  return UN_StickyNoteIndex(
295  UN_Data::dataIndex( id ));
296  }
297 
298 private:
299  /// Returns the current size of the internals data buffers.
300  /// The number of valid entries (slots) in data buffers is less than
301  /// or equal to that number, since some data slots may be free.
302  UN_DataSize coreDataBufferSize() const
303  {
304  UN_DataSize size( myName.size() );
305  UT_ASSERT( isCoreDataSizeConsistent( size ));
306  return size;
307  }
308 
309  /// Handles merging of another sticky note data container into this one.
310  void mergeCoreData( const UN_StickyNoteData &src,
311  const UN_DataMergeInfo &merge_info );
312 
313  /// Adds a new data slot to accommodate a new data piece at the given index.
314  void addCoreData( UN_StickyNoteIndex sticky_note_index );
315 
316  /// Clears the data for the given sticky note to the default state.
317  void clearCoreData( UN_StickyNoteIndex sticky_note_index );
318 
319  /// Frees the data slot occupied by the given sticky note,
320  /// clearing it if necessary.
321  void removeCoreData() //, index)
322  // Nothing urgent to free; will clear lazily
323  { UT_ASSERT( isDataSizeConsistent() ); }
324 
325  /// Frees all the data slots.
326  void removeAllCoreData();
327 
328  /// Sets the capacity of core data buffers if needed.
329  void setCoreDataCapacityIfNeeded( UN_DataSize min_capacity );
330 
331  /// @{ Returns true if the sizes of all core data buffers are equal.
332  bool isCoreDataSizeConsistent( UN_DataSize expected_size ) const;
333  bool isCoreDataSizeConsistent() const
334  { return isCoreDataSizeConsistent( myName.size() ); }
335  /// @}
336 
337  /// Returns true if the sizes of data buffers and index map are equal.
338  bool isDataSizeConsistent() const;
339 
340 public:
341  // The default values for the UN sticky note data.
342  static inline const UT_StringHolder theDefText;
343  static inline const auto theDefPos = UT_Vector2D(0.0);
344  static inline const auto theDefDim = UT_Vector2D(2.5);
345  static inline const auto theDefColor =
346  UT_Color(UT_RGB, 1.000F, 0.969F, 0.522F);
347  static inline const auto theDefTextColor = UT_BLACK;
348  static inline const auto theDefTextSize = 0.0F;
349  static inline const auto theDefCollapsed = false;
350  static inline const auto theDefBackgroundHidden = false;
351 
352 private:
353  /// The name of the sticky note, to identify it in a subnet.
354  UN_StringDataBuffer myName;
355 
356  /// The contents of the sticky note.
357  UN_StringDataBuffer myText;
358 
359  /// The location of the sticky note in the graph.
360  UN_Vector2DDataBuffer myPosition;
361 
362  /// The width and height of the sticky note in the graph.
363  UN_Vector2DDataBuffer myDimensions;
364 
365  /// Sticky note's (backgroun) color.
366  UN_ColorDataBuffer myColor;
367 
368  /// Sticky note's text color.
369  UN_ColorDataBuffer myTextColor;
370 
371  /// Sticky note's text size.
372  UN_FloatDataBuffer myTextSize;
373 
374  /// Collapsed (minimized) flag.
375  UN_BoolDataBuffer myIsCollapsed;
376 
377  /// Indicates that the background is not rendered.
378  UN_BoolDataBuffer myIsBackgroundHidden;
379 
380 
381  /// Extra characters that are legal in the sticky note names,
382  /// in addition to the standard C-var style alphanumerics.
383  UT_StringHolder myNameSafeChars;
384 
385  /// Check an assertion that the sticky note names are alphanumeric.
386  bool myCheckValidNames = false;
387 };
388 
389 
390 #endif
UN_StickyNoteIndex stickyNoteIndex(UN_StickyNoteID id) const
Returns the sticky note's data index into the data buffer arrays.
IDRange idRange() const
Definition: UN_Data.h:55
void setColor(UN_StickyNoteID note_id, const UT_Color &color)
Sets the sticky notes's background color in the graph editor.
#define UT_BLACK
Definition: UT_Color.h:128
Iterator for traversing valid sticky note IDs in an ascending order.
#define SYS_STATIC_ASSERT(expr)
OrderedIDIterator(const UN_DataIndexMap::OrderedIDIterator &id_iterator)
void setCheckValidStickyNoteNames(bool flag)
Asserts that the sticky note names are alphanumeric.
UN_CustomStickyNoteData * customStickyNoteData()
UT_Vector2T< fpreal64 > UT_Vector2D
IDRange idRange() const
static const UT_StringHolder theDefText
bool isValid(UN_DataID data_id) const
Definition: UN_Data.h:140
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:242
Iterator for traversing valid data IDs in the map.
const UT_Color & textColor(UN_StickyNoteID note_id) const
Returns the sticky note's text (foreground) color in the graph editor.
Iterator for traversing valid sticky note IDs.
#define UN_API
Definition: UN_API.h:11
UN_StickyNoteIDList sortedStickyNoteIDs() const
Returns a list of all the valid sticky note IDs in the graph.
UN_Data & operator=(UN_Data &&)
const UT_Vector2D & position(UN_StickyNoteID note_id) const
Returns the sticky note's position in the graph editor.
const UT_StringHolder & name(UN_StickyNoteID note_id) const
Returns the name that identifies the sticky notes among its siblings.
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
UN_DataIndex dataIndex(UN_DataID id) const
Definition: UN_Data.h:147
const UT_Vector2D & dimensions(UN_StickyNoteID note_id) const
Returns the sticky note's dimensions (width & height).
void setBackgroundHidden(UN_StickyNoteID note_id, bool is_hidden)
void setText(UN_StickyNoteID note_id, const UT_StringRef &text)
Sets the sticky note's contents text.
UN_CustomData * customData()
Returns the custom data container, if one was provided.
Definition: UN_Data.h:47
const UN_CustomStickyNoteData * customStickyNoteData() const
static const UT_StringHolder theEmptyString
ROI OIIO_API text_size(string_view text, int fontsize=16, string_view fontname="")
void setPosition(UN_StickyNoteID note_id, const UT_Vector2D &position)
Sets the sticky note's location in the graph editor.
UN_DataIDList dataIDs() const
Returns a list of all the valid IDs in this container.
Definition: UN_Data.h:64
IDIterator(const UN_DataIndexMap::IDIterator &id_iterator)
Data buffer specialization for boolean (bit) values.
GLuint const GLchar * name
Definition: glcorearb.h:786
V getDataVal(const B &buffer, UN_DataID id, const V &default_value) const
Definition: UN_Data.h:204
const UT_StringHolder & text(UN_StickyNoteID note_id) const
Returns the sticky note's contents.
UN_DataIndexMap::IDRange IDRange
Returns a range for iterating valid IDs.
Definition: UN_Data.h:54
bool isValid(UN_StickyNoteID sticky_note_id) const
OrderedIDRange orderedIDRange() const
Maintains a mapping from data ID to data index in the data buffer.
void setStickyNoteNameSafeChars(const UT_StringRef &safe_chars)
A set of additional characters that are legal in sticky note names.
UN_StickyNoteIDList stickyNoteIDs() const
Returns a list of all the valid sticky note IDs in the graph.
GLsizeiptr size
Definition: glcorearb.h:664
void setDimensions(UN_StickyNoteID note_id, const UT_Vector2D &dimensions)
Sets the sticky note's width and height.
Iterator for traversing valid data IDs in the map in an ordered fashion.
void setTextColor(UN_StickyNoteID note_id, const UT_Color &text_color)
Sets the sticky notes's text (foreground) color in the graph editor.
GLuint color
Definition: glcorearb.h:1261
SIM_API const UT_StringHolder position
void setData(B &buffer, UN_DataID id, const V &value)
Helper method to copy-assign the value to an entry in the data buffer.
Definition: UN_Data.h:173
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:165
const UT_Color & color(UN_StickyNoteID note_id) const
Returns the sticky note's background color in the graph editor.
OutGridT XformOp bool bool MergePolicy merge
UN_DataSize size() const
Returns the number of valid data items in the buffer.
Definition: UN_Data.h:72
void setCollapsed(UN_StickyNoteID note_id, bool is_collapsed)
Sets the sticky note's collapsed (minimized) state.
UN_DataIDList sortedDataIDs() const
Returns a sorted list of all the valid IDs in this container.
Definition: UN_Data.h:68
UN_DataIndexMap::OrderedIDRange OrderedIDRange
Returns a range for iterating valid IDs in an ascending order.
Definition: UN_Data.h:59
bool isBackgroundHidden(UN_StickyNoteID note_id) const
Definition: UNI_ID.h:25
const V & getDataRef(const B &buffer, UN_DataID id, const V &default_value) const
Helper method to return a const ref to an entry in the data buffer.
Definition: UN_Data.h:190
void setName(UN_StickyNoteID note_id, const UT_StringRef &name)
Sets the sticky note name that differentiates it among its siblings.
UT_UniquePtr< UN_CustomStickyNoteData > UN_CustomStickyNoteDataPtr
bool isCollapsed(UN_StickyNoteID note_id) const
Returns true if the sticky note is collapsed (minimized).
float textSize(UN_StickyNoteID note_id) const
Returns the sticky note's text size.
OrderedIDRange orderedIDRange() const
Definition: UN_Data.h:60
GLenum src
Definition: glcorearb.h:1793
void setTextSize(UN_StickyNoteID note_id, float text_size)
Sets the sticky note's text size.