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 "TGeoParaEditor.h"
00029 #include "TGeoTabManager.h"
00030 #include "TGeoPara.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(TGeoParaEditor)
00043
00044 enum ETGeoParaWid {
00045 kPARA_NAME, kPARA_X, kPARA_Y, kPARA_Z, kPARA_ALPHA,
00046 kPARA_THETA, kPARA_PHI, kPARA_APPLY, kPARA_UNDO
00047 };
00048
00049
00050 TGeoParaEditor::TGeoParaEditor(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 fXi = fYi = fZi = fAlphai = fThetai = fPhii = 0.0;
00057 fNamei = "";
00058 fIsModified = kFALSE;
00059 fIsShapeEditable = kTRUE;
00060
00061
00062 MakeTitle("Name");
00063 fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kPARA_NAME);
00064 fShapeName->Resize(135, fShapeName->GetDefaultHeight());
00065 fShapeName->SetToolTipText("Enter the parallelipiped 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, "DX"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00074 fEDx = new TGNumberEntry(f1, 0., 5, kPARA_X);
00075 fEDx->SetNumAttr(TGNumberFormat::kNEAPositive);
00076 fEDx->Resize(100, fEDx->GetDefaultHeight());
00077 nef = (TGTextEntry*)fEDx->GetNumberEntry();
00078 nef->SetToolTipText("Enter the half-lenth in X");
00079 fEDx->Associate(this);
00080 f1->AddFrame(fEDx, 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, "DY"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00086 fEDy = new TGNumberEntry(f1, 0., 5, kPARA_Y);
00087 fEDy->SetNumAttr(TGNumberFormat::kNEAPositive);
00088 fEDy->Resize(100, fEDy->GetDefaultHeight());
00089 nef = (TGTextEntry*)fEDy->GetNumberEntry();
00090 nef->SetToolTipText("Enter the half-lenth in Y");
00091 fEDy->Associate(this);
00092 f1->AddFrame(fEDy, 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, "Dz"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00098 fEDz = new TGNumberEntry(f1, 0., 5, kPARA_Z);
00099 fEDz->SetNumAttr(TGNumberFormat::kNEAPositive);
00100 fEDz->Resize(100, fEDz->GetDefaultHeight());
00101 nef = (TGTextEntry*)fEDz->GetNumberEntry();
00102 nef->SetToolTipText("Enter the half-lenth in Z");
00103 fEDz->Associate(this);
00104 f1->AddFrame(fEDz, 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, "Alpha"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00110 fEAlpha = new TGNumberEntry(f1, 0., 5, kPARA_ALPHA);
00111 fEAlpha->Resize(100, fEAlpha->GetDefaultHeight());
00112 nef = (TGTextEntry*)fEAlpha->GetNumberEntry();
00113 nef->SetToolTipText("Enter the angle with respect to Y axis [deg]");
00114 fEAlpha->Associate(this);
00115 f1->AddFrame(fEAlpha, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00116 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00117
00118
00119 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00120 f1->AddFrame(new TGLabel(f1, "Theta"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00121 fETheta = new TGNumberEntry(f1, 0., 5, kPARA_THETA);
00122 fETheta->SetNumAttr(TGNumberFormat::kNEAPositive);
00123 fETheta->Resize(100, fETheta->GetDefaultHeight());
00124 nef = (TGTextEntry*)fETheta->GetNumberEntry();
00125 nef->SetToolTipText("Enter the theta angle of the para axis [deg]");
00126 fETheta->Associate(this);
00127 f1->AddFrame(fETheta, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00128 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00129
00130
00131 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00132 f1->AddFrame(new TGLabel(f1, "Phi"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00133 fEPhi = new TGNumberEntry(f1, 0., 5, kPARA_PHI);
00134 fEPhi->SetNumAttr(TGNumberFormat::kNEAPositive);
00135 fEPhi->Resize(100, fEPhi->GetDefaultHeight());
00136 nef = (TGTextEntry*)fEPhi->GetNumberEntry();
00137 nef->SetToolTipText("Enter the phi angle of the para axis [deg]");
00138 fEPhi->Associate(this);
00139 f1->AddFrame(fEPhi, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00140 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00141
00142
00143 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
00144 fDelayed = new TGCheckButton(f1, "Delayed draw");
00145 f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
00146 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00147
00148
00149 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00150 fApply = new TGTextButton(f1, "Apply");
00151 f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00152 fApply->Associate(this);
00153 fUndo = new TGTextButton(f1, "Undo");
00154 f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
00155 fUndo->Associate(this);
00156 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00157 fUndo->SetSize(fApply->GetSize());
00158 }
00159
00160
00161 TGeoParaEditor::~TGeoParaEditor()
00162 {
00163
00164 TGFrameElement *el;
00165 TIter next(GetList());
00166 while ((el = (TGFrameElement *)next())) {
00167 if (el->fFrame->IsComposite())
00168 TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00169 }
00170 Cleanup();
00171 }
00172
00173
00174 void TGeoParaEditor::ConnectSignals2Slots()
00175 {
00176
00177 fApply->Connect("Clicked()", "TGeoParaEditor", this, "DoApply()");
00178 fUndo->Connect("Clicked()", "TGeoParaEditor", this, "DoUndo()");
00179 fShapeName->Connect("TextChanged(const char *)", "TGeoParaEditor", this, "DoModified()");
00180 fEDx->Connect("ValueSet(Long_t)", "TGeoParaEditor", this, "DoX()");
00181 fEDy->Connect("ValueSet(Long_t)", "TGeoParaEditor", this, "DoY()");
00182 fEDz->Connect("ValueSet(Long_t)", "TGeoParaEditor", this, "DoZ()");
00183 fEAlpha->Connect("ValueSet(Long_t)", "TGeoParaEditor", this, "DoAlpha()");
00184 fETheta->Connect("ValueSet(Long_t)", "TGeoParaEditor", this, "DoTheta()");
00185 fEPhi->Connect("ValueSet(Long_t)", "TGeoParaEditor", this, "DoPhi()");
00186 fEDx->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoParaEditor", this, "DoModified()");
00187 fEDy->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoParaEditor", this, "DoModified()");
00188 fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoParaEditor", this, "DoModified()");
00189 fEAlpha->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoParaEditor", this, "DoModified()");
00190 fETheta->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoParaEditor", this, "DoModified()");
00191 fEPhi->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoParaEditor", this, "DoModified()");
00192 fInit = kFALSE;
00193 }
00194
00195
00196
00197 void TGeoParaEditor::SetModel(TObject* obj)
00198 {
00199
00200 if (obj == 0 || (obj->IsA()!=TGeoPara::Class())) {
00201 SetActive(kFALSE);
00202 return;
00203 }
00204 fShape = (TGeoPara*)obj;
00205 fXi = fShape->GetX();
00206 fYi = fShape->GetY();
00207 fZi = fShape->GetZ();
00208 fAlphai = fShape->GetAlpha();
00209 fThetai = fShape->GetTheta();
00210 fPhii = fShape->GetPhi();
00211 const char *sname = fShape->GetName();
00212 if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
00213 else {
00214 fShapeName->SetText(sname);
00215 fNamei = sname;
00216 }
00217 fEDx->SetNumber(fXi);
00218 fEDy->SetNumber(fYi);
00219 fEDz->SetNumber(fZi);
00220 fEAlpha->SetNumber(fAlphai);
00221 fETheta->SetNumber(fThetai);
00222 fEPhi->SetNumber(fPhii);
00223 fApply->SetEnabled(kFALSE);
00224 fUndo->SetEnabled(kFALSE);
00225
00226 if (fInit) ConnectSignals2Slots();
00227 SetActive();
00228 }
00229
00230
00231 Bool_t TGeoParaEditor::IsDelayed() const
00232 {
00233
00234 return (fDelayed->GetState() == kButtonDown);
00235 }
00236
00237
00238 void TGeoParaEditor::DoName()
00239 {
00240
00241 DoModified();
00242 }
00243
00244
00245 void TGeoParaEditor::DoApply()
00246 {
00247
00248 const char *name = fShapeName->GetText();
00249 if (strcmp(name,fShape->GetName())) fShape->SetName(name);
00250 Double_t dx = fEDx->GetNumber();
00251 Double_t dy = fEDy->GetNumber();
00252 Double_t dz = fEDz->GetNumber();
00253 Double_t alpha = fEAlpha->GetNumber();
00254 Double_t theta = fETheta->GetNumber();
00255 Double_t phi = fEPhi->GetNumber();
00256 Double_t param[6];
00257 param[0] = dx;
00258 param[1] = dy;
00259 param[2] = dz;
00260 param[3] = alpha;
00261 param[4] = theta;
00262 param[5] = phi;
00263 fShape->SetDimensions(param);
00264 fShape->ComputeBBox();
00265 fUndo->SetEnabled();
00266 fApply->SetEnabled(kFALSE);
00267 if (fPad) {
00268 if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00269 TView *view = fPad->GetView();
00270 if (!view) {
00271 fShape->Draw();
00272 fPad->GetView()->ShowAxis();
00273 } else {
00274 view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(),
00275 fShape->GetDX(), fShape->GetDY(), fShape->GetDZ());
00276 Update();
00277 }
00278 } else Update();
00279 }
00280 }
00281
00282
00283 void TGeoParaEditor::DoModified()
00284 {
00285
00286 fApply->SetEnabled();
00287 }
00288
00289
00290 void TGeoParaEditor::DoUndo()
00291 {
00292
00293 fEDx->SetNumber(fXi);
00294 fEDy->SetNumber(fYi);
00295 fEDz->SetNumber(fZi);
00296 fEAlpha->SetNumber(fAlphai);
00297 fETheta->SetNumber(fThetai);
00298 fEPhi->SetNumber(fPhii);
00299 DoApply();
00300 fUndo->SetEnabled(kFALSE);
00301 fApply->SetEnabled(kFALSE);
00302 }
00303
00304
00305 void TGeoParaEditor::DoX()
00306 {
00307
00308 Double_t dx = fEDx->GetNumber();
00309 if (dx<=0) {
00310 dx = 0.1;
00311 fEDx->SetNumber(dx);
00312 }
00313 DoModified();
00314 if (!IsDelayed()) DoApply();
00315 }
00316
00317
00318 void TGeoParaEditor::DoY()
00319 {
00320
00321 Double_t dy = fEDy->GetNumber();
00322 if (dy<=0) {
00323 dy = 0.1;
00324 fEDy->SetNumber(dy);
00325 }
00326 DoModified();
00327 if (!IsDelayed()) DoApply();
00328 }
00329
00330
00331 void TGeoParaEditor::DoZ()
00332 {
00333
00334 Double_t dz = fEDz->GetNumber();
00335 if (dz<=0) {
00336 dz = 0.1;
00337 fEDz->SetNumber(dz);
00338 }
00339 DoModified();
00340 if (!IsDelayed()) DoApply();
00341 }
00342
00343
00344 void TGeoParaEditor::DoAlpha()
00345 {
00346
00347 Double_t alpha = fEAlpha->GetNumber();
00348 if (TMath::Abs(alpha)>=90) {
00349 alpha = 89.9*TMath::Sign(1.,alpha);
00350 fEAlpha->SetNumber(alpha);
00351 }
00352 DoModified();
00353 if (!IsDelayed()) DoApply();
00354 }
00355
00356
00357 void TGeoParaEditor::DoTheta()
00358 {
00359
00360 Double_t theta = fETheta->GetNumber();
00361 if (theta<0) {
00362 theta = 0;
00363 fETheta->SetNumber(theta);
00364 }
00365 if (theta>180) {
00366 theta = 180;
00367 fETheta->SetNumber(theta);
00368 }
00369 DoModified();
00370 if (!IsDelayed()) DoApply();
00371 }
00372
00373
00374 void TGeoParaEditor::DoPhi()
00375 {
00376
00377 Double_t phi = fEPhi->GetNumber();
00378 if (phi<0 || phi>360) {
00379 phi = 0;
00380 fEPhi->SetNumber(phi);
00381 }
00382 DoModified();
00383 if (!IsDelayed()) DoApply();
00384 }
00385