About
maxon::CommandClassInterface is a base interface for standardized commands. Such a command operates solely on the given input data and can be used in various situations.
CommandClassInterface
A custom command must implement these two methods:
An implementation for such a data object must be based on maxon::CommandDataInterface which in return in based on maxon::DataDictionaryObjectInterface.
- Note
- All data related to the execution of the command must be stored in the maxon::CommandDataRef object.
Interactive commands (e.g. tools) can also implement maxon::CommandInteractionClassInterface:
class ExampleDataImpl :
public Component<ExampleDataImpl, CommandDataInterface>
{
public:
MAXON_METHOD Result<void> SetData(ForwardingDataPtr&& key, Data&& data)
{
return super.SetData(std::move(key), std::move(data));
}
MAXON_METHOD Result<Data> GetData(
const ConstDataPtr& key)
const
{
return super.GetData(std::move(key));
}
};
class ExampleCommandImpl :
public Component<ExampleCommandImpl, CommandClassInterface>
{
public:
MAXON_METHOD Result<COMMANDSTATE> GetState(CommandDataRef& data)
const
{
}
MAXON_METHOD Result<COMMANDRESULT> Execute(CommandDataRef& data)
const
{
}
};
LegacyCommandClassInterface
Some classic data types like BaseContainer cannot be stored in a maxon::DataDictionary. Therefore a custom data class is needed to store specific custom data. Such a data class can be implemented based on maxon::LegacyCommandDataInterface:
maxon::LegacyCommandClassInterface is based on maxon::CommandClassInterface. It can be implemented if custom data should be handled.
struct MoGraphSetupData
{
{
_doc = other._doc;
_cloner = other._cloner;
_object = other._object;
}
};
class MoGraphSetupDataImpl :
public Component<MoGraphSetupDataImpl, LegacyCommandDataInterface>
{
public:
{
return 1;
}
{
Generic* const dtaPtr = reinterpret_cast<Generic*>(&_data);
return dtaPtr;
}
{
if (data == nullptr)
const MoGraphSetupData* const moGraphData = reinterpret_cast<const MoGraphSetupData*>(data);
}
MAXON_METHOD Result<void> SetData(ForwardingDataPtr&& key, Data&& data)
{
return super.SetData(std::move(key), std::move(data));
}
MAXON_METHOD Result<Data> GetData(
const ConstDataPtr& key)
const
{
return super.GetData(std::move(key));
}
private:
MoGraphSetupData _data;
};
class MoGraphSetupCommandImpl :
public Component<MoGraphSetupCommandImpl, CommandClassInterface>
{
public:
MAXON_METHOD Result<COMMANDSTATE> GetState(CommandDataRef& data)
const
{
}
MAXON_METHOD Result<COMMANDRESULT> Execute(CommandDataRef& data)
const
{
LegacyCommandDataRef legacyData = Cast<LegacyCommandDataRef>(data);
MoGraphSetupData& moData = legacyData.GetLegacyData<MoGraphSetupData>(dataIndex)
iferr_return;
if (moData._doc == nullptr)
if (moData._object == nullptr)
{
BaseObject*
const activeObject = moData._doc->GetActiveObject();
if (activeObject == nullptr)
moData._object = activeObject;
}
if (cloner == nullptr)
moData._doc->InsertObject(cloner, nullptr, nullptr);
moData._object->Remove();
moData._doc->InsertObject(moData._object, cloner, nullptr);
moData._cloner = cloner;
}
};
Data
The data a command operates on is stored in a data object. A default data implementation is stored at maxon::CommandDataClasses::BASE. A custom data class can be implemented based on:
Calling Commands
A given command can be executed by calling the "Invoke" of the data object.
namespace CommandDataClasses
{
MAXON_DECLARATION(CommandDataClasses::EntryType, EXAMPLEDATA,
"net.maxonexample.commanddata.exampledata");
}
namespace CommandClasses
{
MAXON_DECLARATION(CommandClasses::EntryType, EXAMPLE,
"net.maxonexample.command.addition");
MAXON_DECLARATION(CommandClasses::EntryType, MOGRAPHSETUP,
"net.maxonexample.command.mographsetup");
}
namespace LegacyCommandDataClasses
{
MAXON_DECLARATION(LegacyCommandDataClasses::EntryType, MOGRAPHSETUPDATA,
"net.maxonexample.legacycommanddata.mographsetup");
}
maxon::CommandDataRef data = maxon::CommandDataClasses::EXAMPLEDATA().Create()
iferr_return;
const auto command = maxon::CommandClasses::EXAMPLE();
MoGraphSetupData data;
data._doc = doc;
data._object = nullptr;
maxon::LegacyCommandDataRef legacyData = maxon::LegacyCommandDataClasses::MOGRAPHSETUPDATA().Create()
iferr_return;
legacyData.SetLegacyData<MoGraphSetupData>(data, dataIndex)
iferr_return;
const auto command = maxon::CommandClasses::MOGRAPHSETUP();
const MoGraphSetupData result = legacyData.GetLegacyData<MoGraphSetupData>(dataIndex)
iferr_return;
result._cloner->SetName("The New Cloner"_s);
Further Reading