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 "TGeoTorusEditor.h"
00029 #include "TGeoTabManager.h"
00030 #include "TGeoTorus.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(TGeoTorusEditor)
00043
00044 enum ETGeoTorusWid {
00045 kTORUS_NAME, kTORUS_R, kTORUS_RMIN, kTORUS_RMAX, kTORUS_PHI1,
00046 kTORUS_DPHI, kTORUS_APPLY, kTORUS_UNDO
00047 };
00048
00049
00050 TGeoTorusEditor::TGeoTorusEditor(const TGWindow *p, Int_t width,
00051 Int_t height, UInt_t options, Pixel_t back)
00052 : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
00053 {
00054
00055 fShape = 0;
00056 fRi = fRmini = fRmaxi = fPhi1i = fDphii = 0.0;
00057 fNamei = "";
00058 fIsModified = kFALSE;
00059 fIsShapeEditable = kTRUE;
00060
00061
00062 MakeTitle("Name");
00063 fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kTORUS_NAME);
00064 fShapeName->Resize(135, fShapeName->GetDefaultHeight());
00065 fShapeName->SetToolTipText("Enter the torus name");
00066 fShapeName->Associate(this);
00067 AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
00068
00069 TGTextEntry *nef;
00070 MakeTitle("Dimensions");
00071
00072 TGCompositeFrame *f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00073 f1->AddFrame(new TGLabel(f1, "R"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00074 fER = new TGNumberEntry(f1, 0., 5, kTORUS_R);
00075 fER->SetNumAttr(TGNumberFormat::kNEAPositive);
00076 fER->Resize(100, fER->GetDefaultHeight());
00077 nef = (TGTextEntry*)fER->GetNumberEntry();
00078 nef->SetToolTipText("Enter the axial radius R");
00079 fER->Associate(this);
00080 f1->AddFrame(fER, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00081 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00082
00083
00084 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00085 f1->AddFrame(new TGLabel(f1, "Rmin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00086 fERmin = new TGNumberEntry(f1, 0., 5, kTORUS_RMIN);
00087 fERmin->SetNumAttr(TGNumberFormat::kNEAPositive);
00088 fERmin->Resize(100, fERmin->GetDefaultHeight());
00089 nef = (TGTextEntry*)fERmin->GetNumberEntry();
00090 nef->SetToolTipText("Enter the inner radius Rmin");
00091 fERmin->Associate(this);
00092 f1->AddFrame(fERmin, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00093 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00094
00095
00096 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00097 f1->AddFrame(new TGLabel(f1, "Rmax"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00098 fERmax = new TGNumberEntry(f1, 0., 5, kTORUS_RMAX);
00099 fERmax->SetNumAttr(TGNumberFormat::kNEAPositive);
00100 fERmax->Resize(100, fERmax->GetDefaultHeight());
00101 nef = (TGTextEntry*)fERmax->GetNumberEntry();
00102 nef->SetToolTipText("Enter the outer radius Rmax");
00103 fERmax->Associate(this);
00104 f1->AddFrame(fERmax, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00105 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00106
00107
00108 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00109 f1->AddFrame(new TGLabel(f1, "Phi1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00110 fEPhi1 = new TGNumberEntry(f1, 0., 5, kTORUS_PHI1);
00111 fEPhi1->SetNumAttr(TGNumberFormat::kNEANonNegative);
00112 fEPhi1->Resize(100, fEPhi1->GetDefaultHeight());
00113 nef = (TGTextEntry*)fEPhi1->GetNumberEntry();
00114 nef->SetToolTipText("Enter the starting phi angle[deg]");
00115 fEPhi1->Associate(this);
00116 f1->AddFrame(fEPhi1, 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, "Dphi"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00122 fEDphi = new TGNumberEntry(f1, 0., 5, kTORUS_DPHI);
00123 fEDphi->SetNumAttr(TGNumberFormat::kNEAPositive);
00124 fEDphi->Resize(100, fEDphi->GetDefaultHeight());
00125 nef = (TGTextEntry*)fEDphi->GetNumberEntry();
00126 nef->SetToolTipText("Enter the extent phi Dphi [deg]");
00127 fEDphi->Associate(this);
00128 f1->AddFrame(fEDphi, 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 TGeoTorusEditor::~TGeoTorusEditor()
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 TGeoTorusEditor::ConnectSignals2Slots()
00164 {
00165
00166 fApply->Connect("Clicked()", "TGeoTorusEditor", this, "DoApply()");
00167 fUndo->Connect("Clicked()", "TGeoTorusEditor", this, "DoUndo()");
00168 fShapeName->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
00169 fER->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoR()");
00170 fERmin->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoRmin()");
00171 fERmax->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoRmax()");
00172 fEPhi1->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoPhi1()");
00173 fEDphi->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoDphi()");
00174 fER->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
00175 fERmin->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
00176 fERmax->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
00177 fEPhi1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
00178 fEDphi->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
00179 fInit = kFALSE;
00180 }
00181
00182
00183
00184 void TGeoTorusEditor::SetModel(TObject* obj)
00185 {
00186
00187 if (obj == 0 || (obj->IsA()!=TGeoTorus::Class())) {
00188 SetActive(kFALSE);
00189 return;
00190 }
00191 fShape = (TGeoTorus*)obj;
00192 fRi = fShape->GetR();
00193 fRmini = fShape->GetRmin();
00194 fRmaxi = fShape->GetRmax();
00195 fPhi1i = fShape->GetPhi1();
00196 fDphii = fShape->GetDphi();
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 fER->SetNumber(fRi);
00204 fERmin->SetNumber(fRmini);
00205 fERmax->SetNumber(fRmaxi);
00206 fEPhi1->SetNumber(fPhi1i);
00207 fEDphi->SetNumber(fDphii);
00208 fApply->SetEnabled(kFALSE);
00209 fUndo->SetEnabled(kFALSE);
00210
00211 if (fInit) ConnectSignals2Slots();
00212 SetActive();
00213 }
00214
00215
00216 Bool_t TGeoTorusEditor::IsDelayed() const
00217 {
00218
00219 return (fDelayed->GetState() == kButtonDown);
00220 }
00221
00222
00223 void TGeoTorusEditor::DoName()
00224 {
00225
00226 DoModified();
00227 }
00228
00229
00230 void TGeoTorusEditor::DoApply()
00231 {
00232
00233 const char *name = fShapeName->GetText();
00234 if (strcmp(name,fShape->GetName())) fShape->SetName(name);
00235 Double_t r = fER->GetNumber();
00236 Double_t rmax = fERmax->GetNumber();
00237 Double_t rmin = fERmin->GetNumber();
00238 Double_t phi = fEPhi1->GetNumber();
00239 Double_t dphi = fEDphi->GetNumber();
00240 Double_t param[5];
00241 param[0] = r;
00242 param[1] = rmin;
00243 param[2] = rmax;
00244 param[3] = phi;
00245 param[4] = dphi;
00246 fShape->SetDimensions(param);
00247 fShape->ComputeBBox();
00248 fUndo->SetEnabled();
00249 fApply->SetEnabled(kFALSE);
00250 if (fPad) {
00251 if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00252 TView *view = fPad->GetView();
00253 if (!view) {
00254 fShape->Draw();
00255 fPad->GetView()->ShowAxis();
00256 } else {
00257 view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(),
00258 fShape->GetDX(), fShape->GetDY(), fShape->GetDZ());
00259 Update();
00260 }
00261 } else Update();
00262 }
00263 }
00264
00265
00266 void TGeoTorusEditor::DoModified()
00267 {
00268
00269 fApply->SetEnabled();
00270 }
00271
00272
00273 void TGeoTorusEditor::DoUndo()
00274 {
00275
00276 fER->SetNumber(fRi);
00277 fERmin->SetNumber(fRmini);
00278 fERmax->SetNumber(fRmaxi);
00279 fEPhi1->SetNumber(fPhi1i);
00280 fEDphi->SetNumber(fDphii);
00281 DoApply();
00282 fUndo->SetEnabled(kFALSE);
00283 fApply->SetEnabled(kFALSE);
00284 }
00285
00286
00287 void TGeoTorusEditor::DoR()
00288 {
00289
00290 Double_t r = fER->GetNumber();
00291 Double_t rmax = fERmax->GetNumber();
00292 if (r<rmax) {
00293 r = rmax;
00294 fER->SetNumber(r);
00295 }
00296 DoModified();
00297 if (!IsDelayed()) DoApply();
00298 }
00299
00300
00301 void TGeoTorusEditor::DoRmin()
00302 {
00303
00304 Double_t rmin = fERmin->GetNumber();
00305 Double_t rmax = fERmax->GetNumber();
00306 if (rmin>rmax) {
00307 rmin = rmax-0.1;
00308 fERmin->SetNumber(rmin);
00309 }
00310 DoModified();
00311 if (!IsDelayed()) DoApply();
00312 }
00313
00314
00315 void TGeoTorusEditor::DoRmax()
00316 {
00317
00318 Double_t r = fER->GetNumber();
00319 Double_t rmin = fERmin->GetNumber();
00320 Double_t rmax = fERmax->GetNumber();
00321 if (rmax<=rmin) {
00322 rmax = rmin+0.1;
00323 fERmax->SetNumber(rmax);
00324 }
00325 if (rmax>r) {
00326 rmax = r;
00327 fERmax->SetNumber(rmax);
00328 }
00329 DoModified();
00330 if (!IsDelayed()) DoApply();
00331 }
00332
00333
00334 void TGeoTorusEditor::DoPhi1()
00335 {
00336
00337 Double_t phi = fEPhi1->GetNumber();
00338 if (phi<0 || phi>360) {
00339 phi = 0;
00340 fEPhi1->SetNumber(phi);
00341 }
00342 DoModified();
00343 if (!IsDelayed()) DoApply();
00344 }
00345
00346
00347 void TGeoTorusEditor::DoDphi()
00348 {
00349
00350 Double_t dphi = fEDphi->GetNumber();
00351 if (dphi<=0 || dphi>360) {
00352 dphi = 1;
00353 fEDphi->SetNumber(dphi);
00354 }
00355 DoModified();
00356 if (!IsDelayed()) DoApply();
00357 }
00358