Using OCAF function mechanism

I am trying to use OCAF function mechanism and have the following questions.

1.After I set an attribute at a particular label as Impacted or touched, the driver->MustExecute(log) will recognize that the relevant function has to be executed. But after the driver->Execute(log) is called if I call driver->MustExecute(log) again, it returns "true". Probably because the labels are still marked as touched/impacted. Is there a mechanism to unset the labels/attributes touched/impacted feature after execution? How does this work?
If I somehow unset these flags at the driver->Execute(log) function, another function at another node which has this label as a reference label will not identify that this label attribute is touched. However, I do not want the first_driver->MustExecute(log) to return "true" the second time also.

Note: I am setting "TFunction_Scope::Set(OcafDoc->Main());" when creating a new document in the main application and access the log book when I need it as follows.
Handle(TFunction_Scope) scope = TFunction_Scope::Set(OcafDoc->Main());
TFunction_Logbook& log = scope->GetLogbook();

2. Function iteration loop:
When I come to the function iteration loop my loop starts as follows.

TFunction_Iterator iterator(OcafDoc->Main());
iterator.SetUsageOfExecutionStatus(false);
int numThrds = iterator.GetMaxNbThreads(); //this gives me a zero value

for(;iterator.More(); iterator.Next())
{

}

However, the iterator doesn't find anything. It does not go in to the loop. I know there are function drivers attached to some of the labels because when I use the following loop it shows me the functions are attached at some labels.(the counter shows a +ve number at the end) & the log book has values set as impacted/touched.

int counter = 0;
for (TDF_ChildIterator it1(OcafDoc->Main(),Standard_True); it1.More(); it1.Next())
{
TDF_Label L1 = it1.Value();
Handle_TDF_Attribute TDR;
if(L1.FindAttribute(TFunction_Function::GetID(),TDR))
{
counter++;
}
}

Really appreciate any help & guidance.

Chanaka Mallikarachchi's picture

Do I have to declare a TFunction_Sope object and use TFunction_Scope::AddFunction(label) method?

Forum supervisor's picture

Dear Chanaka,
I suggest you to overlook the document
"OPEN CASCADE APPLICATION FRAMEWORK FUNCTION MECHANISM USER’S GUIDE"
or contact us via Contact Form http://www.opencascade.org/about/contacts/.
Regards

Chanaka Mallikarachchi's picture

Dear Forum Supervisor,
Thank you for the suggestion.I have gone through all the documentation available online and what is on the forum. I have few specific questions while on the implementation part.Hopefully someone on the forum will answer me.

Chanaka Mallikarachchi's picture

To answer my own questions.

1. I think I have to clear the log after I iterate through all the functions and execute functions that returns mustExecture() true.

2. The above function iteration loop was an attempt at directly using the code used for lamp example. I think I have to make a tree node graph with proper dependencies and execute the functions in that dependency order.

JuryS's picture

Hi, Chanaka.
I'm active user of OCAF and I would like to help you, but
I never used TFunction_Logbook. Why you are need to use this? Maybe we can find another way ?

Chanaka Mallikarachchi's picture

Hi Yuriy,
I'm using TFunction_Logbook to keep a track of which attributes are changed by the user or by an algorithm in the data tree.
When the function driver calls it's mustExecute() function it will check the logbook to see if any of the variables used in its algorithm is changed and if Yes, the Execute() will be called. The execute() function will also update the Logbook on which variables(shapes) it is changing.

Do you use any iterations to search through the data tree (such as 'TDataStd_TreeNode') and execute function drivers?

Thanks,

Chanaka.

JuryS's picture

I'm use more easy method. I don't use any logging in my application, but if I want to know something about create or delete label I'm check the before and after vector of labels TAGS or some tag of label, created or no, for example:

createline *runMe = new createline();
TDF_Label MainLab = command->getMainLab();
uint aTag(0); // THE CONTROL VALUE
const QString &result = runMe->lineForMac(aTag,MainLab,X1,Y1,Z1,X2,Y2,Z2,Name,R,G,B);
delete runMe;
if (aTag==0) // AFTER EXECUTION
{
MacroEngine->setIsErrorEvaul();
engine->abortEvaluation(result.toUtf8().constData());
return 0;
}
MacroEngine->AddObject(aTag,Name);
stApp->addNewHistoryText(result);

return 0;

Also if you have more that one tag:

createspline* runMe = new createspline();
TDF_Label MainLab = command->getMainLab();
QVector myVec = MacroEngine->createdLabels;
const QString &result = runMe->SplineForMac(MacroEngine->namesOfScene,MainLab,myVec,
NamesOfPoints,Name,R,G,B);
delete runMe;
if (!MacroEngine->checkTags(myVec))
{
MacroEngine->setIsErrorEvaul();
engine->abortEvaluation(result.toUtf8().constData());
return 0;
}
stApp->addNewHistoryText(result);
return 0;
}

Here is QVector contains all tags of before labels. And after I'm check him for new values.

JuryS's picture

Your think about TFunction_Logbook is cool, but I think It's very hard to use in application.

JuryS's picture

Total:

use tags of label, tags for all document:

QVector MacroAnalizer::GetAllTags()
{
QVector myVec;
for (TDF_ChildIterator it(getMainLab(),false); it.More(); it.Next())
{
if (it.Value().IsAttribute(TDataStd_AsciiString::GetID()))
myVec.append(it.Value().Tag());
}
return myVec;
}

And check this vector before and after any operation

Chanaka Mallikarachchi's picture

Hi Yuriy,
Thank you very much for your input. I managed to get the function mechanism and redo/undo mechanism working using OCAF. What I did was a small application but it is a good base to expand.

JuryS's picture

Ok, Chanaka.
Glad for you. Ask if something doesn't turn out.