CATIA CAA API Help – 11

refreshing the visualization of CATIA tree

I will try to explain the scenario and give some sample code:
My model looks like:

Root product (xxx.CATProduct)
-Child product.1 (yyy.CATProduct) (Active Doc)
+Child part (aaa.CATPart)
+Child part (bbb.CATPart)
+Child product.2 (yyy.CATProduct)
….

In my code I add a new part (ccc.CATPart)
to Child product.1.

Sample code:
in this code _pRootDoc points to xxx.CATProduct
_pActiveDoc points to yyy.CATProduct and_spInstProd is the CATIProduct_var for the instance Child product.1
_UtilityRtns.GetRootProduct uses the normal method to get the root product.
_UtilityRtns.UpdateProduct creates a CATCreate notification for the products father.
_UtilityRtns.SendModifyNotice creates a CATModify notification.
_UtilityRtns.RedrawSpecTree performs the Redraw using CATIRedrawEvent.

// open the CATPart or CATProduct to be imported
CATDocument *pPartDoc = NULL;
rc = CATDocumentServices::Open(LPath,pPartDoc);
if (SUCCEEDED(rc) && pPartDoc != NULL)
{
// get the root product of the main document
CATIProduct *pRootProduct = _UtilityRtns.GetRootProduct(_pRootDoc);

// get the root product of the active document
CATIProduct *pActiveProduct = _UtilityRtns.GetRootProduct(_pActiveDoc);

// get the root product of the new instance
CATIProduct *pExtProduct = _UtilityRtns.GetRootProduct(pPartDoc);

if (pActiveProduct != NULL && pExtProduct != NULL)
{
CATIProduct_var spReference(pExtProduct);
CATIProduct_var spNewProduct = NULL_var;
spNewProduct = pActiveProduct->AddProduct(spReference);
pExtProduct->Release();
if (spNewProduct != NULL_var)
{
_UtilityRtns.UpdateProduct(spNewProduct);
if (!_UtilityRtns.ProductsEqual(pRootProduct,pActiveProduct))
{
_UtilityRtns.SendModifyNotice(pActiveProduct);

// Update the Active product
CATISpecObject_var spUpdt(pActiveProduct);
if (spUpdt != NULL_var)
{
spUpdt->Update();
}

// Redraw the updated specification tree
_UtilityRtns.RedrawSpecTree(pActiveProduct);

// Redraw the updated specification tree using
// the instance product
_UtilityRtns.RedrawSpecTree(_spInstProd);
}

// Update the Root product
_UtilityRtns.SendModifyNotice(pRootProduct);
CATISpecObject_var spUpdt(pRootProduct);
if (spUpdt != NULL_var)
spUpdt->Update();

// Redraw the updated specification tree
_UtilityRtns.RedrawSpecTree(pRootProduct);
}
}

This code may also do too many operations but it works and it doesn’t process every child under the root product.
I hope that this helps
Bob
Original message :
I solved the problem, calling the CATIProduct::GetAllChildren() from the root product, and applying the CATIRedrawEvent::Redraw() to all the elements of the result, so that it executes a CATIRedrawEvent::Redraw() for each product of the tree. It works, but i perform this operation several times, and it is unefficient. I could also change slightly the program so that i call that operation only when needed, maybe only on that part of the tree that is changed, but i would like to avoid it. I didn’t really understand your solution. Do you have a piece of code to show me? Thanks a lot dario

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s