00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "TGeoPconEditor.h"
00029 #include "TGeoTabManager.h"
00030 #include "TGeoPcon.h"
00031 #include "TGeoManager.h"
00032 #include "TVirtualGeoPainter.h"
00033 #include "TPad.h"
00034 #include "TView.h"
00035 #include "TGTab.h"
00036 #include "TGComboBox.h"
00037 #include "TGButton.h"
00038 #include "TGTextEntry.h"
00039 #include "TGNumberEntry.h"
00040 #include "TGLabel.h"
00041
00042 ClassImp(TGeoPconEditor)
00043
00044 enum ETGeoPconWid {
00045 kPCON_NAME, kPCON_NZ, kPCON_PHI1, kPCON_DPHI, kPCON_APPLY, kPCON_UNDO
00046 };
00047
00048
00049 TGeoPconEditor::TGeoPconEditor(const TGWindow *p, Int_t width,
00050 Int_t height, UInt_t options, Pixel_t back)
00051 : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
00052 {
00053
00054 fShape = 0;
00055 fNsections = 0;
00056 fSections = 0;
00057 fNsecti = 0;
00058 fPhi1i = 0;
00059 fDPhii = 0;
00060 fZi = 0;
00061 fRmini = 0;
00062 fRmaxi = 0;
00063 fIsModified = kFALSE;
00064 fIsShapeEditable = kFALSE;
00065
00066 fLHsect = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0,0,2,2);
00067
00068
00069 MakeTitle("Name");
00070 fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kPCON_NAME);
00071 fShapeName->Resize(135, fShapeName->GetDefaultHeight());
00072 fShapeName->SetToolTipText("Enter the polycone name");
00073 fShapeName->Associate(this);
00074 AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
00075
00076 MakeTitle("Parameters");
00077
00078 TGTextEntry *nef;
00079 TGCompositeFrame *f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00080 f1->AddFrame(new TGLabel(f1, "Nz"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00081 fENz = new TGNumberEntry(f1, 0., 5, kPCON_NZ);
00082 fENz->SetNumAttr(TGNumberFormat::kNEAPositive);
00083 fENz->SetNumStyle(TGNumberFormat::kNESInteger);
00084 fENz->Resize(100,fENz->GetDefaultHeight());
00085 nef = (TGTextEntry*)fENz->GetNumberEntry();
00086 nef->SetToolTipText("Enter the number of Z sections");
00087 fENz->Associate(this);
00088 f1->AddFrame(fENz, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
00089 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00090
00091
00092 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00093 f1->AddFrame(new TGLabel(f1, "Phi1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00094 fEPhi1 = new TGNumberEntry(f1, 0., 5, kPCON_PHI1);
00095 fEPhi1->Resize(100,fEPhi1->GetDefaultHeight());
00096 nef = (TGTextEntry*)fEPhi1->GetNumberEntry();
00097 nef->SetToolTipText("Enter the starting phi angle [deg]");
00098 fEPhi1->Associate(this);
00099 f1->AddFrame(fEPhi1, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
00100 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00101
00102
00103 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00104 f1->AddFrame(new TGLabel(f1, "Dphi"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00105 fEDPhi = new TGNumberEntry(f1, 0., 5, kPCON_DPHI);
00106 fEDPhi->SetNumAttr(TGNumberFormat::kNEAPositive);
00107 fEDPhi->Resize(100,fEDPhi->GetDefaultHeight());
00108 nef = (TGTextEntry*)fEDPhi->GetNumberEntry();
00109 nef->SetToolTipText("Enter the phi range [deg]");
00110 fEDPhi->Associate(this);
00111 f1->AddFrame(fEDPhi, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
00112 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00113
00114
00115 MakeTitle("Pcon sections");
00116 fCan = new TGCanvas(this, 160, 200, kSunkenFrame | kDoubleBorder);
00117 TGCompositeFrame *cont = new TGCompositeFrame(fCan->GetViewPort(), 155, 20, kVerticalFrame | kFixedWidth);
00118 fCan->SetContainer(cont);
00119
00120 f1 = new TGCompositeFrame(cont, 160, 10, kHorizontalFrame | kFixedWidth);
00121 f1->AddFrame(new TGLabel(f1, "#"), new TGLayoutHints(kLHintsLeft, 2, 20, 6, 0));
00122 f1->AddFrame(new TGLabel(f1, "Z"), new TGLayoutHints(kLHintsLeft, 2, 20, 6, 0));
00123 f1->AddFrame(new TGLabel(f1, "Rmin"), new TGLayoutHints(kLHintsLeft, 2, 20, 6, 0));
00124 f1->AddFrame(new TGLabel(f1, "Rmax"), new TGLayoutHints(kLHintsLeft, 2, 10, 6, 0));
00125 cont->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 0,0,0,0));
00126 CreateSections(2);
00127
00128 AddFrame(fCan, new TGLayoutHints(kLHintsLeft, 0, 0, 4, 4));
00129
00130
00131 fDFrame = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
00132 fDelayed = new TGCheckButton(fDFrame, "Delayed draw");
00133 fDFrame->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
00134 AddFrame(fDFrame, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00135
00136
00137 fBFrame = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00138 fApply = new TGTextButton(fBFrame, "Apply");
00139 fBFrame->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00140 fApply->Associate(this);
00141 fUndo = new TGTextButton(fBFrame, "Undo");
00142 fBFrame->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
00143 fUndo->Associate(this);
00144 AddFrame(fBFrame, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00145 fUndo->SetSize(fApply->GetSize());
00146 }
00147
00148
00149 TGeoPconEditor::~TGeoPconEditor()
00150 {
00151
00152 if (fSections) delete fSections;
00153 if (fZi) delete [] fZi;
00154 if (fRmini) delete [] fRmini;
00155 if (fRmaxi) delete [] fRmaxi;
00156 TGFrameElement *el;
00157 TIter next(GetList());
00158 while ((el = (TGFrameElement *)next())) {
00159 if (el->fFrame->IsComposite())
00160 TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00161 }
00162 Cleanup();
00163 }
00164
00165
00166 void TGeoPconEditor::ConnectSignals2Slots()
00167 {
00168
00169 fENz->Connect("ValueSet(Long_t)", "TGeoPconEditor", this, "DoNz()");
00170 fEPhi1->Connect("ValueSet(Long_t)", "TGeoPconEditor", this, "DoPhi()");
00171 fEDPhi->Connect("ValueSet(Long_t)", "TGeoPconEditor", this, "DoPhi()");
00172 fApply->Connect("Clicked()", "TGeoPconEditor", this, "DoApply()");
00173 fUndo->Connect("Clicked()", "TGeoPconEditor", this, "DoUndo()");
00174 fShapeName->Connect("TextChanged(const char *)", "TGeoPconEditor", this, "DoModified()");
00175 fInit = kFALSE;
00176 }
00177
00178
00179
00180 void TGeoPconEditor::SetModel(TObject* obj)
00181 {
00182
00183 if (obj == 0 || (obj->IsA() != TGeoPcon::Class())) {
00184 SetActive(kFALSE);
00185 return;
00186 }
00187 fShape = (TGeoPcon*)obj;
00188 const char *sname = fShape->GetName();
00189 if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
00190 else fShapeName->SetText(sname);
00191
00192 Int_t nsections = fShape->GetNz();
00193 fNsecti = nsections;
00194 fENz->SetNumber(nsections);
00195 fEPhi1->SetNumber(fShape->GetPhi1());
00196 fPhi1i = fShape->GetPhi1();
00197 fEDPhi->SetNumber(fShape->GetDphi());
00198 fDPhii = fShape->GetDphi();
00199 CreateSections(nsections);
00200 UpdateSections();
00201
00202 fApply->SetEnabled(kFALSE);
00203 fUndo->SetEnabled(kFALSE);
00204
00205 if (fInit) ConnectSignals2Slots();
00206 SetActive();
00207 }
00208
00209
00210 void TGeoPconEditor::CreateSections(Int_t inew)
00211 {
00212
00213 if (inew == fNsections) return;
00214 if (!fSections) fSections = new TObjArray(8);
00215 TGCompositeFrame *cont = (TGCompositeFrame*)fCan->GetContainer();
00216 TGeoPconSection *sect;
00217 Int_t isect;
00218
00219 if (inew>fNsections) {
00220 for (isect=fNsections; isect<inew; isect++) {
00221 sect = new TGeoPconSection(cont, 150, 10, isect);
00222 fSections->Add(sect);
00223 cont->AddFrame(sect, fLHsect);
00224 sect->Connect("Changed(Int_t)", "TGeoPconEditor", this, "DoSectionChange(Int_t)");
00225 }
00226 } else {
00227
00228 for (isect=inew; isect<fNsections; isect++) {
00229 sect = (TGeoPconSection*)fSections->At(isect);
00230 sect->HideDaughters();
00231 cont->HideFrame(sect);
00232 cont->RemoveFrame(sect);
00233
00234 fSections->RemoveAt(isect);
00235 delete sect;
00236 }
00237 }
00238 fNsections = inew;
00239 fCan->MapSubwindows();
00240 cont->Layout();
00241 cont->MapWindow();
00242 fCan->Layout();
00243 }
00244
00245
00246 Bool_t TGeoPconEditor::CheckSections(Bool_t change)
00247 {
00248
00249 TGeoPconSection *sect;
00250 Double_t zmin = 0;
00251 Double_t rmin = 0, rmax = 1.;
00252 for (Int_t isect=0; isect<fNsections; isect++) {
00253 sect = (TGeoPconSection*)fSections->At(isect);
00254 if (isect && (sect->GetZ()<zmin)) {
00255 if (!change) return kFALSE;
00256 sect->SetZ(zmin+1.);
00257 }
00258 zmin = sect->GetZ();
00259 if (sect->GetRmin()<0 ||
00260 (sect->GetRmax()<0) || ((sect->GetRmin()==0) && (sect->GetRmax()==0))) {
00261 if (!change) return kFALSE;
00262 sect->SetRmin(rmin);
00263 sect->SetRmax(rmax);
00264 }
00265 rmin = sect->GetRmin();
00266 rmax = sect->GetRmax();
00267 }
00268 return kTRUE;
00269 }
00270
00271
00272 void TGeoPconEditor::UpdateSections()
00273 {
00274
00275 if (fZi) delete [] fZi;
00276 if (fRmini) delete [] fRmini;
00277 if (fRmaxi) delete [] fRmaxi;
00278 fZi = new Double_t[fNsections];
00279 fRmini = new Double_t[fNsections];
00280 fRmaxi = new Double_t[fNsections];
00281 TGeoPconSection *sect;
00282 for (Int_t isect=0; isect<fNsections; isect++) {
00283 sect = (TGeoPconSection*)fSections->At(isect);
00284 sect->SetZ(fShape->GetZ(isect));
00285 fZi[isect] = fShape->GetZ(isect);
00286 sect->SetRmin(fShape->GetRmin(isect));
00287 fRmini[isect] = fShape->GetRmin(isect);
00288 sect->SetRmax(fShape->GetRmax(isect));
00289 fRmaxi[isect] = fShape->GetRmax(isect);
00290 }
00291 }
00292
00293
00294 Bool_t TGeoPconEditor::IsDelayed() const
00295 {
00296
00297 return (fDelayed->GetState() == kButtonDown);
00298 }
00299
00300
00301 void TGeoPconEditor::DoName()
00302 {
00303
00304 DoModified();
00305 }
00306
00307
00308 void TGeoPconEditor::DoApply()
00309 {
00310
00311 const char *name = fShapeName->GetText();
00312 if (strcmp(name,fShape->GetName())) fShape->SetName(name);
00313 fApply->SetEnabled(kFALSE);
00314 fUndo->SetEnabled();
00315 if (!CheckSections()) return;
00316
00317 Bool_t recreate = kFALSE;
00318 Int_t nz = fENz->GetIntNumber();
00319 Double_t phi1 = fEPhi1->GetNumber();
00320 Double_t dphi = fEDPhi->GetNumber();
00321 if (nz != fShape->GetNz()) recreate = kTRUE;
00322 TGeoPconSection *sect;
00323 Int_t isect;
00324 if (recreate) {
00325 Double_t *array = new Double_t[3*(nz+1)];
00326 array[0] = phi1;
00327 array[1] = dphi;
00328 array[2] = nz;
00329 for (isect=0; isect<nz; isect++) {
00330 sect = (TGeoPconSection*)fSections->At(isect);
00331 array[3+3*isect] = sect->GetZ();
00332 array[4+3*isect] = sect->GetRmin();
00333 array[5+3*isect] = sect->GetRmax();
00334 }
00335 fShape->SetDimensions(array);
00336 delete [] array;
00337 if (fPad) {
00338 if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00339 TView *view = fPad->GetView();
00340 if (!view) {
00341 fShape->Draw();
00342 fPad->GetView()->ShowAxis();
00343 } else {
00344 const Double_t *orig = fShape->GetOrigin();
00345 view->SetRange(orig[0]-fShape->GetDX(), orig[1]-fShape->GetDY(), orig[2]-fShape->GetDZ(),
00346 orig[0]+fShape->GetDX(), orig[1]+fShape->GetDY(), orig[2]+fShape->GetDZ());
00347 Update();
00348 }
00349 } else Update();
00350 }
00351 return;
00352 }
00353
00354 if (TMath::Abs(phi1-fShape->GetPhi1())>1.e-6) fShape->Phi1() = phi1;
00355 if (TMath::Abs(dphi-fShape->GetDphi())>1.e-6) fShape->Dphi() = dphi;
00356 for (isect=0; isect<fNsections; isect++) {
00357 sect = (TGeoPconSection*)fSections->At(isect);
00358 fShape->Z(isect) = sect->GetZ();
00359 fShape->Rmin(isect) = sect->GetRmin();
00360 fShape->Rmax(isect) = sect->GetRmax();
00361 }
00362 fShape->ComputeBBox();
00363 if (fPad) {
00364 if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00365 TView *view = fPad->GetView();
00366 if (!view) {
00367 fShape->Draw();
00368 fPad->GetView()->ShowAxis();
00369 } else {
00370 const Double_t *orig = fShape->GetOrigin();
00371 view->SetRange(orig[0]-fShape->GetDX(), orig[1]-fShape->GetDY(), orig[2]-fShape->GetDZ(),
00372 orig[0]+fShape->GetDX(), orig[1]+fShape->GetDY(), orig[2]+fShape->GetDZ());
00373 Update();
00374 }
00375 } else Update();
00376 }
00377 }
00378
00379
00380 void TGeoPconEditor::DoSectionChange(Int_t isect)
00381 {
00382
00383 TGeoPconSection *sect, *sectlo=0, *secthi=0;
00384 sect = (TGeoPconSection*)fSections->At(isect);
00385 if (isect) sectlo = (TGeoPconSection*)fSections->At(isect-1);
00386 if (isect<fNsections-1) secthi = (TGeoPconSection*)fSections->At(isect+1);
00387 Double_t z = sect->GetZ();
00388 if (sectlo && z<sectlo->GetZ()) {
00389 z = sectlo->GetZ();
00390 sect->SetZ(z);
00391 }
00392 if (secthi && z>secthi->GetZ()) {
00393 z = secthi->GetZ();
00394 sect->SetZ(z);
00395 }
00396 DoModified();
00397 if (!IsDelayed()) DoApply();
00398 }
00399
00400
00401 void TGeoPconEditor::DoNz()
00402 {
00403
00404 Int_t nz = fENz->GetIntNumber();
00405 if (nz < 2) {
00406 nz = 2;
00407 fENz->SetNumber(nz);
00408 }
00409 CreateSections(nz);
00410 CheckSections(kTRUE);
00411 DoModified();
00412 if (!IsDelayed()) DoApply();
00413 }
00414
00415
00416 void TGeoPconEditor::DoPhi()
00417 {
00418
00419 Double_t phi1 = fEPhi1->GetNumber();
00420 Double_t dphi = fEDPhi->GetNumber();
00421 if (TMath::Abs(phi1)>360) fEPhi1->SetNumber(0);
00422 if (dphi>360) fEDPhi->SetNumber(360);
00423 DoModified();
00424 if (!IsDelayed()) DoApply();
00425 }
00426
00427
00428 void TGeoPconEditor::DoModified()
00429 {
00430
00431 fApply->SetEnabled();
00432 }
00433
00434
00435 void TGeoPconEditor::DoUndo()
00436 {
00437
00438 fENz->SetNumber(fNsecti);
00439 CreateSections(fNsecti);
00440 fEPhi1->SetNumber(fPhi1i);
00441 fEDPhi->SetNumber(fDPhii);
00442 TGeoPconSection *sect;
00443 for (Int_t isect=0; isect<fNsections; isect++) {
00444 sect = (TGeoPconSection*)fSections->At(isect);
00445 sect->SetZ(fZi[isect]);
00446 sect->SetRmin(fRmini[isect]);
00447 sect->SetRmax(fRmaxi[isect]);
00448 }
00449 DoApply();
00450 fUndo->SetEnabled(kFALSE);
00451 fApply->SetEnabled(kFALSE);
00452 }
00453
00454 ClassImp(TGeoPconSection)
00455
00456
00457 TGeoPconSection::TGeoPconSection(const TGWindow *p, UInt_t w, UInt_t h, Int_t id)
00458 :TGCompositeFrame(p,w,h,kHorizontalFrame | kFixedWidth)
00459 {
00460
00461
00462 fNumber = id;
00463 TGTextEntry *nef;
00464
00465 AddFrame(new TGLabel(this, TString::Format("#%i",id)), new TGLayoutHints(kLHintsLeft, 2, 4, 6, 0));
00466
00467
00468 fEZ = new TGNumberEntry(this, 0., 5);
00469 fEZ->Resize(40,fEZ->GetDefaultHeight());
00470 nef = (TGTextEntry*)fEZ->GetNumberEntry();
00471 nef->SetToolTipText("Enter the Z position");
00472 fEZ->Associate(this);
00473 AddFrame(fEZ, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
00474
00475 fERmin = new TGNumberEntry(this, 0., 5);
00476 fERmin->SetNumAttr(TGNumberFormat::kNEAPositive);
00477 fERmin->Resize(40,fERmin->GetDefaultHeight());
00478 nef = (TGTextEntry*)fERmin->GetNumberEntry();
00479 nef->SetToolTipText("Enter the minimum radius");
00480 fERmin->Associate(this);
00481 AddFrame(fERmin, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
00482
00483 fERmax = new TGNumberEntry(this, 0., 5);
00484 fERmax->SetNumAttr(TGNumberFormat::kNEAPositive);
00485 fERmax->Resize(40,fERmax->GetDefaultHeight());
00486 nef = (TGTextEntry*)fERmax->GetNumberEntry();
00487 nef->SetToolTipText("Enter the maximum radius");
00488 fERmax->Associate(this);
00489 AddFrame(fERmax, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
00490
00491 ConnectSignals2Slots();
00492 MapSubwindows();
00493 Layout();
00494 }
00495
00496
00497 TGeoPconSection::~TGeoPconSection()
00498 {
00499
00500 Cleanup();
00501 }
00502
00503
00504 void TGeoPconSection::HideDaughters()
00505 {
00506
00507 fEZ->UnmapWindow();
00508 fERmin->UnmapWindow();
00509 fERmax->UnmapWindow();
00510 }
00511
00512
00513 void TGeoPconSection::Changed(Int_t i)
00514 {
00515
00516 Emit("Changed(Int_t)", i);
00517 }
00518
00519
00520 void TGeoPconSection::ConnectSignals2Slots()
00521 {
00522
00523 fEZ->Connect("ValueSet(Long_t)", "TGeoPconSection", this, "DoZ()");
00524 fERmin->Connect("ValueSet(Long_t)", "TGeoPconSection", this, "DoRmin()");
00525 fERmax->Connect("ValueSet(Long_t)", "TGeoPconSection", this, "DoRmax()");
00526 }
00527
00528
00529 Double_t TGeoPconSection::GetZ() const
00530 {
00531
00532 return fEZ->GetNumber();
00533 }
00534
00535
00536 Double_t TGeoPconSection::GetRmin() const
00537 {
00538
00539 return fERmin->GetNumber();
00540 }
00541
00542
00543 Double_t TGeoPconSection::GetRmax() const
00544 {
00545
00546 return fERmax->GetNumber();
00547 }
00548
00549
00550 void TGeoPconSection::SetZ(Double_t z)
00551 {
00552
00553 fEZ->SetNumber(z);
00554 }
00555
00556
00557 void TGeoPconSection::SetRmin(Double_t rmin)
00558 {
00559
00560 fERmin->SetNumber(rmin);
00561 }
00562
00563
00564 void TGeoPconSection::SetRmax(Double_t rmax)
00565 {
00566
00567 fERmax->SetNumber(rmax);
00568 }
00569
00570
00571 void TGeoPconSection::DoZ()
00572 {
00573
00574 Changed(fNumber);
00575 }
00576
00577
00578 void TGeoPconSection::DoRmin()
00579 {
00580
00581 Double_t rmin = fERmin->GetNumber();
00582 Double_t rmax = fERmax->GetNumber();
00583 if (rmin>rmax-1.e-8) fERmin->SetNumber(rmax);
00584 Changed(fNumber);
00585 }
00586
00587
00588 void TGeoPconSection::DoRmax()
00589 {
00590
00591 Double_t rmin = fERmin->GetNumber();
00592 Double_t rmax = fERmax->GetNumber();
00593 if (rmax<rmin+1.e-8) fERmax->SetNumber(rmin);
00594 Changed(fNumber);
00595 }