-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathShapeValidator.cpp
More file actions
150 lines (131 loc) · 3.66 KB
/
ShapeValidator.cpp
File metadata and controls
150 lines (131 loc) · 3.66 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
#include "stdafx.h"
#include "ShapeValidator.h"
#include "ShapeValidationInfo.h"
#include "Shapefile.h"
// ***************************************************************
// Validate()
// ***************************************************************
IShapeValidationInfo* ShapeValidator::Validate(IShapefile* isf, tkShapeValidationMode validationMode,
tkShapeValidationType validationType, CString className, CString methodName, CString parameterName,
ICallback* callback, BSTR& key, bool selectedOnly, bool reportOnly)
{
if (!isf)
return NULL;
tkShapefileSourceType sourceType;
isf->get_SourceType(&sourceType);
if (sourceType == tkShapefileSourceType::sstUninitialized)
return NULL;
CShapefile* sf = (CShapefile*)isf;
VARIANT_BOOL vb;
IShapeValidationInfo* iinfo = NULL;
ComHelper::CreateInstance(idShapeValidationInfo, (IDispatch**)&iinfo);
CShapeValidationInfo* info = (CShapeValidationInfo*)iinfo;
info->className = className;
info->methodName = methodName;
info->parameterName = parameterName;
info->validationType = validationType;
info->validationMode = validationMode;
info->validationStatus = tkShapeValidationStatus::Valid;
if (validationMode == NoValidation)
{
info->validationStatus = tkShapeValidationStatus::WasntValidated;
info->wereInvalidCount = -1;
info->stillInvalidCount = -1;
info->fixedCount = -1;
info->skippedCount = -1;
}
else
{
info->wereInvalidCount = 0;
info->stillInvalidCount = 0;
info->fixedCount = 0;
info->skippedCount = 0;
VARIANT_BOOL canEdit;
isf->get_EditingShapes(&canEdit);
if (validationType == svtInput) {
canEdit = VARIANT_FALSE;
}
if (!canEdit && validationMode == TryFixProceedOnFailure ||
validationMode== TryFixProceedOnFailure) {
CallbackHelper::ErrorMsg("Validation mode demands fixing of invalid shapes, but shapefile isn't in edit mode. "
"Validation without fixing will be performed.");
reportOnly = true;
}
long numShapes;
isf->get_NumShapes(&numShapes);
bool checkEditMode = true;
long percent = 0;
for (int i = numShapes - 1; i >= 0 ; i--)
{
CallbackHelper::Progress(callback, numShapes - 1 - i, numShapes, "Validating shapes...", key, percent);
IShape* shp = NULL;
isf->get_Shape(i, &shp);
shp->get_IsValid(&vb);
if (vb)
{
shp->Release();
}
else
{
info->wereInvalidCount++;
if (reportOnly)
{
info->stillInvalidCount++;
shp->Release();
}
else if (validationMode == AbortOnErrors) // retreat on the first error
{
info->validationStatus = tkShapeValidationStatus::OperationAborted;
shp->Release();
goto stop_operation;
}
else
{
IShape* fixedShape = NULL;
shp->FixUp(&fixedShape);
shp->Release();
if (fixedShape)
{
info->fixedCount++;
sf->EditUpdateShape(i, fixedShape, &vb);
}
else
{
info->stillInvalidCount++;
switch(validationMode)
{
case TryFixProceedOnFailure:
// do nothing
break;
case TryFixSkipOnFailure:
sf->EditDeleteShape(i, &vb);
break;
}
}
}
}
}
}
stop_operation:
if (info->validationStatus == OperationAborted)
{
info->stillInvalidCount = 1;
info->wereInvalidCount = 1;
}
else
{
if (info->stillInvalidCount > 0)
{
info->validationStatus = InvalidReturned;
}
else if (info->skippedCount > 0)
{
info->validationStatus = InvalidSkipped;
}
else if (info->fixedCount > 0)
{
info->validationStatus = InvalidFixed;
}
}
return iinfo;
}