GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
condition.js
Go to the documentation of this file.
1 (function(){
2 
3  if (typeof JSROOT != "object") {
4  var e1 = new Error("condition.js requires JSROOT to be already loaded");
5  e1.source = "condition.js";
6  throw e1;
7  }
8 
9  if (typeof GO4 != "object") {
10  var e1 = new Error("condition.js requires GO4 to be already loaded");
11  e1.source = "condition.js";
12  throw e1;
13  }
14 
15  // =========================================================================================
16 
17  GO4.ConditionEditor = function(cond) {
18  JSROOT.TBasePainter.call(this, cond);
19  this.cond = cond;
20  this.changes = ["dummy", "init"];
21  this.ClearChanges();
22  }
23 
24  GO4.ConditionEditor.prototype = Object.create(JSROOT.TBasePainter.prototype);
25 
26  GO4.ConditionEditor.prototype.isPolyCond = function() {
27  return ((this.cond._typename == "TGo4PolyCond") || (this.cond._typename == "TGo4ShapedCond"));
28  }
29 
30  GO4.ConditionEditor.prototype.isEllipseCond = function() {
31  return (this.cond._typename == "TGo4ShapedCond");
32  }
33 
34  GO4.ConditionEditor.prototype.DabcCommand = function(cmd, option, callback) {
35  var pre="";
36  if (this.GetItemName())
37  pre = this.GetItemName() + "/"; // suppress / if item name is empty
38 
39  pre += "exe.json\?method=";
40  var fullcom = pre + cmd + option;
41 
42  JSROOT.NewHttpRequest(fullcom, 'text', function(res) {
43  console.log("DabcCommand completed.");
44  callback(res!=null);
45  }).send(null);
46  }
47 
48  // add identifier of changed element to list, make warning sign visible
49  GO4.ConditionEditor.prototype.MarkChanged = function(key) {
50  // first avoid duplicate keys:
51  for (var index = 0; index < this.changes.length; index++) {
52  if (this.changes[index]== key) return;
53  }
54  this.changes.push(key);
55  console.log("Mark changed :%s", key);
56  var id = "#" + this.get_main_id();
57 
58  $(id+" .buttonChangeLabel").show();// show warning sign
59  }
60 
61  // clear changed elements' ist, make warning sign invisible
62  GO4.ConditionEditor.prototype.ClearChanges = function() {
63  for (var index = 0; index < this.changes.length ; index++) {
64  var removed=this.changes.pop();
65  console.log("Clear changes removed :%s", removed);
66  }
67  var id = this.get_main_id();
68  if (id) $("#" + id + " .buttonChangeLabel").hide(); // hide warning sign
69  }
70 
71  // scan changed value list and return optionstring to be send to server
72  GO4.ConditionEditor.prototype.EvaluateChanges = function(optionstring) {
73  var id = "#" + this.get_main_id();
74  var index;
75  var len=this.changes.length;
76  for (index = 0; index < len ; index++) {
77  //var cursor=changes.pop();
78  var key=this.changes[index];
79  //console.log("Evaluate change key:%s", key);
80 
81  // here mapping of key to editor field:
82  if(key=="limits")
83  {
84  var xmin=$(id+" .cond_xmin")[0].value;
85  var xmax=$(id+" .cond_xmax")[0].value;
86  optionstring +="&xmin="+xmin+"&xmax="+xmax;
87  this.cond.fLow1 = xmin;
88  this.cond.fUp1 = xmax;
89  if (this.cond.fiDim==2) {
90  var ymin=$(id+" .cond_ymin")[0].value;
91  var ymax=$(id+" .cond_ymax")[0].value;
92  this.cond.fLow2 = xmin;
93  this.cond.fUp2 = xmax;
94  optionstring +="&ymin="+ymin+"&ymax="+ymax;
95  }
96  }
97  else if(key=="polygon")
98  {
99  var npoints=$(id+" .cut_points")[0].value;
100  optionstring +="&npolygon="+npoints;
101  // TODO: set display of polygon points
102  for(i=0; i<npoints; ++i)
103  {
104  var x = $(id + " .cut_values input").eq(2*i)[0].value;
105  var y = $(id + " .cut_values input").eq(2*i+1)[0].value;
106  optionstring +="&x"+i+"="+x+"&y"+i+"="+y;
107  }
108  }
109  else if (key=="ellinpts"){
110  var val=$(id+" .cond_ellipse_points")[0].value;
111  optionstring +="&"+key+"="+val;
112  }
113  else if (key=="ellicx"){
114  var val=$(id+" .cond_ellipse_cx")[0].value;
115  optionstring +="&"+key+"="+val;
116  }
117  else if (key=="ellicy"){
118  var val=$(id+" .cond_ellipse_cy")[0].value;
119  optionstring +="&"+key+"="+val;
120  }
121  else if (key=="ellia1"){
122  var val=$(id+" .cond_ellipse_a1")[0].value;
123  optionstring +="&"+key+"="+val;
124  }
125  else if (key=="ellia2"){
126  var val=$(id+" .cond_ellipse_a2")[0].value;
127  optionstring +="&"+key+"="+val;
128  }
129  else if (key=="ellishape"){
130  var arg=$(id+" .cond_ellipse_iscircle")[0].value;
131  optionstring +="&"+key+"="+arg;
132  }
133  else if (key=="ellith"){
134  var val=$(id+" .cond_ellipse_theta")[0].value;
135  optionstring +="&"+key+"="+val;
136  }
137  else if (key=="resultmode"){
138  var selected=$(id+" .cond_execmode")[0].value;
139  optionstring +="&"+key+"="+selected;
140  }
141  else if (key=="invertmode"){
142  var selected=$(id+" .cond_invertmode")[0].value;
143  optionstring +="&"+key+"="+selected;
144  }
145  else if (key=="visible"){
146  var checked=$(id+" .cond_visible")[0].checked;
147  var arg= (checked ? "1" : "0");
148  optionstring +="&"+key+"="+arg;
149  }
150  else if (key=="labeldraw"){
151  var checked=$(id+" .cond_label")[0].checked;
152  var arg= (checked ? "1" : "0");
153  this.cond.fbLabelDraw=arg;
154  optionstring +="&"+key+"="+arg;
155  }
156  else if (key=="limitsdraw"){
157  var checked=$(id+" .cond_limits")[0].checked;
158  var arg= (checked ? "1" : "0");
159  this.cond.fbLimitsDraw=arg;
160  optionstring +="&"+key+"="+arg;
161  }
162  else if (key=="intdraw"){
163  var checked=$(id+" .cond_integr")[0].checked;
164  var arg= (checked ? "1" : "0");
165  this.cond.fbIntDraw=arg;
166  optionstring +="&"+key+"="+arg;
167  }
168  else if (key=="xmeandraw"){
169  var checked=$(id+" .cond_xmean")[0].checked;
170  var arg= (checked ? "1" : "0");
171  this.cond.fbXMeanDraw=arg;
172  optionstring +="&"+key+"="+arg;
173  }
174  else if (key=="xrmsdraw"){
175  var checked=$(id+" .cond_xrms")[0].checked;
176  var arg= (checked ? "1" : "0");
177  this.cond.fbXRMSDraw=arg;
178  optionstring +="&"+key+"="+arg;
179  }
180  else if (key=="ymeandraw"){
181  var checked=$(id+" .cond_ymean")[0].checked;
182  var arg= (checked ? "1" : "0");
183  this.cond.fbYMeanDraw=arg;
184  optionstring +="&"+key+"="+arg;
185  }
186  else if (key=="yrmsdraw"){
187  var checked=$(id+" .cond_yrms")[0].checked;
188  var arg= (checked ? "1" : "0");
189  this.cond.fbYRMSDraw=arg;
190  optionstring +="&"+key+"="+arg;
191  }
192  else if (key=="xmaxdraw"){
193  var checked=$(id+" .cond_maxx")[0].checked;
194  var arg= (checked ? "1" : "0");
195  this.cond.fbXMaxDraw=arg;
196  optionstring +="&"+key+"="+arg;
197  }
198  else if (key=="ymaxdraw"){
199  var checked=$(id+" .cond_maxy")[0].checked;
200  var arg= (checked ? "1" : "0");
201  this.cond.fbYMaxDraw=arg;
202  optionstring +="&"+key+"="+arg;
203  }
204  else if (key=="cmaxdraw"){
205  var checked=$(id+" .cond_max")[0].checked;
206  var arg= (checked ? "1" : "0");
207  this.cond.fbCMaxDraw=arg;
208  optionstring +="&"+key+"="+arg;
209  }
210  else{
211  console.log("Warning: EvaluateChanges found unknown key:%s", key);
212  }
213 
214  }// for index
215  console.log("Resulting option string:%s", optionstring);
216  return optionstring;
217  }
218 
219  GO4.ConditionEditor.prototype.CheckResize = function() {
220  }
221 
222 
223  GO4.ConditionEditor.prototype.ChangePolygonDimension = function() {
224  // this only changes display of condition, not condition itself!
225  // note that condition is still changed in analysis only by EvaluateChanges
226  // local condition copy is unchanged until we can display it somewhere.
227 
228  if(!this.isPolyCond()) return;
229  var id = "#" + this.get_main_id();
230  var oldpoints=this.cond.fxCut.fNpoints;
231  var npoints=$(id+" .cut_points")[0].value;
232  console.log("ChangePolygonDimension with numpoints="+npoints+", oldpoints="+oldpoints);
233  //if(npoints==oldpoints) return; // no dimension change, do nothing - disabled, error if we again go back to original condition dimension
234  if (this.cond.fxCut != null) {
235 
236  $(id + " .cut_values tbody").html(""); // clear old contents
237  if (npoints > oldpoints) {
238  // insert last but one point into table:
239  // first points are unchanged:
240  for (i = 0; i < oldpoints - 1; i++) {
241  var x = this.cond.fxCut.fX[i];
242  var y = this.cond.fxCut.fY[i];
243  $(id + " .cut_values tbody")
244  .append(
245  "<tr><td><input type='text' value='"
246  + x
247  + "'/></td> <td> <input type='text' value='"
248  + y + "'/> </td></tr>");
249  console.log("i:" + i + ", X=" + x + " Y=" + y);
250  }
251  // inserted points will reproduce values of last but one point:
252  var insx = this.cond.fxCut.fX[oldpoints - 2];
253  var insy = this.cond.fxCut.fY[oldpoints - 2];
254  for (i = oldpoints - 1; i < npoints - 1; i++) {
255  $(id + " .cut_values tbody")
256  .append(
257  "<tr><td><input type='text' value='"
258  + insx
259  + "'/></td> <td> <input type='text' value='"
260  + insy + "'/> </td></tr>");
261  console.log("i:" + i + ", X=" + insx + " Y=" + insy);
262  }
263  // final point is kept as last point of old polygon, should
264  // match first point for closed tcutg:
265  var lastx = this.cond.fxCut.fX[oldpoints - 1];
266  var lasty = this.cond.fxCut.fY[oldpoints - 1];
267  $(id + " .cut_values tbody").append(
268  "<tr><td><input type='text' value='" + lastx
269  + "'/></td> <td> <input type='text' value='"
270  + lasty + "'/> </td></tr>");
271  console.log("i:" + npoints - 1 + ", X=" + lastx + " Y=" + lasty);
272 
273  }
274  else
275  {
276  // remove last but one point from table:
277  for (i = 0; i < npoints - 1; i++) {
278  var x = this.cond.fxCut.fX[i];
279  var y = this.cond.fxCut.fY[i];
280  $(id + " .cut_values tbody")
281  .append(
282  "<tr><td><input type='text' value='"
283  + x
284  + "'/></td> <td> <input type='text' value='"
285  + y + "'/> </td></tr>");
286  console.log("i:" + i + ", X=" + x + " Y=" + y);
287  }
288  // final point is kept as last point of old polygon, should
289  // match first point for closed tcutg:
290  var lastx = this.cond.fxCut.fX[oldpoints - 1];
291  var lasty = this.cond.fxCut.fY[oldpoints - 1];
292  $(id + " .cut_values tbody").append(
293  "<tr><td><input type='text' value='" + lastx
294  + "'/></td> <td> <input type='text' value='"
295  + lasty + "'/> </td></tr>");
296  console.log("i:" + npoints - 1 + ", X=" + lastx + " Y=" + lasty);
297 
298  }
299  }
300  this.MarkChanged("polygon");
301  }
302 
303  GO4.ConditionEditor.prototype.refreshEditor = function() {
304  var editor = this;
305  var id = "#" + this.get_main_id();
306  var cond = this.cond;
307 
308  $(id+" .cond_name").text(cond.fName);
309  $(id+" .cond_type").text(cond._typename);
310 
311 
312  if(cond.fbEnabled) {
313  $(id+" .cond_execmode").val(0);
314  }
315  else{
316  if(cond.fbResult)
317  $(id+" .cond_execmode").val(1);
318  else
319  $(id+" .cond_execmode").val(2);
320  }
321  $(id+" .cond_execmode").selectmenu("refresh");
322  $(id+" .cond_execmode").selectmenu("option", "width", "100%"); // workaround for selecmenu refresh problem (increases width each time!)
323  if(cond.fbTrue)
324  $(id+" .cond_invertmode").val(0);
325  else
326  $(id+" .cond_invertmode").val(1);
327 
328  $(id+" .cond_invertmode").selectmenu("refresh");
329  $(id+" .cond_invertmode").selectmenu("option", "width", "100%"); // workaround for selecmenu refresh problem (increases width each time!)
330 
331 
332  $(id+" .cond_xmin").val(cond.fLow1).change(function(){ editor.MarkChanged("limits")});
333  $(id+" .cond_xmax").val(cond.fUp1).change(function(){ editor.MarkChanged("limits")});
334  if (cond.fiDim==2) {
335  $(id+" .cond_ymin").val(cond.fLow2).change(function(){editor.MarkChanged("limits")});
336  $(id+" .cond_ymax").val(cond.fUp2).change(function(){ editor.MarkChanged("limits")});
337  } else {
338  $(id+" .cond_ymin").prop('disabled', true);
339  $(id+" .cond_ymax").prop('disabled', true);
340  }
341 
342  if(this.isPolyCond()) {
343  $(id+" .cond_tabs").tabs( "disable", 0 ); // enable/disable by tab index
344  $(id+" .cond_tabs").tabs( "enable", 1 ); // enable/disable by tab index
345  if (this.cond.fxCut != null) {
346  var numpoints=this.cond.fxCut.fNpoints;
347  console.log("refreshEditor: npoints="+numpoints);
348  $(id+" .cut_points").val(numpoints); //.change(function(){ editor.MarkChanged("polygon")});
349  $(id + " .cut_values tbody").html("");
350 
351 
352  for(i = 0; i < numpoints; i++) {
353  var x= this.cond.fxCut.fX[i];
354  var y= this.cond.fxCut.fY[i];
355  $(id + " .cut_values tbody").append("<tr><td><input type='text' value='" + x + "'/></td> <td> <input type='text' value='" + y + "'/> </td></tr>");
356  console.log("i:"+i+", X="+x+" Y="+y);
357  }
358  $(id + " .cut_values tbody").change(function(){ editor.MarkChanged("polygon")});
359 
360  }
361  if(this.isEllipseCond()) {
362  $(id+" .cond_tabs").tabs( "enable", 2 ); // enable/disable by tab index
363  var numpoints=this.cond.fiResolution;
364  $(id+" .cond_ellipse_points").val(numpoints);
365  $(id+" .cond_ellipse_cx").val(cond.fdCenterX).change(function(){ editor.MarkChanged("ellicx")});
366  $(id+" .cond_ellipse_cy").val(cond.fdCenterY).change(function(){ editor.MarkChanged("ellicy")});
367  $(id+" .cond_ellipse_a1").val(cond.fdRadius1).change(function(){ editor.MarkChanged("ellia1")});
368  $(id+" .cond_ellipse_a2").val(cond.fdRadius2).prop('disabled', cond.fbIsCircle).change(function(){ editor.MarkChanged("ellia2")});
369  $(id+" .cond_ellipse_theta").val(cond.fdTheta).prop('disabled', cond.fbIsCircle).change(function(){
370  editor.MarkChanged("ellith");
371  $(id+" .cond_ellipse_theta_slider").slider( "option", "value", $(this)[0].value % 360);
372  console.log("ellipse theta value="+$(this)[0].value);
373  });
374 
375 
376  var options = $(id+" .cond_ellipse_iscircle")[0].options;
377  for ( var i = 0; i < options.length; i++){
378  options[i].selected = (options[i].value == cond.fiShapeType);
379  }
380  $(id+" .cond_ellipse_iscircle").selectmenu('refresh', true).selectmenu("option", "width", "80%");;
381 
382 
383  $(id + " .cond_ellipse_theta_slider")
384  .slider({
385  min : 0,
386  max : 360,
387  step : 1,
388  value: cond.fdTheta,
389  disabled: cond.fbIsCircle,
390  change : function(event, ui) {
391  editor.MarkChanged("ellith");
392  $(id + " .cond_ellipse_theta").val(ui.value);
393  console.log("slider changed to" + ui.value);
394  },
395  stop : function(event, ui) {
396  editor.MarkChanged("ellith");
397  console.log("sliderstopped.");
398  }
399  })
400 
401  ;
402 
403  }
404 
405  }
406  else
407  {
408  console.log("refreshEditor: - NO POLYGON CUT");
409  $(id+" .cond_tabs").tabs( "enable", 0 );
410  $(id+" .cond_tabs").tabs( "disable", 1 ); // enable/disable by tab index
411  $(id+" .cond_tabs").tabs( "disable", 2 ); // enable/disable by tab index
412  }
413 
414 
415  $(id+" .cond_counts").text(cond.fiCounts);
416  $(id+" .cond_true").text(cond.fiTrueCounts);
417  $(id+" .cond_percent").text((cond.fiCounts > 0 ? 100. * cond.fiTrueCounts / cond.fiCounts : 0.).toFixed(2) + "%");
418 
419 
420  // todo: get keywords from condition class definition
421  // problem: static variables are not streamed by default
422 
423  $(id+" .cond_visible")
424  .prop('checked', cond.fbVisible)
425  .click(function() { cond.fbVisible = this.checked; editor.MarkChanged("visible")});
426  $(id+" .cond_limits")
427  .prop('checked', cond.fbLimitsDraw)
428  .click(function() { cond.fbLimitsDraw = this.checked; editor.MarkChanged("limitsdraw")});
429 
430  $(id+" .cond_label")
431  .prop('checked', cond.fbLabelDraw)
432  .click(function() { cond.fbLabelDraw = this.checked; editor.MarkChanged("labeldraw")});
433 
434 
435  $(id+" .cond_integr")
436  .prop('checked', cond.fbIntDraw)
437  .click(function() { cond.fbIntDraw = this.checked; editor.MarkChanged("intdraw")});
438 
439  $(id+" .cond_maxx")
440  .prop('checked', cond.fbXMaxDraw)
441  .click(function() { cond.fbXMaxDraw = this.checked; editor.MarkChanged("xmaxdraw")});
442 
443  $(id+" .cond_max")
444  .prop('checked', cond.fbCMaxDraw)
445  .click(function() { cond.fbCMaxDraw = this.checked; editor.MarkChanged("cmaxdraw")});
446 
447  $(id+" .cond_maxy")
448  .prop('checked', cond.fbYMaxDraw)
449  .click(function() { cond.fbYMaxDraw = this.checked; editor.MarkChanged("ymaxdraw")});
450 
451  $(id+" .cond_xmean")
452  .prop('checked', cond.fbXMeanDraw)
453  .click(function() { cond.fbXMeanDraw = this.checked; editor.MarkChanged("xmeandraw")});
454 
455  $(id+" .cond_xrms")
456  .prop('checked', cond.fbXRMSDraw)
457  .click(function() { cond.fbXRMSDraw = this.checked; editor.MarkChanged("xrmsdraw")});
458 
459  $(id+" .cond_ymean")
460  .prop('checked', cond.fbYMeanDraw)
461  .click(function() { cond.fbYMeanDraw = this.checked; editor.MarkChanged("ymeandraw")});
462 
463  $(id+" .cond_yrms")
464  .prop('checked', cond.fbYRMSDraw)
465  .click(function() { cond.fbYRMSDraw = this.checked; editor.MarkChanged("yrmsdraw")});
466 
467 
468  editor.ClearChanges();
469  }
470  //--------- end refreshEditor
471 
472 
474  GO4.ConditionEditor.prototype.fillEditor = function(divid) {
475  this.SetDivId(divid);
476  var id = "#" + this.get_main_id();
477  var editor = this;
478  var cond = this.cond;
479  console.log("GO4.ConditionEditor.prototype.fillEditor " + this.cond.fName);
480  // $(id).css("display","table");
481 
482  this.CheckResize();
483 
484  $(id+" .cond_tabs").tabs();
485 
486 
487  $(id + " .cond_execmode").selectmenu({
488  change : function(event, ui) {
489  editor.MarkChanged("resultmode");
490  }
491  });
492  $(id + " .cond_invertmode").selectmenu({
493  change : function(event, ui) {
494  editor.MarkChanged("invertmode");
495  }
496  });
497 
498  if(this.isEllipseCond()) {
499  $(id+" .cond_ellipse_iscircle").selectmenu({
500  change : function(event, ui) {
501  cond.fiShapeType = ui.item.value;
502  if(cond.fiShapeType == 2)
503  {
504  // circle
505  $(id+" .cond_ellipse_a2").prop('disabled', true);
506  $(id+" .cond_ellipse_theta").prop('disabled', true);
507  $(id + " .cond_ellipse_theta_slider").slider("disable");
508  $(id + "cond_ellipse_points").prop('disabled', false);
509  }
510  else if(cond.fiShapeType == 3)
511  {
512  // ellipse
513  $(id+" .cond_ellipse_a2").prop('disabled', false);
514  $(id+" .cond_ellipse_theta").prop('disabled', false);
515  $(id + " .cond_ellipse_theta_slider").slider("enable");
516  $(id + "cond_ellipse_points").prop('disabled', false);
517 
518 
519  }
520  else if(cond.fiShapeType == 4)
521  {
522  // box
523  $(id+" .cond_ellipse_a2").prop('disabled', false);
524  $(id+" .cond_ellipse_theta").prop('disabled', false);
525  $(id + " .cond_ellipse_theta_slider").slider("enable");
526  $(id + "cond_ellipse_points").prop('disabled', true);
527  }
528  else
529  {
530  // free style
531  $(id+" .cond_ellipse_a2").prop('disabled', true);
532  $(id+" .cond_ellipse_theta").prop('disabled', true);
533  $(id + " .cond_ellipse_theta_slider").slider("disable");
534  $(id + "cond_ellipse_points").prop('disabled', false);
535  }
536 
537 
538  editor.MarkChanged("ellishape");
539  }
540  })
541 
542  }
543 
544  $(id+" .buttonGetCondition")
545  .button({text: false, icons: { primary: "ui-icon-blank MyButtonStyle"}})
546  .click(function() {
547  console.log("update item = " + editor.GetItemName());
548  if (JSROOT.hpainter) JSROOT.hpainter.display(editor.GetItemName());
549  else console.log("hierarhy painter object not found!");
550  })
551  .children(":first") // select first button element, used for images
552  .css('background-image', "url(" + GO4.source_dir + "icons/right.png)");
553 
554 
555 
556  $(id+" .buttonSetCondition")
557  .button({text: false, icons: { primary: "ui-icon-blank MyButtonStyle"}})
558  .click(function() {
559  var options=""; // do not need to use name here
560  options=editor.EvaluateChanges(options); // complete option string from all changed elements
561  console.log("set - condition "+ editor.GetItemName()+ ", options="+options);
562  editor.DabcCommand("UpdateFromUrl",options,function(result) {
563  console.log(result ? "set condition done. " : "set condition FAILED.");
564  if(result) editor.ClearChanges();
565  });
566  })
567  .children(":first") // select first button element, used for images
568  .css('background-image', "url(" + GO4.source_dir + "icons/left.png)");
569 
570 
571  $(id+" .buttonChangeLabel")
572  .button({text: false, icons: { primary: "ui-icon-blank MyButtonStyle"}}).click()
573  .children(":first") // select first button element, used for images
574  .css('background-image', "url(" + GO4.source_dir + "icons/info1.png)");
575 
576  $(id+" .buttonDrawCondition")
577  .button({text: false, icons: { primary: "ui-icon-blank MyButtonStyle"}})
578  .click(function() {
579  // TODO: implement correctly after MDI is improved, need to find out active frame and location of bound histogram
580 
581  if (JSROOT.hpainter) {
582  editor.EvaluateChanges("");
583 
584  if (JSROOT.hpainter.updateOnOtherFrames(editor, editor.cond)) return;
585 
586  JSROOT.hpainter.drawOnSuitableHistogram(editor, editor.cond, editor.cond.fiDim==2);
587 
588  return;
589  }
590 
591  //if (JSROOT.hpainter){
592  //var onlineprop = JSROOT.hpainter.GetOnlineProp(editor.GetItemName());
593  //var baseurl = onlineprop.server + onlineprop.itemname + "/";
594  var baseurl = editor.GetItemName() + "/";
595  var drawurl = baseurl + "draw.htm", editorurl = baseurl + "draw.htm?opt=editor";
596  console.log("draw condition to next window with url="+drawurl);
597  //window.open(drawurl);
598  window.open(drawurl,'_blank');
599 // }
600 // else
601 // {
602 // console.log("hpainter object not found!");
603 // }
604 // problem: we do not have method to get currently selected pad...
605 // var nextid="#"+(editor.divid + 1); // does not work, id is string and not number here
606 // console.log("draw condition to id="+nextid);
607 // GO4.drawGo4Cond(nextid, editor.cond, "");
608 
609 
610  })
611  .children(":first") // select first button element, used for images
612  .css('background-image', "url(" + GO4.source_dir + "icons/chart.png)");
613 
614 
615  $(id+" .buttonClearCondition")
616  .button({text: false, icons: { primary: "ui-icon-blank MyButtonStyle"}})
617  .click(function() {
618  console.log("clearing counters...");
619  var options="&resetcounters=1";
620  editor.DabcCommand("UpdateFromUrl",options,function(result) {
621  console.log(result ? "reset condition counters done. " : "reset condition counters FAILED.");
622  if (result) {
623  if(JSROOT.hpainter) JSROOT.hpainter.display(editor.GetItemName());
624  else console.log("hpainter object not found!");
625  }
626  });
627  })
628  .children(":first") // select first button element, used for images
629  .css('background-image', "url(" + GO4.source_dir + "icons/clear.png)");
630 
631  $(id+" .cut_points").spinner({
632  min: 0,
633  max: 1000,
634  step: 1,
635  //spin: function( event, ui ) {console.log("cut spin has value:"+ui.value);},
636  change: function( event, ui ) {editor.ChangePolygonDimension();//console.log("cut changed.");
637  },
638  stop: function( event, ui ) {editor.ChangePolygonDimension();//console.log("cut spin stopped.");
639  }
640  });
641 
642  $(id+" .cond_ellipse_points").spinner({
643  min: 0,
644  max: 1000,
645  step: 1,
646  //spin: function( event, ui ) {console.log("cut spin has value:"+ui.value);},
647  change: function( event, ui ) {editor.MarkChanged("ellinpts");console.log("ellipse points changed.");
648  },
649  stop: function( event, ui ) {editor.MarkChanged("ellinpts");console.log("ellipse points stopped.");
650  }
651  });
652 
653  this.refreshEditor();
654 
655  this.DrawingReady();
656 
657  //$(document).tooltip();
658  //$(id).tooltip(); // NOTE: jquery ui tooltips will change title information, currently conflict with jsroot!
659  }
660 
661  GO4.ConditionEditor.prototype.drawEditor = function(divid) {
662  $("#"+divid)
663  .empty()
664  .load(GO4.source_dir + "html/condeditor.htm", "", this.fillEditor.bind(this, divid));
665  return this;
666  }
667 
668  GO4.ConditionEditor.prototype.RedrawPad = function(resize) {
669  this.refreshEditor();
670  }
671 
672  GO4.ConditionEditor.prototype.UpdateObject = function(obj) {
673  if (obj._typename != this.cond._typename) return false;
674 
675  this.cond= JSROOT.clone(obj); // does this also work with polygon condition?
676 
677  return true;
678  }
679 
680 
681  // ==================================================================
682 
683  GO4.ConditionPainter = function(cond) {
684  JSROOT.TObjectPainter.call(this, cond);
685  this.cond = cond;
686  this.pave = null; // drawing of stat
687  }
688 
689  GO4.ConditionPainter.prototype = Object.create(JSROOT.TObjectPainter.prototype);
690 
691  GO4.ConditionPainter.prototype.Test = function(x,y) {
692  // JAM: need to put this here, since condition object will lose internal definition after cloning it again!
693  var cond=this.cond;
694  if (!cond.fbEnabled) return cond.fbResult;
695 
696  if (cond.fxCut)
697  return cond.fxCut.IsInside(x,y) ? cond.fbTrue : cond.fbFalse;
698 
699  if ((x < cond.fLow1) || (x > cond.fUp1)) return cond.fbFalse;
700 
701  if (cond.fiDim==2)
702  if ((y < cond.fLow2) || (y > cond.fUp2)) return cond.fbFalse;
703 
704  return cond.fbTrue;
705  }
706 
707 
708  GO4.ConditionPainter.prototype.GetObject = function() {
709  return this.cond;
710  }
711 
712  GO4.ConditionPainter.prototype.isPolyCond = function() {
713  return ((this.cond._typename == "TGo4PolyCond") || (this.cond._typename == "TGo4ShapedCond"));
714  }
715 
716  GO4.ConditionPainter.prototype.isEllipseCond = function() {
717  return (this.cond._typename == "TGo4ShapedCond");
718  }
719 
720 
721  GO4.ConditionPainter.prototype.drawCondition = function() {
722 
723  if (this.isPolyCond()) {
724  if (this.cond.fxCut != null) {
725  // look here if cut is already drawn in divid:
726  var cutfound=false;
727  var cut=this.cond.fxCut;
728  this.ForEachPainter(function(p) {
729  if (p.obj_typename != "TCutG") return;
730  console.log("Find TCutG painter");
731  p.UpdateObject(cut);
732  p.Redraw();
733  cutfound=true;
734  });
735  if(cutfound) return;
736  // only redraw if previous cut display was not there:
737  this.cond.fxCut.fFillStyle = 3006;
738  this.cond.fxCut.fFillColor = 2;
739  JSROOT.draw(this.divid, this.cond.fxCut, "LF");
740  }
741  return;
742  }
743 
744  this.CreateG(true);
745 
746  var w = this.frame_width(),
747  h = this.frame_height(),
748  main = this.main_painter();
749 
750  if (!main.grx || !main.gry) main = this.frame_painter();
751 
752  if ((this.cond.fFillStyle==1001) && (this.cond.fFillColor==19)) {
753  this.cond.fFillStyle = 3006;
754  this.cond.fFillColor = 2;
755  }
756 
757  var fill = this.createAttFill(this.cond);
758  var line = this.createAttLine(this.cond);
759 
760  this.draw_g.attr("class","cond_container");
761 
762  var ndim = this.cond.fiDim;
763 
764  this.draw_g.append("svg:rect")
765  .attr("x", main.grx(this.cond.fLow1))
766  .attr("y", (ndim==1) ? 0 : main.gry(this.cond.fUp2))
767  .attr("width", main.grx(this.cond.fUp1) - main.grx(this.cond.fLow1))
768  .attr("height", (ndim==1) ? h : main.gry(this.cond.fLow2) - main.gry(this.cond.fUp2))
769  .call(line.func)
770  .call(fill.func);
771  }
772 
773  GO4.ConditionPainter.prototype.drawLabel = function() {
774  if (!this.cond.fbLabelDraw) return;
775 
776  var pave_painter = this.FindPainterFor(this.pave);
777 
778  if (pave_painter == null) {
779  this.pave = JSROOT.Create("TPaveStats");
780  this.pave.fName = "stats_" + this.cond.fName;
781  jQuery.extend(this.pave, { fX1NDC: 0.1, fY1NDC: 0.4, fX2NDC: 0.4, fY2NDC: 0.65, fBorderSize: 1, fFillColor: 0, fFillStyle: 1001 });
782  jQuery.extend(this.pave, JSROOT.gStyle.StatText);
783  jQuery.extend(this.pave, JSROOT.gStyle.StatFill);
784  } else {
785  this.pave.Clear();
786  }
787 
788  this.pave.AddText(this.cond.fName);
789 
790  this.pave.AddText("Counts = " + this.cond.fiCounts);
791 
792  if (this.cond.fbLimitsDraw)
793  if (this.isPolyCond()) {
794  var r = this.cond.fxCut.ComputeRange();
795  this.pave.AddText("Xmin = " + r.xmin);
796  this.pave.AddText("Xmax = " + r.xmax);
797  this.pave.AddText("Ymin = " + r.ymin);
798  this.pave.AddText("Ymax = " + r.ymax);
799  } else {
800  this.pave.AddText("Xmin = " + this.cond.fLow1);
801  this.pave.AddText("Xmax = " + this.cond.fUp1);
802  if (this.cond.fiDim==2) {
803  this.pave.AddText("Ymin = " + this.cond.fLow2);
804  this.pave.AddText("Ymax = " + this.cond.fUp2);
805  }
806  }
807 
808  var painter = this;
809  var cond = this.cond;
810 
811  if (!('FFormat' in JSROOT))
812  JSROOT.FFormat = function(value, fmt) {
813  if (fmt == '14.7g') return value.toFixed(1);
814  return value.toFixed(4);
815  }
816 
817  var stat = this.main_painter().CountStat(function(x,y) { return painter.Test(x,y); });
818 
819  if (this.cond.fbIntDraw) this.pave.AddText("Integral = " + JSROOT.FFormat(stat.integral, "14.7g"));
820 
821  if (this.cond.fbXMeanDraw) this.pave.AddText("Mean x = " + JSROOT.FFormat(stat.meanx, "6.4g"));
822 
823  if (this.cond.fbXRMSDraw) this.pave.AddText("RMS x = " + JSROOT.FFormat(stat.rmsx, "6.4g"));
824 
825  if (this.cond.fiDim==2) {
826  if (this.cond.fbYMeanDraw) this.pave.AddText("Mean y = " + JSROOT.FFormat(stat.meany, "6.4g"));
827  if (this.cond.fbYRMSDraw) this.pave.AddText("RMS y = " + JSROOT.FFormat(stat.rmsy, "6.4g"));
828  }
829 
830  if (this.cond.fbXMaxDraw) this.pave.AddText("X max = " + JSROOT.FFormat(stat.xmax, "6.4g"));
831 
832  if (this.cond.fiDim==2)
833  if (this.cond.fbYMaxDraw) this.pave.AddText("Y max = " + JSROOT.FFormat(stat.ymax, "6.4g"));
834  if (this.cond.fbCMaxDraw) this.pave.AddText("C max = " + JSROOT.FFormat(stat.wmax, "14.7g"));
835 
836  if (pave_painter == null)
837  pave_painter = JSROOT.draw(this.divid, this.pave, "");
838  else
839  pave_painter.Redraw();
840  }
841 
842  GO4.ConditionPainter.prototype.RedrawObject = function(obj) {
843  if (this.UpdateObject(obj))
844  this.Redraw(); // no need to redraw complete pad
845  }
846 
847  GO4.ConditionPainter.prototype.UpdateObject = function(obj) {
848  if (obj._typename != this.cond._typename) return false;
849 
850  this.cond = JSROOT.clone(obj);
851 
852  return true;
853  }
854 
855  GO4.ConditionPainter.prototype.Redraw = function() {
856  this.drawCondition();
857  this.drawLabel();
858  }
859 
860  GO4.drawGo4Cond = function(divid, cond, option) {
861 
862  if (option=='same') {
863  var condpainter = new GO4.ConditionPainter(cond);
864  condpainter.SetDivId(divid);
865  condpainter.drawCondition();
866  condpainter.drawLabel();
867  return condpainter.DrawingReady();
868  }
869 
870  if ((cond.fxHistoName=="") || (option=='editor')) {
871  // $('#'+divid).append("<br/>Histogram name not specified");
872  var h = $("#"+divid).height(), w = $("#"+divid).width();
873  if ((h<10) && (w>10)) $("#"+divid).height(w*0.4);
874  var editor = new GO4.ConditionEditor(cond);
875  return editor.drawEditor(divid);
876  }
877 
878  // $('#'+divid).append("<br/>Histogram name is " + cond.fxHistoName);
879 
880  if (JSROOT.hpainter==null) {
881  $('#'+divid).append("<br/>Error - did not found hierarchy painter");
882  return;
883  }
884 
885  var histofullpath = null;
886 
887  JSROOT.hpainter.ForEach(function(h) {
888  if ((h['_name'] == cond.fxHistoName) && (h['_kind'].indexOf("ROOT.TH")==0)) {
889  histofullpath = JSROOT.hpainter.itemFullName(h);
890  return true;
891  }
892  });
893 
894  if (histofullpath == null) {
895  $('#'+divid).append("<br/>Error - did not found histogram " + cond.fxHistoName);
896 
897  histofullpath = "../../Histograms/" + cond.fxHistoName;
898 
899  JSROOT.hpainter.Find({ name: histofullpath, force: true})['_kind'] = "ROOT.TH1I";
900 
901  console.log("Try histogram" + histofullpath);
902  }
903 
904  $('#'+divid).append("<br/>Drawing histogram " + histofullpath);
905 
906  $('#'+divid).empty();
907 
908  var condpainter = new GO4.ConditionPainter(cond);
909 
910  JSROOT.hpainter.display(histofullpath, "divid:" + divid, function(res) {
911  if (res==null) return console.log("fail to get histogram " + histofullpath);
912  condpainter.SetDivId(divid);
913  condpainter.drawCondition();
914  condpainter.drawLabel();
915  condpainter.DrawingReady();
916  });
917 
918  return condpainter;
919  }
920 
921  // JSROOT.addDrawFunc("TGo4WinCond", GO4.drawGo4Cond, ";editor");
922  // JSROOT.addDrawFunc("TGo4PolyCond", GO4.drawGo4Cond, ";editor");
923  // JSROOT.addDrawFunc("TGo4ShapedCond", GO4.drawGo4Cond, ";editor");
924 
925 
926 })(); // function
function GO4 ConditionEditor prototype isPolyCond
Definition: condition.js:26
int main(int argc, char **argv)
function GO4 ParameterEditor prototype CheckResize
Definition: pareditor.js:25