37 ClassImp(TGeoPconEditor);
40 kPCON_NAME, kPCON_NZ, kPCON_PHI1, kPCON_DPHI, kPCON_APPLY, kPCON_UNDO
46 TGeoPconEditor::TGeoPconEditor(
const TGWindow *p, Int_t width,
47 Int_t height, UInt_t options, Pixel_t back)
48 : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
60 fIsShapeEditable = kFALSE;
62 fLHsect =
new TGLayoutHints(kLHintsTop | kLHintsLeft, 0,0,2,2);
66 fShapeName =
new TGTextEntry(
this,
new TGTextBuffer(50), kPCON_NAME);
67 fShapeName->Resize(135, fShapeName->GetDefaultHeight());
68 fShapeName->SetToolTipText(
"Enter the polycone name");
69 fShapeName->Associate(
this);
70 AddFrame(fShapeName,
new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
72 MakeTitle(
"Parameters");
75 TGCompositeFrame *f1 =
new TGCompositeFrame(
this, 155, 10, kHorizontalFrame | kFixedWidth);
76 f1->AddFrame(
new TGLabel(f1,
"Nz"),
new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
77 fENz =
new TGNumberEntry(f1, 0., 5, kPCON_NZ);
78 fENz->SetNumAttr(TGNumberFormat::kNEAPositive);
79 fENz->SetNumStyle(TGNumberFormat::kNESInteger);
80 fENz->Resize(100,fENz->GetDefaultHeight());
81 nef = (TGTextEntry*)fENz->GetNumberEntry();
82 nef->SetToolTipText(
"Enter the number of Z sections");
83 fENz->Associate(
this);
84 f1->AddFrame(fENz,
new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
85 AddFrame(f1,
new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
88 f1 =
new TGCompositeFrame(
this, 155, 10, kHorizontalFrame | kFixedWidth);
89 f1->AddFrame(
new TGLabel(f1,
"Phi1"),
new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
90 fEPhi1 =
new TGNumberEntry(f1, 0., 5, kPCON_PHI1);
91 fEPhi1->Resize(100,fEPhi1->GetDefaultHeight());
92 nef = (TGTextEntry*)fEPhi1->GetNumberEntry();
93 nef->SetToolTipText(
"Enter the starting phi angle [deg]");
94 fEPhi1->Associate(
this);
95 f1->AddFrame(fEPhi1,
new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
96 AddFrame(f1,
new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
99 f1 =
new TGCompositeFrame(
this, 155, 10, kHorizontalFrame | kFixedWidth);
100 f1->AddFrame(
new TGLabel(f1,
"Dphi"),
new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
101 fEDPhi =
new TGNumberEntry(f1, 0., 5, kPCON_DPHI);
102 fEDPhi->SetNumAttr(TGNumberFormat::kNEAPositive);
103 fEDPhi->Resize(100,fEDPhi->GetDefaultHeight());
104 nef = (TGTextEntry*)fEDPhi->GetNumberEntry();
105 nef->SetToolTipText(
"Enter the phi range [deg]");
106 fEDPhi->Associate(
this);
107 f1->AddFrame(fEDPhi,
new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
108 AddFrame(f1,
new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
111 MakeTitle(
"Pcon sections");
112 fCan =
new TGCanvas(
this, 160, 200, kSunkenFrame | kDoubleBorder);
113 TGCompositeFrame *cont =
new TGCompositeFrame(fCan->GetViewPort(), 155, 20, kVerticalFrame | kFixedWidth);
114 fCan->SetContainer(cont);
116 f1 =
new TGCompositeFrame(cont, 160, 10, kHorizontalFrame | kFixedWidth);
117 f1->AddFrame(
new TGLabel(f1,
"#"),
new TGLayoutHints(kLHintsLeft, 2, 20, 6, 0));
118 f1->AddFrame(
new TGLabel(f1,
"Z"),
new TGLayoutHints(kLHintsLeft, 2, 20, 6, 0));
119 f1->AddFrame(
new TGLabel(f1,
"Rmin"),
new TGLayoutHints(kLHintsLeft, 2, 20, 6, 0));
120 f1->AddFrame(
new TGLabel(f1,
"Rmax"),
new TGLayoutHints(kLHintsLeft, 2, 10, 6, 0));
121 cont->AddFrame(f1,
new TGLayoutHints(kLHintsLeft, 0,0,0,0));
124 AddFrame(fCan,
new TGLayoutHints(kLHintsLeft, 0, 0, 4, 4));
127 fDFrame =
new TGCompositeFrame(
this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
128 fDelayed =
new TGCheckButton(fDFrame,
"Delayed draw");
129 fDFrame->AddFrame(fDelayed,
new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
130 AddFrame(fDFrame,
new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
133 fBFrame =
new TGCompositeFrame(
this, 155, 10, kHorizontalFrame | kFixedWidth);
134 fApply =
new TGTextButton(fBFrame,
"Apply");
135 fBFrame->AddFrame(fApply,
new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
136 fApply->Associate(
this);
137 fUndo =
new TGTextButton(fBFrame,
"Undo");
138 fBFrame->AddFrame(fUndo,
new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
139 fUndo->Associate(
this);
140 AddFrame(fBFrame,
new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
141 fUndo->SetSize(fApply->GetSize());
147 TGeoPconEditor::~TGeoPconEditor()
149 if (fSections)
delete fSections;
150 if (fZi)
delete [] fZi;
151 if (fRmini)
delete [] fRmini;
152 if (fRmaxi)
delete [] fRmaxi;
154 TIter next(GetList());
155 while ((el = (TGFrameElement *)next())) {
156 if (el->fFrame->IsComposite())
157 TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
165 void TGeoPconEditor::ConnectSignals2Slots()
167 fENz->Connect(
"ValueSet(Long_t)",
"TGeoPconEditor",
this,
"DoNz()");
168 fEPhi1->Connect(
"ValueSet(Long_t)",
"TGeoPconEditor",
this,
"DoPhi()");
169 fEDPhi->Connect(
"ValueSet(Long_t)",
"TGeoPconEditor",
this,
"DoPhi()");
170 fApply->Connect(
"Clicked()",
"TGeoPconEditor",
this,
"DoApply()");
171 fUndo->Connect(
"Clicked()",
"TGeoPconEditor",
this,
"DoUndo()");
172 fShapeName->Connect(
"TextChanged(const char *)",
"TGeoPconEditor",
this,
"DoModified()");
180 void TGeoPconEditor::SetModel(TObject* obj)
182 if (obj == 0 || (obj->IsA() != TGeoPcon::Class())) {
186 fShape = (TGeoPcon*)obj;
187 const char *sname = fShape->GetName();
188 if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText(
"-no_name");
189 else fShapeName->SetText(sname);
191 Int_t nsections = fShape->GetNz();
193 fENz->SetNumber(nsections);
194 fEPhi1->SetNumber(fShape->GetPhi1());
195 fPhi1i = fShape->GetPhi1();
196 fEDPhi->SetNumber(fShape->GetDphi());
197 fDPhii = fShape->GetDphi();
198 CreateSections(nsections);
201 fApply->SetEnabled(kFALSE);
202 fUndo->SetEnabled(kFALSE);
204 if (fInit) ConnectSignals2Slots();
211 void TGeoPconEditor::CreateSections(Int_t inew)
213 if (inew == fNsections)
return;
214 if (!fSections) fSections =
new TObjArray(8);
215 TGCompositeFrame *cont = (TGCompositeFrame*)fCan->GetContainer();
216 TGeoPconSection *sect;
219 if (inew>fNsections) {
220 for (isect=fNsections; isect<inew; isect++) {
221 sect =
new TGeoPconSection(cont, 150, 10, isect);
222 fSections->Add(sect);
223 cont->AddFrame(sect, fLHsect);
224 sect->Connect(
"Changed(Int_t)",
"TGeoPconEditor",
this,
"DoSectionChange(Int_t)");
228 for (isect=inew; isect<fNsections; isect++) {
229 sect = (TGeoPconSection*)fSections->At(isect);
230 sect->HideDaughters();
231 cont->HideFrame(sect);
232 cont->RemoveFrame(sect);
234 fSections->RemoveAt(isect);
239 fCan->MapSubwindows();
248 Bool_t TGeoPconEditor::CheckSections(Bool_t change)
250 TGeoPconSection *sect;
252 Double_t rmin = 0, rmax = 1.;
253 for (Int_t isect=0; isect<fNsections; isect++) {
254 sect = (TGeoPconSection*)fSections->At(isect);
255 if (isect && (sect->GetZ()<zmin)) {
256 if (!change)
return kFALSE;
260 if (sect->GetRmin()<0 ||
261 (sect->GetRmax()<0) || ((sect->GetRmin()==0) && (sect->GetRmax()==0))) {
262 if (!change)
return kFALSE;
266 rmin = sect->GetRmin();
267 rmax = sect->GetRmax();
275 void TGeoPconEditor::UpdateSections()
277 if (fZi)
delete [] fZi;
278 if (fRmini)
delete [] fRmini;
279 if (fRmaxi)
delete [] fRmaxi;
280 fZi =
new Double_t[fNsections];
281 fRmini =
new Double_t[fNsections];
282 fRmaxi =
new Double_t[fNsections];
283 TGeoPconSection *sect;
284 for (Int_t isect=0; isect<fNsections; isect++) {
285 sect = (TGeoPconSection*)fSections->At(isect);
286 sect->SetZ(fShape->GetZ(isect));
287 fZi[isect] = fShape->GetZ(isect);
288 sect->SetRmin(fShape->GetRmin(isect));
289 fRmini[isect] = fShape->GetRmin(isect);
290 sect->SetRmax(fShape->GetRmax(isect));
291 fRmaxi[isect] = fShape->GetRmax(isect);
298 Bool_t TGeoPconEditor::IsDelayed()
const
300 return (fDelayed->GetState() == kButtonDown);
306 void TGeoPconEditor::DoName()
314 void TGeoPconEditor::DoApply()
316 const char *name = fShapeName->GetText();
317 if (strcmp(name,fShape->GetName())) fShape->SetName(name);
318 fApply->SetEnabled(kFALSE);
320 if (!CheckSections())
return;
322 Bool_t recreate = kFALSE;
323 Int_t nz = fENz->GetIntNumber();
324 Double_t phi1 = fEPhi1->GetNumber();
325 Double_t dphi = fEDPhi->GetNumber();
326 if (nz != fShape->GetNz()) recreate = kTRUE;
327 TGeoPconSection *sect;
330 Double_t *array =
new Double_t[3*(nz+1)];
334 for (isect=0; isect<nz; isect++) {
335 sect = (TGeoPconSection*)fSections->At(isect);
336 array[3+3*isect] = sect->GetZ();
337 array[4+3*isect] = sect->GetRmin();
338 array[5+3*isect] = sect->GetRmax();
340 fShape->SetDimensions(array);
343 if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
344 TView *view = fPad->GetView();
347 fPad->GetView()->ShowAxis();
349 const Double_t *orig = fShape->GetOrigin();
350 view->SetRange(orig[0]-fShape->GetDX(), orig[1]-fShape->GetDY(), orig[2]-fShape->GetDZ(),
351 orig[0]+fShape->GetDX(), orig[1]+fShape->GetDY(), orig[2]+fShape->GetDZ());
359 if (TMath::Abs(phi1-fShape->GetPhi1())>1.e-6) fShape->Phi1() = phi1;
360 if (TMath::Abs(dphi-fShape->GetDphi())>1.e-6) fShape->Dphi() = dphi;
361 for (isect=0; isect<fNsections; isect++) {
362 sect = (TGeoPconSection*)fSections->At(isect);
363 fShape->Z(isect) = sect->GetZ();
364 fShape->Rmin(isect) = sect->GetRmin();
365 fShape->Rmax(isect) = sect->GetRmax();
367 fShape->ComputeBBox();
369 if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
370 TView *view = fPad->GetView();
373 fPad->GetView()->ShowAxis();
375 const Double_t *orig = fShape->GetOrigin();
376 view->SetRange(orig[0]-fShape->GetDX(), orig[1]-fShape->GetDY(), orig[2]-fShape->GetDZ(),
377 orig[0]+fShape->GetDX(), orig[1]+fShape->GetDY(), orig[2]+fShape->GetDZ());
387 void TGeoPconEditor::DoSectionChange(Int_t isect)
389 TGeoPconSection *sect, *sectlo=0, *secthi=0;
390 sect = (TGeoPconSection*)fSections->At(isect);
391 if (isect) sectlo = (TGeoPconSection*)fSections->At(isect-1);
392 if (isect<fNsections-1) secthi = (TGeoPconSection*)fSections->At(isect+1);
393 Double_t z = sect->GetZ();
394 if (sectlo && z<sectlo->GetZ()) {
398 if (secthi && z>secthi->GetZ()) {
403 if (!IsDelayed()) DoApply();
409 void TGeoPconEditor::DoNz()
411 Int_t nz = fENz->GetIntNumber();
417 CheckSections(kTRUE);
419 if (!IsDelayed()) DoApply();
425 void TGeoPconEditor::DoPhi()
427 Double_t phi1 = fEPhi1->GetNumber();
428 Double_t dphi = fEDPhi->GetNumber();
429 if (TMath::Abs(phi1)>360) fEPhi1->SetNumber(0);
430 if (dphi>360) fEDPhi->SetNumber(360);
432 if (!IsDelayed()) DoApply();
438 void TGeoPconEditor::DoModified()
440 fApply->SetEnabled();
446 void TGeoPconEditor::DoUndo()
448 fENz->SetNumber(fNsecti);
449 CreateSections(fNsecti);
450 fEPhi1->SetNumber(fPhi1i);
451 fEDPhi->SetNumber(fDPhii);
452 TGeoPconSection *sect;
453 for (Int_t isect=0; isect<fNsections; isect++) {
454 sect = (TGeoPconSection*)fSections->At(isect);
455 sect->SetZ(fZi[isect]);
456 sect->SetRmin(fRmini[isect]);
457 sect->SetRmax(fRmaxi[isect]);
460 fUndo->SetEnabled(kFALSE);
461 fApply->SetEnabled(kFALSE);
471 ClassImp(TGeoPconSection);
476 TGeoPconSection::TGeoPconSection(
const TGWindow *p, UInt_t w, UInt_t h, Int_t
id)
477 :TGCompositeFrame(p,w,h,kHorizontalFrame | kFixedWidth)
482 AddFrame(
new TGLabel(
this, TString::Format(
"#%i",
id)),
new TGLayoutHints(kLHintsLeft, 2, 4, 6, 0));
485 fEZ =
new TGNumberEntry(
this, 0., 5);
486 fEZ->Resize(40,fEZ->GetDefaultHeight());
487 nef = (TGTextEntry*)fEZ->GetNumberEntry();
488 nef->SetToolTipText(
"Enter the Z position");
489 fEZ->Associate(
this);
490 AddFrame(fEZ,
new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
492 fERmin =
new TGNumberEntry(
this, 0., 5);
493 fERmin->SetNumAttr(TGNumberFormat::kNEAPositive);
494 fERmin->Resize(40,fERmin->GetDefaultHeight());
495 nef = (TGTextEntry*)fERmin->GetNumberEntry();
496 nef->SetToolTipText(
"Enter the minimum radius");
497 fERmin->Associate(
this);
498 AddFrame(fERmin,
new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
500 fERmax =
new TGNumberEntry(
this, 0., 5);
501 fERmax->SetNumAttr(TGNumberFormat::kNEAPositive);
502 fERmax->Resize(40,fERmax->GetDefaultHeight());
503 nef = (TGTextEntry*)fERmax->GetNumberEntry();
504 nef->SetToolTipText(
"Enter the maximum radius");
505 fERmax->Associate(
this);
506 AddFrame(fERmax,
new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
508 ConnectSignals2Slots();
516 TGeoPconSection::~TGeoPconSection()
524 void TGeoPconSection::HideDaughters()
527 fERmin->UnmapWindow();
528 fERmax->UnmapWindow();
534 void TGeoPconSection::Changed(Int_t i)
536 Emit(
"Changed(Int_t)", i);
542 void TGeoPconSection::ConnectSignals2Slots()
544 fEZ->Connect(
"ValueSet(Long_t)",
"TGeoPconSection",
this,
"DoZ()");
545 fERmin->Connect(
"ValueSet(Long_t)",
"TGeoPconSection",
this,
"DoRmin()");
546 fERmax->Connect(
"ValueSet(Long_t)",
"TGeoPconSection",
this,
"DoRmax()");
552 Double_t TGeoPconSection::GetZ()
const
554 return fEZ->GetNumber();
560 Double_t TGeoPconSection::GetRmin()
const
562 return fERmin->GetNumber();
568 Double_t TGeoPconSection::GetRmax()
const
570 return fERmax->GetNumber();
576 void TGeoPconSection::SetZ(Double_t z)
584 void TGeoPconSection::SetRmin(Double_t rmin)
586 fERmin->SetNumber(rmin);
592 void TGeoPconSection::SetRmax(Double_t rmax)
594 fERmax->SetNumber(rmax);
600 void TGeoPconSection::DoZ()
608 void TGeoPconSection::DoRmin()
610 Double_t rmin = fERmin->GetNumber();
611 Double_t rmax = fERmax->GetNumber();
612 if (rmin>rmax-1.e-8) fERmin->SetNumber(rmax);
619 void TGeoPconSection::DoRmax()
621 Double_t rmin = fERmin->GetNumber();
622 Double_t rmax = fERmax->GetNumber();
623 if (rmax<rmin+1.e-8) fERmax->SetNumber(rmin);