Inspector.cxx
Go to the documentation of this file.
1 
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15 
16 #ifdef _MSC_VER
17 #include "msdevstudio/MSconfig.h"
18 #endif
19 
20 #include "Inspector.h"
21 
22 #include "CanvasSelectionEvent.h"
23 #include "CanvasWindow.h"
24 #include "PlotterEvent.h"
25 #include "WindowController.h"
26 #include "AxisWidget.h"
27 #include "QtFont.h"
28 
29 #include <qapplication.h>
30 
31 #if QT_VERSION < 0x040000
32 #include "qlistview.h"
33 #include "qbuttongroup.h"
34 #include "qgroupbox.h"
35 #include "qwidgetstack.h"
36 #include "qlayout.h"
37 #else
38 #include <QtCore/QCustomEvent>
39 #include <QtGui/QHBoxLayout>
40 #include <QtGui/QVBoxLayout>
41 #include "q3button.h"
42 #include "q3listview.h"
43 #include "q3buttongroup.h"
44 #include "q3groupbox.h"
45 #include "q3widgetstack.h"
46 #endif
47 
48 #include "qtooltip.h"
49 #include "qcheckbox.h"
50 #include "qcolordialog.h"
51 #include "qcombobox.h"
52 #include "qlineedit.h"
53 #include "qmessagebox.h"
54 #include "qpushbutton.h"
55 #include "qradiobutton.h"
56 #include "qslider.h"
57 #include "qlabel.h"
58 #include "qinputdialog.h"
59 #include "qfontdialog.h"
60 #include "qtabwidget.h"
61 #include "qsettings.h"
62 #include "qstringlist.h"
63 #include "qtextstream.h"
64 
65 
66 #include "colorreps/BinToColor.h"
71 
74 
76 #include "datasrcs/NTuple.h"
77 #include "datasrcs/TupleCut.h"
78 
79 #include "plotters/CutPlotter.h"
80 #include "plotters/TextPlotter.h"
81 
83 
84 #include "reps/ContourPointRep.h"
86 
87 #ifdef HAVE_ROOT
88 #include "root/RootController.h"
89 #include "boost/tokenizer.hpp"
90 #include "boost/lexical_cast.hpp"
91 #endif
92 
93 #include "pattern/string_convert.h"
94 
95 #include <algorithm>
96 #include <iostream>
97 #include <stdexcept>
98 
99 using std::cout;
100 using std::endl;
101 
102 #include <cmath>
103 #include <cassert>
104 
105 using std::map;
106 using std::runtime_error;
107 using std::string;
108 using std::vector;
109 
110 using namespace hippodraw;
111 
112 
113 void
115 stringTokenize ( std::string input, const std::string & delimiters,
116  std::vector<std::string> & tokens, bool clear )
117 {
118  if (clear) {
119  tokens.clear();
120  }
121  std::string::size_type j;
122  while ( (j = input.find_first_of(delimiters)) != std::string::npos ) {
123  if (j != 0) {
124  tokens.push_back(input.substr(0, j));
125  }
126  input = input.substr(j+1);
127  }
128  tokens.push_back(input);
129  if (tokens.back() == "") {
130  tokens.pop_back();
131  }
132 }
133 
134 
135 QString Inspector::s_registry ( "/Trolltech" );
136 
137 
139 Inspector ( QWidget * parent, const char * name, bool modal, Qt::WFlags flags )
140  : InspectorBase ( parent, name, modal, flags ),
141  m_plotter ( 0 ),
142  m_is_updating ( false ),
143  m_user_models_loaded ( false )
144 {
145  init ();
147  const vector < string > & names = controller -> getFitterNames ();
148  for ( unsigned int i = 0; i < names.size(); i++ ) {
149  QString name ( names[i].c_str() );
150  m_fitter_names -> insertItem ( name );
151  }
152 #if QT_VERSION < 0x040000
153 #else // correct code generated by uic3 with release 4.1.1
154 // for ( int i = 0; i < 3; i++ ) {
155 // o QAbstractButton * b = axis_button_group -> find ( i );
156 // axis_button_group -> remove ( b );
157 // }
158 // radioButton38 = new QRadioButton(axis_button_group);
159 // radioButton38->setObjectName(QString::fromUtf8("radioButton38"));
160 // radioButton38->setEnabled(true);
161 // radioButton38->setGeometry(QRect(10, 0, 65, 30));
162 // radioButton38->setMinimumSize(QSize(60, 0));
163 // radioButton38->setChecked(true);
164 
165 // radioButton39 = new QRadioButton(axis_button_group);
166 // radioButton39->setObjectName(QString::fromUtf8("radioButton39"));
167 // radioButton39->setEnabled(true);
168 // radioButton39->setGeometry(QRect(80, 0, 65, 30));
169 // radioButton39->setMinimumSize(QSize(65, 0));
170 // radioButton39->setChecked(false);
171 
172 // radioButton40 = new QRadioButton(axis_button_group);
173 // radioButton40->setObjectName(QString::fromUtf8("radioButton40"));
174 // radioButton40->setEnabled(true);
175 // radioButton40->setGeometry(QRect(150, 0, 65, 30));
176 // radioButton40->setMinimumSize(QSize(65, 0));
177 // radioButton40->setChecked(false);
178 
179  // add index change for Qt 4
180  connect ( m_all_ntuples, SIGNAL ( currentIndexChanged ( int ) ),
181  this, SLOT ( dataNTupleSelChanged ( int ) ) );
182 #endif
183 
184 
185  connect ( axisWidget1, SIGNAL ( lowTextReturnPressed() ),
186  this, SLOT ( setLowText() ) );
187 
188  connect ( axisWidget2, SIGNAL ( lowTextReturnPressed() ),
189  this, SLOT ( cutText_returnPressed() ) );
190 
191  connect ( axisWidget1, SIGNAL ( highTextReturnPressed() ),
192  this, SLOT ( setHighText() ) );
193 
194  connect ( axisWidget2, SIGNAL ( highTextReturnPressed() ),
195  this, SLOT ( cutText_returnPressed() ) );
196 
197  connect ( axisWidget1, SIGNAL ( lowSliderReleased() ),
198  this, SLOT ( lowRangeDrag() ) );
199 
200  connect ( axisWidget2, SIGNAL ( lowSliderReleased() ),
201  this, SLOT ( cutLowSlider_sliderReleased() ) );
202 
203  connect ( axisWidget1, SIGNAL ( lowSliderPressed() ),
204  this, SLOT ( setDragOn() ) );
205 
206  connect ( axisWidget1, SIGNAL ( highSliderPressed() ),
207  this, SLOT ( setDragOn() ) );
208 
209  connect ( axisWidget1, SIGNAL ( lowSliderValueChanged ( int ) ),
210  this, SLOT ( setLowRange ( int ) ) );
211 
212  connect ( axisWidget2, SIGNAL ( lowSliderValueChanged ( int ) ),
213  this, SLOT ( cutLowSlider_sliderMoved ( int ) ) );
214 
215  connect ( axisWidget1, SIGNAL ( highSliderReleased() ),
216  this, SLOT ( highRangeDrag() ) );
217 
218  connect ( axisWidget2, SIGNAL ( highSliderReleased() ),
219  this, SLOT ( cutHighSlider_sliderReleased() ) );
220 
221  connect ( axisWidget1, SIGNAL ( highSliderValueChanged ( int ) ),
222  this, SLOT ( setHighRange ( int ) ) );
223 
224  connect ( axisWidget2, SIGNAL ( highSliderValueChanged ( int ) ),
225  this, SLOT ( cutHighSlider_sliderMoved ( int ) ) );
226 
227  connect ( axisWidget1, SIGNAL ( zoomPanCheckBoxClicked () ),
228  this, SLOT ( axisZoomPanCheckBox_clicked () ) );
229 
230  connect ( axisWidget2, SIGNAL ( zoomPanCheckBoxClicked () ),
231  this, SLOT ( cutZoomPanCheckBox_clicked () ) );
232 
233  axisWidget2 -> setCut ( true );
234  // Default position of the sliders is center which corrosponds to
235  // a value of 50. So initialization takes place as 50.
238 
239  updatePlotTypes ();
240 
241 }
242 
245 {
247  delete controller;
248 
249 }
250 
251 void
254 {
255 
256  unsigned int n = 5;
257  m_new_labels.reserve ( n );
258  m_new_labels.push_back ( new_binding_0 );
259  m_new_labels.push_back ( new_binding_1 );
260  m_new_labels.push_back ( new_binding_2 );
261  m_new_labels.push_back ( new_binding_3 );
262  m_new_labels.push_back ( new_binding_4 );
263 
264  m_new_combos.reserve ( n );
265  m_new_combos.push_back ( new_combo_0 );
266  m_new_combos.push_back ( new_combo_1 );
267  m_new_combos.push_back ( new_combo_2 );
268  m_new_combos.push_back ( new_combo_3 );
269  m_new_combos.push_back ( new_combo_4 );
270 
271  m_sel_labels.reserve ( n );
272  m_sel_labels.push_back ( sel_binding_0 );
273  m_sel_labels.push_back ( sel_binding_1 );
274  m_sel_labels.push_back ( sel_binding_2 );
275  m_sel_labels.push_back ( sel_binding_3 );
276  m_sel_labels.push_back ( sel_binding_4 );
277 
278  m_sel_combos.reserve ( n );
279  m_sel_combos.push_back ( sel_combo_0 );
280  m_sel_combos.push_back ( sel_combo_1 );
281  m_sel_combos.push_back ( sel_combo_2 );
282  m_sel_combos.push_back ( sel_combo_3 );
283  m_sel_combos.push_back ( sel_combo_4 );
284 
285  QSize cur_size = size();
286  setFixedSize ( cur_size );
287 
288  m_min_entries = 0;
289  m_rotate_enable = true;
290  m_dragging = false;
291  m_axis = Axes::X;
292  m_layoutWidget = new QWidget( currentPlot, "m_Layout" );
293  m_layoutWidget->setGeometry( QRect ( 7, 75, 360, 0 ) );
294  m_vLayout = new QVBoxLayout( m_layoutWidget, 0, 6, "m_vLayout");
295 
296  newPlotButton->setEnabled( false );
297 
298  m_newLayoutWidget = new QWidget ( m_new_plot_box, "m_newLayout" );
299  m_newLayoutWidget->setGeometry( QRect ( 7, 75, 360, 0 ) );
301  "m_newVLayout");
302 
303  updateValueCombo ();
304 
305  m_interval_le->setDisabled ( true );
306 
307  // Add fixed sized column headers to the function params group box
308  // This we could not do using the designer.
309  m_FunctionParamsListView -> addColumn( QString( "Function" ),40 );
310  m_FunctionParamsListView -> addColumn( QString( "Params" ), 20 );
311  m_FunctionParamsListView -> addColumn( QString( "Value" ), 20 );
312  m_FunctionParamsListView -> addColumn( QString( "Error" ), 20 );
313  m_FunctionParamsListView -> addColumn( QString( "Fixed" ), 3 );
314  m_FunctionParamsListView -> setSorting ( -1 );
315 
316  // vector of QRadioButtons on transform tabbed panel. Needed for
317  // workaround of faulty code generation of Qt 4.1.1
318  m_transform_buttons.push_back ( m_linear );
319  m_transform_buttons.push_back ( m_logy );
320  m_transform_buttons.push_back ( m_logx );
321  m_transform_buttons.push_back ( m_logxy );
322  m_transform_buttons.push_back ( m_hammer );
323  m_transform_buttons.push_back ( m_lambert );
324  m_transform_buttons.push_back ( m_Car );
325  m_transform_buttons.push_back ( m_Mer );
326  m_transform_buttons.push_back ( m_Gls );
327  m_transform_buttons.push_back ( m_Arc );
328  m_transform_buttons.push_back ( m_Tan );
329  m_transform_buttons.push_back ( m_Sin );
330  m_transform_buttons.push_back ( m_Stg );
331  m_transform_buttons.push_back ( m_Air );
332 }
333 
334 void
337 {
339  const vector < string > & names = controller -> getValueTransformTypes ();
340  m_value_combo -> clear ();
341  unsigned int size = names.size ();
342  for ( unsigned int i = 0; i < size; i++ ) {
343  m_value_combo -> insertItem ( names[i].c_str() );
344  }
345 }
346 
347 void
349 enableNewPlotBox ( bool yes )
350 {
351  m_new_plot_box->setEnabled ( yes );
352  m_summary->setEnabled ( yes );
353 }
354 
355 #if QT_VERSION < 0x040000
357 #else
358 void Inspector::customEvent ( QEvent * event )
359 #endif
360 {
361  PlotterEvent * pev = dynamic_cast < PlotterEvent * > ( event );
362  if ( pev != 0 ) {
363  m_plotter = pev -> plotter ();
364  update ();
365  }
366 
368  = dynamic_cast < CanvasSelectionEvent * > ( event );
369  if ( ev != 0 ) {
370  m_plotter_list = ev -> getPlotters ();
371  if ( m_plotter_list.size () == 1 ) {
372  m_plotter = m_plotter_list.front ();
373  }
374  else {
375  m_plotter = 0;
376  }
377  update ();
378  }
379 }
380 
381 PlotterBase *
384 {
385  return m_plotter;
386 }
387 
388 void
390 setZRadioButton ( bool enabled )
391 {
392  if (!enabled && m_axis == Axes::Z )
393  {
394 #if QT_VERSION < 0x040000
395  QButton * b = axis_button_group -> find ( 0 );
396 #else
397  QAbstractButton * b = axis_button_group -> find ( 2 );
398 #endif
399  QRadioButton * button = dynamic_cast< QRadioButton * > ( b );
400  button -> setChecked ( true );
401  m_axis = Axes::X;
402  updateAxisTab ();
403  }
404 
405 #if QT_VERSION < 0x040000
406  QButton * button = axis_button_group -> find ( 2 );
407 #else
408  QAbstractButton * button = axis_button_group -> find ( 2 );
409 #endif
410 
411  button -> setEnabled ( enabled );
412 }
413 
414 void
417 {
418  update ();
419 }
420 
421 void
424 {
425  if ( isHidden() == true ) return;
426  m_is_updating = true;
427  int index = m_plot_tab -> currentPageIndex ();
428 
429  switch ( index )
430  {
431  case ( 0 ) :
432  updateDataTab();
433  break;
434  case ( 1 ) :
435  updatePlotTab();
436  break;
437  case ( 2 ) :
438  updateAxisTab();
439  break;
440  case ( 3 ) :
441  updateCutsTab();
442  break;
443  case ( 4 ) :
445  break;
446  case ( 5 ) :
447  updateSummaryTab ();
448  break;
449  case ( 6 ) :
451  break;
452  default :
453  assert ( false );
454  break;
455  }
456 
457 // if ( m_plotter != 0 ) {
458 // bool hasZ = m_plotter -> hasAxis ( Axes::Z );
459 // setZRadioButton ( hasZ );
460 
461 // }
462 
463  m_is_updating = false;
464  updateCutsActive ();
465 
466 }
467 
468 void
471 {
472  PlotterBase * plotter = getPlotter ();
473  if ( plotter == 0 ) {
474  setAllCutsActive ( true );
475  }
476  else {
477  vector < PlotterBase * > cutlist;
478  CutController * controller = CutController::instance ();
479  controller -> fillCutList ( plotter, cutlist );
480 
481  if ( cutlist.empty () ) {
482  setAllCutsActive ( false );
483  return;
484  }
485  else {
486  setAllCutsActive ( false );
487  vector < PlotterBase * >::iterator first = cutlist.begin();
488  while ( first != cutlist.end () ) {
489  PlotterBase * pb = *first++;
490  CutPlotter * cutter = dynamic_cast < CutPlotter * > ( pb );
491  assert ( cutter );
492  cutter -> setActive ( true );
493  }
494  }
495  }
496 }
497 
498 std::string
501 {
502  string s;
503  const vector < string > & names
504  = DataSourceController::instance () -> getNTupleNames ();
505  int index = m_all_ntuples -> count () == 0 ? -1 : m_all_ntuples -> currentItem ();
506  if ( index >= 0 &&
507  names.empty () == false ) {
508  s = names [ index ];
509  }
510 
511  return s;
512 }
513 
514 void
517 {
518  const vector < string > & nt_vector
519  = DataSourceController::instance() -> getNTupleNames ();
520 
521 
522  if ( nt_vector.empty () ) {
523 
524  m_all_ntuples -> clear ();
525  return;
526  }
527 
528  unsigned int count = m_all_ntuples -> count ();
529  if ( count == nt_vector.size () ) return;
530 
531 #ifdef ITERATOR_MEMBER_DEFECT
532  //std::
533 #endif
534 
535  m_all_ntuples -> clear();
536  vector < string > ::const_iterator first = nt_vector.begin();
537  while ( first != nt_vector.end() ) {
538  const string & name = *first++;
539  m_all_ntuples->insertItem ( name.c_str() );
540  }
541 
542  if ( m_all_ntuples -> count () != 0 ) {
543  const string & name = nt_vector.back ();
544 
545  setNewPlotNTuple ( name );
546 
547 
548  availPlotTypesActivated ( name.c_str() );
549 
550  }
551  else {
552  availPlotTypesActivated ( QString::null );
553 
554  }
555 }
556 
557 void
559 setNewPlotNTuple ( const std::string & name )
560 {
561  const vector < string > & nt_vector
562  = DataSourceController::instance() -> getNTupleNames ();
563 
564  for ( unsigned int i = 0; i < nt_vector.size(); i++ ) {
565  if ( nt_vector[i] == name ) {
566  unsigned int current = m_all_ntuples -> currentItem ();
567  if ( current != i ) {
568  m_all_ntuples -> setCurrentItem ( i );
569  }
570  break;
571  }
572  }
573 
574  // Update tip tool.
576  const QString tip=getSelectedDataSourceName().c_str();
578 
579 }
580 
581 void
584 {
585  m_last_ntuple_edited = m_all_ntuples -> currentItem ();
586 
587 }
588 
589 void
591 changeNTupleName ( const QString & text )
592 {
594  vector < DataSource * > nt_vector;
595  controller -> getDataSources ( nt_vector ); // get all
596  DataSource * ds = nt_vector [ m_last_ntuple_edited ];
597  if ( ds == 0 ) return;
598 
599  const string new_name = text.latin1();
600 
601  ds -> setName ( new_name );
602 }
603 
604 void
607 {
609  controller -> setCurrentIndex ( item );
610 
611  m_all_ntuples -> setCurrentItem ( item );
612  QString text ( "" );
613 
614  availPlotTypesActivated ( text );
615 
616  // Update tip tool.
618  const QString tip=getSelectedDataSourceName().c_str();
620 
621 }
622 
623 void
626 {
627  // Change the number and type of axes depending on what is selected
628  // inside m_availPlotTypes. Then insert the axis labels based on the
629  // selection of nTupleNameComboBox.
630 
631  changeNTupleName ( text );
632  m_all_ntuples -> setCurrentItem ( m_last_ntuple_edited );
633  m_all_ntuples -> changeItem ( text, m_last_ntuple_edited );
634 
636  int index = m_all_ntuples -> currentItem ();
637  controller -> setCurrentIndex( index );
638 
639  availPlotTypesActivated ( text );
640 }
641 
642 void
645 {
646  axisLabelChanged ( 0, label );
647 }
648 
649 void
652 {
653  axisLabelChanged ( 1, label );
654 }
655 
656 void
659 {
660  axisLabelChanged ( 2, label );
661 }
662 
663 void
666 {
667  axisLabelChanged ( 3, label );
668 }
669 
670 void
672 axisLabelChanged ( int index, const QString & label )
673 {
674  if ( m_plotter_list.size () > 1 ) {
676  return;
677  }
678 
679  PlotterBase * plotter = getPlotter ();
680  if ( !plotter ) return ;
681 
682  QString axisName = m_sel_labels [index] -> text();
683  const std::string strAxisName ( axisName.latin1() );
684  const std::string strLabel( label.latin1() );
685 
687  controller -> setAxisBinding ( plotter, strAxisName, strLabel );
688 
689  bool valid = controller -> isDataValid ( plotter );
690  if ( valid == false ) {
692  }
693 }
694 
695 void
698 {
699  const vector < string > & dataRepNames
700  = DisplayController::instance() -> getDisplayTypes ();
701  if ( dataRepNames.empty () ) return;
702  unsigned int size = m_availPlotTypes -> count ();
703 
704  if ( dataRepNames.size() != size ) {
706 
707  vector < string > ::const_iterator first = dataRepNames.begin ();
708  while ( first != dataRepNames.end() ) {
709  const string & name = *first++;
710  if ( name.find ( "Static" ) != string::npos ) continue;
711  m_availPlotTypes->insertItem ( name.c_str() );
712  }
713  m_availPlotTypes->setCurrentItem ( 2 ); //Histogram
714  }
715 
716  newPlotButton->setEnabled( true );
717 }
718 
719 void
721 clear ( std::vector < QLabel * > & labels,
722  std::vector < QComboBox * > & combos )
723 {
724  unsigned int size = combos.size ();
725  for ( unsigned int i = 0; i < size; i++ ) {
726  QComboBox * box = combos [ i ];
727  box -> clear ();
728  box -> setEnabled ( false );
729  QLabel * label = labels [ i ];
730  label -> setEnabled ( false );
731  }
732 }
733 
734 void
737 {
738  int index = m_all_ntuples -> count () == 0 ? -1 : m_all_ntuples -> currentItem ();
739  vector < DataSource * > nt_vector;
740  DataSourceController::instance() -> getDataSources ( nt_vector );
741 
742 
743  int size = static_cast < int > ( nt_vector.size() );
744  if ( size == 0 ) {
746  return;
747  }
748 
749 
750  if ( ! (index < size ) ) {
751  index = 0;
752  }
753  std::string plotTypeStr( (m_availPlotTypes->currentText()).latin1() );
754 
756 
757  const vector < string > & bindingOptions
758  = controller -> bindingOptions ( plotTypeStr );
759 
760  if ( bindingOptions.empty () ) return;
761 
762  //Layout the stuff.
763 
765 
766  vector < int > indices;
767  unsigned int s = m_new_combos.size ();
768  for ( unsigned int i = 0; i < s; i++ ) {
769  indices.push_back ( m_new_combos[i] -> currentItem () );
770  }
772  QString qs1;
773 
774  if ( index >= 0 ) {
775  DataSource * nt = nt_vector[index];
776  const vector < string > & cols = nt->getLabels();
777 
778  for ( unsigned int i = 0; i < m_new_combos.size (); i++ ) {
779  if ( i < bindingOptions.size () ) {
780  const string & axisName = bindingOptions[i];
781 
782  qs1 = ( axisName.c_str() );
783  m_new_labels [i] -> setEnabled ( true );
784  m_new_labels [i] -> setText ( qs1 );
785  m_new_combos [i] -> setEnabled ( true );
786  for (std::vector<string>::size_type j = 0; j < cols.size(); j++){
787  m_new_combos [i] -> insertItem ( cols [j].c_str() );
788  }
789 
790  if ( axisName.find ( "optional" ) != string::npos ) {
791  m_new_combos [i] -> insertItem ( "nil" );
792  m_new_combos [i] -> setCurrentText ( "nil" );
793  indices[i] = -1;
794  }
795  }
796  }
797  }
798 
799 
800  for ( unsigned int i = 0; i < m_new_combos.size(); i++ ) {
801 
802 
803  if ( indices[i] >= 0 &&
804  indices[i] < m_new_combos[i] -> count () ) {
805  m_new_combos[i] ->setCurrentItem ( indices[i] );
806  }
807  }
808 
809 }
810 
811 void
814 {
815 
816 
818 
819 
821 
822 
823  PlotterBase * plotter = getPlotter ();
824  updateSelectedPlotType ( plotter );
825 
826 
827 
828  if ( plotter != 0 ) {
829 
830  currentPlot->setEnabled ( true );
831  bool yes = plotter -> isTargetable ();
832  if ( yes == false ) return;
833  }
834  else {
835 
836  if ( m_plotter_list.empty () == true ) {
837 
838  currentPlot -> setDisabled ( true );
839  }
840  else {
841 
842  currentPlot -> setDisabled ( false );
843  }
844 
845  return;
846  }
847 
848 
849 
850  updateSelectedPlotData ( plotter );
851 
852 
853 
854 
855 }
856 
857 void
859 updateSelectedPlotDataSource ( const std::string & name )
860 {
861  const vector < string > & nt_vector
862  = DataSourceController::instance () -> getNTupleNames ();
863 
864  unsigned int size = nt_vector.size ();
865  unsigned int count = m_sel_ntuple_name -> count ();
866  bool refresh = count != size;
867  if ( refresh ) m_sel_ntuple_name -> clear ();
868  int jndex = -1;
869  for ( std::size_t i = 0; i < size; i++ ) {
870  const string & ntname = nt_vector[i];
871  if ( ntname == name ) jndex = i;
872  if ( refresh ) m_sel_ntuple_name -> insertItem ( ntname.c_str () );
873  }
874 
875  if ( jndex < 0 ) { // not bound to ntuple
876  m_sel_ntuple_name -> setEnabled ( false );
877  }
878  else {
879  m_sel_ntuple_name -> setEnabled ( true );
880  m_sel_ntuple_name -> setCurrentItem ( jndex );
881  }
882  // Update tip tool.
884  const QString tip = m_sel_ntuple_name -> currentText ();
886 
887 
888 }
889 
890 void
893 {
894  bool yes = plotter != 0;
895  if ( yes ) {
896  yes = plotter -> isTargetable ();
897  if ( yes ) {
898  DataRep * datarep = plotter -> getTarget ();
899  yes = datarep != 0;
900  if ( yes ) {
901  int index = plotter -> indexOf ( datarep );
903  const string & dataRepName
904  = controller -> getType ( plotter, index );
905  QString qst2 ( dataRepName.c_str() );
906  m_dataRepNameText->setText ( qst2 );
907  }
908  }
909  }
910 
911  m_dataRepNameText -> setEnabled ( yes );
912 }
913 
914 void
917 {
918  QLayoutIterator it = m_vLayout->iterator();
919  while ( it.current() != 0 )
920  {
921  QLayoutItem * ptr = it.current();
922  QHBoxLayout * hbox = static_cast <QHBoxLayout *> (ptr);
923 
924  QLayoutIterator hit = hbox->iterator();
925  while ( hit.current() != 0 )
926  {
927  QLayoutItem * hptr = hit.current();
928  QWidget * hwidget = hptr->widget();
929  hit.deleteCurrent();
930  if ( hwidget ) delete ( hwidget );
931  }
932 
933  it.deleteCurrent();
934 
935  }
936 }
937 
938 void
941 {
943  DataRep * datarep = plotter -> getTarget ();
944  int index = plotter -> indexOf ( datarep );
945  assert ( datarep != 0 );
946 
947  bool ntuple_bindings = datarep -> hasNTupleBindings ( );
948  string name;
949 
950  if ( ntuple_bindings ) {
951  name = controller -> getDataSourceName ( plotter, index );
952  setNewPlotNTuple ( name );
953  }
954  else {
955  name = "<none>";
956  }
958 
959  //Layout the stuff.
960 
961  m_layoutWidget->hide();
962 
963  const vector < string > & bindings
964  = controller -> axisBindings ( plotter, index );
965  const vector < string > & bindingOptions
966  = controller -> bindingOptions ( plotter, index );
967  unsigned int listSize;
968 
969  if ( bindings.size() < bindingOptions.size() )
970  {
971  listSize = bindings.size();
972  }
973  else
974  {
975  listSize = bindingOptions.size();
976  }
977 
978  bool yes = plotter -> isTargetable ();
979  if ( ntuple_bindings == false ||
980  yes == false ) return;
981 
982  // Now add the new hlayouts.
983 
984  QString qs1, qs2;
985 
986  const vector < string > & cols
987  = controller -> getDataSourceLabels ( plotter, index );
988 
989  if ( cols.empty () ) return;
990 
992 
993  for ( unsigned int i = 0; i < m_sel_combos.size (); i++ )
994  {
995  if ( i == listSize ) break;
996  const string & axisLabel = bindings[i];
997  const string & axisName = bindingOptions[i];
998 
999  qs1 = ( axisName.c_str() );
1000  m_sel_labels [i] -> setEnabled ( true );
1001  m_sel_labels [i] -> setText ( qs1 );
1002 
1003  qs2 = ( axisLabel.c_str() );
1004 
1005  // Insert all column labels from the vector cols, and make qs2
1006  // the current text.
1007 
1008  m_sel_combos [i] -> setEnabled ( true );
1009  for (std::vector<string>::size_type j = 0; j < cols.size(); j++ )
1010  {
1011  m_sel_combos [i] -> insertItem ( cols [j].c_str() );
1012  }
1013  if ( axisName.find ( "optional" ) != string::npos )
1014  {
1015  m_sel_combos [i] -> insertItem ( "nil" );
1016  }
1017  m_sel_combos [i] -> setCurrentText ( qs2 );
1018  }
1019 }
1020 
1021 void
1024 {
1025  const QString message =
1026  "One or more columns of the bound data source\n"
1027  "contains invalid data.";
1028  QMessageBox::warning ( this, // parent
1029  "Invalid data", // caption
1030  message,
1031  QMessageBox::Ok,
1032  Qt::NoButton,
1033  Qt::NoButton );
1034 }
1035 
1036 void
1039 {
1040  const QString message =
1041  "No n-tuple selected error\n"
1042  "Need to load n-tuple to create a plot";
1043  QMessageBox::critical ( this, // parent
1044  "No n-tuple selected error", // cpation
1045  message,
1046  QMessageBox::Ok,
1047  Qt::NoButton,
1048  Qt::NoButton );
1049 }
1050 
1051 void
1053 incompatibleDataRepError ( const std::string & type )
1054 {
1055  QString message ("Plot of type " );
1056  message += type.c_str();
1057  message += " can not be added\n"
1058  "to selected plot\n\n"
1059  "It might be incompatible. For example, \n"
1060  "requiring a Z axis display while selected\n"
1061  "does not have one.";
1062  QMessageBox::critical ( this, // parent
1063  "Add to plot error", // caption
1064  message,
1065  QMessageBox::Ok,
1066  Qt::NoButton,
1067  Qt::NoButton );
1068 }
1069 void
1071 incompatibleFitterError ( const std::string & type )
1072 {
1073  QString message ( "Fitter of type " );
1074  message += type.c_str();
1075  message += " can not be used\n"
1076  "with selected plot\n\n"
1077  "It might be incompatible. For example, \n"
1078  "Maximum Likelihood fitting requires binned\n"
1079  "data representation.";
1080  QMessageBox::critical ( this, // parent
1081  "Set fitter error", // caption
1082  message,
1083  QMessageBox::Ok,
1084  Qt::NoButton,
1085  Qt::NoButton );
1086 }
1087 
1088 void
1090 badFunctionError ( const std::string & name, const char * what )
1091 {
1092  QString message = "Function`";
1093  message += name.c_str();
1094  message += "' could not be used because ...\n";
1095  message += what;
1096  message +="\nMaybe the copy constructor or clone function is bad.";
1097 
1098  QMessageBox::critical ( this, // parent
1099  "Function error", // caption
1100  message,
1101  QMessageBox::Ok,
1102  Qt::NoButton,
1103  Qt::NoButton );
1104 }
1105 
1106 void
1108 incompatibleFunctionError ( const std::string & type )
1109 {
1110  QString message ( "Funtion of type " );
1111  message += type.c_str();
1112  message += " can not be used\n"
1113  "with selected fitter\n\n"
1114  "It might be incompatible. For example, \n"
1115  "the fitter requires derivatives\n"
1116  "that the function can not supply.";
1117  QMessageBox::critical ( this, // parent
1118  "Set fitter error", // caption
1119  message,
1120  QMessageBox::Ok,
1121  Qt::NoButton,
1122  Qt::NoButton );
1123 }
1124 
1125 void
1127 invalidRangeError ( const std::string & bad )
1128 {
1129  QString message ( "Attempt to apply invalid range:\n\n" );
1130  message += bad.c_str();
1131  message += "\n\n Low end of range must be less than high end.";
1132 
1133  QMessageBox::critical ( this, // parent
1134  "Range error", // caption
1135  message,
1136  QMessageBox::Ok,
1137  Qt::NoButton,
1138  Qt::NoButton );
1139 }
1140 
1141 void
1143 multipleDataRepError ( const std::string & type )
1144 {
1145  QString message ( "Multiple data representations are active.\n"
1146  "Can not apply a " );
1147  message += type.c_str();
1148 #ifdef Q_OS_MACX
1149  message += ".\n\n"
1150  "Use Command-click to select only one data representation.";
1151 #else
1152  message += ".\n\n"
1153  "Use Control-click to select only one data representation.";
1154 #endif
1155  QMessageBox::information ( this, // parent
1156  "Multiple data representation error", // caption
1157  message,
1158  QMessageBox::Ok,
1159  Qt::NoButton,
1160  Qt::NoButton );
1161 }
1162 
1163 bool
1165 multipleDataRepInfo ( const std::string & type )
1166 {
1167  bool ok = false;
1168  QString message ( "Multiple data representations are active.\n"
1169  "Apply " );
1170  message += type.c_str();
1171  message += " to each?\n\n";
1172 
1173 #ifdef Q_OS_MACX
1174  message += "One can use Control-click to apply a ";
1175 #else
1176  message += "One can use Command-click to apply a ";
1177 #endif
1178  message += type.c_str();
1179  message +=" to a selected data representation.";
1180 
1181  int result = QMessageBox::
1182  information ( this, // parent
1183  "Multiple data representation error", // caption
1184  message,
1185  QMessageBox::Yes,
1186  QMessageBox::No,
1187  QMessageBox::NoButton );
1188 
1189  ok = result == QMessageBox::Ok;
1190 
1191  return ok;
1192 }
1193 
1194 void
1197 {
1198  const QString message ( "Attempt to add cut to itself\n"
1199  "The request was ignorned" );
1200  QMessageBox::information ( this, // parent
1201  "Applying cut error", // caption
1202  message,
1203  QMessageBox::Ok,
1204  Qt::NoButton,
1205  Qt::NoButton );
1206 }
1207 
1208 void
1211 {
1212  const QString message (
1213  "Multiple plots are selected.\n"
1214  "Can not apply change until only one is selected\n\n"
1215  "Use shift-click to deselect a selected plot" );
1216  QMessageBox::information ( this, // parent
1217  "Multiple plot error", // caption
1218  message, // .c_str(),
1219  QMessageBox::Ok,
1220  Qt::NoButton,
1221  Qt::NoButton );
1222 }
1223 
1225 {
1226  const QString message =
1227  "Functions are not supported on the selected data reaxisWitation.";
1228 
1229  QMessageBox::critical ( this, "Function Add Error",
1230  message,
1231  QMessageBox::Ok,
1232  Qt::NoButton,
1233  Qt::NoButton );
1234 }
1235 
1239 void
1241 newPlotError ( const std::exception & e )
1242 {
1243  QString message ( "New plot could not be created because:\n" );
1244  message += e.what ();
1245  QMessageBox::critical ( this, // parent
1246  "New plot error", // caption
1247  message,
1248  QMessageBox::Ok,
1249  Qt::NoButton,
1250  Qt::NoButton );
1251 }
1252 
1253 std::string
1255 getArrayTupleLabel( const DataSource * rtuple, const std::string & column )
1256 {
1257 #ifdef HAVE_ROOT
1258  RootController * controller = RootController::instance ();
1259  vector < int > dimSize;
1260  controller -> fillDimSize ( dimSize, rtuple, column );
1261 
1262  // Set the caption
1263  QString caption( "MultiDimensional data in rows of the column ");
1264  caption.append( QString( column.c_str() ) );
1265 
1266  // Set the label
1267  std::ostringstream ost;
1268  ost << " Rows of this column are of size ";
1269 
1270  unsigned int i;
1271  for( i = 0; i < dimSize.size() - 1; i++ )
1272  ost << dimSize[i] << " x ";
1273  ost << dimSize[i];
1274 
1275  ost << "\n Enter C-style index of a single element of this";
1276  ost << "\n multidimentional data which you wish to analyse.";
1277  ost << "\n Index should be a comma separated list of ";
1278  ost << dimSize.size() << " integers.";
1279 
1280  ost << "\n For e.g. ";
1281  for( i = 0; i < dimSize.size() - 1; i++ )
1282  ost << "0, ";
1283  ost << "0 \n";
1284 
1285  string label( ost.str() );
1286 
1287  bool ok;
1288  QString text = QInputDialog::getText( caption, QString( label.c_str() ),
1290  QString::null, &ok, this );
1291 
1292  // Also create the array tuple label
1293  std::ostringstream labelstream;
1294  labelstream << column;
1295 
1296  if ( ok && !text.isEmpty() )
1297  {
1298  vector< unsigned int > index;
1299  string s( text.ascii() );
1300 
1301  // User entered something and pressed OK
1302  // Creating the list of dropped delimiters.
1303  boost::char_separator< char > sep( "," );
1304 
1305  // A tokenizer with above dropped delimiters.
1306  typedef boost::tokenizer< boost::char_separator< char > > tokenizer;
1307  tokenizer tok( s, sep );
1308 
1309  // Start extracting the dimension sizes.
1310  for( tokenizer::iterator tok_iter = tok.begin();
1311  tok_iter != tok.end();
1312  ++tok_iter )
1313  {
1314  unsigned int idx = boost::lexical_cast< unsigned int >( *tok_iter );
1315  index.push_back( idx );
1316  labelstream << "[" << idx << "]";
1317  }
1318  }
1319 
1320  return labelstream.str();
1321 #else
1322  return string(); // will not be used.
1323 #endif
1324 }
1325 
1326 void
1329 {
1330  vector < DataSource * > nt_vector;
1331  DataSourceController::instance() -> getDataSources ( nt_vector );
1332 
1333  if ( nt_vector.empty() )
1334  {
1336  return;
1337  }
1338 
1339  // See all comboboxes and create a new plotter.
1340  int current = m_all_ntuples->currentItem ();
1341  DataSource * ds = nt_vector[current];
1342 
1343  // Find the datarep.
1344  std::string plotTypeStr( (m_availPlotTypes -> currentText()).latin1() );
1345 
1346  // Find the axis bindings.
1347  vector < string > bindings;
1348  for ( unsigned int i = 0; i < m_new_combos.size(); i++ )
1349  {
1350  if ( m_new_combos [i] -> count () == 0 ) break;
1351 
1352  QString qstring = m_new_combos [ i ] -> currentText();
1353  string column ( qstring.latin1() );
1354  string label = column;
1355 
1356 #ifdef HAVE_ROOT
1357  if( column != "nil" && ds -> isMultiDimensional( column ) ) {
1358  bool yes = ds -> isUseable ( column );
1359  if ( yes == false ) {
1360  const QString
1361  message ( "This column is not useable because it contains\n"
1362  "a multidimension array that varies is size or is\n"
1363  "an unsupported data type." );
1364  QMessageBox::critical ( this, // parent
1365  "DataSource error",
1366  message,
1367  QMessageBox::Ok,
1368  QMessageBox::NoButton,
1369  QMessageBox::NoButton );
1370  return;
1371  }
1372 
1373  label = getArrayTupleLabel ( ds, column );
1374  RootController * rcontroller = RootController::instance();
1375  rcontroller -> smartExpandRootNTuple ( ds, column );
1376  }
1377 #endif
1378  bindings.push_back ( label );
1379  }
1380 
1381  // Create the plotter.
1382  try {
1384  PlotterBase * newDisplay =
1385  controller -> createDisplay ( plotTypeStr, * ds, bindings );
1386  CanvasWindow * canvas = WindowController::instance() -> currentCanvas();
1387  canvas->addPlotDisplay ( newDisplay, true );
1388 
1389  bool valid = controller -> isDataValid ( newDisplay );
1390  if ( valid == false ) {
1391  invalidDataWarning ();
1392  }
1393  }
1394 // catch ( const DataSourceException & e ) {
1395  catch ( const std::exception & e ) {
1396  newPlotError ( e );
1397  }
1398 }
1399 
1400 
1401 void
1404 {
1405  // Find the display.
1406 
1407  PlotterBase * plotter = getPlotter ();
1408  if ( !plotter ) return;
1409 
1410  // Find the datarep.
1411  std::string plotTypeStr( (m_availPlotTypes->currentText()).latin1() );
1412 
1413  vector < DataSource * > nt_vector;
1414  DataSourceController::instance() -> getDataSources ( nt_vector );
1415 
1416  int current = m_all_ntuples->currentItem ();
1417  DataSource * ds = nt_vector[current];
1418 
1419  // Find the axis bindings.
1420 
1421  vector < string > bindings;
1422  for ( unsigned int i = 0; i < m_new_combos.size(); i++ )
1423  {
1424  if ( m_new_combos [i] -> count () == 0 ) break;
1425 
1426  QString qstring = m_new_combos [ i ] -> currentText();
1427  string column ( qstring.latin1() );
1428  string label = column;
1429 #ifdef HAVE_ROOT
1430  if ( column != "nil" && ds -> isMultiDimensional ( column ) ) {
1431  label = getArrayTupleLabel ( ds, column );
1432  RootController * rcontroller = RootController::instance ();
1433  rcontroller -> smartExpandRootNTuple ( ds, column );
1434  }
1435 #endif
1436  bindings.push_back ( label );
1437  }
1438 
1439  // Add the data rep.
1440 
1442  DataRep * rep = controller -> addDataRep ( plotter, plotTypeStr, ds,
1443  bindings );
1444 
1445  // If incompatible, do nothing.
1446  if ( rep == 0 )
1447  {
1448  incompatibleDataRepError ( plotTypeStr );
1449  return;
1450  }
1451 
1452  rep->set(Color::getColor());
1453 
1454  plotter -> autoScale ();
1455  bool valid = controller -> isDataValid ( rep );
1456  if ( valid == false ) {
1457  invalidDataWarning ();
1458  }
1459 
1460  update ();
1461 }
1462 
1463 void
1466 {
1467  PlotterBase * plotter = getPlotter ();
1468  if ( !plotter ) return;
1469 
1470  int num_active = plotter->activePlotIndex();
1471  int num_rep = plotter -> getNumDataReps();
1472 
1473  // If more than one active datarep or only one datarep
1474  // in the plot, show warning message and do nothing.
1475  if (( num_active < 0) || ( num_rep <= 1 ))
1476  {
1477  const QString message=
1478  "You must have more than one DataReps \n"
1479  "in this view AND only one DataRep \n"
1480  "selected to be removed.";
1481 
1482  QMessageBox::warning ( this, // parent
1483  "Unable to remove DataRep", // caption
1484  message,
1485  QMessageBox::Ok,
1486  Qt::NoButton,
1487  Qt::NoButton );
1488  return;
1489  }
1490 
1491  DataRep * rep = plotter -> getDataRep( num_active );
1492  //Reset index before remove the datarep.
1493  plotter->setActivePlot(-1,false);
1494  plotter -> removeDataRep ( rep );
1495  plotter -> autoScale ();
1496  delete rep;
1497 
1498  update();
1499 }
1500 
1501 
1502 void
1505 {
1506  const PlotterBase * plotter = getPlotter ();
1507  if ( plotter == 0 ) return;
1509  NTuple * ntuple = fc -> createNTuple ( plotter, 0 );
1510  DataSourceController::instance () -> registerNTuple ( ntuple );
1511 
1512  update ();
1513 }
1514 
1515 
1516 void
1518 fillPlotterList ( std::vector < PlotterBase * > & plotterlist )
1519 {
1520  plotterlist.clear();
1522 
1523  if ( canvaz != 0 ) {
1524  canvaz -> fillPlotterList ( plotterlist );
1525  }
1526 }
1527 
1528 void
1530 ntupleChanged ( int index )
1531 {
1532  // Update tip tool.
1534  const QString tip = m_sel_ntuple_name -> currentText ();
1536 
1537  unsigned int size = m_plotter_list.size ();
1538  if ( size == 0 ) return;
1539 
1540  CutController * controller = CutController::instance ();
1541  vector < PlotterBase * > web;
1542  controller -> fillCutWeb ( m_plotter_list, web );
1543  size = web.size ();
1544 
1545  for ( unsigned int i = 0; i < size; i++ ) {
1546  PlotterBase * plotter = web [ i ];
1547  bool yes = plotter != 0;
1548  if ( yes ) yes = plotter -> isTargetable ();
1549  if ( yes == false ) continue;
1550 
1551  DataRep * rep = plotter -> getTarget ();
1552  yes = rep -> hasNTupleBindings ();
1553  if ( yes == false ) continue;
1554 
1556  const vector < string > & names = ds_controller -> getNTupleNames ();
1557  const string & ds_name = names [ index ];
1558  const DataSource * source = ds_controller -> getDataSource ( ds_name );
1559  DataRepController * dr_controller = DataRepController::instance ();
1560 
1561  try {
1562  dr_controller -> changeDataSource ( rep, source );
1563  }
1564  catch ( const runtime_error & e ) {
1565  QString message ( "Could not change binding because\n" );
1566  message += e.what ();
1567  QMessageBox::critical ( this, // parent
1568  "Data source error",
1569  message,
1570  QMessageBox::Ok,
1571  Qt::NoButton,
1572  Qt::NoButton );
1573  }
1574  }
1575 }
1576 
1577 void
1580 {
1582 
1583  const vector < double > & sv =
1584  controller -> getValueCtrlPts ( plotter );
1585  unsigned int size = sv.size ();
1586  if ( size > 0 ) {
1587  brk_pt -> setEnabled ( true );
1588  brk_label -> setEnabled ( true );
1589  brk_pt -> setValue ( static_cast <int> ( sv[0] * brk_pt -> maxValue() ));
1590  }
1591  if ( size > 1 ) {
1592  flat_width -> setEnabled ( true );
1593  flatlabel -> setEnabled ( true );
1594  flat_width->setValue(static_cast <int>( sv[1] * flat_width->maxValue()));
1595  }
1596  if ( size > 2 ) {
1597  color_scale -> setEnabled ( true );
1598  colorlabel -> setEnabled ( true);
1599  color_scale->setValue(static_cast<int>( sv[2] * color_scale->maxValue()));
1600  }
1601  if ( size < 3 ) {
1602  color_scale -> setEnabled ( false );
1603  colorlabel -> setEnabled ( false);
1604  }
1605  if ( size < 2 ) {
1606  flat_width -> setEnabled ( false );
1607  flatlabel -> setEnabled ( false );
1608  }
1609  if ( size < 1 ) {
1610  brk_pt -> setEnabled ( false );
1611  brk_label -> setEnabled ( false );
1612  }
1613 }
1614 
1618 void
1621 {
1622 
1623  loadAllUserModels ();
1624 
1625  bool yes = m_plotter_list.empty();
1626 
1627  m_plot_title -> setDisabled ( yes );
1628 
1629  PlotterBase * plotter = getPlotter ();
1630 
1631  yes = plotter != 0;
1632  if ( yes ) {
1633  int number = plotter -> getNumDataReps ();
1634  int index = plotter -> activePlotIndex ();
1635  yes = ( number < 2 ) || index >= 0;
1636  }
1637 
1638  m_plot_symbols->setEnabled ( yes );
1639 // m_plot_color->setEnabled ( yes );
1640 // m_selectedColor -> setEnabled ( yes );
1641  m_interval_le->setEnabled ( yes );
1642  m_interval_cb->setEnabled ( yes );
1643  m_errorBars ->setEnabled ( yes );
1644  m_grid -> setEnabled ( yes );
1645  m_boxedge->setEnabled ( yes );
1646  m_pointRepComboBox->setEnabled ( yes );
1647  if ( yes == false ) {
1648  m_selectedColor->setPaletteBackgroundColor ( "black" );
1649  return;
1650  }
1651 
1652 
1653  // Point Reps stuff.
1654 
1656 
1658 
1659  DataRep * datarep = controller -> activeDataRep ( plotter );
1660 
1661  assert ( datarep != 0 );
1662 
1663  yes = datarep -> hasErrorDisplay ();
1664  m_errorBars -> setEnabled ( yes );
1665 
1666  ProjectorBase * proj = datarep -> getProjector();
1667 
1668  if ( proj != 0 ) {
1669  const vector <string> & pointreps = proj -> getPointReps();
1670 
1671 
1672  if ( pointreps.empty () == false ) {
1673  for (std::vector<string>::size_type i = 0; i < pointreps.size(); i++ ) {
1674 
1675 
1676  m_pointRepComboBox->insertItem ( pointreps[i].c_str() );
1677  }
1678  }
1679  RepBase * rep = datarep->getRepresentation();
1680 
1681  const string & curRep = rep->name();
1682  m_pointRepComboBox->setCurrentText ( curRep.c_str() );
1683  }
1684 
1685  if ( plotter -> hasAxis ( Axes::Z ) == false ) { // no Z axis (colormap)
1686  m_value_combo -> setDisabled ( true );
1687  m_slider_control -> setDisabled ( true );
1688  }
1689  else { // has z axis (colormap)
1690 
1691  int jndex = controller -> getValueTransformIndex ( plotter ); // return the index to the list
1692 
1693 
1694  // of value to color transform names of the plotter. from 0 to size-1
1695  if ( jndex < 0 ) { // no value available, jndex=-1
1696  m_value_combo -> setDisabled ( true );
1697  }
1698  else {
1699  m_value_combo -> setEnabled ( true );
1700  m_value_combo -> setCurrentItem ( jndex );
1701 
1702  // ***************************
1703  const BinToColor * repp=plotter -> getValueRep ();
1704 
1705  if (repp != 0) {
1706  bool yess = repp -> acceptChangeColor ();
1707  m_plot_color -> setEnabled (yess);
1708  m_selectedColor -> setEnabled (yess);
1709  }
1710  // *****************************
1711 
1712  bool yes = controller -> hasControlPoints ( plotter ); //return true if the value to color transform has control points
1713  m_slider_control -> setEnabled ( yes );
1714  yes = controller -> isUserDefinedValueTransform ( plotter );
1715  edit_model -> setEnabled ( yes );
1716  updateColorMapCtrls ( plotter );
1717  }// end of jndex<0
1718  }// end of plotter -> hasAxis ( Axes::Z ) == false
1719 
1720  // data source
1721  const DataSource * nt = controller -> getDataSource ( plotter, 0 );
1722 
1723  if ( nt && nt -> empty () ) {
1724  m_plot_symbols->setDisabled ( true );
1725  m_plot_title->setDisabled ( true );
1726  m_plot_color->setDisabled ( true );
1727  m_selectedColor -> setDisabled ( true );
1728  return;
1729  }
1730 
1731  //title
1732  const std::string & st = plotter->getTitle();
1733  QString qst ( st.c_str() );
1734  m_titleText->setText ( qst );
1735 
1736  // error bar and show grid checkbox
1737  m_errorBars->setChecked ( plotter->errorDisplay ( Axes::Y ) );
1738  m_grid->setChecked ( plotter->getShowGrid () );
1739  m_boxedge->setChecked (plotter->getBoxEdge ());
1740 
1741  // whether use symbols(triangle,plus,circle...) to represent data
1742  yes = controller -> hasSymbolRep ( plotter );
1743  m_symbol_group -> setEnabled ( yes );
1744 
1745  if ( yes ) {
1746  m_point_stack -> raiseWidget ( 0 );
1747  unsigned int index = controller ->getRepStyle ( plotter );
1748  m_symbol_group -> setButton ( index );
1749  }
1750 
1751  // whether use line(solid, dash...)to represent data
1752  yes = controller -> hasLineRep ( plotter );
1753  m_line_group -> setEnabled ( yes );
1754  if ( yes ) {
1755  m_point_stack -> raiseWidget ( 1 );
1756  unsigned int style = controller -> getRepStyle ( plotter );
1757 #if QT_VERSION < 0x040000
1758  QButton * button = m_line_group -> find ( style );
1759 #else
1760  QAbstractButton * button = m_line_group -> find ( style );
1761 #endif
1762  QRadioButton * rb = dynamic_cast < QRadioButton * > ( button );
1763  rb -> setChecked ( true );
1764  }
1765  // set the point size
1766  float ptsize = controller -> pointSize ( plotter );
1767  m_symbolPointSize -> setText ( QString ("%1").arg (ptsize) );
1768 
1769  // set color the user choose by RGB
1770  const Color & color = plotter->repColor ();
1771  QColor qcolor ( color.getRed(), color.getGreen(), color.getBlue () ); // constructor
1772  m_selectedColor->setPaletteBackgroundColor ( qcolor );
1773 
1774  // display interval
1775  if ( nt == 0 ) {
1776  m_interval_cb -> setEnabled ( false );
1777  m_interval_le -> setEnabled ( false );
1778  return;
1779  }
1780  const NTuple * ntuple = dynamic_cast < const NTuple * > ( nt );
1781  yes = ntuple != 0 && ntuple -> isIntervalEnabled ();
1782  m_interval_cb->setChecked ( yes );
1783  m_interval_le->setEnabled ( yes );
1784 
1785  if ( yes ) {
1786  unsigned int count = ntuple->getIntervalCount ();
1787  m_interval_le->setText ( QString ("%1").arg ( count ) );
1788  }
1789 }
1790 
1791 void
1793 valueChanged ( int index )
1794 {
1795  PlotterBase * plotter = getPlotter ();
1796  if ( plotter != 0 ) {
1797 
1799  controller -> setValueTransform ( plotter, index );
1800 
1801  const BinToColor * rep = plotter -> getValueRep();
1802  bool yes = false;
1803  if ( rep != 0 ) {
1804  yes = rep -> acceptChangeColor ();
1805  }
1806  m_plot_color -> setEnabled ( yes );
1807  m_selectedColor -> setEnabled ( yes );
1808 
1809  yes = controller -> hasControlPoints ( plotter );
1810  m_slider_control -> setEnabled ( yes );
1811  bool y = rep -> isUserDefined ();
1812  edit_model -> setEnabled ( y );
1813  if ( yes ) {
1814  m_is_updating = true;
1815  updateColorMapCtrls ( plotter );
1816  m_is_updating = false;
1817  }
1818  }
1819 }
1820 
1821 void
1824 {
1826  if ( canvas != 0 ) {
1827  m_app_key = canvas -> getAppKey ();
1828  m_model_name = m_app_key + "/Model Name/";
1829  m_break_point = m_app_key + "/break point/";
1830  m_flat_width = m_app_key + "/flat width/";
1831  m_color_scale = m_app_key + "/color scale/";
1832  }
1833 }
1834 
1835 void
1838 {
1839  if ( m_user_models_loaded == false ) {
1840  setAppKey ();
1841 
1842  QSettings settings;
1843  settings.insertSearchPath ( QSettings::Windows, s_registry );
1844 
1845  QString model_name_key ( m_model_name );
1846  QStringList model_list
1847  = settings.entryList ( model_name_key );
1848 
1849  QStringList::size_type size = model_list.size ();
1850  for ( QStringList::size_type i = 0; i < size ; i++ )
1851  {
1852  QString number = model_list [ i ];
1853  QString name
1854  = settings.readEntry ( model_name_key + number );
1855 
1856  double brk_pt
1857  = settings.readDoubleEntry ( m_break_point + number );
1858  double flat_width
1859  = settings.readDoubleEntry ( m_flat_width + number );
1860  double color_scale
1861  = settings.readDoubleEntry ( m_color_scale + number );
1862 
1863  string mname ( name.latin1() );
1864  vector < double > cpts;
1865  cpts.push_back ( brk_pt );
1866  cpts.push_back ( flat_width );
1867  cpts.push_back ( color_scale );
1868 
1870  controller -> addValueTransform ( mname, cpts );
1871  }
1872 
1873  updateValueCombo ();
1874  m_user_models_loaded = true;
1875  }
1876 }
1877 
1878 void
1881 {
1882  if ( m_is_updating == false ) {
1883  vector < double > sv;
1884 
1885  double m = brk_pt -> maxValue ();
1886  assert(m != 0);
1887  sv.push_back ( (brk_pt -> value()) / m + 0.001);
1888 
1889  double w = flat_width -> maxValue();
1890  assert(w != 0);
1891  sv.push_back ( (flat_width -> value()) / w + 0.001);
1892 
1893  double c = color_scale -> maxValue ();
1894  assert( c!= 0 );
1895  sv.push_back ( ( ( (color_scale -> value()) / c ) ) * 1.5 );
1896 
1897  PlotterBase * plotter = getPlotter ();
1898  if ( plotter != 0 ) {
1900  controller -> setValueCtrlPts (plotter,sv );
1901  }
1902  }
1903 }
1904 
1905 void
1908 {
1909  if ( m_slider_control -> isEnabled () )
1910  {
1911  brk_pt -> setValue ( 50 );
1912  flat_width -> setValue ( 50 );
1913  color_scale -> setValue ( 0 );
1914  }
1915 }
1916 
1917 
1918 void
1920 convertCtrlPts ( std::vector < double > & sv )
1921 {
1922  sv.clear();
1923 
1924  int ibp = brk_pt -> value ();
1925  int ifw = flat_width -> value ();
1926  int ics = color_scale -> value ();
1927 
1928  double bp = static_cast < double > ( ibp) /
1929  static_cast <double>( brk_pt -> maxValue () );
1930 
1931  double fw = static_cast < double > ( ifw ) /
1932  static_cast <double>( flat_width -> maxValue () );
1933 
1934  double cs = static_cast < double > ( ics ) /
1935  static_cast <double>(color_scale -> maxValue () );
1936 
1937  sv.push_back ( bp );
1938  sv.push_back ( fw );
1939  sv.push_back ( cs );
1940 }
1941 
1942 void
1945 {
1946  setAppKey ();
1947 
1948  bool ok = false;
1949  QString text = QInputDialog::getText ( "Save color model", // caption
1950  "Enter name", // label
1952  QString::null, // default text
1953  & ok, this );
1954 
1955  if ( ok )
1956  {
1957  const string name ( text.latin1() );
1958  vector < double > sv;
1959  convertCtrlPts ( sv );
1961  controller -> addValueTransform ( name, sv );
1962 
1963  updateValueCombo ();
1964 
1965  PlotterBase * plotter = getPlotter ();
1966  controller -> setValueTransform ( plotter, name );
1967  int index = controller -> getValueTransformIndex ( plotter );
1968  m_value_combo -> setCurrentItem ( index );
1969 
1970  QSettings settings;
1971  settings.insertSearchPath ( QSettings::Windows, s_registry );
1972  QString model_name_key ( m_model_name );
1973 
1974  QStringList model_list
1975  = settings.entryList ( model_name_key );
1976 
1977  int iat = 0;
1978  while ( true ) {
1979  int index = model_list.findIndex ( QString::number ( iat )) ;
1980  if ( index == -1 ) break;
1981  iat++;
1982  }
1983 
1984  QString at ( QString::number ( iat ) );
1985  settings.writeEntry ( m_model_name + at, text );
1986  settings.writeEntry ( m_break_point + at, sv[0] );
1987  settings.writeEntry ( m_flat_width + at, sv[1] );
1988  settings.writeEntry ( m_color_scale + at, sv[2] );
1989  }
1990 }
1991 
1992 void
1995 {
1996  // If it's the first time to save the variable rainbow color scale,
1997  // we will need special handling.
1998  bool isFirstVR = true;
1999 
2000  QString item = m_value_combo -> currentText ();
2001  vector < double > sv;
2002  convertCtrlPts ( sv );
2003 
2004  PlotterBase * plotter = getPlotter ();
2006  // Use saveValueCtrlPts instead of setValueCtrlPts to make the
2007  // changes effective in this session.
2008  controller -> saveValueCtrlPts ( plotter, sv );
2009 
2010  QSettings settings;
2011  settings.insertSearchPath ( QSettings::Windows, s_registry );
2012 
2013  QString model_name_key ( m_model_name );
2014  QStringList model_list
2015  = settings.entryList ( model_name_key );
2016 
2017 #if QT_VERSION < 0x040000
2018  for ( unsigned int i = 0; i < model_list.size(); i++ ) {
2019 #else
2020  for ( int i = 0; i < model_list.size(); i++ ) {
2021 #endif
2022  QString at ( QString::number ( i ) );
2023  QString name_key ( model_name_key + at );
2024  QString name = settings.readEntry ( name_key );
2025  if ( name == item ) {
2026  settings.writeEntry ( m_break_point + at, sv[0] );
2027  settings.writeEntry ( m_flat_width + at, sv[1] );
2028  settings.writeEntry ( m_color_scale + at, sv[2] );
2029  isFirstVR = false;
2030  break;
2031  }
2032  }
2033 
2034  // For the first time, save the variable rainbow color scale.
2035  if ( isFirstVR ) {
2036  // Find the end of the settings.
2037  int iat = 0;
2038  while ( true ) {
2039  int index = model_list.findIndex ( QString::number ( iat )) ;
2040  if ( index == -1 ) break;
2041  iat++;
2042  }
2043 
2044  QString at ( QString::number ( iat ) );
2045  settings.writeEntry ( m_model_name + at, item );
2046  settings.writeEntry ( m_break_point + at, sv[0] );
2047  settings.writeEntry ( m_flat_width + at, sv[1] );
2048  settings.writeEntry ( m_color_scale + at, sv[2] );
2049  }
2050 }
2051 
2052 void
2055 {
2056  QString item = m_value_combo -> currentText ();
2057  const string name ( item.latin1() );
2058 
2060  bool yes = controller -> removeValueTransform ( name );
2061 
2062  if ( yes ) {
2063  PlotterBase * plotter = getPlotter ();
2064  controller -> setValueTransform ( plotter, "Rainbow" );
2065 
2066  QSettings settings;
2067  settings.insertSearchPath ( QSettings::Windows, s_registry );
2068  QString model_name_key ( m_model_name );
2069  QStringList model_list
2070  = settings.entryList ( model_name_key );
2071  QStringList::size_type size = model_list.size ();
2072 
2073  for (QStringList::size_type i = 0; i < size; i++ ) {
2074  QString at ( model_list [ i ] );
2075  QString name_key ( model_name_key + at );
2076  QString name = settings.readEntry ( name_key );
2077  if ( name == item ) {
2078  settings.removeEntry ( name_key );
2079  settings.removeEntry ( m_break_point + at );
2080  settings.removeEntry ( m_flat_width + at );
2081  settings.removeEntry ( m_color_scale + at );
2082  break;
2083  }
2084  }
2085  updateValueCombo ();
2086  }
2087 }
2088 
2089 void
2092 {
2093  PlotterBase * plotter = getPlotter ();
2094  if ( !plotter ) return;
2095 
2096  bool checked = m_errorBars->isChecked();
2098 
2099  controller -> setErrorDisplayed ( plotter, Axes::Y, checked );
2100 }
2101 void
2103 {
2104  const QString message ( "HippoDraw was not built with TeX support on "
2105  "this platfrom." );
2106  QMessageBox::information ( this, /* parent */
2107  "Input error",
2108  message,
2109  QMessageBox::Ok,
2110  Qt::NoButton,
2111  Qt::NoButton );
2112 }
2113 
2114 void
2117 {
2118  std::string s( (m_titleText->text()).latin1() );
2119  unsigned int size = m_plotter_list.size();
2120 
2121  for ( unsigned int i = 0; i < size; i++ ) {
2122  PlotterBase * plotter = m_plotter_list [ i ];
2123 
2124  /* The size of drawrect, marginrect, need to be updated
2125  according to title text format. LaTeX format starts with
2126  "tex:" (case insensitive).
2127  */
2128  bool needMargin = String::ci_find(s, "tex:")==0;
2129  if ( needMargin ) {
2130 #ifdef HAVE_TEX_UTILS
2131  plotter -> setTopMargin ( needMargin?10.0:0.0 );
2132  plotter -> setNeedUpdate(true);
2133  plotter -> notifyObservers ();
2134 #else
2135  warningTex ();
2136  s.erase ( 0, 4 );
2137 
2138 #endif
2139  }
2140  plotter->setTitle ( s );
2141  }
2142 
2143 
2144 }
2145 
2147 {
2148  m_symbol_group -> setButton ( id );
2149  PlotterBase * plotter = getPlotter ();
2150  if ( !plotter ) return ;
2151 
2153  DataRep * rep = controller -> activeDataRep ( plotter );
2154  if ( rep == 0 ) {
2155  multipleDataRepError ( "plot symbol change" );
2156  return;
2157  }
2158 
2159  rep -> setRepStyle ( id );
2160 }
2161 
2163 {
2164 
2165  m_line_group -> setButton ( id );
2166  PlotterBase * plotter = getPlotter ();
2167  if ( !plotter ) return ;
2168 
2170  DataRep * rep = controller -> activeDataRep ( plotter );
2171  if ( rep == 0 ) {
2172  multipleDataRepError ( "plot symbol change" );
2173  return;
2174  }
2175 
2176  rep -> setRepStyle ( id );
2177 }
2178 
2180 {
2181 
2182  PlotterBase * plotter = getPlotter ();
2183  if ( !plotter ) return;
2184 
2186  DataRep * rep = controller -> activeDataRep ( plotter );
2187  if ( rep == 0 ) {
2188  multipleDataRepError ( "plot symbol size change" );
2189  return;
2190  }
2191 
2192  QString text = m_symbolPointSize->text();
2193  float size = text.toFloat();
2194 
2195  rep->setRepSize ( size );
2196 
2197 }
2198 
2200 {
2201  PlotterBase * plotter = getPlotter ();
2202  if ( plotter == 0 ) return;
2203 
2205  controller->setIntervalEnabled ( plotter, state );
2206  m_interval_le->setEnabled ( state );
2207 }
2208 
2209 void
2212 {
2213  PlotterBase * plotter = getPlotter ();
2214  if ( plotter == 0 ) return;
2215 
2217 
2218  unsigned int interval = text.toUInt ();
2219  controller->setIntervalCount ( plotter, interval );
2220 }
2221 
2222 void
2225 {
2226  PlotterBase * plotter = getPlotter ();
2227  if ( !plotter ) return;
2228 
2229  int index = plotter->activePlotIndex ();
2230 
2231  if ( index < 0 ) {
2232  multipleDataRepError ( "color change" );
2233  return;
2234  }
2235 
2236  const Color & rep_color = plotter->repColor();
2237  QColor color ( rep_color.getRed(),
2238  rep_color.getGreen(),
2239  rep_color.getBlue() );
2240  color = QColorDialog::getColor ( color );
2241  if ( color.isValid() == false ) return;
2242 
2243  m_selectedColor->setPaletteBackgroundColor ( color );
2244 
2245  Color c ( color.red(), color.green(), color.blue() );
2246  plotter->setRepColor ( c );
2247 }
2248 
2249 void
2252 {
2253  PlotterBase * plotter = getPlotter ();
2254 
2255  if ( plotter != 0 ) {
2257  const string rep ( qstr.latin1() );
2258 
2259  controller -> setPointRep ( plotter, rep );
2260 
2261  if ( plotter -> hasAxis ( Axes::Z ) == true ) {
2262 
2263  int index = m_value_combo -> currentItem ();
2264  controller -> setValueTransform ( plotter, index );
2265  }
2266 
2267  updatePlotTab (); // to update the m_point_stack and size.
2268  }
2269 }
2270 
2271 void
2274 {
2275 // #if QT_VERSION < 0x040000
2276 // #else
2277 // id -= 3; // The re-inserted ones have wrong id
2278 // #endif
2280  updateAxisTab ();
2281 }
2282 
2283 void
2286 {
2287  PlotterBase * plotter = getPlotter ();
2288  if ( !plotter ) return;
2289 
2290  plotter->setAutoRanging ( m_axis, false );
2291  const Range & r = plotter->getRange ( m_axis, true );
2292 
2293  m_autoScale->setChecked ( false );
2294 
2295  if ( axisWidget1->isZoomPanChecked() ) {
2296  m_zoompan[plotter] = true;
2297  }
2298 
2299  else {
2300 
2301  std::map < const PlotterBase *, bool >::const_iterator it
2302  = m_zoompan.find ( plotter );
2303  if ( it != m_zoompan.end () ) {
2304  m_zoompan[plotter] = false;
2305  }
2306 
2307  }
2308 
2310 }
2311 
2312 void
2315 {
2316  int value = axisWidget1->getHighSliderValue ();
2317  setHighRange ( value, false );
2318 
2320 }
2321 
2322 void
2325 {
2326  int value = axisWidget1->getLowSliderValue ();
2327  setLowRange ( value, false );
2328 
2330 }
2331 
2332 void
2335 {
2336  int value = m_offset_range->value ();
2337  setOffset ( value, false );
2338  m_offset_range->setValue ( 50 );
2339 }
2340 
2341 void
2344 {
2345  int value = m_width_range->value ();
2346  setBinWidth ( value, false );
2347 
2348  m_width_range->setValue ( 50 );
2349 }
2350 
2351 void
2354 {
2355  int value = min_entries_slider->value ();
2356  m_dragging = false;
2357  setMinEntries(value);
2358 
2359  // min_entries_slider->setValue ( 50 );
2360 }
2361 
2362 void
2365 {
2366  PlotterBase * plotter = getPlotter ();
2367  if ( !plotter ) return;
2368 
2370  int index = controller -> activeDataRepIndex ( plotter );
2371  bool yes = controller -> hasNTupleBindings ( plotter, index );
2372  if ( yes ) {
2373  //Get the string and convert it to double.
2374  QString text = m_width_text->text();
2375  double width = text.toDouble();
2376 
2377  if ( width == 0 ) return; // To prevent it from crashing.
2378  plotter -> setBinWidth ( m_axis, width );
2379  }
2380 
2381  updateAxisTab();
2382 }
2383 
2384 void
2387 {
2388  m_dragging = true;
2390 
2391  if ( ! axisWidget1->isZoomPanChecked() )
2392  {
2393  m_autoScale->setChecked ( false );
2394  autoScale_clicked ();
2395  }
2396  else
2397  {
2398  // Save current width and position.
2399  m_autoScale->setChecked ( false );
2400  autoScale_clicked ();
2401 
2402  PlotterBase * plotter = getPlotter ();
2403  if ( !plotter ) return;
2404  const Range & r = plotter->getRange ( m_axis, true );
2405  m_range.setRange ( r.low(), r.high(), r.pos() );
2406  }
2407 
2408 }
2409 
2410 void
2413 {
2414  PlotterBase * plotter = getPlotter ();
2415  if ( !plotter ) return;
2416 
2418  int index = controller -> activeDataRepIndex ( plotter );
2419  bool yes = controller -> hasNTupleBindings ( plotter, index );
2420  if ( yes ) {
2421  //Get the string and convert it to double.
2422  QString text = m_offset_text->text();
2423  double offset = text.toDouble();
2424 
2425  int value = static_cast < int > ( 50.0 * offset ) + 49;
2426  setDragOn ();
2427  setOffset( value );
2428  offsetDrag ();
2429  }
2430 
2431  updateAxisTab ();
2432 }
2433 
2434 void
2436 setBinWidth ( int value )
2437 {
2438  setBinWidth ( value, m_dragging );
2439 
2440  if ( m_dragging == false ) m_width_range -> setValue ( 50 );
2441 }
2442 
2443 void
2445 setBinWidth ( int value, bool drag )
2446 {
2447  PlotterBase * plotter = getPlotter ();
2448  if ( !plotter ) return;
2449  m_dragging = drag;
2450 
2451  plotter -> setBinWidth ( m_axis, value, m_dragging );
2452  updateAxisTab ();
2453 }
2454 
2455 void
2458 {
2459  PlotterBase * plotter = getPlotter ();
2460  if ( plotter != 0 ) {
2461  QString text = m_axis_label -> text ();
2462  string ltext = text.latin1();
2463  const string axis = convertToString ( m_axis );
2464 
2465  /* The size of drawrect, marginrect, need to be updated
2466  according to title text format. LaTeX format starts with
2467  "tex:" (case insensitive).
2468  */
2469  bool needMargin = String::ci_find(ltext, "tex:")==0;
2470  if ( needMargin ) {
2471 #ifdef HAVE_TEX_UTILS
2472  if (m_axis==Axes::X)
2473  plotter -> setBottomMargin ( needMargin?8.0:0.0 );
2474  else if (m_axis==Axes::Y)
2475  plotter -> setLeftMargin ( needMargin?0.0:0.0 );
2476  else if (m_axis==Axes::Z)
2477  plotter -> setZMargin ( needMargin?7.0:0.0 );
2478  plotter -> setNeedUpdate(true);
2479  plotter -> notifyObservers ();
2480 #else
2481  warningTex();
2482  ltext.erase( 0, 4 );
2483 #endif
2484  }
2485  plotter -> setLabel ( m_axis, ltext );
2486  }
2487 
2488 
2489 }
2490 
2491 void
2494 {
2495 
2496  PlotterBase * plotter = getPlotter ();
2497  if ( !plotter ) return;
2498 
2499  Range r = plotter->getRange ( m_axis, true );
2500 
2502 
2503  plotter->setRange ( m_axis, r, true, false ); // scaled, keep bin width
2504  m_autoScale->setChecked ( false );
2505 
2506  updateAxisTab ();
2507 }
2508 
2509 void
2511 setLowRange ( int value )
2512 {
2513  if ( m_is_updating == false ) {
2514  setLowRange ( value, m_dragging );
2515  if ( m_dragging == false ) {
2517  }
2518  }
2519 }
2520 
2521 void
2523 setLowRange ( int value, bool yes )
2524 {
2525  PlotterBase * plotter = getPlotter ();
2526  if ( !plotter ) return;
2527  m_dragging = yes;
2528 
2529  plotter->setAutoRanging ( m_axis, false );
2530 
2531  if ( ! axisWidget1->isZoomPanChecked() )
2532  {
2533  const string axis = convertToString ( m_axis );
2534  plotter->setLowRange ( m_axis, value, m_dragging );
2535  const Range & r = plotter->getRange ( m_axis, true );
2536  double low = r.low();
2537  axisWidget1 -> setLowText ( QString("%1").arg(low));
2538  }
2539  else
2540  {
2541  const Range & r = plotter->getRange ( m_axis, true );
2542  Range range ( r.low(), r.high(), r.pos() );
2543  axisWidget1->processLowSliderMoved ( value, range, m_range );
2544  if ( m_dragging ) plotter->setRange ( m_axis, range, true, false );
2545  }
2546 }
2547 
2548 void
2550 setHighRange ( int value )
2551 {
2552  if ( m_is_updating == false ) {
2553  setHighRange ( value, m_dragging );
2554  if ( m_dragging == false ) {
2556  }
2557  }
2558 }
2559 
2560 void
2562 setHighRange ( int value, bool yes )
2563 {
2564  PlotterBase * plotter = getPlotter ();
2565  if ( !plotter ) return;
2566  m_dragging = yes;
2567 
2568  plotter->setAutoRanging ( m_axis, false );
2569 
2570  if ( !axisWidget1->isZoomPanChecked() )
2571  {
2572  const string axis = convertToString ( m_axis );
2573  plotter->setHighRange ( m_axis, value, m_dragging );
2574  const Range & r = plotter->getRange ( m_axis, true );
2575  double high = r.high();
2576  axisWidget1 -> setHighText ( QString("%1").arg(high));
2577  return;
2578  }
2579 
2580  BinaryTransform *t =
2581  dynamic_cast< BinaryTransform* > ( plotter->getTransform() );
2582 
2583  if ( axisWidget1->isZoomPanChecked() && ! t->isPeriodic() )
2584  {
2585  const Range & r = plotter->getRange ( m_axis, true );
2586  Range range ( r.low(), r.high(), r.pos() );
2587  axisWidget1->processHighSliderMoved ( value, range, m_range );
2588  if ( m_dragging ) plotter->setRange ( m_axis, range, true, false );
2589  return;
2590  }
2591 
2592  double offset(0.0), incr(0.0);
2593 
2594  if ( axisWidget1->isZoomPanChecked() && t->isPeriodic() )
2595  {
2596 
2598  dynamic_cast< PeriodicBinaryTransform* > ( t );
2599 
2600  const Range & r = plotter->getRange ( m_axis, true );
2601  Range range (r.low(), r.high(), r.pos());
2602 
2603  incr = ( value - m_highslider1_last_val ) * r.length() / 100;
2604  m_highslider1_last_val = value;
2605 
2606  // Exchange axes to make the GUI more understandable.
2607  if ( m_axis == Axes::Y )
2608  {
2609  offset = tp->xOffset();
2610  offset = tp->moduloAddY( offset, incr );
2611  tp->setXOffset( offset );
2612  }
2613  else if ( m_axis == Axes::X )
2614  {
2615  offset = tp->yOffset();
2616  offset = tp->moduloAddX( offset, incr );
2617  tp->setYOffset( offset );
2618  }
2619 
2620 
2621  axisWidget1 -> setHighText ( QString( "%1" ).arg( offset ) );
2622  if ( m_dragging ) plotter->setRange ( m_axis, range, true, false );
2623  return;
2624  }
2625 }
2626 
2627 void
2630 {
2631 
2632  PlotterBase * plotter = getPlotter ();
2633  if ( !plotter ) return;
2634 
2635  Range r = plotter->getRange ( m_axis, true );
2636 
2638 
2639  plotter->setRange ( m_axis, r, true, false ); // scaled and keep bin width
2640  m_autoScale->setChecked ( false );
2641 
2642  updateAxisTab ();
2643 }
2644 
2645 void
2647 setOffset ( int value )
2648 {
2649  setOffset( value, m_dragging );
2650 }
2651 
2652 void
2654 setOffset ( int value, bool yes )
2655 {
2656  PlotterBase * plotter = getPlotter ();
2657  if ( !plotter ) return;
2658  m_dragging = yes;
2659 
2660  const string axis = convertToString ( m_axis );
2662  controller -> setOffset ( plotter, axis, value, m_dragging );
2663  double offset = plotter->getOffset ( m_axis );
2664  m_offset_text -> setText ( QString ("%1").arg (offset) );
2665 
2666  updateAxisTab ();
2667 }
2668 
2669 const std::vector < PlotterBase * > &
2672 {
2673  vector < PlotterBase * > plotterlist;
2674  fillPlotterList ( plotterlist );
2675 
2676 
2678  const DataSource * tuple = controller -> getDataSource ( plotter );
2679  CutController * cutcontroller = CutController::instance();
2680  return cutcontroller->getCutList ( plotterlist, tuple );
2681 }
2682 
2683 void
2686 {
2687  m_is_updating = true;
2688 
2689  int id = cutRadioId ();
2690  bool fit_cut = id == 2;
2691 
2692  int index = m_selCutComboBox -> currentItem ();
2693  Range currentRange = m_tuple_cuts [index] -> getRange();
2694  PlotterBase * plotter = getSelectedCut();
2695 
2696  if ( fit_cut == false ) {
2697  Axes::Type cut_axis = getAxes ( index );
2698  const Range & fullRange = plotter -> getRange ( cut_axis, false );
2699  axisWidget2->processTextBoxReturnPressed ( currentRange, fullRange );
2700  plotter->setCutRangeAt ( currentRange, cut_axis );
2701  }
2702  else {
2703  const Range & fullRange = plotter -> getRange ( Axes::X, false );
2704  axisWidget2->processTextBoxReturnPressed ( currentRange, fullRange );
2705  plotter->setCutRangeAt ( currentRange, index );
2706  }
2707 }
2708 
2710 {
2711  axisWidget2->setAllDisabled ( yes );
2712  colorSelect_2->setDisabled ( yes );
2713  cutRemovePushButton->setDisabled ( yes );
2714  cutInvertPushButton->setDisabled ( yes );
2715  cutEnablePushButton -> setDisabled ( yes );
2716  m_cutAddSelected->setDisabled ( yes );
2717  m_cutAddAll -> setDisabled ( yes );
2718 
2719  if ( yes ) {
2720  int number = m_selCutComboBox -> count ();
2721  while ( number-- > 0 ) {
2722  m_selCutComboBox -> removeItem ( 0 );
2723  }
2724  }
2725  m_selCutComboBox -> setDisabled ( yes );
2726 }
2727 
2728 void
2730 updateTupleCuts ( const std::vector < PlotterBase * > & cutlist )
2731 {
2732  m_tuple_cuts.clear ();
2733  m_tuple_cut_plotters.clear ();
2734 
2735  unsigned int size = cutlist.size ();
2736 
2737  for ( unsigned int i = 0; i < size; i++ ) {
2738  PlotterBase * plotter = cutlist[i];
2739  TupleCutList_t cuts;
2740  plotter -> fillCutList ( cuts );
2741 
2742  for ( unsigned int j = 0; j < cuts.size (); j++ ) {
2743  m_tuple_cuts.push_back ( cuts[j] );
2744  m_tuple_cut_plotters.push_back ( plotter );
2745  }
2746  }
2747 }
2748 
2749 void
2751 updateCutControls ( const std::vector < PlotterBase * > & cutlist )
2752 {
2753  QString old_current = m_selCutComboBox -> currentText ();
2754  int numberItems = m_selCutComboBox->count();
2755 
2756  while ( numberItems-- > 0 ) {
2758  }
2759 
2760  m_selCutComboBox -> setEnabled ( true );
2761 
2762  updateTupleCuts ( cutlist );
2763  bool yes = m_tuple_cuts.empty ();
2764  if ( yes ) {
2765  cutRemovePushButton -> setEnabled ( false );
2766  return;
2767  }
2768 
2769  int index = -1;
2770  unsigned int size = m_tuple_cuts.size ();
2771 
2772  for ( unsigned int i = 0; i < size; i++ ) {
2773  const TupleCut * cut = m_tuple_cuts[i];
2774  const string & label = cut -> getLabel ();
2775  QString item = label.c_str ();
2776  m_selCutComboBox -> insertItem ( item );
2777  if ( item == old_current ) index = i;
2778  }
2779 
2780  PlotterBase * plotter = getPlotter ();
2781  assert ( plotter );
2782  index = -1;
2783  map < PlotterBase *, int > ::iterator first
2784  = m_cut_map.find ( plotter );
2785 
2786  if ( first == m_cut_map.end () ) { // not found
2787  index = 0;
2788  m_cut_map [ plotter ] = index;
2789  }
2790  else {
2791  index = first -> second;
2792  }
2793  int count = m_selCutComboBox -> count ();
2794  if ( index >= count ) {
2795  index = count -1;
2796  m_cut_map [ plotter] = index;
2797  }
2798 
2799  m_selCutComboBox -> setCurrentItem ( index );
2801 }
2802 
2806 void
2809 {
2810  if ( m_tuple_cuts.empty () ) return;
2811 
2812  int index = m_selCutComboBox -> currentItem ();
2813  const TupleCut * cut = m_tuple_cuts [ index ];
2814  assert ( cut != 0 );
2815  bool yes = cut -> isEnabled ();
2816  m_cut_enable_updating = true;
2817  cutEnablePushButton -> setOn ( ! yes );
2818  m_cut_enable_updating = false;
2819 }
2820 
2821 Axes::Type
2823 getAxes ( unsigned int index )
2824 {
2825  Axes::Type axis = Axes::Y;
2826 
2827  PlotterBase * plotter = m_tuple_cut_plotters [ index ];
2828  unsigned int size = m_tuple_cut_plotters.size ();
2829  for ( unsigned int i = 0; i < size; i++ ) {
2830  if ( m_tuple_cut_plotters[i] == plotter ) {
2831  if ( i == index ) {
2832  axis = Axes::X;
2833  }
2834  break;
2835  }
2836  }
2837 
2838  return axis;
2839 }
2840 
2841 void
2844 {
2845  m_is_updating = true;
2846  int index = m_selCutComboBox -> currentItem ();
2847  const Range & currentRange = m_tuple_cuts[index] -> getRange ();
2848 
2849  Axes::Type cut_axis = Axes::X;
2850  int id = cutRadioId ();
2851  bool fit_cut = id == 2;
2852  if ( fit_cut == false ) {
2853  cut_axis = getAxes ( index );
2854  }
2855  const Range & fullRange = cplotter->getRange ( cut_axis, false );
2856 
2857  axisWidget2->updateCutControlValues ( currentRange, fullRange );
2858  CutController * controller = CutController::instance ();
2859 
2860  bool yes
2861  = controller -> isZoomPan ( cplotter, cut_axis );
2862  axisWidget2 -> setZoomPan ( yes );
2863  axisWidget2->processZoomPanCheckBoxClicked ( currentRange, fullRange );
2864  m_is_updating = false;
2865 }
2866 
2867 // void
2868 // Inspector::
2869 // fillCutsOn ( const PlotterBase * plotter,
2870 // std::vector < PlotterBase * > & cutlist )
2871 // {
2872 // cutlist.clear();
2873 
2874 // DisplayController * controller = DisplayController::instance ();
2875 // const DataRep * datarep = controller -> activeDataRep ( plotter );
2876 // if ( datarep != 0 ) {
2877 // CutController * cutcontroller = CutController::instance();
2878 
2879 // cutcontroller->fillCutList ( datarep, cutlist );
2880 // }
2881 // }
2882 
2883 const std::vector < const TupleCut * > &
2885 getCutList ( const PlotterBase * plotter ) const
2886 {
2888  int index = controller -> activeDataRepIndex ( plotter );
2889  if ( index < 0 ) {
2890  string what ( "Inspector::getCutList: " );
2891  what += "no active DataRep in PlotterBase object.";
2892  throw std::logic_error ( what );
2893  }
2894  const DataRep * datarep = plotter -> getDataRep ( index );
2895  CutController * cut_controller = CutController::instance ();
2896 
2897  return cut_controller -> getCutList ( datarep );
2898 }
2899 
2900 void
2903 {
2904  if ( !m_selectedPlotRadioButton->isChecked() ) return;
2905 
2906  // Change the items in the combo box to only cuts over selected datarep.
2907 
2908  PlotterBase * plotter = getPlotter ();
2909  bool yes = plotter != 0;
2910  if ( yes ) yes = plotter -> isTargetable ();
2911  disableCutControls ( yes == false );
2912  if ( yes == false ) return;
2913 
2914  vector < PlotterBase * > cutlist;
2915 
2916  if ( cutRadioId () != 2 ) {
2917  CutController * controller = CutController::instance ();
2918  controller -> fillCutList ( plotter, cutlist );
2919 
2920  // Clear the combobox and insert the new strings.
2921 
2922  if ( cutlist.empty () ) {
2923  disableCutControls ( true );
2924  cutRemovePushButton->setEnabled ( false );
2925  return;
2926  }
2927  }
2928  else { // fitting cut
2929  cutlist.push_back ( plotter );
2930  }
2931 
2932  updateCutControls ( cutlist );
2933 
2934  if ( m_tuple_cuts.empty () ) {
2935  disableCutControls ( true );
2936  cutRemovePushButton->setEnabled ( false );
2937  return;
2938  }
2939 
2940  // Update Controls.
2941 
2942  disableCutControls ( false );
2943  cutRemovePushButton->setEnabled ( true );
2944  m_cutAddSelected -> setDisabled ( true );
2945  m_cutAddAll -> setDisabled ( true );
2946 
2947  // Update texts and sliders.
2948 
2949  int index = m_selCutComboBox -> currentItem ();
2950  const PlotterBase * cut_plotter = m_tuple_cut_plotters [ index ];
2951  updateCutControlValues ( cut_plotter );
2952 }
2953 
2954 void
2957 {
2958  // Take the selected cut from cutlistcombobox and add it to selected
2959  // plotter on canvas.
2960 
2961  // Find the selected cutplotter.
2962 
2963  CutPlotter * cp = getSelectedCut();
2964 
2965  // Find the selected Plotter.
2966  PlotterBase * plotter = getPlotter ();
2967  if ( !plotter ) return ;
2968 
2969  // Add the cut to the plotter.
2970  CutController * controller = CutController::instance();
2971  controller -> addCut ( cp, plotter );
2972 
2973 }
2974 
2975 void
2978 {
2979  PlotterBase * plotter = getPlotter ();
2980  if ( plotter == 0 ) return;
2981 
2982  CutController * controller = CutController::instance ();
2983  const vector < PlotterBase * > & cut_list = getDataCutList ( plotter );
2984 
2985  controller -> addCuts ( cut_list, plotter );
2986 
2987  unsigned int size = cut_list.size ();
2988  for ( unsigned int i = 0; i < size; i++ ) {
2989  PlotterBase * pb = cut_list[i];
2990  CutPlotter * cut_plotter = dynamic_cast < CutPlotter * > ( pb );
2991  if ( cut_plotter == plotter ) {
2992  cutOnCutError ();
2993  }
2994  }
2995 }
2996 
2997 /* Take the selected cut from cutlistcombobox and remove it from the selected
2998  plotter on canvas.
2999 */
3000 void
3003 {
3004  PlotterBase * plotter = getPlotter ();
3005  if ( !plotter ) return ;
3006 
3007  bool is_fit_radio = cutRadioId () == 2;
3008  if ( is_fit_radio ) {
3010  int index = controller->activeDataRepIndex ( plotter );
3011  DataRep * rep = plotter -> getDataRep ( index );
3012  FunctionController::instance () -> removeTupleCut ( plotter, rep );
3013  }
3014  else {
3015  // Find the selected cutplotter.
3016  CutPlotter * cp = getSelectedCut();
3017  CutController::instance() -> removeCut ( cp, plotter );
3018  }
3019 
3020  if ( m_selectedPlotRadioButton -> isChecked () ) {
3021  // post event so we don't delete item that sent us the signal.
3022  PlotterEvent * event = new PlotterEvent ( plotter );
3023  QApplication::postEvent ( this, event );
3024  }
3025 }
3026 
3027 void
3030 {
3031  if ( !allCutsRadioButton->isChecked() ) return;
3032 
3033  PlotterBase * plotter = getPlotter ();
3034 
3035  bool yes = plotter != 0;
3036  if ( yes ) yes = plotter -> isTargetable ();
3037 
3038  disableCutControls ( yes == false );
3039  if ( yes == false ) return;
3040 
3041  const vector < PlotterBase * > & cutlist = getDataCutList ( plotter );
3042 
3043  // Clear the combobox and insert the new strings.
3044 
3045  updateCutControls ( cutlist );
3046 
3047  if ( cutlist.empty () ) {
3048  disableCutControls ( true );
3049  return;
3050  }
3051 
3052  // Update Controls.
3053 
3054  disableCutControls ( false );
3055  cutRemovePushButton->setDisabled ( true );
3056  m_cutAddSelected -> setEnabled ( true );
3057  m_cutAddAll -> setEnabled ( true );
3058 
3059  // Update texts and sliders.
3060 
3061  const PlotterBase * cut_plotter = cutlist.back ();
3062  updateCutControlValues ( cut_plotter );
3063 }
3064 
3066 {
3067  CutPlotter * cut_plotter = getSelectedCut ();
3068  updateCutControlValues ( cut_plotter );
3069 
3070  PlotterBase * plotter = getPlotter (); // the target
3071  int index = m_selCutComboBox -> currentItem ();
3072  m_cut_map [ plotter ] = index;
3073 
3075 }
3076 
3077 CutPlotter *
3080 {
3081  if ( cutRadioId() != 2 ) {
3082  PlotterBase * plotter = getPlotter ();
3083  if ( plotter == 0 ) return 0;
3084 
3086 
3088  return dynamic_cast < CutPlotter * > ( pb );
3089  }
3090  else { // fitting cut
3091  PlotterBase * pb = getPlotter ();
3092  CutPlotter * plotter = dynamic_cast < CutPlotter * > ( pb);
3093  return plotter;
3094  }
3095 }
3096 
3100 void
3103 {
3104  // Get the column label from m_CutVariableComboBox1, and create a cut on
3105  // the selected plotter with that column label. Also update the list of
3106  // cuts and the high and low range.
3107 
3108  PlotterBase * plotter = getPlotter ();
3109  bool yes = plotter != 0;
3110 
3111  if ( yes ) yes = plotter -> isTargetable ();
3112  if ( yes == false ) {
3113  int index = plotter -> activePlotIndex ();
3114  if ( index < 0 ) {
3115  multipleDataRepError ( "Cut" );
3116  }
3117  else { // must be a function
3118  const QString message ( "Can not apply cut to a function" );
3119  QMessageBox::information ( this, /* parent */
3120  "Cut application error",
3121  message,
3122  QMessageBox::Ok,
3123  Qt::NoButton,
3124  Qt::NoButton );
3125  }
3126  return;
3127  }
3128 
3130  int index = controller->activeDataRepIndex ( plotter );
3131  assert ( index >= 0 );
3132 
3133  const DataRep * rep = plotter -> getDataRep ( index );
3134  if ( rep -> hasNTupleBindings () == false ) {
3135  const QString message ( "Can not apply cut to a static histogram" );
3136  QMessageBox::information ( this, /* parent */
3137  "Cut application error",
3138  message,
3139  QMessageBox::Ok,
3140  Qt::NoButton,
3141  Qt::NoButton );
3142  return;
3143  }
3144 
3145  vector < string > bindings;
3146  int id = cutRadioId ();
3147  if ( id != 2 ) {
3148 #if QT_VERSION < 0x030100 // 3.1.0
3149  string label1 ( m_CutVariableComboBox1 -> currentText() );
3150  string label2 ( m_CutVariableComboBox2 -> currentText() );
3151 #else
3152  QString text1 = m_CutVariableComboBox1 -> currentText();
3153  string label1 = text1.latin1();
3154  QString text2 = m_CutVariableComboBox2 -> currentText();
3155  string label2 = text2.latin1();
3156 #endif
3157 
3158  switch ( id ) {
3159  case 0 : // 1d data cut
3160  bindings.push_back( label1 );
3161  break;
3162  case 1 : // 2d data cut
3163  bindings.push_back( label1 );
3164  bindings.push_back( label2 );
3165  break;
3166  }
3167  CutController * cutcontroller = CutController::instance();
3168  PlotterBase * cutplotter = cutcontroller -> addCut ( plotter, bindings );
3170  if ( canvas == 0 ) return;
3171 
3172  canvas -> addPlotDisplay ( cutplotter, false );
3173  }
3174  else {
3175  DataRep * datarep = plotter -> getDataRep ( index );
3177  controller -> setTupleCut ( plotter, datarep );
3178  }
3179 
3180  // Update other guys.
3182  allCutsRadioButton_toggled ( true );
3183 }
3184 
3185 int
3188 {
3189  int index = -1;
3190 
3191  int size = m_selCutComboBox -> count ();
3192  for ( int i = 0; i < size; i++ ) {
3193  QString text = m_selCutComboBox -> text ( i );
3194  if ( text == label ) {
3195  index = i;
3196  break;
3197  }
3198  }
3199  return index;
3200 }
3201 
3202 void
3205 {
3206  if ( m_new_plot_box->isEnabled () == false ) return;
3207 
3208  PlotterBase * plotter = getPlotter ();
3209  bool yes = plotter != 0;
3210  m_new_cut_box->setEnabled ( yes );
3211 
3212  if ( yes ) yes = plotter -> isTargetable ();
3213  m_cut_selected_box->setEnabled ( yes );
3214 
3215  if ( yes ) {
3216  int id = cutRadioId ();
3217  bool is_fit_radio = id == 2;
3219  allCutsRadioButton_toggled ( true );
3220 
3221  if ( is_fit_radio == false ) {
3222  updateDataCutsTab ();
3223  }
3224  else {
3225  updateFitCutsTab ();
3226  }
3227  }
3228 }
3229 
3230 void
3233 {
3234 }
3235 
3236 void
3239 {
3240  int id = cutRadioId ();
3241 
3242  if ( id == 0 ) {
3243  m_CutVariableComboBox2 -> setEnabled ( false );
3244  }
3245 
3246  PlotterBase * plotter = getPlotter ();
3248  int index = controller->activeDataRepIndex ( plotter );
3249  if ( index < 0 ) {
3250  m_new_cut_box -> setDisabled ( true );
3251  m_cut_selected_box -> setDisabled ( true );
3252  }
3253  else {
3254  DataRep * datarep = plotter->getDataRep ( index );
3255  if ( datarep->hasZeroRows() )
3256  {
3257  m_new_cut_box->setDisabled ( true );
3258  m_cut_selected_box->setDisabled ( true );
3259  return;
3260  }
3261 
3262  m_new_cut_box->setDisabled ( false );
3263  const vector < PlotterBase * > & cuts = getDataCutList ( plotter );
3264  if ( cuts.empty() ) {
3265  m_cut_selected_box->setDisabled ( true );
3266  }
3267  else {
3268  m_cut_selected_box -> setDisabled ( false );
3269  }
3270  }
3271 
3272  updateCutVarGroupBox ( plotter, index );
3273 }
3274 
3275 void
3277 setAllCutsActive ( bool yes )
3278 {
3279  vector < PlotterBase * > plotters;
3280  fillPlotterList ( plotters );
3281 
3282  if ( plotters.empty () == false ) {
3283  CutController * controller = CutController::instance ();
3284  vector < CutPlotter * > cutters;
3285  controller -> fillCutList ( plotters, cutters );
3286  vector < CutPlotter * > ::iterator first = cutters.begin ();
3287 
3288  while ( first != cutters.end () ) {
3289  CutPlotter * cutter = *first++;
3290  cutter -> setActive ( yes );
3291  }
3292  }
3293 }
3294 
3295 void
3297 updateCutVarGroupBox ( const PlotterBase * plotter, int index )
3298 {
3299  const DataSource * tuple
3300  = DisplayController::instance() -> getDataSource ( plotter, index );
3301 
3302  if (!tuple) return;
3303  int index1 = -1;
3304  int index2 = -1;
3305  if ( m_CutVariableComboBox1 -> count() > 0 ) {
3306  index1 = m_CutVariableComboBox1 -> currentItem ();
3307  }
3308  if ( m_CutVariableComboBox2 -> count() > 0 ) {
3309  index2 = m_CutVariableComboBox2 -> currentItem ();
3310  }
3313 
3314  const vector < string > & cols = tuple->getLabels();
3315 #ifdef ITERATOR_MEMBER_DEFECT
3316  std::
3317 #endif
3318  vector < string > ::const_iterator first = cols.begin ();
3319  while ( first != cols.end() ) {
3320  const string & str = *first++;
3321  m_CutVariableComboBox1 -> insertItem ( str.c_str() );
3322  m_CutVariableComboBox2 -> insertItem ( str.c_str() );
3323  }
3324  if ( index1 >= m_CutVariableComboBox1 -> count () ) {
3325  index1 = 0;
3326  }
3327  if ( index2 >= m_CutVariableComboBox2 -> count () ) {
3328  index2 = 0;
3329  }
3330 
3331  if ( index1 >= 0 ) {
3332  m_CutVariableComboBox1 -> setCurrentItem ( index1 );
3333  }
3334  if ( index2 >= 0 ) {
3335  m_CutVariableComboBox2 -> setCurrentItem ( index2 );
3336  }
3337 
3338  cut_button_group -> setEnabled ( true );
3339  int id = cutRadioId ();
3340  if ( id == 1 ) {
3341  m_CutVariableComboBox2 -> setEnabled( true );
3342  }
3343 }
3344 
3345 int
3347 cutRadioId () const
3348 {
3349  int id = -1;
3350  if ( m_cut_data1 -> isChecked () ) id = 0;
3351  if ( m_cut_data2 -> isChecked () ) id = 1;
3352  if ( m_cut_fit_radio -> isChecked () ) id = 2;
3353 
3354  return id;
3355 }
3356 
3357 void
3360 {
3361  int id = cutRadioId ();
3362 
3363  switch ( id ) {
3364  case 0 : // 1d data cut
3365  m_CutVariableComboBox1 -> setEnabled ( true );
3366  m_CutVariableComboBox2 -> setEnabled ( false );
3367  break;
3368  case 1 : // 2d data cut
3369  m_CutVariableComboBox1 -> setEnabled ( true );
3370  m_CutVariableComboBox2 -> setEnabled ( true );
3371  break;
3372  case 2 : // fit cut
3373  m_CutVariableComboBox1 -> setEnabled ( false );
3374  m_CutVariableComboBox2 -> setEnabled ( false );
3375  break;
3376  }
3377 
3378  updateCutsTab (); // in case of switching from data to fitting
3379 }
3380 void
3382  setSelectedFitter ( const std::string & name )
3383 {
3385  const vector < string > & fitters = controller -> getFitterNames ();
3386  for ( unsigned int i = 0; i < fitters.size(); i++ ) {
3387  if ( name == fitters[i] )
3388  {
3389  m_fitter_names -> setCurrentItem ( i );
3390  break;
3391  }
3392  }
3393 }
3394 
3395 void
3398 {
3400  const vector < string > & names = controller -> getFunctionNames ();
3401  int current = newFunctionsComboBox->currentItem ();
3402 
3403  if ( newFunctionsComboBox -> count () !=
3404  static_cast < int > ( names.size () ) ) {
3406 
3407  for ( unsigned int i = 0; i < names.size(); i++) {
3408  if ( names[i] != "Linear Sum" ) {
3409  newFunctionsComboBox->insertItem ( names[i].c_str() );
3410  }
3411  }
3412  }
3413 
3414  PlotterBase * plotter = getPlotter();
3415  bool yes = plotter != 0;
3416  m_func_new->setEnabled ( yes );
3417 
3418  if ( yes ) yes = plotter -> isTargetable ();
3419  functionsRemoveButton -> setEnabled ( yes );
3420  m_IgnoreErrorCheckBox -> setEnabled (yes);
3421  functionsFitToDataButton -> setEnabled ( yes );
3422  functionsResetButton -> setEnabled ( yes );
3423  m_resid->setEnabled ( yes );
3424  if ( yes == false ) {
3425  return;
3426  }
3427 
3428  const DataSource * nt
3429  = DisplayController::instance()->getDataSource ( plotter, 0 );
3430 
3431  if ( nt && nt -> empty () )
3432  {
3433  m_func_new->setDisabled ( true );
3434  functionsRemoveButton -> setEnabled ( false );
3435  m_IgnoreErrorCheckBox -> setDisabled (true);
3436  functionsFitToDataButton -> setEnabled ( false );
3437  functionsResetButton -> setEnabled ( false );
3438  return;
3439  }
3440 
3441  // Update new functions section //
3442  //------------------------------//
3443  newFunctionsAddButton->setEnabled ( true );
3444  m_func_new->setEnabled ( true );
3445 
3446  if ( current >= 0 ) {
3448  }
3449  newFunctionsComboBox->setEnabled ( true );
3450 
3451  // Update functionsAppliedComboBox. //
3452  //----------------------------------//
3453  bool to_enable = false;
3454  DisplayController * d_controller = DisplayController::instance ();
3455  int index = d_controller -> activeDataRepIndex ( plotter );
3456 
3458 
3459  if ( index >= 0 ) {
3460  DataRep * datarep = plotter ->getDataRep ( index );
3461  if ( f_controller -> hasFunction ( plotter, datarep ) ) {
3462 
3463  const vector < string > & fnames
3464  = f_controller -> functionNames ( plotter, datarep );
3465 
3466  if ( fnames.size() != 0 )
3467  {
3468  to_enable = true;
3469  m_functionIndexMap.clear();
3470 
3471  for ( unsigned i = 0; i < fnames.size(); i++)
3472  {
3473  if ( fnames[i].find ( "Linear Sum" ) == string::npos )
3474  {
3475  m_functionIndexMap.push_back ( i );
3476  }
3477  }
3478  }
3479  }
3480  }
3481 
3482  functionsRemoveButton -> setEnabled ( to_enable );
3483  m_IgnoreErrorCheckBox -> setEnabled (to_enable);
3484  functionsFitToDataButton -> setEnabled ( to_enable );
3485  functionsResetButton -> setEnabled ( to_enable );
3486  if ( to_enable == false ) {
3488  }
3489 
3490  if ( to_enable )
3491  {
3492  Fitter * fitter = f_controller -> getFitter ( plotter );
3493  string name = "none";
3494  if ( fitter != 0 ) {
3495  name = f_controller -> getFitterName ( plotter );
3496  setSelectedFitter ( name );
3497  }
3498  }
3499 
3500  m_resid->setEnabled ( to_enable );
3501 
3502  // Update function parameters tab //
3503  //--------------------------------//
3504 
3505  // Set Parameters in list view as well as in line editor and
3506  // the check box. Focus is set to the current selected item
3507  // or in case none is selected 1st item.
3508  if ( to_enable ) setParameters ( index, plotter );
3509 
3510  // Set the slider to be in the center
3511  m_FunctionParamsSlider -> setValue(50);
3512 
3513 }
3514 
3515 void
3518 {
3519  PlotterBase * plotter = getPlotter ();
3520  if ( !plotter ) return ;
3521 
3522  FunctionRep * frep = getFunctionRep ( );
3524  controller -> removeFunction ( plotter, frep );
3525  if ( plotter->activePlotIndex ( ) != 0 )
3526  plotter->setActivePlot ( -1, true );
3527  else
3528  plotter->setActivePlot ( 0, true );
3529 
3530  // Update the rest.
3532 }
3533 
3534 void
3537 {
3538  PlotterBase * plotter = getPlotter ();
3539  if ( !plotter ) return ;
3540 
3542  int index = dcontroller -> activeDataRepIndex ( plotter );
3543  if ( index < 0 ) return;
3544  DataRep * datarep = plotter -> getDataRep ( index );
3545 
3547  if ( ! ( fcontroller -> hasFunction ( plotter, datarep ) ) ) {
3548  return;
3549  }
3550 
3551  fcontroller -> restoreParameters ( plotter );
3552 
3553  // Set the parameters
3554  setParameters ( index, plotter );
3555 }
3556 
3557 void
3559 setParameters ( int index, PlotterBase * plotter )
3560 {
3562  m_FunctionParamsCheckBox -> setChecked( false );
3564 
3565  DataRep * datarep = plotter -> getDataRep ( index );
3566  assert ( datarep != 0 );
3567 
3569  if ( ! ( controller -> hasFunction ( plotter, datarep ) ) )
3570  {
3571  return;
3572  }
3573 
3574  const vector < string > & fnames
3575  = controller -> functionNames ( plotter, datarep );
3576 
3577  if ( fnames.empty () ) {
3578  return;
3579  }
3580 
3581  m_function_lv_map.clear ();
3582  vector < FunctionRep * > freps;
3583  controller -> fillTopLevelFunctionReps ( freps, plotter, datarep );
3584  for ( unsigned int i = 0; i < freps.size (); i++ ) {
3585  FunctionRep * frep = freps [ i ];
3586  const string & func_name = frep -> functionName ();
3587 
3588 #if QT_VERSION < 0x040000
3589  QListViewItem * parent
3591 #else
3592  Q3ListViewItem * parent
3593  = new Q3ListViewItem ( m_FunctionParamsListView );
3594 #endif
3595  parent -> setOpen ( true );
3596  parent -> setText ( Index, QString ( func_name.c_str() ) );
3597  m_function_lv_map [ parent ] = frep;
3598 
3599  //Ignore errors flag, conected with the ignoreError check box.
3600  bool ignoreFlag = true;
3601 
3602  Fitter * fitter = frep -> getFitter ();
3603  if ( fitter != 0 ) {
3604  //Get the ignore errors flag of the current function.
3605  ignoreFlag = frep -> getIgnoreErrors ();
3606  }
3607  const vector < double > & parms = frep -> parameters ();
3608  unsigned int start_index = parms.size();
3609  fillFunctionParameters ( parent, frep, start_index );
3610 
3611  m_FunctionParamsListView -> setAllColumnsShowFocus ( true );
3612 #if QT_VERSION < 0x040000
3613  QListViewItem * firstItem = parent -> firstChild ();
3614 #else
3615  Q3ListViewItem * firstItem = parent -> firstChild ();
3616 #endif
3617  m_IgnoreErrorCheckBox -> setChecked(ignoreFlag);
3618 
3619  if ( firstItem != 0 ) {
3620  m_FunctionParamsLineEdit -> setText ( firstItem -> text( Value ) );
3621  m_FunctionParamsListView -> setSelected ( firstItem, true );
3622  m_FunctionParamsListView -> setCurrentItem ( firstItem );
3623 
3624  QString fixedFlag = firstItem -> text( Fixed );
3625  m_FunctionParamsCheckBox->setChecked((fixedFlag == QString ( "Yes" ) ) ?
3626  true : false );
3627  }
3628  }
3629 }
3630 
3631 void
3632 Inspector::
3633 #if QT_VERSION < 0x040000
3635  const FunctionRep * frep,
3636  unsigned int & index )
3637 #else
3638 fillFunctionParameters ( Q3ListViewItem * parent,
3639  const FunctionRep * frep,
3640  unsigned int & index )
3641 #endif
3642 {
3643  const CompositeFunctionRep * composite
3644  = dynamic_cast < const CompositeFunctionRep * > ( frep );
3645 
3646  if ( composite != 0 ) {
3647  const vector < FunctionRep * > & freps
3648  = composite -> getFunctionReps ();
3649  unsigned int size = freps.size();
3650 
3651  // because children are inserted at the beginning, we must do things
3652  // backwards
3653  for ( int i = size -1; i >= 0; i-- ) {
3654  FunctionRep * rep = freps[i];
3655  const string & func_name = rep -> functionName ();
3656 #if QT_VERSION < 0x040000
3657  QListViewItem * child
3658  = new QListViewItem ( parent );
3659 #else
3660  Q3ListViewItem * child
3661  = new Q3ListViewItem ( parent );
3662 #endif
3663  child -> setOpen ( true );
3664  child -> setText ( Index, QString ( func_name.c_str() ) );
3665  m_function_lv_map [ child ] = rep;
3666 
3667  fillFunctionParameters ( child, rep, index );
3668  }
3669  }
3670  else { // not composite
3671  vector < FunctionParameter > function_parameters;
3672  frep -> fillFunctionParameters ( function_parameters );
3673 
3674  QString qyes( "Yes" );
3675  QString qno( "No" );
3676 
3677  // Because items are inserted at the begining, we must do things
3678  // backwards
3679  unsigned int size = function_parameters.size ();
3680 
3681  for ( int pindex = size-1; pindex >= 0; pindex-- ) {
3682  FunctionParameter fp = function_parameters[pindex];
3683  QString dummy;
3684 #if QT_VERSION < 0x040000
3685  QCheckListItem * item
3686  = new QCheckListItem ( parent, dummy,
3687  QCheckListItem::CheckBox );
3688 #else
3689  Q3CheckListItem * item
3690  = new Q3CheckListItem ( parent, dummy,
3691  Q3CheckListItem::CheckBox );
3692 #endif
3693  item -> setText( Index, QString( "%1" ).arg( index-- ) );
3694 
3695  const string & name = fp.name ();
3696  QString pname = name.c_str();
3697  QString fixedFlag ( qno );
3698  fixedFlag = fp.isFixed () ? qyes : qno;
3699 
3700  item -> setText( Name, QString( "%1" ).arg( pname ) );
3701  item -> setText( Value, QString( "%1" ).arg( fp.value() ) );
3702  item -> setText( Error, QString( "%1" ).arg( fp.error() ));
3703  item -> setText( Fixed, QString( "%1" ).arg( fixedFlag ) );
3704  item -> setText( Dummy, QString( "%1" ).arg( pindex ) );
3705  }
3706  }
3707 }
3708 
3712 void
3715 {
3716  PlotterBase * plotter = getPlotter ();
3717  if ( !plotter ) return ;
3718 
3719  bool yes = plotter -> isTargetable ();
3720  if ( yes == false ) {
3721  multipleDataRepError ( "function" );
3722  return;
3723  }
3724 
3726 
3727  DataRep * datarep = dc -> activeDataRep ( plotter );
3728  assert ( datarep != 0 );
3729 
3730  if ( !datarep->acceptFunction(1) ){
3731  functionAddError ();
3732  return;
3733  }
3734 
3735  // Get the selected function name.
3736 
3738  std::string fun_name = qstr.latin1();
3739 
3740  // Add the function.
3741 
3742  QString s = m_fitter_names -> currentText ( );
3743  const string fit_name = s.latin1();
3744 
3746  yes = fc -> isCompatible ( fun_name, fit_name );
3747 
3748  if ( yes == false ) {
3749  incompatibleFunctionError ( fun_name );
3750  return;
3751  }
3752 
3753  FunctionRep * new_rep = 0;
3754  try {
3755 #if QT_VERSION < 0x040000
3756  QListViewItem * item = m_FunctionParamsListView -> currentItem ();
3757 #else
3758  Q3ListViewItem * item = m_FunctionParamsListView -> currentItem ();
3759 #endif
3760  bool is_selected = m_FunctionParamsListView -> isSelected ( item );
3761  FunctionRep * frep = 0;
3762  if ( is_selected ) {
3763  frep = getTopFunctionRep ( item );
3764  }
3765 
3766  new_rep = fc->addFunction ( plotter, fun_name, frep, datarep );
3767  }
3768  catch ( std::exception & e ) {
3769  badFunctionError ( fun_name, e.what() );
3770  }
3771 
3772  int index = m_fitter_names -> currentItem ();
3773  fitterNamesActivated ( index ); // sets the fitter
3774 
3775  functionsRemoveButton -> setEnabled ( true );
3776  m_IgnoreErrorCheckBox -> setEnabled (true);
3777  functionsFitToDataButton -> setEnabled ( true );
3778  functionsResetButton -> setEnabled ( true );
3779  fc->saveParameters ( plotter );
3780 
3781  bool ok = false;
3782  if ( new_rep != 0 ) {
3783  ok = fc -> tryFitFunction ( plotter, new_rep ); // try fit
3784  }
3785  if ( ! ok ) {
3786  fitFailedError ();
3787  }
3788  // Update other tabs that need it.
3789 
3791 }
3792 
3793 void
3796 {
3798  const vector < string > & names = controller -> getFitterNames ();
3799  const string & def_fitter = names [ index ];
3800  controller -> setDefaultFitter ( def_fitter );
3801 
3802  PlotterBase * plotter = getPlotter ();
3803  if ( plotter != 0 ) {
3804  const DataRep * datarep = plotter -> getTarget ();
3805  bool yes = controller -> hasFunction ( plotter, datarep );
3806  if ( yes ) {
3807  bool ok = controller -> changeFitter ( plotter, datarep,
3808  def_fitter );
3809  if ( ok == false ) {
3810  incompatibleFitterError ( def_fitter );
3811  functionsFitToDataButton -> setEnabled ( false );
3812  }
3813  else {
3814  functionsFitToDataButton -> setEnabled ( true );
3815  }
3816  }
3817  }
3818 }
3819 
3820 void
3823 {
3824  const QString message ( "The Fit failed to converge" );
3825  QMessageBox::critical ( this, // parent
3826  "Fit failed",
3827  message,
3828  QMessageBox::Ok,
3829  Qt::NoButton,
3830  Qt::NoButton );
3831 }
3832 
3833 FunctionRep *
3834 Inspector::
3835 #if QT_VERSION < 0x040000
3837 #else
3838 getTopFunctionRep ( Q3ListViewItem * item )
3839 #endif
3840 {
3841  FunctionRep * rep = 0;
3842  if ( item != 0 ) {
3843  item = getTopParent ( item );
3844  rep = m_function_lv_map [ item ];
3845  }
3846  return rep;
3847 }
3848 
3849 FunctionRep *
3850 Inspector::
3851 #if QT_VERSION < 0x040000
3853 #else
3854 getFunctionRep ( Q3ListViewItem * item )
3855 #endif
3856 {
3857  FunctionRep * rep = 0;
3858  if ( item != 0 ) {
3859  rep = m_function_lv_map [ item ];
3860  }
3861  return rep;
3862 }
3863 
3864 FunctionRep *
3867 {
3868 #if QT_VERSION < 0x040000
3869  QListViewItem * item = m_FunctionParamsListView -> currentItem();
3870 #else
3871  Q3ListViewItem * item = m_FunctionParamsListView -> currentItem();
3872 #endif
3873 
3874  return getTopFunctionRep ( item );
3875 }
3876 
3877 FunctionRep *
3880 {
3881 #if QT_VERSION < 0x040000
3882  QListViewItem * item = m_FunctionParamsListView -> currentItem();
3883 #else
3884  Q3ListViewItem * item = m_FunctionParamsListView -> currentItem();
3885 #endif
3886 
3887  if ( item -> childCount() == 0 ) { // parameter item
3888  item = item -> parent ();
3889  }
3890 
3891  return getFunctionRep ( item );
3892 }
3893 
3894 void
3897 {
3898  PlotterBase * plotter = getPlotter ();
3899  if ( !plotter ) return ;
3900 
3902  if ( ! ( fcnt -> hasFunction ( plotter, 0 ) ) ) { // any function
3903  return;
3904  }
3905 
3906  fcnt -> saveParameters ( plotter );
3907 
3908  FunctionRep * fun_rep = getTopFunctionRep ();
3909 
3910  bool ok = fcnt -> fitFunction ( plotter, fun_rep );
3911  if ( ! ok ) {
3912  fitFailedError ();
3913  }
3914 
3915  // Set the parameters
3917  int index = dcontroller -> activeDataRepIndex ( plotter );
3918 
3919  setParameters ( index, plotter );
3920 }
3921 
3922 void
3925 {
3926  QString text_str = box -> text ();
3927  int i = text_str.find ( "=" );
3928  text_str.remove ( i + 1, 1024 );
3929  box -> setText ( text_str );
3930 }
3931 
3933 {
3934  if ( m_new_plot_box->isEnabled() == false ) return;
3935 
3936  PlotterBase * plotter = getPlotter();
3937  bool yes = plotter == 0;
3938  if ( yes == false ) {
3939  TextPlotter * text = dynamic_cast < TextPlotter * > ( plotter );
3940  yes |= text != 0;
3941  }
3942  bool enable = ! yes;
3943  m_summary->setEnabled ( enable );
3944 
3945  if ( enable == false ) return;
3946 
3948  const DataSource * nt = dcontroller -> getDataSource ( plotter, 0 );
3949 
3950  if ( nt && nt -> empty () ) {
3951  m_summary->setEnabled ( false );
3952  return;
3953  }
3954 
3955  enable = false; // might be changed below...
3956  int index = dcontroller -> activeDataRepIndex ( plotter );
3957  if ( index >= 0 ) {
3958  DataRep * datarep = plotter -> getDataRep ( index );
3960 
3961  enable = controller->hasFunction ( plotter, datarep );
3962  }
3963  if ( enable == false ) {
3964  if ( m_stats_fparms->isChecked () ||
3965  m_stats_chi->isChecked () ) {
3966  m_stats_number->setChecked ( true );
3967  }
3968  }
3969 
3970  m_stats_fparms->setEnabled ( enable );
3971  m_stats_chi->setEnabled ( enable );
3972 
3973  yes = index < 0;
3974 
3975  m_stats_number->setDisabled ( yes );
3976  m_stats_underflow->setDisabled ( yes );
3977  m_stats_overflow->setDisabled ( yes );
3978  m_stats_avg_x->setDisabled ( yes );
3979  m_stats_avg_y->setDisabled ( yes );
3980  m_stats_text->setDisabled ( yes );
3981  yes = m_stats_text -> isChecked ();
3982  m_statsTextField ->setEnabled ( yes );
3983 
3989 
3990  if ( index >= 0 ) {
3991  int number = dcontroller -> getNumberOfEntries ( plotter, index );
3992  QString text = m_stats_number -> text ();
3993  QString str;
3994  str.setNum ( number );
3995  text += " ";
3996  text += str;
3997  m_stats_number -> setText ( text );
3998 
3999  int underflow = dcontroller -> getUnderflow ( plotter, index );
4000  text = m_stats_underflow -> text ();
4001  if ( underflow == -1 ) str = "meaningless";
4002  else str.setNum ( underflow );
4003  text += " ";
4004  text += str;
4005  m_stats_underflow -> setText ( text );
4006 
4007  int overflow = dcontroller -> getOverflow ( plotter, index );
4008  text = m_stats_overflow -> text ();
4009  if ( overflow == -1 ) str = "meaningless";
4010  else str.setNum ( overflow );
4011  text += " ";
4012  text += str;
4013  m_stats_overflow -> setText ( text );
4014 
4015  double average = dcontroller -> getAverage ( plotter, Axes::X, index );
4016  text = m_stats_avg_x -> text ();
4017  str.setNum ( average );
4018  text += " ";
4019  text += str;
4020  m_stats_avg_x -> setText ( text );
4021 
4022  average = dcontroller -> getAverage ( plotter, Axes::Y, index );
4023  text = m_stats_avg_y -> text ();
4024  str.setNum ( average );
4025  text += " ";
4026  text += str;
4027  m_stats_avg_y -> setText ( text );
4028  }
4029 
4030 }
4031 
4032 void
4035 {
4036  bool yes = m_stats_text -> isChecked ();
4037  m_statsTextField -> setEnabled ( yes );
4038 }
4039 
4041 void Inspector::
4043 {
4044  PlotterBase * plotter = getPlotter ();
4045  if ( !plotter ) return;
4046 
4047  DisplayController * d_controller = DisplayController::instance ();
4048  int index = d_controller->activeDataRepIndex ( plotter );
4049  if ( index < 0 ) {
4050  multipleDataRepError ( "summary" );
4051  return;
4052  }
4053 
4055 
4056  string nullstring ("");
4057 
4058  if ( m_stats_number->isChecked() )
4059  {
4060  const string s ("Total Entries");
4061  canvas->addTextDisplay ( plotter, s, nullstring );
4062  }
4063 
4064  else if ( m_stats_underflow->isChecked() )
4065  {
4066  const string s ("Underflow");
4067  canvas->addTextDisplay ( plotter, s, nullstring );
4068  }
4069 
4070  else if ( m_stats_overflow->isChecked() )
4071  {
4072  const string s ("Overflow");
4073  canvas->addTextDisplay ( plotter, s, nullstring );
4074  }
4075 
4076  else if ( m_stats_avg_x->isChecked() )
4077  {
4078  const string s ("averagex");
4079  canvas->addTextDisplay ( plotter, s, nullstring );
4080  }
4081 
4082  else if ( m_stats_avg_y->isChecked() )
4083  {
4084  const string s ("averagey");
4085  canvas->addTextDisplay ( plotter, s, nullstring );
4086  }
4087 
4088  else if ( m_stats_fparms->isChecked() )
4089  {
4090  const string s ("Function Parameters");
4092  assert ( controller -> hasFunction ( plotter, 0 ) );
4093  canvas->addFuncDisplay ( plotter, s );
4094 
4095  }
4096 
4097  else if ( m_stats_chi->isChecked() )
4098  {
4099  const string s ("Chi-squared");
4101  assert ( controller -> hasFunction ( plotter, 0 ) );
4102  canvas->addFuncDisplay ( plotter, s );
4103 
4104  }
4105 
4106  else if ( m_stats_text->isChecked() )
4107  {
4108 
4109  QString qtext = m_statsTextField->text();
4110  const string t = qtext.latin1();
4111  bool needMargin = String::ci_find(t, "tex:")==0;
4112  if ( needMargin ) {
4113 #ifdef HAVE_TEX_UTILS
4114 #else
4115  qtext.remove (0, 4);
4116  warningTex ();
4117 #endif
4118  }
4119  string text (qtext.latin1());
4120  const string s ("Text From Box");
4121  canvas->addTextDisplay ( plotter, s, text );
4122  }
4123 }
4124 
4128 {
4129  PlotterBase * plotter = getPlotter ();
4130  if ( plotter == 0 ) return;
4131 
4132  FunctionRep * func_rep = getTopFunctionRep ();
4134  PlotterBase * res_plotter
4135  = controller -> createResidualsDisplay ( plotter, func_rep );
4136  const Range & range = plotter -> getRange ( Axes::X, false );
4137  res_plotter -> setRange ( Axes::X, range, false );
4138 
4139  CanvasWindow * canvas = WindowController::instance () -> currentCanvas ();
4140 
4141  canvas -> addPlotDisplay ( res_plotter, true );
4142 }
4143 
4144 void Inspector::
4146 {
4147  m_func_parm_checked.clear ();
4148 
4149 #if QT_VERSION < 0x040000
4151 #else
4152  Q3ListViewItemIterator it ( m_FunctionParamsListView );
4153 #endif
4154  while ( it.current () ) {
4155 #if QT_VERSION < 0x040000
4156  QListViewItem * item = it.current ();
4157  QCheckListItem * check_item = dynamic_cast < QCheckListItem * > ( item );
4158 #else
4159  Q3ListViewItem * item = it.current ();
4160  Q3CheckListItem * check_item = dynamic_cast < Q3CheckListItem * > ( item );
4161 #endif
4162  if ( check_item != 0 ) {
4163  bool yes = check_item -> isOn ();
4164  if ( yes ) {
4165  m_func_parm_checked.push_back ( item );
4166  }
4167  }
4168  ++it;
4169  }
4170 }
4171 
4176 void
4179 {
4180  PlotterBase * plotter = getPlotter ();
4181  if ( plotter == 0 ) return;
4182 
4184 
4186  if ( m_func_parm_checked.size () != 2 ) {
4187  const QString
4188  message ( "Two and only two function parameters should be\n"
4189  "checked to create error contour display.\n" );
4190  QMessageBox::critical( this, // parent
4191  "Invalid parameter pair selection", // caption
4192  message,
4193  QMessageBox::Ok,
4194  Qt::NoButton,
4195  Qt::NoButton );
4196  return;
4197  }
4198 
4199 #if QT_VERSION < 0x040000
4200  QListViewItem * first = m_func_parm_checked[0];
4201  QListViewItem * second = m_func_parm_checked[1];
4202 #else
4203  Q3ListViewItem * first = m_func_parm_checked[0];
4204  Q3ListViewItem * second = m_func_parm_checked[1];
4205 #endif
4206  if ( getTopParent ( first ) != getTopParent ( second ) ) {
4207  const QString message =
4208  "Both checked function parameters must\n"
4209  "have same parent function.";
4210  QMessageBox::critical( this, // parent
4211  "Invalid parameter pair selection", // caption
4212  message,
4213  QMessageBox::Ok,
4214  Qt::NoButton,
4215  Qt::NoButton );
4216  return;
4217  }
4218  QString text = first -> text ( Index );
4219  bool ok = true;
4220  int index = text.toInt ( & ok ) - 1;
4221  fcontroller -> setEllpsoidParamIndex ( Axes::X , index );
4222 
4223  text = second -> text ( Index );
4224  ok = true;
4225  index = text.toInt ( & ok ) -1 ;
4226  fcontroller -> setEllpsoidParamIndex ( Axes::Y , index );
4227 
4228  // Create / refresh the error plot
4229  const QString xlabel = first -> text ( Name );
4230  const QString ylabel = second -> text ( Name );
4231  QString stat = m_PushButtonNewErrorPlot -> text();
4232 #if QT_VERSION < 0x040000
4233  QListViewItem * parent = getTopParent ( first );
4234 #else
4235  Q3ListViewItem * parent = getTopParent ( first );
4236 #endif
4237  FunctionRep * frep = m_function_lv_map [ parent ];
4238  if( stat == QString( "Change Error Plot" ) )
4239  {
4240  fcontroller -> refreshEllipsoidDisplay ( plotter, frep );
4241  plotter -> setLabel( Axes::X, xlabel.latin1() );
4242  plotter -> setLabel( Axes::Y, ylabel.latin1() );
4243  }
4244  else // "New Error Plot"
4245  {
4246  PlotterBase * err_plotter =
4247  fcontroller -> createNewEllipsoidDisplay ( plotter, frep );
4248  assert( err_plotter != 0);
4249 
4250  err_plotter -> setLabel( Axes::X, xlabel.latin1() );
4251  err_plotter -> setLabel( Axes::Y, ylabel.latin1() );
4252 
4253  CanvasWindow * canvas
4254  = WindowController::instance () -> currentCanvas ();
4255  assert( canvas != 0 );
4256 
4257  // Add the plot to the display BUT donot select it. Let mother
4258  // plot be the one which is selected.
4259  canvas -> addPlotDisplay ( err_plotter, false );
4260  }
4261 }
4262 
4263 const std::string
4266 {
4267  if ( axis == Axes::X ) return "X";
4268  else if ( axis == Axes::Y ) return "Y";
4269  else if ( axis == Axes::Z ) return "Z";
4270 
4271  return "nil";
4272 }
4273 
4274 void
4277 {
4278  bool yes = m_plotter_list.empty () == false;
4279 
4280  logScale -> setEnabled ( yes );
4281  if ( yes ) {
4282  PlotterBase * plotter = m_plotter_list.front ();
4283  bool log = DisplayController::instance () -> getLog ( plotter, m_axis );
4284  logScale -> setChecked ( log );
4285  }
4286 }
4287 
4288 void
4291 {
4292  bool yes = m_plotter_list.empty () == false;
4293  m_autoScale -> setEnabled ( yes );
4294  if ( yes ) {
4295  PlotterBase * plotter = m_plotter_list.front ();
4296  bool scaled = plotter -> isAutoRanging ( m_axis );
4297  m_autoScale -> setChecked ( scaled );
4298  }
4299 }
4300 
4301 void
4304 {
4305  bool yes = ( m_plotter_list.empty () == false )
4306  && ( m_axis == Axes::X );
4307  m_reverse -> setEnabled ( yes );
4308 
4309  if ( yes ) {
4310  PlotterBase * plotter = m_plotter_list.front ();
4311  bool reversed = plotter -> isReverse ();
4312  m_reverse -> setChecked ( reversed );
4313  }
4314 }
4315 
4322 void
4325 {
4326  updateLogBox ();
4327  updateAutoScaleBox ();
4328  updateReverseBox ();
4329 
4330  PlotterBase * plotter = getPlotter ();
4331  bool yes = plotter == 0;
4332  if ( yes == false ) {
4333  TextPlotter * text = dynamic_cast < TextPlotter * > ( plotter );
4334  yes |= text != 0;
4335  }
4336  m_axis_frame->setEnabled ( ! yes );
4337 
4338  if ( yes ) return;
4339 
4341  int index = -1;
4342  if ( plotter -> isTargetable () ) {
4343  index = controller->activeDataRepIndex ( plotter );
4344  }
4345 
4346  bool has_ntuple = controller->hasNTupleBindings ( plotter, 0 );
4347  if ( has_ntuple )
4348  {
4349  const DataSource * nt
4350  = DisplayController::instance() -> getDataSource ( plotter, 0 );
4351  if ( nt && nt -> empty () ) return;
4352  }
4353 
4354  if ( plotter -> hasAxis ( m_axis ) == false ) setZRadioButton ( false );
4355 
4356  const string & label = plotter -> getLabel ( m_axis );
4357  const QString ltext = label.c_str();
4358  m_axis_label -> setText ( ltext );
4359 
4360  const string s_axis = convertToString ( m_axis );
4361  bool axis_bined = controller -> isAxisBinned ( plotter, s_axis );
4362  const Range & r = plotter->getRange(m_axis, true);
4363  double low = r.low();
4364  double high = r.high();
4365 
4366  axisWidget1 -> setLowText ( QString("%1").arg(low),
4367  axis_bined == true &&
4368  has_ntuple == false );
4369  axisWidget1 -> setHighText ( QString("%1").arg(high),
4370  axis_bined == true &&
4371  has_ntuple == false );
4372 
4373  axisWidget1 -> setLowSliderValue( 50 );
4374  m_lowslider1_last_val = 50;
4375  axisWidget1 -> setHighSliderValue( 50 );
4377 
4378  if (getMinEntries()==-1) {
4379  m_combine_checkbox->setEnabled( false );
4380  min_entries_text->setEnabled ( false );
4381  min_entries_slider->setEnabled ( false );
4382  }
4383 
4384  else {
4385  m_combine_checkbox->setEnabled( true );
4386 
4387  if ( m_combine_checkbox->isChecked() )
4388  {
4389  min_entries_text->setEnabled ( true );
4390  min_entries_slider->setEnabled ( true );
4391  unsigned int min = getMinEntries();
4392  min_entries_text->setText( QString ("%1").arg(min) );
4394  }
4395  else
4396  {
4397  min_entries_text->setEnabled ( false );
4398  min_entries_slider->setEnabled ( false );
4399  unsigned int min = getMinEntries();
4400  min_entries_text->setText( QString ("%1").arg(min) );
4401  min_entries_slider->setValue ( 50 );
4402  }
4403  }
4404 
4405 
4406 
4407 
4408  if ( axis_bined == false )
4409  {
4410  m_width_text->setEnabled ( false );
4411  m_width_range->setEnabled ( false );
4412  m_width_text -> setText ( QString ("%1").arg (0) );
4413 
4414  m_offset_text->setEnabled ( false );
4415  m_offset_range->setEnabled ( false );
4416  m_offset_text -> setText ( QString ("%1").arg (0) );
4417  }
4418  else
4419  {
4420  m_width_text->setEnabled ( true );
4421  m_width_range->setEnabled ( true );
4422  double width = plotter->getBinWidth ( m_axis );
4423  m_width_text -> setText ( QString ("%1").arg (width) );
4424 
4425  m_offset_text->setEnabled ( true );
4426  m_offset_range->setEnabled ( true );
4427  double offset = plotter->getOffset ( m_axis );
4428  m_offset_text -> setText ( QString ("%1").arg (offset) );
4429 
4430  // make read only if not bound to ntuple
4431  m_width_text->setReadOnly ( ! has_ntuple );
4432  m_width_range->setEnabled ( has_ntuple );
4433  m_offset_text->setReadOnly ( ! has_ntuple );
4434  m_offset_range->setEnabled ( has_ntuple );
4435  }
4436 
4437  //----------------------------//
4438  // Handling the log check box //
4439  //----------------------------//
4440  bool disable_log = has_ntuple == false && axis_bined == true;
4441  logScale -> setDisabled ( disable_log );
4442  m_autoScale -> setDisabled ( disable_log );
4443 
4444  const PeriodicBinaryTransform *pbtf =
4445  dynamic_cast < const PeriodicBinaryTransform * >
4446  ( plotter->getTransform() );
4447 
4448  if( pbtf == 0 ) {
4449  bool log = DisplayController::instance() -> getLog ( plotter, m_axis );
4450 
4451  if( log )
4452  {
4453  m_offset_text -> setEnabled( false );
4454  m_offset_range -> setEnabled( false );
4455  }
4456  }
4457 
4458 
4459  axisWidget1->setAllDisabled ( false );
4460 
4461  //--------------------------------//
4462  // Handling of zoom pan check box //
4463  //--------------------------------//
4464  bool isZoomPan = false;
4465 
4466  std::map < const PlotterBase *, bool >::const_iterator it
4467  = m_zoompan.find ( plotter );
4468  if ( it != m_zoompan.end () )
4469  isZoomPan = it->second;
4470 
4471  // By defalut for periodic binary transforms (pbtf) zoom pan mode should
4472  // be set for both X and Y axis. For Z axis setting zoom pan mode does
4473  // not make sense.
4474  if( pbtf != 0 && m_axis != Axes::Z) {
4475  axisWidget1->setZoomPan ( true, true );
4476  }
4477  else {
4478  if ( m_axis == Axes::Z ) {
4479  axisWidget1 -> setZoomPan ( false, true ); //disables it
4480  }
4481  else {
4482  axisWidget1->setZoomPan ( isZoomPan );
4483  }
4484  }
4485 
4487 
4488  yes = false;
4489  if ( index >= 0 ) {
4490  const DataRep * datarep = plotter -> getDataRep ( index );
4491  RepBase * rep = datarep -> getRepresentation ();
4492  ContourPointRep * contourRep = dynamic_cast < ContourPointRep * > ( rep );
4493  yes = contourRep != 0;
4494  if ( yes ) {
4495  bool user = contourRep->getUsingUserValues();
4496  contourRadioButton1->setChecked ( !user );
4497  contourRadioButton2->setChecked ( user );
4498  contourRadioButton1_toggled ( true );
4499  }
4500  }
4501 
4502  m_contourBox->setEnabled ( yes );
4503 }
4504 
4505 
4509 #if QT_VERSION < 0x040000
4511 #else
4513 #endif
4514 {
4515 #if QT_VERSION < 0x040000
4516  QListViewItem * item = m_FunctionParamsListView -> currentItem ();
4517 #else
4518  Q3ListViewItem * item = m_FunctionParamsListView -> currentItem ();
4519 #endif
4520  bool is_selected = m_FunctionParamsListView -> isSelected ( item );
4521  bool is_parm = item -> childCount () == 0;
4522  bool enable = is_selected && is_parm;
4523 
4524  m_FunctionParamsCheckBox -> setEnabled ( enable );
4525  m_FunctionParamsLineEdit -> setEnabled ( enable );
4526  m_FunctionParamsSlider -> setEnabled ( enable );
4527 
4528  if ( enable ) {
4529  QString fixedFlag = item -> text( Fixed );
4530  QString qyes( "Yes" );
4532  setChecked(( fixedFlag == qyes ) ? true : false );
4533  m_FunctionParamsLineEdit -> setText ( item -> text( Value ) );
4534  }
4535 
4536  enable = is_selected && (! is_parm);
4537  functionsRemoveButton -> setEnabled ( enable );
4538 
4539 }
4540 #if QT_VERSION < 0x040000
4541 QListViewItem *
4544 {
4545  QListViewItem * parent = item;
4546  while ( true ) {
4547  QListViewItem * t = parent -> parent ();
4548  if ( t == 0 ) break;
4549  parent = t;
4550  }
4551 #else
4552 Q3ListViewItem *
4554 getTopParent ( Q3ListViewItem * item )
4555 {
4556  Q3ListViewItem * parent = item;
4557  while ( true ) {
4558  Q3ListViewItem * t = parent -> parent ();
4559  if ( t == 0 ) break;
4560  parent = t;
4561  }
4562 #endif
4563  return parent;
4564 }
4565 
4568 void
4571 {
4572  PlotterBase * plotter = getPlotter();
4573  if ( !plotter ) return;
4574 
4576  if ( ! ( fcontroller -> hasFunction ( plotter, 0 ) ) ) {
4577  return;
4578  }
4579 
4580  fcontroller -> saveParameters ( plotter );
4581 
4582 #if QT_VERSION < 0x040000
4583  QListViewItem * item = m_FunctionParamsListView -> currentItem();
4584 #else
4585  Q3ListViewItem * item = m_FunctionParamsListView -> currentItem();
4586 #endif
4587  if( !item ) return;
4588 
4589  FunctionRep * frep = getTopFunctionRep ( item );
4590 
4591  vector < int > fixed = frep -> getFixedFlags ();
4592 
4593  QString pidx = item -> text( Index ); // As a hack we hide in the 5th place
4594  int paramindex = pidx.toUInt() - 1; // the index of the parameter
4595 
4596  // Set the new fixed flag for the function
4597  bool flag = m_FunctionParamsCheckBox -> isChecked();
4598 
4599  fixed[ paramindex ] = flag == true ? 1 : 0;
4600  frep -> setFixedFlags( fixed );
4601 
4602  if ( item -> childCount () == 0 ) {
4603  QString qyes ( "Yes" );
4604  QString qno ( "No" );
4605  QString fixedFlag = ( flag == true ) ? qyes : qno;
4606  item -> setText ( Fixed, fixedFlag );
4607  }
4608 
4609 }
4610 
4611 
4616 {
4617  // Check if there is plotter.
4618  PlotterBase * plotter = getPlotter();
4619  if ( !plotter ) return;
4620 
4621  // Check if there is a function attached to this plotter.
4623  if ( ! ( fcontroller -> hasFunction ( plotter, 0 ) ) )
4624  return;
4625 
4626  // Save old parameters
4627  fcontroller -> saveParameters ( plotter );
4628 
4629  // Get the current item and item-number
4630 #if QT_VERSION < 0x040000
4631  QListViewItem * item = m_FunctionParamsListView -> currentItem();
4632 #else
4633  Q3ListViewItem * item = m_FunctionParamsListView -> currentItem();
4634 #endif
4635  if( !item ) return;
4636 
4637  QString pidx = item -> text( Index );
4638  int paramindex = pidx.toUInt() -1; // the index of the parameter
4639 
4640  FunctionRep * frep = getTopFunctionRep ( item );
4641  vector < double > parameters = frep-> parameters();
4642 
4643  // Set the new fixed flag for the function
4644  QString text = m_FunctionParamsLineEdit -> text();
4645  parameters[ paramindex ] = text.toDouble();
4646  frep -> setParameters( parameters );
4647  frep -> setDirty();
4648 
4649  // Change the new parameter in ListView
4650  item -> setText ( Value, QString ( "%1" ).arg ( parameters[ paramindex ] ) );
4651 }
4652 
4653 
4657 void
4660 {
4661  PlotterBase * plotter = getPlotter();
4662  if ( !plotter ) return;
4663 
4665  if ( ! ( fcontroller -> hasFunction ( plotter, 0 ) ) )
4666  return;
4667 
4668  // Save old parameters
4669  fcontroller -> saveParameters ( plotter );
4670 
4671  FunctionRep * frep = getTopFunctionRep ( );
4672 
4673  if ( frep != 0 ) {
4674  m_oldParameters = frep -> parameters ();
4675  }
4676 }
4677 
4678 
4682 void
4685 {
4686  PlotterBase * plotter = getPlotter();
4687  if ( !plotter ) return;
4688 
4690  if ( ! ( fcontroller -> hasFunction ( plotter, 0 ) ) )
4691  return;
4692 
4693 #if QT_VERSION < 0x040000
4694  QListViewItem * item = m_FunctionParamsListView -> currentItem();
4695 #else
4696  Q3ListViewItem * item = m_FunctionParamsListView -> currentItem();
4697 #endif
4698 
4699  if( !item ) return;
4700 
4701  QString pidx = item -> text( Index );
4702  int paramindex = pidx.toUInt() - 1; // the index of the parameter
4703 
4704  vector < double > newParameters = m_oldParameters;
4705 
4706  int sliderValue = m_FunctionParamsSlider -> value();
4707  int sign = ( m_oldParameters[ paramindex ] < 0 )? -1:1;
4708 
4709  newParameters[ paramindex ]
4710  = m_oldParameters[ paramindex ] *
4711  pow ( 2.0, static_cast<double>( (sliderValue - 50) * sign) / 50.0 );
4712 
4713  FunctionRep * frep = getTopFunctionRep ( item );
4714  frep -> setParameters( newParameters ); // will set projector dirty
4715 
4716  item -> setText( Value, QString ( "%1" ).arg ( newParameters[ paramindex ]));
4718  setText ( QString ( "%1" ).arg ( newParameters[ paramindex ] ) );
4719 }
4720 
4723 void
4726 {
4727  m_FunctionParamsSlider -> setValue(50);
4728 }
4729 
4730 void
4732 invalidOperationError ( const string & message )
4733 {
4734  QMessageBox::critical ( this, // parent )
4735  "Operation error", // caption
4736  message.c_str(), // message
4737  QMessageBox::Ok,
4738  Qt::NoButton,
4739  Qt::NoButton );
4740 }
4741 
4746 {
4747  bool log = logScale -> isChecked();
4748  bool auto_scale = m_autoScale -> isChecked ();
4749 
4750  vector < PlotterBase * > ::iterator first = m_plotter_list.begin ();
4751 
4752  while ( first != m_plotter_list.end () ) {
4753  PlotterBase * plotter = *first++;
4754  try {
4755  DisplayController::instance()-> setLog ( plotter, m_axis, log );
4756  plotter -> setAutoRanging ( m_axis, auto_scale );
4757  }
4758  catch ( const runtime_error & e ) {
4759  invalidOperationError ( e.what () );
4760  }
4761  }
4762 
4763  updateAxisTab ();
4764 }
4765 
4767 {
4768  bool reverse = m_reverse -> isChecked();
4769 
4770  vector < PlotterBase * > ::iterator first = m_plotter_list.begin ();
4771 
4772  while ( first != m_plotter_list.end () ) {
4773  PlotterBase * plotter = *first++;
4774  plotter -> setReverse ( reverse );
4775  }
4776 
4777  updateAxisTab ();
4778 }
4779 
4781 {
4782  bool scale = m_autoScale -> isChecked ();
4783  vector < PlotterBase * > ::iterator first = m_plotter_list.begin ();
4784 
4785  while ( first != m_plotter_list.end () ) {
4786  PlotterBase * plotter = *first++;
4787  plotter -> setAutoRanging ( m_axis, scale );
4788 
4789  // If the transform be periodic it sets both the offsets to be 0.0
4791  dynamic_cast< PeriodicBinaryTransform* > ( plotter->getTransform() );
4792  if ( tp != 0 )
4793  {
4794  tp->setXOffset( 0.0 );
4795  tp->setYOffset( 0.0 );
4796  }
4797  }
4798 
4799  updateAxisTab();
4800 }
4801 
4803 {
4804  if ( m_is_updating == false ) {
4805  int index = m_selCutComboBox -> currentItem ();
4806  Range currentRange = m_tuple_cuts [ index] -> getRange ();
4807  int id = cutRadioId ();
4808  bool fit_cut = id == 2;
4809 
4810  if ( fit_cut == false ) { //data cut
4811  Axes::Type axis = getAxes ( index );
4812  PlotterBase * plotter = getSelectedCut();
4813  const Range & fullRange = plotter -> getRange ( axis, false );
4814  axisWidget2 -> processHighSliderMoved ( value, currentRange, fullRange );
4815  plotter -> setCutRangeAt ( currentRange, axis );
4816  }
4817  else { // fit cut
4818  PlotterBase * plotter = getPlotter ();
4819  const Range & fullRange = plotter -> getRange ( Axes::X, false );
4820  axisWidget2 -> processHighSliderMoved ( value, currentRange, fullRange );
4821  plotter -> setCutRangeAt ( currentRange, index );
4822  }
4823  }
4824 }
4825 
4827 {
4828  if ( m_is_updating == false ) {
4829  int index = m_selCutComboBox -> currentItem ();
4830  Range currentRange = m_tuple_cuts [ index ] -> getRange ();
4831 
4832  bool fit_cut = cutRadioId () == 2;
4833 
4834  if ( fit_cut == false ) { //data cut
4835  Axes::Type axis = getAxes ( index );
4836  PlotterBase * plotter = getSelectedCut();
4837  const Range & fullRange = plotter -> getRange ( axis, false );
4838  axisWidget2 -> processLowSliderMoved ( value, currentRange, fullRange );
4839  plotter -> setCutRangeAt ( currentRange, axis );
4840  }
4841  else { // fit cut
4842  PlotterBase * plotter = getPlotter ();
4843  const Range & fullRange = plotter -> getRange ( Axes::X, false );
4844  axisWidget2 -> processLowSliderMoved ( value, currentRange, fullRange );
4845  plotter -> setCutRangeAt ( currentRange, index );
4846  }
4847  }
4848 }
4849 
4851 {
4852  PlotterBase * cd = getSelectedCut();
4853  if ( cd == 0 ) return;
4854  int index = m_selCutComboBox -> currentItem ();
4855  Axes::Type axis = getAxes ( index );
4856  const Range & fullRange = cd->getRange ( axis, false );
4857  axisWidget2->processLowSliderReleased ( fullRange );
4858 }
4859 
4861 {
4862  PlotterBase * cd = getSelectedCut();
4863  if ( cd == 0 ) return;
4864  int index = m_selCutComboBox -> currentItem ();
4865  Axes::Type axis = getAxes ( index );
4866  const Range & fullRange = cd->getRange ( axis, false );
4867  axisWidget2->processHighSliderReleased ( fullRange );
4868 }
4869 
4871 {
4872  PlotterBase * plotter = getSelectedCut();
4873 
4874  int index = m_selCutComboBox -> currentItem ();
4875  int id = cutRadioId ();
4876  bool fit_cut = id ==2;
4877 
4878  Axes::Type axis = Axes::X;
4879  if ( fit_cut == false ) {
4880  axis = getAxes ( index );
4881  }
4882  bool yes = axisWidget2 -> isZoomPanChecked ();
4883  CutController * controller = CutController::instance ();
4884  controller -> setZoomPan ( plotter, axis, yes );
4885 
4886  Range currentRange = m_tuple_cuts [ index ] -> getRange ();
4887  const Range & fullRange = plotter -> getRange ( axis, false );
4888 
4889  axisWidget2 -> processZoomPanCheckBoxClicked ( currentRange, fullRange ) ;
4890 }
4891 
4892 
4894 {
4895  int id = cutRadioId ();
4896  bool fit_cut = id == 2;
4897 
4898  if ( fit_cut == false ) { //data cut
4899  PlotterBase * plotter = getSelectedCut ();
4900  CutPlotter * cp = dynamic_cast < CutPlotter * > ( plotter );
4901  cp -> toggleInverted ();
4902  }
4903  else {
4904  int index = m_selCutComboBox -> currentItem ();
4905  bool state = ! m_tuple_cuts [ index ] -> getInversion ();
4906  PlotterBase * plotter = getPlotter ();
4907  XyPlotter * xyplotter = dynamic_cast < XyPlotter * > ( plotter );
4908  xyplotter -> setCutInverted ( index, state );
4909  }
4910 }
4911 
4912 void
4915 {
4916  if ( m_cut_enable_updating == true ) return;
4917 
4918  bool fit_cut = cutRadioId () == 2;
4919 
4920  if ( fit_cut == false ) { //data cut
4921  PlotterBase * plotter = getSelectedCut ();
4922  CutPlotter * cut_plotter = dynamic_cast < CutPlotter * > ( plotter );
4923  cut_plotter -> setEnabled ( ! on );
4924  }
4925  else {
4926  int index = m_selCutComboBox -> currentItem ();
4927  PlotterBase * plotter = getPlotter ();
4928  XyPlotter * xyplotter = dynamic_cast < XyPlotter * > ( plotter );
4929  xyplotter -> setCutEnabled ( index, ! on );
4930  }
4931 }
4932 
4933 void
4936 {
4937  int id = cutRadioId ();
4938  bool fit_cut = id == 2;
4939  if ( fit_cut ) {
4940  }
4941  else {
4942  PlotterBase * cplotter = getSelectedCut();
4943  CutPlotter * cp = dynamic_cast < CutPlotter * > ( cplotter );
4944 
4945  const Color & rep_color = cp -> getCutColor ();
4946  QColor color ( rep_color.getRed(),
4947  rep_color.getGreen(),
4948  rep_color.getBlue () );
4949 
4950  color = QColorDialog::getColor ( color );
4951 
4952  if ( color.isValid() == true ) {
4953  Color c( color.red(), color.green(), color.blue() );
4954  cp -> setCutColor ( c );
4955  }
4956  }
4957 }
4958 
4959 void
4962 {
4963 
4964  PlotterBase * plotter = getPlotter ();
4965  if ( !plotter ) return;
4967  int index = controller->activeDataRepIndex ( plotter );
4968  DataRep * datarep = plotter->getDataRep ( index );
4969 
4970  RepBase * rep = datarep->getRepresentation();
4971  ContourPointRep * contourRep = dynamic_cast < ContourPointRep * > ( rep );
4972 
4973  if ( !contourRep ) return;
4974 
4975  contourRep->setUsingUserValues ( false );
4976  contourRep->setNumContours ( val );
4977  m_numContoursTextBox->setText ( QString("%1").arg ( val ) );
4978 
4979  datarep->notifyObservers();
4980 
4981 }
4982 
4983 void
4986 {
4987 
4988  PlotterBase * plotter = getPlotter ();
4989  if ( !plotter ) return;
4991  int index = controller->activeDataRepIndex ( plotter );
4992  DataRep * datarep = plotter->getDataRep ( index );
4993 
4994  RepBase * rep = datarep->getRepresentation();
4995  ContourPointRep * contourRep = dynamic_cast < ContourPointRep * > ( rep );
4996 
4997  if ( !contourRep ) return;
4998 
4999  QString text = m_numContoursTextBox->text();
5000  int val = text.toInt();
5001 
5002  if ( val < 1 || val > 100 ) {
5003  int num = contourRep->getNumContours ();
5004  m_numContourSlider->setValue ( num );
5005  m_numContoursTextBox->setText ( QString ("%1").arg ( num ) );
5006  return;
5007  }
5008 
5009  contourRep->setUsingUserValues ( false );
5010  contourRep->setNumContours ( val );
5011  m_numContourSlider->setValue ( val );
5012 
5013  datarep->notifyObservers();
5014 
5015 }
5016 
5017 void
5020 {
5021  PlotterBase * plotter = getPlotter ();
5022  if ( !plotter ) return;
5023  if ( plotter -> isTargetable () == false ) return;
5024 
5025  DataRep * datarep = plotter -> getTarget ( );
5026  RepBase * rep = datarep->getRepresentation();
5027 
5028  ContourPointRep * contourRep = dynamic_cast < ContourPointRep * > ( rep );
5029 
5030  if ( !contourRep ) return;
5031 
5032  if ( contourRadioButton1->isChecked() ) {
5033 
5034  m_numContourSlider->setEnabled ( true );
5035  m_numContoursTextBox->setEnabled ( true );
5036  m_numContoursLabel->setEnabled ( true );
5037  m_contourLevelsTextBox->setEnabled ( false );
5038 
5039  int num = contourRep->getNumContours ();
5040  m_numContourSlider->setValue ( num );
5041  m_numContoursTextBox->setText ( QString ("%1").arg ( num ) );
5042 
5044 
5045  }
5046 
5047  else {
5048 
5049  m_numContourSlider->setEnabled ( false );
5050  m_numContoursTextBox->setEnabled ( false );
5051  m_numContoursLabel->setEnabled ( false );
5052  m_contourLevelsTextBox->setEnabled ( true );
5053 
5055 
5056  }
5057 
5058 }
5059 
5060 void
5063 {
5064 // const QString message =
5065 // "Invalid Input String. Please check that\n"
5066 // "1. The string contains only numbers separated by white spaces, and,\n"
5067 // "2. The numbers are in increasing order without any duplicates.\n";
5068  const QString message =
5069  "Invalid Input String.\n"
5070  "Please check that the string contains only numbers,\n"
5071  "separated by commas or white space.\n";
5072  QMessageBox::critical ( this, // parent
5073  "Invalid Input String", // caption
5074  message,
5075  QMessageBox::Ok,
5076  Qt::NoButton,
5077  Qt::NoButton );
5078 }
5079 
5080 void
5083 {
5084  if ( contourRadioButton2->isChecked () == false ) return;
5085 
5086  PlotterBase * plotter = getPlotter ();
5087  if ( !plotter ) return;
5089  int index = controller->activeDataRepIndex ( plotter );
5090  DataRep * datarep = plotter->getDataRep ( index );
5091 
5092  RepBase * rep = datarep->getRepresentation();
5093  ContourPointRep * contourRep = dynamic_cast < ContourPointRep * > ( rep );
5094 
5095  if ( !contourRep ) return;
5096 
5097  const QString qstr1 = m_contourLevelsTextBox->text();
5098  if ( qstr1.isEmpty () ) return;
5099 
5100  const QString qstr2 = qstr1.simplifyWhiteSpace();
5101 
5102  vector < double > values;
5103 
5104 // Get a std::string from the QString.
5105 #if QT_VERSION < 0x040000
5106  std::string contourLevels(qstr2.ascii());
5107 #else
5108  std::string contourLevels(qstr2.toAscii());
5109 #endif
5110 
5111 // Break string into components; convert and validate each value.
5112  std::vector<std::string> tokens;
5113  stringTokenize(contourLevels, " \t,", tokens);
5114  for (size_t i = 0; i < tokens.size(); i++) {
5115  QString strval(tokens.at(i).c_str() );
5116  bool ok(true);
5117  double value(strval.toDouble(&ok));
5118  if (!ok) {
5119  contourError();
5120  return;
5121  }
5122  values.push_back(value);
5123  }
5124 
5125 // Sort and remove duplicates.
5126  std::stable_sort(values.begin(), values.end());
5127  vector<double>::iterator leftover =
5128  std::unique(values.begin(), values.end());
5129  values.erase(leftover, values.end());
5130 
5131  contourRep->setContourValues ( values, datarep->getProjector() );
5132  datarep->notifyObservers();
5133 }
5134 
5136 {
5137  PlotterBase * plotter = getPlotter ();
5138  if ( !plotter ) return ;
5139 
5140  QFont labelFont;
5141  bool ok;
5142 
5143  XyPlotter * xyplotter = dynamic_cast < XyPlotter * > ( plotter );
5144  assert ( xyplotter != 0 );
5145 
5146  const FontBase * fb = xyplotter -> labelFont ( m_axis );
5147  if ( fb == 0 ) {
5148  labelFont = QFontDialog::getFont ( &ok, this);
5149  }
5150  else {
5151  const QtFont * qtfont = dynamic_cast < const QtFont * > ( fb );
5152  const QFont & qfont = qtfont -> font ();
5153  labelFont = QFontDialog::getFont ( &ok, qfont, this);
5154  }
5155 
5156  if ( ok )
5157  {
5158  QtFont * font = new QtFont;
5159  font -> setFont( labelFont );
5160  xyplotter -> setLabelFont( font, m_axis );
5161 
5162  /* The size of drawrect, marginrect, need to be updated
5163  according to new font.
5164  */
5165  xyplotter -> setNeedUpdate(true);
5166  xyplotter -> notifyObservers ();
5167  }
5168 }
5169 
5171 {
5172  PlotterBase * plotter = getPlotter ();
5173  if ( plotter == 0 ) return ;
5174 
5175  XyPlotter * xyplotter = dynamic_cast< XyPlotter* > ( plotter );
5176  assert( xyplotter != 0 );
5177 
5178  QFont titleFont;
5179  bool ok;
5180 
5181  const FontBase * fb = xyplotter -> titleFont ();
5182  if ( fb == 0 ) {
5183  // From the Qt documentation - "The usual way to use QFontDialog class is
5184  // to call one of the static convenience functions"
5185  titleFont = QFontDialog::getFont ( &ok, this );
5186  }
5187  else {
5188  const QtFont * qtfont = dynamic_cast < const QtFont * > ( fb );
5189  const QFont & qfont = qtfont -> font ();
5190  titleFont = QFontDialog::getFont ( &ok, qfont, this );
5191  }
5192 
5193  if ( ok )
5194  {
5195  QtFont * font = new QtFont;
5196  font -> setFont( titleFont );
5197  xyplotter -> setTitleFont( font );
5198 
5199  /* The size of drawrect, marginrect, need to be updated
5200  according to new font.
5201  */
5202  xyplotter -> setNeedUpdate(true);
5203  xyplotter -> notifyObservers ();
5204  }
5205 }
5206 
5207 
5209 {
5210  // Check if there is plotter.
5211  PlotterBase * plotter = getPlotter();
5212  if ( !plotter ) return;
5213 
5214  // Check if there is a function attached to this plotter.
5216  if ( ! ( fcontroller -> hasFunction ( plotter, 0 ) ) ) {
5217  return;
5218  }
5219 
5220  FunctionRep * frep = getTopFunctionRep ();
5221  Fitter * fitter = frep -> getFitter ();
5222 
5223  // Set the new ignoreError flag for the function
5224  bool flag = m_IgnoreErrorCheckBox -> isChecked();
5225  if ( fitter != 0 ) {
5226  frep -> setIgnoreError ( flag );
5227  }
5228 }
5229 
5230 void
5233 {
5234 
5235  // Disable the tab if no plotter selected.
5236  PlotterBase * plotter = getPlotter ();
5237  bool yes = plotter == 0;
5238  if ( yes == false ) {
5239  TextPlotter * tp = dynamic_cast < TextPlotter * > ( plotter );
5240  yes |= tp != 0;
5241  }
5242  if ( yes ) {
5243  transform_button_group -> setEnabled ( false );
5244  rotateGroupBox -> setEnabled ( false );
5245  return;
5246  }
5247  else {
5248  transform_button_group -> setEnabled ( true );
5249  }
5250 
5251  bool hasZ = plotter -> hasAxis ( Axes::Z );
5252  m_hammer -> setEnabled ( hasZ );
5253  m_lambert -> setEnabled ( hasZ );
5254  m_Car -> setEnabled ( hasZ );
5255  m_Mer -> setEnabled ( hasZ );
5256  m_Gls -> setEnabled ( hasZ );
5257  m_Arc -> setEnabled ( hasZ );
5258  m_Tan -> setEnabled ( hasZ );
5259  m_Sin -> setEnabled ( hasZ );
5260  m_Stg -> setEnabled ( hasZ );
5261  m_Air -> setEnabled ( hasZ );
5262 
5263 
5265 
5266  bool xlog = d_controller -> getLog ( plotter, Axes::X );
5267  bool ylog = d_controller -> getLog ( plotter, Axes::Y );
5268 
5269 
5270  if ( ( !xlog ) && ( !ylog ) ){
5271 
5272  BinaryTransform *t =
5273  dynamic_cast< BinaryTransform* > ( plotter->getTransform() );
5274 
5275  if (( t -> name () == "HammerAito" ) || ( t->name() == "HammerAito2")){
5276  m_hammer -> setChecked ( true );
5277  }
5278 
5279  else if (( t -> name() == "Lambert" ) || ( t->name() == "Lambert2")) {
5280  m_lambert -> setChecked ( true );
5281  }
5282 
5283  else if (( t -> name() == "Cartesian" ) || ( t->name() == "Cartesian2")){
5284  m_Car -> setChecked ( true );
5285  }
5286 
5287  else if (( t -> name() == "Mercator" ) || ( t->name() == "Mecator2")){
5288  m_Mer -> setChecked ( true );
5289  }
5290 
5291  else if (( t -> name() == "GlobalSinusoidal" ) || ( t->name() == "GlobalSinusoidal2")) {
5292  m_Gls -> setChecked ( true );
5293  }
5294 
5295  else if (( t -> name() == "ARC" ) || (t->name()=="ARC2")){
5296  m_Arc -> setChecked ( true );
5297  }
5298 
5299  else if (( t -> name() == "TAN" ) || (t->name()=="TAN2")){
5300  m_Tan -> setChecked ( true );
5301  }
5302 
5303  else if (( t -> name() == "SIN" ) || (t->name()=="SIN2")){
5304  m_Sin -> setChecked ( true );
5305  }
5306 
5307  else if (( t -> name() == "STG" ) || (t->name()=="STG2")){
5308  m_Stg -> setChecked ( true );
5309  }
5310 
5311  else if (( t -> name() == "AIR" ) || (t->name()=="AIR2")){
5312  m_Air -> setChecked ( true );
5313  }
5314 
5315  else m_linear->setChecked ( true );
5316 
5317  // Enable rotation if periodic transform.
5318  // Then set the rotation offset.
5319  if (t->isPeriodic()) {
5320 
5321  rotateGroupBox -> setEnabled ( true );
5322 
5324  dynamic_cast< PeriodicBinaryTransform* > ( t );
5325 
5326  int xoffset = (int) tp->xOffset();
5327  int yoffset = (int) tp->yOffset();
5328 
5329  setRotate ( yoffset, xoffset);
5330  }
5331  else {
5332  setRotate ( 0, 0 );
5333  rotateGroupBox -> setEnabled ( false );
5334  }
5335  }
5336 
5337  else if ( ( !xlog ) && ( ylog ) ){
5338  m_logy -> setChecked ( true );
5339  }
5340 
5341  else if ( ( xlog ) && ( !ylog ) ){
5342  m_logx -> setChecked ( true );
5343  }
5344 
5345  else if ( ( xlog ) && ( ylog ) ){
5346  m_logxy -> setChecked ( true );
5347  }
5348 }
5349 
5350 
5351 void
5354 {
5355  QString message (
5356  "A transform of this type can not be used because\n"
5357  "this application was not compiled with WCSLIB support." );
5358 
5359  QMessageBox::information ( this, // parent
5360  "Invalid transform", // caption
5361  message, // .c_str(),
5362  QMessageBox::Ok,
5363  Qt::NoButton,
5364  Qt::NoButton );
5365 }
5366 
5367 int
5369 transformId () const
5370 {
5371  int id = -1;
5372  for ( unsigned int i = 0; i < m_transform_buttons.size (); i++ ) {
5373  if ( m_transform_buttons[i] -> isChecked () ) {
5374  id = i;
5375  break;
5376  }
5377  }
5378  return id;
5379 }
5380 
5381 void
5384 {
5385 
5386  int id = transformId ();
5387 
5388  PlotterBase * plotter = getPlotter ();
5389  if ( !plotter ) return;
5390 
5391  // Reset rotation offset when do another transform
5392  setRotate ( 0, 0 );
5393 
5394 #ifndef HAVE_WCSLIB
5395  if ( id > 3 ) {
5397  return;
5398  }
5399 #endif
5400 
5402  int max_x = validPeriodicTransformRange();
5403  bool valid2 = false;
5404  try {
5405  switch ( id ) {
5406  case 0:
5407  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5408  d_controller -> setTransform ( plotter, "Linear Linear" );
5409  rotateGroupBox -> setEnabled ( false );
5410  break;
5411 
5412  case 1:
5413  d_controller -> setTransformAxis ( plotter, "Linear", "Log" );
5414  d_controller -> setTransform ( plotter, "Linear Log");
5415  rotateGroupBox -> setEnabled ( false );
5416  break;
5417 
5418  case 2:
5419  d_controller -> setTransformAxis ( plotter, "Log", "Linear" );
5420  d_controller -> setTransform ( plotter, "Log Linear" );
5421  rotateGroupBox -> setEnabled ( false );
5422  break;
5423 
5424  case 3:
5425  d_controller -> setTransformAxis ( plotter, "Log", "Log" );
5426  d_controller -> setTransform ( plotter, "Log Log" );
5427  rotateGroupBox -> setEnabled ( false );
5428  break;
5429 
5430  case 4:
5431  if ( max_x == 180 ) {
5432  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5433  d_controller -> setTransform ( plotter, "HammerAito" );
5434  rotateGroupBox -> setEnabled ( true );
5435  }
5436  else if ( max_x == 360 ) {
5437  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5438  d_controller -> setTransform ( plotter, "HammerAito2" );
5439  rotateGroupBox -> setEnabled ( true );
5440  }
5441  else {
5442  QString message (
5443  "The range of current plotter is not valid for.\n"
5444  "HammerAito transform.\n\n"
5445  "A valid range should be within: \n"
5446  "X axis [-180, 180] or [0, 360]\n"
5447  "Y axis [ -90, 90]\n" );
5448  QMessageBox::information ( this, // parent
5449  "Invalid range", // caption
5450  message, // .c_str(),
5451  QMessageBox::Ok,
5452  Qt::NoButton,
5453  Qt::NoButton );
5454  }
5455  break;
5456 
5457  case 5:
5458  if ( max_x == 180 ) {
5459  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5460  d_controller -> setTransform ( plotter, "Lambert" );
5461  rotateGroupBox -> setEnabled ( true );
5462  }
5463  else if ( max_x == 360 ) {
5464  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5465  d_controller -> setTransform ( plotter, "Lambert2" );
5466  rotateGroupBox -> setEnabled ( true );
5467  }
5468  else {
5469  QString message (
5470  "The range of current plotter is not valid for.\n"
5471  "Lambert transform.\n\n"
5472  "A valid range should be within: \n"
5473  "X axis [-180, 180] or [0, 360]\n"
5474  "Y axis [ -90, 90]\n" );
5475  QMessageBox::information ( this, // parent
5476  "Invalid range", // caption
5477  message, // .c_str(),
5478  QMessageBox::Ok,
5479  Qt::NoButton,
5480  Qt::NoButton );
5481  }
5482  break;
5483 
5484  case 6:
5485  if ( max_x==180 ) {
5486  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5487  d_controller -> setTransform ( plotter, "Cartesian" );
5488  rotateGroupBox -> setEnabled ( true );
5489  }
5490  else if ( max_x==360 ) {
5491  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5492  d_controller -> setTransform ( plotter, "Cartesian2" );
5493  rotateGroupBox -> setEnabled ( true );
5494  }
5495  else {
5496  QString message (
5497  "The range of current plotter is not valid for.\n"
5498  "Cartesian transform.\n\n"
5499  "A valid range should be within: \n"
5500  "X axis [-180, 180]\n"
5501  "Y axis [ -90, 90]\n" );
5502  QMessageBox::information ( this, // parent
5503  "Invalid range", // caption
5504  message, // .c_str(),
5505  QMessageBox::Ok,
5506  Qt::NoButton,
5507  Qt::NoButton );
5508  }
5509  break;
5510 
5511  case 7:
5512  if ( max_x == 180 ) {
5513  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5514  d_controller -> setTransform ( plotter, "Mercator" );
5515  rotateGroupBox -> setEnabled ( true );
5516  }
5517  else if ( max_x == 360 ) {
5518  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5519  d_controller -> setTransform ( plotter, "Mercator2" );
5520  rotateGroupBox -> setEnabled ( true );
5521  }
5522  else {
5523  QString message (
5524  "The range of current plotter is not valid for.\n"
5525  "Mercator transform.\n\n"
5526  "A valid range should be within: \n"
5527  "X axis [-180, 180] or [0, 360]\n"
5528  "Y axis [ -90, 90]\n" );
5529  QMessageBox::information ( this, // parent
5530  "Invalid range", // caption
5531  message, // .c_str(),
5532  QMessageBox::Ok,
5533  Qt::NoButton,
5534  Qt::NoButton );
5535  }
5536  break;
5537 
5538  case 8:
5539  if ( max_x == 180 ) {
5540  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5541  d_controller -> setTransform ( plotter, "GlobalSinusoidal" );
5542  rotateGroupBox -> setEnabled ( true );
5543  }
5544  else if ( max_x == 360 ) {
5545  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5546  d_controller -> setTransform ( plotter, "GlobalSinusoidal2" );
5547  rotateGroupBox -> setEnabled ( true );
5548  }
5549  else {
5550  QString message (
5551  "The range of current plotter is not valid for.\n"
5552  "GlobalSinusoidal transform.\n\n"
5553  "A valid range should be within: \n"
5554  "X axis [-180, 180] or [0, 360]\n"
5555  "Y axis [ -90, 90]\n" );
5556  QMessageBox::information ( this, // parent
5557  "Invalid range", // caption
5558  message, // .c_str(),
5559  QMessageBox::Ok,
5560  Qt::NoButton,
5561  Qt::NoButton );
5562  }
5563  break;
5564 
5565  case 9:
5566  if ( max_x == 180 ) {
5567  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5568  d_controller -> setTransform ( plotter, "ARC" );
5569  rotateGroupBox -> setEnabled ( true );
5570  }
5571  else if ( max_x == 360 ) {
5572  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5573  d_controller -> setTransform ( plotter, "ARC" );
5574  rotateGroupBox -> setEnabled ( true );
5575  }
5576  else {
5577  QString message (
5578  "The range of current plotter is not valid for.\n"
5579  "ARC transform.\n\n"
5580  "A valid range should be within: \n"
5581  "X axis [-180, 180] or [0, 360]\n"
5582  "Y axis [ -90, 90]\n" );
5583  QMessageBox::information ( this, // parent
5584  "Invalid range", // caption
5585  message, // .c_str(),
5586  QMessageBox::Ok,
5587  Qt::NoButton,
5588  Qt::NoButton );
5589  }
5590  break;
5591 
5592  case 10:
5593  valid2 = validPeriodicTransformRange( 0 );
5594  if ( max_x == 180 && valid2 ) {
5595  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5596  d_controller -> setTransform ( plotter, "TAN" );
5597  rotateGroupBox -> setEnabled ( true );
5598  }
5599  else if ( max_x == 360 && valid2 ) {
5600  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5601  d_controller -> setTransform ( plotter, "TAN2" );
5602  rotateGroupBox -> setEnabled ( true );
5603  }
5604  else {
5605  QString message (
5606  "The range of current plotter is not valid for.\n"
5607  "TAN transform.\n\n"
5608  "A valid range should be within: \n"
5609  "X axis [-180, 180] or [0, 360]\n"
5610  "Y axis ( 0, 90]\n" );
5611  QMessageBox::information ( this, // parent
5612  "Invalid range", // caption
5613  message, // .c_str(),
5614  QMessageBox::Ok,
5615  Qt::NoButton,
5616  Qt::NoButton );
5617  }
5618  break;
5619 
5620  case 11:
5621  valid2 = validPeriodicTransformRange( 0 );
5622  if ( max_x==180 && valid2 ) {
5623  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5624  d_controller -> setTransform ( plotter, "SIN" );
5625  rotateGroupBox -> setEnabled ( true );
5626  }
5627  if ( max_x==360 && valid2 ) {
5628  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5629  d_controller -> setTransform ( plotter, "SIN2" );
5630  rotateGroupBox -> setEnabled ( true );
5631  }
5632  else {
5633  QString message (
5634  "The range of current plotter is not valid for.\n"
5635  "SIN transform.\n\n"
5636  "A valid range should be within: \n"
5637  "X axis [-180, 180] or [0, 360]\n"
5638  "Y axis ( 0, 90]\n" );
5639  QMessageBox::information ( this, // parent
5640  "Invalid range", // caption
5641  message, // .c_str(),
5642  QMessageBox::Ok,
5643  Qt::NoButton,
5644  Qt::NoButton );
5645  }
5646  break;
5647 
5648  case 12:
5649  valid2 = true; //validPeriodicTransformRange( -90 );
5650  if ( max_x==180 && valid2 ) {
5651  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5652  d_controller -> setTransform ( plotter, "STG" );
5653  rotateGroupBox -> setEnabled ( true );
5654  }
5655  if ( max_x==360 && valid2 ) {
5656  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5657  d_controller -> setTransform ( plotter, "STG2" );
5658  rotateGroupBox -> setEnabled ( true );
5659  }
5660  else {
5661  QString message (
5662  "The range of current plotter is not valid for.\n"
5663  "STG transform.\n\n"
5664  "A valid range should be within: \n"
5665  "X axis [-180, 180] or [0, 360]\n"
5666  "Y axis ( -90, 90]\n" );
5667  QMessageBox::information ( this, // parent
5668  "Invalid range", // caption
5669  message, // .c_str(),
5670  QMessageBox::Ok,
5671  Qt::NoButton,
5672  Qt::NoButton );
5673  }
5674  break;
5675 
5676  case 13:
5677  valid2 = validPeriodicTransformRange( -90 );
5678  if ( max_x==180 && valid2 ) {
5679  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5680  d_controller -> setTransform ( plotter, "AIR" );
5681  rotateGroupBox -> setEnabled ( true );
5682  }
5683  if ( max_x==360 && valid2 ) {
5684  d_controller -> setTransformAxis ( plotter, "Linear", "Linear" );
5685  d_controller -> setTransform ( plotter, "AIR2" );
5686  rotateGroupBox -> setEnabled ( true );
5687  }
5688  else {
5689  QString message (
5690  "The range of current plotter is not valid for.\n"
5691  "AIR transform.\n\n"
5692  "A valid range should be within: \n"
5693  "X axis [-180, 180] or [0, 360]\n"
5694  "Y axis ( -90, 90]\n" );
5695  QMessageBox::information ( this, // parent
5696  "Invalid range", // caption
5697  message, // .c_str(),
5698  QMessageBox::Ok,
5699  Qt::NoButton,
5700  Qt::NoButton );
5701  }
5702  break;
5703 
5704  }
5705  }
5706  catch ( const std::runtime_error & e ) {
5707  invalidOperationError ( e.what() );
5708  }
5709 }
5710 
5711 
5712 
5713 int
5716 {
5717  PlotterBase * plotter = getPlotter ();
5718 
5719  const Range & rx = plotter -> getDataRange ( Axes::X );
5720  const Range & ry = plotter -> getDataRange ( Axes::Y );
5721 
5722  if ( ( rx.low() > -181 ) && ( rx.high() < 181 ) &&
5723  ( ry.low() > -91 ) && ( ry.high() < 91 )) {
5724  return 180;
5725  }
5726 
5727  if ( ( rx.low() > -1 ) && ( rx.high() < 361 ) &&
5728  ( ry.low() > -91 ) && ( ry.high() < 91 )) {
5729  return 360;
5730  }
5731 
5732  else return 0;
5733 }
5734 
5735 
5736 bool
5739 {
5740  PlotterBase * plotter = getPlotter ();
5741 
5742  const Range & rx = plotter -> getRange ( Axes::X, false );
5743  const Range & ry = plotter -> getRange ( Axes::Y, false );
5744 
5745  if ( ( rx.low() < -180 ) || ( rx.high() > 180 ) ||
5746  ( ry.low() <= miny ) || ( ry.high() > 90 ) ) {
5747  return false;
5748  }
5749 
5750  else {
5751  return true;
5752  }
5753 }
5754 
5755 
5756 
5757 void
5759 rotateX( int offset )
5760 {
5761  if (!m_rotate_enable) return;
5762 
5763  if (offset>180) offset = offset-360 ;
5764  if (offset< -180) offset = offset+360;
5765 
5766  PlotterBase * plotter = getPlotter ();
5767  if ( !plotter ) return;
5768 
5769  plotter->setAutoRanging ( Axes::X, false );
5770 
5771 
5772  BinaryTransform *t =
5773  dynamic_cast< BinaryTransform* > ( plotter->getTransform() );
5774 
5775 
5777  dynamic_cast< PeriodicBinaryTransform* > ( t );
5778 
5779  const Range & r = plotter->getRange ( Axes::X, true );
5780  Range range (r.low(), r.high(), r.pos());
5781 
5782  // Actually rotating X axes
5783  tp->setYOffset( offset );
5784 
5785  plotter->setRange ( Axes::X, range, true, false );
5786  m_x_offset_text->setText ( QString("%1").arg(offset)) ;
5787 
5788 }
5789 
5790 
5791 void
5793 rotateY( int offset )
5794 {
5795  if (!m_rotate_enable) return;
5796 
5797  if (offset>180) offset = offset-360 ;
5798  if (offset< -180) offset = offset+360;
5799 
5800  PlotterBase * plotter = getPlotter ();
5801  if ( !plotter ) return;
5802 
5803  plotter->setAutoRanging ( Axes::Y, false );
5804 
5805 
5806  BinaryTransform *t =
5807  dynamic_cast< BinaryTransform* > ( plotter->getTransform() );
5808 
5809 
5811  dynamic_cast< PeriodicBinaryTransform* > ( t );
5812 
5813  const Range & r = plotter->getRange ( Axes::Y, true );
5814  Range range (r.low(), r.high(), r.pos());
5815 
5816  // Rotate Y;
5817  tp->setXOffset( offset );
5818 
5819  plotter->setRange ( Axes::Y, range, true, false );
5820  m_y_offset_text->setText ( QString("%1").arg(offset)) ;
5821 
5822 }
5823 
5824 void
5826 setRotate( int x, int y )
5827 {
5828  m_rotate_enable = false;
5829  m_x_offset -> setValue ( x );
5830  m_x_offset_text -> setText ( QString("%1").arg(x) );
5831  m_y_offset -> setValue ( y );
5832  m_y_offset_text -> setText ( QString("%1").arg(y) );
5833  m_rotate_enable = true;
5834 }
5835 
5836 void
5839 {
5840  rotateX(0);
5841  rotateY(0);
5842  setRotate(0, 0);
5843 }
5844 
5845 void
5848 {
5849  PlotterBase * plotter = getPlotter ();
5850  if ( !plotter ) return;
5851 
5852  plotter->setShowGrid ( m_grid -> isChecked() );
5853 }
5854 
5855 void
5858 {
5859  PlotterBase * plotter = getPlotter();
5860  if ( !plotter ) return;
5861  plotter->setBoxEdge( m_boxedge->isChecked() );
5862 }
5863 
5864 
5865 void
5868 {
5869  PlotterBase * plotter = getPlotter ();
5870  if ( !plotter ) return;
5871 
5872  if (m_combine_checkbox->isChecked()) {
5873  plotter->setMinEntries(m_min_entries);
5874  }
5875  else plotter->setMinEntries(0);
5876 
5877  updateAxisTab();
5878 }
5879 
5880 void
5882 setMinEntries( int increment )
5883 {
5884  int minEntries = m_min_entries + increment - 50;
5885  if ( minEntries < 0 ) minEntries = 0;
5886 
5887  PlotterBase * plotter = getPlotter ();
5888  if ( !plotter ) return;
5889 
5890  if (!m_combine_checkbox->isChecked()) return;
5891 
5892  plotter->setMinEntries(minEntries);
5893  min_entries_text->setText(QString("%1").arg(minEntries));
5894 
5895  if (m_dragging == false ) {
5896  m_min_entries = minEntries;
5898  }
5899 }
5900 
5901 int
5904 {
5905  PlotterBase * plotter = getPlotter ();
5906  if ( !plotter ) return -1;
5907 
5908  return plotter->getMinEntries ();
5909 }
5910 
5911 void
5914 {
5915  PlotterBase * plotter = getPlotter ();
5916  if ( !plotter ) return;
5917 
5918  int min = min_entries_text->text().toInt();
5919  plotter->setMinEntries(min);
5920  updateAxisTab();
5921 }
5922 
5923 
5924 void
5927 {
5928  PlotterBase * plotter = getPlotter ();
5929  if ( !plotter ) return;
5930 
5931  int offset = m_x_offset_text->text().toInt();
5932 
5933 
5934  if (!m_rotate_enable) return;
5935 
5936  if (offset>180) offset = offset-360 ;
5937  if (offset< -180) offset = offset+360;
5938 
5939  plotter->setAutoRanging ( Axes::X, false );
5940 
5941  BinaryTransform *t =
5942  dynamic_cast< BinaryTransform* > ( plotter->getTransform() );
5943 
5944 
5946  dynamic_cast< PeriodicBinaryTransform* > ( t );
5947 
5948  const Range & r = plotter->getRange ( Axes::X, true );
5949  Range range (r.low(), r.high(), r.pos());
5950 
5951  // Actually rotating X axes
5952  tp->setYOffset( offset );
5953 
5954  plotter->setRange ( Axes::X, range, true, false );
5955  m_x_offset->setValue(offset);
5956  m_x_offset_text->setText ( QString("%1").arg(offset)) ;
5957 
5958  updateAxisTab();
5959 }
5960 
5961 void
5964 {
5965  PlotterBase * plotter = getPlotter ();
5966  if ( !plotter ) return;
5967 
5968  int offset = m_y_offset_text->text().toInt();
5969 
5970 
5971  if (!m_rotate_enable) return;
5972 
5973  if (offset>180) offset = offset-360 ;
5974  if (offset< -180) offset = offset+360;
5975 
5976  plotter->setAutoRanging ( Axes::Y, false );
5977 
5978  BinaryTransform *t =
5979  dynamic_cast< BinaryTransform* > ( plotter->getTransform() );
5980 
5981 
5983  dynamic_cast< PeriodicBinaryTransform* > ( t );
5984 
5985  const Range & r = plotter->getRange ( Axes::Y, true );
5986  Range range (r.low(), r.high(), r.pos());
5987 
5988  // Actually rotating Y axes
5989  tp->setXOffset( offset );
5990 
5991  plotter->setRange ( Axes::Y, range, true, false );
5992  m_y_offset->setValue(offset);
5993  m_y_offset_text->setText ( QString("%1").arg(offset)) ;
5994 
5995  updateAxisTab();
5996 }
5997 
6000 void
6003 {
6004  PlotterBase * plotter = getPlotter ();
6005 
6006  if ( !plotter ) return;
6007 
6008  int num_rep = plotter -> getNumDataReps();
6009 
6010  // If number of datarep is not equal to 2
6011  // in the plot, show warning message and do nothing.
6012  if ( num_rep != 2 )
6013  {
6014  const QString message=
6015  "You must have two DataReps in this view.";
6016 
6017  QMessageBox::warning ( this, // parent
6018  "Unable to compare DataRep", // caption
6019  message,
6020  QMessageBox::Ok,
6021  Qt::NoButton,
6022  Qt::NoButton );
6023  return;
6024  }
6025 
6026 
6027  FunctionRep * func_rep = getTopFunctionRep ();
6029  PlotterBase * res_plotter
6030  //= controller -> createResidualsDisplay ( plotter, func_rep );
6031  = controller -> createDifferenceDisplay ( plotter );
6032  const Range & range = plotter -> getRange ( Axes::X, false );
6033  res_plotter -> setRange ( Axes::X, range, false );
6034 
6035  CanvasWindow * canvas = WindowController::instance () -> currentCanvas ();
6036 
6037  canvas -> addPlotDisplay ( res_plotter, true );
6038 }

Generated for HippoDraw Class Library by doxygen