Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

QtDisplay.cxx

Go to the documentation of this file.
00001 
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h" // for have_root and have_numarray
00014 #endif
00015 
00016 // For truncation warning
00017 #ifdef _MSC_VER
00018 #include "msdevstudio/MSconfig.h"
00019 #endif
00020 
00021 #include "QtDisplay.h"
00022 
00023 #include "ListTuple.h"
00024 #include "PyFunctionRep.h"
00025 #include "PyDataRep.h"
00026 #include "PyDataSource.h"
00027 #include "FunctionWrap.h"
00028 
00029 #include "controllers/DisplayController.h"
00030 #include "controllers/FunctionController.h"
00031 #include "pattern/FactoryException.h"
00032 #include "pattern/Observer.h"
00033 #include "plotters/PlotterBase.h"
00034 #include "plotters/PlotterException.h"
00035 #include "projectors/ProjectorBase.h"
00036 #include "datareps/DataRepException.h"
00037 #include "datareps/DataRep.h"
00038 #include "datasrcs/DataSourceController.h"
00039 #include "datasrcs/DataSourceException.h"
00040 #include "datasrcs/NTuple.h"
00041 #include "reps/RepBase.h"
00042 #include "reps/ContourPointRep.h"
00043 #include "reps/BinToColorFactory.h"
00044 #include "reps/BinToColor.h"
00045 
00046 #ifdef HAVE_ROOT
00047 #include "root/QtRootNTuple.h"
00048 #include "root/RootNTuple.h"
00049 #endif
00050 
00051 #include "qapplication.h"
00052 
00053 #include <algorithm>
00054 #include <sstream>
00055 #include <stdexcept>
00056 #include <utility>
00057 
00058 using std::string;
00059 using std::vector;
00060 using namespace boost::python;
00061 
00062 namespace hippodraw {
00063 namespace Python {
00064 
00065 void
00066 export_QtDisplay()
00067 {
00068   class_< QtDisplay > 
00069     ( "Display",
00070       "A wrapper for the HippoDraw PlotterBase C++ class.\n "
00071       "  See HippoDraw's QtDisplay documentation for more details.",
00072       init < const std::string & >
00073       (
00074 #if __GNUC__ < 3
00075        "Display ( string, Datasource, tuple ) -> Display\n"
00076        "\n"
00077        "The main consturctor for a Display."
00078 #else // gcc 2.95.3 crashes on the following...
00079        "Display ( string ) -> Display\n"
00080        "Display ( string, DataSource, tuple ) -> Display\n"
00081        "Display ( string, DataArray, tuple ) - > Display\n"
00082        "Display ( string, tuple, tuple ) -> Display\n"
00083        "Display ( string, list, tuple ) -> Display\n"
00084        "Display ( string, RootNTuple, tuple ) -> Display\n"
00085        "Display ( string, RootNTuple, tuple, tuple ) -> Display\n"
00086        "\n"
00087         "This method is used to create a Display object.\n"
00088         "The first method is used for creating static version of\n "
00089         "Histograms, etc., where the string is the type of DataRep.\n"
00090         "The remaining methods are for dynamic versions.\n"
00091         "The string argument is the type.   The second argument\n"
00092         "is the DataSource and the third argument is tuple of\n"
00093         "string for the binding to the DataSource.\n"
00094         "For the last method, the fourth argument is a tuple\n"
00095         "of integers to access a ROOT array variable.\n"
00096 #endif
00097         ) )
00098           
00099     .def ( init < const std::string &,
00100            const DataSource &,
00101            const std::vector< std::string > & > () )
00102 
00103     .def ( init < const std::string &,
00104            const PyDataSource &,
00105            const std::vector< std::string > & > () )
00106 
00107     .def ( init < const std::string &,
00108            boost::python::tuple,
00109            const std::vector< std::string > & > () )
00110 
00111     .def ( init < const std::string &,
00112             boost::python::list,
00113            const std::vector< std::string > & > () )
00114 
00115 #ifdef HAVE_ROOT
00116     .def ( init < const std::string &,
00117             const QtRootNTuple &,
00118            const std::vector< std::string > & > () )
00119 
00120     .def ( init < const std::string &,
00121            const QtRootNTuple &,
00122            const std::vector< std::string > &,
00123            boost::python::list > () )
00124 #endif
00125 
00126     .def ( "createNTuple", &QtDisplay::createNTuple,
00127            return_value_policy < manage_new_object > (),
00128            "createNTuple ( ) -> NTuple\n"
00129            "\n"
00130            "Returns a NTuple representation of the Display's contents." )
00131 
00132 #ifdef HAVE_NUMARRAY
00133     .def ( "createDataArray", &QtDisplay::createDataArray,
00134            return_value_policy < manage_new_object > (),
00135            "createDataArray ( ) -> DataArray\n"
00136            "\n"
00137            "Returns a DataArray representation of the Display's contents\n"
00138            "(This method available if configured with numarray)" )
00139 #endif
00140 
00141     .def ( "setNumberOfBins", &QtDisplay::setNumberOfBins,
00142            "setNumberOfBins ( string, value ) -> None\n\n"
00143            "Sets the number of bins on named axis, e.g. 'x' to the given \n"
00144            "value." )
00145           
00146     .def ( "setBinWidth", 
00147            ( void (QtDisplay::*) ( const std::string &,
00148                                    double, 
00149                                    bool ) )
00150             &QtDisplay::setBinWidth,
00151             "Set the bin width, explicitly saving the value or not." )
00152 
00153     .def ( "getBinWidth", 
00154            ( double (QtDisplay::*) ( const std::string & ) )
00155             &QtDisplay::getBinWidth,
00156            "getBinWidth ( string ) -> value\n"
00157            "\n"
00158            "Returns the bin width on axis specified as a string,\n"
00159            "e.g., 'x'." )
00160 
00161     .def ( "setBinWidth", 
00162            ( void (QtDisplay::*) ( const std::string &,
00163                                    double ) )
00164             &QtDisplay::setBinWidth,
00165            "setBinWidth ( string, value ) -> None\n"
00166            "\n"
00167             "Set the bin width to value  on axis specified as a string,\n"
00168            "e.g., 'x'." )
00169 
00170     .def ( "reset", &QtDisplay::reset,
00171            "reset () -> None\n"
00172            "\n"
00173            "Resets the contents of all bins.   Only applicable to statis\n"
00174            "static histograms." )
00175 
00176     .def ( "setOffset", &QtDisplay::setOffset,
00177            "setOffset ( string, value ) -> None\n"
00178            "\n"
00179            "Sets the offset of the bins relative to their current width on\n"
00180            "specified axis." )
00181           
00182     .def ( "setRange", 
00183            ( void (QtDisplay::*) (const std::string &, 
00184                                   double, double) )
00185            &QtDisplay::setRange )
00186 
00187     .def ( "setRange", 
00188            ( void (QtDisplay::*) (const std::string &, 
00189                                   double, double, bool) )
00190            &QtDisplay::setRange,
00191            "setRange ( string, value, value ) -> None\n"
00192            "setRange ( string, value, value, boolean ) -> None\n"
00193            "\n"
00194            "Set the upper and lower bounds for the specified axis.  For the\n"
00195            "second form, also save them if the boolean argument is true." )
00196 
00197 
00198     .def ( "getRange", &QtDisplay::getRange,
00199            "getRange ( string ) -> tuple\n"
00200            "\n"
00201            "Returns the tuple representing the range for the axis specified\n"
00202            "as a string, e.g., 'x'." )
00203 
00204      .def ( "saveView", &QtDisplay::saveView,
00205             "saveView ( ) -> int\n"
00206             "\n"
00207             "Saves the current set of x and y ranges and "
00208             "returns the index of the saved view." )
00209 
00210      .def ( "setView", &QtDisplay::setView,
00211             "setView ( int ) -> None\n"
00212             "\n"
00213             "Set the view by its index." )
00214 
00215      .def ( "nextView", &QtDisplay::nextView,
00216             "nextView ( bool ) -> int\n"
00217             "\n"
00218             "Cycle to the next view in the view buffer. "
00219             "Set the argument to True to cycle forwards, "
00220             "False to cycle backwards.\n"
00221             "Returns the index of the new view." )
00222 
00223      .def ( "numViews", &QtDisplay::numViews,
00224             "numViews ( ) -> int\n"
00225             "\n"
00226             "Return the number of stored views." )
00227 
00228      .def ( "deleteView", &QtDisplay::deleteView,
00229             "deleteView ( int ) -> None\n"
00230             "\n"
00231             "Delete a view by index." )
00232 
00233      .def ( "currentView", &QtDisplay::currentView,
00234             "currentView ( ) -> int\n"
00235             "\n"
00236             "Index of the current view." )
00237 
00238     .def ( "setTitle", &QtDisplay::setTitle,
00239            "setTitle ( string ) -> None\n"
00240            "\n"
00241            "Sets the title of the display." )
00242 
00243     .def ( "getTitle", &QtDisplay::getTitle,
00244             return_value_policy < copy_const_reference > (),
00245            "getTitle () -> string\n"
00246            "\n"
00247            "Returns the current title.   The title will be the title of\n"
00248            "the DataSource unless it has been explicitly changed." )
00249 
00250     .def ( "setLabel", &QtDisplay::setLabel,
00251            "setLabel ( string, string ) -> None\n"
00252            "\n"
00253            "Sets the label for the axis specified by first argument to value\n"
00254            "of the second argument." )
00255 
00256     .def ( "getLabel", &QtDisplay::getLabel,
00257             return_value_policy< copy_const_reference > (),
00258            "getLabel ( string ) -> string\n"
00259            "\n"
00260             "Returns the label of the axis specified as a string,\n"
00261            "e.g., 'x'." )
00262 
00263     .def ( "getDataRep", &QtDisplay::getDataRep,
00264            return_value_policy < reference_existing_object > (),
00265            "getDataRep ( ) -> DataRep\n"
00266            "\n"
00267            "Returns a reference to the active DataRep." )
00268 
00269     .def ( "getDataReps", &QtDisplay::getDataReps,
00270             return_value_policy < copy_const_reference > (),
00271            "getDataReps ( ) -> list\n"
00272            "\n"
00273            "Returns a list of DataRep objects contained by the Display.." )
00274     
00275     .def ( "addDataRep", 
00276            ( void (QtDisplay::*) (PyDataRep *) )
00277            &QtDisplay::addDataRep,
00278            "addDataRep ( DataRep ) -> Display\n"
00279            "addDataREp ( Function ) -> Display\n"
00280            "addDataRep ( string, DataSource, tuple ) -> Display\n"
00281            "\n"
00282            "Adds a DataRep to the display sharing the same Y axis range\n"
00283            "The first two methods adds existing DataRep or Function to the\n"
00284            "Display.  The third method creates and adds DataRep to the\n"
00285            "Display.  Arguments are same as Display consturctor." )
00286 
00287     .def ( "addDataRep", 
00288            ( void (QtDisplay::*) (const std::string &, 
00289                                   const DataSource *,
00290                                   const std::vector <std::string > &) )
00291            &QtDisplay::addDataRep )
00292 
00293     .def ( "addDataRep", 
00294            ( void (QtDisplay::*) (PyFunctionRep *) )
00295            &QtDisplay::addDataRep )
00296 
00297     .def ( "addDataRepStacked", 
00298            ( void (QtDisplay::*) (const std::string &, 
00299                                   const DataSource *,
00300                                   const std::vector <std::string > &) )
00301            &QtDisplay::addDataRepStacked,
00302            "addDataRepStacked ( string, DataSource, tuple ) -> Display\n"
00303            "\n"
00304            "Creates and adds a DataRep with independant Y axis ranges.\n"
00305            "The arguments are the same as Display constructor." ) 
00306 
00307 #ifndef BOOST_DEFECT
00308     .def ( "addFunction", 
00309            ( void (QtDisplay::*) (FunctionBase *) )
00310            &QtDisplay::addFunction,
00311            "addFunction ( FunctionBase ) -> None\n"
00312            "\n"
00313            "Adds a FunctionBase object to the display by appropriatelly\n"
00314            "wrapping it with a Function." )
00315 #endif // BOOST_DEFECT
00316 
00317     .def ( "setAutoRanging",
00318             ( void (QtDisplay::*) (const std::string &,
00319                                    bool flag ) )
00320             &QtDisplay::setAutoRanging,
00321            "setAutoRanging ( string, boolean ) -> None\n"
00322            "\n"
00323            "Sets auto-ranging on axis specified as a string, e.g. 'x',n"
00324            "on or off." )
00325 
00326     .def ( "setLog", &QtDisplay::setLog,
00327            "setLog ( string, boolean ) -> None\n"
00328            "\n"
00329            "Sets the axis specified by the first argument on log scale." )
00330 
00331     .def ( "getLog", &QtDisplay::getLog,
00332            "getLog ( string ) -> value\n"
00333            "\n"
00334            "Returns True if axis specified as a string, e.g. 'x', is being\n"
00335            "displayed on a logrithmic scale." )
00336 
00337     .def ( "setTransform", &QtDisplay::setTransform,
00338            "setTransform ( string ) -> None\n"
00339            "\n"
00340            "Sets the transform object." )
00341 
00342     .def ( "addValues", &QtDisplay::addValues,
00343            "addValue ( tuple ) -> None\n"
00344            "\n"
00345            "For static histograms, adds a value to the accumulaton.\n"
00346            "For 1D histogram, the tuple should contain one or two values,\n"
00347            "the second used as a weight.  For 2D histogram, the tuple should\n"
00348            "contain two or three elements, the third being the weight.\n"
00349            "non static Displays do nothing." )
00350 
00351     .def ( "setPointRep", &QtDisplay::setPointRep,
00352            "setPointRep ( RepBase ) -> None\n"
00353            "\n"
00354            "Sets the point representation to be used." )
00355 
00356     .def ( "setContourLevels", &QtDisplay::setContourLevels,
00357            "setContourLevels ( sequence ) -> None\n"
00358            "\n"
00359            "Sets the contour levels if the Display is using contour point\n"
00360            "representation from the values in the sequence." )
00361 
00362     .def ( "setAspectRatio", &QtDisplay::setAspectRatio,
00363            "setAspectRatio ( value ) -> None\n"
00364            "\n"
00365            "Sets the required aspect ratio of the Display to value, the\n"
00366            "ratio of the width to the height." )
00367 
00368      .def ( "numberOfEntries", &QtDisplay::numberOfEntries,
00369             "numberOfEntries ( ) -> value\n"
00370             "\n"
00371             "Returns the number of Entris in the Display." )
00372 
00373      .def ( "resize", &QtDisplay::resize,
00374             "resize () -> None\n"
00375             "\n"
00376             "Resizes the Display to its saved values." )
00377 
00378      .def ( "plotterId", &QtDisplay::plotterId,
00379             "plotterId () -> value\n"
00380             "\n"
00381             "Returns a unique identifier for the Display." )
00382 
00383      .def ( "setColorMap", &QtDisplay::setColorMap,
00384             "setColorMap ( string ) -> None\n"
00385             "\n"
00386             "Set the value-to-color map to one named by the argument.")
00387 
00388     .def ( "update", &QtDisplay::update,
00389            "update () -> None\n"
00390            "\n"
00391            "Updates the display." )
00392 
00393     .def ( "addObserver", &QtDisplay::addObserver,
00394            "addObserver ( Observer ) -> None\n"
00395            "\n"
00396            "Adds an Observer to the Display object." )
00397 
00398     .def ( "setAutoTicks", &QtDisplay::setAutoTicks,
00399            "setAutoTicks ( boolean ) -> None\n"
00400            "\n"
00401            "Set the ticks generation to be automatic (the default) or\n"
00402            "manually." )
00403 
00404     .def ( "setTicks", &QtDisplay::setTicks,
00405            "setTicks ( string, sequence, sequence ) -> None\n"
00406            "\n"
00407            "Sets the tick locations and labels.   The first argument is the\n"
00408            " axis, the second argument is a sequence containing the\n"
00409            "locations, and the third argument is a sequence of tick labels." )
00410 
00411     .def ( "unlock", &QtDisplay::unlock,
00412            "unlock () -> None\n"
00413            "\n"
00414            "Unlock the application thread." )
00415 
00416     ;
00417 }
00418 
00419 } // namespace Python
00420 } // namespace hippodraw
00421 
00422 using namespace hippodraw;
00423 
00426 void QtDisplay::createDisplay ( const std::string & type, 
00427                                 const DataSource & nt, 
00428                                 const std::vector < std::string > & bindings )
00429 {
00430   if ( qApp ) qApp->lock ();
00431   DisplayController * controller = DisplayController::instance ();
00432   try {
00433     m_plotter = controller->createDisplay ( type, nt, bindings );
00434     if ( qApp ) qApp->unlock ();
00435   }
00436   catch ( const FactoryException & e ) {
00437     if ( qApp ) qApp->unlock ();
00438     throw e;
00439   }
00440   catch ( const DataRepException & e ) {
00441     if ( qApp ) qApp->unlock ();
00442     throw e;
00443   }
00444   catch ( const DataSourceException & e ) {
00445     if ( qApp ) qApp->unlock ();
00446     throw e;
00447   }
00448 }
00449 
00450 QtDisplay::
00451 QtDisplay ( const std::string & type,
00452             boost::python::tuple seq,
00453             const std::vector < std::string > & labels )
00454 {
00455   if ( qApp ) qApp -> lock ();
00456 
00457   object obj = seq.attr ( "__len__" ) ();
00458 
00459   ListTuple * ntuple = new ListTuple ( );
00460 
00461   try {
00462     unsigned int size = extract < unsigned int > ( obj );
00463 
00464     if ( size > labels.size () ) {
00465       string what ( "Display: Too few labels" );
00466       throw DataSourceException ( what );
00467     }
00468       
00469     for ( unsigned int i = 0, j = 0; i < size; i++, j++ ) {
00470       boost::python::list l = extract < boost::python::list > ( seq[i] );
00471 
00472       while ( labels[j] == "nil" ) {
00473         j++; // skip such labels
00474         if ( ! ( j < labels.size () ) ) {
00475           string what ( "Display: Too few non 'nil' labels" );
00476           throw DataSourceException ( what );
00477         }
00478 
00479       }
00480       ntuple -> addColumn ( labels[j], l );
00481     }
00482   }
00483   catch ( const DataSourceException & e ) {
00484     delete ntuple;
00485     if ( qApp ) qApp -> unlock ();
00486     throw e;
00487   }
00488 
00489   // Do not call createDisplay() as exceptions wouldn't print nicely
00490   try { 
00491     DisplayController * dc = DisplayController::instance ();
00492     m_plotter = dc -> createDisplay ( type, *ntuple, labels );
00493   }
00494   catch ( const FactoryException & e ) {
00495     delete ntuple;
00496     if ( qApp ) qApp->unlock ();
00497     throw e;
00498   }
00499   catch ( const DataRepException & e ) {
00500     delete ntuple;
00501     if ( qApp ) qApp->unlock ();
00502     throw e;
00503   }
00504   catch ( const DataSourceException & e ) {
00505     delete ntuple;
00506     if ( qApp ) qApp->unlock ();
00507     throw e;
00508   }
00509 
00510   // No use telling controller about it until we are sure to accept it.
00511   DataSourceController * dsc = DataSourceController::instance ();
00512   dsc -> registerNTuple ( ntuple );
00513 
00514   if ( qApp ) qApp -> unlock ();
00515 }
00516 
00517 QtDisplay::
00518 QtDisplay ( const std::string & type,
00519             boost::python::list seq,
00520             const std::vector < std::string > & labels )
00521 {
00522   if ( qApp ) qApp -> lock ();
00523 
00524   object obj = seq.attr ( "__len__" ) ();
00525 
00526   ListTuple * ntuple = new ListTuple ( );
00527 
00528   try {
00529     unsigned int size = extract < unsigned int > ( obj );
00530 
00531     if ( size > labels.size () ) {
00532       string what ( "Display: Too few labels" );
00533       throw DataSourceException ( what );
00534     }
00535       
00536     // gcc 2.95.3 needs full scoping
00537     for ( unsigned int i = 0, j = 0; i < size; i++, j++ ) {
00538       boost::python::list l = extract < boost::python::list > ( seq[i] );
00539 
00540       while ( labels[j] == "nil" ) {
00541         j++; // skip such labels
00542         if ( ! ( j < labels.size () ) ) {
00543           string what ( "Display: Too few non 'nil' labels" );
00544           throw DataSourceException ( what );
00545         }
00546 
00547       }
00548       ntuple -> addColumn ( labels[j], l );
00549     }
00550   }
00551   catch ( const DataSourceException & e ) {
00552     delete ntuple;
00553     if ( qApp ) qApp -> unlock ();
00554     throw e;
00555   }
00556 
00557   // Do not call createDisplay() as exceptions wouldn't print nicely
00558   try { 
00559     DisplayController * dc = DisplayController::instance ();
00560     m_plotter = dc -> createDisplay ( type, *ntuple, labels );
00561   }
00562   catch ( const FactoryException & e ) {
00563     delete ntuple;
00564     if ( qApp ) qApp->unlock ();
00565     throw e;
00566   }
00567   catch ( const DataRepException & e ) {
00568     delete ntuple;
00569     if ( qApp ) qApp->unlock ();
00570     throw e;
00571   }
00572   catch ( const DataSourceException & e ) {
00573     delete ntuple;
00574     if ( qApp ) qApp->unlock ();
00575     throw e;
00576   }
00577 
00578   // No use telling controller about it until we are sure to accept it.
00579   DataSourceController * dsc = DataSourceController::instance ();
00580   dsc -> registerNTuple ( ntuple );
00581 
00582   if ( qApp ) qApp -> unlock ();
00583 }
00584 
00585 QtDisplay::QtDisplay ()
00586   : m_plotter ( 0 )
00587 {
00588 }
00589 
00590 QtDisplay::
00591 QtDisplay ( const std::string & type )
00592 {
00593   if ( qApp ) qApp -> lock ();
00594   DisplayController * controller = DisplayController::instance ();
00595   try {
00596     m_plotter = controller -> createDisplay ( type );
00597     if ( qApp ) qApp -> unlock ();
00598   }
00599   catch ( const FactoryException & e ) {
00600     if ( qApp ) qApp->unlock ();
00601     throw e;
00602   }
00603   catch ( const DataRepException & e ) {
00604     if ( qApp ) qApp->unlock ();
00605     throw e;
00606   }
00607 }
00608 
00609 QtDisplay::QtDisplay( const std::string & type,
00610                       const DataSource & nt,
00611                       const std::vector< std::string > & bindings )
00612 {
00613    createDisplay ( type, nt, bindings );
00614 }
00615 
00616 QtDisplay::QtDisplay( const std::string & type,
00617                       const PyDataSource & nt,
00618                       const std::vector< std::string > & bindings )
00619 {
00620    createDisplay ( type, nt.dataSource(), bindings );
00621 }
00622 
00623 #ifdef HAVE_ROOT
00624 QtDisplay::
00625 QtDisplay ( const std::string & type,
00626             const QtRootNTuple & nt,
00627             const std::vector < std::string > & bindings )
00628 {
00629   nt.expandIfNeeded ( bindings );
00630   createDisplay ( type, nt, bindings );
00631 }
00632 
00633 QtDisplay::
00634 QtDisplay ( const std::string & type,
00635             const QtRootNTuple & nt,
00636             const std::vector < std::string > & variables,
00637             boost::python::list indices )
00638 {
00639   object obj = indices.attr ( "__len__" ) ();
00640   unsigned int size = extract < unsigned int > ( obj );
00641 
00642   if ( size != variables.size() ) {
00643     const string what ( "Display: bindings and indices not the same size." );
00644     throw DataSourceException ( what );
00645   }
00646 
00647   vector < vector < int > > vec ( size );
00648   for ( unsigned int i = 0; i < size; i++ ) {
00649     boost::python::list l = extract < boost::python::list > ( indices[i] );
00650     object o = l.attr ( "__len__" ) ();
00651     unsigned int len = extract < unsigned int > ( o );
00652     for ( unsigned int j = 0; j < len; j++ ) {
00653       unsigned int k = extract < unsigned int > ( l[j] );
00654       vec[i].push_back ( k );
00655     }
00656   }
00657 
00658   vector < string > bindings ( size );
00659 
00660   for ( unsigned int i = 0; i < size; i++ ) {
00661     const string & label = variables [ i ];
00662     const vector < int > & indexes = vec [ i ];
00663     const string name = nt.createBinding ( label, indexes );
00664     bindings [ i ] = name;
00665   }
00666   nt.expandIfNeeded ( bindings );
00667 
00668   createDisplay ( type, nt, bindings );
00669 }
00670 
00671 #endif // have_root
00672 
00673 QtDisplay::QtDisplay( PlotterBase * plotter) : m_plotter(plotter) {}
00674 
00675 QtDisplay::~QtDisplay () 
00676 { 
00677   //   delete m_plotter; 
00678 }
00679 
00680 PlotterBase * QtDisplay::display()
00681 {
00682   return m_plotter;
00683 }
00684 
00689 void QtDisplay::addDataRep ( const std::string & type, 
00690                              const DataSource * ntuple,
00691                              const std::vector < std::string > & bindings )
00692 {
00693   qApp->lock();
00694 
00695   DisplayController * controller = DisplayController::instance ();
00696   controller->addDataRep ( m_plotter, type, ntuple, bindings );
00697 
00698   qApp->unlock();
00699 }
00700 
00701 void
00702 QtDisplay::
00703 addDataRepStacked ( const std::string & type, 
00704                   const DataSource * ntuple,
00705                   const std::vector < std::string > & bindings )
00706 {
00707   qApp->lock();
00708 
00709   DisplayController * controller = DisplayController::instance ();
00710   controller->addDataRepStacked ( m_plotter, type, ntuple, bindings );
00711 
00712   qApp->unlock();
00713 }
00714 
00715 void QtDisplay::addDataRep ( PyDataRep * pyRep )
00716 {
00717    qApp->lock();
00718 
00719    DisplayController * controller = DisplayController::instance ();
00720    controller->addDataRep ( m_plotter, pyRep->getDataRep() );
00721 
00722    qApp->unlock();
00723 }
00724 
00725 void QtDisplay::addDataRep ( PyFunctionRep * pyFuncRep )
00726 {
00727    qApp->lock();
00728 
00729    DisplayController * controller = DisplayController::instance ();
00730    
00731    controller->addDataRep ( m_plotter, pyFuncRep->getRep() );
00732 
00733    qApp->unlock();
00734 }
00735 
00736 #ifndef BOOST_DEFECT
00737 void QtDisplay::addFunction ( FunctionBase * function ) {
00738    FunctionController * funcController = FunctionController::instance();
00739    DataRep * dataRep = m_plotter->getDataRep( 0 );
00740 
00741 // The following datarep will be deleted by the CompositePlotter.
00742    FunctionRep * funcRep = 
00743       funcController->createFunctionRep(function, dataRep);
00744 
00745    qApp->lock();
00746    DisplayController * controller = DisplayController::instance();
00747    dataRep = reinterpret_cast<DataRep *>(funcRep);
00748    controller->addDataRep(m_plotter, dataRep);
00749    qApp->unlock();
00750 }
00751 #endif // BOOST_DEFECT
00752 
00753 void QtDisplay::setRange ( const std::string & axis, double low, double high,
00754                            bool save)
00755 {
00756   if ( qApp ) qApp->lock ();
00757 
00758   if (save) {
00759      if (axis == "x" || axis == "X") 
00760         m_ranges["x"] = std::make_pair(low, high);
00761      if (axis == "y" || axis == "Y") 
00762         m_ranges["y"] = std::make_pair(low, high);
00763   }
00764      
00765   m_plotter->setRange ( axis, low, high );
00766 
00767   if ( qApp ) qApp->unlock();
00768 }
00769 
00770 void QtDisplay::setRange ( const std::string & axis, double low, double high )
00771 {
00772    setRange( axis, low, high, false );
00773 }
00774 
00775 std::vector<double> QtDisplay::getRange( const std::string & axis )
00776 {
00777    Axes::Type type = Axes::convert ( axis );
00778    const Range & axisRange = m_plotter->getRange( type, true );
00779    std::vector<double> myRange;
00780    myRange.push_back(axisRange.low());
00781    myRange.push_back(axisRange.high());
00782    return myRange;
00783 }
00784 
00785 int QtDisplay::saveView ()
00786 {
00787    std::vector<double> range_values;
00788    std::vector<double> range = getRange("x");
00789    range_values.push_back(range[0]);
00790    range_values.push_back(range[1]);
00791    m_ranges["x"] = std::make_pair(range[0], range[1]);
00792 
00793    range = getRange("y");
00794    range_values.push_back(range[0]);
00795    range_values.push_back(range[1]);
00796    m_ranges["y"] = std::make_pair(range[0], range[1]);
00797 
00798    return m_plotter->saveView(range_values);
00799 }
00800 
00801 void QtDisplay::setView ( int index )
00802 {
00803   if ( qApp ) qApp->lock ();
00804   try {
00805      m_plotter->setView( index );
00806   } catch (...) {
00807      if ( qApp ) qApp->unlock();
00808      throw;
00809   }
00810   if ( qApp ) qApp->unlock();
00811 }
00812 
00813 int QtDisplay::nextView( bool stepForward ) {
00814    int index(-1);
00815    if ( qApp ) qApp->lock ();
00816    try {
00817       index = m_plotter->nextView(stepForward);
00818    } catch (...) {
00819       if ( qApp ) qApp->unlock();
00820       throw;
00821    }
00822    if ( qApp ) qApp->unlock();
00823    return index;
00824 }
00825 
00826 int QtDisplay::numViews () {
00827    return m_plotter->numViews();
00828 }
00829 
00830 void QtDisplay::deleteView (int index) {
00831    if ( qApp ) qApp->lock ();
00832    try {
00833       m_plotter->deleteView(index);
00834    } catch (...) {
00835       if ( qApp ) qApp->unlock();
00836       throw;
00837    }
00838    if ( qApp ) qApp->unlock();
00839 }
00840 
00841 int QtDisplay::currentView () {
00842    return m_plotter->currentView();
00843 }
00844 
00845 void QtDisplay::setTitle ( const std::string & title )
00846 {
00847   if ( qApp ) qApp->lock ();
00848   m_plotter->setTitle ( title );
00849   if ( qApp ) qApp->unlock();
00850 }
00851 
00852 const std::string & QtDisplay::getTitle() const {
00853    return m_plotter->getTitle();
00854 }
00855 
00856 void
00857 QtDisplay::
00858 setPointRep ( RepBase * rep )
00859 {
00860   if ( qApp ) qApp->lock ();
00861   try {
00862      m_plotter->setRepresentation ( rep );
00863   } catch ( const std::runtime_error & e ) {
00864     if ( qApp ) qApp->unlock ();
00865     throw e;
00866   }
00867   if ( qApp ) qApp->unlock();
00868 }
00869 
00870 void
00871 QtDisplay::
00872 setContourLevels ( const std::vector<double> &levels ) 
00873 {
00874    if (qApp ) qApp->lock ();
00875    RepBase * rep = m_plotter->representation();
00876    
00877    if ( rep->name() == std::string("Contour") ) {
00878       DataRep * datarep 
00879          = m_plotter->getDataRep ( m_plotter->activePlotIndex() );
00880 
00881       dynamic_cast<ContourPointRep *>(rep)
00882          ->setContourValues( const_cast<std::vector<double>&>(levels), 
00883                              datarep->getProjector() );
00884 
00885       datarep->notifyObservers();
00886 
00887    } else {
00888       // do nothing
00889    }
00890    if (qApp ) qApp->unlock ();
00891 }
00892 
00893 void QtDisplay::setLabel ( const std::string & axis,
00894                            const std::string & label )
00895 {
00896   if ( qApp ) qApp->lock ();
00897   Axes::Type at = Axes::convert ( axis );
00898   m_plotter->setLabel ( at, label );
00899   if ( qApp ) qApp->unlock();
00900 }
00901 
00902 const std::string & QtDisplay::getLabel ( const std::string & axis ) const {
00903    Axes::Type at = Axes::convert ( axis );
00904    return m_plotter -> getLabel ( at );
00905 }
00906 
00907 void
00908 QtDisplay::
00909 setNumberOfBins ( const std::string & axis, unsigned int number )
00910 {
00911   m_plotter->setNumberOfBins ( axis, number );
00912 }
00913 
00914 void 
00915 QtDisplay::
00916 reset()
00917 {
00918   qApp -> lock ();
00919   m_plotter -> reset ();
00920   qApp -> unlock ();
00921 }
00922 
00923 void QtDisplay::setBinWidth ( const std::string & axis, double width,
00924                               bool save )
00925 {
00926   if ( qApp ) qApp->lock ();
00927 
00928   if (save) {
00929      if (axis == "x" || axis == "X") 
00930         m_binWidths["x"] = width;
00931      if (axis == "y" || axis == "Y") 
00932         m_binWidths["y"] = width;
00933   }     
00934 
00935   m_plotter->setBinWidth ( axis, width );
00936 
00937   if ( qApp ) qApp->unlock ();
00938 }
00939 
00940 double
00941 QtDisplay::
00942 getBinWidth ( const std::string & axis ) const
00943 {
00944   return m_plotter->getBinWidth ( axis);
00945 }
00946 
00947 void QtDisplay::setBinWidth ( const std::string & axis, double width ) {
00948    setBinWidth( axis, width, false );
00949 }
00950 
00951 void QtDisplay::setOffset ( const std::string & axis, double offset )
00952 {
00953   DisplayController * controller = DisplayController::instance ();
00954   Axes::Type type = Axes::convert ( axis );
00955 
00956   controller->setOffset ( m_plotter, type, offset );
00957 }
00958 
00961 void QtDisplay::setTransform ( const std::string & name )
00962 {
00963   qApp->lock();
00964 
00965   DisplayController * controller = DisplayController::instance ();
00966   try {
00967      controller->setTransform ( m_plotter, name );
00968      qApp->unlock ();
00969   } catch (PlotterException & eObj) {
00970      qApp->unlock ();
00971      throw eObj;
00972   } catch (FactoryException & eObj) {
00973      qApp->unlock ();
00974      throw eObj;
00975   }
00976 }
00977 
00978 void QtDisplay::unlock() {
00979    qApp->unlock();
00980 }
00981 
00982 void QtDisplay::setLog ( const std::string & axis, int flag )
00983 {
00984   if ( qApp ) qApp->lock ();
00985   Axes::Type type = Axes::convert ( axis );
00986   DisplayController * controller = DisplayController::instance ();
00987   bool yes = flag != 0;
00988 
00989   controller->setLog ( m_plotter, type, yes );
00990   if ( qApp ) qApp->unlock();
00991 }
00992 
00993 int QtDisplay::getLog ( const std::string & axis )
00994 {
00995   DisplayController * controller = DisplayController::instance ();
00996   if ( controller->getLog ( m_plotter, axis) ) {
00997      return 1;
00998   } else {
00999      return 0;
01000   }
01001 }
01002 
01003 void QtDisplay::setAutoRanging ( const std::string & axis, bool flag )
01004 {
01005   if ( qApp ) qApp->lock ();
01006   Axes::Type type = Axes::convert ( axis );
01007   m_plotter->setAutoRanging ( type, flag );
01008   if ( qApp ) qApp->unlock ();
01009 }
01010 
01011 PyDataRep * QtDisplay::getDataRep ()
01012 {
01013   int index = m_plotter->activePlotIndex();
01014   if ( index < 0 ) index = 0;
01015   DataRep * rep = m_plotter->getDataRep ( index );
01016   PyDataRep * pyrep = new PyDataRep ( rep );
01017 
01018   return pyrep;
01019 }
01020 
01021 const std::vector<PyDataRep *> &QtDisplay::getDataReps () const
01022 {
01023    m_pyDataReps.clear();
01024    int nReps = m_plotter->getNumDataReps();
01025    for (int i = 0; i < nReps; i++) {
01026       m_pyDataReps.push_back( new PyDataRep ( m_plotter->getDataRep( i ) ) );
01027    }
01028    return m_pyDataReps;
01029 }
01030 
01031 void
01032 QtDisplay::
01033 setAspectRatio ( double ratio )
01034 {
01035   m_plotter->setAspectRatio ( ratio );
01036 }
01037 
01038 void
01039 QtDisplay::
01040 addValues ( const std::vector < double > & v )
01041 {
01042   if ( qApp ) qApp -> lock ();
01043   m_plotter -> addValues ( v );
01044   if ( qApp ) qApp -> unlock ();
01045 }
01046 
01047 NTuple *
01048 QtDisplay::
01049 createNTuple () const
01050 {
01051   // Need to lock else could create NTuple not yet displayed
01052   if (qApp) qApp -> lock ();
01053   FunctionController * controller = FunctionController::instance();
01054   NTuple * ntuple = controller -> createNTuple ( m_plotter );
01055   if(qApp) qApp -> unlock ();
01056 
01057   return ntuple;
01058 }
01059 
01060 double
01061 QtDisplay::
01062 numberOfEntries() const
01063 {
01064    ProjectorBase * projector = m_plotter->activeProjector();
01065    return projector->getNumberOfEntries();
01066 }
01067 
01068 void
01069 QtDisplay::
01070 resize() 
01071 {
01072    if ( qApp ) qApp->lock ();
01073 
01074    if (m_binWidths.count("x")) {
01075       m_plotter->setBinWidth("x", m_binWidths["x"]);
01076    } else {
01077 // set and unset log-scale to get decent bin sizes
01078       DisplayController * controller = DisplayController::instance();
01079       if ( controller->getLog( m_plotter, "x" ) ) {
01080          setLog( "x", 0 );
01081          setLog( "x", 1 );
01082       } else { 
01083          setLog( "x", 1 );
01084          setLog( "x", 0 );
01085       }
01086    }
01087 
01088    if (m_binWidths.count("y")) {
01089       m_plotter->setBinWidth("y", m_binWidths["y"]);
01090    } else {
01091 // set and unset log-scale to get decent bin sizes
01092       DisplayController * controller = DisplayController::instance();
01093       if ( controller->getLog( m_plotter, "y" ) ) {
01094          setLog( "y", 0 );
01095          setLog( "y", 1 );
01096       } else { 
01097          setLog( "y", 1 );
01098          setLog( "y", 0 );
01099       }
01100    }
01101 
01102    if (m_ranges.count("x")) {
01103       m_plotter->setRange("x", m_ranges["x"].first, m_ranges["x"].second);
01104    } else {
01105       m_plotter->setAutoRanging("x", true);
01106    }
01107 
01108    if (m_ranges.count("y")) {
01109       m_plotter->setRange("y", m_ranges["y"].first, m_ranges["y"].second);
01110    } else {
01111       m_plotter->setAutoRanging("y", true);
01112    }
01113 
01114    if ( qApp ) qApp->unlock ();
01115 }
01116 
01117 int QtDisplay::plotterId() const
01118 {
01119    return m_plotter->plotterId();
01120 }
01121 
01125 void QtDisplay::
01126 setColorMap ( const std::string & name ) {
01127    if ( qApp ) qApp->lock ();
01128    BinToColorFactory * factory = BinToColorFactory::instance();
01129    const vector< std::string > & names = factory -> names();
01130    if ( std::find(names.begin(), names.end(), name) != names.end() ) {
01131       BinToColor * rep = factory -> create ( name );
01132       m_plotter -> setValueRep( rep );
01133       if ( qApp ) qApp->unlock ();
01134    } else {
01135       if ( qApp ) qApp->unlock ();
01136       std::ostringstream message;
01137       message << "QtDisplay::setColorMap:\n"
01138               << "BinToColor rep '" << name << "' does not exist.\n"
01139               << "Valid rep names are \n\n";
01140       for (unsigned int i = 0; i < names.size() ; i++) {
01141          message << "'" << names[i] << "'\n";
01142       }
01143       throw std::runtime_error(message.str());
01144    }
01145 }
01146 
01147 void
01148 QtDisplay::
01149 update ()
01150 {
01151   if ( qApp ) qApp->lock ();
01152 
01153   m_plotter -> update ();
01154 
01155   if ( qApp ) qApp->unlock ();
01156 }
01157 
01158 void
01159 QtDisplay::
01160 addObserver ( Observer * observer )
01161 {
01162   m_plotter -> addObserver ( observer );
01163 }
01164 
01165 void
01166 QtDisplay::
01167 setTicks ( const std::string & axis,
01168            const std::vector < double > & values,
01169            const std::vector < std::string > & labels )
01170 {
01171   if ( qApp ) qApp -> lock ();
01172   m_plotter -> setTicks ( axis, values, labels );
01173   if ( qApp ) qApp -> unlock ();
01174 }
01175 
01176 void
01177 QtDisplay::
01178 setAutoTicks ( const std::string & axis, bool yes )
01179 {
01180   if ( qApp ) qApp -> lock ();
01181   m_plotter -> setAutoTicks ( axis, yes );
01182   if ( qApp ) qApp -> unlock ();
01183 }
01184 
01185 #ifdef HAVE_NUMARRAY
01186 
01187 PyDataSource *
01188 QtDisplay::
01189 createDataArray () const
01190 {
01191   // Need to lock else could create NTuple not yet displayed
01192   if (qApp) qApp -> lock ();
01193 
01194   FunctionController * controller = FunctionController::instance();
01195   NTuple * ntuple = controller -> createNTuple ( m_plotter );
01196   PyDataSource * ds = new PyDataSource ( "NTuple", ntuple );
01197 
01198   if(qApp) qApp -> unlock ();
01199 
01200   return ds;
01201 }
01202 #endif

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3