Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TLineEditor.cxx
Go to the documentation of this file.
1 // @(#)root/ged:$Id$
2 // Author: Ilka Antcheva 24/04/06
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 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TLineEditor //
15 // //
16 // Implements GUI for editing line attributes: shape, size, angle. // //
17 // //
18 //////////////////////////////////////////////////////////////////////////
19 //Begin_Html
20 /*
21 <img src="gif/TLineEditor.gif">
22 */
23 //End_Html
24 
25 
26 #include "TLineEditor.h"
27 #include "TGLabel.h"
28 #include "TGNumberEntry.h"
29 #include "TLine.h"
30 #include "TVirtualPad.h"
31 
32 ClassImp(TLineEditor);
33 
34 enum ELineWid {
35  kLine_STAX,
36  kLine_STAY,
37  kLine_ENDX,
38  kLine_ENDY,
39  kLine_VERTICAL,
40  kLine_HORIZONTAL
41 };
42 
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Constructor of line GUI.
46 
47 TLineEditor::TLineEditor(const TGWindow *p, Int_t width,
48  Int_t height, UInt_t options, Pixel_t back)
49  : TGedFrame(p, width, height, options | kVerticalFrame, back)
50 {
51  fLine = 0;
52 
53  MakeTitle("Points");
54 
55  TGCompositeFrame *f3 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
56  AddFrame(f3, new TGLayoutHints(kLHintsTop, 1, 1, 3, 0));
57 
58  TGCompositeFrame *f3a = new TGCompositeFrame(f3, 80, 20);
59  f3->AddFrame(f3a, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
60 
61  TGLabel *fStartPointXLabel = new TGLabel(f3a, "Start X:");
62  f3a->AddFrame(fStartPointXLabel, new TGLayoutHints(kLHintsNormal, 8, 0, 5, 5));
63 
64  TGLabel *fStartPointYLabel = new TGLabel(f3a, "Y:");
65  f3a->AddFrame(fStartPointYLabel, new TGLayoutHints(kLHintsNormal, 37, 0, 5, 5));
66 
67  TGLabel *fEndPointXLabel = new TGLabel(f3a, "End X:");
68  f3a->AddFrame(fEndPointXLabel, new TGLayoutHints(kLHintsNormal, 10, 0, 5, 5));
69 
70  TGLabel *fEndPointYLabel = new TGLabel(f3a, "Y:");
71  f3a->AddFrame(fEndPointYLabel, new TGLayoutHints(kLHintsNormal, 37, 0, 5, 5));
72 
73  TGCompositeFrame *f3b = new TGCompositeFrame(f3, 80, 20, kFixedWidth);
74  f3->AddFrame(f3b, new TGLayoutHints(kLHintsNormal, 8, 0, 0, 0));
75 
76  fStartPointX = new TGNumberEntry(f3b, 0.0, 8, kLine_STAX,
77  TGNumberFormat::kNESRealThree,
78  TGNumberFormat::kNEAAnyNumber,
79  TGNumberFormat::kNELNoLimits);
80  fStartPointX->GetNumberEntry()->SetToolTipText("Set start point X coordinate of Line.");
81  f3b->AddFrame(fStartPointX, new TGLayoutHints(kLHintsExpandX, 1, 1, 1, 1));
82 
83  fStartPointY = new TGNumberEntry(f3b, 0.0, 8, kLine_STAY,
84  TGNumberFormat::kNESRealThree,
85  TGNumberFormat::kNEAAnyNumber,
86  TGNumberFormat::kNELNoLimits);
87  fStartPointY->GetNumberEntry()->SetToolTipText("Set start point Y coordinate of Line.");
88  f3b->AddFrame(fStartPointY, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
89 
90  fEndPointX = new TGNumberEntry(f3b, 0.0, 8, kLine_ENDX,
91  TGNumberFormat::kNESRealThree,
92  TGNumberFormat::kNEAAnyNumber,
93  TGNumberFormat::kNELNoLimits);
94  fEndPointX->GetNumberEntry()->SetToolTipText("Set end point X xoordinate of Line.");
95  f3b->AddFrame(fEndPointX, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
96 
97  fEndPointY = new TGNumberEntry(f3b, 0.0, 8, kLine_ENDY,
98  TGNumberFormat::kNESRealThree,
99  TGNumberFormat::kNEAAnyNumber,
100  TGNumberFormat::kNELNoLimits);
101  fEndPointY->GetNumberEntry()->SetToolTipText("Set end point Y coordinate of Line.");
102  f3b->AddFrame(fEndPointY, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
103 
104  fVertical = new TGCheckButton(this,"Vertical",kLine_VERTICAL);
105  fVertical->SetToolTipText("Set vertical");
106  AddFrame(fVertical, new TGLayoutHints(kLHintsTop, 8, 1, 5, 0));
107 
108  fHorizontal = new TGCheckButton(this,"Horizontal",kLine_HORIZONTAL);
109  fHorizontal->SetToolTipText("Set horizontal");
110  AddFrame(fHorizontal, new TGLayoutHints(kLHintsTop, 8, 1, 3, 0));
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Destructor of line editor.
115 
116 TLineEditor::~TLineEditor()
117 {
118 }
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 /// Connect signals to slots.
122 
123 void TLineEditor::ConnectSignals2Slots()
124 {
125  fStartPointX->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoStartPoint()");
126  (fStartPointX->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoStartPoint()");
127  fStartPointY->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoStartPoint()");
128  (fStartPointY->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoStartPoint()");
129  fEndPointX->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoEndPoint()");
130  (fEndPointX->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoEndPoint()");
131  fEndPointY->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoEndPoint()");
132  (fEndPointY->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoEndPoint()");
133  fVertical->Connect("Clicked()","TLineEditor",this,"DoLineVertical()");
134  fHorizontal->Connect("Clicked()","TLineEditor",this,"DoLineHorizontal()");
135 
136  fInit = kFALSE;
137 }
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// Pick up the used line attributes.
141 
142 void TLineEditor::SetModel(TObject* obj)
143 {
144  fLine = (TLine *)obj;
145  fAvoidSignal = kTRUE;
146 
147  Float_t val = fLine->GetX1();
148  fStartPointX->SetNumber(val);
149 
150  val = fLine->GetX2();
151  fEndPointX->SetNumber(val);
152 
153  val = fLine->GetY1();
154  fStartPointY->SetNumber(val);
155 
156  val = fLine->GetY2();
157  fEndPointY->SetNumber(val);
158 
159  if (fLine->IsHorizontal()) fHorizontal->SetState(kButtonDown, kFALSE);
160  else fHorizontal->SetState(kButtonUp, kFALSE);
161 
162  if (fLine->IsVertical()) fVertical->SetState(kButtonDown, kFALSE);
163  else fVertical->SetState(kButtonUp, kFALSE);
164 
165  if (fInit) ConnectSignals2Slots();
166 
167  fAvoidSignal = kFALSE;
168 }
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Slot connected to the line start point.
172 
173 void TLineEditor::DoStartPoint()
174 {
175  if (fAvoidSignal) return;
176  fLine->SetX1((Double_t)fStartPointX->GetNumber());
177  fLine->SetY1((Double_t)fStartPointY->GetNumber());
178  fLine->Paint(fLine->GetDrawOption());
179  Update();
180 }
181 ////////////////////////////////////////////////////////////////////////////////
182 /// Slot connected to the line EndPoint.
183 
184 void TLineEditor::DoEndPoint()
185 {
186  if (fAvoidSignal) return;
187  fLine->SetX2((Double_t)fEndPointX->GetNumber());
188  fLine->SetY2((Double_t)fEndPointY->GetNumber());
189  fLine->Paint(fLine->GetDrawOption());
190  Update();
191 }
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 /// Slot so set the line vertical
195 
196 void TLineEditor::DoLineVertical()
197 {
198  if (fAvoidSignal) return;
199  if (fVertical->GetState() == kButtonDown) {
200  fLine->SetVertical();
201  fHorizontal->SetState(kButtonUp, kFALSE);
202  } else {
203  fLine->SetVertical(kFALSE);
204  }
205  Update();
206 }
207 
208 ////////////////////////////////////////////////////////////////////////////////
209 /// Slot so set the line horizontal
210 
211 void TLineEditor::DoLineHorizontal()
212 {
213  if (fAvoidSignal) return;
214  if (fHorizontal->GetState() == kButtonDown) {
215  fLine->SetHorizontal();
216  fVertical->SetState(kButtonUp, kFALSE);
217  } else {
218  fLine->SetHorizontal(kFALSE);
219  }
220  Update();
221 }