15 #include "ui_graphform.h"
16 #include "graphwidget.h"
25 XScalarEntry::XScalarEntry(
const char *name,
bool runtime,
const shared_ptr<XDriver> &driver,
27 :
XNode(name, runtime),
30 m_store(create<
XBoolNode>(
"Store", false)),
32 m_storedValue(create<
XDoubleNode>(
"StoredValue", true)) {
34 m_delta->setFormat(format);
35 m_storedValue->setFormat(format);
36 m_value->setFormat(format);
37 trans( *store()) =
false;
41 tr[ *storedValue()] = (double)tr[ *value()];
42 tr[ *
this].m_bTriggered =
false;
53 if((shot[ *delta()] != 0) && (fabs(val - shot[ *storedValue()]) > shot[ *delta()])) {
54 tr[ *
this].m_bTriggered =
true;
59 XValChart::XValChart(
const char *name,
bool runtime,
60 const shared_ptr<XScalarEntry> &entry)
61 :
XNode(name, runtime),
63 m_graph(create<
XGraph>(name, false)),
64 m_graphForm(new
FrmGraph(g_pFrmMain, Qt::Window)) {
66 m_graphForm->m_graphwidget->setGraph(m_graph);
69 m_chart= m_graph->plots()->create<
XXYPlot>(tr, entry->getLabel().c_str(),
true, ref(tr), m_graph);
70 tr[ *m_graph->persistence()] = 0.0;
71 tr[ *m_chart->label()] = entry->
getLabel();
73 shared_ptr<XAxis> axisx = static_pointer_cast<
XAxis>(axes_list.at(0));
74 shared_ptr<XAxis> axisy = static_pointer_cast<
XAxis>(axes_list.at(1));
76 tr[ *m_chart->axisX()] = axisx;
77 tr[ *m_chart->axisY()] = axisy;
78 tr[ *m_chart->maxCount()] = 600;
79 tr[ *axisx->length()] = 0.95 - tr[ *axisx->x()];
80 tr[ *axisy->length()] = 0.90 - tr[ *axisy->y()];
81 tr[ *axisx->label()] =
"Time";
82 tr[ *axisx->ticLabelFormat()] =
"TIME:%H:%M:%S";
83 tr[ *axisy->label()] = entry->
getLabel();
84 tr[ *axisy->ticLabelFormat()] = entry->value()->format();
85 tr[ *axisx->minValue()].setUIEnabled(
false);
86 tr[ *axisx->maxValue()].setUIEnabled(
false);
87 tr[ *axisx->autoScale()].setUIEnabled(
false);
88 tr[ *axisx->logScale()].setUIEnabled(
false);
89 tr[ *m_graph->label()] = entry->getLabel();
92 entry->driver()->iterate_commit([=](
Transaction &tr){
93 m_lsnOnRecord = tr[ *entry->driver()].onRecord().connectWeakly(
94 shared_from_this(), &XValChart::onRecord);
100 val = shot[ *m_entry->value()];
101 XTime time = shot[ *driver].time();
104 m_chart->addPoint(tr, time.sec() + time.usec() * 1e-6, val);
108 XValChart::showChart(
void) {
109 m_graphForm->setWindowTitle(i18n(
"Chart - ") +
getLabel() );
110 m_graphForm->showNormal();
113 XChartList::XChartList(
const char *name,
bool runtime,
const shared_ptr<XScalarEntryList> &entries)
117 m_lsnOnCatchEntry = tr[ *entries].onCatch().connectWeakly(shared_from_this(), &XChartList::onCatchEntry);
118 m_lsnOnReleaseEntry = tr[ *entries].onRelease().connectWeakly(shared_from_this(), &XChartList::onReleaseEntry);
124 shared_ptr<XScalarEntry> entry = static_pointer_cast<
XScalarEntry>(e.caught);
125 create<XValChart>(entry->getLabel().c_str(),
true, entry);
129 shared_ptr<XScalarEntry> entry = dynamic_pointer_cast<
XScalarEntry>(e.released);
131 shared_ptr<XValChart> valchart;
134 for(
auto it = list.begin(); it != list.end(); it++) {
135 auto chart = dynamic_pointer_cast<
XValChart>( *it);
136 if(chart->entry() == entry) valchart = chart;
147 XValGraph::XValGraph(
const char *name,
bool runtime,
148 Transaction &tr_entries,
const shared_ptr<XScalarEntryList> &entries)
149 :
XNode(name, runtime),
151 m_axisX(create<tAxis>(
"AxisX", false, ref(tr_entries), entries)),
152 m_axisY1(create<tAxis>(
"AxisY1", false, ref(tr_entries), entries)),
153 m_axisZ(create<tAxis>(
"AxisZ", false, ref(tr_entries), entries)),
156 m_lsnAxisChanged = tr[ *axisX()].onValueChanged().connectWeakly(
157 shared_from_this(), &XValGraph::onAxisChanged,
158 XListener::FLAG_MAIN_THREAD_CALL | XListener::FLAG_AVOID_DUP);
159 tr[ *axisY1()].onValueChanged().connect(m_lsnAxisChanged);
160 tr[ *axisZ()].onValueChanged().connect(m_lsnAxisChanged);
165 shared_ptr<XScalarEntry> entryx;
166 shared_ptr<XScalarEntry> entryy1;
167 shared_ptr<XScalarEntry> entryz;
168 shared_ptr<XGraph> graph;
171 entryx = shot_this[ *axisX()];
172 entryy1 = shot_this[ *axisY1()];
173 entryz = shot_this[ *axisZ()];
175 if(tr[ *
this].m_graph)
release(tr, tr[ *
this].m_graph);
176 tr[ *
this].m_graph = create<XGraph>(tr,
getName().c_str(),
false);
177 graph = tr[ *
this].m_graph;
179 if( !entryx || !entryy1)
return;
181 tr[ *
this].m_livePlot =
182 graph->plots()->create<
XXYPlot>(tr,
183 (graph->getName() +
"-Live").c_str(),
false, ref(tr), graph);
184 tr[ *shot_this[ *
this].m_livePlot->label()] = graph->
getLabel() +
" Live";
185 tr[ *
this].m_storePlot =
186 graph->plots()->create<
XXYPlot>(tr,
187 (graph->getName() +
"-Stored").c_str(),
false, ref(tr), graph);
188 tr[ *shot_this[ *
this].m_storePlot->label()] = graph->
getLabel() +
" Stored";
191 auto axisx = static_pointer_cast<
XAxis>(axes_list.at(0));
192 auto axisy = static_pointer_cast<
XAxis>(axes_list.at(1));
194 tr[ *axisx->ticLabelFormat()] = entryx->value()->format();
195 tr[ *axisy->ticLabelFormat()] = entryy1->value()->format();
196 tr[ *shot_this[ *
this].m_livePlot->axisX()] = axisx;
197 tr[ *shot_this[ *
this].m_livePlot->axisY()] = axisy;
198 tr[ *shot_this[ *
this].m_storePlot->axisX()] = axisx;
199 tr[ *shot_this[ *
this].m_storePlot->axisY()] = axisy;
201 tr[ *axisx->length()] = 0.95 - shot_this[ *axisx->x()];
202 tr[ *axisy->length()] = 0.90 - shot_this[ *axisy->y()];
204 shared_ptr<XAxis> axisz = graph->axes()->create<
XAxis>(
205 tr,
"Z Axis",
false, XAxis::DirAxisZ,
false, ref(tr), graph);
206 tr[ *axisz->ticLabelFormat()] = entryz->value()->format();
207 tr[ *shot_this[ *
this].m_livePlot->axisZ()] = axisz;
208 tr[ *shot_this[ *
this].m_storePlot->axisZ()] = axisz;
210 tr[ *axisz->label()] = entryz->
getLabel();
213 tr[ *shot_this[ *
this].m_storePlot->pointColor()] = clGreen;
214 tr[ *shot_this[ *
this].m_storePlot->lineColor()] = clGreen;
215 tr[ *shot_this[ *
this].m_storePlot->barColor()] = clGreen;
216 tr[ *shot_this[ *
this].m_storePlot->displayMajorGrid()] =
false;
217 tr[ *shot_this[ *
this].m_livePlot->maxCount()] = 10000;
218 tr[ *shot_this[ *
this].m_storePlot->maxCount()] = 10000;
219 tr[ *axisx->label()] = entryx->
getLabel();
220 tr[ *axisy->label()] = entryy1->
getLabel();
223 m_graphForm.reset(
new FrmGraph(g_pFrmMain, Qt::Window));
224 m_graphForm->m_graphwidget->setGraph(graph);
225 m_entries.lock()->iterate_commit([=](
Transaction &tr){
226 if( !tr.isUpperOf( *entryx))
return;
227 if( !tr.isUpperOf( *entryy1))
return;
228 if(entryz && !tr.isUpperOf( *entryz))
return;
229 m_lsnLiveChanged = tr[ *entryx->value()].onValueChanged().connectWeakly(
230 shared_from_this(), &XValGraph::onLiveChanged);
231 tr[ *entryy1->value()].onValueChanged().connect(m_lsnLiveChanged);
232 if(entryz) tr[ *entryz->value()].onValueChanged().connect(m_lsnLiveChanged);
234 m_lsnStoreChanged = tr[ *entryx->storedValue()].onValueChanged().connectWeakly(
235 shared_from_this(), &XValGraph::onStoreChanged);
236 tr[ *entryy1->storedValue()].onValueChanged().connect(m_lsnStoreChanged);
237 if(entryz) tr[ *entryz->storedValue()].onValueChanged().connect(m_lsnStoreChanged);
244 XValGraph::clearAllPoints() {
246 if( !tr[ *
this].m_graph)
return;
247 tr[ *
this].m_storePlot->clearAllPoints(tr);
248 tr[ *
this].m_livePlot->clearAllPoints(tr);
254 shared_ptr<XScalarEntry> entryx = shot_this[ *axisX()];
255 shared_ptr<XScalarEntry> entryy1 = shot_this[ *axisY1()];
256 shared_ptr<XScalarEntry> entryz = shot_this[ *axisZ()];
257 if( !entryx || !entryy1)
return;
258 Snapshot shot_entries( *m_entries.lock());
259 if( !shot_entries.isUpperOf( *entryx))
return;
260 if( !shot_entries.isUpperOf( *entryy1))
return;
261 if(entryz && !shot_entries.isUpperOf( *entryz))
return;
263 double x, y, z = 0.0;
264 x = shot_entries[ *entryx->value()];
265 y = shot_entries[ *entryy1->value()];
266 if(entryz) z = shot_entries[ *entryz->value()];
269 tr[ *
this].m_livePlot->addPoint(tr, x, y, z);
275 shared_ptr<XScalarEntry> entryx = shot_this[ *axisX()];
276 shared_ptr<XScalarEntry> entryy1 = shot_this[ *axisY1()];
277 shared_ptr<XScalarEntry> entryz = shot_this[ *axisZ()];
278 if( !entryx || !entryy1)
return;
279 Snapshot shot_entries( *m_entries.lock());
280 if( !shot_entries.isUpperOf( *entryx))
return;
281 if( !shot_entries.isUpperOf( *entryy1))
return;
282 if(entryz && !shot_entries.isUpperOf( *entryz))
return;
284 double x, y, z = 0.0;
285 x = shot_entries[ *entryx->storedValue()];
286 y = shot_entries[ *entryy1->storedValue()];
287 if(entryz) z = shot_entries[ *entryz->storedValue()];
290 tr[ *
this].m_storePlot->addPoint(tr, x, y, z);
294 XValGraph::showGraph() {
296 m_graphForm->setWindowTitle(i18n(
"Graph - ") +
getLabel() );
297 m_graphForm->showNormal();
301 XGraphList::XGraphList(
const char *name,
bool runtime,
const shared_ptr<XScalarEntryList> &entries)
308 shared_ptr<XValGraph> x;
309 m_entries->iterate_commit([=, &x](
Transaction &tr){
310 x = create<XValGraph>(name.c_str(),
false, ref(tr), m_entries);