TPad as a container for graphical objects

Hello,

I write an monitoring software and I’d like to employ the following feature. I’d like to store several graphical objects (like TGraph, TText, …) in a TPad without drawing them immediately. The TPad would be visualized when user asks for that. An illustration code

[code]// create some stuff
TGraph *g = new TGraph(…)
TText *t = new TText(…)

/// store the objects into a TPad
TPad *container = new TPad();
container->GetListOfPrimitives()->Add(g, “AL”);
container->GetListOfPrimitives()->Add(t, “”);

/// some code in between

/// user asks to plot the TPad container
container->Draw();
[/code]

The problem is that no TPad constructor is convenient for this. The TPad() doesn’t initialize list of primitives. The TPad(name, title, …) does so, but requires gPad to point to an existing TCanvas object.

Could someone give me any hit? Thanks very much,

Kašpi.

Instead of calling the TPad default constructor, create a normal pad as shown below

Rene

[code]// create some stuff
TGraph *g = new TGraph(…)
TText *t = new TText(…)

/// store the objects into a TPad
TPad *container = new TPad(“pad”,“title”,0,0,1,1);
container->GetListOfPrimitives()->Add(g, “AL”);
container->GetListOfPrimitives()->Add(t, “”);

/// some code in between

/// user asks to plot the TPad container
container->Draw();
[/code]

Thanks for help. Unfortunatelly, it doesn’t work. The TPad constructor you suggested requires a TCanvas to be created before. Hence, I’m left with message:

Error in <TPad::TPad>: You must create a TCanvas before creating a TPad

The problem can be obtained by the following code:

[code]#include “TGraph.h”
#include “TPad.h”
#include “TList.h”

int option()
{
double X[2] = {0., 1.};
double Y1[2] = {0., 1.};
double Y2[2] = {1., 0.};

TGraph *g1 = new TGraph(2, X, Y1);	g1->SetTitle("g1;x;y");
TGraph *g2 = new TGraph(2, X, Y2);	g2->SetTitle("g2;z;a");

TPad *container = new TPad("pad","title",0,0,1,1);
container->GetListOfPrimitives()->Add(g1, "AL");
container->GetListOfPrimitives()->Add(g2, "L"); 

return 0;

}
[/code]

What shall I do? Thanks very much,

Kaspi.