-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathVertexEditor.cpp
More file actions
127 lines (113 loc) · 3.39 KB
/
VertexEditor.cpp
File metadata and controls
127 lines (113 loc) · 3.39 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
#include "stdafx.h"
#include "VertexEditor.h"
#include "ShapeEditor.h"
#include "ShapeHelper.h"
// ************************************************************
// StartEdit
// ************************************************************
void VertexEditor::StartEdit(CShapeEditor* editor, long layerHandle, long shapeIndex)
{
editor->Clear();
if (layerHandle != -1 && shapeIndex != -1)
{
VARIANT_BOOL vb;
editor->StartEdit(layerHandle, shapeIndex, &vb);
if (vb) {
editor->SetRedrawNeeded(rtVolatileLayer);
}
}
}
// ************************************************************
// OnMouseDown
// ************************************************************
bool VertexEditor::OnMouseDown(IMapViewCallback* map, CShapeEditor* editor, double projX, double projY, bool ctrl, bool shift)
{
if (!editor) return true;
VARIANT_BOOL isEmpty;
editor->get_IsEmpty(&isEmpty);
long layerHandle = -1, shapeIndex = -1;
if (!isEmpty)
{
if (ctrl)
{
bool stopped = editor->TryStop();
if (stopped)
editor->SetRedrawNeeded(rtVolatileLayer);
return true;
}
if (!OnMouseDownEditing(map, editor, projX, projY, shift))
{
if (!editor->TryStop()) // it was clicked outside shape; so clear it
return true;
}
else
return true;
}
return false;
}
// ************************************************************
// OnMouseDownEditing
// ************************************************************
bool VertexEditor::OnMouseDownEditing(IMapViewCallback* map, CShapeEditor* editor, double projX, double projY, bool shift)
{
CComPtr<IShape> shp = NULL;
editor->get_RawData(&shp);
double tol = map->_GetMouseProjTolerance();
tkEditorBehavior behavior;
editor->get_EditorBehavior(&behavior);
// select vertex
if (behavior == ebVertexEditor)
{
int pntIndex = editor->GetClosestVertex(projX, projY, tol);
if (pntIndex != -1)
{
// start vertex moving
bool changed = editor->SetSelectedVertex(pntIndex);
map->_StartDragging(DragMoveVertex);
editor->SaveState();
if (changed) editor->SetRedrawNeeded(rtShapeEditor);
return true;
}
}
// select part
if (behavior == ebPartEditor)
{
double x, y;
if (editor->GetClosestPoint(projX, projY, x, y))
{
double dist = sqrt(pow(x - projX, 2.0) + pow(y - projY, 2.0));
if (dist < tol)
{
// select part
int partIndex = editor->SelectPart(x, y);
if (partIndex != -1)
{
if (editor->SetSelectedPart(partIndex)) {
map->_StartDragging(DragMovePart);
}
editor->SetRedrawNeeded(rtShapeEditor);
return true;
}
if (editor->HasSelectedPart())
{
map->_StartDragging(DragMovePart);
return true;
}
}
}
}
if (shift)
return true; // use shift to prevent editor from stopping edits
// MWGIS-153: until further review, due to difficulty in editing,
// disable 'moving' altogether within the context of the vertex editor
//
//// start shape moving (only if 'shift' is pressed)
//if (shift && ShapeHelper::PointWithinShape(shp, projX, projY, tol))
//{
// // it's confusing to have both part and shape move depending on where you clicked
// if (editor->HasSelectedPart()) return true;
// map->_StartDragging(DragMoveShape);
// return true;
//}
return false;
}