TArrowEditor.cxx

Go to the documentation of this file.
00001 // @(#)root/ged:$Id: TArrowEditor.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Ilka Antcheva   20/10/04
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, 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 #include "TArrowEditor.h"
00013 #include "TGComboBox.h"
00014 #include "TGLabel.h"
00015 #include "TGNumberEntry.h"
00016 #include "TArrow.h"
00017 
00018 ClassImp(TArrowEditor)
00019 
00020 enum EArrowWid {
00021    kARROW_ANG,
00022    kARROW_OPT,
00023    kARROW_SIZ
00024 };
00025 
00026 //______________________________________________________________________________
00027 /* Begin_Html
00028 <center><h2>Implements user interface for editing of arrow attributes: 
00029 shape, size, angle.</h2></center>
00030 The picture below shows this interface.
00031 End_Html 
00032 Begin_Macro(GUI)
00033 {
00034    gROOT->ProcessLine(".x $ROOTSYS/tutorials/graphics/arrow.C");
00035    c1->SetBorderMode(0);
00036    c1->ToggleEditor();
00037    c1->Selected(c1,TArrow,1);
00038    TRootCanvas *r = (TRootCanvas*)c1->GetCanvasImp();
00039    r->SetWindowSize(700,500);
00040    return r->GetMainFrame();
00041 }
00042 End_Macro */
00043 
00044 
00045 //______________________________________________________________________________
00046 TArrowEditor::TArrowEditor(const TGWindow *p, Int_t width,
00047                            Int_t height, UInt_t options, Pixel_t back)
00048    : TGedFrame(p, width, height, options | kVerticalFrame, back)
00049 {
00050    // Constructor of arrow GUI.
00051 
00052    fArrow = 0;
00053 
00054    MakeTitle("Arrow");
00055 
00056    TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
00057    AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
00058 
00059    TGCompositeFrame *f2a = new TGCompositeFrame(f2, 80, 20);
00060    f2->AddFrame(f2a, new TGLayoutHints(kLHintsTop, 10, 0, 0, 0));
00061 
00062    TGLabel *fShapeLabel = new TGLabel(f2a, "Shape:");
00063    f2a->AddFrame(fShapeLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 1, 5));
00064 
00065    TGLabel *fAngleLabel = new TGLabel(f2a, "Angle:");
00066    f2a->AddFrame(fAngleLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 5));
00067 
00068    TGLabel *fSizeLabel = new TGLabel(f2a, "Size: ");
00069    f2a->AddFrame(fSizeLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 1));
00070 
00071    TGCompositeFrame *f2b = new TGCompositeFrame(f2, 80, 20, kFixedWidth);
00072    f2->AddFrame(f2b, new TGLayoutHints(kLHintsTop, 10, 0, 0, 0));
00073 
00074    fOptionCombo = BuildOptionComboBox(f2b, kARROW_OPT);
00075    fOptionCombo->Resize(80, 20);
00076    f2b->AddFrame(fOptionCombo, new TGLayoutHints(kLHintsExpandX, 1, 1, 1, 1));
00077    fOptionCombo->Associate(this);
00078 
00079    fAngleEntry = new TGNumberEntry(f2b, 30, 8, kARROW_ANG,
00080                              TGNumberFormat::kNESInteger,
00081                              TGNumberFormat::kNEANonNegative,
00082                              TGNumberFormat::kNELLimitMinMax,0, 180);
00083    fAngleEntry->GetNumberEntry()->SetToolTipText("Set the arrow opening angle in degrees.");
00084    f2b->AddFrame(fAngleEntry, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
00085 
00086    fSizeEntry = new TGNumberEntry(f2b, 0.03, 8, kARROW_SIZ,
00087                                   TGNumberFormat::kNESRealTwo,
00088                                   TGNumberFormat::kNEANonNegative,
00089                                   TGNumberFormat::kNELLimitMinMax, 0.01, 0.30);
00090    fSizeEntry->GetNumberEntry()->SetToolTipText("Set the size of arrow.");
00091    f2b->AddFrame(fSizeEntry, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
00092 
00093 }
00094 
00095 //______________________________________________________________________________
00096 TArrowEditor::~TArrowEditor()
00097 {
00098    // Destructor of arrow editor.
00099 
00100    TGFrameElement *el;
00101    TIter next(GetList());
00102 
00103    while ((el = (TGFrameElement *)next())) {
00104       if (!strcmp(el->fFrame->ClassName(), "TGCompositeFrame"))
00105          ((TGCompositeFrame *)el->fFrame)->Cleanup();
00106    }
00107    Cleanup();
00108 }
00109 
00110 //______________________________________________________________________________
00111 void TArrowEditor::ConnectSignals2Slots()
00112 {
00113    // Connect signals to slots.
00114 
00115    fOptionCombo->Connect("Selected(Int_t)", "TArrowEditor", this, "DoOption(Int_t)");
00116    fAngleEntry->Connect("ValueSet(Long_t)", "TArrowEditor", this, "DoAngle()");
00117    (fAngleEntry->GetNumberEntry())->Connect("ReturnPressed()", "TArrowEditor", this, "DoAngle()");
00118    fSizeEntry->Connect("ValueSet(Long_t)", "TArrowEditor", this, "DoSize()");
00119    (fSizeEntry->GetNumberEntry())->Connect("ReturnPressed()", "TArrowEditor", this, "DoSize()");
00120 
00121    fInit = kFALSE;
00122 }
00123 
00124 //______________________________________________________________________________
00125 void TArrowEditor::SetModel(TObject* obj)
00126 {
00127    // Pick up the used arrow attributes.
00128 
00129    fArrow = (TArrow *)obj;
00130    fAvoidSignal = kTRUE;
00131 
00132    Int_t id = GetShapeEntry(fArrow->GetDrawOption());
00133    if (id != fOptionCombo->GetSelected())
00134       fOptionCombo->Select(id);
00135 
00136    Float_t sz = fArrow->GetArrowSize();
00137    fSizeEntry->SetNumber(sz);
00138 
00139    Int_t deg = (Int_t)fArrow->GetAngle();
00140    fAngleEntry->SetNumber(deg);
00141 
00142    if (fInit) ConnectSignals2Slots();
00143    fAvoidSignal = kFALSE;
00144 }
00145 
00146 //______________________________________________________________________________
00147 void TArrowEditor::DoAngle()
00148 {
00149    // Slot connected to the arrow opening angle setting.
00150 
00151    if (fAvoidSignal) return;
00152    fArrow->SetAngle((Float_t)fAngleEntry->GetNumber());
00153    fArrow->Paint(fArrow->GetDrawOption());
00154    Update();
00155 }
00156 
00157 //______________________________________________________________________________
00158 void TArrowEditor::DoOption(Int_t id)
00159 {
00160    // Slot connected to the arrow shape setting.
00161 
00162    if (fAvoidSignal) return;
00163    const char* opt=0;
00164    switch (id) {
00165       case 1:
00166          opt = "|>";
00167          break;
00168       case 2:
00169          opt = "<|";
00170          break;
00171       case 3:
00172          opt = ">";
00173          break;
00174       case 4:
00175          opt = "<";
00176          break;
00177       case 5:
00178          opt = "->-";
00179          break;
00180       case 6:
00181          opt = "-<-";
00182          break;
00183       case 7:
00184          opt = "-|>-";
00185          break;
00186       case 8:
00187          opt = "-<|-";
00188          break;
00189       case 9:
00190          opt = "<>";
00191          break;
00192       case 10:
00193          opt = "<|>";
00194          break;
00195    }
00196    fArrow->SetDrawOption(opt);
00197    fArrow->Paint(fArrow->GetDrawOption());
00198    Update();
00199 }
00200 
00201 
00202 //______________________________________________________________________________
00203 void TArrowEditor::DoSize()
00204 {
00205    // Slot connected to the arrow size.
00206 
00207    if (fAvoidSignal) return;
00208    fArrow->SetArrowSize(fSizeEntry->GetNumber());
00209    fArrow->Paint(fArrow->GetDrawOption());
00210    Update();
00211 }
00212 
00213 //______________________________________________________________________________
00214 TGComboBox* TArrowEditor::BuildOptionComboBox(TGFrame* parent, Int_t id)
00215 {
00216    // Arrow shape combobox.
00217 
00218    TGComboBox *cb = new TGComboBox(parent, id);
00219 
00220    cb->AddEntry(" -------|>",1);
00221    cb->AddEntry(" <|-------",2);
00222    cb->AddEntry(" -------->",3);
00223    cb->AddEntry(" <--------",4);
00224    cb->AddEntry(" ---->----",5);
00225    cb->AddEntry(" ----<----",6);
00226    cb->AddEntry(" ----|>---",7);
00227    cb->AddEntry(" ---<|----",8);
00228    cb->AddEntry(" <------>", 9);
00229    cb->AddEntry(" <|-----|>",10);
00230    (cb->GetListBox())->Resize((cb->GetListBox())->GetWidth(), 136);
00231    cb->Select(1);
00232    return cb;
00233 }
00234 
00235 //______________________________________________________________________________
00236 Int_t TArrowEditor::GetShapeEntry(Option_t *option)
00237 {
00238    // Return shape entry according to the arrow draw option.
00239 
00240    TString opt = option;
00241    opt.ToLower();
00242    Int_t id = 0;
00243 
00244    if (opt == "|>")   id = 1;
00245    if (opt == "<|")   id = 2;
00246    if (opt == ">")    id = 3;
00247    if (opt == "<")    id = 4;
00248    if (opt == "->-")  id = 5;
00249    if (opt == "-<-")  id = 6;
00250    if (opt == "-|>-") id = 7;
00251    if (opt == "-<|-") id = 8;
00252    if (opt == "<>")   id = 9;
00253    if (opt == "<|>")  id = 10;
00254    return id;
00255 }

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