summaryrefslogtreecommitdiff
path: root/src/pmview/modulate.cpp
blob: 8e3fb98919643f0fb7283c7f6a18c3bf3868f60c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * Copyright (c) 1997 Silicon Graphics, Inc.  All Rights Reserved.
 * Copyright (c) 2009 Aconex.  All Rights Reserved.
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoSelection.h>
#include "modulate.h"
#include "modlist.h"

#include <iostream>
using namespace std;

double			theNormError = 1.05;

const QString	Modulate::theErrorText = "Metric Unavailable";
const QString	Modulate::theStartText = "Metric has not been fetched from source";
const float	Modulate::theDefErrorColor[] = {0.2, 0.2, 0.2};
const float	Modulate::theDefSaturatedColor[] = {1.0, 1.0, 1.0};
const double	Modulate::theMinScale = 0.01;

Modulate::~Modulate()
{
}

Modulate::Modulate(const char *metric, double scale,
			   MetricList::AlignColor align)
: _sts(0), _metrics(0), _root(0)
{
    _metrics = new MetricList();
    _sts = _metrics->add(metric, scale);
    if (_sts >= 0) {
	_metrics->resolveColors(align);
	_saturatedColor.setValue(theDefSaturatedColor);
    }
    _errorColor.setValue(theDefErrorColor);
}

Modulate::Modulate(const char *metric, double scale, 
			   const SbColor &color,
			   MetricList::AlignColor align)
:  _sts(0), _metrics(0), _root(0)
{
    _metrics = new MetricList();
    _sts = _metrics->add(metric, scale);
    if (_sts >= 0) {
	_metrics->add(color),
	_metrics->resolveColors(align);
    }
    _saturatedColor.setValue(theDefSaturatedColor);
    _errorColor.setValue(theDefErrorColor);
}

Modulate::Modulate(MetricList *list)
:  _sts(0), _metrics(list), _root(0)
{
    _saturatedColor.setValue(theDefSaturatedColor);
    _errorColor.setValue(theDefErrorColor);
}

const char *
Modulate::add()
{
    const char *str = theModList->add(this);
    _root->setName((SbName)str);
    return str;
}

QTextStream &
operator<<(QTextStream & os, const Modulate &rhs)
{
    rhs.dump(os);
    return os;
}

void
Modulate::dumpState(QTextStream &os, Modulate::State state) const
{
    switch(state) {
    case Modulate::start:
	os << "Start";
	break;
    case Modulate::error:
	os << "Error";
	break;
    case Modulate::saturated:
	os << "Saturated";
	break;
    case Modulate::normal:
	os << "Normal";
	break;
    default:
	os << "Unknown";
	break;
    }
}

void
Modulate::record(Record &rec) const
{
#if 1	// TODO
     (void)rec;
#else	// TODO
    int		i;

    if (_metrics != NULL)
	for (i = 0; i < _metrics->numMetrics(); i++) {
	    const QmcMetric &metric = _metrics->metric(i);
	    rec.add(metric.context()->source().sourceAscii(), 
		    (const char *)metric.spec(false, true).toAscii());
	}
#endif
}

void
Modulate::selectAll()
{
#ifdef PCP_DEBUG
    if (pmDebug & DBG_TRACE_APPL2)
	cerr << "Modulate::selectAll: selectAll for " << *this << endl;
#endif

    theModList->selectAllId(_root, 1);
    theModList->selectSingle(_root);
}