forked from trikset/trik-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrikdisplayemu.cpp
More file actions
112 lines (91 loc) · 3.6 KB
/
trikdisplayemu.cpp
File metadata and controls
112 lines (91 loc) · 3.6 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
112
/* Copyright 2016-2017 CyberTech Labs Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. */
#include <stdexcept>
#include <QMetaObject>
#include <trikKitInterpreterCommon/trikEmulation/trikdisplayemu.h>
#include <kitBase/robotModel/robotModelUtils.h>
///todo:
#include <trikKitInterpreterCommon/robotModel/twoD/parts/twoDDisplay.h>
using namespace trik;
using robotModel::twoD::parts::Display;
TrikDisplayEmu::TrikDisplayEmu(const QSharedPointer<robotModel::twoD::TrikTwoDRobotModel> &model)
: mTwoDRobotModel(model), mDisplay(nullptr)
{
}
Qt::ConnectionType TrikDisplayEmu::callType() const {
return Qt::AutoConnection;
// Very strange, but forced blocking connection causes SIGSEGV crash....
// return thread() != mDisplay->thread()? Qt::BlockingQueuedConnection : Qt::DirectConnection;
}
void TrikDisplayEmu::init()
{
mDisplay = kitBase::robotModel::RobotModelUtils::findDevice<Display>(*mTwoDRobotModel, "DisplayPort");
}
void TrikDisplayEmu::showImage(const QString &fileName)
{
const bool smile = fileName.endsWith(QLatin1String("sad.png"));
QMetaObject::invokeMethod(mDisplay, [=](){ mDisplay->drawSmile(smile); }, callType());
}
void TrikDisplayEmu::show(const QVector<int32_t> &array, int width, int height, const QString &format)
{
QMetaObject::invokeMethod(mDisplay, [=](){ mDisplay->show(array, width, height, format); }, callType());
}
void TrikDisplayEmu::addLabel(const QString &text, int x, int y, int fontSize)
{
QMetaObject::invokeMethod(mDisplay, [=](){ mDisplay->printText(x, y, text, fontSize); }, callType());
}
void TrikDisplayEmu::setPainterColor(const QString &color)
{
QMetaObject::invokeMethod(mDisplay, [=](){ mDisplay->setPainterColor(color); }, callType());
}
void TrikDisplayEmu::setPainterWidth(int penWidth)
{
QMetaObject::invokeMethod(mDisplay,[=](){ mDisplay->setPainterWidth(penWidth); }, callType());
}
void TrikDisplayEmu::drawLine(int x1, int y1, int x2, int y2)
{
QMetaObject::invokeMethod(mDisplay, [=](){ mDisplay->drawLine(x1, y1, x2, y2); }, callType());
}
void TrikDisplayEmu::drawPoint(int x, int y)
{
QMetaObject::invokeMethod(mDisplay, [=]() { mDisplay->drawPixel(x, y); }, callType());
}
void TrikDisplayEmu::drawRect(int x, int y, int w, int h, bool filled)
{
QMetaObject::invokeMethod(mDisplay, [=](){ mDisplay->drawRect(x, y, w, h, filled); }, callType());
}
void TrikDisplayEmu::drawEllipse(int x, int y, int w, int h, bool filled)
{
QMetaObject::invokeMethod(mDisplay, [=](){ mDisplay->drawEllipse(x, y, w, h, filled); }, callType());
}
void TrikDisplayEmu::drawArc(int x, int y, int w, int h, int start, int span)
{
QMetaObject::invokeMethod(mDisplay, [=]() { mDisplay->drawArc(x, y, w, h, start, span); }, callType());
}
void TrikDisplayEmu::setBackground(const QString &color)
{
QMetaObject::invokeMethod(mDisplay, [=](){ mDisplay->setBackground(color); }, callType());
}
void TrikDisplayEmu::clear()
{
QMetaObject::invokeMethod(mDisplay, &Display::clearScreen, callType());
}
void TrikDisplayEmu::reset()
{
QMetaObject::invokeMethod(mDisplay, &Display::reset, callType());
}
void TrikDisplayEmu::redraw()
{
QMetaObject::invokeMethod(mDisplay, &Display::redraw, callType());
}