Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TArrowEditor.cxx
Go to the documentation of this file.
1 // @(#)root/ged:$Id$
2 // Author: Ilka Antcheva 20/10/04
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TArrowEditor.h"
13 #include "TGComboBox.h"
14 #include "TGLabel.h"
15 #include "TGNumberEntry.h"
16 #include "TArrow.h"
17 
18 ClassImp(TArrowEditor);
19 
20 enum EArrowWid {
21  kARROW_ANG,
22  kARROW_OPT,
23  kARROW_SIZ
24 };
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 
28 /*
29 <center><h2>Implements user interface for editing of arrow attributes:
30 shape, size, angle.</h2></center>
31 The picture below shows this interface.
32 */
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 /// Constructor of arrow GUI.
36 
37 TArrowEditor::TArrowEditor(const TGWindow *p, Int_t width,
38  Int_t height, UInt_t options, Pixel_t back)
39  : TGedFrame(p, width, height, options | kVerticalFrame, back)
40 {
41  fArrow = 0;
42 
43  MakeTitle("Arrow");
44 
45  TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
46  AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
47 
48  TGCompositeFrame *f2a = new TGCompositeFrame(f2, 80, 20);
49  f2->AddFrame(f2a, new TGLayoutHints(kLHintsTop, 10, 0, 0, 0));
50 
51  TGLabel *fShapeLabel = new TGLabel(f2a, "Shape:");
52  f2a->AddFrame(fShapeLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 1, 5));
53 
54  TGLabel *fAngleLabel = new TGLabel(f2a, "Angle:");
55  f2a->AddFrame(fAngleLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 5));
56 
57  TGLabel *fSizeLabel = new TGLabel(f2a, "Size: ");
58  f2a->AddFrame(fSizeLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 1));
59 
60  TGCompositeFrame *f2b = new TGCompositeFrame(f2, 80, 20, kFixedWidth);
61  f2->AddFrame(f2b, new TGLayoutHints(kLHintsTop, 10, 0, 0, 0));
62 
63  fOptionCombo = BuildOptionComboBox(f2b, kARROW_OPT);
64  fOptionCombo->Resize(80, 20);
65  f2b->AddFrame(fOptionCombo, new TGLayoutHints(kLHintsExpandX, 1, 1, 1, 1));
66  fOptionCombo->Associate(this);
67 
68  fAngleEntry = new TGNumberEntry(f2b, 30, 8, kARROW_ANG,
69  TGNumberFormat::kNESInteger,
70  TGNumberFormat::kNEANonNegative,
71  TGNumberFormat::kNELLimitMinMax,0, 180);
72  fAngleEntry->GetNumberEntry()->SetToolTipText("Set the arrow opening angle in degrees.");
73  f2b->AddFrame(fAngleEntry, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
74 
75  fSizeEntry = new TGNumberEntry(f2b, 0.03, 8, kARROW_SIZ,
76  TGNumberFormat::kNESRealTwo,
77  TGNumberFormat::kNEANonNegative,
78  TGNumberFormat::kNELLimitMinMax, 0.01, 0.30);
79  fSizeEntry->GetNumberEntry()->SetToolTipText("Set the size of arrow.");
80  f2b->AddFrame(fSizeEntry, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
81 
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Destructor of arrow editor.
86 
87 TArrowEditor::~TArrowEditor()
88 {
89  TGFrameElement *el;
90  TIter next(GetList());
91 
92  while ((el = (TGFrameElement *)next())) {
93  if (!strcmp(el->fFrame->ClassName(), "TGCompositeFrame"))
94  ((TGCompositeFrame *)el->fFrame)->Cleanup();
95  }
96  Cleanup();
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// Connect signals to slots.
101 
102 void TArrowEditor::ConnectSignals2Slots()
103 {
104  fOptionCombo->Connect("Selected(Int_t)", "TArrowEditor", this, "DoOption(Int_t)");
105  fAngleEntry->Connect("ValueSet(Long_t)", "TArrowEditor", this, "DoAngle()");
106  (fAngleEntry->GetNumberEntry())->Connect("ReturnPressed()", "TArrowEditor", this, "DoAngle()");
107  fSizeEntry->Connect("ValueSet(Long_t)", "TArrowEditor", this, "DoSize()");
108  (fSizeEntry->GetNumberEntry())->Connect("ReturnPressed()", "TArrowEditor", this, "DoSize()");
109 
110  fInit = kFALSE;
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Pick up the used arrow attributes.
115 
116 void TArrowEditor::SetModel(TObject* obj)
117 {
118  fArrow = (TArrow *)obj;
119  fAvoidSignal = kTRUE;
120 
121  Int_t id = GetShapeEntry(fArrow->GetDrawOption());
122  if (id != fOptionCombo->GetSelected())
123  fOptionCombo->Select(id);
124 
125  Float_t sz = fArrow->GetArrowSize();
126  fSizeEntry->SetNumber(sz);
127 
128  Int_t deg = (Int_t)fArrow->GetAngle();
129  fAngleEntry->SetNumber(deg);
130 
131  if (fInit) ConnectSignals2Slots();
132  fAvoidSignal = kFALSE;
133 }
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 /// Slot connected to the arrow opening angle setting.
137 
138 void TArrowEditor::DoAngle()
139 {
140  if (fAvoidSignal) return;
141  fArrow->SetAngle((Float_t)fAngleEntry->GetNumber());
142  fArrow->Paint(fArrow->GetDrawOption());
143  Update();
144 }
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 /// Slot connected to the arrow shape setting.
148 
149 void TArrowEditor::DoOption(Int_t id)
150 {
151  if (fAvoidSignal) return;
152  const char* opt=0;
153  switch (id) {
154  case 1:
155  opt = "|>";
156  break;
157  case 2:
158  opt = "<|";
159  break;
160  case 3:
161  opt = ">";
162  break;
163  case 4:
164  opt = "<";
165  break;
166  case 5:
167  opt = "->-";
168  break;
169  case 6:
170  opt = "-<-";
171  break;
172  case 7:
173  opt = "-|>-";
174  break;
175  case 8:
176  opt = "-<|-";
177  break;
178  case 9:
179  opt = "<>";
180  break;
181  case 10:
182  opt = "<|>";
183  break;
184  }
185  fArrow->SetDrawOption(opt);
186  fArrow->Paint(fArrow->GetDrawOption());
187  Update();
188 }
189 
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Slot connected to the arrow size.
193 
194 void TArrowEditor::DoSize()
195 {
196  if (fAvoidSignal) return;
197  fArrow->SetArrowSize(fSizeEntry->GetNumber());
198  fArrow->Paint(fArrow->GetDrawOption());
199  Update();
200 }
201 
202 ////////////////////////////////////////////////////////////////////////////////
203 /// Arrow shape combobox.
204 
205 TGComboBox* TArrowEditor::BuildOptionComboBox(TGFrame* parent, Int_t id)
206 {
207  TGComboBox *cb = new TGComboBox(parent, id);
208 
209  cb->AddEntry(" -------|>",1);
210  cb->AddEntry(" <|-------",2);
211  cb->AddEntry(" -------->",3);
212  cb->AddEntry(" <--------",4);
213  cb->AddEntry(" ---->----",5);
214  cb->AddEntry(" ----<----",6);
215  cb->AddEntry(" ----|>---",7);
216  cb->AddEntry(" ---<|----",8);
217  cb->AddEntry(" <------>", 9);
218  cb->AddEntry(" <|-----|>",10);
219  (cb->GetListBox())->Resize((cb->GetListBox())->GetWidth(), 136);
220  cb->Select(1);
221  return cb;
222 }
223 
224 ////////////////////////////////////////////////////////////////////////////////
225 /// Return shape entry according to the arrow draw option.
226 
227 Int_t TArrowEditor::GetShapeEntry(Option_t *option)
228 {
229  TString opt = option;
230  opt.ToLower();
231  Int_t id = 0;
232 
233  if (opt == "|>") id = 1;
234  if (opt == "<|") id = 2;
235  if (opt == ">") id = 3;
236  if (opt == "<") id = 4;
237  if (opt == "->-") id = 5;
238  if (opt == "-<-") id = 6;
239  if (opt == "-|>-") id = 7;
240  if (opt == "-<|-") id = 8;
241  if (opt == "<>") id = 9;
242  if (opt == "<|>") id = 10;
243  return id;
244 }