Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Refreshing customgui tree view in a dialog

 Post Reply Post Reply
Author
Message
peterakos View Drop Down
Member
Member


Joined: 2015 Jul 13
Online Status: Offline
Posts: 309
Post Options Post Options   Quote peterakos Quote  Post ReplyReply Direct Link To This Post Topic: Refreshing customgui tree view in a dialog
    Posted: 2017 Oct 04 at 7:50am

User Information:

Cinema 4D Version:   R17 
Platform:   Windows  ;   
Language(s):     C++  ;   

---------

Hello.

I have a GeDialog with a Treeview custom gui in a group. 
I want to recreate the tree with different nodes after a specific node is selected. 
What I do is that i set a different root, but since I do it in the Select method of TreeViewFunctions, I get memory corruption crash (since I delete the previous).
Where is the correct place to set a different root node in the treeview ? 
I didn't find any callback for that purpose in TreeViewFunctions.

Should I do it by sending a message in the dialog ?

Thank you for your time !
Back to Top
knickknack View Drop Down
Forum Moderator
Forum Moderator


Joined: 2016 Jul 01
Location: Italy
Online Status: Offline
Posts: 170
Post Options Post Options   Quote knickknack Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Oct 06 at 12:47pm
Hi Peterakos, thanks for writing us.

With reference to your question, from my research, you should not encounter any issue in defining a new root in the TreeViewFunctions::Select() method. Are you maybe deleting the old root before setting the new one?

I've actually changed the "Layer Shader Browser" example found in the cinema4dsdk modifying the accepted items from a LayerShaderLayer to a standard BaseObject. The behavior is simple but yet adhering to what you've described: every time an item is selected in the TreeViewCustomGui, assuming that this isn't the first, the newly selected object become the new root whilst the previous "root" is removed from the scene and disposed.

This actually happen in the TreeViewFunctions::Select() method as shown below:

void Select(void* root, void* userdata, void* obj, Int32 mode)
{
    BaseObject* bo = static_cast<BaseObject*>(obj);

    // retrieve the GeDialog instance
    MyTreeBrowser* tb = ((MyTreeBrowser*)userdata);
   
    // retrieve the TreeViewCustomGui instance
    TreeViewCustomGui* tree = (TreeViewCustomGui*)tb->FindCustomGui(DLG_MYTREEBROWSER_TREE, CUSTOMGUI_TREEVIEW);
   
    if (!tree)
        return;
   
    // retrieve the first object which is also set as root
    BaseObject* currentRoot = (BaseObject*)this->GetFirst(root, userdata);
   
    // set the new root
    tree->SetRoot(bo, this, userdata);
   
    // eventually remove the "previous" root
    if (currentRoot && currentRoot != bo)
    {
        currentRoot->Remove();
        BaseObject::Free(currentRoot);
        EventAdd();
    }
    // do something else
    // ...     
}


That said I actually used no fancy callbacks or messages rather than simply relying on the methods pointed above.

Let me know if it helps, otherwise well let's dig down again.

Best, Riccardo


Edited by knickknack - 2017 Oct 06 at 12:49pm
MAXON Computer GmbH
SDK Support Team
Back to Top
peterakos View Drop Down
Member
Member


Joined: 2015 Jul 13
Online Status: Offline
Posts: 309
Post Options Post Options   Quote peterakos Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Oct 08 at 2:38pm
Hello.

Originally posted by knickknack


Are you maybe deleting the old root before setting the new one?

That's exactly what I do !
I'll fix my code to delete it after setting the new root.

Thank you very much for your help !

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.109 seconds.