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

QtCut.cxx

Go to the documentation of this file.
00001 
00012 // For truncation warning
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016 
00017 #include "QtCut.h"
00018 
00019 #include "PyDataSource.h"
00020 
00021 #include "controllers/CutController.h"
00022 #include "datasrcs/DataSource.h"
00023 #include "datasrcs/TupleCut.h"
00024 #include "plotters/Cut1DPlotter.h"
00025 #include "plotters/Cut2DPlotter.h"
00026 #include "axes/Range.h"
00027 #include "axes/AxesType.h"
00028 
00029 
00030 // with Python 2.3, include before qapplication.h to avoid conflict
00031 // with symbol `slots'
00032 #include <boost/python.hpp>
00033 
00034 #include "qapplication.h"
00035 
00036 using std::vector;
00037 using namespace boost::python;
00038 
00039 namespace hippodraw {
00040 namespace Python {
00041 
00042 void
00043 export_QtCut()
00044 {
00045   class_ <QtCut, bases<QtDisplay> >
00046     ( "Cut",
00047       "An object of this class applies a cut or filter on the data that is\n"
00048       "used as input to its target displays.",
00049       init < const DataSource&, 
00050              const std::vector < std::string > & >
00051       ( "Cut ( DataSource, sequence ) -> Cut\n"
00052         "Cut ( DataArray, sequence ) -> Cut\n"
00053         "Cut ( DataSource, sequence, Display, value, value ) -> Cut\n"
00054         "Cut ( DataArray, sequence, Display, value, value ) -> Cut\n"
00055         "\n"
00056         "Creates a Cut bound to DataSource.  For each form, the first\n"
00057         "argument is the DataSource and the second argument is sequence of\n"
00058         "strings specifying the binding.  The latter two forms apply the\n"
00059         "Cut to a Display with low and high values for the Cut range." ) )
00060 
00061     .def ( init < const DataSource &,
00062            const std::vector < std::string > &,
00063            QtDisplay *, double, double > () )
00064 
00065     .def (  init < const PyDataSource&, 
00066             const std::vector < std::string > & > () )
00067 
00068     .def ( init < const PyDataSource &,
00069            const std::vector < std::string > &,
00070            QtDisplay *, double, double > () )
00071 
00072     .def ( "addTarget", &QtCut::addTarget,
00073            "addTarget ( Display ) -> None\n"
00074            "\n"
00075            "Adds a Display to the list of targets." )
00076 
00077     .def ( "addTargets", &QtCut::addTargets,
00078            "addTargets ( sequence ) -> None\n"
00079            "\n"
00080            "Adds Display objects in the sequence to the list targets" )
00081 
00082     .def ( "setCutRange", &QtCut::setCutRange,
00083            "setCutRange ( value, value, string ) -> None\n"
00084            "\n"
00085            "Sets the range of the Cut.  Arguments are low and high values,\n"
00086            "and the axis." )
00087 
00088     .def ( "cutRange", &QtCut::cutRange,
00089            "cutRange () -> tuple\n"
00090            "\n"
00091            "Returns a pair of values of the range ofeach Cut." )
00092 
00093     .def ( "setEnabled", &QtCut::setEnabled,
00094            "setEnabled ( boolean ) -> None\n"
00095            "\n"
00096            "Sets the cut to be enabled or not" )
00097 
00098     .def ( "toggleInverted", &QtCut::toggleInverted,
00099            "toggleInverted () -> None\n"
00100            "\n"
00101            "Toggles the inversion status" )
00102 
00103     ;
00104 }
00105 
00106 } // namespace Python
00107 } // namespace hippodraw
00108 
00109 void
00110 QtCut::
00111 createCut ( const DataSource & nt,
00112             const std::vector < std::string > & binding )
00113 {
00114   CutController * controller = CutController::instance ();
00115   m_plotter = controller -> createCut ( std::string(), &nt, binding );
00116 }
00117 
00118 QtCut::
00119 QtCut ( const DataSource & nt, 
00120         const std::vector< std::string > & binding,
00121         QtDisplay * target, double low, double high  )
00122    : QtDisplay ( )
00123 {
00124   createCut ( nt, binding );
00125 
00126   addTarget ( target );
00127   setCutRange ( low, high, "x" );
00128 }
00129 
00130 QtCut::
00131 QtCut ( const PyDataSource & ds, 
00132         const std::vector< std::string > & binding,
00133         QtDisplay * target, double low, double high  )
00134    : QtDisplay ( )
00135 {
00136   createCut ( ds.dataSource(), binding );
00137 
00138   addTarget ( target );
00139   setCutRange ( low, high, "x" );
00140 }
00141 
00142 QtCut::
00143 QtCut ( const DataSource & nt, 
00144         const std::vector< std::string > & binding )
00145    : QtDisplay ( )
00146 {
00147   createCut ( nt, binding );
00148 }
00149 
00150 QtCut::
00151 QtCut ( const PyDataSource & nt, 
00152         const std::vector< std::string > & binding )
00153    : QtDisplay ( )
00154 {
00155   createCut ( nt.dataSource (), binding );
00156 }
00157 
00158 QtCut::QtCut ( PlotterBase * plotter ) 
00159    : QtDisplay()
00160 {
00161   CutPlotter * cut_plotter = dynamic_cast < CutPlotter * > ( plotter );
00162   assert ( cut_plotter != 0 );
00163 
00164   m_plotter = plotter;
00165 }
00166 
00167 void QtCut::addTarget ( QtDisplay * target )
00168 {
00169   if (qApp) qApp->lock();
00170 
00171   CutController * controller = CutController::instance ();
00172   controller -> addCut ( m_plotter, target -> display () );
00173   
00174   if (qApp) qApp->unlock();
00175 }
00176 
00177 void QtCut::addTargets ( const std::vector < QtDisplay * > & targets )
00178 {
00179   if (qApp) qApp->lock();
00180 
00181   CutController * controller = CutController::instance ();
00182   unsigned int size = targets.size ();
00183   for ( unsigned int i = 0; i < size; i++ ) {
00184     QtDisplay * target = targets [ i ];
00185     controller -> addCut ( m_plotter, target -> display () );
00186   }
00187   
00188   if (qApp) qApp->unlock();
00189 }
00190 
00191 void QtCut::setCutRange ( double low, double high, const std::string & axis )
00192 {
00193   hippodraw::Axes::Type type = hippodraw::Axes::convert( axis );
00194 
00195   if (qApp) qApp->lock();
00196   
00197   CutPlotter * cut_plotter = dynamic_cast < CutPlotter * > ( m_plotter );
00198   assert ( cut_plotter != 0 );
00199 
00200   const Range range ( low, high );
00201   cut_plotter -> setCutRangeAt ( range, type );    
00202 
00203   if (qApp) qApp->unlock();
00204 }
00205 
00206 
00207 std::vector<double> QtCut::cutRange ()
00208 {
00209   if (qApp) qApp->lock();
00210 
00211   std::vector<double> myCutRange;
00212   vector < const TupleCut * > cuts;
00213   m_plotter -> fillCutList ( cuts );
00214 
00215   for ( unsigned int i = 0; i < cuts.size(); i++ ) {
00216     const TupleCut * cut = cuts [ i ];
00217     const Range & range = cut -> getRange ();
00218     myCutRange.push_back ( range.low () );
00219     myCutRange.push_back ( range.high () );
00220   }
00221   if (qApp) qApp->unlock();
00222 
00223   return myCutRange;
00224 
00225 }
00226 
00227 void
00228 QtCut::
00229 setEnabled ( bool yes )
00230 {
00231   if ( qApp ) qApp -> lock ();
00232   CutPlotter * plotter = dynamic_cast < CutPlotter * > ( m_plotter );
00233   plotter -> setEnabled ( yes );
00234   if (qApp) qApp->unlock();
00235 }
00236 
00237 void
00238 QtCut::
00239 toggleInverted ()
00240 {
00241   if ( qApp ) qApp -> lock ();
00242   CutPlotter * plotter = dynamic_cast < CutPlotter * > ( m_plotter );
00243   plotter -> toggleInverted ();
00244   if (qApp) qApp->unlock();
00245 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3