PrintDialog.cxx
Go to the documentation of this file.
1 ///
2 /// \file PrintDialog.h
3 /// \brief Pop up dialog for printing
4 ///
5 /// \author messier@indiana.edu
6 /// \version $Id: PrintDialog.cxx,v 1.2 2011-07-12 15:53:25 messier Exp $
7 ///
8 #include <map>
9 #include <string>
10 // ROOT includes
11 #include "TGWindow.h"
12 #include "TGFrame.h"
13 #include "TGLayout.h"
14 #include "TGButton.h"
15 #include "TGTextEntry.h"
16 
17 #include "nutools/EventDisplayBase/PrintDialog.h"
18 #include "nutools/EventDisplayBase/Printable.h"
19 #include "nutools/EventDisplayBase/EventHolder.h"
20 #include "nutools/EventDisplayBase/evdb.h"
21 
22 namespace evdb{
23 
24  static std::map<std::string,bool> gsPrintableSelection;
25  static std::map<std::string,bool> gsFormatSelection;
26 
27  //......................................................................
28 
30  TGTransientFrame(0,0,800,300,0),
31  fNprintable(0)
32  {
33  fL1 = new TGLayoutHints(kLHintsLeft|kLHintsTop|kLHintsExpandX, 2, 2, 2, 2);
34  fL2 = new TGLayoutHints(kLHintsLeft|kLHintsTop, 2, 2, 2, 2);
35 
36  // Add list of printable object to dialog box. Make a check box for
37  // each one:
38  //
39  // Description | Filename Format
40  // ----------------| -------------------------------------------------
41  // [*] Main window | evd.main.001234.000123456 [ ].eps [ ].ps [*].gif
42  // [*] TPC display | evd.tpc.001234.000123456 [ ].eps [ ].ps [*].gif
43  //
44  int wPrintable = 500; // Width of description field
45  int wFilename = 200; // Width of filename field
46  int wCheckBox = 100; // Width of check boxes
47  int h = 20; // Height of fields
48  int i = 0; // Counter
49  std::map<std::string,Printable*>&
50  printables = Printable::GetPrintables();
51  std::map<std::string,Printable*>::iterator itr(printables.begin());
52  std::map<std::string,Printable*>::iterator itrEnd(printables.end());
53  for (; itr!=itrEnd; ++itr) {
54  fPrintTag[i] = itr->first;
55  fPrintable[i] = itr->second;
56  fPrintFrame[i] = new TGHorizontalFrame(this,20,20);
57 
58  std::string ptag;
61  base = "evd.";
62  base += itr->second->PrintTag();
63 
64  char runevt[128];
65  sprintf(runevt,".%d.%d",
66  evdb::EventHolder::Instance()->GetEvent()->run(),
67  evdb::EventHolder::Instance()->GetEvent()->id().event());
68  base += runevt;
69 
70  // Title of the printable object
71  fPrintableCB[i] = new TGCheckButton(fPrintFrame[i], itr->first.c_str());
72  fPrintableCB[i]->Resize(wPrintable, h);
73  fPrintFrame[i]->AddFrame(fPrintableCB[i], fL1);
74  if (gsPrintableSelection[fPrintTag[i]]) {
75  fPrintableCB[i]->SetState(kButtonDown);
76  }
77 
78  // Base file name to use during print
79  fFilename[i] = new TGTextEntry(fPrintFrame[i], new TGTextBuffer(256));
80  fFilename[i]->SetToolTipText("Base file name for print");
81  fFilename[i]->SetText(base.c_str());
82  fFilename[i]->Resize(wFilename,h);
83  fPrintFrame[i]->AddFrame(fFilename[i], fL2);
84 
85  // PNG check box
86  fDoPNG[i] = new TGCheckButton(fPrintFrame[i], ".png");
87  fDoPNG[i]->Resize(wCheckBox,h);
88  fPrintFrame[i]->AddFrame(fDoPNG[i], fL2);
89  ptag = fPrintTag[i]; ptag += ".png";
90  if (gsFormatSelection[ptag]) fDoPNG[i]->SetState(kButtonDown);
91 
92  // GIF check box
93  fDoGIF[i] = new TGCheckButton(fPrintFrame[i], ".gif");
94  fDoGIF[i]->Resize(wCheckBox,h);
95  fPrintFrame[i]->AddFrame(fDoGIF[i], fL2);
96  ptag = fPrintTag[i]; ptag += ".gif";
97  if (gsFormatSelection[ptag]) fDoGIF[i]->SetState(kButtonDown);
98 
99  // PDF check box
100  fDoPDF[i] = new TGCheckButton(fPrintFrame[i], ".pdf");
101  fDoPDF[i]->Resize(wCheckBox,h);
102  fPrintFrame[i]->AddFrame(fDoPDF[i], fL2);
103  ptag = fPrintTag[i]; ptag += ".pdf";
104  if (gsFormatSelection[ptag]) fDoPDF[i]->SetState(kButtonDown);
105 
106  // EPS check box
107  fDoEPS[i] = new TGCheckButton(fPrintFrame[i], ".eps");
108  fDoEPS[i]->Resize(wCheckBox,h);
109  fPrintFrame[i]->AddFrame(fDoEPS[i], fL2);
110  ptag = fPrintTag[i]; ptag += ".eps";
111  if (gsFormatSelection[ptag]) fDoEPS[i]->SetState(kButtonDown);
112 
113  ++i;
114  }
115  fNprintable = i;
116 
117  // Build the button frame along the bottom
118  fButtonFrame = new TGHorizontalFrame(this,20,20);
119 
120  fPrintButton = new TGTextButton(fButtonFrame,"&Print",150);
121  fPrintButton->Connect("Clicked()",
122  "evdb::PrintDialog",
123  this,
124  "PrintToFile()");
125 
126  fButtonFrame->AddFrame(fPrintButton,
127  new TGLayoutHints(kLHintsLeft,4,4,4,4));
128 
129  fCancelButton = new TGTextButton(fButtonFrame,"&Cancel",150);
130  fCancelButton->Connect("Clicked()", "evdb::PrintDialog", this, "Cancel()");
131  fButtonFrame->AddFrame(fCancelButton,
132  new TGLayoutHints(kLHintsRight,4,4,4,4));
133 
134  // Layout the main frame
135  for (int i=0; i<fNprintable; ++i) this->AddFrame(fPrintFrame[i],fL1);
136  this->AddFrame(fButtonFrame);
137  this->MapSubwindows();
138  this->Resize(500, fNprintable*(h+8)+38);
139 
140  this->SetWindowName("Print Dialog");
141  this->MapWindow();
142 
143  this->Connect("CloseWindow()","evdb::PrintDialog",this,"CloseWindow()");
144  }
145 
146  //......................................................................
147 
148  void PrintDialog::CloseWindow() { delete this; }
149 
150  //......................................................................
151 
153  {
154  for (int i=0; i<fNprintable; ++i) {
155  delete fDoPNG[i];
156  delete fDoGIF[i];
157  delete fDoEPS[i];
158  delete fDoPDF[i];
159  delete fFilename[i];
160  delete fPrintableCB[i];
161  delete fPrintFrame[i];
162  }
163  delete fPrintButton;
164  delete fCancelButton;
165  delete fButtonFrame;
166  delete fL1;
167  delete fL2;
168  }
169 
170  //......................................................................
171 
172  void PrintDialog::Cancel() { this->SendCloseMessage(); }
173 
174  //......................................................................
175 
177  {
178  int nFormats = 4;
179  std::string format[4] = { ".png", ".gif", ".pdf", ".eps" };
180  bool doPrint[4];
181 
182  for (int i=0; i<fNprintable; ++i) {
183  bool printMe = (fPrintableCB[i]->GetState() == kButtonDown);
184 
185  // Remember which printables are selected for use next time
186  gsPrintableSelection[fPrintTag[i]] = printMe;
187 
188  // Handle the print
189  if (printMe) {
190  std::string base = fFilename[i]->GetText();
191 
192  doPrint[0] = (fDoPNG[i]->GetState() == kButtonDown);
193  doPrint[1] = (fDoGIF[i]->GetState() == kButtonDown);
194  doPrint[2] = (fDoPDF[i]->GetState() == kButtonDown);
195  doPrint[3] = (fDoEPS[i]->GetState() == kButtonDown);
196  for (int j=0; j<nFormats; ++j) {
197  // Printable tag (with format) and file name
198  std::string ftag(fPrintTag[i]); ftag += format[j];
199  std::string f(base); f += format[j];
200 
201  // Remember format choices for next time
202  gsFormatSelection[ftag] = doPrint[j];
203 
204  // Actually do the print
205  if (doPrint[j]) {
206  fPrintable[i]->Print(f.c_str());
207  }
208 
209  } // Loop on formats
210  } // If printable is checked
211  } // Loop on printables
212 
213  // Done printing. Cancel the window
214  this->Cancel();
215  }
216 
217 }// namespace
218 ////////////////////////////////////////////////////////////////////////
intermediate_table::iterator iterator
static std::map< std::string, bool > gsPrintableSelection
Definition: PrintDialog.cxx:24
TGCheckButton * fDoGIF[10]
Definition: PrintDialog.h:39
std::string string
Definition: nybbler.cc:12
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
Definition: qstring.cpp:11496
TGCheckButton * fDoEPS[10]
Definition: PrintDialog.h:37
TGTextEntry * fFilename[10]
Definition: PrintDialog.h:36
TGLayoutHints * fL2
Definition: PrintDialog.h:47
Manage all things related to colors for the event display.
std::string fPrintTag[10]
Definition: PrintDialog.h:50
string filename
Definition: train.py:213
TGCheckButton * fDoPDF[10]
Definition: PrintDialog.h:38
TGCheckButton * fPrintableCB[10]
Definition: PrintDialog.h:35
static std::map< std::string, evdb::Printable * > & GetPrintables()
Definition: Printable.cxx:61
TGCheckButton * fDoPNG[10]
Definition: PrintDialog.h:40
static EventHolder * Instance()
Definition: EventHolder.cxx:15
TGTextButton * fCancelButton
Definition: PrintDialog.h:44
TGLayoutHints * fL1
Definition: PrintDialog.h:46
TGCompositeFrame * fButtonFrame
Definition: PrintDialog.h:42
TGCompositeFrame * fPrintFrame[10]
Definition: PrintDialog.h:34
static std::map< std::string, bool > gsFormatSelection
Definition: PrintDialog.cxx:25
TGTextButton * fPrintButton
Definition: PrintDialog.h:43
Printable * fPrintable[10]
Definition: PrintDialog.h:51
h
training ###############################
Definition: train_cnn.py:186
unsigned int run
virtual void Print(const char *filename)=0