00001    #include <probeDialog.h>
00002    
00003    void probeDialog::monitorPvConnection (
00004      struct connection_handler_args arg
00005    ) {
00006    
00007    QString *str;
00008    int stat;
00009    probeDialog *pd = (probeDialog *) ca_puser(arg.chid);
00010    
00011      if ( arg.op == CA_OP_CONN_UP ) {
00012    
00013        str = new QString( ca_name(arg.chid) );
00014        pd->setPvName( *str );
00015        delete str;
00016    
00017        if ( !pd->ev ) {
00018          stat = ca_add_masked_array_event( DBR_DOUBLE, 0, arg.chid,
00019           probeDialog::monitorPvValue, (void *) pd, 0.0, 0.0, 0.0,
00020           &pd->ev, DBE_VALUE );
00021        }
00022    
00023      }
00024      else {
00025    
00026        pd->setPvName( tr("[Disconnected]") );
00027    
00028      }
00029    
00030    }
00031    
00032    void probeDialog::monitorPvValue (
00033      struct event_handler_args arg
00034    ) {
00035    
00036    char buf[31+1];
00037    double v;
00038    QString *str;
00039    probeDialog *pd = (probeDialog *) ca_puser(arg.chid);
00040    
00041      v = *( (double *) arg.dbr );
00042      snprintf( buf, 31, "%g", v );
00043    
00044      str = new QString( buf );
00045      pd->setPvValue( *str );
00046      delete str;
00047    
00048    }
00049    
00050    probeDialog::probeDialog () :
00051      QDialog( 0 ) {
00052    
00053      setWindowTitle( "<No Title>" );
00054    
00055      id = NULL;
00056      ev = NULL;
00057      pvConnected = 0;
00058    
00059    }
00060    
00061    probeDialog::probeDialog (
00062      QString titleStr
00063    ) : QDialog( 0 ) {
00064    
00065      setWindowTitle( titleStr );
00066    
00067      // CA init
00068    
00069      id = NULL;
00070      ev = NULL;
00071      pvConnected = false;
00072    
00073      // Setup layouts
00074    
00075      pvArea = new QVBoxLayout;
00076      pvArea->setMargin( 10 );
00077      pvArea->setSpacing( 6 );
00078    
00079      buttonArea = new QGridLayout;
00080      buttonArea->setMargin( 2 );
00081      buttonArea->setSpacing( 2 );
00082    
00083      // Widgets
00084    
00085      frame = new QGroupBox;
00086    
00087      pvName = new QLabel( this );
00088      pvName->setText( tr("[PV Name]") );
00089      pvName->setAlignment( Qt::AlignLeft );
00090    
00091      QFont f1( gAppFont, 18, QFont::Normal );
00092      f1.setItalic( true );
00093      pvName->setFont( f1 );
00094    
00095      pvArea->addWidget( pvName );
00096    
00097      pvValue = new QLabel( this );
00098      QFont f2( "Helvetica", 24, QFont::Bold );
00099      pvValue->setFont( f2 );
00100      setPvValue( tr("[Value]") );
00101      pvValue->setAlignment( Qt::AlignLeft );
00102    
00103      pvArea->addWidget( pvValue );
00104    
00105      pvStatus = new QLabel( this );
00106      setPvStatus( tr("[Status]") );
00107      pvStatus->setAlignment( Qt::AlignLeft );
00108      pvStatus->setFrameShadow( QFrame::Raised );
00109      pvStatus->setFrameShape( QFrame::Panel );
00110    
00111      pvArea->addWidget( pvStatus, 0, 0 );
00112    
00113      textField = new QLineEdit( this );
00114      connect( textField, SIGNAL(returnPressed(void)),
00115       this, SLOT(pvNameEntered(void)) );
00116    
00117      pvArea->addWidget( textField );
00118    
00119      // push buttons
00120    
00121      startB = new QPushButton( tr("start"), this );
00122      connect( startB, SIGNAL(pressed(void)), this, SLOT(start(void)) );
00123      buttonArea->addWidget( startB, 0, 0, Qt::AlignLeft );
00124      startB->setAutoDefault( false );
00125    
00126      stopB = new QPushButton( tr("stop"), this );
00127      connect( stopB, SIGNAL(pressed(void)), this, SLOT(stop(void)) );
00128      buttonArea->addWidget( stopB, 0, 1, Qt::AlignLeft );
00129      stopB->setAutoDefault( false );
00130    
00131      versionB = new QPushButton( tr("version"), this );
00132      connect( versionB, SIGNAL(pressed(void)), this, SLOT(version(void)) );
00133      buttonArea->addWidget( versionB, 0, 2, Qt::AlignLeft );
00134      versionB->setAutoDefault( false );
00135    
00136      quitB = new QPushButton( tr("quit"), this );
00137      connect( quitB, SIGNAL(pressed(void)), this, SLOT(quit(void)) );
00138      buttonArea->addWidget( quitB, 0, 3, Qt::AlignLeft );
00139      quitB->setAutoDefault( false );
00140    
00141      adjustB = new QPushButton( tr("adjust"), this );
00142      connect( adjustB, SIGNAL(pressed(void)), this, SLOT(adjust(void)) );
00143      buttonArea->addWidget( adjustB, 1, 0, Qt::AlignLeft );
00144      adjustB->setAutoDefault( false );
00145    
00146      histB = new QPushButton( tr("hist"), this );
00147      connect( histB, SIGNAL(pressed(void)), this, SLOT(hist(void)) );
00148      buttonArea->addWidget( histB, 1, 1, Qt::AlignLeft );
00149      histB->setAutoDefault( false );
00150    
00151      infoB = new QPushButton( tr("info"), this );
00152      connect( infoB, SIGNAL(pressed(void)), this, SLOT(info(void)) );
00153      buttonArea->addWidget( infoB, 1, 2, Qt::AlignLeft );
00154      infoB->setAutoDefault( false );
00155    
00156      formatB = new QPushButton( tr("format"), this );
00157      connect( formatB, SIGNAL(pressed(void)), this, SLOT(format(void)) );
00158      buttonArea->addWidget( formatB, 1, 3, Qt::AlignLeft );
00159      formatB->setAutoDefault( false );
00160    
00161      // frame layout
00162    
00163      frame->setLayout( pvArea );
00164    
00165      // main layout
00166    
00167      mainLayout = new QVBoxLayout( this );
00168      mainLayout->addWidget( frame );
00169      mainLayout->addLayout( buttonArea );
00170    
00171    }
00172    
00173    probeDialog::~probeDialog ( void ) {
00174    
00175    }
00176    
00177    void probeDialog::connectPv (
00178      const QString& name
00179    ) {
00180    
00181    int stat;
00182    
00183      pvConnected = 0;
00184      setPvName( "" );
00185    
00186      if ( id ) {
00187        ca_clear_channel( id );
00188        id = NULL;
00189        ev = 0;
00190      }
00191    
00192      stat = ca_search_and_connect( name.toAscii(),
00193       &id, probeDialog::monitorPvConnection, this );
00194      if ( stat != ECA_NORMAL ) {
00195        pvName->setText( tr("[ca_search_and_connect failure]") );
00196      }
00197    
00198    }
00199    
00200    QString probeDialog::getPvName ( void ) const {
00201    
00202      return pvName->text();
00203    
00204    }
00205    
00206    void probeDialog::setPvName (
00207        const QString& name
00208      ) const {
00209    
00210      pvName->setText( name );
00211    
00212    }
00213    
00214    void probeDialog::setPvValue (
00215        const QString& value
00216      ) const {
00217    
00218      pvValue->setText( value );
00219    
00220    }
00221    
00222    void probeDialog::setPvStatus (
00223        const QString& value
00224      ) const {
00225    
00226      pvStatus->setText( value );
00227    
00228    }
00229    
00230    void probeDialog::start ( void ) {
00231    
00232      printf( tr("start\n").toAscii() );
00233    
00234    }
00235    
00236    void probeDialog::stop ( void ) {
00237    
00238      printf( tr("stop\n").toAscii() );
00239    
00240    }
00241    
00242    void probeDialog::version ( void ) {
00243    
00244      printf( tr("version\n").toAscii() );
00245    
00246    }
00247    
00248    void probeDialog::quit ( void ) {
00249    
00250      printf( tr("quit\n").toAscii() );
00251      exit( 0 );
00252    
00253    }
00254    
00255    void probeDialog::adjust ( void ) {
00256    
00257      printf( tr("adjust\n").toAscii() );
00258    
00259    }
00260    
00261    void probeDialog::hist ( void ) {
00262    
00263      printf( tr("hist\n").toAscii() );
00264    
00265    }
00266    
00267    void probeDialog::info ( void ) {
00268    
00269      printf( tr("info\n").toAscii() );
00270    
00271    }
00272    
00273    void probeDialog::format ( void ) {
00274    
00275      printf( tr("format\n").toAscii() );
00276    
00277    }
00278    
00279    void probeDialog::pvNameEntered ( void ) {
00280    
00281      textField->end( false );
00282      connectPv( textField->text() );
00283    
00284    }