dcsource.cpp
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13  ***************************************************************************/
14 #include "ui_dcsourceform.h"
15 #include "dcsource.h"
16 #include "xnodeconnector.h"
17 #include <QStatusBar>
18 #include <QPushButton>
19 #include <QCheckBox>
20 
21 XDCSource::XDCSource(const char *name, bool runtime,
22  Transaction &tr_meas, const shared_ptr<XMeasure> &meas) :
23  XPrimaryDriver(name, runtime, ref(tr_meas), meas),
24  m_entryValue(create<XScalarEntry>("EntryValue", false,
25  dynamic_pointer_cast<XDriver>(shared_from_this()), "%.8f")),
26  m_function(create<XComboNode>("Function", false)),
27  m_output(create<XBoolNode>("Output", true)),
28  m_value(create<XDoubleNode>("Value", false)),
29  m_channel(create<XComboNode>("Channel", false, true)),
30  m_range(create<XComboNode>("Range", false, true)),
31  m_form(new FrmDCSource(g_pFrmMain)) {
32  m_form->statusBar()->hide();
33  m_form->setWindowTitle(i18n("DC Source - ") + getLabel() );
34 
35  meas->scalarEntries()->insert(tr_meas, m_entryValue);
36 
37  m_output->setUIEnabled(false);
38  m_function->setUIEnabled(false);
39  m_value->setUIEnabled(false);
40  m_channel->setUIEnabled(false);
41  m_range->setUIEnabled(false);
42 
43  m_conFunction = xqcon_create<XQComboBoxConnector>(m_function, m_form->m_cmbFunction, Snapshot( *m_function));
44  m_conOutput = xqcon_create<XQToggleButtonConnector>(m_output, m_form->m_ckbOutput);
45  m_conValue = xqcon_create<XQLineEditConnector>(m_value, m_form->m_edValue);
46  m_conChannel = xqcon_create<XQComboBoxConnector>(m_channel, m_form->m_cmbChannel, Snapshot( *m_channel));
47  m_conRange = xqcon_create<XQComboBoxConnector>(m_range, m_form->m_cmbRange, Snapshot( *m_range));
48 }
49 
50 void
52 //! impliment form->show() here
53  m_form->show();
54  m_form->raise();
55 }
56 
57 void
59  m_output->setUIEnabled(true);
60  m_function->setUIEnabled(true);
61  m_value->setUIEnabled(true);
62  m_channel->setUIEnabled(true);
63  m_range->setUIEnabled(true);
64 
65  iterate_commit([=](Transaction &tr){
66  m_lsnOutput = tr[ *output()].onValueChanged().connectWeakly(
67  shared_from_this(), &XDCSource::onOutputChanged);
68  m_lsnFunction = tr[ *function()].onValueChanged().connectWeakly(
69  shared_from_this(), &XDCSource::onFunctionChanged);
70  m_lsnValue = tr[ *value()].onValueChanged().connectWeakly(
71  shared_from_this(), &XDCSource::onValueChanged);
72  m_lsnChannel = tr[ *channel()].onValueChanged().connectWeakly(
73  shared_from_this(), &XDCSource::onChannelChanged);
74  m_lsnRange = tr[ *range()].onValueChanged().connectWeakly(
75  shared_from_this(), &XDCSource::onRangeChanged);
76  });
77  updateStatus();
78 }
79 void
81  m_lsnChannel.reset();
82  m_lsnOutput.reset();
83  m_lsnFunction.reset();
84  m_lsnValue.reset();
85 
86  m_output->setUIEnabled(false);
87  m_function->setUIEnabled(false);
88  m_value->setUIEnabled(false);
89  m_channel->setUIEnabled(false);
90  m_range->setUIEnabled(false);
91 
93 }
94 
95 void
97  m_entryValue->value(tr, tr[ *value()]);
98 }
99 void
101 }
102 
103 void
104 XDCSource::finish(const XTime &time_awared) {
105  auto writer = std::make_shared<RawData>();
106  if( !Snapshot( *this)[ *output()])
107  finishWritingRaw(writer, XTime(), XTime());
108  else
109  finishWritingRaw(writer, time_awared, XTime::now());
110 }
111 void
112 XDCSource::onOutputChanged(const Snapshot &shot, XValueNodeBase *) {
113  XTime time_awared(XTime::now());
114  int ch = ***channel();
115  try {
116  changeOutput(ch, shot[ *output()]);
117  }
118  catch (XKameError& e) {
119  e.print(getLabel() + i18n(": Error while changing output, "));
120  return;
121  }
122  finish(time_awared);
123 }
124 void
125 XDCSource::onFunctionChanged(const Snapshot &shot, XValueNodeBase *) {
126  XTime time_awared(XTime::now());
127  int ch = ***channel();
128  try {
129  changeFunction(ch, shot[ *function()]);
130  }
131  catch (XKameError& e) {
132  e.print(getLabel() + i18n(": Error while changing function, "));
133  return;
134  }
135  finish(time_awared);
136 }
137 void
138 XDCSource::onValueChanged(const Snapshot &shot, XValueNodeBase *) {
139  XTime time_awared(XTime::now());
140  int ch = ***channel();
141  try {
142  changeValue(ch, shot[ *value()], true);
143  }
144  catch (XKameError& e) {
145  e.print(getLabel() + i18n(": Error while changing value, "));
146  return;
147  }
148  finish(time_awared);
149 }
150 void
151 XDCSource::onRangeChanged(const Snapshot &shot, XValueNodeBase *) {
152  XTime time_awared(XTime::now());
153  int ch = ***channel();
154  try {
155  changeRange(ch, shot[ *range()]);
156  }
157  catch (XKameError& e) {
158  e.print(getLabel() + i18n(": Error while changing value, "));
159  return;
160  }
161  finish(time_awared);
162 }
163 void
164 XDCSource::onChannelChanged(const Snapshot &shot, XValueNodeBase *) {
165  try {
166  iterate_commit([=](Transaction &tr){
167  int ch = tr[ *channel()];
168  queryStatus(tr, ch);
169  tr.unmark(m_lsnOutput);
170  tr.unmark(m_lsnFunction);
171  tr.unmark(m_lsnRange);
172  tr.unmark(m_lsnValue);
173  });
174  }
175  catch (XKameError& e) {
176  e.print(getLabel());
177  return;
178  }
179 }

Generated for KAME4 by  doxygen 1.8.3