ParameterSetEdit.cxx
Go to the documentation of this file.
1 ///
2 /// \file ParameterSetEdit.cxx
3 /// \brief Popup to edit configuration data
4 ///
5 /// \version $Id: ParameterSetEdit.cxx,v 1.5 2012-09-24 15:19:47 brebel Exp $
6 /// \author messier@indiana.edu
7 ///
8 #include <iostream>
9 #include <sstream>
10 #include <string>
11 #include <vector>
12 #include <cstdlib>
13 extern "C" {
14 #include <sys/types.h>
15 #include <unistd.h>
16 }
17 #include "TROOT.h"
18 #include "TApplication.h"
19 #include "TGCanvas.h"
20 #include "TGLabel.h"
21 #include "TGWindow.h"
22 #include "TGButton.h"
23 #include "TGTextEntry.h"
24 
25 #include "nutools/EventDisplayBase/ParameterSetEdit.h"
26 #include "nutools/EventDisplayBase/NavState.h"
27 
28 namespace evdb{
29 
30  static void parse_pset_string(const std::string& pset,
31  std::vector<std::string>& names,
32  std::vector<std::string>& values)
33  {
34  // Parse out the content of the parameter set
35  size_t istart = 0;
36  size_t iend = 0;
37  while (1) {
38  iend = pset.find(' ',istart);
39 
40  std::string param = pset.substr(istart, iend-istart);
41 
42  size_t ieq = param.find(':');
43  if (ieq == param.npos) { abort(); }
44 
45  std::string nm = param.substr(0,ieq);
46  std::string value = param.substr(ieq+1,param.size());
47 
48  names. push_back(nm);
49  values.push_back(value);
50 
51  if (iend==pset.npos) break;
52  istart = iend+1;
53  }
54 
55  }
56 
57 
58  //......................................................................
59 
60  ParamFrame::ParamFrame(const TGWindow* p,
61  std::vector<std::string>& name,
62  std::vector<std::string>& value,
63  std::vector<TGTextEntry*>& fT2)
64  {
65  // Create tile view container. Used to show colormap.
66 
67  fFrame = new TGGroupFrame(p, "Parameters", kVerticalFrame);
68 
69  TGLayoutHints* fLH3 = new TGLayoutHints(kLHintsCenterX|kLHintsExpandX,
70  2,2,2,2);
71 
72  fML = new TGMatrixLayout(fFrame, 0, 2, 2);
73  fFrame->SetLayoutManager(fML);
74  int h=26;
75 
76  for (unsigned int i=0; i<name.size(); ++i) {
77  // skip if the name is module_label, module_type or service_type
78  if((name[i].compare("module_label") == 0) ||
79  (name[i].compare("module_type") == 0) ||
80  (name[i].compare("service_type") == 0)) continue;
81 
82  // Build the parameter label
83  TGTextButton*
84  b = new TGTextButton(fFrame,
85  name[i].c_str(),
86  -1,
87  TGButton::GetDefaultGC()(),
88  TGTextButton::GetDefaultFontStruct(),
89  0);
90  fFrame->AddFrame(b, fLH3);
91 
92  // Build the text edit box for the values
93  TGTextEntry* t = new TGTextEntry(fFrame, value[i].c_str());
94 
95  // Set the size of the edit box
96  t->Resize(225,18);
97  fFrame->AddFrame(t, fLH3);
98  fT2.push_back(t);
99  h += 26;
100  }
101  if (h>30*26) h = 30*26;
102 
103  fFrame->Resize(fFrame->GetWidth(), h);
104 
105  fFrame->Connect("ProcessedEvent(Event_t*)", "evdb::ParamFrame", this,
106  "HandleMouseWheel(Event_t*)");
107  fCanvas = 0;
108 
109  delete fLH3;
110  }
111 
112  //......................................................................
113 
115  {
116  if (fFrame) return fFrame->GetHeight();
117  else return 0;
118  }
119 
120  //......................................................................
121 
123  {
124  if (fFrame) return fFrame->GetWidth();
125  else return 0;
126  }
127 
128  //......................................................................
129 
131  {
132  // Handle mouse wheel to scroll.
133 
134  if (event->fType != kButtonPress && event->fType != kButtonRelease)
135  return;
136 
137  Int_t page = 0;
138  if (event->fCode == kButton4 || event->fCode == kButton5) {
139  if (!fCanvas) return;
140  if (fCanvas->GetContainer()->GetHeight())
141  page = Int_t(Float_t(fCanvas->GetViewPort()->GetHeight() *
142  fCanvas->GetViewPort()->GetHeight()) /
143  fCanvas->GetContainer()->GetHeight());
144  }
145 
146  if (event->fCode == kButton4) {
147  //scroll up
148  Int_t newpos = fCanvas->GetVsbPosition() - page;
149  if (newpos < 0) newpos = 0;
150  fCanvas->SetVsbPosition(newpos);
151  }
152  if (event->fCode == kButton5) {
153  // scroll down
154  Int_t newpos = fCanvas->GetVsbPosition() + page;
155  fCanvas->SetVsbPosition(newpos);
156  }
157  }
158 
159  //......................................................................
160 
162  const std::string& module,
163  const std::string& label,
164  const std::string& pset,
165  std::string* newpset) :
166  TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), 4, 4),
167  fResult(newpset)
168  {
169  int h = 800;
170  int w = 500;
171 
172  // Convert the parameter set to a list of names, types, and values.
174 
175  fLH1 = new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 2,2,2,2);
176  fLH2 = new TGLayoutHints(kLHintsRight|kLHintsExpandX, 2,2,2,2);
177  fLH3 = new TGLayoutHints(kLHintsCenterX|kLHintsExpandX,2,2,2,2);
178  fLH4 = new TGLayoutHints(kLHintsLeft|kLHintsExpandY, 4,4,4,4);
179 
180  // Add the heading at the top of the window
181  h = 0;
182  fF1 = new TGCompositeFrame(this, w, h, kVerticalFrame);
183  std::ostringstream lbl1;
184  lbl1 << "Module " << module << " - " << label;
185 
186  fL1 = new TGLabel(fF1, lbl1.str().c_str());
187 
188  fF1->AddFrame(fL1,fLH3);
189 
190  fL1->SetHeight(26);
191  this->AddFrame(fF1);
192  h = 30;
193 
194  // Add the parameter fields and edit boxes
195  fCanvas = new TGCanvas(this, w, h);
196  fParam = new ParamFrame(fCanvas->GetViewPort(),
197  fName,
198  fValue,
199  fT2);
201  fCanvas->SetContainer(fParam->GetFrame());
202  fParam->GetFrame()->SetCleanup(kDeepCleanup);
203 
204  for(unsigned int n = 0; n < fT2.size(); ++n){
205  // Pressing enter in a field applies the changes
206  fT2[n]->Connect("ReturnPressed()", "evdb::ParameterSetEdit", this,
207  "Apply()");
208  fT2[n]->Connect("TabPressed()", "evdb::ParameterSetEdit", this,
209  "HandleTab()");
210  }
211 
212  h = fParam->GetHeight();
213  if (h>800) h = 800;
214  fCanvas->Resize(w,h);
215 
216  this->AddFrame(fCanvas);
217 
218  // Button bar across the bottom
219  fF3 = new TGCompositeFrame(this, w, 16, kHorizontalFrame);
220  this->AddFrame(fF3);
221 
222  fB3 = new TGTextButton(fF3, " Apply ");
223  fB4 = new TGTextButton(fF3, " Cancel ");
224  fB5 = new TGTextButton(fF3, " Done ");
225  fF3->AddFrame(fB3, fLH1);
226  fF3->AddFrame(fB4, fLH1);
227  fF3->AddFrame(fB5, fLH1);
228 
229  fB3->Connect("Clicked()","evdb::ParameterSetEdit",this,"Apply()");
230  fB4->Connect("Clicked()","evdb::ParameterSetEdit",this,"Cancel()");
231  fB5->Connect("Clicked()","evdb::ParameterSetEdit",this,"Done()");
232 
233  this->Connect("CloseWindow()","evdb::ParameterSetEdit",this,"CloseWindow()");
234 
235  h += 50;
236 
237  this->Resize(w+8,h);
238  this->MapSubwindows();
239  this->MapWindow();
240 
241  if(!fT2.empty()){
242  // TRy to focus the first text field
243  fT2[0]->SetFocus();
244  fT2[0]->End();
245  }
246 
247  (*fResult) = "";
248  }
249 
250  //......................................................................
251 
253  {
254  unsigned int i;
255  const char* values;
256  std::ostringstream pset;
257 
258  for (i=0; i<fName.size(); ++i) {
259  if(i < fT2.size() ) values = fT2[i]->GetText();
260  else values = fValue[i].c_str();
261  pset << fName[i] << ":" << values << " ";
262  }
263 
264  (*fResult) = pset.str();
265 
266  return 1;
267  }
268 
269  //......................................................................
270 
272  {
273  unsigned int i;
274  delete fB5;
275  delete fB4;
276  delete fB3;
277  for (i=0; i<fT2.size(); ++i) delete fT2[i];
278  delete fL1;
279  delete fF3;
280  delete fF1;
281  delete fLH4;
282  delete fLH3;
283  delete fLH2;
284  delete fLH1;
285  }
286 
287  //......................................................................
288 
289  void ParameterSetEdit::CloseWindow() { delete this; }
290 
291  //......................................................................
292 
294  {
295  this->SendCloseMessage();
296  }
297 
298  //......................................................................
299 
301  {
302  this->Edit();
303  this->SendCloseMessage();
305  }
306 
307  //......................................................................
308 
310  {
311  this->Edit();
313  }
314 
315  //......................................................................
316 
318  {
319  // Work out which text field has focus
320  Window_t focusId = gVirtualX->GetInputFocus();
321  int focusIdx = -1;
322  for(unsigned int n = 0; n < fT2.size(); ++n){
323  if(fT2[n]->GetId() == focusId) focusIdx = n;
324  }
325  // We don't know. Bail out
326  if(focusIdx == -1) return;
327 
328  // Move focus to the next field cyclically
329  ++focusIdx;
330  focusIdx %= fT2.size();
331  fT2[focusIdx]->SetFocus();
332  fT2[focusIdx]->End();
333  }
334 
335 }// namespace
336 
337 ////////////////////////////////////////////////////////////////////////
static QCString name
Definition: declinfo.cpp:673
static void Set(int which)
Definition: NavState.cxx:24
int GetHeight() const
TGGroupFrame * GetFrame() const
std::string string
Definition: nybbler.cc:12
int compare(unsigned *r, sha1::digest_t const &d)
Definition: sha1_test_2.cc:61
std::vector< TGTextEntry * > fT2
std::vector< std::string > fName
Manage all things related to colors for the event display.
TGMatrixLayout * fML
static void parse_pset_string(const std::string &pset, std::vector< std::string > &names, std::vector< std::string > &values)
TGCompositeFrame * fF3
void SetCanvas(TGCanvas *canvas)
std::void_t< T > n
ParamFrame(const TGWindow *p, std::vector< std::string > &names, std::vector< std::string > &value, std::vector< TGTextEntry * > &fT2)
Q_UINT16 values[128]
p
Definition: test.py:223
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
TGGroupFrame * fFrame
std::vector< std::string > fValue
TGCompositeFrame * fF1
static bool * b
Definition: config.cpp:1043
ParameterSetEdit(TGMainFrame *mf, const std::string &module, const std::string &label, const std::string &params, std::string *newpset)
Helper class to setup scroll bars in evdb::ParameterSetEdit.
void HandleMouseWheel(Event_t *event)
Event finding and building.
h
training ###############################
Definition: train_cnn.py:186