newly added example of addon menus for TCanvas

This commit is contained in:
nemu 2008-10-06 09:05:39 +00:00
parent 0956bd24f0
commit 1413fb152c
6 changed files with 418 additions and 0 deletions

View File

@ -0,0 +1,105 @@
#---------------------------------------------------
# Makefile
#
# Author: Andreas Suter
# e-mail: andreas.suter@psi.ch
#
# $Id$
#
#---------------------------------------------------
#---------------------------------------------------
# get compilation and library flags from root-config
ROOTCFLAGS = $(shell $(ROOTSYS)/bin/root-config --cflags)
ROOTLIBS = $(shell $(ROOTSYS)/bin/root-config --libs)
ROOTGLIBS = $(shell $(ROOTSYS)/bin/root-config --glibs)
#---------------------------------------------------
# depending on the architecture, choose the compiler,
# linker, and the flags to use
#
OSTYPE = $(shell uname)
ifeq ($(OSTYPE),Linux)
OS = LINUX
endif
ifeq ($(OSTYPE),Linux-gnu)
OS = LINUX
endif
ifeq ($(OSTYPE),darwin)
OS = DARWIN
endif
# -- Linux
ifeq ($(OS),LINUX)
CXX = g++
CXXFLAGS = -g -Wall -Wno-trigraphs -fPIC
INCLUDES = -I./
LD = g++
LDFLAGS = -g
SOFLAGS = -O -shared
endif
# -- Darwin
ifeq ($(OS),DARWIN)
CXX = g++
CXXFLAGS = -g -Wall -Wno-trigraphs -fPIC
INCLUDES = -I../include
LD = g++
LDFLAGS = -g
SOFLAGS = -dynamic
endif
# the output from the root-config script:
CXXFLAGS += $(ROOTCFLAGS)
LDFLAGS +=
# the ROOT libraries (G = graphic)
LIBS = $(ROOTLIBS) -lXMLParser
GLIBS = $(ROOTGLIBS) -lXMLParser
# PSI libs
PSILIBS = -lTLemRunHeader
# Minuit2 lib
MNLIB = -L$(ROOTSYS)/lib -lMinuit2
# GSL lib
GSLLIB = -lgslcblas -lgsl
# FFTW lib
FFTW3LIB = -lfftw3
EXEC = canvasMenu
# some definitions: headers (used to generate *Dict* stuff), sources, objects,...
OBJS =
OBJS += $(EXEC).o
OBJS += PMyCanvas.o PMyCanvasDict.o
SHLIB = libPMusr.so
# make the executable:
#
all: $(EXEC)
$(EXEC): $(OBJS)
@echo "---> Building $(EXEC) ..."
/bin/rm -f $(SHLIB)
$(LD) $(OBJS) -o $(EXEC) $(GLIBS)
@echo "done"
# clean up: remove all object file (and core files)
# semicolon needed to tell make there is no source
# for this target!
#
clean:; @rm -f $(OBJS) *Dict* core*
@echo "---> removing $(OBJS)"
#
$(OBJS): %.o: %.cpp
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $<
PMyCanvasDict.cpp: ./PMyCanvas.h ./PMyCanvasLinkDef.h
@echo "Generating dictionary $@..."
rootcint -v -f $@ -c -p $^

View File

@ -0,0 +1,102 @@
/***************************************************************************
PMyCanvas.cpp
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2007 by Andreas Suter *
* andreas.suter@psi.ch *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <iostream>
using namespace std;
#include "PMyCanvas.h"
#define P_ID_FOURIER 1
#define P_ID_DIFFERENCE 2
#define P_ID_SAVE_DATA 3
ClassImpQ(PMyCanvas)
PMyCanvas::PMyCanvas()
{
fValid = true;
fMainCanvas = 0;
fImp = 0;
fBar = 0;
fPopup = 0;
TCanvas *fMainCanvas = new TCanvas("fMainCanvas", "my canvas ..");
cout << endl << ">> fMainCanvas=" << fMainCanvas << endl;
TRootCanvas *fImp = (TRootCanvas*)fMainCanvas->GetCanvasImp();
cout << endl << ">> fImp=" << fImp << endl;
TGMenuBar *fBar = fImp->GetMenuBar();
cout << endl << ">> fBar=" << fBar << endl;
TGPopupMenu *fPopup = fBar->AddPopup("m&y menu");
cout << endl << ">> fPopup=" << fPopup << endl;
fPopup->AddEntry("F&ourier", 1);
fPopup->AddEntry("&Difference", 2);
fPopup->AddSeparator();
fPopup->AddEntry("Save Data", 3);
fBar->MapSubwindows();
fBar->Layout();
fPopup->Connect("TGPopupMenu", "Activated(Int_t)", "PMyCanvas", this, "HandlePopup(Int_t)");
}
PMyCanvas::~PMyCanvas()
{
if (fMainCanvas) {
delete fMainCanvas;
fMainCanvas = 0;
}
}
//---------------------------------------------------------------------------------------
// HandlePopup (SLOT)
//---------------------------------------------------------------------------------------
/**
* <p>
*/
void PMyCanvas::HandlePopup(Int_t id)
{
switch (id) {
case P_ID_FOURIER:
cout << endl << ">> id=" << id << ", you actived the \"Fourier\" menu item." << endl;
break;
case P_ID_DIFFERENCE:
cout << endl << ">> id=" << id << ", you actived the \"Difference\" menu item." << endl;
break;
case P_ID_SAVE_DATA:
cout << endl << ">> id=" << id << ", you actived the \"Save Data\" menu item." << endl;
break;
default:
cout << endl << ">> id=" << id << ", you never should have reached this point :-( " << endl << endl;
break;
}
}

View File

@ -0,0 +1,63 @@
/***************************************************************************
PMyCanvas.h
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2007 by Andreas Suter *
* andreas.suter@psi.ch *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef _PMYCANVAS_H_
#define _PMYCANVAS_H_
#include "TObject.h"
#include "TQObject.h"
#include "TCanvas.h"
#include "TRootCanvas.h"
#include "TGMenu.h"
class PMyCanvas : public TObject, public TQObject
{
public:
PMyCanvas();
virtual ~PMyCanvas();
bool IsValid() { return fValid; }
void HandlePopup(Int_t id); // SLOT
private:
bool fValid;
TCanvas *fMainCanvas;
TRootCanvas *fImp;
TGMenuBar *fBar;
TGPopupMenu *fPopup;
ClassDef(PMyCanvas, 1)
};
#endif // _PMYCANVAS_H_

View File

@ -0,0 +1,41 @@
/***************************************************************************
PMyCanvasLinkDef.h
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2007 by Andreas Suter *
* andreas.suter@psi.ch *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class PMyCanvas+;
#endif

View File

@ -0,0 +1,44 @@
/***************************************************************************
canvasMenu.C
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2007 by Andreas Suter *
* andreas.suter@psi.ch *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
{
TCanvas *c1 = new TCanvas("c1", "my canvas ..");
TRootCanvas *imp = (TRootCanvas*)c1->GetCanvasImp();
TGMenuBar *bar = imp->GetMenuBar();
TGPopupMenu *popup = bar->AddPopup("m&y popup");
popup->AddEntry("F&ourier", 1);
popup->AddEntry("&Difference", 2);
popup->AddSeparator();
popup->AddEntry("Save Data", 3);
bar->MapSubwindows();
bar->Layout();
}

View File

@ -0,0 +1,63 @@
/***************************************************************************
canvasMenu.cpp
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2007 by Andreas Suter *
* andreas.suter@psi.ch *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <iostream>
using namespace std;
#include <TApplication.h>
#include <TROOT.h>
#include "PMyCanvas.h"
int main(int argc, char* argv[])
{
// generate Root application needed for PMyCanvas
TApplication app("App", &argc, argv);
PMyCanvas *myCanvas = 0;
myCanvas = new PMyCanvas();
if (!myCanvas->IsValid()) {
cout << endl << "**ERROR** Couldn't invoke the canvas object ..." << endl;
return 0;
}
app.Run(true);
// clean up
if (myCanvas) {
cout << endl << "cleaning up ..." << endl;
delete myCanvas;
myCanvas = 0;
}
return 0;
}