-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.cpp
82 lines (68 loc) · 3.66 KB
/
main.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
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "capturecontroller.hpp"
#include "cvmatsurfacesource.hpp"
#include "cameracalibrator.h"
#include "linedetector.h"
#include "linedetectordatasource.h"
#include "gcodeplayer.h"
#include "rayreceiver.h"
#include "automator.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QQmlApplicationEngine engine;
qmlRegisterType<CVMatSurfaceSource>("io.opencv", 1, 0, "CVMatSurfaceSource");
//qmlRegisterType<CaptureController>("io.opencv", 1, 0, "CaptureController");
CaptureController captureController;
CameraCalibrator cameraCalibrator(&captureController);
QObject::connect(&captureController, &CaptureController::frameReady,
&cameraCalibrator, &CameraCalibrator::onFrameReady);
qmlRegisterUncreatableType<LineDetector>("tech.vhrd.vision", 1, 0, "LineDetector", "Only for enums");
LineDetector lineDetector(&captureController);
QObject::connect(&captureController, &CaptureController::frameReady,
&lineDetector, &LineDetector::onFrameReady);
LineDetectorDataSource lineDetectorDataSource;
QObject::connect(&lineDetector, &LineDetector::integrationComplete,
&lineDetectorDataSource, &LineDetectorDataSource::updateIntegratedPlot);
QObject::connect(&lineDetector, &LineDetector::lineDetected,
&lineDetectorDataSource, &LineDetectorDataSource::drawBeamThickness);
engine.rootContext()->setContextProperty("captureController", &captureController);
engine.rootContext()->setContextProperty("cameraCalibrator", &cameraCalibrator);
engine.rootContext()->setContextProperty("lineDetector", &lineDetector);
engine.rootContext()->setContextProperty("lineDetectorDataSource", &lineDetectorDataSource);
GcodePlayer::registerQmlTypes();
GcodePlayerModel::registerQmlTypes();
GcodePlayer player;
engine.rootContext()->setContextProperty("player", &player);
RayReceiver receiver;
engine.rootContext()->setContextProperty("ray", &receiver);
Automator automator;
engine.rootContext()->setContextProperty("automator", &automator);
QObject::connect(&lineDetector, QOverload<float>::of(&LineDetector::dzChanged),
&automator, &Automator::ondzChanged);
QObject::connect(&lineDetector, &LineDetector::dzValidChanged,
&automator, &Automator::ondzValidChanged);
QObject::connect(&player, QOverload<bool>::of(&GcodePlayer::connectionStateChanged),
&automator, &Automator::onMcConnectionStateChanged);
QObject::connect(&receiver, &RayReceiver::stateChanged,
&automator, &Automator::onMcStateChanged);
QObject::connect(&receiver, &RayReceiver::coordsChanged,
&automator, &Automator::onCoordsChanged);
QObject::connect(&receiver, &RayReceiver::connectionStateChanged,
&automator, &Automator::onRayConnectionStateChanged);
QObject::connect(&automator, &Automator::changePower,
&receiver, &RayReceiver::setLaserPower);
QObject::connect(&automator, &Automator::sendToMC,
&player, &GcodePlayer::send);
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}