Data class instantiation and loading from document

Hello,

I have developed a Rhino c++ plug-in.
My plug-in shows a tree, contained into a CRhinoTabbedDockBarDialog, which presents the data contained into a tree model.
The tree model is populated with:

  • some static elements which are always present, such the root and few children that allow to run particular actions;
  • some dynamic elements built by the user, (the user can add, modify, move, delete these elements) that are saved into the .3dm on Rhino save event.

I don’t know if can be of help, but my tree view is build using Qt framework. I hook it to the CRhinoTabbedDockBarDialog throw the QWinWidget class, which allows to hook a QWidget to a Win dialog

I would like to better understand:

  1. Where should I instantiate the tree model and its static elements. Into my CRhinoPlugIn::OnLoadPlugIn() overload?
  2. Where should I load the data from the .3dm file and fill-in the tree model? I thought to my CRhinoEventWatcher::OnEndOpenDocument(CRhinoDoc&, const wchar_t*, BOOL, BOOL) and CRhinoEventWatcher::OnNewDocument(CRhinoDoc&) functions overload but I’m not sure they are executed after the OnLoadPlugIn() execution. I need to update the data model both when I open a document (new or saved) after the plug-in is fully loaded and when I load my plug-in after the document has been already opened. Anyway, should I manage the tree model updating into other CRhinoEventWatcher events?
  3. Which is the best place where I can store the reference to my tree model? Into my CRhinoPlugIn class? I need to access to it from several commands of my plug-in, and I would prefer to avoid to include my CRhinoPlugIn header file into each file where I need to change the tree model.

Any tips would be very appreciated!

Thank you,
Alberto

Hi @margari,

  1. I tend to instantiate stuff in a lazy, on-demand manner. For example, I wouldn’t create and initialize a tree until the user requested it.
  2. Definitely override the event watcher virtual functions you’ve mentioned. By the time these are called, any document data that you’ve written will have been read.
  3. Its comment for devs to store plug-in specific document data on their plug-in object. But creating some singleton somewhere is also a good practice.

A sample you might enjoy.

TestMfcTree.zip (36.4 KB)

– Dale

Sorry @dale,

I noticed that in your example, which explains well how to develop what I need, each time I show the CTreePanel from the “Show Panel” menu, the CTreePanel constructor is called but when I hide the panel its destructor is not called.
I can show and hide the panel several times but the CTreePanel destructor is never called, neither on Rhino closure.

Did I miss something?
It seems to me there are memory leaks, but probably I didn’t understand something.
Can you clarify this to me, please?

Best regards,
Alberto

Hi @margari,

Showing and hiding a panel just shows and hides - it does not create and destroy.

– Dale

Thanks for your prompt reply @Dale,

in the example you sent me, each time I show the panel, its constructor is called. I simply add dummy code inside it and put there a breakpoint and a static counter.

Is it not the same on your pc?