Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

gui.cpp

Go to the documentation of this file.
00001 #include <TH1.h>
00002 #include <TH2.h>
00003 
00004 #include "gui.h"
00005 #include "enum.h"
00006 #include "gear.xpm"
00007 
00008 TGNumEntry::TGNumEntry(const TGWindow* p, Double_t f, Int_t id = -1)
00009     : TGTextEntry(p, "", id)
00010 {
00011     char* str = new char[32];
00012     
00013     snprintf(str, 32, "%f", f);
00014     SetText((const char*)str);
00015 }
00016         
00017 
00018 void TGNumEntry::Insert(const char* c)
00019 {
00020     if ((c[0] >= '0' && c[0] <= '9') || c[0] == ',' || c[0] == '.' || c[0] == '-')
00021         TGTextEntry::Insert(c);
00022 }
00023 
00024 
00025 void TGFuncNameEntry::Insert(const char* c)
00026 {
00027     if (c[0] != ' ' && c[0] != '<' && c[0] != '>' && c[0] != '/' && c[0] != '\\')
00028         TGTextEntry::Insert(c);
00029 }
00030 
00031 void TGToggleButton::SetState(EButtonState state)
00032 {
00033     // Set button state.
00034 
00035     Bool_t was = !IsDown();     // kTRUE if button was off
00036 
00037     if (state != fState) {
00038         switch (state) {
00039             case kButtonEngaged:
00040             case kButtonDown:
00041                 fOptions &= ~kRaisedFrame;
00042                 fOptions |= kSunkenFrame;
00043                 break;
00044             case kButtonDisabled:
00045             case kButtonUp:
00046                 fOptions &= ~kSunkenFrame;
00047                 fOptions |= kRaisedFrame;
00048                 break;
00049         }
00050         fState = state;
00051         fClient->NeedRedraw(this);
00052     }
00053 
00054     Bool_t now = !IsDown();         // kTRUE if button now is off
00055 
00056     // emit signals
00057     if (was && !now) {
00058         Pressed();                  // emit Pressed  = was off , now on
00059         if (fStayDown) Clicked();   // emit Clicked
00060     }
00061     /*
00062     if (!was && now) {
00063         Released();                 // emit Released = was on , now off
00064         Clicked();                  // emit Clicked
00065     }
00066 
00067     if ((was != now) && IsToggleButton()) Toggled(!now); // emit Toggled  = was != now
00068     */
00069 }
00070 
00071 
00072 MainFrame::MainFrame(const TGWindow* pWnd, UInt_t width, UInt_t height)
00073     : TGMainFrame(pWnd, width, height)
00074 {
00075     Int_t wId;
00076     char str[32];
00077     
00078     pTempControl = 0;
00079     pConfig = new Configuration();
00080 
00081     pMainCont = new TGCompositeFrame(this, 500, 400, kVerticalFrame);
00082     
00083     pEFormula = new TEFormula();
00084     pEPlot1 = new TEF1();
00085     pEPlot2 = new TEF2();
00086     pCleanup = new TList();
00087     pParamElems = new TList();
00088     pParamVals = new TList();
00089     
00090     //----- MENU --------------------------
00091     pMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 1);
00092     pMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
00093     
00094     pMenuProg = new TGPopupMenu(gClient->GetRoot());
00095     pMenuProg->AddEntry("&Save Lattice...", M_PROG_SAVE);
00096     pMenuProg->AddEntry("&Choose Lattice...", M_PROG_CHLAT);
00097     pMenuProg->AddSeparator();
00098     pMenuProg->AddEntry("&Quit", M_PROG_QUIT);
00099     pMenuProg->Connect("Activated(Int_t)", "MainFrame", this, "HandleMenu(Int_t)");
00100     
00101     pMenuSim = new TGPopupMenu(gClient->GetRoot());
00102     pMenuSim->AddEntry("&Insert Defect", M_SIM_INS);
00103     pMenuSim->AddEntry("&Remove Defect", M_SIM_REM);
00104     pMenuSim->AddEntry("Remove &All Defects", M_SIM_REM_ALL);
00105     pMenuSim->AddEntry("Compute &Energy", M_SIM_ENERGY);
00106     pMenuSim->AddEntry("&Temperature Range", M_SIM_TMP_RANGE);
00107     pMenuSim->AddSeparator();
00108     pMenuSim->AddEntry("&Start / Stop", M_SIM_STARTSTOP);
00109     pMenuSim->Connect("Activated(Int_t)", "MainFrame", this, "HandleMenu(Int_t)");
00110     
00111     pMenuOpts = new TGPopupMenu(gClient->GetRoot());
00112     pMenuOpts->AddEntry("&Update Canvas", M_OPTS_UPDATECANV);
00113     if (pConfig->UpdateCanvas()) pMenuOpts->CheckEntry(M_OPTS_UPDATECANV);
00114     pMenuOpts->AddEntry("&Autosave Lattice", M_OPTS_AUTOSAVE);
00115     if (pConfig->AutoSave()) pMenuOpts->CheckEntry(M_OPTS_AUTOSAVE);
00116     pMenuOpts->AddSeparator();
00117     pMenuOpts->AddEntry("&Formula...", M_OPTS_FORMULA);
00118     pMenuOpts->AddEntry("&Simulation...", M_OPTS_SIM);
00119     pMenuOpts->Connect("Activated(Int_t)", "MainFrame", this, "HandleMenu(Int_t)");
00120     
00121     pMenuView = new TGPopupMenu(gClient->GetRoot());
00122     pMenuView->AddEntry("&Temp Control", M_VIEW_TEMP);
00123     pMenuView->AddEntry("&Control Panel", M_VIEW_CONTROL);
00124     pMenuView->CheckEntry(M_VIEW_CONTROL);
00125     pMenuView->AddEntry("&Info Panel", M_VIEW_INFO);
00126     pMenuView->CheckEntry(M_VIEW_INFO);
00127     pMenuView->Connect("Activated(Int_t)", "MainFrame", this, "HandleMenu(Int_t)");
00128         
00129     pMenuPlot = new TGPopupMenu(gClient->GetRoot());
00130     pMenuPlot->AddEntry("Plot Function", M_PLOT_FUNC);
00131     pMenuPlot->Connect("Activated(Int_t)", "MainFrame", this, "HandleMenu(Int_t)");
00132     
00133     pMenuBar = new TGMenuBar(pMainCont, 1, 1, kHorizontalFrame);
00134     pMenuBar->AddPopup("&Program", pMenuProg, pMenuBarItemLayout);
00135     pMenuBar->AddPopup("&Simulation", pMenuSim, pMenuBarItemLayout);
00136     pMenuBar->AddPopup("&Options", pMenuOpts, pMenuBarItemLayout);
00137     pMenuBar->AddPopup("&View", pMenuView, pMenuBarItemLayout);
00138     pMenuBar->AddPopup("&Plot", pMenuPlot, pMenuBarItemLayout);
00139     
00140     pMainCont->AddFrame(pMenuBar, pMenuBarLayout);  
00141     //------ END - MENU ---------------------
00142     
00143     pSplitFrame = new TGCompositeFrame(pMainCont, 10, 10, kHorizontalFrame);
00144     pSplitter = new TGVSplitter(pSplitFrame);
00145     //------ CONTROL-BAR -------------------
00146     pControlFrame = new TGCompositeFrame(pSplitFrame, 180, 10, kFixedWidth | kVerticalFrame);
00147     pFuncL = new TGLabel(pControlFrame, "Int. Energy Function");
00148     pFuncL->SetTextJustify(kTextLeft);
00149     pFuncCombo = new TGComboBox(pControlFrame, MF_CHOOSE_FUNC);
00150     pFuncCombo->Resize(50, 20);
00151     pFuncCombo->Connect("Selected(Int_t, Int_t)", "MainFrame", this, "DoButtons()");
00152 
00153     FillEnFuncCombo(pFuncCombo);
00154     
00155     pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2);
00156     pCleanup->Add(pL);
00157     pControlFrame->AddFrame(pFuncL, pL);
00158     pControlFrame->AddFrame(pFuncCombo, pL);
00159     
00160     pParamGrFr = new TGGroupFrame(pControlFrame, "Param-Values", kVerticalFrame);
00161     pParamSV = new ScrollView(pParamGrFr, 150, 10, kFitWidth | kFitHeight);
00162     pParamCont = new TGCompositeFrame(pParamSV, 10, 10, kVerticalFrame);
00163     FillParamCont(pParamCont);  // called also after ConfigDialog::~ConfigDialog()  
00164     pParamSV->SetContainer(pParamCont);
00165     pParamSV->SetScrolling(TGCanvas::kCanvasScrollVertical);
00166     pParamSetBt = new TGTextButton(pParamGrFr, "Set", MF_SET_PARAM);
00167     pParamSetBt->Connect("Clicked()", "MainFrame", this, "DoButtons()");
00168     pParamGrFr->AddFrame(pParamSV, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
00169     pCleanup->Add(pL);
00170     pParamGrFr->AddFrame(pParamSetBt, pL = new TGLayoutHints(kLHintsBottom | kLHintsRight | kLHintsExpandX, 2, 2, 6, 0));
00171     pCleanup->Add(pL);
00172     pControlFrame->AddFrame(pParamGrFr, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
00173     pCleanup->Add(pL);
00174     
00175     pSimGrFr = new TGGroupFrame(pControlFrame, "Simulation", kVerticalFrame);
00176     pSimToolFr = new TGCompositeFrame(pSimGrFr, 200, 300, kHorizontalFrame);
00177     pSimBtFr = new TGCompositeFrame(pSimToolFr, 200, 300, kVerticalFrame);
00178     pSimInsBt = new TGTextButton(pSimBtFr, "Insert Defect", M_SIM_INS);
00179     pSimInsBt->Connect("Clicked()", "MainFrame", this, "DoButtons()");
00180     pSimRemBt = new TGTextButton(pSimBtFr, "Remove Defect", M_SIM_REM);
00181     pSimRemBt->Connect("Clicked()", "MainFrame", this, "DoButtons()");
00182     pSimRemAllBt = new TGTextButton(pSimBtFr, "Remove All", M_SIM_REM_ALL);
00183     pSimRemAllBt->Connect("Clicked()", "MainFrame", this, "DoButtons()");
00184     pSimEnBt = new TGTextButton(pSimBtFr, "Compute Energy", M_SIM_ENERGY);
00185     pSimEnBt->Connect("Clicked()", "MainFrame", this, "DoButtons()");
00186     pSimTempRangeBt = new TGTextButton(pSimBtFr, "Temp. Range", M_SIM_TMP_RANGE);
00187     pSimTempRangeBt->Connect("Clicked()", "MainFrame", this, "DoButtons()");
00188     pSimUpdBt = new TGTextButton(pSimBtFr, "Update Canvas", M_SIM_UPDCANV);
00189     pSimUpdBt->Connect("Clicked()", "MainFrame", this, "DoButtons()");
00190     pSimOptsBt = new TGTextButton(pSimBtFr, "Options", MF_SIM_OPTS);
00191     pSimOptsBt->Connect("Clicked()", "MainFrame", this, "DoButtons()");
00192     pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 2, 2);
00193     pCleanup->Add(pL);
00194     pSimBtFr->AddFrame(pSimInsBt, pL);
00195     pSimBtFr->AddFrame(pSimRemBt, pL);
00196     pSimBtFr->AddFrame(pSimRemAllBt, pL);
00197     pSimBtFr->AddFrame(pSimEnBt, pL);
00198     pSimBtFr->AddFrame(pSimTempRangeBt, pL);
00199     pSimBtFr->AddFrame(pSimUpdBt, pL);
00200     pSimBtFr->AddFrame(pSimOptsBt, pL);
00201     
00202     pSimTmpFr = new TGCompositeFrame(pSimToolFr, 40, 200, kVerticalFrame | kFixedWidth);
00203     pSimTmpSlider = new TGDoubleVSlider(pSimTmpFr, 100, kDoubleScaleBoth, MF_SIM_TMP_SLIDER, kHorizontalFrame, GetDefaultFrameBackground(), kTRUE);
00204     pSimTmpSlider->Connect("PositionChanged()", "MainFrame", this, "DoButtons()");
00205     pSimTmpSlider->SetRange(pConfig->GetTempMin(), pConfig->GetTempMax());
00206     pSimTmpSlider->SetPosition(pConfig->GetTemp(), pConfig->GetTemp());
00207     pSimTmpEntry = new TGNumEntry(pSimTmpFr, pSimTmpEBuf = new TGTextBuffer(10), MF_SIM_TMP_ENTRY);
00208     pSimTmpEntry->Connect("TextChanged(char*)", "MainFrame", this, "DoTempText(char*)");
00209     snprintf(str, 32, "%f", pConfig->GetTemp());
00210     pSimTmpEBuf->AddText(0, str);
00211     pSimTmpFr->AddFrame(pSimTmpEntry, pL = new TGLayoutHints(kLHintsLeft | kLHintsBottom | kLHintsExpandX, 2, 2, 3, 0));
00212     pCleanup->Add(pL);
00213     pSimTmpFr->AddFrame(pSimTmpSlider, pL = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
00214     pCleanup->Add(pL);
00215     
00216     pSimToolFr->AddFrame(pSimBtFr, pL);
00217     pSimToolFr->AddFrame(pSimTmpFr, pL = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandY, 0, 0, 0, 0));
00218     pCleanup->Add(pL);
00219     
00220     pSimSep = new TGHorizontal3DLine(pSimGrFr, 200, 10);
00221     pSimLaunchBtFr = new TGCompositeFrame(pSimGrFr, 200, 200, kHorizontalFrame);
00222     pSimStartBt = new TGToggleButton(pSimLaunchBtFr, "Start", MF_SIM_START);
00223     pSimStartBt->AllowStayDown(kTRUE);
00224     pSimStartBt->Connect("Clicked()", "MainFrame", this, "DoButtons()");
00225     pSimStopBt = new TGToggleButton(pSimLaunchBtFr, "Stop", MF_SIM_STOP);
00226     pSimStopBt->AllowStayDown(kTRUE);
00227     pSimStopBt->SetState((EButtonState)kButtonDown);
00228     pSimStopBt->Connect("Clicked()", "MainFrame", this, "DoButtons()");
00229     pSimLaunchBtFr->AddFrame(pSimStartBt, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 2, 0, 0));
00230     pCleanup->Add(pL);
00231     pSimLaunchBtFr->AddFrame(pSimStopBt, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 0, 0, 0));
00232     pCleanup->Add(pL);
00233     
00234     pSimGrFr->AddFrame(pSimToolFr, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 6, 2));
00235     pCleanup->Add(pL);
00236     pSimGrFr->AddFrame(pSimSep, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 6, 0));
00237     pCleanup->Add(pL);
00238     pSimGrFr->AddFrame(pSimLaunchBtFr, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 0));
00239     pCleanup->Add(pL);
00240     
00241     pControlFrame->AddFrame(pSimGrFr, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
00242     pCleanup->Add(pL);
00243         
00244     pSplitter->SetFrame(pControlFrame, kTRUE);
00245     //------ END - CONTROL-BAR -----------------
00246     
00247     //------ CANVAS --------------------------
00248     pRECanvas = new TRootEmbeddedCanvas(0, pSplitFrame, 400, 350, kSunkenFrame);
00249     wId = pRECanvas->GetCanvasWindowId();
00250     pLayer = new Layer(this, pConfig, "Layer", 400, 350, wId);
00251     pRECanvas->AdoptCanvas(pLayer);
00252     pLayer->SetFormula(pEFormula);
00253     //------ END - CANVAS ---------------------
00254     pSplitFrame->AddFrame(pControlFrame, pL = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandY, 0, 0, 0, 0));
00255     pCleanup->Add(pL);
00256     pSplitFrame->AddFrame(pSplitter, pL = new TGLayoutHints(kLHintsExpandY, 0, 0, 0, 0));
00257     pCleanup->Add(pL);
00258     pSplitFrame->AddFrame(pRECanvas, pL = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
00259     pCleanup->Add(pL);
00260     
00261     //------ INFO-FRAME ----------------------
00262     pL2 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2);
00263     pL = new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2);
00264     pCleanup->Add(pL2);
00265     pCleanup->Add(pL);
00266     
00267     pInfoFr = new TGCompositeFrame(pMainCont, 700, 100, kHorizontalFrame);
00268     pFr = new TGCompositeFrame(pInfoFr, 100, 100, kVerticalFrame);
00269     pCleanup->Add(pFr);
00270     pLabel = new TGLabel(pFr, "Number of atoms:");
00271     pLabel->SetTextJustify(kTextRight);
00272     pCleanup->Add(pLabel);
00273     pFr->AddFrame(pLabel, pL2);
00274     pLabel = new TGLabel(pFr, "Number of defects:");
00275     pLabel->SetTextJustify(kTextRight);
00276     pCleanup->Add(pLabel);
00277     pFr->AddFrame(pLabel, pL2);
00278     pInfoFr->AddFrame(pFr, pL);
00279     pFr = new TGCompositeFrame(pInfoFr, 50, 100, kVerticalFrame | kFixedWidth);
00280     pCleanup->Add(pFr);
00281     pNumAtomL = new TGLabel(pFr, "");
00282     pNumAtomL->SetTextJustify(kTextLeft);
00283     pNumDefL = new TGLabel(pFr, "");
00284     pNumDefL->SetTextJustify(kTextLeft);
00285     pFr->AddFrame(pNumAtomL, pL2);
00286     pFr->AddFrame(pNumDefL, pL2);
00287     pInfoFr->AddFrame(pFr, pL);
00288     pFr = new TGCompositeFrame(pInfoFr, 100, 100, kVerticalFrame);
00289     pCleanup->Add(pFr);
00290     pLabel = new TGLabel(pFr, "Energy:");
00291     pLabel->SetTextJustify(kTextRight);
00292     pCleanup->Add(pLabel);
00293     pFr->AddFrame(pLabel, pL2);
00294     pLabel = new TGLabel(pFr, "Moves:");
00295     pLabel->SetTextJustify(kTextRight);
00296     pCleanup->Add(pLabel);
00297     pFr->AddFrame(pLabel, pL2);
00298     pInfoFr->AddFrame(pFr, pL);
00299     pFr = new TGCompositeFrame(pInfoFr, 100, 100, kVerticalFrame | kFixedWidth);
00300     pCleanup->Add(pFr);
00301     pEnergyL = new TGLabel(pFr, "");
00302     pEnergyL->SetTextJustify(kTextLeft);
00303     pMovesL = new TGLabel(pFr, "");
00304     pMovesL->SetTextJustify(kTextLeft);
00305     pFr->AddFrame(pEnergyL, pL2);
00306     pFr->AddFrame(pMovesL, pL2);
00307     pInfoFr->AddFrame(pFr, pL);
00308     pFr = new TGCompositeFrame(pInfoFr, 100, 100, kVerticalFrame);
00309     pCleanup->Add(pFr);
00310     pLabel = new TGLabel(pFr, "Saved Images:");
00311     pLabel->SetTextJustify(kTextRight);
00312     pCleanup->Add(pLabel);
00313     pFr->AddFrame(pLabel, pL2);
00314     pLabel = new TGLabel(pFr, "Sim. Status:");
00315     pLabel->SetTextJustify(kTextRight);
00316     pCleanup->Add(pLabel);
00317     pFr->AddFrame(pLabel, pL2);
00318     pInfoFr->AddFrame(pFr, pL);
00319     pFr = new TGCompositeFrame(pInfoFr, 350, 100, kVerticalFrame | kFixedWidth);
00320     pCleanup->Add(pFr);
00321     pImgL = new TGLabel(pFr, "");
00322     pImgL->SetTextJustify(kTextLeft);
00323     pStatusL = new TGLabel(pFr, "");
00324     pStatusL->SetTextJustify(kTextLeft);
00325     pFr->AddFrame(pImgL, pL2);
00326     pFr->AddFrame(pStatusL, pL2);
00327     pInfoFr->AddFrame(pFr, pL);
00328     //------ END - INFO-FRAME ------------------
00329     
00330     pMainCont->AddFrame(pSplitFrame, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
00331     pCleanup->Add(pL);
00332     pMainCont->AddFrame(pInfoFr, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
00333     pCleanup->Add(pL);
00334     
00335     AddFrame(pMainCont, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
00336     
00337     Connect("CloseWindow()", "MainFrame", this, "CloseWindow()");
00338 
00339     SetWindowName("XEIS Elastic Interaction Simulation");
00340     MapSubwindows();
00341     Resize(1000, 700);
00342     Layout();
00343     MapWindow();
00344 }
00345 
00346 MainFrame::~MainFrame()
00347 {
00348     delete pConfig;
00349     delete pLayer;
00350     delete pEFormula;
00351     if (pEPlot1) delete pEPlot1;
00352     if (pEPlot2) delete pEPlot2;
00353     
00354     pCleanup->Delete();
00355     delete pCleanup;
00356     pParamVals->Clear();
00357     delete pParamVals;
00358     pParamElems->Delete();
00359     delete pParamElems;
00360     
00361     delete pMenuBarItemLayout; delete pMenuBarLayout;
00362     delete pMenuPlot; delete pMenuView; delete pMenuOpts; delete pMenuProg;
00363     delete pMenuBar;
00364     delete pParamSetBt;
00365     delete pSimStartBt; delete pSimStopBt; delete pSimLaunchBtFr;
00366     delete pSimSep; delete pSimTempRangeBt; delete pSimEnBt;
00367     delete pSimOptsBt; delete pSimRemBt; delete pSimInsBt;
00368     delete pSimRemAllBt; delete pSimUpdBt;
00369     delete pSimTmpEBuf; delete pSimTmpEntry; delete pSimTmpSlider;
00370     delete pSimTmpFr;
00371     delete pSimBtFr; delete pSimToolFr;
00372     delete pSimGrFr;
00373     delete pParamCont; delete pParamSV; delete pParamGrFr;
00374     delete pFuncCombo; delete pFuncL;
00375     delete pControlFrame; delete pSplitter; delete pRECanvas;
00376     delete pNumAtomL; delete pNumDefL; delete pEnergyL;
00377     delete pMovesL; delete pImgL; delete pStatusL;
00378     delete pInfoFr;
00379     delete pMainCont;
00380 }
00381 
00382 void MainFrame::CloseWindow()
00383 {
00384     pConfig->SaveTempToFile();
00385     gApplication->Terminate(0);
00386 }
00387 
00388 void MainFrame::HandleMenu(Int_t mid)
00389 {
00390     Int_t num;
00391     TGFileInfo *pFileInfo;
00392     TGFileDialog *pFileDialog;
00393     
00394     const char* pFileTypes[14] = {"Postscript", "*.ps", "Encapsulated PS", "*.eps",
00395                                 "GIF", "*.gif", "C++ macro", "*.C", 
00396                                 "C++ macro", "*.cxx", "ROOT file", "*.root", 0, 0};
00397     
00398     switch (mid) {
00399         case M_PROG_SAVE:
00400             pFileInfo = new TGFileInfo();
00401             pFileInfo->fFileTypes = pFileTypes;
00402             pFileDialog = new TGFileDialog(gClient->GetRoot(), this, (EFileDialogMode)1, pFileInfo);
00403             if (pFileInfo->fFilename) {
00404                 gSystem->cd(pFileInfo->fIniDir);
00405                 pLayer->cd();
00406                 gPad->SaveAs(pFileInfo->fFilename);
00407             }
00408             delete pFileInfo;
00409             break;
00410         case M_PROG_CHLAT:
00411             new LatticeDlg(pLayer, gClient->GetRoot(), this, 200, 230);
00412             SetInfoAtoms(pLayer->GetLattice()->GetNUniqueAtoms());
00413             SetInfoDefects(pLayer->GetLattice()->GetNUniqueDefects());
00414             break;
00415         case M_PROG_QUIT:
00416             SendCloseMessage();
00417             break;
00418         case M_SIM_INS:
00419             if (pLayer->GetLattice()) {
00420                 pLayer->GetLattice()->SetInfo(kFALSE);
00421                 num = pConfig->GetInsNum();
00422                 for (Int_t i = 0; i < num; i++)
00423                     pLayer->GetLattice()->RndInsertDefect();
00424                 pLayer->GetLattice()->SetInfo(kTRUE);
00425                 pLayer->Modified();
00426                 pLayer->Update();
00427                 SetInfoDefects(pLayer->GetLattice()->GetNUniqueDefects());
00428             }
00429             break;
00430         case M_SIM_REM:
00431             if (pLayer->GetLattice()) {
00432                 pLayer->GetLattice()->SetInfo(kFALSE);
00433                 num = pConfig->GetRemNum();
00434                 for (Int_t i = 0; i < num; i++)
00435                     pLayer->GetLattice()->RndRemoveDefect();
00436                 pLayer->GetLattice()->SetInfo(kTRUE);
00437                 pLayer->Modified();
00438                 pLayer->Update();
00439                 SetInfoDefects(pLayer->GetLattice()->GetNUniqueDefects());
00440             }
00441             break;
00442         case M_SIM_REM_ALL:
00443             if (pLayer->GetLattice()) {
00444                 pLayer->GetLattice()->SetInfo(kFALSE);
00445                 pLayer->GetLattice()->RemoveAllDefects();
00446                 pLayer->GetLattice()->SetInfo(kTRUE);
00447                 SetInfoDefects(0);
00448             }
00449             break;
00450         case M_SIM_ENERGY:
00451             if (pLayer->GetLattice())
00452                 SetInfoEnergy(pLayer->CompEnergy());
00453             break;
00454         case M_SIM_TMP_RANGE:
00455             new SliderRangeDlg(pSimTmpSlider, pConfig, gClient->GetRoot(), this, 170, 84);
00456             break;
00457         case M_SIM_UPDCANV:
00458             pLayer->Modified();
00459             pLayer->Update();
00460             break;
00461         case M_SIM_STARTSTOP:
00462             if (pLayer->RunSimulation()) {
00463                 pSimStopBt->SetState((EButtonState)kButtonDown);
00464             }
00465             else {
00466                 pSimStartBt->SetState((EButtonState)kButtonDown);
00467             }
00468             break;
00469         case M_OPTS_UPDATECANV:
00470             if (pMenuOpts->IsEntryChecked(mid)) {
00471                 pMenuOpts->UnCheckEntry(mid);
00472                 pConfig->UpdateCanvas(0);
00473             }
00474             else {
00475                 pMenuOpts->CheckEntry(mid);
00476                 pConfig->UpdateCanvas(1);
00477             }
00478         break;
00479         case M_OPTS_AUTOSAVE:
00480             if (pMenuOpts->IsEntryChecked(mid)) {
00481                 pMenuOpts->UnCheckEntry(mid);
00482                 pConfig->AutoSave(0);
00483             }
00484             else {
00485                 pMenuOpts->CheckEntry(mid);
00486                 pConfig->AutoSave(1);
00487             }
00488         break;
00489         case M_OPTS_FORMULA:
00490             ClearEnFuncCombo(pFuncCombo);
00491             new ConfigDialog(pConfig, gClient->GetRoot(), this, 600, 350);
00492             FillEnFuncCombo(pFuncCombo);
00493             FillParamCont(pParamCont);
00494         break;
00495         case M_OPTS_SIM:
00496             new SimulationDialog(pConfig, pLayer->GetLattice(), gClient->GetRoot(), this, 300, 350);
00497             if (pConfig->UpdateCanvas()) pMenuOpts->CheckEntry(M_OPTS_UPDATECANV);
00498             else pMenuOpts->UnCheckEntry(M_OPTS_UPDATECANV);
00499             if (pConfig->AutoSave()) pMenuOpts->CheckEntry(M_OPTS_AUTOSAVE);
00500             else pMenuOpts->UnCheckEntry(M_OPTS_AUTOSAVE);
00501         break;
00502         case M_VIEW_TEMP:
00503             if (pMenuView->IsEntryChecked(M_VIEW_TEMP)) {
00504                 pMenuView->UnCheckEntry(M_VIEW_TEMP);
00505                 if (pTempControl) delete pTempControl;
00506             }
00507             else {
00508                 pMenuView->CheckEntry(M_VIEW_TEMP);
00509                 pTempControl = new TempControl(pConfig, this, gClient->GetRoot(), this, 400, 55);
00510             }
00511         break;
00512         case M_VIEW_CONTROL:
00513             if (pMenuView->IsEntryChecked(M_VIEW_CONTROL)) {
00514                 pMenuView->UnCheckEntry(M_VIEW_CONTROL);
00515                 pSplitFrame->HideFrame(pControlFrame);
00516             }
00517             else {
00518                 pMenuView->CheckEntry(M_VIEW_CONTROL);
00519                 pSplitFrame->ShowFrame(pControlFrame);
00520             }
00521         break;
00522         case M_VIEW_INFO:
00523             if (pMenuView->IsEntryChecked(M_VIEW_INFO)) {
00524                 pMenuView->UnCheckEntry(M_VIEW_INFO);
00525                 pMainCont->HideFrame(pInfoFr);
00526             }
00527             else {
00528                 pMenuView->CheckEntry(M_VIEW_INFO);
00529                 pMainCont->ShowFrame(pInfoFr);
00530             }
00531         break;
00532         case M_PLOT_FUNC:
00533             if (pLayer->GetLattice()) {
00534                 TCanvas *c = new TCanvas();
00535                 c->cd();
00536                 if (pEFormula->GetNdim() == 2) {
00537                     pEPlot2->SetRange(pLayer->GetLattice()->GetCellSize(), 0.0, pConfig->GetInteractionLimit(), 6.3);
00538                     pEPlot2->SetNpx();
00539                     pEPlot2->SetNpy();
00540                     pEPlot2->SetContour();
00541                     pEPlot2->Draw("SURF4");
00542                     pEPlot2->GetHistogram()->GetXaxis()->SetTitle("distance");
00543                     pEPlot2->GetHistogram()->GetYaxis()->SetTitle("angle");
00544                 }
00545                 else if (pEFormula->GetNdim() == 1) {
00546                     pEPlot1->SetRange(pLayer->GetLattice()->GetCellSize(), 0.0, pConfig->GetInteractionLimit(), 6.3);
00547                     pEPlot1->SetNpx();
00548                     pEPlot1->Draw();
00549                     pEPlot1->GetHistogram()->GetXaxis()->SetTitle("distance");
00550                 }
00551             }
00552         break;
00553     }
00554 }
00555 
00556 void MainFrame::DoButtons(Int_t wid, Int_t id)
00557 {
00558     Function** functions;
00559     Param** params;
00560     UInt_t count, i;
00561     char str[32];
00562     
00563     TGFrame *fr = (TGFrame*)gTQSender;
00564     if (fr->IsA()->InheritsFrom(TGDoubleSlider::Class())) {
00565         TGDoubleSlider *sl = (TGDoubleSlider*)fr;
00566         wid = sl->WidgetId();
00567     }
00568     else if (wid == -1) {
00569         TGButton* btn = (TGButton*)gTQSender;
00570         wid = btn->WidgetId();
00571     }
00572     
00573     switch (wid) {
00574         case MF_CHOOSE_FUNC:
00575             count = pConfig->GetFunction(functions);
00576             for (i = 0; i < count; i++)
00577                 if (functions[i]->id == id) {
00578                     pConfig->GetParam(params);
00579                     pEFormula->SetVariables(functions[i]->curX, functions[i]->curY, functions[i]->curZ);
00580                     pEFormula->Compile(functions[i]->parsedExpr);
00581                     pEFormula->SetParNames(params);
00582                     
00583                     if (pEFormula->GetNdim() == 1) {
00584                         pEPlot1->SetVariables(functions[i]->curX, functions[i]->curY, functions[i]->curZ);
00585                         pEPlot1->Compile(functions[i]->parsedExpr);
00586                         pEPlot1->SetParNames(params);
00587                     }
00588                     else if (pEFormula->GetNdim() == 2) {
00589                         pEPlot2->SetVariables(functions[i]->curX, functions[i]->curY, functions[i]->curZ);
00590                         pEPlot2->Compile(functions[i]->parsedExpr);
00591                         pEPlot2->SetParNames(params);
00592                     }
00593                     DoButtons(MF_SET_PARAM);
00594                     break;
00595                 }
00596         break;
00597         case MF_SET_PARAM:
00598             count = pConfig->GetParam(params);
00599             for (i = 0; (i < (UInt_t)pParamVals->GetSize()) || (i < count); i++) {
00600                 params[i]->value = ((TGNumEntry*)pParamVals->At(i))->GetDoubleNum();
00601                 pEFormula->SetParameter(params[i]->name, params[i]->value);
00602                 if (pEFormula->GetNdim() == 1)
00603                     pEPlot1->SetParameter(params[i]->name, params[i]->value);
00604                 else if (pEFormula->GetNdim() == 2)
00605                     pEPlot2->SetParameter(params[i]->name, params[i]->value);
00606             }
00607         break;
00608         case M_SIM_INS:
00609         case M_SIM_REM:
00610         case M_SIM_REM_ALL:
00611         case M_SIM_ENERGY:
00612         case M_SIM_TMP_RANGE:
00613         case M_SIM_UPDCANV:
00614             HandleMenu(wid);
00615         break;
00616         case MF_SIM_TMP_SLIDER:
00617             snprintf(str, 32, "%f", pSimTmpSlider->GetMinPosition());
00618             pSimTmpEBuf->Clear();
00619             pSimTmpEBuf->AddText(0, str);
00620             gClient->NeedRedraw(pSimTmpEntry);
00621             pConfig->SetTemp(pSimTmpSlider->GetMinPosition());
00622         break;
00623         case MF_SIM_OPTS:
00624             HandleMenu(M_OPTS_SIM);
00625         break;
00626         case MF_SIM_START:
00627             if (pFuncCombo->GetSelected() == -1) {
00628                 new TGMsgBox(gClient->GetRoot(), this, "Hint", "Please choose a function", kMBIconAsterisk, kMBOk);
00629                 pSimStartBt->SetState((EButtonState)kButtonUp);
00630             }
00631             else if (pLayer->GetLattice()) {
00632                 simStartTime = time(NULL);
00633                 pSimStopBt->SetState((EButtonState)kButtonUp);
00634                 pLayer->MonteCarloStart(this);
00635             }
00636             else
00637                 pSimStartBt->SetState((EButtonState)kButtonUp);
00638         break;
00639         case MF_SIM_STOP:
00640             pSimStartBt->SetState((EButtonState)kButtonUp);
00641             pLayer->MonteCarloStop();
00642         break;
00643     }
00644 }
00645 
00646 void MainFrame::DoTempText(const char* text)
00647 {
00648     pSimTmpSlider->SetPosition(atof(pSimTmpEBuf->GetString()), atof(pSimTmpEBuf->GetString()));
00649     pSimTmpSlider->PositionChanged();
00650 }
00651 
00652 void MainFrame::SetInfoAtoms(Int_t num)
00653 {
00654     TThread::Lock();
00655     char str[32];
00656     
00657     TThread::Lock();
00658     snprintf(str, 32, "%d", num);
00659     pNumAtomL->SetText(str);
00660     TThread::UnLock();
00661 }
00662 
00663 void MainFrame::SetInfoDefects(Int_t num)
00664 {
00665     TThread::Lock();
00666     char str[32];
00667     
00668     TThread::Lock();
00669     snprintf(str, 32, "%d", num);
00670     pNumDefL->SetText(str);
00671     TThread::UnLock();
00672 }
00673 
00674 void MainFrame::SetInfoEnergy(Double_t e)
00675 {
00676     TThread::Lock();
00677     char str[32];
00678     
00679     snprintf(str, 32, "%f", e);
00680     pEnergyL->SetText(str);
00681     TThread::UnLock();
00682 }
00683 
00684 void MainFrame::SetInfoMoves(Int_t m)
00685 {
00686     TThread::Lock();
00687     char str[32];
00688     
00689     snprintf(str, 32, "%d", m);
00690     pMovesL->SetText(str);
00691     TThread::UnLock();
00692 }
00693 
00694 void MainFrame::SetInfoImages(Int_t i)
00695 {
00696     TThread::Lock();
00697     char str[32];
00698     
00699     snprintf(str, 32, "%d", i);
00700     pImgL->SetText(str);
00701     TThread::UnLock();
00702 }
00703 
00704 void MainFrame::SetInfoStatus()
00705 {
00706         TThread::Lock();
00707     char diffstr[64], tmp[128];
00708     char str[128];
00709     char *start;
00710     tm *timediff = 0;
00711     time_t secdiff;
00712     
00713     tmp[0] = '\0';
00714     if (pLayer->RunSimulation()) {
00715         secdiff = time(NULL) - simStartTime;
00716         //cout << secdiff << endl;
00717         timediff = gmtime(&secdiff);
00718         if (timediff->tm_yday != 0) {
00719             snprintf(diffstr, 64, "%dd ", timediff->tm_yday);
00720             strncpy(tmp, diffstr, 64);
00721         }
00722         if (timediff->tm_hour != 0) {
00723             snprintf(diffstr, 64, "%s%dh ", tmp, timediff->tm_hour);
00724             strncpy(tmp, diffstr, 64);
00725         }
00726         if (timediff->tm_min != 0) {
00727             snprintf(diffstr, 64, "%s%dm ", tmp, timediff->tm_min);
00728             strncpy(tmp, diffstr, 64);
00729         }
00730         snprintf(diffstr, 64, "%s%ds", tmp, timediff->tm_sec);
00731         start = ctime(&simStartTime);
00732         snprintf(str, 128, "running since ");
00733         strncpy(&(str[14]), start, strlen(start)-1);
00734         strncpy(tmp, str, 128);
00735         snprintf(str, 128, "%s (%s)", tmp, diffstr); 
00736     }
00737     else
00738         snprintf(str, 128, "not running");
00739     
00740     pStatusL->SetText(str);
00741     TThread::UnLock();
00742 }
00743 
00744 void MainFrame::FillParamCont(TGCompositeFrame *p)
00745 {
00746     TList *pElemList, *pElemList2;
00747     TGFrameElement *el, *el2;
00748     TGCompositeFrame *pCompFr;
00749     TGLabel *pLabel;
00750     TGNumEntry *pNumE;
00751     TGLayoutHints *pL1, *pL2, *pL3;
00752     TIter *next, *next2;
00753     Param **params;
00754     UInt_t count, i;
00755     char *label;
00756     char text[30];
00757     
00758     pElemList = p->GetList();
00759 
00760     if (!pElemList) return;
00761 
00762     next = new TIter(pElemList);
00763     while ((el = (TGFrameElement*)(*next)())) {
00764         pElemList2 = ((TGCompositeFrame*)el->fFrame)->GetList();
00765         if (pElemList2) {
00766             next2 = new TIter(pElemList2);
00767             while ((el2 = (TGFrameElement*)(*next2)())) {
00768                 ((TGCompositeFrame*)el->fFrame)->RemoveFrame(el2->fFrame);
00769                 el2->fFrame->DestroyWindow();
00770             }
00771             delete next2;
00772         }
00773         p->RemoveFrame(el->fFrame);
00774         el->fFrame->DestroyWindow();
00775     }
00776     delete next;
00777     
00778     pParamVals->Clear();
00779     pParamElems->Delete();
00780     
00781     count = pConfig->GetParam(params);
00782     pL1 = new TGLayoutHints(kLHintsLeft | kLHintsBottom | kLHintsExpandX, 2, 2, 2, 2);
00783     pL2 = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 2, 2, 2, 2);
00784     pL3 = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX, 0, 0, 0, 0);
00785     pCleanup->Add(pL1);
00786     pCleanup->Add(pL2);
00787     pCleanup->Add(pL3);
00788     for (i = 0; i < count; i++) {
00789         pCompFr = new TGCompositeFrame(p, 100, 20, kHorizontalFrame);
00790         pParamElems->Add(pCompFr);
00791         label = new char[strlen(params[i]->name)+1];
00792         strncpy(label, params[i]->name, strlen(params[i]->name) + 1);
00793         pLabel = new TGLabel(pCompFr, label);
00794         pLabel->SetTextJustify(kTextRight);
00795         pParamElems->Add(pLabel);
00796         snprintf(text, 30, "%f", params[i]->value);
00797         pNumE = new TGNumEntry(pCompFr, text);
00798         pNumE->SetWidth(60);
00799         pParamVals->Add(pNumE);
00800         pParamElems->Add(pNumE);
00801         
00802         pCompFr->AddFrame(pLabel, pL1);
00803         pCompFr->AddFrame(pNumE, pL2);
00804         pCompFr->Layout();
00805         p->AddFrame(pCompFr, pL3);
00806     }
00807     
00808     p->MapSubwindows();
00809     p->Layout();
00810     p->MapWindow();
00811 }
00812 
00813 void MainFrame::ClearEnFuncCombo(TGComboBox *combo)
00814 {
00815     UInt_t funcCount, i;
00816     Function **functions;
00817     
00818     funcCount = pConfig->GetFunction(functions);
00819     for (i = 0; i < funcCount; i++)
00820         if (!functions[i]->bDeleted)
00821             combo->RemoveEntry(functions[i]->id);
00822     
00823     combo->Select(-1);
00824 }
00825 
00826 void MainFrame::FillEnFuncCombo(TGComboBox *combo)
00827 {
00828     UInt_t funcCount, i;
00829     Function **functions;
00830     char *formula;
00831     
00832     funcCount = pConfig->GetFunction(functions);
00833     for (i = 0; i < funcCount; i++)
00834         if (!functions[i]->bDeleted) {
00835             if (strlen(functions[i]->parsedExpr) == 0) {
00836                 pEFormula->SetVariables(functions[i]->curX, functions[i]->curY, functions[i]->curZ);
00837                 formula = ConfigDialog::ParseExpression(pConfig, functions[i]->curExpr);
00838                 if (pEFormula->Compile(formula)) {
00839                     cout << formula << endl;
00840                     cout << "Compile error (" << functions[i]->curName << ")" << endl;
00841                     delete formula;
00842                     continue;
00843                 }
00844                 else functions[i]->parsedExpr = formula;
00845             }
00846             combo->AddEntry(functions[i]->curName, functions[i]->id);
00847         }
00848 }
00849 
00850 
00851 ParamFrame::ParamFrame(TGCompositeFrame* fr, const char* id, const char* name, Double_t value, const char* descr)
00852     : TGCompositeFrame(fr, 320, 80, kHorizontalFrame)
00853 {
00854     char strVal[30];
00855     char *strId;
00856     
00857     pFr = fr;
00858 
00859     snprintf(strVal, 30, "%f", value);
00860     strId = new char[strlen(id)+1];
00861     strcpy(strId, id);
00862 
00863     pL1 = new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 2, 2, 2);
00864     pL2 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 2, 2, 2);
00865     pL3 = new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandX, 2, 0, 2, 2);
00866     pChk = new TGCheckButton(this, id, -1, TGCheckButton::GetDefaultGC()(), TGCheckButton::GetDefaultFontStruct(), kFixedWidth);
00867     pChk->SetUserData((void*)strId);
00868     pChk->Resize(60, pChk->GetDefaultHeight());
00869     pName = new TGTextEntry(this, name);
00870     pName->SetWidth(80);
00871     pValue = new TGNumEntry(this, strVal);
00872     pValue->SetWidth(70);
00873     pDescr = new TGTextEntry(this, descr);
00874     AddFrame(pChk, pL2);
00875     AddFrame(pDescr, pL3);
00876     AddFrame(pValue, pL1);
00877     AddFrame(pName, pL1);
00878 }
00879 
00880 ParamFrame::~ParamFrame()
00881 {
00882     RemoveFrame(pChk);
00883     pChk->DestroyWindow();
00884     RemoveFrame(pName);
00885     pName->DestroyWindow();
00886     RemoveFrame(pValue);
00887     pValue->DestroyWindow();
00888     RemoveFrame(pDescr);
00889     pDescr->DestroyWindow();
00890     
00891     pFr->RemoveFrame(this);
00892     DestroyWindow();
00893     
00894     delete (char*)pChk->GetUserData();
00895     delete pL1; delete pL2; delete pL3;
00896     delete pChk;
00897     delete pName;
00898     delete pValue;
00899     delete pDescr;
00900 }
00901 
00902 void ParamFrame::SetId(Int_t id)
00903 {
00904     char *strId = new char[20];
00905     
00906     snprintf(strId, 20, "[%d]", id);
00907     RemoveFrame(pChk);
00908     pChk->DestroyWindow();
00909     delete (char*)pChk->GetUserData();
00910     delete pChk;
00911     
00912     pChk = new TGCheckButton(this, strId);
00913     pChk->SetUserData((void*)strId);
00914     AddFrame(pChk, pL2);
00915     
00916     MapSubwindows();
00917     Layout();
00918 }
00919 
00920 AddFuncDlg::AddFuncDlg(ConfigDialog* c, const TGWindow* p, const TGWindow *main, UInt_t w, UInt_t h, UInt_t options)
00921 {
00922     Function** functions;
00923     UInt_t i, count;
00924 
00925     confDlg = c;
00926     pCleanup = new TList();
00927     
00928     pMain = new TGTransientFrame(p, main, w, h, options);
00929     pMain->Connect("CloseWindow()", "AddFuncDlg", this, "CloseWindow()");
00930     
00931     pDlgFrame = new TGCompositeFrame(pMain, w, h, kVerticalFrame | kFixedHeight);
00932     pNameL = new TGLabel(pDlgFrame, "Name for new function");
00933     pNameL->SetTextJustify(kTextLeft);
00934     pNameT = new TGFuncNameEntry(pDlgFrame, "");
00935     pGrpFrame = new TGGroupFrame(pDlgFrame, "New function contains");
00936     pEmptyRad = new TGRadioButton(pGrpFrame, "Empty fields", D_ADDFUNC_EMPTY);
00937     pCloneRad = new TGRadioButton(pGrpFrame, "Clone existing function", D_ADDFUNC_CLONE);
00938     pFuncList = new TGComboBox(pGrpFrame, D_ADDFUNC_COMBO);
00939     pFuncList->Connect("Selected(Int_t, Int_t)", "AddFuncDlg", this, "DoButtons()");
00940         
00941     pFuncList->Resize(50, 20);
00942     count = confDlg->pConfig->GetFunction(functions);
00943     for (i = 0; i < count; i++)
00944         if (!functions[i]->bDeleted)
00945             pFuncList->AddEntry(functions[i]->curName, functions[i]->id);
00946     
00947     pEmptyRad->SetDown(kTRUE);
00948     pEmptyRad->Connect("Pressed()", "AddFuncDlg", this, "DoButtons()");
00949     pCloneRad->Connect("Pressed()", "AddFuncDlg", this, "DoButtons()");
00950     
00951     pDlgFrame->AddFrame(pNameL, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
00952     pDlgFrame->AddFrame(pNameT, pL);
00953     pGrpFrame->AddFrame(pEmptyRad, pL);
00954     pGrpFrame->AddFrame(pCloneRad, pL);
00955     pCleanup->Add(pL);
00956     pGrpFrame->AddFrame(pFuncList, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 24, 2, 2, 2));
00957     pCleanup->Add(pL);
00958     
00959     pBtFrame = new TGCompositeFrame(pDlgFrame, 160, 60, kFixedWidth | kHorizontalFrame);
00960     pOkButton = new TGTextButton(pBtFrame, "Ok", D_ADDFUNC_OK);
00961     pCancelButton = new TGTextButton(pBtFrame, "Cancel", D_ADDFUNC_CANCEL);
00962     pBtFrame->AddFrame(pOkButton, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
00963     pBtFrame->AddFrame(pCancelButton, pL);
00964     pCleanup->Add(pL);
00965     
00966     pOkButton->Connect("Clicked()", "AddFuncDlg", this, "DoButtons()");
00967     pCancelButton->Connect("Clicked()", "AddFuncDlg", this, "DoButtons()");
00968     
00969     pDlgFrame->AddFrame(pGrpFrame, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
00970     pCleanup->Add(pL);
00971     pDlgFrame->AddFrame(pBtFrame, pL = new TGLayoutHints(kLHintsRight | kLHintsBottom, 2, 0, 2, 4));
00972     pCleanup->Add(pL);
00973     
00974     pMain->AddFrame(pDlgFrame, pL = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX, 2, 2, 2, 2));
00975     pMain->MapSubwindows();
00976     pMain->SetWindowName("Add Function");
00977     pMain->Layout();
00978     pMain->Resize(w, pMain->GetDefaultHeight());
00979     pMain->MapWindow();
00980     
00981     gClient->WaitFor(pMain);
00982 }
00983 
00984 AddFuncDlg::~AddFuncDlg()
00985 {
00986     pCleanup->Delete();
00987     delete pCleanup;
00988     delete pOkButton; delete pCancelButton;
00989     delete pBtFrame;
00990     delete pNameL; delete pNameT;
00991     delete pEmptyRad; delete pCloneRad; delete pFuncList;
00992     delete pGrpFrame; delete pDlgFrame; delete pMain;
00993 }
00994 
00995 void AddFuncDlg::DoButtons(Int_t wid, Int_t id)
00996 {
00997     Function** functions;
00998     Int_t cloneId, funcId;
00999 
01000     if (wid == -1) {
01001         TGButton *btn = (TGButton*)gTQSender;
01002         wid = btn->WidgetId();
01003     }
01004 
01005     switch (wid) {
01006         case D_ADDFUNC_EMPTY:
01007             pCloneRad->SetState(kButtonUp);
01008         break;
01009         case D_ADDFUNC_CLONE:
01010             pEmptyRad->SetState(kButtonUp);
01011         break;
01012         case D_ADDFUNC_COMBO:
01013             pCloneRad->SetDown(kTRUE);
01014             pCloneRad->Pressed();
01015         break;
01016         case D_ADDFUNC_OK:
01017             if (strlen(pNameT->GetText()) == 0) {
01018                 new TGMsgBox(gClient->GetRoot(), pMain, "Error", "Please enter a name for the new function", kMBIconExclamation, kMBOk);
01019                 break;
01020             }
01021             else {
01022                 funcId = confDlg->pConfig->GetFunction(functions);
01023                 if (pEmptyRad->GetState() == kButtonDown)
01024                     confDlg->pConfig->AddFunction(funcId, pNameT->GetText(), "", "");
01025                 else {
01026                     cloneId = pFuncList->GetSelected();
01027                     if (cloneId < 0)
01028                         functions = confDlg->pConfig->AddFunction(funcId, pNameT->GetText(), "", "");
01029                     else
01030                         functions = confDlg->pConfig->AddFunction(funcId, pNameT->GetText(), functions[cloneId]->curExpr, functions[cloneId]->curLatex, functions[cloneId]->curX, functions[cloneId]->curY, functions[cloneId]->curZ);
01031                 }
01032                 confDlg->DoTabButtons(D_ENERGY_CHOOSE_NAME, -1); // for saving the current values
01033                 confDlg->RemoveFunctions();
01034                 confDlg->LoadFunctions(funcId);
01035                 confDlg->DoTabButtons(D_ENERGY_CHOOSE_NAME, funcId);
01036             }
01037         case D_ADDFUNC_CANCEL:
01038             pMain->SendCloseMessage();
01039         break;
01040     }
01041 }
01042 
01043 void AddFuncDlg::CloseWindow()
01044 {
01045     delete this;
01046 }
01047 
01048 RenFuncDlg::RenFuncDlg(ConfigDialog* c, const TGWindow* p, const TGWindow *main, UInt_t w, UInt_t h, UInt_t options)
01049 {
01050     Function** functions;
01051     UInt_t i, count;
01052     Int_t len;
01053     
01054     confDlg = c;
01055     pCleanup = new TList();
01056     strLabel = "";
01057 
01058     count = confDlg->pConfig->GetFunction(functions);
01059         
01060     pMain = new TGTransientFrame(p, main, w, h, options);
01061     pMain->Connect("CloseWindow()", "RenFuncDlg", this, "CloseWindow()");
01062     
01063     id = confDlg->pEnFunCombo->GetSelected();
01064     for (i = 0; i < count; i++)
01065         if (functions[i]->id == id) {
01066             strLabel = new char[(len = strlen(functions[i]->curName)+16)];
01067             snprintf(strLabel, len, "New name for \"%s\"", functions[i]->curName);
01068             break;
01069         }
01070         
01071     pDlgFrame = new TGCompositeFrame(pMain, w, h, kVerticalFrame | kFixedHeight);
01072     pNameL = new TGLabel(pDlgFrame, strLabel);
01073     pNameL->SetTextJustify(kTextLeft);
01074     pNameT = new TGFuncNameEntry(pDlgFrame, functions[i]->curName);
01075         
01076     pDlgFrame->AddFrame(pNameL, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
01077     pDlgFrame->AddFrame(pNameT, pL);
01078     pCleanup->Add(pL);
01079     
01080     pBtFrame = new TGCompositeFrame(pDlgFrame, 160, 60, kFixedWidth | kHorizontalFrame);
01081     pOkButton = new TGTextButton(pBtFrame, "Ok", D_RENFUNC_OK);
01082     pCancelButton = new TGTextButton(pBtFrame, "Cancel", D_RENFUNC_CANCEL);
01083     pBtFrame->AddFrame(pOkButton, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
01084     pBtFrame->AddFrame(pCancelButton, pL);
01085     pCleanup->Add(pL);
01086     
01087     pOkButton->Connect("Clicked()", "RenFuncDlg", this, "DoButtons()");
01088     pCancelButton->Connect("Clicked()", "RenFuncDlg", this, "DoButtons()");
01089     
01090     pDlgFrame->AddFrame(pBtFrame, pL = new TGLayoutHints(kLHintsRight | kLHintsBottom, 2, 0, 2, 4));
01091     pCleanup->Add(pL);
01092     
01093     pMain->AddFrame(pDlgFrame, pL = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX, 2, 2, 2, 2));
01094     pCleanup->Add(pL);
01095     pMain->MapSubwindows();
01096     pMain->SetWindowName("Rename Function");
01097     pMain->Layout();
01098     pMain->Resize(w, pMain->GetDefaultHeight());
01099     pMain->MapWindow();
01100     
01101     gClient->WaitFor(pMain);
01102 }
01103 
01104 RenFuncDlg::~RenFuncDlg()
01105 {
01106     pCleanup->Delete();
01107     delete pCleanup;
01108     delete pNameT; delete pNameL;
01109     delete pOkButton; delete pCancelButton; delete pBtFrame;
01110     delete pDlgFrame; delete pMain;
01111     delete strLabel;
01112 }
01113 
01114 void RenFuncDlg::DoButtons(Int_t wid)
01115 {
01116     Function** functions;
01117     Int_t len;
01118     UInt_t i, count;
01119 
01120     if (wid == -1) {
01121         TGButton *btn = (TGButton*)gTQSender;
01122         wid = btn->WidgetId();
01123     }
01124 
01125     switch (wid) {
01126         case D_RENFUNC_OK:
01127             if (strlen(pNameT->GetText()) == 0) {
01128                 new TGMsgBox(gClient->GetRoot(), pMain, "Error", "Please enter a name for the function", kMBIconExclamation, kMBOk);
01129                 break;
01130             }
01131             count = confDlg->pConfig->GetFunction(functions);
01132             for (i = 0; i < count; i++)
01133                 if (functions[i]->id == id) {
01134                     delete functions[i]->curName;
01135                     functions[i]->curName = new char[(len = strlen(pNameT->GetText())+1)];
01136                     strncpy(functions[i]->curName, pNameT->GetText(), len);
01137                     break;
01138                 }
01139             confDlg->DoTabButtons(D_ENERGY_CHOOSE_NAME, -1); //saving current values
01140             confDlg->RemoveFunctions();
01141             confDlg->LoadFunctions(id);
01142         case D_RENFUNC_CANCEL:
01143             pMain->SendCloseMessage();
01144         break;
01145     }
01146 }
01147 
01148 void RenFuncDlg::CloseWindow()
01149 {
01150     delete this;
01151 }
01152 
01153 
01154 SliderRangeDlg::SliderRangeDlg(TGDoubleSlider* sl, Configuration* conf, const TGWindow* p, const TGWindow *main, UInt_t w, UInt_t h, UInt_t options)
01155 {
01156     slider = sl;
01157     pConfig = conf;
01158     pCleanup = new TList();
01159     
01160     pMain = new TGTransientFrame(p, main, w, h, options | kFixedWidth | kFixedHeight);
01161     pMain->Connect("CloseWindow()", "SliderRangeDlg", this, "CloseWindow()");
01162     
01163     pDlgFrame = new TGCompositeFrame(pMain, w, h, kVerticalFrame);
01164     
01165     pLabel = new TGLabel(pDlgFrame, "Set new range from");
01166     pCleanup->Add(pLabel);
01167     pDlgFrame->AddFrame(pLabel, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft, 4, 4, 4, 2));
01168     pCleanup->Add(pL);
01169     pRangeFr = new TGCompositeFrame(pDlgFrame, 160, 30, kHorizontalFrame);
01170     pFromEntry = new TGNumEntry(pRangeFr, pConfig->GetTempMin());
01171     pLabel = new TGLabel(pRangeFr, "to");
01172     pLabel->SetTextJustify(kTextCenterY);
01173     pCleanup->Add(pLabel);
01174     pToEntry = new TGNumEntry(pRangeFr, pConfig->GetTempMax());
01175     pRangeFr->AddFrame(pFromEntry, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 2, 0, 0));
01176     pCleanup->Add(pL);
01177     pRangeFr->AddFrame(pLabel, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 3, 3, 0, 0));
01178     pCleanup->Add(pL);
01179     pRangeFr->AddFrame(pToEntry, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 0, 0, 0));
01180     pCleanup->Add(pL);
01181     pDlgFrame->AddFrame(pRangeFr, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 4, 4, 2, 8));
01182     pCleanup->Add(pL);
01183     
01184     pBtFrame = new TGCompositeFrame(pDlgFrame, 160, 60, kHorizontalFrame);
01185     pOkButton = new TGTextButton(pBtFrame, "Ok", D_OK);
01186     pCancelButton = new TGTextButton(pBtFrame, "Cancel", D_CANCEL);
01187     pBtFrame->AddFrame(pOkButton, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
01188     pBtFrame->AddFrame(pCancelButton, pL);
01189     pCleanup->Add(pL);
01190     
01191     pOkButton->Connect("Clicked()", "SliderRangeDlg", this, "DoButtons()");
01192     pCancelButton->Connect("Clicked()", "SliderRangeDlg", this, "DoButtons()");
01193     
01194     pDlgFrame->AddFrame(pBtFrame, pL = new TGLayoutHints(kLHintsLeft | kLHintsBottom | kLHintsExpandX, 2, 2, 2, 4));
01195     pCleanup->Add(pL);
01196     
01197     pMain->AddFrame(pDlgFrame, pL = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX, 0, 0, 0, 0));
01198     pCleanup->Add(pL);
01199     pMain->MapSubwindows();
01200     pMain->SetWindowName("Temperature Range");
01201     pMain->Layout();
01202     pMain->Resize(w, h);
01203     pMain->MapWindow();
01204     
01205     gClient->WaitFor(pMain);
01206 }
01207 
01208 SliderRangeDlg::~SliderRangeDlg()
01209 {
01210     pCleanup->Delete();
01211     delete pCleanup;
01212     delete pFromEntry; delete pToEntry; delete pRangeFr;
01213     delete pOkButton; delete pCancelButton; delete pBtFrame;
01214     delete pDlgFrame; delete pMain;
01215 }
01216 
01217 void SliderRangeDlg::DoButtons(Int_t wid)
01218 {
01219 
01220     if (wid == -1) {
01221         TGButton *btn = (TGButton*)gTQSender;
01222         wid = btn->WidgetId();
01223     }
01224 
01225     switch (wid) {
01226         case D_OK:
01227             if (pFromEntry->GetDoubleNum() < pToEntry->GetDoubleNum()) {
01228                 slider->SetRange(pFromEntry->GetDoubleNum(), pToEntry->GetDoubleNum());
01229                 pConfig->SetTempMin(pFromEntry->GetDoubleNum());
01230                 pConfig->SetTempMax(pToEntry->GetDoubleNum());
01231                 if (slider->GetMaxPosition() > pToEntry->GetDoubleNum())
01232                     slider->SetPosition(pToEntry->GetDoubleNum(), pToEntry->GetDoubleNum());
01233                 else slider->SetPosition(pConfig->GetTemp(), pConfig->GetTemp());
01234                 slider->PositionChanged();
01235             }
01236             else {
01237                 new TGMsgBox(gClient->GetRoot(), pMain, "Error", "Range not coinsistent", kMBIconExclamation, kMBOk);
01238                 break;
01239             }
01240         case D_CANCEL:
01241             pMain->SendCloseMessage();
01242         break;
01243     }
01244 }
01245 
01246 void SliderRangeDlg::CloseWindow()
01247 {
01248     delete this;
01249 }
01250 
01251 ConfigDialog::ConfigDialog(Configuration* c, const TGWindow* p, const TGWindow *main, UInt_t w, UInt_t h, UInt_t options)
01252 {
01253     UInt_t paramCount;
01254     Param **params;
01255     
01256     pCleanup = new TList();
01257     pParamLFr = new TList();
01258     pEFormula = new TEFormula();
01259     
01260     curFuncId = -1;
01261     pLatexExpr = 0;
01262     pConfig = c;
01263     paramCount = pConfig->GetParam(params);
01264     
01265     pMain = new TGTransientFrame(p, main, w, h, options);
01266     pMain->Connect("CloseWindow()", "ConfigDialog", this, "CloseWindow()");
01267     
01268     pFr1 = new TGHorizontalFrame(pMain, 220, 20, kFixedWidth);
01269     pOkButton = new TGTextButton(pFr1, "Ok", D_OK);
01270     pOkButton->Connect("Clicked()", "ConfigDialog", this, "DoOk()");
01271     pCancelButton = new TGTextButton(pFr1, "Cancel", D_CANCEL);
01272     pCancelButton->Connect("Clicked()", "ConfigDialog", this, "DoCancel()");
01273     pSaveButton = new TGTextButton(pFr1, "Save", D_SAVE);
01274     pSaveButton->Connect("Clicked()", "ConfigDialog", this, "DoSave()");
01275     
01276     pL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2);
01277     pL2 = new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 4, 1);
01278     pL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2);
01279     pL4 = new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2);
01280     
01281     pFr1->AddFrame(pOkButton, pL1);
01282     pFr1->AddFrame(pCancelButton, pL1);
01283     pFr1->AddFrame(pSaveButton, pL1);
01284     pFr1->Resize(220, pOkButton->GetDefaultHeight());
01285     pMain->AddFrame(pFr1, pL2);
01286     
01287     pTab = new TGTab(pMain, 350, 300);
01288     pTab->Connect("Selected(Int_t)", "ConfigDialog", this, "DoTab(Int_t)");
01289     
01290     //---- Energy - Tab ---------------------------
01291     pTabFrame = pTab->AddTab("Int. Energy");
01292     
01293     pEnergyFr = new TGCompositeFrame(pTabFrame, 320, 280, kVerticalFrame);
01294     pParVarFr = new TGCompositeFrame(pEnergyFr, 320, 200, kHorizontalFrame);
01295     pParListGrFr = new TGGroupFrame(pParVarFr, "Parameter", kVerticalFrame);
01296     pVarGrFr = new TGGroupFrame(pParVarFr, "Variables", kVerticalFrame | kFixedWidth);
01297     pVarGrFr->Resize(130, 80);
01298     pEnGrFr = new TGGroupFrame(pEnergyFr, "Function", kVerticalFrame | kFixedHeight);
01299     pEnGrFr->Resize(pEnGrFr->GetDefaultWidth(), 280);
01300     
01301     pParLV = new TGListView(pParListGrFr, 200, 100);
01302     pParLVCont = new TGLVContainer(pParLV->GetViewPort(), 200, 100, kHorizontalFrame, TGFrame::GetWhitePixel());
01303     pParLVCont->Associate(pParLV);
01304     pParLVCont->SetListView(pParLV);
01305     pParLV->SetContainer(pParLVCont);
01306     
01307     pParLV->SetHeaders(2);
01308     pParLV->SetHeader("Name", kTextLeft, kTextLeft, 0);
01309     pParLV->SetHeader("Description", kTextLeft, kTextLeft, 1);
01310     pParLV->SetViewMode(kLVDetails);
01311     
01312     // Generating pixmap from compiled data (gear_xpm)
01313     pPic = new LVPicture();
01314         
01315     LoadParameters();
01316     
01317     pParListGrFr->AddFrame(pParLV, pL3);
01318     
01319     pFr = new TGCompositeFrame(pVarGrFr, 200, 80, kHorizontalFrame);
01320     pCleanup->Add(pFr);
01321     pXLabel = new TGLabel(pFr, "x =");
01322     pXEntry = new TGTextEntry(pFr, "");
01323     pFr->AddFrame(pXLabel, pL = new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
01324     pFr->AddFrame(pXEntry, pL1);
01325     pVarGrFr->AddFrame(pFr, pL1);
01326     pFr = new TGCompositeFrame(pVarGrFr, 200, 80, kHorizontalFrame);
01327     pCleanup->Add(pFr);
01328     pYLabel = new TGLabel(pFr, "y =");
01329     pYEntry = new TGTextEntry(pFr, "");
01330     pFr->AddFrame(pYLabel, pL);
01331     pFr->AddFrame(pYEntry, pL1);
01332     pVarGrFr->AddFrame(pFr, pL1);
01333     pFr = new TGCompositeFrame(pVarGrFr, 200, 80, kHorizontalFrame);
01334     pCleanup->Add(pFr);
01335     pZLabel = new TGLabel(pFr, "z =");
01336     pZEntry = new TGTextEntry(pFr, "");
01337     pFr->AddFrame(pZLabel, pL);
01338     pFr->AddFrame(pZEntry, pL1);
01339     pVarGrFr->AddFrame(pFr, pL1);
01340     pCleanup->Add(pL);
01341     
01342     pParVarFr->AddFrame(pParListGrFr, pL3);
01343     pParVarFr->AddFrame(pVarGrFr, pL = new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandY, 2, 2, 2, 2));
01344     pCleanup->Add(pL);
01345     pEnergyFr->AddFrame(pParVarFr, pL3);
01346     
01347     pFr = new TGCompositeFrame(pEnGrFr, 300, 50, kHorizontalFrame);
01348     pCleanup->Add(pFr);
01349     pEnFunCombo = new TGComboBox(pFr, D_ENERGY_CHOOSE_NAME);
01350     pEnFunCombo->Resize(50, 20);
01351     pEnFunCombo->Connect("Selected(Int_t, Int_t)", "ConfigDialog", this, "DoTabButtons()");
01352     pLabel = new TGLabel(pFr, "Choose a function");
01353     pCleanup->Add(pLabel);
01354     pFr->AddFrame(pLabel, pL4);
01355     pFr->AddFrame(pEnFunCombo, pL1);
01356     pEnGrFr->AddFrame(pFr, pL1);
01357     
01358     pEnLine = new TGHorizontal3DLine(pEnGrFr);
01359     pEnGrFr->AddFrame(pEnLine, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 7));
01360     pCleanup->Add(pL);
01361     
01362     pFr = new TGCompositeFrame(pEnGrFr, 300, 50, kHorizontalFrame);
01363     pCleanup->Add(pFr);
01364     pLabel = new TGLabel(pFr, "Expression");
01365     pCleanup->Add(pLabel);
01366     pEnFunExp = new TGTextEntry(pFr, "");
01367     pFr->AddFrame(pLabel, pL4);
01368     pFr->AddFrame(pEnFunExp, pL1);
01369     pEnGrFr->AddFrame(pFr, pL1);
01370     
01371     pFr = new TGCompositeFrame(pEnGrFr, 300, 50, kHorizontalFrame);
01372     pCleanup->Add(pFr);
01373     pLabel = new TGLabel(pFr, "Latex        ");
01374     pCleanup->Add(pLabel);
01375     pEnFunLat = new TGTextEntry(pFr, "");
01376     pFr->AddFrame(pLabel, pL4);
01377     pFr->AddFrame(pEnFunLat, pL1);
01378     pEnGrFr->AddFrame(pFr, pL1);
01379     
01380     pLatexFr = new TGCompositeFrame(pEnGrFr, 300, 100, kHorizontalFrame);
01381     pLatexCanv = new TRootEmbeddedCanvas("latex", pLatexFr, 300, 100, 0);
01382     pLatexCanv->GetCanvas()->SetBorderMode(0);
01383     pLatexCanv->GetCanvas()->SetBit(kNoContextMenu);
01384     pLatexFr->AddFrame(pLatexCanv, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 4, 0, 0));
01385     pCleanup->Add(pL);
01386     pLatexBtFr = new TGCompositeFrame(pLatexFr, 30, 100, kVerticalFrame | kFixedWidth);
01387     pLatPBt = new TGTextButton(pLatexBtFr, "+", D_ENERGY_LATEX_PLUS);
01388     pLatPBt->Connect("Clicked()", "ConfigDialog", this, "DoTabButtons()");
01389     pLatMBt = new TGTextButton(pLatexBtFr, "-", D_ENERGY_LATEX_MINUS);
01390     pLatMBt->Connect("Clicked()", "ConfigDialog", this, "DoTabButtons()");
01391     pLatexBtFr->AddFrame(pLatPBt, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 2));
01392     pCleanup->Add(pL);
01393     pLatexBtFr->AddFrame(pLatMBt, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 0, 2, 0));
01394     pCleanup->Add(pL);
01395     pLatexFr->AddFrame(pLatexBtFr, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
01396     pCleanup->Add(pL);
01397     
01398     pEnGrFr->AddFrame(pLatexFr, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 4, 4, 2, 2));
01399     pCleanup->Add(pL);
01400     
01401     pEnFunBtFr = new TGCompositeFrame(pEnGrFr, 300, 80, kHorizontalFrame | kFixedWidth);
01402     pEnFunBtVer = new TGTextButton(pEnFunBtFr, "Verify", D_ENERGY_VERIFY);
01403     pEnFunBtVer->Connect("Clicked()", "ConfigDialog", this, "DoTabButtons()");
01404     pEnFunBtRen = new TGTextButton(pEnFunBtFr, "Rename", D_ENERGY_RENAME);
01405     pEnFunBtRen->Connect("Clicked()", "ConfigDialog", this, "DoTabButtons()");
01406     pEnFunBtFr->AddFrame(pEnFunBtVer, pL1);
01407     pEnFunBtFr->AddFrame(pEnFunBtRen, pL1);
01408     pEnFunBtFr->Resize(170, pEnFunBtVer->GetDefaultHeight());
01409     pEnGrFr->AddFrame(pEnFunBtFr, pL2);
01410     
01411     pEnergyFr->AddFrame(pEnGrFr, pL1);
01412     
01413     pEnBtFr = new TGCompositeFrame(pEnergyFr, 220, 80, kHorizontalFrame | kFixedWidth);
01414     pEnBtAdd = new TGTextButton(pEnBtFr, "Add", D_ENERGY_ADD);
01415     pEnBtAdd->Connect("Clicked()", "ConfigDialog", this, "DoTabButtons()");
01416     pEnBtDel = new TGTextButton(pEnBtFr, "Delete", D_ENERGY_DEL);
01417     pEnBtDel->Connect("Clicked()", "ConfigDialog", this, "DoTabButtons()");
01418     pEnBtRev = new TGTextButton(pEnBtFr, "Revert", D_ENERGY_REV);
01419     pEnBtRev->Connect("Clicked()", "ConfigDialog", this, "DoTabButtons()");
01420     pEnBtFr->Resize(220, pEnBtAdd->GetDefaultHeight());
01421     pEnBtFr->AddFrame(pEnBtAdd, pL1);
01422     pEnBtFr->AddFrame(pEnBtDel, pL1);
01423     pEnBtFr->AddFrame(pEnBtRev, pL1);
01424     
01425     pEnergyFr->AddFrame(pEnBtFr, pL2);
01426     
01427     pTabFrame->AddFrame(pEnergyFr, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 4, 4, 4, 4));
01428     pCleanup->Add(pL);
01429     
01430     LoadFunctions();
01431     //---------------------------------------------
01432     
01433     //---- Parameter - Tab ------------------------
01434     pTabFrame = pTab->AddTab("Parameter");
01435     pParamFr = new TGCompositeFrame(pTabFrame, 320, 280, kVerticalFrame);
01436     pParamBtFr = new TGCompositeFrame(pParamFr, 220, 80, kHorizontalFrame | kFixedWidth);
01437     pParamBtAdd = new TGTextButton(pParamBtFr, "Add", D_PARAM_ADD);
01438     pParamBtAdd->Connect("Clicked()", "ConfigDialog", this, "DoTabButtons()");
01439     pParamBtDel = new TGTextButton(pParamBtFr, "Delete", D_PARAM_DEL);
01440     pParamBtDel->Connect("Clicked()", "ConfigDialog", this, "DoTabButtons()");
01441     pParamBtRev = new TGTextButton(pParamBtFr, "Revert", D_PARAM_REV);
01442     pParamBtRev->Connect("Clicked()", "ConfigDialog", this, "DoTabButtons()");
01443     pParamBtFr->AddFrame(pParamBtAdd, pL1);
01444     pParamBtFr->AddFrame(pParamBtDel, pL1);
01445     pParamBtFr->AddFrame(pParamBtRev, pL1);
01446     pParamFr->AddFrame(pParamBtFr, pL2);
01447     pParamBtFr->Resize(220, pParamBtAdd->GetDefaultHeight());
01448     
01449     pParGrFr = new TGGroupFrame(pParamFr, "Current Parameter", kVerticalFrame);
01450     pParSV = new ScrollView(pParGrFr, 300, 200, kFitWidth | kFitHeight);
01451     pParLineFr = new TGCompositeFrame(pParSV, 300, 200, kVerticalFrame);
01452     pParSV->SetContainer(pParLineFr);
01453     for (UInt_t i = 0; i < paramCount; i++) {
01454         pPFr = new ParamFrame(pParLineFr, params[i]->id, params[i]->name, params[i]->value, params[i]->descr);
01455         pParamLFr->Add(pPFr);
01456         pParSV->AddFrame(pPFr, pL1);
01457     }
01458     
01459     pParHeadFr = new TGCompositeFrame(pParGrFr, 300, 80, kHorizontalFrame);
01460     pParHeadL1 = new TGLabel(pParHeadFr, "Name");
01461     pParHeadL2 = new TGLabel(pParHeadFr, "Value");
01462     pParHeadL3 = new TGLabel(pParHeadFr, "Description");
01463     
01464     pParHeadFr->AddFrame(pParHeadL1, pL = new TGLayoutHints(kLHintsBottom | kLHintsLeft, 42, 2, 2, 0));
01465     pCleanup->Add(pL);
01466     pParHeadFr->AddFrame(pParHeadL2, pL = new TGLayoutHints(kLHintsBottom | kLHintsLeft, 50, 20, 2, 0));
01467     pCleanup->Add(pL);
01468     pParHeadFr->AddFrame(pParHeadL3, pL = new TGLayoutHints(kLHintsBottom | kLHintsLeft, 20, 2, 2, 0));
01469     pCleanup->Add(pL);
01470     
01471     pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 1, 1, 4, 0);
01472     pCleanup->Add(pL);
01473     pParGrFr->AddFrame(pParHeadFr, pL);
01474     
01475     pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 1, 1, 2, 2);
01476     pCleanup->Add(pL);
01477     pParGrFr->AddFrame(pParSV, pL);
01478     pParamFr->AddFrame(pParGrFr, pL);
01479     pParSV->SetScrolling(TGCanvas::kCanvasScrollVertical);
01480     
01481     pTabFrame->AddFrame(pParamFr, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 4, 4, 4, 4));
01482     pCleanup->Add(pL);
01483     //---------------------------------------------
01484     
01485     pL = new TGLayoutHints(kLHintsBottom | kLHintsExpandX | kLHintsExpandY, 2, 2, 4, 1);
01486     pCleanup->Add(pL);
01487     pMain->AddFrame(pTab, pL);
01488     
01489     pMain->MapSubwindows();
01490     pMain->Resize(400, pMain->GetDefaultHeight());
01491     
01492     pMain->SetWindowName("Formula Configuration");
01493     pMain->MapWindow();
01494     gClient->WaitFor(pMain);
01495 }
01496 
01497 ConfigDialog::~ConfigDialog()
01498 {
01499     pCleanup->Delete();
01500     delete pCleanup;
01501     delete pEFormula;
01502 
01503     //--- Energy-Tab --------------------
01504     delete pPic;
01505     delete pParLVCont; delete pParLV;
01506     
01507     delete pXLabel; delete pYLabel; delete pZLabel;
01508     delete pXEntry; delete pYEntry; delete pZEntry;
01509     
01510     delete pEnFunCombo;
01511     delete pEnLine;
01512     delete pEnFunExp; delete pEnFunLat;
01513     delete pLatexExpr; delete pLatexCanv;
01514     delete pLatPBt; delete pLatMBt;
01515     delete pLatexBtFr; delete pLatexFr;
01516     delete pEnBtAdd; delete pEnBtDel; delete pEnBtRev;
01517     delete pEnFunBtVer; delete pEnFunBtRen;
01518     delete pEnFunBtFr; delete pEnBtFr;
01519     delete pParListGrFr; delete pVarGrFr;
01520     delete pParVarFr; delete pEnGrFr; delete pEnergyFr;
01521     //----------------------------------
01522 
01523     //--- Parameter-Tab ------------------
01524     pParamLFr->Delete();
01525     delete pParamLFr;
01526     delete pParamBtAdd; delete pParamBtDel; delete pParamBtRev;
01527     delete pParamBtFr;
01528     delete pParamFr;
01529     delete pParLineFr;
01530     delete pParHeadL1; delete pParHeadL2; delete pParHeadL3;
01531     delete pParHeadFr;
01532     delete pParSV;
01533     delete pParGrFr;
01534     //--------------------------------
01535 
01536     delete pOkButton; delete pCancelButton;
01537     delete pSaveButton;
01538     delete pFr1;
01539     delete pL1; delete pL2; delete pL3; delete pL4;
01540     delete pTab;
01541     delete pMain;
01542 }
01543 
01544 void ConfigDialog::CloseWindow()
01545 {
01546     delete this;
01547 }
01548 
01549 void ConfigDialog::DoOk()
01550 {
01551     if (DoSave()) return;
01552     
01553     pMain->SendCloseMessage();
01554 }
01555 
01556 void ConfigDialog::DoCancel()
01557 {
01558     pConfig->RevertFunction();
01559     pMain->SendCloseMessage();
01560 }
01561 
01562 Int_t ConfigDialog::DoSave()
01563 {
01564     // --- Parameter-Tab ---------------
01565     const char **id;
01566     const char **name;
01567     const char **descr;
01568     Double_t *value;
01569     Int_t count;
01570     ParamFrame *pObj;
01571     TListIter iter(pParamLFr);
01572     
01573     count = pParamLFr->GetSize();
01574     id = new (const char*)[count];
01575     name = new (const char*)[count];
01576     value = new Double_t[count];
01577     descr = new (const char*)[count];
01578     
01579     count = 0;
01580     while ((pObj = (ParamFrame*)iter())) {
01581         id[count] = (const char*)pObj->pChk->GetUserData();
01582         name[count] = pObj->pName->GetText();
01583         value[count] = pObj->pValue->GetDoubleNum();
01584         descr[count] = pObj->pDescr->GetText();
01585         count++;
01586     }
01587     
01588     pConfig->SetParam(id, name, value, descr, count);
01589     
01590     delete [] id;
01591     delete [] name;
01592     delete [] value;
01593     delete [] descr;
01594     // ---------------------------------------------
01595     
01596     // --- Energy-Tab --------------------
01597     Function **functions;
01598     UInt_t fCount, i;
01599     Int_t err;
01600     
01601     DoTabButtons(D_ENERGY_CHOOSE_NAME, -1);
01602     
01603     err = 1;
01604     fCount = pConfig->GetFunction(functions);
01605     for (i = 0; i < fCount; i++)
01606         if (!functions[i]->bDeleted)
01607             err *= VerifyFunction(functions[i]->id, kFALSE);
01608     
01609     if (err == 0) {
01610         new TGMsgBox(gClient->GetRoot(), pMain, "Error", "Could not save functions, check syntax.", kMBIconExclamation, kMBOk);
01611         return -1;
01612     }   
01613     
01614     pConfig->CleanFunction();
01615     // ---------------------------------------------
01616     
01617     pConfig->SaveFormulaToFile();
01618     return 0;
01619 }
01620 
01621 void ConfigDialog::DoTab(Int_t id)
01622 {
01623     if (id == 0) // Energy-Tab
01624         LoadParameters();
01625 }
01626 
01627 void ConfigDialog::DoTabButtons(Int_t wid, Int_t id)
01628 {
01629     Int_t i, len;
01630     UInt_t count, k;
01631     Bool_t bDel;
01632     Function **functions;
01633     TListIter *pIter;
01634     ParamFrame *pObj;
01635     
01636     if (wid == -1) {
01637         TGButton* btn = (TGButton*)gTQSender;
01638         wid = btn->WidgetId();
01639     }
01640 
01641     switch (wid) {
01642         case D_ENERGY_CHOOSE_NAME:
01643             count = pConfig->GetFunction(functions);
01644             for (k = 0; k < count; k++)
01645                 if (functions[k]->id == curFuncId) {
01646                     delete functions[k]->curExpr;
01647                     functions[k]->curExpr = new char[(len = strlen(pEnFunExp->GetText())+1)];
01648                     strncpy(functions[k]->curExpr, pEnFunExp->GetText(), len);
01649                     delete functions[k]->curLatex;
01650                     functions[k]->curLatex = new char[(len = strlen(pEnFunLat->GetText())+1)];
01651                     strncpy(functions[k]->curLatex, pEnFunLat->GetText(), len);
01652                     delete functions[k]->curX;
01653                     functions[k]->curX = new char[(len = strlen(pXEntry->GetText())+1)];
01654                     strncpy(functions[k]->curX, pXEntry->GetText(), len);
01655                     delete functions[k]->curY;
01656                     functions[k]->curY = new char[(len = strlen(pYEntry->GetText())+1)];
01657                     strncpy(functions[k]->curY, pYEntry->GetText(), len);
01658                     delete functions[k]->curZ;
01659                     functions[k]->curZ = new char[(len = strlen(pZEntry->GetText())+1)];
01660                     strncpy(functions[k]->curZ, pZEntry->GetText(), len);
01661                     break;
01662                 }
01663                 
01664             for (k = 0; k < count; k++)
01665                 if (functions[k]->id == id) {
01666                     pEnFunExp->SetText(functions[k]->curExpr);
01667                     pEnFunLat->SetText(functions[k]->curLatex);
01668                     pXEntry->SetText(functions[k]->curX);
01669                     pYEntry->SetText(functions[k]->curY);
01670                     pZEntry->SetText(functions[k]->curZ);
01671                     pLatexCanv->GetCanvas()->cd();
01672                     gPad->Clear();
01673                     pLatexExpr = new TLatex();
01674                     pLatexExpr->SetTextSize(0.3);
01675                     pLatexExpr->SetTextAlign(21);
01676                     pLatexExpr->DrawLatex(0.5, 0.5, functions[k]->curLatex);
01677                     gPad->Modified();
01678                     gPad->Update();
01679                     curFuncId = id;
01680                     break;
01681                 }
01682         break;
01683         case D_ENERGY_LATEX_PLUS:
01684             if (pLatexExpr) {
01685                 count = pConfig->GetFunction(functions);
01686                 for (k = 0; k < count; k++)
01687                     if (functions[k]->id == curFuncId) {
01688                         pLatexCanv->GetCanvas()->cd();
01689                         gPad->Clear();
01690                         pLatexExpr->SetTextSize(pLatexExpr->GetTextSize()*1.1);
01691                         pLatexExpr->DrawLatex(0.5, 0.5, functions[k]->curLatex);
01692                         gPad->Modified();
01693                         gPad->Update();
01694                     }
01695             }
01696         break;
01697         case D_ENERGY_LATEX_MINUS:
01698             if (pLatexExpr) {
01699                 count = pConfig->GetFunction(functions);
01700                 for (k = 0; k < count; k++)
01701                     if (functions[k]->id == curFuncId) {
01702                         pLatexCanv->GetCanvas()->cd();
01703                         gPad->Clear();
01704                         pLatexExpr->SetTextSize(pLatexExpr->GetTextSize()*0.9);
01705                         pLatexExpr->DrawLatex(0.5, 0.5, functions[k]->curLatex);
01706                         gPad->Modified();
01707                         gPad->Update();
01708                     }
01709             }
01710         break;
01711         case D_ENERGY_ADD:
01712             new AddFuncDlg(this, gClient->GetRoot(), pMain, 350, 170, kVerticalFrame | kFixedHeight);
01713         break;
01714         case D_ENERGY_DEL:
01715             count = pConfig->GetFunction(functions);
01716             i = pEnFunCombo->GetSelected();
01717             for (k = 0; k < count; k++)
01718                 if (functions[k]->id == i) {
01719                     functions[k]->bDeleted = kTRUE;
01720                     pEnFunCombo->RemoveEntry(i);
01721                     break;
01722                 }
01723             
01724             RemoveFunctions();
01725             LoadFunctions();
01726         break;
01727         case D_ENERGY_REV:
01728             RemoveFunctions();
01729             pConfig->RevertFunction();
01730             LoadFunctions();
01731         break;
01732         case D_ENERGY_RENAME:
01733             if (pEnFunCombo->GetSelected() != -1)
01734                 new RenFuncDlg(this, gClient->GetRoot(), pMain, 350, 80);
01735         break;
01736         case D_ENERGY_VERIFY:
01737             DoTabButtons(D_ENERGY_CHOOSE_NAME, -1);
01738             VerifyFunction(pEnFunCombo->GetSelected());
01739         break;
01740         case D_PARAM_DEL:
01741             pIter = new TListIter(pParamLFr);
01742             i = 0;
01743             bDel = kFALSE;
01744             while ((pObj = (ParamFrame*)(*pIter)())) {
01745                 if (pObj->pChk->GetState() == kButtonDown) {
01746                     pParamLFr->Remove(pObj);
01747                     delete pObj;
01748                     bDel = kTRUE;
01749                 }
01750                 else {
01751                     if (bDel)
01752                         pObj->SetId(i);
01753                     i++;
01754                 }   
01755             }
01756             delete pIter;
01757             pMain->Layout();
01758         break;
01759         case D_PARAM_ADD:
01760             pPFr = new ParamFrame(pParLineFr, "", "unnamed", 0, "");
01761             pPFr->SetId((UInt_t)pParamLFr->GetSize());
01762             pPFr->Layout();
01763             pParamLFr->Add(pPFr);
01764             pParSV->AddFrame(pPFr, pL1);
01765             pParSV->SetVsbPosition(pParSV->GetVsbPosition() + pPFr->GetHeight());
01766             pMain->MapSubwindows();
01767             pMain->Layout();
01768         break;
01769         case D_PARAM_REV:
01770             Param **params;
01771             ParamFrame *pPFr;
01772             
01773             pParamLFr->Delete();
01774                 
01775             count = pConfig->GetParam(params);
01776             for (k = 0; k < count; k++) {
01777                 pPFr = new ParamFrame(pParLineFr, params[k]->id, params[k]->name, params[k]->value, params[k]->descr);
01778                 pParamLFr->Add(pPFr);
01779                 pParSV->AddFrame(pPFr, pL1);
01780             }
01781             pMain->MapSubwindows();
01782             pMain->Layout();
01783         break;
01784     }
01785 }
01786 
01787 void ConfigDialog::LoadParameters()
01788 {
01789     UInt_t paramCount, i;
01790     Param **params;
01791     TGString ***pLVEntryStr, *pLVEntryName;
01792     TGLVEntry *pParLVEntry;
01793     
01794     paramCount = pConfig->GetParam(params);
01795 
01796     pParLVCont->RemoveAll();
01797 
01798     pLVEntryStr = new (TGString**)[paramCount];
01799     
01800     for (i = 0; i < paramCount; i++) {
01801         pLVEntryStr[i] = new (TGString*)[2];
01802         pLVEntryStr[i][0] = new TGString(params[i]->descr);
01803         pLVEntryStr[i][1] = 0;
01804         pLVEntryName = new TGString(params[i]->name);
01805         pParLVEntry = new TGLVEntry(pParLVCont, pPic, pPic, pLVEntryName, pLVEntryStr[i], kLVDetails);
01806         pParLVCont->AddItem(pParLVEntry);
01807     }
01808     
01809     pParLV->MapSubwindows();
01810     pParLV->MapWindow();
01811     pParLV->Layout();
01812 }
01813 
01814 void ConfigDialog::LoadFunctions(Int_t id)
01815 {
01816     UInt_t funcCount;
01817     Function **functions;
01818     
01819     funcCount = pConfig->GetFunction(functions);
01820     
01821     for (UInt_t i = 0; i < funcCount; i++)
01822             if (!functions[i]->bDeleted)
01823                 pEnFunCombo->AddEntry(functions[i]->curName, functions[i]->id);
01824         
01825     pLatexCanv->GetCanvas()->cd();
01826     gPad->Clear();
01827             
01828     pEnFunCombo->Select(id);
01829     
01830     pEnFunExp->SetText("");
01831     pEnFunLat->SetText("");
01832     for (UInt_t i = 0; i < funcCount; i++)
01833         if (functions[i]->id == id) {
01834             pEnFunExp->SetText(functions[i]->curExpr);
01835             pEnFunLat->SetText(functions[i]->curLatex);
01836             pXEntry->SetText(functions[i]->curX);
01837             pYEntry->SetText(functions[i]->curY);
01838             pZEntry->SetText(functions[i]->curZ);
01839             pLatexExpr = new TLatex();
01840             pLatexExpr->SetTextSize(0.25);
01841             pLatexExpr->SetTextAlign(21);
01842             pLatexExpr->DrawLatex(0.5, 0.5, functions[i]->curLatex);
01843             break;
01844         }
01845     
01846     gPad->Modified();
01847     gPad->Update();
01848     
01849     curFuncId = id;
01850 }
01851 
01852 void ConfigDialog::RemoveFunctions()
01853 {
01854     UInt_t funcCount;
01855     Function **functions;
01856     
01857     funcCount = pConfig->GetFunction(functions);
01858     for (UInt_t i = 0; i < funcCount; i++)
01859         if (!functions[i]->bDeleted)
01860             pEnFunCombo->RemoveEntry(functions[i]->id);
01861 }
01862 
01863 Int_t ConfigDialog::VerifyFunction(Int_t id, Bool_t vermsg, Bool_t errmsg)
01864 {
01865     Function **functions;
01866     UInt_t count, i;
01867     char *formula;
01868     char msg[256];
01869     
01870     count = pConfig->GetFunction(functions);
01871     for (i = 0; i < count; i++)
01872         if (functions[i]->id == id) {
01873             pEFormula->SetVariables(functions[i]->curX, functions[i]->curY, functions[i]->curZ);
01874             formula = ParseExpression(pConfig, functions[i]->curExpr);
01875             if (pEFormula->Compile(formula)) {
01876                 cout << "compile error" << endl;
01877                 if (errmsg == kTRUE) {
01878                     sprintf(msg, "Could not correctly parse function %s.", functions[i]->curName);
01879                     new TGMsgBox(gClient->GetRoot(), pMain, "Error", msg, kMBIconExclamation, kMBOk);
01880                 }
01881                 delete functions[i]->parsedExpr;
01882                 functions[i]->parsedExpr = "";
01883                 return 0;
01884             }
01885             else {
01886                 cout << "compilation successfull" << endl;
01887                 if (vermsg == kTRUE) {
01888                     sprintf(msg, "Successfully parsed function %s.", functions[i]->curName);
01889                     new TGMsgBox(gClient->GetRoot(), pMain, "Verifying", msg, kMBIconAsterisk, kMBOk);
01890                 }
01891                 delete functions[i]->parsedExpr;
01892                 functions[i]->parsedExpr = formula;
01893                 return 1;
01894             }
01895         }
01896         
01897     return 1;
01898 }
01899 
01900 char* ConfigDialog::ParseExpression(Configuration* pConfig, const char* expr)
01901 {
01902     Param **params;
01903     UInt_t count, i;
01904     size_t l, l1, l2, l3;
01905     char c1, c2;
01906     char *tok, *newExpr, *tmp, *tmp2;
01907     const char *ops = "+-*/%() &|=!<>,^";
01908     
01909     
01910     tmp = 0;
01911     tmp2 = 0;
01912     newExpr = 0;
01913     
01914     count = pConfig->GetParam(params);
01915     
01916     newExpr = new char[(l = strlen(expr)+1)];
01917     strncpy(newExpr, expr, l);
01918     for (i = 0; i < count; i++) {
01919         while ((tok = strstr(newExpr, params[i]->name))) {
01920             if (strlen(newExpr) == strlen(tok)) {
01921                 c1 = '+';
01922                 l1 = 0;
01923             }
01924             else {
01925                 l = strlen(newExpr)-strlen(tok)-1;
01926                 c1 = newExpr[l];
01927                 l1 = l+1;
01928             }
01929             if (strlen(tok) == strlen(params[i]->name)) {
01930                 c2 = '+';
01931                 l2 = 0;
01932             }
01933             else {
01934                 l = strlen(params[i]->name);
01935                 c2 = tok[l];
01936                 l2 = strlen(newExpr)-l1-l;
01937             }
01938         
01939             if (strchr(ops, c1) && strchr(ops, c2)) {
01940                 l3 = strlen(params[i]->id);
01941                 l = strlen(params[i]->name);
01942                 tmp = new char[l1+l3+l2+1];
01943                 strncpy(tmp, newExpr, l1);
01944                 strncpy(&tmp[l1], params[i]->id, l3);
01945                 strncpy(&tmp[l1+l3], &newExpr[l1+l], l2+1);
01946                 delete newExpr;
01947                 newExpr = new char[(l = strlen(tmp)+1)];
01948                 strncpy(newExpr, tmp, l);
01949                 delete tmp;
01950             }
01951             else {
01952                 if (strlen(tok) > 1) {
01953                     tmp2 = strpbrk(tok, ops);
01954                     if (tmp2) {
01955                         l1 = strlen(newExpr)-strlen(tmp2);
01956                         tmp = ParseExpression(pConfig, tmp2);
01957                         if (strcmp(tmp, tmp2) == 0) break;
01958                         l2 = strlen(tmp);
01959                         tmp2 = new char[l1+l2+1];
01960                         strncpy(tmp2, newExpr, l1);
01961                         strncpy(&tmp2[l1], tmp, l2+1);
01962                         delete newExpr;
01963                         newExpr = new char[(l = strlen(tmp2)+1)];
01964                         strncpy(newExpr, tmp2, l);
01965                         delete tmp2;
01966                     }
01967                     else break;
01968                 }
01969                 else break; 
01970             }           
01971             
01972         }
01973     }
01974     
01975     return newExpr;
01976 }
01977 
01978 SimulationDialog::SimulationDialog(Configuration* c, Lattice* l, const TGWindow* p, const TGWindow *main, UInt_t w, UInt_t h, UInt_t options)
01979 {
01980     char str[128];
01981     pCleanup = new TList();
01982 
01983     pConfig = c;
01984     pLattice = l;
01985         
01986     pMain = new TGTransientFrame(p, main, w, h, options);
01987     pMain->Connect("CloseWindow()", "SimulationDialog", this, "CloseWindow()");
01988     
01989     pBtFrame = new TGCompositeFrame(pMain, 220, 20, kHorizontalFrame | kFixedWidth);
01990     pOkButton = new TGTextButton(pBtFrame, "Ok", D_OK);
01991     pOkButton->Connect("Clicked()", "SimulationDialog", this, "DoOk()");
01992     pCancelButton = new TGTextButton(pBtFrame, "Cancel", D_CANCEL);
01993     pCancelButton->Connect("Clicked()", "SimulationDialog", this, "DoCancel()");
01994         
01995     pL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2);
01996     pL2 = new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 4, 1);
01997     pL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2);
01998     pL4 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2);
01999     
02000     pBtFrame->AddFrame(pOkButton, pL1);
02001     pBtFrame->AddFrame(pCancelButton, pL1);
02002     pBtFrame->Resize(160, pOkButton->GetDefaultHeight());
02003     pMain->AddFrame(pBtFrame, pL2);
02004     
02005     pTab = new TGTab(pMain, 350, 300);
02006     
02007     //---- Monte-Carlo - Tab ----------------------
02008     pTabFrame = pTab->AddTab("Monte-Carlo");
02009     pMCFr = new TGCompositeFrame(pTabFrame, 350, 300, kVerticalFrame);
02010     pAlgFr = new TGGroupFrame(pMCFr, "Algorithm");
02011     pFr = new TGCompositeFrame(pAlgFr, 350, 30, kVerticalFrame);
02012     pCleanup->Add(pFr);
02013     
02014     pBoltzmL = new TGLabel(pFr, "Boltzmanns Constant (k):");
02015     pBoltzmE = new TGNumEntry(pFr, pConfig->GetBoltzConst());
02016     pFr->AddFrame(pBoltzmL, pL4);
02017     pFr->AddFrame(pBoltzmE, pL1);
02018     pAlgFr->AddFrame(pFr, pL1);
02019     
02020     pFr = new TGCompositeFrame(pAlgFr, 350, 30, kVerticalFrame);
02021     pCleanup->Add(pFr);
02022     pIntLimL = new TGLabel(pFr, "Interaction Limit:");
02023     if (pLattice)
02024         snprintf(str, 128, "(width = %f, height = %f, cellsize = %f)", pLattice->GetWidth(), pLattice->GetHeight(), pLattice->GetCellSize());
02025     else
02026         snprintf(str, 128, "(no distance info available - lattice not defined)");
02027     pIntLimL2 = new TGLabel(pFr, str);
02028     pIntLimE = new TGNumEntry(pFr, pConfig->GetInteractionLimit());
02029     pFr->AddFrame(pIntLimL, pL4);
02030     pFr->AddFrame(pIntLimL2, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 0, 2));
02031     pCleanup->Add(pL);
02032     pFr->AddFrame(pIntLimE, pL1);
02033     pAlgFr->AddFrame(pFr, pL1);
02034     pMCFr->AddFrame(pAlgFr, pL1);
02035     
02036     pGraphFr = new TGGroupFrame(pMCFr, "Visualization");
02037     pUpdateChBt = new TGCheckButton(pGraphFr, "Update Canvas");
02038     pUpdateChBt->SetDown(pConfig->UpdateCanvas());
02039     pFr = new TGCompositeFrame(pGraphFr, 350, 30, kHorizontalFrame);
02040     pCleanup->Add(pFr);
02041     pUpdateL = new TGLabel(pFr, "every");
02042     pUpdateNum = new TGNumberEntry(pFr, (Double_t)pConfig->GetUpdateInterval(), 3, -1, (TGNumberFormat::EStyle)0, (TGNumberFormat::EAttribute)2, (TGNumberFormat::ELimit)1, 1.0);
02043     pUpdateNum->Resize(pUpdateNum->GetDefaultWidth(), 20);
02044     pUpdateL2 = new TGLabel(pFr, "moves");
02045     pFr->AddFrame(pUpdateL, pL = new TGLayoutHints(kLHintsLeft | kLHintsTop, 20, 2, 2, 2));
02046     pCleanup->Add(pL);
02047     pFr->AddFrame(pUpdateNum, pL4);
02048     pFr->AddFrame(pUpdateL2, pL4);
02049     pGraphFr->AddFrame(pUpdateChBt, pL1);
02050     pGraphFr->AddFrame(pFr, pL1);
02051     
02052     pAutoSaveChBt = new TGCheckButton(pGraphFr, "Autosave Canvas");
02053     pAutoSaveChBt->SetDown(pConfig->AutoSave());
02054     pFr = new TGCompositeFrame(pGraphFr, 350, 30, kHorizontalFrame);
02055     pCleanup->Add(pFr);
02056     pAutoSaveL = new TGLabel(pFr, "every");
02057     pAutoSaveNum = new TGNumberEntry(pFr, (Double_t)pConfig->GetSaveInterval(), 3, -1, (TGNumberFormat::EStyle)0, (TGNumberFormat::EAttribute)2, (TGNumberFormat::ELimit)1, 1.0);
02058     pAutoSaveNum->Resize(pAutoSaveNum->GetDefaultWidth(), 20);
02059     pAutoSaveL2 = new TGLabel(pFr, "moves");
02060     pFr->AddFrame(pAutoSaveL, pL = new TGLayoutHints(kLHintsLeft | kLHintsTop, 20, 2, 2, 2));
02061     pCleanup->Add(pL);
02062     pFr->AddFrame(pAutoSaveNum, pL4);
02063     pFr->AddFrame(pAutoSaveL2, pL4);
02064     pGraphFr->AddFrame(pAutoSaveChBt, pL1);
02065     pGraphFr->AddFrame(pFr, pL1);
02066     pImgFr = new TGCompositeFrame(pGraphFr, 350, 60, kHorizontalFrame);
02067     pFr = new TGCompositeFrame(pImgFr, 200, 30, kVerticalFrame);
02068     pCleanup->Add(pFr);
02069     pImgPathL = new TGLabel(pFr, "Image Path");
02070     pImgPathE = new TGTextEntry(pFr, pConfig->GetImagePath());
02071     pFr->AddFrame(pImgPathL, pL = new TGLayoutHints(kLHintsLeft | kLHintsTop, 20, 2, 2, 2));
02072     pCleanup->Add(pL);
02073     pFr->AddFrame(pImgPathE, pL = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX, 20, 2, 2, 2));
02074     pCleanup->Add(pL);
02075     pImgFr->AddFrame(pFr, pL1);
02076     pFr = new TGCompositeFrame(pImgFr, 200, 30, kVerticalFrame);
02077     pCleanup->Add(pFr);
02078     pImgPrefixL = new TGLabel(pFr, "Prefix");
02079     pImgPrefixE = new TGTextEntry(pFr, pConfig->GetImagePrefix());
02080     pImgPrefixE->Resize(60, pImgPrefixE->GetDefaultHeight());
02081     pFr->AddFrame(pImgPrefixL, pL4);
02082     pFr->AddFrame(pImgPrefixE, pL1),
02083     pImgFr->AddFrame(pFr, pL4);
02084     pFr = new TGCompositeFrame(pImgFr, 200, 30, kVerticalFrame);
02085     pCleanup->Add(pFr);
02086     pImgFormatL = new TGLabel(pFr, "Format");
02087     pImgFormatC = new TGComboBox(pFr, -1);
02088     pImgFormatC->Resize(50, pImgPrefixE->GetDefaultHeight());
02089     pImgFormatC->AddEntry(".ps", 1);
02090     pImgFormatC->AddEntry(".eps", 2);
02091     pImgFormatC->AddEntry(".gif", 3);
02092     pImgFormatC->AddEntry(".C", 4);
02093     pImgFormatC->AddEntry(".cxx", 5);
02094     pImgFormatC->AddEntry(".root", 6);
02095     pImgFormatC->Select(pConfig->GetImageFormat());
02096     pFr->AddFrame(pImgFormatL, pL4);
02097     pFr->AddFrame(pImgFormatC, pL1);
02098     pImgFr->AddFrame(pFr, pL4);
02099     pGraphFr->AddFrame(pImgFr, pL1);
02100     
02101     pMCFr->AddFrame(pGraphFr, pL1);
02102     
02103     pTabFrame->AddFrame(pMCFr, pL3);
02104     //----------------------------------------------------
02105     
02106     //---- Lattice - Tab ---------------------------
02107     pTabFrame = pTab->AddTab("Lattice");
02108     pLatticeFr = new TGCompositeFrame(pTabFrame, 350, 300, kVerticalFrame);
02109     
02110     pAtomFr = new TGGroupFrame(pLatticeFr, "Atom Appearance");
02111     pFr = new TGCompositeFrame(pAtomFr, 350, 30, kHorizontalFrame);
02112     pCleanup->Add(pFr);
02113     pAShapeL = new TGLabel(pFr, "Shape");
02114     pAShapeC = new TGComboBox(pFr, -1);
02115     pAShapeC->Resize(50, 20);
02116     pAShapeC->AddEntry("Dot", 1);
02117     pAShapeC->AddEntry("Plus", 2);
02118     pAShapeC->AddEntry("Star", 3);
02119     pAShapeC->AddEntry("Circle", 4);
02120     pAShapeC->AddEntry("Multiply", 5);
02121     pAShapeC->AddEntry("FullDotSmall", 6);
02122     pAShapeC->AddEntry("FullDotMedium", 7);
02123     pAShapeC->AddEntry("FullDotlarge", 8);
02124     pAShapeC->AddEntry("FullCircle", 20);
02125     pAShapeC->AddEntry("FullSquare", 21);
02126     pAShapeC->AddEntry("FullTriangleUp", 22);
02127     pAShapeC->AddEntry("FullTriangleDown", 23);
02128     pAShapeC->AddEntry("OpenCircle", 24);
02129     pAShapeC->AddEntry("OpenSquare", 25);
02130     pAShapeC->AddEntry("OpenTriangleUp", 26);
02131     pAShapeC->AddEntry("OpenDiamond", 27);
02132     pAShapeC->AddEntry("OpenCross", 28);
02133     pAShapeC->AddEntry("FullStar", 29);
02134     pAShapeC->AddEntry("OpenStar", 30);
02135     pFr->AddFrame(pAShapeL, pL4);
02136     pFr->AddFrame(pAShapeC, pL1);
02137     pAtomFr->AddFrame(pFr, pL1);
02138     pFr = new TGCompositeFrame(pAtomFr, 350, 30, kHorizontalFrame);
02139     pCleanup->Add(pFr);
02140     pASizeL = new TGLabel(pFr, "Size   ");
02141     pASizeE = new TGNumberEntry(pFr, 1.0, 2, -1, (TGNumberFormat::EStyle)2, (TGNumberFormat::EAttribute)2, (TGNumberFormat::ELimit)1, 0.1);
02142     pASizeE->Resize(50, 20);
02143     pFr->AddFrame(pASizeL, pL4);
02144     pFr->AddFrame(pASizeE, pL1);
02145     pAtomFr->AddFrame(pFr, pL1);
02146     pFr = new TGCompositeFrame(pAtomFr, 350, 30, kHorizontalFrame);
02147     pCleanup->Add(pFr);
02148     pAColorL = new TGLabel(pFr, "Color ");
02149     pAColorC = new TGComboBox(pFr, -1);
02150     pAColorC->Resize(50, 20);
02151     pAColorC->AddEntry("White", 0);
02152     pAColorC->AddEntry("Black", 1);
02153     pAColorC->AddEntry("Red", 2);
02154     pAColorC->AddEntry("Green", 3);
02155     pAColorC->AddEntry("Blue", 4);
02156     pAColorC->AddEntry("Yellow", 5);
02157     pAColorC->AddEntry("Magenta", 6);
02158     pAColorC->AddEntry("Cyan", 7);
02159     pFr->AddFrame(pAColorL, pL4);
02160     pFr->AddFrame(pAColorC, pL1);
02161     pAtomFr->AddFrame(pFr, pL1);
02162     
02163     pDefectFr = new TGGroupFrame(pLatticeFr, "Defect Appearance");
02164     pFr = new TGCompositeFrame(pDefectFr, 350, 30, kHorizontalFrame);
02165     pCleanup->Add(pFr);
02166     pDShapeL = new TGLabel(pFr, "Shape");
02167     pDShapeC = new TGComboBox(pFr, -1);
02168     pDShapeC->Resize(50, 20);
02169     pDShapeC->AddEntry("Dot", 1);
02170     pDShapeC->AddEntry("Plus", 2);
02171     pDShapeC->AddEntry("Star", 3);
02172     pDShapeC->AddEntry("Circle", 4);
02173     pDShapeC->AddEntry("Multiply", 5);
02174     pDShapeC->AddEntry("FullDotSmall", 6);
02175     pDShapeC->AddEntry("FullDotMedium", 7);
02176     pDShapeC->AddEntry("FullDotlarge", 8);
02177     pDShapeC->AddEntry("FullCircle", 20);
02178     pDShapeC->AddEntry("FullSquare", 21);
02179     pDShapeC->AddEntry("FullTriangleUp", 22);
02180     pDShapeC->AddEntry("FullTriangleDown", 23);
02181     pDShapeC->AddEntry("OpenCircle", 24);
02182     pDShapeC->AddEntry("OpenSquare", 25);
02183     pDShapeC->AddEntry("OpenTriangleUp", 26);
02184     pDShapeC->AddEntry("OpenDiamond", 27);
02185     pDShapeC->AddEntry("OpenCross", 28);
02186     pDShapeC->AddEntry("FullStar", 29);
02187     pDShapeC->AddEntry("OpenStar", 30);
02188     pFr->AddFrame(pDShapeL, pL4);
02189     pFr->AddFrame(pDShapeC, pL1);
02190     pDefectFr->AddFrame(pFr, pL1);
02191     pFr = new TGCompositeFrame(pDefectFr, 350, 30, kHorizontalFrame);
02192     pCleanup->Add(pFr);
02193     pDSizeL = new TGLabel(pFr, "Size   ");
02194     pDSizeE = new TGNumberEntry(pFr, 1, 2, -1, (TGNumberFormat::EStyle)2, (TGNumberFormat::EAttribute)2, (TGNumberFormat::ELimit)1, 0.1);
02195     pDSizeE->Resize(50, 20);
02196     pFr->AddFrame(pDSizeL, pL4);
02197     pFr->AddFrame(pDSizeE, pL1);
02198     pDefectFr->AddFrame(pFr, pL1);
02199     pFr = new TGCompositeFrame(pDefectFr, 350, 30, kHorizontalFrame);
02200     pCleanup->Add(pFr);
02201     pDColorL = new TGLabel(pFr, "Color ");
02202     pDColorC = new TGComboBox(pFr,-1);
02203     pDColorC->Resize(50, 20);
02204     pDColorC->AddEntry("White", 0);
02205     pDColorC->AddEntry("Black", 1);
02206     pDColorC->AddEntry("Red", 2);
02207     pDColorC->AddEntry("Green", 3);
02208     pDColorC->AddEntry("Blue", 4);
02209     pDColorC->AddEntry("Yellow", 5);
02210     pDColorC->AddEntry("Magenta", 6);
02211     pDColorC->AddEntry("Cyan", 7);
02212     pFr->AddFrame(pDColorL, pL4);
02213     pFr->AddFrame(pDColorC, pL1);
02214     pDefectFr->AddFrame(pFr, pL1);
02215     
02216     pInsRemFr = new TGGroupFrame(pLatticeFr, "Insert / Remove Defects");
02217     pFr = new TGCompositeFrame(pInsRemFr, 350, 30, kHorizontalFrame);
02218     pCleanup->Add(pFr);
02219     pInsL = new TGLabel(pFr, "Insert    ");
02220     pInsE = new TGNumberEntry(pFr, (Double_t)pConfig->GetInsNum(), 3, -1, (TGNumberFormat::EStyle)0, (TGNumberFormat::EAttribute)2, (TGNumberFormat::ELimit)1, 1.0);
02221     pInsE->Resize(50, 20);
02222     pInsL2 = new TGLabel(pFr, " defects at once");
02223     pFr->AddFrame(pInsL, pL4);
02224     pFr->AddFrame(pInsE, pL4);
02225     pFr->AddFrame(pInsL2, pL4);
02226     pInsRemFr->AddFrame(pFr, pL1);
02227     pFr = new TGCompositeFrame(pInsRemFr, 350, 30, kHorizontalFrame);
02228     pCleanup->Add(pFr);
02229     pRemL = new TGLabel(pFr, "Remove ");
02230     pRemE = new TGNumberEntry(pFr, (Double_t)pConfig->GetRemNum(), 3, -1, (TGNumberFormat::EStyle)0, (TGNumberFormat::EAttribute)2, (TGNumberFormat::ELimit)1, 1.0);
02231     pRemE->Resize(50, 20);
02232     pRemL2 = new TGLabel(pFr, " defects at once");
02233     pFr->AddFrame(pRemL, pL4);
02234     pFr->AddFrame(pRemE, pL4);
02235     pFr->AddFrame(pRemL2, pL4);
02236     pInsRemFr->AddFrame(pFr, pL1);
02237     
02238     
02239     pFr = new TGCompositeFrame(pLatticeFr, 70, 20, kHorizontalFrame | kFixedWidth);
02240     pCleanup->Add(pFr);
02241     pTryButton = new TGTextButton(pFr, "Try", D_SIM_TRY);
02242     pTryButton->Connect("Clicked()", "SimulationDialog", this, "DoTabButtons()");
02243     pFr->AddFrame(pTryButton, pL1);
02244     pFr->Resize(70, pTryButton->GetDefaultHeight());
02245     
02246     pLatticeFr->AddFrame(pAtomFr, pL1);
02247     pLatticeFr->AddFrame(pDefectFr, pL1);
02248     pLatticeFr->AddFrame(pInsRemFr, pL1);
02249     pLatticeFr->AddFrame(pFr, pL2);
02250     
02251     pAShapeC->Select(pConfig->GetAtomShape());
02252     pASizeE->SetNumber(pConfig->GetAtomSize());
02253     pAColorC->Select(pConfig->GetAtomColor());
02254     pDShapeC->Select(pConfig->GetDefectShape());
02255     pDSizeE->SetNumber(pConfig->GetDefectSize());
02256     pDColorC->Select(pConfig->GetDefectColor());
02257     
02258     pTabFrame->AddFrame(pLatticeFr, pL3);
02259     //-------------------------------------------
02260     
02261     pL = new TGLayoutHints(kLHintsBottom | kLHintsExpandX | kLHintsExpandY, 2, 2, 4, 1);
02262     pCleanup->Add(pL);
02263     pMain->AddFrame(pTab, pL);
02264     
02265     pMain->MapSubwindows();
02266     pMain->Resize(350, pMain->GetDefaultHeight());
02267     
02268     pMain->SetWindowName("Simulation Configuration");
02269     pMain->MapWindow();
02270     gClient->WaitFor(pMain);
02271 }
02272 
02273 SimulationDialog::~SimulationDialog()
02274 {
02275     pCleanup->Delete();
02276     delete pCleanup;
02277     delete pL1; delete pL2; delete pL3; delete pL4;
02278     delete pDShapeC; delete pDSizeE; delete pDColorC;
02279     delete pAShapeC; delete pASizeE; delete pAColorC;
02280     delete pDShapeL; delete pDSizeL; delete pDColorL;
02281     delete pAShapeL; delete pASizeL; delete pAColorL;
02282     delete pAtomFr; delete pDefectFr; delete pLatticeFr;
02283     delete pTryButton;
02284     
02285     delete pBoltzmL; delete pBoltzmE;
02286     delete pIntLimL; delete pIntLimL2; delete pIntLimE;
02287     delete pAlgFr;
02288     
02289     delete pUpdateL; delete pUpdateL2;
02290     delete pUpdateNum; delete pUpdateChBt;
02291     delete pAutoSaveChBt; delete pAutoSaveL; delete pAutoSaveL2;
02292     delete pAutoSaveNum; delete pImgPathL; delete pImgPrefixL;
02293     
02294     delete pInsL; delete pInsL2; delete pRemL; delete pRemL2;
02295     delete pInsE; delete pRemE;
02296     delete pInsRemFr;
02297     
02298     delete pImgFormatL; delete pImgPathE; delete pImgPrefixE;
02299     delete pImgFormatC; delete pImgFr;
02300     
02301     delete pGraphFr;
02302     delete pMCFr;
02303     delete pCancelButton; delete pOkButton;
02304     delete pBtFrame;
02305     delete pTab;
02306     delete pMain;
02307 }
02308 
02309 void SimulationDialog::CloseWindow()
02310 {
02311     delete this;
02312 }
02313 
02314 void SimulationDialog::DoOk()
02315 {
02316     void *dir;
02317 
02318     if ((dir = gSystem->OpenDirectory(pImgPathE->GetText()))) {
02319         gSystem->FreeDirectory(dir);
02320         pConfig->SetBoltzConst(pBoltzmE->GetDoubleNum());
02321         pConfig->SetTemp(0.0);
02322         pConfig->SetInteractionLimit(pIntLimE->GetDoubleNum());
02323         pConfig->UpdateCanvas((pUpdateChBt->GetState() & kButtonDown) ? 1 : 0);
02324         pConfig->AutoSave((pAutoSaveChBt->GetState() & kButtonDown) ? 1 : 0);
02325         pConfig->SetUpdateInterval((Int_t)pUpdateNum->GetIntNumber());
02326         pConfig->SetSaveInterval((Int_t)pAutoSaveNum->GetIntNumber());
02327         pConfig->SetImageFormat(pImgFormatC->GetSelected());
02328         pConfig->SetImagePath(pImgPathE->GetText());
02329         pConfig->SetImagePrefix(pImgPrefixE->GetText());
02330 
02331         pConfig->SetAtomStyle(pAShapeC->GetSelected(), pASizeE->GetNumber(), pAColorC->GetSelected());
02332         pConfig->SetDefectStyle(pDShapeC->GetSelected(), pDSizeE->GetNumber(), pDColorC->GetSelected());
02333         pConfig->SetInsNum(pInsE->GetIntNumber());
02334         pConfig->SetRemNum(pRemE->GetIntNumber());
02335         
02336         pConfig->SaveSimulationToFile();
02337         DoCancel();
02338     }
02339     else
02340         new TGMsgBox(gClient->GetRoot(), pMain, "Error", "Image path not valid", kMBIconExclamation, kMBOk);
02341             
02342 }
02343 
02344 void SimulationDialog::DoCancel()
02345 {
02346     if (pLattice) {
02347         pLattice->SetAtomStyle(pConfig->GetAtomShape(), pConfig->GetAtomSize(), pConfig->GetAtomColor());
02348         pLattice->SetDefectStyle(pConfig->GetDefectShape(), pConfig->GetDefectSize(), pConfig->GetDefectColor());
02349     }
02350     
02351     pMain->SendCloseMessage();
02352 }
02353 
02354 void SimulationDialog::DoTabButtons(Int_t wid)
02355 {
02356     if (wid == -1) {
02357         TGButton* btn = (TGButton*)gTQSender;
02358         wid = btn->WidgetId();
02359     }
02360     
02361     switch (wid) {
02362         case D_SIM_TRY:
02363             if (pLattice) {
02364                 pLattice->SetAtomStyle(pAShapeC->GetSelected(), pASizeE->GetNumber(), pAColorC->GetSelected());
02365                 pLattice->SetDefectStyle(pDShapeC->GetSelected(), pDSizeE->GetNumber(), pDColorC->GetSelected());
02366             }
02367             break;
02368     }
02369 }
02370 
02371 
02372 LVPicture::LVPicture() : TGPicture("", kFALSE)
02373 {
02374     WindowAttributes_t root_attr;
02375 
02376     gVirtualX->GetWindowAttributes(gClient->GetRoot()->GetId(), root_attr);
02377     
02378     fAttributes.fColormap = root_attr.fColormap;
02379     fAttributes.fCloseness = 40000; // Allow for "similar" colors
02380     fAttributes.fMask = kPASize | kPAColormap | kPACloseness;
02381     gVirtualX->CreatePictureFromData(gClient->GetRoot()->GetId(), gear_xpm, fPic, fMask, fAttributes);
02382 }
02383 
02384 LVPicture::~LVPicture() {}
02385 
02386 TempControl::TempControl(Configuration *config, MainFrame *mf, const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h, UInt_t options)
02387 {
02388     char str[32];
02389     
02390     pConfig = config;
02391     pMainFrame = mf;
02392     
02393     pMain = new TGTransientFrame(p, main, w, h, options | kFixedHeight);
02394     pMain->Connect("CloseWindow()", "TempControl", this, "CloseWindow()");
02395     
02396     pL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2);
02397     pL2 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2);
02398     
02399     pDlgFrame = new TGCompositeFrame(pMain, w, h, kVerticalFrame | kFixedHeight);
02400     pTempSlider = new TGDoubleHSlider(pDlgFrame, w, kDoubleScaleDownRight);
02401     pTempSlider->SetRange(pConfig->GetTempMin(), pConfig->GetTempMax());
02402     pTempSlider->SetPosition(pConfig->GetTemp(), pConfig->GetTemp());
02403     pTempSlider->Connect("PositionChanged()", "TempControl", this, "DoSlider()");   
02404     pRangeFrame = new TGCompositeFrame(pMain, w, 40, kHorizontalFrame);
02405     pFromEntry = new TGNumEntry(pRangeFrame, pConfig->GetTempMin());
02406     pFromEntry->Connect("TextChanged(char*)", "TempControl", this, "DoMinRange(char*)");
02407     pFromEntry->Resize(60, 18);
02408     pToEntry = new TGNumEntry(pRangeFrame, pConfig->GetTempMax());
02409     pToEntry->Connect("TextChanged(char*)", "TempControl", this, "DoMaxRange(char*)");
02410     pToEntry->Resize(60, 18);
02411     snprintf(str, 32, "%f", pConfig->GetTemp());
02412     pTempL = new TGLabel(pRangeFrame, str);
02413     pRangeFrame->AddFrame(pFromEntry, pL1);
02414     pRangeFrame->AddFrame(pTempL, pL2);
02415     pRangeFrame->AddFrame(pToEntry, pL1);
02416     
02417     pDlgFrame->AddFrame(pTempSlider, pL2);
02418     pDlgFrame->AddFrame(pRangeFrame, pL2);
02419     
02420     pMain->AddFrame(pDlgFrame, pL2);
02421     
02422     pMain->Layout();
02423     pMain->MapSubwindows();
02424     pMain->SetWindowName("Temperature Control");
02425     pMainFrame->pSimToolFr->HideFrame(pMainFrame->pSimTmpFr);
02426     pMain->MapWindow();
02427 }
02428 
02429 TempControl::~TempControl()
02430 {
02431     pMainFrame->pSimTmpSlider->SetRange(pConfig->GetTempMin(), pConfig->GetTempMax());
02432     pMainFrame->pSimTmpSlider->SetPosition(pConfig->GetTemp(), pConfig->GetTemp());
02433     pMainFrame->pSimTmpSlider->PositionChanged();
02434     pMainFrame->pSimToolFr->ShowFrame(pMainFrame->pSimTmpFr);
02435     pMainFrame->pMenuView->UnCheckEntry(M_VIEW_TEMP);
02436         
02437     delete pL1; delete pL2;
02438     delete pTempL; delete pFromEntry; delete pToEntry;
02439     delete pTempSlider; delete pRangeFrame;
02440     delete pDlgFrame; delete pMain;
02441 }
02442 
02443 void TempControl::DoMinRange(char* t)
02444 {
02445     Double_t newMin;
02446     char str[32];
02447     
02448     newMin = atof(t);
02449     
02450     if (newMin > pConfig->GetTempMax()) {
02451         snprintf(str, 32, "%f", pConfig->GetTempMin());
02452         pFromEntry->SetText(str);
02453     }
02454     else {
02455         pTempSlider->SetRange(newMin, pConfig->GetTempMax());
02456         if (newMin > pTempSlider->GetMinPosition()) {
02457             pTempSlider->SetPosition(newMin, newMin);
02458             pConfig->SetTemp(newMin);
02459         }
02460         else
02461             pTempSlider->SetPosition(pConfig->GetTemp(), pConfig->GetTemp());
02462         
02463         pConfig->SetTempMin(newMin);
02464         pTempSlider->PositionChanged();
02465     }
02466 }
02467 
02468 void TempControl::DoMaxRange(char* t)
02469 {
02470     Double_t newMax;
02471     char str[32];
02472     
02473     newMax = atof(t);
02474     
02475     if (newMax < pConfig->GetTempMin()) {
02476         snprintf(str, 32, "%f", pConfig->GetTempMax());
02477         pToEntry->SetText(str);
02478     }
02479     else {
02480         pTempSlider->SetRange(pConfig->GetTempMin(), newMax);
02481         if (newMax < pTempSlider->GetMaxPosition()) {
02482             pTempSlider->SetPosition(newMax, newMax);
02483             pConfig->SetTemp(newMax);
02484         }
02485         else
02486             pTempSlider->SetPosition(pConfig->GetTemp(), pConfig->GetTemp());
02487         
02488         pConfig->SetTempMax(newMax);
02489         pTempSlider->PositionChanged();
02490     }
02491 }
02492 
02493 void TempControl::DoSlider()
02494 {
02495     char str[32];
02496     
02497     snprintf(str, 32, "%f", pTempSlider->GetMinPosition());
02498     pTempL->SetText(str);
02499     pConfig->SetTemp(pTempSlider->GetMinPosition());
02500 }
02501 
02502 void TempControl::CloseWindow()
02503 {
02504     delete this;
02505 }
02506 
02507 LatticeDlg::LatticeDlg(Layer *l, const TGWindow* p, const TGWindow *main, UInt_t w, UInt_t h, UInt_t options)
02508 {
02509     pLayer = l;
02510     
02511     pCleanup = new TList();
02512     
02513     pMain = new TGTransientFrame(p, main, w, h, options);
02514     pMain->Connect("CloseWindow()", "LatticeDlg", this, "CloseWindow()");
02515             
02516     pDlgFrame = new TGCompositeFrame(pMain, w, h, kVerticalFrame | kFixedHeight);
02517     pLatticeL = new TGLabel(pDlgFrame, "Choose a lattice");
02518     pLatticeL->SetTextJustify(kTextLeft);
02519     pLatticeCombo = new TGComboBox(pDlgFrame, -1);
02520     pLatticeCombo->Resize(50, 20);
02521     pNumXL = new TGLabel(pDlgFrame, "Cell number (x)");
02522     pNumXL->SetTextJustify(kTextLeft);
02523     pNumXE = new TGNumEntry(pDlgFrame, "");
02524     pNumYL = new TGLabel(pDlgFrame, "Cell number (y)");
02525     pNumYL->SetTextJustify(kTextLeft);
02526     pNumYE = new TGNumEntry(pDlgFrame, "");
02527     pNumSizeL = new TGLabel(pDlgFrame, "Size of cell");
02528     pNumSizeL->SetTextJustify(kTextLeft);
02529     pNumSizeE = new TGNumEntry(pDlgFrame, "");
02530     
02531     pLatticeCombo->AddEntry("Square Lattice", kLSquare);
02532     pLatticeCombo->AddEntry("Hexagonal Lattice", kLHexagonal);
02533     
02534     pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 3, 3, 3, 3);
02535     pDlgFrame->AddFrame(pLatticeL, pL);
02536     pDlgFrame->AddFrame(pLatticeCombo, pL);
02537     pDlgFrame->AddFrame(pNumXL, pL);
02538     pDlgFrame->AddFrame(pNumXE, pL);
02539     pDlgFrame->AddFrame(pNumYL, pL);
02540     pDlgFrame->AddFrame(pNumYE, pL);
02541     pDlgFrame->AddFrame(pNumSizeL, pL);
02542     pDlgFrame->AddFrame(pNumSizeE, pL);
02543     pCleanup->Add(pL);
02544     
02545     pBtFrame = new TGCompositeFrame(pDlgFrame, 160, 60, kFixedWidth | kHorizontalFrame);
02546     pOkButton = new TGTextButton(pBtFrame, "Ok", D_CHLAT_OK);
02547     pCancelButton = new TGTextButton(pBtFrame, "Cancel", D_CHLAT_CANCEL);
02548     pBtFrame->AddFrame(pOkButton, pL = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
02549     pBtFrame->AddFrame(pCancelButton, pL);
02550     pCleanup->Add(pL);
02551     
02552     pOkButton->Connect("Clicked()", "LatticeDlg", this, "DoButtons()");
02553     pCancelButton->Connect("Clicked()", "LatticeDlg", this, "DoButtons()");
02554     
02555     pDlgFrame->AddFrame(pBtFrame, pL = new TGLayoutHints(kLHintsRight | kLHintsBottom, 2, 0, 2, 4));
02556     pCleanup->Add(pL);
02557     
02558     pMain->AddFrame(pDlgFrame, pL = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX, 2, 2, 2, 2));
02559     pCleanup->Add(pL);
02560     pMain->MapSubwindows();
02561     pMain->SetWindowName("Choose lattice");
02562     pMain->Layout();
02563     pMain->Resize(w, pMain->GetDefaultHeight());
02564     pMain->MapWindow();
02565     
02566     gClient->WaitFor(pMain);
02567 }
02568 
02569 LatticeDlg::~LatticeDlg()
02570 {
02571     pCleanup->Delete();
02572     delete pCleanup;
02573     
02574     delete pOkButton; delete pCancelButton;
02575     delete pBtFrame;
02576     delete pNumXL; delete pNumYL; delete pNumXE; delete pNumYE;
02577     delete pLatticeCombo; delete pLatticeL;
02578     delete pDlgFrame; delete pMain;
02579 }
02580 
02581 void LatticeDlg::CloseWindow()
02582 {
02583     delete this;
02584 }
02585 
02586 void LatticeDlg::DoButtons(Int_t wid)
02587 {
02588     if (wid == -1) {
02589         TGButton *btn = (TGButton*)gTQSender;
02590         wid = btn->WidgetId();
02591     }
02592 
02593     switch (wid) {
02594         case D_CHLAT_OK:
02595             if (pLatticeCombo->GetSelected() == -1)
02596                 new TGMsgBox(gClient->GetRoot(), pMain, "Error", "Please choose a lattice", kMBIconExclamation, kMBOk);
02597             else if (strlen(pNumXE->GetText()) == 0)
02598                 new TGMsgBox(gClient->GetRoot(), pMain, "Error", "Please enter the number of cells in x-direction", kMBIconExclamation, kMBOk);
02599             else if (strlen(pNumYE->GetText()) == 0)
02600                 new TGMsgBox(gClient->GetRoot(), pMain, "Error", "Please enter the number of cells in y-direction", kMBIconExclamation, kMBOk);
02601             else if (strlen(pNumSizeE->GetText()) == 0)
02602                 new TGMsgBox(gClient->GetRoot(), pMain, "Error", "Please enter the size of the cell", kMBIconExclamation, kMBOk);
02603             else {
02604                 pLayer->SetLattice(pLatticeCombo->GetSelected(), pNumXE->GetIntNum(), pNumYE->GetIntNum(), pNumSizeE->GetDoubleNum());
02605                 pMain->SendCloseMessage();
02606             }
02607         break;
02608         case D_CHLAT_CANCEL:
02609             pMain->SendCloseMessage();
02610         break;
02611     }
02612 }

Generated on Sun Jun 16 20:08:04 2002 for XEIS by doxygen1.2.16