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 "TGeoBBoxEditor.h"
00029 #include "TGeoTabManager.h"
00030 #include "TGeoBBox.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(TGeoBBoxEditor)
00043
00044 enum ETGeoBBoxWid {
00045 kBOX_NAME, kBOX_X, kBOX_Y, kBOX_Z,
00046 kBOX_OX, kBOX_OY, kBOX_OZ,
00047 kBOX_APPLY, kBOX_CANCEL, kBOX_UNDO
00048 };
00049
00050
00051 TGeoBBoxEditor::TGeoBBoxEditor(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
00057 fShape = 0;
00058 fDxi = fDyi = fDzi = 0.0;
00059 memset(fOrigi, 0, 3*sizeof(Double_t));
00060 fNamei = "";
00061 fIsModified = kFALSE;
00062 fIsShapeEditable = kFALSE;
00063
00064
00065 MakeTitle("Name");
00066 fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kBOX_NAME);
00067 fShapeName->Resize(135, fShapeName->GetDefaultHeight());
00068 fShapeName->SetToolTipText("Enter the box name");
00069 fShapeName->Associate(this);
00070 AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
00071
00072 TGTextEntry *nef;
00073 MakeTitle("Box half-lengths");
00074 TGCompositeFrame *compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame | kDoubleBorder);
00075
00076 TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00077 kLHintsExpandX | kFixedWidth | kOwnBackground);
00078 f1->AddFrame(new TGLabel(f1, "DX"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00079 fBoxDx = new TGNumberEntry(f1, 0., 5, kBOX_X);
00080 fBoxDx->SetNumAttr(TGNumberFormat::kNEAPositive);
00081 nef = (TGTextEntry*)fBoxDx->GetNumberEntry();
00082 nef->SetToolTipText("Enter the box half-lenth in X");
00083 fBoxDx->Associate(this);
00084 f1->AddFrame(fBoxDx, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00085 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00086
00087
00088 TGCompositeFrame *f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00089 kLHintsExpandX | kFixedWidth | kOwnBackground);
00090 f2->AddFrame(new TGLabel(f2, "DY"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00091 fBoxDy = new TGNumberEntry(f2, 0., 5, kBOX_Y);
00092 fBoxDy->SetNumAttr(TGNumberFormat::kNEAPositive);
00093 nef = (TGTextEntry*)fBoxDy->GetNumberEntry();
00094 nef->SetToolTipText("Enter the box half-lenth in Y");
00095 fBoxDy->Associate(this);
00096 f2->AddFrame(fBoxDy, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00097 compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00098
00099
00100 TGCompositeFrame *f3 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00101 kLHintsExpandX | kFixedWidth | kOwnBackground);
00102 f3->AddFrame(new TGLabel(f3, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00103 fBoxDz = new TGNumberEntry(f3, 0., 5, kBOX_Z);
00104 fBoxDz->SetNumAttr(TGNumberFormat::kNEAPositive);
00105 nef = (TGTextEntry*)fBoxDz->GetNumberEntry();
00106 nef->SetToolTipText("Enter the box half-lenth in Z");
00107 fBoxDz->Associate(this);
00108 f3->AddFrame(fBoxDz, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00109 compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00110
00111 compxyz->Resize(150,30);
00112 AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00113
00114 MakeTitle("Box origin");
00115 compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame | kDoubleBorder);
00116
00117 f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00118 kLHintsExpandX | kFixedWidth | kOwnBackground);
00119 f1->AddFrame(new TGLabel(f1, "OX"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00120 fBoxOx = new TGNumberEntry(f1, 0., 5, kBOX_OX);
00121 nef = (TGTextEntry*)fBoxOx->GetNumberEntry();
00122 nef->SetToolTipText("Enter the box origin X coordinate");
00123 fBoxOx->Associate(this);
00124 f1->AddFrame(fBoxOx, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00125 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00126
00127
00128 f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00129 kLHintsExpandX | kFixedWidth | kOwnBackground);
00130 f2->AddFrame(new TGLabel(f2, "OY"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00131 fBoxOy = new TGNumberEntry(f2, 0., 5, kBOX_OY);
00132 nef = (TGTextEntry*)fBoxOy->GetNumberEntry();
00133 nef->SetToolTipText("Enter the box origin Y coordinate");
00134 fBoxOy->Associate(this);
00135 f2->AddFrame(fBoxOy, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00136 compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00137
00138
00139 f3 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00140 kLHintsExpandX | kFixedWidth | kOwnBackground);
00141 f3->AddFrame(new TGLabel(f3, "OZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00142 fBoxOz = new TGNumberEntry(f3, 0., 5, kBOX_OZ);
00143 nef = (TGTextEntry*)fBoxOz->GetNumberEntry();
00144 nef->SetToolTipText("Enter the box origin Z coordinate");
00145 fBoxOz->Associate(this);
00146 f3->AddFrame(fBoxOz, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00147 compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00148
00149 compxyz->Resize(150,30);
00150 AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00151
00152
00153 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
00154 fDelayed = new TGCheckButton(f1, "Delayed draw");
00155 f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
00156 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00157
00158
00159 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00160 fApply = new TGTextButton(f1, "Apply");
00161 f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00162 fApply->Associate(this);
00163 fUndo = new TGTextButton(f1, "Undo");
00164 f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
00165 fUndo->Associate(this);
00166 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00167 fUndo->SetSize(fApply->GetSize());
00168 }
00169
00170
00171 TGeoBBoxEditor::~TGeoBBoxEditor()
00172 {
00173
00174
00175 TGFrameElement *el;
00176 TIter next(GetList());
00177 while ((el = (TGFrameElement *)next())) {
00178 if (el->fFrame->IsComposite())
00179 TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00180 }
00181 Cleanup();
00182 }
00183
00184
00185 void TGeoBBoxEditor::ConnectSignals2Slots()
00186 {
00187
00188
00189 fApply->Connect("Clicked()", "TGeoBBoxEditor", this, "DoApply()");
00190 fUndo->Connect("Clicked()", "TGeoBBoxEditor", this, "DoUndo()");
00191 fShapeName->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
00192 fBoxDx->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoDx()");
00193 fBoxDy->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoDy()");
00194 fBoxDz->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoDz()");
00195 fBoxDx->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
00196 fBoxDy->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
00197 fBoxDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
00198 fBoxOx->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoOx()");
00199 fBoxOy->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoOy()");
00200 fBoxOz->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoOz()");
00201 fBoxOx->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
00202 fBoxOy->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
00203 fBoxOz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
00204 fInit = kFALSE;
00205 }
00206
00207
00208
00209 void TGeoBBoxEditor::SetModel(TObject* obj)
00210 {
00211
00212 if (obj == 0 || (obj->IsA()!=TGeoBBox::Class())) {
00213 SetActive(kFALSE);
00214 return;
00215 }
00216 fShape = (TGeoBBox*)obj;
00217 fDxi = fShape->GetDX();
00218 fDyi = fShape->GetDY();
00219 fDzi = fShape->GetDZ();
00220 memcpy(fOrigi, fShape->GetOrigin(), 3*sizeof(Double_t));
00221 const char *sname = fShape->GetName();
00222 if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
00223 else {
00224 fShapeName->SetText(sname);
00225 fNamei = sname;
00226 }
00227 fBoxDx->SetNumber(fDxi);
00228 fBoxDy->SetNumber(fDyi);
00229 fBoxDz->SetNumber(fDzi);
00230 fBoxOx->SetNumber(fOrigi[0]);
00231 fBoxOy->SetNumber(fOrigi[1]);
00232 fBoxOz->SetNumber(fOrigi[2]);
00233 fApply->SetEnabled(kFALSE);
00234 fUndo->SetEnabled(kFALSE);
00235
00236 if (fInit) ConnectSignals2Slots();
00237 SetActive();
00238 }
00239
00240
00241 Bool_t TGeoBBoxEditor::IsDelayed() const
00242 {
00243
00244 return (fDelayed->GetState() == kButtonDown);
00245 }
00246
00247
00248 void TGeoBBoxEditor::DoName()
00249 {
00250
00251 DoModified();
00252 }
00253
00254
00255 void TGeoBBoxEditor::DoApply()
00256 {
00257
00258 const char *name = fShapeName->GetText();
00259 if (strcmp(name,fShape->GetName())) fShape->SetName(name);
00260 Double_t dx = fBoxDx->GetNumber();
00261 Double_t dy = fBoxDy->GetNumber();
00262 Double_t dz = fBoxDz->GetNumber();
00263 Double_t orig[3];
00264 orig[0] = fBoxOx->GetNumber();
00265 orig[1] = fBoxOy->GetNumber();
00266 orig[2] = fBoxOz->GetNumber();
00267 fShape->SetBoxDimensions(dx, dy, dz, orig);
00268 fUndo->SetEnabled();
00269 fApply->SetEnabled(kFALSE);
00270 if (fPad) {
00271 if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00272 TView *view = fPad->GetView();
00273 if (!view) {
00274 fShape->Draw();
00275 fPad->GetView()->ShowAxis();
00276 } else {
00277 const Double_t *origin = fShape->GetOrigin();
00278 view->SetRange(origin[0]-fShape->GetDX(), origin[1]-fShape->GetDY(), origin[2]-fShape->GetDZ(),
00279 origin[0]+fShape->GetDX(), origin[1]+fShape->GetDY(), origin[2]+fShape->GetDZ());
00280 Update();
00281 }
00282 } else Update();
00283 }
00284 }
00285
00286
00287 void TGeoBBoxEditor::DoModified()
00288 {
00289
00290 fApply->SetEnabled();
00291 }
00292
00293
00294 void TGeoBBoxEditor::DoUndo()
00295 {
00296
00297 fBoxDx->SetNumber(fDxi);
00298 fBoxDy->SetNumber(fDyi);
00299 fBoxDz->SetNumber(fDzi);
00300 fBoxOx->SetNumber(fOrigi[0]);
00301 fBoxOy->SetNumber(fOrigi[1]);
00302 fBoxOz->SetNumber(fOrigi[2]);
00303 DoApply();
00304 fUndo->SetEnabled(kFALSE);
00305 fApply->SetEnabled(kFALSE);
00306 }
00307
00308
00309 void TGeoBBoxEditor::DoDx()
00310 {
00311
00312 Double_t dx = fBoxDx->GetNumber();
00313 if (dx<=0) {
00314 dx=0.1;
00315 fBoxDx->SetNumber(dx);
00316 }
00317 DoModified();
00318 if (!IsDelayed()) DoApply();
00319 }
00320
00321
00322 void TGeoBBoxEditor::DoDy()
00323 {
00324
00325 Double_t dy = fBoxDy->GetNumber();
00326 if (dy<=0) {
00327 dy=0.1;
00328 fBoxDy->SetNumber(dy);
00329 }
00330 DoModified();
00331 if (!IsDelayed()) DoApply();
00332 }
00333
00334
00335 void TGeoBBoxEditor::DoDz()
00336 {
00337
00338 Double_t dz = fBoxDz->GetNumber();
00339 if (dz<=0) {
00340 dz=0.1;
00341 fBoxDz->SetNumber(dz);
00342 }
00343 DoModified();
00344 if (!IsDelayed()) DoApply();
00345 }
00346
00347
00348 void TGeoBBoxEditor::DoOx()
00349 {
00350
00351 DoModified();
00352 if (!IsDelayed()) DoApply();
00353 }
00354
00355
00356 void TGeoBBoxEditor::DoOy()
00357 {
00358
00359 DoModified();
00360 if (!IsDelayed()) DoApply();
00361 }
00362
00363
00364 void TGeoBBoxEditor::DoOz()
00365 {
00366
00367 DoModified();
00368 if (!IsDelayed()) DoApply();
00369 }
00370
00371