00001 #ifndef _CONFIGURATION_H_ 00002 #define _CONFIGURATION_H_ 00003 00004 #include <TROOT.h> 00005 #include <TSystem.h> 00006 #include <TThread.h> 00007 #include <Gtypes.h> 00008 #include <stdlib.h> 00009 #include <iostream.h> 00010 00011 #ifndef __CINT__ 00012 #include <libxml/xmlmemory.h> 00013 #include <libxml/parser.h> 00014 #endif // __CINT__ 00015 00016 #define CONFIG_FILE "/.xeis-config.xml" 00017 extern char** environ; 00018 00019 struct Param 00020 { 00021 Param(const char* i, const char* n, Double_t v, const char* d) { 00022 Int_t l; 00023 00024 l = strlen(i)+1; 00025 id = new char[l]; 00026 strncpy(id, i, l); 00027 l = strlen(n)+1; 00028 name = new char[l]; 00029 strncpy(name, n, l); 00030 value = v; 00031 l = strlen(d)+1; 00032 descr = new char[l]; 00033 strncpy(descr, d, l); 00034 } 00035 ~Param() {delete id; delete name; delete descr;} 00036 char* id; 00037 char* name; 00038 char* descr; 00039 Double_t value; 00040 }; 00041 00042 struct Function 00043 { 00044 Function(Int_t i, const char* n, const char* e, const char* l, const char* x, const char* y, const char* z) { 00045 Int_t s; 00046 00047 id = i; 00048 s = strlen(n)+1; 00049 curName = new char[s]; 00050 oldName = new char[s]; 00051 strncpy(curName, n, s); 00052 strncpy(oldName, n, s); 00053 s = strlen(e)+1; 00054 curExpr = new char[s]; 00055 oldExpr = new char[s]; 00056 strncpy(curExpr, e, s); 00057 strncpy(oldExpr, e, s); 00058 s = strlen(l)+1; 00059 curLatex = new char[s]; 00060 oldLatex = new char[s]; 00061 strncpy(curLatex, l, s); 00062 strncpy(oldLatex, l, s); 00063 s = strlen(x)+1; 00064 curX = new char[s]; 00065 oldX = new char[s]; 00066 strncpy(curX, x, s); 00067 strncpy(oldX, x, s); 00068 s = strlen(y)+1; 00069 curY = new char[s]; 00070 oldY = new char[s]; 00071 strncpy(curY, y, s); 00072 strncpy(oldY, y, s); 00073 s = strlen(z)+1; 00074 curZ = new char[s]; 00075 oldZ = new char[s]; 00076 strncpy(curZ, z, s); 00077 strncpy(oldZ, z, s); 00078 parsedExpr = new char[1]; 00079 parsedExpr[0] = '\0'; 00080 00081 bDeleted = kFALSE; 00082 bAdded = kFALSE; 00083 } 00084 Function(const Function* func) { 00085 Int_t s; 00086 00087 id = func->id; 00088 bDeleted = func->bDeleted; 00089 bAdded = func->bAdded; 00090 00091 s = strlen(func->curName)+1; 00092 curName = new char[s]; 00093 strncpy(curName, func->curName, s); 00094 s = strlen(func->curExpr)+1; 00095 curExpr = new char[s]; 00096 strncpy(curExpr, func->curExpr, s); 00097 s = strlen(func->curLatex)+1; 00098 curLatex = new char[s]; 00099 strncpy(curLatex, func->curLatex, s); 00100 s = strlen(func->curX)+1; 00101 curX = new char[s]; 00102 strncpy(curX, func->curX, s); 00103 s = strlen(func->curY)+1; 00104 curY = new char[s]; 00105 strncpy(curY, func->curY, s); 00106 s = strlen(func->curZ)+1; 00107 curZ = new char[s]; 00108 strncpy(curZ, func->curZ, s); 00109 s = strlen(func->oldName)+1; 00110 oldName = new char[s]; 00111 strncpy(oldName, func->oldName, s); 00112 s = strlen(func->oldExpr)+1; 00113 oldExpr = new char[s]; 00114 strncpy(oldExpr, func->oldExpr, s); 00115 s = strlen(func->oldLatex)+1; 00116 oldLatex = new char[s]; 00117 strncpy(oldLatex, func->oldLatex, s); 00118 s = strlen(func->oldX)+1; 00119 oldX = new char[s]; 00120 strncpy(oldX, func->oldX, s); 00121 s = strlen(func->oldY)+1; 00122 oldY = new char[s]; 00123 strncpy(oldY, func->oldY, s); 00124 s = strlen(func->oldZ)+1; 00125 oldZ = new char[s]; 00126 strncpy(oldZ, func->oldZ, s); 00127 s = strlen(func->parsedExpr)+1; 00128 parsedExpr = new char[s]; 00129 strncpy(parsedExpr, func->parsedExpr, s); 00130 } 00131 ~Function() { 00132 delete curName; delete curExpr; delete curLatex; 00133 delete oldName; delete oldExpr; delete oldLatex; 00134 delete curX; delete curY; delete curZ; 00135 delete oldX; delete oldY; delete oldZ; 00136 delete parsedExpr; 00137 } 00138 Bool_t bDeleted, bAdded; 00139 Int_t id; 00140 char *curName, *oldName; 00141 char *curExpr, *oldExpr; 00142 char *curLatex, *oldLatex; 00143 char *curX, *oldX; 00144 char *curY, *oldY; 00145 char *curZ, *oldZ; 00146 char *parsedExpr; 00147 }; 00148 00149 class Configuration 00150 { 00151 public: 00152 Configuration(); 00153 virtual ~Configuration(); 00154 00155 void LoadConfigFromFile(); 00156 void SaveFormulaToFile(); 00157 void SaveSimulationToFile(); 00158 void SaveTempToFile(); 00159 00160 void SetAtomShape(Style_t s) { atomShape = s; } 00161 void SetAtomSize(Size_t s) { atomSize = s; } 00162 void SetAtomColor(Color_t c) { atomColor = c; } 00163 void SetAtomStyle(Style_t, Size_t, Color_t); 00164 void SetDefectShape(Style_t s) { defectShape = s; } 00165 void SetDefectSize(Size_t s) { defectSize = s; } 00166 void SetDefectColor(Color_t c) { defectColor = c; } 00167 void SetDefectStyle(Style_t, Size_t, Color_t); 00168 void SetParam(const char**, const char**, Double_t*, const char**, UInt_t); 00169 void SetFunction(Int_t*, const char**, const char**, const char**, const char**, const char**, const char**, UInt_t); 00170 void SetBoltzConst(Double_t c) { TThread::Lock(); k = c; TThread::UnLock(); } 00171 void SetTemp(Double_t temp) { TThread::Lock(); T = temp; TThread::UnLock(); } 00172 void SetTempMin(Double_t t) { TThread::Lock(); Tmin = t; TThread::UnLock(); } 00173 void SetTempMax(Double_t t) { TThread::Lock(); Tmax = t; TThread::UnLock(); } 00174 void SetInsNum(Int_t n) { insNum = n; } 00175 void SetRemNum(Int_t n) { remNum = n; } 00176 void SetInteractionLimit(Double_t lim) { TThread::Lock(); intLimit = lim; TThread::UnLock(); } 00177 void UpdateCanvas(Int_t flag) { TThread::Lock(); bUpdateCanvas = flag; TThread::UnLock(); } 00178 void AutoSave(Int_t flag) { TThread::Lock(); bAutoSave = flag; TThread::UnLock(); } 00179 void SetUpdateInterval(Int_t i) { TThread::Lock(); updateInt = i; TThread::UnLock(); } 00180 void SetSaveInterval(Int_t i) { TThread::Lock(); saveInt = i; TThread::UnLock(); } 00181 void SetImageFormat(Int_t f) { TThread::Lock(); imgFormat = f; TThread::UnLock(); } 00182 void SetImagePath(const char* str); 00183 void SetImagePrefix(const char* str); 00184 00185 Function** AddFunction(Int_t, const char*, const char*, const char*, const char* = "", const char* = "", const char* = ""); 00186 void RevertFunction(); 00187 void CleanFunction(); 00188 00189 Style_t GetAtomShape() { return atomShape; } 00190 Size_t GetAtomSize() { return atomSize; } 00191 Color_t GetAtomColor() { return atomColor; } 00192 Style_t GetDefectShape() { return defectShape; } 00193 Size_t GetDefectSize() { return defectSize; } 00194 Color_t GetDefectColor() { return defectColor; } 00195 UInt_t GetParam(Param**&); 00196 UInt_t GetFunction(Function**&); 00197 UInt_t GetParamCount() { return paramCount; } 00198 UInt_t GetFuncCount() { return funcCount; } 00199 Double_t GetBoltzConst() { return k; } 00200 Double_t GetTemp() { return T; } 00201 Double_t GetTempMax() { return Tmax; } 00202 Double_t GetTempMin() { return Tmin; } 00203 Double_t GetInteractionLimit() { return intLimit; } 00204 Int_t GetInsNum() { return insNum; } 00205 Int_t GetRemNum() { return remNum; } 00206 Int_t UpdateCanvas() { return bUpdateCanvas; } 00207 Int_t AutoSave() { return bAutoSave; } 00208 Int_t GetUpdateInterval() { return updateInt; } 00209 Int_t GetSaveInterval() { return saveInt; } 00210 Int_t GetImageFormat() { return imgFormat; } 00211 const char* GetImagePath() { return (const char*)imgPath; } 00212 const char* GetImagePrefix() { return (const char*)imgPrefix; } 00213 00214 00215 protected: 00216 00217 #ifndef __CINT__ 00218 xmlDocPtr CreateConfigFile(); 00219 xmlNodePtr GetConfigNode(char*); 00220 void WriteParam(xmlNodePtr); 00221 void WriteFunction(xmlNodePtr); 00222 void WriteLattice(xmlNodePtr); 00223 void WriteMonteCarlo(xmlNodePtr); 00224 xmlDocPtr xmlDoc; 00225 #endif // __CINT__ 00226 00227 Double_t k, T, Tmin, Tmax, intLimit; 00228 Int_t bUpdateCanvas, bAutoSave; 00229 Int_t updateInt, saveInt, imgFormat; 00230 Int_t insNum, remNum; 00231 char *imgPath, *imgPrefix; 00232 const char *homePath, *fileName; 00233 Style_t atomShape, defectShape; 00234 Size_t atomSize, defectSize; 00235 Color_t atomColor, defectColor; 00236 Param** params; 00237 Function** functions; 00238 UInt_t paramCount, funcCount; 00239 }; 00240 00241 #endif // _CONFIGURATION_H_