build: update parfait spec with a parfait-agent package
[pcp.git] / src / pmview / stackobj.cpp
blobaf56204f3ea06f9ee897e36f9bdf3154cb921f2c
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/SoScale.h>
17 #include <Inventor/nodes/SoSeparator.h>
18 #include <Inventor/nodes/SoTranslation.h>
19 #include <Inventor/nodes/SoTransform.h>
20 #include "stackobj.h"
21 #include "colorlist.h"
22 #include "defaultobj.h"
24 #include <iostream>
25 using namespace std;
27 StackObj::~StackObj()
29 delete _stack;
32 StackObj::StackObj(StackMod::Height height,
33 ViewObj::Shape shape,
34 bool baseFlag,
35 const DefaultObj &defaults,
36 int x, int y,
37 int cols, int rows,
38 BaseObj::Alignment align)
39 : ModObj(baseFlag, defaults, x, y, cols, rows, align),
40 _width(0),
41 _depth(0),
42 _height(height),
43 _stack(0),
44 _text()
46 _objtype |= STACKOBJ;
47 _shape = shape;
50 void
51 StackObj::finishedAdd()
53 int i;
55 BaseObj::addBase(_root);
57 if (_metrics.numMetrics() == 0) {
58 pmprintf("%s: Error: Stack object has no metrics\n",
59 pmProgname);
60 _length = 0;
62 else {
63 SoScale *blockScale = new SoScale();
64 blockScale->scaleFactor.setValue(_length, _maxHeight, _length);
65 _root->addChild(blockScale);
67 if (_metrics.numMetrics()) {
68 const char *colName = (const char *)_colors.toLatin1();
69 const ColorSpec *colSpec = theColorLists.list(colName);
70 if (colSpec != NULL) {
71 if (colSpec->_scale)
72 pmprintf("%s: Warning: Color scale ignored for stack object.\n",
73 pmProgname);
74 else {
75 #ifdef PCP_DEBUG
76 if (pmDebug & DBG_TRACE_APPL0)
77 cerr << "StackObj::finishedAdd: Adding "
78 << colSpec->_list.length()
79 << " colors for " << _metrics.numMetrics()
80 << " metrics" << endl;
81 #endif
83 for (i = 0; i < colSpec->_list.size(); i++)
84 _metrics.add(*(colSpec->_list)[i]);
87 else
88 pmprintf("%s: Warning: No colours specified for stack object, "
89 "defaulting to blue.\n", pmProgname);
91 _metrics.resolveColors(MetricList::perValue);
93 #ifdef PCP_DEBUG
94 if (pmDebug & DBG_TRACE_APPL0)
95 cerr << "StackObj::finishedAdd: metrics: " << endl
96 << _metrics << endl;
97 #endif
99 _stack = new StackMod(&_metrics, ViewObj::object(_shape), _height);
100 _root->addChild(_stack->root());
102 if (_text.length())
103 _stack->setFillText((const char *)_text.toLatin1());
105 BaseObj::add(_stack);
106 ViewObj::theNumModObjects++;
108 else
109 _length = 0;
112 #ifdef PCP_DEBUG
113 if (pmDebug & DBG_TRACE_APPL0)
114 cerr << name() << "has length " << _length << endl;
115 #endif
117 _width = baseWidth() + _length;
118 _depth = baseDepth() + _length;
121 void
122 StackObj::setTran(float xTran, float zTran, int setWidth, int setDepth)
124 BaseObj::setBaseSize(width(), depth());
125 BaseObj::setTran(xTran + (width() / 2.0),
126 zTran + (depth() / 2.0),
127 setWidth, setDepth);
130 QTextStream&
131 operator<<(QTextStream& os, StackObj const& rhs)
133 rhs.display(os);
134 return os;
137 void
138 StackObj::display(QTextStream& os) const
140 BaseObj::display(os);
141 os << ", length = " << _length << ": ";
142 if (_stack)
143 os << *_stack << endl;
144 else
145 os << "stack undefined!" << endl;