-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcellfieldpicture.cpp
97 lines (74 loc) · 2.38 KB
/
cellfieldpicture.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
#include "cellfieldpicture.hpp"
#include "svgprinter.hpp"
#include <fstream>
using namespace std;
void initializeModule_cellfieldpicture() {
}
CellFieldPicture::CellFieldPicture(int width, int height) {
mWidth = width;
mHeight = height;
mLabel = new string*[mHeight];
mStroke = new string*[mHeight];
mFill = new string*[mHeight];
for(int i = 0; i < mHeight; i++) {
mLabel[i] = new string[mWidth];
mStroke[i] = new string[mWidth];
mFill[i] = new string[mWidth];
for(int j = 0; j < mWidth; j++) {
mStroke[i][j] = "black";
mFill[i][j] = "white";
mLabel[i][j]="";
}
}
mBoxX1 = NO_BOX;
mBoxY1 = NO_BOX;
mBoxX2 = NO_BOX;
mBoxY2 = NO_BOX;
// Calculate radius and spacing based on width and height
mSpacing = 640 / max(height, width);
mRadius = mSpacing / 2 - mSpacing / 10;
}
void CellFieldPicture::saveToFile(string filename) {
ofstream file(filename.c_str());
SVGPrinter svg(file);
svg.printHeader();
// place a box behind cells if specified
if(mBoxX1 != NO_BOX) {
int x = (mBoxX1) * mSpacing + mSpacing/2;
int y = (mHeight - mBoxY2) * mSpacing - mSpacing/2;
int w = (mBoxX2 - mBoxX1 + 1) * mSpacing;
int h = (mBoxY2 - mBoxY1 + 1) * mSpacing;
svg.printRectangle(x, y, w, h, "darkgrey", "lightgrey");
}
// output the field of cells
for(int i = 0; i < mHeight; i++) {
for(int j = 0; j < mWidth; j++) {
int x = (j+1) * mSpacing;
int y = (mHeight - i) * mSpacing;
svg.printCircle(x, y, mRadius, mStroke[j][i], mFill[j][i]);
svg.printCenteredText(x, y, mLabel[j][i], "16");
}
}
svg.printFooter();
}
void CellFieldPicture::setLabel(int x, int y, string label) {
mLabel[x][y] = label;
}
void CellFieldPicture::setStroke(int x, int y, string stroke) {
mStroke[x][y] = stroke;
}
void CellFieldPicture::setFill(int x, int y, string fill) {
mFill[x][y] = fill;
}
void CellFieldPicture::setBox(int x1, int y1, int x2, int y2) {
mBoxX1 = x1; mBoxY1 = y1; mBoxX2 = x2; mBoxY2 = y2;
}
string CellFieldPicture::getLabel(int x, int y) {
return(mLabel[x][y]);
}
string CellFieldPicture::getStroke(int x, int y) {
return(mStroke[x][y]);
}
string CellFieldPicture::getFill(int x, int y) {
return(mFill[x][y]);
}