opennurbs_compstat.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2014 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 
18 //////////////////////////////////////////////////////////////////////////
19 //
20 // ON_ComponentState and ON_ComponentStatus
21 //
22 
23 #pragma region RH_C_SHARED_ENUM [ON_ComponentState] [Rhino.Geometry.ComponentState] [internal:byte]
24 
25 ///<summary><para>Provides a set of values describing component state.</para>
26 ///<para>This is not a bit field.</para>
27 ///<para>Some of these values are mutually exclusive and should not be combined.</para></summary>
28 enum class ON_ComponentState : unsigned char
29 {
30  ///<summary>Not a valid status.</summary>
31  Unset = 0,
32 
33  ///<summary>This is a default component state.</summary>
34  Clear = 1,
35 
36  ///<summary>This is a default component state, but not selected.</summary>
37  NotSelected = 2,
38 
39  ///<summary>This component is selected.</summary>
40  Selected = 3,
41 
42  ///<summary>This component is selected persistently.</summary>
43  SelectedPersistent = 4,
44 
45  ///<summary>This is a default component state, but not highlighted.</summary>
46  NotHighlighted = 5,
47 
48  ///<summary>This component is highlighted.</summary>
49  Highlighted = 6,
50 
51  ///<summary>This is a default component state, but not hidden.</summary>
52  NotHidden = 7,
53 
54  ///<summary>This component is hidden.</summary>
55  Hidden = 8,
56 
57  ///<summary>This is a default component state, but not locked.</summary>
58  NotLocked = 9,
59 
60  ///<summary>This component is locked.</summary>
61  Locked = 10,
62 
63  ///<summary>This is a default component state, but not damaged.</summary>
64  NotDamaged = 11,
65 
66  ///<summary>This component is damaged.</summary>
67  Damaged = 12,
68 
69  ///<summary>This component is not deleted.</summary>
70  NotDeleted = 13,
71 
72  ///<summary>This component is deleted.</summary>
73  Deleted = 14,
74 
75  ///<summary>This runtime mark is clear.</summary>
76  RuntimeMarkClear = 15,
77 
78  ///<summary>This runtime mark is set.</summary>
79  RuntimeMarkSet = 16
80 };
81 #pragma endregion
82 
83 ON_DECL
84 ON_ComponentState ON_ComponentStateFromUnsigned(
85  unsigned int state_as_unsigned
86  );
87 
88 class ON_CLASS ON_ComponentStatus
89 {
90 public:
91 
96  static const ON_ComponentStatus Hidden;
97  static const ON_ComponentStatus Locked;
101 
102  ON_ComponentStatus() = default;
103  ~ON_ComponentStatus() = default;
104  ON_ComponentStatus(const ON_ComponentStatus&) = default;
105  ON_ComponentStatus& operator=(const ON_ComponentStatus&) = default;
106 
107  /*
108  Description:
109  Constructs a status with the specified state set.
110  */
112  ON_ComponentState state
113  );
114 
115  bool operator==(ON_ComponentStatus);
116  bool operator!=(ON_ComponentStatus);
117 
118  /*
119  Returns:
120  True if every setting besides runtime mark is 0 or false.
121  Ignores the runtime mark state.
122  Remarks:
123  The runtime mark setting is ignored by IsClear().
124  */
125  bool IsClear() const;
126 
127  /*
128  Description:
129  Sets *this = status_to_copy and returns 1 if a state setting changed.
130  Returns:
131  1 if status changed.
132  0 if status did not change.
133  Remarks:
134  The runtime mark setting cannot be changed using SetStatus().
135  */
136  unsigned int SetStatus(
137  ON_ComponentStatus status_to_copy
138  );
139 
140  /*
141  Description:
142  If a state is set in states_to_set, the same state is set in "this".
143  Parameters:
144  states_to_set - [in]
145  Returns:
146  1 if status changed.
147  0 if status did not change.
148  Remarks:
149  The runtime mark setting cannot be changed using SetStates().
150  */
151  unsigned int SetStates(
152  ON_ComponentStatus states_to_set
153  );
154 
155  /*
156  Description:
157  If a state is set in states_to_clear, the same state is cleared in "this".
158  Parameters:
159  states_to_clear - [in]
160  Returns:
161  1 if status changed.
162  0 if status did not change.
163  Remarks:
164  The runtime mark setting cannot be changed using ClearStates().
165  */
166  unsigned int ClearStates(
167  ON_ComponentStatus states_to_clear
168  );
169 
170  //////////////////////////////////////////////////////////////////////////
171  //
172  // RuntimeMark
173  //
174  bool RuntimeMark() const;
175  unsigned int SetRuntimeMark(
176  bool bRuntimeMark
177  );
178  unsigned int SetRuntimeMark();
179  unsigned int ClearRuntimeMark();
180 
181  //////////////////////////////////////////////////////////////////////////
182  //
183  // Selection
184  //
185 
186  /*
187  Returns:
188  ON_ComponentState::not_selected,
189  ON_ComponentState::Selected or
190  ON_ComponentState::Selected_pesistent.
191  */
192  ON_ComponentState SelectedState() const;
193 
194  /*
195  Returns:
196  1 if status changed.
197  0 if status did not change.
198  */
199  unsigned int SetSelectedState(
200  bool bSelectedState,
201  bool bPersistent,
202  bool bSynchronizeHighlight
203  );
204 
205  unsigned int SetSelectedState(
206  ON_ComponentState selected_state,
207  bool bSynchronizeHighlight
208  );
209 
210  /*
211  Returns:
212  false
213  The selection state is ON_ComponentState::not_selected.
214  true
215  The selection state is ON_ComponentState::Selected
216  or ON_ComponentState::Selected_pesistent.
217  */
218  bool IsSelected() const;
219 
220  /*
221  Returns:
222  false
223  The selection state is ON_ComponentState::not_selected.
224  true
225  The selection state is ON_ComponentState::Selected_pesistent.
226  */
227  bool IsSelectedPersistent() const;
228 
229  //////////////////////////////////////////////////////////////////////////
230  //
231  // Highlighted
232  //
233  /*
234  Returns:
235  1 if status changed.
236  0 if status did not change.
237  */
238  unsigned int SetHighlightedState(
239  bool bIsHighlighed
240  );
241 
242  /*
243  Returns:
244  false if not highlighted.
245  true otherwise.
246  */
247  bool IsHighlighted() const;
248 
249 
250  //////////////////////////////////////////////////////////////////////////
251  //
252  // Hidden
253  //
254 
255  /*
256  Returns:
257  1 if status changed.
258  0 if status did not change.
259  */
260  unsigned int SetHiddenState(
261  bool bIsHidden
262  );
263 
264  /*
265  Returns:
266  false if not hidden.
267  true otherwise.
268  (ON_ComponentStatus::HIDDEN_STATE::not_hidden != HiddenState())
269  */
270  bool IsHidden() const;
271 
272  //////////////////////////////////////////////////////////////////////////
273  //
274  // Locked
275  //
276  /*
277  Returns:
278  1 if status changed.
279  0 if status did not change.
280  */
281  unsigned int SetLockedState(
282  bool bIsLocked
283  );
284 
285  /*
286  Returns:
287  false if not locked.
288  true otherwise.
289  (ON_ComponentStatus::LOCKED_STATE::not_locked != LockedState())
290  */
291  bool IsLocked() const;
292 
293  //////////////////////////////////////////////////////////////////////////
294  //
295  // Deleted
296  //
297 
298  /*
299  Returns:
300  1 if status changed.
301  0 if status did not change.
302  */
303  unsigned int SetDeletedState(
304  bool bIsDeleted
305  );
306 
307  /*
308  Returns:
309  false if not hidden.
310  true otherwise.
311  (ON_ComponentStatus::DELETED_STATE::not_deleted != DeletedState())
312  */
313  bool IsDeleted() const;
314 
315 
316  //////////////////////////////////////////////////////////////////////////
317  //
318  // Damaged
319  //
320 
321  /*
322  Returns:
323  1 if status changed.
324  0 if status did not change.
325  */
326  unsigned int SetDamagedState(
327  bool bIsDamaged
328  );
329 
330  /*
331  Returns:
332  false if not damaged.
333  true otherwise.
334  (ON_ComponentStatus::DAMAGED_STATE::not_damaged != DamagedState())
335  */
336  bool IsDamaged() const;
337 
338 
339  //////////////////////////////////////////////////////////////////////////
340  //
341  // Checking multiple state values efficently
342  //
343 
344  bool operator==(const ON_ComponentStatus&) const;
345  bool operator!=(const ON_ComponentStatus&) const;
346 
347  /*
348  Parameters:
349  states_filter - [in]
350  If no states are specified, then false is returned.
351  comparand - [in]
352  If a state is set in states_filter, the corresponding state
353  in "this" and comparand will be tested.
354  Returns:
355  True if every tested state in "this" and comparand are identical.
356  Remarks:
357  For the purposes of this test, ON_ComponentState::Selected
358  and ON_ComponentState::SelectedPersistent are considered equal.
359  */
360  bool AllEqualStates(
361  ON_ComponentStatus states_filter,
362  ON_ComponentStatus comparand
363  ) const;
364 
365  /*
366  Parameters:
367  states_filter - [in]
368  If no states are specified, then false is returned.
369  comparand - [in]
370  If a state is set in states_filter, the corresponding state
371  in "this" and comparand will be tested.
372  Returns:
373  True if at least one tested state in "this" and comparand are identical.
374  Remarks:
375  For the purposes of this test, ON_ComponentState::Selected
376  and ON_ComponentState::SelectedPersistent are considered equal.
377  */
378  bool SomeEqualStates(
379  ON_ComponentStatus states_filter,
380  ON_ComponentStatus comparand
381  ) const;
382 
383  /*
384  Parameters:
385  states_filter - [in]
386  If no states are specified, then false is returned.
387  comparand - [in]
388  If a state is set in states_filter, the corresponding state
389  in "this" and comparand will be tested.
390  Returns:
391  True if every tested state in "this" and comparand are different.
392  Remarks:
393  For the purposes of this test, ON_ComponentState::Selected
394  and ON_ComponentState::SelectedPersistent are considered equal.
395  */
396  bool NoEqualStates(
397  ON_ComponentStatus states_filter,
398  ON_ComponentStatus comparand
399  ) const;
401 private:
402  friend class ON_AggregateComponentStatus;
403  unsigned char m_status_flags = 0U;
404 };
405 
406 
407 
408 //////////////////////////////////////////////////////////////////////////
409 //
410 // ON_AggregateComponentStatus
411 //
412 //
413 class ON_CLASS ON_AggregateComponentStatus
414 {
415 public:
416  static const ON_AggregateComponentStatus Empty;
417  static const ON_AggregateComponentStatus NotCurrent;
418 
419  ON_AggregateComponentStatus() = default;
420  ~ON_AggregateComponentStatus() = default;
422  ON_AggregateComponentStatus& operator=(const ON_AggregateComponentStatus&) = default;
423 
424  /*
425  Description:
426  Sets all states to clear.
427  Marks status as current.
428  Does not change compoent count
429  Returns
430  true if successful.
431  false if information is not current and ClearAllStates() failed.
432  */
433  bool ClearAllStates();
434 
435  /*
436  Description:
437  Sets all states specified by states_to_clear to clear.
438  Does not change current mark.
439  Does not change compoent count.
440  Returns
441  true if successful.
442  false if information is not current and ClearAggregateStatus() failed.
443  */
444  bool ClearAggregateStatus(
445  ON_ComponentStatus states_to_clear
446  );
447 
448  /*
449  Description:
450  Add the status information in component_status to this aggregate status.
451  Parameters:
452  component_status - [in]
453  Returns:
454  true if successful.
455  false if information is not current and Add failed.
456  */
457  bool Add(
458  ON_ComponentStatus component_status
459  );
460 
461  /*
462  Description:
463  Add the status information in aggregate_status to this aggregate status.
464  Parameters:
465  aggregate_status - [in]
466  Returns:
467  true if successful.
468  false if information is not current and Add failed.
469  */
470  bool Add(
471  const ON_AggregateComponentStatus& aggregate_status
472  );
473 
474  /*
475  Returns:
476  true if this is empty
477  false if not empty.
478  */
479  bool IsEmpty() const;
480 
481  /*
482  Returns:
483  true if the information is current (valid, up to date, ...).
484  false if the information is not current.
485  Remarks:
486  If the information is not current, all counts are zero and states are clear.
487  */
488  bool IsCurrent() const;
489 
490  /*
491  Description:
492  Mark the information as not current.
493  Erases all information.
494  */
495  void MarkAsNotCurrent();
496 
497  ON_ComponentStatus AggregateStatus() const;
498 
499  unsigned int ComponentCount() const;
500 
501  /*
502  Returns:
503  Number of compoents that are selected or persistently selected.
504  */
505  unsigned int SelectedCount() const;
506 
507  /*
508  Returns:
509  Number of compoents that are persistently selected.
510  */
511  unsigned int SelectedPersistentCount() const;
512 
513  unsigned int HighlightedCount() const;
514 
515  unsigned int HiddenCount() const;
516 
517  unsigned int LockedCount() const;
518 
519  unsigned int DamagedCount() const;
520 
521 private:
522  // a bitwise or of all component status settings
523  ON_ComponentStatus m_aggregate_status = ON_ComponentStatus::NoneSet;
524 
525 private:
526  unsigned char m_current = 0; // 0 = empty, 1 = current, 2 = dirty
527  unsigned short m_reserved2 = 0;
528 
529 private:
530  // number of components
531  unsigned int m_component_count = 0;
532 
533  // number of selected components (includes persistent and non persistent)
534  unsigned int m_selected_count = 0;
535 
536  // number of selected components
537  unsigned int m_selected_persistent_count = 0;
538 
539  // number of highlighted components
540  unsigned int m_highlighted_count = 0;
541 
542  // number of hidden components
543  unsigned int m_hidden_count = 0;
544 
545  // number of locked components
546  unsigned int m_locked_count = 0;
547 
548  // number of damaged components
549  unsigned int m_damaged_count = 0;
550 };
551 
static const ON_ComponentStatus Locked
Definition: opennurbs_compstat.h:97
static const ON_ComponentStatus Deleted
Definition: opennurbs_compstat.h:98
static const ON_ComponentStatus Damaged
Definition: opennurbs_compstat.h:99
Definition: opennurbs_compstat.h:396
Definition: opennurbs_compstat.h:88
static const ON_ComponentStatus Highlighted
Definition: opennurbs_compstat.h:95
static const ON_ComponentStatus NoneSet
Definition: opennurbs_compstat.h:92
static const ON_ComponentStatus Hidden
Definition: opennurbs_compstat.h:96
static const ON_ComponentStatus Selected
Definition: opennurbs_compstat.h:93
static const ON_ComponentStatus AllSet
Definition: opennurbs_compstat.h:100
static const ON_ComponentStatus SelectedPersistent
Definition: opennurbs_compstat.h:94