VariableChanged Struct Reference

#include <c4d_baselist.h>

Detailed Description

The VariableChanged structure is essential for changing point/polygon counts in objects to allocate or remove multiple elements with a single C4DAtom::Message() call.
It can be used for example when sending MSG_POINTS_CHANGED and MSG_POLYGONS_CHANGED messages to objects, tags and keys.

The structure contains the number of elements (points or polygons) before and after the change, and optionally a translation map array.
Each element in the map represents an element before the change, and its value decides what element this corresponds to after the change. This is used to keep for example point selections and vertex maps valid.

Example: Adding a point to a point object.

Int32 count = op->GetPointCount(); // Get actual point count
vc.old_cnt = count;
vc.new_cnt = count+1; // Resize point count from count to count+1
// Just for adding a point at the end of the point list a map is not needed
// Send the message to all tags and keys and let them return a boolean, telling us if everything is alright
if (op->Message(MSG_POINTS_CHANGED, &vc))
{
// Now all tags and structures have reacted and resized their memory part, so the new point can be accessed
Vector* points = op->GetPointW();
if (points)
points[count] = Vector(0, 0, 0); // Set data for the new point
op->Message(MSG_UPDATE); // Notify change to the object
}

Example: Inserting a point in a point object.

Int32 count = op->GetPointCount(); // Get actual point count
vc.old_cnt = count;
vc.new_cnt = count+1; // Resize point count from count to count+1
// Allocate a map
vc.map = NewMemClear(Int32, count);
if (vc.map != nullptr)
{
Int32 i, pos = 5; // pos is the index to insert the point at
// The points below pos stay at the same point number
for (i = 0; i <= pos; i++)
vc.map[i] = i;
// The points above pos are shifted 1 step
for (i = pos+1; i < count; i++)
vc.map[i] = i+1;
// Send the message to all tags and keys and let them return a boolean, telling us if everything is alright
if (op->Message(MSG_POINTS_CHANGED, &vc))
{
// Now all tags and structures have reacted and resized their memory part, so the new point can be accessed
Vector* points= op->GetPointW();
if (points)
points[pos] = Vector(0, 0, 0); // Set data for the new point
op->Message(MSG_UPDATE); // Notify change to the object
}
}

Public Member Functions

 VariableChanged ()
 

Public Attributes

Int32 old_cnt
 
Int32 new_cnt
 
Int32map
 
Int32 vc_flags
 

Constructor & Destructor Documentation

◆ VariableChanged()

Default constructor.

Member Data Documentation

◆ old_cnt

Int32 old_cnt

The number of elements before the change.

◆ new_cnt

Int32 new_cnt

The new number of elements.

◆ map

Int32 * map

The optional translation map.

Note
A map element can be NOTOK.

◆ vc_flags

Int32 vc_flags

Flags: VC_FLAGS

VariableChanged::map
Int32 * map
Definition: c4d_baselist.h:669
NewMemClear
#define NewMemClear(T, cnt)
Definition: defaultallocator.h:205
VariableChanged
Definition: c4d_baselist.h:660
MSG_POINTS_CHANGED
#define MSG_POINTS_CHANGED
The points have changed. The corresponding data is VariableChanged.
Definition: c4d_baselist.h:333
VariableChanged::new_cnt
Int32 new_cnt
The new number of elements.
Definition: c4d_baselist.h:668
MSG_UPDATE
#define MSG_UPDATE
Must be sent if the bounding box has to be recalculated. (Otherwise use MSG_CHANGE....
Definition: c4d_baselist.h:335
maxon::Vec3< maxon::Float64, 1 >
maxon::DeleteMem
void DeleteMem(T *&p)
Definition: defaultallocator.h:258
Int32
maxon::Int32 Int32
Definition: ge_sys_math.h:45
VariableChanged::old_cnt
Int32 old_cnt
The number of elements before the change.
Definition: c4d_baselist.h:667
Vector
maxon::Vec3< maxon::Float64, 1 > Vector
Definition: ge_math.h:133
EventAdd
void EventAdd(EVENT eventflag=EVENT::NONE)