-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathMeasuringBase.cpp
More file actions
156 lines (143 loc) · 4.32 KB
/
MeasuringBase.cpp
File metadata and controls
156 lines (143 loc) · 4.32 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
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
#include "stdafx.h"
#include "MeasuringBase.h"
// *******************************************************
// GetPartStartAndEnd()
// *******************************************************
bool MeasuringBase::GetPartStartAndEnd(int partIndex, MixedShapePart whichPoints, int& startIndex, int& endIndex)
{
startIndex = 0;
endIndex = _points.size(); // actually the next after end one
switch (whichPoints)
{
case PolygonPart:
{
if (_firstPolyPointIndex == -1)
return false;
if (_firstPolyPointIndex >(int)_points.size() - 1)
{
return false;
}
startIndex = _firstPolyPointIndex;
endIndex = (int)_points.size();
return true;
}
}
return true;
}
// *******************************************************
// Clear()
// *******************************************************
void MeasuringBase::Clear()
{
ActiveShape::Clear();
_firstPolyPointIndex = _measuringType == MeasureArea ? 0 : -1;
}
// *******************************************************
// ClearIfStopped()
// *******************************************************
void MeasuringBase::ClearIfStopped()
{
_closedPoly = false;
if (_stopped)
{
_points.clear();
_stopped = false;
}
}
// *******************************************************
// UndoPoint()
// *******************************************************
bool MeasuringBase::UndoPoint()
{
bool result = ActiveShape::UndoPoint();
_stopped = false;
return result;
}
// *******************************************************
// SetMeasuringType()
// *******************************************************
void MeasuringBase::SetMeasuringType(tkMeasuringType type)
{
_measuringType = type;
_firstPolyPointIndex = type == MeasureArea ? 0 : -1;
if (_measuringType == MeasureArea)
_closedPoly = true;
}
// *******************************************************
// HandleProjPointAdd()
// *******************************************************
void MeasuringBase::HandleProjPointAdd(double projX, double projY)
{
double pixelX, pixelY;
_mapCallback->_ProjectionToPixel(projX, projY, &pixelX, &pixelY);
AddPoint(projX, projY, pixelX, pixelY);
}
// *******************************************************
// UpdatePolyCloseState()
// *******************************************************
void MeasuringBase::UpdatePolyCloseState(bool close, int pointIndex)
{
if (_measuringType == MeasureDistance)
{
if (close && pointIndex != -1){
_closedPoly = true;
_firstPolyPointIndex = pointIndex;
_stopped = true;
}
else if (!close) {
_closedPoly = false;
_firstPolyPointIndex = -1;
_stopped = false;
}
}
}
// *******************************************************
// SnapToPreviousVertex()
// *******************************************************
bool MeasuringBase::SnapToPreviousVertex(int& vertexIndex, double screenX, double screenY)
{
double minDist = DBL_MAX;
double xTemp, yTemp;
vertexIndex = -1;
int size = _points.size() - 2;
for (int i = 0; i < size; i++)
{
ProjToPixel(_points[i]->Proj.x, _points[i]->Proj.y, xTemp, yTemp);
double dist = sqrt(pow(screenX - xTemp, 2.0) + pow(screenY - yTemp, 2.0));
if (dist < minDist && dist < SNAP_TOLERANCE)
{
minDist = dist;
vertexIndex = i;
}
}
return vertexIndex > -1;
}
// *******************************************************
// HasLine()
// *******************************************************
bool MeasuringBase::HasLine(bool dynamicBuffer)
{
//if (_measuringType != MeasureDistance || _points.size()== 0) return false;
if ( _points.size() == 0) return false;
if (dynamicBuffer && _stopped) return false;
return true;
}
// ************************************************
// HasPolygon
// ************************************************
bool MeasuringBase::HasPolygon(bool dynamicBuffer)
{
if (!dynamicBuffer) {
return (_measuringType == MeasureDistance && _closedPoly) || (_measuringType == MeasureArea && _stopped && _points.size() > 2);
}
else {
return _measuringType == MeasureArea && _points.size() > 0 && !_stopped;
}
}
// ************************************************
// HasPolygon
// ************************************************
bool MeasuringBase::HasPolygon()
{
return _firstPolyPointIndex != -1 && _points.size() >= 2;
}