Changeset 7001 for trunk/MagicSoft/Mars/mbase
- Timestamp:
- 05/09/05 10:15:41 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mbase
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MLog.cc
r5820 r7001 134 134 #endif 135 135 const char *const MLog::kBlue = "\033[34m"; 136 const char *const MLog::kUnderline = "\033[4m"; ;137 const char *const MLog::kBlink = "\033[5m"; ;138 const char *const MLog::kBright = "\033[1m"; ;139 const char *const MLog::kDark = "\033[2m"; ;136 const char *const MLog::kUnderline = "\033[4m"; 137 const char *const MLog::kBlink = "\033[5m"; 138 const char *const MLog::kBright = "\033[1m"; 139 const char *const MLog::kDark = "\033[2m"; 140 140 141 141 // … … 488 488 if (fDevice&eStdout) 489 489 { 490 if (! TestBit(eNoColors))490 if (!fIsNull && !TestBit(eNoColors)) 491 491 cout << kReset; 492 492 cout.flush(); -
trunk/MagicSoft/Mars/mbase/MLog.h
r5720 r7001 129 129 void operator=(TGTextView *out) { SetOutputGui(out); } 130 130 131 Bool_t IsNullOutput() const { return fIsNull; } 131 132 Bool_t IsOutputDeviceEnabled(int i) const { return fDevice & i; } 132 133 -
trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc
r7000 r7001 33 33 // To write gif files of C-Macros use SaveAsGif()/SaveAsPNG() or SaveAsC(). 34 34 // Direct printing to the default printer (via lpr) can be done by 35 // Print ToLpr().35 // PrintPS(). 36 36 // 37 37 // It has also to half status lines which can be used to display the status … … 64 64 65 65 #include <TH1.h> // TH1::AddDirectory 66 #include <TPDF.h> // TPDF 67 #include <TSVG.h> // TSVG 66 68 #include <TEnv.h> // TEnv 67 69 #include <TLine.h> // TLine … … 74 76 #include <TDatime.h> // TDatime 75 77 #include <TRandom.h> // TRandom 78 #include <TRegexp.h> // TRegexp 76 79 #include <TThread.h> // TThread::Self() 77 80 #include <TBrowser.h> // TBrowser … … 80 83 #include <TMethodCall.h> // TMethodCall 81 84 82 //#include <TRint.h> // gApplication, TRint::Class()83 85 #include <TInterpreter.h> // gInterpreter 84 86 … … 92 94 #include <TGFileDialog.h> // TGFileDialog 93 95 #include <TGProgressBar.h> // TGHProgressBar 96 #include <TGTextEditDialogs.h> // TGPrintDialog 94 97 #include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas 95 98 … … 245 248 // 246 249 MGPopupMenu *filemenu = new MGPopupMenu(gClient->GetRoot()); 247 // filemenu->AddEntry("Save &As...", kFileSaveAs); 248 filemenu->AddEntry("New Can&vas", kFileCanvas); 249 filemenu->AddEntry("New &Browser", kFileBrowser); 250 filemenu->AddEntry("New &Canvas", kFileCanvas); 251 filemenu->AddEntry("New &Browser", kFileBrowser); 250 252 filemenu->AddSeparator(); 251 filemenu->AddEntry("Save status.&ps", kFileSaveAsPS); 252 filemenu->AddEntry("Save status.&png", kFileSaveAsPNG); 253 filemenu->AddEntry("Save status.&gif", kFileSaveAsGIF); 254 filemenu->AddEntry("Save status.&jpg", kFileSaveAsJPG); 255 filemenu->AddEntry("Save status.&xpm", kFileSaveAsXPM); 256 filemenu->AddEntry("Save status.&C", kFileSaveAsC); 257 filemenu->AddEntry("Save status.&root", kFileSaveAsRoot); 253 254 const TString fname(MString::Form("Save %s.", gROOT->GetName())); 255 MGPopupMenu *savemenu = new MGPopupMenu(gClient->GetRoot()); 256 savemenu->AddEntry(MString::Form("%s&ps", fname.Data()), kFileSaveAsPS); 257 savemenu->AddEntry(MString::Form("%sp&df", fname.Data()), kFileSaveAsPDF); 258 savemenu->AddEntry(MString::Form("%s&svg", fname.Data()), kFileSaveAsSVG); 259 savemenu->AddSeparator(); 260 savemenu->AddEntry(MString::Form("%sp&ng", fname.Data()), kFileSaveAsPNG); 261 savemenu->AddEntry(MString::Form("%s&gif", fname.Data()), kFileSaveAsGIF); 262 savemenu->AddEntry(MString::Form("%s&jpg", fname.Data()), kFileSaveAsJPG); 263 savemenu->AddEntry(MString::Form("%s&xpm", fname.Data()), kFileSaveAsXPM); 264 //savemenu->AddEntry("Save status.x&cf", kFileSaveAsXCF); 265 //savemenu->AddEntry("Save status.&tiff", kFileSaveAsTIFF); 266 //savemenu->AddEntry("Save status.&bmp", kFileSaveAsBMP); 267 savemenu->AddSeparator(); 268 savemenu->AddEntry(MString::Form("%s&C", fname.Data()), kFileSaveAsC); 269 savemenu->AddEntry(MString::Form("%s&root", fname.Data()), kFileSaveAsRoot); 270 savemenu->Associate(this); 271 272 filemenu->AddEntry("&Open...", kFileOpen); 273 filemenu->AddPopup("&Save", savemenu); 274 filemenu->AddEntry("Save &As...", kFileSaveAs); 258 275 filemenu->AddSeparator(); 259 filemenu->AddEntry("&Open...", kFileOpen); 260 filemenu->AddEntry("Save &As...", kFileSaveAs); 276 filemenu->AddEntry("&Reset", kFileReset); 261 277 filemenu->AddSeparator(); 262 filemenu->AddEntry(" Re&set", kFileReset);278 filemenu->AddEntry("&Print", kFilePrint); 263 279 filemenu->AddSeparator(); 264 filemenu->AddEntry("Print with &lpr", kFilePrint); 265 //filemenu->AddEntry("Set printer &name", kFilePrinterName); 266 filemenu->AddSeparator(); 267 filemenu->AddEntry("C&lose", kFileClose); 268 filemenu->AddEntry("E&xit", kFileExit); 280 filemenu->AddEntry("C&lose", kFileClose); 281 filemenu->AddEntry("E&xit", kFileExit); 269 282 filemenu->Associate(this); 270 283 … … 273 286 // 274 287 MGPopupMenu *tabmenu = new MGPopupMenu(gClient->GetRoot()); 275 tabmenu->AddEntry("Next [&+]", 276 tabmenu->AddEntry("Previous [&-]", 288 tabmenu->AddEntry("Next [&+]", kTabNext); 289 tabmenu->AddEntry("Previous [&-]", kTabPrevious); 277 290 tabmenu->AddSeparator(); 278 tabmenu->AddEntry("Save tab-i.&ps", kTabSaveAsPS); 279 tabmenu->AddEntry("Save tab-i.&png", kTabSaveAsPNG); 280 tabmenu->AddEntry("Save tab-i.&gif", kTabSaveAsGIF); 281 tabmenu->AddEntry("Save tab-i.&jpg", kTabSaveAsJPG); 282 tabmenu->AddEntry("Save tab-i.&xpm", kTabSaveAsXPM); 283 tabmenu->AddEntry("Save tab-i.&C", kTabSaveAsC); 284 tabmenu->AddEntry("Save tab-i.&root", kTabSaveAsRoot); 291 292 const TString fname2(MString::Form("Save %s-i.", gROOT->GetName())); 293 MGPopupMenu *savemenu2 = new MGPopupMenu(gClient->GetRoot()); 294 savemenu2->AddEntry(MString::Form("%s&ps", fname2.Data()), kTabSaveAsPS); 295 savemenu2->AddEntry(MString::Form("%sp&df", fname2.Data()), kTabSaveAsPDF); 296 savemenu2->AddEntry(MString::Form("%s&svg", fname2.Data()), kTabSaveAsSVG); 297 savemenu2->AddSeparator(); 298 savemenu2->AddEntry(MString::Form("%sp&ng", fname2.Data()), kTabSaveAsPNG); 299 savemenu2->AddEntry(MString::Form("%s&gif", fname2.Data()), kTabSaveAsGIF); 300 savemenu2->AddEntry(MString::Form("%s&jpg", fname2.Data()), kTabSaveAsJPG); 301 savemenu2->AddEntry(MString::Form("%s&xpm", fname2.Data()), kTabSaveAsXPM); 302 //savemenu->AddEntry("Save status.x&cf", kFileSaveAsXCF); 303 //savemenu->AddEntry("Save status.&tiff", kFileSaveAsTIFF); 304 //savemenu->AddEntry("Save status.&bmp", kFileSaveAsBMP); 305 savemenu2->AddSeparator(); 306 savemenu2->AddEntry(MString::Form("%s&C", fname2.Data()), kTabSaveAsC); 307 savemenu2->AddEntry(MString::Form("%s&root", fname2.Data()), kTabSaveAsRoot); 308 savemenu2->Associate(this); 309 310 tabmenu->AddPopup("&Save", savemenu2); 311 tabmenu->AddEntry("Save tab &As...", kTabSaveAs); 285 312 tabmenu->AddSeparator(); 286 tabmenu->AddEntry(" Save tab &As...", kTabSaveAs);313 tabmenu->AddEntry("&Remove", kTabRemove); 287 314 tabmenu->AddSeparator(); 288 tabmenu->AddEntry("Re&move", kTabRemove); 289 tabmenu->AddSeparator(); 290 tabmenu->AddEntry("Print with &lpr", kTabPrint); 315 tabmenu->AddEntry("&Print", kTabPrint); 291 316 tabmenu->Associate(this); 292 317 … … 326 351 logmenu->AddEntry("&Save", kLogSave); 327 352 logmenu->AddEntry("Save &append", kLogAppend); 353 logmenu->AddSeparator(); 354 logmenu->AddEntry("&Print", kLogPrint); 328 355 logmenu->Associate(this); 329 356 … … 355 382 // Add everything to autodel list 356 383 // 384 fList->Add(savemenu); 385 fList->Add(savemenu2); 357 386 fList->Add(filemenu); 358 387 fList->Add(loopmenu); … … 1085 1114 } 1086 1115 1116 TString MStatusDisplay::PrintDialog(TString &p, TString &c, TString &t, const char *ext) 1117 { 1118 // If not in batch mode open a user dialog 1119 if (!gROOT->IsBatch()) 1120 { 1121 char *cprinter = StrDup(p); 1122 char *ccmd = StrDup(c); 1123 1124 Int_t rc=0; 1125 new TGPrintDialog(fClient->GetRoot(), this, 400, 150, &cprinter, &ccmd, &rc); 1126 if (rc) 1127 { 1128 p = cprinter; // default has been changed 1129 c = ccmd; 1130 } 1131 1132 delete [] cprinter; 1133 delete [] ccmd; 1134 1135 if (!rc) 1136 return ""; 1137 } 1138 1139 1140 if (c.Contains("%f") && ext) 1141 { 1142 // Get temporary file name 1143 TString name = "mars"; 1144 1145 FILE *f = gSystem->TempFileName(name, t); 1146 if (!f) 1147 { 1148 *fLog << warn << "MStatusDisplay::PrintDialog: Couldn't create temporary file in " << t << endl; 1149 SetStatusLine2("failed!"); 1150 return ""; 1151 } 1152 fclose(f); 1153 1154 // remove temp file 1155 gSystem->Unlink(name); 1156 name += "."; 1157 name += ext; 1158 1159 t = name; 1160 } 1161 1162 // compile command 1163 TString cmd(c); 1164 1165 // if sprinter.IsNull we assume that everything around %p can 1166 // be omitted and the program uses some kind of default 1167 if (p.IsNull()) 1168 { 1169 TString sub; 1170 while (1) 1171 { 1172 sub = TString(cmd(TRegexp(" .*%p.* "))).Strip(TString::kBoth); 1173 if (sub.IsNull()) 1174 break; 1175 1176 cmd.ReplaceAll(sub, ""); 1177 } 1178 } 1179 1180 cmd.ReplaceAll("%p", p); 1181 cmd.ReplaceAll("%f", t); 1182 1183 return cmd; 1184 } 1185 1087 1186 // -------------------------------------------------------------------------- 1088 1187 // 1089 1188 // Saves the given canvas (pad) or all pads (num<0) as a temporary 1090 // postscript file and prints it using 'lpr'. If a printer name is set 1091 // via SetPrinter 'lpr -Pname' is used. 1092 // 1093 Int_t MStatusDisplay::PrintToLpr(Int_t num) 1094 { 1095 TString name = "mars"; 1096 1097 for (int i=0; i<6; i++) 1098 name += (char)(gRandom->Uniform(25)+65); 1099 1100 name += ".ps"; 1101 1102 const Int_t pages = SaveAsPS(num, name); 1103 1189 // postscript file and prints it. 1190 // 1191 // The default command line c is: lpr -P%p %f 1192 // %p: printer name 1193 // %f: temporary file name 1194 // 1195 // The default printer name p is: <empty> 1196 // 1197 // Both can be changed in .rootrc by: 1198 // PrintPS.Printer 1199 // PrintPS.Command 1200 // 1201 // Ant the location of the temporary file t can by changed by 1202 // Print.Directory 1203 // the default is the system default directory (normally /tmp) 1204 // 1205 Int_t MStatusDisplay::PrintPS(Int_t num, const char *p, const char *c, const char *t) 1206 { 1207 static TString sprinter = gEnv->GetValue("PrintPS.Printer", p&&*p?p:""); 1208 static TString scmd = gEnv->GetValue("PrintPS.Command", c&&*c?c:"lpr -P%p %f"); 1209 1210 TString tmp = gEnv->GetValue("Print.Directory", t&&*t?t:gSystem->TempDirectory()); 1211 1212 TString cmd = PrintDialog(sprinter, scmd, tmp, "ps"); 1213 if (cmd.IsNull()) 1214 return 0; 1215 1216 // set status lines 1104 1217 SetStatusLine1("Printing..."); 1105 1218 SetStatusLine2(""); 1106 1219 1220 // print to temporary file 1221 const Int_t pages = SaveAsPS(num, tmp); 1222 1223 // check 1107 1224 if (!pages) 1108 1225 { 1109 *fLog << warn << "MStatusDisplay::Print ToLpr: Sorry, couldn't save file as temporary postscript!" << endl;1226 *fLog << warn << "MStatusDisplay::Print: Sorry, couldn't save file as temporary postscript!" << endl; 1110 1227 SetStatusLine2("Failed!"); 1111 1228 return 0; 1112 1229 } 1113 1230 1114 TString cmd="lpr "; 1115 if (!fPrinter.IsNull()) 1116 { 1117 cmd += "-P"; 1118 cmd += fPrinter; 1119 cmd += " "; 1120 } 1121 cmd += name; 1122 1231 // execute command 1232 *fLog << dbg << "Executing: " << cmd << endl; 1123 1233 gSystem->Exec(cmd); 1124 gSystem->Unlink(name); 1234 1235 // remove temporary file 1236 gSystem->Unlink(tmp); 1125 1237 1126 1238 SetStatusLine2(MString::Form("Done (%dpage(s))", pages)); … … 1226 1338 } 1227 1339 1340 Bool_t MStatusDisplay::SaveLogAsPS(const char *n) const 1341 { 1342 TString name(n); 1343 AddExtension(name, "ps"); 1344 1345 // Code taken from TGTextEdit::Print 1346 const TString pipe = MString::Form("a2ps -o%s", name.Data()); 1347 FILE *p = gSystem->OpenPipe(pipe, "w"); 1348 if (!p) 1349 { 1350 *fLog << err << "ERROR - Couldn't open pipe " << pipe << endl; 1351 return kFALSE; 1352 } 1353 1354 TGText *text = fLogBox->GetText(); 1355 1356 char *buf1, *buf2; 1357 Long_t len; 1358 ULong_t i = 0; 1359 TGLongPosition pos; 1360 1361 pos.fX = pos.fY = 0; 1362 while (pos.fY < text->RowCount()) 1363 { 1364 len = text->GetLineLength(pos.fY); 1365 buf1 = text->GetLine(pos, len); 1366 buf2 = new char[len + 2]; 1367 strncpy(buf2, buf1, (UInt_t)len); 1368 buf2[len] = '\n'; 1369 buf2[len+1] = '\0'; 1370 while (buf2[i] != '\0') { 1371 if (buf2[i] == '\t') { 1372 ULong_t j = i+1; 1373 while (buf2[j] == 16 && buf2[j] != '\0') 1374 j++; 1375 strcpy(buf2+i+1, buf2+j); 1376 } 1377 i++; 1378 } 1379 fwrite(buf2, sizeof(char), strlen(buf2)+1, p); 1380 1381 delete [] buf1; 1382 delete [] buf2; 1383 pos.fY++; 1384 } 1385 gSystem->ClosePipe(p); 1386 return kTRUE; 1387 } 1388 1389 // -------------------------------------------------------------------------- 1390 // 1391 // Print the log text. 1392 // 1393 // The default command line c is: a2ps -P%p 1394 // %p: printer name 1395 // 1396 // The default printer name p is: <empty> 1397 // 1398 // Both can be changed in .rootrc by: 1399 // PrintText.Printer 1400 // PrintText.Command 1401 // 1402 Bool_t MStatusDisplay::PrintLog(const char *p, const char *c) 1403 { 1404 static TString sprinter = gEnv->GetValue("PrintText.Printer", p&&*p?p:""); 1405 static TString scmd = gEnv->GetValue("PrintText.Command", c&&*c?c:"a2ps -P%p"); 1406 1407 TString tmp; 1408 TString cmd = PrintDialog(sprinter, scmd, tmp); 1409 if (cmd.IsNull()) 1410 return kFALSE; 1411 1412 // set status lines 1413 SetStatusLine1("Printing..."); 1414 SetStatusLine2(""); 1415 1416 // print to temporary file 1417 if (!SaveLogAsPS(cmd)) 1418 { 1419 *fLog << warn << "MStatusDisplay::PrintLog: Sorry, couldn't create postscript!" << endl; 1420 SetStatusLine2("Failed!"); 1421 return kFALSE; 1422 } 1423 1424 // execute command 1425 *fLog << dbg << "Executing: " << cmd << endl; 1426 gSystem->Exec(cmd); 1427 1428 SetStatusLine2("Done."); 1429 1430 return kTRUE; 1431 } 1432 1228 1433 // -------------------------------------------------------------------------- 1229 1434 // … … 1267 1472 return kTRUE; 1268 1473 1474 case kFileSaveAsPDF: 1475 SaveAsPDF(); 1476 return kTRUE; 1477 1478 case kFileSaveAsSVG: 1479 SaveAsSVG(); 1480 return kTRUE; 1481 1269 1482 case kFileSaveAsPNG: 1270 1483 SaveAsPNG(); … … 1283 1496 return kTRUE; 1284 1497 1498 //case kFileSaveAsXCF: 1499 // SaveAsXCF(); 1500 // return kTRUE; 1501 1502 //case kFileSaveAsTIFF: 1503 // SaveAsTIFF(); 1504 // return kTRUE; 1505 1506 //case kFileSaveAsBMP: 1507 // SaveAsBMP(); 1508 // return kTRUE; 1509 1285 1510 case kFileSaveAsC: 1286 1511 SaveAsC(); … … 1292 1517 1293 1518 case kFilePrint: 1294 Print ToLpr();1519 PrintPS(); 1295 1520 return kTRUE; 1296 1521 … … 1303 1528 return kTRUE; 1304 1529 1530 case kTabSaveAsPDF: 1531 SaveAsPDF(fTab->GetCurrent()); 1532 return kTRUE; 1533 1534 case kTabSaveAsSVG: 1535 SaveAsSVG(fTab->GetCurrent()); 1536 return kTRUE; 1537 1305 1538 case kTabSaveAsPNG: 1306 1539 SaveAsPNG(fTab->GetCurrent()); … … 1319 1552 return kTRUE; 1320 1553 1554 //case kTabSaveAsXCF: 1555 // SaveAsXCF(fTab->GetCurrent()); 1556 // return kTRUE; 1557 1558 //case kTabSaveAsBMP: 1559 // SaveAsBMP(fTab->GetCurrent()); 1560 // return kTRUE; 1561 1562 //case kTabSaveAsTIFF: 1563 // SaveAsTIFF(fTab->GetCurrent()); 1564 // return kTRUE; 1565 1321 1566 case kTabSaveAsC: 1322 1567 SaveAsC(fTab->GetCurrent()); … … 1328 1573 1329 1574 case kTabPrint: 1330 Print ToLpr(fTab->GetCurrent());1575 PrintPS(fTab->GetCurrent()); 1331 1576 return kTRUE; 1332 1577 … … 1386 1631 SetStatusLine2(""); 1387 1632 *fLog << inf << "Saving log... " << flush; 1388 if (fLogBox->GetText()->Save( "statusdisplay.log"))1633 if (fLogBox->GetText()->Save(MString::Form("%s.log", gROOT->GetName()))) 1389 1634 { 1390 1635 *fLog << "done." << endl; … … 1402 1647 SetStatusLine2(""); 1403 1648 *fLog << inf << "Appending log... " << flush; 1404 if (fLogBox->GetText()->Append( "statusdisplay.log"))1649 if (fLogBox->GetText()->Append(MString::Form("%s.log", gROOT->GetName()))) 1405 1650 { 1406 1651 *fLog << "done." << endl; … … 1412 1657 SetStatusLine2("Failed!"); 1413 1658 } 1659 return kTRUE; 1660 1661 case kLogPrint: 1662 PrintLog(); 1414 1663 return kTRUE; 1415 1664 #ifdef DEBUG … … 1973 2222 if (name.IsNull()) 1974 2223 { 1975 name = "status";2224 name = gROOT->GetName(); 1976 2225 if (num>0) 1977 2226 { … … 2042 2291 gSystem->Unlink(name); 2043 2292 gSystem->Rename(name+".$$$", name); 2044 /* 2045 // 2046 // Old style algorithm. Shifts blocks inside a single file --- SLOW! 2047 // 2048 const Int_t l = newstr.Length(); 2049 2050 Long_t t[4]; // { id, size, flags, modtime } 2051 gSystem->GetPathInfo(name, t, t+1, t+2, t+3); 2052 2053 char *c[2] = { new char[l], new char[l] }; 2054 2055 fstream f(name, ios::in|ios::out); 2056 2057 TString str; 2058 f >> str >> c[0][0]; // Read "%!PS-Adobe-2.0\n" (Mini Header) 2059 f.read(c[0], l); 2060 f.seekp(-l, ios::cur); 2061 f.write(newstr, l); 2062 2063 int i=0; 2064 while (1) 2065 { 2066 f.read(c[(i+1)%2], l); 2067 f.seekp(-l, ios::cur); 2068 2069 if (f) 2070 { 2071 f.write(c[i%2],l); 2072 i++; 2073 i%=2; 2074 continue; 2075 } 2076 2077 const Int_t ssz = str.Length()+1; // Length of Mini-Header 2078 const Int_t block = t[1]-ssz; // Length of block to be shifted 2079 const Int_t size = block%l; // Reminder 2080 const Int_t pos = (block/l)*l + ssz + 1; // Position to start writing 2081 2082 f.clear(); 2083 f.seekp(pos); 2084 f.write(c[i%2], l); 2085 f.write(c[(i+1)%2], size); 2086 break; 2087 } 2088 2089 delete c[1]; 2090 delete c[0]; 2091 */ 2092 } 2093 2094 // -------------------------------------------------------------------------- 2095 // 2096 // In case of num<0 all tabs are written into the PS file. If num>0 2293 } 2294 2295 void MStatusDisplay::PSToolsRange(TVirtualPS &vps, Float_t psw, Float_t psh) const 2296 { 2297 if (vps.InheritsFrom(TPostScript::Class())) 2298 static_cast<TPostScript&>(vps).Range(psw, psh); 2299 // if (vps.InheritsFrom(TPDF::Class())) 2300 // static_cast<TPDF&>(vps).Range(psw/2, psh/2); 2301 // if (vps.InheritsFrom(TSVG::Class())) 2302 // static_cast<TSVG&>(vps).Range(psw, psh); 2303 } 2304 2305 void MStatusDisplay::PSToolsTextNDC(TVirtualPS &vps, Double_t u, Double_t v, const char *string) const 2306 { 2307 if (vps.InheritsFrom(TPostScript::Class())) 2308 static_cast<TPostScript&>(vps).TextNDC(u, v, string); 2309 // if (vps.InheritsFrom(TPDF::Class())) 2310 // static_cast<TPDF&>(vps).TextNDC(u, v, string); 2311 // if (vps.InheritsFrom(TSVG::Class())) 2312 // static_cast<TSVG&>(vps).TextNDC(u, v, string); 2313 } 2314 2315 // -------------------------------------------------------------------------- 2316 // 2317 // Write some VGF (vector graphics format). Currently PS, PDF and SVG 2318 // is available. Specified by ext. 2319 // 2320 // In case of num<0 all tabs are written into the VGF file. If num>0 2097 2321 // the canvas in the corresponding tab is written to the file. 2098 2322 // Name is the name of the file (with or without extension). … … 2100 2324 // Returns the number of pages written. 2101 2325 // 2102 // To write all tabs you can also use SaveAs PS(name)2326 // To write all tabs you can also use SaveAsVGF(name, ext) 2103 2327 // 2104 2328 // If the third argument is given a bottom line is drawn with the text … … 2106 2330 // fTitle (SetTitle) is not empty. 2107 2331 // 2108 Int_t MStatusDisplay::SaveAs PS(Int_t num, TString name, const TString addon)2109 { 2110 SetStatusLine1( "Writing Postscript file...");2332 Int_t MStatusDisplay::SaveAsVGF(Int_t num, TString name, const TString addon, const TString ext) 2333 { 2334 SetStatusLine1(Form("Writing %s file...",ext.Data())); 2111 2335 SetStatusLine2(""); 2112 2336 … … 2117 2341 } 2118 2342 2119 AddExtension(name, "ps", num);2343 AddExtension(name, ext, num); 2120 2344 2121 2345 if (num<0) 2122 *fLog << inf << "Open ps-File: " << name << endl;2346 *fLog << inf << "Open " << ext << "-File: " << name << endl; 2123 2347 2124 2348 TPad *padsav = (TPad*)gPad; … … 2127 2351 TDatime d; 2128 2352 2129 TPostScript ps(name, 112); 2130 ps.SetBit(TPad::kPrintingPS); 2131 ps.PrintFast(13, "/nan {1} def "); 2132 2133 gVirtualPS = &ps; 2353 Int_t type = -1; 2354 2355 TVirtualPS *ps =0; 2356 if (!ext.CompareTo("ps", TString::kIgnoreCase)) 2357 { 2358 ps = new TPostScript(name, 112); 2359 type = 1; 2360 } 2361 if (!ext.CompareTo("pdf", TString::kIgnoreCase)) 2362 { 2363 ps = new TPDF(name, 112); 2364 type = 2; 2365 } 2366 if (!ext.CompareTo("svg", TString::kIgnoreCase)) 2367 { 2368 ps = new TSVG(name, 112); 2369 type = 3; 2370 } 2371 2372 if (!ps) 2373 { 2374 *fLog << err << "Extension " << ext << " unknown..." << endl; 2375 SetStatusLine2("Failed!"); 2376 return 0; 2377 } 2378 2379 ps->SetBit(TPad::kPrintingPS); 2380 if (type==1) 2381 ps->PrintFast(13, "/nan {1} def "); 2382 2383 gVirtualPS = ps; 2134 2384 2135 2385 // … … 2170 2420 // has the same Aspect Ratio than on the screen. 2171 2421 // 2172 ps.NewPage(); 2422 if (i>from) 2423 ps->NewPage(); 2173 2424 2174 2425 // … … 2176 2427 // such that the page title can be set above the canvas... 2177 2428 // 2178 Float_t psw = 28.0; // A4 - width (29.7)2429 Float_t psw = 28.0; // A4 - width (29.7) 2179 2430 Float_t psh = 21.0; // A4 - height (21.0) 2180 2431 … … 2187 2438 psh = ch/cw*psw; 2188 2439 2189 ps.Range(psw, psh); // A42440 PSToolsRange(*ps, psw, psh); 2190 2441 2191 2442 // … … 2219 2470 // Print overlaying text (NDC = %) 2220 2471 // 2221 ps .SetTextColor(kBlack);2222 ps .SetTextSize(0.015);2223 ps .SetTextFont(22);2224 ps .SetTextAlign(11); // left top2225 ps.TextNDC(0, 1.015, TString(" ")+n->GetName());2226 ps .SetTextAlign(21); // cent top2227 ps.TextNDC(0.5, 1.015, TString("MARS - Magic Analysis and Reconstruction Software - ")+d.AsString());2228 ps .SetTextAlign(31); // right top2229 ps.TextNDC(1, 1.015, MString::Form("Page No.%i (%i) ", page++, i));2472 ps->SetTextColor(kBlack); 2473 ps->SetTextSize(0.015); 2474 ps->SetTextFont(22); 2475 ps->SetTextAlign(11); // left top 2476 PSToolsTextNDC(*ps, 0, 1.015, TString(" ")+n->GetName()); 2477 ps->SetTextAlign(21); // cent top 2478 PSToolsTextNDC(*ps, 0.5, 1.015, TString("MARS - Magic Analysis and Reconstruction Software - ")+d.AsString()); 2479 ps->SetTextAlign(31); // right top 2480 PSToolsTextNDC(*ps, 1, 1.015, MString::Form("Page No.%i (%i) ", page++, i)); 2230 2481 line.PaintLineNDC(0, 1.01, 1, 1.01); 2231 2482 … … 2234 2485 { 2235 2486 line.PaintLineNDC(0, -0.00, 1, -0.00); 2236 ps .SetTextAlign(11); // left top2237 ps.TextNDC(0, -0.015, TString(" ")+txt);2238 ps .SetTextAlign(31); // right top2239 ps.TextNDC(1, -0.015, "(c) 2000-2004, Thomas Bretz ");2487 ps->SetTextAlign(11); // left top 2488 PSToolsTextNDC(*ps, 0, -0.015, TString(" ")+txt); 2489 ps->SetTextAlign(31); // right top 2490 PSToolsTextNDC(*ps, 1, -0.015, "(c) 2000-2005, Thomas Bretz "); 2240 2491 } 2241 2492 … … 2250 2501 l.Delete(); 2251 2502 2252 ps.Close(); 2253 2254 SetStatusLine2("Updating header of PS file..."); 2255 2256 if (num<0) 2257 *fLog << " - Updating header of PS file... " << flush; 2258 UpdatePSHeader(name); 2259 if (num<0) 2260 *fLog << inf << "done." << endl; 2503 ps->Close(); 2504 delete ps; 2505 2506 if (type==1) 2507 { 2508 SetStatusLine2("Updating header of PS file..."); 2509 2510 if (num<0) 2511 *fLog << " - Updating header of PS file... " << flush; 2512 UpdatePSHeader(name); 2513 if (num<0) 2514 *fLog << inf << "done." << endl; 2515 } 2261 2516 2262 2517 gVirtualPS = psave; … … 2274 2529 Bool_t MStatusDisplay::SaveAsImage(Int_t num, TString name, TImage::EImageFileTypes type) 2275 2530 { 2531 //#if ROOT_VERSION_CODE < ROOT_VERSION(4,04,00) 2276 2532 if (gROOT->IsBatch()) 2277 2533 { … … 2280 2536 return 0; 2281 2537 } 2282 //SetStatusLine1("Writing GIF file..."); 2538 //#endif 2539 2283 2540 SetStatusLine1("Writing image file... <please be patient>"); 2284 2541 SetStatusLine2(""); … … 2306 2563 ext = AddExtension(name, "jpg", num); 2307 2564 break; 2308 // case TImage::kXcf: 2309 // ext = AddExtension(name, "xcf", num); 2565 case TImage::kGif: 2566 ext = AddExtension(name, "gif", num); 2567 break; 2568 // case TImage::kTiff: 2569 // ext = AddExtension(name, "tiff", num); 2310 2570 // break; 2311 2571 // case TImage::kPpm: … … 2315 2575 // ext = AddExtension(name, "pnm", num); 2316 2576 // break; 2317 // case TImage::kBmp:2318 // ext = AddExtension(name, "bmp", num);2319 // break;2320 2577 // case TImage::kIco: 2321 2578 // ext = AddExtension(name, "ico", num); … … 2324 2581 // ext = AddExtension(name, "cur", num); 2325 2582 // break; 2326 case TImage::kGif:2327 ext = AddExtension(name, "gif", num);2328 break;2329 // case TImage::k Tiff:2330 // ext = AddExtension(name, " tif", num);2583 // case TImage::kBmp: 2584 // ext = AddExtension(name, "bmp", num); 2585 // break; 2586 // case TImage::kXcf: 2587 // ext = AddExtension(name, "xcf", num); 2331 2588 // break; 2332 2589 // case TImage::kXbm: … … 2397 2654 *fLog << "..." << flush; 2398 2655 2656 #if ROOT_VERSION_CODE < ROOT_VERSION(4,04,00) 2399 2657 c->Draw(); 2658 2400 2659 if (type==TImage::kGif) 2401 2660 c->SaveAs(writename); // FIXME: Seems not to work well in TImage! (root 3.10/02) … … 2407 2666 delete img; 2408 2667 } 2409 2668 #else 2669 c->Print(writename); 2670 #endif 2410 2671 if (num<0) 2411 2672 *fLog << "done." << endl; … … 2535 2796 // -------------------------------------------------------------------------- 2536 2797 // 2798 // Determin File type to save file as by extension. Allowed extensions are: 2799 // root, ps, pdf, svg, gif, png, jpg, xpm, C 2800 // 2801 // returns -1 if file type is unknown. Otherwise return value of SaveAs* 2802 // 2803 Int_t MStatusDisplay::SaveAs(Int_t num, TString name) 2804 { 2805 if (name.EndsWith(".root")) return SaveAsRoot(num, name); 2806 if (name.EndsWith(".ps")) return SaveAsPS(num, name); 2807 if (name.EndsWith(".pdf")) return SaveAsPDF(num, name); 2808 if (name.EndsWith(".svg")) return SaveAsSVG(num, name); 2809 if (name.EndsWith(".gif")) return SaveAsGIF(num, name); 2810 if (name.EndsWith(".png")) return SaveAsPNG(num, name); 2811 if (name.EndsWith(".jpg")) return SaveAsJPG(num, name); 2812 if (name.EndsWith(".xpm")) return SaveAsXPM(num, name); 2813 if (name.EndsWith(".C")) return SaveAsC(num, name); 2814 return -1; 2815 } 2816 2817 // -------------------------------------------------------------------------- 2818 // 2537 2819 // Opens a save as dialog 2538 2820 // … … 2542 2824 { 2543 2825 "PostScript", "*.ps", 2826 "Acrobat pdf", "*.pdf", 2827 "SVG vector", "*.svg", 2544 2828 "Gif files", "*.gif", 2829 "Png files", "*.png", 2830 "Gif files", "*.gif", 2831 "Jpeg files", "*.jpeg", 2832 "Xpm files", "*.xpm", 2545 2833 "Macro files", "*.C", 2546 2834 "ROOT files", "*.root", … … 2563 2851 dir = fi.fIniDir; 2564 2852 2565 const TString name(fi.fFilename); 2566 2567 if (name.EndsWith(".root")) return SaveAsRoot(num, name); 2568 if (name.EndsWith(".ps")) return SaveAsPS(num, name); 2569 if (name.EndsWith(".gif")) return SaveAsGIF(num, name); 2570 if (name.EndsWith(".C")) return SaveAsC(num, name); 2853 const Int_t rc = SaveAs(num, fi.fFilename); 2854 if (rc>=0) 2855 return rc; 2571 2856 2572 2857 Warning("MStatusDisplay::SaveAs", "Unknown Extension: %s", fi.fFilename); -
trunk/MagicSoft/Mars/mbase/MStatusDisplay.h
r6978 r7001 26 26 class TMutex; 27 27 class TCanvas; 28 class TVirtualPS; 28 29 29 30 class TGTab; … … 42 43 typedef enum { 43 44 // kFile 44 kFileBrowser, kFileCanvas, kFileOpen, kFileSave, kFileSaveAs, kFileSaveAsPS, 45 kFileSaveAsRoot, kFileSaveAsPNG, kFileSaveAsGIF, kFileSaveAsJPG, 46 kFileSaveAsXPM, kFileSaveAsC, kFilePrint, kFilePrinterName, 45 kFileBrowser, kFileCanvas, kFileOpen, kFileSave, kFileSaveAs, 46 kFileSaveAsPS, kFileSaveAsPDF, kFileSaveAsSVG, kFileSaveAsRoot, 47 kFileSaveAsPNG, kFileSaveAsGIF, kFileSaveAsJPG, kFileSaveAsXPM, 48 /*kFileSaveAsBMP, kFileSaveAsXCF, kFileSaveAsTIFF,*/ 49 kFileSaveAsC, kFilePrint, kFilePrinterName, 47 50 kFileClose, kFileExit, kFileReset, 48 51 // kLoop 49 52 kLoopNone, kLoopStop, 50 53 // kTab 51 kTabSave, kTabSaveAs, kTabSaveAsPS, kTabSaveAsRoot, kTabSaveAsPNG, 52 kTabSaveAsGIF, kTabSaveAsJPG, kTabSaveAsXPM, kTabSaveAsC, 54 kTabSave, kTabSaveAs, kTabSaveAsPS, kTabSaveAsPDF, kTabSaveAsSVG, 55 kTabSaveAsRoot, kTabSaveAsPNG, kTabSaveAsGIF, kTabSaveAsJPG, 56 kTabSaveAsXPM, /*kTabSaveAsBMP, kTabSaveAsXCF, kTabSaveAsTIFF,*/ 57 kTabSaveAsC, 53 58 kTabPrint, kTabNext, kTabPrevious, kTabRemove, 54 59 // kSize … … 57 62 // kLog 58 63 kLogCopy, kLogClear, kLogSelect, kLogFind, kLogSave, kLogAppend, 64 kLogPrint, 59 65 // kPic 60 66 kPicMagic, kPicMars, … … 91 97 92 98 Status_t fStatus; 93 94 TString fPrinter;95 99 96 100 Int_t fLogIdx; … … 134 138 Bool_t Display(const TObjArray &list, const char *tab=0); 135 139 136 const TString &AddExtension(TString &name, const TString &ext, Int_t num ) const;140 const TString &AddExtension(TString &name, const TString &ext, Int_t num=-1) const; 137 141 138 142 void UpdatePSHeader(const TString &name) const; … … 144 148 145 149 Bool_t SaveAsImage(Int_t num, TString name, TImage::EImageFileTypes type); 150 Int_t SaveAsVGF(Int_t num, TString name, const TString addon, const TString ext); 151 152 void PSToolsRange(TVirtualPS &vps, Float_t w, Float_t h) const; 153 void PSToolsTextNDC(TVirtualPS &vps, Double_t u, Double_t v, const char *string) const; 154 TString PrintDialog(TString &p, TString &c, TString &t, const char *ext=0); 155 146 156 147 157 public: … … 161 171 void SetStatusLine2(const char *txt) { SetStatusLine(txt, 1); } 162 172 void SetStatusLine2(const MParContainer &cont); 163 164 void SetPrinter(const TString &lpr) { fPrinter = lpr; }165 173 166 174 virtual void SetName(const char *name) { fName = name; } … … 198 206 void SetNoContextMenu(Bool_t flag=kTRUE); 199 207 200 Int_t SaveAsPS(TString name="", const TString addon="") { return SaveAsPS(-1, name, addon); } 201 Bool_t SaveAsPNG(TString name="") { return SaveAsPNG(-1, name); } 202 Bool_t SaveAsGIF(TString name="") { return SaveAsGIF(-1, name); } 203 Bool_t SaveAsXPM(TString name="") { return SaveAsXPM(-1, name); } 204 Bool_t SaveAsJPG(TString name="") { return SaveAsJPG(-1, name); } 205 Bool_t SaveAsC(TString name="") { return SaveAsC(-1, name); } 208 Int_t SaveAsPS(TString name="", const TString addon="") { return SaveAsVGF(-1, name, addon, "ps"); } 209 Int_t SaveAsPDF(TString name="", const TString addon="") { return SaveAsVGF(-1, name, addon, "pdf"); } 210 Int_t SaveAsSVG(TString name="", const TString addon="") { return SaveAsVGF(-1, name, addon, "svg"); } 211 Bool_t SaveAsPNG(TString name="") { return SaveAsPNG(-1, name); } 212 Bool_t SaveAsGIF(TString name="") { return SaveAsGIF(-1, name); } 213 Bool_t SaveAsXPM(TString name="") { return SaveAsXPM(-1, name); } 214 Bool_t SaveAsJPG(TString name="") { return SaveAsJPG(-1, name); } 215 //Bool_t SaveAsTIFF(TString name="") { return SaveAsTIFF(-1, name); } 216 //Bool_t SaveAsXCF(TString name="") { return SaveAsXCF(-1, name); } 217 //Bool_t SaveAsBMP(TString name="") { return SaveAsBMP(-1, name); } 218 Bool_t SaveAsC(TString name="") { return SaveAsC(-1, name); } 206 219 Int_t SaveAsRoot(TString name="") { return SaveAsRoot(-1, name); } 207 Int_t PrintToLpr() { return PrintToLpr(-1); } 208 209 Int_t SaveAsPS(Int_t num, TString name="", const TString addon=""); 210 Bool_t SaveAsPNG(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kPng); } 211 Bool_t SaveAsGIF(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kGif); } 212 Bool_t SaveAsXPM(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kXpm); } 213 Bool_t SaveAsJPG(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kJpeg); } 220 Int_t SaveAs(TString name) { return SaveAs(-1, name); } 221 Int_t PrintPS() { return PrintPS(-1); } 222 223 Int_t SaveAsPS(Int_t num, TString name="", const TString addon="") { return SaveAsVGF(num, name, addon, "ps"); } 224 Int_t SaveAsPDF(Int_t num, TString name="", const TString addon="") { return SaveAsVGF(num, name, addon, "pdf"); } 225 Int_t SaveAsSVG(Int_t num, TString name="", const TString addon="") { return SaveAsVGF(num, name, addon, "svg"); } 226 Bool_t SaveAsPNG(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kPng); } 227 Bool_t SaveAsGIF(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kGif); } 228 Bool_t SaveAsXPM(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kXpm); } 229 Bool_t SaveAsJPG(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kJpeg); } 230 //Bool_t SaveAsTIFF(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kTiff); } 231 //Bool_t SaveAsXCF(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kXcf); } 232 //Bool_t SaveAsBMP(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kBmp); } 214 233 Bool_t SaveAsC(Int_t num, TString name=""); 215 234 Int_t SaveAsRoot(Int_t num, TString name=""); 216 Int_t PrintToLpr(Int_t num); 235 Int_t SaveAs(Int_t num, TString name); 236 Int_t PrintPS(Int_t num, const char *p=0, const char *cmd=0, const char *tmp=0); 237 Bool_t PrintLog(const char *p=0, const char *c=0); 238 Bool_t SaveLogAsPS(const char *name) const; 217 239 218 240 Int_t SaveAs(Int_t num=-1);
Note:
See TracChangeset
for help on using the changeset viewer.