00001 #include <Midad/Gui/GuiButton.h>
00002 #include <Midad/Gui/GuiTable.h>
00003 #include <Midad/Gui/GuiMainWindow.h>
00004 #include <Midad/Gui/GuiMenu.h>
00005 #include <Midad/Gui/GuiBox.h>
00006 #include <Midad/Gui/GuiTab.h>
00007 #include <Midad/Gui/GuiFrame.h>
00008 #include <Midad/Gui/GuiCanvas.h>
00009 #include <Midad/Gui/GuiStatusBar.h>
00010 #include <Midad/Gui/GuiSlider.h>
00011 #include <Midad/Gui/GuiTextEntry.h>
00012
00013 #include <Midad/Util/CompositeRange.h>
00014
00015 #include <Midad/Base/ColorAxis.h>
00016 #include <Midad/Base/ZoomPad.h>
00017
00018 #include "TROOT.h"
00019 #include "TApplication.h"
00020 #include "TGTableLayout.h"
00021 #include "TCanvas.h"
00022 #include "TH1F.h"
00023
00024 #include <sigc++/sigc++.h>
00025 #include <sigc++/retype_return.h>
00026 using namespace SigC;
00027
00028 #include <string>
00029 #include <sstream>
00030 #include <iostream>
00031 using namespace std;
00032
00033 void set_pad_in_history(ZoomPad* pad, UndoHistory* hist)
00034 {
00035 CompositeRange<double> cr;
00036 cr.push_back(pad->GetCurRange().x);
00037 cr.push_back(pad->GetCurRange().y);
00038 hist->Store(cr);
00039 pad->ApplySelectionToZoom();
00040 }
00041
00042 void print_range(RangeDouble* r)
00043 {
00044 cerr << r->Min() << " < " << r->Max() << endl;
00045 }
00046 void zoom_range(RangeControl<double>* rc, RangeDouble* r)
00047 {
00048 rc->Set(r->Min(), r->Max());
00049 }
00050
00051 void update_canvas(TCanvas* canvas)
00052 {
00053 canvas->Modified();
00054 canvas->Update();
00055 }
00056
00057 int main (int argc, char *argv[])
00058 {
00059 TApplication theApp("App", &argc, argv);
00060
00061 GuiMainWindow mw(300,300);
00062
00063 GuiBox box(mw,kVerticalFrame);
00064 mw.Add(box);
00065
00066 GuiCanvas gc(box);
00067 gc.SetLayoutHints(kLHintsExpandX|kLHintsExpandY);
00068 box.Add(gc);
00069
00070 GuiSlider s1(box,kHorizontalFrame);
00071 box.Add(s1);
00072
00073 GuiBox hbox(box,kHorizontalFrame);
00074 hbox.SetLayoutHints(kLHintsExpandX);
00075 box.Add(hbox);
00076
00077 GuiTextButton b_undo(hbox,"Undo");
00078 b_undo.SetLayoutHints(kLHintsExpandX);
00079 hbox.Add(b_undo);
00080 GuiTextButton b_redo(hbox,"Redo");
00081 b_redo.SetLayoutHints(kLHintsExpandX);
00082 hbox.Add(b_redo);
00083
00084
00085 gc.GetCanvas()->cd();
00086 ZoomPad zp("blah","blah",.2,.2,.8,.8);
00087 zp.Draw();
00088 zp.cd();
00089 RangeDouble* hxr = zp.GetCurRange().x;
00090 hxr->modified.connect(bind(slot(print_range),hxr));
00091 TH1F h1("gaus","gaus",100,-3,3);
00092 h1.FillRandom("gaus");
00093 h1.Draw();
00094
00095
00096 UndoHistory* hist = manage(new UndoHistory);
00097
00098 zp.selection.connect(bind(bind(slot(set_pad_in_history),hist),&zp));
00099
00100 RangeDouble* range = manage(new RangeDouble(2,8));
00101 RangeControl<double> rc(hist,range);
00102 RangeDouble* extrema = manage(new RangeDouble(2,8));
00103 RangeControl<double> ec(hist,extrema);
00104 s1.UseRangeControl(rc);
00105 s1.UseExtremaControl(ec);
00106
00107 gc.GetCanvas()->cd();
00108 ColorAxis* ca[4];
00109 ca[0] = new ColorAxis(20,0.05,range, .1,.1,.9,.1);
00110 ca[1] = new ColorAxis(20,0.05,range, .1,.1,.1,.9);
00111 ca[2] = new ColorAxis(20,0.05,range, .1,.9,.9,.9,510,"-");
00112 ca[3] = new ColorAxis(20,0.05,range, .9,.1,.9,.9,510,"+L");
00113 for (int i=0; i<4; ++i) {
00114 RangeDouble& sel = ca[i]->GetSelectionRange();
00115 sel.modified.connect(bind(slot(rc,&RangeControl<double>::Apply),&sel));
00116 ca[i]->Draw();
00117 }
00118
00119 range->modified.connect(bind(slot(print_range),range));
00120 range->modified.connect(bind(slot(update_canvas),gc.GetCanvas()));
00121
00122 b_undo.clicked.connect(retype_return<void>(slot(*hist,&UndoHistory::Undo)));
00123 b_redo.clicked.connect(retype_return<void>(slot(*hist,&UndoHistory::Redo)));
00124
00125
00126 mw.ShowAll();
00127 mw.SetMinSize();
00128 mw.ConnectClose();
00129
00130 theApp.Run();
00131 return 0;
00132 }