-
Notifications
You must be signed in to change notification settings - Fork 0
/
psout.cpp
215 lines (179 loc) · 5.54 KB
/
psout.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <stdlib.h>
#include "psout.h"
Psout::Psout() {
cellvalues = new int[81];
showcandidates = std::vector<std::string>();
highlightedcandidates = std::vector<std::string>();
highlightedcells = std::vector<std::string>();
highlightedrules = std::vector<std::string>();
outlinedcells = std::vector<std::string>();
}
Psout::~Psout() {
delete [] cellvalues;
}
void Psout::init() {
for(int i=0; i < 81; i++) {
cellvalues[i] = 0;
}
showcandidates.clear();
highlightedcandidates.clear();
highlightedcells.clear();
highlightedrules.clear();
outlinedcells.clear();
}
void Psout::to_file(const char* file) {
std::string filestr = std::string(file);
std::string introstr = std::string("cat t11_intro > ");
introstr.append(filestr);
system(introstr.c_str());
std::ofstream out;
out.open(file, std::ios::app | std::ios::out);
for(int i=0; i < highlightedrules.size(); i++) {
out << highlightedrules[i];
}
for(int i=0; i < highlightedcells.size(); i++) {
out << highlightedcells[i];
}
for(int i=0; i < highlightedcandidates.size(); i++) {
out << highlightedcandidates[i];
}
for(int i=0; i < outlinedcells.size(); i++) {
out << outlinedcells[i];
}
for(int i=0; i < 81; i++) {
Spot p = spot_of_idx(i);
if(cellvalues[i] != 0) {
out << cellvalues[i] << " " << p.row + 1 << " " << p.col + 1 << " fullnumber" << std::endl;
}
}
for(int i=0; i < showcandidates.size(); i++) {
out << showcandidates[i];
}
out << std::endl << "makegrid" << std::endl;
out << std::endl << "showpage" << std::endl;
out.flush();
out.close();
}
void Psout::start_file(const char* file) {
std::string filestr = std::string(file);
std::string introstr = std::string("cat t20_intro > ");
introstr.append(filestr);
system(introstr.c_str());
}
void Psout::append_file(const char* file) {
std::ofstream out;
out.open(file, std::ios::app | std::ios::out);
out << "10 510 translate" << std::endl;
for(int i=0; i < highlightedrules.size(); i++) {
out << highlightedrules[i];
}
for(int i=0; i < highlightedcells.size(); i++) {
out << highlightedcells[i];
}
for(int i=0; i < highlightedcandidates.size(); i++) {
out << highlightedcandidates[i];
}
for(int i=0; i < outlinedcells.size(); i++) {
out << outlinedcells[i];
}
for(int i=0; i < 81; i++) {
Spot p = spot_of_idx(i);
if(cellvalues[i] != 0) {
out << cellvalues[i] << " " << p.row + 1 << " " << p.col + 1 << " fullnumber" << std::endl;
}
}
for(int i=0; i < showcandidates.size(); i++) {
out << showcandidates[i];
}
out << std::endl << "makegrid" << std::endl;
out << std::endl << "showpage" << std::endl;
out.flush();
out.close();
}
void Psout::append_file_barebones(const char* file) {
std::ofstream out;
out.open(file, std::ios::app | std::ios::out);
for(int i=0; i < highlightedrules.size(); i++) {
out << highlightedrules[i];
}
for(int i=0; i < highlightedcells.size(); i++) {
out << highlightedcells[i];
}
for(int i=0; i < highlightedcandidates.size(); i++) {
out << highlightedcandidates[i];
}
for(int i=0; i < outlinedcells.size(); i++) {
out << outlinedcells[i];
}
for(int i=0; i < 81; i++) {
Spot p = spot_of_idx(i);
if(cellvalues[i] != 0) {
out << cellvalues[i] << " " << p.row + 1 << " " << p.col + 1 << " fullnumber" << std::endl;
}
}
for(int i=0; i < showcandidates.size(); i++) {
out << showcandidates[i];
}
out << std::endl << "makegrid" << std::endl;
out.flush();
out.close();
}
void Psout::set_fullnumber(Spot p, int val) {
cellvalues[idx_of_spot(p)] = val;
}
void Psout::add_candidate(Spot p, int val) {
std::string str;
std::stringstream outter;;
outter << val << " " << p.row + 1 << " " << p.col + 1 << " showcandidate" << std::endl;
str = outter.str();
showcandidates.push_back(str);
}
void Psout::highlight_candidate(Spot p, int val, float r, float g, float b) {
std::string str;
std::stringstream outter;;
outter << val << " " << p.row + 1 << " " << p.col + 1 << " " << r << " "<< g << " " << b << " highlightcandidate" << std::endl;
str = outter.str();
highlightedcandidates.push_back(str);
}
void Psout::highlight_cell(Spot p, float r, float g, float b) {
std::string str;
std::stringstream outter;;
outter << p.row + 1 << " " << p.col + 1 << " " << r << " "<< g << " " << b << " highlightcell" << std::endl;
str = outter.str();
highlightedcells.push_back(str);
}
void Psout::highlight_row(int row, float r, float g, float b) {
std::string str;
std::stringstream outter;;
outter << row + 1 << " " << r << " "<< g << " " << b << " highlightrow" << std::endl;
str = outter.str();
highlightedrules.push_back(str);
}
void Psout::highlight_col(int col, float r, float g, float b) {
std::string str;
std::stringstream outter;;
outter << col + 1 << " " << r << " "<< g << " " << b << " highlightcol" << std::endl;
str = outter.str();
highlightedrules.push_back(str);
}
void Psout::highlight_box(int boxid, float r, float g, float b) {
std::string str;
std::stringstream outter;;
outter << boxid + 1 << " " << r << " "<< g << " " << b << " highlightbox" << std::endl;
str = outter.str();
highlightedrules.push_back(str);
}
void Psout::outline_cell(Spot p, float width, float r, float g, float b) {
std::string str;
std::stringstream outter;;
outter << width << " " << p.row + 1 << " " << p.col + 1 << " " << r << " "<< g << " " << b << " outlinecell" << std::endl;
str = outter.str();
outlinedcells.push_back(str);
}
void Psout::link_candidate(Spot spot_a, int val_a, Spot spot_b, int val_b, float width, float r, float g, float b) {
// NEEDED
}