Files
opennurbs/opennurbs_compstat.h
2018-09-10 17:39:40 -07:00

552 lines
14 KiB
C++

/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2014 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
//////////////////////////////////////////////////////////////////////////
//
// ON_ComponentState and ON_ComponentStatus
//
#pragma region RH_C_SHARED_ENUM [ON_ComponentState] [Rhino.Geometry.ComponentState] [internal:byte]
///<summary><para>Provides a set of values describing component state.</para>
///<para>This is not a bit field.</para>
///<para>Some of these values are mutually exclusive and should not be combined.</para></summary>
enum class ON_ComponentState : unsigned char
{
///<summary>Not a valid status.</summary>
Unset = 0,
///<summary>This is a default component state.</summary>
Clear = 1,
///<summary>This is a default component state, but not selected.</summary>
NotSelected = 2,
///<summary>This component is selected.</summary>
Selected = 3,
///<summary>This component is selected persistently.</summary>
SelectedPersistent = 4,
///<summary>This is a default component state, but not highlighted.</summary>
NotHighlighted = 5,
///<summary>This component is highlighted.</summary>
Highlighted = 6,
///<summary>This is a default component state, but not hidden.</summary>
NotHidden = 7,
///<summary>This component is hidden.</summary>
Hidden = 8,
///<summary>This is a default component state, but not locked.</summary>
NotLocked = 9,
///<summary>This component is locked.</summary>
Locked = 10,
///<summary>This is a default component state, but not damaged.</summary>
NotDamaged = 11,
///<summary>This component is damaged.</summary>
Damaged = 12,
///<summary>This component is not deleted.</summary>
NotDeleted = 13,
///<summary>This component is deleted.</summary>
Deleted = 14,
///<summary>This runtime mark is clear.</summary>
RuntimeMarkClear = 15,
///<summary>This runtime mark is set.</summary>
RuntimeMarkSet = 16
};
#pragma endregion
ON_DECL
ON_ComponentState ON_ComponentStateFromUnsigned(
unsigned int state_as_unsigned
);
class ON_CLASS ON_ComponentStatus
{
public:
static const ON_ComponentStatus NoneSet;
static const ON_ComponentStatus Selected;
static const ON_ComponentStatus SelectedPersistent;
static const ON_ComponentStatus Highlighted;
static const ON_ComponentStatus Hidden;
static const ON_ComponentStatus Locked;
static const ON_ComponentStatus Deleted;
static const ON_ComponentStatus Damaged;
static const ON_ComponentStatus AllSet;
ON_ComponentStatus() = default;
~ON_ComponentStatus() = default;
ON_ComponentStatus(const ON_ComponentStatus&) = default;
ON_ComponentStatus& operator=(const ON_ComponentStatus&) = default;
/*
Description:
Constructs a status with the specified state set.
*/
ON_ComponentStatus(
ON_ComponentState state
);
bool operator==(ON_ComponentStatus);
bool operator!=(ON_ComponentStatus);
/*
Returns:
True if every setting besides runtime mark is 0 or false.
Ignores the runtime mark state.
Remarks:
The runtime mark setting is ignored by IsClear().
*/
bool IsClear() const;
/*
Description:
Sets *this = status_to_copy and returns 1 if a state setting changed.
Returns:
1 if status changed.
0 if status did not change.
Remarks:
The runtime mark setting cannot be changed using SetStatus().
*/
unsigned int SetStatus(
ON_ComponentStatus status_to_copy
);
/*
Description:
If a state is set in states_to_set, the same state is set in "this".
Parameters:
states_to_set - [in]
Returns:
1 if status changed.
0 if status did not change.
Remarks:
The runtime mark setting cannot be changed using SetStates().
*/
unsigned int SetStates(
ON_ComponentStatus states_to_set
);
/*
Description:
If a state is set in states_to_clear, the same state is cleared in "this".
Parameters:
states_to_clear - [in]
Returns:
1 if status changed.
0 if status did not change.
Remarks:
The runtime mark setting cannot be changed using ClearStates().
*/
unsigned int ClearStates(
ON_ComponentStatus states_to_clear
);
//////////////////////////////////////////////////////////////////////////
//
// RuntimeMark
//
bool RuntimeMark() const;
unsigned int SetRuntimeMark(
bool bRuntimeMark
);
unsigned int SetRuntimeMark();
unsigned int ClearRuntimeMark();
//////////////////////////////////////////////////////////////////////////
//
// Selection
//
/*
Returns:
ON_ComponentState::not_selected,
ON_ComponentState::Selected or
ON_ComponentState::Selected_pesistent.
*/
ON_ComponentState SelectedState() const;
/*
Returns:
1 if status changed.
0 if status did not change.
*/
unsigned int SetSelectedState(
bool bSelectedState,
bool bPersistent,
bool bSynchronizeHighlight
);
unsigned int SetSelectedState(
ON_ComponentState selected_state,
bool bSynchronizeHighlight
);
/*
Returns:
false
The selection state is ON_ComponentState::not_selected.
true
The selection state is ON_ComponentState::Selected
or ON_ComponentState::Selected_pesistent.
*/
bool IsSelected() const;
/*
Returns:
false
The selection state is ON_ComponentState::not_selected.
true
The selection state is ON_ComponentState::Selected_pesistent.
*/
bool IsSelectedPersistent() const;
//////////////////////////////////////////////////////////////////////////
//
// Highlighted
//
/*
Returns:
1 if status changed.
0 if status did not change.
*/
unsigned int SetHighlightedState(
bool bIsHighlighed
);
/*
Returns:
false if not highlighted.
true otherwise.
*/
bool IsHighlighted() const;
//////////////////////////////////////////////////////////////////////////
//
// Hidden
//
/*
Returns:
1 if status changed.
0 if status did not change.
*/
unsigned int SetHiddenState(
bool bIsHidden
);
/*
Returns:
false if not hidden.
true otherwise.
(ON_ComponentStatus::HIDDEN_STATE::not_hidden != HiddenState())
*/
bool IsHidden() const;
//////////////////////////////////////////////////////////////////////////
//
// Locked
//
/*
Returns:
1 if status changed.
0 if status did not change.
*/
unsigned int SetLockedState(
bool bIsLocked
);
/*
Returns:
false if not locked.
true otherwise.
(ON_ComponentStatus::LOCKED_STATE::not_locked != LockedState())
*/
bool IsLocked() const;
//////////////////////////////////////////////////////////////////////////
//
// Deleted
//
/*
Returns:
1 if status changed.
0 if status did not change.
*/
unsigned int SetDeletedState(
bool bIsDeleted
);
/*
Returns:
false if not hidden.
true otherwise.
(ON_ComponentStatus::DELETED_STATE::not_deleted != DeletedState())
*/
bool IsDeleted() const;
//////////////////////////////////////////////////////////////////////////
//
// Damaged
//
/*
Returns:
1 if status changed.
0 if status did not change.
*/
unsigned int SetDamagedState(
bool bIsDamaged
);
/*
Returns:
false if not damaged.
true otherwise.
(ON_ComponentStatus::DAMAGED_STATE::not_damaged != DamagedState())
*/
bool IsDamaged() const;
//////////////////////////////////////////////////////////////////////////
//
// Checking multiple state values efficently
//
bool operator==(const ON_ComponentStatus&) const;
bool operator!=(const ON_ComponentStatus&) const;
/*
Parameters:
states_filter - [in]
If no states are specified, then false is returned.
comparand - [in]
If a state is set in states_filter, the corresponding state
in "this" and comparand will be tested.
Returns:
True if every tested state in "this" and comparand are identical.
Remarks:
For the purposes of this test, ON_ComponentState::Selected
and ON_ComponentState::SelectedPersistent are considered equal.
*/
bool AllEqualStates(
ON_ComponentStatus states_filter,
ON_ComponentStatus comparand
) const;
/*
Parameters:
states_filter - [in]
If no states are specified, then false is returned.
comparand - [in]
If a state is set in states_filter, the corresponding state
in "this" and comparand will be tested.
Returns:
True if at least one tested state in "this" and comparand are identical.
Remarks:
For the purposes of this test, ON_ComponentState::Selected
and ON_ComponentState::SelectedPersistent are considered equal.
*/
bool SomeEqualStates(
ON_ComponentStatus states_filter,
ON_ComponentStatus comparand
) const;
/*
Parameters:
states_filter - [in]
If no states are specified, then false is returned.
comparand - [in]
If a state is set in states_filter, the corresponding state
in "this" and comparand will be tested.
Returns:
True if every tested state in "this" and comparand are different.
Remarks:
For the purposes of this test, ON_ComponentState::Selected
and ON_ComponentState::SelectedPersistent are considered equal.
*/
bool NoEqualStates(
ON_ComponentStatus states_filter,
ON_ComponentStatus comparand
) const;
private:
friend class ON_AggregateComponentStatus;
unsigned char m_status_flags = 0U;
};
//////////////////////////////////////////////////////////////////////////
//
// ON_AggregateComponentStatus
//
//
class ON_CLASS ON_AggregateComponentStatus
{
public:
static const ON_AggregateComponentStatus Empty;
static const ON_AggregateComponentStatus NotCurrent;
ON_AggregateComponentStatus() = default;
~ON_AggregateComponentStatus() = default;
ON_AggregateComponentStatus(const ON_AggregateComponentStatus&) = default;
ON_AggregateComponentStatus& operator=(const ON_AggregateComponentStatus&) = default;
/*
Description:
Sets all states to clear.
Marks status as current.
Does not change compoent count
Returns
true if successful.
false if information is not current and ClearAllStates() failed.
*/
bool ClearAllStates();
/*
Description:
Sets all states specified by states_to_clear to clear.
Does not change current mark.
Does not change compoent count.
Returns
true if successful.
false if information is not current and ClearAggregateStatus() failed.
*/
bool ClearAggregateStatus(
ON_ComponentStatus states_to_clear
);
/*
Description:
Add the status information in component_status to this aggregate status.
Parameters:
component_status - [in]
Returns:
true if successful.
false if information is not current and Add failed.
*/
bool Add(
ON_ComponentStatus component_status
);
/*
Description:
Add the status information in aggregate_status to this aggregate status.
Parameters:
aggregate_status - [in]
Returns:
true if successful.
false if information is not current and Add failed.
*/
bool Add(
const ON_AggregateComponentStatus& aggregate_status
);
/*
Returns:
true if this is empty
false if not empty.
*/
bool IsEmpty() const;
/*
Returns:
true if the information is current (valid, up to date, ...).
false if the information is not current.
Remarks:
If the information is not current, all counts are zero and states are clear.
*/
bool IsCurrent() const;
/*
Description:
Mark the information as not current.
Erases all information.
*/
void MarkAsNotCurrent();
ON_ComponentStatus AggregateStatus() const;
unsigned int ComponentCount() const;
/*
Returns:
Number of compoents that are selected or persistently selected.
*/
unsigned int SelectedCount() const;
/*
Returns:
Number of compoents that are persistently selected.
*/
unsigned int SelectedPersistentCount() const;
unsigned int HighlightedCount() const;
unsigned int HiddenCount() const;
unsigned int LockedCount() const;
unsigned int DamagedCount() const;
private:
// a bitwise or of all component status settings
ON_ComponentStatus m_aggregate_status = ON_ComponentStatus::NoneSet;
private:
unsigned char m_current = 0; // 0 = empty, 1 = current, 2 = dirty
unsigned short m_reserved2 = 0;
private:
// number of components
unsigned int m_component_count = 0;
// number of selected components (includes persistent and non persistent)
unsigned int m_selected_count = 0;
// number of selected components
unsigned int m_selected_persistent_count = 0;
// number of highlighted components
unsigned int m_highlighted_count = 0;
// number of hidden components
unsigned int m_hidden_count = 0;
// number of locked components
unsigned int m_locked_count = 0;
// number of damaged components
unsigned int m_damaged_count = 0;
};