summaryrefslogtreecommitdiff
path: root/src/pmview/stackobj.cpp
blob: faa8d42a7cef01ace0451d92e9f16c489194b6b5 (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
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * 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/SoBaseColor.h>
#include <Inventor/nodes/SoScale.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoTranslation.h>
#include <Inventor/nodes/SoTransform.h>
#include "stackobj.h"
#include "colorlist.h"
#include "defaultobj.h"

#include <iostream>
using namespace std;

StackObj::~StackObj()
{
    delete _stack;
}

StackObj::StackObj(StackMod::Height height, 
		   ViewObj::Shape shape,
		   bool baseFlag,
		   const DefaultObj &defaults,
		   int x, int y, 
		   int cols, int rows, 
		   BaseObj::Alignment align)
: ModObj(baseFlag, defaults, x, y, cols, rows, align),
  _width(0),
  _depth(0),
  _height(height),
  _stack(0),
  _text()
{
    _objtype |= STACKOBJ;
    _shape = shape;
}

void
StackObj::finishedAdd()
{
    int		i;
    
    BaseObj::addBase(_root);

    if (_metrics.numMetrics() == 0) {
	pmprintf("%s: Error: Stack object has no metrics\n",
		 pmProgname);
	_length = 0;
    }
    else {
	SoScale *blockScale = new SoScale();
	blockScale->scaleFactor.setValue(_length, _maxHeight, _length);
	_root->addChild(blockScale);

	if (_metrics.numMetrics()) {
	    const char *colName = (const char *)_colors.toAscii();
	    const ColorSpec *colSpec = theColorLists.list(colName);
	    if (colSpec != NULL) {
		if (colSpec->_scale)
		    pmprintf("%s: Warning: Color scale ignored for stack object.\n",
			     pmProgname);
		else {
#ifdef PCP_DEBUG
		    if (pmDebug & DBG_TRACE_APPL0)
			cerr << "StackObj::finishedAdd: Adding " 
			     << colSpec->_list.length()
			     << " colors for " << _metrics.numMetrics() 
			     << " metrics" << endl;
#endif

		    for (i = 0; i < colSpec->_list.size(); i++)
			_metrics.add(*(colSpec->_list)[i]);
		}
	    }
	    else
		pmprintf("%s: Warning: No colours specified for stack object, "
			 "defaulting to blue.\n", pmProgname);

	    _metrics.resolveColors(MetricList::perValue);

#ifdef PCP_DEBUG
	    if (pmDebug & DBG_TRACE_APPL0)
		cerr << "StackObj::finishedAdd: metrics: " << endl 
		     << _metrics << endl;
#endif

	    _stack = new StackMod(&_metrics, ViewObj::object(_shape), _height);
	    _root->addChild(_stack->root());

	    if (_text.length())
		_stack->setFillText((const char *)_text.toAscii());

	    BaseObj::add(_stack);
	    ViewObj::theNumModObjects++;
	}
	else
	    _length = 0;
    }

#ifdef PCP_DEBUG
    if (pmDebug & DBG_TRACE_APPL0)
	cerr << name() << "has length " << _length << endl;
#endif

    _width = baseWidth() + _length;
    _depth = baseDepth() + _length;
}

void
StackObj::setTran(float xTran, float zTran, int setWidth, int setDepth)
{
    BaseObj::setBaseSize(width(), depth());
    BaseObj::setTran(xTran + (width() / 2.0),
		     zTran + (depth() / 2.0),
		     setWidth, setDepth);
}

QTextStream&
operator<<(QTextStream& os, StackObj const& rhs)
{
    rhs.display(os);
    return os;
}

void
StackObj::display(QTextStream& os) const
{
    BaseObj::display(os);
    os << ", length = " << _length << ": ";
    if (_stack)
	os << *_stack << endl;
    else
	os << "stack undefined!" << endl;
}