TMemStatDrawDlg.cxx

Go to the documentation of this file.
00001 // @(#)root/memstat:$Name$:$Id: TMemStatDrawDlg.cxx 24658 2008-07-04 09:06:58Z anar $
00002 // Author: Anar Manafov (A.Manafov@gsi.de) 31/05/2008
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 // STD
00013 #include <sstream>
00014 #include <algorithm>
00015 // ROOT
00016 #include "TGLabel.h"
00017 #include "TGComboBox.h"
00018 #include "TGNumberEntry.h"
00019 #include "TGButton.h"
00020 #include "TCanvas.h"
00021 #include "TRootEmbeddedCanvas.h"
00022 // MemStat
00023 #include "TMemStat.h"
00024 #include "TMemStatDrawDlg.h"
00025 #include "TMemStatResource.h"
00026 
00027 using namespace std;
00028 
00029 //______________________________________________________________________________
00030 struct SFill_t : public binary_function<string, TGComboBox*, bool>
00031 {
00032    bool operator()(const string &val, TGComboBox* box) const
00033    {
00034       if (!box)
00035          return false;//Parameter is a NULL pointer"
00036 
00037       box->AddEntry(val.c_str(), box->GetNumberOfEntries());
00038       return true;
00039    }
00040 };
00041 
00042 //______________________________________________________________________________
00043 TMemStatDrawDlg::TMemStatDrawDlg(TGCompositeFrame *parent, TMemStat *MemStat):
00044       fMemStat(MemStat),
00045       fboxOrder(NULL),
00046       fboxSortStat(NULL),
00047       fboxSortStamp(NULL),
00048       fNmbStackDeep(NULL),
00049       fNmbSortDeep(NULL),
00050       fNmbMaxLength(NULL),
00051       fEc(NULL)
00052 {
00053   // a ctor
00054    PlaceCtrls(parent);
00055 }
00056 
00057 //______________________________________________________________________________
00058 TMemStatDrawDlg::~TMemStatDrawDlg()
00059 {
00060   // a dtor
00061 }
00062 
00063 //______________________________________________________________________________
00064 void TMemStatDrawDlg::PlaceCtrls(TGCompositeFrame *frame)
00065 {
00066    // TODO: Comment me
00067 
00068    TGCompositeFrame *cont = new TGCompositeFrame(frame, 800, 400, kHorizontalFrame | kFitWidth | kFitHeight);
00069    frame->AddFrame(cont, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY | kLHintsExpandX, 2, 2, 2, 2));
00070 
00071    TGCompositeFrame *contR = new TGCompositeFrame(cont, 200, 200, kVerticalFrame | kFitWidth | kFitHeight);
00072    cont->AddFrame(contR, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 2, 2, 2, 2));
00073 
00074    StringVector_t values;
00075    // Order
00076    values.push_back("increasing");
00077    values.push_back("decreasing");
00078    PlaceLBoxCtrl(contR, &fboxOrder, "Order: ", values, resCBoxOrder);
00079    // Sort Stat
00080    values.clear();
00081    values.push_back("TotalAllocCount");
00082    values.push_back("TotalAlocSize");
00083    values.push_back("AllocCount");
00084    values.push_back("AllocSize");
00085    PlaceLBoxCtrl(contR, &fboxSortStat, "Sort stat: ", values, resCBoxSortStat);
00086    // Sort Stamp
00087    values.clear();
00088    values.push_back("Current");
00089    values.push_back("MaxSize");
00090    values.push_back("MaxCount");
00091    PlaceLBoxCtrl(contR, &fboxSortStamp, "Sort stamp: ", values, resCBoxSortStamp);
00092    // sortdeep and stackdeep
00093    PlaceDeepCtrl(contR);
00094 
00095    // a Draw button
00096    TGTextButton *btnDraw = new TGTextButton(contR);
00097    btnDraw->Connect("Clicked()", "TMemStatDrawDlg", this, "HandleDrawMemStat()");
00098    btnDraw->SetText("Draw");
00099    contR->AddFrame(btnDraw,
00100                    new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 10, 10, 10, 10));
00101 
00102    // a Canvas
00103    PlaceEmbeddedCanvas(cont);
00104 }
00105 
00106 //______________________________________________________________________________
00107 void TMemStatDrawDlg::PlaceLBoxCtrl(TGCompositeFrame *frame, TGComboBox **box,
00108                                     const string &Label, const StringVector_t &Vealues, Int_t resource)
00109 {
00110    // TODO: Comment me
00111 
00112    TGHorizontalFrame *horz = new TGHorizontalFrame(frame);
00113    frame->AddFrame(horz, new TGLayoutHints(kLHintsExpandX));
00114    // text description
00115    TGLabel *lbl = new TGLabel(horz, Label.c_str());
00116    horz->AddFrame(lbl,
00117                   new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2));
00118 
00119    // a list box of stamps
00120    *box = new TGComboBox( horz, resource );
00121    (*box)->Resize(120, 20);
00122    horz->AddFrame((*box), new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
00123 
00124    // filling Combo box with values
00125    for_each(Vealues.begin(), Vealues.end(), bind2nd(SFill_t(), (*box)));
00126 
00127    (*box)->Select(0);
00128 }
00129 
00130 //______________________________________________________________________________
00131 void TMemStatDrawDlg::PlaceDeepCtrl(TGCompositeFrame *frame)
00132 {
00133    // create and layout "Deep" controls
00134 
00135    // deep of information
00136    TGGroupFrame *contDeep = new TGGroupFrame(frame, "Deepnes", kVerticalFrame | kFitWidth | kFitHeight);
00137    frame->AddFrame(contDeep, new TGLayoutHints(kLHintsExpandX));
00138 
00139    // A "Deep" frame
00140    TGHorizontalFrame *horz0 = new TGHorizontalFrame(contDeep);
00141    contDeep->AddFrame(horz0, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY));
00142    // ------ Stack Deep
00143    // text description
00144    TGLabel *lblStackDeep = new TGLabel(horz0, "Stack deep:");
00145    horz0->AddFrame(lblStackDeep, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
00146    // number entry box for specifying the stack deepness
00147    fNmbStackDeep = new TGNumberEntry(horz0, fMemStat->GetStackDeep(), 1, resNmbStackDeep, TGNumberFormat::kNESInteger,
00148                                      TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 1, 50);
00149    horz0->AddFrame(fNmbStackDeep, new TGLayoutHints( kLHintsRight, 2, 2, 2, 2));
00150    fNmbStackDeep->Resize(100, 20);
00151 
00152    // ------ Sort Deep
00153    TGHorizontalFrame *horz1 = new TGHorizontalFrame(contDeep);
00154    contDeep->AddFrame(horz1, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY));
00155    // text description
00156    TGLabel *lSortDeep = new TGLabel(horz1, "Sort deep:");
00157    horz1->AddFrame(lSortDeep, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
00158    // number entry box for specifying the number of stamps
00159    fNmbSortDeep = new TGNumberEntry(horz1, fMemStat->GetSortDeep(), 1, resNmbSortDeep, TGNumberFormat::kNESInteger,
00160                                     TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 1, 50);
00161    horz1->AddFrame(fNmbSortDeep, new TGLayoutHints( kLHintsRight, 2, 2, 2, 2));
00162    fNmbSortDeep->Resize(100, 20);
00163 
00164    // ------ Max length
00165    TGHorizontalFrame *horz2 = new TGHorizontalFrame(contDeep);
00166    contDeep->AddFrame(horz2, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY));
00167    // text description
00168    TGLabel *lbl = new TGLabel(horz2, "Max length:");
00169    horz2->AddFrame(lbl, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
00170    // number entry box for specifying the number of stamps
00171    fNmbMaxLength = new TGNumberEntry(horz2, fMemStat->GetMaxStringLength(), 1, resNmbMaxLength, TGNumberFormat::kNESInteger,
00172                                      TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 1, 500);
00173    horz2->AddFrame(fNmbMaxLength, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
00174    fNmbMaxLength->Resize(100, 20);
00175 }
00176 
00177 //______________________________________________________________________________
00178 void TMemStatDrawDlg::ReDraw()
00179 {
00180    // TODO: Comment me
00181 
00182    if (!fMemStat)
00183       return;
00184 
00185    //"order 0 sortstat 2 sortstamp 1 sortdeep 10 stackdeep 5 maxlength 50"
00186    ostringstream ss;
00187    // order
00188    if (fboxOrder)
00189       ss << "order " << fboxOrder->GetSelected();
00190    // sort stat
00191    if (fboxSortStat)
00192       ss << " sortstat " << fboxSortStat->GetSelected();
00193    // sort stamp
00194    if (fboxSortStamp)
00195       ss << " sortstamp " << fboxSortStamp->GetSelected();
00196    // sort deep
00197    if (fNmbStackDeep)
00198       ss << " sortdeep " << fNmbStackDeep->GetIntNumber();
00199    // stack deep
00200    if (fNmbSortDeep)
00201       ss << " stackdeep " << fNmbSortDeep->GetIntNumber();
00202    // max length
00203    if (fNmbMaxLength)
00204       ss << " maxlength " << fNmbMaxLength->GetIntNumber();
00205 
00206    fMemStat->Draw(ss.str().c_str());
00207    fEc->GetCanvas()->Modified();
00208    fEc->GetCanvas()->Update();
00209 }
00210 
00211 //______________________________________________________________________________
00212 void TMemStatDrawDlg::HandleDrawMemStat()
00213 {
00214    // TODO: Comment me
00215    ReDraw();
00216 }
00217 
00218 //______________________________________________________________________________
00219 void TMemStatDrawDlg::PlaceEmbeddedCanvas(TGCompositeFrame *frame)
00220 {
00221    // TODO: Comment me
00222    if (fEc)
00223       return;
00224 
00225    fEc = new TRootEmbeddedCanvas("ec", frame, 200, 200);
00226    frame->AddFrame(fEc, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00227    fEc->GetCanvas()->SetBorderMode(0);
00228 }

Generated on Tue Jul 5 14:43:51 2011 for ROOT_528-00b_version by  doxygen 1.5.1