PickSessionDataStruct Struct Reference

#include <c4d_basedocument.h>

详细描述

A pick session allows to select objects in the viewport or in the Object Manager.
An example of pick session is the way objects are selected for a link field pressing its interrogation's button.
A session is usually started with BaseDocument::StartPickSession() and can be ended by the developer with BaseDocument::StopPickSession() .
范例:
First, declare a static variable for the pick session data:

static PickSessionDataStruct * pickSessionData = nullptr ;

Define two functions to allocate and free the session data:

Bool AllocPickSession() { pickSessionData = NewObj ( PickSessionDataStruct ); return pickSessionData!= nullptr ; } void FreePickSession() { DeleteObj (pickSessionData); }

PluginStart() (usually defined in the Main.cpp of the plugin) call AllocPickSession() and in PluginEnd() call FreePickSession() .
Do not forget to forward declare AllocPickSession() and FreePickSession() at the beginning of Main.cpp . (Otherwise linking errors are raised by the compiler.)
Then the pick data can be initialized and the session started:

if (pickSessionData) { doc-> StopPickSession ( true ); pickSessionData-> multi = true ; pickSessionData-> callback = pickSessionCallBack; doc-> StartPickSession (pickSessionData); }

PickSessionDataStruct::multi 被设为 true to start a multi-object pick session. It is also possible to assign custom data to PickSessionDataStruct::userdata for use in the pick session callback.
Finally, the callback can be defined like this:

void pickSessionCallBack( Int32 flags, const PickSessionDataStruct *psd) { for ( Int32 i=0; i<psd-> active -> GetCount (); i++) { C4DAtom * atom = psd-> active -> GetIndex (i); if (atom && atom-> IsInstanceOf ( Obase )) { BaseObject *ob = ( BaseObject *)atom; if (ob) GePrint (ob-> GetName ()); } } }

The callback is called when the pick session has ended. PickSessionDataStruct::active holds the list of picked objects. In this example, the name of the selected object(s) during the pick session is printed to the console.

注意
Drag&Drop is handled automatically for an AtomArray by this functionality.
GeUserArea::HandleMouseDrag() is used with an AtomArray , all the objects in the array are pickable. There is no additional work needed.

公共成员函数

  PickSessionDataStruct ()
  ~PickSessionDataStruct ()

Public Attributes

AtomArray active
maxon::Delegate < void( Int32 , const PickSessionDataStruct *)>  callback
void *  userdata
Bool   multi

构造函数 & 析构函数文档编制

◆  PickSessionDataStruct()

PickSessionDataStruct ( )

Constructor.

◆  ~PickSessionDataStruct()

~ PickSessionDataStruct ( )

Destructor.

Member Data Documentation

◆  active

AtomArray * active

Filled with the picked objects.

◆  callback

maxon::Delegate <void( Int32 , const PickSessionDataStruct *)> callback

The pick session callback. The arguments are the flags and the populated PickSesionDataStruct with any selected objects linked in the active AtomArray .

◆  userdata

void* userdata

The user data passed to the pick session callback . The caller owns the pointed user data.

◆  multi

Bool multi

Set to true for multi-pick sessions. Usually a pick session ends when something is selected. With a multi-pick session it ends when the user terminates it ( ESC or double-click ).

PickSessionDataStruct::active
AtomArray * active
Filled with the picked objects.
定义: c4d_basedocument.h:456
DeleteObj
#define DeleteObj(obj)
定义: newobj.h:159
BaseDocument::StopPickSession
void StopPickSession(Bool cancel)
BaseObject
定义: c4d_baseobject.h:224
PickSessionDataStruct
定义: c4d_basedocument.h:454
PickSessionDataStruct::callback
maxon::Delegate< void(Int32, const PickSessionDataStruct *)> callback
The pick session callback. The arguments are the flags and the populated PickSesionDataStruct with an...
定义: c4d_basedocument.h:457
AtomArray::GetCount
Int32 GetCount() const
定义: c4d_baselist.h:1619
PickSessionDataStruct::multi
Bool multi
Set to true for multi-pick sessions. Usually a pick session ends when something is selected....
定义: c4d_basedocument.h:459
GePrint
void GePrint(const maxon::String &str)
BaseDocument::StartPickSession
void StartPickSession(PickSessionDataStruct *psd)
Obase
#define Obase
Base object - BaseObject.
定义: ge_prepass.h:1021
C4DAtom
定义: c4d_baselist.h:1331
Int32
maxon::Int32 Int32
定义: ge_sys_math.h:58
NewObj
#define NewObj(T,...)
定义: newobj.h:108
Bool
maxon::Bool Bool
定义: ge_sys_math.h:53
C4DAtom::IsInstanceOf
Bool IsInstanceOf(Int32 id) const
定义: c4d_baselist.h:1373
BaseList2D::GetName
String GetName() const
定义: c4d_baselist.h:2318
AtomArray::GetIndex
C4DAtom * GetIndex(Int32 idx) const
定义: c4d_baselist.h:1634