00001
00002
00003
00004
00005
00006
00007
00008 #include "StCheckQtEnv.h"
00009 #include "TSystem.h"
00010 #include "TApplication.h"
00011 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,00,0)
00012 #include "TPRegexp.h"
00013 #endif
00014 #include "TEnv.h"
00015 namespace {
00016 class InitGraph {
00017 public:
00018 InitGraph() {
00019 gEnv->SetValue("Gui.Backend", "qt");
00020 gEnv->SetValue("Gui.Factory", "qtgui");
00021 gApplication->NeedGraphicsLibs();
00022 gApplication->InitializeGraphics();
00023 }
00024 };
00025 }
00026
00027
00028 FILE *StCheckQtEnv::OpeFileName(const char *fileNamePrototype)
00029 {
00030
00031 return fopen( (const char*)GetNewFileName(fileNamePrototype),"w");
00032 }
00033
00034 TString StCheckQtEnv::GetNewFileName(const char *fileNamePrototype)
00035 {
00036
00037 TString fileName = fileNamePrototype;
00038 gSystem->ExpandPathName(fileName);
00039
00040 Ssiz_t fileExtension = fileName.Last('.');
00041 TString fileNameHold = fileName;
00042 if ((fileExtension==0) || (fileExtension == -1)) {
00043 fileExtension = fileName.Length();
00044 }
00045 Int_t counter = 0;
00046 while (gSystem->AccessPathName(fileName.Data())==0) {
00047 fileName = fileNameHold;
00048 fileName.Insert(fileExtension,Form(".%d",counter++));
00049 }
00050 return fileName;
00051 }
00052
00053
00054
00055
00056 Int_t StCheckQtEnv::SetRootResource(FILE *file, const char *plugin,
00057 const char *lib, const char *full,Bool_t append)
00058 {
00059 fprintf(stderr," Testing the plugin <%s> from the lib = <%s>\n", plugin, lib);
00060 Int_t success = 0;
00061 TString fullName;
00062 TString fullValue;
00063 if (full) {
00064
00065 fullName = Form("lib%s",lib);
00066 fullValue = Form(full,lib);
00067 } else {
00068 fullValue = lib;
00069 }
00070
00071 if ( !full || gSystem->DynamicPathName(fullName.Data(),kTRUE) ) {
00072
00073 success = 1;
00074 TString currentPlugin = gEnv->GetValue(plugin,"none");
00075 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,00,0)
00076 TPRegexp exp(Form("\\b%s\\b",lib));
00077 #else
00078 TString exp(Form(" %s ",lib));
00079 #endif
00080 if ( !currentPlugin.Contains(exp) )
00081 {
00082 TString p = "+";
00083 if (append) {
00084 p +=plugin;
00085 plugin = p.Data();
00086
00087 }
00088 gEnv->SetValue(plugin,fullValue);
00089 if (file) {
00090 fputs(Form("%s %s\n",plugin,fullValue.Data()), file);
00091 }
00092 } else {
00093
00094 }
00095 }
00096 return success;
00097 }
00098
00099
00100 Long_t StCheckQtEnv::SetQtEnv(bool checkCoin) {
00101
00102
00103
00104
00105
00106
00107
00108 static InitGraph init_graph;
00109 const char *plugins[] = {
00110 "Plugin.TVirtualX"
00111 , "GQt"
00112 , " qt TGQt %s \"TGQt(const char*,const char*)\""
00113
00114 , "Gui.Backend", "qt", 0
00115
00116 , "Plugin.TGuiFactory"
00117 , "QtRootGui"
00118 , " qtgui TQtGUIFactory %s \"TQtGUIFactory()\""
00119
00120 , "Gui.Factory", "qtgui", 0
00121
00122 , "Gui.Factory", "qt" , 0
00123
00124 , "Plugin.TVirtualPadEditor"
00125 , "QtGed"
00126 , " Ged TQtGedEditor %s \"TQtGedEditor(TCanvas*)\""
00127
00128 , "Plugin.TVirtualViewer3D"
00129 , "RQTGL"
00130 , " ogl TQtRootViewer3D %s \"TQtRootViewer3D(TVirtualPad*)\""
00131
00132 , "Plugin.TVirtualViewer3D"
00133 , "RQIVTGL"
00134 , " oiv TQtRootCoinViewer3D %s \"TQtRootCoinViewer3D(TVirtualPad*)\""
00135 , "", "", ""
00136 };
00137 Int_t iPlugin = 0;
00138 Long_t c = 0;
00139 TString fileName = GetNewFileName("rootrc");
00140 FILE *f = fopen((const char *)fileName, "w");
00141 if (f) {
00142
00143 if ((c+=SetRootResource(f,plugins[iPlugin],plugins[iPlugin+1],plugins[iPlugin+2]))) {
00144 iPlugin+=3;
00145 c+=SetRootResource(f,plugins[iPlugin],plugins[iPlugin+1],plugins[iPlugin+2]);
00146 iPlugin+=3;
00147
00148 if ((c+=SetRootResource(f,plugins[iPlugin],plugins[iPlugin+1],plugins[iPlugin+2]))) {
00149 iPlugin+=3;
00150 if ((c+=SetRootResource(f,plugins[iPlugin],plugins[iPlugin+1],plugins[iPlugin+2]))) {
00151
00152
00153
00154 iPlugin+=3;
00155 } else {
00156
00157 iPlugin+=3;
00158 c+=SetRootResource(f,plugins[iPlugin],plugins[iPlugin+1],plugins[iPlugin+2]);
00159 }
00160
00161
00162 iPlugin+=3;
00163 c+=SetRootResource(f,plugins[iPlugin],plugins[iPlugin+1],plugins[iPlugin+2]);
00164
00165 iPlugin+=3;
00166
00167 if ((c+=SetRootResource(f,plugins[iPlugin],plugins[iPlugin+1],plugins[iPlugin+2]))) {
00168
00169 Long_t savedC = c;
00170
00171 if (checkCoin) {
00172 if (gSystem->DynamicPathName("libCoin",kTRUE)) {
00173 iPlugin+=3;
00174 c+=SetRootResource(f,plugins[iPlugin],plugins[iPlugin+1],plugins[iPlugin+2],kTRUE);
00175 } else {
00176 fprintf(stderr," ----------------------------------------------------------\n");
00177 fprintf(stderr," ATTENTION : \n");
00178 fprintf(stderr,"\"Coin3d\" shared libraries has not beed detected\n");
00179 fprintf(stderr," Please, run:\n\n");
00180 fprintf(stderr,"===== \"source $STAR/QtRoot/qtgl/qtcoin/setup.csh\" =====\n\n");
00181 fprintf(stderr," script to activated the advanced (recommended) Coin3D env.\n");
00182 fprintf(stderr," ----------------------------------------------------------\n");
00183 fprintf(stderr," and re-start your application\n");
00184 fprintf(stderr," ----------------------------------------------------------\n");
00185 c = savedC;
00186 gSystem->Sleep(5000);
00187 } }
00188 } } }
00189
00190 fclose(f);
00191 } else {
00192 c = 1;
00193 }
00194 if (c == 0) {
00195 fprintf(stderr," No shared library to activate the Qt-layer has been detected.\n");
00196 fprintf(stderr," Please talk to your SysAdmin\n");
00197 gSystem->Unlink(fileName.Data());
00198 c = -1;
00199 } else {
00200 Long_t id; Long_t size; Long_t flags; Long_t modtime;
00201 gSystem->GetPathInfo(fileName.Data(), &id, &size, &flags, &modtime);
00202 c = size;
00203 if (size == 0) {
00204 fprintf(stderr," ----------------------------------------------------------\n");
00205 fprintf(stderr," The correct Qt/Root env has been detected.\n");
00206 fprintf(stderr," ----------------------------------------------------------\n");
00207 gSystem->Unlink(fileName.Data());
00208 } else {
00209 fprintf(stderr," ----------------------------------------------------------\n");
00210 fprintf(stderr," ATTENTION : \n");
00211 fprintf(stderr," The new version of ROOT resource file has been created: <%s>.\n",fileName.Data());
00212 if (gSystem->AccessPathName(".rootrc")) {
00213 fprintf(stderr," To active the Qt-layer - create a symlink:\n");
00214 fprintf(stderr,"============ \"ln -s %s .rootrc \" ====================\n", fileName.Data());
00215 } else {
00216 fprintf(stderr," To active the Qt-layer - **merge** the existen \".rootrc\" file with \"%s\" \n", fileName.Data());
00217 }
00218 fprintf(stderr," and re-start your application\n");
00219 fprintf(stderr," ----------------------------------------------------------\n");
00220 }
00221 }
00222 return c;
00223
00224
00225 }