TGeoMaterialEditor.cxx

Go to the documentation of this file.
00001 // @(#):$Id: TGeoMaterialEditor.cxx 36535 2010-11-08 14:41:54Z agheata $
00002 // Author: M.Gheata 
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //______________________________________________________________________________
00013 //                                                                      
00014 //  TGeoMaterialEditor, TGeoMixtureEditor
00015 // =======================================
00016 //
00017 //   Editors for materials and mixtures.                                                                      
00018 //______________________________________________________________________________
00019 
00020 #include "TGeoMaterialEditor.h"
00021 #include "TGeoTabManager.h"
00022 #include "TGeoMaterial.h"
00023 #include "TGeoManager.h"
00024 #include "TVirtualGeoPainter.h"
00025 #include "TPad.h"
00026 #include "TView.h"
00027 #include "TGTab.h"
00028 #include "TGComboBox.h"
00029 #include "TGButton.h"
00030 #include "TGTextEntry.h"
00031 #include "TGNumberEntry.h"
00032 #include "TGLabel.h"
00033 #include "TGListView.h"
00034 
00035 ClassImp(TGeoMaterialEditor)
00036 
00037 enum ETGeoMaterialWid {
00038    kMATERIAL_NAME, kMATERIAL_A, kMATERIAL_Z, kMATERIAL_RHO,
00039    kMATERIAL_RAD, kMATERIAL_ABS, kMATERIAL_STATE, kMATERIAL_TEMP, kMATERIAL_PRES,
00040    kMATERIAL_APPLY, kMATERIAL_CANCEL, kMATERIAL_UNDO
00041 };
00042 
00043 enum ETGeoMaterialStates {
00044    kMAT_UNDEFINED, kMAT_SOLID, kMAT_LIQUID, kMAT_GAS
00045 };   
00046 
00047 enum ETGeoMixtureWid {
00048    kMIX_ELEM, kMIX_CHK1, kMIX_FRAC, kMIX_CHK2, kMIX_NATOMS, kMIX_ADDELEM
00049 };
00050 
00051 //______________________________________________________________________________
00052 TGeoMaterialEditor::TGeoMaterialEditor(const TGWindow *p, Int_t width,
00053                                    Int_t height, UInt_t options, Pixel_t back)
00054    : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
00055 {
00056    // Constructor for material editor.
00057    fMaterial   = 0;
00058    fAi = fZi = 0;
00059    fDensityi = 0.0;
00060    fNamei = "";
00061    fIsModified = kFALSE;
00062    fIsMaterialEditable = kTRUE;
00063 
00064    // TextEntry for material name
00065    MakeTitle("Name");
00066    fMaterialName = new TGTextEntry(this, new TGTextBuffer(50), kMATERIAL_NAME);
00067    fMaterialName->SetDefaultSize(135, fMaterialName->GetDefaultHeight());
00068    fMaterialName->SetToolTipText("Enter the material name");
00069    fMaterialName->Associate(this);
00070    AddFrame(fMaterialName, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 1, 1, 2, 5));
00071 
00072    TGTextEntry *nef;
00073    MakeTitle("Material properties");
00074    TGCompositeFrame *f1 = new TGCompositeFrame(this, 118, 10, kHorizontalFrame |
00075                                  kFixedWidth | kOwnBackground);
00076    f1->AddFrame(new TGLabel(f1, "A"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00077    fMatA = new TGNumberEntry(f1, 0., 6, kMATERIAL_A, TGNumberFormat::kNESRealThree);
00078    nef = (TGTextEntry*)fMatA->GetNumberEntry();
00079    nef->SetToolTipText("Enter the atomic mass");
00080    fMatA->Associate(this);
00081    f1->AddFrame(fMatA, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00082    f1->AddFrame(new TGLabel(f1, "Z"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00083    fMatZ = new TGNumberEntry(f1, 0., 4, kMATERIAL_Z, TGNumberFormat::kNESInteger);
00084    nef = (TGTextEntry*)fMatZ->GetNumberEntry();
00085    nef->SetToolTipText("Enter the atomic charge");
00086    fMatZ->Associate(this);
00087    f1->AddFrame(fMatZ, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00088    f1->Resize(150,30);
00089    AddFrame(f1, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
00090    
00091    
00092    TGCompositeFrame *compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame | kDoubleBorder);
00093    // Combo box for material state
00094    f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00095                              kLHintsExpandX | kFixedWidth | kOwnBackground);
00096    f1->AddFrame(new TGLabel(f1, "State"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00097    fMatState = new TGComboBox(f1, kMATERIAL_STATE);
00098    fMatState->AddEntry("Undefined", TGeoMaterial::kMatStateUndefined);
00099    fMatState->AddEntry("Solid", TGeoMaterial::kMatStateSolid);
00100    fMatState->AddEntry("Liquid", TGeoMaterial::kMatStateLiquid);
00101    fMatState->AddEntry("Gas", TGeoMaterial::kMatStateGas);
00102    fMatState->Resize(90, fMaterialName->GetDefaultHeight());
00103    f1->AddFrame(fMatState, new TGLayoutHints(kLHintsRight , 2, 2, 1, 1));
00104    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
00105 
00106    // Number entry for density
00107    f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00108                              kLHintsExpandX | kFixedWidth | kOwnBackground);
00109    f1->AddFrame(new TGLabel(f1, "Density"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00110    fMatDensity = new TGNumberEntry(f1, 0., 5, kMATERIAL_RHO, TGNumberFormat::kNESRealThree);
00111    fMatDensity->Resize(90, fMaterialName->GetDefaultHeight());
00112    nef = (TGTextEntry*)fMatDensity->GetNumberEntry();
00113    nef->SetToolTipText("Enter material density in [g/cm3]");
00114    fMatDensity->Associate(this);
00115    f1->AddFrame(fMatDensity, new TGLayoutHints(kLHintsRight, 2, 2, 1, 1));
00116    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
00117    
00118    // Number entry for temperature
00119    f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00120                              kLHintsExpandX | kFixedWidth | kOwnBackground);
00121    f1->AddFrame(new TGLabel(f1, "Temperature"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00122    fMatTemperature = new TGNumberEntry(f1, 0., 5, kMATERIAL_TEMP, TGNumberFormat::kNESRealTwo);
00123    fMatTemperature->Resize(90, fMaterialName->GetDefaultHeight());
00124    nef = (TGTextEntry*)fMatTemperature->GetNumberEntry();
00125    nef->SetToolTipText("Enter material temperature in [Kelvin]");
00126    fMatTemperature->Associate(this);
00127    f1->AddFrame(fMatTemperature, new TGLayoutHints(kLHintsRight, 2, 2, 1, 1));
00128    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
00129 
00130    // Number entry for pressure
00131    f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00132                              kLHintsExpandX | kFixedWidth | kOwnBackground);
00133    f1->AddFrame(new TGLabel(f1, "Pressure"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00134    fMatPressure = new TGNumberEntry(f1, 0., 5, kMATERIAL_PRES, TGNumberFormat::kNESRealThree);
00135    fMatPressure->Resize(90, fMaterialName->GetDefaultHeight());
00136    nef = (TGTextEntry*)fMatPressure->GetNumberEntry();
00137    nef->SetToolTipText("Enter material pressure in [bar]");
00138    fMatPressure->Associate(this);
00139    f1->AddFrame(fMatPressure, new TGLayoutHints(kLHintsRight, 2, 2, 1, 1));
00140    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
00141 
00142    // Number entry for radiation length
00143    f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00144                              kLHintsExpandX | kFixedWidth | kOwnBackground);
00145    f1->AddFrame(new TGLabel(f1, "RadLen"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00146    fMatRadLen = new TGNumberEntry(f1, 0., 5, kMATERIAL_RAD);
00147    fMatRadLen->Resize(90, fMaterialName->GetDefaultHeight());
00148    nef = (TGTextEntry*)fMatRadLen->GetNumberEntry();
00149    nef->SetToolTipText("Computed radiation length");
00150    fMatRadLen->Associate(this);
00151    f1->AddFrame(fMatRadLen, new TGLayoutHints(kLHintsRight, 2, 2, 1, 1));
00152    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
00153    
00154    // Number entry for absorbtion length
00155    f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00156                              kLHintsExpandX | kFixedWidth | kOwnBackground);
00157    f1->AddFrame(new TGLabel(f1, "AbsLen"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00158    fMatAbsLen = new TGNumberEntry(f1, 0., 5, kMATERIAL_ABS);
00159    fMatAbsLen->Resize(90, fMaterialName->GetDefaultHeight());
00160    nef = (TGTextEntry*)fMatAbsLen->GetNumberEntry();
00161    nef->SetToolTipText("Absorbtion length");
00162    fMatAbsLen->Associate(this);
00163    f1->AddFrame(fMatAbsLen, new TGLayoutHints(kLHintsRight, 2, 2, 1, 1));
00164    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
00165       
00166    compxyz->Resize(150,30);
00167    AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 0, 0, 2, 2));
00168 
00169    // Buttons
00170    f23 = new TGCompositeFrame(this, 118, 20, kHorizontalFrame | kSunkenFrame | kDoubleBorder);
00171    fApply = new TGTextButton(f23, "Apply");
00172    f23->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 1, 1));
00173    fApply->Associate(this);
00174    fUndo = new TGTextButton(f23, " Undo ");
00175    f23->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 1, 1));
00176    fUndo->Associate(this);
00177    AddFrame(f23,  new TGLayoutHints(kLHintsLeft, 0, 0, 4, 4));  
00178    fUndo->SetSize(fApply->GetSize());
00179 }
00180 
00181 //______________________________________________________________________________
00182 TGeoMaterialEditor::~TGeoMaterialEditor()
00183 {
00184 // Destructor
00185    TGFrameElement *el;
00186    TIter next(GetList());
00187    while ((el = (TGFrameElement *)next())) {
00188       if (el->fFrame->IsComposite()) 
00189          TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00190    }
00191    Cleanup();   
00192 }
00193 
00194 //______________________________________________________________________________
00195 void TGeoMaterialEditor::ConnectSignals2Slots()
00196 {
00197    // Connect signals to slots.
00198    fApply->Connect("Clicked()", "TGeoMaterialEditor", this, "DoApply()");
00199    fUndo->Connect("Clicked()", "TGeoMaterialEditor", this, "DoUndo()");
00200    fMaterialName->Connect("TextChanged(const char *)", "TGeoMaterialEditor", this, "DoName()");
00201    fMatA->Connect("ValueSet(Long_t)", "TGeoMaterialEditor", this, "DoA()");
00202    fMatZ->Connect("ValueSet(Long_t)", "TGeoMaterialEditor", this, "DoZ()");
00203    fMatState->Connect("Selected(Int_t)", "TGeoMaterialEditor", this, "DoState(Int_t)");
00204    fMatDensity->Connect("ValueSet(Long_t)", "TGeoMaterialEditor", this, "DoDensity()");
00205    fMatTemperature->Connect("ValueSet(Long_t)", "TGeoMaterialEditor", this, "DoTemperature()");
00206    fMatPressure->Connect("ValueSet(Long_t)", "TGeoMaterialEditor", this, "DoPressure()");
00207    fMatRadLen->Connect("ValueSet(Long_t)", "TGeoMaterialEditor", this, "DoRadAbs()");
00208    fMatAbsLen->Connect("ValueSet(Long_t)", "TGeoMaterialEditor", this, "DoRadAbs()");
00209    fInit = kFALSE;
00210 }
00211 
00212 //______________________________________________________________________________
00213 void TGeoMaterialEditor::SetModel(TObject* obj)
00214 {
00215    // Connect to the selected material.
00216    if (obj == 0 || !(obj->InheritsFrom(TGeoMaterial::Class()))) {
00217       SetActive(kFALSE);
00218       return;                 
00219    } 
00220    fMaterial = (TGeoMaterial*)obj;
00221    fAi = fMaterial->GetA();
00222    fZi = (Int_t)fMaterial->GetZ();
00223    fStatei = (Int_t)fMaterial->GetState();
00224    fDensityi = fMaterial->GetDensity();
00225    fTempi = fMaterial->GetTemperature();
00226    fPresi = fMaterial->GetPressure()/6.2415e+8;
00227    fNamei = fMaterial->GetName();
00228    fMaterialName->SetText(fMaterial->GetName());
00229    fMatA->SetNumber(fAi);
00230    fMatZ->SetNumber(fZi);
00231    fMatState->Select(fStatei);
00232    fMatDensity->SetNumber(fDensityi);
00233    fMatTemperature->SetNumber(fTempi);
00234    fMatPressure->SetNumber(fPresi);
00235    fMatRadLen->SetNumber(fMaterial->GetRadLen());
00236    fMatAbsLen->SetNumber(fMaterial->GetIntLen());
00237    fApply->SetEnabled(kFALSE);
00238    fUndo->SetEnabled(kFALSE);
00239    
00240    if (fInit) ConnectSignals2Slots();
00241    SetActive();
00242 }
00243 
00244 //______________________________________________________________________________
00245 void TGeoMaterialEditor::DoName()
00246 {
00247 // Perform name change.
00248    DoModified();
00249 }
00250 
00251 //______________________________________________________________________________
00252 void TGeoMaterialEditor::DoA()
00253 {
00254 // Slot for atomic mass.
00255    if (fMaterial->IsMixture()) {
00256       fMatA->SetNumber(fMaterial->GetA());
00257       return;
00258    }   
00259    DoModified();
00260 }
00261 
00262 //______________________________________________________________________________
00263 void TGeoMaterialEditor::DoZ()
00264 {
00265 // Slot for charge.
00266    if (fMaterial->IsMixture()) {
00267       fMatZ->SetNumber(fMaterial->GetZ());
00268       return;
00269    }   
00270    Int_t z = (Int_t)fMatZ->GetNumber();
00271    TGeoElementTable *table = gGeoManager->GetElementTable();
00272    if (z >= table->GetNelements()) {
00273       z = table->GetNelements()-1;
00274       fMatZ->SetNumber(z);
00275    }   
00276    TGeoElement *elem = table->GetElement(z);
00277    if (!elem) return;
00278    Double_t a = elem->A();
00279    fMatA->SetNumber(a);
00280    DoModified();
00281 }
00282 
00283 //______________________________________________________________________________
00284 void TGeoMaterialEditor::DoState(Int_t /*state*/)
00285 {
00286 // Slot for material state.
00287    DoModified();
00288 }
00289 
00290 //______________________________________________________________________________
00291 void TGeoMaterialEditor::DoTemperature()
00292 {
00293 // Slot for material temperature.
00294    DoModified();
00295 }
00296 
00297 //______________________________________________________________________________
00298 void TGeoMaterialEditor::DoPressure()
00299 {
00300 // Slot for material pressure.
00301    DoModified();
00302 }
00303 
00304 //______________________________________________________________________________
00305 void TGeoMaterialEditor::DoDensity()
00306 {
00307 // Slot for density.
00308 //   fMatDensity->SetNumber(fDensityi);
00309    DoModified();
00310 }
00311 
00312 //______________________________________________________________________________
00313 void TGeoMaterialEditor::DoRadAbs()
00314 {
00315 // Slot for radiation/absorbtion length. 
00316    fMatRadLen->SetNumber(fMaterial->GetRadLen());
00317    fMatAbsLen->SetNumber(fMaterial->GetIntLen());
00318    DoModified();
00319 }
00320 
00321 //______________________________________________________________________________
00322 void TGeoMaterialEditor::DoApply()
00323 {
00324 // Slot for applying modifications.
00325    const char *name = fMaterialName->GetText();
00326    fMaterial->SetName(name);
00327    
00328    fMaterial->SetA(fMatA->GetNumber());
00329    fMaterial->SetZ(fMatZ->GetNumber());
00330    fMaterial->SetDensity(fMatDensity->GetNumber());
00331    fMaterial->SetTemperature(fMatTemperature->GetNumber());
00332    fMaterial->SetPressure(6.2415e+8*fMatPressure->GetNumber());
00333    fMaterial->SetState((TGeoMaterial::EGeoMaterialState)fMatState->GetSelected());
00334    fMaterial->SetRadLen(fMatRadLen->GetNumber(), fMatAbsLen->GetNumber());
00335    fMatRadLen->SetNumber(fMaterial->GetRadLen());
00336    fMatAbsLen->SetNumber(fMaterial->GetIntLen());
00337    fUndo->SetEnabled();
00338    fApply->SetEnabled(kFALSE);
00339 }
00340 
00341 //______________________________________________________________________________
00342 void TGeoMaterialEditor::DoUndo()
00343 {
00344 // Slot for cancelling current modifications.
00345    fMaterialName->SetText(fNamei.Data());
00346    fMaterial->SetName(fNamei.Data());
00347    fMatA->SetNumber(fAi);
00348    fMaterial->SetA(fAi);
00349    fMatZ->SetNumber(fZi);
00350    fMaterial->SetZ(fZi);
00351    fMatState->Select(fStatei);
00352    fMaterial->SetState((TGeoMaterial::EGeoMaterialState)fStatei);
00353    fMatDensity->SetNumber(fDensityi);
00354    fMaterial->SetDensity(fDensityi);
00355    fMatTemperature->SetNumber(fTempi);
00356    fMaterial->SetTemperature(fTempi);
00357    fMatPressure->SetNumber(fPresi);
00358    fMaterial->SetPressure(fPresi*6.2415e+8);
00359    fMatRadLen->SetNumber(fMaterial->GetRadLen());
00360    fMatAbsLen->SetNumber(fMaterial->GetIntLen());
00361    fApply->SetEnabled(kFALSE);
00362    fUndo->SetEnabled(kFALSE);
00363 }
00364 
00365 //______________________________________________________________________________
00366 void TGeoMaterialEditor::DoModified()
00367 {
00368 // Slot for signaling modifications.
00369    fApply->SetEnabled();
00370 }
00371 
00372 ClassImp(TGeoMixtureEditor)
00373 
00374 //______________________________________________________________________________
00375 TGeoMixtureEditor::TGeoMixtureEditor(const TGWindow *p, Int_t width,
00376                                    Int_t height, UInt_t options, Pixel_t back)
00377    : TGeoMaterialEditor(p, width, height, options | kVerticalFrame, back)
00378 {
00379    // Constructor for mixture editor.
00380    fMixture = 0;
00381    TGCompositeFrame *compxyz=0, *f1=0;
00382    TGTextEntry *nef;
00383    MakeTitle("Mixture settings");
00384    fNelem = new TGLabel(this, "Number of elements: 0");
00385    AddFrame(fNelem, new TGLayoutHints(kLHintsLeft , 6, 2, 2, 2));
00386    compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame | kDoubleBorder);
00387    // Combo box for selecting elements
00388    f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00389                              kLHintsExpandX | kFixedWidth | kOwnBackground);
00390    fMixElem = new TGComboBox(f1, kMIX_ELEM);
00391    TGeoElementTable *table = gGeoManager->GetElementTable();
00392    if (table) {
00393       TGeoElement *element;
00394       for (Int_t i=0; i<table->GetNelements(); i++) {
00395          element = table->GetElement(i);
00396          fMixElem->AddEntry(element->GetTitle(),i);
00397       }
00398    }      
00399    fMixElem->Select(0);
00400    fMixElem->Resize(90, fMaterialName->GetDefaultHeight());
00401    f1->AddFrame(fMixElem, new TGLayoutHints(kLHintsLeft , 2, 2, 1, 1));
00402    TGCompositeFrame *comp1 = new TGCompositeFrame(f1, 118, 30, kVerticalFrame);
00403    fAelem = new TGLabel(comp1, "A = 0");
00404    comp1->AddFrame(fAelem, new TGLayoutHints(kLHintsRight , 2, 2, 2, 0));
00405    fZelem = new TGLabel(comp1, "Z = 0");
00406    comp1->AddFrame(fZelem, new TGLayoutHints(kLHintsRight , 2, 2, 2, 0));
00407    f1->AddFrame(comp1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX| kLHintsExpandY , 2, 2, 0, 0));
00408    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 0, 0));
00409 
00410    // Fraction by weight
00411    f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00412                              kLHintsExpandX | kFixedWidth | kOwnBackground);
00413    fChkFraction = new TGCheckButton(f1, "% weight");
00414    fChkFraction->SetDown(kTRUE);
00415    f1->AddFrame(fChkFraction, new TGLayoutHints(kLHintsLeft , 2, 2, 6, 1));
00416    fNEFraction = new TGNumberEntry(f1, 0., 5, kMIX_FRAC, TGNumberFormat::kNESRealThree);
00417    fNEFraction->SetFormat(TGNumberFormat::kNESRealThree, TGNumberFormat::kNEANonNegative);
00418    fNEFraction->Resize(65, fMaterialName->GetDefaultHeight());
00419    nef = (TGTextEntry*)fNEFraction->GetNumberEntry();
00420    nef->SetToolTipText("Enter fraction by weight of this element");
00421    fNEFraction->SetNumber(0.);
00422    fNEFraction->Associate(this);
00423    f1->AddFrame(fNEFraction, new TGLayoutHints(kLHintsRight, 2, 2, 1, 1));
00424    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
00425    
00426    // Fraction by number of atoms
00427    f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00428                              kLHintsExpandX | kFixedWidth | kOwnBackground);
00429    fChkNatoms = new TGCheckButton(f1, "N. atoms");
00430    fChkNatoms->SetDown(kFALSE);
00431    f1->AddFrame(fChkNatoms, new TGLayoutHints(kLHintsLeft, 2, 2, 6, 1));
00432    fNENatoms = new TGNumberEntry(f1, 0., 5, kMIX_NATOMS);
00433    fNENatoms->SetFormat(TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative);
00434    fNENatoms->Resize(65, fMaterialName->GetDefaultHeight());
00435    nef = (TGTextEntry*)fNENatoms->GetNumberEntry();
00436    nef->SetToolTipText("Enter number of atoms for this element");
00437    fNENatoms->SetNumber(0);
00438    fNENatoms->Associate(this);
00439    f1->AddFrame(fNENatoms, new TGLayoutHints(kLHintsRight, 2, 2, 1, 1));
00440    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 1, 1));
00441 
00442    // Button for adding the element
00443    fBAddElem = new TGTextButton(compxyz, "Add component");
00444    fBAddElem->Associate(this);
00445    compxyz->AddFrame(fBAddElem, new TGLayoutHints(kLHintsRight , 2, 2, 2, 0));
00446 
00447    compxyz->Resize(150,30);
00448    AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 0, 0, 1, 1));
00449    
00450    // List view with all components
00451    fComps = new TGCompositeFrame(this, 150, 100, kVerticalFrame | kSunkenFrame);
00452    AddFrame(fComps, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 2, 1, 2));
00453 
00454    TGeoTabManager::MoveFrame(f23, this);
00455 }   
00456    
00457 //______________________________________________________________________________
00458 void TGeoMixtureEditor::ConnectSignals2Slots()
00459 {
00460    // Connect signals to slots.
00461    fApply->Connect("Clicked()", "TGeoMixtureEditor", this, "DoApply1()");
00462    fUndo->Connect("Clicked()", "TGeoMixtureEditor", this, "DoUndo1()");
00463    fChkFraction->Connect("Clicked()", "TGeoMixtureEditor", this, "DoChkFraction()");
00464    fChkNatoms->Connect("Clicked()", "TGeoMixtureEditor", this, "DoChkNatoms()");
00465    fNEFraction->Connect("ValueSet(Long_t)", "TGeoMixtureEditor", this, "DoFraction()");
00466    fNENatoms->Connect("ValueSet(Long_t)", "TGeoMixtureEditor", this, "DoNatoms()");
00467    fMixElem->Connect("Selected(Int_t)", "TGeoMixtureEditor", this, "DoSelectElement(Int_t)");
00468    fBAddElem->Connect("Clicked()", "TGeoMixtureEditor", this, "DoAddElem()");
00469    fMaterialName->Connect("TextChanged(const char *)", "TGeoMaterialEditor", this, "DoName()");
00470    fMatA->Connect("ValueSet(Long_t)", "TGeoMaterialEditor", this, "DoA()");
00471    fMatZ->Connect("ValueSet(Long_t)", "TGeoMaterialEditor", this, "DoZ()");
00472    fMatState->Connect("Selected(Int_t)", "TGeoMaterialEditor", this, "DoState(Int_t)");
00473    fMatDensity->Connect("ValueSet(Long_t)", "TGeoMaterialEditor", this, "DoDensity()");
00474    fMatTemperature->Connect("ValueSet(Long_t)", "TGeoMaterialEditor", this, "DoTemperature()");
00475    fMatPressure->Connect("ValueSet(Long_t)", "TGeoMaterialEditor", this, "DoPressure()");
00476    fMatRadLen->Connect("ValueSet(Long_t)", "TGeoMaterialEditor", this, "DoRadAbs()");
00477    fMatAbsLen->Connect("ValueSet(Long_t)", "TGeoMaterialEditor", this, "DoRadAbs()");
00478    fInit = kFALSE;
00479 }
00480       
00481 //______________________________________________________________________________
00482 void TGeoMixtureEditor::SetModel(TObject* obj)
00483 {
00484    // Connect to the selected mixture.
00485    if (obj == 0 || !(obj->InheritsFrom(TGeoMixture::Class()))) {
00486       SetActive(kFALSE);
00487       return;                 
00488    } 
00489    TGeoMaterialEditor::SetModel(obj);
00490    fMixture = (TGeoMixture*)fMaterial;
00491    UpdateElements();
00492 }
00493 
00494 //______________________________________________________________________________
00495 void TGeoMixtureEditor::DoChkFraction()
00496 {
00497 // Check button state changed for fraction.
00498    if (fMixture->GetNelements() && fMixture->GetNmixt()) {
00499       fChkFraction->SetDown(kFALSE);
00500       fChkNatoms->SetDown(kTRUE);
00501       return;
00502    }   
00503    Bool_t isDown = fChkFraction->IsDown();
00504    fChkNatoms->SetDown(!isDown);
00505 }   
00506 
00507 //______________________________________________________________________________
00508 void TGeoMixtureEditor::DoChkNatoms()
00509 {
00510 // Check button state changed for natoms.
00511    if (fMixture->GetNelements() && !fMixture->GetNmixt()) {
00512       fChkFraction->SetDown(kTRUE);
00513       fChkNatoms->SetDown(kFALSE);
00514       return;
00515    }   
00516    Bool_t isDown = fChkNatoms->IsDown();
00517    fChkFraction->SetDown(!isDown);
00518 }   
00519 
00520 //______________________________________________________________________________
00521 void TGeoMixtureEditor::DoFraction()
00522 {
00523 // Fraction changed.
00524    if (fMixture->GetNelements() && fMixture->GetNmixt()) return;
00525    fChkFraction->SetDown(kTRUE);
00526    fChkNatoms->SetDown(kFALSE);
00527 }   
00528 
00529 //______________________________________________________________________________
00530 void TGeoMixtureEditor::DoNatoms()
00531 {
00532 // Natoms changed.
00533    if (fMixture->GetNelements() && !fMixture->GetNmixt()) return;
00534    fChkFraction->SetDown(kFALSE);
00535    fChkNatoms->SetDown(kTRUE);
00536 }   
00537 
00538 //______________________________________________________________________________
00539 void TGeoMixtureEditor::DoSelectElement(Int_t ielem)
00540 {
00541 // Slot for selecting an element.
00542    TGeoElement *el = gGeoManager->GetElementTable()->GetElement(ielem);
00543    TString z = TString::Format("Z=%d",el->Z());
00544    TString a = TString::Format("A=%d",(Int_t)el->A());
00545    fAelem->SetText(a.Data());
00546    fZelem->SetText(z.Data());
00547 }   
00548 
00549 //______________________________________________________________________________
00550 void TGeoMixtureEditor::DoAddElem()
00551 {
00552 // Slot for adding an element. No undo.
00553    Bool_t byfraction = fChkFraction->IsDown();   
00554    Int_t natoms = (Int_t)fNENatoms->GetNumber();
00555    if (!byfraction && natoms<=0) return;
00556    Double_t frac = fNEFraction->GetNumber();
00557    if (byfraction && frac<=0) return;
00558    TGeoElement *el = gGeoManager->GetElementTable()->GetElement(fMixElem->GetSelected());
00559    if (!el) return;
00560    if (byfraction) fMixture->AddElement(el, frac);
00561    else            fMixture->AddElement(el, natoms);   
00562    fTabMgr->GetMaterialEditor(fMixture);
00563 }
00564 
00565 //______________________________________________________________________________
00566 void TGeoMixtureEditor::DoApply1()
00567 {
00568 // Slot for applying modifications.
00569    const char *name = fMaterialName->GetText();
00570    fMaterial->SetName(name);
00571    
00572    fMaterial->SetDensity(fMatDensity->GetNumber());
00573    fMaterial->SetTemperature(fMatTemperature->GetNumber());
00574    fMaterial->SetPressure(6.2415e+8*fMatPressure->GetNumber());
00575    fMaterial->SetState((TGeoMaterial::EGeoMaterialState)fMatState->GetSelected());
00576 //   fMaterial->SetRadLen(fMatRadLen->GetNumber(), fMatAbsLen->GetNumber());
00577    fMatRadLen->SetNumber(fMaterial->GetRadLen());
00578    fMatAbsLen->SetNumber(fMaterial->GetIntLen());
00579    fUndo->SetEnabled();
00580    fApply->SetEnabled(kFALSE);
00581 }   
00582 
00583 //______________________________________________________________________________
00584 void TGeoMixtureEditor::DoUndo1()
00585 {
00586 // Slot for undoing all changes.
00587    fMaterialName->SetText(fNamei.Data());
00588    fMaterial->SetName(fNamei.Data());
00589    fMatState->Select(fStatei);
00590    fMaterial->SetState((TGeoMaterial::EGeoMaterialState)fStatei);
00591    fMatDensity->SetNumber(fDensityi);
00592    fMaterial->SetDensity(fDensityi);
00593    fMatTemperature->SetNumber(fTempi);
00594    fMaterial->SetTemperature(fTempi);
00595    fMatPressure->SetNumber(fPresi);
00596    fMaterial->SetPressure(fPresi*6.2415e+8);
00597    fMatRadLen->SetNumber(fMaterial->GetRadLen());
00598    fMatAbsLen->SetNumber(fMaterial->GetIntLen());
00599    fApply->SetEnabled(kFALSE);
00600    fUndo->SetEnabled(kFALSE);
00601 }   
00602 
00603 //______________________________________________________________________________
00604 void TGeoMixtureEditor::UpdateElements()
00605 {
00606 // Update the list of elements in the TGCanvas.
00607    fComps->RemoveAll();
00608    Int_t nelem = fMixture->GetNelements();
00609    for (Int_t i=0; i<nelem; i++) {
00610       TString s;
00611       Bool_t byfrac = (fMixture->GetNmixt())?kFALSE:kTRUE;
00612       if (byfrac) 
00613          s.TString::Format("%d-%s-%d: Wmass = %g %%", (Int_t)fMixture->GetZmixt()[i], fMixture->GetElement(i)->GetName(), 
00614                 (Int_t)fMixture->GetAmixt()[i],fMixture->GetWmixt()[i]);
00615       else
00616          s.TString::Format("%d-%s-%d: Natoms = %d", (Int_t)fMixture->GetZmixt()[i], fMixture->GetElement(i)->GetName(), 
00617                 (Int_t)fMixture->GetAmixt()[i],fMixture->GetNmixt()[i]);
00618                      
00619       TGLabel *label = new TGLabel(fComps, s);
00620       label->SetTextJustify(kTextLeft | kTextCenterY);
00621       fComps->AddFrame(label, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 1, 1, 0, 0));
00622    }   
00623    fComps->MapSubwindows();
00624 }

Generated on Tue Jul 5 14:13:16 2011 for ROOT_528-00b_version by  doxygen 1.5.1