-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathSelectionListHelper.cpp
More file actions
149 lines (125 loc) · 3.69 KB
/
Copy pathSelectionListHelper.cpp
File metadata and controls
149 lines (125 loc) · 3.69 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 "SelectionListHelper.h"
#include <set>
#include "ShapefileHelper.h"
#include "SelectionList.h"
#include "ShapeHelper.h"
/***********************************************************************/
/* GetCount()
/***********************************************************************/
long SelectionListHelper::GetCount(ISelectionList* list)
{
if (!list) return 0;
long count = 0;
list->get_Count(&count);
return count;
}
/***********************************************************************/
/* GetUniqueLayers()
/***********************************************************************/
bool SelectionListHelper::GetUniqueLayers(ISelectionList* list, vector<long>& result)
{
long count = GetCount(list);
if (count == 0) return false;
long layerHandle = -1;
set<long> handles;
for (long i = 0; i < count; i++)
{
list->get_LayerHandle(i, &layerHandle);
if (handles.find(layerHandle) == handles.end())
{
handles.insert(layerHandle);
}
}
result.assign(handles.begin(), handles.end());
return true;
}
/***********************************************************************/
/* PopulateShapefile()
/***********************************************************************/
void SelectionListHelper::PopulateShapefile(ISelectionList* list, IShapefile* source, IShapefile* target, long layerHandle)
{
if (!source || !target || !list) return;
ShpfileType shpType = ShapefileHelper::GetShapeType(source);
VARIANT_BOOL vb;
target->EditClear(&vb);
target->CreateNew(m_globalSettings.emptyBstr, shpType, &vb);
long count = GetCount(list);
long handle, shapeIndex;
for (long j = 0; j < count; j++)
{
list->get_LayerHandle(j, &handle);
if (handle == layerHandle)
{
IShape* shp = NULL;
list->get_ShapeIndex(j, &shapeIndex);
source->get_Shape(shapeIndex, &shp);
if (shp)
{
target->EditAddShape(shp, &shapeIndex);
shp->Release();
}
}
}
}
/***********************************************************************/
/* AddSelectedPixelsToShapefile()
/***********************************************************************/
void SelectionListHelper::AddSelectedPixelsToShapefile(ISelectionList* list, IShapefile* target, set<long>& layerHandles, bool polygon)
{
if (!target || !list) return;
VARIANT_BOOL vb;
target->EditClear(&vb);
target->CreateNew(m_globalSettings.emptyBstr, polygon ? SHP_POLYGON : SHP_POINT, &vb);
long count = SelectionListHelper::GetCount(list);
for (long i = 0; i < count; i++)
{
long layerHandle;
list->get_LayerHandle(i, &layerHandle);
if (layerHandles.find(layerHandle) == layerHandles.end())
{
continue;
}
tkLayerType layerType;
list->get_LayerType(i, &layerType);
if (layerType == ltRaster)
{
SelectedItem* item = ((CSelectionList*)list)->GetItem(i);
if (item)
{
if (item->Polygon && polygon && item->ShapePixel)
{
long shapeIndex;
target->EditAddShape(item->ShapePixel, &shapeIndex);
}
if (!item->Polygon && !polygon && item->ShapePixel)
{
IShape* center = ShapeHelper::CenterAsShape(item->ShapePixel);
if (center)
{
long shapeIndex;
target->EditAddShape(center, &shapeIndex);
center->Release();
}
}
}
}
}
}
/***********************************************************************/
/* HasLayers()
/***********************************************************************/
bool SelectionListHelper::HasLayers(ISelectionList* list, tkLayerType layerTypeToSearch)
{
long count = GetCount(list);
for (long j = 0; j < count; j++)
{
tkLayerType layerType;
list->get_LayerType(j, &layerType);
if (layerType == layerTypeToSearch || layerTypeToSearch == UndefinedLayer)
{
return true;
}
}
return false;
}