Commit 5840e676 authored by Jérémie Dudouet's avatar Jérémie Dudouet
Browse files

Add the possibility to handle root files containing TDirectoryFiles inside

Add the possibility to move in the previous subfolder of a file
parent 1356101c
......@@ -18,6 +18,7 @@
#include "TGListTree.h"
#include "TClass.h"
#include "TCanvas.h"
#include "TCutG.h"
using namespace std;
......@@ -59,7 +60,7 @@ CXFileList::CXFileList(const TGCompositeFrame *MotherFrame, UInt_t w, UInt_t h)
fMenu->AddEntry("Lar&ge Icons",kLVLargeIcons);
fMenu->AddEntry("S&mall Icons",kLVSmallIcons);
fMenu->AddEntry("&List", kLVList);
// fMenu->AddEntry("&Details", kLVDetails);
// fMenu->AddEntry("&Details", kLVDetails);
fMenu->Connect("Activated(Int_t)","CXFileList",this,"DoMenu(Int_t)");
TGHorizontalFrame *h3 = new TGHorizontalFrame(fv2,10,10);
......@@ -91,7 +92,7 @@ CXFileList::CXFileList(const TGCompositeFrame *MotherFrame, UInt_t w, UInt_t h)
Resize();
DoMenu(kLVSmallIcons);
DoMenu(kLVList);
}
void CXFileList::DoubleClicked(TGListTreeItem *item, Int_t a_int)
......@@ -99,20 +100,15 @@ void CXFileList::DoubleClicked(TGListTreeItem *item, Int_t a_int)
TGListTree *sender = (TGListTree *)gTQSender;
const TGWindow *parent = sender->GetParent()->GetParent()->GetParent();
if(parent == fBrowser)
{
if(parent == fBrowser){
TObject *obj = (TObject *) item->GetUserData();
if(obj)
{
if(obj){
obj->IsA()->SetName("");
TString filename = fBrowser->FullPathName(item);
if(gSystem->IsFileInIncludePath(filename) && filename.EndsWith(".root"))
{
DisplayFile(filename);
}
}
}
}
......@@ -120,7 +116,6 @@ void CXFileList::DoubleClicked(TGListTreeItem *item, Int_t a_int)
CXFileList::~CXFileList()
{
// Cleanup.
delete fContents;
fMain->DeleteWindow(); // deletes fMain
......@@ -130,15 +125,21 @@ CXFileList::~CXFileList()
void CXFileList::DoMenu(Int_t mode)
{
// Switch view mode.
if (mode<10) {
if (mode<10)
fContents->SetViewMode((EListViewMode)mode);
} else {
else
delete this;
}
}
void CXFileList::DisplayFile(const TString &fname)
{
//Close the last opened file
if(fCurrentFile){
fCurrentFile->Close();
fCurrentFile = nullptr;
fFolders.clear();
}
// Display content of ROOT file.
TFile *file = TFile::Open(fname);
fContents->RemoveAll();
......@@ -155,7 +156,7 @@ void CXFileList::DisplayFile(const TString &fname)
TGLVEntry *entry = new TGLVEntry(fContents,name,cname);
entry->SetSubnames(key->GetTitle());
if(cname=="TList")
if(cname=="TList" || cname=="TDirectoryFile")
entry->SetPictures(gClient->GetPicture("folder_s.xpm"),gClient->GetPicture("folder_t.xpm"));
if(cname=="TCutG")
entry->SetPictures(gClient->GetPicture("bld_cut.png"),gClient->GetPicture("bld_cut.png"));
......@@ -168,49 +169,53 @@ void CXFileList::DisplayFile(const TString &fname)
entry->SetUserData((void*)StrDup(fname));
}
fMain->Resize();
fParent = file;
if(fParentFile && file!=fParentFile){
fParentFile->Close();
}
fParentFile = file;
fCurrentFile = file;
fFolders.push_back(file);
}
void CXFileList::DisplayList(TList *list)
{
// Display content of ROOT file.
TString Name = fParentFile->GetName();
TString Name = fCurrentFile->GetName();
TObjArray *arr = Name.Tokenize("/");
Name = arr->Last()->GetName();
delete arr;
TGLVEntry *entry = new TGLVEntry(fContents,Name,fParentFile->ClassName());
entry->SetUserData((void*)StrDup(fParentFile->GetName()));
fContents->RemoveAll();
// fContents->AddFile(gSystem->WorkingDirectory());
fContents->AddItem(entry);
fContents->SetPagePosition(0,0);
// fContents->SetColHeaders("Name","Title");
// fContents->SetColHeaders("Name","Title");
TObject *Folder = fFolders.back();
TGLVEntry *entry = nullptr;
if(fFolders.size()>1){
entry = new TGLVEntry(fContents,"..",Folder->ClassName());
entry->SetUserData((void*)StrDup(Folder->GetName()));
entry->SetPictures(gClient->GetPicture("folder_s.xpm"),gClient->GetPicture("folder_t.xpm"));
fContents->AddItem(entry);
}
TIter next(list);
TObject *key;
while ((key=(TObject*)next())) {
if(Folder->InheritsFrom(TDirectoryFile::Class_Name())){
key = ((TDirectoryFile*)Folder)->Get(key->GetName());
}
TString cname = key->ClassName();
TString name = key->GetName();
TGLVEntry *entry = new TGLVEntry(fContents,name,cname);
entry->SetSubnames(key->GetTitle());
fContents->AddItem(entry);
if(cname=="TList")
if(cname==TList::Class_Name() || cname==TDirectoryFile::Class_Name())
entry->SetPictures(gClient->GetPicture("folder_s.xpm"),gClient->GetPicture("folder_t.xpm"));
if(cname=="TCutG")
if(cname==TCutG::Class_Name())
entry->SetPictures(gClient->GetPicture("bld_cut.png"),gClient->GetPicture("bld_cut.png"));
if(cname.BeginsWith("TGraph"))
if(cname.BeginsWith(TGraph::Class_Name()))
entry->SetPictures(gClient->GetPicture("graph.xpm"),gClient->GetPicture("graph.xpm"));
// user data is a filename
......@@ -219,44 +224,34 @@ void CXFileList::DisplayList(TList *list)
fMain->Resize();
}
void CXFileList::DisplayDirectory(const TString &fname)
{
// Display content of directory.
fContents->SetDefaultHeaders();
gSystem->ChangeDirectory(fname);
fContents->ChangeDirectory(fname);
fContents->DisplayDirectory();
fContents->AddFile(".."); // up level directory
fContents->Sort(EFSSortMode::kSortByName);
fMain->Resize();
}
void CXFileList::DisplayObject(const TString& fname,const TString& name)
{
// Browse object located in file.
TDirectory *sav = gDirectory;
TObject* obj = nullptr;
TObject *CurrentFolder = fFolders.back();
if(fParent->InheritsFrom("TFile"))
obj = fParentFile->Get(name);
else if(fParent->InheritsFrom("TList"))
obj = fParent->FindObject(name);
if(name==".."){
fFolders.pop_back();
obj=fFolders.back();
fFolders.pop_back();
}
else if(CurrentFolder->InheritsFrom(TList::Class_Name()))
obj = ((TList*)CurrentFolder)->FindObject(name);
else if(CurrentFolder->InheritsFrom(TDirectoryFile::Class_Name()))
obj = ((TDirectoryFile*)CurrentFolder)->Get(name);
if(obj == nullptr){
DisplayFile(fParentFile->GetName());
DisplayFile(fCurrentFile->GetName());
return;
}
if (obj)
{
if (!obj->IsFolder())
{
if (!obj->IsFolder()){
TString CanvasName = fMainWindow->GetCanvas()->GetName();
if(CanvasName.BeginsWith("GxG"))
{
if(CanvasName.BeginsWith("GxG")){
cout<<" cannot plot in a Tab dedicated to Gamma Gamma projections" << endl;
return;
}
......@@ -268,12 +263,10 @@ void CXFileList::DisplayObject(const TString& fname,const TString& name)
if(gPad && (obj->InheritsFrom("TH1")
|| obj->InheritsFrom("TGraph")
|| obj->InheritsFrom("TF1")))
{
|| obj->InheritsFrom("TF1"))){
obj->Draw(fBrowser->GetDrawOption());
if(obj->InheritsFrom("TH1"))
{
if(obj->InheritsFrom("TH1")){
TH1 *hist = (TH1*)obj;
hist->SetDirectory(nullptr);
}
......@@ -281,8 +274,7 @@ void CXFileList::DisplayObject(const TString& fname,const TString& name)
gPad->Update();
gPad->GetFrame()->SetBit(TObject::kCannotPick);
}
else if(gPad && obj->InheritsFrom("TCanvas"))
{
else if(gPad && obj->InheritsFrom("TCanvas")){
TCanvas *canvas_in = (TCanvas*)obj;
CXCanvas *canvas_out = fMainWindow->GetCanvas();
canvas_out->cd();
......@@ -290,30 +282,27 @@ void CXFileList::DisplayObject(const TString& fname,const TString& name)
Int_t idraw = 0;
for(int i=0 ; i<canvas_in->GetListOfPrimitives()->GetEntries() ; i++)
{
for(int i=0 ; i<canvas_in->GetListOfPrimitives()->GetEntries() ; i++){
TObject *o = canvas_in->GetListOfPrimitives()->At(i);
if(idraw==0)
{
if(idraw==0){
idraw++;
if(o->InheritsFrom("TH2"))
if(o->InheritsFrom(TH2::Class_Name()))
o->Draw("col");
else if(o->InheritsFrom("TH1"))
else if(o->InheritsFrom(TH1::Class_Name()))
o->Draw("hist");
else if(o->InheritsFrom("TGraph"))
else if(o->InheritsFrom(TGraph::Class_Name()))
o->Draw("APL");
else
idraw--;
}
else
{
if(o->InheritsFrom("TH2"))
else{
if(o->InheritsFrom(TH2::Class_Name()))
o->Draw("col same");
else if(o->InheritsFrom("TH1"))
else if(o->InheritsFrom(TH1::Class_Name()))
o->Draw("hist same");
else if(o->InheritsFrom("TGraph"))
else if(o->InheritsFrom(TGraph::Class_Name()))
o->Draw("PL");
}
}
......@@ -323,14 +312,14 @@ void CXFileList::DisplayObject(const TString& fname,const TString& name)
fMainWindow->RefreshPad();
}
else
{
cout<<"No possibility to drawn "<<obj->ClassName()<<" objects"<<endl;
}
}
else if(obj->InheritsFrom("TList"))
{
fParent = obj;
DisplayList(((TList*)obj));
else if(obj->InheritsFrom(TList::Class_Name()) || obj->InheritsFrom(TDirectoryFile::Class_Name())){
fFolders.push_back(obj);
if(obj->InheritsFrom(TList::Class_Name()))
DisplayList((TList*)obj);
if(obj->InheritsFrom(TDirectoryFile::Class_Name()))
DisplayList(((TDirectoryFile*)obj)->GetListOfKeys());
}
}
......@@ -341,14 +330,16 @@ void CXFileList::OnClick(TGLVEntry *f, Int_t btn, Int_t x, Int_t y)
{
if (btn == kButton3)
{
TObject *CurrentFolder = fFolders.back();
TString name(f->GetTitle());
TObject* obj = nullptr;
if(fParent->InheritsFrom("TFile"))
obj = fParentFile->Get(name);
else if(fParent->InheritsFrom("TList"))
obj = fParent->FindObject(name);
if(CurrentFolder->InheritsFrom(TDirectoryFile::Class_Name()))
obj = ((TDirectoryFile*)CurrentFolder)->Get(name);
else if(CurrentFolder->InheritsFrom(TList::Class_Name()))
obj = CurrentFolder->FindObject(name);
if(obj == nullptr)
return;
......@@ -370,13 +361,8 @@ void CXFileList::OnDoubleClick(TGLVEntry *f, Int_t btn)
TString name(f->GetTitle());
const char* fname = (const char*)f->GetUserData();
if (fname) {
DisplayObject(fname, name);
} else if (name.EndsWith(".root")) {
DisplayFile(name);
} else {
DisplayDirectory(name);
}
DisplayObject(fname, name);
// set kPointer cursor
cur = gVirtualX->CreateCursor(kPointer);
gVirtualX->SetCursor(fContents->GetId(), cur);
......
......@@ -14,6 +14,7 @@ class TList;
class TFile;
class TGListTreeItem;
class CXGFileBrowser;
class TDirectoryFile;
class CXFileList : public TGVerticalFrame
{
......@@ -33,8 +34,11 @@ protected:
TGPopupMenu *fMenu;
TGTextEntry *fDrawOption;
std::vector<TObject*> fFolders;
TObject *fCurrent = nullptr;
TObject *fParent = nullptr;
TFile *fParentFile = nullptr;
TFile *fCurrentFile = nullptr;
CXGFileBrowser *fBrowser = nullptr;
......@@ -57,7 +61,6 @@ public:
private:
void DisplayFile(const TString &fname);
void DisplayDirectory(const TString &fname);
void DisplayObject(const TString& fname,const TString& name);
void DisplayList(TList *list);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment