Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TGeoTrd2Editor.cxx
Go to the documentation of this file.
1// @(#):$Id$
2// Author: M.Gheata
3
4/*************************************************************************
5 * Copyright (C) 1995-2002, 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/** \class TGeoTrd2Editor
13\ingroup Geometry_builder
14
15Editor for a TGeoTrd2.
16
17\image html geom_trd2_pic.png
18
19\image html geom_trd2_ed.png
20
21*/
22
23#include "TGeoTrd2Editor.h"
24#include "TGeoTabManager.h"
25#include "TGeoTrd2.h"
26#include "TGeoManager.h"
27#include "TVirtualGeoPainter.h"
28#include "TVirtualPad.h"
29#include "TView.h"
30#include "TGButton.h"
31#include "TGTextEntry.h"
32#include "TGNumberEntry.h"
33#include "TGLabel.h"
34
35
37
38////////////////////////////////////////////////////////////////////////////////
39/// Constructor for trd2 editor
40
41TGeoTrd2Editor::TGeoTrd2Editor(const TGWindow *p, Int_t width, Int_t height, UInt_t options, Pixel_t back)
42 : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
43{
44 fShape = nullptr;
45 fDxi1 = fDxi2 = fDyi1 = fDyi2 = fDzi = 0.0;
46 fNamei = "";
49
50 // TextEntry for shape name
51 MakeTitle("Name");
52 fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kTRD2_NAME);
53 fShapeName->Resize(135, fShapeName->GetDefaultHeight());
54 fShapeName->SetToolTipText("Enter the box name");
55 fShapeName->Associate(this);
57
58 TGTextEntry *nef;
59 MakeTitle("Trd2 dimensions");
61
62 // Number entry for dx1
65 f1->AddFrame(new TGLabel(f1, "DX1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
66 fEDx1 = new TGNumberEntry(f1, 0., 5, kTRD2_X1);
68 nef = (TGTextEntry *)fEDx1->GetNumberEntry();
69 nef->SetToolTipText("Enter the half-length in X1");
70 fEDx1->Associate(this);
71 f1->AddFrame(fEDx1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
72 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
73
74 // Number entry for dx2
76 f1->AddFrame(new TGLabel(f1, "DX2"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
77 fEDx2 = new TGNumberEntry(f1, 0., 5, kTRD2_X2);
79 nef = (TGTextEntry *)fEDx2->GetNumberEntry();
80 nef->SetToolTipText("Enter the half-length in X2");
81 fEDx2->Associate(this);
82 f1->AddFrame(fEDx2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
83 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
84
85 // Number entry for dy1
88 f2->AddFrame(new TGLabel(f2, "DY1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
89 fEDy1 = new TGNumberEntry(f2, 0., 5, kTRD2_Y1);
91 nef = (TGTextEntry *)fEDy1->GetNumberEntry();
92 nef->SetToolTipText("Enter the half-length in Y1");
93 fEDy1->Associate(this);
94 f2->AddFrame(fEDy1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
95 compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
96
97 // Number entry for dy2
99 f2->AddFrame(new TGLabel(f2, "DY2"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
100 fEDy2 = new TGNumberEntry(f2, 0., 5, kTRD2_Y2);
102 nef = (TGTextEntry *)fEDy2->GetNumberEntry();
103 nef->SetToolTipText("Enter the half-length in Y2");
104 fEDy2->Associate(this);
105 f2->AddFrame(fEDy2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
106 compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
107
108 // Number entry for dz
109 TGCompositeFrame *f3 =
111 f3->AddFrame(new TGLabel(f3, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
112 fEDz = new TGNumberEntry(f3, 0., 5, kTRD2_Z);
114 nef = (TGTextEntry *)fEDz->GetNumberEntry();
115 nef->SetToolTipText("Enter the half-length in Z");
116 fEDz->Associate(this);
117 f3->AddFrame(fEDz, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
118 compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
119
120 compxyz->Resize(150, 30);
121 AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
122
123 // Delayed draw
125 fDelayed = new TGCheckButton(f1, "Delayed draw");
126 f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
127 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
128
129 // Buttons
130 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
131 fApply = new TGTextButton(f1, "Apply");
132 f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
133 fApply->Associate(this);
134 fUndo = new TGTextButton(f1, "Undo");
135 f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
136 fUndo->Associate(this);
137 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
138 fUndo->SetSize(fApply->GetSize());
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Destructor.
143
145{
146 TGFrameElement *el;
147 TIter next(GetList());
148 while ((el = (TGFrameElement *)next())) {
149 if (el->fFrame->IsComposite())
151 }
152 Cleanup();
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// Connect signals to slots.
157
159{
160 fApply->Connect("Clicked()", "TGeoTrd2Editor", this, "DoApply()");
161 fUndo->Connect("Clicked()", "TGeoTrd2Editor", this, "DoUndo()");
162 fShapeName->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
163 fEDx1->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDx1()");
164 fEDx2->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDx2()");
165 fEDy1->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDy1()");
166 fEDy2->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDy2()");
167 fEDz->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDz()");
168 fEDx1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
169 fEDx2->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
170 fEDy1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
171 fEDy2->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
172 fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
173 fInit = kFALSE;
174}
175
176////////////////////////////////////////////////////////////////////////////////
177/// Connect to the selected object.
178
180{
181 if (obj == nullptr || (obj->IsA() != TGeoTrd2::Class())) {
183 return;
184 }
185 fShape = (TGeoTrd2 *)obj;
186 fDxi1 = fShape->GetDx1();
187 fDxi2 = fShape->GetDx2();
188 fDyi1 = fShape->GetDy1();
189 fDyi2 = fShape->GetDy2();
190 fDzi = fShape->GetDz();
191 const char *sname = fShape->GetName();
192 if (!strcmp(sname, fShape->ClassName()))
193 fShapeName->SetText("-no_name");
194 else {
195 fShapeName->SetText(sname);
196 fNamei = sname;
197 }
198 fEDx1->SetNumber(fDxi1);
199 fEDx2->SetNumber(fDxi2);
200 fEDy1->SetNumber(fDyi1);
201 fEDy2->SetNumber(fDyi2);
202 fEDz->SetNumber(fDzi);
203 fApply->SetEnabled(kFALSE);
204 fUndo->SetEnabled(kFALSE);
205
206 if (fInit)
208 SetActive();
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// Check if shape drawing is delayed.
213
215{
216 return (fDelayed->GetState() == kButtonDown);
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// Perform name change.
221
223{
224 DoModified();
225}
226
227////////////////////////////////////////////////////////////////////////////////
228/// Slot for applying modifications.
229
231{
232 const char *name = fShapeName->GetText();
233 if (strcmp(name, fShape->GetName()))
234 fShape->SetName(name);
235 Double_t dx1 = fEDx1->GetNumber();
236 Double_t dx2 = fEDx2->GetNumber();
237 Double_t dy1 = fEDy1->GetNumber();
238 Double_t dy2 = fEDy2->GetNumber();
239 Double_t dz = fEDz->GetNumber();
240 Double_t param[5];
241 param[0] = dx1;
242 param[1] = dx2;
243 param[2] = dy1;
244 param[3] = dy2;
245 param[4] = dz;
246 fShape->SetDimensions(param);
247 fShape->ComputeBBox();
248 fUndo->SetEnabled();
249 fApply->SetEnabled(kFALSE);
250 if (fPad) {
251 if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
252 fShape->Draw();
253 fPad->GetView()->ShowAxis();
254 } else
255 Update();
256 }
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Slot for signaling modifications.
261
263{
264 fApply->SetEnabled();
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// Slot for undoing last operation.
269
271{
272 fEDx1->SetNumber(fDxi1);
273 fEDx2->SetNumber(fDxi2);
274 fEDy1->SetNumber(fDyi1);
275 fEDy2->SetNumber(fDyi2);
276 fEDz->SetNumber(fDzi);
277 DoApply();
278 fUndo->SetEnabled(kFALSE);
279 fApply->SetEnabled(kFALSE);
280}
281
282////////////////////////////////////////////////////////////////////////////////
283/// Slot for dx1.
284
286{
287 Double_t dx1 = fEDx1->GetNumber();
288 Double_t dx2 = fEDx2->GetNumber();
289 if (dx1 < 0) {
290 dx1 = 0;
291 fEDx1->SetNumber(dx1);
292 }
293 if (dx1 < 1.e-6 && dx2 < 1.e-6) {
294 dx1 = 0.1;
295 fEDx1->SetNumber(dx1);
296 }
297 DoModified();
298 if (!IsDelayed())
299 DoApply();
300}
301
302////////////////////////////////////////////////////////////////////////////////
303/// Slot for dx2.
304
306{
307 Double_t dx1 = fEDx1->GetNumber();
308 Double_t dx2 = fEDx2->GetNumber();
309 if (dx2 < 0) {
310 dx2 = 0;
311 fEDx2->SetNumber(dx2);
312 }
313 if (dx1 < 1.e-6 && dx2 < 1.e-6) {
314 dx2 = 0.1;
315 fEDx2->SetNumber(dx2);
316 }
317 DoModified();
318 if (!IsDelayed())
319 DoApply();
320}
321
322////////////////////////////////////////////////////////////////////////////////
323/// Slot for dy1.
324
326{
327 Double_t dy1 = fEDy1->GetNumber();
328 Double_t dy2 = fEDy2->GetNumber();
329 if (dy1 < 0) {
330 dy1 = 0;
331 fEDy1->SetNumber(dy1);
332 }
333 if (dy1 < 1.e-6 && dy2 < 1.e-6) {
334 dy1 = 0.1;
335 fEDy1->SetNumber(dy1);
336 }
337 DoModified();
338 if (!IsDelayed())
339 DoApply();
340}
341
342////////////////////////////////////////////////////////////////////////////////
343/// Slot for dy2.
344
346{
347 Double_t dy1 = fEDy1->GetNumber();
348 Double_t dy2 = fEDy2->GetNumber();
349 if (dy2 < 0) {
350 dy2 = 0;
351 fEDy2->SetNumber(dy2);
352 }
353 if (dy1 < 1.e-6 && dy2 < 1.e-6) {
354 dy2 = 0.1;
355 fEDy2->SetNumber(dy2);
356 }
357 DoModified();
358 if (!IsDelayed())
359 DoApply();
360}
361
362////////////////////////////////////////////////////////////////////////////////
363/// Slot for dz.
364
366{
367 Double_t dz = fEDz->GetNumber();
368 if (dz <= 0) {
369 dz = 0.1;
370 fEDz->SetNumber(dz);
371 }
372 DoModified();
373 if (!IsDelayed())
374 DoApply();
375}
@ kRaisedFrame
Definition GuiTypes.h:385
@ kSunkenFrame
Definition GuiTypes.h:384
@ kVerticalFrame
Definition GuiTypes.h:382
@ kDoubleBorder
Definition GuiTypes.h:386
@ kFixedWidth
Definition GuiTypes.h:388
@ kFitWidth
Definition GuiTypes.h:387
@ kHorizontalFrame
Definition GuiTypes.h:383
@ kOwnBackground
Definition GuiTypes.h:392
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:41
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
@ kButtonDown
Definition TGButton.h:54
@ kLHintsRight
Definition TGLayout.h:26
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsExpandX
Definition TGLayout.h:30
char name[80]
Definition TGX11.cxx:148
externTGeoManager * gGeoManager
ETGeoTrd2Wid
@ kTRD2_Y1
@ kTRD2_UNDO
@ kTRD2_X1
@ kTRD2_Y2
@ kTRD2_NAME
@ kTRD2_APPLY
@ kTRD2_Z
@ kTRD2_X2
Selects different options.
Definition TGButton.h:264
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
virtual TList * GetList() const
Definition TGFrame.h:312
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition TGFrame.cxx:959
TGCompositeFrame(const TGCompositeFrame &)=delete
TGFrame * fFrame
Definition TGLayout.h:112
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
virtual Bool_t IsComposite() const
Definition TGFrame.h:214
This class handles GUI labels.
Definition TGLabel.h:24
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
TGNumberEntry is a number entry input widget with up/down buttons.
@ kNEAPositive
Positive number.
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
ROOT GUI Window base class.
Definition TGWindow.h:23
Bool_t fInit
init flag for setting signals/slots
Definition TGedFrame.h:47
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition TGedFrame.cxx:94
void Update() override
Override Update from TGedFrame as fGedEditor can be null.
TVirtualPad * fPad
TGeoGedFrame(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor.
virtual void SetActive(Bool_t active=kTRUE)
Set active GUI attribute frames related to the selected object.
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hierarchically all daughters of a composite frame.
void DoName()
Perform name change.
~TGeoTrd2Editor() override
Destructor.
TGNumberEntry * fEDy2
void SetModel(TObject *obj) override
Connect to the selected object.
virtual void ConnectSignals2Slots()
Connect signals to slots.
TGeoTrd2Editor(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor for trd2 editor.
void DoApply()
Slot for applying modifications.
void DoModified()
Slot for signaling modifications.
Bool_t fIsShapeEditable
void DoDx1()
Slot for dx1.
TGTextButton * fUndo
TGCheckButton * fDelayed
TGNumberEntry * fEDz
void DoDz()
Slot for dz.
void DoUndo()
Slot for undoing last operation.
TGTextButton * fApply
TGNumberEntry * fEDx1
void DoDx2()
Slot for dx2.
TGNumberEntry * fEDy1
Bool_t IsDelayed() const
Check if shape drawing is delayed.
void DoDy2()
Slot for dy2.
TGTextEntry * fShapeName
void DoDy1()
Slot for dy1.
TGNumberEntry * fEDx2
TGeoTrd2 * fShape
static TClass * Class()
Mother of all ROOT objects.
Definition TObject.h:42
virtual TClass * IsA() const
Definition TObject.h:248
TF1 * f1
Definition legend1.C:11