On 27/11/2017 at 03:38, xxxxxxxx wrote:
Hello,
could you post the code of your custom data type? This would help to understand what you are doing.
Please notice the the custom data stored in a custom data type is typically based on iCustomDataType. You find an example in customdata_customgui.cpp.
A simple data type that defines a sub-parameters can look like this:
class ExampleCustomDataClass;
class iExampleData : public iCustomDataType<iExampleData>
{
friend class ExampleCustomDataClass;
public:
String _string;
Int32 _int;
iExampleData()
{
_string = "";
_int = 0;
}
};
const Int g_customDataID = 1000001;
class ExampleCustomDataClass : public CustomDataTypeClass
{
INSTANCEOF(ExampleCustomData, CustomDataTypeClass)
public:
virtual Int32 GetId()
{
return g_customDataID;
}
virtual CustomDataType* AllocData()
{
iExampleData* data = NewObjClear(iExampleData);
return data;
};
virtual void FreeData(CustomDataType* data)
{
iExampleData* d = static_cast<iExampleData*>(data);
DeleteObj(d);
}
virtual Bool CopyData(const CustomDataType* src, CustomDataType* dst, AliasTrans* aliastrans)
{
const iExampleData* s = static_cast<const iExampleData*>(src);
iExampleData* d = static_cast<iExampleData*>(dst);
if (!s || !d)
return false;
d->_int = s->_int;
d->_string = d->_string;
return true;
}
virtual Int32 Compare(const CustomDataType* d1, const CustomDataType* d2)
{
const iExampleData* const s = static_cast<const iExampleData*>(d1);
const iExampleData* const d = static_cast<const iExampleData*>(d2);
if (!s || !d)
return 0;
// just compare the int because I'm lazy
const maxon::Int countd1 = s->_int;
const maxon::Int countd2 = d->_int;
if (countd1 == countd2)
return 0;
if (countd1 < countd2)
return -1;
if (countd1 > countd2)
return 1;
return 0;
}
virtual Bool _GetDescription(const CustomDataType* data, Description& res, DESCFLAGS_DESC& flags, const BaseContainer& parentdescription, DescID* singledescid)
{
BaseContainer stringSettings = GetCustomDataTypeDefault(DTYPE_STRING);
stringSettings.SetString(DESC_NAME, "String Data");
stringSettings.SetString(DESC_SHORT_NAME, "String Data");
stringSettings.SetFloat(DESC_MIN, 0.0f);
stringSettings.SetFloat(DESC_MAX, 1.0f);
stringSettings.SetFloat(DESC_STEP, 0.01f);
if (!res.SetParameter(DescLevel(1000, DTYPE_STRING, g_customDataID), stringSettings, DESCID_ROOT))
return false;
BaseContainer intSettings = GetCustomDataTypeDefault(DTYPE_LONG);
intSettings.SetString(DESC_NAME, "Int data");
intSettings.SetString(DESC_SHORT_NAME, "Intdata");
if (!res.SetParameter(DescLevel(1001, DTYPE_LONG, g_customDataID), intSettings, DESCID_ROOT))
return false;
flags |= DESCFLAGS_DESC_LOADED;
return CustomDataTypeClass::_GetDescription(data, res, flags, parentdescription, singledescid);
}
virtual Bool GetParameter(const CustomDataType* data, const DescID& id, GeData& t_data, DESCFLAGS_GET& flags)
{
iExampleData* s = (iExampleData* )data;
if (!s)
return false;
const Int32 subID = id[0].id;
if (subID == 1000)
t_data = GeData(s->_string);
else if (subID == 1001)
t_data = GeData((Int32)s->_int);
flags |= DESCFLAGS_GET_PARAM_GET;
return CustomDataTypeClass::GetParameter(data, id, t_data, flags);
}
virtual Bool SetDParameter(CustomDataType* data, const DescID& id, const GeData& t_data, DESCFLAGS_SET& flags)
{
iExampleData* s = (iExampleData* )data;
if (!s)
return false;
const Int32 subID = id[0].id;
if (subID == 1000)
{
s->_string = t_data.GetString();
}
else if (subID == 1001)
{
s->_int = t_data.GetInt32();
}
flags |= DESCFLAGS_SET_PARAM_SET;
return CustomDataTypeClass::SetDParameter(data, id, t_data, flags);
}
virtual Bool GetEnabling(const CustomDataType* data, const DescID& id, const GeData& t_data, DESCFLAGS_ENABLE& flags, const BaseContainer* itemdesc)
{
const iExampleData* s = static_cast<const iExampleData*>(data);
if (!s)
return false;
const Int32 subID = id[0].id;;
if (subID == 1001)
{
if (s->_string.Content())
return true;
else
return false;
}
return SUPER::GetEnabling(data, id, t_data, flags, itemdesc);
}
virtual const Char* GetResourceSym()
{
return "EXAMPLE";
}
virtual void GetDefaultProperties(BaseContainer& data)
{
// the default values of this datatype
data.SetInt32(DESC_ANIMATE, DESC_ANIMATE_ON);
}
virtual Bool WriteData(const CustomDataType* t_d, HyperFile* hf)
{
// skip that to make this example easy
return true;
}
virtual Bool ReadData(CustomDataType* t_d, HyperFile* hf, Int32 level)
{
// skip that to make this example easy
return true;
}
};
The sub-parameter can then be accessed with a properly created DescID:
GeData data;
DescID desc(DescLevel(ID_USERDATA, DTYPE_SUBCONTAINER, 0), DescLevel(1, g_customDataID, 0), DescLevel(1000, DTYPE_STRING, 0));
node->GetParameter(desc, data, DESCFLAGS_GET_0);
const String str = data.GetString();
GePrint(str);
To work with the CustomDataType returned by GetCustomDataType() you would have to define a public class based on CustomDataType that exposes internal functionality using the library system. But that's quite an advanced topic.
From a quick look, it seems that GetEnabling() is not used at all.
best wishes,
Sebastian