Skip to content

Commit 00315c8

Browse files
committed
Debug code, better error logging and some cleanup.
Added debug function: DebugDump(IShape* shp).
1 parent a76557e commit 00315c8

10 files changed

Lines changed: 142 additions & 7 deletions

File tree

src/COM classes/Shape.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ CShape::CShape()
6161
_labelRotation = 0;
6262

6363
gReferenceCounter.AddRef(tkInterface::idShape);
64+
#if DEBUG_ALLOCATED_OBJECTS
65+
gReferenceCounter.AddRef(this);
66+
if (ComHelper::GetBreak())
67+
::OutputDebugStringA("Break!");
68+
#endif
6469
}
6570

6671
// **********************************************
@@ -80,6 +85,11 @@ CShape::~CShape()
8085
}
8186

8287
gReferenceCounter.Release(tkInterface::idShape); // TODO: Fix compile warning
88+
#if DEBUG_ALLOCATED_OBJECTS
89+
gReferenceCounter.Release(this);
90+
if (ComHelper::GetBreak())
91+
::OutputDebugStringA("Break!");
92+
#endif
8393
}
8494

8595
#pragma region DataConversions
@@ -259,6 +269,13 @@ STDMETHODIMP CShape::put_ShapeType(const ShpfileType newVal)
259269
const ShapeWrapperType type = _shp->get_WrapperType();
260270
const ShapeWrapperType newType = ShapeUtility::GetShapeWrapperType(newVal, !_useFastMode);
261271

272+
/*if ((newVal == SHP_POINT || newVal == SHP_POINTM || newVal == SHP_POINTZ) && ComHelper::GetBreak()) {
273+
CString str;
274+
str.Format("0x%016llx SHP_POINT", this);
275+
const CComBSTR bstr(str);
276+
put_Key(bstr);
277+
} */
278+
262279
if (type == newType)
263280
{
264281
if (!_shp->put_ShapeType(newVal)) {

src/COM classes/ShapeDrawingOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ STDMETHODIMP CShapeDrawingOptions::put_LineWidth (float newVal)
11641164
AFX_MANAGE_STATE(AfxGetStaticModuleState());
11651165
if (newVal < 1) newVal = 1;
11661166
if (newVal > 20) newVal = 20;
1167-
_options.lineWidth = newVal;
1167+
_options.lineWidth = newVal;
11681168
return S_OK;
11691169
}
11701170

src/COM classes/ShapeDrawingOptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ class ATL_NO_VTABLE CShapeDrawingOptions :
4747
_isLineDecoration = false;
4848
_pointRotationExpression = SysAllocString(L"");
4949
gReferenceCounter.AddRef(tkInterface::idShapeDrawingOptions);
50+
//gReferenceCounter.AddRef(this);
5051
}
5152
~CShapeDrawingOptions()
5253
{
5354
::SysFreeString(_pointRotationExpression);
5455
gReferenceCounter.Release(tkInterface::idShapeDrawingOptions);
56+
//gReferenceCounter.Release(this);
5557
}
5658

5759
DECLARE_REGISTRY_RESOURCEID(IDR_SHAPEDRAWINGOPTIONS)

src/ComHelpers/ShapeHelper.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,108 @@ int ShapeHelper::GetContentLength(IShape* shp)
428428
return ShapeUtility::get_ContentLength(shpType, numPoints, numParts);
429429
}
430430

431+
432+
// *************************************************************
433+
// DebugDump()
434+
// *************************************************************
435+
void ShapeHelper::DebugDump(IShape* shp)
436+
{
437+
long numPoints, numParts;
438+
ShpfileType shpType;
439+
440+
shp->get_NumPoints(&numPoints);
441+
shp->get_NumParts(&numParts);
442+
shp->get_ShapeType(&shpType);
443+
444+
if (numParts > 1) {
445+
::OutputDebugStringA("Not support NumParts > 1");
446+
return;
447+
}
448+
449+
if (numPoints <= 10 || numPoints > 15)
450+
return;
451+
452+
HRESULT hr;
453+
IPoint* pnt = nullptr;
454+
CString sOutput;
455+
double x, y, z, m;
456+
switch (shpType)
457+
{
458+
case SHP_NULLSHAPE:
459+
::OutputDebugStringA("ShapeHelper::DebugDump(): NULLSHAPE");
460+
break;
461+
462+
case SHP_POINT:
463+
case SHP_POINTZ:
464+
hr = shp->get_Point(0, &pnt);
465+
if (FAILED(hr)) {
466+
CString sError;
467+
sError.AppendFormat("ShapeHelper::DebugDump() Failed in get_Point(1, ..)\r\n");
468+
::OutputDebugStringA(sError.GetBuffer());
469+
return;
470+
}
471+
pnt->get_X(&x);
472+
pnt->get_Y(&y);
473+
474+
if (shpType == SHP_POINT)
475+
sOutput.AppendFormat("Point N: %f E: %f\r\n", y, x);
476+
else {
477+
pnt->get_Z(&z);
478+
pnt->get_M(&m);
479+
sOutput.AppendFormat("Point N: %f E: %f Z: %f M: %f\r\n", y, x, z, m);
480+
}
481+
break;
482+
483+
484+
case SHP_POLYLINE:
485+
case SHP_POLYLINEZ:
486+
for (int i = 0; i < numPoints; i++) {
487+
hr = shp->get_Point(i, &pnt);
488+
if (FAILED(hr)) {
489+
CString sError;
490+
sError.AppendFormat("ShapeHelper::DebugDump() Failed in get_Point(%d, ..)\r\n", i);
491+
::OutputDebugStringA(sError.GetBuffer());
492+
return;
493+
}
494+
pnt->get_X(&x);
495+
pnt->get_Y(&y);
496+
if (shpType == SHP_POLYLINE)
497+
sOutput.AppendFormat("Point# %d X: %f Y: %f\r\n", i, x, y);
498+
else {
499+
pnt->get_Z(&z);
500+
pnt->get_M(&m);
501+
sOutput.AppendFormat("Point# %d N: %f E: %f Z: %f M: %f\r\n", i, y, x, z, m);
502+
}
503+
}
504+
break;
505+
506+
case SHP_POLYGON:
507+
case SHP_POLYGONZ:
508+
for (int i = 0; i < numPoints; i++) {
509+
hr = shp->get_Point(i, &pnt);
510+
if (FAILED(hr)) {
511+
CString sError;
512+
sError.AppendFormat("ShapeHelper::DebugDump() Failed in get_Point(%d, ..)\r\n", i);
513+
::OutputDebugStringA(sError.GetBuffer());
514+
return;
515+
}
516+
pnt->get_X(&x);
517+
pnt->get_Y(&y);
518+
if (shpType == SHP_POLYGON)
519+
sOutput.AppendFormat("Point# %d X: %f Y: %f\r\n", i, x, y);
520+
else {
521+
pnt->get_Z(&z);
522+
pnt->get_M(&m);
523+
sOutput.AppendFormat("Point# %d N: %f E: %f Z: %f M: %f\r\n", i, y, x, z, m);
524+
}
525+
}
526+
break;
527+
528+
default:
529+
::OutputDebugStringA("ShapeHelper::DebugDump(): Shape Type: Unknown");
530+
break;
531+
}
532+
sOutput.Append("\r\n");
533+
::OutputDebugStringA(sOutput.GetBuffer());
534+
}
535+

src/ComHelpers/ShapeHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ class ShapeHelper
1919
static void AddLabelToShape(IShape* shp, ILabels* labels, BSTR text, tkLabelPositioning method, tkLineLabelOrientation orientation, double offsetX, double offsetY);
2020
static IShape* CenterAsShape(IShape* shp);
2121
static int GetContentLength(IShape* shp);
22+
static void DebugDump(IShape* shp);
2223
};
2324

src/Resource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#define IDC_SELECT2_CURSOR 220
8686
#define IDC_IDENTIFY_CURSOR 221
8787
#define IDC_PAN_ALTERNATE 222
88+
#define IDR_PLACEDLABELS 223
8889

8990
// Next default values for new objects
9091
//

src/Structures/Extent.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class Extent
131131
top = yCent + dy;
132132
}
133133

134-
Point2D GetCenter ()
134+
Point2D GetCenter ()
135135
{
136136
return Point2D((left + right) / 2.0, (top + bottom) / 2.0);
137137
}
@@ -143,7 +143,9 @@ class Extent
143143

144144
CString ToString()
145145
{
146-
return Debug::Format("x: %f; y: %f; w: %f; h: %f", left, top, Width(), Height());
146+
auto width = Width();
147+
auto height = Height();
148+
return Debug::Format("x: %f; y: %f; w: %f; h: %f", left, top, width, height);
147149
}
148150

149151
};

src/Tiles/Caching/SQLiteCache.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,13 @@ void SQLiteCache::AddTile(TileCore* tile)
212212

213213
if (val != SQLITE_OK)
214214
{
215-
CallbackHelper::ErrorMsg("SQLiteCache::DoCaching: Failed to prepare statement.");
215+
auto sqlite3_error = sqlite3_errmsg(_conn);
216+
auto errorCode = sqlite3_extended_errcode(_conn);
217+
//std:string errorMessage("SQLiteCache::DoCaching: Failed to prepare statement: ");
218+
//errorMessage += sqlite3_error ? sqlite3_error : "Unknown error";
219+
//CallbackHelper::ErrorMsg(errorMessage.c_str());
220+
CallbackHelper::ErrorMsg(Debug::Format("SQLiteCache::DoCaching: Failed to prepare statement errorNo: %d Message: %s", errorCode, sqlite3_error));
221+
//CallbackHelper::ErrorMsg("SQLiteCache::DoCaching: Failed to prepare statement.");
216222
}
217223
else
218224
{

src/Utilities/GdalHelper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ int GdalHelper::CloseSharedOgrDataset(GDALDataset* ds)
113113
const int count = ds->Dereference();
114114
if (count == 0)
115115
{
116-
//Debug::WriteLine("Shared datasource is closed.");
116+
Debug::WriteLine("Shared datasource(%s) is closed.", ds->GetDescription());
117117
RemoveCachedOgrDataset(ds);
118118
GDALClose(ds);
119119
}
@@ -139,6 +139,7 @@ void GdalHelper::RemoveCachedOgrDataset(GDALDataset* ds)
139139
{
140140
if (it->second == ds)
141141
{
142+
Debug::WriteLine("RemoveCachedOgrDataset(ds: %s)", it->first.GetString());
142143
m_ogrDatasets.erase(it->first);
143144
break;
144145
}
@@ -740,7 +741,7 @@ CStringW GdalHelper::GetDefaultConfigPath(const GdalPath option)
740741
path += L"\\gdalplugins\\";
741742
break;
742743
case PathProjLib:
743-
path += L"\\proj7\\share\\";
744+
path += L"\\proj9\\share\\";
744745
break;
745746
}
746747
return path;

src/Utilities/Logger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace Debug
3131
{
3232
if (IsOpened() || Debug::IsDebugMode())
3333
{
34-
TCHAR buffer[1024];
34+
TCHAR buffer[4096];
3535
va_list args;
3636
va_start( args, format);
3737
vsprintf( buffer, format, args );

0 commit comments

Comments
 (0)