-
Notifications
You must be signed in to change notification settings - Fork 1
/
Canvas.cpp
146 lines (119 loc) · 3.17 KB
/
Canvas.cpp
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
#include "GraphInfos.h"
#include "Canvas.h"
#include <iostream>
using namespace std;
const char * Canvas::graphTypeDescriptions[] =
{
"2D Graph",
"Shower Angles",
"Hardware Layout",
"1D Histogram",
"Polar Graph"
// ## add the description for the new graph type in the same order as
// in the enum graphTypes
};
Canvas::Canvas()
{
graphInfo = 0;
}
Canvas::~Canvas()
{
delete graphInfo;
}
void Canvas::setGraphType (graphTypes graphType)
{
// no need to change if old and new are the same
if ((graphInfo) && getGraphType() == graphType) return;
if (graphInfo)
{
delete graphInfo;
graphInfo = NULL;
}
type = graphType;
switch (type)
{
case GRAPH_2D:
graphInfo = new infoGraph2D();
break;
case SHOWER_ANGLE:
graphInfo = new infoShowerAngle();
break;
case GRAPH_POLAR:
graphInfo = new infoGraphPolar();
break;
case ANTENNA_POSITION:
graphInfo = new infoGraphPosition();
break;
case HIST_1D:
graphInfo = new infoHist1D();
break;
// ## to add case for new graph type: case ... see above for example
default:
graphInfo = new infoGraph();
}
if (graphInfo)
graphInfo->parentCanvas = this;
}
void Canvas::streamToFile(ofstream & s)
{
// output header in format: [Canvas:_type]
s << "[Canvas:"; s << (int) type; s << "]\n";
s << "Name = " << getName() << "\n";
s << "EventCut = " << getEventCut() << endl;
if (graphInfo)
graphInfo->print(&s);
s << endl;
}
bool Canvas::parseFromFile(ifstream & s)
{
if (!s) return false;
bool isSectionStarted = false;
string line, name, value;
int type;
while (getline(s,line,END_OF_LINE))
{
// stop parsing when encountered '[', since that's the start of the
// next canvas
if (isSectionStarted && s.peek() == '[') return true;
// skip blank and comment line
if (line.size() < 1 || line[0] == CFG_COMMENT_CHAR) continue;
if (line[0] == '[') // then parse header line
{
if (sscanf(line.c_str(),"[Canvas:%i]",&type) > 0)
{
isSectionStarted = true;
setGraphType((graphTypes) type);
}
else
{
cerr << "malformatted header line; parse aborted" << endl;
return false;
}
}
if (isSectionStarted && parseNameValuePair(line,name,value))
{
if (name == "Name") setName(value);
else if (name == "EventCut") setEventCut(value);
else getGraphInfo()->enterValue(name,value);
}
if (s.eof()) return false;
}
return true;
}
bool Canvas::readyToDraw()
{
bool ret;
if (!getGraphInfo())
ret = false;
else
ret = getGraphInfo()->readyToDraw();
return ret;
}
void Canvas::draw(Draw* d)
{
if (graphInfo) graphInfo->draw(d);
}
void Canvas::print()
{
getGraphInfo()->print();
}