00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "TGeoMediumEditor.h"
00019 #include "TGeoTabManager.h"
00020 #include "TGeoManager.h"
00021 #include "TGeoMedium.h"
00022 #include "TGeoMaterial.h"
00023 #include "TPad.h"
00024 #include "TGTab.h"
00025 #include "TGComboBox.h"
00026 #include "TGButton.h"
00027 #include "TGTextEntry.h"
00028 #include "TGNumberEntry.h"
00029 #include "TGLabel.h"
00030 #include "TG3DLine.h"
00031
00032 ClassImp(TGeoMediumEditor)
00033
00034 enum ETGeoMediumWid {
00035 kMED_NAME, kMED_ID, kMED_MATSEL,
00036 kMED_SENS, kMED_FLDOPT, kMED_EDIT_MAT,
00037 kMED_FIELDM, kMED_TMAX, kMED_STEMAX,
00038 kMED_DEEMAX, kMED_EPSIL, kMED_STMIN,
00039 kMED_APPLY, kMED_CANCEL, kMED_UNDO
00040 };
00041
00042
00043 TGeoMediumEditor::TGeoMediumEditor(const TGWindow *p, Int_t width,
00044 Int_t height, UInt_t options, Pixel_t back)
00045 : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
00046 {
00047
00048 fMedium = 0;
00049 fIsEditable = kFALSE;
00050 fIsModified = kFALSE;
00051 Pixel_t color;
00052 TGLabel *label;
00053
00054
00055 MakeTitle("Name");
00056 fMedName = new TGTextEntry(this, "", kMED_NAME);
00057 fMedName->SetDefaultSize(135, fMedName->GetDefaultHeight());
00058 fMedName->SetToolTipText("Enter the medium name");
00059 fMedName->Associate(this);
00060 AddFrame(fMedName, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 3, 1, 2, 2));
00061
00062 TGTextEntry *nef;
00063
00064
00065 TGCompositeFrame *f1 = new TGCompositeFrame(this, 120, 30, kHorizontalFrame | kRaisedFrame);
00066 f1->AddFrame(new TGLabel(f1, "ID"), new TGLayoutHints(kLHintsLeft, 4, 1, 6, 0));
00067 fMedId = new TGNumberEntry(f1, 0., 1, kMED_ID);
00068 nef = (TGTextEntry*)fMedId->GetNumberEntry();
00069 nef->SetToolTipText("Enter the medium ID");
00070 fMedId->Associate(this);
00071 f1->AddFrame(fMedId, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
00072 fMedSensitive = new TGCheckButton(f1, "&Sens", kMED_SENS);
00073 fMedSensitive->Associate(this);
00074 f1->AddFrame(fMedSensitive, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00075 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 3, 3, 2, 2));
00076
00077
00078 f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame | kFixedWidth | kOwnBackground);
00079 f1->AddFrame(label = new TGLabel(f1, "Current material"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
00080 f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
00081 gClient->GetColorByName("#ff0000", color);
00082 label->SetTextColor(color);
00083 AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
00084 f1 = new TGCompositeFrame(this, 155, 30, kHorizontalFrame);
00085 fSelectedMaterial = 0;
00086 fLSelMaterial = new TGLabel(f1, "Select material");
00087 gClient->GetColorByName("#0000ff", color);
00088 fLSelMaterial->SetTextColor(color);
00089 fLSelMaterial->ChangeOptions(kChildFrame | kSunkenFrame | kDoubleBorder);
00090 f1->AddFrame(fLSelMaterial, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 1, 1, 2, 2));
00091 fBSelMaterial = new TGPictureButton(f1, fClient->GetPicture("rootdb_t.xpm"), kMED_MATSEL);
00092 fBSelMaterial->SetToolTipText("Replace with one of the existing materials");
00093 fBSelMaterial->Associate(this);
00094 f1->AddFrame(fBSelMaterial, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
00095 fEditMaterial = new TGTextButton(f1, "Edit");
00096 f1->AddFrame(fEditMaterial, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
00097 fEditMaterial->SetToolTipText("Edit selected material");
00098 fEditMaterial->Associate(this);
00099 AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 0, 0));
00100
00101
00102 f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame | kLHintsExpandX | kFixedWidth | kOwnBackground);
00103 f1->AddFrame(label = new TGLabel(f1, "Mag. field option"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
00104 f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
00105 gClient->GetColorByName("#ff0000", color);
00106 label->SetTextColor(color);
00107 AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
00108 fMagfldOption = new TGComboBox(this, kMED_FLDOPT);
00109 fMagfldOption->Resize(135, fMedName->GetDefaultHeight());
00110 AddFrame(fMagfldOption, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 2));
00111
00112
00113
00114 f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame | kFixedWidth | kOwnBackground);
00115 f1->AddFrame(label = new TGLabel(f1, "Medium cuts"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
00116 f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
00117 gClient->GetColorByName("#ff0000", color);
00118 label->SetTextColor(color);
00119 AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
00120 TGCompositeFrame *compxyz = new TGCompositeFrame(this, 130, 30, kVerticalFrame | kRaisedFrame | kDoubleBorder);
00121
00122
00123 f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00124 kLHintsExpandX | kFixedWidth | kOwnBackground);
00125 f1->AddFrame(new TGLabel(f1, "FIELDM"), new TGLayoutHints(kLHintsLeft, 1, 1, 4, 0));
00126 fMedFieldm = new TGNumberEntry(f1, 0., 5, kMED_FIELDM);
00127 nef = (TGTextEntry*)fMedFieldm->GetNumberEntry();
00128 nef->SetToolTipText("Maximum magnetic field [kilogauss]");
00129 fMedFieldm->Associate(this);
00130 fMedFieldm->Resize(90, fMedFieldm->GetDefaultHeight());
00131 f1->AddFrame(fMedFieldm, new TGLayoutHints(kLHintsRight | kFixedWidth , 2, 2, 2, 2));
00132 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
00133
00134
00135 TGCompositeFrame *f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00136 kLHintsExpandX | kFixedWidth | kOwnBackground);
00137 f2->AddFrame(new TGLabel(f2, "TMAXFD"), new TGLayoutHints(kLHintsLeft, 1, 1, 4, 0));
00138 fMedTmaxfd = new TGNumberEntry(f2, 0., 5, kMED_TMAX);
00139 nef = (TGTextEntry*)fMedTmaxfd->GetNumberEntry();
00140 nef->SetToolTipText("Maximum angle per step due to field [deg]");
00141 fMedTmaxfd->Associate(this);
00142 fMedTmaxfd->Resize(90, fMedTmaxfd->GetDefaultHeight());
00143 f2->AddFrame(fMedTmaxfd, new TGLayoutHints(kLHintsRight | kFixedWidth , 2, 2, 2, 2));
00144 compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
00145
00146
00147 TGCompositeFrame *f3 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00148 kLHintsExpandX | kFixedWidth | kOwnBackground);
00149 f3->AddFrame(new TGLabel(f3, "STEMAX"), new TGLayoutHints(kLHintsLeft, 1, 1, 4, 0));
00150 fMedStemax = new TGNumberEntry(f3, 0., 5, kMED_STEMAX);
00151 nef = (TGTextEntry*)fMedStemax->GetNumberEntry();
00152 nef->SetToolTipText("Maximum step allowed [cm]");
00153 fMedStemax->Associate(this);
00154 fMedStemax->Resize(90, fMedStemax->GetDefaultHeight());
00155 f3->AddFrame(fMedStemax, new TGLayoutHints(kLHintsRight | kFixedWidth , 2, 2, 2, 2));
00156 compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
00157
00158
00159 TGCompositeFrame *f4 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00160 kLHintsExpandX | kFixedWidth | kOwnBackground);
00161 f4->AddFrame(new TGLabel(f4, "DEEMAX"), new TGLayoutHints(kLHintsLeft, 1, 1, 4, 0));
00162 fMedDeemax = new TGNumberEntry(f4, 0., 5, kMED_DEEMAX);
00163 nef = (TGTextEntry*)fMedDeemax->GetNumberEntry();
00164 nef->SetToolTipText("Maximum fraction of energy lost in a step");
00165 fMedDeemax->Associate(this);
00166 fMedDeemax->Resize(90, fMedDeemax->GetDefaultHeight());
00167 f4->AddFrame(fMedDeemax, new TGLayoutHints(kLHintsRight | kFixedWidth , 2, 2, 2, 2));
00168 compxyz->AddFrame(f4, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
00169
00170
00171 TGCompositeFrame *f5 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00172 kLHintsExpandX | kFixedWidth | kOwnBackground);
00173 f5->AddFrame(new TGLabel(f5, "EPSIL"), new TGLayoutHints(kLHintsLeft, 1, 1, 4, 0));
00174 fMedEpsil = new TGNumberEntry(f5, 0., 5, kMED_EPSIL);
00175 nef = (TGTextEntry*)fMedEpsil->GetNumberEntry();
00176 nef->SetToolTipText("Tracking precision [cm]");
00177 fMedEpsil->Associate(this);
00178 fMedEpsil->Resize(90, fMedEpsil->GetDefaultHeight());
00179 f5->AddFrame(fMedEpsil, new TGLayoutHints(kLHintsRight | kFixedWidth , 2, 2, 2, 2));
00180 compxyz->AddFrame(f5, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
00181
00182
00183 TGCompositeFrame *f6 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00184 kLHintsExpandX | kFixedWidth | kOwnBackground);
00185 f6->AddFrame(new TGLabel(f6, "STMIN"), new TGLayoutHints(kLHintsLeft, 1, 1, 4, 0));
00186 fMedStmin = new TGNumberEntry(f6, 0., 5, kMED_STMIN);
00187 nef = (TGTextEntry*)fMedStmin->GetNumberEntry();
00188 nef->SetToolTipText("Minimum step due to continuous processes [cm]");
00189 fMedStmin->Associate(this);
00190 fMedStmin->Resize(90, fMedStmin->GetDefaultHeight());
00191 f6->AddFrame(fMedStmin, new TGLayoutHints(kLHintsRight | kFixedWidth , 2, 2, 2, 2));
00192 compxyz->AddFrame(f6, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
00193
00194 compxyz->Resize(160,50);
00195 AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
00196
00197
00198 TGCompositeFrame *f23 = new TGCompositeFrame(this, 118, 20, kHorizontalFrame | kSunkenFrame | kDoubleBorder);
00199 fApply = new TGTextButton(f23, "&Apply");
00200 f23->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00201 fApply->Associate(this);
00202 fUndo = new TGTextButton(f23, " &Undo ");
00203 f23->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
00204 fUndo->Associate(this);
00205 AddFrame(f23, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00206 }
00207
00208
00209 TGeoMediumEditor::~TGeoMediumEditor()
00210 {
00211
00212 TGFrameElement *el;
00213 TIter next(GetList());
00214 while ((el = (TGFrameElement *)next())) {
00215 if (el->fFrame->IsA() == TGCompositeFrame::Class() ||
00216 el->fFrame->IsA() == TGHorizontalFrame::Class() ||
00217 el->fFrame->IsA() == TGVerticalFrame::Class())
00218 TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00219 }
00220 Cleanup();
00221 }
00222
00223
00224 void TGeoMediumEditor::ConnectSignals2Slots()
00225 {
00226
00227 fApply->Connect("Clicked()", "TGeoMediumEditor", this, "DoApply()");
00228 fUndo->Connect("Clicked()", "TGeoMediumEditor", this, "DoUndo()");
00229 fMedName->Connect("TextChanged(const char *)", "TGeoMediumEditor", this, "DoMedName()");
00230 fBSelMaterial->Connect("Clicked()", "TGeoMediumEditor", this, "DoSelectMaterial()");
00231 fEditMaterial->Connect("Clicked()", "TGeoMediumEditor", this, "DoEditMaterial()");
00232 fMedId->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoMediumEditor", this, "DoMedId()");
00233 fMedTmaxfd->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoMediumEditor", this, "DoTmaxfd()");
00234 fMedStemax->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoMediumEditor", this, "DoStemax()");
00235 fMedDeemax->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoMediumEditor", this, "DoDeemax()");
00236 fMedEpsil->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoMediumEditor", this, "DoEpsil()");
00237 fMedStmin->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoMediumEditor", this, "DoStmin()");
00238 fMedSensitive->Connect("Clicked()", "TGeoMediumEditor", this, "DoToggleSensitive()");
00239 fMagfldOption->Connect("Selected(Int_t)", "TGeoMediumEditor", this, "DoMagfldSelect(Int_t)");
00240 fInit = kFALSE;
00241 }
00242
00243
00244
00245 void TGeoMediumEditor::SetModel(TObject* obj)
00246 {
00247
00248 if (obj == 0 || !(obj->IsA()==TGeoMedium::Class())) {
00249 SetActive(kFALSE);
00250 return;
00251 }
00252 fMedium = (TGeoMedium*)obj;
00253 const char *sname = fMedium->GetName();
00254 if (!strcmp(sname, fMedium->ClassName())) fMedName->SetText("");
00255 else fMedName->SetText(sname);
00256
00257 fMedId->SetNumber(fMedium->GetId());
00258 Int_t isvol = (Int_t)fMedium->GetParam(0);
00259 fMedSensitive->SetState((isvol==0)?kButtonUp:kButtonDown);
00260
00261 fSelectedMaterial = fMedium->GetMaterial();
00262 if (fSelectedMaterial) fLSelMaterial->SetText(fSelectedMaterial->GetName());
00263
00264 if (!fMagfldOption->GetNumberOfEntries()) {
00265 fMagfldOption->AddEntry("No field", 0);
00266 fMagfldOption->AddEntry("User decision", 1);
00267 fMagfldOption->AddEntry("Runge-Kutta", 2);
00268 fMagfldOption->AddEntry("Helix", 3);
00269 fMagfldOption->AddEntry("Helix3", 4);
00270 fMagfldOption->AddEntry("Unknown option", 5);
00271 }
00272 Int_t ifld = (Int_t)fMedium->GetParam(1);
00273 switch (ifld) {
00274 case 0:
00275 fMagfldOption->Select(0);
00276 break;
00277 case -1:
00278 fMagfldOption->Select(1);
00279 break;
00280 case 1:
00281 fMagfldOption->Select(2);
00282 break;
00283 case 2:
00284 fMagfldOption->Select(3);
00285 break;
00286 case 3:
00287 fMagfldOption->Select(4);
00288 break;
00289 default:
00290 fMagfldOption->Select(5);
00291 break;
00292 }
00293
00294 fMedFieldm->SetNumber(fMedium->GetParam(2));
00295 fMedTmaxfd->SetNumber(fMedium->GetParam(3));
00296 fMedStemax->SetNumber(fMedium->GetParam(4));
00297 fMedDeemax->SetNumber(fMedium->GetParam(5));
00298 fMedEpsil->SetNumber(fMedium->GetParam(6));
00299 fMedStmin->SetNumber(fMedium->GetParam(7));
00300
00301 fUndo->SetEnabled(kFALSE);
00302 fIsModified = kFALSE;
00303
00304
00305 if (fInit) ConnectSignals2Slots();
00306 SetActive();
00307 }
00308
00309
00310 void TGeoMediumEditor::DoEditMaterial()
00311 {
00312
00313 fTabMgr->GetMaterialEditor(fMedium->GetMaterial());
00314 }
00315
00316
00317 void TGeoMediumEditor::DoMedName()
00318 {
00319
00320 const char *name = fMedName->GetText();
00321 if (!strlen(name) || !strcmp(name, fMedium->GetName())) return;
00322 fMedium->SetName(name);
00323 }
00324
00325
00326 void TGeoMediumEditor::DoMedId()
00327 {
00328
00329 }
00330
00331
00332 void TGeoMediumEditor::DoSelectMaterial()
00333 {
00334
00335 TGeoMaterial *material = fSelectedMaterial;
00336 new TGeoMaterialDialog(fBSelMaterial, gClient->GetRoot(), 200,300);
00337 fSelectedMaterial = (TGeoMaterial*)TGeoMaterialDialog::GetSelected();
00338 if (fSelectedMaterial) fLSelMaterial->SetText(fSelectedMaterial->GetName());
00339 else fSelectedMaterial = material;
00340 }
00341
00342
00343 void TGeoMediumEditor::DoToggleSensitive()
00344 {
00345
00346 fIsModified = kTRUE;
00347 }
00348
00349
00350 void TGeoMediumEditor::DoMagfldSelect(Int_t)
00351 {
00352
00353 fIsModified = kTRUE;
00354 }
00355
00356
00357 void TGeoMediumEditor::DoFieldm()
00358 {
00359
00360 fIsModified = kTRUE;
00361 }
00362
00363
00364 void TGeoMediumEditor::DoTmaxfd()
00365 {
00366
00367 fIsModified = kTRUE;
00368 }
00369
00370
00371 void TGeoMediumEditor::DoStemax()
00372 {
00373
00374 fIsModified = kTRUE;
00375 }
00376
00377
00378 void TGeoMediumEditor::DoDeemax()
00379 {
00380
00381 fIsModified = kTRUE;
00382 }
00383
00384
00385 void TGeoMediumEditor::DoEpsil()
00386 {
00387
00388 fIsModified = kTRUE;
00389 }
00390
00391
00392 void TGeoMediumEditor::DoStmin()
00393 {
00394
00395 fIsModified = kTRUE;
00396 }
00397
00398
00399 void TGeoMediumEditor::DoApply()
00400 {
00401
00402 if (!fIsModified) return;
00403 Double_t isvol = (fMedSensitive->IsOn())?1:0;
00404 Double_t ifield = fMagfldOption->GetSelected();
00405 if (ifield>0) {
00406 ifield -= 1.;
00407 if (ifield < 1.) ifield -= 1.;
00408 }
00409 Double_t fieldm = fMedFieldm->GetNumber();
00410 Double_t tmaxfd = fMedTmaxfd->GetNumber();
00411 Double_t stemax = fMedStemax->GetNumber();
00412 Double_t deemax = fMedDeemax->GetNumber();
00413 Double_t epsil = fMedEpsil->GetNumber();
00414 Double_t stmin = fMedStmin->GetNumber();
00415
00416 fMedium->SetParam(0,isvol);
00417 fMedium->SetParam(1,ifield);
00418 fMedium->SetParam(2,fieldm);
00419 fMedium->SetParam(3,tmaxfd);
00420 fMedium->SetParam(4,stemax);
00421 fMedium->SetParam(5,deemax);
00422 fMedium->SetParam(6,epsil);
00423 fMedium->SetParam(7,stmin);
00424 if (strcmp(fMedium->GetName(), fMedName->GetText())) fMedium->SetName(fMedName->GetText());
00425 if (fMedium->GetId() != fMedId->GetIntNumber()) fMedium->SetId(fMedId->GetIntNumber());
00426 }
00427
00428
00429 void TGeoMediumEditor::DoUndo()
00430 {
00431
00432 }
00433