-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp_init.h
More file actions
111 lines (98 loc) · 4.1 KB
/
Copy pathhelp_init.h
File metadata and controls
111 lines (98 loc) · 4.1 KB
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
#pragma once
#include <QDateTime>
#include <QIODevice>
#include <QTextStream>
#include <QFile>
#include "config.h"
#include "profiler.h"
#include "ObjectDictCatalogue/Builder/xmlbuilder.h"
#include "ObjectMapCatalogue/Builder/xmlparser.h"
#include "ObjectMapCatalogue/contextparameter.h"
#include "ObjectDrawCatalogue/drawing_instructions_controller.h"
#include "LuaPortroyal/LuaRuleMashine.h"
char* getLine(const uint N, char D){
char* line = new char[N];
for (uint i = 0; i < N-1; ++i)
line[i] = D;
line[N-1] = 0;
return line;
}
#ifdef DEBUG_TO_LOG_FILE
FILE* out = fopen(filenames::LOG.toStdString().c_str(), "w");
#else
FILE* out = stderr;
#endif
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
#ifdef DEBUG_OUT_ENABLE
static const char *line1 = getLine(120, '_');
static const char *line2 = getLine(120, '=');
static const char *line3 = getLine(120, ':');
static const char *line4 = getLine(120, '#');
QByteArray localMsg = msg.toLocal8Bit();
const char *file = context.file ? context.file : "";
const char *function = context.function ? context.function : "";
switch (type) {
case QtDebugMsg: // is used for writing custom debug output.";
fprintf(out, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
break;
case QtInfoMsg: // "is used for informational messages.";
//fprintf(stderr, "%s\nInfo: %s\n\n", line1, localMsg.constData());
fprintf(out, "%s\nInfo: %s\n\n", line1, localMsg.constData());
break;
case QtWarningMsg: // "is used to report warnings and recoverable errors in your application.";
fprintf(out, "\n%s\nWarning: %s (%s:%u, %s)\n%s\n", line2, localMsg.constData(), file, context.line, function, line2);
break;
case QtCriticalMsg: // "is used for writing critical error messages and reporting system errors.";
fprintf(out, "\n\n%s\nCritical: %s (%s:%u, %s)\n%s\n\n", line3, localMsg.constData(), file, context.line, function, line3);
break;
case QtFatalMsg: // is used for writing fatal error messages shortly before exiting."
fprintf(out, "\n\n%s\nFatal: %s (%s:%u, %s)\n%s\n\n", line4, localMsg.constData(), file, context.line, function, line4);
fprintf(stderr, "\n\n%s\nFatal: %s (%s:%u, %s)\n%s\n\n", line4, localMsg.constData(), file, context.line, function, line4);
abort();
break;
}
#endif
}
///----------------------------------------------------------------------------
bool isOpen(QTextStream &errorStream, QFile &file, const QIODevice::OpenMode &flags)
{
if (!file.open(flags)){
errorStream << QString(
"Filed to open file %1.\n"
).arg(file.fileName());
return false;
}
return true;
}
bool isExists(QTextStream &errorStream, const QString fileName)
{
if (!QFile::exists(fileName)) {
errorStream << QString(
"File %1 does not exist.\n"
).arg(fileName);
return false;
}
return true;
}
bool isExistsEndOpen(QTextStream &errorStream, QFile &file, const QIODevice::OpenMode &flags)
{
if (!isExists(errorStream, file.fileName())){
return false;
} else if (!isOpen(errorStream, file, flags)){
return false;
}
return true;
}
///----------------------------------------------------------------------------
bool writeDrawInst(QFile & portayalFile, const DrawingInstructionsController& drawCtrl, const FeatureCatalogueController& fcCtrl, const FeatureMapController &fmCtrl)
{
QTextStream out(&portayalFile);
for (const auto& featureID : fmCtrl.getFeaturesIDs()){
std::string featureCode = fmCtrl.getFeatureById(featureID).classAlias();
std::string drawInstr = drawCtrl.drawInstr(stoi(featureID)).drawingInstruction();
out << "Feature : [" << QString::fromStdString(featureID) << "] " << QString::fromStdString(featureCode)
<< "\n " << QString::fromStdString(drawInstr)
<< "\n---------------------------------------\n";
}
}