BaseSelect Class Reference

#include <c4d_baseselect.h>

Inheritance diagram for BaseSelect:

Detailed Description

This class is used to keep track of point and polygon selections, it may also be used to track other types of element selections.

Note
Has to be created with Alloc() and destroyed with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Private Member Functions

 BaseSelect ()
 
 ~BaseSelect ()
 

Alloc/Free

static BaseSelectAlloc (void)
 
static void Free (BaseSelect *&bs)
 

Selection/Segment Count

Int32 GetCount (void) const
 
Int32 GetSegments (void) const
 

Select/Deselect/Toggle

Bool Select (Int32 num)
 
Bool SelectAll (Int32 min, Int32 max, Bool deselectAll=true)
 
Bool Deselect (Int32 num)
 
Bool DeselectAll (void)
 
Bool Toggle (Int32 num)
 
Bool ToggleAll (Int32 min, Int32 max)
 

Get/Check Selection

Bool GetRange (Int32 seg, Int32 maxElements, Int32 *a, Int32 *b) const
 
Bool IsSelected (Int32 num) const
 

Copy/Clone

Bool CopyTo (BaseSelect *dest) const
 
BaseSelectGetClone (void) const
 

Merge/Deselect/cross

Bool Merge (const BaseSelect *src)
 
Bool Deselect (const BaseSelect *src)
 
Bool Cross (const BaseSelect *src)
 

Conversion from/to Array

Bool FromArray (UChar *selection, Int32 count)
 
UCharToArray (Int32 count) const
 
Bool ToBitSet (Int32 count, maxon::BaseBitSet< maxon::DefaultAllocator > &bitSet) const
 

Read/Write

Bool Read (HyperFile *hf)
 
void Write (HyperFile *hf)
 

Miscellaneous

Bool FindSegment (Int32 num, Int32 *segment) const
 
Int32 GetDirty () const
 
Int32 GetLastElement (void) const
 
Bool IsAllSelected (Int32 num) const
 
Bool IsNothingSelected () const
 

Private

BaseSelectDataGetData ()
 
Bool CopyFrom (BaseSelectData *ndata, Int32 ncnt)
 

Constructor & Destructor Documentation

◆ BaseSelect()

BaseSelect ( )
private

◆ ~BaseSelect()

~BaseSelect ( )
private

Member Function Documentation

◆ Alloc()

static BaseSelect* Alloc ( void  )
static

Allocates a base selection. Destroy the allocated base selection with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Returns
The allocated base selection, or nullptr if the allocation failed.

◆ Free()

static void Free ( BaseSelect *&  bs)
static

Destructs base selections allocated with Alloc(). Use AutoAlloc to automate the allocation and destruction based on scope.

Parameters
[in,out]bsThe base selection to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆ GetCount()

Int32 GetCount ( void  ) const

Gets the number of selected elements.

Returns
The number of selected elements.

◆ GetSegments()

Int32 GetSegments ( void  ) const

Gets the number of segments that contain elements.

Note
For example: with the selections 0..4, 6..7, 9..12, GetSegments() would return 3 and GetCount() would return 11.
Returns
The number of segments with selected elements.

◆ Select()

Bool Select ( Int32  num)

Selects an element.

Parameters
[in]numThe element index to select.
Returns
true if the element was already selected, otherwise false.

◆ SelectAll()

Bool SelectAll ( Int32  min,
Int32  max,
Bool  deselectAll = true 
)

Selects all elements in the given range.

Parameters
[in]minThe first element to select.
[in]maxThe last element in the range to select.
[in]deselectAllSince R17. Deselects all previously selected elements before creating the new selection (equivalent to SELECTION_NEW).
Returns
Success of selecting the elements.

◆ Deselect() [1/2]

Bool Deselect ( Int32  num)

Deselects an element.

Parameters
[in]numThe element index to deselect.
Returns
true if the element was already deselected, otherwise false.

◆ DeselectAll()

Bool DeselectAll ( void  )

Deselects all elements.

Returns
Success of deselecting all elements.

◆ Toggle()

Bool Toggle ( Int32  num)

Toggles the selection state of an element.

Parameters
[in]numThe element index to toggle.
Returns
Success of changing the selection state of the element.

◆ ToggleAll()

Bool ToggleAll ( Int32  min,
Int32  max 
)

Toggles the selection state of all elements in the given range.

Parameters
[in]minThe first element to toggle.
[in]maxThe last element to toggle in the range.
Returns
Success of changing the selection state.

◆ GetRange()

Bool GetRange ( Int32  seg,
Int32  maxElements,
Int32 a,
Int32 b 
) const

Gets the selected elements contained in a segment.

Parameters
[in]segThe segment to get the elements for. 0 <= seg < GetSegments()
[in]maxElementsThe maximum value for a and b. Makes sure a and b are < maxElements. Pass LIMIT<Int32>::MAX for no additional checks.
[out]aAssigned the index of the first selected element.
[out]bAssigned the index of the last selected element.
Returns
true if if the range was successfully retrieved, otherwise false. Only false if seg is not 0 <= seg < GetSegments()
The spans are always sorted (spans with higher index have higher numbers for a/b), also b is always >= a.

◆ IsSelected()

Bool IsSelected ( Int32  num) const

Checks the selection state of an element.
To efficiently go through selections use the following code:

Int32 seg = 0, a, b, i;
while (bs->GetRange(seg++, LIMIT<Int32>::MAX, &a, &b))
{
for (i=a; i<=b; ++i)
{
// Do something. 'i' is the selected element
}
}

This is faster than:

for (i=0; i<maxelements; i++)
{
if (bs->IsSelected(i))
{
// Do something
}
}
Parameters
[in]numThe element index to get the state for.
Returns
true if the element num is selected, otherwise false.

◆ CopyTo()

Bool CopyTo ( BaseSelect dest) const

Copies the selection elements to another BaseSelect.

Parameters
[out]destThe destination selection. The caller owns the pointed selection.
Returns
true if selection elements were copied successfully, otherwise false.

◆ GetClone()

BaseSelect* GetClone ( void  ) const

Makes a duplicate of the selection with its elements.

Returns
The cloned BaseSelect or nullptr if failed. The caller owns the pointed BaseSelect.

◆ Merge()

Bool Merge ( const BaseSelect src)

Selects all elements that are in src.

Parameters
[in]srcThe source selection. The caller owns the pointed selection.
Returns
true if the selection elements were merged successfully, otherwise false.

◆ Deselect() [2/2]

Bool Deselect ( const BaseSelect src)

Deselects all elements that are in src.

Parameters
[in]srcThe source selection. The caller owns the pointed selection.
Returns
true if the selection elements were deselected successfully, otherwise false.

◆ Cross()

Bool Cross ( const BaseSelect src)

Intersects all elements in src.

Parameters
[in]srcThe source selection. The caller owns the pointed selection.
Returns
true if the selection elements were crossed successfully, otherwise false.

◆ FromArray()

Bool FromArray ( UChar selection,
Int32  count 
)

Gets a number of selected elements from an array. The elements in the array are interpreted as Bool: 0 means the element is unselected, and 1 means it is selected.

Warning
The old selection will completely be overridden.
Parameters
[in]selectionAn array of elements to select. The caller owns the pointed array.
[in]countThe number of elements in the array.
Returns
true if the elements from the array were selected successfully, otherwise false.

◆ ToArray()

UChar* ToArray ( Int32  count) const

Gets an array of selected elements. The elements in the array are interpreted as Bool: 0 means the element is unselected, and 1 means it is selected.

Warning
The array is created with NewMemClear() and must be freed with DeleteMem() afterward.
Parameters
[in]countThe number of elements to place into the array.
Returns
The array containing the selected elements or nullptr if failed. The caller owns the pointed array.

◆ ToBitSet()

Bool ToBitSet ( Int32  count,
maxon::BaseBitSet< maxon::DefaultAllocator > &  bitSet 
) const
Returns
true if the elements from the array were selected successfully, otherwise false.

◆ Read()

Bool Read ( HyperFile hf)

Reads a selection from a file.

Parameters
[in]hfThe file to read a selection from. The caller owns the pointed hyper file.
Returns
true if a selection was successfully read, otherwise false.

◆ Write()

void Write ( HyperFile hf)

Writes the selection to a file.

Parameters
[in]hfThe file to write the selection to. The caller owns the pointed hyper file.

◆ FindSegment()

Bool FindSegment ( Int32  num,
Int32 segment 
) const

Calculates which segment contains the element num and returns it in segment.

Parameters
[in]numAn element number.
[out]segmentAssigned the found segment index.
Returns
true if the segment was found, otherwise false.

◆ GetDirty()

Int32 GetDirty ( ) const

Gets the dirty counter of the selection.

Note
The dirty counter is increased every time a function that changes the selection is called.
Returns
The dirty counter.

◆ GetLastElement()

Int32 GetLastElement ( void  ) const

Gets the last selected element, e.g. the last element selected through Select().

Returns
The last selected element.

◆ IsAllSelected()

Bool IsAllSelected ( Int32  num) const

Checks if all elements from zero to num-1 are selected.

Parameters
[in]numNumber of elements to check.
Returns
True, if all elements are selected.

◆ IsNothingSelected()

Bool IsNothingSelected ( ) const

Checks if nothing is selected.

Returns
True, if nothing is selected.

◆ GetData()

BaseSelectData* GetData ( void  )

Private.

◆ CopyFrom()

Bool CopyFrom ( BaseSelectData ndata,
Int32  ncnt 
)

Private.