-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathChartsHelper.cpp
More file actions
148 lines (131 loc) · 3.41 KB
/
ChartsHelper.cpp
File metadata and controls
148 lines (131 loc) · 3.41 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
#include "stdafx.h"
#include "ChartsHelper.h"
// *******************************************************************
// ReadChartFields()
// *******************************************************************
// Fills array with data values from the selected fields
bool ChartsHelper::ReadChartFields(IShapefile* sf, std::vector<double*>* values)
{
if (!sf) return false;
struct FieldIndex
{
FieldType type;
int index;
};
long numShapes;
sf->get_NumShapes(&numShapes);
CComPtr<ICharts> charts = NULL;
sf->get_Charts(&charts);
long numBars;
charts->get_NumFields(&numBars);
if (numBars == 0) return false;
// reading types of fields
std::vector<FieldIndex> fields;
for (int j = 0; j < numBars; j++)
{
long fieldIndex;
CComPtr<IChartField> chartField = NULL;
charts->get_Field(j, &chartField);
if (chartField)
{
chartField->get_Index(&fieldIndex);
}
//m_charts->get_FieldIndex(j, &fieldIndex);
IField* fld = NULL;
sf->get_Field(fieldIndex, &fld);
if (fld)
{
FieldIndex ind;
fld->get_Type(&ind.type);
ind.index = fieldIndex;
fields.push_back(ind);
fld->Release(); fld = NULL;
}
else
{
FieldIndex ind;
ind.index = -1;
ind.type = STRING_FIELD;
fields.push_back(ind);
}
}
// reading data
VARIANT val;
VariantInit(&val);
values->resize(numShapes);
for (int i = 0; i < numShapes; i++)
{
(*values)[i] = new double[numBars];
double* arr = (*values)[i];
for (int j = 0; j < numBars; j++)
{
if (fields[j].type == INTEGER_FIELD || fields[j].type == DOUBLE_FIELD)
{
sf->get_CellValue(fields[j].index, i, &val);
dVal(val, arr[j]);
}
else
{
arr[j] = 0.0;
}
}
}
VariantClear(&val);
return true;
}
// *******************************************************************
// ReadChartField()
// *******************************************************************
bool ChartsHelper::ReadChartField(IShapefile* sf, std::vector<double>* values, int fieldIndex)
{
if (!sf) return false;
IField* fld = NULL;
sf->get_Field(fieldIndex, &fld);
if (!fld)
return false;
FieldType type;
fld->get_Type(&type);
if (type != INTEGER_FIELD && type != DOUBLE_FIELD)
return false;
fld->Release(); fld = NULL;
// reading data
VARIANT val;
VariantInit(&val);
long numShapes;
sf->get_NumShapes(&numShapes);
values->resize(numShapes);
for (int i = 0; i < numShapes; i++)
{
sf->get_CellValue(fieldIndex, i, &val);
dVal(val, (*values)[i]);
}
VariantClear(&val);
return true;
}
// *************************************************************
// GetCollisionBuffer()
// *************************************************************
long ChartsHelper::GetCollisionBuffer(ICharts* charts)
{
long collisionBuffer;
charts->get_CollisionBuffer(&collisionBuffer);
return collisionBuffer;
}
// *************************************************************
// GetOffsetX()
// *************************************************************
long ChartsHelper::GetOffsetX(ICharts* charts)
{
long offsetX;
charts->get_OffsetX(&offsetX);
return offsetX;
}
// *************************************************************
// GetOffsetY()
// *************************************************************
long ChartsHelper::GetOffsetY(ICharts* charts)
{
long offsetY;
charts->get_OffsetY(&offsetY);
return offsetY;
}