forked from torriem/QtAgOpenGPS
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathformgps_ui_boundary.cpp
126 lines (102 loc) · 3.51 KB
/
formgps_ui_boundary.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
// Copyright (C) 2024 Michael Torrie and the QtAgOpenGPS Dev Team
// SPDX-License-Identifier: GNU General Public License v3.0 or later
//GUI to backend boundary interface
#include "formgps.h"
#include "qmlutil.h"
void FormGPS::boundary_calculate_area() {
int ptCount = bnd.bndBeingMadePts.count();
double area = 0;
if (ptCount > 0)
{
int j = ptCount - 1; // The last vertex is the 'previous' one to the first
for (int i = 0; i < ptCount; j = i++)
{
area += (bnd.bndBeingMadePts[j].easting + bnd.bndBeingMadePts[i].easting) * (bnd.bndBeingMadePts[j].northing - bnd.bndBeingMadePts[i].northing);
}
area = fabs(area / 2);
}
qmlItem(mainWindow,"boundaryInterface")->setProperty("area", area);
qmlItem(mainWindow,"boundaryInterface")->setProperty("pts", ptCount);
}
void FormGPS::boundary_update_list() {
QList<QVariant> boundList;
QMap<QString, QVariant> bndMap;
int index = 0;
for (CBoundaryList &b: bnd.bndList) {
bndMap["index"] = index++;
bndMap["area"] = b.area;
bndMap["drive_through"] = b.isDriveThru;
boundList.append(bndMap);
}
qmlItem(mainWindow,"boundaryInterface")->setProperty("boundary_list", boundList);
}
void FormGPS::boundary_start() {
bnd.createBndOffset = tool.width * 0.5;
bnd.isBndBeingMade = true;
bnd.bndBeingMadePts.clear();
boundary_calculate_area();
}
void FormGPS::boundary_stop() {
if (bnd.bndBeingMadePts.count() > 2)
{
CBoundaryList New;
for (int i = 0; i < bnd.bndBeingMadePts.count(); i++)
{
New.fenceLine.append(bnd.bndBeingMadePts[i]);
}
New.CalculateFenceArea(bnd.bndList.count());
New.FixFenceLine(bnd.bndList.count());
bnd.bndList.append(New);
fd.UpdateFieldBoundaryGUIAreas(bnd.bndList);
//turn lines made from boundaries
calculateMinMax();
FileSaveBoundary();
bnd.BuildTurnLines(fd);
}
//stop it all for adding
bnd.isOkToAddPoints = false;
bnd.isBndBeingMade = false;
bnd.bndBeingMadePts.clear();
boundary_update_list();
qmlItem(mainWindow,"boundaryInterface")->setProperty("count", bnd.bndList.count());
}
void FormGPS::boundary_add_point() {
bnd.isOkToAddPoints = true;
AddBoundaryPoint();
bnd.isOkToAddPoints = false;
}
void FormGPS::boundary_delete_last_point() {
int ptCount = bnd.bndBeingMadePts.count();
if (ptCount > 0)
bnd.bndBeingMadePts.pop_back();
boundary_calculate_area();
}
void FormGPS::boundary_pause(){
bnd.isOkToAddPoints = false;
}
void FormGPS::boundary_record() {
bnd.isOkToAddPoints = true;
}
void FormGPS::boundary_restart() {
bnd.bndBeingMadePts.clear();
boundary_calculate_area();
}
void FormGPS::boundary_delete(int which_boundary) {
//boundary 0 is special. It's the outer boundary.
if (which_boundary == 0 && bnd.bndList.count() > 1)
return; //must remove other boundaries first.
bnd.bndList.remove(which_boundary);
qmlItem(mainWindow,"boundaryInterface")->setProperty("count", bnd.bndList.count());
boundary_update_list();
}
void FormGPS::boundary_set_drivethru(int which_boundary, bool drive_through) {
bnd.bndList[which_boundary].isDriveThru = drive_through;
boundary_update_list();
}
void FormGPS::boundary_delete_all() {
bnd.bndList.clear();
FileSaveBoundary();
bnd.BuildTurnLines(fd);
qmlItem(mainWindow,"boundaryInterface")->setProperty("count", bnd.bndList.count());
boundary_update_list();
}