User Tools

Site Tools


reference:propertyextension

单元属性扩展

扩展单元属性时,对象类应从XProperty继承,需按照下列代码重新实现基类的接口。

class NewPrp: public XProperty
{
	DECLARE_CITEM(NewPrp)
public:
	NewPrp(ulong id = 0);
	~NewPrp();
	const PropertyAttribute * getAttribute() const { return attribute(); }
	const NewPrpAttribute * attribute() const { return &m_Atb; }
	void setAttribute(const PropertyAttribute * atb) { m_Atb = *(NewPrpAttribute*)atb; }
	ulong getMaterialId() const { return m_Atb.ulMatId; }
	void setMaterial(ulong matId) { m_Atb.ulMatId = matId; }

	void write(XBinaryIO * io);
	ErrorCode read(XBinaryIO * io);
	void write(XH5IO * io, H5Obj * grp);
	bool read(XH5IO * io, H5Obj * dset);

private:
	NewPrpAttribute m_Atb;
};
  • 注册对象定义,它被归为Domain_Property域,所以被PropertyManager管理,DECLARE_CITEM(NewPrp)是声明, 类型标识前缀为“CPRP”,其实现通过宏按照如下形式实现:
REGISTER_CITEM(NewPrp, "CPRPNEWPRP", PropertyManager::ctype(), 0);
  • 定义单元属性,每个新扩展的单元属性都有自己的属性(NewPrpAttribute),它从PropertyAttribute继承:
struct NewPrpAttribute: public PropertyAttribute
{
	double dValue;
};
  • 重新实现材料ID的访问设置接口getMaterialId、setMaterialId
  • 重新实现属性的接口getAttribute、listProperty以及专有属性接口
	const NewPrpAttribute * attribute() const {return &m_Atb;}
  • 重新实现读写对象数据的接口read、write
reference/propertyextension.txt · Last modified: 2023/05/06 07:01 (external edit)