2 * Copyright (c) 1997 Silicon Graphics, Inc. All Rights Reserved.
3 * Copyright (c) 2009 Aconex. All Rights Reserved.
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.
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
15 #include <Inventor/nodes/SoBaseColor.h>
16 #include <Inventor/nodes/SoSeparator.h>
29 ColorMod::ColorMod(const char *metric
, double scale
,
30 const ColorScale
&colors
, SoNode
*obj
)
31 : Modulate(metric
, scale
),
32 _state(Modulate::start
),
36 _root
= new SoSeparator
;
37 _color
= new SoBaseColor
;
39 _color
->rgb
.setValue(_errorColor
.getValue());
40 _root
->addChild(_color
);
43 if (_metrics
->numValues() == 1 && _scale
.numSteps() && status() >= 0) {
46 if (pmDebug
& DBG_TRACE_APPL2
)
47 cerr
<< "ColorMod: Added " << metric
<< " (Id = "
48 << _root
->getName().getString() << ")" << endl
;
52 else if (_metrics
->numValues() > 1) {
54 "Color modulated metric (%s) has more than one value (%d)",
55 metric
, _metrics
->numValues());
57 else if (_scale
.numSteps() == 0) {
59 "No color steps for color modulated metric (%s)",
65 ColorMod::refresh(bool fetchFlag
)
67 QmcMetric
&metric
= _metrics
->metric(0);
75 if (metric
.error(0) <= 0) {
76 if (_state
!= Modulate::error
) {
77 _color
->rgb
.setValue(_errorColor
.getValue());
78 _state
= Modulate::error
;
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
;
90 if (_state
!= Modulate::normal
)
91 _state
= Modulate::normal
;
92 _color
->rgb
.setValue(_scale
.step(value
).color().getValue());
98 ColorMod::dump(QTextStream
&os
) const
102 os
<< "Invalid Metric: " << pmErrStr(status()) << endl
;
105 dumpState(os
, _state
);
106 os
<< ", scale = " << _scale
<< ": ";
107 _metrics
->metric(0).dump(os
, true);
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
);
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());
128 str
.append(value
.setNum(metric
.value(0) * 100.0 * theScale
, 'g', 4));
129 str
.append("% of color scale]");
134 ColorMod::launch(Launch
&launch
, bool) const
138 launch
.startGroup("point");
139 launch
.addMetric(_metrics
->metric(0), _scale
, 0);
144 ColorMod::select(SoPath
*)
147 if (pmDebug
& DBG_TRACE_APPL2
)
148 cerr
<< "ColorMod::select: " << _metrics
->metric(0) << endl
;
154 ColorMod::remove(SoPath
*)
157 if (pmDebug
& DBG_TRACE_APPL2
)
158 cerr
<< "ColorMod::remove: " << _metrics
->metric(0) << endl
;