-
Notifications
You must be signed in to change notification settings - Fork 22
/
formgps_ui.cpp
750 lines (632 loc) · 28.3 KB
/
formgps_ui.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
#include <QQuickView>
#include <QQuickWidget>
#include <QQmlContext>
#include <QScreen>
#include "formgps.h"
#include "qmlutil.h"
#include <QTimer>
#include "cvehicle.h"
#include "ccontour.h"
#include "cabline.h"
#include "aogproperty.h"
#include <QGuiApplication>
#include <QQmlEngine>
#include <functional>
#include <assert.h>
#include "aogrenderer.h"
#include "qmlsettings.h"
#include "qmlsectionbuttons.h"
#include "interfaceproperty.h"
#include "cboundarylist.h"
#include <cmath>
#include <cstring>
QString caseInsensitiveFilename(QString directory, QString filename);
extern QMLSettings qml_settings;
void FormGPS::setupGui()
{
/* Load the QML UI and display it in the main area of the GUI */
setProperty("title","QtAgOpenGPS");
//Load the QML into a view
rootContext()->setContextProperty("screenPixelDensity",QGuiApplication::primaryScreen()->physicalDotsPerInch() * QGuiApplication::primaryScreen()->devicePixelRatio());
rootContext()->setContextProperty("mainForm", this);
rootContext()->setContextProperty("settings", &qml_settings);
#ifdef LOCAL_QML
// Look for QML files relative to our current directory
QStringList search_pathes = { "..",
"../qtaog",
"../QtAgOpenGPS",
"."
};
qWarning() << "Looking for QML.";
for(QString search_path : search_pathes) {
//look relative to current working directory
QDir d = QDir(QDir::currentPath() + "/" + search_path + "/qml/");
if (d.exists("AOGInterface.qml")) {
QDir::addSearchPath("local",QDir::currentPath() + "/" + search_path);
qWarning() << "QML path is " << search_path;
break;
}
//look relative to the executable's directory
d = QDir(QCoreApplication::applicationDirPath() + "/" + search_path + "/qml/");
if (d.exists("AOGInterface.qml")) {
QDir::addSearchPath("local",QCoreApplication::applicationDirPath() + "/" + search_path);
qWarning() << "QML path is " << search_path;
break;
}
}
QObject::connect(this, &QQmlApplicationEngine::warnings, [=] (const QList<QQmlError> &warnings) {
foreach (const QQmlError &error, warnings) {
qWarning() << "warning: " << error.toString();
}
});
rootContext()->setContextProperty("prefix","local:");
load("local:/qml/MainWindow.qml");
#else
rootContext()->setContextProperty("prefix",":");
load(QUrl("qrc:/qml/MainWindow.qml"));
#endif
//get pointer to root QML object, which is the OpenGLControl,
//store in a member variable for future use.
QList<QObject*> root_context = rootObjects();
if (root_context.length() == 0) {
qWarning() << "MainWindow.qml did not load. Aborting.";
assert(root_context.length() > 0);
}
qml_root = root_context.first();
qml_root->setProperty("visible",true);
//have to do this for each Interface and supported data type.
InterfaceProperty<AOGInterface, int>::set_qml_root(qmlItem(qml_root, "aog"));
InterfaceProperty<AOGInterface, uint>::set_qml_root(qmlItem(qml_root, "aog"));
InterfaceProperty<AOGInterface, bool>::set_qml_root(qmlItem(qml_root, "aog"));
InterfaceProperty<AOGInterface, double>::set_qml_root(qmlItem(qml_root, "aog"));
InterfaceProperty<AOGInterface, btnStates>::set_qml_root(qmlItem(qml_root, "aog"));
InterfaceProperty<LinesInterface, int>::set_qml_root(qmlItem(qml_root, "linesInterface"));
InterfaceProperty<LinesInterface, uint>::set_qml_root(qmlItem(qml_root, "linesInterface"));
InterfaceProperty<LinesInterface, bool>::set_qml_root(qmlItem(qml_root, "linesInterface"));
InterfaceProperty<LinesInterface, double>::set_qml_root(qmlItem(qml_root, "linesInterface"));
InterfaceProperty<LinesInterface, btnStates>::set_qml_root(qmlItem(qml_root, "linesInterface"));
InterfaceProperty<FieldInterface, int>::set_qml_root(qmlItem(qml_root, "fieldInterface"));
InterfaceProperty<FieldInterface, uint>::set_qml_root(qmlItem(qml_root, "fieldInterface"));
InterfaceProperty<FieldInterface, bool>::set_qml_root(qmlItem(qml_root, "fieldInterface"));
InterfaceProperty<FieldInterface, double>::set_qml_root(qmlItem(qml_root, "fieldInterface"));
InterfaceProperty<FieldInterface, btnStates>::set_qml_root(qmlItem(qml_root, "fieldInterface"));
InterfaceProperty<VehicleInterface, int>::set_qml_root(qmlItem(qml_root, "vehicleInterface"));
InterfaceProperty<VehicleInterface, uint>::set_qml_root(qmlItem(qml_root, "vehicleInterface"));
InterfaceProperty<VehicleInterface, bool>::set_qml_root(qmlItem(qml_root, "vehicleInterface"));
InterfaceProperty<VehicleInterface, double>::set_qml_root(qmlItem(qml_root, "vehicleInterface"));
InterfaceProperty<VehicleInterface, btnStates>::set_qml_root(qmlItem(qml_root, "vehicleInterface"));
InterfaceProperty<BoundaryInterface, int>::set_qml_root(qmlItem(qml_root, "boundaryInterface"));
InterfaceProperty<BoundaryInterface, uint>::set_qml_root(qmlItem(qml_root, "boundaryInterface"));
InterfaceProperty<BoundaryInterface, bool>::set_qml_root(qmlItem(qml_root, "boundaryInterface"));
InterfaceProperty<BoundaryInterface, double>::set_qml_root(qmlItem(qml_root, "boundaryInterface"));
InterfaceProperty<BoundaryInterface, btnStates>::set_qml_root(qmlItem(qml_root, "boundaryInterface"));
InterfaceProperty<RecordedPathInterface, int>::set_qml_root(qmlItem(qml_root, "recordedPathInterface"));
InterfaceProperty<RecordedPathInterface, uint>::set_qml_root(qmlItem(qml_root, "recordedPathInterface"));
InterfaceProperty<RecordedPathInterface, bool>::set_qml_root(qmlItem(qml_root, "recordedPathInterface"));
InterfaceProperty<RecordedPathInterface, double>::set_qml_root(qmlItem(qml_root, "recordedPathInterface"));
InterfaceProperty<RecordedPathInterface, btnStates>::set_qml_root(qmlItem(qml_root, "recordedPathInterface"));
QMLSectionButtons::set_aog_root(qmlItem(qml_root, "aog"));
//hook up our AOGInterface properties
QObject *aog = qmlItem(qml_root, "aog");
QObject *linesInterface = qmlItem(qml_root, "linesInterface");
QObject *vehicleInterface = qmlItem(qml_root, "vehicleInterface");
QObject *fieldInterface = qmlItem(qml_root, "fieldInterface");
QObject *boundaryInterface = qmlItem(qml_root, "boundaryInterface");
//react to UI changing this property
connect(aog,SIGNAL(sectionButtonStateChanged()), &tool.sectionButtonState, SLOT(onStatesUpdated()));
openGLControl = qml_root->findChild<AOGRendererInSG *>("openglcontrol");
//This is a bit hackish, but all rendering is done in this item, so
//we have to give it a way of calling our initialize and draw functions
openGLControl->setProperty("callbackObject",QVariant::fromValue((void *) this));
openGLControl->setProperty("initCallback",QVariant::fromValue<std::function<void (void)>>(std::bind(&FormGPS::openGLControl_Initialized, this)));
openGLControl->setProperty("paintCallback",QVariant::fromValue<std::function<void (void)>>(std::bind(&FormGPS::oglMain_Paint,this)));
openGLControl->setProperty("samples",settings->value("display/antiAliasSamples", 0));
openGLControl->setMirrorVertically(true);
connect(openGLControl,SIGNAL(clicked(QVariant)),this,SLOT(onGLControl_clicked(QVariant)));
connect(openGLControl,SIGNAL(dragged(int,int,int,int)),this,SLOT(onGLControl_dragged(int,int,int,int)));
//TODO: save and restore these numbers from settings
// qml_root->setProperty("width",1024);
// qml_root->setProperty("height",768);
//AB Line Picker
//react to UI changing these properties
connect(aog,SIGNAL(currentABLineChanged()), this, SLOT(update_current_ABline_from_qml()));
connect(aog,SIGNAL(currentABCurveChanged()), this, SLOT(update_current_ABline_from_qml()));
//linesInterface signals
connect(linesInterface,SIGNAL(abLine_updateLines()),this,SLOT(update_ABlines_in_qml()));
connect(linesInterface,SIGNAL(abLine_addLine(QString, double, double, double)), this, SLOT(add_new_ABline(QString,double,double,double)));
connect(linesInterface,SIGNAL(abLine_setA(bool,double,double,double)), this, SLOT(start_newABLine(bool,double,double,double)));
connect(linesInterface,SIGNAL(abLine_deleteLine(int)), this, SLOT( delete_ABLine(int)));
connect(linesInterface,SIGNAL(abLine_swapHeading(int)), this, SLOT(swap_heading_ABLine(int)));
connect(linesInterface,SIGNAL(abLine_changeName(int, QString)), this, SLOT(change_name_ABLine(int,QString)));
//on screen buttons
connect(aog,SIGNAL(zoomIn()), this, SLOT(onBtnZoomIn_clicked()));
connect(aog,SIGNAL(zoomOut()), this, SLOT(onBtnZoomOut_clicked()));
connect(aog,SIGNAL(tiltDown()), this, SLOT(onBtnTiltDown_clicked()));
connect(aog,SIGNAL(tiltUp()), this, SLOT(onBtnTiltUp_clicked()));
connect(aog,SIGNAL(btn2D()), this, SLOT(onBtn2D_clicked()));
connect(aog,SIGNAL(btn3D()), this, SLOT(onBtn3D_clicked()));
connect(aog,SIGNAL(n2D()), this, SLOT(onBtnN2D_clicked()));
connect(aog,SIGNAL(n3D()), this, SLOT(onBtnN3D_clicked()));
connect(aog, SIGNAL(isHydLiftOn()), this, SLOT(onBtnHydLift_clicked()));
connect(aog, SIGNAL(btnResetTool()), this, SLOT(onBtnResetTool_clicked()));
connect(aog, SIGNAL(btnHeadland()), this, SLOT(onBtnHeadland_clicked()));
connect(aog, SIGNAL(btnResetSim()), this, SLOT(onBtnResetSim_clicked()));
connect(aog, SIGNAL(reset_direction()), this, SLOT(onBtnResetDirection_clicked()));
connect(aog, SIGNAL(centerOgl()), this, SLOT(onBtnCenterOgl_clicked()));
//manual youturn buttons
connect(aog,SIGNAL(uturn(bool)), this, SLOT(onBtnManUTurn_clicked(bool)));
connect(aog,SIGNAL(lateral(bool)), this, SLOT(onBtnLateral_clicked(bool)));
connect(aog,SIGNAL(autoYouTurn()), this, SLOT(onBtnAutoYouTurn_clicked()));
connect(aog,SIGNAL(swapAutoYouTurnDirection()), this, SLOT(onBtnSwapAutoYouTurnDirection_clicked()));
connect(qml_root, SIGNAL(save_everything()), this, SLOT(fileSaveEverythingBeforeClosingField()));
//connect(qml_root,SIGNAL(closing(QQuickCloseEvent *)), this, SLOT(fileSaveEverythingBeforeClosingField(QQuickCloseEvent *)));
//connect settings dialog box
connect(aog,SIGNAL(settings_reload()), this, SLOT(on_settings_reload()));
connect(aog,SIGNAL(settings_save()), this, SLOT(on_settings_save()));
//vehicle saving and loading
connect(vehicleInterface,SIGNAL(vehicle_update_list()), this, SLOT(vehicle_update_list()));
connect(vehicleInterface,SIGNAL(vehicle_load(QString)), this, SLOT(vehicle_load(QString)));
connect(vehicleInterface,SIGNAL(vehicle_delete(QString)), this, SLOT(vehicle_delete(QString)));
connect(vehicleInterface,SIGNAL(vehicle_saveas(QString)), this, SLOT(vehicle_saveas(QString)));
//field saving and loading
connect(fieldInterface,SIGNAL(field_update_list()), this, SLOT(field_update_list()));
connect(fieldInterface,SIGNAL(field_close()), this, SLOT(field_close()));
connect(fieldInterface,SIGNAL(field_open(QString)), this, SLOT(field_open(QString)));
connect(fieldInterface,SIGNAL(field_new(QString)), this, SLOT(field_new(QString)));
connect(fieldInterface,SIGNAL(field_new_from(QString,QString,int)), this, SLOT(field_new_from(QString,QString,int)));
connect(fieldInterface,SIGNAL(field_delete(QString)), this, SLOT(field_delete(QString)));
//React to UI changing imuHeading, in order to reset the IMU heading
connect(aog, SIGNAL(changeImuHeading(double)), &ahrs, SLOT(changeImuHeading(double)));
connect(aog, SIGNAL(changeImuRoll(double)), &ahrs, SLOT(changeImuRoll(double)));
//React to UI setting hyd life settings
connect(aog, SIGNAL(modules_send_238()), this, SLOT(modules_send_238()));
connect(aog, SIGNAL(modules_send_251()), this, SLOT(modules_send_251()));
connect(aog, SIGNAL(sim_bump_speed(bool)), &sim, SLOT(speed_bump(bool)));
connect(aog, SIGNAL(sim_zero_speed()), &sim, SLOT(speed_zero()));
connect(aog, SIGNAL(sim_reset()), &sim, SLOT(reset()));
//boundary signals and slots
connect(&yt, SIGNAL(outOfBounds()),boundaryInterface,SLOT(setIsOutOfBoundsTrue()));
connect(boundaryInterface, SIGNAL(calculate_area()), this, SLOT(boundary_calculate_area()));
connect(boundaryInterface, SIGNAL(update_list()), this, SLOT(boundary_update_list()));
connect(boundaryInterface, SIGNAL(start()), this, SLOT(boundary_start()));
connect(boundaryInterface, SIGNAL(stop()), this, SLOT(boundary_stop()));
connect(boundaryInterface, SIGNAL(add_point()), this, SLOT(boundary_add_point()));
connect(boundaryInterface, SIGNAL(delete_last_point()), this, SLOT(boundary_delete_last_point()));
connect(boundaryInterface, SIGNAL(pause()), this, SLOT(boundary_pause()));
connect(boundaryInterface, SIGNAL(record()), this, SLOT(boundary_record()));
connect(boundaryInterface, SIGNAL(reset()), this, SLOT(boundary_restart()));
connect(boundaryInterface, SIGNAL(delete_boundary(int)), this, SLOT(boundary_delete(int)));
connect(boundaryInterface, SIGNAL(set_drive_through(int, bool)), this, SLOT(boundary_set_drivethru(int,bool)));
connect(boundaryInterface, SIGNAL(delete_all()), this, SLOT(boundary_delete_all()));
headland_form.bnd = &bnd;
headland_form.vehicle = &vehicle;
headland_form.hdl = &hdl;
headland_form.tool = &tool;
headland_form.connect_ui(qmlItem(qml_root, "headlandDesigner"));
connect(&headland_form, SIGNAL(saveHeadland()),this,SLOT(headland_save()));
connect(&headland_form, SIGNAL(timedMessageBox(int,QString,QString)),this,SLOT(TimedMessageBox(int,QString,QString)));
headache_form.bnd = &bnd;
headache_form.vehicle = &vehicle;
headache_form.hdl = &hdl;
headache_form.tool = &tool;
headache_form.connect_ui(qmlItem(qml_root, "headacheDesigner"));
connect(&headache_form, SIGNAL(saveHeadland()),this,SLOT(headland_save()));
connect(&headache_form, SIGNAL(timedMessageBox(int,QString,QString)),this,SLOT(TimedMessageBox(int,QString,QString)));
connect(&headache_form, SIGNAL(saveHeadlines()), this,SLOT(headlines_save()));
connect(&headache_form, SIGNAL(loadHeadlines()), this,SLOT(headlines_load()));
//connect qml button signals to callbacks (it's not automatic with qml)
/*btnPerimeter = qmlItem(qml_root,"btnPerimeter");
connect(btnPerimeter,SIGNAL(clicked()),this,
SLOT(onBtnPerimeter_clicked()));
*/
btnFlag = qmlItem(qml_root,"btnFlag");
connect(btnFlag,SIGNAL(clicked()),this,
SLOT(onBtnFlag_clicked()));
btnContour = qmlItem(qml_root,"btnContour");
connect(btnContour,SIGNAL(clicked()),this,
SLOT(onBtnContour_clicked()));
btnContourPriority = qmlItem(qml_root,"btnContourPriority");
connect(btnContourPriority,SIGNAL(clicked()),this,
SLOT(onBtnContourPriority_clicked()));
//Any objects we don't need to access later we can just store
//temporarily
QObject *temp;
temp = qmlItem(qml_root,"btnRedFlag");
connect(temp,SIGNAL(clicked()),this,SLOT(onBtnRedFlag_clicked()));
temp = qmlItem(qml_root,"btnGreenFlag");
connect(temp,SIGNAL(clicked()),this,SLOT(onBtnGreenFlag_clicked()));
temp = qmlItem(qml_root,"btnYellowFlag");
connect(temp,SIGNAL(clicked()),this,SLOT(onBtnYellowFlag_clicked()));
btnDeleteFlag = qmlItem(qml_root,"btnDeleteFlag");
connect(btnDeleteFlag,SIGNAL(clicked()),this,SLOT(onBtnDeleteFlag_clicked()));
btnDeleteAllFlags = qmlItem(qml_root,"btnDeleteAllFlags");
connect(btnDeleteAllFlags,SIGNAL(clicked()),this,SLOT(onBtnDeleteAllFlags_clicked()));
contextFlag = qmlItem(qml_root, "contextFlag");
//txtDistanceOffABLine = qmlItem(qml_root,"txtDistanceOffABLine");
tmrWatchdog = new QTimer(this);
connect (tmrWatchdog, SIGNAL(timeout()),this,SLOT(tmrWatchdog_timeout()));
tmrWatchdog->start(250); //fire every 50ms.
//SIM on
connect_classes();
swFrame.start();
stopwatch.start();
vehicle_update_list();
}
void FormGPS::onGLControl_dragged(int pressX, int pressY, int mouseX, int mouseY)
{
QVector3D from,to,offset;
from = mouseClickToPan(pressX, pressY);
to = mouseClickToPan(mouseX, mouseY);
offset = to - from;
camera.panX += offset.x();
camera.panY += offset.y();
openGLControl->update();
}
void FormGPS::onBtnCenterOgl_clicked(){
qDebug()<<"center ogl";
camera.panX = 0;
camera.panY = 0;
openGLControl->update();
}
void FormGPS::onGLControl_clicked(const QVariant &event)
{
QObject *m = event.value<QObject *>();
//Pass the click on to the rendering routine.
//make the bottom left be 0,0
mouseX = m->property("x").toInt();
mouseY = m->property("y").toInt();
QVector3D field = mouseClickToField(mouseX, mouseY);
mouseEasting = field.x();
mouseNorthing = field.y();
leftMouseDownOnOpenGL = true;
openGLControl->update();
}
void FormGPS::onBtnAcres_clicked(){
qDebug()<<"AcresButton";
}
void FormGPS::onBtnSettings_clicked(){
qDebug()<<"Settings";
}
void FormGPS::onBtnAgIO_clicked(){
qDebug()<<"AgIO";
}
void FormGPS::onBtnSteerConfig_clicked(){
qDebug()<<"Steer config`";
}
void FormGPS::onBtnSteerMode_clicked(){
qDebug()<<"Steer mode`";
}
void FormGPS::onBtnToggleAB_clicked(){
qDebug()<<"Toggle AB";
}
void FormGPS::onBtnToggleABBack_clicked(){
qDebug()<<"toggle AB back";
}
void FormGPS::onBtnResetTool_clicked(){
qDebug()<<"REset tool";
vehicle.tankPos.heading = vehicle.fixHeading;
vehicle.tankPos.easting = vehicle.hitchPos.easting + (sin(vehicle.tankPos.heading) * (tool.tankTrailingHitchLength));
vehicle.tankPos.northing = vehicle.hitchPos.northing + (cos(vehicle.tankPos.heading) * (tool.tankTrailingHitchLength));
vehicle.toolPivotPos.heading = vehicle.tankPos.heading;
vehicle.toolPivotPos.easting = vehicle.tankPos.easting + (sin(vehicle.toolPivotPos.heading) * (tool.trailingHitchLength));
vehicle.toolPivotPos.northing = vehicle.tankPos.northing + (cos(vehicle.toolPivotPos.heading) * (tool.trailingHitchLength));
}
void FormGPS::onBtnHeadland_clicked(){
qDebug()<<"Headland";
bnd.isHeadlandOn = !bnd.isHeadlandOn;
if (bnd.isHeadlandOn)
{
//btnHeadlandOnOff.Image = Properties.Resources.HeadlandOn;
}
else
{
//btnHeadlandOnOff.Image = Properties.Resources.HeadlandOff;
}
if (vehicle.isHydLiftOn && !bnd.isHeadlandOn) vehicle.isHydLiftOn = false;
if (!bnd.isHeadlandOn)
{
p_239.pgn[p_239.hydLift] = 0;
//btnHydLift.Image = Properties.Resources.HydraulicLiftOff;
}
}
void FormGPS::onBtnHydLift_clicked(){
if (bnd.isHeadlandOn)
{
vehicle.isHydLiftOn = !vehicle.isHydLiftOn;
if (vehicle.isHydLiftOn)
{
}
else
{
p_239.pgn[p_239.hydLift] = 0;
}
}
else
{
p_239.pgn[p_239.hydLift] = 0;
vehicle.isHydLiftOn = false;
}
}
void FormGPS::onBtnTramlines_clicked(){
qDebug()<<"tramline";
}
void FormGPS::onBtnSectionColor_clicked(){
qDebug()<<"Section color";
}
void FormGPS::onBtnLinePicker_clicked(){
qDebug()<<"Line picker";
}
void FormGPS::onBtnSnapToPivot_clicked(){
qDebug()<<"snap to pivot";
}
void FormGPS::onBtnYouSkip_clicked(){
qDebug()<<"you skip";
}
void FormGPS::onBtnResetDirection_clicked(){
qDebug()<<"reset Direction";
// c#Array.Clear(stepFixPts, 0, stepFixPts.Length);
std::memset(stepFixPts, 0, sizeof(stepFixPts));
isFirstHeadingSet = false;
vehicle.isReverse = false;
TimedMessageBox(2000, "Reset Direction", "Drive Forward > 1.5 kmh");
}
void FormGPS::onBtnFlag_clicked() {
//TODO if this button is disabled until field is started, we won't
//need this check.
if(isGPSPositionInitialized) {
int nextflag = flagPts.size() + 1;
//CFlag flagPt(pn.latitude, pn.longitude, pn.easting, pn.northing, flagColor, nextflag);
//flagPts.append(flagPt);
flagsBufferCurrent = false;
//TODO: FileSaveFlags();
}
}
void FormGPS::onBtnContour_clicked(){
qDebug()<<"contour button clicked." ;
ct.isContourBtnOn = !ct.isContourBtnOn;
if (ct.isContourBtnOn) {
qmlItem(qml_root,"btnContour")->setProperty("isChecked",true);
qmlItem(qml_root,"btnContourPriority")->setProperty("visible",true);
} else {
qmlItem(qml_root,"btnContour")->setProperty("isChecked",false);
qmlItem(qml_root,"btnContourPriority")->setProperty("visible",false);
}
}
void FormGPS::onBtnContourPriority_clicked(){
qDebug()<<"contour priority button clicked." ;
ct.isRightPriority = !ct.isRightPriority;
if (ct.isRightPriority)
qmlItem(qml_root,"btnContourPriority")->setProperty("isChecked",true);
else
qmlItem(qml_root,"btnContourPriority")->setProperty("isChecked",false);
}
void FormGPS::onBtnTiltDown_clicked(){
qDebug()<<"TiltDown button clicked.";
if (camera.camPitch > -59) camera.camPitch = -60;
camera.camPitch += ((camera.camPitch * 0.012) - 1);
if (camera.camPitch < -76) camera.camPitch = -76;
lastHeight = -1; //redraw the sky
property_setDisplay_camPitch = camera.camPitch;
openGLControl->update();
}
void FormGPS::onBtnTiltUp_clicked(){
double camPitch = property_setDisplay_camPitch;
qDebug()<<"TiltUp button clicked.";
lastHeight = -1; //redraw the sky
camera.camPitch -= ((camera.camPitch * 0.012) - 1);
if (camera.camPitch > -58) camera.camPitch = 0;
property_setDisplay_camPitch = camera.camPitch;
openGLControl->update();
}
void FormGPS::onBtn2D_clicked(){
camera.camFollowing = true;
camera.camPitch = 0;
navPanelCounter = 0;
}
void FormGPS::onBtn3D_clicked(){
camera.camFollowing = true;
camera.camPitch = -65;
navPanelCounter = 0;
}
void FormGPS::onBtnN2D_clicked(){
camera.camFollowing = false;
camera.camPitch = 0;
navPanelCounter = 0;
}
void FormGPS::onBtnN3D_clicked(){
camera.camPitch = -65;
camera.camFollowing = false;
navPanelCounter = 0;
}
void FormGPS::onBtnZoomIn_clicked(){
qDebug() <<"ZoomIn button clicked.";
if (camera.zoomValue <= 20) {
if ((camera.zoomValue -= camera.zoomValue * 0.1) < 3.0)
camera.zoomValue = 3.0;
} else {
if ((camera.zoomValue -= camera.zoomValue * 0.05) < 3.0)
camera.zoomValue = 3.0;
}
camera.camSetDistance = camera.zoomValue * camera.zoomValue * -1;
SetZoom();
//TODO save zoom to properties
openGLControl->update();
}
void FormGPS::onBtnZoomOut_clicked(){
qDebug() <<"ZoomOut button clicked.";
if (camera.zoomValue <= 20) camera.zoomValue += camera.zoomValue * 0.1;
else camera.zoomValue += camera.zoomValue * 0.05;
if (camera.zoomValue > 220) camera.zoomValue = 220;
camera.camSetDistance = camera.zoomValue * camera.zoomValue * -1;
SetZoom();
//todo save to properties
openGLControl->update();
}
void FormGPS::onBtnRedFlag_clicked()
{
flagColor = 0;
contextFlag->setProperty("visible",false);
btnFlag->setProperty("icon","/images/FlagRed.png");
}
void FormGPS::onBtnGreenFlag_clicked()
{
flagColor = 1;
contextFlag->setProperty("visible",false);
btnFlag->setProperty("icon","/images/FlagGrn.png");
}
void FormGPS::onBtnYellowFlag_clicked()
{
flagColor = 2;
contextFlag->setProperty("visible",false);
btnFlag->setProperty("icon","/images/FlagYel.png");
}
void FormGPS::onBtnDeleteFlag_clicked()
{
//delete selected flag and set selected to none
flagPts.remove(flagNumberPicked - 1);
flagsBufferCurrent = false;
flagNumberPicked = 0;
int flagCnt = flagPts.size();
if (flagCnt > 0) {
for (int i = 0; i < flagCnt; i++)
flagPts[i].ID = i + 1;
}
contextFlag->setProperty("visible",false);
}
void FormGPS::onBtnDeleteAllFlags_clicked()
{
contextFlag->setProperty("visible",false);
flagPts.clear();
flagsBufferCurrent = false;
flagNumberPicked = 0;
//TODO: FileSaveFlags
}
void FormGPS::onBtnAutoYouTurn_clicked(){
qDebug()<<"activate youturn";
yt.isTurnCreationTooClose = false;
// if (bnd.bndArr.Count == 0) this needs to be moved to qml
// {
// TimedMessageBox(2000, gStr.gsNoBoundary, gStr.gsCreateABoundaryFirst);
// return;
// }
if (!yt.isYouTurnBtnOn)
{
//new direction so reset where to put turn diagnostic
yt.ResetCreatedYouTurn();
if (!isAutoSteerBtnOn) return;
yt.isYouTurnBtnOn = true;
yt.isTurnCreationTooClose = false;
yt.isTurnCreationNotCrossingError = false;
yt.ResetYouTurn();
//mc.autoSteerData[mc.sdX] = 0;
// mc.machineControlData[mc.cnYouTurn] = 0;
// btnAutoYouTurn.Image = Properties.Resources.Youturn80;
}
else
{
yt.isYouTurnBtnOn = false;
// yt.rowSkipsWidth = Properties.Vehicle.Default.set_youSkipWidth;
// btnAutoYouTurn.Image = Properties.Resources.YouTurnNo;
yt.ResetYouTurn();
//new direction so reset where to put turn diagnostic
yt.ResetCreatedYouTurn();
//mc.autoSteerData[mc.sdX] = 0;commented in aog
// mc.machineControlData[mc.cnYouTurn] = 0;
}
}
void FormGPS::onBtnSwapAutoYouTurnDirection_clicked()
{
if (!yt.isYouTurnTriggered)
{
yt.isYouTurnRight = !yt.isYouTurnRight;
yt.ResetCreatedYouTurn();
}
//else if (yt.isYouTurnBtnOn)
//btnAutoYouTurn.PerformClick();
}
void FormGPS::onBtnManUTurn_clicked(bool right)
{
if (yt.isYouTurnTriggered) {
yt.ResetYouTurn();
}else {
yt.isYouTurnTriggered = true;
yt.BuildManualYouTurn(vehicle, ABLine, curve, right, true);
}
}
void FormGPS::onBtnLateral_clicked(bool right)
{
yt.BuildManualYouLateral(vehicle, ABLine, curve, right);
}
void FormGPS::TimedMessageBox(int timeout, QString s1, QString s2)
{
qDebug() << "Timed message " << timeout << s1 << ", " << s2 << Qt::endl;
//TODO ask QML to display a message
QObject *temp = qmlItem(qml_root, "timedMessage");
QMetaObject::invokeMethod(temp, "addMessage", Q_ARG(int, timeout), Q_ARG(QString, s1), Q_ARG(QString, s2));
}
void FormGPS::turnOffBoundAlarm()
{
qDebug() << "Bound alarm should be off" << Qt::endl;
//TODO implement sounds
}
void FormGPS::FixTramModeButton()
{
//TODO QML
//unhide button if it should be seen
if (tram.tramList.count() > 0 || tram.tramBndOuterArr.count() > 0)
{
//btnTramDisplayMode.Visible = true;
tram.displayMode = 1;
}
//make sure tram has right icon. DO this through javascript
}
void FormGPS::on_settings_reload() {
loadSettings();
//TODO: if vehicle name is set, write settings out to that
//vehicle json file
}
void FormGPS::on_settings_save() {
settings->sync();
loadSettings();
}
void FormGPS::modules_send_238() {
qDebug() << "Sending 238 message to AgIO";
p_238.pgn[p_238.set0] = (int)property_setArdMac_setting0;
p_238.pgn[p_238.raiseTime] = (int)property_setArdMac_hydRaiseTime;
p_238.pgn[p_238.lowerTime] = (int)property_setArdMac_hydLowerTime;
p_238.pgn[p_238.user1] = (int)property_setArdMac_user1;
p_238.pgn[p_238.user2] = (int)property_setArdMac_user2;
p_238.pgn[p_238.user3] = (int)property_setArdMac_user3;
p_238.pgn[p_238.user4] = (int)property_setArdMac_user4;
qDebug() << p_238.pgn;
SendPgnToLoop(p_238.pgn);
}
void FormGPS::modules_send_251() {
//qDebug() << "Sending 251 message to AgIO";
p_251.pgn[p_251.set0] = (int)property_setArdSteer_setting0;
p_251.pgn[p_251.set1] = (int)property_setArdSteer_setting1;
p_251.pgn[p_251.maxPulse] = (int)property_setArdSteer_maxPulseCounts;
p_251.pgn[p_251.minSpeed] = 5; //0.5 kmh THIS IS CHANGED IN AOG FIXES
if ((int)property_setAS_isConstantContourOn)
p_251.pgn[p_251.angVel] = 1;
else p_251.pgn[p_251.angVel] = 0;
qDebug() << p_251.pgn;
SendPgnToLoop(p_251.pgn);
}
void FormGPS::headland_save() {
//TODO make FileHeadland() a slot so we don't have to have this
//wrapper.
FileSaveHeadland();
}
void FormGPS::headlines_load() {
//TODO make FileLoadHeadLines a slot, skip this wrapper
FileLoadHeadLines();
}
void FormGPS::headlines_save() {
//TODO make FileSaveHeadLines a slot, skip this wrapper
FileSaveHeadLines();
}
void FormGPS::onBtnResetSim_clicked(){
sim.latitude = property_setGPS_SimLatitude;
sim.longitude = property_setGPS_SimLongitude;
}