00001
00002
00003
00004
00005
00006
00008 #include "EventDisplayBase/PrintDialog.h"
00009 #include <map>
00010 #include <string>
00011
00012 #include "TGWindow.h"
00013 #include "TGFrame.h"
00014 #include "TGLayout.h"
00015 #include "TGButton.h"
00016 #include "TGTextEntry.h"
00017
00018 #include "EventDataModel/EventHandle.h"
00019 #include "EventDataModel/EventHeader.h"
00020 #include "EventDisplayBase/evdb.h"
00021 #include "EventDisplayBase/Printable.h"
00022 #include "EventDisplayBase/IoModule.h"
00023 using namespace evdb;
00024
00025 ClassImp(evdb::PrintDialog)
00026
00027 static std::map<std::string,bool> gsPrintableSelection;
00028 static std::map<std::string,bool> gsFormatSelection;
00029
00030
00031
00032 PrintDialog::PrintDialog() :
00033 TGTransientFrame(evdb::TopWindow(),evdb::TopWindow(),500,300,0),
00034 fNprintable(0)
00035 {
00036 fL1 = new TGLayoutHints(kLHintsLeft|kLHintsTop|kLHintsExpandX, 2, 2, 2, 2);
00037 fL2 = new TGLayoutHints(kLHintsLeft|kLHintsTop, 2, 2, 2, 2);
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 int wPrintable = 50;
00048 int wFilename = 200;
00049 int wCheckBox = 100;
00050 int h = 20;
00051 int i = 0;
00052 std::map<std::string,Printable*>&
00053 printables = Printable::GetPrintables();
00054 std::map<std::string,Printable*>::iterator itr(printables.begin());
00055 std::map<std::string,Printable*>::iterator itrEnd(printables.end());
00056 for (; itr!=itrEnd; ++itr) {
00057 fPrintTag[i] = itr->first;
00058 fPrintable[i] = itr->second;
00059 fPrintFrame[i] = new TGHorizontalFrame(this,20,20);
00060
00061 std::string ptag;
00062 std::string base;
00063 std::string filename;
00064 base = "evd.";
00065 base += itr->second->PrintTag();
00066
00067 char runevt[128];
00068 edm::EventHeader& head = IoModule::Instance()->GetEvent().Header();
00069 sprintf(runevt,".%.5d.%.9d",head.Run(),head.Event());
00070 base += runevt;
00071
00072
00073 fPrintableCB[i] = new TGCheckButton(fPrintFrame[i], itr->first.c_str());
00074 fPrintableCB[i]->Resize(wPrintable, h);
00075 fPrintFrame[i]->AddFrame(fPrintableCB[i], fL1);
00076 if (gsPrintableSelection[fPrintTag[i]]) {
00077 fPrintableCB[i]->SetState(kButtonDown);
00078 }
00079
00080
00081 fFilename[i] = new TGTextEntry(fPrintFrame[i], new TGTextBuffer(256));
00082 fFilename[i]->SetToolTipText("Base file name for print");
00083 fFilename[i]->SetText(base.c_str());
00084 fFilename[i]->Resize(wFilename,h);
00085 fPrintFrame[i]->AddFrame(fFilename[i], fL2);
00086
00087
00088 fDoPS[i] = new TGCheckButton(fPrintFrame[i], ".ps");
00089 fDoPS[i]->Resize(wCheckBox,h);
00090 fPrintFrame[i]->AddFrame(fDoPS[i], fL2);
00091 ptag = fPrintTag[i]; ptag += ".ps";
00092 if (gsFormatSelection[ptag]) fDoPS[i]->SetState(kButtonDown);
00093
00094
00095 fDoEPS[i] = new TGCheckButton(fPrintFrame[i], ".eps");
00096 fDoEPS[i]->Resize(wCheckBox,h);
00097 fPrintFrame[i]->AddFrame(fDoEPS[i], fL2);
00098 ptag = fPrintTag[i]; ptag += ".eps";
00099 if (gsFormatSelection[ptag]) fDoEPS[i]->SetState(kButtonDown);
00100
00101
00102 fDoGIF[i] = new TGCheckButton(fPrintFrame[i], ".gif");
00103 fDoGIF[i]->Resize(wCheckBox,h);
00104 fPrintFrame[i]->AddFrame(fDoGIF[i], fL2);
00105 ptag = fPrintTag[i]; ptag += ".gif";
00106 if (gsFormatSelection[ptag]) fDoGIF[i]->SetState(kButtonDown);
00107
00108
00109 fDoJPG[i] = new TGCheckButton(fPrintFrame[i], ".jpg");
00110 fDoJPG[i]->Resize(wCheckBox,h);
00111 fPrintFrame[i]->AddFrame(fDoJPG[i], fL2);
00112 ptag = fPrintTag[i]; ptag += ".jpg";
00113 if (gsFormatSelection[ptag]) fDoJPG[i]->SetState(kButtonDown);
00114
00115 ++i;
00116 }
00117 fNprintable = i;
00118
00119
00120 fButtonFrame = new TGHorizontalFrame(this,20,20);
00121
00122 fPrintButton = new TGTextButton(fButtonFrame,"&Print",150);
00123 fPrintButton->Connect("Clicked()", "evdb::PrintDialog", this, "Print()");
00124 fButtonFrame->AddFrame(fPrintButton,
00125 new TGLayoutHints(kLHintsLeft,4,4,4,4));
00126
00127 fCancelButton = new TGTextButton(fButtonFrame,"&Cancel",150);
00128 fCancelButton->Connect("Clicked()", "evdb::PrintDialog", this, "Cancel()");
00129 fButtonFrame->AddFrame(fCancelButton,
00130 new TGLayoutHints(kLHintsRight,4,4,4,4));
00131
00132
00133 for (int i=0; i<fNprintable; ++i) this->AddFrame(fPrintFrame[i],fL1);
00134 this->AddFrame(fButtonFrame);
00135 this->MapSubwindows();
00136 this->Resize(500, fNprintable*(h+8)+38);
00137
00138 this->SetWindowName("Print Dialog");
00139 this->MapWindow();
00140
00141 this->Connect("CloseWindow()","evdb::PrintDialog",this,"CloseWindow()");
00142 }
00143
00144
00145
00146 void PrintDialog::CloseWindow() { delete this; }
00147
00148
00149
00150 PrintDialog::~PrintDialog()
00151 {
00152 for (int i=0; i<fNprintable; ++i) {
00153 delete fDoJPG[i];
00154 delete fDoGIF[i];
00155 delete fDoEPS[i];
00156 delete fDoPS[i];
00157 delete fFilename[i];
00158 delete fPrintableCB[i];
00159 delete fPrintFrame[i];
00160 }
00161 delete fPrintButton;
00162 delete fCancelButton;
00163 delete fButtonFrame;
00164 delete fL1;
00165 delete fL2;
00166 }
00167
00168
00169
00170 void PrintDialog::Cancel() { this->SendCloseMessage(); }
00171
00172
00173
00174 void PrintDialog::Print()
00175 {
00176 int nFormats = 4;
00177 std::string format[4] = { ".ps", ".eps", ".gif", ".jpg" };
00178 bool doPrint[4];
00179
00180 for (int i=0; i<fNprintable; ++i) {
00181 bool printMe = (fPrintableCB[i]->GetState() == kButtonDown);
00182
00183
00184 gsPrintableSelection[fPrintTag[i]] = printMe;
00185
00186
00187 if (printMe) {
00188 std::string base = fFilename[i]->GetText();
00189
00190 doPrint[0] = (fDoPS[i]->GetState() == kButtonDown);
00191 doPrint[1] = (fDoEPS[i]->GetState() == kButtonDown);
00192 doPrint[2] = (fDoGIF[i]->GetState() == kButtonDown);
00193 doPrint[3] = (fDoJPG[i]->GetState() == kButtonDown);
00194 for (int j=0; j<nFormats; ++j) {
00195
00196 std::string ftag(fPrintTag[i]); ftag += format[j];
00197 std::string f(base); f += format[j];
00198
00199
00200 gsFormatSelection[ftag] = doPrint[j];
00201
00202
00203 if (doPrint[j]) {
00204 fPrintable[i]->Print(f.c_str());
00205 }
00206
00207 }
00208 }
00209 }
00210
00211
00212 this->Cancel();
00213 }
00214