7 #include "TrackingTable.h"
13 #include "IException.h"
15 #include "SpecialPixel.h"
17 #include "TableField.h"
18 #include "TableRecord.h"
27 TrackingTable::TrackingTable() {
38 TrackingTable::TrackingTable(
Table table) {
40 for (
int i=0; i < table.
Records(); i++) {
42 QString nameField = QString(record[
"FileName"]).split(
"/").last();
43 QString extension(
FileName(nameField).extension());
44 int found = nameField.lastIndexOf(extension);
47 nameField.remove(found + 3);
50 QString serialNumber = QString(record[
"SerialNumber"]);
59 TrackingTable::~TrackingTable() {
69 Table TrackingTable::toTable() {
75 for (
int i=0; i < m_fileList.size(); i++) {
76 if (m_fileList[i].first.name().length() > fieldLength) {
77 fieldLength = m_fileList[i].first.name().length();
79 if (m_fileList[i].second.length() > fieldLength) {
80 fieldLength = m_fileList[i].second.length();
86 TableField fileNameField(
"FileName", TableField::Text, fieldLength);
87 TableField serialNumberField(
"SerialNumber", TableField::Text, fieldLength);
88 TableField indexField(
"PixelValue", TableField::Integer);
89 dummyRecord += fileNameField;
90 dummyRecord += serialNumberField;
91 dummyRecord += indexField;
92 Table table(trackingTableName, dummyRecord);
95 for (
int i=0; i < m_fileList.size(); i++) {
97 fileNameField = m_fileList[i].first.
name();
98 serialNumberField = m_fileList[i].second;
99 indexField = (int) (i + VALID_MINUI4);
102 record += fileNameField;
103 record += serialNumberField;
104 record += indexField;
120 FileName TrackingTable::pixelToFileName(
unsigned int pixel) {
121 if (pixel < VALID_MINUI4) {
122 QString msg =
"Cannot convert pixel [" +
toString(pixel)
123 +
"] to a filename, pixel is below valid minimum ["
125 throw IException(IException::Programmer, msg, _FILEINFO_);
128 unsigned int index = pixel - VALID_MINUI4;
129 if (index >= (
unsigned int)m_fileList.size()) {
130 QString msg =
"Cannot convert pixel [" +
toString(pixel)
131 +
"] to a filename, pixel is above valid maximum ["
132 +
toString(VALID_MINUI4 + m_fileList.size()) +
"].";
133 throw IException(IException::Programmer, msg, _FILEINFO_);
136 return m_fileList[index].first;
150 unsigned int TrackingTable::fileNameToPixel(
FileName file, QString serialNumber) {
151 for (
int i = 0; i < m_fileList.size(); i++) {
152 if (QString::compare(m_fileList[i].first.toString(), file.
name()) == 0) {
153 return i + VALID_MINUI4;
160 return m_fileList.size() - 1 + VALID_MINUI4;
170 QString TrackingTable::pixelToSN(
unsigned int pixel) {
171 if (pixel < VALID_MINUI4) {
172 QString msg =
"Cannot convert pixel [" +
toString(pixel)
173 +
"] to a serial number, pixel is below valid minimum ["
175 throw IException(IException::Programmer, msg, _FILEINFO_);
178 unsigned int index = pixel - VALID_MINUI4;
179 if (index >= (
unsigned int)m_fileList.size()) {
180 QString msg =
"Cannot convert pixel [" +
toString(pixel)
181 +
"] to a serial number, pixel is above valid maximum ["
182 +
toString(VALID_MINUI4 + m_fileList.size()) +
"].";
183 throw IException(IException::Programmer, msg, _FILEINFO_);
186 return m_fileList[index].second;
200 int TrackingTable::fileNameToIndex(
FileName file, QString serialNumber) {
201 for (
int i = 0; i < m_fileList.size(); i++) {
202 if (m_fileList[i].first == file) {
210 return m_fileList.size() - 1;