-
Notifications
You must be signed in to change notification settings - Fork 7
/
output.cpp
executable file
·210 lines (171 loc) · 4.94 KB
/
output.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
//--begin_license--
//
//Copyright 2013 Søren Vissing Jørgensen.
// 2014 Søren Vissing Jørgensen, Center for Bio-Robotics, SDU, MMMI.
//
//This file is part of RANA.
//
//RANA is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//RANA is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with RANA. If not, see <http://www.gnu.org/licenses/>.
//
//--end_license--
#include <cstring>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <thread>
#include <chrono>
#include "api/phys.h"
#include "output.h"
Output* Output::output;
MainWindow* Output::mainWindow;
std::mutex Output::autonMutex;
std::atomic<int> Output::DelayValue;
std::atomic<bool> Output::RunSimulation;
std::atomic<bool> Output::KillSimulation;
std::atomic<bool> Output::RunEventProcessing;
std::atomic<bool> Output::SimRunning;
std::atomic<bool> Output::LegacyMode;
unsigned long long Output::RUNTIME = 0;
std::string Output::AgentPath = "";
std::string Output::AgentFile = "";
std::string Output::RanaDir = "";
Output* Output::Inst()
{
if(!output)
output = new Output();
return output;
}
Output::Output()
{
}
/**
* @brief Ranas version of printf, prints a message to current active output
* For example kprintf("sum of %i + %i = %i", 5, 5, 10) will output "sum of
* 5 + 5 = 10", the string can be html formatted!
* @param msg formated string that is to written to output
* @see MainWindow::write_regularOutput()
*/
void Output::kprintf(const char* msg, ...)
{
//lock.lock();
va_list args;
va_start(args, msg);
char buffer[4096] = {};
vsprintf(buffer, msg, args);
QString string(buffer);
qDebug() << buffer;
mainWindow->write_regularOutput(string);
va_end(args);
//lock.unlock();
}
/**
* @brief Same as Output::kprintf but it's output can be disabled via the menu
* @see Output::kprintf()
* @see MainWindow::write_output()
*/
void Output::kdebug(const char* msg, ...)
{
//lock.lock();
va_list args;
va_start(args, msg);
char buffer[4096] = {};
vsprintf(buffer, msg, args);
QString string(buffer);
qDebug() << buffer;
mainWindow->write_output(string);
va_end(args);
//lock.unlock();
}
/**
* @brief Updates the simulation status screen, with relevant values.
* Only used during simulation.
* @param ms current microstep
* @param eventInit number of events initiated
* @param internalEvents total number of internal events
* @param externalEvents total number of external events
* @see MainWindow::on_udateStatus()
*/
void Output::updateStatus(unsigned long long internalEvents, unsigned long long externalEvents)
{
mainWindow->write_status(internalEvents, externalEvents);
}
/**
* @brief Updates the simulation windows progress bar
* @param current Current progress value, e.g current microstep
* @param maximum Final microstep
* @see MainWindow::advanceProgess()
*/
void Output::progressBar(unsigned long long current, unsigned long long maximum)
{
int progress = (current * 100)/maximum;
mainWindow->advanceProgess(progress);
}
/**
* @brief Updates the event postprocessing progress bar
* @param current Current progress value
* @param maximum Maximun progress value
* @see MainWindow::advancePPProgess()
*/
void Output::ppprogressbar(int current, int maximum)
{
int progress = (current * 100)/maximum;
mainWindow->advancePPProgess(progress);
}
void Output::setEventSceneRect(int x, int y)
{
mainWindow->setEventSceneRect(x, y);
}
void Output::setMainWindow(MainWindow *mainwindow)
{
Output::mainWindow = mainwindow;
}
/**
* @brief Deprecated use Output::kprintf()
* @param msg
*/
void Output::ppprintf(const char *msg,...)
{
va_list args;
va_start(args, msg);
char buffer[2048] = {};
vsnprintf(buffer, 2047, msg, args);
QString string(buffer);
mainWindow->write_PPOutput(string);
va_end(args);
}
/**
* @brief Writes a string to the zvalue label, in event postprocessing.
* @param string
*/
void Output::updateZvalue(QString string)
{
Output::mainWindow->writeZValue(string);
}
void Output::removeGraphicAgent(int Id)
{
mainWindow->removeGraphicAgent(Id);
}
void Output::addGraphicAgent(int Id, double posX, double posY, rgba color, double angle)
{
std::lock_guard<std::mutex> guard(autonMutex);
mainWindow->addGraphicAgent(Id, int(posX)/Phys::getScale(), int(posY)/Phys::getScale(), color, angle);
}
//void Output::changeGraphicAgentColor(int id, int r, int g, int b, int alpha)
//{
// mainWindow->changeGraphicAgentColor(id, r, g, b, alpha);
//}
void Output::enableRunBotton(bool enabled)
{
mainWindow->enableRunButton(enabled);
}