00001
00012 #ifdef _MSC_VER
00013 #include "msdevstudio/MSconfig.h"
00014 #endif
00015
00016 #include "Inspector.h"
00017
00018 #include "CanvasSelectionEvent.h"
00019 #include "CanvasWindow.h"
00020 #include "ComboBox.h"
00021 #include "PlotterEvent.h"
00022 #include "WindowController.h"
00023 #include "AxisWidget.h"
00024 #include "QtFont.h"
00025 #include "NewModelDialog.h"
00026 #include "EditModelDialog.h"
00027
00028
00029 #include <qapplication.h>
00030
00031 #if QT_VERSION < 0x040000
00032 #include "qlistview.h"
00033 #include "qbuttongroup.h"
00034 #include "qgroupbox.h"
00035 #include "qwidgetstack.h"
00036 #else
00037 #include <QCustomEvent>
00038 #include <QHBoxLayout>
00039 #include <QVBoxLayout>
00040 #include "q3button.h"
00041 #include "q3listview.h"
00042 #include "q3buttongroup.h"
00043 #include "q3groupbox.h"
00044 #include "q3widgetstack.h"
00045 #endif
00046
00047 #include "qcheckbox.h"
00048 #include "qcolordialog.h"
00049 #include "qabstractlayout.h"
00050 #include "qlineedit.h"
00051 #include "qmessagebox.h"
00052 #include "qpushbutton.h"
00053 #include "qradiobutton.h"
00054 #include "qslider.h"
00055 #include "qlabel.h"
00056 #include "qinputdialog.h"
00057 #include "qfontdialog.h"
00058 #include "qtabwidget.h"
00059 #include "qsettings.h"
00060 #include "qstringlist.h"
00061 #include "qtextstream.h"
00062
00063
00064 #include "controllers/CutController.h"
00065 #include "controllers/DataRepController.h"
00066 #include "controllers/DisplayController.h"
00067 #include "controllers/FunctionController.h"
00068
00069 #include "datareps/FunctionRep.h"
00070
00071 #include "datasrcs/DataSourceController.h"
00072 #include "datasrcs/DataSourceException.h"
00073 #include "datasrcs/NTuple.h"
00074 #include "datasrcs/TupleCut.h"
00075
00076 #include "functions/FunctionFactory.h"
00077
00078 #include "plotters/CutPlotter.h"
00079 #include "plotters/TextPlotter.h"
00080
00081 #include "projectors/FunctionProjector.h"
00082 #include "projectors/NTupleProjector.h"
00083
00084 #include "reps/ContourPointRep.h"
00085 #include "transforms/PeriodicBinaryTransform.h"
00086
00087 #ifdef HAVE_ROOT
00088 #include "root/RootController.h"
00089 #include "boost/tokenizer.hpp"
00090 #include "boost/lexical_cast.hpp"
00091 #endif
00092
00093
00094
00095 #include <sstream>
00096 #include <stdexcept>
00097
00098 #include <cmath>
00099 #include <cassert>
00100
00101 using namespace hippodraw;
00102
00103 using std::map;
00104 using std::string;
00105 using std::vector;
00106
00107
00108 QString Inspector::s_app_key ( "/HippoDraw/" );
00109 QString Inspector::s_registry ( "/Trolltech" );
00110
00111
00112 #if QT_VERSION < 0x040000
00113
00114 Inspector::
00115 Inspector ( QWidget * parent, const char * name, bool modal, Qt::WFlags flags )
00116 : InspectorBase ( parent, name, modal, flags ),
00117 m_plotter ( 0 )
00118 {
00119 #else
00120 Inspector::
00121 Inspector ( QWidget * parent )
00122 : QDialog ( parent ),
00123 m_plotter ( 0 )
00124 {
00125 setupUi ( this );
00126 #endif
00127 init ();
00128
00129 FunctionController * controller = FunctionController::instance();
00130 const vector < string > & names = controller -> getFitterNames ();
00131
00132 for ( unsigned int i = 0; i < names.size(); i++ ) {
00133 #if defined(QT_NO_STL) || QT_VERSION < 0x030100
00134 QString name ( names[i].c_str() );
00135 #else
00136 QString name ( names[i] );
00137 #endif
00138 m_fitter_names -> insertItem ( name );
00139 }
00140
00141 connect ( axisWidget1, SIGNAL ( lowTextReturnPressed() ),
00142 this, SLOT ( setLowText() ) );
00143
00144 connect ( axisWidget2, SIGNAL ( lowTextReturnPressed() ),
00145 this, SLOT ( cutText_returnPressed() ) );
00146
00147 connect ( axisWidget1, SIGNAL ( highTextReturnPressed() ),
00148 this, SLOT ( setHighText() ) );
00149
00150 connect ( axisWidget2, SIGNAL ( highTextReturnPressed() ),
00151 this, SLOT ( cutText_returnPressed() ) );
00152
00153 connect ( axisWidget1, SIGNAL ( lowSliderReleased() ),
00154 this, SLOT ( lowRangeDrag() ) );
00155
00156 connect ( axisWidget2, SIGNAL ( lowSliderReleased() ),
00157 this, SLOT ( cutLowSlider_sliderReleased() ) );
00158
00159 connect ( axisWidget1, SIGNAL ( lowSliderPressed() ),
00160 this, SLOT ( setDragOn() ) );
00161
00162 connect ( axisWidget1, SIGNAL ( highSliderPressed() ),
00163 this, SLOT ( setDragOn() ) );
00164
00165 connect ( axisWidget1, SIGNAL ( lowSliderValueChanged ( int ) ),
00166 this, SLOT ( setLowRange ( int ) ) );
00167
00168 connect ( axisWidget2, SIGNAL ( lowSliderValueChanged ( int ) ),
00169 this, SLOT ( cutLowSlider_sliderMoved ( int ) ) );
00170
00171 connect ( axisWidget1, SIGNAL ( highSliderReleased() ),
00172 this, SLOT ( highRangeDrag() ) );
00173
00174 connect ( axisWidget2, SIGNAL ( highSliderReleased() ),
00175 this, SLOT ( cutHighSlider_sliderReleased() ) );
00176
00177 connect ( axisWidget1, SIGNAL ( highSliderValueChanged ( int ) ),
00178 this, SLOT ( setHighRange ( int ) ) );
00179
00180 connect ( axisWidget2, SIGNAL ( highSliderValueChanged ( int ) ),
00181 this, SLOT ( cutHighSlider_sliderMoved ( int ) ) );
00182
00183 connect ( axisWidget1, SIGNAL ( zoomPanCheckBoxClicked () ),
00184 this, SLOT ( axisZoomPanCheckBox_clicked () ) );
00185
00186 connect ( axisWidget2, SIGNAL ( zoomPanCheckBoxClicked () ),
00187 this, SLOT ( cutZoomPanCheckBox_clicked () ) );
00188
00189 axisWidget2 -> setCut ( true );
00190
00191
00192 m_lowslider1_last_val = 50;
00193 m_highslider1_last_val = 50;
00194
00195 updatePlotTypes ();
00196 }
00197
00198 Inspector::
00199 ~Inspector ()
00200 {
00201 }
00202
00203 void
00204 Inspector::
00205 init()
00206 {
00207 m_new_labels.reserve ( 4 );
00208 m_new_labels.push_back ( new_binding_0 );
00209 m_new_labels.push_back ( new_binding_1 );
00210 m_new_labels.push_back ( new_binding_2 );
00211 m_new_labels.push_back ( new_binding_3 );
00212
00213 m_new_combos.reserve ( 4 );
00214 m_new_combos.push_back ( new_combo_0 );
00215 m_new_combos.push_back ( new_combo_1 );
00216 m_new_combos.push_back ( new_combo_2 );
00217 m_new_combos.push_back ( new_combo_3 );
00218
00219 m_sel_labels.reserve ( 4 );
00220 m_sel_labels.push_back ( sel_binding_0 );
00221 m_sel_labels.push_back ( sel_binding_1 );
00222 m_sel_labels.push_back ( sel_binding_2 );
00223 m_sel_labels.push_back ( sel_binding_3 );
00224
00225 m_sel_combos.reserve ( 4 );
00226 m_sel_combos.push_back ( sel_combo_0 );
00227 m_sel_combos.push_back ( sel_combo_1 );
00228 m_sel_combos.push_back ( sel_combo_2 );
00229 m_sel_combos.push_back ( sel_combo_3 );
00230
00231 QSize cur_size = size();
00232 setFixedSize ( cur_size );
00233
00234 m_dragging = false;
00235 m_axis = Axes::X;
00236 m_layoutWidget = new QWidget( currentPlot, "m_Layout" );
00237 m_layoutWidget->setGeometry( QRect ( 7, 75, 360, 0 ) );
00238 m_vLayout = new QVBoxLayout( m_layoutWidget, 0, 6, "m_vLayout");
00239
00240 newPlotButton->setEnabled( false );
00241
00242 m_newLayoutWidget = new QWidget ( m_new_plot_box, "m_newLayout" );
00243 m_newLayoutWidget->setGeometry( QRect ( 7, 75, 360, 0 ) );
00244 m_newVLayout = new QVBoxLayout( m_newLayoutWidget, 0, 6,
00245 "m_newVLayout");
00246
00247 DisplayController * controller = DisplayController::instance ();
00248 const vector < string > & names = controller -> getValueTransformTypes ();
00249 m_value_combo -> clear ();
00250 unsigned int size = names.size ();
00251 for ( unsigned int i = 0; i < size; i++ ) {
00252 m_value_combo -> insertItem ( names[i].c_str() );
00253 }
00254
00255 loadAllUsrModels();
00256 for ( unsigned int i = size; i < size + usr_models.size (); i++ ) {
00257 m_value_combo -> insertItem ( usr_models[ i - size ].c_str() );
00258 }
00259
00260
00261 m_interval_le->setDisabled ( true );
00262
00263
00264
00265 m_FunctionParamsListView -> addColumn( QString( "Sl." ), 3 );
00266 m_FunctionParamsListView -> addColumn( QString( "Params" ),40 );
00267 m_FunctionParamsListView -> addColumn( QString( "Fixed" ), 3 );
00268 m_FunctionParamsListView -> addColumn( QString( "Value" ), 40 );
00269 m_FunctionParamsListView -> addColumn( QString( "Error" ), 40 );
00270
00271 }
00272 void
00273 Inspector::
00274 enableNewPlotBox ( bool yes )
00275 {
00276 m_new_plot_box->setEnabled ( yes );
00277 m_summary->setEnabled ( yes );
00278 }
00279
00280 void Inspector::customEvent ( QCustomEvent * event )
00281 {
00282 PlotterEvent * pev = dynamic_cast < PlotterEvent * > ( event );
00283 if ( pev != 0 ) {
00284 m_plotter = pev -> plotter ();
00285 update ();
00286 }
00287
00288 CanvasSelectionEvent * ev
00289 = dynamic_cast < CanvasSelectionEvent * > ( event );
00290 if ( ev != 0 ) {
00291 m_plotter_list = ev -> getPlotters ();
00292 if ( m_plotter_list.size () == 1 ) {
00293 m_plotter = m_plotter_list.front ();
00294 }
00295 else {
00296 m_plotter = 0;
00297 }
00298 update ();
00299 }
00300 }
00301
00302 PlotterBase *
00303 Inspector::
00304 getPlotter ()
00305 {
00306 return m_plotter;
00307 }
00308
00309 void
00310 Inspector::
00311 setZRadioButton ( bool enabled )
00312 {
00313
00314 if (!enabled && m_axis == Axes::Z )
00315 {
00316 QButton * b = axis_button_group -> find ( 0 );
00317 QRadioButton * button = dynamic_cast< QRadioButton * > ( b );
00318 button -> setChecked ( true );
00319 m_axis = Axes::X;
00320 updateAxisTab ();
00321 }
00322
00323 QButton * button = axis_button_group -> find ( 2 );
00324 button -> setEnabled ( enabled );
00325 }
00326
00327 void
00328 Inspector::
00329 tabChanged ()
00330 {
00331 update ();
00332 }
00333
00334 void
00335 Inspector::
00336 update ()
00337 {
00338 if ( isHidden() == true ) return;
00339 m_is_updating = true;
00340 int index = m_plot_tab -> currentPageIndex ();
00341
00342 switch ( index )
00343 {
00344 case ( 0 ) :
00345 updateDataTab();
00346 break;
00347 case ( 1 ) :
00348 updatePlotTab();
00349 break;
00350 case ( 2 ) :
00351 updateAxisTab();
00352 break;
00353 case ( 3 ) :
00354 updateCutsTab();
00355 break;
00356 case ( 4 ) :
00357 updateFunctionsTab();
00358 break;
00359 case ( 5 ) :
00360 updateSummaryTab ();
00361 break;
00362 default :
00363 assert ( false );
00364 break;
00365 }
00366
00367 if ( m_plotter != 0 ) {
00368 bool hasZ = m_plotter -> hasAxis ( Axes::Z );
00369 setZRadioButton ( hasZ );
00370 }
00371
00372 m_is_updating = false;
00373 updateCutsActive ();
00374 }
00375
00376 void
00377 Inspector::
00378 updateCutsActive ()
00379 {
00380 PlotterBase * plotter = getPlotter ();
00381 bool yes = plotter != 0;
00382 if ( yes ) yes = plotter -> isTargetable ();
00383 if ( yes == false ) {
00384 setAllCutsActive ( true );
00385 return;
00386 }
00387 vector < PlotterBase * > cutlist;
00388 fillCutsOn ( plotter, cutlist );
00389
00390 if ( cutlist.empty () ) {
00391 setAllCutsActive ( true );
00392 return;
00393 }
00394 else {
00395 setAllCutsActive ( false );
00396 vector < PlotterBase * >::iterator first = cutlist.begin();
00397 while ( first != cutlist.end () ) {
00398 PlotterBase * pb = *first++;
00399 CutPlotter * cutter = dynamic_cast < CutPlotter * > ( pb );
00400 assert ( cutter );
00401 cutter -> setActive ( true );
00402 }
00403 }
00404 }
00405
00406 std::string
00407 Inspector::
00408 getSelectedDataSourceName () const
00409 {
00410 const vector < string > & names
00411 = DataSourceController::instance () -> getNTupleNames ();
00412 int index = m_all_ntuples -> currentItem ();
00413
00414 return names [ index ];
00415 }
00416
00417 void
00418 Inspector::
00419 updateNewPlotControls ()
00420 {
00421 const vector < string > & nt_vector
00422 = DataSourceController::instance() -> getNTupleNames ();
00423 if ( nt_vector.empty () ) {
00424 m_all_ntuples -> clear ();
00425 return;
00426 }
00427
00428 unsigned int count = m_all_ntuples -> count ();
00429 if ( count == nt_vector.size () ) return;
00430
00431 #ifdef ITERATOR_MEMBER_DEFECT
00432
00433 #endif
00434
00435 m_all_ntuples -> clear();
00436 vector < string > ::const_iterator first = nt_vector.begin();
00437 while ( first != nt_vector.end() ) {
00438 const string & name = *first++;
00439 m_all_ntuples->insertItem ( name.c_str() );
00440 }
00441
00442 if ( m_all_ntuples -> count () != 0 ) {
00443 const string & name = nt_vector.back ();
00444
00445 setNewPlotNTuple ( name );
00446 availPlotTypesActivated ( name.c_str() );
00447 }
00448 else {
00449 availPlotTypesActivated ( QString::null );
00450 }
00451 }
00452
00453 void
00454 Inspector::
00455 setNewPlotNTuple ( const std::string & name )
00456 {
00457 const vector < string > & nt_vector
00458 = DataSourceController::instance() -> getNTupleNames ();
00459
00460 for ( unsigned int i = 0; i < nt_vector.size(); i++ ) {
00461 if ( nt_vector[i] == name ) {
00462 unsigned int current = m_all_ntuples -> currentItem ();
00463 if ( current != i ) {
00464 m_all_ntuples -> setCurrentItem ( i );
00465 }
00466 break;
00467 }
00468 }
00469 }
00470
00471 void
00472 Inspector::
00473 dataTupleNameChanged ( const QString & text )
00474 {
00475 m_last_ntuple_edited = m_all_ntuples -> currentItem ();
00476 }
00477
00478 void
00479 Inspector::
00480 changeNTupleName ( const QString & text )
00481 {
00482 DataSourceController * controller = DataSourceController::instance ();
00483 const vector < DataSource * > & nt_vector = controller -> getDataSources();
00484 DataSource * ds = nt_vector [ m_last_ntuple_edited ];
00485 if ( ds == 0 ) return;
00486
00487 const string new_name = text.latin1();
00488
00489 ds -> setName ( new_name );
00490 }
00491
00492 void
00493 Inspector::
00494 dataNTupleSelChanged ( int item )
00495 {
00496 m_all_ntuples -> setCurrentItem ( item );
00497 QString text ( "" );
00498
00499 availPlotTypesActivated ( text );
00500 }
00501
00502 void
00503 Inspector::
00504 allNtupleComboActivated ( const QString & text )
00505 {
00506
00507
00508
00509
00510 changeNTupleName ( text );
00511 m_all_ntuples -> setCurrentItem ( m_last_ntuple_edited );
00512 m_all_ntuples -> changeItem ( text, m_last_ntuple_edited );
00513
00514 availPlotTypesActivated ( text );
00515 }
00516
00517 void
00518 Inspector::
00519 on_sel_combo_0_activated ( const QString & label )
00520 {
00521 axisLabelChanged ( 0, label );
00522 }
00523
00524 void
00525 Inspector::
00526 on_sel_combo_1_activated ( const QString & label )
00527 {
00528 axisLabelChanged ( 1, label );
00529 }
00530
00531 void
00532 Inspector::
00533 on_sel_combo_2_activated ( const QString & label )
00534 {
00535 axisLabelChanged ( 2, label );
00536 }
00537
00538 void
00539 Inspector::
00540 on_sel_combo_3_activated ( const QString & label )
00541 {
00542 axisLabelChanged ( 3, label );
00543 }
00544
00545 void
00546 Inspector::
00547 axisLabelChanged ( int index, const QString & label )
00548 {
00549 if ( m_plotter_list.size () > 1 ) {
00550 multiplePlotError ();
00551 return;
00552 }
00553
00554 PlotterBase * plotter = getPlotter ();
00555 if ( !plotter ) return ;
00556
00557 QString axisName = m_sel_labels [index] -> text();
00558 const std::string strAxisName ( axisName.latin1() );
00559 const std::string strLabel( label.latin1() );
00560
00561 DisplayController * controller = DisplayController::instance();
00562 controller -> setAxisBinding ( plotter, strAxisName, strLabel );
00563
00564 bool valid = controller -> isDataValid ( plotter );
00565 if ( valid == false ) {
00566 invalidDataWarning ();
00567 }
00568 }
00569
00570 void
00571 Inspector::
00572 updatePlotTypes ()
00573 {
00574 const vector < string > & dataRepNames
00575 = DisplayController::instance() -> getDisplayTypes ();
00576 if ( dataRepNames.empty () ) return;
00577 unsigned int size = m_availPlotTypes -> count ();
00578
00579 if ( dataRepNames.size() != size ) {
00580 m_availPlotTypes->clear();
00581
00582 vector < string > ::const_iterator first = dataRepNames.begin ();
00583 while ( first != dataRepNames.end() ) {
00584 const string & name = *first++;
00585 if ( name.find ( "Static" ) != string::npos ) continue;
00586 m_availPlotTypes->insertItem ( name.c_str() );
00587 }
00588 m_availPlotTypes->setCurrentItem ( 2 );
00589 }
00590
00591 newPlotButton->setEnabled( true );
00592 }
00593
00594 void
00595 Inspector::
00596 clearNewBindings ()
00597 {
00598 unsigned int size = m_new_combos.size ();
00599 for ( unsigned int i = 0; i < size; i++ ) {
00600 QComboBox * box = m_new_combos [ i ];
00601 box -> clear ();
00602 box -> setEnabled ( false );
00603 QLabel * label = m_new_labels [ i ];
00604 label -> setEnabled ( false );
00605 }
00606 }
00607
00608 void
00609 Inspector::
00610 availPlotTypesActivated ( const QString & )
00611 {
00612
00613
00614
00615
00616
00617
00618 int index = m_all_ntuples->currentItem ();
00619 const vector < DataSource * > & nt_vector
00620 = DataSourceController::instance() -> getDataSources ();
00621 int size = static_cast < int > ( nt_vector.size() );
00622 if ( size == 0 ) {
00623 clearNewBindings();
00624 return;
00625 }
00626
00627 if ( ! (index < size ) ) {
00628 index = 0;
00629 }
00630
00631 DataSource * nt = nt_vector[index];
00632 const vector < string > & cols = nt->getLabels();
00633
00634 std::string plotTypeStr( (m_availPlotTypes->currentText()).latin1() );
00635
00636
00637 DisplayController * controller = DisplayController::instance ();
00638 const vector < string > & bindingOptions
00639 = controller -> bindingOptions ( plotTypeStr );
00640 if ( bindingOptions.empty () ) return;
00641
00642
00643
00644 m_newLayoutWidget->hide();
00645
00646 clearNewBindings ();
00647 QString qs1;
00648
00649 for ( unsigned int i = 0; i < bindingOptions.size(); i++ )
00650 {
00651 const string & axisName = bindingOptions[i];
00652
00653 qs1 = ( axisName.c_str() );
00654 m_new_labels [i] -> setEnabled ( true );
00655 m_new_labels [i] -> setText ( qs1 );
00656 m_new_combos [i] -> setEnabled ( true );
00657
00658 for (std::vector<string>::size_type j = 0; j < cols.size(); j++)
00659 {
00660 m_new_combos [i] -> insertItem ( cols [j].c_str() );
00661 }
00662 if ( axisName.find ( "optional" ) != string::npos ) {
00663 m_new_combos [i] -> insertItem ( "nil" );
00664 m_new_combos [i] -> setCurrentText ( "nil" );
00665 }
00666 }
00667 }
00668
00669 void
00670 Inspector::
00671 updateDataTab()
00672 {
00673 updateNewPlotControls ();
00674 dataClearSelectedControls ();
00675
00676 PlotterBase * plotter = getPlotter ();
00677 updateSelectedPlotType ( plotter );
00678
00679 if ( plotter != 0 ) {
00680 currentPlot->setEnabled ( true );
00681 bool yes = plotter -> isTargetable ();
00682 m_addDataRepButton->setEnabled ( yes );
00683 if ( yes == false ) return;
00684 }
00685 else {
00686 if ( m_plotter_list.empty () == true ) {
00687 currentPlot -> setDisabled ( true );
00688 }
00689 else {
00690 currentPlot -> setDisabled ( false );
00691 }
00692 return;
00693 }
00694 updateSelectedPlotData ( plotter );
00695 }
00696
00697 void
00698 Inspector::
00699 updateSelectedPlotDataSource ( const std::string & name )
00700 {
00701 const vector < string > & nt_vector
00702 = DataSourceController::instance () -> getNTupleNames ();
00703
00704 unsigned int size = nt_vector.size ();
00705 unsigned int count = m_sel_ntuple_name -> count ();
00706 bool refresh = count != size;
00707 if ( refresh ) m_sel_ntuple_name -> clear ();
00708 int jndex = -1;
00709 for ( std::size_t i = 0; i < size; i++ ) {
00710 const string & ntname = nt_vector[i];
00711 if ( ntname == name ) jndex = i;
00712 if ( refresh ) m_sel_ntuple_name -> insertItem ( ntname.c_str () );
00713 }
00714
00715 if ( jndex < 0 ) {
00716 m_sel_ntuple_name -> setEnabled ( false );
00717 }
00718 else {
00719 m_sel_ntuple_name -> setEnabled ( true );
00720 m_sel_ntuple_name -> setCurrentItem ( jndex );
00721 }
00722 }
00723
00724 void
00725 Inspector::
00726 updateSelectedPlotType ( const PlotterBase * plotter )
00727 {
00728 bool yes = plotter != 0;
00729 if ( yes ) {
00730 yes = plotter -> isTargetable ();
00731 if ( yes ) {
00732 DataRep * datarep = plotter -> getTarget ();
00733 yes = datarep != 0;
00734 if ( yes ) {
00735 int index = plotter -> indexOf ( datarep );
00736 DisplayController * controller = DisplayController::instance ();
00737 const string & dataRepName
00738 = controller -> getType ( plotter, index );
00739 QString qst2 ( dataRepName.c_str() );
00740 m_dataRepNameText->setText ( qst2 );
00741 }
00742 }
00743 }
00744
00745 m_dataRepNameText -> setEnabled ( yes );
00746 }
00747
00748 void
00749 Inspector::
00750 dataClearSelectedControls ()
00751 {
00752 QLayoutIterator it = m_vLayout->iterator();
00753 while ( it.current() != 0 )
00754 {
00755 QLayoutItem * ptr = it.current();
00756 QHBoxLayout * hbox = static_cast <QHBoxLayout *> (ptr);
00757
00758 QLayoutIterator hit = hbox->iterator();
00759 while ( hit.current() != 0 )
00760 {
00761 QLayoutItem * hptr = hit.current();
00762 QWidget * hwidget = hptr->widget();
00763 hit.deleteCurrent();
00764 if ( hwidget ) delete ( hwidget );
00765 }
00766
00767 it.deleteCurrent();
00768
00769 }
00770 }
00771
00772 void
00773 Inspector::
00774 updateSelectedPlotData ( const PlotterBase * plotter )
00775 {
00776 DisplayController * controller = DisplayController::instance ();
00777 DataRep * datarep = plotter -> getTarget ();
00778 int index = plotter -> indexOf ( datarep );
00779 assert ( datarep != 0 );
00780
00781 bool ntuple_bindings = datarep -> hasNTupleBindings ( );
00782 string name;
00783
00784 if ( ntuple_bindings ) {
00785 name = controller -> getDataSourceName ( plotter, index );
00786 setNewPlotNTuple ( name );
00787 }
00788 else {
00789 name = "<none>";
00790 }
00791 updateSelectedPlotDataSource ( name );
00792
00793
00794
00795 m_layoutWidget->hide();
00796
00797 const vector < string > & bindings
00798 = controller -> axisBindings ( plotter, index );
00799 const vector < string > & bindingOptions
00800 = controller -> bindingOptions ( plotter, index );
00801 unsigned int listSize;
00802
00803 if ( bindings.size() < bindingOptions.size() )
00804 {
00805 listSize = bindings.size();
00806 }
00807 else
00808 {
00809 listSize = bindingOptions.size();
00810 }
00811
00812 bool yes = plotter -> isTargetable ();
00813 if ( ntuple_bindings == false ||
00814 yes == false ) return;
00815
00816
00817
00818 QString qs1, qs2;
00819
00820 const vector < string > & cols
00821 = controller -> getDataSourceLabels ( plotter, index );
00822
00823 if ( cols.empty () ) return;
00824
00825 for ( unsigned int i = 0; i < m_sel_combos.size (); i++ ) {
00826 QLabel * label = m_sel_labels [i];
00827 label -> setEnabled ( false );
00828 QComboBox * box = m_sel_combos [i];
00829 box -> clear ();
00830 box -> setEnabled ( false );
00831 }
00832
00833 for ( unsigned int i = 0; i < m_sel_combos.size (); i++ )
00834 {
00835 if ( i == listSize ) break;
00836 const string & axisLabel = bindings[i];
00837 const string & axisName = bindingOptions[i];
00838
00839 qs1 = ( axisName.c_str() );
00840 m_sel_labels [i] -> setEnabled ( true );
00841 m_sel_labels [i] -> setText ( qs1 );
00842
00843 qs2 = ( axisLabel.c_str() );
00844
00845
00846
00847
00848 m_sel_combos [i] -> setEnabled ( true );
00849 for (std::vector<string>::size_type j = 0; j < cols.size(); j++ )
00850 {
00851 m_sel_combos [i] -> insertItem ( cols [j].c_str() );
00852 }
00853 if ( axisName.find ( "optional" ) != string::npos )
00854 {
00855 m_sel_combos [i] -> insertItem ( "nil" );
00856 }
00857 m_sel_combos [i] -> setCurrentText ( qs2 );
00858 }
00859 }
00860
00861 void
00862 Inspector::
00863 invalidDataWarning ()
00864 {
00865 const QString message =
00866 "One or more columns of the bound data source\n"
00867 "contains invalid data.";
00868 QMessageBox::warning ( this,
00869 "Invalid data",
00870 message,
00871 QMessageBox::Ok,
00872 Qt::NoButton,
00873 Qt::NoButton );
00874 }
00875
00876 void
00877 Inspector::
00878 noNTupleSelectedError ()
00879 {
00880 const string message =
00881 "No n-tuple selected error\n"
00882 "Need to load n-tuple to create a plot";
00883 QMessageBox::critical ( this,
00884 "No n-tuple selected error",
00885 message.c_str(),
00886 QMessageBox::Ok,
00887 Qt::NoButton,
00888 Qt::NoButton );
00889 }
00890
00891 void
00892 Inspector::
00893 incompatibleDataRepError ( const std::string & type )
00894 {
00895 const string message =
00896 "Plot of type " + type + " can not be added\n"
00897 "to selected plot\n\n"
00898 "It might be incompatible. For example, \n"
00899 "requiring a Z axis display while selected\n"
00900 "does not have one.";
00901 QMessageBox::critical ( this,
00902 "Add to plot error",
00903 message.c_str(),
00904 QMessageBox::Ok,
00905 Qt::NoButton,
00906 Qt::NoButton );
00907 }
00908 void
00909 Inspector::
00910 incompatibleFitterError ( const std::string & type )
00911 {
00912 const string message =
00913 "Fitter of type " + type + " can not be used\n"
00914 "with selected plot\n\n"
00915 "It might be incompatible. For example, \n"
00916 "Maximum Likelihood fitting requires binned\n"
00917 "data representation.";
00918 QMessageBox::critical ( this,
00919 "Set fitter error",
00920 message.c_str(),
00921 QMessageBox::Ok,
00922 Qt::NoButton,
00923 Qt::NoButton );
00924 }
00925
00926 void
00927 Inspector::
00928 incompatibleFunctionError ( const std::string & type )
00929 {
00930 const string message =
00931 "Funtion of type " + type + " can not be used\n"
00932 "with selected fitter\n\n"
00933 "It might be incompatible. For example, \n"
00934 "the fitter requires derivatives\n"
00935 "that function can not supply.";
00936 QMessageBox::critical ( this,
00937 "Set fitter error",
00938 message.c_str(),
00939 QMessageBox::Ok,
00940 Qt::NoButton,
00941 Qt::NoButton );
00942 }
00943
00944 void
00945 Inspector::
00946 invalidRangeError ( const std::string & bad )
00947 {
00948 const string message
00949 = "Attempt to apply invalid range:\n\n"
00950 + bad + "\n\n"
00951 + "Low end of range must be less than high end.";
00952
00953 QMessageBox::critical ( this,
00954 "Range error",
00955 message.c_str(),
00956 QMessageBox::Ok,
00957 Qt::NoButton,
00958 Qt::NoButton );
00959 }
00960
00961 void
00962 Inspector::
00963 multipleDataRepError ( const std::string & type )
00964 {
00965 const string message
00966 = "Multiple data representations are active.\n"
00967 "Can not apply a " + type + ".\n\n"
00968 "Use Control-click to select only one data representation.";
00969 QMessageBox::information ( this,
00970 "Multiple data representation error",
00971 message.c_str(),
00972 QMessageBox::Ok,
00973 Qt::NoButton,
00974 Qt::NoButton );
00975 }
00976
00977 void
00978 Inspector::
00979 multiplePlotError ( )
00980 {
00981 QString message (
00982 "Multiple plots are selected.\n"
00983 "Can not apply change until only one is selected\n\n"
00984 "Use shift-click to deselect a selected plot" );
00985 QMessageBox::information ( this,
00986 "Multiple plot error",
00987 message,
00988 QMessageBox::Ok,
00989 Qt::NoButton,
00990 Qt::NoButton );
00991 }
00992
00993 void Inspector::functionAddError ()
00994 {
00995 const string message =
00996 "Functions are not supported on the selected data reaxisWitation.";
00997
00998 QMessageBox::critical ( this, "Function Add Error",
00999 message.c_str(),
01000 QMessageBox::Ok,
01001 Qt::NoButton,
01002 Qt::NoButton );
01003 }
01004
01008 void
01009 Inspector::
01010 newPlotError ( const DataSourceException & e )
01011 {
01012 string message ( "New plot could not be created because:\n" );
01013 message += e.what ();
01014 QMessageBox::critical ( this,
01015 "New plot error",
01016 message.c_str(),
01017 QMessageBox::Ok,
01018 Qt::NoButton,
01019 Qt::NoButton );
01020 }
01021
01022 #ifdef HAVE_ROOT
01023 std::string
01024 Inspector::
01025 getArrayTupleLabel( const DataSource * rtuple, const std::string & column )
01026 {
01027 RootController * controller = RootController::instance ();
01028 vector < int > dimSize;
01029 controller -> fillDimSize ( dimSize, rtuple, column );
01030
01031
01032 QString caption( "MultiDimensional data in rows of the column ");
01033 caption.append( QString( column.c_str() ) );
01034
01035
01036 std::ostringstream ost;
01037 ost << " Rows of this column are of size ";
01038
01039 unsigned int i;
01040 for( i = 0; i < dimSize.size() - 1; i++ )
01041 ost << dimSize[i] << " x ";
01042 ost << dimSize[i];
01043
01044 ost << "\n Enter C-style index of a single element of this";
01045 ost << "\n multidimentional data which you wish to analyse.";
01046 ost << "\n Index should be a comma separated list of ";
01047 ost << dimSize.size() << " integers.";
01048
01049 ost << "\n For e.g. ";
01050 for( i = 0; i < dimSize.size() - 1; i++ )
01051 ost << "0, ";
01052 ost << "0 \n";
01053
01054 string label( ost.str() );
01055
01056 bool ok;
01057 QString text = QInputDialog::getText( caption, QString( label.c_str() ),
01058 QLineEdit::Normal,
01059 QString::null, &ok, this );
01060
01061
01062 std::ostringstream labelstream;
01063 labelstream << column;
01064
01065 if ( ok && !text.isEmpty() )
01066 {
01067 vector< unsigned int > index;
01068 string s( text.ascii() );
01069
01070
01071
01072 boost::char_separator< char > sep( "," );
01073
01074
01075 typedef boost::tokenizer< boost::char_separator< char > > tokenizer;
01076 tokenizer tok( s, sep );
01077
01078
01079 for( tokenizer::iterator tok_iter = tok.begin();
01080 tok_iter != tok.end();
01081 ++tok_iter )
01082 {
01083 unsigned int idx = boost::lexical_cast< unsigned int >( *tok_iter );
01084 index.push_back( idx );
01085 labelstream << "[" << idx << "]";
01086 }
01087 }
01088
01089 return labelstream.str();
01090 }
01091
01092
01093 #endif
01094
01095 void
01096 Inspector::
01097 newPlotButton_clicked()
01098 {
01099 const vector < DataSource * > & nt_vector
01100 = DataSourceController::instance() -> getDataSources ();
01101
01102 if ( nt_vector.empty() )
01103 {
01104 noNTupleSelectedError ();
01105 return;
01106 }
01107
01108
01109 int current = m_all_ntuples->currentItem ();
01110 DataSource * ds = nt_vector[current];
01111
01112
01113 std::string plotTypeStr( (m_availPlotTypes -> currentText()).latin1() );
01114
01115
01116 vector < string > bindings;
01117 for ( unsigned int i = 0; i < m_new_combos.size(); i++ )
01118 {
01119 if ( m_new_combos [i] -> count () == 0 ) break;
01120
01121 QString qstring = m_new_combos [ i ] -> currentText();
01122 string column ( qstring.latin1() );
01123 string label = column;
01124
01125 #ifdef HAVE_ROOT
01126 if( column != "nil" && ds -> isMultiDimensional( column ) )
01127 {
01128 label = getArrayTupleLabel ( ds, column );
01129 RootController * rcontroller = RootController::instance();
01130 rcontroller -> smartExpandRootNTuple ( ds, column );
01131 }
01132 #endif
01133 bindings.push_back ( label );
01134 }
01135
01136
01137 try {
01138 DisplayController * controller = DisplayController::instance();
01139 PlotterBase * newDisplay =
01140 controller -> createDisplay ( plotTypeStr, * ds, bindings );
01141 CanvasWindow * canvas = WindowController::instance() -> currentCanvas();
01142 canvas->addPlotDisplay ( newDisplay, true );
01143
01144 bool valid = controller -> isDataValid ( newDisplay );
01145 if ( valid == false ) {
01146 invalidDataWarning ();
01147 }
01148 }
01149 catch ( const DataSourceException & e ) {
01150 newPlotError ( e );
01151 }
01152 }
01153
01154
01155 void
01156 Inspector::
01157 addDataRepButton_clicked()
01158 {
01159
01160
01161 PlotterBase * plotter = getPlotter ();
01162 if ( !plotter ) return;
01163
01164
01165 std::string plotTypeStr( (m_availPlotTypes->currentText()).latin1() );
01166
01167 const vector < DataSource * > & nt_vector
01168 = DataSourceController::instance() -> getDataSources ();
01169
01170 int current = m_all_ntuples->currentItem ();
01171 DataSource * ds = nt_vector[current];
01172
01173
01174
01175 vector < string > bindings;
01176 for ( unsigned int i = 0; i < m_new_combos.size(); i++ )
01177 {
01178 if ( m_new_combos [i] -> count () == 0 ) break;
01179
01180 QString qstring = m_new_combos [ i ] -> currentText();
01181 string column ( qstring.latin1() );
01182 string label = column;
01183 #ifdef HAVE_ROOT
01184 if ( column != "nil" && ds -> isMultiDimensional ( column ) ) {
01185 label = getArrayTupleLabel ( ds, column );
01186 RootController * rcontroller = RootController::instance ();
01187 rcontroller -> smartExpandRootNTuple ( ds, column );
01188 }
01189 #endif
01190 bindings.push_back ( label );
01191 }
01192
01193
01194
01195 DisplayController * controller = DisplayController::instance();
01196 DataRep * rep = controller -> addDataRep ( plotter, plotTypeStr, ds,
01197 bindings );
01198
01199 if ( rep == 0 ) incompatibleDataRepError ( plotTypeStr );
01200
01201 plotter -> autoScale ();
01202 bool valid = controller -> isDataValid ( rep );
01203 if ( valid == false ) {
01204 invalidDataWarning ();
01205 }
01206
01207 update ();
01208 }
01209
01210 void
01211 Inspector::
01212 dataCreateNTuple ()
01213 {
01214 const PlotterBase * plotter = getPlotter ();
01215 if ( plotter == 0 ) return;
01216 DisplayController * controller = DisplayController::instance ();
01217 controller -> createNTuple ( plotter );
01218
01219 update ();
01220 }
01221
01222
01223 void
01224 Inspector::
01225 fillPlotterList ( std::vector < PlotterBase * > & plotterlist )
01226 {
01227 plotterlist.clear();
01228 CanvasWindow * canvaz = WindowController::instance () ->currentCanvas();
01229
01230 if ( canvaz != 0 ) {
01231 canvaz -> fillPlotterList ( plotterlist );
01232 }
01233 }
01234
01235 void
01236 Inspector::
01237 ntupleChanged ( int index )
01238 {
01239 unsigned int size = m_plotter_list.size ();
01240 if ( size == 0 ) return;
01241
01242 CutController * controller = CutController::instance ();
01243 vector < PlotterBase * > web;
01244 controller -> fillCutWeb ( m_plotter_list, web );
01245 size = web.size ();
01246
01247 for ( unsigned int i = 0; i < size; i++ ) {
01248 PlotterBase * plotter = web [ i ];
01249 bool yes = plotter != 0;
01250 if ( yes ) yes = plotter -> isTargetable ();
01251 if ( yes == false ) continue;
01252
01253 DataRep * rep = plotter -> getTarget ();
01254 yes = rep -> hasNTupleBindings ();
01255 if ( yes == false ) continue;
01256
01257 DataSourceController * ds_controller = DataSourceController::instance ();
01258 const vector < string > & names = ds_controller -> getNTupleNames ();
01259 const string & ds_name = names [ index ];
01260 const DataSource * source = ds_controller -> getDataSource ( ds_name );
01261 DataRepController * dr_controller = DataRepController::instance ();
01262
01263 try {
01264 dr_controller -> changeDataSource ( rep, source );
01265 }
01266 catch ( const DataSourceException & e ) {
01267 string message ( "Could not change binding because\n" );
01268 message += e.what ();
01269 QMessageBox::critical ( this,
01270 "Data source error",
01271 message.c_str (),
01272 QMessageBox::Ok,
01273 Qt::NoButton,
01274 Qt::NoButton );
01275 }
01276 }
01277 }
01278
01282 void
01283 Inspector::
01284 updatePlotTab()
01285 {
01286 bool yes = m_plotter_list.empty();
01287 m_plot_title -> setDisabled ( yes );
01288
01289 PlotterBase * plotter = getPlotter ();
01290
01291 yes = plotter != 0;
01292 if ( yes ) yes = plotter -> isTargetable ();
01293
01294 m_plot_symbols->setEnabled ( yes );
01295 m_plot_color->setEnabled ( yes );
01296 m_interval_le->setEnabled ( yes );
01297 m_interval_cb->setEnabled ( yes );
01298 m_errorBars ->setEnabled ( yes );
01299 m_pointRepComboBox->setEnabled ( yes );
01300
01301 if ( yes == false ) return;
01302
01303
01304
01305
01306
01307 m_pointRepComboBox->clear();
01308
01309 DisplayController * controller = DisplayController::instance ();
01310 DataRep * datarep = controller -> activeDataRep ( plotter );
01311 assert ( datarep != 0 );
01312
01313 yes = datarep -> hasErrorDisplay ();
01314 m_errorBars -> setEnabled ( yes );
01315
01316 ProjectorBase * proj = datarep -> getProjector();
01317 const vector <string> & pointreps = proj -> getPointReps();
01318
01319 for (std::vector<string>::size_type i = 0; i < pointreps.size(); i++ ) {
01320 m_pointRepComboBox->insertItem ( pointreps[i].c_str() );
01321 }
01322
01323 if ( pointreps.empty () == false ) {
01324 RepBase * rep = datarep->getRepresentation();
01325 const string & curRep = rep->name();
01326 m_pointRepComboBox->setCurrentText ( curRep.c_str() );
01327 }
01328
01329 if ( plotter -> hasAxis ( Axes::Z ) == false ) {
01330 m_value_combo -> setDisabled ( true );
01331 m_slider_control -> setDisabled ( true );
01332 m_model_control -> setDisabled ( true );
01333 }
01334 else {
01335 int jndex = controller -> getValueTransformIndex ( plotter );
01336 if ( jndex < 0 ) {
01337 m_value_combo -> setDisabled ( true );
01338 }
01339 else {
01340 m_value_combo -> setEnabled ( true );
01341 m_value_combo -> setCurrentItem ( jndex );
01342
01343 bool yes = controller -> hasControlPoints ( plotter );
01344 m_slider_control -> setEnabled ( yes );
01345 m_model_control -> setEnabled ( yes );
01346
01347 if ( yes ) {
01348 const vector < double > & sv
01349 = controller -> getValueBrkPt ( plotter );
01350 brk_pt -> setValue
01351 ( static_cast<int> ( sv[0] * brk_pt -> maxValue() ) );
01352 flat_width -> setValue
01353 ( static_cast<int> (sv[1]* flat_width -> maxValue() ) );
01354 color_scale -> setValue
01355 ( static_cast<int> (sv[2]* color_scale -> maxValue() ) );
01356 }
01357 }
01358 }
01359
01360 const DataSource * nt = controller -> getNTuple ( plotter );
01361
01362 if ( nt && nt -> empty () ) {
01363 m_plot_symbols->setDisabled ( true );
01364 m_plot_title->setDisabled ( true );
01365 m_plot_color->setDisabled ( true );
01366 return;
01367 }
01368
01369 const std::string & st = plotter->getTitle();
01370 QString qst ( st.c_str() );
01371 m_titleText->setText ( qst );
01372
01373 m_errorBars->setChecked ( plotter->errorDisplay ( Axes::Y ) );
01374
01375 yes = controller -> hasSymbolRep ( plotter );
01376 m_symbol_group -> setEnabled ( yes );
01377
01378 if ( yes ) {
01379 m_point_stack -> raiseWidget ( 0 );
01380 unsigned int index = controller ->getRepStyle ( plotter );
01381 m_symbol_group -> setButton ( index );
01382 }
01383
01384
01385 yes = controller -> hasLineRep ( plotter );
01386 m_line_group -> setEnabled ( yes );
01387 if ( yes ) {
01388 m_point_stack -> raiseWidget ( 1 );
01389 unsigned int style = controller -> getRepStyle ( plotter );
01390 #if QT_VERSION < 0x040000
01391 QButton * button = m_line_group -> find ( style );
01392 #else
01393
01394 #endif
01395 QRadioButton * rb = dynamic_cast < QRadioButton * > ( button );
01396 rb -> setChecked ( true );
01397 }
01398
01399 float ptsize = controller -> pointSize ( plotter );
01400 m_symbolPointSize -> setText ( QString ("%1").arg (ptsize) );
01401
01402 const Color & color = plotter->repColor ();
01403 QColor qcolor ( color.getRed(), color.getGreen(), color.getBlue () );
01404 m_selectedColor->setPaletteBackgroundColor ( qcolor );
01405
01406 if ( nt == 0 ) {
01407 m_interval_cb -> setEnabled ( false );
01408 m_interval_le -> setEnabled ( false );
01409 return;
01410 }
01411 const NTuple * ntuple = dynamic_cast < const NTuple * > ( nt );
01412 yes = ntuple != 0 && ntuple -> isIntervalEnabled ();
01413 m_interval_cb->setChecked ( yes );
01414 m_interval_le->setEnabled ( yes );
01415
01416 if ( yes ) {
01417 unsigned int count = ntuple->getIntervalCount ();
01418 m_interval_le->setText ( QString ("%1").arg ( count ) );
01419 }
01420 }
01421
01422 void
01423 Inspector::
01424 valueChanged ( int index )
01425 {
01426 PlotterBase * plotter = getPlotter ();
01427 if ( plotter != 0 ) {
01428 loadAllUsrModels ();
01429 DisplayController * controller = DisplayController::instance ();
01430 controller -> setValueTransform ( plotter, index , usr_models ,
01431 brk_points, flat_widths,color_scales);
01432
01433 bool yes = controller -> hasControlPoints ( plotter );
01434 m_slider_control -> setEnabled ( yes );
01435 m_model_control -> setEnabled ( yes );
01436 if ( yes ) {
01437 flat_width ->setValue(50);
01438 brk_pt->setValue (50);
01439
01440 }
01441 }
01442 }
01443
01444 void
01445 Inspector::
01446 loadAllUsrModels ()
01447
01448 {
01449 usr_models.clear();
01450 brk_points.clear();
01451 flat_widths.clear();
01452 color_scales.clear();
01453
01454 QSettings settings;
01455 settings.insertSearchPath ( QSettings::Windows, s_registry );
01456
01457 int length = ( settings.entryList(s_app_key + "/Model Name/")).size( );
01458 for ( int i = 0; i < length ; i++ )
01459 {
01460 QString name = settings.readEntry ( s_app_key + "/Model Name/" +
01461 QString::number ( i ) );
01462 usr_models.push_back( name.ascii() );
01463
01464 double brk_pt = settings.readDoubleEntry ( s_app_key +
01465 "/break point/" +
01466 QString::number ( i ) );
01467 brk_points.push_back( brk_pt );
01468
01469
01470 double flat_width = settings.readDoubleEntry ( s_app_key +
01471 "/flat width/" +
01472 QString::number ( i ) );
01473 flat_widths.push_back( flat_width );
01474
01475
01476 double color_scale = settings.readDoubleEntry ( s_app_key +
01477 "/color scale/" +
01478 QString::number ( i ) );
01479 color_scales.push_back( color_scale );
01480
01481 }
01482 }
01483
01484
01485
01486 void
01487 Inspector::
01488 sliderChanged ( int index )
01489 {
01490 vector < double > sv;
01491
01492 double m = brk_pt -> maxValue ();
01493 assert(m != 0);
01494 sv.push_back ( (brk_pt -> value()) / m + 0.001);
01495
01496 double w = flat_width -> maxValue();
01497 assert(w != 0);
01498 sv.push_back ( (flat_width -> value()) / w + 0.001);
01499
01500 double c = color_scale -> maxValue ();
01501 assert( c!= 0 );
01502 sv.push_back ( ( ( (color_scale -> value()) / c ) ) * 1.5 );
01503
01504 PlotterBase * plotter = getPlotter ();
01505 if ( plotter != 0 ) {
01506 DisplayController * controller = DisplayController::instance ();
01507 controller -> setValueBrkPt (plotter,sv );
01508 }
01509 }
01510
01511 void
01512 Inspector::
01513 resetSlider ( )
01514 {
01515 if ( m_slider_control -> isEnabled () )
01516 {
01517 brk_pt -> setValue ( 50 );
01518 flat_width -> setValue ( 50 );
01519 color_scale -> setValue ( 50 );
01520 }
01521 }
01522
01523
01524 void
01525 Inspector::
01526 newColorModel ( )
01527 {
01528 NewModelDialog * dialog = new NewModelDialog ( this );
01529 dialog -> set_brk_pt ( brk_pt -> value () );
01530 dialog -> set_flat_width ( flat_width -> value () );
01531 dialog -> set_color_scale ( color_scale -> value () );
01532
01533 int retval = dialog -> exec ( );
01534 if ( retval == QDialog::Accepted )
01535 {
01536 m_value_combo -> insertItem ( dialog -> get_model_name ( ) );
01537 double bp = static_cast <double>(dialog -> get_brk_pt ()) /
01538 static_cast <double>( brk_pt -> maxValue () );
01539
01540 double fw = static_cast <double>(dialog -> get_flat_width ()) /
01541 static_cast <double>( flat_width -> maxValue () );
01542
01543 double cs = static_cast <double>(dialog -> get_color_scale ()) /
01544 static_cast <double>(color_scale -> maxValue () );
01545
01546 QSettings settings;
01547 settings.insertSearchPath ( QSettings::Windows, s_registry );
01548
01549 int length = (settings.entryList(s_app_key + "/Model Name/")).size( );
01550
01551 settings.writeEntry ( s_app_key + "/Model Name/" +
01552 QString::number (length ),
01553 dialog -> get_model_name ( ) );
01554
01555 settings.writeEntry ( s_app_key + "/break point/" +
01556 QString::number (length ), bp );
01557
01558 settings.writeEntry ( s_app_key + "/flat width/" +
01559 QString::number (length ), fw);
01560
01561 settings.writeEntry ( s_app_key + "/color scale/" +
01562 QString::number (length ), cs);
01563
01564
01565 loadAllUsrModels ();
01566
01567 }
01568 delete dialog;
01569 if ( retval == QDialog::Rejected ) return;
01570 }
01571
01572
01573 void
01574 Inspector::
01575 editColorModel ( )
01576 {
01577 loadAllUsrModels ();
01578 if ( ( usr_models.size() != 0 ) ){
01579
01580 int i = m_value_combo -> currentItem ();
01581 int index = i - (m_value_combo -> count () - usr_models.size () );
01582 if ( index >= 0){
01583 EditModelDialog * dialog = new EditModelDialog ( this,
01584 usr_models [ index ] ,
01585 brk_points[ index ] ,
01586 flat_widths [ index ],
01587 color_scales [ index ],
01588 brk_pt -> maxValue(),
01589 flat_width -> maxValue(),
01590 color_scale -> maxValue() );
01591
01592 int retval = dialog -> exec ( );
01593 if ( retval == QDialog::Accepted )
01594 {
01595 double bp = static_cast <double>(dialog -> get_brk_pt ()) /
01596 static_cast <double>( brk_pt -> maxValue () );
01597
01598 double fw = static_cast <double>(dialog -> get_flat_width ()) /
01599 static_cast <double>( flat_width -> maxValue () );
01600
01601 double cs = static_cast <double>(dialog -> get_color_scale ()) /
01602 static_cast <double>( color_scale -> maxValue () );
01603
01604 QSettings settings;
01605 settings.insertSearchPath ( QSettings::Windows, s_registry );
01606
01607 settings.writeEntry ( s_app_key + "/Model Name/" +
01608 QString::number ( index ),
01609 dialog -> get_model_name ( ) );
01610
01611 settings.writeEntry ( s_app_key + "/break point/" +
01612 QString::number (index ), bp );
01613
01614 settings.writeEntry ( s_app_key + "/flat width/" +
01615 QString::number (index ), fw);
01616
01617 settings.writeEntry ( s_app_key + "/color scale/" +
01618 QString::number (index ), cs);
01619
01620 loadAllUsrModels ();
01621
01622 }
01623 delete dialog;
01624 if ( retval == QDialog::Rejected ) return;
01625 }
01626 }
01627 }
01628
01629
01630 void
01631 Inspector::
01632 deleteColorModel ( )
01633 {
01634 loadAllUsrModels();
01635 if ( usr_models.size () != 0 ){
01636 int i = m_value_combo -> currentItem ();
01637 int index = i - (m_value_combo -> count () - usr_models.size () );
01638 if ( index >= 0 ){
01639 m_value_combo -> removeItem ( i );
01640 QSettings settings;
01641 settings.insertSearchPath ( QSettings::Windows, s_registry );
01642 for ( unsigned int j = index ; j < usr_models.size () - 1 ; j++ )
01643 {
01644
01645 QString name = settings.readEntry ( s_app_key + "/Model Name/" +
01646 QString::number ( j + 1 ) );
01647 settings.writeEntry ( s_app_key + "/Model Name/" +
01648 QString::number ( j ),
01649 name );
01650
01651 double bp = settings.readDoubleEntry ( s_app_key +
01652 "/break point/" +
01653 QString::number ( j + 1 ) );
01654 settings.writeEntry ( s_app_key + "/break point/" +
01655 QString::number ( j ),
01656 bp );
01657
01658 double fw = settings.readDoubleEntry ( s_app_key +
01659 "/flat width/" +
01660 QString::number ( j + 1 ) );
01661 settings.writeEntry ( s_app_key + "/flat width/" +
01662 QString::number ( j ),
01663 fw );
01664
01665 double cs = settings.readDoubleEntry ( s_app_key +
01666 "/color scale/" +
01667 QString::number ( j + 1 ) );
01668 settings.writeEntry ( s_app_key + "/color scale/" +
01669 QString::number ( j ),
01670 cs );
01671 }
01672
01673
01674 int last = usr_models.size () - 1 ;
01675 settings.removeEntry ( s_app_key + "/Model Name/" +
01676 QString::number ( last ));
01677 settings.removeEntry ( s_app_key + "/break point/" +
01678 QString::number ( last ));
01679 settings.removeEntry ( s_app_key + "/flat width/" +
01680 QString::number ( last ));
01681 settings.removeEntry ( s_app_key + "/color scale/" +
01682 QString::number ( last ));
01683
01684
01685 loadAllUsrModels();
01686
01687 }
01688 }
01689
01690 }
01691
01692 void
01693 Inspector::
01694 errorBars_toggled( bool )
01695 {
01696 PlotterBase * plotter = getPlotter ();
01697 if ( !plotter ) return;
01698
01699 bool checked = m_errorBars->isChecked();
01700 DisplayController * controller = DisplayController::instance ();
01701
01702 controller -> setErrorDisplayed ( plotter, Axes::Y, checked );
01703 }
01704
01705 void
01706 Inspector::
01707 titleText_returnPressed()
01708 {
01709 std::string s( (m_titleText->text()).latin1() );
01710 unsigned int size = m_plotter_list.size();
01711
01712 for ( unsigned int i = 0; i < size; i++ ) {
01713 PlotterBase * plotter = m_plotter_list [ i ];
01714 plotter->setTitle ( s );
01715 }
01716 }
01717
01718 void Inspector::symbolTypeButtonGroup_clicked ( int id )
01719 {
01720 m_symbol_group -> setButton ( id );
01721 PlotterBase * plotter = getPlotter ();
01722 if ( !plotter ) return ;
01723
01724 DisplayController * controller = DisplayController::instance ();
01725 DataRep * rep = controller -> activeDataRep ( plotter );
01726 if ( rep == 0 ) {
01727 multipleDataRepError ( "plot symbol change" );
01728 return;
01729 }
01730
01731 rep -> setRepStyle ( id );
01732 }
01733
01734 void Inspector::lineStyleButtonGroup_clicked ( int id )
01735 {
01736
01737 m_line_group -> setButton ( id );
01738 PlotterBase * plotter = getPlotter ();
01739 if ( !plotter ) return ;
01740
01741 DisplayController * controller = DisplayController::instance ();
01742 DataRep * rep = controller -> activeDataRep ( plotter );
01743 if ( rep == 0 ) {
01744 multipleDataRepError ( "plot symbol change" );
01745 return;
01746 }
01747
01748 rep -> setRepStyle ( id );
01749 }
01750
01751 void Inspector::symbolPointSize_returnPressed()
01752 {
01753
01754 PlotterBase * plotter = getPlotter ();
01755 if ( !plotter ) return;
01756
01757 DisplayController * controller = DisplayController::instance ();
01758 DataRep * rep = controller -> activeDataRep ( plotter );
01759 if ( rep == 0 ) {
01760 multipleDataRepError ( "plot symbol size change" );
01761 return;
01762 }
01763
01764 QString text = m_symbolPointSize->text();
01765 float size = text.toFloat();
01766
01767 rep->setRepSize ( size );
01768
01769 }
01770
01771
01772 void Inspector::intervalStateChanged ( bool state )
01773 {
01774 PlotterBase * plotter = getPlotter ();
01775 if ( plotter == 0 ) return;
01776
01777 DisplayController * controller = DisplayController::instance ();
01778 controller->setIntervalEnabled ( plotter, state );
01779 m_interval_le->setEnabled ( state );
01780 }
01781
01782
01783 void Inspector::intervalTextChanged ( const QString & text )
01784 {
01785 PlotterBase * plotter = getPlotter ();
01786 if ( plotter == 0 ) return;
01787
01788 DisplayController * controller = DisplayController::instance ();
01789
01790 unsigned int interval = text.toUInt ();
01791 controller->setIntervalCount ( plotter, interval );
01792 }
01793
01794 void
01795 Inspector::
01796 colorSelect_clicked()
01797 {
01798 PlotterBase * plotter = getPlotter ();
01799 if ( !plotter ) return;
01800
01801 int index = plotter->activePlotIndex ();
01802
01803 if ( index < 0 ) {
01804 multipleDataRepError ( "color change" );
01805 return;
01806 }
01807
01808 const Color & rep_color = plotter->repColor();
01809 QColor color ( rep_color.getRed(),
01810 rep_color.getGreen(),
01811 rep_color.getBlue() );
01812 color = QColorDialog::getColor ( color );
01813 if ( color.isValid() == false ) return;
01814
01815 m_selectedColor->setPaletteBackgroundColor ( color );
01816
01817 Color c ( color.red(), color.green(), color.blue() );
01818 plotter->setRepColor ( c );
01819 }
01820
01821 void
01822 Inspector::
01823 pointRepComboBox_activated ( const QString & qstr )
01824 {
01825 PlotterBase * plotter = getPlotter ();
01826
01827 if ( plotter != 0 ) {
01828 DisplayController * controller = DisplayController::instance ();
01829 const string rep ( qstr.latin1() );
01830
01831
01832 controller -> setRepresentation ( plotter, rep );
01833
01834 if ( plotter -> hasAxis ( Axes::Z ) == true ) {
01835
01836 int index = m_value_combo -> currentItem ();
01837 controller -> setValueTransform ( plotter, index , usr_models ,
01838 brk_points, flat_widths,color_scales);
01839 }
01840
01841 updatePlotTab ();
01842 }
01843 }
01844
01845 void
01846 Inspector::
01847 on_axis_button_group_clicked ( int id )
01848 {
01849 m_axis = Axes::convert ( id );
01850 updateAxisTab ();
01851 }
01852
01853 void
01854 Inspector::
01855 axisZoomPanCheckBox_clicked()
01856 {
01857 PlotterBase * plotter = getPlotter ();
01858 if ( !plotter ) return;
01859
01860 plotter->setAutoRanging ( m_axis, false );
01861 const Range & r = plotter->getRange ( m_axis, true );
01862
01863 m_autoScale->setChecked ( false );
01864
01865 if ( axisWidget1->isZoomPanChecked() ) {
01866 m_zoompan[plotter] = true;
01867 }
01868
01869 else {
01870
01871 std::map < const PlotterBase *, bool >::const_iterator it
01872 = m_zoompan.find ( plotter );
01873 if ( it != m_zoompan.end () ) {
01874 m_zoompan[plotter] = false;
01875 }
01876
01877 }
01878
01879 axisWidget1->processZoomPanCheckBoxClicked ( r, r );
01880 }
01881
01882 void
01883 Inspector::
01884 highRangeDrag()
01885 {
01886
01887 int value = axisWidget1->getHighSliderValue ();
01888 setHighRange ( value, false );
01889
01890 axisWidget1->setHighSliderValue ( 50 );
01891 }
01892
01893 void
01894 Inspector::
01895 lowRangeDrag()
01896 {
01897 int value = axisWidget1->getLowSliderValue ();
01898 setLowRange ( value, false );
01899
01900 axisWidget1->setLowSliderValue ( 50 );
01901 }
01902
01903 void
01904 Inspector::
01905 offsetDrag()
01906 {
01907 int value = m_offset_range->value ();
01908 setOffset ( value, false );
01909 m_offset_range->setValue ( 50 );
01910 }
01911
01912 void
01913 Inspector::
01914 widthDrag ()
01915 {
01916 int value = m_width_range->value ();
01917 setBinWidth ( value, false );
01918
01919 m_width_range->setValue ( 50 );
01920 }
01921
01922 void
01923 Inspector::
01924 setWidthText()
01925 {
01926 PlotterBase * plotter = getPlotter ();
01927 if ( !plotter ) return;
01928
01929 DisplayController * controller = DisplayController::instance ();
01930 int index = controller -> activeDataRepIndex ( plotter );
01931 bool yes = controller -> hasNTupleBindings ( plotter, index );
01932 if ( yes ) {
01933
01934 QString text = m_width_text->text();
01935 double width = text.toDouble();
01936
01937 if ( width == 0 ) return;
01938
01939 controller -> setBinWidth ( plotter, m_axis, width );
01940 }
01941
01942 updateAxisTab();
01943 }
01944
01945 void
01946 Inspector::
01947 setDragOn ()
01948 {
01949 m_dragging = true;
01950
01951 if ( ! axisWidget1->isZoomPanChecked() )
01952 {
01953 m_autoScale->setChecked ( false );
01954 autoScale_clicked ();
01955 }
01956 else
01957 {
01958
01959 m_autoScale->setChecked ( false );
01960 autoScale_clicked ();
01961
01962 PlotterBase * plotter = getPlotter ();
01963 if ( !plotter ) return;
01964 const Range & r = plotter->getRange ( m_axis, true );
01965 m_range.setRange ( r.low(), r.high(), r.pos() );
01966 }
01967
01968 }
01969
01970 void
01971 Inspector::
01972 setOffsetText()
01973 {
01974 PlotterBase * plotter = getPlotter ();
01975 if ( !plotter ) return;
01976
01977 DisplayController * controller = DisplayController::instance ();
01978 int index = controller -> activeDataRepIndex ( plotter );
01979 bool yes = controller -> hasNTupleBindings ( plotter, index );
01980 if ( yes ) {
01981
01982 QString text = m_offset_text->text();
01983 double offset = text.toDouble();
01984
01985 int value = static_cast < int > ( 50.0 * offset ) + 49;
01986 setDragOn ();
01987 setOffset( value );
01988 offsetDrag ();
01989 }
01990
01991 updateAxisTab ();
01992 }
01993
01994 void
01995 Inspector::
01996 setBinWidth ( int value )
01997 {
01998 setBinWidth ( value, m_dragging );
01999
02000 if ( m_dragging == false ) m_width_range -> setValue ( 50 );
02001 }
02002
02003 void
02004 Inspector::
02005 setBinWidth ( int value, bool drag )
02006 {
02007 PlotterBase * plotter = getPlotter ();
02008 if ( !plotter ) return;
02009 m_dragging = drag;
02010
02011 const string axis = convertToString ( m_axis );
02012 DisplayController * controller = DisplayController::instance ();
02013 controller -> setBinWidth ( plotter, axis, value, m_dragging );
02014 double width = plotter->getBinWidth ( m_axis );
02015 m_width_text -> setText ( QString ("%1").arg (width) );
02016 bool has_ntuple = controller->hasNTupleBindings ( plotter, 0 );
02017 m_width_text->setReadOnly ( ! has_ntuple );
02018 }
02019
02020 void
02021 Inspector::
02022 axisLabelText()
02023 {
02024 PlotterBase * plotter = getPlotter ();
02025 if ( plotter != 0 ) {
02026 QString text = m_axis_label -> text ();
02027 const string ltext = text.latin1();
02028 const string axis = convertToString ( m_axis );
02029 plotter -> setLabel ( m_axis, ltext );
02030 }
02031 }
02032
02033 void
02034 Inspector::
02035 setLowText()
02036 {
02037
02038 PlotterBase * plotter = getPlotter ();
02039 if ( !plotter ) return;
02040
02041 Range r = plotter->getRange ( m_axis, true );
02042
02043 axisWidget1->processTextBoxReturnPressed ( r, r );
02044
02045 plotter->setRange ( m_axis, r, true, false );
02046 m_autoScale->setChecked ( false );
02047
02048 updateAxisTab ();
02049 }
02050
02051 void
02052 Inspector::
02053 setLowRange ( int value )
02054 {
02055 if ( m_is_updating == false ) {
02056 setLowRange ( value, m_dragging );
02057 if ( m_dragging == false ) {
02058 axisWidget1->setLowSliderValue ( 50 );
02059 }
02060 }
02061 }
02062
02063 void
02064 Inspector::
02065 setLowRange ( int value, bool yes )
02066 {
02067 PlotterBase * plotter = getPlotter ();
02068 if ( !plotter ) return;
02069 m_dragging = yes;
02070
02071 plotter->setAutoRanging ( m_axis, false );
02072
02073 if ( ! axisWidget1->isZoomPanChecked() )
02074 {
02075 const string axis = convertToString ( m_axis );
02076 plotter->setLowRange ( m_axis, value, m_dragging );
02077 const Range & r = plotter->getRange ( m_axis, true );
02078 double low = r.low();
02079 axisWidget1 -> setLowText ( QString("%1").arg(low));
02080 }
02081 else
02082 {
02083 const Range & r = plotter->getRange ( m_axis, true );
02084 Range range ( r.low(), r.high(), r.pos() );
02085 axisWidget1->processLowSliderMoved ( value, range, m_range );
02086 if ( m_dragging ) plotter->setRange ( m_axis, range, true, false );
02087 }
02088 }
02089
02090 void
02091 Inspector::
02092 setHighRange ( int value )
02093 {
02094 if ( m_is_updating == false ) {
02095 setHighRange ( value, m_dragging );
02096 if ( m_dragging == false ) {
02097 axisWidget1->setHighSliderValue ( 50 );
02098 }
02099 }
02100 }
02101
02102 void
02103 Inspector::
02104 setHighRange ( int value, bool yes )
02105 {
02106 PlotterBase * plotter = getPlotter ();
02107 if ( !plotter ) return;
02108 m_dragging = yes;
02109
02110 plotter->setAutoRanging ( m_axis, false );
02111
02112 if ( !axisWidget1->isZoomPanChecked() )
02113 {
02114 const string axis = convertToString ( m_axis );
02115 plotter->setHighRange ( m_axis, value, m_dragging );
02116 const Range & r = plotter->getRange ( m_axis, true );
02117 double high = r.high();
02118 axisWidget1 -> setHighText ( QString("%1").arg(high));
02119 return;
02120 }
02121
02122
02123 BinaryTransform *t =
02124 dynamic_cast< BinaryTransform* > ( plotter->getTransform() );
02125
02126 if ( axisWidget1->isZoomPanChecked() && ! t->isPeriodic() )
02127 {
02128 const Range & r = plotter->getRange ( m_axis, true );
02129 Range range ( r.low(), r.high(), r.pos() );
02130 axisWidget1->processHighSliderMoved ( value, range, m_range );
02131 if ( m_dragging ) plotter->setRange ( m_axis, range, true, false );
02132 return;
02133 }
02134
02135 double offset(0.0), incr(0.0);
02136
02137 if ( axisWidget1->isZoomPanChecked() && t->isPeriodic() )
02138 {
02139 PeriodicBinaryTransform *tp =
02140 dynamic_cast< PeriodicBinaryTransform* > ( t );
02141
02142 const Range & r = plotter->getRange ( m_axis, true );
02143 Range * range = new Range ( r.low(), r.high(), r.pos() );
02144
02145 incr = ( value - m_highslider1_last_val ) * r.length() / 100;
02146 m_highslider1_last_val = value;
02147
02148 if ( m_axis == Axes::X )
02149 {
02150 offset = tp->xOffset();
02151 offset = tp->moduloAddX( offset, incr );
02152 tp->setXOffset( offset );
02153 }
02154 else if ( m_axis == Axes::Y )
02155 {
02156 offset = tp->yOffset();
02157 offset = tp->moduloAddY( offset, incr );
02158 tp->setYOffset( offset );
02159 }
02160
02161 axisWidget1 -> setHighText ( QString( "%1" ).arg( offset ) );
02162 if ( m_dragging ) plotter->setRange ( m_axis, *range, true );
02163 delete ( range );
02164 return;
02165 }
02166 }
02167
02168 void
02169 Inspector::
02170 setHighText()
02171 {
02172
02173 PlotterBase * plotter = getPlotter ();
02174 if ( !plotter ) return;
02175
02176 Range r = plotter->getRange ( m_axis, true );
02177
02178 axisWidget1->processTextBoxReturnPressed ( r, r );
02179
02180 plotter->setRange ( m_axis, r, true, false );
02181 m_autoScale->setChecked ( false );
02182
02183 updateAxisTab ();
02184 }
02185
02186 void
02187 Inspector::
02188 setOffset ( int value )
02189 {
02190 setOffset( value, m_dragging );
02191 }
02192
02193 void
02194 Inspector::
02195 setOffset ( int value, bool yes )
02196 {
02197 PlotterBase * plotter = getPlotter ();
02198 if ( !plotter ) return;
02199 m_dragging = yes;
02200
02201 const string axis = convertToString ( m_axis );
02202 DisplayController * controller = DisplayController::instance();
02203 controller -> setOffset ( plotter, axis, value, m_dragging );
02204 double offset = plotter->getOffset ( m_axis );
02205 m_offset_text -> setText ( QString ("%1").arg (offset) );
02206
02207 }
02208
02209 const std::vector < PlotterBase * > &
02210 Inspector::
02211 getDataCutList ( PlotterBase * plotter )
02212 {
02213 vector < PlotterBase * > plotterlist;
02214 fillPlotterList ( plotterlist );
02215
02216 int numDataReps = plotter -> getNumDataReps();
02217
02218 DisplayController * controller = DisplayController::instance ();
02219 int index = controller ->activeDataRepIndex ( plotter );
02220 const DataSource * tuple;
02221 CutController * cutcontroller = CutController::instance();
02222
02223 if( index >= 0 || numDataReps < 2 ) {
02224 tuple = controller -> getNTuple( plotter );
02225 }
02226 else
02227 {
02228 tuple = controller -> getNTuple( plotter, 0 );
02229
02230 for( int i = 1; i < numDataReps; i++ ) {
02231 const DataSource * nt = controller -> getNTuple( plotter, i );
02232 if ( tuple != nt )
02233 {
02234 tuple = 0;
02235 break;
02236 }
02237 }
02238 }
02239
02240 return cutcontroller->getCutList ( plotterlist, tuple );
02241 }
02242
02243 void
02244 Inspector::
02245 cutText_returnPressed ()
02246 {
02247 m_is_updating = true;
02248
02249 bool fit_cut = cut_button_group -> selected () == m_cut_fit_radio;
02250
02251 int index = m_selCutComboBox -> currentItem ();
02252 Range currentRange = m_tuple_cuts [index] -> getRange();
02253 PlotterBase * plotter = getSelectedCut();
02254
02255 if ( fit_cut == false ) {
02256 Axes::Type cut_axis = getAxes ( index );
02257 const Range & fullRange = plotter -> getRange ( cut_axis, false );
02258 axisWidget2->processTextBoxReturnPressed ( currentRange, fullRange );
02259 plotter->setCutRangeAt ( currentRange, cut_axis );
02260 }
02261 else {
02262 const Range & fullRange = plotter -> getRange ( Axes::X, false );
02263 axisWidget2->processTextBoxReturnPressed ( currentRange, fullRange );
02264 plotter->setCutRangeAt ( currentRange, index );
02265 }
02266 }
02267
02268 void Inspector::disableCutControls ( bool yes )
02269 {
02270 axisWidget2->setAllDisabled ( yes );
02271 colorSelect_2->setDisabled ( yes );
02272 cutRemovePushButton->setDisabled ( yes );
02273 cutInvertPushButton->setDisabled ( yes );
02274 cutEnablePushButton -> setDisabled ( yes );
02275 m_cutAddSelected->setDisabled ( yes );
02276 m_cutAddAll -> setDisabled ( yes );
02277
02278 if ( yes ) {
02279 int number = m_selCutComboBox -> count ();
02280 while ( number-- > 0 ) {
02281 m_selCutComboBox -> removeItem ( 0 );
02282 }
02283 }
02284 m_selCutComboBox -> setDisabled ( yes );
02285 }
02286
02287 void
02288 Inspector::
02289 updateTupleCuts ( const std::vector < PlotterBase * > & cutlist )
02290 {
02291 m_tuple_cuts.clear ();
02292 m_tuple_cut_plotters.clear ();
02293
02294 unsigned int size = cutlist.size ();
02295
02296 for ( unsigned int i = 0; i < size; i++ ) {
02297 PlotterBase * plotter = cutlist[i];
02298 TupleCutList_t cuts;
02299 plotter -> fillCutList ( cuts );
02300
02301 for ( unsigned int j = 0; j < cuts.size (); j++ ) {
02302 m_tuple_cuts.push_back ( cuts[j] );
02303 m_tuple_cut_plotters.push_back ( plotter );
02304 }
02305 }
02306 }
02307
02308 void
02309 Inspector::
02310 updateCutControls ( const std::vector < PlotterBase * > & cutlist )
02311 {
02312 QString old_current = m_selCutComboBox -> currentText ();
02313 int numberItems = m_selCutComboBox->count();
02314
02315 while ( numberItems-- > 0 ) {
02316 m_selCutComboBox->removeItem(0);
02317 }
02318
02319 m_selCutComboBox -> setEnabled ( true );
02320
02321 updateTupleCuts ( cutlist );
02322 bool yes = m_tuple_cuts.empty ();
02323 if ( yes ) {
02324 cutRemovePushButton -> setEnabled ( false );
02325 return;
02326 }
02327
02328 int index = -1;
02329 unsigned int size = m_tuple_cuts.size ();
02330
02331 for ( unsigned int i = 0; i < size; i++ ) {
02332 const TupleCut * cut = m_tuple_cuts[i];
02333 const string & label = cut -> getLabel ();
02334 QString item = label.c_str ();
02335 m_selCutComboBox -> insertItem ( item );
02336 if ( item == old_current ) index = i;
02337 }
02338
02339 PlotterBase * plotter = getPlotter ();
02340 assert ( plotter );
02341 index = -1;
02342 map < PlotterBase *, int > ::iterator first
02343 = m_cut_map.find ( plotter );
02344
02345 if ( first == m_cut_map.end () ) {
02346 index = 0;
02347 m_cut_map [ plotter ] = index;
02348 }
02349 else {
02350 index = first -> second;
02351 }
02352 int count = m_selCutComboBox -> count ();
02353 if ( index >= count ) {
02354 index = count -1;
02355 m_cut_map [ plotter] = index;
02356 }
02357
02358 m_selCutComboBox -> setCurrentItem ( index );
02359 updateCutEnableButton ();
02360 }
02361
02365 void
02366 Inspector::
02367 updateCutEnableButton ( )
02368 {
02369 if ( m_tuple_cuts.empty () ) return;
02370
02371 int index = m_selCutComboBox -> currentItem ();
02372 const TupleCut * cut = m_tuple_cuts [ index ];
02373 assert ( cut != 0 );
02374 bool yes = cut -> isEnabled ();
02375 m_cut_enable_updating = true;
02376 cutEnablePushButton -> setOn ( ! yes );
02377 m_cut_enable_updating = false;
02378 }
02379
02380 Axes::Type
02381 Inspector::
02382 getAxes ( unsigned int index )
02383 {
02384 Axes::Type axis = Axes::Y;
02385
02386 PlotterBase * plotter = m_tuple_cut_plotters [ index ];
02387 unsigned int size = m_tuple_cut_plotters.size ();
02388 for ( unsigned int i = 0; i < size; i++ ) {
02389 if ( m_tuple_cut_plotters[i] == plotter ) {
02390 if ( i == index ) {
02391 axis = Axes::X;
02392 }
02393 break;
02394 }
02395 }
02396
02397 return axis;
02398 }
02399
02400 void
02401 Inspector::
02402 updateCutControlValues ( const PlotterBase * cplotter )
02403 {
02404 m_is_updating = true;
02405 int index = m_selCutComboBox -> currentItem ();
02406 const Range & currentRange = m_tuple_cuts[index] -> getRange ();
02407
02408 Axes::Type cut_axis = Axes::X;
02409 bool fit_cut = cut_button_group -> selected () == m_cut_fit_radio;
02410 if ( fit_cut == false ) {
02411 cut_axis = getAxes ( index );
02412 }
02413 const Range & fullRange = cplotter->getRange ( cut_axis, false );
02414
02415 axisWidget2->updateCutControlValues ( currentRange, fullRange );
02416 CutController * controller = CutController::instance ();
02417
02418 bool yes
02419 = controller -> isZoomPan ( cplotter, cut_axis );
02420 axisWidget2 -> setZoomPan ( yes );
02421 axisWidget2->processZoomPanCheckBoxClicked ( currentRange, fullRange );
02422 m_is_updating = false;
02423 }
02424
02425 void
02426 Inspector::
02427 fillCutsOn ( const PlotterBase * plotter,
02428 std::vector < PlotterBase * > & cutlist )
02429 {
02430 cutlist.clear();
02431
02432 DisplayController * controller = DisplayController::instance ();
02433 const DataRep * datarep = controller -> activeDataRep ( plotter );
02434 if ( datarep != 0 ) {
02435 CutController * cutcontroller = CutController::instance();
02436
02437 cutcontroller->fillCutList ( datarep, cutlist );
02438 }
02439 }
02440
02441 const std::vector < const TupleCut * > &
02442 Inspector::
02443 getCutList ( const PlotterBase * plotter ) const
02444 {
02445 DisplayController * controller = DisplayController::instance ();
02446 int index = controller -> activeDataRepIndex ( plotter );
02447 if ( index < 0 ) {
02448 string what ( "Inspector::getCutList: " );
02449 what += "no active DataRep in PlotterBase object.";
02450 throw std::logic_error ( what );
02451 }
02452 const DataRep * datarep = plotter -> getDataRep ( index );
02453 CutController * cut_controller = CutController::instance ();
02454
02455 return cut_controller -> getCutList ( datarep );
02456 }
02457
02458 void
02459 Inspector::
02460 selectedCutsRadioButton_toggled ( bool selected )
02461 {
02462 if ( !m_selectedPlotRadioButton->isChecked() ) return;
02463
02464
02465
02466 PlotterBase * plotter = getPlotter ();
02467 bool yes = plotter != 0;
02468 if ( yes ) yes = plotter -> isTargetable ();
02469 disableCutControls ( yes == false );
02470 if ( yes == false ) return;
02471
02472 vector < PlotterBase * > cutlist;
02473
02474 if ( cut_button_group -> selected () != m_cut_fit_radio ) {
02475 fillCutsOn ( plotter, cutlist );
02476
02477
02478
02479 if ( cutlist.empty () ) {
02480 disableCutControls ( true );
02481 cutRemovePushButton->setEnabled ( false );
02482 return;
02483 }
02484 }
02485 else {
02486 FunctionController * controller = FunctionController::instance ();
02487 bool yes = controller -> hasFunction ( plotter, 0 );
02488 if ( yes ) cutlist.push_back ( plotter );
02489 }
02490
02491 updateCutControls ( cutlist );
02492
02493 if ( m_tuple_cuts.empty () ) {
02494 disableCutControls ( true );
02495 cutRemovePushButton->setEnabled ( false );
02496 return;
02497 }
02498
02499
02500
02501 disableCutControls ( false );
02502 cutRemovePushButton->setEnabled ( true );
02503 m_cutAddSelected -> setDisabled ( true );
02504 m_cutAddAll -> setDisabled ( true );
02505
02506
02507
02508 int index = m_selCutComboBox -> currentItem ();
02509 const PlotterBase * cut_plotter = m_tuple_cut_plotters [ index ];
02510 updateCutControlValues ( cut_plotter );
02511 }
02512
02513 void
02514 Inspector::
02515 cutAddSelected ()
02516 {
02517
02518
02519
02520
02521
02522 PlotterBase * cd = getSelectedCut();
02523
02524
02525 PlotterBase * plotter = getPlotter ();
02526 if ( !plotter ) return ;
02527
02528
02529 CutController * controller = CutController::instance();
02530 controller -> addCut ( cd, plotter );
02531
02532 }
02533
02534 void
02535 Inspector::
02536 cutAddAll ()
02537 {
02538 PlotterBase * plotter = getPlotter ();
02539 if ( plotter == 0 ) return;
02540
02541 CutController * controller = CutController::instance ();
02542 const vector < PlotterBase * > & cut_list = getDataCutList ( plotter );
02543 unsigned int size = cut_list.size ();
02544
02545 for ( unsigned int i = 0; i < size; i++ ) {
02546 PlotterBase * cut_plotter = cut_list[i];
02547 controller -> addCut ( cut_plotter, plotter );
02548 }
02549 }
02550
02551 void
02552 Inspector::cutRemovePushButton_clicked()
02553 {
02554
02555
02556
02557
02558
02559
02560 PlotterBase * plotter = getPlotter ();
02561 if ( !plotter ) return ;
02562
02563
02564
02565
02566 PlotterBase * cd = getSelectedCut();
02567 CutController::instance() -> removeCut ( cd, plotter );
02568
02569 if ( m_selectedPlotRadioButton -> isChecked () ) {
02570
02571 PlotterEvent * event = new PlotterEvent ( plotter );
02572 QApplication::postEvent ( this, event );
02573 }
02574 }
02575
02576 void
02577 Inspector::
02578 allCutsRadioButton_toggled ( bool selected )
02579 {
02580
02581 if ( !allCutsRadioButton->isChecked() ) return;
02582
02583 PlotterBase * plotter = getPlotter ();
02584
02585 bool yes = plotter != 0;
02586 if ( yes ) yes = plotter -> isTargetable ();
02587
02588 disableCutControls ( yes == false );
02589 if ( yes == false ) return;
02590
02591 const vector < PlotterBase * > & cutlist = getDataCutList ( plotter );
02592
02593
02594
02595 updateCutControls ( cutlist );
02596
02597 if ( cutlist.empty () ) {
02598 disableCutControls ( true );
02599 return;
02600 }
02601
02602
02603
02604 disableCutControls ( false );
02605 cutRemovePushButton->setDisabled ( true );
02606 m_cutAddSelected -> setEnabled ( true );
02607 m_cutAddAll -> setEnabled ( true );
02608
02609
02610
02611 const PlotterBase * cut_plotter = cutlist.back ();
02612 updateCutControlValues ( cut_plotter );
02613 }
02614
02615
02616 void Inspector::selCutChanged ( )
02617 {
02618 PlotterBase * cp = getSelectedCut ();
02619 CutPlotter * cut_plotter = dynamic_cast < CutPlotter * > ( cp );
02620 updateCutControlValues ( cut_plotter );
02621
02622 PlotterBase * plotter = getPlotter ();
02623 int index = m_selCutComboBox -> currentItem ();
02624 m_cut_map [ plotter ] = index;
02625
02626 updateCutEnableButton ();
02627 }
02628
02629 PlotterBase *
02630 Inspector::
02631 getSelectedCut ()
02632 {
02633 QButton * button = cut_button_group -> selected ();
02634 if ( button != m_cut_fit_radio ) {
02635 PlotterBase * plotter = getPlotter ();
02636 if ( plotter == 0 ) return 0;
02637
02638 m_last_cut_index = m_selCutComboBox->currentItem();
02639
02640 return m_tuple_cut_plotters [ m_last_cut_index ];
02641 }
02642 else {
02643 PlotterBase * plotter = getPlotter ();
02644 if ( plotter == 0 ) return 0;
02645 FunctionController * controller = FunctionController::instance ();
02646 bool yes = controller -> hasFunction ( plotter, 0 );
02647 if ( yes ) return plotter;
02648 else return 0;
02649 }
02650 }
02651
02659 void
02660 Inspector::
02661 cutNew()
02662 {
02663
02664
02665
02666
02667
02668 PlotterBase * plotter = getPlotter ();
02669 bool yes = plotter != 0;
02670
02671 if ( yes ) yes = plotter -> isTargetable ();
02672 if ( yes == false ) {
02673 int index = plotter -> activePlotIndex ();
02674 if ( index < 0 ) {
02675 multipleDataRepError ( "Cut" );
02676 }
02677 else {
02678 const string message ( "Can not apply cut to a function" );
02679 QMessageBox::information ( this,
02680 "Cut application error",
02681 message.c_str (),
02682 QMessageBox::Ok,
02683 Qt::NoButton,
02684 Qt::NoButton );
02685 }
02686 return;
02687 }
02688
02689 DisplayController * controller = DisplayController::instance ();
02690 int index = controller->activeDataRepIndex ( plotter );
02691 assert ( index >= 0 );
02692
02693 vector < string > bindings;
02694 QButton * button = cut_button_group -> selected ();
02695 int id = cut_button_group -> id ( button );
02696
02697 if ( button != m_cut_fit_radio ) {
02698 #if QT_VERSION < 0x030100 // 3.1.0
02699 string label1 ( m_CutVariableComboBox1 -> currentText() );
02700 string label2 ( m_CutVariableComboBox2 -> currentText() );
02701 #else
02702 QString text1 = m_CutVariableComboBox1 -> currentText();
02703 string label1 = text1.latin1();
02704 QString text2 = m_CutVariableComboBox2 -> currentText();
02705 string label2 = text2.latin1();
02706 #endif
02707
02708 switch ( id ) {
02709 case 0 :
02710 bindings.push_back( label1 );
02711 break;
02712 case 1 :
02713 bindings.push_back( label1 );
02714 bindings.push_back( label2 );
02715 break;
02716 }
02717 }
02718 else {
02719 const Range & range = plotter -> getRange ( Axes::X, false );
02720 FunctionController * f_controller = FunctionController::instance ();
02721 f_controller -> setFitRange ( plotter, range );
02722 }
02723
02724 CanvasWindow * canvas = WindowController::instance () ->currentCanvas();
02725 if ( canvas == 0 ) return;
02726
02727 if ( id < 2 ) {
02728 CutController * cutcontroller = CutController::instance();
02729 PlotterBase * cutplotter = cutcontroller -> addCut ( plotter, bindings );
02730 canvas -> addPlotDisplay ( cutplotter, false );
02731 }
02732
02733
02734 selectedCutsRadioButton_toggled ( true );
02735 allCutsRadioButton_toggled ( true );
02736 }
02737
02738 int
02739 Inspector::
02740 findCutIndex ( const QString & label )
02741 {
02742 int index = -1;
02743
02744 int size = m_selCutComboBox -> count ();
02745 for ( int i = 0; i < size; i++ ) {
02746 QString text = m_selCutComboBox -> text ( i );
02747 if ( text == label ) {
02748 index = i;
02749 break;
02750 }
02751 }
02752 return index;
02753 }
02754
02755 void
02756 Inspector::
02757 updateCutsTab ()
02758 {
02759 if ( m_new_plot_box->isEnabled () == false ) return;
02760
02761 PlotterBase * plotter = getPlotter ();
02762 bool yes = plotter != 0;
02763 m_new_cut_box->setEnabled ( yes );
02764
02765 if ( yes ) yes = plotter -> isTargetable ();
02766 m_cut_selected_box->setEnabled ( yes );
02767
02768 if ( yes ) {
02769 QButton * button = cut_button_group -> selected ();
02770 FunctionController * controller = FunctionController::instance ();
02771 yes = controller -> hasFunction ( plotter, 0 );
02772 m_cut_fit_radio -> setEnabled ( yes );
02773 bool is_fit_radio = button == m_cut_fit_radio;
02774 if ( yes == false && is_fit_radio ) {
02775 m_cut_data1 -> setChecked ( true );
02776 }
02777
02778 selectedCutsRadioButton_toggled (true );
02779 allCutsRadioButton_toggled ( true );
02780
02781 if ( is_fit_radio == false ) {
02782 updateDataCutsTab ();
02783 }
02784 else {
02785 updateFitCutsTab ();
02786 }
02787 }
02788 }
02789
02790 void
02791 Inspector::
02792 updateFitCutsTab ()
02793 {
02794 }
02795
02796 void
02797 Inspector::
02798 updateDataCutsTab ()
02799 {
02800 QButton * button = cut_button_group -> selected ();
02801 int id = cut_button_group -> id ( button );
02802
02803 if ( id == 0 ) {
02804 m_CutVariableComboBox2 -> setEnabled ( false );
02805 }
02806
02807 PlotterBase * plotter = getPlotter ();
02808 DisplayController * controller = DisplayController::instance ();
02809 int index = controller->activeDataRepIndex ( plotter );
02810 if ( index < 0 ) {
02811 m_new_cut_box -> setDisabled ( true );
02812 m_cut_selected_box -> setDisabled ( true );
02813 }
02814 else {
02815 DataRep * datarep = plotter->getDataRep ( index );
02816 if ( datarep->hasZeroRows() )
02817 {
02818 m_new_cut_box->setDisabled ( true );
02819 m_cut_selected_box->setDisabled ( true );
02820 return;
02821 }
02822
02823 m_new_cut_box->setDisabled ( false );
02824 const vector < PlotterBase * > & cuts = getDataCutList ( plotter );
02825 if ( cuts.empty() ) {
02826 m_cut_selected_box->setDisabled ( true );
02827 }
02828 else {
02829 m_cut_selected_box -> setDisabled ( false );
02830 }
02831 }
02832
02833 updateCutVarGroupBox ( plotter, index );
02834 }
02835
02836 void
02837 Inspector::
02838 setAllCutsActive ( bool yes )
02839 {
02840 vector < PlotterBase * > plotters;
02841 fillPlotterList ( plotters );
02842
02843 if ( plotters.empty () == false ) {
02844 CutController * controller = CutController::instance ();
02845 vector < CutPlotter * > cutters;
02846 controller -> fillCutList ( plotters, cutters );
02847 vector < CutPlotter * > ::iterator first = cutters.begin ();
02848
02849 while ( first != cutters.end () ) {
02850 CutPlotter * cutter = *first++;
02851 cutter -> setActive ( yes );
02852 }
02853 }
02854 }
02855
02856 void
02857 Inspector::
02858 updateCutVarGroupBox ( const PlotterBase * plotter, int index )
02859 {
02860 const DataSource * tuple
02861 = DisplayController::instance() -> getNTuple ( plotter, index );
02862
02863 if (!tuple) return;
02864 m_CutVariableComboBox1->clear();
02865
02866 const vector < string > & cols = tuple->getLabels();
02867 #ifdef ITERATOR_MEMBER_DEFECT
02868 std::
02869 #endif
02870 vector < string > ::const_iterator first = cols.begin ();
02871 while ( first != cols.end() ) {
02872 const string & str = *first++;
02873 m_CutVariableComboBox1 -> insertItem ( str.c_str() );
02874 m_CutVariableComboBox2 -> insertItem ( str.c_str() );
02875 }
02876
02877 m_CutVariableComboBox1 -> setCurrentItem ( 0 );
02878 m_CutVariableComboBox2 -> setCurrentItem ( 0 );
02879
02880 cut_button_group -> setEnabled ( true );
02881 QButton * button = cut_button_group -> selected ();
02882 int id = cut_button_group -> id ( button );
02883 if ( id == 1 ) {
02884 m_CutVariableComboBox2 -> setEnabled( true );
02885 }
02886 }
02887
02888
02889 void
02890 Inspector::
02891 on_cut_button_group_clicked ( int id )
02892 {
02893 switch ( id ) {
02894 case 0 :
02895 m_CutVariableComboBox1 -> setEnabled ( true );
02896 m_CutVariableComboBox2 -> setEnabled ( false );
02897 break;
02898 case 1 :
02899 m_CutVariableComboBox1 -> setEnabled ( true );
02900 m_CutVariableComboBox2 -> setEnabled ( true );
02901 break;
02902 case 2 :
02903 m_CutVariableComboBox1 -> setEnabled ( false );
02904 m_CutVariableComboBox2 -> setEnabled ( false );
02905 break;
02906 }
02907
02908 updateCutsTab ();
02909 }
02910
02913 void
02914 Inspector::
02915 updateFunctionsTab ()
02916 {
02917
02918
02919 const vector < string > & names = FunctionFactory::instance() -> names ();
02920 int current = newFunctionsComboBox->currentItem ();
02921 if ( newFunctionsComboBox -> count () !=
02922 static_cast < int > ( names.size () ) ) {
02923 newFunctionsComboBox->clear();
02924
02925 for ( unsigned int i = 0; i < names.size(); i++) {
02926 if ( names[i] != "Linear Sum" ) {
02927 newFunctionsComboBox->insertItem ( names[i].c_str() );
02928 }
02929 }
02930 }
02931
02932 PlotterBase * plotter = getPlotter();
02933 bool yes = plotter != 0;
02934 m_func_new->setEnabled ( yes );
02935
02936 if ( yes ) yes = plotter -> isTargetable ();
02937 functionsRemoveButton -> setEnabled ( yes );
02938 functionsFitToDataButton -> setEnabled ( yes );
02939 functionsResetButton -> setEnabled ( yes );
02940 functionsAppliedComboBox -> setEnabled ( yes );
02941 m_func_parms->setEnabled ( yes );
02942 m_resid->setEnabled ( yes );
02943 m_func_parms -> setEnabled ( yes );
02944 if ( yes == false ) {
02945 m_functionRep = 0;
02946 functionsAppliedComboBox -> clear();
02947 return;
02948 }
02949
02950 const DataSource * nt
02951 = DisplayController::instance()->getNTuple ( plotter );
02952
02953 if ( nt && nt -> empty () )
02954 {
02955 m_func_new->setDisabled ( true );
02956 functionsRemoveButton -> setEnabled ( false );
02957 functionsFitToDataButton -> setEnabled ( false );
02958 functionsResetButton -> setEnabled ( false );
02959 functionsAppliedComboBox -> clear ();
02960 functionsAppliedComboBox -> setEnabled ( false );
02961 m_func_parms->setDisabled ( true );
02962 m_functionRep = 0;
02963 return;
02964 }
02965
02966
02967
02968 newFunctionsAddButton->setEnabled ( true );
02969 m_func_new->setEnabled ( true );
02970
02971 newFunctionsComboBox->setCurrentItem(current);
02972 newFunctionsComboBox->setEnabled ( true );
02973
02974
02975
02976 bool to_enable = false;
02977 DisplayController * d_controller = DisplayController::instance ();
02978 int index = d_controller -> activeDataRepIndex ( plotter );
02979
02980 FunctionController * f_controller = FunctionController::instance ();
02981
02982 if ( index >= 0 ) {
02983 DataRep * datarep = plotter ->getDataRep ( index );
02984 if ( f_controller -> hasFunction ( plotter, datarep ) ) {
02985
02986 const vector < string > & fnames
02987 = f_controller -> functionNames ( plotter, datarep );
02988
02989 if ( fnames.size() != 0 )
02990 {
02991 to_enable = true;
02992 functionsAppliedComboBox->clear();
02993 m_functionIndexMap.clear();
02994
02995 for ( unsigned i = 0; i < fnames.size(); i++)
02996 {
02997 if ( fnames[i].find ( "Linear Sum" ) == string::npos )
02998 {
02999 functionsAppliedComboBox->insertItem ( fnames[i].c_str() );
03000 m_functionIndexMap.push_back ( i );
03001 }
03002 }
03003 functionsAppliedComboBox->setCurrentItem (0);
03004 }
03005 }
03006 }
03007
03008 functionsRemoveButton -> setEnabled ( to_enable );
03009 functionsFitToDataButton -> setEnabled ( to_enable );
03010 functionsResetButton -> setEnabled ( to_enable );
03011 m_func_parms -> setEnabled ( to_enable );
03012 functionsAppliedComboBox -> setEnabled ( to_enable );
03013 if ( to_enable == false ) {
03014 m_FunctionParamsListView -> clear();
03015 functionsAppliedComboBox -> clear ();
03016 }
03017
03018 if ( to_enable )
03019 {
03020
03021
03022 const vector < string > & fitters = f_controller -> getFitterNames ();
03023 Fitter * fitter = f_controller -> getFitter ( plotter );
03024 string name = "none";
03025 if ( fitter != 0 ) {
03026 name = f_controller -> getFitterName ( plotter );
03027
03028 for ( unsigned int i = 0; i < fitters.size(); i++ ) {
03029 if ( name == fitters[i] )
03030 {
03031 m_fitter_names -> setCurrentItem ( i );
03032 break;
03033 }
03034 }
03035 }
03036 }
03037
03038 m_resid->setEnabled ( to_enable );
03039
03040
03041
03042
03043
03044
03045
03046 if ( to_enable ) setParameters ( index, plotter );
03047
03048
03049 m_FunctionParamsSlider -> setValue(50);
03050
03051 }
03052
03053
03054 void Inspector::updateErrorEllipseTab()
03055 {
03056
03057 m_ComboBoxEllipsoidParamX -> clear();
03058 m_ComboBoxEllipsoidParamY -> clear();
03059
03060
03061
03062 m_ConfidenceEllipsoidsGroupBox -> setDisabled( false );
03063
03064
03065 PlotterBase * plotter = getPlotter ();
03066 TextPlotter * text = dynamic_cast < TextPlotter * > ( plotter );
03067 bool disable = plotter == 0 || text != 0;
03068
03069 int index = -1;
03070 if ( plotter != 0 ) {
03071 DisplayController * dc = DisplayController::instance ();
03072 index = dc -> activeDataRepIndex ( plotter );
03073 disable |= index < 0;
03074 }
03075
03076 if ( disable )
03077 {
03078 m_ConfidenceEllipsoidsGroupBox -> setDisabled( true );
03079 return;
03080 }
03081
03082
03083
03084
03085 PlotterBase* parentPlotter = plotter -> getParentPlotter();
03086
03087 if( parentPlotter == 0 )
03088 {
03089 DisplayController * dcontroller = DisplayController::instance ();
03090 index = dcontroller -> activeDataRepIndex ( plotter );
03091 plotter = plotter;
03092 m_PushButtonNewErrorPlot -> setText( QString( "New Error Plot" ) );
03093 }
03094 else
03095 {
03096 index = plotter -> getParentDataRepIndex();
03097 plotter = parentPlotter;
03098 m_PushButtonNewErrorPlot -> setText( QString( "Change Error Plot" ) );
03099 }
03100
03101
03102
03103
03104 const DataSource * nt
03105 = DisplayController::instance()->getNTuple ( plotter );
03106
03107 if ( nt && nt -> empty () )
03108 {
03109 m_ConfidenceEllipsoidsGroupBox -> setDisabled( true );
03110 return;
03111 }
03112
03113 DataRep * datarep = plotter -> getDataRep ( index );
03114
03115
03116 FunctionController * fcontroller = FunctionController::instance ();
03117 if ( ! ( fcontroller -> hasFunction ( plotter, datarep ) ) )
03118 {
03119 m_ConfidenceEllipsoidsGroupBox -> setDisabled( true );
03120 return;
03121 }
03122
03123
03124 FunctionRep * frep = fcontroller -> getFunctionRep( plotter, datarep );
03125 vector < string > paramNames;
03126 const vector < string > & names = frep -> parmNames ();
03127 const vector < int > & fixed = frep -> getFixedFlags ();
03128 unsigned int size = names.size ();
03129
03130 for ( unsigned int i = 0; i < size; i++ ) {
03131 if ( fixed [i] == 0 ) {
03132 paramNames.push_back ( names [i] );
03133 }
03134 }
03135
03136 for( unsigned int i = 0; i < paramNames.size(); i++ )
03137 {
03138 m_ComboBoxEllipsoidParamX -> insertItem ( paramNames[i].c_str() );
03139 m_ComboBoxEllipsoidParamY -> insertItem ( paramNames[i].c_str() );
03140 }
03141
03142
03143
03144
03145 fcontroller -> setEllpsoidParamIndex( Axes::X, 0 );
03146 fcontroller -> setEllpsoidParamIndex( Axes::Y, 0 );
03147 }
03148
03149 void
03150 Inspector::
03151 functionsRemoveButton_clicked()
03152 {
03153 PlotterBase * plotter = getPlotter ();
03154 if ( !plotter ) return ;
03155
03156
03157 int count = functionsAppliedComboBox -> count ();
03158 if ( count <= 0 ) return;
03159 QString qstr = functionsAppliedComboBox->currentText();
03160
03161 int item = functionsAppliedComboBox -> currentItem();
03162 unsigned int funcindex = m_functionIndexMap[item];
03163
03164
03165 FunctionController::instance() -> removeFunction ( plotter, funcindex );
03166
03167
03168 if ( plotter->activePlotIndex ( ) != 0 )
03169 plotter->setActivePlot ( -1, true );
03170 else
03171 plotter->setActivePlot ( 0, true );
03172
03173
03174 updateFunctionsTab();
03175 updateErrorEllipseTab();
03176 }
03177
03178 void
03179 Inspector::
03180 functionsResetButton_clicked()
03181 {
03182 PlotterBase * plotter = getPlotter ();
03183 if ( !plotter ) return ;
03184
03185 DisplayController * dcontroller = DisplayController::instance ();
03186 int index = dcontroller -> activeDataRepIndex ( plotter );
03187 if ( index < 0 ) return;
03188 DataRep * datarep = plotter -> getDataRep ( index );
03189
03190 FunctionController * fcontroller = FunctionController::instance();
03191 if ( ! ( fcontroller -> hasFunction ( plotter, datarep ) ) ) {
03192 return;
03193 }
03194
03195 fcontroller -> restoreParameters ( plotter );
03196
03197
03198 setParameters ( index, plotter );
03199 }
03200
03201 void
03202 Inspector::
03203 setParameters ( int index, PlotterBase * plotter )
03204 {
03205 m_FunctionParamsListView -> clear();
03206 m_FunctionParamsCheckBox -> setChecked( false );
03207 m_FunctionParamsLineEdit -> clear();
03208
03209 DataRep * datarep = plotter -> getDataRep ( index );
03210 assert ( datarep != 0 );
03211
03212 FunctionController * controller = FunctionController::instance ();
03213 if ( ! ( controller -> hasFunction ( plotter, datarep ) ) )
03214 {
03215 m_func_parms -> setDisabled ( true );
03216 m_functionRep = 0;
03217 return;
03218 }
03219
03220 m_func_parms -> setEnabled ( true );
03221
03222
03223 const vector < string > & fnames
03224 = controller -> functionNames ( plotter, datarep );
03225
03226 if ( fnames.empty () ) {
03227 m_func_parms -> setDisabled ( true );
03228 m_functionRep = 0;
03229 return;
03230 }
03231
03232 #if defined(QT_NO_STL) || QT_VERSION < 0x030100
03233 QString qyes( string("Yes").c_str() );
03234 QString qno( string("No").c_str() );
03235 #else
03236 QString qyes( string("Yes") );
03237 QString qno( string("No") );
03238 #endif
03239
03240 FunctionRep * frep = controller -> getFunctionRep( plotter, datarep );
03241 m_functionRep = frep;
03242
03243 const vector < string > & paramNames = frep -> parmNames();
03244 vector < int > fixedFlags;
03245 Fitter * fitter = frep -> getFitter ();
03246 if ( fitter != 0 ) {
03247 fixedFlags = frep -> getFixedFlags();
03248 }
03249 const vector < double > & parameters = frep -> parameters();
03250 const vector < double > & principleErrors = frep -> principleErrors();
03251
03252 unsigned int size = paramNames.size ();
03253 assert ( size == parameters.size() );
03254
03255 for( unsigned int pindex = 0; pindex < size; pindex++ )
03256 {
03257 #if QT_VERSION < 0x040000
03258 QListViewItem * item
03259 = new QListViewItem ( m_FunctionParamsListView );
03260 #else
03261 Q3ListViewItem * item
03262 = new Q3ListViewItem ( m_FunctionParamsListView );
03263 #endif
03264 item -> setText( 0, QString( "%1" ).arg( pindex + 1 ) );
03265
03266 #if defined(QT_NO_STL) || QT_VERSION < 0x030100
03267 QString pname ( paramNames[ pindex ].c_str() );
03268 #else
03269 QString pname ( paramNames[ pindex ] );
03270 #endif
03271 QString fixedFlag ( qno );
03272 if ( fitter != 0 ) {
03273 fixedFlag = ( fixedFlags[ pindex ] != 0 ) ? qyes : qno;
03274 }
03275
03276 item -> setText( 1, QString( "%1" ).arg( pname ) );
03277 item -> setText( 2, QString( "%1" ).arg( fixedFlag ) );
03278 item -> setText( 3, QString( "%1" ).arg( parameters[ pindex ] ) );
03279 if ( principleErrors.empty () ) {
03280 item -> setText ( 4, QString ( "nil" ) );
03281 }
03282 else{
03283 item -> setText( 4, QString( "%1" ).arg( principleErrors[ pindex ] ));
03284 }
03285 item -> setText( 5, QString( "%1" ).arg( pindex ) );
03286
03287 m_FunctionParamsListView -> insertItem( item );
03288 }
03289
03290 m_FunctionParamsListView -> setAllColumnsShowFocus ( true );
03291 #if QT_VERSION < 0x040000
03292 QListViewItem * firstItem = m_FunctionParamsListView -> firstChild ();
03293 #else
03294 Q3ListViewItem * firstItem = m_FunctionParamsListView -> firstChild ();
03295 #endif
03296 if ( firstItem != 0 ) {
03297 m_FunctionParamsListView -> setSelected ( firstItem, true );
03298 m_FunctionParamsListView -> setCurrentItem ( firstItem );
03299
03300 QString fixedFlag = firstItem -> text( 2 );
03301 m_FunctionParamsCheckBox->setChecked( ( fixedFlag == qyes ) ?
03302 true : false );
03303 m_FunctionParamsLineEdit -> setText ( firstItem -> text( 3 ) );
03304 }
03305 }
03306
03307 void
03308 Inspector::
03309 functionAdd ()
03310 {
03311 PlotterBase * plotter = getPlotter ();
03312 if ( !plotter ) return ;
03313
03314 bool yes = plotter -> isTargetable ();
03315 if ( yes == false ) {
03316 multipleDataRepError ( "function" );
03317 return;
03318 }
03319
03320 DisplayController * dc = DisplayController::instance();
03321
03322 DataRep * datarep = dc -> activeDataRep ( plotter );
03323 assert ( datarep != 0 );
03324
03325 if ( !datarep->acceptFunction(1) ){
03326 functionAddError ();
03327 return;
03328 }
03329
03330
03331
03332 QString qstr = newFunctionsComboBox->currentText();
03333 std::string fun_name = qstr.latin1();
03334
03335
03336
03337 QString s = m_fitter_names -> currentText ( );
03338 const string fit_name = s.latin1();
03339
03340 FunctionController * fc = FunctionController::instance();
03341 yes = fc -> isCompatible ( fun_name, fit_name );
03342
03343 if ( yes == false ) {
03344 incompatibleFunctionError ( fun_name );
03345 return;
03346 }
03347
03348 int index = fc->addFunction ( plotter, fun_name, datarep );
03349 if ( index < 0 ) return;
03350
03351 index = m_fitter_names -> currentItem ();
03352 fitterNamesActivated ( index );
03353
03354 functionsRemoveButton -> setEnabled ( true );
03355 functionsFitToDataButton -> setEnabled ( true );
03356 functionsResetButton -> setEnabled ( true );
03357 functionsAppliedComboBox -> setEnabled ( true );
03358 fc->saveParameters ( plotter );
03359
03360 fc -> tryFitFunction ( plotter, datarep );
03361
03362
03363
03364 updateFunctionsTab();
03365 updateErrorEllipseTab();
03366 updateSummaryTab ();
03367
03368
03369
03370 int curitem = 0;
03371 for ( int i = 0; i < functionsAppliedComboBox -> count(); i++ )
03372 if ( newFunctionsComboBox -> currentText() ==
03373 functionsAppliedComboBox -> text (i) )
03374 {
03375 curitem = i;
03376 break;
03377 }
03378
03379 functionsAppliedComboBox->setCurrentItem ( curitem );
03380 }
03381
03382 void
03383 Inspector::
03384 fitterNamesActivated ( int index )
03385 {
03386 PlotterBase * plotter = getPlotter ();
03387 if ( plotter != 0 ) {
03388 FunctionController * controller = FunctionController::instance ();
03389 const DataRep * datarep = plotter -> getTarget ();
03390 bool yes = controller -> hasFunction ( plotter, datarep );
03391 if ( yes ) {
03392 const vector < string > & fitters = controller -> getFitterNames ();
03393 bool ok = controller -> setFitter ( plotter, fitters[index] );
03394 if ( ok == false ) {
03395 incompatibleFitterError ( fitters[index] );
03396 functionsFitToDataButton -> setEnabled ( false );
03397 }
03398 else functionsFitToDataButton -> setEnabled ( true );
03399 }
03400 }
03401 }
03402
03403 void
03404 Inspector::
03405 functionsFitToDataButton_clicked()
03406 {
03407
03408 PlotterBase * plotter = getPlotter ();
03409 if ( !plotter ) return ;
03410
03411 FunctionController * fcnt = FunctionController::instance();
03412 if ( ! ( fcnt -> hasFunction ( plotter, 0 ) ) ) {
03413 return;
03414 }
03415
03416 fcnt -> saveParameters ( plotter );
03417
03418
03419
03420 int count = functionsAppliedComboBox -> count ();
03421 if ( count <= 0 ) return;
03422 QString qstr = functionsAppliedComboBox->currentText();
03423
03424
03425 FunctionRep * fun_rep = fcnt ->getFunctionRep ( plotter );
03426 bool ok = fcnt -> fitFunction ( plotter, fun_rep );
03427 if ( ! ok ) {
03428 const string message ( "The Fit failed to converge" );
03429 QMessageBox::critical ( this,
03430 "Fit failed",
03431 message.c_str (),
03432 QMessageBox::Ok,
03433 Qt::NoButton,
03434 Qt::NoButton );
03435 }
03436
03437
03438 DisplayController * dcontroller = DisplayController::instance ();
03439 int index = dcontroller -> activeDataRepIndex ( plotter );
03440
03441 setParameters ( index, plotter );
03442 }
03443
03444 void
03445 Inspector::
03446 statsStripValue ( QRadioButton * box )
03447 {
03448 QString text_str = box -> text ();
03449 int i = text_str.find ( "=" );
03450 text_str.remove ( i + 1, 1024 );
03451 box -> setText ( text_str );
03452 }
03453
03454
03455 void Inspector::updateSummaryTab()
03456 {
03457 if ( m_new_plot_box->isEnabled() == false ) return;
03458
03459 PlotterBase * plotter = getPlotter();
03460 bool yes = plotter == 0;
03461 if ( yes == false ) {
03462 TextPlotter * text = dynamic_cast < TextPlotter * > ( plotter );
03463 yes |= text != 0;
03464 }
03465 bool enable = ! yes;
03466 m_summary->setEnabled ( enable );
03467
03468 if ( enable == false ) return;
03469
03470 DisplayController * dcontroller = DisplayController::instance ();
03471 const DataSource * nt = dcontroller -> getNTuple ( plotter );
03472
03473 if ( nt && nt -> empty () ) {
03474 m_summary->setEnabled ( false );
03475 return;
03476 }
03477
03478 enable = false;
03479 int index = dcontroller -> activeDataRepIndex ( plotter );
03480 if ( index >= 0 ) {
03481 DataRep * datarep = plotter -> getDataRep ( index );
03482 FunctionController * controller = FunctionController::instance();
03483
03484 enable = controller->hasFunction ( plotter, datarep );
03485 }
03486 if ( enable == false ) {
03487 if ( m_stats_fparms->isChecked () ||
03488 m_stats_chi->isChecked () ) {
03489 m_stats_number->setChecked ( true );
03490 }
03491 }
03492
03493 m_stats_fparms->setEnabled ( enable );
03494 m_stats_chi->setEnabled ( enable );
03495
03496 yes = index < 0;
03497
03498 m_stats_number->setDisabled ( yes );
03499 m_stats_avg_x->setDisabled ( yes );
03500 m_stats_avg_y->setDisabled ( yes );
03501 m_stats_text->setDisabled ( yes );
03502 yes = m_stats_text -> isChecked ();
03503 m_statsTextField ->setEnabled ( yes );
03504
03505 statsStripValue ( m_stats_number );
03506 statsStripValue ( m_stats_avg_x );
03507 statsStripValue ( m_stats_avg_y );
03508
03509 if ( index >= 0 ) {
03510 int number = dcontroller -> getNumberOfEntries ( plotter, index );
03511 QString text = m_stats_number -> text ();
03512 QString str;
03513 str.setNum ( number );
03514 text += " ";
03515 text += str;
03516 m_stats_number -> setText ( text );
03517
03518 double average = dcontroller -> getAverage ( plotter, Axes::X, index );
03519 text = m_stats_avg_x -> text ();
03520 str.setNum ( average );
03521 text += " ";
03522 text += str;
03523 m_stats_avg_x -> setText ( text );
03524
03525 average = dcontroller -> getAverage ( plotter, Axes::Y, index );
03526 text = m_stats_avg_y -> text ();
03527 str.setNum ( average );
03528 text += " ";
03529 text += str;
03530 m_stats_avg_y -> setText ( text );
03531 }
03532
03533 updateErrorEllipseTab ();
03534 }
03535
03536 void
03537 Inspector::
03538 statsButtonGroupClicked ( int )
03539 {
03540 bool yes = m_stats_text -> isChecked ();
03541 m_statsTextField -> setEnabled ( yes );
03542 }
03543
03545 void Inspector::
03546 summaryNew ()
03547 {
03548 PlotterBase * plotter = getPlotter ();
03549 if ( !plotter ) return;
03550
03551 DisplayController * d_controller = DisplayController::instance ();
03552 int index = d_controller->activeDataRepIndex ( plotter );
03553 if ( index < 0 ) {
03554 multipleDataRepError ( "summary" );
03555 return;
03556 }
03557
03558 CanvasWindow * canvas = WindowController::instance () ->currentCanvas();
03559
03560 string nullstring ("");
03561
03562 if ( m_stats_number->isChecked() )
03563 {
03564 const string s ("Total Entries");
03565 canvas->addTextDisplay ( plotter, s, nullstring );
03566 }
03567
03568 else if ( m_stats_avg_x->isChecked() )
03569 {
03570 const string s ("averagex");
03571 canvas->addTextDisplay ( plotter, s, nullstring );
03572 }
03573
03574 else if ( m_stats_avg_y->isChecked() )
03575 {
03576 const string s ("averagey");
03577 canvas->addTextDisplay ( plotter, s, nullstring );
03578 }
03579
03580 else if ( m_stats_fparms->isChecked() )
03581 {
03582 const string s ("Function Parameters");
03583 FunctionController * controller = FunctionController::instance ();
03584 assert ( controller -> hasFunction ( plotter, 0 ) );
03585 canvas->addFuncDisplay ( plotter, s );
03586
03587 }
03588
03589 else if ( m_stats_chi->isChecked() )
03590 {
03591 const string s ("Chi-squared");
03592 FunctionController * controller = FunctionController::instance ();
03593 assert ( controller -> hasFunction ( plotter, 0 ) );
03594 canvas->addFuncDisplay ( plotter, s );
03595
03596 }
03597
03598 else if ( m_stats_text->isChecked() )
03599 {
03600
03601 QString qtext = m_statsTextField->text();
03602 string text (qtext.latin1());
03603
03604 const string s ("Text From Box");
03605 canvas->addTextDisplay ( plotter, s, text );
03606
03607 }
03608 }
03609
03611 void Inspector::createResiduals()
03612 {
03613 PlotterBase * plotter = getPlotter ();
03614 if ( plotter == 0 ) return;
03615
03616 FunctionController * controller = FunctionController::instance ();
03617 PlotterBase * res_plotter = controller -> createResidualsDisplay ( plotter );
03618 const Range & range = plotter -> getRange ( Axes::X, false );
03619 res_plotter -> setRange ( Axes::X, range, false );
03620
03621 CanvasWindow * canvas = WindowController::instance () -> currentCanvas ();
03622
03623 canvas -> addPlotDisplay ( res_plotter, true );
03624 }
03625
03630 void Inspector::comboBoxEllipsoidParamXHighlighted( int index )
03631 {
03632 FunctionController * fcontroller = FunctionController::instance ();
03633 fcontroller -> setEllpsoidParamIndex( Axes::X, index );
03634 }
03635
03640 void Inspector::comboBoxEllipsoidParamYHighlighted( int index )
03641 {
03642 FunctionController * fcontroller = FunctionController::instance ();
03643 fcontroller -> setEllpsoidParamIndex( Axes::Y, index );
03644 }
03645
03650 void
03651 Inspector::
03652 pushButtonNewErrorPlotClicked()
03653 {
03654 PlotterBase * plotter = getPlotter ();
03655 if ( plotter == 0 ) return;
03656
03657 FunctionController * fcontroller = FunctionController::instance ();
03658
03659
03660
03661 m_functionRep = fcontroller -> getFunctionRep ( plotter );
03662
03663 FunctionRep * rep = m_functionRep;
03664 PlotterBase* parentPlotter = plotter -> getParentPlotter();
03665 if( rep == 0 && parentPlotter == 0) return;
03666
03667
03668
03669 QString xlabel = m_ComboBoxEllipsoidParamX -> currentText();
03670 QString ylabel = m_ComboBoxEllipsoidParamY -> currentText();
03671
03672
03673
03674
03675 if( xlabel == ylabel )
03676 {
03677 const QString message =
03678 "Both enteries of the parameter pair, selected for drawing error\n"
03679 "ellipsoids are same. Please select x and y parameters which are\n"
03680 "different.";
03681
03682 QMessageBox::critical( this,
03683 "Invalid Parameter pair Selection",
03684 message,
03685 QMessageBox::Ok,
03686 Qt::NoButton,
03687 Qt::NoButton );
03688 return;
03689 }
03690
03691
03692 QString stat = m_PushButtonNewErrorPlot -> text();
03693 if( stat == QString( "Change Error Plot" ) )
03694 {
03695 fcontroller -> refreshEllipsoidDisplay ( plotter );
03696
03697 plotter -> setLabel( Axes::X, xlabel.latin1() );
03698 plotter -> setLabel( Axes::Y, ylabel.latin1() );
03699
03700 updateErrorEllipseTab();
03701
03702 }
03703 else
03704 {
03705 PlotterBase * err_plotter =
03706 fcontroller -> createNewEllipsoidDisplay ( plotter );
03707 assert( err_plotter != 0);
03708
03709 err_plotter -> setLabel( Axes::X, xlabel.latin1() );
03710 err_plotter -> setLabel( Axes::Y, ylabel.latin1() );
03711
03712 CanvasWindow * canvas
03713 = WindowController::instance () -> currentCanvas ();
03714 assert( canvas != 0 );
03715
03716
03717
03718 canvas -> addPlotDisplay ( err_plotter, false );
03719 }
03720 }
03721
03722 const std::string
03723 Inspector::
03724 convertToString ( hippodraw::Axes::Type axis )
03725 {
03726 if ( m_axis == Axes::X ) return "X";
03727 else if ( m_axis == Axes::Y ) return "Y";
03728 else if ( m_axis == Axes::Z ) return "Z";
03729
03730 return "nil";
03731 }
03732
03733 void
03734 Inspector::
03735 updateLogBox ()
03736 {
03737 bool yes = m_plotter_list.empty () == false;
03738
03739 logScale -> setEnabled ( yes );
03740 if ( yes ) {
03741 PlotterBase * plotter = m_plotter_list.front ();
03742 bool log = DisplayController::instance () -> getLog ( plotter, m_axis );
03743 logScale -> setChecked ( log );
03744 }
03745 }
03746
03747 void
03748 Inspector::
03749 updateAutoScaleBox ()
03750 {
03751 bool yes = m_plotter_list.empty () == false;
03752 m_autoScale -> setEnabled ( yes );
03753 if ( yes ) {
03754 PlotterBase * plotter = m_plotter_list.front ();
03755 bool scaled = plotter -> isAutoRanging ( m_axis );
03756 m_autoScale -> setChecked ( scaled );
03757 }
03758 }
03759
03766 void
03767 Inspector::
03768 updateAxisTab ()
03769 {
03770 updateLogBox ();
03771 updateAutoScaleBox ();
03772
03773 PlotterBase * plotter = getPlotter ();
03774 bool yes = plotter == 0;
03775 if ( yes == false ) {
03776 TextPlotter * text = dynamic_cast < TextPlotter * > ( plotter );
03777 yes |= text != 0;
03778 }
03779 m_axis_frame->setEnabled ( ! yes );
03780
03781 if ( yes ) return;
03782
03783 DisplayController * controller = DisplayController::instance ();
03784 int index = -1;
03785 if ( plotter -> isTargetable () ) {
03786 index = controller->activeDataRepIndex ( plotter );
03787 }
03788
03789 bool has_ntuple = controller->hasNTupleBindings ( plotter, 0 );
03790 if ( has_ntuple )
03791 {
03792 const DataSource * nt
03793 = DisplayController::instance()->getNTuple ( plotter );
03794 if ( nt && nt -> empty () ) return;
03795 }
03796
03797 if ( plotter -> hasAxis ( m_axis ) == false ) setZRadioButton ( false );
03798
03799 const string & label = plotter -> getLabel ( m_axis );
03800 const QString ltext = label.c_str();
03801 m_axis_label -> setText ( ltext );
03802
03803 const string s_axis = convertToString ( m_axis );
03804 bool axis_bined = controller -> isAxisBinned ( plotter, s_axis );
03805 const Range & r = plotter->getRange(m_axis, true);
03806 double low = r.low();
03807 double high = r.high();
03808
03809 axisWidget1 -> setLowText ( QString("%1").arg(low),
03810 axis_bined == true &&
03811 has_ntuple == false );
03812 axisWidget1 -> setHighText ( QString("%1").arg(high),
03813 axis_bined == true &&
03814 has_ntuple == false );
03815
03816 axisWidget1 -> setLowSliderValue( 50 );
03817 m_lowslider1_last_val = 50;
03818 axisWidget1 -> setHighSliderValue( 50 );
03819 m_highslider1_last_val = 50;
03820
03821 if ( axis_bined == false )
03822 {
03823 m_width_text->setEnabled ( false );
03824 m_width_range->setEnabled ( false );
03825 m_width_text -> setText ( QString ("%1").arg (0) );
03826
03827 m_offset_text->setEnabled ( false );
03828 m_offset_range->setEnabled ( false );
03829 m_offset_text -> setText ( QString ("%1").arg (0) );
03830 }
03831 else
03832 {
03833 m_width_text->setEnabled ( true );
03834 m_width_range->setEnabled ( true );
03835 double width = plotter->getBinWidth ( m_axis );
03836 m_width_text -> setText ( QString ("%1").arg (width) );
03837
03838 m_offset_text->setEnabled ( true );
03839 m_offset_range->setEnabled ( true );
03840 double offset = plotter->getOffset ( m_axis );
03841 m_offset_text -> setText ( QString ("%1").arg (offset) );
03842
03843
03844 m_width_text->setReadOnly ( ! has_ntuple );
03845 m_width_range->setEnabled ( has_ntuple );
03846 m_offset_text->setReadOnly ( ! has_ntuple );
03847 m_offset_range->setEnabled ( has_ntuple );
03848 }
03849
03850
03851
03852
03853 bool disable_log = has_ntuple == false && axis_bined == true;
03854 logScale -> setDisabled ( disable_log );
03855 m_autoScale -> setDisabled ( disable_log );
03856
03857 const PeriodicBinaryTransform *pbtf =
03858 dynamic_cast < const PeriodicBinaryTransform * >
03859 ( plotter->getTransform() );
03860
03861 if( pbtf == 0 ) {
03862 bool log = DisplayController::instance() -> getLog ( plotter, m_axis );
03863
03864 if( log )
03865 {
03866 m_offset_text -> setEnabled( false );
03867 m_offset_range -> setEnabled( false );
03868 }
03869 }
03870
03871
03872 axisWidget1->setAllDisabled ( false );
03873
03874
03875
03876
03877 bool isZoomPan = false;
03878
03879 std::map < const PlotterBase *, bool >::const_iterator it
03880 = m_zoompan.find ( plotter );
03881 if ( it != m_zoompan.end () )
03882 isZoomPan = it->second;
03883
03884
03885
03886
03887 if( pbtf != 0 && m_axis != Axes::Z)
03888 axisWidget1->setZoomPan ( true, true );
03889 else
03890 axisWidget1->setZoomPan ( isZoomPan );
03891
03892 axisWidget1->processZoomPanCheckBoxClicked ( r, r );
03893
03894 yes = false;
03895 if ( index >= 0 ) {
03896 const DataRep * datarep = plotter -> getDataRep ( index );
03897 RepBase * rep = datarep -> getRepresentation ();
03898 ContourPointRep * contourRep = dynamic_cast < ContourPointRep * > ( rep );
03899 yes = contourRep != 0;
03900 if ( yes ) {
03901 bool user = contourRep->getUsingUserValues();
03902 contourRadioButton1->setChecked ( !user );
03903 contourRadioButton2->setChecked ( user );
03904 contourRadioButton1_toggled ( true );
03905 }
03906 }
03907
03908 m_contourBox->setEnabled ( yes );
03909 }
03910
03911
03914 #if QT_VERSION < 0x040000
03915 void Inspector::functionParamsListViewCurrentChanged( QListViewItem * item )
03916 #else
03917 void Inspector::functionParamsListViewCurrentChanged( Q3ListViewItem * item )
03918 #endif
03919 {
03920 #if defined(QT_NO_STL) || QT_VERSION < 0x030100
03921 QString qyes( string("Yes").c_str() );
03922 QString qno( string("No").c_str() );
03923 #else
03924 QString qyes( string("Yes") );
03925 QString qno( string("No") );
03926 #endif
03927
03928 QString fixedFlag = item -> text( 2 );
03929 m_FunctionParamsCheckBox->setChecked(( fixedFlag == qyes ) ? true : false );
03930 m_FunctionParamsLineEdit -> setText ( item -> text( 3 ) );
03931 }
03932
03935 void Inspector::functionParamsCheckBoxToggled( bool )
03936 {
03937
03938 PlotterBase * plotter = getPlotter();
03939 if ( !plotter ) return;
03940
03941
03942 FunctionController * fcontroller = FunctionController::instance();
03943 if ( ! ( fcontroller -> hasFunction ( plotter, 0 ) ) ) {
03944 return;
03945 }
03946 m_functionRep = fcontroller -> getFunctionRep ( plotter );
03947
03948
03949 fcontroller -> saveParameters ( plotter );
03950
03951
03952 FunctionRep * frep = m_functionRep;
03953 vector < int > fixed;
03954 Fitter * fitter = frep -> getFitter ();
03955 if ( fitter != 0 ) {
03956 fixed = frep -> getFixedFlags();
03957 }
03958
03959
03960 #if QT_VERSION < 0x040000
03961 QListViewItem * item = m_FunctionParamsListView -> currentItem();
03962 #else
03963 Q3ListViewItem * item = m_FunctionParamsListView -> currentItem();
03964 #endif
03965 if( !item ) return;
03966
03967 QString pidx = item -> text( 5 );
03968 int paramindex = pidx.toUInt();
03969
03970
03971 bool flag = m_FunctionParamsCheckBox -> isChecked();
03972 if ( fitter != 0 ) {
03973 fixed[ paramindex ] = flag == true ? 1 : 0;
03974 frep -> setFixedFlags( fixed );
03975 }
03976
03977
03978 #if defined(QT_NO_STL) || QT_VERSION < 0x030100
03979 QString qyes( string("Yes").c_str() );
03980 QString qno( string("No").c_str() );
03981 #else
03982 QString qyes( string("Yes") );
03983 QString qno( string("No") );
03984 #endif
03985
03986 QString fixedFlag = ( flag == true ) ? qyes : qno;
03987 item -> setText ( 2, fixedFlag );
03988
03989
03990
03991
03992 updateErrorEllipseTab();
03993 }
03994
03995
03998 void Inspector::functionParamsLineEditReturnPressed()
03999 {
04000
04001 PlotterBase * plotter = getPlotter();
04002 if ( !plotter ) return;
04003
04004
04005 FunctionController * fcontroller = FunctionController::instance();
04006 if ( ! ( fcontroller -> hasFunction ( plotter, 0 ) ) )
04007 return;
04008
04009
04010 fcontroller -> saveParameters ( plotter );
04011
04012
04013 FunctionRep * frep = m_functionRep;
04014 vector < double > parameters = frep-> parameters();
04015
04016
04017 #if QT_VERSION < 0x040000
04018 QListViewItem * item = m_FunctionParamsListView -> currentItem();
04019 #else
04020 Q3ListViewItem * item = m_FunctionParamsListView -> currentItem();
04021 #endif
04022 if( !item ) return;
04023
04024 QString pidx = item -> text( 5 );
04025 int paramindex = pidx.toUInt();
04026
04027
04028 QString text = m_FunctionParamsLineEdit -> text();
04029 parameters[ paramindex ] = text.toDouble();
04030 frep -> setParameters( parameters );
04031 frep -> setDirty();
04032
04033
04034 item -> setText ( 3, QString ( "%1" ).arg ( parameters[ paramindex ] ) );
04035 }
04036
04037
04038
04039
04040 void Inspector::functionParamsSliderSliderPressed()
04041 {
04042
04043 PlotterBase * plotter = getPlotter();
04044 if ( !plotter ) return;
04045
04046
04047 FunctionController * fcontroller = FunctionController::instance();
04048 if ( ! ( fcontroller -> hasFunction ( plotter, 0 ) ) )
04049 return;
04050
04051
04052 fcontroller -> saveParameters ( plotter );
04053
04054
04055 FunctionRep * frep = m_functionRep;
04056 vector < double > parameters = frep -> parameters();
04057
04058
04059 #if QT_VERSION < 0x040000
04060 QListViewItem * item = m_FunctionParamsListView -> currentItem();
04061 #else
04062 Q3ListViewItem * item = m_FunctionParamsListView -> currentItem();
04063 #endif
04064 if( !item ) return;
04065
04066
04067 m_oldParameters = parameters;
04068 }
04069
04070
04073 void Inspector::functionParamsSliderSliderMoved( int )
04074 {
04075
04076 PlotterBase * plotter = getPlotter();
04077 if ( !plotter ) return;
04078
04079
04080 FunctionController * fcontroller = FunctionController::instance();
04081 if ( ! ( fcontroller -> hasFunction ( plotter, 0 ) ) )
04082 return;
04083
04084
04085 fcontroller -> saveParameters ( plotter );
04086
04087
04088 FunctionRep * frep = m_functionRep;
04089 vector < double > parameters = frep -> parameters();
04090
04091
04092 #if QT_VERSION < 0x040000
04093 QListViewItem * item = m_FunctionParamsListView -> currentItem();
04094 #else
04095 Q3ListViewItem * item = m_FunctionParamsListView -> currentItem();
04096 #endif
04097 if( !item ) return;
04098
04099 QString pidx = item -> text( 5 );
04100 int paramindex = pidx.toUInt();
04101
04102
04103 vector < double > newParameters = m_oldParameters;
04104
04105 int sliderValue = m_FunctionParamsSlider -> value();
04106 int sign = ( m_oldParameters[ paramindex ] < 0 )? -1:1;
04107
04108 newParameters[ paramindex ]
04109 = m_oldParameters[ paramindex ] *
04110 pow ( 2.0, static_cast<double>( (sliderValue - 50) * sign) / 50.0 );
04111
04112 frep -> setParameters( newParameters );
04113
04114
04115 item -> setText ( 3, QString ( "%1" ).arg ( newParameters[ paramindex ] ) );
04116 m_FunctionParamsLineEdit ->
04117 setText ( QString ( "%1" ).arg ( newParameters[ paramindex ] ) );
04118 }
04119
04121 void Inspector::functionParamsSliderSliderReleased()
04122 {
04123
04124 m_FunctionParamsSlider -> setValue(50);
04125 }
04126
04130 void Inspector::logScale_clicked()
04131 {
04132 bool log = logScale -> isChecked();
04133 bool auto_scale = m_autoScale -> isChecked ();
04134
04135 vector < PlotterBase * > ::iterator first = m_plotter_list.begin ();
04136
04137 while ( first != m_plotter_list.end () ) {
04138 PlotterBase * plotter = *first++;
04139 DisplayController::instance()-> setLog ( plotter, m_axis, log );
04140 plotter -> setAutoRanging ( m_axis, auto_scale );
04141 }
04142 }
04143
04144 void Inspector::autoScale_clicked()
04145 {
04146 bool scale = m_autoScale -> isChecked ();
04147 vector < PlotterBase * > ::iterator first = m_plotter_list.begin ();
04148
04149 while ( first != m_plotter_list.end () ) {
04150 PlotterBase * plotter = *first++;
04151 plotter -> setAutoRanging ( m_axis, scale );
04152
04153
04154 PeriodicBinaryTransform * tp =
04155 dynamic_cast< PeriodicBinaryTransform* > ( plotter->getTransform() );
04156 if ( tp != 0 )
04157 {
04158 tp->setXOffset( 0.0 );
04159 tp->setYOffset( 0.0 );
04160 }
04161 }
04162 updateAxisTab();
04163 }
04164
04165 void Inspector::cutHighSlider_sliderMoved ( int value )
04166 {
04167 if ( m_is_updating == false ) {
04168 int index = m_selCutComboBox -> currentItem ();
04169 PlotterBase * plotter = getSelectedCut();
04170 Range currentRange = m_tuple_cuts [ index] -> getRange ();
04171 bool fit_cut = cut_button_group -> selected () == m_cut_fit_radio;
04172
04173 if ( fit_cut == false ) {
04174 Axes::Type axis = getAxes ( index );
04175 const Range & fullRange = plotter -> getRange ( axis, false );
04176 axisWidget2 -> processHighSliderMoved ( value, currentRange, fullRange );
04177 plotter -> setCutRangeAt ( currentRange, axis );
04178 }
04179 else {
04180 const Range & fullRange = plotter -> getRange ( Axes::X, false );
04181 axisWidget2 -> processHighSliderMoved ( value, currentRange, fullRange );
04182 plotter -> setCutRangeAt ( currentRange, index );
04183 }
04184 }
04185 }
04186
04187 void Inspector::cutLowSlider_sliderMoved ( int value )
04188 {
04189 if ( m_is_updating == false ) {
04190 PlotterBase * plotter = getSelectedCut();
04191 int index = m_selCutComboBox -> currentItem ();
04192 Range currentRange = m_tuple_cuts [ index ] -> getRange ();
04193
04194 bool fit_cut = cut_button_group -> selected () == m_cut_fit_radio;
04195 if ( fit_cut == false ) {
04196 Axes::Type axis = getAxes ( index );
04197 const Range & fullRange = plotter -> getRange ( axis, false );
04198 axisWidget2 -> processLowSliderMoved ( value, currentRange, fullRange );
04199 plotter -> setCutRangeAt ( currentRange, axis );
04200 }
04201 else {
04202 const Range & fullRange = plotter -> getRange ( Axes::X, false );
04203 axisWidget2 -> processLowSliderMoved ( value, currentRange, fullRange );
04204 plotter -> setCutRangeAt ( currentRange, index );
04205 }
04206 }
04207 }
04208
04209 void Inspector::cutLowSlider_sliderReleased()
04210 {
04211 PlotterBase * cd = getSelectedCut();
04212 if ( cd == 0 ) return;
04213 int index = m_selCutComboBox -> currentItem ();
04214 Axes::Type axis = getAxes ( index );
04215 const Range & fullRange = cd->getRange ( axis, false );
04216 axisWidget2->processLowSliderReleased ( fullRange );
04217 }
04218
04219 void Inspector::cutHighSlider_sliderReleased()
04220 {
04221 PlotterBase * cd = getSelectedCut();
04222 if ( cd == 0 ) return;
04223 int index = m_selCutComboBox -> currentItem ();
04224 Axes::Type axis = getAxes ( index );
04225 const Range & fullRange = cd->getRange ( axis, false );
04226 axisWidget2->processHighSliderReleased ( fullRange );
04227 }
04228
04229 void Inspector::cutZoomPanCheckBox_clicked()
04230 {
04231 PlotterBase * plotter = getSelectedCut();
04232
04233 int index = m_selCutComboBox -> currentItem ();
04234 bool fit_cut = cut_button_group -> selected () == m_cut_fit_radio;
04235
04236 Axes::Type axis = Axes::X;
04237 if ( fit_cut == false ) {
04238 axis = getAxes ( index );
04239 }
04240 bool yes = axisWidget2 -> isZoomPanChecked ();
04241 CutController * controller = CutController::instance ();
04242 controller -> setZoomPan ( plotter, axis, yes );
04243
04244 Range currentRange = m_tuple_cuts [ index ] -> getRange ();
04245 const Range & fullRange = plotter -> getRange ( axis, false );
04246
04247 axisWidget2 -> processZoomPanCheckBoxClicked ( currentRange, fullRange ) ;
04248 }
04249
04250
04251 void Inspector::cutInvertPushButton_clicked()
04252 {
04253 PlotterBase * plotter = getSelectedCut ();
04254 bool fit_cut = cut_button_group -> selected () == m_cut_fit_radio;
04255
04256 if ( fit_cut == false ) {
04257 CutPlotter * cp = dynamic_cast < CutPlotter * > ( plotter );
04258 cp -> toggleInverted ();
04259 }
04260 else {
04261 int index = m_selCutComboBox -> currentItem ();
04262 bool state = ! m_tuple_cuts [ index ] -> getInversion ();
04263
04264 XyPlotter * xyplotter = dynamic_cast < XyPlotter * > ( plotter );
04265 xyplotter -> setCutInverted ( index, state );
04266 }
04267 }
04268
04269 void
04270 Inspector::
04271 cutEnablePushButton_toggled ( bool on)
04272 {
04273 if ( m_cut_enable_updating == true ) return;
04274
04275 PlotterBase * plotter = getSelectedCut ();
04276 bool fit_cut = cut_button_group -> selected () == m_cut_fit_radio;
04277
04278 if ( fit_cut == false ) {
04279 CutPlotter * cut_plotter = dynamic_cast < CutPlotter * > ( plotter );
04280 cut_plotter -> setEnabled ( ! on );
04281 }
04282 else {
04283 int index = m_selCutComboBox -> currentItem ();
04284 XyPlotter * xyplotter = dynamic_cast < XyPlotter * > ( plotter );
04285 xyplotter -> setCutEnabled ( index, ! on );
04286 }
04287 }
04288
04289 void
04290 Inspector::
04291 colorSelect_2_clicked()
04292 {
04293 PlotterBase * cplotter = getSelectedCut();
04294 CutPlotter * cp = dynamic_cast < CutPlotter * > ( cplotter );
04295
04296 const Color & rep_color = cp -> getCutColor ();
04297 QColor color ( rep_color.getRed(),
04298 rep_color.getGreen(),
04299 rep_color.getBlue () );
04300
04301 color = QColorDialog::getColor ( color );
04302
04303 if ( color.isValid() == true ) {
04304 Color c( color.red(), color.green(), color.blue() );
04305 cp -> setCutColor ( c );
04306 }
04307 }
04308
04309 void
04310 Inspector::
04311 contourSlider_valueChanged ( int val )
04312 {
04313
04314 PlotterBase * plotter = getPlotter ();
04315 if ( !plotter ) return;
04316 DisplayController * controller = DisplayController::instance ();
04317 int index = controller->activeDataRepIndex ( plotter );
04318 DataRep * datarep = plotter->getDataRep ( index );
04319
04320 RepBase * rep = datarep->getRepresentation();
04321 ContourPointRep * contourRep = dynamic_cast < ContourPointRep * > ( rep );
04322
04323 if ( !contourRep ) return;
04324
04325 contourRep->setUsingUserValues ( false );
04326 contourRep->setNumContours ( val );
04327 m_numContoursTextBox->setText ( QString("%1").arg ( val ) );
04328
04329 datarep->notifyObservers();
04330
04331 }
04332
04333 void
04334 Inspector::
04335 contourTextBox_returnPressed()
04336 {
04337
04338 PlotterBase * plotter = getPlotter ();
04339 if ( !plotter ) return;
04340 DisplayController * controller = DisplayController::instance ();
04341 int index = controller->activeDataRepIndex ( plotter );
04342 DataRep * datarep = plotter->getDataRep ( index );
04343
04344 RepBase * rep = datarep->getRepresentation();
04345 ContourPointRep * contourRep = dynamic_cast < ContourPointRep * > ( rep );
04346
04347 if ( !contourRep ) return;
04348
04349 QString text = m_numContoursTextBox->text();
04350 int val = text.toInt();
04351
04352 if ( val < 1 || val > 100 ) {
04353 int num = contourRep->getNumContours ();
04354 m_numContourSlider->setValue ( num );
04355 m_numContoursTextBox->setText ( QString ("%1").arg ( num ) );
04356 return;
04357 }
04358
04359 contourRep->setUsingUserValues ( false );
04360 contourRep->setNumContours ( val );
04361 m_numContourSlider->setValue ( val );
04362
04363 datarep->notifyObservers();
04364
04365 }
04366
04367 void
04368 Inspector::
04369 contourRadioButton1_toggled ( bool )
04370 {
04371 PlotterBase * plotter = getPlotter ();
04372 if ( !plotter ) return;
04373 if ( plotter -> isTargetable () == false ) return;
04374
04375 DataRep * datarep = plotter -> getTarget ( );
04376 RepBase * rep = datarep->getRepresentation();
04377
04378 ContourPointRep * contourRep = dynamic_cast < ContourPointRep * > ( rep );
04379
04380 if ( !contourRep ) return;
04381
04382 if ( contourRadioButton1->isChecked() ) {
04383
04384 m_numContourSlider->setEnabled ( true );
04385 m_numContoursTextBox->setEnabled ( true );
04386 m_numContoursLabel->setEnabled ( true );
04387 m_contourLevelsTextBox->setEnabled ( false );
04388
04389 int num = contourRep->getNumContours ();
04390 m_numContourSlider->setValue ( num );
04391 m_numContoursTextBox->setText ( QString ("%1").arg ( num ) );
04392
04393 contourSlider_valueChanged ( num );
04394
04395 }
04396
04397 else {
04398
04399 m_numContourSlider->setEnabled ( false );
04400 m_numContoursTextBox->setEnabled ( false );
04401 m_numContoursLabel->setEnabled ( false );
04402 m_contourLevelsTextBox->setEnabled ( true );
04403
04404 contourLevelsTextBox_returnPressed();
04405
04406 }
04407
04408 }
04409
04410 void
04411 Inspector::
04412 contourError ()
04413 {
04414 const QString message =
04415 "Invalid Input String. Please check that\n"
04416 "1. The string contains only numbers separated by white spaces, and,\n"
04417 "2. The numbers are in increasing order without any duplicates.\n";
04418 QMessageBox::critical ( this,
04419 "Invalid Input String",
04420 message,
04421 QMessageBox::Ok,
04422 Qt::NoButton,
04423 Qt::NoButton );
04424 }
04425
04426 void
04427 Inspector::
04428 contourLevelsTextBox_returnPressed ()
04429 {
04430 if ( contourRadioButton2->isChecked () == false ) return;
04431
04432 PlotterBase * plotter = getPlotter ();
04433 if ( !plotter ) return;
04434 DisplayController * controller = DisplayController::instance ();
04435 int index = controller->activeDataRepIndex ( plotter );
04436 DataRep * datarep = plotter->getDataRep ( index );
04437
04438 RepBase * rep = datarep->getRepresentation();
04439 ContourPointRep * contourRep = dynamic_cast < ContourPointRep * > ( rep );
04440
04441 if ( !contourRep ) return;
04442
04443 const QString qstr1 = m_contourLevelsTextBox->text();
04444 if ( qstr1.isEmpty () ) return;
04445 const QString qstr2 = qstr1.simplifyWhiteSpace();
04446
04447 QTextIStream * stream = new QTextIStream ( &qstr2 );
04448
04449 vector < double > values;
04450 double prev = 0, cur = 0;
04451 bool first = true;
04452
04453 while ( !stream->atEnd() ){
04454
04455 QString strval;
04456 (*stream) >> strval;
04457 bool ok = true;
04458 cur = strval.toDouble ( &ok );
04459
04460
04461
04462 if ( !ok ) {
04463 contourError();
04464 return;
04465 }
04466
04467
04468
04469 if ( first ) {
04470 first = false;
04471 }
04472 else {
04473 if ( cur <= prev ) {
04474 contourError();
04475 return;
04476 }
04477 }
04478
04479
04480 values.push_back ( cur );
04481 prev = cur;
04482
04483 }
04484
04485 contourRep->setContourValues ( values, datarep->getProjector() );
04486 datarep->notifyObservers();
04487
04488 }
04489
04490
04491 void Inspector::editLabelFontClicked()
04492 {
04493 PlotterBase * plotter = getPlotter ();
04494 if ( !plotter ) return ;
04495
04496 QFont labelFont;
04497 bool ok;
04498
04499 XyPlotter * xyplotter = dynamic_cast < XyPlotter * > ( plotter );
04500 assert ( xyplotter != 0 );
04501
04502 const FontBase * fb = xyplotter -> labelFont ( m_axis );
04503 if ( fb == 0 ) {
04504 labelFont = QFontDialog::getFont ( &ok, this);
04505 }
04506 else {
04507 const QtFont * qtfont = dynamic_cast < const QtFont * > ( fb );
04508 const QFont & qfont = qtfont -> font ();
04509 labelFont = QFontDialog::getFont ( &ok, qfont, this);
04510 }
04511
04512 if ( ok )
04513 {
04514 QtFont * font = new QtFont;
04515 font -> setFont( labelFont );
04516 xyplotter -> setLabelFont( font, m_axis );
04517 xyplotter -> notifyObservers ();
04518 }
04519 }
04520
04521 void Inspector::editTitleFontClicked()
04522 {
04523 PlotterBase * plotter = getPlotter ();
04524 if ( plotter == 0 ) return ;
04525
04526 XyPlotter * xyplotter = dynamic_cast< XyPlotter* > ( plotter );
04527 assert( xyplotter != 0 );
04528
04529 QFont titleFont;
04530 bool ok;
04531
04532 const FontBase * fb = xyplotter -> titleFont ();
04533 if ( fb == 0 ) {
04534
04535
04536 titleFont = QFontDialog::getFont ( &ok, this );
04537 }
04538 else {
04539 const QtFont * qtfont = dynamic_cast < const QtFont * > ( fb );
04540 const QFont & qfont = qtfont -> font ();
04541 titleFont = QFontDialog::getFont ( &ok, qfont, this );
04542 }
04543
04544 if ( ok )
04545 {
04546 QtFont * font = new QtFont;
04547 font -> setFont( titleFont );
04548 xyplotter -> setTitleFont( font );
04549 xyplotter -> notifyObservers ();
04550 }
04551 }