
Fri, 03/28/2025 - 03:23
I am trying to use OCCT's function mechanism to achieve real-time updates for parametric modeling. To start, I wrote a simple demo, but during the output testing of the demo, I found that regardless of whether I modified the attributes of an Attribute in a Label, the output information always showed "No attribute Modified." This confuses me, and I hope you can help me figure it out. Below is the main code of my demo:
Handle(TDocStd_Application) m_app = new TDocStd_Application();
BinDrivers::DefineFormat(m_app);
Handle(TDocStd_Document) newDoc;
m_app->NewDocument("BinOcaf", newDoc);
TDF_Label rootLabel = newDoc->Main();
Handle(TFunction_Scope) scope = TFunction_Scope::Set(rootLabel);
Handle(TFunction_DriverTable) driverTable = TFunction_DriverTable::Get();
Handle(MyFunctionDriver) myDriver = new MyFunctionDriver();
newDoc->NewCommand();
TDF_Label IntLabel = rootLabel.FindChild(1);
TDataStd_Integer::Set(IntLabel, 10);
Standard_Boolean success = driverTable->AddDriver(MyFunctionDriver::GetID(), myDriver, 0);
if (success)
{
std::cout << "Driver successfully added to DriverTable!" << std::endl;
}
else
{
std::cerr << "Failed to add Driver to DriverTable!" << std::endl;
}
Handle(TFunction_Function) func = new TFunction_Function();
func->SetDriverGUID(myDriver->GetID());
IntLabel.AddAttribute(func);
TDataStd_Name::Set(IntLabel, "int++");
newDoc->CommitCommand();
scope->AddFunction(IntLabel);
Handle(TDataStd_Integer) attr;
newDoc->NewCommand();
if (IntLabel.FindAttribute(TDataStd_Integer::GetID(), attr))
{
attr->Set(20);
}
newDoc->CommitCommand();
std::cout << IntLabel.AttributesModified() << std::endl;//it will cout 0 here.