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 "TGeoHypeEditor.h"
00029 #include "TGeoTabManager.h"
00030 #include "TGeoHype.h"
00031 #include "TGeoManager.h"
00032 #include "TVirtualGeoPainter.h"
00033 #include "TPad.h"
00034 #include "TView.h"
00035 #include "TMath.h"
00036 #include "TGTab.h"
00037 #include "TGComboBox.h"
00038 #include "TGButton.h"
00039 #include "TGTextEntry.h"
00040 #include "TGNumberEntry.h"
00041 #include "TGLabel.h"
00042
00043 ClassImp(TGeoHypeEditor)
00044
00045 enum ETGeoHypeWid {
00046 kHYPE_NAME, kHYPE_RIN, kHYPE_ROUT, kHYPE_DZ, kHYPE_STIN,
00047 kHYPE_STOUT, kHYPE_APPLY, kHYPE_UNDO
00048 };
00049
00050
00051 TGeoHypeEditor::TGeoHypeEditor(const TGWindow *p, Int_t width,
00052 Int_t height, UInt_t options, Pixel_t back)
00053 : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
00054 {
00055
00056 fShape = 0;
00057 fRini = fRouti = fStIni = fStOuti = 0.0;
00058 fNamei = "";
00059 fIsModified = kFALSE;
00060 fIsShapeEditable = kTRUE;
00061
00062
00063 MakeTitle("Name");
00064 fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kHYPE_NAME);
00065 fShapeName->Resize(135, fShapeName->GetDefaultHeight());
00066 fShapeName->SetToolTipText("Enter the hyperboloid name");
00067 fShapeName->Associate(this);
00068 AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
00069
00070 TGTextEntry *nef;
00071 MakeTitle("Dimensions");
00072
00073 TGCompositeFrame *f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00074 f1->AddFrame(new TGLabel(f1, "Rin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00075 fERin = new TGNumberEntry(f1, 0., 5, kHYPE_RIN);
00076 fERin->SetNumAttr(TGNumberFormat::kNEAPositive);
00077 fERin->Resize(100, fERin->GetDefaultHeight());
00078 nef = (TGTextEntry*)fERin->GetNumberEntry();
00079 nef->SetToolTipText("Enter the inner radius ");
00080 fERin->Associate(this);
00081 f1->AddFrame(fERin, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00082 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00083
00084
00085 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00086 f1->AddFrame(new TGLabel(f1, "Rout"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00087 fERout = new TGNumberEntry(f1, 0., 5, kHYPE_ROUT);
00088 fERout->SetNumAttr(TGNumberFormat::kNEAPositive);
00089 fERout->Resize(100, fERout->GetDefaultHeight());
00090 nef = (TGTextEntry*)fERout->GetNumberEntry();
00091 nef->SetToolTipText("Enter the outer radius");
00092 fERout->Associate(this);
00093 f1->AddFrame(fERout, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00094 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00095
00096
00097 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00098 f1->AddFrame(new TGLabel(f1, "Dz"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00099 fEDz = new TGNumberEntry(f1, 0., 5, kHYPE_DZ);
00100 fEDz->SetNumAttr(TGNumberFormat::kNEAPositive);
00101 fEDz->Resize(100, fEDz->GetDefaultHeight());
00102 nef = (TGTextEntry*)fEDz->GetNumberEntry();
00103 nef->SetToolTipText("Enter the half-lenth in Dz");
00104 fEDz->Associate(this);
00105 f1->AddFrame(fEDz, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00106 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00107
00108
00109 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00110 f1->AddFrame(new TGLabel(f1, "StIn"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00111 fEStIn = new TGNumberEntry(f1, 0., 5, kHYPE_STIN);
00112 fEStIn->Resize(100, fEStIn->GetDefaultHeight());
00113 nef = (TGTextEntry*)fEStIn->GetNumberEntry();
00114 nef->SetToolTipText("Enter the stereo angle for inner surface");
00115 fEStIn->Associate(this);
00116 f1->AddFrame(fEStIn, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00117 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00118
00119
00120 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00121 f1->AddFrame(new TGLabel(f1, "StOut"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00122 fEStOut = new TGNumberEntry(f1, 0., 5, kHYPE_STOUT);
00123 fEStOut->SetNumAttr(TGNumberFormat::kNEAPositive);
00124 fEStOut->Resize(100, fEStOut->GetDefaultHeight());
00125 nef = (TGTextEntry*)fEStOut->GetNumberEntry();
00126 nef->SetToolTipText("Enter the stereo angle for outer surface");
00127 fEStOut->Associate(this);
00128 f1->AddFrame(fEStOut, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00129 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00130
00131
00132 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
00133 fDelayed = new TGCheckButton(f1, "Delayed draw");
00134 f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
00135 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00136
00137
00138 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00139 fApply = new TGTextButton(f1, "Apply");
00140 f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00141 fApply->Associate(this);
00142 fUndo = new TGTextButton(f1, "Undo");
00143 f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
00144 fUndo->Associate(this);
00145 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00146 fUndo->SetSize(fApply->GetSize());
00147 }
00148
00149
00150 TGeoHypeEditor::~TGeoHypeEditor()
00151 {
00152
00153 TGFrameElement *el;
00154 TIter next(GetList());
00155 while ((el = (TGFrameElement *)next())) {
00156 if (el->fFrame->IsComposite())
00157 TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00158 }
00159 Cleanup();
00160 }
00161
00162
00163 void TGeoHypeEditor::ConnectSignals2Slots()
00164 {
00165
00166 fApply->Connect("Clicked()", "TGeoHypeEditor", this, "DoApply()");
00167 fUndo->Connect("Clicked()", "TGeoHypeEditor", this, "DoUndo()");
00168 fShapeName->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
00169 fERin->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoRin()");
00170 fERout->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoRout()");
00171 fEDz->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoDz()");
00172 fEStIn->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoStIn()");
00173 fEStOut->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoStOut()");
00174 fERin->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
00175 fERout->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
00176 fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
00177 fEStIn->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
00178 fEStOut->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
00179 fInit = kFALSE;
00180 }
00181
00182
00183
00184 void TGeoHypeEditor::SetModel(TObject* obj)
00185 {
00186
00187 if (obj == 0 || (obj->IsA()!=TGeoHype::Class())) {
00188 SetActive(kFALSE);
00189 return;
00190 }
00191 fShape = (TGeoHype*)obj;
00192 fRini = fShape->GetRmin();
00193 fRouti = fShape->GetRmax();
00194 fDzi = fShape->GetDz();
00195 fStIni = fShape->GetStIn();
00196 fStOuti = fShape->GetStOut();
00197 const char *sname = fShape->GetName();
00198 if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
00199 else {
00200 fShapeName->SetText(sname);
00201 fNamei = sname;
00202 }
00203 fERin->SetNumber(fRini);
00204 fERout->SetNumber(fRouti);
00205 fEDz->SetNumber(fDzi);
00206 fEStIn->SetNumber(fStIni);
00207 fEStOut->SetNumber(fStOuti);
00208 fApply->SetEnabled(kFALSE);
00209 fUndo->SetEnabled(kFALSE);
00210
00211 if (fInit) ConnectSignals2Slots();
00212 SetActive();
00213 }
00214
00215
00216 Bool_t TGeoHypeEditor::IsDelayed() const
00217 {
00218
00219 return (fDelayed->GetState() == kButtonDown);
00220 }
00221
00222
00223 void TGeoHypeEditor::DoName()
00224 {
00225
00226 DoModified();
00227 }
00228
00229
00230 void TGeoHypeEditor::DoApply()
00231 {
00232
00233 const char *name = fShapeName->GetText();
00234 if (strcmp(name,fShape->GetName())) fShape->SetName(name);
00235 Double_t rin = fERin->GetNumber();
00236 Double_t rout = fERout->GetNumber();
00237 Double_t dz = fEDz->GetNumber();
00238 Double_t stin = fEStIn->GetNumber();
00239 Double_t stout = fEStOut->GetNumber();
00240 Double_t tin = TMath::Tan(stin*TMath::DegToRad());
00241 Double_t tout = TMath::Tan(stout*TMath::DegToRad());
00242 if ((dz<=0) || (rin<0) || (rin>rout) ||
00243 (rin*rin+tin*tin*dz*dz > rout*rout+tout*tout*dz*dz)) {
00244 fUndo->SetEnabled();
00245 fApply->SetEnabled(kFALSE);
00246 return;
00247 }
00248 Double_t param[5];
00249 param[0] = dz;
00250 param[1] = rin;
00251 param[2] = stin;
00252 param[3] = rout;
00253 param[4] = stout;
00254 fShape->SetDimensions(param);
00255 fShape->ComputeBBox();
00256 fUndo->SetEnabled();
00257 fApply->SetEnabled(kFALSE);
00258 if (fPad) {
00259 if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00260 TView *view = fPad->GetView();
00261 if (!view) {
00262 fShape->Draw();
00263 fPad->GetView()->ShowAxis();
00264 } else {
00265 view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(),
00266 fShape->GetDX(), fShape->GetDY(), fShape->GetDZ());
00267 Update();
00268 }
00269 } else Update();
00270 }
00271 }
00272
00273
00274 void TGeoHypeEditor::DoModified()
00275 {
00276
00277 fApply->SetEnabled();
00278 }
00279
00280
00281 void TGeoHypeEditor::DoUndo()
00282 {
00283
00284 fERin->SetNumber(fRini);
00285 fERout->SetNumber(fRouti);
00286 fEDz->SetNumber(fDzi);
00287 fEStIn->SetNumber(fStIni);
00288 fEStOut->SetNumber(fStOuti);
00289 DoApply();
00290 fUndo->SetEnabled(kFALSE);
00291 fApply->SetEnabled(kFALSE);
00292 }
00293
00294
00295 void TGeoHypeEditor::DoRin()
00296 {
00297
00298 Double_t rin = fERin->GetNumber();
00299 Double_t rout = fERout->GetNumber();
00300 Double_t dz = fEDz->GetNumber();
00301 Double_t stin = fEStIn->GetNumber();
00302 Double_t stout = fEStOut->GetNumber();
00303 Double_t tin = TMath::Tan(stin*TMath::DegToRad());
00304 Double_t tout = TMath::Tan(stout*TMath::DegToRad());
00305 if (rin<0) {
00306 rin = 0;
00307 fERin->SetNumber(rin);
00308 }
00309 Double_t rinmax = TMath::Sqrt((rout*rout+tout*tout*dz*dz)/(tin*tin*dz*dz));
00310 rinmax = TMath::Min(rinmax, rout);
00311 if (rin > rinmax) {
00312 rin = rinmax-1.e-6;
00313 fERin->SetNumber(rin);
00314 }
00315 DoModified();
00316 if (!IsDelayed()) DoApply();
00317 }
00318
00319
00320 void TGeoHypeEditor::DoRout()
00321 {
00322
00323 Double_t rin = fERin->GetNumber();
00324 Double_t rout = fERout->GetNumber();
00325 Double_t dz = fEDz->GetNumber();
00326 Double_t stin = fEStIn->GetNumber();
00327 Double_t stout = fEStOut->GetNumber();
00328 Double_t tin = TMath::Tan(stin*TMath::DegToRad());
00329 Double_t tout = TMath::Tan(stout*TMath::DegToRad());
00330 Double_t routmin = TMath::Sqrt((rin*rin+tin*tin*dz*dz)/(tout*tout*dz*dz));
00331 routmin = TMath::Max(routmin,rin);
00332 if (rout < routmin) {
00333 rout = routmin+1.e-6;
00334 fERout->SetNumber(rout);
00335 }
00336 DoModified();
00337 if (!IsDelayed()) DoApply();
00338 }
00339
00340
00341 void TGeoHypeEditor::DoDz()
00342 {
00343
00344 Double_t rin = fERin->GetNumber();
00345 Double_t rout = fERout->GetNumber();
00346 Double_t dz = fEDz->GetNumber();
00347 Double_t stin = fEStIn->GetNumber();
00348 Double_t stout = fEStOut->GetNumber();
00349 if (TMath::Abs(stin-stout)<1.e-6) {
00350 stin = stout+1.;
00351 fEStIn->SetNumber(stin);
00352 }
00353 Double_t tin = TMath::Tan(stin*TMath::DegToRad());
00354 Double_t tout = TMath::Tan(stout*TMath::DegToRad());
00355 if (dz<=0) {
00356 dz = 0.1;
00357 fEDz->SetNumber(dz);
00358 }
00359 Double_t dzmax = TMath::Sqrt((rout*rout-rin*rin)/(tin*tin-tout*tout));
00360 if (dz>dzmax) {
00361 dz = dzmax;
00362 fEDz->SetNumber(dz);
00363 }
00364 DoModified();
00365 if (!IsDelayed()) DoApply();
00366 }
00367
00368
00369 void TGeoHypeEditor::DoStIn()
00370 {
00371
00372 Double_t rin = fERin->GetNumber();
00373 Double_t rout = fERout->GetNumber();
00374 Double_t dz = fEDz->GetNumber();
00375 Double_t stin = fEStIn->GetNumber();
00376 Double_t stout = fEStOut->GetNumber();
00377 if (stin >= 90) {
00378 stin = 89.;
00379 fEStIn->SetNumber(stin);
00380 }
00381 Double_t tin = TMath::Tan(stin*TMath::DegToRad());
00382 Double_t tout = TMath::Tan(stout*TMath::DegToRad());
00383 Double_t tinmax = TMath::Sqrt(tout*tout+(rout*rout-rin*rin)/(dz*dz));
00384 if (tin>tinmax) {
00385 tin = tinmax-1.e-6;
00386 stin = TMath::RadToDeg()*TMath::ATan(tin);
00387 fEStIn->SetNumber(stin);
00388 }
00389 DoModified();
00390 if (!IsDelayed()) DoApply();
00391 }
00392
00393
00394 void TGeoHypeEditor::DoStOut()
00395 {
00396
00397 Double_t rin = fERin->GetNumber();
00398 Double_t rout = fERout->GetNumber();
00399 Double_t dz = fEDz->GetNumber();
00400 Double_t stin = fEStIn->GetNumber();
00401 Double_t stout = fEStOut->GetNumber();
00402 if (stout > 90) {
00403 stout = 89;
00404 fEStOut->SetNumber(stout);
00405 }
00406 Double_t tin = TMath::Tan(stin*TMath::DegToRad());
00407 Double_t tout = TMath::Tan(stout*TMath::DegToRad());
00408 Double_t tinmin = TMath::Sqrt((rout*rout-rin*rin)/(dz*dz));
00409 if (tin < tinmin) {
00410 tin = tinmin;
00411 stin = TMath::RadToDeg()*TMath::ATan(tin);
00412 fEStIn->SetNumber(stin);
00413 }
00414 Double_t toutmin = TMath::Sqrt(tin*tin -tinmin*tinmin);
00415 if (tout < toutmin) {
00416 tout = toutmin+1.e-6;
00417 stout = TMath::RadToDeg()*TMath::ATan(tout);
00418 fEStOut->SetNumber(stout);
00419 }
00420 DoModified();
00421 if (!IsDelayed()) DoApply();
00422 }