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

Treeview with custom tree

Page  <12
Author
Message
  Topic Search Topic Search
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Direct Link To This Post Posted: 2014 Jan 20 at 8:23am
Originally posted by pgrooff

@Scott: I want to download information from the Internet and present it in a treeview.
So, the information is not cinema 4d info, thus I need to define my own nodes and present it in the treeview.


Does the code Niklas provided answer your question though Pim?
Because as far as I can see. Even if you create a tree node system from scratch. Which I still don't think you have to do. You still have the problem of how to display text based information in the tree.

There's void *parameters in the tree's methods that I think are there to use for things like this. But I keep running into type errors.
A good example is the help system in C4D.
It's using a tree to display names of pages. And jumps you to them when clicked on in the tree gizmo.
How do we do that?

That's the kind of example I think Robert was going to show.
Are still will to share that code Robert?

-ScottA
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2014 Jan 20 at 9:45am
Originally posted by ScottA

Because as far as I can see. Even if you create a tree node system from scratch. Which I still don't think you have to do. You still have the problem of how to display text based information in the tree.

Of course you could use the BaseList2D class, but it is not optimized for this purpose. It would come with
a huge overhead and you would make your life hard yourself if you want to display any data more than
just a name and folding and selection states.

Originally posted by ScottA

A good example is the help system in C4D.It's using a tree to display names of pages. And jumps you to them when clicked on in the tree gizmo.
How do we do that?

It's a Treeview Gui and an HTML Gui. When one item in the tree is clicked, the HTML Gui changes its
contents. What is the problem you have here?

-Niklas


Edited by NiklasR - 2014 Jan 20 at 9:46am
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Direct Link To This Post Posted: 2014 Jan 20 at 10:38am
I know how to handle the HTML GUI part.
It's making the tree display data other than a BaseObject() or a BaseMaterial() that I can't figure out how to do.

For example. This code displays BaseObjects:
    virtual void *GetFirst(void *root,void *userdata)
    {
        //Casting from BaseDocument() to root works fine here
        BaseDocument *doc = (BaseDocument*)root;

        //Grabs the first object in the OM and fills the node data with a BaseObject type of data
        return GetActiveDocument()->GetFirstObject();
    }
...
    virtual String GetName(void *root, void *userdata, void *obj)
    {
        //The text in our tree branches comes from the string values in BaseObject
        return ((BaseObject*)obj)->GetName();
    }


Now what if we don't want to display a BaseObject() or BaseMaterial() in our tree?
What if for example. We want to use the objects stored in a BaseContainer? Or an array? Or maybe the file names of the HTML pages stored in a folder like the C4D help tree gui works?

This does not work:

    virtual void *GetFirst(void *root,void *userdata)
    {
        //Casting from BaseContainer() to root does not work like BaseDocument() does
        BaseContainer *bc = (BaseContainer*)root;  //<---Ouch! void type error!!
 
        return  bc->GetLong(1)  //<---Trying to return the first object in the container???
    }



From what I'm guessing.
The tree gizmo is a linked list that takes a bunch of items that are stored somewhere (the document, an array, a container, etc...).
Using the SDK tree gizmo we can easily use the objects stored in a BaseDocument() to populate the tree. Because somehow...Somewhere. The node for the tree is set up to handle these type of data.

But how do we use data from an array, or a BaseContainer, or a folder containing a bunch of HTML files like the C4D help tree gizmo works?
Making a custom node only shows how to set up the way a tree looks and behaves. But it doesn't address how to use it with data stored someplace other than BaseDocument or BaseList2D.

I had thought that we could maybe use the void *params. to do that. But maybe not?

-ScottA
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2014 Jan 20 at 11:27am
That is the very reason to use your own Node class, Scott. First, you build the tree, then you display it
in the TreeViewCustomGui. The TreeViewCustomGui is nowhere fixed to be used with objects from a
document, it is just a coincidence (intentionally of course) that it is easy to use with them.

Regarding your pseudo-example code, GetFirst(), just as many of the other methods in the
TreeViewFunctions class, returns a void* pointer. It is up to you to be sure about the actual type of
the memory address to return, all it wants is a memory address. From this memory address, it will
ask you for more data (GetNext(), GetName(), IsSelected() all get that void pointer passed as an argument).

In your example, you will probably want to do something like this instead?

virtual void* GetFirst(void* root, void* ud) {
    BaseDocument* doc = GetActiveDocument();
    if (doc)
        return doc->GetFirstObject();
    return nullptr;
}

// ... GetNext(), GetPred(), GetDown(), GetUp() ...

virtual String GetName(void* root, void* ud, void* obj) {
    BaseObject* op = static_cast<BaseObject*>(obj);
    BaseContainer* bc = op->GetDataInstance();
    if (bc)
        return bc->GetString(1);
    return "<???>";
}

Best,
-Niklas


Edited by NiklasR - 2014 Jan 20 at 11:30am
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Direct Link To This Post Posted: 2014 Jan 20 at 12:36pm
Ok Thanks.
That answers the question I had whether or not we must create a new Node or not.

But I still don't know how to write the code that declares what data type the node can hold and use.
So that I can display a list of filenames in the tree rather than object names?

You've got three classes involved in your tree gizmo
-class BaseNode
-class Node : public BaseNode
-class TreeModel : public TreeViewFunctions

I assume we don't declare the data type in the TreeModel class.
So where (how) do we declare the data type we want to display in our tree. If I wanted to display the names of HTML files I have in a folder on my HD?

-ScottA

*Edit-- Oh wait..I think I can do that in the AddNode() function. And use Filename() there to set the node's text instead of "NewNode".


Edited by ScottA - 2014 Jan 20 at 2:04pm
Back to Top
Page  <12

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.