How a TRootEmbeddeCanvas should adopt an existent canvas?

Hello,
I’m developing an application that use TGMainFrame and TRootEmbeddedCanvas. I would like to use only one TRootEmbeddedCanvas that show all the TCanvases that I need.
In addition, I would like to store all the canvases that are created into a root file.
I have added a simple script that do this. Use to button Add to add canvases and the combo box to show a canvas that is stored into the root file.
The AddCanvas() method add a new canvas. If a current canvas is present, store the current canvas into the file and create a new canvas (line 91-93).
When an entry into the combo box is selected, (DoSelection() slot), write the current canvas into a file and load, from file, a canvas already stored. The problem is in the lines 69-70, because I’m not able to associate the canvas loaded from file with the TRootEmbeddedCanvas object. How is possible to do this?
An additional question. Why if a run the script two times in the same root session I get an error about TQObject::CheckConnectArgs?

Thank you very much for the help.

Best regards
Andrea Bulgarelli
multicanvas_file.c (4.85 KB)

Hi Andrea,

How to embed a canvas in an TRootEmbedded canvas is written in the ROOT reference guide available on web. Here is the the text :

To embed a canvas derived from a TCanvas do the following:

TRootEmbeddedCanvas *embedded = new TRootEmbeddedCanvas(0, p, w, h);
      [note name must be 0, not null string ""]
 Int_t wid = embedded->GetCanvasWindowId();
 TMyCanvas *myc = new TMyCanvas("myname", 10, 10, wid);
 embedded->AdoptCanvas(myc);

Did you try it? I am going to see how the macro you have attached works.

Best regards, Ilka

Yes, I have seen the code but maybe I have not understand how it work, because my problem is to get a canvas from a root file and show it into the TRootEmbeddedCanvas of my application.
For example, in the example that I have sent I load a canvas from a root file with the following line of code:

TCanvas* fCurrentCanvas = file->Get(padname);

and after this I try to associate the fCurrentCanvas with the TRootEmbeddedCanvas (fEcan):

fEcan->AdoptCanvas(fCurrentCanvas);

but this don’t work.
The question is: how is possible to get a canvas from a file and associate the wid of the TRootEmbeddedCanvas to this canvas?

Thank you very much
Best regards
Andrea Bulgarelli

Hi Andrea,

The current CVS version allow to do it now.
This code works :

[code] TCanvas* oldCanvas = fEmbeddedCanvas->GetCanvas();
if (oldCanvas) {
delete oldCanvas;
}
//Get a canvas from the file -----------------------
fCurrentCanvas = (TCanvas *)file->Get(CanvasName);
if(fCurrentCanvas == 0) return;
fEmbeddedCanvas->AdoptCanvas(fCurrentCanvas);

fCurrentCanvas->Draw();
fCurrentCanvas->Modified();
fCurrentCanvas->Update();
[/code]
Cheers,
Bertrand.

Thank you. It work.

Best regards
Andrea Bulgarelli