build: update parfait spec with a parfait-agent package
[pcp.git] / src / pmview / colormod.cpp
blobb2cefd956ace221729d1bcbc65c0576ae20c03b4
1 /*
2 * Copyright (c) 1997 Silicon Graphics, Inc. All Rights Reserved.
3 * Copyright (c) 2009 Aconex. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
15 #include <Inventor/nodes/SoBaseColor.h>
16 #include <Inventor/nodes/SoSeparator.h>
17 #include "main.h"
18 #include "colormod.h"
19 #include "modlist.h"
20 #include "launch.h"
22 #include <iostream>
23 using namespace std;
25 ColorMod::~ColorMod()
29 ColorMod::ColorMod(const char *metric, double scale,
30 const ColorScale &colors, SoNode *obj)
31 : Modulate(metric, scale),
32 _state(Modulate::start),
33 _scale(colors),
34 _color(0)
36 _root = new SoSeparator;
37 _color = new SoBaseColor;
39 _color->rgb.setValue(_errorColor.getValue());
40 _root->addChild(_color);
41 _root->addChild(obj);
43 if (_metrics->numValues() == 1 && _scale.numSteps() && status() >= 0) {
44 add();
45 #ifdef PCP_DEBUG
46 if (pmDebug & DBG_TRACE_APPL2)
47 cerr << "ColorMod: Added " << metric << " (Id = "
48 << _root->getName().getString() << ")" << endl;
49 #endif
52 else if (_metrics->numValues() > 1) {
53 warningMsg(_POS_,
54 "Color modulated metric (%s) has more than one value (%d)",
55 metric, _metrics->numValues());
57 else if (_scale.numSteps() == 0) {
58 warningMsg(_POS_,
59 "No color steps for color modulated metric (%s)",
60 metric);
64 void
65 ColorMod::refresh(bool fetchFlag)
67 QmcMetric &metric = _metrics->metric(0);
69 if (status() < 0)
70 return;
72 if (fetchFlag)
73 metric.update();
75 if (metric.error(0) <= 0) {
76 if (_state != Modulate::error) {
77 _color->rgb.setValue(_errorColor.getValue());
78 _state = Modulate::error;
81 else {
82 double value = metric.value(0) * theScale;
83 if (value > theNormError) {
84 if (_state != Modulate::saturated) {
85 _color->rgb.setValue(Modulate::_saturatedColor);
86 _state = Modulate::saturated;
89 else {
90 if (_state != Modulate::normal)
91 _state = Modulate::normal;
92 _color->rgb.setValue(_scale.step(value).color().getValue());
97 void
98 ColorMod::dump(QTextStream &os) const
100 os << "ColorMod: ";
101 if (status() < 0)
102 os << "Invalid Metric: " << pmErrStr(status()) << endl;
103 else {
104 os << "state = ";
105 dumpState(os, _state);
106 os << ", scale = " << _scale << ": ";
107 _metrics->metric(0).dump(os, true);
111 void
112 ColorMod::infoText(QString &str, bool) const
114 const QmcMetric &metric = _metrics->metric(0);
115 str = metric.spec(true, true, 0);
116 str.append(QChar('\n'));
117 if (_state == Modulate::error)
118 str.append(theErrorText);
119 else if (_state == Modulate::start)
120 str.append(theStartText);
121 else {
122 QString value;
123 str.append(value.setNum(metric.realValue(0), 'g', 4));
124 str.append(QChar(' '));
125 if (metric.desc().units().length() > 0)
126 str.append(metric.desc().units());
127 str.append(" [");
128 str.append(value.setNum(metric.value(0) * 100.0 * theScale, 'g', 4));
129 str.append("% of color scale]");
133 void
134 ColorMod::launch(Launch &launch, bool) const
136 if (status() < 0)
137 return;
138 launch.startGroup("point");
139 launch.addMetric(_metrics->metric(0), _scale, 0);
140 launch.endGroup();
144 ColorMod::select(SoPath *)
146 #ifdef PCP_DEBUG
147 if (pmDebug & DBG_TRACE_APPL2)
148 cerr << "ColorMod::select: " << _metrics->metric(0) << endl;
149 #endif
150 return 1;
154 ColorMod::remove(SoPath *)
156 #ifdef PCP_DEBUG
157 if (pmDebug & DBG_TRACE_APPL2)
158 cerr << "ColorMod::remove: " << _metrics->metric(0) << endl;
159 #endif
160 return 0;