-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathEditorHelper.cpp
More file actions
147 lines (130 loc) · 4.32 KB
/
EditorHelper.cpp
File metadata and controls
147 lines (130 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
#include "stdafx.h"
#include "EditorHelper.h"
#include "ShapeEditor.h"
#include "ShapefileHelper.h"
// ************************************************************
// GetShapeType2D
// ************************************************************
ShpfileType EditorHelper::GetShapeType2D(IShapeEditor* editor)
{
if (!editor) return SHP_NULLSHAPE;
ShpfileType shpType;
editor->get_ShapeType(&shpType);
return ShapeUtility::Convert2D(shpType);
}
// ************************************************************
// IsEmpty
// ************************************************************
bool EditorHelper::IsEmpty(IShapeEditor* editor)
{
if (!editor) return true;
VARIANT_BOOL isEmpty;
editor->get_IsEmpty(&isEmpty);
return isEmpty ? true : false;
}
// ************************************************************
// IsGroupOverlayCursor
// ************************************************************
bool EditorHelper::IsGroupOverlayCursor(tkCursorMode cursorMode)
{
return cursorMode == cmSplitByPolyline || cursorMode == cmSplitByPolygon ||
cursorMode == cmEraseByPolygon || cursorMode == cmClipByPolygon ||
cursorMode == cmSelectByPolygon;
}
// ************************************************************
// IsDigitizingCursor
// ************************************************************
bool EditorHelper::IsDigitizingCursor(tkCursorMode mode)
{
return mode == cmAddShape || IsGroupOverlayCursor(mode);
}
// ************************************************************
// IsSnappableCursor
// ************************************************************
bool EditorHelper::IsSnappableCursor(tkCursorMode mode)
{
return mode == cmAddShape || mode == cmSplitByPolyline || mode == cmSplitByPolygon ||
mode == cmEraseByPolygon || mode == cmClipByPolygon;
}
// *******************************************************
// CopyOptionsFrom()
// *******************************************************
void EditorHelper::CopyOptionsFrom(IShapeEditor* editor, IShapefile* sf)
{
if (!sf || !editor) return;
CComPtr<IShapeDrawingOptions> options = NULL;
sf->get_DefaultDrawingOptions(&options);
CopyOptionsFrom(editor, options);
}
void EditorHelper::CopyOptionsFrom(IShapeEditor* editor, IShapeDrawingOptions* options)
{
if (!editor || !options) return;
ShpfileType shpType;
editor->get_ShapeType(&shpType);
float lineWidth;
OLE_COLOR fillColor, lineColor;
options->get_FillColor(&fillColor);
options->get_LineColor(&lineColor);
options->get_LineWidth(&lineWidth);
editor->put_FillColor(fillColor);
if (ShapeUtility::Convert2D(shpType) == SHP_POLYGON) {
lineColor = Utility::ChangeBrightness(fillColor, -50);
lineWidth = 1.0f;
}
editor->put_LineColor(lineColor);
editor->put_LineWidth(lineWidth);
}
// *******************************************************
// OnCursorChanged()
// *******************************************************
bool EditorHelper::OnCursorChanged(CShapeEditor* editor, bool clearEditor, tkCursorMode newCursor, bool& redrawNeeded)
{
if (!editor) return true;
if (clearEditor)
{
CComPtr<IShape> shp = NULL;
editor->get_RawData(&shp);
if (shp)
{
VARIANT_BOOL saved;
editor->SaveChanges(&saved);
if (!saved) return false; // don't change cursor as user will loose unsaved changes
redrawNeeded = true;
}
else {
bool empty = EditorHelper::IsEmpty(editor);
editor->Clear();
if (!empty) {
redrawNeeded = true;
}
}
if (newCursor == cmAddShape) {
editor->put_EditorState(esDigitize);
}
}
if (EditorHelper::IsGroupOverlayCursor(newCursor))
{
editor->StartUnboundShape(newCursor);
}
return true;
}
// *******************************************************
// GetSnappingBehavior()
// *******************************************************
tkLayerSelection EditorHelper::GetSnappingBehavior(IShapeEditor* editor)
{
if (!editor) return lsNoLayer;
tkLayerSelection behavior;
editor->get_SnapBehavior(&behavior);
return behavior;
}
// *******************************************************
// GetSnappingMode()
// *******************************************************
tkSnapMode EditorHelper::GetSnappingMode(IShapeEditor* editor)
{
if (!editor) return smVerticesAndLines;
tkSnapMode mode;
editor->get_SnapMode(&mode);
return mode;
}