Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TGeoBBoxEditor.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 TGeoBBoxEditor
13\ingroup Geometry_builder
14
15Editor for a TGeoBBox.
16
17\image html geom_box_pic.png
18
19\image html geom_box_ed.png
20
21*/
22
23#include "TGeoBBoxEditor.h"
24#include "TGeoTabManager.h"
25#include "TGeoBBox.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 volume editor.
40
41TGeoBBoxEditor::TGeoBBoxEditor(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 fDxi = fDyi = fDzi = 0.0;
46 memset(fOrigi, 0, 3 * sizeof(Double_t));
47 fNamei = "";
50
51 // TextEntry for shape name
52 MakeTitle("Name");
53 fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kBOX_NAME);
54 fShapeName->Resize(135, fShapeName->GetDefaultHeight());
55 fShapeName->SetToolTipText("Enter the box name");
56 fShapeName->Associate(this);
58
59 TGTextEntry *nef;
60 MakeTitle("Box half-lengths");
62 // Number entry for dx
65 f1->AddFrame(new TGLabel(f1, "DX"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
66 fBoxDx = new TGNumberEntry(f1, 0., 5, kBOX_X);
68 nef = (TGTextEntry *)fBoxDx->GetNumberEntry();
69 nef->SetToolTipText("Enter the box half-length in X");
70 fBoxDx->Associate(this);
71 f1->AddFrame(fBoxDx, 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 dy
77 f2->AddFrame(new TGLabel(f2, "DY"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
78 fBoxDy = new TGNumberEntry(f2, 0., 5, kBOX_Y);
80 nef = (TGTextEntry *)fBoxDy->GetNumberEntry();
81 nef->SetToolTipText("Enter the box half-length in Y");
82 fBoxDy->Associate(this);
84 compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
85
86 // Number entry for dx
89 f3->AddFrame(new TGLabel(f3, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
90 fBoxDz = new TGNumberEntry(f3, 0., 5, kBOX_Z);
92 nef = (TGTextEntry *)fBoxDz->GetNumberEntry();
93 nef->SetToolTipText("Enter the box half-length in Z");
94 fBoxDz->Associate(this);
96 compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
97
98 compxyz->Resize(150, 30);
99 AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
100
101 MakeTitle("Box origin");
102 compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame | kDoubleBorder);
103 // Number entry for dx
105 f1->AddFrame(new TGLabel(f1, "OX"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
106 fBoxOx = new TGNumberEntry(f1, 0., 5, kBOX_OX);
107 nef = (TGTextEntry *)fBoxOx->GetNumberEntry();
108 nef->SetToolTipText("Enter the box origin X coordinate");
109 fBoxOx->Associate(this);
110 f1->AddFrame(fBoxOx, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
111 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
112
113 // Number entry for dy
114 f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame | kFitWidth | kFixedWidth | kOwnBackground);
115 f2->AddFrame(new TGLabel(f2, "OY"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
116 fBoxOy = new TGNumberEntry(f2, 0., 5, kBOX_OY);
117 nef = (TGTextEntry *)fBoxOy->GetNumberEntry();
118 nef->SetToolTipText("Enter the box origin Y coordinate");
119 fBoxOy->Associate(this);
120 f2->AddFrame(fBoxOy, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
121 compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
122
123 // Number entry for dx
124 f3 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame | kFitWidth | kFixedWidth | kOwnBackground);
125 f3->AddFrame(new TGLabel(f3, "OZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
126 fBoxOz = new TGNumberEntry(f3, 0., 5, kBOX_OZ);
127 nef = (TGTextEntry *)fBoxOz->GetNumberEntry();
128 nef->SetToolTipText("Enter the box origin Z coordinate");
129 fBoxOz->Associate(this);
130 f3->AddFrame(fBoxOz, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
131 compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
132
133 compxyz->Resize(150, 30);
134 AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
135
136 // Delayed draw
138 fDelayed = new TGCheckButton(f1, "Delayed draw");
139 f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
140 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
141
142 // Buttons
143 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
144 fApply = new TGTextButton(f1, "Apply");
145 f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
146 fApply->Associate(this);
147 fUndo = new TGTextButton(f1, "Undo");
148 f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
149 fUndo->Associate(this);
150 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
151 fUndo->SetSize(fApply->GetSize());
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Destructor.
156
158{
159 TGFrameElement *el;
160 TIter next(GetList());
161 while ((el = (TGFrameElement *)next())) {
162 if (el->fFrame->IsComposite())
164 }
165 Cleanup();
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Connect signals to slots.
170
172{
173 fApply->Connect("Clicked()", "TGeoBBoxEditor", this, "DoApply()");
174 fUndo->Connect("Clicked()", "TGeoBBoxEditor", this, "DoUndo()");
175 fShapeName->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
176 fBoxDx->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoDx()");
177 fBoxDy->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoDy()");
178 fBoxDz->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoDz()");
179 fBoxDx->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
180 fBoxDy->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
181 fBoxDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
182 fBoxOx->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoOx()");
183 fBoxOy->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoOy()");
184 fBoxOz->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoOz()");
185 fBoxOx->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
186 fBoxOy->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
187 fBoxOz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
188 fInit = kFALSE;
189}
190
191////////////////////////////////////////////////////////////////////////////////
192/// Update editor for a new selected box.
193
195{
196 if (obj == nullptr || (obj->IsA() != TGeoBBox::Class())) {
198 return;
199 }
200 fShape = (TGeoBBox *)obj;
201 fDxi = fShape->GetDX();
202 fDyi = fShape->GetDY();
203 fDzi = fShape->GetDZ();
204 memcpy(fOrigi, fShape->GetOrigin(), 3 * sizeof(Double_t));
205 const char *sname = fShape->GetName();
206 if (!strcmp(sname, fShape->ClassName()))
207 fShapeName->SetText("-no_name");
208 else {
209 fShapeName->SetText(sname);
210 fNamei = sname;
211 }
212 fBoxDx->SetNumber(fDxi);
213 fBoxDy->SetNumber(fDyi);
214 fBoxDz->SetNumber(fDzi);
215 fBoxOx->SetNumber(fOrigi[0]);
216 fBoxOy->SetNumber(fOrigi[1]);
217 fBoxOz->SetNumber(fOrigi[2]);
218 fApply->SetEnabled(kFALSE);
219 fUndo->SetEnabled(kFALSE);
220
221 if (fInit)
223 SetActive();
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Check if shape drawing is delayed.
228
230{
231 return (fDelayed->GetState() == kButtonDown);
232}
233
234////////////////////////////////////////////////////////////////////////////////
235/// Slot for name.
236
238{
239 DoModified();
240}
241
242////////////////////////////////////////////////////////////////////////////////
243/// Slot for applying current parameters.
244
246{
247 const char *name = fShapeName->GetText();
248 if (strcmp(name, fShape->GetName()))
249 fShape->SetName(name);
250 Double_t dx = fBoxDx->GetNumber();
251 Double_t dy = fBoxDy->GetNumber();
252 Double_t dz = fBoxDz->GetNumber();
253 Double_t orig[3];
254 orig[0] = fBoxOx->GetNumber();
255 orig[1] = fBoxOy->GetNumber();
256 orig[2] = fBoxOz->GetNumber();
257 fShape->SetBoxDimensions(dx, dy, dz, orig);
258 fUndo->SetEnabled();
259 fApply->SetEnabled(kFALSE);
260 if (fPad) {
261 if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
262 TView *view = fPad->GetView();
263 if (!view) {
264 fShape->Draw();
265 fPad->GetView()->ShowAxis();
266 } else {
267 const Double_t *origin = fShape->GetOrigin();
268 view->SetRange(origin[0] - fShape->GetDX(), origin[1] - fShape->GetDY(), origin[2] - fShape->GetDZ(),
269 origin[0] + fShape->GetDX(), origin[1] + fShape->GetDY(), origin[2] + fShape->GetDZ());
270 Update();
271 }
272 } else
273 Update();
274 }
275}
276
277////////////////////////////////////////////////////////////////////////////////
278/// Slot for modifying current parameters.
279
281{
282 fApply->SetEnabled();
283}
284
285////////////////////////////////////////////////////////////////////////////////
286/// Slot for undoing last operation.
287
289{
290 fBoxDx->SetNumber(fDxi);
291 fBoxDy->SetNumber(fDyi);
292 fBoxDz->SetNumber(fDzi);
293 fBoxOx->SetNumber(fOrigi[0]);
294 fBoxOy->SetNumber(fOrigi[1]);
295 fBoxOz->SetNumber(fOrigi[2]);
296 DoApply();
297 fUndo->SetEnabled(kFALSE);
298 fApply->SetEnabled(kFALSE);
299}
300
301////////////////////////////////////////////////////////////////////////////////
302/// Slot for Dx modification.
303
305{
306 Double_t dx = fBoxDx->GetNumber();
307 if (dx <= 0) {
308 dx = 0.1;
309 fBoxDx->SetNumber(dx);
310 }
311 DoModified();
312 if (!IsDelayed())
313 DoApply();
314}
315
316////////////////////////////////////////////////////////////////////////////////
317/// Slot for Dy modification.
318
320{
321 Double_t dy = fBoxDy->GetNumber();
322 if (dy <= 0) {
323 dy = 0.1;
324 fBoxDy->SetNumber(dy);
325 }
326 DoModified();
327 if (!IsDelayed())
328 DoApply();
329}
330
331////////////////////////////////////////////////////////////////////////////////
332/// Slot for Dz modification.
333
335{
336 Double_t dz = fBoxDz->GetNumber();
337 if (dz <= 0) {
338 dz = 0.1;
339 fBoxDz->SetNumber(dz);
340 }
341 DoModified();
342 if (!IsDelayed())
343 DoApply();
344}
345
346////////////////////////////////////////////////////////////////////////////////
347/// Slot for Ox modification.
348
350{
351 DoModified();
352 if (!IsDelayed())
353 DoApply();
354}
355
356////////////////////////////////////////////////////////////////////////////////
357/// Slot for Oy modification.
358
360{
361 DoModified();
362 if (!IsDelayed())
363 DoApply();
364}
365
366////////////////////////////////////////////////////////////////////////////////
367/// Slot for Oz modification.
368
370{
371 DoModified();
372 if (!IsDelayed())
373 DoApply();
374}
@ 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
ETGeoBBoxWid
@ kBOX_OZ
@ kBOX_CANCEL
@ kBOX_OX
@ kBOX_APPLY
@ kBOX_Y
@ kBOX_Z
@ kBOX_OY
@ kBOX_NAME
@ kBOX_X
@ kBOX_UNDO
externTGeoManager * gGeoManager
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 DoDy()
Slot for Dy modification.
TGTextButton * fUndo
void SetModel(TObject *obj) override
Update editor for a new selected box.
TGNumberEntry * fBoxDx
TGNumberEntry * fBoxDy
TGTextEntry * fShapeName
TGNumberEntry * fBoxOy
void DoApply()
Slot for applying current parameters.
TGeoBBoxEditor(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor for volume editor.
void DoDz()
Slot for Dz modification.
TGeoBBox * fShape
TGCheckButton * fDelayed
void DoOz()
Slot for Oz modification.
TGNumberEntry * fBoxOx
Double_t fOrigi[3]
void DoUndo()
Slot for undoing last operation.
void DoDx()
Slot for Dx modification.
Bool_t fIsShapeEditable
void DoName()
Slot for name.
void DoModified()
Slot for modifying current parameters.
void DoOx()
Slot for Ox modification.
void DoOy()
Slot for Oy modification.
~TGeoBBoxEditor() override
Destructor.
Bool_t IsDelayed() const
Check if shape drawing is delayed.
virtual void ConnectSignals2Slots()
Connect signals to slots.
TGNumberEntry * fBoxOz
TGNumberEntry * fBoxDz
TGTextButton * fApply
static TClass * Class()
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.
Mother of all ROOT objects.
Definition TObject.h:42
virtual TClass * IsA() const
Definition TObject.h:248
See TView3D.
Definition TView.h:25
virtual void SetRange(const Double_t *min, const Double_t *max)=0
TF1 * f1
Definition legend1.C:11