TCanvas allways with default size?

Hi,

I am trying to set the canvas size when creating the canvas. But when opened via TBrowser the Canvas has allways assigned the defualt 800*600 size.

I am running compiled program, not a macro. My testing code looks as follows:


#include <TCanvas.h>
#include <TFile.h>

#include
#include
#include

int main(){
TCanvas* c1 = new TCanvas(“c1”, “test size”, 10, 10, 50, 400);
c1->SetWindowSize(100, 100);
c1->Divide(3, 2);

TFile* out = new TFile("test.root", "RECREATE");
out->cd();
c1->Write();
out->Save();
out->Close();

if(c1) delete c1;
if(out) delete out;

return 0;

}


The code is compiled and executed of course.

But if I open the output file and run the TBrowser and then “dump” the canvas before drawing it - I will get following nubers:



fWindowTopX 0 Top X position of window (in pixels)
fWindowTopY 0 Top Y position of window (in pixels)
fWindowWidth 0 Width of window (including borders, etc.)
fWindowHeight 0 Height of window (including menubar, borders, etc.)
fCw 46 Width of the canvas along X (pixels)
fCh 372 Height of the canvas along Y (pixels)


  • so the size (fCw and fCh) seems OK, but the “fWindowWidth” and “fWindowHeight” are equall to 0. When plotting the canvas the root that will use the defaul 800*600 size because of these two zeros.

If I dump the canvas after drawing I get:



fWindowTopX 4 Top X position of window (in pixels)
fWindowTopY 27 Top Y position of window (in pixels)
fWindowWidth 800 Width of window (including borders, etc.)
fWindowHeight 600 Height of window (including menubar, borders, etc.)
fCw 796 Width of the canvas along X (pixels)
fCh 571 Height of the canvas along Y (pixels)


  • the canvas was assigned the default values.

**

Apart from this problen the function “SetCanvasSize” called wai right click on the canvas has also no effect.

Am I doing something wrong or … ?

thanks

Matus

Hi Matus,

I cannot reproduce the reported case with svn trunk (CVS head). The saved canvas appears with the correct size after I compile and execute your example, and draw the canvas using the TBrowser. Below is the related info printed after the Dump method was called:fWindowTopX 16 Top X position of window (in pixels) fWindowTopY 30 Top Y position of window (in pixels) fWindowWidth 100 Width of window (including borders,etc.) fWindowHeight 100 Height of window (including menubar,borders,etc.) fCw 96 Width of the canvas along X (pixels) fCh 72 Height of the canvas along Y (pixels) fEvent 53 !Type of current or last handled event Please tell us which is your ROOT version.

I have tried the method SetCanvasSize from the context menu, and I see the canvas resized to the width and height I have specified (saying this I would like to add, the window containing the menu is not resized, only the canvas inside).

Thank you, Ilka

Excuse me - I forgot the ROOT version - it is 516-00.

Do you use the “SetCanvasSize” on the already drawn canvas or you first use the function and then you draw the canvas (doubleclick or from the menu)?

When I first draw the canvas (it will be the default 800*600 as mentioned before) and only then via maus use the “SetCanvasSizse” - the canvas will indeed cahnge its size (the whole window will not as in your case).

In the following exaple I apllied via “SetCanvasSize” size of 100100.
I got tiny 100
100 canvas in rather large 800*600 window.
Dumping the object afterwards produced following outpout:

fWindowTopX 4 Top X position of window (in pixels) fWindowTopY 27 Top Y position of window (in pixels) fWindowWidth 800 Width of window (including borders, etc.) fWindowHeight 600 Height of window (including menubar, borders, etc.) fCw 100 Width of the canvas along X (pixels) fCh 100 Height of the canvas along Y (pixels)

If I would have applied the “SetCanvasSize” before drawing the object - nothing would change. Dumping the object would then bring:

fWindowTopX 4 Top X position of window (in pixels) fWindowTopY 27 Top Y position of window (in pixels) fWindowWidth 800 Width of window (including borders, etc.) fWindowHeight 600 Height of window (including menubar, borders, etc.) fCw 796 Width of the canvas along X (pixels) fCh 571 Height of the canvas along Y (pixels)

You can set rthe default canvas size via gStyle, eg

gStyle->SetCanvasDefH(400); gStyle->SetCanvasDefW(700);
Rene

Hi Matus,

I hope you pay attention that TCanvas has two different methods: SetCanvasSize and SetWindowSize. The first one defines the canvas size, the second one defines the size of the application window and includes the menu, the borders, etc.

Cheers, Ilka

[quote=“brun”]You can set rthe default canvas size via gStyle, eg

gStyle->SetCanvasDefH(400); gStyle->SetCanvasDefW(700);
Rene[/quote]

Thanks. Well let’s see what it does. Of course - in my code I want to produce several canvases with different sizes so I changed my testing code a bit to produce 3 canvases with possibly 3 different sizes. Of ourse - I have to change the default canvas size settings 3 times now.

So ma code looks as follows:

[code]int main(){
// 1)
gStyle->SetCanvasDefH(100);
gStyle->SetCanvasDefH(400);
TCanvas* c1 = new TCanvas(“c1”, “test size”);
c1->Divide(3, 2);
// 2)
gStyle->SetCanvasDefH(200);
gStyle->SetCanvasDefH(200);
TCanvas* c2 = new TCanvas(“c2”, “test size 2”);
c2->Divide(3, 2);
// 3)
gStyle->SetCanvasDefH(400);
gStyle->SetCanvasDefH(100);
TCanvas* c3 = new TCanvas(“c3”, “test size 3”);
c3->Divide(3, 2);

TFile* out = new TFile("test.root", "RECREATE");
out->cd();
c1->Write();
c2->Write();
c3->Write();
out->Save();
out->Close();

if(c1) delete c1;
if(out) delete out;

return 0;

}[/code]

unfortunately - all 3 look the same - 800*600 event though the “dump” info differs a bit:

1 )

fWindowTopX 0 Top X position of window (in pixels) fWindowTopY 0 Top Y position of window (in pixels) fWindowWidth 0 Width of window (including borders, etc.) fWindowHeight 0 Height of window (including menubar, borders, etc.) fCw 692 Width of the canvas along X (pixels) fCh 344 Height of the canvas along Y (pixels)

fWindowTopX 0 Top X position of window (in pixels) fWindowTopY 0 Top Y position of window (in pixels) fWindowWidth 0 Width of window (including borders, etc.) fWindowHeight 0 Height of window (including menubar, borders, etc.) fCw 692 Width of the canvas along X (pixels) fCh 144 Height of the canvas along Y (pixels)

fWindowTopX 0 Top X position of window (in pixels) fWindowTopY 0 Top Y position of window (in pixels) fWindowWidth 0 Width of window (including borders, etc.) fWindowHeight 0 Height of window (including menubar, borders, etc.) fCw 692 Width of the canvas along X (pixels) fCh 44 Height of the canvas along Y (pixels)

Am I doing something wrong here ?

[quote=“antcheva”]Hi Matus,

I hope you pay attention that TCanvas has two different methods: SetCanvasSize and SetWindowSize. The first one defines the canvas size, the second one defines the size of the application window and includes the menu, the borders, etc.

Cheers, Ilka[/quote]

Indeed. The important message here are that the values of “fWindowWidth” and “fWindowHeight” are allways equal to 0, so during the drawing procedure the default 800*600 size will be used.

And apart from that, when one defines a new canvas in a following way:

, the sizes set concern the canvas size not the window size - and I assume that the window size is adjusted accordingly.

And anyhow - after trying to use “SetWindowSize” nothing changed either.

Hi Matus,

Please attach the macro you are running, which will help to get fWindowWidth=0 and fWindowHeight=0. Using your very first example (compiling and running it) I got what was expected (and SetWindowSize sets the given values as it should). According to the TCanvas code if they are 0, they are set to values you have reported.

In addition, could you please say what is your environment (platform).

Thank you, Ilka

[quote=“antcheva”]Hi Matus,

Please attach the macro you are running, which will help to get fWindowWidth=0 and fWindowHeight=0. Using your very first example (compiling and running it) I got what was expected (and SetWindowSize sets the given values as it should). According to the TCanvas code if they are 0, they are set to values you have reported.

In addition, could you please say what is your environment (platform).

Thank you, Ilka[/quote]
I was able to reproduce this behavior with the following code:

[code]#include <TCanvas.h>
#include <TFile.h>

int main()
{
TCanvas* c1 = new TCanvas(“c1”, “test size”, 10, 10, 50, 400);
c1->Divide(3, 2);

TFile* out = new TFile(“test.root”, “RECREATE”);
out->cd();
c1->Write();
out->Save();
out->Close();

return 0;
}[/code]

I used ROOT v.5.17.01 (Fedora Core6, gcc version 4.1.2 20070626 (Red Hat 4.1.2-13)).

After compiling the example above I have executed the executable :slight_smile: and in the root’s TBrowser I tried to check newly produced ROOT file and I see the following (before drawing the Canvas):

fWindowTopX 0 Top X position of window (in pixels) fWindowTopY 0 Top Y position of window (in pixels) fWindowWidth 0 Width of window (including borders, etc.) fWindowHeight 0 Height of window (including menubar, borders, etc.) fCw 46 Width of the canvas along X (pixels) fCh 372 Height of the canvas along Y (pixels)
Which is wrong, because fWindowWidth = fWindowHeight = 0, which leads to a change of the Canvas size in the Draw method to default values. I wouldn’t consider this a proper behavior.

I believe, that the Window size should (“must” - since I request it) be just enough to keep Children (canvas, menubar…) but not a 0x0 or any default 800x600 or something.

Hi,

I agree with you. The strange thing is using the same code I see no zero values for both data members (my environment is SLC3, gcc version 3.2.3, tested with several ROOT versions starting from 5.15/06). I am attaching the created root file.

Cheers, Ilka
test.root (11.1 KB)

[quote=“antcheva”]Hi,

I agree with you. The strange thing is using the same code I see no zero values for both data members (my environment is SLC3, gcc version 3.2.3, tested with several ROOT versions starting from 5.15/06). I am attaching the created root file.

Cheers, Ilka[/quote]
hm
Indeed, your files shows correct values.
Find attached my file.
test.root (11 KB)

Hi,

The only way to understand what happens is to test it on Fedora - one of my colleagues has ROOT installed on Fedora and will run your example. We will keep you informed.

Cheers, Ilka

Some more testing will probably be needed.
I am running the code mentioned under Debian 3.1 (Sarge), compiller gcc335 with
exactely same results as Anar - with following ROOT versions:

[code] - 517-02

  • 516-00 (my default)
  • 515-06
  • 514-00
  • 510-00
    [/code]

Hi,

I don’t see the problem with:

  • Fedora 7 (amd64)
  • gcc version 4.1.2 20070502 (Red Hat 4.1.2-12)
  • ROOT svn trunk (HEAD).
    Using this example code:[code]#include <TCanvas.h>
    #include <TFile.h>

int main()
{
TCanvas* c1 = new TCanvas(“c1”, “test size”, 10, 10, 50, 400);
c1->Divide(3, 2);

TFile* out = new TFile(“test.root”, “RECREATE”);
out->cd();
c1->Write();
out->Save();
out->Close();

return 0;
}[/code]
I obtain this result:

fWindowTopX                   8                   Top X position of window (in pixels)
fWindowTopY                   45                  Top Y position of window (in pixels)
fWindowWidth                  44                  Width of window (including borders, etc.)
fWindowHeight                 352                 Height of window (including menubar, borders, etc.)
fCw                           40                  Width of the canvas along X (pixels)
fCh                           324                 Height of the canvas along Y (pixels)

It seems correct… or did I miss something?

Cheers,
Bertrand.

Hi all,

I tried the posted code on

[quote] OS: Debian GNU/Linux “sid” (unstable)
Kernel: 2.6.22
CPU: Intel® Core™2 CPU T7400 (i386)
GCC: 4.2.3
ROOT: 5.16/00[/quote]

and

[quote] OS: Scientific Linux CERN 3
Kernel: 2.4.21
CPU: Intel® Pentium® 4 CPU (i386)
GCC: 3.2.3
ROOT: 5.13/05 [/quote]

and go the same results as posted in the thread (fWindowWidth=fWindowHeight=0).

Now, notice, that TCanvas uses a TCanvasImp to do the actual drawing.
[ul]Also notice, that in TCanvas::Streamer, the member function TCanvasImp::GetWindowSize is called to get the size of the window via the TVirtualX object.[/ul]
[ul]If the implementation object u[/u] points to a TRootCanvas object, then the member function TVirtualX::GetWindowSize is called. [/ul]
[ul]If the fVirtualX pointer points to a TGX11 object, then X function XGetWindowGeometry is called to get the result, which is then propagated back to TCanvas::Streamer. [/ul]
[ul]If fCanvasImp points to a plain TCanvasImp object, then TCanvasImp::GetWindowSize will not modify it’s four arguments, and the window dimensions will be 0. [/ul]

With this in mind, I tried to play around a little with the example code. I wanted to know exactly which kind of object fCanvasImp points to.

#include <TCanvas.h>
#include <TFile.h>
#include <iostream>
#include <TApplication.h>

int main(int argc, char** argv)
{
#ifdef USE_APP
  TApplication app("app", &argc, argv);
#endif
  TCanvas* c1 = new TCanvas("c1", "test size", 10, 10, 50, 400);
  c1->Divide(3, 2);
  TCanvasImp* imp = c1->GetCanvasImp();
  std::cout << "Implementation is " << typeid(*imp).name() << std::endl;

  TFile* out = new TFile("test.root", "RECREATE");
  out->cd();
  c1->Write();
  out->Save();
  out->Close();

  return 0;
}

So if you compile the attached code, and run it, you get

$ g++ `root-config --cflags --libs` test.C -o test
$ ./test
Implementation is 10TCanvasImp

That is, fCanvasImp points to a TCanvasImp object.

Now, try to compile and run the attached code like

$ g++ -DUSE_APP `root-config --cflags --libs` test.C -o test_app
$ ./test_app
Implementation is 11TRootCanvas

The difference is, that we now explicitly make a TApplication object. Now try to run the most recently compiled version of test_app like

$ ./test_app -b
Implementation is 10TCanvasImp

So there’s a difference there if you run your code in batch mode or not.

Needles to say, when compiled with -DUSE_APP (and not passing the -b switch), the correct dimensions are written to the output file.

It’s actually not that surprising. In batch mode, you have no information on the size of the actual window you need, since things like menus, borders, etc. have not been rendered. Of course, TCanvasImp could make an estimate of these dimensions if so needed, but it will never be exactly the same thing as TRootCanvas.

Yours,

Christian
test.C (533 Bytes)