Hi, fix now in cvs. Thanks. Cheers, Fons. On Sat, 2003-08-16 at 14:20, Hamlet wrote: > I apologize if it was a known issue: > > MakeDefCanvas() creates a new canvas adding a "_n#" string to the name > of canvas if basename alone (some gROOT->GetDefCanvasName() or so) is > already used by a canvas. That number is the number of current canvases > in gROOT plus one. > Now, if I create three canvases (say, from "New canvas" menu item in a > TBrowser window), c1, c1_n1, c1_n2 and c1_n3, and then I close c1_n1 > and c1_n2, when I create another default canvas, it will be named c1_n3 > (since 2 canvases are left), and will overwrite old c1_n3. > > Run time workarounds can be to change default name of canvases or to > create new canvases from CINT command line (not via MakeDefCanvas()). > > A possible code solution, if you like it, could be something like (sorry > for word wrap): > > > void TCanvas::MakeDefCanvas() > { > //*-*-*-*-*-*-*Static function to build a default > // canvas*-*-*-*-*-*-*-*-*-*-* > //*-* ========================================= > > const char *defcanvas = gROOT->GetDefCanvasName(); > char *cdef; > > TList *lc = (TList*)gROOT->GetListOfCanvases(); > if (lc->FindObject(defcanvas)) { > // CVS 3.05/07 code: > // cdef = StrDup(Form("%s_n%d",defcanvas,lc->GetSize()+1)); > int n = lc->GetSize() + 1; > cdef = new char[strlen(defcanvas)+15]; > do { > strcpy(cdef, Form("%s_n%d", defcanvas, n++)); > } while(lc->FindObject(cdef)); > } > else > cdef = StrDup(Form("%s",defcanvas)); > > // if (gInterpreter) > // gROOT->ProcessLine(Form("TCanvas *%s = > // new TCanvas("%s","%s",1);",cdef,cdef,cdef)); > // else > new TCanvas(cdef, cdef, 1); > > Printf("<TCanvas::MakeDefCanvas>: created default TCanvas with name \ > %s",cdef); > delete [] cdef; > } -- Org: CERN, European Laboratory for Particle Physics. Mail: 1211 Geneve 23, Switzerland E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248 WWW: http://root.cern.ch/~rdm/ Fax: +41 22 7679480
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:14 MET