From 1413fb152c81bc5471ea720b7d9fe831d6d34989 Mon Sep 17 00:00:00 2001 From: nemu Date: Mon, 6 Oct 2008 09:05:39 +0000 Subject: [PATCH] newly added example of addon menus for TCanvas --- src/tests/canvasMenu/Makefile | 105 ++++++++++++++++++++++++ src/tests/canvasMenu/PMyCanvas.cpp | 102 +++++++++++++++++++++++ src/tests/canvasMenu/PMyCanvas.h | 63 ++++++++++++++ src/tests/canvasMenu/PMyCanvasLinkDef.h | 41 +++++++++ src/tests/canvasMenu/canvasMenu.C | 44 ++++++++++ src/tests/canvasMenu/canvasMenu.cpp | 63 ++++++++++++++ 6 files changed, 418 insertions(+) create mode 100644 src/tests/canvasMenu/Makefile create mode 100644 src/tests/canvasMenu/PMyCanvas.cpp create mode 100644 src/tests/canvasMenu/PMyCanvas.h create mode 100644 src/tests/canvasMenu/PMyCanvasLinkDef.h create mode 100644 src/tests/canvasMenu/canvasMenu.C create mode 100644 src/tests/canvasMenu/canvasMenu.cpp diff --git a/src/tests/canvasMenu/Makefile b/src/tests/canvasMenu/Makefile new file mode 100644 index 00000000..c36b74bc --- /dev/null +++ b/src/tests/canvasMenu/Makefile @@ -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 $^ diff --git a/src/tests/canvasMenu/PMyCanvas.cpp b/src/tests/canvasMenu/PMyCanvas.cpp new file mode 100644 index 00000000..b6b4dc8d --- /dev/null +++ b/src/tests/canvasMenu/PMyCanvas.cpp @@ -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 +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) +//--------------------------------------------------------------------------------------- +/** + *

+ */ +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; + } +} + diff --git a/src/tests/canvasMenu/PMyCanvas.h b/src/tests/canvasMenu/PMyCanvas.h new file mode 100644 index 00000000..2a26b334 --- /dev/null +++ b/src/tests/canvasMenu/PMyCanvas.h @@ -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_ diff --git a/src/tests/canvasMenu/PMyCanvasLinkDef.h b/src/tests/canvasMenu/PMyCanvasLinkDef.h new file mode 100644 index 00000000..d40a8294 --- /dev/null +++ b/src/tests/canvasMenu/PMyCanvasLinkDef.h @@ -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 + diff --git a/src/tests/canvasMenu/canvasMenu.C b/src/tests/canvasMenu/canvasMenu.C new file mode 100644 index 00000000..a54c1e93 --- /dev/null +++ b/src/tests/canvasMenu/canvasMenu.C @@ -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(); +} \ No newline at end of file diff --git a/src/tests/canvasMenu/canvasMenu.cpp b/src/tests/canvasMenu/canvasMenu.cpp new file mode 100644 index 00000000..7a44c67c --- /dev/null +++ b/src/tests/canvasMenu/canvasMenu.cpp @@ -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 +using namespace std; + +#include +#include + +#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; +}