~d-nelson/research-assistant/nextDNK

« back to all changes in this revision

Viewing changes to RAPlugins/Rigaku_APRI/Ludmil.cpp

  • Committer: Viktor Bursian
  • Date: 2013-06-06 13:42:39 UTC
  • Revision ID: vbursian@gmail.com-20130606134239-bx5ks8sg3y9oqckz
Tags: version_0.2.0
first usable version 0.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
/*! @file Ludmil.cpp   Людмил - прибор Русланы.
 
3
- Part of Rigaku_APRI - Research Assistant Plugin package.
 
4
- Uses  RAGUI - Research Assistant Graphical User Interface.
 
5
- Uses  QtGui v.4.6  -  http://qt.nokia.com/
 
6
- Uses  RANet - Research Assistant Net Library (based on ANSI C++).
 
7
- Copyright(C) 2010, Viktor E. Bursian, St.Petersburg, Russia.
 
8
                     Viktor.Bursian@mail.ioffe.ru
 
9
- Copyright(C) 2010, Dmitry K. Nelson, St.Petersburg, Russia.
 
10
                     D.Nelson@mail.ioffe.ru
 
11
*///////////////////////////////////////////////////////////////////////////////
 
12
#include "Ludmil.h"
 
13
#include "NetOps.h"
 
14
#include "GeneralGUI.h"
 
15
#include <QMessageBox>
 
16
#include <QDebug>
 
17
namespace RA {
 
18
//------------------------------------------------------------------------------
 
19
 
 
20
DEFINE_CLASS_TAG(sLudmil)
 
21
 
 
22
//------------------------------------------------------------------ sLudmil ---
 
23
 
 
24
sLudmil::~sLudmil()
 
25
{
 
26
  if( ! DeviceConfig.IsNULL() ){
 
27
    DeviceConfig << attr("Speed",FldSpeed->currentIndex());
 
28
  };
 
29
  if( PhotonCounter ){
 
30
    delete PhotonCounter;  PhotonCounter=NULL;
 
31
  };
 
32
};
 
33
 
 
34
 
 
35
sLudmil::sLudmil (sString   DevicetId
 
36
                 ,sNodePtr  DeviceCfg
 
37
                 ,sNodePtr  WidgetCfg)
 
38
    :sUniScanner(DevicetId,DeviceCfg,WidgetCfg)
 
39
    ,PhotonCounter(NULL)
 
40
    ,StartQuantum(1.0)
 
41
    ,NumOfSpeeds(3)
 
42
{
 
43
  LblStepUnit = new QLabel(tr("degree"),ParamArea);
 
44
  LblStepUnit->setObjectName("LblStepUnit");
 
45
  ParamLayout->addWidget(LblStepUnit,Row-1,2,1,1);
 
46
 
 
47
  LblSpeed = new QLabel(tr("Speed"),ParamArea);
 
48
  LblSpeed->setObjectName("LblSpeed");
 
49
  ParamLayout->addWidget(LblSpeed,Row,0,1,1);
 
50
  FldSpeed = new QComboBox(ParamArea);
 
51
  FldSpeed->setObjectName("FldSpeed");
 
52
  FldSpeed->insertItem(0,"ASpeed");
 
53
  FldSpeed->setCurrentIndex(0);
 
54
  ParamLayout->addWidget(FldSpeed,Row,1,1,1);
 
55
  LblSpeedUnit = new QLabel(tr("deg/min"),ParamArea);
 
56
  LblSpeedUnit->setObjectName("LblSpeedUnit");
 
57
  ParamLayout->addWidget(LblSpeedUnit,Row++,2,1,1);
 
58
  for( int i = 0 ; i < 12 ; ++i )
 
59
    Speeds[i]=0.5*(i+1);
 
60
 
 
61
  if( ! DeviceConfig.IsNULL() ){
 
62
    sIntegerNode::sPtr          I;
 
63
    sPhysValueNode::sPtr        R;
 
64
 
 
65
    DeviceConfig |= attr("NumOFSpeeds",3);
 
66
    I=DeviceConfig->GetAttr("NumOFSpeeds");
 
67
    if( I.IsCorrect() )
 
68
      NumOfSpeeds = (int)(*I);
 
69
    for (int Index = 1; Index < NumOfSpeeds; Index++ ) {
 
70
        FldSpeed->insertItem(Index,"ASpeed");
 
71
    }
 
72
    DeviceConfig |= attr("Speed",FldSpeed->currentIndex());
 
73
    I=DeviceConfig->GetAttr("Speed");
 
74
    if( I.IsCorrect() )
 
75
      FldSpeed->setCurrentIndex((int)(*I));
 
76
 
 
77
    sCluster::sPtr              SpeedsConf;
 
78
 
 
79
    DeviceConfig |= "Speeds";
 
80
    SpeedsConf=DeviceConfig->GetAttr("Speeds");
 
81
    if( SpeedsConf.IsCorrect() ){
 
82
      for( int i = 0 ; i < NumOfSpeeds ; ++i ){
 
83
        SpeedsConf |= attr(i+1,Speeds[i]);
 
84
        R=SpeedsConf->GetAttr(i+1);
 
85
        if( R.IsCorrect() )
 
86
          Speeds[i] = ((sPhysValue)(*R)).Value();
 
87
      };
 
88
    };
 
89
 
 
90
    DeviceConfig |= attr("StartQuantum",StartQuantum);
 
91
    R=DeviceConfig->GetAttr("StartQuantum");
 
92
    if( R.IsCorrect() )
 
93
      StartQuantum = ((sPhysValue)(*R)).Value();
 
94
 
 
95
    QString SS;
 
96
    for (int Index = 0; Index < NumOfSpeeds; Index++ ) {
 
97
        SS.setNum((double)Speeds[Index],'f',2);
 
98
        FldSpeed->setItemText(Index,SS);
 
99
    }
 
100
  };
 
101
 
 
102
  sTextNode::sPtr             CounterId(DeviceConfig
 
103
                                                 ->GetAttr("Counter"));
 
104
  if( CounterId.IsCorrect() ){
 
105
    PhotonCounter = dynamic_cast<psCounter_APRI_ML327>
 
106
                         (sDevice::CreateDevice(sString(*CounterId)));
 
107
  };
 
108
  connect(this,SIGNAL(ScanIsStarting()) ,this,SLOT(OnStartScan()));
 
109
  connect(this,SIGNAL(ScanIsFinished()) ,this,SLOT(OnFinishScan()));
 
110
};
 
111
 
 
112
 
 
113
void  sLudmil::Connect ()
 
114
{
 
115
  if( DeviceState() == Offline ){
 
116
    if( PhotonCounter ){
 
117
      SetDeviceState(Warming);
 
118
      PhotonCounter->Connect();
 
119
      connect(PhotonCounter,SIGNAL(NowStandby()),this,SLOT(EnterStandby()));
 
120
      connect(PhotonCounter,SIGNAL(NowOffline()),this,SLOT(ReportError()));
 
121
    }else{
 
122
      QMessageBox::critical(this
 
123
          ,sString2QString(DeviceIdentifier()+" failure.")
 
124
          ,tr("The counter driver has not been found. Check config.") );
 
125
    };
 
126
  };
 
127
};
 
128
 
 
129
void  sLudmil::EnterStandby ()
 
130
{
 
131
  disconnect(PhotonCounter,SIGNAL(NowStandby()),this,SLOT(EnterStandby()));
 
132
  SetDeviceState(Standby);
 
133
};
 
134
 
 
135
void  sLudmil::ReportError ()
 
136
{
 
137
  QMessageBox::critical(this
 
138
                       ,sString2QString(DeviceIdentifier()+" failure.")
 
139
                       ,tr("The counter '")
 
140
                       +sString2QString(PhotonCounter->DeviceIdentifier())
 
141
                       +tr("' does not respond.  Check connections.")
 
142
                       );
 
143
  SetDeviceState(Offline);
 
144
};
 
145
 
 
146
void  sLudmil::OnStartScan ()
 
147
{
 
148
  if (PhotonCounter->CountIsStarted())    PhotonCounter->StopCount();
 
149
  QMessageBox::information(this, tr("Start scanning")
 
150
                                ,tr("Set the starting angle ")
 
151
                                +QString::number(From-StartQuantum/2,'g',5)
 
152
                                 +tr(" and switch the motor on.")
 
153
                                ,QMessageBox::Ok);
 
154
    int CountMultiple = round((Step / Speeds[FldSpeed->currentIndex()])*60*10);
 
155
    if (CountMultiple < 1) CountMultiple = 1;
 
156
    int TimePar = round((Step / Speeds[FldSpeed->currentIndex()])*60*100/CountMultiple);
 
157
    //??  real RealStep = FldSpeed->value()*TimePar*CountMultiple/60/100;
 
158
    connect(PhotonCounter,SIGNAL(NewData(real)),this,SLOT(AddNewPoint(real)));
 
159
    PhotonCounter->StartScan(TimePar, CountMultiple);
 
160
    qDebug() << "Scan started";
 
161
}
 
162
 
 
163
void  sLudmil::OnFinishScan ()
 
164
{
 
165
  PhotonCounter->StopCount();
 
166
  disconnect(PhotonCounter,SIGNAL(NewData(real)),this,SLOT(AddNewPoint(real)));
 
167
  QMessageBox::information(this, tr("Scanning is finished")
 
168
                                ,tr("Switch off the motor.")
 
169
                                ,QMessageBox::Ok);
 
170
};
 
171
 
 
172
//------------------------------------------------------------------------------
 
173
}; //namespace RA