forked from samuel-rey/StripMaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflightStrip.cpp
83 lines (76 loc) · 2.83 KB
/
flightStrip.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
#include "pch.h"
#include "flightStrip.h"
#include "constant.h"
#include "settings.h"
#include <algorithm>
#include <exception>
flightStrip::flightStrip(int type, std::vector<std::string> fpContents) { // constructor. sets strip type and fills stripContents with those provided
if (settings.currentStripSet.type[type].templateFile == "") {
std::string message = std::string("Cannot print strip as strip type ").append(typeToString(type)).append(" does not have a template file specified in the settings.");
MessageBox(GetActiveWindow(), message.c_str(), NULL, MB_OK | MB_ICONERROR);
throw std::exception();
}
try {
CImg <unsigned int>newTemplate(settings.dllPath().append("\\templates\\").append(settings.currentStripSet.type[type].templateFile).c_str());
stripTemplate = newTemplate;
}
catch (CImgIOException) {
std::string message = std::string("Failed to load strip template BMP for strip type ").append(typeToString(type)).append(" in ").append(settings.dllPath().append(settings.currentStripSet.type[type].templateFile).c_str()).append("\nThe plugin will now close.");
MessageBox(GetActiveWindow(), message.c_str(), NULL, MB_OK | MB_ICONERROR);
}
std::copy(std::begin(settings.currentStripSet.type[type].fields), std::end(settings.currentStripSet.type[type].fields), std::begin(fields));
for (int i = 0; i < FIELDS_TOTAL; i++) {
fieldContents.push_back(std::string());
fieldContents[i] = fpContents[i];
}
applyTextToFields();
}
void flightStrip::applyTextToFields() { // takes the stripContents and writes them into the stripTemplate with the settings provided by the stripType
for (int i = 0; i < FIELDS_TOTAL; i++) {
const unsigned char black[] = { 0,0,0 };
stripTemplate.draw_text(fields[i].fieldXLocation, fields[i].fieldYLocation, fieldContents[i].c_str(), black, 0, 1, fields[i].fieldHeight);
}
}
void flightStrip::display() { // opens a window with the generated strip and saves it to disk for debug purposes
try {
stripTemplate.save(settings.dllPath().append("strip.bmp").c_str());
}
catch (CImgIOException) {
MessageBox(GetActiveWindow(), std::string("Failed to save strip to ").append(settings.dllPath()).append("\\strip.bmp").c_str(),NULL,MB_OK|MB_ICONERROR);
}
CImgDisplay main_disp(stripTemplate, "Flight Strip",0);
while (!main_disp.is_closed()) {
main_disp.wait();
}
}
std::string typeToString(int type){
switch (type) {
case TYPE_DEPARTURE:
return "Departure";
case TYPE_ENROUTE:
return "Enroute";
case TYPE_ARRIVAL:
return "Arrival";
case TYPE_LOCAL:
return "Local";
default:
return "Unknown";
}
}
int stringToType(std::string typeName) {
if (typeName == "Departure") {
return TYPE_DEPARTURE;
}
else if (typeName == "Enroute") {
return TYPE_ENROUTE;
}
else if (typeName == "Arrival") {
return TYPE_ARRIVAL;
}
else if (typeName == "Local") {
return TYPE_LOCAL;
}
else {
return 0;
}
}