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 "TGeoTrd1Editor.h"
00029 #include "TGeoTabManager.h"
00030 #include "TGeoTrd1.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(TGeoTrd1Editor)
00043
00044 enum ETGeoTrd1Wid {
00045 kTRD1_NAME, kTRD1_X1, kTRD1_X2, kTRD1_Y, kTRD1_Z,
00046 kTRD1_APPLY, kTRD1_UNDO
00047 };
00048
00049
00050 TGeoTrd1Editor::TGeoTrd1Editor(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 fDxi1 = fDxi2 = fDyi = fDzi = 0.0;
00057 fNamei = "";
00058 fIsModified = kFALSE;
00059 fIsShapeEditable = kFALSE;
00060
00061
00062 MakeTitle("Name");
00063 fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kTRD1_NAME);
00064 fShapeName->Resize(135, fShapeName->GetDefaultHeight());
00065 fShapeName->SetToolTipText("Enter the box name");
00066 fShapeName->Associate(this);
00067 AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
00068
00069 TGTextEntry *nef;
00070 MakeTitle("Trd1 dimensions");
00071 TGCompositeFrame *compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame | kDoubleBorder);
00072
00073
00074 TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00075 kLHintsExpandX | kFixedWidth | kOwnBackground);
00076 f1->AddFrame(new TGLabel(f1, "DX1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00077 fEDx1 = new TGNumberEntry(f1, 0., 5, kTRD1_X1);
00078 fEDx1->SetNumAttr(TGNumberFormat::kNEAPositive);
00079 nef = (TGTextEntry*)fEDx1->GetNumberEntry();
00080 nef->SetToolTipText("Enter the half-lenth in X1");
00081 fEDx1->Associate(this);
00082 f1->AddFrame(fEDx1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00083 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00084
00085
00086 f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00087 kLHintsExpandX | kFixedWidth | kOwnBackground);
00088 f1->AddFrame(new TGLabel(f1, "DX2"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00089 fEDx2 = new TGNumberEntry(f1, 0., 5, kTRD1_X2);
00090 fEDx2->SetNumAttr(TGNumberFormat::kNEAPositive);
00091 nef = (TGTextEntry*)fEDx2->GetNumberEntry();
00092 nef->SetToolTipText("Enter the half-lenth in X2");
00093 fEDx2->Associate(this);
00094 f1->AddFrame(fEDx2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00095 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00096
00097
00098 TGCompositeFrame *f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00099 kLHintsExpandX | kFixedWidth | kOwnBackground);
00100 f2->AddFrame(new TGLabel(f2, "DY"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00101 fEDy = new TGNumberEntry(f2, 0., 5, kTRD1_Y);
00102 fEDy->SetNumAttr(TGNumberFormat::kNEAPositive);
00103 nef = (TGTextEntry*)fEDy->GetNumberEntry();
00104 nef->SetToolTipText("Enter the half-lenth in Y");
00105 fEDy->Associate(this);
00106 f2->AddFrame(fEDy, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00107 compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00108
00109
00110 TGCompositeFrame *f3 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00111 kLHintsExpandX | kFixedWidth | kOwnBackground);
00112 f3->AddFrame(new TGLabel(f3, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00113 fEDz = new TGNumberEntry(f3, 0., 5, kTRD1_Z);
00114 fEDz->SetNumAttr(TGNumberFormat::kNEAPositive);
00115 nef = (TGTextEntry*)fEDz->GetNumberEntry();
00116 nef->SetToolTipText("Enter the half-lenth in Z");
00117 fEDz->Associate(this);
00118 f3->AddFrame(fEDz, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00119 compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00120
00121 compxyz->Resize(150,30);
00122 AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00123
00124
00125 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
00126 fDelayed = new TGCheckButton(f1, "Delayed draw");
00127 f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
00128 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00129
00130
00131 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00132 fApply = new TGTextButton(f1, "Apply");
00133 f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00134 fApply->Associate(this);
00135 fUndo = new TGTextButton(f1, "Undo");
00136 f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
00137 fUndo->Associate(this);
00138 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00139 fUndo->SetSize(fApply->GetSize());
00140 }
00141
00142
00143 TGeoTrd1Editor::~TGeoTrd1Editor()
00144 {
00145
00146 TGFrameElement *el;
00147 TIter next(GetList());
00148 while ((el = (TGFrameElement *)next())) {
00149 if (el->fFrame->IsComposite())
00150 TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00151 }
00152 Cleanup();
00153 }
00154
00155
00156 void TGeoTrd1Editor::ConnectSignals2Slots()
00157 {
00158
00159 fApply->Connect("Clicked()", "TGeoTrd1Editor", this, "DoApply()");
00160 fUndo->Connect("Clicked()", "TGeoTrd1Editor", this, "DoUndo()");
00161 fShapeName->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
00162 fEDx1->Connect("ValueSet(Long_t)", "TGeoTrd1Editor", this, "DoDx1()");
00163 fEDx2->Connect("ValueSet(Long_t)", "TGeoTrd1Editor", this, "DoDx2()");
00164 fEDy->Connect("ValueSet(Long_t)", "TGeoTrd1Editor", this, "DoDy()");
00165 fEDz->Connect("ValueSet(Long_t)", "TGeoTrd1Editor", this, "DoDz()");
00166 fEDx1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
00167 fEDx2->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
00168 fEDy->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
00169 fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
00170 fInit = kFALSE;
00171 }
00172
00173
00174
00175 void TGeoTrd1Editor::SetModel(TObject* obj)
00176 {
00177
00178 if (obj == 0 || (obj->IsA()!=TGeoTrd1::Class())) {
00179 SetActive(kFALSE);
00180 return;
00181 }
00182 fShape = (TGeoTrd1*)obj;
00183 fDxi1 = fShape->GetDx1();
00184 fDxi2 = fShape->GetDx2();
00185 fDyi = fShape->GetDy();
00186 fDzi = fShape->GetDz();
00187 const char *sname = fShape->GetName();
00188 if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
00189 else {
00190 fShapeName->SetText(sname);
00191 fNamei = sname;
00192 }
00193 fEDx1->SetNumber(fDxi1);
00194 fEDx2->SetNumber(fDxi2);
00195 fEDy->SetNumber(fDyi);
00196 fEDz->SetNumber(fDzi);
00197 fApply->SetEnabled(kFALSE);
00198 fUndo->SetEnabled(kFALSE);
00199
00200
00201 if (fInit) ConnectSignals2Slots();
00202 SetActive();
00203 }
00204
00205
00206 Bool_t TGeoTrd1Editor::IsDelayed() const
00207 {
00208
00209 return (fDelayed->GetState() == kButtonDown);
00210 }
00211
00212
00213 void TGeoTrd1Editor::DoName()
00214 {
00215
00216 DoModified();
00217 }
00218
00219
00220 void TGeoTrd1Editor::DoApply()
00221 {
00222
00223 const char *name = fShapeName->GetText();
00224 if (strcmp(name,fShape->GetName())) fShape->SetName(name);
00225 Double_t dx1 = fEDx1->GetNumber();
00226 Double_t dx2 = fEDx2->GetNumber();
00227 Double_t dy = fEDy->GetNumber();
00228 Double_t dz = fEDz->GetNumber();
00229 Double_t param[4];
00230 param[0] = dx1;
00231 param[1] = dx2;
00232 param[2] = dy;
00233 param[3] = dz;
00234 fShape->SetDimensions(param);
00235 fShape->ComputeBBox();
00236 fUndo->SetEnabled();
00237 fApply->SetEnabled(kFALSE);
00238 if (fPad) {
00239 if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00240 fShape->Draw();
00241 fPad->GetView()->ShowAxis();
00242 } else Update();
00243 }
00244 }
00245
00246
00247 void TGeoTrd1Editor::DoModified()
00248 {
00249
00250 fApply->SetEnabled();
00251 }
00252
00253
00254 void TGeoTrd1Editor::DoUndo()
00255 {
00256
00257 fEDx1->SetNumber(fDxi1);
00258 fEDx2->SetNumber(fDxi2);
00259 fEDy->SetNumber(fDyi);
00260 fEDz->SetNumber(fDzi);
00261 DoApply();
00262 fUndo->SetEnabled(kFALSE);
00263 fApply->SetEnabled(kFALSE);
00264 }
00265
00266
00267 void TGeoTrd1Editor::DoDx1()
00268 {
00269
00270 Double_t dx1 = fEDx1->GetNumber();
00271 Double_t dx2 = fEDx2->GetNumber();
00272 if (dx1<0) {
00273 dx1 = 0;
00274 fEDx1->SetNumber(dx1);
00275 }
00276 if (dx1<1.e-6 && dx2<1.e-6) {
00277 dx1 = 0.1;
00278 fEDx1->SetNumber(dx1);
00279 }
00280 DoModified();
00281 if (!IsDelayed()) DoApply();
00282 }
00283
00284
00285 void TGeoTrd1Editor::DoDx2()
00286 {
00287
00288 Double_t dx1 = fEDx1->GetNumber();
00289 Double_t dx2 = fEDx2->GetNumber();
00290 if (dx2<0) {
00291 dx2 = 0;
00292 fEDx2->SetNumber(dx2);
00293 }
00294 if (dx1<1.e-6 && dx2<1.e-6) {
00295 dx2 = 0.1;
00296 fEDx2->SetNumber(dx2);
00297 }
00298 DoModified();
00299 if (!IsDelayed()) DoApply();
00300 }
00301
00302
00303 void TGeoTrd1Editor::DoDy()
00304 {
00305
00306 Double_t dy = fEDy->GetNumber();
00307 if (dy<=0) {
00308 dy = 0.1;
00309 fEDy->SetNumber(dy);
00310 }
00311 DoModified();
00312 if (!IsDelayed()) DoApply();
00313 }
00314
00315
00316 void TGeoTrd1Editor::DoDz()
00317 {
00318
00319 Double_t dz = fEDz->GetNumber();
00320 if (dz<=0) {
00321 dz = 0.1;
00322 fEDz->SetNumber(dz);
00323 }
00324 DoModified();
00325 if (!IsDelayed()) DoApply();
00326 }
00327
00328