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