BaseSelect Class Reference

#include <c4d_baseselect.h>

Protected Member Functions

Bool FindNum (Int32 num, Int32 *last, Bool protect=true) const
 
Bool FlushData (Int32 num)
 
Bool InsertData (Int32 num, Int32 a, Int32 b)
 
void Write_API (HyperFile *hf)
 
Bool Read_API (HyperFile *hf)
 

Protected Attributes

BaseSelectDatadata
 
Int32 cnt
 
Int32 lseg
 
Int32 dirtycnt
 
Int32 lelement
 

Friends

class ItemListDataTypeClass
 

Constructor/Destructor

 BaseSelect ()
 
virtual ~BaseSelect ()
 

Alloc/Free

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

Selection/Segment Count

Int32 GetCount ()
 
Int32 GetSegments ()
 

Select/Deselect/Toggle

Bool Select (Int32 num)
 
Bool SelectAll (Int32 min, Int32 max)
 
Bool Deselect (Int32 num)
 
Bool DeselectAll ()
 
Bool Toggle (Int32 num)
 
Bool ToggleAll (Int32 min, Int32 max)
 
Bool IsAllSelected (Int32 num) const
 
Bool GetRange (Int32 seg, Int32 *a, Int32 *b) const
 
Bool IsSelected (Int32 num) const
 
Bool FindSegment (Int32 id, Int32 *segment)
 

Copy/Merge/Cross

Bool CopyTo (BaseSelect *dest) const
 
Bool Merge (BaseSelect *src)
 
Bool Deselect (BaseSelect *src)
 
Bool Cross (const BaseSelect *src)
 
BaseSelectGetClone () const
 
Bool IsEqual (const BaseSelect &compare) const
 

Conversion from/to Array

Bool FromArray (UChar *selection, Int32 count)
 
UCharToArray (Int32 count)
 

Private

Int32GetData ()
 
Bool CopyFrom (BaseSelectData *ndata, Int32 ncnt)
 
virtual Bool Write (HyperFile *hf)
 
virtual Bool Read (HyperFile *hf, Int32 id, Int32 level)
 

Detailed Description

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().

Constructor & Destructor Documentation

◆ BaseSelect()

Default constructor.

◆ ~BaseSelect()

virtual ~BaseSelect ( )
virtual

Default destructor.

Member Function Documentation

◆ FindNum()

Bool FindNum ( Int32  num,
Int32 last,
Bool  protect = true 
) const
protected

◆ FlushData()

Bool FlushData ( Int32  num)
protected

◆ InsertData()

Bool InsertData ( Int32  num,
Int32  a,
Int32  b 
)
protected

◆ Write_API()

void Write_API ( HyperFile hf)
protected

◆ Read_API()

Bool Read_API ( HyperFile hf)
protected

◆ Alloc()

static BaseSelect* Alloc ( )
static

Allocates a base selection. Destroy the allocated base selection with Free().

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

◆ Free()

static void Free ( BaseSelect *&  bs)
static

Destructs base selections allocated with Alloc().

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

◆ GetCount()

Int32 GetCount ( )

Gets the number of selected elements.

Returns
The number of selected elements.

◆ GetSegments()

Int32 GetSegments ( )

Gets the number of segments that contain elements.
For example: The selections 0..4, 6..7, 9..12 would be three segments. 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 
)

Selects all elements in the given range.

Note
All previous selections are cleared.
Parameters
[in]minThe first element to select.
[in]maxThe last element in the range to select.
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 ( )

Deselect 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.

◆ IsAllSelected()

Bool IsAllSelected ( Int32  num) const

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

Parameters
[in]numThe last element to check.
Returns
true if all the element sin the range 0 to num-1 are selected, otherwise false.

◆ GetRange()

Bool GetRange ( Int32  seg,
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()
[out]aAssigned the index of the first selected element.
[out]bAssigned the index of the last selected element.
Returns
Success of getting the range; 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

Check 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++, &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.

◆ FindSegment()

Bool FindSegment ( Int32  id,
Int32 segment 
)

Calculates which segment contain the element id and assign it to segment.

Parameters
[in]idAn element number.
[in]segmentAssigned the found segment index.
Returns
Success of finding the segment for element id.

◆ CopyTo()

Bool CopyTo ( BaseSelect dest) const

Copies the selection elements to another BaseSelect.

Parameters
[out]destThe destination selection.
Returns
Success of copying the selection elements.

◆ Merge()

Bool Merge ( BaseSelect src)

Selects all elements that are selected in src.

Parameters
[in]srcThe source selection.
Returns
Success of merging the selection elements.

◆ Deselect() [2/2]

Bool Deselect ( BaseSelect src)

Deselects all elements that are selected in src.

Parameters
[in]srcThe source selection.
Returns
Success of deselecting the selection elements.

◆ Cross()

Bool Cross ( const BaseSelect src)

Intersects all elements in src.

Parameters
[in]srcThe source selection.
Returns
Success of crossing the selection elements.

◆ GetClone()

BaseSelect* GetClone ( ) const

Makes a duplicate of the selection with its elements.

Returns
The cloned BaseSelect or nullptr if failed.

◆ IsEqual()

Bool IsEqual ( const BaseSelect compare) const

Compares the selection with another selection.

Parameters
[in]compareThe selection to compare with.
Returns
true if the elements in the selections are exactly the same, 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.

Note
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
Success of selecting the elements from the array.

◆ ToArray()

UChar* ToArray ( Int32  count)

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.
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.

◆ GetData()

Int32* GetData ( )

Private.

◆ CopyFrom()

Bool CopyFrom ( BaseSelectData ndata,
Int32  ncnt 
)

Private.

◆ Write()

virtual Bool Write ( HyperFile hf)
virtual

Private.

◆ Read()

virtual Bool Read ( HyperFile hf,
Int32  id,
Int32  level 
)
virtual

Private.

Friends And Related Function Documentation

◆ ItemListDataTypeClass

friend class ItemListDataTypeClass
friend

Member Data Documentation

◆ data

BaseSelectData* data
protected

◆ cnt

Int32 cnt
protected

◆ lseg

Int32 lseg
protected

◆ dirtycnt

Int32 dirtycnt
protected

◆ lelement

Int32 lelement
protected