From 2f4f3c11c6c61422a47a0ee6e700ec710dd46862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Sat, 21 Oct 2023 18:00:19 +0200 Subject: [PATCH 01/55] Fixed OgrConverter to correctly handle Z and M values. --- src/Ogr/OgrConverter.cpp | 154 ++++++++++++++++++++++----------- src/Shapefile/ShapeUtility.cpp | 11 +++ src/Shapefile/ShapeUtility.h | 1 + 3 files changed, 115 insertions(+), 51 deletions(-) diff --git a/src/Ogr/OgrConverter.cpp b/src/Ogr/OgrConverter.cpp index 150df2e1..af1350be 100644 --- a/src/Ogr/OgrConverter.cpp +++ b/src/Ogr/OgrConverter.cpp @@ -71,22 +71,35 @@ void AddPoints(CShape* shp, OGRLineString* geom, int startPointIndex, int endPoi { ShpfileType shpType; shp->get_ShapeType(&shpType); - bool isM = ShapeUtility::IsM(shpType); + bool haveZ = ShapeUtility::IsZ(shpType); + bool haveM = ShapeUtility::HaveM(shpType); VARIANT_BOOL vb; - double x, y, z; + double x, y, z, m; for( int i = startPointIndex; i < endPointIndex; i++ ) { - if (isM) + if ( haveZ ) { - shp->get_XY(i, &x, &y, &vb); - shp->get_M(i, &z); + shp->get_XYZ(i, &x, &y, &z); + if( haveM ) + { + shp->get_M(i, &m); + geom->addPoint(x, y, z, m); + } + else + geom->addPoint(x, y, z); } - else + else // No Z { - shp->get_XYZ(i, &x, &y, &z); + shp->get_XY(i, &x, &y, &vb); + if( haveM ) + { + shp->get_M(i, &m); + geom->addPointM(x, y, m); + } + else + geom->addPoint(x, y); } - geom->addPoint(x, y, z); } } @@ -106,12 +119,15 @@ OGRGeometry* OgrConverter::ShapeToGeometry(IShape* shape, OGRwkbGeometryType for long numPoints, numParts; long beg_part, end_part; ShpfileType shptype; - double x,y,z; + double x,y,z,m; shp->get_ShapeType(&shptype); shp->get_NumParts(&numParts); shp->get_NumPoints(&numPoints); + bool haveZ = ShapeUtility::IsZ(shptype); + bool haveM = ShapeUtility::HaveM(shptype); + VARIANT_BOOL vb; if (shptype == SHP_POINT || shptype == SHP_POINTM || shptype == SHP_POINTZ) @@ -120,18 +136,27 @@ OGRGeometry* OgrConverter::ShapeToGeometry(IShape* shape, OGRwkbGeometryType for OGRPoint *oPnt = (OGRPoint*)OGRGeometryFactory::createGeometry(wkbPoint); if (numPoints > 0) { - if (shptype == SHP_POINTM) + if ( haveZ ) { - shp->get_XY(0, &x, &y, &vb); - shp->get_M(0, &z); + shp->get_XYZ(0, &x, &y, &z); + if( haveM ) + { + shp->get_M(0, &m); + oPnt->setM(m); + } + oPnt->setZ(z); } - else + else // No Z { - shp->get_XYZ(0, &x, &y, &z); + shp->get_XY(0, &x, &y, &vb); + if( haveM ) + { + shp->get_M(0, &m); + oPnt->setM(m); + } } oPnt->setX(x); oPnt->setY(y); - oPnt->setZ(z); } oGeom = oPnt; } @@ -144,19 +169,28 @@ OGRGeometry* OgrConverter::ShapeToGeometry(IShape* shape, OGRwkbGeometryType for { for( int i = 0; i < numPoints; i++ ) { - if (shptype == SHP_MULTIPOINTM) + OGRPoint *oPnt = (OGRPoint*)OGRGeometryFactory::createGeometry(wkbPoint); + if ( haveZ ) { - shp->get_XY(i, &x, &y, &vb); - shp->get_M(i, &z); + shp->get_XYZ(0, &x, &y, &z); + oPnt->setZ(z); + if( haveM ) + { + shp->get_M(0, &m); + oPnt->setM(m); + } } - else + else // No Z { - shp->get_XYZ(i, &x, &y, &z); + shp->get_XY(0, &x, &y, &vb); + if( haveM ) + { + shp->get_M(0, &m); + oPnt->setM(m); + } } - OGRPoint *oPnt = (OGRPoint*)OGRGeometryFactory::createGeometry(wkbPoint); oPnt->setX(x); oPnt->setY(y); - oPnt->setZ(z); oMPnt->addGeometryDirectly(oPnt); // no memory release is needed when "direct" methods are used } } @@ -412,11 +446,11 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, if (oForceType != wkbNone) oType = oForceType; - if (oType == wkbPoint || oType == wkbPoint25D || oType == wkbPointZM) + if (oType == wkbPoint || oType == wkbPoint25D || oType == wkbPointM || oType == wkbPointZM) { if (oType == wkbPoint) shptype = SHP_POINT; - else if (oType == wkbPoint25D || oType == wkbPointZM) + else if (oType == wkbPoint25D || oType == wkbPointM || oType == wkbPointZM) shptype = isM ? SHP_POINTM : SHP_POINTZ; OGRPoint* oPnt = (OGRPoint *) oGeom; @@ -424,20 +458,23 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, ComHelper::CreateShape(&shp); shp->put_ShapeType(shptype); + bool haveZ = shptype == SHP_POINTZ; + bool haveM = shptype == SHP_POINTZ || shptype == SHP_POINTM; + ComHelper::CreatePoint(&pnt); pnt->put_X(oPnt->getX()); pnt->put_Y(oPnt->getY()); - if (isM) pnt->put_M(oPnt->getZ()); - else pnt->put_Z(oPnt->getZ()); + if(haveZ) pnt->put_Z(oPnt->getZ()); + if(haveM) pnt->put_M(oPnt->getM()); shp->InsertPoint(pnt,&pointIndex,&retval); pnt->Release(); } - else if (oType == wkbMultiPoint || oType == wkbMultiPoint25D || oType == wkbMultiPointZM) + else if (oType == wkbMultiPoint || oType == wkbMultiPoint25D || oType == wkbMultiPointM || oType == wkbMultiPointZM) { if (oType == wkbMultiPoint) shptype = SHP_MULTIPOINT; - else if (oType == wkbMultiPoint25D || oType == wkbMultiPointZM) + else if (oType == wkbMultiPoint25D || oType == wkbMultiPointM || oType == wkbMultiPointZM) shptype = isM ? SHP_MULTIPOINTM : SHP_MULTIPOINTZ; OGRMultiPoint* oMPnt = (OGRMultiPoint* ) oGeom; @@ -447,6 +484,9 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, ComHelper::CreateShape(&shp); shp->put_ShapeType(shptype); + bool haveZ = shptype == SHP_MULTIPOINTZ; + bool haveM = shptype == SHP_MULTIPOINTZ || shptype == SHP_MULTIPOINTM; + for(long i = 0; i < oMPnt->getNumGeometries(); i++ ) { OGRPoint* oPnt = (OGRPoint *) oMPnt->getGeometryRef(i); @@ -457,8 +497,8 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, ComHelper::CreatePoint(&pnt); pnt->put_X(oPnt->getX()); pnt->put_Y(oPnt->getY()); - if (isM) pnt->put_M(oPnt->getZ()); - else pnt->put_Z(oPnt->getZ()); + if(haveZ) pnt->put_Z(oPnt->getZ()); + if(haveM) pnt->put_M(oPnt->getM()); shp->InsertPoint(pnt,&i,&retval); pnt->Release(); } @@ -466,11 +506,11 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, } } - else if (oType == wkbLineString || oType == wkbLineString25D || oType == wkbLineStringZM) + else if (oType == wkbLineString || oType == wkbLineString25D || oType == wkbLineStringM || oType == wkbLineStringZM) { if (oType == wkbLineString) shptype = SHP_POLYLINE; - else if (oType == wkbLineString25D || oType == wkbLineStringZM) + else if (oType == wkbLineString25D || oType == wkbLineStringM || oType == wkbLineStringZM) shptype = isM ? SHP_POLYLINEM : SHP_POLYLINEZ; OGRLineString* oLine = (OGRLineString *) oGeom; @@ -480,24 +520,27 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, ComHelper::CreateShape(&shp); shp->put_ShapeType(shptype); shp->InsertPart(0,&partIndex,&retval); - + + bool haveZ = shptype == SHP_POLYLINEZ; + bool haveM = shptype == SHP_POLYLINEZ || shptype == SHP_POLYLINEM; + for(long i = 0; i < oLine->getNumPoints(); i++ ) { ComHelper::CreatePoint(&pnt); pnt->put_X(oLine->getX(i)); pnt->put_Y(oLine->getY(i)); - if (isM) pnt->put_M(oLine->getZ(i)); - else pnt->put_Z(oLine->getZ(i)); + if(haveZ) pnt->put_Z(oLine->getZ(i)); + if(haveM) pnt->put_M(oLine->getM(i)); shp->InsertPoint(pnt,&i,&retval); pnt->Release(); } } - else if (oType == wkbMultiLineString || oType == wkbMultiLineString25D || oType == wkbMultiLineStringZM) + else if (oType == wkbMultiLineString || oType == wkbMultiLineString25D || oType == wkbMultiLineStringM || oType == wkbMultiLineStringZM) { if (oType == wkbMultiLineString) shptype = SHP_POLYLINE; - else if (oType == wkbMultiLineString25D || oType == wkbMultiLineStringZM) + else if (oType == wkbMultiLineString25D || oType == wkbMultiLineStringM || oType == wkbMultiLineStringZM) shptype = isM ? SHP_POLYLINEM : SHP_POLYLINEZ; OGRMultiLineString * oMLine = (OGRMultiLineString *) oGeom; @@ -506,7 +549,10 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, ComHelper::CreateShape(&shp); shp->put_ShapeType(shptype); - + + bool haveZ = shptype == SHP_POLYLINEZ; + bool haveM = shptype == SHP_POLYLINEZ || shptype == SHP_POLYLINEM; + long count = 0; for (long j=0; j < oMLine->getNumGeometries(); j++) { @@ -524,8 +570,8 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, ComHelper::CreatePoint(&pnt); pnt->put_X(oLine->getX(i)); pnt->put_Y(oLine->getY(i)); - if (isM) pnt->put_M(oLine->getZ(i)); - else pnt->put_Z(oLine->getZ(i)); + if(haveZ) pnt->put_Z(oLine->getZ(i)); + if(haveM) pnt->put_M(oLine->getM(i)); shp->InsertPoint(pnt,&count,&retval); pnt->Release(); if (retval) count++; @@ -536,7 +582,7 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, } // (meant to be part of poly; but we'll treat it alone also) - else if (oType == wkbLinearRing) + else if (oType == wkbLinearRing) { OGRLinearRing* oRing; @@ -552,31 +598,34 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, shp->put_ShapeType(shptype); shp->InsertPart(0,&partIndex,&retval); + bool haveZ = shptype == SHP_POLYGONZ; + bool haveM = shptype == SHP_POLYGONZ || shptype == SHP_POLYGONM; + for(long i=0; i< oRing->getNumPoints(); i++) { ComHelper::CreatePoint(&pnt); pnt->put_X(oRing->getX(i)); pnt->put_Y(oRing->getY(i)); - if (isM) pnt->put_M(oRing->getZ(i)); - else pnt->put_Z(oRing->getZ(i)); + if(haveZ) pnt->put_Z(oRing->getZ(i)); + if(haveM) pnt->put_M(oRing->getM(i)); shp->InsertPoint(pnt,&i,&retval); pnt->Release(); } } - else if (oType == wkbPolygon || oType == wkbPolygon25D || oType == wkbPolygonZM || + else if (oType == wkbPolygon || oType == wkbPolygon25D || oType == wkbPolygonM || oType == wkbPolygonZM || oType == wkbMultiPolygon || oType == wkbMultiPolygon25D || oType == wkbMultiPolygonZM) { OGRPolygon* oPoly; OGRLinearRing** papoRings=NULL; int nRings = 0; - if ((oType == wkbPolygon25D || oType == wkbPolygonZM || oType == wkbMultiPolygon25D || oType == wkbMultiPolygonZM) || force25D) + if ((oType == wkbPolygon25D || oType == wkbPolygonM || oType == wkbPolygonZM || oType == wkbMultiPolygon25D || oType == wkbMultiLineStringM || oType == wkbMultiPolygonZM) || force25D) shptype = isM ? SHP_POLYGONM : SHP_POLYGONZ; else if (oType == wkbPolygon || oType == wkbMultiPolygon) shptype = SHP_POLYGON; - if (oType == wkbPolygon || oType == wkbPolygon25D || oType == wkbPolygonZM) + if (oType == wkbPolygon || oType == wkbPolygon25D || oType == wkbPolygonM || oType == wkbPolygonZM) { oPoly = (OGRPolygon *) oGeom; @@ -597,7 +646,7 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, } } - else if (oType == wkbMultiPolygon || oType == wkbMultiPolygon25D || oType == wkbMultiPolygonZM) + else if (oType == wkbMultiPolygon || oType == wkbMultiPolygon25D || oType == wkbMultiPolygonM || oType == wkbMultiPolygonZM) { OGRMultiPolygon* oMPoly = (OGRMultiPolygon *) oGeom; @@ -605,7 +654,7 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, { oPoly = (OGRPolygon *) oMPoly->getGeometryRef(iGeom); - if (oPoly->getGeometryType() == wkbPolygon || oPoly->getGeometryType() == wkbPolygon25D || oPoly->getGeometryType() == wkbPolygonZM) + if (oPoly->getGeometryType() == wkbPolygon || oPoly->getGeometryType() == wkbPolygon25D || oPoly->getGeometryType() == wkbPolygonM || oPoly->getGeometryType() == wkbPolygonZM) { if( oPoly->getExteriorRing() == NULL) continue; if (oPoly->getExteriorRing()->IsEmpty()) continue; @@ -631,7 +680,10 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, ComHelper::CreateShape(&shp); shp->put_ShapeType(shptype); - + + bool haveZ = shptype == SHP_POLYGONZ; + bool haveM = shptype == SHP_POLYGONZ || shptype == SHP_POLYGONM; + OGRLinearRing *oRing; long count = 0; @@ -645,8 +697,8 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, ComHelper::CreatePoint(&pnt); pnt->put_X(oRing->getX(i)); pnt->put_Y(oRing->getY(i)); - if (isM) pnt->put_M(oRing->getZ(i)); - else pnt->put_Z(oRing->getZ(i)); + if(haveZ) pnt->put_Z(oRing->getZ(i)); + if(haveM) pnt->put_M(oRing->getM(i)); shp->InsertPoint(pnt,&count,&retval); pnt->Release(); pnt = NULL; diff --git a/src/Shapefile/ShapeUtility.cpp b/src/Shapefile/ShapeUtility.cpp index 0ef538e0..ce230760 100644 --- a/src/Shapefile/ShapeUtility.cpp +++ b/src/Shapefile/ShapeUtility.cpp @@ -28,6 +28,17 @@ bool ShapeUtility::IsZ(const ShpfileType shpType) || shpType == SHP_POLYGONZ; } +// ************************************************************** +// HaveM() +// ************************************************************** +bool ShapeUtility::HaveM(const ShpfileType shpType) +{ + return shpType == SHP_POINTM || shpType == SHP_POINTZ + || shpType == SHP_MULTIPOINTM || shpType == SHP_MULTIPOINTZ + || shpType == SHP_POLYLINEM || shpType == SHP_POLYLINEZ + || shpType == SHP_POLYGONM || shpType == SHP_POLYGONZ; +} + // ************************************************************** // Convert2D() // ************************************************************** diff --git a/src/Shapefile/ShapeUtility.h b/src/Shapefile/ShapeUtility.h index d58b3433..37852081 100644 --- a/src/Shapefile/ShapeUtility.h +++ b/src/Shapefile/ShapeUtility.h @@ -8,6 +8,7 @@ class ShapeUtility static void SwapEndian(char* a, int size); static bool IsM(ShpfileType shpType); static bool IsZ(ShpfileType shpType); + static bool HaveM(const ShpfileType shpType); static ShpfileType Convert2D(ShpfileType shpType); static ShpfileType Get25DShapeType(ShpfileType shpTypeBase, bool isZ, bool isM); static IShapeWrapper* CreateWrapper(char* data, int recordLength, bool forceCom); From c1c6aa69f8b78fdbcbdee296c4f2bd2d3a91cb1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 09:36:23 +0200 Subject: [PATCH 02/55] =?UTF-8?q?Fixed=20opening/creating=20shapefile=20wi?= =?UTF-8?q?th=20=C3=A5=C3=A4=C3=B6=20in=20path/filename.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Shapefile/dbf.cpp | 4 ++-- src/Utilities/UtilityFunctions.cpp | 14 +++++++++++++- src/Utilities/UtilityFunctions.h | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Shapefile/dbf.cpp b/src/Shapefile/dbf.cpp index 53123d23..6764eccb 100644 --- a/src/Shapefile/dbf.cpp +++ b/src/Shapefile/dbf.cpp @@ -12,7 +12,7 @@ DBFHandle SHPAPI_CALL DBFOpen_MW( CStringW pszFilename, const char * pszAccess ) { - CStringA nameA = Utility::ConvertToUtf8(pszFilename); + CStringA nameA = Utility::ConvertToAnsi1252(pszFilename); m_globalSettings.SetGdalUtf8(true); DBFHandle handle = DBFOpen(nameA, pszAccess); m_globalSettings.SetGdalUtf8(false); @@ -21,7 +21,7 @@ DBFHandle SHPAPI_CALL DBFOpen_MW( CStringW pszFilename, const char * pszAccess ) DBFHandle SHPAPI_CALL DBFCreate_MW( CStringW nameW ) { - CStringA nameA = Utility::ConvertToUtf8(nameW); + CStringA nameA = Utility::ConvertToAnsi1252(nameW); m_globalSettings.SetGdalUtf8(true); DBFHandle handle = DBFCreate(nameA); m_globalSettings.SetGdalUtf8(false); diff --git a/src/Utilities/UtilityFunctions.cpp b/src/Utilities/UtilityFunctions.cpp index a8d70a24..906345b3 100644 --- a/src/Utilities/UtilityFunctions.cpp +++ b/src/Utilities/UtilityFunctions.cpp @@ -1,4 +1,4 @@ -#include "StdAfx.h" +#include "StdAfx.h" #include #include #include "macros.h" @@ -39,6 +39,15 @@ namespace Utility return utf8; } + // ******************************************************** + // ConvertToAnsi1252() + // ******************************************************** + CStringA ConvertToAnsi1252(CStringW unicode) { + USES_CONVERSION; + CStringA acp = CW2A(unicode, CP_ACP); + return acp; + } + // ******************************************************** // ConvertFromUtf8() // ******************************************************** @@ -705,6 +714,9 @@ namespace Utility } break; } + case admMetricMeters: + localizedUnits = lsSquareMeters; + break; case admHectars: { area /= 10000.0; diff --git a/src/Utilities/UtilityFunctions.h b/src/Utilities/UtilityFunctions.h index aefc94d9..d0d6905f 100644 --- a/src/Utilities/UtilityFunctions.h +++ b/src/Utilities/UtilityFunctions.h @@ -18,7 +18,8 @@ namespace Utility CString UrlEncode(CString s); CStringW XmlFilenameToUnicode(CStringA s, bool utf8); - CStringA ConvertToUtf8(CStringW unicode); + CStringA ConvertToUtf8(CStringW unicode); + CStringA ConvertToAnsi1252(CStringW unicode); CStringW ConvertFromUtf8(CStringA utf8); CString GetSocketErrorMessage(DWORD socketError); From 965aa6988c81d557da1ca4d7b130a7a355cbeb6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 09:50:13 +0200 Subject: [PATCH 03/55] IK-82 - try to convert from GCP to GeoTransform, with looser tolerances (ApproxOK = True) (if we have GCP) --- src/Image/GdalRaster.cpp | 13 +++++++++++++ src/Ogr/OgrConverter.cpp | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Image/GdalRaster.cpp b/src/Image/GdalRaster.cpp index a362fece..4f298e11 100644 --- a/src/Image/GdalRaster.cpp +++ b/src/Image/GdalRaster.cpp @@ -362,6 +362,19 @@ bool GdalRaster::ReadGeoTransform() double adfGeoTransform[6]; bool success = _dataset->GetGeoTransform(adfGeoTransform) == CE_None; + if (!success) { + // IK-82, try to convert from GCP to GeoTransform, with looser tolerances (ApproxOK = True) (if we have GCP) + auto count = _dataset->GetGCPCount(); + if (count > 0) + { + auto gcps = _dataset->GetGCPs(); + success = CPL_TO_BOOL(GDALGCPsToGeoTransform(count, gcps, adfGeoTransform, TRUE)); + CString sOutput; + sOutput.AppendFormat("GDALGCPsToGeoTransform(%d,..,TRUE): return: %s\r\n", count, success ? "true" : "false"); + ::OutputDebugStringA(sOutput.GetBuffer()); + } + } + m_globalSettings.SetGdalUtf8(false); if (!success) return false; diff --git a/src/Ogr/OgrConverter.cpp b/src/Ogr/OgrConverter.cpp index af1350be..478ec3dc 100644 --- a/src/Ogr/OgrConverter.cpp +++ b/src/Ogr/OgrConverter.cpp @@ -120,7 +120,7 @@ OGRGeometry* OgrConverter::ShapeToGeometry(IShape* shape, OGRwkbGeometryType for long beg_part, end_part; ShpfileType shptype; double x,y,z,m; - + shp->get_ShapeType(&shptype); shp->get_NumParts(&numParts); shp->get_NumPoints(&numPoints); From 1f6ca146ee40afacfc6cf268837d946d0adeca0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 10:02:44 +0200 Subject: [PATCH 04/55] Added edit support for geometry with X and M. --- src/COM classes/ShapeEditor.cpp | 79 +++++++++++++++++++++++++++---- src/COM classes/ShapeEditor.h | 6 +++ src/Editor/ActiveShape.cpp | 8 ++-- src/Editor/ActiveShape.h | 5 +- src/Editor/MeasuringBase.cpp | 2 +- src/MapControl/Map_Edit.cpp | 18 ++++++- src/MapControl/Map_Events.cpp | 56 +++++++++++++++++++--- src/Shapefile/ShapeWrapper.cpp | 2 +- src/Shapefile/ShapeWrapperCOM.cpp | 30 +++++++++++- src/Structures/Structures.h | 12 ++++- 10 files changed, 195 insertions(+), 23 deletions(-) diff --git a/src/COM classes/ShapeEditor.cpp b/src/COM classes/ShapeEditor.cpp index cace166e..b8561279 100644 --- a/src/COM classes/ShapeEditor.cpp +++ b/src/COM classes/ShapeEditor.cpp @@ -173,6 +173,10 @@ STDMETHODIMP CShapeEditor::get_ValidatedShape(IShape** retVal) // ******************************************************* void CShapeEditor::CopyData(int firstIndex, int lastIndex, IShape* target ) { + ShpfileType shpType; + target->get_ShapeType(&shpType); + bool haveZ = ShapeUtility::IsZ(shpType); + bool haveM = ShapeUtility::HaveM(shpType); long index, partCount = 0; VARIANT_BOOL vb; for(int i = firstIndex; i < lastIndex; i++) @@ -180,6 +184,12 @@ void CShapeEditor::CopyData(int firstIndex, int lastIndex, IShape* target ) MeasurePoint* pnt = _activeShape->GetPoint(i); if (pnt) { target->AddPoint(pnt->Proj.x, pnt->Proj.y, &index); + IPoint* pt; + target->get_Point(index, &pt); + if (haveZ) + pt->put_Z(pnt->z); + if (haveM) + pt->put_M(pnt->m); if (pnt->Part == PartBegin) { target->InsertPart(i, &partCount, &vb); partCount++; @@ -345,11 +355,13 @@ STDMETHODIMP CShapeEditor::StartEdit(LONG LayerHandle, LONG ShapeIndex, VARIANT_ if (list) { list->get_UndoCount(&_startingUndoCount); } - + + _startedEditOnInvalidShape = false; CComPtr shp = NULL; sf->get_Shape(ShapeIndex, &shp); if (shp) { + _startedEditOnInvalidShape = !Validate(&shp); put_EditorState(esEdit); SetShape(shp); _layerHandle = LayerHandle; @@ -391,9 +403,12 @@ STDMETHODIMP CShapeEditor::SetShape( IShape* shp ) } VARIANT_BOOL vb; - double x, y; + double x, y, z, m; shp->get_NumPoints(&numPoints); + bool haveZ = ShapeUtility::IsZ(shpType); + bool haveM = ShapeUtility::HaveM(shpType); + for(long i = 0; i < numPoints; i++) { PointPart part = PartNone; @@ -401,7 +416,15 @@ STDMETHODIMP CShapeEditor::SetShape( IShape* shp ) if (endParts.find(i) != endParts.end()) part = PartEnd; shp->get_XY(i, &x, &y, &vb); - _activeShape->AddPoint(x, y, -1, -1, part); + if(haveZ) + shp->get_Z(i, &z, &vb); + else + z = 0.0; + if(haveM) + shp->get_M(i, &m, &vb); + else + m = 0.0; + _activeShape->AddPoint(x, y, z, m, -1, -1, part); } return S_OK; } @@ -717,11 +740,13 @@ STDMETHODIMP CShapeEditor::AddPoint(IPoint *newPoint, VARIANT_BOOL* retVal) get_IsDigitizing(&digitizing); tkCursorMode cursor = _mapCallback->_GetCursorMode(); if (digitizing) { - double x, y; + double x, y, z, m; newPoint->get_X(&x); newPoint->get_Y(&y); + newPoint->get_Z(&z); + newPoint->get_Z(&m); newPoint->Release(); - _activeShape->AddPoint(x, y, -1, -1, PartBegin); + _activeShape->AddPoint(x, y, z, m, -1, -1, PartBegin); *retVal = VARIANT_TRUE; return S_OK; } @@ -1167,6 +1192,8 @@ bool CShapeEditor::TryStop() CComPtr shp = NULL; get_ValidatedShape(&shp); + if (!shp && _startedEditOnInvalidShape ) // Invalid so get the invalid raw shape if we started with invalid shape (IK-379) + get_RawData(&shp); switch (_state) { @@ -1183,8 +1210,9 @@ bool CShapeEditor::TryStop() VARIANT_BOOL isEmpty; get_IsEmpty(&isEmpty); if (isEmpty) return true; - if (!shp) return false; - bool result = TrySaveShape(shp); + if (!shp && !_activeShape->AllowSaveInvalidGeometry) return false; + if( shp ) // Only try to save if we have a shape (IK-379) + bool result = TrySaveShape(shp); SetRedrawNeeded(rtVolatileLayer); break; } @@ -1277,8 +1305,9 @@ void CShapeEditor::HandleProjPointAdd(double projX, double projY) { double pixelX, pixelY; _mapCallback->_ProjectionToPixel(projX, projY, &pixelX, &pixelY); - _activeShape->AddPoint(projX, projY, pixelX, pixelY); + _activeShape->AddPoint(projX, projY, 0.0, 0.0, pixelX, pixelY); _activeShape->ClearSnapPoint(); + _mapCallback->_FireVertexAdded(&projX, &projY); } // *************************************************************** @@ -1783,3 +1812,37 @@ STDMETHODIMP CShapeEditor::Deserialize(BSTR state, VARIANT_BOOL* retVal) return S_OK; } + +// *************************************************************** +// EnableInsertVertex() +// *************************************************************** +STDMETHODIMP CShapeEditor::get_EnableInsertVertex(VARIANT_BOOL* pVal) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()); + *pVal = _activeShape->EnableInsertVertex; + return S_OK; +} + +STDMETHODIMP CShapeEditor::put_EnableInsertVertex(VARIANT_BOOL newVal) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()); + _activeShape->EnableInsertVertex = newVal ? true : false; + return S_OK; +} + +// *************************************************************** +// AllowSaveInvalidGeometry() +// *************************************************************** +STDMETHODIMP CShapeEditor::get_AllowSaveInvalidGeometry(VARIANT_BOOL* pVal) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()); + *pVal = _activeShape->AllowSaveInvalidGeometry; + return S_OK; +} + +STDMETHODIMP CShapeEditor::put_AllowSaveInvalidGeometry(VARIANT_BOOL newVal) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()); + _activeShape->AllowSaveInvalidGeometry = newVal ? true : false; + return S_OK; +} \ No newline at end of file diff --git a/src/COM classes/ShapeEditor.h b/src/COM classes/ShapeEditor.h index a384757f..66622108 100644 --- a/src/COM classes/ShapeEditor.h +++ b/src/COM classes/ShapeEditor.h @@ -162,6 +162,7 @@ class ATL_NO_VTABLE CShapeEditor : double _snapTolerance; tkLayerSelection _snapBehavior; EditorBase* _activeShape; + bool _startedEditOnInvalidShape; long _layerHandle; long _shapeIndex; long _lastErrorCode; @@ -256,5 +257,10 @@ class ATL_NO_VTABLE CShapeEditor : STDMETHOD(put_ShowLength)(VARIANT_BOOL newVal); STDMETHOD(Serialize)(BSTR* retVal); STDMETHOD(Deserialize)(BSTR state, VARIANT_BOOL* retVal); + STDMETHOD(get_EnableInsertVertex)(VARIANT_BOOL* pVal); + STDMETHOD(put_EnableInsertVertex)(VARIANT_BOOL newVal); + STDMETHOD(get_AllowSaveInvalidGeometry)(VARIANT_BOOL* pVal); + STDMETHOD(put_AllowSaveInvalidGeometry)(VARIANT_BOOL newVal); + }; OBJECT_ENTRY_AUTO(__uuidof(ShapeEditor), CShapeEditor) diff --git a/src/Editor/ActiveShape.cpp b/src/Editor/ActiveShape.cpp index f1e0c13c..06edd382 100644 --- a/src/Editor/ActiveShape.cpp +++ b/src/Editor/ActiveShape.cpp @@ -677,7 +677,7 @@ bool ActiveShape::HandlePointAdd(const double screenX, const double screenY, con PixelToProj(screenX, screenY, projX, projY); } - AddPoint(projX, projY, screenX, screenY); + AddPoint(projX, projY, 0.0, 0.0, screenX, screenY); UpdatePolyCloseState(true, closePointIndex); @@ -687,7 +687,7 @@ bool ActiveShape::HandlePointAdd(const double screenX, const double screenY, con // ******************************************************* // AddPoint() // ******************************************************* -void ActiveShape::AddPoint(const double xProj, const double yProj, const double xScreen, const double yScreen, const PointPart part) +void ActiveShape::AddPoint(const double xProj, const double yProj, const double z, const double m, const double xScreen, const double yScreen, const PointPart part) { ClearIfStopped(); @@ -697,6 +697,8 @@ void ActiveShape::AddPoint(const double xProj, const double yProj, const double MeasurePoint* pnt = new MeasurePoint(); // TODO: Fix compile warning pnt->Proj.x = xProj; pnt->Proj.y = yProj; + pnt->z = z; + pnt->m = m; pnt->Part = part; _points.push_back(pnt); @@ -712,7 +714,7 @@ void ActiveShape::AddPoint(const double xProj, const double yProj) { double xScreen, yScreen; ProjToPixel(xProj, yProj, xScreen, yScreen); - AddPoint(xProj, yProj, xScreen, yScreen); + AddPoint(xProj, yProj, 0.0, 0.0, xScreen, yScreen); } // ************************************************************** diff --git a/src/Editor/ActiveShape.h b/src/Editor/ActiveShape.h index 8eb2747b..41a1d924 100644 --- a/src/Editor/ActiveShape.h +++ b/src/Editor/ActiveShape.h @@ -53,6 +53,7 @@ class ActiveShape : public GeoShape ShowLength = true; ShowTotalLength = true; ShowArea = true; + EnableInsertVertex = true; }; virtual ~ActiveShape() { @@ -117,6 +118,8 @@ class ActiveShape : public GeoShape tkAreaDisplayMode AreaDisplayMode; tkBearingType BearingType; tkAngleFormat AngleFormat; + bool EnableInsertVertex; + bool AllowSaveInvalidGeometry; OLE_COLOR FillColor; OLE_COLOR LineColor; @@ -155,7 +158,7 @@ class ActiveShape : public GeoShape virtual bool UndoPoint(); virtual bool GetPartStartAndEnd(int partIndex, MixedShapePart whichPoints, int& startIndex, int& endIndex); ShapeInputMode GetInputMode() const { return _inputMode; } - void AddPoint(double xProj, double yProj, double xScreen, double yScreen, PointPart part = PartNone); + void AddPoint(double xProj, double yProj, const double z, const double m, double xScreen, double yScreen, PointPart part = PartNone); void AddPoint(double xProj, double yProj); bool HandlePointAdd(double screenX, double screenY, bool ctrl); int GetPointCount() const { return gsl::narrow_cast(_points.size()); } diff --git a/src/Editor/MeasuringBase.cpp b/src/Editor/MeasuringBase.cpp index 9b9e92aa..ea57229c 100644 --- a/src/Editor/MeasuringBase.cpp +++ b/src/Editor/MeasuringBase.cpp @@ -77,7 +77,7 @@ void MeasuringBase::HandleProjPointAdd(double projX, double projY) { double pixelX, pixelY; _mapCallback->_ProjectionToPixel(projX, projY, &pixelX, &pixelY); - AddPoint(projX, projY, pixelX, pixelY); + AddPoint(projX, projY, 0.0, 0.0, pixelX, pixelY); } // ******************************************************* diff --git a/src/MapControl/Map_Edit.cpp b/src/MapControl/Map_Edit.cpp index d34ba7f3..b9f17391 100644 --- a/src/MapControl/Map_Edit.cpp +++ b/src/MapControl/Map_Edit.cpp @@ -32,6 +32,9 @@ bool CMapView::HandleLButtonUpDragVertexOrShape(UINT nFlags) bool shift = (nFlags & MK_SHIFT) != 0; bool alt = GetKeyState(VK_MENU) < 0 ? true : false; + // dhe + alt = true; + if (SnappingIsOn(shift)) { VARIANT_BOOL result = this->FindSnapPointCore(_dragging.Move.x, _dragging.Move.y, &x2, &y2); @@ -39,8 +42,11 @@ bool CMapView::HandleLButtonUpDragVertexOrShape(UINT nFlags) return true; // can't proceed without snapping in this mode } + int selectedVertex; + auto ret = _shapeEditor->get_SelectedVertex(&selectedVertex); + if (alt) { // user wants to intercept coordinates and possibly modify them - this->FireBeforeVertexDigitized(&x2, &y2); + this->FireBeforeVertexDigitized(&x2, &y2, selectedVertex); } GetEditorBase()->MoveVertex(x2, y2); // don't save state; it's already saved at the beginning of operation @@ -88,8 +94,18 @@ bool CMapView::HandleOnMouseMoveShapeEditor(int x, int y, long nFlags) // get Snap setting _shapeEditor->get_SnapBehavior(&snapBehavior); +#if DEBUG_ALLOCATED_OBJECTS + ComHelper::SetBreak(false); + auto preCount = gReferenceCounter.GetReferenceCount(); +#endif double projX, projY; VARIANT_BOOL snapped = FindSnapPointCore(x, y, &projX, &projY); +#if DEBUG_ALLOCATED_OBJECTS + auto postCount = gReferenceCounter.GetReferenceCount(); + if (preCount < postCount) + ::OutputDebugStringA("Increased!"); + ComHelper::SetBreak(false); +#endif if (!snapped) { PixelToProjection(x, y, projX, projY); GetEditorBase()->ClearSnapPoint(); diff --git a/src/MapControl/Map_Events.cpp b/src/MapControl/Map_Events.cpp index 69108b35..a3db8a2b 100644 --- a/src/MapControl/Map_Events.cpp +++ b/src/MapControl/Map_Events.cpp @@ -551,15 +551,15 @@ void CMapView::OnLButtonDown(UINT nFlags, CPoint point) if (m_cursorMode == cmAddShape) { if (StartNewBoundShape(projX, projY) != VARIANT_TRUE) return; } - if (alt) { // user wants to intercept coordinates and possibly modify them - this->FireBeforeVertexDigitized(&projX, &projY); + this->FireBeforeVertexDigitized(&projX, &projY, -1); } if (Digitizer::OnMouseDown(_shapeEditor, projX, projY, ctrl)) { + //this->FireVertexAdded(&projX, &projY); UpdateShapeEditor(); } - + return; } @@ -568,13 +568,29 @@ void CMapView::OnLButtonDown(UINT nFlags, CPoint point) { case cmEditShape: { + if( m_sendMouseDown == TRUE ) + this->FireMouseDown(MK_LBUTTON, (short)vbflags, x, y); if (!VertexEditor::OnMouseDown(this, _shapeEditor, projX, projY, ctrl, shift)) { +#if DEBUG_ALLOCATED_OBJECTS + ComHelper::SetBreak(true); + auto preCount = gReferenceCounter.GetReferenceCount(); +#endif long layerHandle, shapeIndex; if (SelectShapeForEditing(x, y, layerHandle, shapeIndex)) { VertexEditor::StartEdit(_shapeEditor, layerHandle, shapeIndex); } +#if DEBUG_ALLOCATED_OBJECTS + auto postCount = gReferenceCounter.GetReferenceCount(); + if (preCount < postCount) + { + ::OutputDebugStringA("Increased!"); + auto report = gReferenceCounter.GetReferenceReport(); + ::OutputDebugStringA(report.GetBuffer()); + } + ComHelper::SetBreak(false); +#endif } UpdateShapeEditor(); } @@ -631,7 +647,9 @@ void CMapView::OnLButtonDown(UINT nFlags, CPoint point) break; case cmZoomOut: { - ZoomToCursorPosition(false); + //ZoomToCursorPosition(false); + this->SetCapture(); + _dragging.Operation = DragZoombox; break; } case cmPan: @@ -694,12 +712,14 @@ void CMapView::OnLButtonDblClk(UINT nFlags, CPoint point) bool alt = GetKeyState(VK_MENU) < 0 ? true : false; if (alt) { // user wants to intercept coordinates and possibly modify them - this->FireBeforeVertexDigitized(&projX, &projY); + this->FireBeforeVertexDigitized(&projX, &projY, -1); } if (_shapeEditor->GetClosestPoint(projX, projY, projX, projY)) { - if (_shapeEditor->InsertVertex(projX, projY)) { + VARIANT_BOOL enableInsertVertex; + _shapeEditor->get_EnableInsertVertex(&enableInsertVertex); + if (enableInsertVertex && _shapeEditor->InsertVertex(projX, projY)) { RedrawCore(tkRedrawType::RedrawSkipDataLayers, true); return; } @@ -785,7 +805,13 @@ void CMapView::OnLButtonUp(UINT nFlags, CPoint point) case DragZoombox: case DragSelectionBox: { +#if DEBUG_ALLOCATED_OBJECTS + ComHelper::SetBreak(false); +#endif HandleLButtonUpZoomBox(vbflags, point.x, point.y); +#if DEBUG_ALLOCATED_OBJECTS + ComHelper::SetBreak(false); +#endif } break; } @@ -955,6 +981,9 @@ void CMapView::HandleLButtonUpZoomBox(long vbflags, long x, long y) case cmZoomIn: ZoomToCursorPosition(true); break; + case cmZoomOut: + ZoomToCursorPosition(false); + break; case cmSelection: if (sf || selectingSelectable) { @@ -1077,6 +1106,9 @@ void CMapView::HandleLButtonUpZoomBox(long vbflags, long x, long y) case cmZoomIn: SetNewExtentsWithForcedZooming(box, true); break; + case cmZoomOut: + SetNewExtentsWithZoomOut(box); + break; case cmSelection: if (sf) { @@ -1416,6 +1448,9 @@ void CMapView::OnMouseMove(UINT nFlags, CPoint point) if (updateHotTracking && _dragging.Operation == DragNone) { LayerShape info; +#if DEBUG_ALLOCATED_OBJECTS + ComHelper::SetBreak(false); +#endif HotTrackingResult result = RecalcHotTracking(point, info); switch (result) { @@ -1432,6 +1467,9 @@ void CMapView::OnMouseMove(UINT nFlags, CPoint point) // do nothing break; } +#if DEBUG_ALLOCATED_OBJECTS + ComHelper::SetBreak(false); +#endif } if (_showCoordinates != cdmNone) { @@ -1514,8 +1552,14 @@ void CMapView::OnRButtonDown(UINT nFlags, CPoint point) long vbflags = ParseKeyboardEventFlags(nFlags); +#if DEBUG_ALLOCATED_OBJECTS + ComHelper::SetBreak(false); +#endif if( m_sendMouseDown == TRUE ) this->FireMouseDown( MK_RBUTTON, (short)vbflags, point.x, point.y ); +#if DEBUG_ALLOCATED_OBJECTS + ComHelper::SetBreak(false); +#endif if (_doTrapRMouseDown) { diff --git a/src/Shapefile/ShapeWrapper.cpp b/src/Shapefile/ShapeWrapper.cpp index b61a4c5c..29139726 100644 --- a/src/Shapefile/ShapeWrapper.cpp +++ b/src/Shapefile/ShapeWrapper.cpp @@ -304,7 +304,7 @@ int CShapeWrapper::get_PartEndPoint(const int partIndex) } if (partIndex == gsl::narrow_cast(_parts.size()) - 1) { - return gsl::narrow_cast(_parts.size()) - 1; + return gsl::narrow_cast(_points.size()) - 1; } return _parts[partIndex + 1] - 1; } diff --git a/src/Shapefile/ShapeWrapperCOM.cpp b/src/Shapefile/ShapeWrapperCOM.cpp index addd14dd..82613a3c 100644 --- a/src/Shapefile/ShapeWrapperCOM.cpp +++ b/src/Shapefile/ShapeWrapperCOM.cpp @@ -471,21 +471,49 @@ bool CShapeWrapperCOM::InsertPointXYZM(const int pointIndex, const double x, con return false; } +bool PointIsXYEqual(IPoint* p1, IPoint* p2) +{ + double x1, x2, y1, y2; + p1->get_X(&x1); + p2->get_X(&x2); + p1->get_Y(&y1); + p2->get_Y(&y2); + return abs(x1 - x2) < 0.00001 && abs(y1 - y2) < 0.00001; +} + // ******************************************************** // DeletePoint() // ******************************************************** bool CShapeWrapperCOM::DeletePoint(const int pointIndex) { - if (pointIndex < 0 || pointIndex >= gsl::narrow_cast(_points.size())) + auto count = gsl::narrow_cast(_points.size()); + if (pointIndex < 0 || pointIndex >= count) { _lastErrorCode = tkINDEX_OUT_OF_BOUNDS; return false; } + const auto needToReClose = pointIndex == 0 && PointIsXYEqual(_points[count - 1], _points[0]); _points[pointIndex]->Release(); _points.erase(_points.begin() + pointIndex); + if (needToReClose) + { // First point is the last point (to close) + count = gsl::narrow_cast(_points.size()); + IPoint* pt; + auto hr = _points[0]->Clone(&pt); + if (FAILED(hr)) { + _lastErrorCode = tkINVALID_SHAPE; + return false; + } + auto replaceIndex = count - 1; + _points[replaceIndex]->Release(); + _points.erase(_points.begin() + replaceIndex); + pt->AddRef(); + _points.insert(_points.begin() + replaceIndex, pt); + } _boundsChanged = true; return true; } + #pragma endregion #pragma region Parts diff --git a/src/Structures/Structures.h b/src/Structures/Structures.h index 36429d61..c47a9ffe 100644 --- a/src/Structures/Structures.h +++ b/src/Structures/Structures.h @@ -57,12 +57,22 @@ struct MeasurePoint Point2D Proj; double x; // in decimal degrees double y; + double z; + double m; void CopyTo(MeasurePoint& pnt2) { pnt2.x = x; pnt2.y = y; + pnt2.z = z; + pnt2.m = m; pnt2.Proj = Proj; } - MeasurePoint() : Part(PartNone) {} + MeasurePoint() : Part(PartNone) + { + x = 0.0; + y = 0.0; + z = 0.0; + m = 0.0; + } }; struct OgrUpdateError From f7e0ad4aa796b2027eb74d877738b46be9f65781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 10:18:11 +0200 Subject: [PATCH 05/55] Added IPlacedLabels --- src/COM classes/LabelClass.cpp | 59 ++++++++++ src/COM classes/LabelClass.h | 4 + src/COM classes/Labels.cpp | 64 +++++++++++ src/COM classes/Labels.h | 10 +- src/COM classes/PlacedLabels.cpp | 49 +++++++++ src/COM classes/PlacedLabels.h | 58 ++++++++++ src/COM classes/PlacedLabels.rgs | 26 +++++ src/MapControl/DispIds.h | 7 +- src/MapControl/GlobalSettingsInfo.h | 4 +- src/MapControl/Map.cpp | 4 +- src/MapControl/Map.h | 16 ++- src/MapControl/MapViewCallback.h | 3 +- src/MapControl/Map_DispatchMap.cpp | 4 +- src/MapControl/Map_Drawing.cpp | 161 +++++++++++++++++++++++++++- src/MapControl/Map_DrawingLayer.cpp | 82 +++++++++++++- src/MapWinGIS.cpp | 5 +- src/MapWinGIS.h | 5 +- src/MapWinGIS.idl | 82 ++++++++++++-- src/MapWinGIS.rc | 9 +- src/Processing/GeometryHelper.cpp | 15 +++ src/Processing/GeometryHelper.h | 1 + src/Utilities/ComHelper.cpp | 3 + src/Utilities/ComHelper.h | 12 +++ 23 files changed, 656 insertions(+), 27 deletions(-) create mode 100644 src/COM classes/PlacedLabels.cpp create mode 100644 src/COM classes/PlacedLabels.h create mode 100644 src/COM classes/PlacedLabels.rgs diff --git a/src/COM classes/LabelClass.cpp b/src/COM classes/LabelClass.cpp index 2f7a469c..ffee92fa 100644 --- a/src/COM classes/LabelClass.cpp +++ b/src/COM classes/LabelClass.cpp @@ -93,3 +93,62 @@ STDMETHODIMP CLabelClass::get_ScreenExtents(IExtents** retval) } return S_OK; } + + +// *********************************************************** +// MapExtents +// *********************************************************** +STDMETHODIMP CLabelClass::get_MapExtents(double inversePixelPerProjection, IExtents** retVal) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + IExtents* ext = nullptr; + if(_label->horizontalFrame) + { + ComHelper::CreateExtents(&ext); + + auto width2 = (_label->horizontalFrame->right - _label->horizontalFrame->left) * inversePixelPerProjection / 2.0; + auto height2 = (_label->horizontalFrame->bottom - _label->horizontalFrame->top) * inversePixelPerProjection / 2.0; + ext->SetBounds(_label->x - width2, + _label->y - height2, + 0.0, + _label->x + width2, + _label->y + height2, + 0.0); + *retVal = ext; + } + else if(_label->rotatedFrame) + { + ComHelper::CreateExtents(&ext); + CRect* rect = _label->rotatedFrame->BoundingBox(); + auto width2 = (rect->right - rect->left) * inversePixelPerProjection / 2.0; + auto height2 = (rect->bottom - rect->top) * inversePixelPerProjection / 2.0; + ext->SetBounds(_label->x - width2, + _label->y - height2, + 0.0, + _label->x + width2, + _label->y + height2, + 0.0); + *retVal = ext; + } + else + *retVal = nullptr; + return S_OK; +} + +// ************************************************************ +// get/put_Key() +// ************************************************************ +STDMETHODIMP CLabelClass::get_Key(BSTR* pVal) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = OLE2BSTR(_label->key); + return S_OK; +} + +STDMETHODIMP CLabelClass::put_Key(BSTR newVal) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + SysFreeString(_label->key); + _label->key = OLE2BSTR(newVal); + return S_OK; +} diff --git a/src/COM classes/LabelClass.h b/src/COM classes/LabelClass.h index 79f64514..13451928 100644 --- a/src/COM classes/LabelClass.h +++ b/src/COM classes/LabelClass.h @@ -105,6 +105,10 @@ class ATL_NO_VTABLE CLabelClass : STDMETHOD(get_ScreenExtents)(IExtents** retval); + STDMETHOD(get_MapExtents)(double inversePixelPerProjection, IExtents** retVal); + + STDMETHOD(get_Key)(/*[out, retval]*/ BSTR* pVal); + STDMETHOD(put_Key)(/*[in]*/ BSTR newVal); private: CLabelInfo* _label; bool _canDelete; // CLabelInfo can be allocated locally, then we need to delete it diff --git a/src/COM classes/Labels.cpp b/src/COM classes/Labels.cpp index 592df6e0..26cc7a15 100644 --- a/src/COM classes/Labels.cpp +++ b/src/COM classes/Labels.cpp @@ -838,6 +838,44 @@ STDMETHODIMP CLabels::Select(IExtents* BoundingBox, long Tolerance, SelectMode S return S_OK; }; +// ***************************************************************** +// SelectNotDrawn() +// ***************************************************************** +// Selection of not drawn labels which fall in the given bounding box +STDMETHODIMP CLabels::SelectNotDrawn(IExtents* BoundingBox, VARIANT* LabelIndices, VARIANT* PartIndices, VARIANT_BOOL* retval) +{ + *retval = VARIANT_FALSE; + if (!BoundingBox) return S_OK; + double xMin, yMin, zMin, xMax, yMax, zMax; + BoundingBox->GetBounds(&xMin, &yMin, &zMin, &xMax, &yMax, &zMax); + + vector indices; + vector parts; + + for (unsigned long i = 0; i < _labels.size(); i++) + { + vector* labelParts = _labels[i]; + for (unsigned long j = 0; j < labelParts->size(); j++) + { + CLabelInfo* lbl = labelParts->at(j); + if (lbl->horizontalFrame == nullptr && lbl->rotatedFrame == nullptr) + { + auto isInside = GeometryHelper::PointInExtent(xMin, yMin, xMax, yMax, lbl->x, lbl->y); + if (isInside) + { + indices.push_back(i); + parts.push_back(j); + } + } + } + } + + bool result = Templates::Vector2SafeArray(&indices, VT_I4, LabelIndices); + *retval = Templates::Vector2SafeArray(&parts, VT_I4, PartIndices); + *retval = *retval && result; + + return S_OK; +} // ******************************************************************* // put_ParentShapefile() @@ -2909,3 +2947,29 @@ STDMETHODIMP CLabels::UpdateSizeField() return S_OK; } + + +// ************************************************************* +// get_LabelDrawnInMap() +// ************************************************************* +STDMETHODIMP CLabels::get_LabelDrawnInMap(long index, VARIANT_BOOL* pVal) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()); + + auto match = _drawnInMap.find(index); + *pVal = match != _drawnInMap.end(); + + return S_OK; +} + +// ************************************************************* +// AddDrawnLabel() +// ************************************************************* +void CLabels::AddDrawnLabel(long index) +{ + if (index == -1) // Reset + _drawnInMap.clear(); + else + _drawnInMap.insert(index); +} + diff --git a/src/COM classes/Labels.h b/src/COM classes/Labels.h index a41b9143..ec1c7857 100644 --- a/src/COM classes/Labels.h +++ b/src/COM classes/Labels.h @@ -26,6 +26,7 @@ #pragma once #include "LabelOptions.h" #include "LabelCategory.h" +#include #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA) #error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms." @@ -164,6 +165,8 @@ class ATL_NO_VTABLE CLabels : // selection STDMETHOD(Select)(IExtents* BoundingBox, long Tolerance, SelectMode SelectMode, VARIANT* LabelIndices, VARIANT* PartIndices, VARIANT_BOOL* retval); + STDMETHOD(SelectNotDrawn)(IExtents* BoundingBox, VARIANT* LabelIndices, VARIANT* PartIndices, VARIANT_BOOL* retval); + // ------------------------------------------------------ // Class-specific properties // ------------------------------------------------------ @@ -388,7 +391,8 @@ class ATL_NO_VTABLE CLabels : STDMETHOD(get_LogScaleForSize)(VARIANT_BOOL* pVal); STDMETHOD(put_LogScaleForSize)(VARIANT_BOOL newVal); STDMETHOD(UpdateSizeField)(); - + STDMETHOD(get_LabelDrawnInMap)(long index, VARIANT_BOOL* pVal); + private: int _sourceField; @@ -454,6 +458,7 @@ class ATL_NO_VTABLE CLabels : tkTextRenderingHint _textRenderingHint; VARIANT_BOOL _synchronized; + std::set _drawnInMap; private: inline void ErrorMessage(long errorCode); @@ -489,7 +494,8 @@ class ATL_NO_VTABLE CLabels : void LoadLblOptions(CPLXMLNode* node); bool RecalculateFontSize(); - + + void AddDrawnLabel(long index); }; diff --git a/src/COM classes/PlacedLabels.cpp b/src/COM classes/PlacedLabels.cpp new file mode 100644 index 00000000..1a5b66cd --- /dev/null +++ b/src/COM classes/PlacedLabels.cpp @@ -0,0 +1,49 @@ +// PlacedLabels.cpp : Implementation of CPlacedLabels + +#include "stdafx.h" +#include "PlacedLabels.h" + +// ***************************************************************** +// get_NumShapes() +// ***************************************************************** +STDMETHODIMP CPlacedLabels::get_NumIndex(long* pVal) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = static_cast(_indexes.size()); + return S_OK; +} + + +// ***************************************************************** +// GetIndexes() +// ***************************************************************** +STDMETHODIMP CPlacedLabels::GetIndexes(SAFEARRAY** retval) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *retval = SafeArrayCreateVector(VT_I4, 0, static_cast(_indexes.size())); + SafeArrayLock((*retval)); + auto pData = static_cast((*retval)->pvData); + for(size_t i = 0; i < _indexes.size(); i++) + { + pData[i] = _indexes[i]; + } + SafeArrayUnlock((*retval)); + + return S_OK; +} + + +// ***************************************************************** +// GetIndexes() +// ***************************************************************** +STDMETHODIMP CPlacedLabels::SetVector(int* indexes, const int length) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + + for(int i = 0; i < length; i++) + { + _indexes.push_back(indexes[i]); + } + + return S_OK; +} \ No newline at end of file diff --git a/src/COM classes/PlacedLabels.h b/src/COM classes/PlacedLabels.h new file mode 100644 index 00000000..3c73f37d --- /dev/null +++ b/src/COM classes/PlacedLabels.h @@ -0,0 +1,58 @@ +// PlacedLabels.h : Declaration of the CPlacedLabels +#pragma once + +#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA) +#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms." +#endif + +using namespace ATL; + +// CPlacedLabels +class ATL_NO_VTABLE CPlacedLabels : + public CComObjectRootEx, + public CComCoClass, + public IDispatchImpl +{ +public: + CPlacedLabels() + { + _pUnkMarshaler = nullptr; + //_hotTracking = VARIANT_TRUE; + //_mode = imAllLayers; + //_color = RGB(255, 0, 0); //RGB(30, 144, 255); + //_activeLayer = -1; + } + + DECLARE_REGISTRY_RESOURCEID(IDR_PLACEDLABELS) + + BEGIN_COM_MAP(CPlacedLabels) + COM_INTERFACE_ENTRY(IPlacedLabels) + COM_INTERFACE_ENTRY(IDispatch) + COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, _pUnkMarshaler.p) + END_COM_MAP() + + DECLARE_PROTECT_FINAL_CONSTRUCT() + + DECLARE_GET_CONTROLLING_UNKNOWN() + + HRESULT FinalConstruct() + { + return CoCreateFreeThreadedMarshaler(GetControllingUnknown(), &_pUnkMarshaler.p); + } + + void FinalRelease() + { + _pUnkMarshaler.Release(); + } + + CComPtr _pUnkMarshaler; + +public: + STDMETHOD(get_NumIndex)(/*[out, retval]*/ long* pVal); + STDMETHOD(GetIndexes)( /*[out, retval]*/ SAFEARRAY** retval); + STDMETHOD(SetVector)(int* indexes, int length); + +private: + std::vector _indexes; +}; +OBJECT_ENTRY_AUTO(__uuidof(PlacedLabels), CPlacedLabels) diff --git a/src/COM classes/PlacedLabels.rgs b/src/COM classes/PlacedLabels.rgs new file mode 100644 index 00000000..e7efc3dc --- /dev/null +++ b/src/COM classes/PlacedLabels.rgs @@ -0,0 +1,26 @@ +HKCR +{ + MapWinGIS.PlacedLabels.1 = s 'PlacedLabels Class' + { + CLSID = s '{92A8E8D4-617E-47A4-8180-82E24AD3C984}' + } + MapWinGIS.PlacedLabels = s 'PlacedLabels Class' + { + CLSID = s '{92A8E8D4-617E-47A4-8180-82E24AD3C984}' + CurVer = s 'MapWinGIS.PlacedLabels.1' + } + NoRemove CLSID + { + ForceRemove {92A8E8D4-617E-47A4-8180-82E24AD3C984} = s 'PlacedLabels Class' + { + ProgID = s 'MapWinGIS.PlacedLabels.1' + VersionIndependentProgID = s 'MapWinGIS.PlacedLabels' + ForceRemove 'Programmable' + InprocServer32 = s '%MODULE%' + { + val ThreadingModel = s 'Both' + } + 'TypeLib' = s '{C368D713-CC5F-40ED-9F53-F84FE197B96A}' + } + } +} diff --git a/src/MapControl/DispIds.h b/src/MapControl/DispIds.h index 5b418dfe..05183f53 100644 --- a/src/MapControl/DispIds.h +++ b/src/MapControl/DispIds.h @@ -3,6 +3,8 @@ enum { //{{AFX_DISP_ID(CMapView) // NOTE: ClassWizard will add and remove enumeration elements here // DO NOT EDIT what you see in these blocks of generated code ! // **ClassWizard is a thing of the past... feel free to edit this code. + dispidGetDrawingLabelExtents = 270L, + dispidPlaceAllMapLabels = 269L, dispidShowCoordinatesBackground = 268L, dispidSetLatitudeLongitude = 267L, dispidStartNewBoundShapeEx = 266L, @@ -19,7 +21,7 @@ enum { //{{AFX_DISP_ID(CMapView) dispidZoomToNext = 255L, dispidShowCoordinatesFormat = 254L, dispidLayerExtents = 253L, - dispidCustomDrawingFlags = 252L, + dispidCustomDrawingFlags = 252L, dispidFocusRectangle = 251L, dispidIdentifiedShapes = 250L, @@ -303,6 +305,7 @@ enum { //{{AFX_DISP_ID(CMapView) eventidLayerReprojectedIncomplete = 39L, eventidBeforeVertexDigitized = 40L, eventidSnapPointRequested = 41L, - eventidSnapPointFound = 42L + eventidSnapPointFound = 42L, + eventidFireVertexAdded = 43L //}}AFX_DISP_ID }; diff --git a/src/MapControl/GlobalSettingsInfo.h b/src/MapControl/GlobalSettingsInfo.h index 3f9ba2a7..97d9dc5d 100644 --- a/src/MapControl/GlobalSettingsInfo.h +++ b/src/MapControl/GlobalSettingsInfo.h @@ -108,7 +108,7 @@ struct GlobalSettingsInfo cacheDbfRecords = true; overrideLocalCallback = true; proxyAuthentication = asBasic; - httpUserAgent = "MapWinGIS/5.4"; // TODO Use VERSION Macros + httpUserAgent = "MapWinGIS/5.5"; // TODO Use VERSION Macros hereAppId = ""; hereAppCode = ""; bingApiKey = ""; @@ -180,7 +180,7 @@ struct GlobalSettingsInfo shortUnitStrings[lsMeters] = L"m"; shortUnitStrings[lsKilometers] = L"km"; shortUnitStrings[lsSquareKilometers] = L"sq.km"; - shortUnitStrings[lsSquareMeters] = L"sq.m"; + shortUnitStrings[lsSquareMeters] = L"m²"; shortUnitStrings[lsMapUnits] = L"mu"; shortUnitStrings[lsSquareMapUnits] = L"sq.mu"; shortUnitStrings[lsMiles] = L"mi"; diff --git a/src/MapControl/Map.cpp b/src/MapControl/Map.cpp index c7090e5a..ef3202dd 100644 --- a/src/MapControl/Map.cpp +++ b/src/MapControl/Map.cpp @@ -146,9 +146,11 @@ BEGIN_EVENT_MAP(CMapView, COleControl) EVENT_CUSTOM_ID("BeforeLayers", eventidBeforeLayers, FireBeforeLayers, VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4) EVENT_CUSTOM_ID("AfterLayers", eventidAfterLayers, FireAfterLayers, VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4) EVENT_CUSTOM_ID("LayerReprojectedIncomplete", eventidLayerReprojectedIncomplete, FireLayerReprojectedIncomplete, VTS_I4 VTS_I4 VTS_I4) - EVENT_CUSTOM_ID("BeforeVertexDigitized", eventidBeforeVertexDigitized, FireBeforeVertexDigitized, VTS_PR8 VTS_PR8) + EVENT_CUSTOM_ID("BeforeVertexDigitized", eventidBeforeVertexDigitized, FireBeforeVertexDigitized, VTS_PR8 VTS_PR8 VTS_I4) EVENT_CUSTOM_ID("SnapPointRequested", eventidSnapPointRequested, FireSnapPointRequested, VTS_R8 VTS_R8 VTS_PR8 VTS_PR8 VTS_PI4 VTS_PI4) EVENT_CUSTOM_ID("SnapPointFound", eventidSnapPointFound, FireSnapPointFound, VTS_R8 VTS_R8 VTS_PR8 VTS_PR8) + EVENT_CUSTOM_ID("VertexAdded", eventidFireVertexAdded, FireVertexAdded, VTS_R8 VTS_R8) + EVENT_STOCK_DBLCLICK() //}}AFX_EVENT_MAP diff --git a/src/MapControl/Map.h b/src/MapControl/Map.h index fcc01f71..b56f0287 100644 --- a/src/MapControl/Map.h +++ b/src/MapControl/Map.h @@ -632,6 +632,9 @@ class CMapView : public COleControl, IMapViewCallback afx_msg VARIANT_BOOL GetRecenterMapOnZoom(); afx_msg void SetShowCoordinatesBackground(VARIANT_BOOL nNewValue); afx_msg VARIANT_BOOL GetShowCoordinatesBackground(); + afx_msg IPlacedLabels* PlaceAllMapLabels(long layerHandle); + afx_msg IExtents* GetDrawingLabelExtents(VARIANT* values); // long layerHandle, long index + #pragma endregion //}}AFX_DISPATCH @@ -707,9 +710,13 @@ class CMapView : public COleControl, IMapViewCallback { FireEvent(eventidValidateShape, EVENT_PARAM(VTS_I4 VTS_DISPATCH VTS_PI4), LayerHandle, Shape, Cancel); } - void FireBeforeVertexDigitized(DOUBLE* pointX, DOUBLE* pointY) + void FireBeforeVertexDigitized(DOUBLE* pointX, DOUBLE* pointY, long selectedVertex) + { + FireEvent(eventidBeforeVertexDigitized, EVENT_PARAM(VTS_PR8 VTS_PR8 VTS_I4), pointX, pointY, selectedVertex); + } + void FireVertexAdded(DOUBLE* pointX, DOUBLE* pointY) { - FireEvent(eventidBeforeVertexDigitized, EVENT_PARAM(VTS_PR8 VTS_PR8), pointX, pointY); + FireEvent(eventidFireVertexAdded, EVENT_PARAM(VTS_PR8 VTS_PR8), pointX, pointY); } void FireSnapPointRequested(DOUBLE pointX, DOUBLE pointY, DOUBLE* snappedX, DOUBLE* snappedY, tkMwBoolean* isFound, tkMwBoolean* isFinal) { @@ -1052,6 +1059,7 @@ class CMapView : public COleControl, IMapViewCallback CString Crypt(CString str); bool VerifySerial(CString str); void DrawLayers(const CRect& rcBounds, Gdiplus::Graphics* graphics, bool layerBuffer = true); + int* PlaceLabels(const CRect& rcBounds, Gdiplus::Graphics* graphics, bool layerBuffer); bool HasImages(); bool HasHotTracking(); bool HasVolatileShapefiles(); @@ -1158,6 +1166,7 @@ class CMapView : public COleControl, IMapViewCallback void SetTempExtents(double left, double right, double top, double bottom, long Width, long Height); void RestoreExtents(); void SetNewExtentsWithForcedZooming(Extent ext, bool zoomIn); + void SetNewExtentsWithZoomOut(Extent ext); IExtents* GetMaxExtents(); DOUBLE DegreesPerMapUnit(); double UnitsPerPixel(); @@ -1360,7 +1369,8 @@ class CMapView : public COleControl, IMapViewCallback virtual void _FireValidateShape(const LONG layerHandle, IDispatch* shape, tkMwBoolean* cancel) { FireValidateShape(layerHandle, shape, cancel); } virtual void _FireAfterShapeEdit(const tkUndoOperation newShape, const LONG layerHandle, const LONG shapeIndex) { FireAfterShapeEdit(newShape, layerHandle, shapeIndex); } virtual void _FireShapeValidationFailed(const LPCTSTR errorMessage) { FireShapeValidationFailed(errorMessage); } - virtual void _FireBeforeVertexDigitized(DOUBLE* pointX, DOUBLE* pointY) { FireBeforeVertexDigitized(pointX, pointY); } + virtual void _FireBeforeVertexDigitized(DOUBLE* pointX, DOUBLE* pointY, long selectedVertex) { FireBeforeVertexDigitized(pointX, pointY, selectedVertex); } + virtual void _FireVertexAdded(DOUBLE* pointX, DOUBLE* pointY) { FireVertexAdded(pointX, pointY); } virtual void _ZoomToEditor() { ZoomToEditor(); } virtual void _SetMapCursor(const tkCursorMode mode, bool clearEditor) { UpdateCursor(mode, false); } virtual void _Redraw(const tkRedrawType redrawType, const bool updateTiles, const bool atOnce) { RedrawCore(redrawType, atOnce, updateTiles); }; diff --git a/src/MapControl/MapViewCallback.h b/src/MapControl/MapViewCallback.h index 53245955..2be2f24f 100644 --- a/src/MapControl/MapViewCallback.h +++ b/src/MapControl/MapViewCallback.h @@ -18,7 +18,8 @@ class IMapViewCallback virtual void _FireValidateShape(LONG LayerHandle, IDispatch* Shape, tkMwBoolean* Cancel) = 0; virtual void _FireAfterShapeEdit(tkUndoOperation action, LONG LayerHandle, LONG ShapeIndex) = 0; virtual void _FireShapeValidationFailed(LPCTSTR ErrorMessage) = 0; - virtual void _FireBeforeVertexDigitized(DOUBLE* pointX, DOUBLE* pointY) = 0; + virtual void _FireBeforeVertexDigitized(DOUBLE* pointX, DOUBLE* pointY, long selectedVertex) = 0; + virtual void _FireVertexAdded(DOUBLE* pointX, DOUBLE* pointY) = 0; virtual void _ZoomToEditor() = 0; virtual void _SetMapCursor(tkCursorMode mode, bool clearEditor) = 0; virtual void _Redraw(tkRedrawType redrawType, bool updateTiles, bool atOnce) = 0; diff --git a/src/MapControl/Map_DispatchMap.cpp b/src/MapControl/Map_DispatchMap.cpp index c24edce6..a2c34800 100644 --- a/src/MapControl/Map_DispatchMap.cpp +++ b/src/MapControl/Map_DispatchMap.cpp @@ -295,7 +295,9 @@ BEGIN_DISPATCH_MAP(CMapView, COleControl) DISP_FUNCTION_ID(CMapView, "RestartBackgroundLoading", dispidRestartBackgroundLoading, RestartBackgroundLoading, VT_EMPTY, VTS_I4) DISP_FUNCTION_ID(CMapView, "StartNewBoundShape", dispidStartNewBoundShape, StartNewBoundShape, VT_BOOL, VTS_R8 VTS_R8) DISP_FUNCTION_ID(CMapView, "StartNewBoundShapeEx", dispidStartNewBoundShapeEx, StartNewBoundShapeEx, VT_BOOL, VTS_I4) - DISP_PROPERTY_EX_ID(CMapView, "ShowCoordinatesBackground", dispidShowCoordinatesBackground, GetShowCoordinatesBackground, SetShowCoordinatesBackground, VT_BOOL) + DISP_PROPERTY_EX_ID(CMapView, "ShowCoordinatesBackground", dispidShowCoordinatesBackground, GetShowCoordinatesBackground, SetShowCoordinatesBackground, VT_BOOL) + DISP_FUNCTION_ID(CMapView, "PlaceAllMapLabels", dispidPlaceAllMapLabels, PlaceAllMapLabels, VT_DISPATCH, VTS_I4) + DISP_FUNCTION_ID(CMapView, "GetDrawingLabelExtents", dispidGetDrawingLabelExtents, GetDrawingLabelExtents, VT_DISPATCH, VTS_VARIANT) END_DISPATCH_MAP() //}}AFX_DISPATCH_MAP diff --git a/src/MapControl/Map_Drawing.cpp b/src/MapControl/Map_Drawing.cpp index ed041839..f6977d94 100644 --- a/src/MapControl/Map_Drawing.cpp +++ b/src/MapControl/Map_Drawing.cpp @@ -124,8 +124,13 @@ void CMapView::HandleNewDrawing(CDC* pdc, const CRect& rcBounds, const CRect& rc // passing main buffer to client for custom drawing FireOnDrawbackBufferCore(g, _isSnapshot ? NULL : _bufferBitmap); } - +#if DEBUG_ALLOCATED_OBJECTS + ComHelper::SetBreak(false); +#endif RedrawTools(g, rcBounds); +#if DEBUG_ALLOCATED_OBJECTS + ComHelper::SetBreak(false); +#endif // redraw time and logo DWORD endTick = GetTickCount(); @@ -336,6 +341,8 @@ void CMapView::RedrawWmsLayers(Gdiplus::Graphics* g) gWms->Clear(Gdiplus::Color::Transparent); } + //manager->VerifyLayers(); + TilesDrawer drawer(gWms, &_extents, _pixelPerProjectionX, _pixelPerProjectionY, PixelsPerMapUnit(), GetWgs84ToMapTransform()); drawer.DrawTiles(manager, GetMapProjection(), _isSnapshot, _projectionChangeCount); @@ -1047,7 +1054,11 @@ void CMapView::DrawImageLayer(const CRect& rcBounds, Layer* l, Gdiplus::Graphics iimg->get_OriginalWidth(&width); iimg->get_OriginalHeight(&height); +#if BIG_TILE_SIZE + if ((width == 512 && height == 512) || _isSnapshot) +#else if ((width == 256 && height == 256) || _isSnapshot) +#endif { // it's tiles, I don't want to cache bitmap here to avoid seams // the same thing with Snapshot calls @@ -1477,7 +1488,155 @@ void CloseMapRotation() // TODO: implement } +// ****************************************************************** +// PlaceLabels() +// ****************************************************************** +int* CMapView::PlaceLabels(const CRect& rcBounds, Gdiplus::Graphics* graphics, bool layerBuffer) +{ + if (_lockCount > 0 && !_isSnapshot) + return nullptr; + + // clear extents of drawn labels and charts + this->ClearLabelFrames(); + + long endcondition = _activeLayers.size(); + // nothing to draw + if (endcondition == 0) + return nullptr; + + register int i; + long startcondition = 0; + + // prepare for placing + + // ------------------------------------------------------------------ + // Check whether some layers are completely concealed by images + // no need to draw them then + // ------------------------------------------------------------------ + bool* isConcealed = new bool[endcondition]; + memset(isConcealed, 0, endcondition * sizeof(bool)); + + double scale = GetCurrentScale(); + int zoom; + _tiles->get_CurrentZoom(&zoom); + + if (layerBuffer) + CheckForConcealedImages(isConcealed, startcondition, endcondition, scale, zoom); + + double currentScale = this->GetCurrentScale(); + + // collision avoidance + _collisionList.Clear(); + CCollisionList collisionListLabels; + CCollisionList collisionListCharts; + + CCollisionList* chosenListLabels = m_globalSettings.commonCollisionListForLabels ? (&_collisionList) : (&collisionListLabels);; + CCollisionList* chosenListCharts = m_globalSettings.commonCollisionListForCharts ? (&_collisionList) : (&collisionListCharts);; + + // initializing classes for drawing + bool forceGdiplus = this->_rotateAngle != 0.0f || _isSnapshot; + + CShapefileDrawer sfDrawer(graphics, &_extents, _pixelPerProjectionX, _pixelPerProjectionY, &_collisionList, this->GetCurrentScale(), this->GetCurrentZoom(), forceGdiplus); + CLabelDrawer lblDrawer(graphics, &_extents, _pixelPerProjectionX, _pixelPerProjectionY, currentScale, _currentZoom, chosenListLabels, _rotateAngle, _isSnapshot); + + // mark all shapes as not drawn + for (int i = startcondition; i < endcondition; i++) + { + Layer* l = _allLayers[_activeLayers[i]]; + if (l->IsShapefile() && l->wasRendered) // if it's hidden don't clear every time + { + CComPtr sf = NULL; + // don't mark as 'undrawn' if we're not going to redraw it + if (l->QueryShapefile(&sf) && ShapefileHelper::IsVolatile(sf) != layerBuffer) + { + ShapefileHelper::Cast(sf)->MarkUndrawn(); + } + } + } + + // run drawing + int shapeCount = 0; + for (int i = startcondition; i < endcondition; i++) + { + long layerHandle = _activeLayers[i]; + Layer* l = _allLayers[layerHandle]; + if (!l || !l->get_Object()) continue; + + bool visible = l->IsVisible(scale, zoom) && !isConcealed[i]; + l->wasRendered = visible; + + if (visible) + { + if (l->IsImage()) + { + if (!layerBuffer) continue; + + LayerDrawer::DrawLabels(l, lblDrawer, vpAboveParentLayer); + } + else if (l->IsShapefile() || l->IsDynamicOgrLayer()) + { + + CComPtr sf = NULL; + if (l->IsDynamicOgrLayer()) + { + // Try to get the data loaded so far & update labels & categories + l->UpdateShapefile(); + + // Get the shapefile + l->QueryShapefile(&sf); + } + else + { + // grab extents from shapefile in case they changed + l->UpdateExtentsFromDatasource(); + + if (!l->extents.Intersects(_extents)) + continue; + + // Update labels & categories + l->UpdateShapefile(); + } + + // layerBuffer == true indicates we're drawing the non-Volatile layers + if (l->QueryShapefile(&sf) && ShapefileHelper::IsVolatile(sf) == layerBuffer) + continue; + + //LayerDrawer::DrawLabels(l, lblDrawer, vpAboveParentLayer); + auto ret = LayerDrawer::PlaceLabels(l, lblDrawer, vpAboveParentLayer); + } + } + } + + shapeCount = sfDrawer.GetShapeCount(); + + if (layerBuffer) + _shapeCountInView = shapeCount; + + if (!layerBuffer && shapeCount > _shapeCountInView) + _shapeCountInView = shapeCount; + + // drawing labels and charts above the layers + for (i = 0; i < (int)_activeLayers.size(); i++) + { + Layer* l = _allLayers[_activeLayers[i]]; + + if (!l || !l->get_Object()) continue; + + if (!l->IsVisible(scale, zoom)) continue; + + CComPtr sf = NULL; + if (l->QueryShapefile(&sf) && ShapefileHelper::IsVolatile(sf) == layerBuffer) + continue; + + //LayerDrawer::DrawLabels(l, lblDrawer, vpAboveAllLayers); + auto ret = LayerDrawer::PlaceLabels(l, lblDrawer, vpAboveAllLayers); + //LayerDrawer::DrawCharts(l, chartDrawer, vpAboveAllLayers); + } + + if (isConcealed) + delete[] isConcealed; +} diff --git a/src/MapControl/Map_DrawingLayer.cpp b/src/MapControl/Map_DrawingLayer.cpp index 15cd2ae5..23215868 100644 --- a/src/MapControl/Map_DrawingLayer.cpp +++ b/src/MapControl/Map_DrawingLayer.cpp @@ -5,6 +5,7 @@ #include "stdafx.h" #include "Map.h" #include "LabelDrawing.h" +#include "Labels.h" // *************************************************************** // IsValidDrawList() @@ -1005,6 +1006,85 @@ void CMapView::SetDrawingLabels(long DrawingLayerIndex, ILabels* newVal) else ErrorMessage(tkINVALID_DRAW_HANDLE); } -#pragma endregion +// *************************************************************** +// PlaceAllMapLabels +// *************************************************************** +IPlacedLabels* CMapView::PlaceAllMapLabels(long layerHandle) +{ + ::OutputDebugStringA("PlaceAllMapLabels"); + auto currentScale = this->GetCurrentScale(); + CCollisionList collisionListLabels; + CCollisionList* chosenListLabels = m_globalSettings.commonCollisionListForLabels ? (&_collisionList) : (&collisionListLabels); + + Gdiplus::Graphics* graphics = Gdiplus::Graphics::FromImage(_layerBitmap); + graphics->Clear(Gdiplus::Color::Transparent); + graphics->SetCompositingMode(Gdiplus::CompositingModeSourceOver); + + auto maxExtents = GetMaxExtents(); + auto extents = new Extent(maxExtents); + CLabelDrawer lblDrawer(graphics, extents, _pixelPerProjectionX, _pixelPerProjectionY, currentScale, _currentZoom, chosenListLabels, _rotateAngle, _isSnapshot); + + Layer* layer = _allLayers[layerHandle]; + auto labels = layer->get_Labels(); + auto array = lblDrawer.PlaceAllMapLabels(labels); + IPlacedLabels* placedLabels; + ComHelper::CreateInstance(idPlacedLabels, (IDispatch**)&placedLabels); + + auto indexes = array.data(); + placedLabels->SetVector(indexes, array.size()); + + return placedLabels; +} + +// *************************************************************** +// GetLabelExtents +// *************************************************************** +IExtents* CMapView::GetDrawingLabelExtents(VARIANT* variant) //long layerHandle, long index) +{ + SAFEARRAY* sar = *variant->pparray; + auto values = static_cast(sar->pvData); + auto layerHandle = values[0]; + auto index = values[1]; + auto currentScale = this->GetCurrentScale(); + CCollisionList collisionListLabels; + CCollisionList* chosenListLabels = m_globalSettings.commonCollisionListForLabels ? (&_collisionList) : (&collisionListLabels); + + Gdiplus::Graphics* graphics = Gdiplus::Graphics::FromImage(_layerBitmap); + graphics->Clear(Gdiplus::Color::Transparent); + graphics->SetCompositingMode(Gdiplus::CompositingModeSourceOver); + + auto maxExtents = GetMaxExtents(); + auto extents = new Extent(maxExtents); + CLabelDrawer lblDrawer(graphics, extents, _pixelPerProjectionX, _pixelPerProjectionY, currentScale, _currentZoom, chosenListLabels, _rotateAngle, _isSnapshot); + + IExtents* box; + ComHelper::CreateExtents(&box); + ILabels* labels = nullptr; + if(IsValidDrawList(layerHandle)) + { + _allDrawLists[layerHandle]->m_labels->AddRef(); + labels = _allDrawLists[layerHandle]->m_labels; + + auto rect = lblDrawer.GetLabelExtents(labels, index); + box->SetBounds(rect.left, rect.bottom, 0.0, rect.right, rect.top, 0.0); + } + + /*CLabels* lbs = static_cast(labels); + vector*>* labelData = lbs->get_LabelData(); + vector* parts = (*labelData)[index]; + CLabelInfo* lbl = (*parts)[0]; */ + + /*ILabel* pLabel; + ComHelper::CreateInstance(idLabel, reinterpret_cast(&pLabel)); + labels->get_Label(index, 0, &pLabel); + *pLabel-> */ + + + //box->SetBounds(layer->extents.left, layer->extents.bottom, 0.0, layer->extents.right, layer->extents.top, 0.0); + + return box; +} + +#pragma endregion diff --git a/src/MapWinGIS.cpp b/src/MapWinGIS.cpp index c8987529..6a7e9b37 100644 --- a/src/MapWinGIS.cpp +++ b/src/MapWinGIS.cpp @@ -31,12 +31,15 @@ static char THIS_FILE[] = __FILE__; const GUID CDECL BASED_CODE _tlid = { 0xc368d713, 0xcc5f, 0x40ed, { 0x9f, 0x53, 0xf8, 0x4f, 0xe1, 0x97, 0xb9, 0x6a } }; const WORD _wVerMajor = 5; -const WORD _wVerMinor = 4; +const WORD _wVerMinor = 5; CMapWinGISApp NEAR theApp; CMapWinGISModule _AtlModule; // this one is from ATL7 (used by all ATL co-classes) CComModule _Module; // this one is from ATL3 (used for ShapefileColorScheme and ShapefileColorBreak) GlobalClassFactory m_factory; // make sure that this one is initialized after the _Module above +#if DEBUG_ALLOCATED_OBJECTS +bool _break; +#endif // ****************************************************** // CMapWinGISApp::InitInstance - DLL initialization diff --git a/src/MapWinGIS.h b/src/MapWinGIS.h index 127ceb67..3b85cf55 100644 --- a/src/MapWinGIS.h +++ b/src/MapWinGIS.h @@ -11,7 +11,7 @@ #include "GlobalClassFactory.h" #define VERSION_MAJOR 5 -#define VERSION_MINOR 4 +#define VERSION_MINOR 5 extern const GUID CDECL _tlid; extern const WORD _wVerMajor; @@ -31,6 +31,9 @@ class CMapWinGISApp : public COleControlModule }; extern GlobalClassFactory m_factory; +#if DEBUG_ALLOCATED_OBJECTS +extern bool _break; +#endif //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. \ No newline at end of file diff --git a/src/MapWinGIS.idl b/src/MapWinGIS.idl index b8d95aff..98f759d4 100644 --- a/src/MapWinGIS.idl +++ b/src/MapWinGIS.idl @@ -69,6 +69,7 @@ interface IFunction; interface IExpression; interface IWmsLayer; interface IGdalUtils; +interface IPlacedLabels; /************************** tkWmsVersion Enumeration **********************/ typedef @@ -98,6 +99,21 @@ enum tkWmsBoundingBoxOrder bboLatLong = 2, } tkWmsBoundingBoxOrder; + +/************************** tkWmsTileSize Enumeration **********************/ +typedef +[ + uuid(5A91B5E6-A6BE-45F5-B2A1-B0ACC8F152BA), + helpstring("tkWmsTileSize"), +] +enum tkWmsTileSize +{ + sizeFullScreen = -100, + size256x256 = 256, + size512x512 = 512, + size1024x1024 = 1024, +} tkWmsTileSize; + /************************** tkCallbackVerbosity Enumeration **********************/ typedef [ @@ -621,6 +637,7 @@ enum tkAreaDisplayMode admMetric = 0, admHectars = 1, admAmerican = 2, + admMetricMeters = 3, } tkAreaDisplayMode; /************************** tkCustomState Enumeration **********************/ @@ -1193,7 +1210,9 @@ enum tkInterface idFunction = 50, idExpression = 51, idWmsLayer = 52, - idGdalUtils = 53 + idGdalUtils = 53, + idPlacedLabels = 54 + } tkInterface; typedef @@ -3717,6 +3736,10 @@ interface IShapeEditor : IDispatch { [id(62)] HRESULT AddPoint([in] IPoint* newPoint, [out, retval] VARIANT_BOOL* retVal); [propget, id(63)] HRESULT SnapMode([out, retval] tkSnapMode* pVal); [propput, id(63)] HRESULT SnapMode([in] tkSnapMode newVal); + [propget, id(64)] HRESULT EnableInsertVertex([out, retval] VARIANT_BOOL* pVal); + [propput, id(64)] HRESULT EnableInsertVertex([in] VARIANT_BOOL newVal); + [propget, id(65)] HRESULT AllowSaveInvalidGeometry([out, retval] VARIANT_BOOL* pVal); + [propput, id(65)] HRESULT AllowSaveInvalidGeometry([in] VARIANT_BOOL newVal); }; @@ -5054,6 +5077,12 @@ interface ILabel : IDispatch { [propget, id(10), helpstring("property OffsetY")] HRESULT OffsetY([out, retval] double* retval); [propput, id(10), helpstring("property OffsetY")] HRESULT OffsetY([in] double newVal); + + [propget, id(11), helpstring("property MapExtents")] HRESULT MapExtents(double inversePixelPerProjection, [out, retval] IExtents** retval); + + [propget, id(12)] HRESULT Key([out, retval]BSTR* retVal); + [propput, id(12)] HRESULT Key([in]BSTR newVal); + }; // *********************************** Labels Interface ******************************* @@ -5329,6 +5358,15 @@ interface ILabels : IDispatch { [propget, id(107), helpstring("property OffsetYField")] HRESULT OffsetYField([out, retval] long* retval); [propput, id(107), helpstring("property OffsetYField")] HRESULT OffsetYField([in] long newVal); [id(108)] HRESULT ApplyLabelExpression(); + [propget, id(109), helpstring("property LabelDrawnInMap")] HRESULT LabelDrawnInMap([in]long Index, [out, retval] VARIANT_BOOL* pVal); + + midl_pragma warning(disable:2402) + // function effectively requires the LabelIndices and PartIndices parameters, + // they were made optional only because they follow other optional parameters, + // and cannot reasonably be changed without breaking the interface. + // this pragma disables the warning only for this (and similar) functions. + [id(110), helpstring("method SelectNotDrawn")] HRESULT SelectNotDrawn([in]IExtents* BoundingBox, [in, optional, out]VARIANT* LabelIndices, [in, optional, out]VARIANT* PartIndices, [out, retval]VARIANT_BOOL* retval); + midl_pragma warning(enable:2402) }; // ******************************* LabelCategory Interface ***************************** @@ -6725,6 +6763,10 @@ interface IWmsLayer : IDispatch { [propput, id(27)] HRESULT Version([in] tkWmsVersion newVal); [propget, id(28)] HRESULT Styles([out, retval] BSTR* pVal); [propput, id(28)] HRESULT Styles([in] BSTR newVal); + [propget, id(29)] HRESULT BoundingBoxOrder([out, retval] tkWmsBoundingBoxOrder* pVal); + [propput, id(29)] HRESULT BoundingBoxOrder([in] tkWmsBoundingBoxOrder newVal); + [propget, id(30)] HRESULT TileSize([out, retval] LONG* pVal); + [propput, id(30)] HRESULT TileSize([in] LONG newVal); }; /**************************** Gdal Utils Interface ***********************/ @@ -6752,7 +6794,20 @@ interface IGdalUtils : IDispatch { } [ - uuid(C368D713-CC5F-40ED-9F53-F84FE197B96A), version(5.4), + object, + uuid(399E8B54-795C-4C7F-84CF-4B127DD4DF5B), + dual, + nonextensible, + pointer_default(unique) +] +interface IPlacedLabels : IDispatch { + [propget, id(1), helpstring("property NumIndex")] HRESULT NumIndex([out, retval] long* pVal); + [id(2), helpstring("method GetIndexes")] HRESULT GetIndexes([out, retval] SAFEARRAY(long)* retval); + [id(3), helpstring("method SetVector")] HRESULT SetVector([in] int* indexes, int length); +}; + +[ + uuid(C368D713-CC5F-40ED-9F53-F84FE197B96A), version(5.5), helpfile("MapWinGIS.chm"), helpstring("MapWinGIS Components"), control @@ -6774,7 +6829,7 @@ library MapWinGIS // Primary dispatch interface for CMap [uuid(1D077739-E866-46A0-B256-8AECC04F2312), - helpstring("Dispatch interface for MapWinGIS Map Control"), version(5.4), hidden + helpstring("Dispatch interface for MapWinGIS Map Control"), version(5.5), hidden ] dispinterface _DMap { @@ -6839,13 +6894,16 @@ library MapWinGIS //[id(17), propput, nonbrowsable] void Extents(IExtents* nNewValue); //[id(17), propget, nonbrowsable] IExtents* Extents(); -#define REDRAW_API -#ifdef REDRAW_API +#define REDRAW_API +#ifdef REDRAW_API [id(21)] void Redraw(); [id(42)] void LockWindow(tkLockMode LockMode); [id(220)] void Redraw2(tkRedrawType redrawType); [id(260)] void Redraw3(tkRedrawType redrawType, VARIANT_BOOL reloadTiles); -#endif + [id(269)] IPlacedLabels* PlaceAllMapLabels(long LayerHandle); + [id(270)] IExtents* GetDrawingLabelExtents(VARIANT* values); + //long LayerHandle, long index); +#endif #define COORDINATES_API #ifdef COORDINATES_API @@ -7297,9 +7355,10 @@ library MapWinGIS [id(37)] void BeforeLayers(long hdc, long xMin, long xMax, long yMin, long yMax, tkMwBoolean* Handled); [id(38)] void AfterLayers(long hdc, long xMin, long xMax, long yMin, long yMax, tkMwBoolean* Handled); [id(39)] void LayerReprojectedIncomplete(LONG LayerHandle, Long NumReprojected, Long NumShapes); - [id(40)] void BeforeVertexDigitized(DOUBLE* pointX, DOUBLE* pointY); + [id(40)] void BeforeVertexDigitized(DOUBLE* pointX, DOUBLE* pointY, LONG selectedVertex); [id(41)] void SnapPointRequested(DOUBLE pointX, DOUBLE pointY, DOUBLE* snappedX, DOUBLE* snappedY, tkMwBoolean* isFound, tkMwBoolean* isFinal); [id(42)] void SnapPointFound(DOUBLE pointX, DOUBLE pointY, DOUBLE* snappedX, DOUBLE* snappedY); + [id(43)] void VertexAdded(DOUBLE pointX, DOUBLE pointY); //}}AFX_ODL_EVENT }; @@ -7706,6 +7765,7 @@ library MapWinGIS { [default] interface IIdentifier; }; + [ uuid(85EA46DF-FCB8-44A2-BFB0-2F5B0162768D) ] @@ -7785,4 +7845,12 @@ library MapWinGIS { [default] interface IGdalUtils; }; + + [ + uuid(92A8E8D4-617E-47A4-8180-82E24AD3C984) + ] + coclass PlacedLabels + { + [default] interface IPlacedLabels; + }; }; diff --git a/src/MapWinGIS.rc b/src/MapWinGIS.rc index a7daaf85..e14daf13 100644 --- a/src/MapWinGIS.rc +++ b/src/MapWinGIS.rc @@ -78,6 +78,7 @@ IDR_GDALDRIVERMANAGER REGISTRY "COM Classes/GdalDriverManager.r IDR_FUNCTION REGISTRY "COM Classes/Function.rgs" IDR_EXPRESSION REGISTRY "COM Classes/Expression.rgs" IDR_WmsLayer REGISTRY "COM Classes/WmsLayer.rgs" +IDR_PLACEDLABELS REGISTRY "COM Classes/PlacedLabels.rgs" IDR_GdalUtils REGISTRY "COM Classes/GdalUtils.rgs" #ifdef APSTUDIO_INVOKED @@ -112,8 +113,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 5,4,0,0 - PRODUCTVERSION 5,4,0,0 + FILEVERSION 5,5,0,5 + PRODUCTVERSION 5,5,0,5 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -131,13 +132,13 @@ BEGIN VALUE "Comments", "This control includes a mapping component and objects for reading and writing shapefiles and various triangulated irregular network and grid files. It also has extensive label and chart options and includes projection routines." VALUE "CompanyName", "MapWindow OSS Team - www.mapwindow.org" VALUE "FileDescription", "MapWinGIS ActiveX Control" - VALUE "FileVersion", "5.4.0.0" + VALUE "FileVersion", "5.5.0.5" VALUE "InternalName", "MapWinGIS ActiveX Control" VALUE "LegalCopyright", "Copyright (C) 2004-2022 MapWindow OSS Team" VALUE "LegalTrademarks", "MapWindow GIS is a trademark of Daniel P. Ames, 2005-2022" VALUE "OriginalFilename", "MapWinGIS.ocx" VALUE "ProductName", "MapWinGIS ActiveX Control" - VALUE "ProductVersion", "5.4.0.0" + VALUE "ProductVersion", "5.5.0.5" END END BLOCK "VarFileInfo" diff --git a/src/Processing/GeometryHelper.cpp b/src/Processing/GeometryHelper.cpp index 2230ce92..cffec066 100644 --- a/src/Processing/GeometryHelper.cpp +++ b/src/Processing/GeometryHelper.cpp @@ -236,6 +236,21 @@ tkExtentsRelation GeometryHelper::RelateExtents(CRect& r1, CRect& r2) return tkExtentsRelation::erIntersection; } +//************************************************************************** +// PointInSegment() +//************************************************************************** +bool GeometryHelper::PointInExtent(double xMin, double yMin, double xMax, double yMax, double ptX, double ptY) +{ + //xMin, yMin, xMax, yMax + + if ((ptX < xMin && ptX < xMax) || (ptX > xMin && ptX > xMax) || + (ptY < yMin && ptY < yMax) || (ptY > yMin && ptY > yMax)) + { + return false; + } + return (xMin <= ptX && xMax >= ptX && xMax >= ptX && yMax >= ptY); +} + //************************************************************************** // PointOnSegment() //************************************************************************** diff --git a/src/Processing/GeometryHelper.h b/src/Processing/GeometryHelper.h index be691b36..5606a1f0 100644 --- a/src/Processing/GeometryHelper.h +++ b/src/Processing/GeometryHelper.h @@ -13,6 +13,7 @@ class GeometryHelper static tkExtentsRelation RelateExtents(IExtents* ext1, IExtents* ext2); static tkExtentsRelation RelateExtents(CRect& r1, CRect& r2); static double GetPointAngle(double &x, double &y); + static bool PointInExtent(double xMin, double yMin, double xMax, double yMax, double ptX, double ptY); static bool PointOnSegment(double x1, double y1, double x2, double y2, double pntX, double pntY); static double GetPointAngleDeg(double x, double y); }; diff --git a/src/Utilities/ComHelper.cpp b/src/Utilities/ComHelper.cpp index 678767a4..7c9739b7 100644 --- a/src/Utilities/ComHelper.cpp +++ b/src/Utilities/ComHelper.cpp @@ -242,6 +242,9 @@ HRESULT ComHelper::CreateInstance(tkInterface interfaceId, IDispatch** retVal) case tkInterface::idGdalUtils: result = CoCreateInstance(CLSID_GdalUtils, NULL, CLSCTX_INPROC_SERVER, IID_IGdalUtils, (void**)&val); break; + case tkInterface::idPlacedLabels: + result = CoCreateInstance(CLSID_PlacedLabels, NULL, CLSCTX_INPROC_SERVER, IID_IPlacedLabels, (void**)&val); + break; } *retVal = val ? (IDispatch*)val : NULL; return result; diff --git a/src/Utilities/ComHelper.h b/src/Utilities/ComHelper.h index 7a0733e8..0e4c8daf 100644 --- a/src/Utilities/ComHelper.h +++ b/src/Utilities/ComHelper.h @@ -8,5 +8,17 @@ class ComHelper static void CreatePoint(IPoint** point); static void CreateShape(IShape** shp); static void CreateExtents(IExtents** box); + +#if DEBUG_ALLOCATED_OBJECTS + static bool GetBreak() + { + return _break; + } + + static void SetBreak(bool breakValue) + { + _break = breakValue; + } +#endif }; From a76557e0fb9deae82bfb69d18a0fd876f6823494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 10:22:57 +0200 Subject: [PATCH 06/55] Filter out logging of: "The method isn't applicable to the in-memory object". --- src/ComHelpers/CallbackHelper.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ComHelpers/CallbackHelper.cpp b/src/ComHelpers/CallbackHelper.cpp index 439d2c59..74094e53 100644 --- a/src/ComHelpers/CallbackHelper.cpp +++ b/src/ComHelpers/CallbackHelper.cpp @@ -122,6 +122,7 @@ void CallbackHelper::ErrorMsg(const CString className, ICallback* localCback, BS if (callback || Debug::IsDebugMode()) { if (strcmp(message, "No Error") == 0) return; + if (strcmp(message, "The method isn't applicable to the in-memory object") == 0) return; TCHAR buffer[1024]; va_list args; From 00315c81353d8b5e205ab4f5c20e56bffba12f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 10:34:46 +0200 Subject: [PATCH 07/55] Debug code, better error logging and some cleanup. Added debug function: DebugDump(IShape* shp). --- src/COM classes/Shape.cpp | 17 ++++ src/COM classes/ShapeDrawingOptions.cpp | 2 +- src/COM classes/ShapeDrawingOptions.h | 2 + src/ComHelpers/ShapeHelper.cpp | 105 ++++++++++++++++++++++++ src/ComHelpers/ShapeHelper.h | 1 + src/Resource.h | 1 + src/Structures/Extent.h | 6 +- src/Tiles/Caching/SQLiteCache.cpp | 8 +- src/Utilities/GdalHelper.cpp | 5 +- src/Utilities/Logger.cpp | 2 +- 10 files changed, 142 insertions(+), 7 deletions(-) diff --git a/src/COM classes/Shape.cpp b/src/COM classes/Shape.cpp index b88356b8..12019a0e 100644 --- a/src/COM classes/Shape.cpp +++ b/src/COM classes/Shape.cpp @@ -61,6 +61,11 @@ CShape::CShape() _labelRotation = 0; gReferenceCounter.AddRef(tkInterface::idShape); +#if DEBUG_ALLOCATED_OBJECTS + gReferenceCounter.AddRef(this); + if (ComHelper::GetBreak()) + ::OutputDebugStringA("Break!"); +#endif } // ********************************************** @@ -80,6 +85,11 @@ CShape::~CShape() } gReferenceCounter.Release(tkInterface::idShape); // TODO: Fix compile warning +#if DEBUG_ALLOCATED_OBJECTS + gReferenceCounter.Release(this); + if (ComHelper::GetBreak()) + ::OutputDebugStringA("Break!"); +#endif } #pragma region DataConversions @@ -259,6 +269,13 @@ STDMETHODIMP CShape::put_ShapeType(const ShpfileType newVal) const ShapeWrapperType type = _shp->get_WrapperType(); const ShapeWrapperType newType = ShapeUtility::GetShapeWrapperType(newVal, !_useFastMode); + /*if ((newVal == SHP_POINT || newVal == SHP_POINTM || newVal == SHP_POINTZ) && ComHelper::GetBreak()) { + CString str; + str.Format("0x%016llx SHP_POINT", this); + const CComBSTR bstr(str); + put_Key(bstr); + } */ + if (type == newType) { if (!_shp->put_ShapeType(newVal)) { diff --git a/src/COM classes/ShapeDrawingOptions.cpp b/src/COM classes/ShapeDrawingOptions.cpp index d9837fa9..579c6338 100644 --- a/src/COM classes/ShapeDrawingOptions.cpp +++ b/src/COM classes/ShapeDrawingOptions.cpp @@ -1164,7 +1164,7 @@ STDMETHODIMP CShapeDrawingOptions::put_LineWidth (float newVal) AFX_MANAGE_STATE(AfxGetStaticModuleState()); if (newVal < 1) newVal = 1; if (newVal > 20) newVal = 20; - _options.lineWidth = newVal; + _options.lineWidth = newVal; return S_OK; } diff --git a/src/COM classes/ShapeDrawingOptions.h b/src/COM classes/ShapeDrawingOptions.h index 75a8c89c..b9dff9af 100644 --- a/src/COM classes/ShapeDrawingOptions.h +++ b/src/COM classes/ShapeDrawingOptions.h @@ -47,11 +47,13 @@ class ATL_NO_VTABLE CShapeDrawingOptions : _isLineDecoration = false; _pointRotationExpression = SysAllocString(L""); gReferenceCounter.AddRef(tkInterface::idShapeDrawingOptions); + //gReferenceCounter.AddRef(this); } ~CShapeDrawingOptions() { ::SysFreeString(_pointRotationExpression); gReferenceCounter.Release(tkInterface::idShapeDrawingOptions); + //gReferenceCounter.Release(this); } DECLARE_REGISTRY_RESOURCEID(IDR_SHAPEDRAWINGOPTIONS) diff --git a/src/ComHelpers/ShapeHelper.cpp b/src/ComHelpers/ShapeHelper.cpp index a3896df2..227bc385 100644 --- a/src/ComHelpers/ShapeHelper.cpp +++ b/src/ComHelpers/ShapeHelper.cpp @@ -428,3 +428,108 @@ int ShapeHelper::GetContentLength(IShape* shp) return ShapeUtility::get_ContentLength(shpType, numPoints, numParts); } + +// ************************************************************* +// DebugDump() +// ************************************************************* +void ShapeHelper::DebugDump(IShape* shp) +{ + long numPoints, numParts; + ShpfileType shpType; + + shp->get_NumPoints(&numPoints); + shp->get_NumParts(&numParts); + shp->get_ShapeType(&shpType); + + if (numParts > 1) { + ::OutputDebugStringA("Not support NumParts > 1"); + return; + } + + if (numPoints <= 10 || numPoints > 15) + return; + + HRESULT hr; + IPoint* pnt = nullptr; + CString sOutput; + double x, y, z, m; + switch (shpType) + { + case SHP_NULLSHAPE: + ::OutputDebugStringA("ShapeHelper::DebugDump(): NULLSHAPE"); + break; + + case SHP_POINT: + case SHP_POINTZ: + hr = shp->get_Point(0, &pnt); + if (FAILED(hr)) { + CString sError; + sError.AppendFormat("ShapeHelper::DebugDump() Failed in get_Point(1, ..)\r\n"); + ::OutputDebugStringA(sError.GetBuffer()); + return; + } + pnt->get_X(&x); + pnt->get_Y(&y); + + if (shpType == SHP_POINT) + sOutput.AppendFormat("Point N: %f E: %f\r\n", y, x); + else { + pnt->get_Z(&z); + pnt->get_M(&m); + sOutput.AppendFormat("Point N: %f E: %f Z: %f M: %f\r\n", y, x, z, m); + } + break; + + + case SHP_POLYLINE: + case SHP_POLYLINEZ: + for (int i = 0; i < numPoints; i++) { + hr = shp->get_Point(i, &pnt); + if (FAILED(hr)) { + CString sError; + sError.AppendFormat("ShapeHelper::DebugDump() Failed in get_Point(%d, ..)\r\n", i); + ::OutputDebugStringA(sError.GetBuffer()); + return; + } + pnt->get_X(&x); + pnt->get_Y(&y); + if (shpType == SHP_POLYLINE) + sOutput.AppendFormat("Point# %d X: %f Y: %f\r\n", i, x, y); + else { + pnt->get_Z(&z); + pnt->get_M(&m); + sOutput.AppendFormat("Point# %d N: %f E: %f Z: %f M: %f\r\n", i, y, x, z, m); + } + } + break; + + case SHP_POLYGON: + case SHP_POLYGONZ: + for (int i = 0; i < numPoints; i++) { + hr = shp->get_Point(i, &pnt); + if (FAILED(hr)) { + CString sError; + sError.AppendFormat("ShapeHelper::DebugDump() Failed in get_Point(%d, ..)\r\n", i); + ::OutputDebugStringA(sError.GetBuffer()); + return; + } + pnt->get_X(&x); + pnt->get_Y(&y); + if (shpType == SHP_POLYGON) + sOutput.AppendFormat("Point# %d X: %f Y: %f\r\n", i, x, y); + else { + pnt->get_Z(&z); + pnt->get_M(&m); + sOutput.AppendFormat("Point# %d N: %f E: %f Z: %f M: %f\r\n", i, y, x, z, m); + } + } + break; + + default: + ::OutputDebugStringA("ShapeHelper::DebugDump(): Shape Type: Unknown"); + break; + } + sOutput.Append("\r\n"); + ::OutputDebugStringA(sOutput.GetBuffer()); +} + diff --git a/src/ComHelpers/ShapeHelper.h b/src/ComHelpers/ShapeHelper.h index a3e3783d..5666ea81 100644 --- a/src/ComHelpers/ShapeHelper.h +++ b/src/ComHelpers/ShapeHelper.h @@ -19,5 +19,6 @@ class ShapeHelper static void AddLabelToShape(IShape* shp, ILabels* labels, BSTR text, tkLabelPositioning method, tkLineLabelOrientation orientation, double offsetX, double offsetY); static IShape* CenterAsShape(IShape* shp); static int GetContentLength(IShape* shp); + static void DebugDump(IShape* shp); }; diff --git a/src/Resource.h b/src/Resource.h index d22708b4..eeb142d8 100644 --- a/src/Resource.h +++ b/src/Resource.h @@ -85,6 +85,7 @@ #define IDC_SELECT2_CURSOR 220 #define IDC_IDENTIFY_CURSOR 221 #define IDC_PAN_ALTERNATE 222 +#define IDR_PLACEDLABELS 223 // Next default values for new objects // diff --git a/src/Structures/Extent.h b/src/Structures/Extent.h index e33fb8ec..33a74a61 100644 --- a/src/Structures/Extent.h +++ b/src/Structures/Extent.h @@ -131,7 +131,7 @@ class Extent top = yCent + dy; } - Point2D GetCenter () + Point2D GetCenter () { return Point2D((left + right) / 2.0, (top + bottom) / 2.0); } @@ -143,7 +143,9 @@ class Extent CString ToString() { - return Debug::Format("x: %f; y: %f; w: %f; h: %f", left, top, Width(), Height()); + auto width = Width(); + auto height = Height(); + return Debug::Format("x: %f; y: %f; w: %f; h: %f", left, top, width, height); } }; diff --git a/src/Tiles/Caching/SQLiteCache.cpp b/src/Tiles/Caching/SQLiteCache.cpp index 616821d4..c3fe9193 100644 --- a/src/Tiles/Caching/SQLiteCache.cpp +++ b/src/Tiles/Caching/SQLiteCache.cpp @@ -212,7 +212,13 @@ void SQLiteCache::AddTile(TileCore* tile) if (val != SQLITE_OK) { - CallbackHelper::ErrorMsg("SQLiteCache::DoCaching: Failed to prepare statement."); + auto sqlite3_error = sqlite3_errmsg(_conn); + auto errorCode = sqlite3_extended_errcode(_conn); + //std:string errorMessage("SQLiteCache::DoCaching: Failed to prepare statement: "); + //errorMessage += sqlite3_error ? sqlite3_error : "Unknown error"; + //CallbackHelper::ErrorMsg(errorMessage.c_str()); + CallbackHelper::ErrorMsg(Debug::Format("SQLiteCache::DoCaching: Failed to prepare statement errorNo: %d Message: %s", errorCode, sqlite3_error)); + //CallbackHelper::ErrorMsg("SQLiteCache::DoCaching: Failed to prepare statement."); } else { diff --git a/src/Utilities/GdalHelper.cpp b/src/Utilities/GdalHelper.cpp index 2ffd5cdb..cec38a99 100644 --- a/src/Utilities/GdalHelper.cpp +++ b/src/Utilities/GdalHelper.cpp @@ -113,7 +113,7 @@ int GdalHelper::CloseSharedOgrDataset(GDALDataset* ds) const int count = ds->Dereference(); if (count == 0) { - //Debug::WriteLine("Shared datasource is closed."); + Debug::WriteLine("Shared datasource(%s) is closed.", ds->GetDescription()); RemoveCachedOgrDataset(ds); GDALClose(ds); } @@ -139,6 +139,7 @@ void GdalHelper::RemoveCachedOgrDataset(GDALDataset* ds) { if (it->second == ds) { + Debug::WriteLine("RemoveCachedOgrDataset(ds: %s)", it->first.GetString()); m_ogrDatasets.erase(it->first); break; } @@ -740,7 +741,7 @@ CStringW GdalHelper::GetDefaultConfigPath(const GdalPath option) path += L"\\gdalplugins\\"; break; case PathProjLib: - path += L"\\proj7\\share\\"; + path += L"\\proj9\\share\\"; break; } return path; diff --git a/src/Utilities/Logger.cpp b/src/Utilities/Logger.cpp index 351ed331..bfd72d72 100644 --- a/src/Utilities/Logger.cpp +++ b/src/Utilities/Logger.cpp @@ -31,7 +31,7 @@ namespace Debug { if (IsOpened() || Debug::IsDebugMode()) { - TCHAR buffer[1024]; + TCHAR buffer[4096]; va_list args; va_start( args, format); vsprintf( buffer, format, args ); From 1db557c65c322855cce3428ce9aaca20367edcc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 12:26:04 +0200 Subject: [PATCH 08/55] Reduced logging of: "Writing .shx file" to now log every 10 %. --- src/COM classes/Shapefile_ReadWrite.cpp | 2692 ++++++++++++----------- 1 file changed, 1352 insertions(+), 1340 deletions(-) diff --git a/src/COM classes/Shapefile_ReadWrite.cpp b/src/COM classes/Shapefile_ReadWrite.cpp index 1b8f2cef..5e1a5471 100644 --- a/src/COM classes/Shapefile_ReadWrite.cpp +++ b/src/COM classes/Shapefile_ReadWrite.cpp @@ -1,1341 +1,1353 @@ -//******************************************************************************************************** -//File name: Shapefile.cpp -//Description: Implementation of the CShapefile (see other cpp files as well) -//******************************************************************************************************** -//The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); -//you may not use this file except in compliance with the License. You may obtain a copy of the License at -//http://www.mozilla.org/MPL/ -//Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF -//ANY KIND, either express or implied. See the License for the specific language governing rights and -//limitations under the License. -// -//The Original Code is MapWindow Open Source. -// -//The Initial Developer of this version of the Original Code is Daniel P. Ames using portions created by -//Utah State University and the Idaho National Engineering and Environmental Lab that were released as -//public domain in March 2004. -// -//Contributor(s): (Open source contributors should list themselves and their modifications here). -// ------------------------------------------------------------------------------------------------------- -// lsu 3-02-2011: split the initial Shapefile.cpp file to make entities of the reasonable size - -#pragma once -#include "stdafx.h" -#include "Shapefile.h" -#include "Shape.h" -#include "ShapeWrapper.h" -#include "ShapeHelper.h" - -#pragma region GetShape - -// ************************************************************ -// get_Shape() -// ************************************************************ -STDMETHODIMP CShapefile::get_Shape(long shapeIndex, IShape **pVal) -{ - AFX_MANAGE_STATE(AfxGetStaticModuleState()) - VARIANT_BOOL vbretval = VARIANT_FALSE; - - // out of bounds? - if( shapeIndex < 0 || shapeIndex >= (long)_shapeData.size()) - { - ErrorMessage(tkINDEX_OUT_OF_BOUNDS); - *pVal = NULL; - return S_OK; - } - - // last shape in the append mode is always in memory - bool appendedShape = _appendMode && shapeIndex == _shapeData.size() - 1; - - // editing shapes? - if (_isEditingShapes || appendedShape) - { - if (_shapeData[shapeIndex]->shape) { - _shapeData[shapeIndex]->shape->AddRef(); - } - - *pVal = _shapeData[shapeIndex]->shape; - return S_OK; - } - - CSingleLock lock(&_readLock, TRUE); - - *pVal = _fastMode ? ReadFastModeShape(shapeIndex) : ReadComShape(shapeIndex); - - return S_OK; -} - -// ************************************************************ -// ReadFastModeShape() -// ************************************************************ -IShape* CShapefile::ReadFastModeShape(long shapeIndex) -{ fseek(_shpfile, _shpOffsets[shapeIndex], SEEK_SET); - - // read the shp from disk - int index = ShapeUtility::ReadIntBigEndian(_shpfile); - - if (index != shapeIndex + 1) - { - ErrorMessage(tkINVALID_SHP_FILE); - return NULL; - } - - int contentLength = ShapeUtility::ReadIntBigEndian(_shpfile) * 2; - - // *2: for conversion from 16-bit words to 8-bit words - // -2: skip first 2 int - it's record number and content length; - int length = contentLength; //- 2 * sizeof(int); - - char* data = new char[length]; - int count = (int)fread(data, sizeof(char), length, _shpfile); - - if (count != length) - { - delete[] data; - return NULL; - } - - IShape* shape = NULL; - - if (data != NULL) - { - ComHelper::CreateShape(&shape); - shape->put_GlobalCallback(_globalCallback); - ((CShape*)shape)->put_RawData(data, contentLength); - delete[] data; - } - - return shape; -} - -// ************************************************************ -// ReadComShape() -// ************************************************************ -IShape* CShapefile::ReadComShape(long shapeIndex) -{ // read the shp from disk - fseek(_shpfile, _shpOffsets[shapeIndex], SEEK_SET); - - int intbuf; - fread(&intbuf, sizeof(int), 1, _shpfile); - ShapeUtility::SwapEndian((char*)&intbuf, sizeof(int)); - - // shape records are 1 based - Allow for a mistake - if (intbuf != shapeIndex + 1 && intbuf != shapeIndex) - { - ErrorMessage(tkINVALID_SHP_FILE); - return NULL; - } - - fread(&intbuf, sizeof(int), 1, _shpfile); - ShapeUtility::SwapEndian((char*)&intbuf, sizeof(int)); - int contentLength = intbuf * 2;//(32 bit words) - - fread(&intbuf, sizeof(int), 1, _shpfile); - - ShpfileType shpType = (ShpfileType)intbuf; - - IShape * shape = NULL; - IPoint * pnt = NULL; - VARIANT_BOOL vbretval; - -#pragma region Nullshape Or Mismatch - // ------------------------------------------------------ - // Shape specific record contents - // ------------------------------------------------------ - - // MWGIS-91 - bool areEqualTypes = shpType == _shpfiletype; - if (!areEqualTypes){ - areEqualTypes = ShapeUtility::Convert2D(shpType) == ShapeUtility::Convert2D(_shpfiletype); - } - - if (_shpfiletype == SHP_NULLSHAPE) - { - if (shpType != SHP_NULLSHAPE) - { - ErrorMessage(tkINVALID_SHP_FILE); - return NULL; - } - else - { - shape->Create(shpType, &vbretval); - shape->put_GlobalCallback(_globalCallback); - return shape; - } - } - else if (shpType != SHP_NULLSHAPE && !areEqualTypes) - { - ErrorMessage(tkINVALID_SHP_FILE); - return NULL; - } -#pragma endregion - -#pragma region Point - // ------------------------------------------------------ - // SHP_POINT - // ------------------------------------------------------ - else if (_shpfiletype == SHP_POINT) - { - ComHelper::CreateShape(&shape); - shape->Create(shpType, &vbretval); - shape->put_GlobalCallback(_globalCallback); - - // if (shpType == SHP_POINT) - if (areEqualTypes) - { - ComHelper::CreatePoint(&pnt); - pnt->put_GlobalCallback(_globalCallback); - - double x, y; - fread(&x, sizeof(double), 1, _shpfile); - fread(&y, sizeof(double), 1, _shpfile); - pnt->put_X(x); - pnt->put_Y(y); - - long pointIndex = 0; - shape->InsertPoint(pnt, &pointIndex, &vbretval); - if (vbretval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - pnt->Release(); - } - } - - // ------------------------------------------------------ - // SHP_POINTZ - // ------------------------------------------------------ - else if (_shpfiletype == SHP_POINTZ) - { - ComHelper::CreateShape(&shape); - shape->Create(shpType, &vbretval); - shape->put_GlobalCallback(_globalCallback); - - // if (shpType == SHP_POINTZ) - if (areEqualTypes) - { - ComHelper::CreatePoint(&pnt); - pnt->put_GlobalCallback(_globalCallback); - - double x, y, z, m; - fread(&x, sizeof(double), 1, _shpfile); - fread(&y, sizeof(double), 1, _shpfile); - fread(&z, sizeof(double), 1, _shpfile); - fread(&m, sizeof(double), 1, _shpfile); - pnt->put_X(x); - pnt->put_Y(y); - pnt->put_Z(z); - pnt->put_M(m); - - long pointIndex = 0; - shape->InsertPoint(pnt, &pointIndex, &vbretval); - if (vbretval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - pnt->Release(); - } - } - - // ------------------------------------------------------ - // SHP_POINTM - // ------------------------------------------------------ - else if (_shpfiletype == SHP_POINTM) - { - ComHelper::CreateShape(&shape); - shape->Create(shpType, &vbretval); - shape->put_GlobalCallback(_globalCallback); - - // if (shpType == SHP_POINTM) - if (areEqualTypes) - { - ComHelper::CreatePoint(&pnt); - pnt->put_GlobalCallback(_globalCallback); - - double x, y, m; - fread(&x, sizeof(double), 1, _shpfile); - fread(&y, sizeof(double), 1, _shpfile); - fread(&m, sizeof(double), 1, _shpfile); - pnt->put_X(x); - pnt->put_Y(y); - pnt->put_M(m); - - long pointIndex = 0; - shape->InsertPoint(pnt, &pointIndex, &vbretval); - if (vbretval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - pnt->Release(); - } - } -#pragma endregion -#pragma region Polyline - // ------------------------------------------------------ - // SHP_POLYLINE - // ------------------------------------------------------ - else if (_shpfiletype == SHP_POLYLINE) - { - ComHelper::CreateShape(&shape); - shape->Create(shpType, &vbretval); - shape->put_GlobalCallback(_globalCallback); - - // if (shpType == SHP_POLYLINE) - if (areEqualTypes) - { - VARIANT_BOOL retval; - double bx, by; - int numParts; - int numPoints; - int part; - double x, y; - - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - - fread(&numParts, sizeof(int), 1, _shpfile); - fread(&numPoints, sizeof(int), 1, _shpfile); - - long partIndex = 0; - for (int i = 0; i < numParts; i++) - { - fread(&part, sizeof(int), 1, _shpfile); - partIndex = i; - shape->InsertPart(part, &partIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - } - - long pointIndex = 0; - for (int j = 0; j < numPoints; j++) - { - ComHelper::CreatePoint(&pnt); - pnt->put_GlobalCallback(_globalCallback); - fread(&x, sizeof(double), 1, _shpfile); - fread(&y, sizeof(double), 1, _shpfile); - pnt->put_X(x); - pnt->put_Y(y); - pointIndex = j; - shape->InsertPoint(pnt, &pointIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - pnt->Release(); - } - } - } - - // ------------------------------------------------------ - // SHP_POLYLINEZ - // ------------------------------------------------------ - else if (_shpfiletype == SHP_POLYLINEZ) - { - ComHelper::CreateShape(&shape); - shape->Create(shpType, &vbretval); - shape->put_GlobalCallback(_globalCallback); - // if (shpType == SHP_POLYLINEZ) - if (areEqualTypes) - { - VARIANT_BOOL retval; - double bx, by, bz, bm; - int numParts; - int numPoints; - int part; - double x, y, z, m; - - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - - fread(&numParts, sizeof(int), 1, _shpfile); - fread(&numPoints, sizeof(int), 1, _shpfile); - - long partIndex = 0; - for (int i = 0; i < numParts; i++) - { - fread(&part, sizeof(int), 1, _shpfile); - partIndex = i; - shape->InsertPart(part, &partIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - } - - long pointIndex = 0; - //Read the x, y part of the point - for (int j = 0; j < numPoints; j++) - { - ComHelper::CreatePoint(&pnt); - pnt->put_GlobalCallback(_globalCallback); - fread(&x, sizeof(double), 1, _shpfile); - fread(&y, sizeof(double), 1, _shpfile); - pnt->put_X(x); - pnt->put_Y(y); - pointIndex = j; - shape->InsertPoint(pnt, &pointIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - pnt->Release(); - } - - fread(&bz, sizeof(double), 1, _shpfile); - fread(&bz, sizeof(double), 1, _shpfile); - - for (int k = 0; k < numPoints; k++) - { - fread(&z, sizeof(double), 1, _shpfile); - pointIndex = k; - IPoint * pnt = NULL; - shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) - { - shape->Release(); - return NULL; - } - pnt->put_Z(z); - pnt->Release(); - } - - fread(&bm, sizeof(double), 1, _shpfile); - fread(&bm, sizeof(double), 1, _shpfile); - - for (int mc = 0; mc < numPoints; mc++) - { - fread(&m, sizeof(double), 1, _shpfile); - pointIndex = mc; - IPoint * pnt = NULL; - shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) - { - shape->Release(); - return NULL; - } - pnt->put_M(m); - //Rob Cairns 20-Dec-05 - pnt->Release(); - } - } - } - - // ------------------------------------------------------ - // SHP_POLYLINEM - // ------------------------------------------------------ - else if (_shpfiletype == SHP_POLYLINEM) - { - ComHelper::CreateShape(&shape); - shape->Create(shpType, &vbretval); - shape->put_GlobalCallback(_globalCallback); - - // if (shpType == SHP_POLYLINEM) - if (areEqualTypes) - { - VARIANT_BOOL retval; - double bx, by, bm; - int numParts; - int numPoints; - int part; - double x, y, m; - - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - - fread(&numParts, sizeof(int), 1, _shpfile); - fread(&numPoints, sizeof(int), 1, _shpfile); - - long partIndex = 0; - for (int i = 0; i < numParts; i++) - { - fread(&part, sizeof(int), 1, _shpfile); - partIndex = i; - shape->InsertPart(part, &partIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - } - - long pointIndex = 0; - //Read the x, y part of the point - for (int j = 0; j < numPoints; j++) - { - ComHelper::CreatePoint(&pnt); - pnt->put_GlobalCallback(_globalCallback); - fread(&x, sizeof(double), 1, _shpfile); - fread(&y, sizeof(double), 1, _shpfile); - pnt->put_X(x); - pnt->put_Y(y); - pointIndex = j; - shape->InsertPoint(pnt, &pointIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - pnt->Release(); - } - - fread(&bm, sizeof(double), 1, _shpfile); - fread(&bm, sizeof(double), 1, _shpfile); - - for (int mc = 0; mc < numPoints; mc++) - { - fread(&m, sizeof(double), 1, _shpfile); - pointIndex = mc; - IPoint * pnt = NULL; - shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) - { - shape->Release(); - return NULL; - } - pnt->put_M(m); - pnt->Release(); - - } - } - } -#pragma endregion -#pragma region Polygon - // ------------------------------------------------------ - // SHP_POLYGON - // ------------------------------------------------------ - else if (_shpfiletype == SHP_POLYGON) - { - ComHelper::CreateShape(&shape); - shape->Create(shpType, &vbretval); - shape->put_GlobalCallback(_globalCallback); - - // if (shpType == SHP_POLYGON) - if (areEqualTypes) - { - VARIANT_BOOL retval; - double bx, by; - int numParts; - int numPoints; - int part; - double x, y; - - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - - fread(&numParts, sizeof(int), 1, _shpfile); - fread(&numPoints, sizeof(int), 1, _shpfile); - - long partIndex = 0; - for (int i = 0; i < numParts; i++) - { - fread(&part, sizeof(int), 1, _shpfile); - partIndex = i; - shape->InsertPart(part, &partIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - } - - long pointIndex = 0; - for (int j = 0; j < numPoints; j++) - { - ComHelper::CreatePoint(&pnt); - pnt->put_GlobalCallback(_globalCallback); - fread(&x, sizeof(double), 1, _shpfile); - fread(&y, sizeof(double), 1, _shpfile); - pnt->put_X(x); - pnt->put_Y(y); - pointIndex = j; - shape->InsertPoint(pnt, &pointIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - pnt->Release(); - } - } - } - - // ------------------------------------------------------ - // SHP_POLYGONZ - // ------------------------------------------------------ - else if (_shpfiletype == SHP_POLYGONZ) - { - ComHelper::CreateShape(&shape); - shape->Create(shpType, &vbretval); - shape->put_GlobalCallback(_globalCallback); - // if (shpType == SHP_POLYGONZ) - if (areEqualTypes) - { - VARIANT_BOOL retval; - double bx, by, bz, bm; - int numParts; - int numPoints; - int part; - double x, y, z, m; - - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - - fread(&numParts, sizeof(int), 1, _shpfile); - fread(&numPoints, sizeof(int), 1, _shpfile); - - long partIndex = 0; - for (int i = 0; i < numParts; i++) - { - fread(&part, sizeof(int), 1, _shpfile); - partIndex = i; - shape->InsertPart(part, &partIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - } - - //Read the x, y part of the point - long pointIndex = 0; - for (int j = 0; j < numPoints; j++) - { - ComHelper::CreatePoint(&pnt); - pnt->put_GlobalCallback(_globalCallback); - fread(&x, sizeof(double), 1, _shpfile); - fread(&y, sizeof(double), 1, _shpfile); - pnt->put_X(x); - pnt->put_Y(y); - pointIndex = j; - shape->InsertPoint(pnt, &pointIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - pnt->Release(); - } - - fread(&bz, sizeof(double), 1, _shpfile); - fread(&bz, sizeof(double), 1, _shpfile); - +//******************************************************************************************************** +//File name: Shapefile.cpp +//Description: Implementation of the CShapefile (see other cpp files as well) +//******************************************************************************************************** +//The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); +//you may not use this file except in compliance with the License. You may obtain a copy of the License at +//http://www.mozilla.org/MPL/ +//Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF +//ANY KIND, either express or implied. See the License for the specific language governing rights and +//limitations under the License. +// +//The Original Code is MapWindow Open Source. +// +//The Initial Developer of this version of the Original Code is Daniel P. Ames using portions created by +//Utah State University and the Idaho National Engineering and Environmental Lab that were released as +//public domain in March 2004. +// +//Contributor(s): (Open source contributors should list themselves and their modifications here). +// ------------------------------------------------------------------------------------------------------- +// lsu 3-02-2011: split the initial Shapefile.cpp file to make entities of the reasonable size + +#pragma once +#include "stdafx.h" +#include "Shapefile.h" +#include "Shape.h" +#include "ShapeWrapper.h" +#include "ShapeHelper.h" + +#pragma region GetShape + +// ************************************************************ +// get_Shape() +// ************************************************************ +STDMETHODIMP CShapefile::get_Shape(long shapeIndex, IShape **pVal) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + VARIANT_BOOL vbretval = VARIANT_FALSE; + + // out of bounds? + if( shapeIndex < 0 || shapeIndex >= (long)_shapeData.size()) + { + ErrorMessage(tkINDEX_OUT_OF_BOUNDS); + *pVal = NULL; + return S_OK; + } + + // last shape in the append mode is always in memory + bool appendedShape = _appendMode && shapeIndex == _shapeData.size() - 1; + + // editing shapes? + if (_isEditingShapes || appendedShape) + { + if (_shapeData[shapeIndex]->shape) { + _shapeData[shapeIndex]->shape->AddRef(); + } + + *pVal = _shapeData[shapeIndex]->shape; + return S_OK; + } + + CSingleLock lock(&_readLock, TRUE); + + *pVal = _fastMode ? ReadFastModeShape(shapeIndex) : ReadComShape(shapeIndex); + + return S_OK; +} + +// ************************************************************ +// ReadFastModeShape() +// ************************************************************ +IShape* CShapefile::ReadFastModeShape(long shapeIndex) +{ + fseek(_shpfile, _shpOffsets[shapeIndex], SEEK_SET); + + // read the shp from disk + int index = ShapeUtility::ReadIntBigEndian(_shpfile); + + if (index != shapeIndex + 1) + { + ErrorMessage(tkINVALID_SHP_FILE); + return NULL; + } + + int contentLength = ShapeUtility::ReadIntBigEndian(_shpfile) * 2; + + // *2: for conversion from 16-bit words to 8-bit words + // -2: skip first 2 int - it's record number and content length; + int length = contentLength; //- 2 * sizeof(int); + + char* data = new char[length]; + int count = (int)fread(data, sizeof(char), length, _shpfile); + + if (count != length) + { + delete[] data; + return NULL; + } + + IShape* shape = NULL; + + if (data != NULL) + { + ComHelper::CreateShape(&shape); + shape->put_GlobalCallback(_globalCallback); + ((CShape*)shape)->put_RawData(data, contentLength); + delete[] data; + } + + return shape; +} + +// ************************************************************ +// ReadComShape() +// ************************************************************ +IShape* CShapefile::ReadComShape(long shapeIndex) +{ + // read the shp from disk + fseek(_shpfile, _shpOffsets[shapeIndex], SEEK_SET); + + int intbuf; + fread(&intbuf, sizeof(int), 1, _shpfile); + ShapeUtility::SwapEndian((char*)&intbuf, sizeof(int)); + + // shape records are 1 based - Allow for a mistake + if (intbuf != shapeIndex + 1 && intbuf != shapeIndex) + { + ErrorMessage(tkINVALID_SHP_FILE); + return NULL; + } + + fread(&intbuf, sizeof(int), 1, _shpfile); + ShapeUtility::SwapEndian((char*)&intbuf, sizeof(int)); + int contentLength = intbuf * 2;//(32 bit words) + + fread(&intbuf, sizeof(int), 1, _shpfile); + + ShpfileType shpType = (ShpfileType)intbuf; + + IShape * shape = NULL; + IPoint * pnt = NULL; + VARIANT_BOOL vbretval; + +#pragma region Nullshape Or Mismatch + // ------------------------------------------------------ + // Shape specific record contents + // ------------------------------------------------------ + + // MWGIS-91 + bool areEqualTypes = shpType == _shpfiletype; + if (!areEqualTypes){ + areEqualTypes = ShapeUtility::Convert2D(shpType) == ShapeUtility::Convert2D(_shpfiletype); + } + + if (_shpfiletype == SHP_NULLSHAPE) + { + if (shpType != SHP_NULLSHAPE) + { + ErrorMessage(tkINVALID_SHP_FILE); + return NULL; + } + else + { + shape->Create(shpType, &vbretval); + shape->put_GlobalCallback(_globalCallback); + return shape; + } + } + else if (shpType != SHP_NULLSHAPE && !areEqualTypes) + { + ErrorMessage(tkINVALID_SHP_FILE); + return NULL; + } +#pragma endregion + +#pragma region Point + // ------------------------------------------------------ + // SHP_POINT + // ------------------------------------------------------ + else if (_shpfiletype == SHP_POINT) + { + ComHelper::CreateShape(&shape); + shape->Create(shpType, &vbretval); + shape->put_GlobalCallback(_globalCallback); + + // if (shpType == SHP_POINT) + if (areEqualTypes) + { + ComHelper::CreatePoint(&pnt); + pnt->put_GlobalCallback(_globalCallback); + + double x, y; + fread(&x, sizeof(double), 1, _shpfile); + fread(&y, sizeof(double), 1, _shpfile); + pnt->put_X(x); + pnt->put_Y(y); + + long pointIndex = 0; + shape->InsertPoint(pnt, &pointIndex, &vbretval); + if (vbretval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + pnt->Release(); + } + } + + // ------------------------------------------------------ + // SHP_POINTZ + // ------------------------------------------------------ + else if (_shpfiletype == SHP_POINTZ) + { + ComHelper::CreateShape(&shape); + shape->Create(shpType, &vbretval); + shape->put_GlobalCallback(_globalCallback); + + // if (shpType == SHP_POINTZ) + if (areEqualTypes) + { + ComHelper::CreatePoint(&pnt); + pnt->put_GlobalCallback(_globalCallback); + + double x, y, z, m; + fread(&x, sizeof(double), 1, _shpfile); + fread(&y, sizeof(double), 1, _shpfile); + fread(&z, sizeof(double), 1, _shpfile); + fread(&m, sizeof(double), 1, _shpfile); + pnt->put_X(x); + pnt->put_Y(y); + pnt->put_Z(z); + pnt->put_M(m); + + long pointIndex = 0; + shape->InsertPoint(pnt, &pointIndex, &vbretval); + if (vbretval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + pnt->Release(); + } + } + + // ------------------------------------------------------ + // SHP_POINTM + // ------------------------------------------------------ + else if (_shpfiletype == SHP_POINTM) + { + ComHelper::CreateShape(&shape); + shape->Create(shpType, &vbretval); + shape->put_GlobalCallback(_globalCallback); + + // if (shpType == SHP_POINTM) + if (areEqualTypes) + { + ComHelper::CreatePoint(&pnt); + pnt->put_GlobalCallback(_globalCallback); + + double x, y, m; + fread(&x, sizeof(double), 1, _shpfile); + fread(&y, sizeof(double), 1, _shpfile); + fread(&m, sizeof(double), 1, _shpfile); + pnt->put_X(x); + pnt->put_Y(y); + pnt->put_M(m); + + long pointIndex = 0; + shape->InsertPoint(pnt, &pointIndex, &vbretval); + if (vbretval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + pnt->Release(); + } + } +#pragma endregion +#pragma region Polyline + // ------------------------------------------------------ + // SHP_POLYLINE + // ------------------------------------------------------ + else if (_shpfiletype == SHP_POLYLINE) + { + ComHelper::CreateShape(&shape); + shape->Create(shpType, &vbretval); + shape->put_GlobalCallback(_globalCallback); + + // if (shpType == SHP_POLYLINE) + if (areEqualTypes) + { + VARIANT_BOOL retval; + double bx, by; + int numParts; + int numPoints; + int part; + double x, y; + + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + + fread(&numParts, sizeof(int), 1, _shpfile); + fread(&numPoints, sizeof(int), 1, _shpfile); + + long partIndex = 0; + for (int i = 0; i < numParts; i++) + { + fread(&part, sizeof(int), 1, _shpfile); + partIndex = i; + shape->InsertPart(part, &partIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + } + + long pointIndex = 0; + for (int j = 0; j < numPoints; j++) + { + ComHelper::CreatePoint(&pnt); + pnt->put_GlobalCallback(_globalCallback); + fread(&x, sizeof(double), 1, _shpfile); + fread(&y, sizeof(double), 1, _shpfile); + pnt->put_X(x); + pnt->put_Y(y); + pointIndex = j; + shape->InsertPoint(pnt, &pointIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + pnt->Release(); + } + } + } + + // ------------------------------------------------------ + // SHP_POLYLINEZ + // ------------------------------------------------------ + else if (_shpfiletype == SHP_POLYLINEZ) + { + ComHelper::CreateShape(&shape); + shape->Create(shpType, &vbretval); + shape->put_GlobalCallback(_globalCallback); + // if (shpType == SHP_POLYLINEZ) + if (areEqualTypes) + { + VARIANT_BOOL retval; + double bx, by, bz, bm; + int numParts; + int numPoints; + int part; + double x, y, z, m; + + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + + fread(&numParts, sizeof(int), 1, _shpfile); + fread(&numPoints, sizeof(int), 1, _shpfile); + + long partIndex = 0; + for (int i = 0; i < numParts; i++) + { + fread(&part, sizeof(int), 1, _shpfile); + partIndex = i; + shape->InsertPart(part, &partIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + } + + long pointIndex = 0; + //Read the x, y part of the point + for (int j = 0; j < numPoints; j++) + { + ComHelper::CreatePoint(&pnt); + pnt->put_GlobalCallback(_globalCallback); + fread(&x, sizeof(double), 1, _shpfile); + fread(&y, sizeof(double), 1, _shpfile); + pnt->put_X(x); + pnt->put_Y(y); + pointIndex = j; + shape->InsertPoint(pnt, &pointIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + pnt->Release(); + } + + fread(&bz, sizeof(double), 1, _shpfile); + fread(&bz, sizeof(double), 1, _shpfile); + for (int k = 0; k < numPoints; k++) - { - fread(&z, sizeof(double), 1, _shpfile); - pointIndex = k; - IPoint * pnt = NULL; - shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) - { - shape->Release(); - return NULL; - } - pnt->put_Z(z); - pnt->Release(); - } - - fread(&bm, sizeof(double), 1, _shpfile); - fread(&bm, sizeof(double), 1, _shpfile); - - for (int mc = 0; mc < numPoints; mc++) - { - fread(&m, sizeof(double), 1, _shpfile); - pointIndex = mc; - IPoint * pnt = NULL; - shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) - { - shape->Release(); - return NULL; - } - pnt->put_M(m); - pnt->Release(); - } - } - } - - // ------------------------------------------------------ - // SHP_POLYGONM - // ------------------------------------------------------ - else if (_shpfiletype == SHP_POLYGONM) - { - ComHelper::CreateShape(&shape); - shape->Create(shpType, &vbretval); - shape->put_GlobalCallback(_globalCallback); - // if (shpType == SHP_POLYGONM) - if (areEqualTypes) - { - VARIANT_BOOL retval; - double bx, by, bm; - int numParts; - int numPoints; - int part; - double x, y, m; - - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - - fread(&numParts, sizeof(int), 1, _shpfile); - fread(&numPoints, sizeof(int), 1, _shpfile); - - long partIndex = 0; - for (int i = 0; i < numParts; i++) - { - fread(&part, sizeof(int), 1, _shpfile); - partIndex = i; - shape->InsertPart(part, &partIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - } - - //Read the x, y part of the point - long pointIndex = 0; - for (int j = 0; j < numPoints; j++) - { - ComHelper::CreatePoint(&pnt); - pnt->put_GlobalCallback(_globalCallback); - fread(&x, sizeof(double), 1, _shpfile); - fread(&y, sizeof(double), 1, _shpfile); - pnt->put_X(x); - pnt->put_Y(y); - pointIndex = j; - shape->InsertPoint(pnt, &pointIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - pnt->Release(); - } - - // M range - fread(&bm, sizeof(double), 1, _shpfile); - fread(&bm, sizeof(double), 1, _shpfile); - - for (int mc = 0; mc < numPoints; mc++) - { - fread(&m, sizeof(double), 1, _shpfile); - pointIndex = mc; - IPoint * pnt = NULL; - shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) - { - shape->Release(); - return NULL; - } - pnt->put_M(m); - pnt->Release(); - } - } - } -#pragma endregion -#pragma region Multipoint - // ------------------------------------------------------ - // SHP_MULTIPOINT - // ------------------------------------------------------ - else if (_shpfiletype == SHP_MULTIPOINT) - { - ComHelper::CreateShape(&shape); - shape->Create(shpType, &vbretval); - shape->put_GlobalCallback(_globalCallback); - - // if (shpType == SHP_MULTIPOINT) - if (areEqualTypes) - { - VARIANT_BOOL retval; - double bx, by; - int numPoints; - double x, y; - - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - - fread(&numPoints, sizeof(int), 1, _shpfile); - - long pointIndex = 0; - for (int j = 0; j < numPoints; j++) - { - ComHelper::CreatePoint(&pnt); - pnt->put_GlobalCallback(_globalCallback); - fread(&x, sizeof(double), 1, _shpfile); - fread(&y, sizeof(double), 1, _shpfile); - pnt->put_X(x); - pnt->put_Y(y); - pointIndex = j; - shape->InsertPoint(pnt, &pointIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - pnt->Release(); - } - } - } - - // ------------------------------------------------------ - // SHP_MULTIPOINTZ - // ------------------------------------------------------ - else if (_shpfiletype == SHP_MULTIPOINTZ) - { - ComHelper::CreateShape(&shape); - shape->Create(shpType, &vbretval); - shape->put_GlobalCallback(_globalCallback); - - // if (shpType == SHP_MULTIPOINTZ) - if (areEqualTypes) - { - VARIANT_BOOL retval; - double bx, by, bz, bm; - int numPoints; - double x, y, z, m; - - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - - fread(&numPoints, sizeof(int), 1, _shpfile); - - long pointIndex = 0; - for (int j = 0; j < numPoints; j++) - { - ComHelper::CreatePoint(&pnt); - pnt->put_GlobalCallback(_globalCallback); - fread(&x, sizeof(double), 1, _shpfile); - fread(&y, sizeof(double), 1, _shpfile); - pnt->put_X(x); - pnt->put_Y(y); - pointIndex = j; - shape->InsertPoint(pnt, &pointIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - pnt->Release(); - } - - fread(&bz, sizeof(double), 1, _shpfile); - fread(&bz, sizeof(double), 1, _shpfile); - - for (int k = 0; k < numPoints; k++) - { - fread(&z, sizeof(double), 1, _shpfile); - pointIndex = k; - IPoint * pnt = NULL; - shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) - { - shape->Release(); - return NULL; - } - pnt->put_Z(z); - pnt->Release(); - } - - fread(&bm, sizeof(double), 1, _shpfile); - fread(&bm, sizeof(double), 1, _shpfile); - - for (int mc = 0; mc < numPoints; mc++) - { - fread(&m, sizeof(double), 1, _shpfile); - pointIndex = mc; - IPoint * pnt = NULL; - shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) - { - shape->Release(); - return NULL; - } - pnt->put_M(m); - pnt->Release(); - } - } - } - - // ------------------------------------------------------ - // SHP_MULTIPOINTM - // ------------------------------------------------------ - else if (_shpfiletype == SHP_MULTIPOINTM) - { - ComHelper::CreateShape(&shape); - shape->Create(shpType, &vbretval); - shape->put_GlobalCallback(_globalCallback); - - // if (shpType == SHP_MULTIPOINTM) - if (areEqualTypes) - { - VARIANT_BOOL retval; - double bx, by, bm; - int numPoints; - double x, y, m; - - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - fread(&bx, sizeof(double), 1, _shpfile); - fread(&by, sizeof(double), 1, _shpfile); - - fread(&numPoints, sizeof(int), 1, _shpfile); - - long pointIndex = 0; - for (int j = 0; j < numPoints; j++) - { - ComHelper::CreatePoint(&pnt); - pnt->put_GlobalCallback(_globalCallback); - fread(&x, sizeof(double), 1, _shpfile); - fread(&y, sizeof(double), 1, _shpfile); - pnt->put_X(x); - pnt->put_Y(y); - pointIndex = j; - shape->InsertPoint(pnt, &pointIndex, &retval); - if (retval == VARIANT_FALSE) - { - shape->Release(); - return NULL; - } - pnt->Release(); - } - - fread(&bm, sizeof(double), 1, _shpfile); - fread(&bm, sizeof(double), 1, _shpfile); - - for (int mc = 0; mc < numPoints; mc++) - { - fread(&m, sizeof(double), 1, _shpfile); - pointIndex = mc; - IPoint * pnt = NULL; - shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) - { - shape->Release(); - return NULL; - } - pnt->put_M(m); - pnt->Release(); - } - } - } -#pragma endregion - - return shape; -} -#pragma endregion - -#pragma region ShxReadingWriting - -// ************************************************************** -// ReadShx() -// ************************************************************** -BOOL CShapefile::ReadShx() -{ // guaranteed that .shx file is open - rewind(_shxfile); - _shpOffsets.clear(); - - // file code - int intbuf; - fread(&intbuf,sizeof(int),1,_shxfile); - ShapeUtility::SwapEndian((char*)&intbuf,sizeof(int)); - if( intbuf != FILE_CODE ) - return FALSE; - - // unused - int unused = UNUSEDVAL; - for(int i=0; i < UNUSEDSIZE; i++) - { - fread(&intbuf,sizeof(int),1,_shxfile); - ShapeUtility::SwapEndian((char*)&intbuf,sizeof(int)); - if( intbuf != unused ) - return FALSE; - } - - // file length (16 bit words) - fread(&intbuf,sizeof(int),1,_shxfile); - ShapeUtility::SwapEndian((char*)&intbuf,sizeof(int)); - int filelength = intbuf; - - // version - fread(&intbuf,sizeof(int),1,_shxfile); - if( intbuf != VERSION ) - return FALSE; - - // shapefile type - fread(&intbuf,sizeof(int),1,_shxfile); - _shpfiletype = (ShpfileType)intbuf; - - // bounds - fread(&_minX,sizeof(double),1,_shxfile); - fread(&_minY,sizeof(double),1,_shxfile); - fread(&_maxX,sizeof(double),1,_shxfile); - fread(&_maxY,sizeof(double),1,_shxfile); - fread(&_minZ,sizeof(double),1,_shxfile); - fread(&_maxZ,sizeof(double),1,_shxfile); - fread(&_minM,sizeof(double),1,_shxfile); - fread(&_maxM,sizeof(double),1,_shxfile); - - int readLength = HEADER_BYTES_16; - while( readLength < filelength ) - { - // offset - fread(&intbuf,sizeof(int),1,_shxfile); - ShapeUtility::SwapEndian((char*)&intbuf,sizeof(int)); - _shpOffsets.push_back(intbuf*2); // convert to (32 bit words) - - // content length - fread(&intbuf,sizeof(int),1,_shxfile); - ShapeUtility::SwapEndian((char*)&intbuf,sizeof(int)); - readLength += 4; - } - - rewind(_shxfile); - return TRUE; -} - -// ************************************************************** -// AppendToShx() -// ************************************************************** -bool CShapefile::AppendToShx(FILE* shx, IShape* shp, int offset) -{ if (!shx || !shp) return false; - - _shpOffsets.push_back(offset); - - int success = fseek(shx, 0, SEEK_END); - - ShapeUtility::WriteBigEndian(shx, offset / 2); - - int contentLength = ShapeHelper::GetContentLength(shp); - ShapeUtility::WriteBigEndian(shx, contentLength / 2); - - fflush(shx); - - return true; -} - -// ************************************************************** -// WriteShx() -// ************************************************************** -BOOL CShapefile::WriteShx(FILE * shx, ICallback * cBack) -{ ICallback* callback = cBack ? cBack : _globalCallback; - - // guaranteed that .shx file is open - rewind(shx); - - // FILE CODE - ShapeUtility::WriteBigEndian(shx, FILE_CODE); - - // unused - for(int j = 0; j < UNUSEDSIZE; j++) - { - ShapeUtility::WriteBigEndian(shx, UNUSEDVAL); - } - - // FILELENGTH (16 bit words) - int fileLength = HEADER_BYTES_16 + (int)_shapeData.size() * 4; - ShapeUtility::WriteBigEndian(shx, fileLength); - - //VERSION - int version = VERSION; - fwrite(&version, sizeof(int),1,shx); - - //SHAPEFILE TYPE - int tmpshapefiletype = (short)_shpfiletype; - fwrite(&tmpshapefiletype, sizeof(int),1,shx); - - //BOUNDS - WriteBounds(shx); - - int offset = HEADER_BYTES_32; - long numPoints = 0; - long numParts = 0; - ShpfileType shptype; - IShape * shape = NULL; - - long percent = 0, newpercent = 0; - - _shpOffsets.clear(); - int size = (int)_shapeData.size(); - for( int i = 0; i < size; i++) - { - // convert to (32 bit words) - _shpOffsets.push_back(offset); - - ShapeUtility::WriteBigEndian(shx, offset / 2); - - get_Shape(i,&shape); - shape->get_NumPoints(&numPoints); - shape->get_NumParts(&numParts); - shape->get_ShapeType(&shptype); - - int contentLength = ShapeUtility::get_ContentLength(shptype, numPoints, numParts); - - offset = offset + RECORD_HEADER_LENGTH_32 + contentLength; - - ShapeUtility::WriteBigEndian(shx, contentLength / 2); - - shape->Release(); - - CallbackHelper::Progress(callback, i, size, "Writing .shx file", _key, percent); - } - - CallbackHelper::ProgressCompleted(callback, _key); - - fflush(shx); - - return TRUE; -} -#pragma endregion - -#pragma region ShpReadingWriting - -// ************************************************************** -// GetWriteFileLength() -// ************************************************************** -int CShapefile::GetWriteFileLength() -{ IShape * sh = NULL; - long numPoints = 0; - long numParts = 0; - long part = 0; - ShpfileType shptype; - - int filelength = HEADER_BYTES_32; - - int size = (int)_shapeData.size(); - for (int i = 0; i < size; i++) - { - this->get_Shape(i, &sh); - sh->get_NumPoints(&numPoints); - sh->get_NumParts(&numParts); - sh->get_ShapeType(&shptype); - - int contentLength = ShapeUtility::get_ContentLength(shptype, numPoints, numParts); - filelength = filelength + RECORD_HEADER_LENGTH_32 + contentLength; - - sh->Release(); - } - return filelength; -} - -// ************************************************************** -// AppendToShpFile() -// ************************************************************** -bool CShapefile::AppendToShpFile(FILE* shp, IShapeWrapper* wrapper) -{ if (!shp || !wrapper) return false; - - int length = wrapper->get_ContentLength(); - - // write record header - ShapeUtility::WriteBigEndian(shp, _shapeData.size()); - ShapeUtility::WriteBigEndian(shp, length / 2); - - // write content - wrapper->RefreshBounds(); - int* data = wrapper->get_RawData(); - if (data) - { - fseek(shp, 0, SEEK_END); - size_t size = fwrite(data, sizeof(char), length, shp); - fflush(shp); - - delete[] data; - - return true; - } - - return false; -} - -// ************************************************************** -// WriteShp() -// ************************************************************** -void CShapefile::WriteBounds(FILE * shp) -{ double ShapefileBounds[8]; - ShapefileBounds[0] = _minX; - ShapefileBounds[1] = _minY; - ShapefileBounds[2] = _maxX; - ShapefileBounds[3] = _maxY; - ShapefileBounds[4] = _minZ; - ShapefileBounds[5] = _maxZ; - ShapefileBounds[6] = _minM; - ShapefileBounds[7] = _maxM; - fwrite(ShapefileBounds, sizeof(double), 8, shp); -} - -// ************************************************************** -// WriteShp() -// ************************************************************** -BOOL CShapefile::WriteShp(FILE * shp, ICallback * cBack) -{ // guaranteed that .shp file is open - rewind(shp); - - //FILE_CODE - ShapeUtility::WriteBigEndian(shp, FILE_CODE); - - //UNUSED - for(int j = 0; j < UNUSEDSIZE; j++) - { - ShapeUtility::WriteBigEndian(shp, UNUSEDVAL); - } - - //FILELENGTH (32 bit words) - int fileLength = GetWriteFileLength(); - ShapeUtility::WriteBigEndian(shp, fileLength / 2); - - //VERSION - int version = VERSION; - fwrite(&version, sizeof(int),1,shp); - - //SHAPEFILE TYPE - int tmpshapefiletype = (short)_shpfiletype; - fwrite(&tmpshapefiletype, sizeof(int),1,shp); - - //BOUNDS - WriteBounds(shp); - - long percent = 0, newpercent = 0; - - ICallback* callback = _globalCallback ? _globalCallback : cBack; - - long numPoints = 0; - long numParts = 0; - long part = 0; - IShape * sh = NULL; - - int size = _shapeData.size(); - - for( int k = 0; k < size; k++) - { - get_Shape(k,&sh); - CShape* shape = (CShape*)sh; - - IShapeWrapper* wrapper = shape->get_ShapeWrapper(); - int length = wrapper->get_ContentLength(); - - //Write the Record Header - ShapeUtility::WriteBigEndian(shp, k + 1); - ShapeUtility::WriteBigEndian(shp, length / 2); - - if ( _fastMode && _isEditingShapes) - { - wrapper->RefreshBounds(); - int* data = wrapper->get_RawData(); - fwrite(data, sizeof(char), length, shp); - delete[] data; - } - else - { - // disk based mode - // disk-based + fast data (probably a bit faster procedure can be devised) - // in-memory mode (COM points) - ShpfileType shptype = wrapper->get_ShapeType(); - ShpfileType shptype2D = wrapper->get_ShapeType2D(); - numPoints = wrapper->get_PointCount(); - numParts = wrapper->get_PartCount(); - - //Write the Record - if( shptype2D == SHP_NULLSHAPE ) - { - int ishptype = shptype; - fwrite(&shptype, sizeof(int), 1, shp); - } - else if( shptype2D == SHP_POINT ) - { - int ishptype = shptype; - fwrite(&ishptype,sizeof(int),1,shp); - switch (shptype) - { - case SHP_POINT: - ShapeUtility::WritePointXY(wrapper, 0, shp); - break; - case SHP_POINTZ: - ShapeUtility::WritePointXYZ(wrapper, 0, shp); - break; - case SHP_POINTM: - ShapeUtility::WritePointXYM(wrapper, 0, shp); - break; - } - } - else if( shptype2D == SHP_POLYLINE || shptype2D == SHP_POLYGON || shptype2D == SHP_MULTIPOINT ) - { - int ishptype = shptype; - fwrite(&ishptype,sizeof(int),1,shp); - - ShapeUtility::WriteExtentsXY(wrapper, shp); - - if (shptype2D != SHP_MULTIPOINT) // parts should be written for both polylines and polygons - fwrite(&numParts,sizeof(int),1,shp); - - fwrite(&numPoints,sizeof(int),1,shp); - - if (shptype2D != SHP_MULTIPOINT) // parts should be written for both polylines and polygons - { - for( int p = 0; p < numParts; p++ ) - { - shape->get_Part(p,&part); - fwrite(&part,sizeof(int),1,shp); - } - } - - // xy - for (int i = 0; i < numPoints; i++) { - ShapeUtility::WritePointXY(wrapper, i, shp); - } - - // z - if (shptype == SHP_POLYLINEZ || shptype == SHP_POLYGONZ || shptype == SHP_MULTIPOINTZ) - { - ShapeUtility::WriteExtentsZ(wrapper, shp); - - for (int i = 0; i < numPoints; i++) { - ShapeUtility::WritePointZ(wrapper, i, shp); - } - } - - // m - if (shptype != SHP_POLYLINE && shptype != SHP_POLYGON && shptype != SHP_MULTIPOINT) // writing for both M and Z - { - ShapeUtility::WriteExtentsM(wrapper, shp); - - for (int i = 0; i < numPoints; i++) { - ShapeUtility::WritePointM(wrapper, i, shp); - } - } - } - } - - shape->Release(); - - CallbackHelper::Progress(callback, k, size, "Writing .shp file", _key, percent); - } - - CallbackHelper::ProgressCompleted(callback, _key); - - fflush(shp); - return TRUE; -} -#pragma endregion + { + fread(&z, sizeof(double), 1, _shpfile); + pointIndex = k; + IPoint * pnt = NULL; + shape->get_Point(pointIndex, &pnt); + if (pnt == NULL) + { + shape->Release(); + return NULL; + } + pnt->put_Z(z); + pnt->Release(); + } + + fread(&bm, sizeof(double), 1, _shpfile); + fread(&bm, sizeof(double), 1, _shpfile); + + for (int mc = 0; mc < numPoints; mc++) + { + fread(&m, sizeof(double), 1, _shpfile); + pointIndex = mc; + IPoint * pnt = NULL; + shape->get_Point(pointIndex, &pnt); + if (pnt == NULL) + { + shape->Release(); + return NULL; + } + pnt->put_M(m); + //Rob Cairns 20-Dec-05 + pnt->Release(); + } + } + } + + // ------------------------------------------------------ + // SHP_POLYLINEM + // ------------------------------------------------------ + else if (_shpfiletype == SHP_POLYLINEM) + { + ComHelper::CreateShape(&shape); + shape->Create(shpType, &vbretval); + shape->put_GlobalCallback(_globalCallback); + + // if (shpType == SHP_POLYLINEM) + if (areEqualTypes) + { + VARIANT_BOOL retval; + double bx, by, bm; + int numParts; + int numPoints; + int part; + double x, y, m; + + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + + fread(&numParts, sizeof(int), 1, _shpfile); + fread(&numPoints, sizeof(int), 1, _shpfile); + + long partIndex = 0; + for (int i = 0; i < numParts; i++) + { + fread(&part, sizeof(int), 1, _shpfile); + partIndex = i; + shape->InsertPart(part, &partIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + } + + long pointIndex = 0; + //Read the x, y part of the point + for (int j = 0; j < numPoints; j++) + { + ComHelper::CreatePoint(&pnt); + pnt->put_GlobalCallback(_globalCallback); + fread(&x, sizeof(double), 1, _shpfile); + fread(&y, sizeof(double), 1, _shpfile); + pnt->put_X(x); + pnt->put_Y(y); + pointIndex = j; + shape->InsertPoint(pnt, &pointIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + pnt->Release(); + } + + fread(&bm, sizeof(double), 1, _shpfile); + fread(&bm, sizeof(double), 1, _shpfile); + + for (int mc = 0; mc < numPoints; mc++) + { + fread(&m, sizeof(double), 1, _shpfile); + pointIndex = mc; + IPoint * pnt = NULL; + shape->get_Point(pointIndex, &pnt); + if (pnt == NULL) + { + shape->Release(); + return NULL; + } + pnt->put_M(m); + pnt->Release(); + + } + } + } +#pragma endregion +#pragma region Polygon + // ------------------------------------------------------ + // SHP_POLYGON + // ------------------------------------------------------ + else if (_shpfiletype == SHP_POLYGON) + { + ComHelper::CreateShape(&shape); + shape->Create(shpType, &vbretval); + shape->put_GlobalCallback(_globalCallback); + + // if (shpType == SHP_POLYGON) + if (areEqualTypes) + { + VARIANT_BOOL retval; + double bx, by; + int numParts; + int numPoints; + int part; + double x, y; + + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + + fread(&numParts, sizeof(int), 1, _shpfile); + fread(&numPoints, sizeof(int), 1, _shpfile); + + long partIndex = 0; + for (int i = 0; i < numParts; i++) + { + fread(&part, sizeof(int), 1, _shpfile); + partIndex = i; + shape->InsertPart(part, &partIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + } + + long pointIndex = 0; + for (int j = 0; j < numPoints; j++) + { + ComHelper::CreatePoint(&pnt); + pnt->put_GlobalCallback(_globalCallback); + fread(&x, sizeof(double), 1, _shpfile); + fread(&y, sizeof(double), 1, _shpfile); + pnt->put_X(x); + pnt->put_Y(y); + pointIndex = j; + shape->InsertPoint(pnt, &pointIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + pnt->Release(); + } + } + } + + // ------------------------------------------------------ + // SHP_POLYGONZ + // ------------------------------------------------------ + else if (_shpfiletype == SHP_POLYGONZ) + { + ComHelper::CreateShape(&shape); + shape->Create(shpType, &vbretval); + shape->put_GlobalCallback(_globalCallback); + // if (shpType == SHP_POLYGONZ) + if (areEqualTypes) + { + VARIANT_BOOL retval; + double bx, by, bz, bm; + int numParts; + int numPoints; + int part; + double x, y, z, m; + + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + + fread(&numParts, sizeof(int), 1, _shpfile); + fread(&numPoints, sizeof(int), 1, _shpfile); + + long partIndex = 0; + for (int i = 0; i < numParts; i++) + { + fread(&part, sizeof(int), 1, _shpfile); + partIndex = i; + shape->InsertPart(part, &partIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + } + + //Read the x, y part of the point + long pointIndex = 0; + for (int j = 0; j < numPoints; j++) + { + ComHelper::CreatePoint(&pnt); + pnt->put_GlobalCallback(_globalCallback); + fread(&x, sizeof(double), 1, _shpfile); + fread(&y, sizeof(double), 1, _shpfile); + pnt->put_X(x); + pnt->put_Y(y); + pointIndex = j; + shape->InsertPoint(pnt, &pointIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + pnt->Release(); + } + + fread(&bz, sizeof(double), 1, _shpfile); + fread(&bz, sizeof(double), 1, _shpfile); + + for (int k = 0; k < numPoints; k++) + { + fread(&z, sizeof(double), 1, _shpfile); + pointIndex = k; + IPoint * pnt = NULL; + shape->get_Point(pointIndex, &pnt); + if (pnt == NULL) + { + shape->Release(); + return NULL; + } + pnt->put_Z(z); + pnt->Release(); + } + + fread(&bm, sizeof(double), 1, _shpfile); + fread(&bm, sizeof(double), 1, _shpfile); + + for (int mc = 0; mc < numPoints; mc++) + { + fread(&m, sizeof(double), 1, _shpfile); + pointIndex = mc; + IPoint * pnt = NULL; + shape->get_Point(pointIndex, &pnt); + if (pnt == NULL) + { + shape->Release(); + return NULL; + } + pnt->put_M(m); + pnt->Release(); + } + } + } + + // ------------------------------------------------------ + // SHP_POLYGONM + // ------------------------------------------------------ + else if (_shpfiletype == SHP_POLYGONM) + { + ComHelper::CreateShape(&shape); + shape->Create(shpType, &vbretval); + shape->put_GlobalCallback(_globalCallback); + // if (shpType == SHP_POLYGONM) + if (areEqualTypes) + { + VARIANT_BOOL retval; + double bx, by, bm; + int numParts; + int numPoints; + int part; + double x, y, m; + + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + + fread(&numParts, sizeof(int), 1, _shpfile); + fread(&numPoints, sizeof(int), 1, _shpfile); + + long partIndex = 0; + for (int i = 0; i < numParts; i++) + { + fread(&part, sizeof(int), 1, _shpfile); + partIndex = i; + shape->InsertPart(part, &partIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + } + + //Read the x, y part of the point + long pointIndex = 0; + for (int j = 0; j < numPoints; j++) + { + ComHelper::CreatePoint(&pnt); + pnt->put_GlobalCallback(_globalCallback); + fread(&x, sizeof(double), 1, _shpfile); + fread(&y, sizeof(double), 1, _shpfile); + pnt->put_X(x); + pnt->put_Y(y); + pointIndex = j; + shape->InsertPoint(pnt, &pointIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + pnt->Release(); + } + + // M range + fread(&bm, sizeof(double), 1, _shpfile); + fread(&bm, sizeof(double), 1, _shpfile); + + for (int mc = 0; mc < numPoints; mc++) + { + fread(&m, sizeof(double), 1, _shpfile); + pointIndex = mc; + IPoint * pnt = NULL; + shape->get_Point(pointIndex, &pnt); + if (pnt == NULL) + { + shape->Release(); + return NULL; + } + pnt->put_M(m); + pnt->Release(); + } + } + } +#pragma endregion +#pragma region Multipoint + // ------------------------------------------------------ + // SHP_MULTIPOINT + // ------------------------------------------------------ + else if (_shpfiletype == SHP_MULTIPOINT) + { + ComHelper::CreateShape(&shape); + shape->Create(shpType, &vbretval); + shape->put_GlobalCallback(_globalCallback); + + // if (shpType == SHP_MULTIPOINT) + if (areEqualTypes) + { + VARIANT_BOOL retval; + double bx, by; + int numPoints; + double x, y; + + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + + fread(&numPoints, sizeof(int), 1, _shpfile); + + long pointIndex = 0; + for (int j = 0; j < numPoints; j++) + { + ComHelper::CreatePoint(&pnt); + pnt->put_GlobalCallback(_globalCallback); + fread(&x, sizeof(double), 1, _shpfile); + fread(&y, sizeof(double), 1, _shpfile); + pnt->put_X(x); + pnt->put_Y(y); + pointIndex = j; + shape->InsertPoint(pnt, &pointIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + pnt->Release(); + } + } + } + + // ------------------------------------------------------ + // SHP_MULTIPOINTZ + // ------------------------------------------------------ + else if (_shpfiletype == SHP_MULTIPOINTZ) + { + ComHelper::CreateShape(&shape); + shape->Create(shpType, &vbretval); + shape->put_GlobalCallback(_globalCallback); + + // if (shpType == SHP_MULTIPOINTZ) + if (areEqualTypes) + { + VARIANT_BOOL retval; + double bx, by, bz, bm; + int numPoints; + double x, y, z, m; + + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + + fread(&numPoints, sizeof(int), 1, _shpfile); + + long pointIndex = 0; + for (int j = 0; j < numPoints; j++) + { + ComHelper::CreatePoint(&pnt); + pnt->put_GlobalCallback(_globalCallback); + fread(&x, sizeof(double), 1, _shpfile); + fread(&y, sizeof(double), 1, _shpfile); + pnt->put_X(x); + pnt->put_Y(y); + pointIndex = j; + shape->InsertPoint(pnt, &pointIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + pnt->Release(); + } + + fread(&bz, sizeof(double), 1, _shpfile); + fread(&bz, sizeof(double), 1, _shpfile); + + for (int k = 0; k < numPoints; k++) + { + fread(&z, sizeof(double), 1, _shpfile); + pointIndex = k; + IPoint * pnt = NULL; + shape->get_Point(pointIndex, &pnt); + if (pnt == NULL) + { + shape->Release(); + return NULL; + } + pnt->put_Z(z); + pnt->Release(); + } + + fread(&bm, sizeof(double), 1, _shpfile); + fread(&bm, sizeof(double), 1, _shpfile); + + for (int mc = 0; mc < numPoints; mc++) + { + fread(&m, sizeof(double), 1, _shpfile); + pointIndex = mc; + IPoint * pnt = NULL; + shape->get_Point(pointIndex, &pnt); + if (pnt == NULL) + { + shape->Release(); + return NULL; + } + pnt->put_M(m); + pnt->Release(); + } + } + } + + // ------------------------------------------------------ + // SHP_MULTIPOINTM + // ------------------------------------------------------ + else if (_shpfiletype == SHP_MULTIPOINTM) + { + ComHelper::CreateShape(&shape); + shape->Create(shpType, &vbretval); + shape->put_GlobalCallback(_globalCallback); + + // if (shpType == SHP_MULTIPOINTM) + if (areEqualTypes) + { + VARIANT_BOOL retval; + double bx, by, bm; + int numPoints; + double x, y, m; + + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + fread(&bx, sizeof(double), 1, _shpfile); + fread(&by, sizeof(double), 1, _shpfile); + + fread(&numPoints, sizeof(int), 1, _shpfile); + + long pointIndex = 0; + for (int j = 0; j < numPoints; j++) + { + ComHelper::CreatePoint(&pnt); + pnt->put_GlobalCallback(_globalCallback); + fread(&x, sizeof(double), 1, _shpfile); + fread(&y, sizeof(double), 1, _shpfile); + pnt->put_X(x); + pnt->put_Y(y); + pointIndex = j; + shape->InsertPoint(pnt, &pointIndex, &retval); + if (retval == VARIANT_FALSE) + { + shape->Release(); + return NULL; + } + pnt->Release(); + } + + fread(&bm, sizeof(double), 1, _shpfile); + fread(&bm, sizeof(double), 1, _shpfile); + + for (int mc = 0; mc < numPoints; mc++) + { + fread(&m, sizeof(double), 1, _shpfile); + pointIndex = mc; + IPoint * pnt = NULL; + shape->get_Point(pointIndex, &pnt); + if (pnt == NULL) + { + shape->Release(); + return NULL; + } + pnt->put_M(m); + pnt->Release(); + } + } + } +#pragma endregion + + return shape; +} +#pragma endregion + +#pragma region ShxReadingWriting + +// ************************************************************** +// ReadShx() +// ************************************************************** +BOOL CShapefile::ReadShx() +{ + // guaranteed that .shx file is open + rewind(_shxfile); + _shpOffsets.clear(); + + // file code + int intbuf; + fread(&intbuf,sizeof(int),1,_shxfile); + ShapeUtility::SwapEndian((char*)&intbuf,sizeof(int)); + if( intbuf != FILE_CODE ) + return FALSE; + + // unused + int unused = UNUSEDVAL; + for(int i=0; i < UNUSEDSIZE; i++) + { + fread(&intbuf,sizeof(int),1,_shxfile); + ShapeUtility::SwapEndian((char*)&intbuf,sizeof(int)); + if( intbuf != unused ) + return FALSE; + } + + // file length (16 bit words) + fread(&intbuf,sizeof(int),1,_shxfile); + ShapeUtility::SwapEndian((char*)&intbuf,sizeof(int)); + int filelength = intbuf; + + // version + fread(&intbuf,sizeof(int),1,_shxfile); + if( intbuf != VERSION ) + return FALSE; + + // shapefile type + fread(&intbuf,sizeof(int),1,_shxfile); + _shpfiletype = (ShpfileType)intbuf; + + // bounds + fread(&_minX,sizeof(double),1,_shxfile); + fread(&_minY,sizeof(double),1,_shxfile); + fread(&_maxX,sizeof(double),1,_shxfile); + fread(&_maxY,sizeof(double),1,_shxfile); + fread(&_minZ,sizeof(double),1,_shxfile); + fread(&_maxZ,sizeof(double),1,_shxfile); + fread(&_minM,sizeof(double),1,_shxfile); + fread(&_maxM,sizeof(double),1,_shxfile); + + int readLength = HEADER_BYTES_16; + while( readLength < filelength ) + { + // offset + fread(&intbuf,sizeof(int),1,_shxfile); + ShapeUtility::SwapEndian((char*)&intbuf,sizeof(int)); + _shpOffsets.push_back(intbuf*2); // convert to (32 bit words) + + // content length + fread(&intbuf,sizeof(int),1,_shxfile); + ShapeUtility::SwapEndian((char*)&intbuf,sizeof(int)); + readLength += 4; + } + + rewind(_shxfile); + return TRUE; +} + +// ************************************************************** +// AppendToShx() +// ************************************************************** +bool CShapefile::AppendToShx(FILE* shx, IShape* shp, int offset) +{ + if (!shx || !shp) return false; + + _shpOffsets.push_back(offset); + + int success = fseek(shx, 0, SEEK_END); + + ShapeUtility::WriteBigEndian(shx, offset / 2); + + int contentLength = ShapeHelper::GetContentLength(shp); + ShapeUtility::WriteBigEndian(shx, contentLength / 2); + + fflush(shx); + + return true; +} + +// ************************************************************** +// WriteShx() +// ************************************************************** +BOOL CShapefile::WriteShx(FILE * shx, ICallback * cBack) +{ + ICallback* callback = cBack ? cBack : _globalCallback; + + // guaranteed that .shx file is open + rewind(shx); + + // FILE CODE + ShapeUtility::WriteBigEndian(shx, FILE_CODE); + + // unused + for(int j = 0; j < UNUSEDSIZE; j++) + { + ShapeUtility::WriteBigEndian(shx, UNUSEDVAL); + } + + // FILELENGTH (16 bit words) + int fileLength = HEADER_BYTES_16 + (int)_shapeData.size() * 4; + ShapeUtility::WriteBigEndian(shx, fileLength); + + //VERSION + int version = VERSION; + fwrite(&version, sizeof(int),1,shx); + + //SHAPEFILE TYPE + int tmpshapefiletype = (short)_shpfiletype; + fwrite(&tmpshapefiletype, sizeof(int),1,shx); + + //BOUNDS + WriteBounds(shx); + + int offset = HEADER_BYTES_32; + long numPoints = 0; + long numParts = 0; + ShpfileType shptype; + IShape * shape = NULL; + + long percent = 0, newpercent = 0; + + _shpOffsets.clear(); + int size = (int)_shapeData.size(); + for( int i = 0; i < size; i++) + { + // convert to (32 bit words) + _shpOffsets.push_back(offset); + + ShapeUtility::WriteBigEndian(shx, offset / 2); + + get_Shape(i,&shape); + shape->get_NumPoints(&numPoints); + shape->get_NumParts(&numParts); + shape->get_ShapeType(&shptype); + + int contentLength = ShapeUtility::get_ContentLength(shptype, numPoints, numParts); + + offset = offset + RECORD_HEADER_LENGTH_32 + contentLength; + + ShapeUtility::WriteBigEndian(shx, contentLength / 2); + + shape->Release(); + + long percent = static_cast(static_cast(i + 1) / size * 100); + + if (percent % 10 == 0) + CallbackHelper::Progress(callback, i, size, "Writing .shx file", _key, percent); + } + + CallbackHelper::ProgressCompleted(callback, _key); + + fflush(shx); + + return TRUE; +} +#pragma endregion + +#pragma region ShpReadingWriting + +// ************************************************************** +// GetWriteFileLength() +// ************************************************************** +int CShapefile::GetWriteFileLength() +{ + IShape * sh = NULL; + long numPoints = 0; + long numParts = 0; + long part = 0; + ShpfileType shptype; + + int filelength = HEADER_BYTES_32; + + int size = (int)_shapeData.size(); + for (int i = 0; i < size; i++) + { + this->get_Shape(i, &sh); + sh->get_NumPoints(&numPoints); + sh->get_NumParts(&numParts); + sh->get_ShapeType(&shptype); + + int contentLength = ShapeUtility::get_ContentLength(shptype, numPoints, numParts); + filelength = filelength + RECORD_HEADER_LENGTH_32 + contentLength; + + sh->Release(); + } + return filelength; +} + +// ************************************************************** +// AppendToShpFile() +// ************************************************************** +bool CShapefile::AppendToShpFile(FILE* shp, IShapeWrapper* wrapper) +{ + if (!shp || !wrapper) return false; + + int length = wrapper->get_ContentLength(); + + // write record header + ShapeUtility::WriteBigEndian(shp, _shapeData.size()); + ShapeUtility::WriteBigEndian(shp, length / 2); + + // write content + wrapper->RefreshBounds(); + int* data = wrapper->get_RawData(); + if (data) + { + fseek(shp, 0, SEEK_END); + size_t size = fwrite(data, sizeof(char), length, shp); + fflush(shp); + + delete[] data; + + return true; + } + + return false; +} + +// ************************************************************** +// WriteShp() +// ************************************************************** +void CShapefile::WriteBounds(FILE * shp) +{ + double ShapefileBounds[8]; + ShapefileBounds[0] = _minX; + ShapefileBounds[1] = _minY; + ShapefileBounds[2] = _maxX; + ShapefileBounds[3] = _maxY; + ShapefileBounds[4] = _minZ; + ShapefileBounds[5] = _maxZ; + ShapefileBounds[6] = _minM; + ShapefileBounds[7] = _maxM; + fwrite(ShapefileBounds, sizeof(double), 8, shp); +} + +// ************************************************************** +// WriteShp() +// ************************************************************** +BOOL CShapefile::WriteShp(FILE * shp, ICallback * cBack) +{ + // guaranteed that .shp file is open + rewind(shp); + + //FILE_CODE + ShapeUtility::WriteBigEndian(shp, FILE_CODE); + + //UNUSED + for(int j = 0; j < UNUSEDSIZE; j++) + { + ShapeUtility::WriteBigEndian(shp, UNUSEDVAL); + } + + //FILELENGTH (32 bit words) + int fileLength = GetWriteFileLength(); + ShapeUtility::WriteBigEndian(shp, fileLength / 2); + + //VERSION + int version = VERSION; + fwrite(&version, sizeof(int),1,shp); + + //SHAPEFILE TYPE + int tmpshapefiletype = (short)_shpfiletype; + fwrite(&tmpshapefiletype, sizeof(int),1,shp); + + //BOUNDS + WriteBounds(shp); + + long percent = 0, newpercent = 0; + + ICallback* callback = _globalCallback ? _globalCallback : cBack; + + long numPoints = 0; + long numParts = 0; + long part = 0; + IShape * sh = NULL; + + int size = _shapeData.size(); + + for( int k = 0; k < size; k++) + { + get_Shape(k,&sh); + CShape* shape = (CShape*)sh; + + IShapeWrapper* wrapper = shape->get_ShapeWrapper(); + int length = wrapper->get_ContentLength(); + + //Write the Record Header + ShapeUtility::WriteBigEndian(shp, k + 1); + ShapeUtility::WriteBigEndian(shp, length / 2); + + if ( _fastMode && _isEditingShapes) + { + wrapper->RefreshBounds(); + int* data = wrapper->get_RawData(); + fwrite(data, sizeof(char), length, shp); + delete[] data; + } + else + { + // disk based mode + // disk-based + fast data (probably a bit faster procedure can be devised) + // in-memory mode (COM points) + ShpfileType shptype = wrapper->get_ShapeType(); + ShpfileType shptype2D = wrapper->get_ShapeType2D(); + numPoints = wrapper->get_PointCount(); + numParts = wrapper->get_PartCount(); + + //Write the Record + if( shptype2D == SHP_NULLSHAPE ) + { + int ishptype = shptype; + fwrite(&shptype, sizeof(int), 1, shp); + } + else if( shptype2D == SHP_POINT ) + { + int ishptype = shptype; + fwrite(&ishptype,sizeof(int),1,shp); + switch (shptype) + { + case SHP_POINT: + ShapeUtility::WritePointXY(wrapper, 0, shp); + break; + case SHP_POINTZ: + ShapeUtility::WritePointXYZ(wrapper, 0, shp); + break; + case SHP_POINTM: + ShapeUtility::WritePointXYM(wrapper, 0, shp); + break; + } + } + else if( shptype2D == SHP_POLYLINE || shptype2D == SHP_POLYGON || shptype2D == SHP_MULTIPOINT ) + { + int ishptype = shptype; + fwrite(&ishptype,sizeof(int),1,shp); + + ShapeUtility::WriteExtentsXY(wrapper, shp); + + if (shptype2D != SHP_MULTIPOINT) // parts should be written for both polylines and polygons + fwrite(&numParts,sizeof(int),1,shp); + + fwrite(&numPoints,sizeof(int),1,shp); + + if (shptype2D != SHP_MULTIPOINT) // parts should be written for both polylines and polygons + { + for( int p = 0; p < numParts; p++ ) + { + shape->get_Part(p,&part); + fwrite(&part,sizeof(int),1,shp); + } + } + + // xy + for (int i = 0; i < numPoints; i++) { + ShapeUtility::WritePointXY(wrapper, i, shp); + } + + // z + if (shptype == SHP_POLYLINEZ || shptype == SHP_POLYGONZ || shptype == SHP_MULTIPOINTZ) + { + ShapeUtility::WriteExtentsZ(wrapper, shp); + + for (int i = 0; i < numPoints; i++) { + ShapeUtility::WritePointZ(wrapper, i, shp); + } + } + + // m + if (shptype != SHP_POLYLINE && shptype != SHP_POLYGON && shptype != SHP_MULTIPOINT) // writing for both M and Z + { + ShapeUtility::WriteExtentsM(wrapper, shp); + + for (int i = 0; i < numPoints; i++) { + ShapeUtility::WritePointM(wrapper, i, shp); + } + } + } + } + + shape->Release(); + + CallbackHelper::Progress(callback, k, size, "Writing .shp file", _key, percent); + } + + CallbackHelper::ProgressCompleted(callback, _key); + + fflush(shp); + return TRUE; +} +#pragma endregion From c47d3ab4718b21a9fa67acca5db978f3d0326ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 12:38:05 +0200 Subject: [PATCH 09/55] Added CorrectAxisOrder to fix proejction handling. Fixed CGeoProjection::get_IsSame to not fail to detect actual match. --- src/COM classes/GeoProjection.cpp | 164 ++++++++++++++++++--- src/COM classes/GeoProjection.h | 1 + src/COM classes/Shapefile.cpp | 32 +++- src/COM classes/Shapefile_SpatialIndex.cpp | 1 + 4 files changed, 179 insertions(+), 19 deletions(-) diff --git a/src/COM classes/GeoProjection.cpp b/src/COM classes/GeoProjection.cpp index ea7487dd..c0036367 100644 --- a/src/COM classes/GeoProjection.cpp +++ b/src/COM classes/GeoProjection.cpp @@ -415,6 +415,7 @@ STDMETHODIMP CGeoProjection::ImportFromWKT(const BSTR proj, VARIANT_BOOL* retVal else { CString strProj(proj); + strProj = CorrectAxisOrder(strProj).c_str(); OGRErr result = OGRERR_NONE; // use newer method importFromWkt(const char*) @@ -449,6 +450,8 @@ STDMETHODIMP CGeoProjection::ImportFromAutoDetect(BSTR proj, VARIANT_BOOL* retVa { const CString s(proj); *retVal = VARIANT_FALSE; + if(s.GetLength() == 0) + return S_OK; const OGRErr err = _projection->SetFromUserInput(s); @@ -529,6 +532,38 @@ STDMETHODIMP CGeoProjection::get_IsSame(IGeoProjection* proj, VARIANT_BOOL* pVal return S_OK; } + CComBSTR name1; + CComBSTR name2; + this->get_Name(&name1); + proj->get_Name(&name2); + if (name1 == name2) + { + *pVal = VARIANT_TRUE; + return S_OK; + } + + CComBSTR projName1; + CComBSTR projName2; + this->get_ProjectionName(&projName1); + proj->get_ProjectionName(&projName2); + if (projName1 == projName2) + { + *pVal = VARIANT_TRUE; + return S_OK; + } + + std::wstring pn1(projName1, SysStringLen(projName1)); + std::wstring pn2(projName2, SysStringLen(projName2)); + std::replace(pn1.begin(), pn1.end(), '-', ' '); + std::replace(pn2.begin(), pn2.end(), '-', ' '); + pn1.erase(std::remove(pn1.begin(), pn1.end(), '.'), pn1.end()); + pn2.erase(std::remove(pn2.begin(), pn2.end(), '.'), pn2.end()); + if (pn1 == pn2) + { + *pVal = VARIANT_TRUE; + return S_OK; + } + const OGRSpatialReference* const sr = dynamic_cast(proj)->get_SpatialReference(); // use OGRSpatialReference to test same-ness *pVal = (_projection->IsSame(sr) == 0) ? VARIANT_FALSE : VARIANT_TRUE; @@ -898,16 +933,20 @@ bool CGeoProjection::ReadFromFileCore(CStringW filename, bool esri) // determine file length fseek(prjFile, 0L, SEEK_END); const int fileLen = ftell(prjFile); - fseek(prjFile, 0L, SEEK_SET); - // allocate buffer for file - vector pszWKT = vector(fileLen, 0); - // read the file - fread(pszWKT.data(), sizeof(char), fileLen, prjFile); - fclose(prjFile); - // do the import - err = _projection->SetFromUserInput(pszWKT.data()); - // clean up - //delete pszWKT; + if (fileLen > 0) { + fseek(prjFile, 0L, SEEK_SET); + // allocate buffer for file + vector pszWKT = vector(fileLen, 0); + // read the file + fread(pszWKT.data(), sizeof(char), fileLen, prjFile); + fclose(prjFile); + // do the import + err = _projection->SetFromUserInput(pszWKT.data()); + // clean up + //delete pszWKT; + } + else + err = OGRERR_NOT_ENOUGH_DATA; } if (err != OGRERR_NONE) @@ -955,11 +994,6 @@ bool CGeoProjection::WriteToFileCore(CStringW filename, bool esri) if (filename.CompareNoCase(L"") == 0) return false; - FILE* prjFile = _wfopen(filename, L"wb"); - if (!prjFile) { - return false; - } - CString proj; CComBSTR bstr; if (esri) @@ -976,13 +1010,17 @@ bool CGeoProjection::WriteToFileCore(CStringW filename, bool esri) if (proj.GetLength() != 0) { + FILE* prjFile = _wfopen(filename, L"wb"); + if (!prjFile) { + return false; + } + fputs((LPCSTR)proj, prjFile); //fprintf(prjFile, "%s", (LPCSTR)proj); + fclose(prjFile); + prjFile = nullptr; } - fclose(prjFile); - prjFile = nullptr; - return true; } @@ -1457,4 +1495,94 @@ bool CGeoProjection::ParseLinearUnits(CString s, tkUnitsOfMeasure& units) Debug::WriteLine("Unrecognized linear units: %s", s); return false; +} + +std::string CGeoProjection::CorrectAxisOrder(CString wkt) +{ + std::string result; + + std::vector dual_value; + dual_value.emplace_back("AUTHORITY"); + dual_value.emplace_back("AXIS"); + dual_value.emplace_back("PARAMETER"); + dual_value.emplace_back("PRIMEM"); + dual_value.emplace_back("UNIT"); + std::string tripple_value = "SPHEROID"; + + std::vector lines; + std::string currentLine; + int openCount = 0; // [ + int commaCount = 0; + for (size_t i = 0; i < wkt.GetLength(); i++) + { + auto ch = wkt[i]; + if (ch == '\r' || ch == '\n') + continue; + else if (ch == '[') + openCount++; + else if (ch == ']') + openCount--; + else if (ch == ',') + { + currentLine += ch; + commaCount++; + auto len = currentLine.find('['); + auto tag = currentLine.substr(0, len); + // Trim left + tag.erase(tag.begin(), std::find_if(tag.begin(), tag.end(), [](unsigned char ch) { + return !std::isspace(ch); + })); + + //tag = "AXIS"; + std::vector match_array; + match_array.emplace_back(tag); + + if (std::find_first_of(dual_value.begin(), dual_value.end(), match_array.begin(), match_array.end()) != dual_value.end()) + { + if (commaCount < 2) + continue; + } + + if (tripple_value == tag) + { + if (commaCount < 3) + continue; + } + + lines.emplace_back(currentLine.c_str()); + currentLine.clear(); + commaCount = 0; + continue; + } + + currentLine += ch; + } + lines.emplace_back(currentLine.c_str()); + + int position1 = -1; + int position2 = -1; + int pos = 0; + for (auto line : lines) + { + auto f1 = line.find("AXIS[\"Northing\"") != std::string::npos; + auto f2 = line.find("AXIS[\"Easting\"") != std::string::npos; + if (position1 == -1 && line.find("AXIS[\"Northing\"") != std::string::npos) + position1 = pos; + else if (position2 == -1 && line.find("AXIS[\"Easting\"") != std::string::npos) + position2 = pos; + pos++; + } + + if (position1 < position2) + std::swap(lines[position1], lines[position2]); + + for (auto line : lines) + { + if (line[0] == '\n') + line = line.substr(1, line.length() - 1); + result += line; + result += "\r\n"; + } + + return result; } \ No newline at end of file diff --git a/src/COM classes/GeoProjection.h b/src/COM classes/GeoProjection.h index 1adc508f..8fde6603 100644 --- a/src/COM classes/GeoProjection.h +++ b/src/COM classes/GeoProjection.h @@ -164,6 +164,7 @@ class ATL_NO_VTABLE CGeoProjection : OGRSpatialReference* get_SpatialReference() noexcept { return _projection; } void SetIsFrozen(bool frozen) noexcept { _isFrozen = frozen; } void InjectSpatialReference(const gsl::not_null sr); + static std::string CorrectAxisOrder(CString wkt); }; OBJECT_ENTRY_AUTO(__uuidof(GeoProjection), CGeoProjection) diff --git a/src/COM classes/Shapefile.cpp b/src/COM classes/Shapefile.cpp index 67c99c78..2f7e021d 100644 --- a/src/COM classes/Shapefile.cpp +++ b/src/COM classes/Shapefile.cpp @@ -35,6 +35,7 @@ #include "LabelsHelper.h" #include "ShapeStyleHelper.h" #include "TableClass.h" +#include #ifdef _DEBUG #define new DEBUG_NEW @@ -137,6 +138,7 @@ CShapefile::CShapefile() ComHelper::CreateInstance(idUndoList, (IDispatch**)&_undoList); gReferenceCounter.AddRef(tkInterface::idShapefile); + //gReferenceCounter.AddRef(this); } CShapefile::~CShapefile() @@ -183,6 +185,7 @@ CShapefile::~CShapefile() _undoList->Release(); } gReferenceCounter.Release(tkInterface::idShapefile); + //gReferenceCounter.Release(this); } std::vector* CShapefile::get_ShapeVector() @@ -1035,7 +1038,11 @@ STDMETHODIMP CShapefile::Close(VARIANT_BOOL* retval) _categories->Clear(); } *retval = VARIANT_TRUE; - +#if DEBUG + CString sError; + sError.AppendFormat("CShapefile::Close() returned: {0}\r\n", *retval); + ::OutputDebugStringA(sError.GetBuffer()); +#endif return S_OK; } @@ -2280,6 +2287,8 @@ CPLXMLNode* CShapefile::SerializeCore(const VARIANT_BOOL saveSelection, CString if (s != "") Utility::CPLCreateXMLAttributeAndValue(psTree, "VisibilityExpression", s); + if (_sourceType == sstUninitialized) + Utility::CPLCreateXMLAttributeAndValue(psTree, "SourceType", "Uninitialized"); if (_useQTree != FALSE) Utility::CPLCreateXMLAttributeAndValue(psTree, "UseQTree", CPLString().Printf("%d", _useQTree)); @@ -2316,6 +2325,10 @@ CPLXMLNode* CShapefile::SerializeCore(const VARIANT_BOOL saveSelection, CString Utility::CPLCreateXMLAttributeAndValue(psTree, "SortAscending", CPLString().Printf("%d", static_cast(_sortAscending))); + s = CString(_key); + if (s != "") + Utility::CPLCreateXMLAttributeAndValue(psTree, "Key", s); + // drawing options CPLXMLNode* node = static_cast(_defaultDrawOpt)->SerializeCore("DefaultDrawingOptions"); if (node) @@ -2765,6 +2778,23 @@ bool CShapefile::ReprojectCore(IGeoProjection* newProjection, LONG* reprojectedC OGRSpatialReference* projSource = static_cast(_geoProjection)->get_SpatialReference(); OGRSpatialReference* projTarget = static_cast(newProjection)->get_SpatialReference(); + char* pszWKT; + projSource->exportToPrettyWkt(&pszWKT); + auto srcWkt = CGeoProjection::CorrectAxisOrder(pszWKT); + auto ret1 = projSource->importFromWkt(srcWkt.c_str()); + /* + ::OutputDebugStringA("\r\nprojSource:\r\n\r\n"); + ::OutputDebugStringA(pszWKT); */ + + projTarget->exportToPrettyWkt(&pszWKT); + auto dstWkt = CGeoProjection::CorrectAxisOrder(pszWKT); + auto ret2 = projTarget->importFromWkt(dstWkt.c_str()); + /* + ::OutputDebugStringA("\r\nprojTarget:\r\n"); + ::OutputDebugStringA(pszWKT); + ::OutputDebugStringA("\r\n"); */ + + OGRCoordinateTransformation* transf = OGRCreateCoordinateTransformation(projSource, projTarget); if (!transf) { diff --git a/src/COM classes/Shapefile_SpatialIndex.cpp b/src/COM classes/Shapefile_SpatialIndex.cpp index c4d31df5..03815588 100644 --- a/src/COM classes/Shapefile_SpatialIndex.cpp +++ b/src/COM classes/Shapefile_SpatialIndex.cpp @@ -197,6 +197,7 @@ STDMETHODIMP CShapefile::get_CanUseSpatialIndex(IExtents* pArea, VARIANT_BOOL* p if (_shpfileName.GetLength() <= 3) { + // dhe, Noisy error? ErrorMessage(tkINVALID_FOR_INMEMORY_OBJECT); return S_OK; } From aa23c80ba405d5da28f0ca6368d73ed6986f0a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 12:39:17 +0200 Subject: [PATCH 10/55] Fixed CField::Clone() whas not setting alias. --- src/COM classes/Field.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/COM classes/Field.cpp b/src/COM classes/Field.cpp index 8853396d..e97b6101 100644 --- a/src/COM classes/Field.cpp +++ b/src/COM classes/Field.cpp @@ -237,6 +237,7 @@ STDMETHODIMP CField::Clone(/*[out, retval]*/ IField** retVal) fld->put_Precision(_precision); fld->put_Type(_type); fld->put_Name(_name); + fld->put_Alias(_alias); fld->put_Width(_width); *retVal = fld; return S_OK; From fb4ac9cec01df763e2fe644587b595f0bda8916a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 13:04:12 +0200 Subject: [PATCH 11/55] Changed to use square tiles (from WMS) Added support for setting tkWmsBoundingBoxOrder on WMS layer. Fixed TileManager::IsNewRequest(). --- src/COM classes/GdalRasterBand.cpp | 3 + src/COM classes/WmsLayer.cpp | 43 +++++ src/COM classes/WmsLayer.h | 6 +- src/Drawing/TilesDrawer.cpp | 190 ++++++++++++++++++- src/Drawing/TilesDrawer.h | 15 +- src/MapControl/Map_Tiles.cpp | 8 + src/Tiles/Caching/DiskCache.cpp | 5 + src/Tiles/Loaders/ITileLoader.cpp | 1 + src/Tiles/Projections/BaseProjection.cpp | 8 +- src/Tiles/Projections/BaseProjection.h | 5 + src/Tiles/Projections/CustomProjection.cpp | 39 +++- src/Tiles/Providers/BaseProvider.cpp | 17 ++ src/Tiles/Providers/WmsCustomProvider.cpp | 25 ++- src/Tiles/Providers/WmsCustomProvider.h | 6 +- src/Tiles/Providers/WmsProviderBase.cpp | 3 +- src/Tiles/TileCore.h | 7 + src/Tiles/TileHelper.cpp | 2 +- src/Tiles/TileManager.cpp | 19 +- src/Tiles/TileManager.h | 1 + src/Utilities/Debugging/ReferenceCounter.cpp | 90 ++++++++- src/Utilities/Debugging/ReferenceCounter.h | 26 +++ 21 files changed, 498 insertions(+), 21 deletions(-) diff --git a/src/COM classes/GdalRasterBand.cpp b/src/COM classes/GdalRasterBand.cpp index 5ccd0606..8c1ad946 100644 --- a/src/COM classes/GdalRasterBand.cpp +++ b/src/COM classes/GdalRasterBand.cpp @@ -65,6 +65,7 @@ STDMETHODIMP CGdalRasterBand::get_Minimum(DOUBLE* pVal) if (!success) { + // Not an error, the band has no minimum value ErrorMessage("Failed to retrieve minimum."); } @@ -87,7 +88,9 @@ STDMETHODIMP CGdalRasterBand::get_Maximum(DOUBLE* pVal) if (!success) { + // Not an error, the band has no maximum value ErrorMessage("Failed to retrieve maximum."); + *pVal = 255; } return S_OK; diff --git a/src/COM classes/WmsLayer.cpp b/src/COM classes/WmsLayer.cpp index b8a17536..c6635d30 100644 --- a/src/COM classes/WmsLayer.cpp +++ b/src/COM classes/WmsLayer.cpp @@ -823,3 +823,46 @@ STDMETHODIMP CWmsLayer::put_Styles(BSTR newVal) return S_OK; } + +// ******************************************************** +// BoundingBoxOrder() +// ******************************************************** +STDMETHODIMP CWmsLayer::get_BoundingBoxOrder(tkWmsBoundingBoxOrder* pVal) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()); + + *pVal = _provider->get_BoundingBoxOrder(); + + return S_OK; +} + +STDMETHODIMP CWmsLayer::put_BoundingBoxOrder(tkWmsBoundingBoxOrder newVal) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()); + + _provider->set_BoundingBoxOrder(newVal); + + return S_OK; +} + + +// ******************************************************** +// TileSize() +// ******************************************************** +STDMETHODIMP CWmsLayer::get_TileSize(LONG* pVal) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()); + + *pVal = _provider->get_TileSize(); + + return S_OK; +} + +STDMETHODIMP CWmsLayer::put_TileSize(LONG newVal) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()); + + _provider->set_TileSize(newVal); + + return S_OK; +} \ No newline at end of file diff --git a/src/COM classes/WmsLayer.h b/src/COM classes/WmsLayer.h index 035d0b7d..a18384ef 100644 --- a/src/COM classes/WmsLayer.h +++ b/src/COM classes/WmsLayer.h @@ -99,8 +99,12 @@ class ATL_NO_VTABLE CWmsLayer : STDMETHOD(put_Version)(tkWmsVersion newVal); STDMETHOD(get_Styles)(BSTR* pVal); STDMETHOD(put_Styles)(BSTR newVal); + STDMETHOD(get_BoundingBoxOrder)(tkWmsBoundingBoxOrder* pVal); + STDMETHOD(put_BoundingBoxOrder)(tkWmsBoundingBoxOrder newVal); + STDMETHOD(get_TileSize)(LONG* pVal); + STDMETHOD(put_TileSize)(LONG newVal); -private: +private: BSTR _key; long _lastErrorCode; WmsCustomProvider* _provider; diff --git a/src/Drawing/TilesDrawer.cpp b/src/Drawing/TilesDrawer.cpp index 0453ba30..1d9c072c 100644 --- a/src/Drawing/TilesDrawer.cpp +++ b/src/Drawing/TilesDrawer.cpp @@ -17,7 +17,10 @@ ************************************************************************************** * Contributor(s): * (Open source contributors should list themselves and their modifications here). */ - #include "stdafx.h" +#include "stdafx.h" +#define DEBUG_TILES_DRAWER 1 +#include +#include #include "TilesDrawer.h" #include "TileHelper.h" #include "CustomProjection.h" @@ -33,6 +36,32 @@ void TilesDrawer::DrawTiles( TileManager* manager, IGeoProjection* mapProjection { if (!manager) return; +#if LOG_TILE_DRAWING + if (_pTileLog != nullptr) + _pTileLog->close(); + + CString fileName; + auto t = std::time(nullptr); + auto tm = *std::localtime(&t); + std::ostringstream oss; + //oss << std::put_time(&tm, "%Y-%m-%d_%H%M%S"); + oss << std::put_time(&tm, "%Y-%m-%d_%H%M%S"); + auto timeStr = oss.str(); + fileName.Empty(); + auto nr = GetTileDrawCount(); + fileName.Format(R"(C:\Temp\tiles\tilesLog_%hs_%d.txt)", timeStr.c_str(), nr); + struct stat buffer; + /*auto exist = stat(fileName.GetString(), &buffer) == 0; + if (exist) + { + // if file exists, append to it + fileName.AppendFormat("_%d.txt", 1); + }*/ + + _pTileLog = new std::ofstream(); + _pTileLog->open(fileName.GetString(), std::ios::out | std::ios::app); +#endif + BaseProvider* provider = manager->get_Provider(); if (!provider) return; @@ -42,12 +71,32 @@ void TilesDrawer::DrawTiles( TileManager* manager, IGeoProjection* mapProjection InitImageAttributes(manager, attr); bool isSame = IsSameProjection(mapProjection, provider); - + // copy to temporary vector, for not lock the original one for the whole length of drawing std::vector tiles; manager->CopyBuffer(tiles); +#if DEBUG_TILES_DRAWER + CString sOutput; + sOutput.AppendFormat("TilesDrawer::DrawTiles() isSame: %s, tiles.Count: %llu\r\n", isSame ? "True" : "False", tiles.size()); + ::OutputDebugStringA(sOutput.GetBuffer()); +#if LOG_TILE_DRAWING + _pTileLog->write(sOutput.GetString(), sOutput.GetLength()); +#endif +#endif // per tile drawing + + auto minTileY = 100000; + auto maxTileY = -100000; + for (size_t i = 0; i < tiles.size(); i++) + { + const auto tileY = tiles[i]->tileY(); + if (tileY < minTileY) + minTileY = tileY; + if (tileY > maxTileY) + maxTileY = tileY; + } + for (size_t i = 0; i < tiles.size();i++) { TileCore* tile = tiles[i]; @@ -61,7 +110,11 @@ void TilesDrawer::DrawTiles( TileManager* manager, IGeoProjection* mapProjection continue; } +#if SQUARE_TILES + DrawOverlays(tile, minTileY, maxTileY, screenBounds, attr); +#else DrawOverlays(tile, screenBounds, attr); +#endif if (drawGrid) { DrawGrid(tile, screenBounds); @@ -75,6 +128,11 @@ void TilesDrawer::DrawTiles( TileManager* manager, IGeoProjection* mapProjection { DrawWmsBounds(provider); } +#if LOG_TILE_DRAWING + _pTileLog->flush(); + _pTileLog->close(); + _pTileLog = nullptr; +#endif } // *************************************************************** @@ -108,8 +166,17 @@ void TilesDrawer::InitImageAttributes(TileManager* manager, ImageAttributes& att // *************************************************************** // DrawOverlays() // *************************************************************** +#if SQUARE_TILES +void TilesDrawer::DrawOverlays(TileCore* tile, int minTileY, int maxTileY, RectF screenBounds, ImageAttributes& attr) +#else void TilesDrawer::DrawOverlays(TileCore* tile, RectF screenBounds, ImageAttributes& attr) +#endif { + CString sOutput; +#if DEBUG_TILES_DRAWER + sOutput.AppendFormat("TilesDrawer::DrawOverlays() tileX: %d screenBounds: %f x %f tile->Overlays.size: %llu \r\n", tile->tileX(), screenBounds.Width, screenBounds.Height, tile->Overlays.size()); + ::OutputDebugStringA(sOutput.GetBuffer()); +#endif for (size_t i = 0; i < tile->Overlays.size(); i++) { Bitmap* bmp = tile->get_Bitmap(i)->m_bitmap; @@ -121,18 +188,113 @@ void TilesDrawer::DrawOverlays(TileCore* tile, RectF screenBounds, ImageAttribut Status status; double ROUNDING_TOLERANCE = 0.1; - + double dx = abs(screenBounds.Width - bmp->GetWidth()); double dy = abs(screenBounds.Height - bmp->GetHeight()); +#if !SQUARE_TILES if (dx < ROUNDING_TOLERANCE && dy < ROUNDING_TOLERANCE) { // TODO: better to check that all tiles have the same size and apply this rendering only then status = _graphics->DrawImage(bmp, Utility::Rint(screenBounds.X), Utility::Rint(screenBounds.Y)); + +#else + auto aspectRatio = screenBounds.Width / screenBounds.Height; // aspect ratio of the tile size + // How much the tile size differs from the screen bounds + auto dxyDiff = abs(dx - dy); + + /*if(i == 0) + { + CLSID pngClsid; + CString encoder = L"image/png"; + USES_CONVERSION; + Utility::GetEncoderClsid(A2OLE(encoder), &pngClsid); + bmp->Save(L"c:\\tmp\\tile_bmp.png", &pngClsid, nullptr); + } */ + + //sOutput.Format("DrawOverlays(%d, %d) screenBounds: %f, %f, %f, %f\r\n", tile->tileX(), tile->tileY(), screenBounds.X, screenBounds.Y, screenBounds.Width, screenBounds.Height); + //::OutputDebugStringA(sOutput.GetBuffer()); + + if (dxyDiff > 2.5) // Tow much difference between tile size and screen bounds size (aspect ratio) + { + // If the tile size is too different from the screen bounds, we draw it with only the top-left corner to prevent stretching of the image + // TODO: better to check that all tiles have the same size and apply this rendering only then + //status = _graphics->DrawImage(bmp, Utility::Rint(screenBounds.X), Utility::Rint(screenBounds.Y)); + + auto diff = screenBounds.Height - screenBounds.Width; + auto srcy = 0.0f; + const auto tilesDown = maxTileY - tile->tileY(); + const auto tilesUpp = tile->tileY() - minTileY; + + if (aspectRatio < 1) + { + screenBounds.Height = screenBounds.Width; + //screenBounds.Y += diff; + //screenBounds.Y += diff / 2.0f; // center the image vertically + + if (tile->tileX() == 234 && tile->tileY() == 28) + ::OutputDebugStringA("\r\n"); + + //if (tilesDown > 0) +#if RELEASE_MODE + screenBounds.Y += (diff / 2.0) * (tilesUpp + 1); +#endif + //screenBounds.Y += (diff / 1.0) * (tilesDown - 1); + + CLSID pngClsid; + const CString encoder = L"image/png"; + USES_CONVERSION; + Utility::GetEncoderClsid(A2OLE(encoder), &pngClsid); + CStringW fileName; + fileName.Format(L"C:\\tmp\\tiles\\live\\tile_bmp_%d_%d.png", tile->tileX(), tile->tileY()); + bmp->Save(fileName.GetBuffer(), &pngClsid, nullptr); + +#if DEBUG_TILES_DRAWER + //DumpTile(tile, bmp); + sOutput.Format("DrawImage(%d, %d) screenBounds.Height: %f, bmp.Height: %u, tilesDown: %d, tilesUpp: %d\r\n", tile->tileX(), tile->tileY(), screenBounds.Height, bmp->GetHeight(), tilesDown, tilesUpp); +#if LOG_TILE_DRAWING + if (_pTileLog != nullptr) + { + _pTileLog->write(sOutput.GetString(), sOutput.GetLength()); + _pTileLog->flush(); + } +#endif + ::OutputDebugStringA(sOutput.GetBuffer()); +#endif + } + else + { + ::OutputDebugStringA("aspectRatio >= 1 "); + //screenBounds.Width = screenBounds.Height; + } + + //sOutput.Format("DrawImage() screenBounds.Height: %f, bmp.Height: %u, diff: %f\r\n", screenBounds.Height, bmp->GetHeight(), diff); + //::OutputDebugStringA(sOutput.GetBuffer()); + //screenBounds.Width = bmp->GetWidth(); + //screenBounds.Height = bmp->GetHeight(); + //if (tilesUpp == 0) + status = _graphics->DrawImage(bmp, screenBounds, 0.0f, srcy, (REAL)bmp->GetWidth(), (REAL)bmp->GetHeight(), UnitPixel, &attr); + +#endif + + + +#if DEBUG_TILES_DRAWER + sOutput.Format("DrawImage(%f, %f, %f, %f, %d, %d) \r\n", screenBounds.X, screenBounds.Y, screenBounds.Width, screenBounds.Height, bmp->GetWidth(), bmp->GetHeight()); + ::OutputDebugStringA(sOutput.GetBuffer()); +#endif } else { + DumpTile(tile, bmp); status = _graphics->DrawImage(bmp, screenBounds, 0.0f, 0.0f, (REAL)bmp->GetWidth(), (REAL)bmp->GetHeight(), UnitPixel, &attr); +#if DEBUG_TILES_DRAWER + if (dxyDiff > 2.5) + { + sOutput.Format("DrawImage(%f, %f, %f, %f, %d, %d) \r\n", screenBounds.X, screenBounds.Y, screenBounds.Width, screenBounds.Height, bmp->GetWidth(), bmp->GetHeight()); + ::OutputDebugStringA(sOutput.GetBuffer()); + } +#endif } if (status != Gdiplus::Status::Ok) @@ -140,6 +302,8 @@ void TilesDrawer::DrawOverlays(TileCore* tile, RectF screenBounds, ImageAttribut Debug::WriteLine("Failed to draw tile."); } } + else + ::OutputDebugStringA("TilesDrawer::DrawOverlays() bmp is null \r\n"); } } @@ -148,11 +312,13 @@ void TilesDrawer::DrawOverlays(TileCore* tile, RectF screenBounds, ImageAttribut // *************************************************************** void TilesDrawer::DumpTile(TileCore* tile, Bitmap* bmp) { - if (tile->tileX() == 0) + //if (tile->tileX() == 0) { CLSID clsid; Utility::GetEncoderClsid(L"image/png", &clsid); - bmp->Save(L"D:\\buffer.png", &clsid, NULL); + CStringW sFileName; + sFileName.Format(L"C:\\Temp\\tiles\\tile_%d_%d.png", tile->tileX(), tile->tileY()); + bmp->Save(sFileName, &clsid, nullptr); } } @@ -222,10 +388,24 @@ bool TilesDrawer::CalculateScreenBounds(TileCore* tile, RectF& screenBounds) return false; } +#if DEBUG_TILES_DRAWER + CString text; + text.Format("CalculateScreenBounds(%d, %d) %f, %f, %f, %f\r\n", tile->tileX(), tile->tileY(), bounds->xLng, bounds->yLat, bounds->WidthLng, bounds->HeightLat); +#if LOG_TILE_DRAWING + if (_pTileLog != nullptr) + { + _pTileLog->write(text.GetString(), text.GetLength()); + _pTileLog->flush(); + } +#endif + ::OutputDebugStringA(text.GetBuffer()); +#endif + screenBounds.X = static_cast(x); screenBounds.Y = static_cast(y); screenBounds.Width = static_cast(width); screenBounds.Height = static_cast(height); + //screenBounds.Height = static_cast(width); return true; } diff --git a/src/Drawing/TilesDrawer.h b/src/Drawing/TilesDrawer.h index 62147d34..a108421a 100644 --- a/src/Drawing/TilesDrawer.h +++ b/src/Drawing/TilesDrawer.h @@ -21,6 +21,8 @@ #include "basedrawer.h" #include "TileManager.h" +static int _tileDrawCount; + class TilesDrawer : public CBaseDrawer { public: @@ -29,6 +31,10 @@ class TilesDrawer : public CBaseDrawer : _graphics(g), _transfomation(transform) { _dc = NULL; +#if LOG_TILE_DRAWING + _pTileLog = nullptr; +#endif + _tileDrawCount = 0; _extents = extents; _pixelPerProjectionX = pixelPerProjectionX; _pixelPerProjectionY = pixelPerProjectionY; @@ -41,16 +47,23 @@ class TilesDrawer : public CBaseDrawer Gdiplus::Graphics* _graphics; IGeoProjection* _transfomation; double _pixelPerMapUnit; - +#if LOG_TILE_DRAWING + std::ofstream* _pTileLog; +#endif public: // properties IGeoProjection* get_Transform() { return _transfomation; } // WGS84 to map transformation + int GetTileDrawCount() { return _tileDrawCount++; } private: bool IsSameProjection(IGeoProjection* mapProjection, BaseProvider* provider); bool UpdateTileBounds(TileCore* tile, bool isSameProjection, int projectionChangeCount); void DrawGrid(TileCore* tile, Gdiplus::RectF& screenRect); +#if SQUARE_TILES + void DrawOverlays(TileCore* tile, int minTileY, int maxTileY, Gdiplus::RectF screenBounds, Gdiplus::ImageAttributes& attr); +#else void DrawOverlays(TileCore* tile, Gdiplus::RectF screenBounds, Gdiplus::ImageAttributes& attr); +#endif bool CalculateScreenBounds(TileCore* tile, Gdiplus::RectF& screenBounds); void DrawGridText(TileCore* tile, Gdiplus::RectF& screenRect); void InitImageAttributes(TileManager* manager, Gdiplus::ImageAttributes& attr); diff --git a/src/MapControl/Map_Tiles.cpp b/src/MapControl/Map_Tiles.cpp index 848cea75..8e835970 100644 --- a/src/MapControl/Map_Tiles.cpp +++ b/src/MapControl/Map_Tiles.cpp @@ -86,7 +86,15 @@ int CMapView::ChooseZoom(BaseProvider* provider, Extent ext, double scalingRatio tileSize *= PixelsPerMapUnit(); +#if BIG_TILE_SIZE + auto tileImageSize = 512; + auto customProvider = reinterpret_cast(provider); + if (customProvider != nullptr) + tileImageSize = static_cast(customProvider->get_TileSize()); + int minSize = (int)(tileImageSize * scalingRatio * ratio); +#else int minSize = (int)(256 * scalingRatio * ratio); +#endif if (tileSize < minSize) { break; } diff --git a/src/Tiles/Caching/DiskCache.cpp b/src/Tiles/Caching/DiskCache.cpp index 76ccf278..fa51cb83 100644 --- a/src/Tiles/Caching/DiskCache.cpp +++ b/src/Tiles/Caching/DiskCache.cpp @@ -100,7 +100,12 @@ void DiskCache::AddTile(TileCore* tile) } // TODO: better to get it from provider (as tile size is not necessarily 256 by 256 pixels) +#if BIG_TILE_SIZE + auto tileImageSize = static_cast(tile->get_TileSize()); + Gdiplus::Bitmap* bmp = new Gdiplus::Bitmap(tileImageSize, tileImageSize); +#else Gdiplus::Bitmap* bmp = new Gdiplus::Bitmap(256, 256); +#endif Gdiplus::Graphics* g = Gdiplus::Graphics::FromImage(bmp); for (size_t i = 0; i < tile->Overlays.size(); i++) diff --git a/src/Tiles/Loaders/ITileLoader.cpp b/src/Tiles/Loaders/ITileLoader.cpp index 8611df78..259e364a 100644 --- a/src/Tiles/Loaders/ITileLoader.cpp +++ b/src/Tiles/Loaders/ITileLoader.cpp @@ -20,6 +20,7 @@ // Paul Meems August 2018: Modernized the code as suggested by CLang and ReSharper #include "StdAfx.h" +#include #include "ITileLoader.h" #include "ILoadingTask.h" diff --git a/src/Tiles/Projections/BaseProjection.cpp b/src/Tiles/Projections/BaseProjection.cpp index c901ede5..83683b5b 100644 --- a/src/Tiles/Projections/BaseProjection.cpp +++ b/src/Tiles/Projections/BaseProjection.cpp @@ -84,10 +84,15 @@ void BaseProjection::GetTileSizeLatLon(CPoint point, int zoom, SizeLatLng &ret) PointLatLng pnt2; this->FromXYToLatLng(newPoint, zoom, pnt2); - + // size ret.WidthLng = fabs( pnt2.Lng - pnt1.Lng); ret.HeightLat = fabs(pnt2.Lat - pnt1.Lat); + + if (ret.WidthLng < ret.HeightLat) + ret.WidthLng = ret.HeightLat; + else if (ret.HeightLat < ret.WidthLng) + ret.HeightLat = ret.WidthLng; } // ******************************************************* @@ -137,6 +142,7 @@ void BaseProjection::getTileRectXY(Extent extentsWgs84, int zoom, CRect &rect) { CPoint p1, p2; + ::OutputDebugStringA(Debug::Format("tile extentsWgs84: %s\r\n", extentsWgs84.ToString())); FromLatLngToXY(PointLatLng(extentsWgs84.top, extentsWgs84.left), zoom, p1); FromLatLngToXY(PointLatLng(extentsWgs84.bottom, extentsWgs84.right), zoom, p2); diff --git a/src/Tiles/Projections/BaseProjection.h b/src/Tiles/Projections/BaseProjection.h index a26ee162..cdbbc596 100644 --- a/src/Tiles/Projections/BaseProjection.h +++ b/src/Tiles/Projections/BaseProjection.h @@ -30,7 +30,11 @@ class BaseProjection : _minLat(0), _maxLat(0), _minLng(0), _maxLng(0), _yMin(0.0), _yMax(0.0), _xMin(0.0), _xMax(0.0), _mapBounds(0.0, 0.0, 0.0, 0.0) { +#if BIG_TILE_SIZE + _tileSize = CSize(512, 512); +#else _tileSize = CSize(256, 256); +#endif _yInverse = false; _earthRadius = 6378137.0; _worldWide = true; @@ -68,6 +72,7 @@ class BaseProjection public: virtual void FromLatLngToXY(PointLatLng pnt, int zoom, CPoint& ret) = 0; + virtual void FromXYToLatLng(CPoint pnt, int zoom, PointLatLng& ret) = 0; virtual void FromXYToProj(CPoint pnt, int zoom, PointLatLng& ret) = 0; virtual double GetWidth() = 0; diff --git a/src/Tiles/Projections/CustomProjection.cpp b/src/Tiles/Projections/CustomProjection.cpp index 047b27e9..a73c8763 100644 --- a/src/Tiles/Projections/CustomProjection.cpp +++ b/src/Tiles/Projections/CustomProjection.cpp @@ -19,6 +19,7 @@ * (Open source contributors should list themselves and their modifications here). */ #include "stdafx.h" +#include #include "CustomProjection.h" // ******************************************************* @@ -29,7 +30,14 @@ void CustomProjection::FromLatLngToXY(PointLatLng pnt, int zoom, CPoint &ret) { double lat = pnt.Lat; double lng = pnt.Lng; - + +#if DEBUG + CComBSTR bstr; + CString proj; + _projWGS84->ExportToWktEx(&bstr); + proj = bstr; +#endif + VARIANT_BOOL vb; _projWGS84->Transform(&lng, &lat, &vb); @@ -45,9 +53,17 @@ void CustomProjection::FromProjToXY(double lat, double lng, int zoom, CPoint &re lat = Clip(lat, _yMin, _yMax); lng = Clip(lng, _xMin, _xMax); + auto width = _xMax - _xMin; + auto height = _yMax - _yMin; + auto maxSize = max(width, height); +#if SQUARE_TILES + double y = (lat - _yMin) / maxSize; + double x = (lng - _xMin) / maxSize; +#else double y = (lat - _yMin)/(_yMax - _yMin); double x = (lng - _xMin)/(_xMax - _xMin); - +#endif + CSize s; GetTileMatrixSizeXY(zoom, s); int mapSizeX = s.cx; @@ -88,8 +104,16 @@ void CustomProjection::FromXYToProj(CPoint pnt, int zoom, PointLatLng &ret) double x = Clip(pnt.x, 0, mapSizeX) / mapSizeX; double y = Clip(pnt.y, 0, mapSizeY) / mapSizeY; +#if SQUARE_TILES + auto width = _xMax - _xMin; + auto height = _yMax - _yMin; + auto maxSize = max(width, height); + x = _xMin + x * (maxSize); + y = _yMin + y * (maxSize); +#else x = _xMin + x * (_xMax - _xMin); y = _yMin + y * (_yMax - _yMin); +#endif ret.Lat = y; ret.Lng = x; @@ -102,8 +126,15 @@ void CustomProjection::GetTileSizeProj(int zoom, SizeLatLng &size) { CSize sizeInt; GetTileMatrixSizeXY(zoom, sizeInt); - size.WidthLng = (_xMax - _xMin) / (double)sizeInt.cx; - size.HeightLat = (_yMax - _yMin) / (double)sizeInt.cy; + size.WidthLng = (_xMax - _xMin) / static_cast(sizeInt.cx); + size.HeightLat = (_yMax - _yMin) / static_cast(sizeInt.cy); + +#if SQUARE_TILES + if (size.WidthLng < size.HeightLat) + size.WidthLng = size.HeightLat; // make square tiles + else if (size.WidthLng > size.HeightLat) + size.HeightLat = size.WidthLng; +#endif } // ****************************************************** diff --git a/src/Tiles/Providers/BaseProvider.cpp b/src/Tiles/Providers/BaseProvider.cpp index a367dc56..9b723a02 100644 --- a/src/Tiles/Providers/BaseProvider.cpp +++ b/src/Tiles/Providers/BaseProvider.cpp @@ -26,6 +26,7 @@ #include #include "SecureHttpClient.h" +#include "WmsCustomProvider.h" CString BaseProvider::_proxyUsername = ""; CString BaseProvider::_proxyPassword = ""; @@ -39,6 +40,18 @@ const CString filePrefix = "file:///"; TileCore* BaseProvider::GetTileImage(CPoint& pos, const int zoom) { auto* tile = new TileCore(this->Id, zoom, pos, this->_projection); // TODO: Fix compile warning + auto* customProvider = dynamic_cast(this); + + if (tile->tileX() == 234 && tile->tileY() == 28) + ::OutputDebugStringA("\r\n"); + + if (customProvider != nullptr) + { + auto bbOrder = customProvider->get_BoundingBoxOrder(); + tile->set_BoundingBoxOrder(bbOrder); + auto tileSize = customProvider->get_TileSize(); + tile->set_TileSize(tileSize); + } for (size_t i = 0; i < _subProviders.size(); i++) { @@ -172,6 +185,10 @@ CMemoryBitmap* BaseProvider::ProcessHttpRequest(void* secureHttpClient, const CS case TileHttpContentType::httpXml: if (IsWms()) { + auto status = client->GetStatus(); + CString sOutput; + sOutput.AppendFormat("WMS server response status: %d", status); + ::OutputDebugStringA(sOutput.GetBuffer()); const CString s(body); ParseServerException(s); } diff --git a/src/Tiles/Providers/WmsCustomProvider.cpp b/src/Tiles/Providers/WmsCustomProvider.cpp index cf648e98..59d55191 100644 --- a/src/Tiles/Providers/WmsCustomProvider.cpp +++ b/src/Tiles/Providers/WmsCustomProvider.cpp @@ -28,20 +28,36 @@ CString WmsCustomProvider::MakeTileImageUrl(CPoint &pos, int zoom) { CString s = _urlFormat; + auto crsKey = "srs"; + if(_version >= wv13) + crsKey = "crs"; + s += "?request=GetMap&service=WMS"; s += "&layers=" + _layers; CString temp; - temp.Format("&crs=EPSG:%d", get_CustomProjection()->get_Epsg()); + temp.Format("&%s=EPSG:%d", crsKey, get_CustomProjection()->get_Epsg()); s += temp; s += "&bbox=" + GetBoundingBox(pos, zoom, _version, _bbo); s += "&format=" + _format; +#if BIG_TILE_SIZE + auto tileImageSize = get_TileSize(); + CString tmp; + tmp.Format("&width=%d", tileImageSize); + s += tmp; + tmp.Format("&height=%d", tileImageSize); + s += tmp; + //s += "&width=512"; + //s += "&height=512"; +#else s += "&width=256"; s += "&height=256"; +#endif s += get_VersionString(); s += "&styles=" + get_Styles(); + ::OutputDebugStringA(s.GetBuffer()); return s; } @@ -50,14 +66,17 @@ CString WmsCustomProvider::MakeTileImageUrl(CPoint &pos, int zoom) // ****************************************************** CString WmsCustomProvider::get_VersionString() { - switch (_version) + auto version = _version; + if ( version == wvAuto ) + version = wv13; // Auto fall back to version 1.3 + + switch (version) { case wvEmpty: return ""; case wv100: return "&version=1.0.0"; case wv110: - case wvAuto: return "&version=1.1.1"; case wv111: return "&version=1.1.1"; diff --git a/src/Tiles/Providers/WmsCustomProvider.h b/src/Tiles/Providers/WmsCustomProvider.h index b16b0573..ba7adf17 100644 --- a/src/Tiles/Providers/WmsCustomProvider.h +++ b/src/Tiles/Providers/WmsCustomProvider.h @@ -32,6 +32,7 @@ class WmsCustomProvider : public WmsProviderBase { _version = wvAuto; _bbo = bboAuto; + _tileSize = 512; _projection = new CustomProjection(); _subProviders.push_back(this); } @@ -44,6 +45,7 @@ class WmsCustomProvider : public WmsProviderBase CString _styles; tkWmsVersion _version; tkWmsBoundingBoxOrder _bbo; + int _tileSize; public: // properties @@ -55,8 +57,10 @@ class WmsCustomProvider : public WmsProviderBase void set_Format(CString value) { _format = value; } tkWmsVersion get_Version() { return _version; } void set_Version(tkWmsVersion value) { _version = value; } - tkWmsBoundingBoxOrder get_BoundingBoxOrder() { return _bbo; } + tkWmsBoundingBoxOrder get_BoundingBoxOrder() const { return _bbo; } void set_BoundingBoxOrder(tkWmsBoundingBoxOrder bbo) { _bbo = bbo; } + int get_TileSize() const { return _tileSize; } + void set_TileSize(int tileSize) { _tileSize = tileSize; } CString get_Styles() { return _styles; } void set_Styles(CString value) { _styles = value; } diff --git a/src/Tiles/Providers/WmsProviderBase.cpp b/src/Tiles/Providers/WmsProviderBase.cpp index 462e8bd2..b82e7fd8 100644 --- a/src/Tiles/Providers/WmsProviderBase.cpp +++ b/src/Tiles/Providers/WmsProviderBase.cpp @@ -33,6 +33,8 @@ CString WmsProviderBase::GetBoundingBox(CPoint &pos, int zoom, tkWmsVersion vers pos.x++; pos.y++; _projection->FromXYToProj(pos, zoom, pnt2); + pos.x--; + pos.y--; CString s; @@ -50,7 +52,6 @@ CString WmsProviderBase::GetBoundingBox(CPoint &pos, int zoom, tkWmsVersion vers case wv111: default: bbo = tkWmsBoundingBoxOrder::bboLongLat; - } } diff --git a/src/Tiles/TileCore.h b/src/Tiles/TileCore.h index 5d3417d0..befdf160 100644 --- a/src/Tiles/TileCore.h +++ b/src/Tiles/TileCore.h @@ -88,6 +88,7 @@ class TileCore _toDelete = false; _inBuffer = false; _geogBounds = projection->CalculateGeogBounds(pnt, zoom); + _bbo = bboAuto; } virtual ~TileCore() @@ -115,6 +116,8 @@ class TileCore bool _inBuffer; // it's currently displayed or scheduled to be displayed; it must not be destroyed while cleaning the cache int _providerId; + tkWmsBoundingBoxOrder _bbo; + int _tileSize; public: // a tile may be comprised of several semi-transparent bitmaps (e.g. satellite image and labels above it) @@ -144,6 +147,10 @@ class TileCore void isDrawn(bool value) { _drawn = value; } bool toDelete() { return _toDelete; } void toDelete(bool value) { _toDelete = value; } + tkWmsBoundingBoxOrder get_BoundingBoxOrder() const { return _bbo; } + void set_BoundingBoxOrder(tkWmsBoundingBoxOrder bbo) { _bbo = bbo; } + int get_TileSize() const { return _tileSize; } + void set_TileSize(int tileSize) { _tileSize = tileSize; } public: //methods diff --git a/src/Tiles/TileHelper.cpp b/src/Tiles/TileHelper.cpp index 36131b9f..7812765c 100644 --- a/src/Tiles/TileHelper.cpp +++ b/src/Tiles/TileHelper.cpp @@ -68,7 +68,7 @@ bool TileHelper::Transform(TileCore* tile, IGeoProjection* mapProjection, bool i { // projection for tiles matches map projection (most often it's Google Mercator; EPSG:3857) PointLatLng pnt; - CustomProjection* customProj = dynamic_cast(tile->get_Projection()); + auto customProj = dynamic_cast(tile->get_Projection()); if (customProj) { diff --git a/src/Tiles/TileManager.cpp b/src/Tiles/TileManager.cpp index d8a4201e..133572bc 100644 --- a/src/Tiles/TileManager.cpp +++ b/src/Tiles/TileManager.cpp @@ -22,6 +22,7 @@ #include "StdAfx.h" #include "TileManager.h" #include "TileCacheManager.h" +#include "WmsCustomProvider.h" // ************************************************************ // set_MapCallback() @@ -150,6 +151,8 @@ bool TileManager::GetTileIndices(BaseProvider* provider, CRect& indices, int& zo return false; } + //VerifyLayers(); + if (!_map->_GetTilesForMap(provider, _scalingRatio, indices, zoom)) { Clear(); @@ -349,9 +352,20 @@ void TileManager::ClearBuffer() // ********************************************************* bool TileManager::IsNewRequest(Extent& mapExtents, CRect indices, int providerId, int zoom) { + auto layersSelectionChanged = false; + auto customProvider = reinterpret_cast(_provider); + if (customProvider != nullptr) { + auto layers = customProvider->get_Layers(); + layersSelectionChanged = _lastLayers != layers; + if (layersSelectionChanged) + _tiles.clear(); + _lastLayers = layers; + } + if (indices == _lastTileExtents && _lastProvider == providerId && - _lastZoom == zoom) + _lastZoom == zoom && + !layersSelectionChanged) { // map extents has changed but the list of tiles to be displayed is the same tilesLogger.WriteLine("The same list of tiles can be used."); @@ -542,7 +556,8 @@ void TileManager::UpdateScreenBuffer() { if (_isBackground) { - _map->_MarkTileBufferChanged(); + if( _map != nullptr ) + _map->_MarkTileBufferChanged(); } else { diff --git a/src/Tiles/TileManager.h b/src/Tiles/TileManager.h index 3b15b32e..25be21aa 100644 --- a/src/Tiles/TileManager.h +++ b/src/Tiles/TileManager.h @@ -61,6 +61,7 @@ class TileManager // can be wrapped in a separate class CCriticalSection _tilesBufferLock; vector _tiles; + CString _lastLayers; Extent _projExtents; // extents of the world under current projection; in WGS84 it'll be (-180, 180, -90, 90) bool _projExtentsNeedUpdate; // do we need to update bounds in m_projExtents on the next request? diff --git a/src/Utilities/Debugging/ReferenceCounter.cpp b/src/Utilities/Debugging/ReferenceCounter.cpp index a759d414..47b3c1fb 100644 --- a/src/Utilities/Debugging/ReferenceCounter.cpp +++ b/src/Utilities/Debugging/ReferenceCounter.cpp @@ -1,5 +1,10 @@ #include "stdafx.h" #include "ReferenceCounter.h" +#if DEBUG_ALLOCATED_OBJECTS +#include "Shape.h" +#include "ShapeDrawingOptions.h" +#include "Shapefile.h" +#endif // ******************************************************** // WriteReport() @@ -37,9 +42,92 @@ CString ReferenceCounter::GetReport(bool unreleasedOnly) } } } + +#if DEBUG_ALLOCATED_OBJECTS + if (unreleasedOnly) { + if (referencePtrs.size() > 0) { + temp.Format("referencePtrs.count: %d\r\n", static_cast(referencePtrs.size())); + s += temp; + for (auto it = referencePtrs.begin(); it != referencePtrs.end();) { + const auto ptr = *it; + + //temp.Format("0x%016llx\r\n", ptr); + //s += temp; + + /*auto shp = static_cast(ptr); + CComBSTR tmp; + shp->Serialize2(VARIANT_FALSE, VARIANT_TRUE, &tmp); + temp = CString(tmp); + s += temp; */ + + /*auto sdOptions = static_cast(ptr); + CComBSTR tmp; + sdOptions->Serialize(&tmp); + temp = CString(tmp); + s += temp;*/ + + /*auto shape = static_cast(ptr); + CComBSTR key; + shape->get_Key(&key); + if (key != "") { + s += key; + } */ + + ++it; + } + } + } + else + referencePtrs.clear(); +#endif + if (temp.GetLength() == 0) { s += ""; } return s; -} \ No newline at end of file +} + +#if DEBUG_ALLOCATED_OBJECTS +CString ReferenceCounter::GetReferenceReport() +{ + CString s, temp; + + if (!referencePtrs.empty()) { + temp.Format("referencePtrs.count: %d\r\n", static_cast(referencePtrs.size())); + s += temp; + for (auto it = referencePtrs.begin(); it != referencePtrs.end();) { + const auto ptr = *it; + + //temp.Format("0x%016llx\r\n", ptr); + //s += temp; + + /*auto shp = static_cast(ptr); + CComBSTR tmp; + shp->Serialize2(VARIANT_FALSE, VARIANT_TRUE, &tmp); + temp = CString(tmp); + s += temp; */ + + /*auto sdOptions = static_cast(ptr); + CComBSTR tmp; + sdOptions->Serialize(&tmp); + temp = CString(tmp); + s += temp;*/ + + /*auto shape = static_cast(ptr); + CComBSTR key; + shape->get_Key(&key); + if (key != "") { + s += CString(key) + " "; + } + CComBSTR bstr; + shape->ExportToWKT(&bstr); + s += "WKT: " + CString(bstr) + "\r\n"; */ + + ++it; + } + } + + return s; +} +#endif \ No newline at end of file diff --git a/src/Utilities/Debugging/ReferenceCounter.h b/src/Utilities/Debugging/ReferenceCounter.h index 23763993..348707cb 100644 --- a/src/Utilities/Debugging/ReferenceCounter.h +++ b/src/Utilities/Debugging/ReferenceCounter.h @@ -1,10 +1,16 @@ #pragma once +#if DEBUG_ALLOCATED_OBJECTS +#include +#endif class ReferenceCounter { static const int INTERFACES_COUNT = 100; int referenceCounts[INTERFACES_COUNT]; int totalCounts[INTERFACES_COUNT]; +#if DEBUG_ALLOCATED_OBJECTS + unordered_set referencePtrs; +#endif public: ReferenceCounter(void) { @@ -27,6 +33,26 @@ class ReferenceCounter int* val = &referenceCounts[(int)type]; (*val)--; } + void WriteReport(bool unreleasedOnly); CString GetReport(bool unreleasedOnly); + +#if DEBUG_ALLOCATED_OBJECTS + void AddRef(void* pThis) + { + referencePtrs.insert(pThis); + } + + void Release(void* pThis) + { + referencePtrs.erase(pThis); + } + + long GetReferenceCount() const + { + return referencePtrs.size(); + } + + CString GetReferenceReport(); +#endif }; From b965c6f89e86e85f6b196af593c3127f33020563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 13:07:01 +0200 Subject: [PATCH 12/55] Added function PlaceLabels. --- src/Drawing/LayerDrawer.cpp | 21 +++++++++++++++++++++ src/Drawing/LayerDrawer.h | 1 + 2 files changed, 22 insertions(+) diff --git a/src/Drawing/LayerDrawer.cpp b/src/Drawing/LayerDrawer.cpp index a1a0a1df..91b5b271 100644 --- a/src/Drawing/LayerDrawer.cpp +++ b/src/Drawing/LayerDrawer.cpp @@ -45,3 +45,24 @@ void LayerDrawer::DrawLabels(Layer* layer, CLabelDrawer& drawer, tkVerticalPosit } } +// **************************************************************** +// PlaceLabels() +// **************************************************************** +int* LayerDrawer::PlaceLabels(Layer* layer, CLabelDrawer& drawer, tkVerticalPosition position) +{ + if (!layer) return NULL; + int* ret = NULL; + ILabels* labels = layer->get_Labels(); + if (labels != NULL) + { + tkVerticalPosition vertPos; + labels->get_VerticalPosition(&vertPos); + if (vertPos == position) + { + ret = drawer.PlaceLabels(labels); + } + labels->Release(); + labels = NULL; + } + return ret; +} \ No newline at end of file diff --git a/src/Drawing/LayerDrawer.h b/src/Drawing/LayerDrawer.h index 578ed54c..e5b81bbd 100644 --- a/src/Drawing/LayerDrawer.h +++ b/src/Drawing/LayerDrawer.h @@ -9,5 +9,6 @@ class LayerDrawer public: static void DrawCharts(Layer* layer, CChartDrawer& drawer, tkVerticalPosition position); static void DrawLabels(Layer* layer, CLabelDrawer& drawer, tkVerticalPosition position); + static int* PlaceLabels(Layer* layer, CLabelDrawer& drawer, tkVerticalPosition position); }; From f592b280c2b9f372177f766650db89984e980e35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 13:29:47 +0200 Subject: [PATCH 13/55] Support for building under Visual Studio 2022 and update GDAL to 3.10.3 --- .../MapWinGisTests-net6.sln.DotSettings | 2 + .../GdalUtils/GdalUtilsTests.cs | 8 +- .../Projections/GeoProjectionsTests.cs | 10 +- .../Projections/UtilsProjectionTests.cs | 12 +- MapWinGisTests-net6/MapWinGisTests/Helpers.cs | 22 +- .../MapWinGisTests/MapWinGisTests.csproj | 17 +- .../MapWinGisTests/ShouldBeExtensions.cs | 22 + .../UnitTests/CodeCoverageTests.cs | 2 +- .../MapWinGisTests/UnitTests/ShapeTests.cs | 428 +++++++- src/COM classes/Utils_OGR.cpp | 52 +- src/CopyTamasFiles.bat | 45 +- src/MapWinGIS-toolset142.sln | 33 + src/MapWinGIS-toolset142.vcxproj | 957 ++++++++++++++++++ src/MapWinGIS.sln | 7 +- src/MapWinGIS.sln.DotSettings | 4 + src/MapWinGIS.vcxproj | 21 +- src/MapWinGIS.vcxproj.filters | 9 + src/MapWinGIS.vcxproj.user | 4 +- src/changingVersionNumbers.txt | 2 +- ...VC2019 win32 headers should be here!!!.txt | 1 + ...!!!VC2019 win32 libs should be here!!!.txt | 1 + support/GDAL_SDK/v143/removeOldGdalFiles.ps1 | 3 + support/ShapeLib/ShapeLib-toolset142.vcxproj | 204 ++++ support/ShapeLib/ShapeLib-toolset143.vcxproj | 208 ++++ support/SupportLibs-toolset142.sln | 52 + support/SupportLibs-toolset143.sln | 52 + support/cqlib/cqlib-toolset142.vcxproj | 226 +++++ support/cqlib/cqlib-toolset143.vcxproj | 228 +++++ .../spatialindex-toolset141.vcxproj | 15 +- .../spatialindex-toolset142.vcxproj | 315 ++++++ test/TestApplication.sln | 10 +- .../Properties/Resources.Designer.cs | 4 +- .../Properties/Settings.Designer.cs | 4 +- test/TestApplication/TestApplication.csproj | 21 +- test/TestApplication/app.config | 90 +- 35 files changed, 2916 insertions(+), 175 deletions(-) create mode 100644 MapWinGisTests-net6/MapWinGisTests-net6.sln.DotSettings create mode 100644 MapWinGisTests-net6/MapWinGisTests/ShouldBeExtensions.cs create mode 100644 src/MapWinGIS-toolset142.sln create mode 100644 src/MapWinGIS-toolset142.vcxproj create mode 100644 support/GDAL_SDK/v143/include/win32/!!!VC2019 win32 headers should be here!!!.txt create mode 100644 support/GDAL_SDK/v143/lib/win32/!!!VC2019 win32 libs should be here!!!.txt create mode 100644 support/GDAL_SDK/v143/removeOldGdalFiles.ps1 create mode 100644 support/ShapeLib/ShapeLib-toolset142.vcxproj create mode 100644 support/ShapeLib/ShapeLib-toolset143.vcxproj create mode 100644 support/SupportLibs-toolset142.sln create mode 100644 support/SupportLibs-toolset143.sln create mode 100644 support/cqlib/cqlib-toolset142.vcxproj create mode 100644 support/cqlib/cqlib-toolset143.vcxproj create mode 100644 support/spatialindex/spatialindex-vc/spatialindex-toolset142.vcxproj diff --git a/MapWinGisTests-net6/MapWinGisTests-net6.sln.DotSettings b/MapWinGisTests-net6/MapWinGisTests-net6.sln.DotSettings new file mode 100644 index 00000000..2d72aa38 --- /dev/null +++ b/MapWinGisTests-net6/MapWinGisTests-net6.sln.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/MapWinGisTests-net6/MapWinGisTests/FunctionalTests/GdalUtils/GdalUtilsTests.cs b/MapWinGisTests-net6/MapWinGisTests/FunctionalTests/GdalUtils/GdalUtilsTests.cs index f39dfd97..75469f3e 100644 --- a/MapWinGisTests-net6/MapWinGisTests/FunctionalTests/GdalUtils/GdalUtilsTests.cs +++ b/MapWinGisTests-net6/MapWinGisTests/FunctionalTests/GdalUtils/GdalUtilsTests.cs @@ -90,8 +90,12 @@ public void Progress(string keyOfSender, int percent, string message) public void Error(string keyOfSender, string errorMsg) { - _testOutputHelper.WriteLine($"Error of {keyOfSender}: {errorMsg}"); - } + try { + _testOutputHelper.WriteLine($"Error of {keyOfSender}: {errorMsg}"); + } catch { + // ignore + } + } #pragma warning restore xUnit1013 #endregion } diff --git a/MapWinGisTests-net6/MapWinGisTests/FunctionalTests/Projections/GeoProjectionsTests.cs b/MapWinGisTests-net6/MapWinGisTests/FunctionalTests/Projections/GeoProjectionsTests.cs index af555020..695b31af 100644 --- a/MapWinGisTests-net6/MapWinGisTests/FunctionalTests/Projections/GeoProjectionsTests.cs +++ b/MapWinGisTests-net6/MapWinGisTests/FunctionalTests/Projections/GeoProjectionsTests.cs @@ -72,8 +72,10 @@ public void IsEmptyTest() [Fact] public void IsSameTest() { - // Setup: - var geoProjection3857 = new GeoProjection(); + System.Diagnostics.Debug.WriteLine("IsSameTest() start"); + + // Setup: + var geoProjection3857 = new GeoProjection(); geoProjection3857.ShouldNotBeNull(); var geoProjection28992 = new GeoProjection(); @@ -113,7 +115,9 @@ public void IsSameTest() geoProjection3857.IsSame[geoProjectionPrj].ShouldBeFalse("GeoProjections should not be the same."); geoProjection28992.IsSame[geoProjectionPrj].ShouldBeTrue("GeoProjections should be the same."); geoProjectionPrj.IsSame[geoProjection28992].ShouldBeTrue("GeoProjections should be the same."); - } + + System.Diagnostics.Debug.WriteLine("IsSameTest() end"); + } [Fact] public void ImportFromAutoDetectTest() diff --git a/MapWinGisTests-net6/MapWinGisTests/FunctionalTests/Projections/UtilsProjectionTests.cs b/MapWinGisTests-net6/MapWinGisTests/FunctionalTests/Projections/UtilsProjectionTests.cs index fed0e554..9eacc263 100644 --- a/MapWinGisTests-net6/MapWinGisTests/FunctionalTests/Projections/UtilsProjectionTests.cs +++ b/MapWinGisTests-net6/MapWinGisTests/FunctionalTests/Projections/UtilsProjectionTests.cs @@ -13,12 +13,13 @@ public UtilsProjectionTests(ITestOutputHelper testOutputHelper) [Fact] public void UtilsReprojectShapefileTest() { - // RD (Amersfoort, The Neterlands) to WGS84: - // https://geodata.nationaalgeoregister.nl/locatieserver/v3/free?q=a325 - // "centroide_rd": "POINT(187816.756 433912.801)", - // "centroide_ll": "POINT(5.86394184 51.89276528)" + System.Diagnostics.Debug.WriteLine("UtilsReprojectShapefileTest() start"); + // RD (Amersfoort, The Neterlands) to WGS84: + // https://geodata.nationaalgeoregister.nl/locatieserver/v3/free?q=a325 + // "centroide_rd": "POINT(187816.756 433912.801)", + // "centroide_ll": "POINT(5.86394184 51.89276528)" - UtilsReprojectPointShapefile(187816.756, 433912.801, 5.86394184, 51.89276528, 0.0000001, 28992, 4326); + UtilsReprojectPointShapefile(187816.756, 433912.801, 5.86394184, 51.89276528, 0.0000001, 28992, 4326); // The other way round: UtilsReprojectPointShapefile(5.86394184, 51.89276528, 187816.756, 433912.801, 0.05, 4326, 28992); @@ -26,6 +27,7 @@ public void UtilsReprojectShapefileTest() UtilsReprojectPointShapefile(4.5703125, 51.944265, 4.5706292, 51.945227, 0.000001, 4258, 4289); // Swap: UtilsReprojectPointShapefile(4.5706292, 51.945227, 4.5703125, 51.944265, 0.000001, 4289, 4258); + System.Diagnostics.Debug.WriteLine("UtilsReprojectShapefileTest() end"); } private void UtilsReprojectPointShapefile(double srcX, double srcY, double dstX, double dstY, double tolerance, int srcEpsgCode, int dstEpsgCode) diff --git a/MapWinGisTests-net6/MapWinGisTests/Helpers.cs b/MapWinGisTests-net6/MapWinGisTests/Helpers.cs index 5c0b9f99..4dd391bc 100644 --- a/MapWinGisTests-net6/MapWinGisTests/Helpers.cs +++ b/MapWinGisTests-net6/MapWinGisTests/Helpers.cs @@ -98,6 +98,19 @@ internal static Shapefile LoadSfUsingFileManager(string filename) return sf; } + internal static Shapefile CreateTestPolylineShapefile() + { + var sfPolyline = MakeShapefile(ShpfileType.SHP_POLYLINE); + AddShape(sfPolyline, "LINESTRING (330695.973322992 5914896.16305817, 330711.986129861 5914867.19586245, 330713.350435287 5914867.56644015, 330716.510827627 5914862.28973662, 330715.632568651 5914860.60107999, 330652.234582712 5914803.80510632, 330553.749382483 5914715.80328169, 330551.979355848 5914714.83347535, 330549.911988583 5914715.86502807, 330545.027807355 5914724.05916443, 330544.592985976 5914725.93531509, 330544.30963704 5914726.72754692, 330543.612620707 5914726.14904553, 330543.271515787 5914727.06633931, 330542.234090059 5914729.85597723, 330542.959654761 5914730.50411962, 330530.319252794 5914765.86064153, 330505.294840402 5914836.7930124, 330471.411812074 5914931.61558331, 330486.074748666 5914941.33795239, 330585.983154737 5915010.32749106, 330618.427962455 5915031.20447119, 330653.234601917 5914970.37328093, 330695.973322992 5914896.16305817)"); + + sfPolyline.NumShapes.ShouldBe(1); + + // Set projection: + sfPolyline.GeoProjection = MakeProjection(28992); + + return sfPolyline; + } + internal static Shapefile CreateTestPolygonShapefile() { var sfPolygon = MakeShapefile(ShpfileType.SHP_POLYGON); @@ -153,7 +166,14 @@ internal static Shape MakeShape(ShpfileType shpType) return shp; } - internal static void AddShape(Shapefile sf, string wktSting) + internal static Shape MakeShape(Point pt) + { + var shape = MakeShape(ShpfileType.SHP_POINT); + shape.AddPoint(pt.x, pt.y); + return shape; + } + + internal static void AddShape(Shapefile sf, string wktSting) { // Create shape var shp = new Shape(); diff --git a/MapWinGisTests-net6/MapWinGisTests/MapWinGisTests.csproj b/MapWinGisTests-net6/MapWinGisTests/MapWinGisTests.csproj index 8fd0fc81..41d8d926 100644 --- a/MapWinGisTests-net6/MapWinGisTests/MapWinGisTests.csproj +++ b/MapWinGisTests-net6/MapWinGisTests/MapWinGisTests.csproj @@ -1,7 +1,7 @@ - net6.0-windows8.0 + net8.0-windows8.0 MapWinGisTests enable @@ -35,15 +35,18 @@ - - - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/MapWinGisTests-net6/MapWinGisTests/ShouldBeExtensions.cs b/MapWinGisTests-net6/MapWinGisTests/ShouldBeExtensions.cs new file mode 100644 index 00000000..4407759d --- /dev/null +++ b/MapWinGisTests-net6/MapWinGisTests/ShouldBeExtensions.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JetBrains.Annotations; + +namespace Shouldly +{ + public static class ShouldBeExtensions + { + //ContractAnnotation("actual:notnull => halt")] + public static void ShouldBeEqualWithin(this double? actual, double expected, double withinAmount, string? customMessage = null) + { + if(!actual.HasValue) + throw new ShouldAssertException("actual value is null"); + + if(Math.Abs(actual.Value - expected) > withinAmount) + throw new ShouldAssertException($"{actual.Value} is not equal to {expected} withing {withinAmount}"); + } + } +} diff --git a/MapWinGisTests-net6/MapWinGisTests/UnitTests/CodeCoverageTests.cs b/MapWinGisTests-net6/MapWinGisTests/UnitTests/CodeCoverageTests.cs index e479a32e..1d84996c 100644 --- a/MapWinGisTests-net6/MapWinGisTests/UnitTests/CodeCoverageTests.cs +++ b/MapWinGisTests-net6/MapWinGisTests/UnitTests/CodeCoverageTests.cs @@ -12,7 +12,7 @@ public CodeCoverageTests(ITestOutputHelper testOutputHelper) _testOutputHelper = testOutputHelper; } - [Fact(Skip = "Unit test is not yet implemented")] + //[Fact(Skip = "Unit test is not yet implemented")] public void CheckShapefileClass() { CheckTests(typeof(ShapefileClass), "Shapefile"); diff --git a/MapWinGisTests-net6/MapWinGisTests/UnitTests/ShapeTests.cs b/MapWinGisTests-net6/MapWinGisTests/UnitTests/ShapeTests.cs index 06b6c849..70712426 100644 --- a/MapWinGisTests-net6/MapWinGisTests/UnitTests/ShapeTests.cs +++ b/MapWinGisTests-net6/MapWinGisTests/UnitTests/ShapeTests.cs @@ -1,4 +1,7 @@ -namespace MapWinGisTests.UnitTests; +using System.Management; +using Shouldly; + +namespace MapWinGisTests.UnitTests; [Collection(nameof(NotThreadSafeResourceCollection))] public class ShapeTests @@ -99,80 +102,403 @@ public void ShapeKeyTest() [Fact(Skip = "Unit test is not yet implemented")] public void ShapeGlobalCallbackTest() { } - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeExtentsTest() { } + [Fact] + public void ShapeExtentsTest() + { + _firstShapePoint.ShouldNotBeNull(); + var ext = _firstShapePoint.Extents; + + var xMin = double.MaxValue; + var xMax = double.MinValue; + var yMin = double.MaxValue; + var yMax = double.MinValue; + for(var i = 0; i < _firstShapePoint.NumPoints; i++) + { + var pt = _firstShapePoint.Point[i]; + if(pt.x < xMin) + xMin = pt.x; + if(pt.x > xMax) + xMax = pt.x; + if(pt.y < yMin) + yMin = pt.y; + if(pt.y > yMax) + yMax = pt.y; + } + + ext.xMin.ShouldBe(xMin); + ext.xMax.ShouldBe(xMax); + ext.yMin.ShouldBe(yMin); + ext.yMax.ShouldBe(yMax); + } - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeCentroidTest() { } + [Fact] + public void ShapeCentroidTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeLengthTest() { } + var shape = sfPolygon.Shape[0]; + var centroid = shape.Centroid; + centroid.ShouldNotBeNull(); - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapePerimeterTest() { } + var centroidShp = Helpers.MakeShape(centroid); + shape.Contains(centroidShp).ShouldBeTrue(); + } - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeAreaTest() { } + [Fact] + public void ShapeLengthTest() + { + var sfPolyline = Helpers.CreateTestPolylineShapefile(); + sfPolyline.ShouldNotBeNull(); - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeIsValidTest() { } + var expectedLength = 828.9983624899301; + var shape = sfPolyline.Shape[0]; - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeXyTest() { } + ((shape.Length - expectedLength) < 0.000001).ShouldBeTrue(); + } - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapePartIsClockWiseTest() { } + [Fact] + public void ShapePerimeterTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeCenterTest() { } + var expectedPerimeter = 828.9983624899301; + var shape = sfPolygon.Shape[0]; + ((shape.Perimeter - expectedPerimeter) < 0.000001).ShouldBeTrue(); + } - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeEndOfPartTest() { } + [Fact] + public void ShapeAreaTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); + + var expectedArea = 41521.544653236866; + var shape = sfPolygon.Shape[0]; + var diff = Math.Abs(shape.Area - expectedArea); + diff.ShouldBeLessThan(0.0001); + } + + [Fact] + public void ShapeIsValidTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); + + var shape = sfPolygon.Shape[0]; + shape.IsValid.ShouldBeTrue(); + } + + [Fact] + public void ShapeXyTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); + + var shape = sfPolygon.Shape[0]; + var pt = shape.Point[0]; + + double x = 0, y = 0; + shape.get_XY(0, ref x, ref y); + x.ShouldBe(pt.x); + y.ShouldBe(pt.y); + + x += 15; + y += 10; + + shape.put_XY(0, x, y); + pt = shape.Point[0]; + x.ShouldBe(pt.x); + y.ShouldBe(pt.y); + } - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapePartAsShapeTest() { } + [Fact] + public void ShapePartIsClockWiseTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeIsValidReasonTest() { } + var shape = sfPolygon.Shape[0]; - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeInteriorPointTest() { } + shape.PartIsClockWise[0].ShouldBeTrue(); + } - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeShapeType2DTest() { } + [Fact] + public void ShapeCenterTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeIsEmptyTest() { } + var shape = sfPolygon.Shape[0]; - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapePut_ZTest() { } + var center = shape.Center; + center.ShouldNotBeNull(); - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeMTest() { } + var centerShp = Helpers.MakeShape(center); + shape.Contains(centerShp).ShouldBeTrue(); + } - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeZTest() { } + [Fact] + public void ShapeEndOfPartTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeBufferWithParamsTest() { } + var shape = sfPolygon.Shape[0]; + shape.EndOfPart[0].ShouldBeGreaterThan(0); + } - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeMoveTest() { } + [Fact] + public void ShapePartAsShapeTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeRotateTest() { } + var shape = sfPolygon.Shape[0]; + var partShape = shape.PartAsShape[0]; + partShape.ShouldNotBeNull(); + } - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeSplitByPolylineTest() { } + [Fact] + public void ShapeIsValidReasonTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeClearTest() { } + var shape = sfPolygon.Shape[0]; + shape.DeletePoint(shape.NumPoints - 1); + shape.IsValid.ShouldBeFalse(); + if(!shape.IsValid) + shape.IsValidReason.ShouldNotBeEmpty(); + } - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeFixUp2Test() { } + [Fact] + public void ShapeInteriorPointTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); - [Fact(Skip = "Unit test is not yet implemented")] - public void ShapeInterpolatePointTest() { } + var shape = sfPolygon.Shape[0]; + var x = (shape.Extents.xMax - shape.Extents.xMin) / 2.0 + shape.Extents.xMin; + var y = (shape.Extents.yMax - shape.Extents.yMin) / 2.0 + shape.Extents.yMin; + + var interiorPoint = shape.InteriorPoint; + interiorPoint.ShouldNotBeNull(); + (Math.Abs(interiorPoint.x - x) < 10).ShouldBeTrue(); + (Math.Abs(interiorPoint.y - y) < 10).ShouldBeTrue(); + } + + [Fact] + public void ShapeShapeType2DTest() + { + var shape = Helpers.MakeShape(ShpfileType.SHP_POLYLINEZ); + shape.ShapeType2D.ShouldBe(ShpfileType.SHP_POLYLINE); + + shape = Helpers.MakeShape(ShpfileType.SHP_POLYGONZ); + shape.ShapeType2D.ShouldBe(ShpfileType.SHP_POLYGON); + + shape = Helpers.MakeShape(ShpfileType.SHP_POINTZ); + shape.ShapeType2D.ShouldBe(ShpfileType.SHP_POINT); + } + + [Fact] + public void ShapeIsEmptyTest() + { + var shp = Helpers.MakeShapefile(ShpfileType.SHP_POLYLINEZ); + shp.ShouldNotBeNull(); + + var shape = Helpers.MakeShape(ShpfileType.SHP_POLYLINEZ); + shape.IsEmpty.ShouldBeTrue(); + + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); + shape = sfPolygon.Shape[0]; + shape.IsEmpty.ShouldBeFalse(); + } + + [Fact] + public void ShapePut_ZTest() + { + Shape shape = new ShapeClass(); + shape.ShapeType = ShpfileType.SHP_POINTZ; + shape.AddPoint(100, 100); + + var z = 3.14; + shape.put_Z(0, z).ShouldBeTrue(); + + shape.get_Z(0, out var zValue); + zValue.ShouldBe(z); + } + + [Fact] + public void ShapeMTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); + + var shape = sfPolygon.Shape[0]; + + var m = 3.1415; + shape.put_M(0, m).ShouldBeTrue(); + shape.get_M(0, out var mValue).ShouldBeTrue(); + mValue.ShouldBe(m); + } + + [Fact] + public void ShapeZTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); + + var shape = sfPolygon.Shape[0]; + + var z = 3.1415; + shape.put_Z(0, z).ShouldBeTrue(); + shape.get_Z(0, out var zValue).ShouldBeTrue(); + zValue.ShouldBe(z); + } + + [Fact] + public void ShapeBufferWithParamsTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); + + var shape = sfPolygon.Shape[0]; + var dist = 10.0; + var newShape = shape.BufferWithParams(dist, 30, false, tkBufferCap.bcROUND, tkBufferJoin.bjROUND, 5.0); + newShape.ShouldNotBeNull(); + (shape.Area < newShape.Area).ShouldBeTrue(); + } + + [Fact] + public void ShapeMoveTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); + + var shape = sfPolygon.Shape[0]; + var xCenter = shape.Center.x; + var yCenter = shape.Center.y; + + var xOffset = 15; + var yOffset = 20; + shape.Move(xOffset, yOffset); + + var center = shape.Center; + var xDiff = center.x - xCenter; + var yDiff = center.y - yCenter; + xDiff.ShouldBe(xOffset); + yDiff.ShouldBe(yOffset); + } + + [Fact] + public void ShapeRotateTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); + + var shape = sfPolygon.Shape[0]; + var orgShape = shape.Clone(); + + var center = shape.Center; + shape.Rotate(center.x, center.y, 360); + + shape.Area.ShouldBe(orgShape.Area); + shape.NumPoints.ShouldBe(orgShape.NumPoints); + + for (var i = 0; i < shape.NumPoints; i++) + { + var pt0 = orgShape.Point[i]; + var pt1 = shape.Point[i]; + pt0.ShouldNotBeNull(); + pt1.ShouldNotBeNull(); + pt0.x.ShouldBe(pt1.x); + pt0.y.ShouldBe(pt1.y); + } + } + + [Fact] + public void ShapeSplitByPolylineTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); + + var shape = sfPolygon.Shape[0]; + + var polyline = Helpers.MakeShape(ShpfileType.SHP_POLYLINE); + polyline.ShouldNotBeNull(); + var wkt = "LineString (330431.80617637105751783 5914860.0969890458509326, 330766.5170847776462324 5914971.03695115447044373, 330766.5170847776462324 5914971.03695115447044373)"; + polyline.ImportFromWKT(wkt).ShouldBeTrue(); + + object result = null; + shape.SplitByPolyline(polyline, ref result).ShouldBeTrue(); + + result.ShouldBeOfType(typeof(object[])); + var array = result as object[]; + array.ShouldNotBeNull(); + array.Length.ShouldBe(2); + + IShape shape0 = array[0] as Shape; + shape0.ShouldNotBeNull(); + shape0.IsValid.ShouldBeTrue(); + + IShape shape1 = array[1] as Shape; + shape1.ShouldNotBeNull(); + shape1.IsValid.ShouldBeTrue(); + + var diff = Math.Abs((shape0.Area + shape1.Area) - shape.Area); + diff.ShouldBeLessThan(0.001); + } + + [Fact] + public void ShapeClearTest() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); + + var shape = sfPolygon.Shape[0]; + shape.ShouldNotBeNull(); + shape.IsEmpty.ShouldBeFalse(); + + shape.Clear(); + shape.IsEmpty.ShouldBeTrue(); + } + + [Fact] + public void ShapeFixUp2Test() + { + var sfPolygon = Helpers.CreateTestPolygonShapefile(); + sfPolygon.ShouldNotBeNull(); + + var shape = sfPolygon.Shape[0]; + var newShape = shape.FixUp2(tkUnitsOfMeasure.umMeters); + newShape.ShouldNotBeNull(); + + shape.DeletePoint(shape.NumPoints - 1); + shape.IsValid.ShouldBeFalse(); + + newShape = shape.FixUp2(tkUnitsOfMeasure.umMeters); + newShape.ShouldNotBeNull(); + newShape.IsValid.ShouldBeTrue(); + } + + [Fact] + public void ShapeInterpolatePointTest() + { + var sfPolyline = Helpers.CreateTestPolylineShapefile(); + sfPolyline.ShouldNotBeNull(); + + var shape = sfPolyline.Shape[0]; + var pt = shape.InterpolatePoint(shape.Point[0], 0.5); + pt.ShouldNotBeNull(); + + var expectedX = 330696.21521950705; + var expectedY = 5914895.72546695; + ShouldBeExtensions.ShouldBeEqualWithin(pt.x, expectedX, 0.0001); + ShouldBeExtensions.ShouldBeEqualWithin(pt.y, expectedY, 0.0001); + } [Fact(Skip = "Unit test is not yet implemented")] public void ShapeProjectDistanceToTest() { } diff --git a/src/COM classes/Utils_OGR.cpp b/src/COM classes/Utils_OGR.cpp index c2b19aa9..d2efcd71 100644 --- a/src/COM classes/Utils_OGR.cpp +++ b/src/COM classes/Utils_OGR.cpp @@ -2,6 +2,7 @@ //File name: Utils_OGR.cpp //Description: Implementation of CUtils. //******************************************************************************************************** +#include "stdafx.h" #include #include #include "cpl_conv.h" @@ -16,6 +17,7 @@ #include "vrtdataset.h" #pragma warning(disable:4996) +#define DISABLE_OGR2OGR 1 int CPL_STDCALL GDALProgressCallback(double dfComplete, const char* pszMessage, void* pData); @@ -47,6 +49,7 @@ typedef struct } AssociatedLayers; +#if GDAL_VERSION_MAJOR >= 3 static int TranslateLayer(TargetLayerInfo* psInfo, GDALDataset* poSrcDS, OGRLayer* poSrcLayer, @@ -54,9 +57,9 @@ static int TranslateLayer(TargetLayerInfo* psInfo, int bTransform, int bWrapDateline, const char* pszDateLineOffset, - OGRSpatialReference* poOutputSRS, + const OGRSpatialReference* poOutputSRS, int bNullifyOutputSRS, - OGRSpatialReference* poUserSourceSRS, + const OGRSpatialReference* poUserSourceSRS, OGRCoordinateTransformation* poGCPCoordTrans, int eGType, int bPromoteToMulti, @@ -71,7 +74,7 @@ static int TranslateLayer(TargetLayerInfo* psInfo, GIntBig* pnReadFeatureCount, GDALProgressFunc pfnProgress, void* pProgressArg); - +#endif /* -------------------------------------------------------------------- */ /* CheckDestDataSourceNameConsistency() */ @@ -802,10 +805,10 @@ class GCPCoordTransformation final : public OGRCoordinateTransformation poSRS->Dereference(); } - OGRSpatialReference* GetSourceCS() override { return poSRS; } - OGRSpatialReference* GetTargetCS() override { return poSRS; } + const OGRSpatialReference* GetSourceCS() const { return poSRS; } + const OGRSpatialReference* GetTargetCS() const { return poSRS; } - int Transform(int nCount, + int Transform(size_t nCount, double* x, double* y, double* z, double* /* t */, int* pabSuccess) override @@ -887,8 +890,8 @@ class GCPCoordTransformation : public OGRCoordinateTransformation poSRS->Dereference(); } - virtual OGRSpatialReference* GetSourceCS() { return poSRS; } - virtual OGRSpatialReference* GetTargetCS() { return poSRS; } + virtual const OGRSpatialReference* GetSourceCS() { return poSRS; } + virtual const OGRSpatialReference* GetTargetCS() { return poSRS; } virtual int Transform(int nCount, double* x, double* y, double* z) override @@ -1053,8 +1056,8 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, } } - OGRSpatialReference* poOutputSRS = poOutputSRSIn; - if (poOutputSRS == NULL && !bNullifyOutputSRS) + const OGRSpatialReference* poOutputSRS = poOutputSRSIn; + if (poOutputSRS == nullptr && !bNullifyOutputSRS) { if (nSrcGeomFieldCount == 1 || anRequestedGeomFields.size() == 0) poOutputSRS = poSrcLayer->GetSpatialRef(); @@ -1572,6 +1575,7 @@ __declspec(deprecated("This is a deprecated function, use CGdalUtils::GdalVector STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, BSTR bstrOptions, ICallback* cBack, VARIANT_BOOL* retval) { +#if !DISABLE_OGR2OGR USES_CONVERSION; struct CallbackParams params(GetCallback(), "Converting"); @@ -3062,6 +3066,10 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, * retval = nRetCode == 0 ? VARIANT_TRUE : VARIANT_FALSE; return ResetConfigOptions(tkNO_ERROR); +#else + *retval = VARIANT_FALSE; + return 0; +#endif } /************************************************************************/ @@ -3165,19 +3173,19 @@ class CompositeCT final : public OGRCoordinateTransformation return new CompositeCT(*this); } - OGRSpatialReference* GetSourceCS() override + const OGRSpatialReference* GetSourceCS() const override { return poCT1 ? poCT1->GetSourceCS() : poCT2 ? poCT2->GetSourceCS() : nullptr; } - OGRSpatialReference* GetTargetCS() override + const OGRSpatialReference* GetTargetCS() const override { return poCT2 ? poCT2->GetTargetCS() : poCT1 ? poCT1->GetTargetCS() : nullptr; } - int Transform(int nCount, + int Transform(size_t nCount, double* x, double* y, double* z, double* t, int* pabSuccess) override @@ -3215,7 +3223,7 @@ class CompositeCT : public OGRCoordinateTransformation } - virtual OGRSpatialReference* GetSourceCS() + virtual const OGRSpatialReference* GetSourceCS() { return poCT1 ? poCT1->GetSourceCS() : poCT2 ? poCT2->GetSourceCS() : NULL; @@ -3261,9 +3269,9 @@ static int SetupCT(TargetLayerInfo* psInfo, int bTransform, int bWrapDateline, const char* pszDateLineOffset, - OGRSpatialReference* poUserSourceSRS, + const OGRSpatialReference* poUserSourceSRS, OGRFeature* poFeature, - OGRSpatialReference* poOutputSRS, + const OGRSpatialReference* poOutputSRS, OGRCoordinateTransformation* poGCPCoordTrans) { OGRLayer* poDstLayer = psInfo->poDstLayer; @@ -3273,9 +3281,9 @@ static int SetupCT(TargetLayerInfo* psInfo, /* -------------------------------------------------------------------- */ /* Setup coordinate transformation if we need it. */ /* -------------------------------------------------------------------- */ - OGRSpatialReference* poSourceSRS = NULL; - OGRCoordinateTransformation* poCT = NULL; - char** papszTransformOptions = NULL; + const OGRSpatialReference* poSourceSRS = nullptr; + OGRCoordinateTransformation* poCT = nullptr; + char** papszTransformOptions = nullptr; int iSrcGeomField; if (psInfo->iRequestedSrcGeomField >= 0) @@ -3301,7 +3309,7 @@ static int SetupCT(TargetLayerInfo* psInfo, if (psInfo->nFeaturesRead == 0) { poSourceSRS = poUserSourceSRS; - if (poSourceSRS == NULL) + if (poSourceSRS == nullptr) { if (iSrcGeomField > 0) poSourceSRS = poSrcLayer->GetLayerDefn()-> @@ -3310,7 +3318,7 @@ static int SetupCT(TargetLayerInfo* psInfo, poSourceSRS = poSrcLayer->GetSpatialRef(); } } - if (poSourceSRS == NULL) + if (poSourceSRS == nullptr) { OGRGeometry* poSrcGeometry = poFeature->GetGeomFieldRef(iSrcGeomField); @@ -3422,7 +3430,7 @@ static int TranslateLayer(TargetLayerInfo* psInfo, int bTransform, int bWrapDateline, const char* pszDateLineOffset, - OGRSpatialReference* poOutputSRS, + const OGRSpatialReference* poOutputSRS, int bNullifyOutputSRS, OGRSpatialReference* poUserSourceSRS, OGRCoordinateTransformation* poGCPCoordTrans, diff --git a/src/CopyTamasFiles.bat b/src/CopyTamasFiles.bat index 84f9bbf4..726ef8b3 100644 --- a/src/CopyTamasFiles.bat +++ b/src/CopyTamasFiles.bat @@ -10,6 +10,7 @@ REM * Paul Meems, update for ecw dll, June 2015 * REM * Paul Meems, update for ecw dll to v5.3, Aug 2017 * REM * Paul Meems, update for xerces and lti_dsdk dll, Aug 2018 * REM * Paul Meems, update for GDAL v3+, Jan 2022 * +REM * Daniel Hedén, update for GDAL v3.10.3, proj9 * REM * Usage to test: * REM * CopyTamasFiles.bat D:\dev\MapwinGIS\GitHub\support\GDAL_SDK\v140\bin\win32 D:\dev\MapwinGIS\GitHub\src\bin\Win32\ REM ************************************************************* @@ -19,7 +20,7 @@ set _to_dir=%2 if '%_from_dir%'=='' if '%_to_dir%'=='' GOTO usage REM Copy gdal plugins: -FOR %%G IN (gdal_MrSID.dll gdal_netCDF.dll gdal_HDF4.dll gdal_HDF4Image.dll gdal_HDF5.dll gdal_HDF5Image.dll gdal_ECW_JP2ECW.dll gdal_MG4Lidar.dll) DO ( +FOR %%G IN (gdal_ECW_JP2ECW.dll gdal_FITS.dll gdal_GEOR.dll gdal_GIF.dll gdal_HDF4.dll gdal_HDF5.dll gdal_KEA.dll gdal_MG4Lidar.dll gdal_MrSID.dll gdal_PDF.dll gdal_netCDF.dll ogr_OCI.dll ogr_ODBC.dll) DO ( IF EXIST %_from_dir%\gdal\plugins\%%G ( xcopy /v /c /r /y %_from_dir%\gdal\plugins\%%G %_to_dir%gdalplugins\ ) @@ -37,13 +38,25 @@ xcopy /v /c /r /y %_from_dir%\gdal-data\*.* %_to_dir%gdal-data\ REM xcopy /v /c /r /y %_from_dir%\proj\SHARE\*.* %_to_dir%..\PROJ_NAD\ REM Copy Proj7 data. TODO: Check if copied to correct location: -xcopy /v /c /r /y %_from_dir%\proj7\share\*.* %_to_dir%proj7\share\ +rem xcopy /v /c /r /y %_from_dir%\proj7\share\*.* %_to_dir%proj7\share\ + +REM Copy Proj9 data. TODO: Check if copied to correct location: +xcopy /v /c /r /y %_from_dir%\proj9\share\*.* %_to_dir%proj9\share\ + +REM Copy gdal plugins +xcopy /v /c /r /y %_from_dir%\gdal\plugins\*.* %_to_dir%gdal\plugins\ + +REM Copy gdal plugins-external +xcopy /v /c /r /y %_from_dir%\gdal\plugins-external\*.* %_to_dir%gdal\plugins-external\ + +REM Copy gdal plugins-external +xcopy /v /c /r /y %_from_dir%\gdal\plugins-optional\*.* %_to_dir%gdal\plugins-optional\ REM Copy needed Tamas binaries: -FOR %%G IN (cfitsio.dll freexl.dll geos.dll geos_c.dll hdf.dll hdf5.dll hdf5_hl.dll hdf5_cpp.dll hdf5_hl_cpp.dll libcrypto-1_1.dll libcrypto-1_1-x64.dll - libcurl.dll libexpat.dll tiff.dll tiffxx.dll ogdi.dll mfhdf.dll - iconv-2.dll libmysql.dll libpng16.dll libpq.dll libssl-1_1.dll libssl-1_1-x64.dll libxml2.dll lti_lidar_dsdk_1.1.dll netcdf.dll - openjp2.dll spatialite.dll sqlite3.dll szip.dll tbb.dll xdr.dll zlib.dll +FOR %%G IN (cfitsio.dll freexl.dll geos.dll geos_c.dll hdf.dll hdf5.dll hdf5_hl.dll hdf5_cpp.dll hdf5_hl_cpp.dll libcrypto-1_1.dll libcrypto-1_1-x64.dll libcrypto-3-x64.dll + libcurl.dll libexpat.dll tiff.dll tiffxx.dll ogdi.dll mfhdf.dll pcre.dll + iconv-2.dll libmysql.dll libpng16.dll libpq.dll libssl-1_1.dll libssl-1_1-x64.dll libssl-3-x64.dll libxml2.dll lti_lidar_dsdk_1.1.dll netcdf.dll + openjp2.dll proj_9.dll spatialite.dll sqlite3.dll szip.dll tbb.dll xdr.dll zlib.dll zstd.dll NCSEcw.dll) DO ( IF EXIST %_from_dir%\%%G ( xcopy /v /c /r /y %_from_dir%\%%G %_to_dir% @@ -51,8 +64,8 @@ FOR %%G IN (cfitsio.dll freexl.dll geos.dll geos_c.dll hdf.dll hdf5.dll hdf5_hl. ) REM gdal contains the version number, so use a wildcard: -del /f /q %_to_dir%\gdal*.dll -xcopy /v /c /r /y %_from_dir%\gdal3*.dll %_to_dir% +rem del /f /q %_to_dir%\gdal*.dll +rem xcopy /v /c /r /y %_from_dir%\gdal3*.dll %_to_dir% REM xerces contains a version number, so use a wildcard: del /f /q %_to_dir%\xerces-c*.dll @@ -63,10 +76,18 @@ del /f /q %_to_dir%\lti_dsdk*.dll xcopy /v /c /r /y %_from_dir%\lti_dsdk*.dll %_to_dir% REM Updates for GDAL v3: -del /f /q %_to_dir%\gdal3*.dll -xcopy /v /c /r /y %_from_dir%\gdal3*.dll %_to_dir% -del /f /q %_to_dir%\proj_7*.dll -xcopy /v /c /r /y %_from_dir%\proj_7*.dll %_to_dir% +rem del /f /q %_to_dir%\gdal3*.dll +rem xcopy /v /c /r /y %_from_dir%\gdal3*.dll %_to_dir% +rem del /f /q %_to_dir%\proj_7*.dll +rem xcopy /v /c /r /y %_from_dir%\proj_7*.dll %_to_dir% + +REM gdal witout the version number: +del /f /q %_to_dir%\gdal.dll +xcopy /v /c /r /y %_from_dir%\gdal.dll %_to_dir% + +REM msvcp140* +rem xcopy /v /c /r /y %_from_dir%\msvcp140.dll %_to_dir% +xcopy /v /c /r /y %_from_dir%\msvcp140*.dll %_to_dir% REM Copy licenses: xcopy /v /c /r /y %_from_dir%\..\..\..\licenses\*.rtf %_to_dir%..\Licenses\ diff --git a/src/MapWinGIS-toolset142.sln b/src/MapWinGIS-toolset142.sln new file mode 100644 index 00000000..f6ff325f --- /dev/null +++ b/src/MapWinGIS-toolset142.sln @@ -0,0 +1,33 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MapWinGIS", "MapWinGIS-toolset142.vcxproj", "{1AB93398-2DE6-4043-BF6D-D438A794FB86}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + VLD|Win32 = VLD|Win32 + VLD|x64 = VLD|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1AB93398-2DE6-4043-BF6D-D438A794FB86}.Debug|Win32.ActiveCfg = Debug|Win32 + {1AB93398-2DE6-4043-BF6D-D438A794FB86}.Debug|Win32.Build.0 = Debug|Win32 + {1AB93398-2DE6-4043-BF6D-D438A794FB86}.Debug|x64.ActiveCfg = Debug|x64 + {1AB93398-2DE6-4043-BF6D-D438A794FB86}.Debug|x64.Build.0 = Debug|x64 + {1AB93398-2DE6-4043-BF6D-D438A794FB86}.Release|Win32.ActiveCfg = Release|Win32 + {1AB93398-2DE6-4043-BF6D-D438A794FB86}.Release|Win32.Build.0 = Release|Win32 + {1AB93398-2DE6-4043-BF6D-D438A794FB86}.Release|x64.ActiveCfg = Release|x64 + {1AB93398-2DE6-4043-BF6D-D438A794FB86}.Release|x64.Build.0 = Release|x64 + {1AB93398-2DE6-4043-BF6D-D438A794FB86}.VLD|Win32.ActiveCfg = VLD|Win32 + {1AB93398-2DE6-4043-BF6D-D438A794FB86}.VLD|Win32.Build.0 = VLD|Win32 + {1AB93398-2DE6-4043-BF6D-D438A794FB86}.VLD|x64.ActiveCfg = Debug|x64 + {1AB93398-2DE6-4043-BF6D-D438A794FB86}.VLD|x64.Build.0 = Debug|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/MapWinGIS-toolset142.vcxproj b/src/MapWinGIS-toolset142.vcxproj new file mode 100644 index 00000000..f7f38e0f --- /dev/null +++ b/src/MapWinGIS-toolset142.vcxproj @@ -0,0 +1,957 @@ + + + + + Release + Win32 + + + Release + x64 + + + VLD + Win32 + + + VLD + x64 + + + Debug + Win32 + + + Debug + x64 + + + + {1AB93398-2DE6-4043-BF6D-D438A794FB86} + MapWinGIS + MFCProj + 10.0.17134.0 + MapWinGIS + + + + DynamicLibrary + false + false + MultiByte + v142 + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)bin\$(Platform)\ + $(Configuration)\$(Platform)\ + false + false + AllRules.ruleset + + + .ocx + true + + + false + false + + + + + Copying executables... + $(ProjectDir)CopyTamasFiles.bat $(ProjectDir)..\Support\GDAL_SDK\$(PlatformToolset)\bin\$(Platform) $(TargetDir) + + + + + + + %(Outputs) + + + + NDEBUG;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + 3 + true + false + true + false + + + + /MP %(AdditionalOptions) + Disabled + false + Default + false + Speed + true + true + $(ProjectDir)..\Support\include;$(ProjectDir)..\Support\include\atlhttp;$(ProjectDir)..\support\include\ShapeLib;$(ProjectDir);$(ProjectDir)\COM classes;$(ProjectDir)\ComHelpers;$(ProjectDir)\MapControl;$(ProjectDir)\Drawing;$(ProjectDir)\Grid;$(ProjectDir)\Image;$(ProjectDir)\Processing;$(ProjectDir)\Shapefile;$(ProjectDir)\ShapeNetwork;$(ProjectDir)\Structures;$(ProjectDir)\Tin;$(ProjectDir)\Utilities;$(ProjectDir)\Grid\fip;$(ProjectDir)\Utilities\SpatialIndex;$(ProjectDir)\Tiles;$(ProjectDir)\Tiles\Providers;$(ProjectDir)\Tiles\Caching;$(ProjectDir)\Tiles\Loaders;$(ProjectDir)\Tiles\Projections;$(ProjectDir)\Tiles\Http;$(ProjectDir)\Utilities\SQLite;$(ProjectDir)..\Support\GDAL_SDK\$(PlatformToolset)\include\$(Platform);$(ProjectDir)..\Support\GDAL_SDK\$(PlatformToolset)\include\$(Platform)\curl;$(ProjectDir)\Ogr;$(ProjectDir)\Editor;C:\SWDEV\Projects\Lib\MapWinGIS_org\src\vcpkg_installed\x64-windows\include;%(AdditionalIncludeDirectories) + _NDBGSYMBOLS;_WINDOWS;_USRDLL;_AFXDLL;_CRT_SECURE_NO_WARNINGS;GEOS_NEW;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + false + false + Sync + Default + MultiThreadedDLL + false + false + Use + stdafx.h + $(IntDir)$(TargetName).pch + $(IntDir) + $(IntDir) + $(IntDir) + false + Level3 + true + ProgramDatabase + Default + false + false + 4503 + + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + %(AdditionalIncludeDirectories);$(intdir) + + + + + + true + /ignore:4099 /Ignore:4254 %(AdditionalOptions) + cqlib.lib;GdiPlus.lib;gdal_i.lib;version.lib;Crypt32.lib;Dbghelp.lib;SpatialIndex-mw.lib;geos_c.lib;libtiff_i.lib;ShapeLib.lib;libcurl_imp.lib;%(AdditionalDependencies) + NotSet + $(OutDir)MapWinGIS.ocx + true + $(ProjectDir)..\Support\GDAL_SDK\$(PlatformToolset)\lib\$(Platform);$(ProjectDir)..\Support\lib\$(PlatformToolset)\$(Platform)\Release;%(AdditionalLibraryDirectories) + false + LIBC.lib;%(IgnoreSpecificDefaultLibraries) + + + %(DelayLoadDLLs) + true + $(OutDir)MapWinGIS.pdb + Windows + Default + false + + + $(IntDir)MapWinGIS.lib + $(IntDir)MapWinGIS.tlb + 2 + + + $(IntDir)$(ProjectName).bsc + + + if $(PlatformName) == Win32 setx MapWinGISBin32 $(OutputPath) +if $(PlatformName) == x64 setx MapWinGISBin64 $(OutputPath) + + + + + + Win32 + + + WIN32;%(PreprocessorDefinitions) + false + + + /MACHINE:I386 %(AdditionalOptions) + MachineX86 + + + + + + x64 + + + WIN64;%(PreprocessorDefinitions) + stdcpp20 + + + /MACHINE:x64 %(AdditionalOptions) + MachineX64 + + + + + + VLD_FORCE_ENABLE;%(PreprocessorDefinitions) + + + false + + + + + + Full + false + RELEASE_MODE;%(PreprocessorDefinitions) + false + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MapWinGIS_i.h + MapWinGIS_i.c + $(IntDir)MapWinGIS.tlb + + + + + + + + + + + \ No newline at end of file diff --git a/src/MapWinGIS.sln b/src/MapWinGIS.sln index 0a9eacc5..998b80ca 100644 --- a/src/MapWinGIS.sln +++ b/src/MapWinGIS.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36203.30 d17.14 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MapWinGIS", "MapWinGIS.vcxproj", "{1AB93398-2DE6-4043-BF6D-D438A794FB86}" EndProject @@ -30,4 +30,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B34A6D21-D737-4E10-B091-38D589393B00} + EndGlobalSection EndGlobal diff --git a/src/MapWinGIS.sln.DotSettings b/src/MapWinGIS.sln.DotSettings index 1f61fb03..b5da44bb 100644 --- a/src/MapWinGIS.sln.DotSettings +++ b/src/MapWinGIS.sln.DotSettings @@ -1,5 +1,9 @@  <NamingElement Priority="1"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="__interface" /><type Name="class" /><type Name="struct" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></NamingElement> <NamingElement Priority="8"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global function" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement> + <NamingElement Priority="8" Title="Global functions"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global function" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aaBb" /></NamingElement> + <NamingElement Priority="1" Title="Classes and structs"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="__interface" /><type Name="class" /><type Name="struct" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement> + True True + True True \ No newline at end of file diff --git a/src/MapWinGIS.vcxproj b/src/MapWinGIS.vcxproj index 295e5150..c8c0153a 100644 --- a/src/MapWinGIS.vcxproj +++ b/src/MapWinGIS.vcxproj @@ -38,7 +38,7 @@ false false MultiByte - v142 + v143 @@ -170,17 +170,17 @@ echo in after $(CustomBuildAfterTargets) true /ignore:4099 /Ignore:4254 %(AdditionalOptions) - GdiPlus.lib;gdal_i.lib;version.lib;Crypt32.lib;Dbghelp.lib;geos_c.lib;tiff.lib;libcurl_imp.lib;cqlib.lib;ShapeLib.lib;%(AdditionalDependencies) + GdiPlus.lib;gdal_i.lib;version.lib;Crypt32.lib;Dbghelp.lib;geos_c.lib;tiff.lib;libcurl_imp.lib;ShapeLib.lib;%(AdditionalDependencies) NotSet $(OutDir)MapWinGIS.ocx true - $(ProjectDir)..\Support\GDAL_SDK\$(PlatformToolset)\lib\$(Platform);$(ProjectDir)..\Support\lib\$(PlatformToolset)\$(Platform)\Release;$(ProjectDir)\vcpkg_installed\$(VcpkgTriplet)\$(VcpkgHostTriplet)\lib;$(ProjectDir)\vcpkg_installed\$(VCPKG_DEFAULT_TRIPLET)\lib;%(AdditionalLibraryDirectories) + $(ProjectDir)..\Support\GDAL_SDK\$(PlatformToolset)\lib\$(Platform);$(ProjectDir)..\Support\lib\$(PlatformToolset)\$(Platform)\Release;$(ProjectDir)\vcpkg_installed\$(VcpkgTriplet)\$(VcpkgHostTriplet)\lib;$(ProjectDir)\vcpkg_installed\$(VCPKG_DEFAULT_TRIPLET)\lib;$(ProjectDir)vcpkg\vcpkg\buildtrees\libgeotiff\x64-windows-rel\lib;%(AdditionalLibraryDirectories) false LIBC.lib;%(IgnoreSpecificDefaultLibraries) %(DelayLoadDLLs) - true + DebugFull $(OutDir)MapWinGIS.pdb Windows Default @@ -241,7 +241,7 @@ if $(PlatformName) == x64 ( x64 - WIN64;%(PreprocessorDefinitions) + WIN64;SQUARE_TILES;BIG_TILE_SIZE;DEBUG_ALLOCATED_OBJECTS_OFF;%(PreprocessorDefinitions) stdc11 stdcpp14 true @@ -249,7 +249,8 @@ if $(PlatformName) == x64 ( /MACHINE:x64 %(AdditionalOptions) MachineX64 - spatialindex-64.lib;%(AdditionalDependencies) + spatialindex-64.lib;ShapeLib-toolset142.lib;xtiff.lib;%(AdditionalDependencies) + false echo "In Pre-Link event" @@ -304,7 +305,7 @@ if $(PlatformName) == x64 ( Full false - RELEASE_MODE;%(PreprocessorDefinitions) + RELEASE_MODE;SQUARE_TILES;%(PreprocessorDefinitions) false stdcpp14 stdc11 @@ -313,7 +314,8 @@ if $(PlatformName) == x64 ( true - false + true + false echo "In Pre-Link event" @@ -462,6 +464,7 @@ if $(PlatformName) == x64 ( + @@ -678,6 +681,7 @@ if $(PlatformName) == x64 ( + @@ -1037,6 +1041,7 @@ if $(PlatformName) == x64 ( + diff --git a/src/MapWinGIS.vcxproj.filters b/src/MapWinGIS.vcxproj.filters index ce4cd171..36ce8bcf 100644 --- a/src/MapWinGIS.vcxproj.filters +++ b/src/MapWinGIS.vcxproj.filters @@ -1130,6 +1130,9 @@ + + COM classes + @@ -1956,6 +1959,9 @@ + + COM classes + @@ -2180,5 +2186,8 @@ + + COM classes + \ No newline at end of file diff --git a/src/MapWinGIS.vcxproj.user b/src/MapWinGIS.vcxproj.user index 18bc6f32..5b64e465 100644 --- a/src/MapWinGIS.vcxproj.user +++ b/src/MapWinGIS.vcxproj.user @@ -10,7 +10,9 @@ WindowsLocalDebugger - $(MSBuildProjectDirectory)\..\MapWinGisTests-net6\WinFormsApp1\bin\$(Platform)\Debug\net6.0-windows\WinFormsApp1.exe + C:\Projects\Intrasis_WinGIS\Intrasis\Applications\IntrasisApp\bin\x64\Debug\net10.0-windows8.0\Intrasis.exe WindowsLocalDebugger + C:\Intrasis\Database\U20043\U20043.ipf sys hemlig + NativeOnly \ No newline at end of file diff --git a/src/changingVersionNumbers.txt b/src/changingVersionNumbers.txt index e628a111..703af3a6 100644 --- a/src/changingVersionNumbers.txt +++ b/src/changingVersionNumbers.txt @@ -1,5 +1,5 @@ When releasing a new version version numbers need to be updated on several locations: -MapWinGIS.rc lines: 115, 116, 134, 140 [5.4.0.0] +MapWinGIS.rc lines: 115, 116, 134, 140 [5.4.0.4] MapWinGIS.cpp lines: 33, 34 [5.4] MapWinGIS.idl line: 6742 (helpfile("MapWinGIS.chm")) [5.4] , 6764 (helpstring("Dispatch interface for Map Control")) [5.4] diff --git a/support/GDAL_SDK/v143/include/win32/!!!VC2019 win32 headers should be here!!!.txt b/support/GDAL_SDK/v143/include/win32/!!!VC2019 win32 headers should be here!!!.txt new file mode 100644 index 00000000..0519ecba --- /dev/null +++ b/support/GDAL_SDK/v143/include/win32/!!!VC2019 win32 headers should be here!!!.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/support/GDAL_SDK/v143/lib/win32/!!!VC2019 win32 libs should be here!!!.txt b/support/GDAL_SDK/v143/lib/win32/!!!VC2019 win32 libs should be here!!!.txt new file mode 100644 index 00000000..0519ecba --- /dev/null +++ b/support/GDAL_SDK/v143/lib/win32/!!!VC2019 win32 libs should be here!!!.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/support/GDAL_SDK/v143/removeOldGdalFiles.ps1 b/support/GDAL_SDK/v143/removeOldGdalFiles.ps1 new file mode 100644 index 00000000..0336ee24 --- /dev/null +++ b/support/GDAL_SDK/v143/removeOldGdalFiles.ps1 @@ -0,0 +1,3 @@ +Get-ChildItem bin\* -Force -Exclude !!!*.txt | Remove-Item -force -recurse +Get-ChildItem include\* -Force -Exclude !!!*.txt | Remove-Item -force -recurse +Get-ChildItem lib\* -Force -Exclude !!!*.txt | Remove-Item -force -recurse \ No newline at end of file diff --git a/support/ShapeLib/ShapeLib-toolset142.vcxproj b/support/ShapeLib/ShapeLib-toolset142.vcxproj new file mode 100644 index 00000000..d62ee7ba --- /dev/null +++ b/support/ShapeLib/ShapeLib-toolset142.vcxproj @@ -0,0 +1,204 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {A0B00502-605B-4382-B313-5983F6BC8E71} + Win32Proj + ShapeLib + 10.0 + + + + StaticLibrary + true + v143 + Unicode + + + StaticLibrary + true + v143 + Unicode + + + StaticLibrary + false + v143 + true + Unicode + + + StaticLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + + + + Level3 + Disabled + WIN32;_CRT_SECURE_NO_WARNINGS;SHAPELIB_DLLEXPORT;_DEBUG;_LIB;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + OldStyle + false + MultiThreadedDLL + Default + + + Windows + true + + + $(OutDir)$(TargetName)$(TargetExt) + + + %(AdditionalLibraryDirectories) + + + + + + + Level3 + Disabled + WIN32;_CRT_SECURE_NO_WARNINGS;SHAPELIB_DLLEXPORT;_DEBUG;_LIB;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + OldStyle + false + MultiThreadedDLL + Default + + + Windows + true + + + $(OutDir)$(TargetName)$(TargetExt) + + + %(AdditionalLibraryDirectories) + + + + + Level3 + + + Full + + + false + WIN32;_CRT_SECURE_NO_WARNINGS;SHAPELIB_DLLEXPORT;NDEBUG;_LIB;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + None + false + true + + + Windows + true + true + true + + + $(OutDir)$(TargetName)$(TargetExt) + + + %(AdditionalLibraryDirectories) + + + + + Level3 + + + Full + + + true + WIN32;_CRT_SECURE_NO_WARNINGS;SHAPELIB_DLLEXPORT;NDEBUG;_LIB;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + None + false + true + + + Windows + true + true + true + + + $(OutDir)$(TargetName)$(TargetExt) + + + %(AdditionalLibraryDirectories) + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/support/ShapeLib/ShapeLib-toolset143.vcxproj b/support/ShapeLib/ShapeLib-toolset143.vcxproj new file mode 100644 index 00000000..f4f82cd5 --- /dev/null +++ b/support/ShapeLib/ShapeLib-toolset143.vcxproj @@ -0,0 +1,208 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {D6A9A8D7-5556-47C9-A002-FAA9B9BD1CEA} + Win32Proj + ShapeLib + 10.0 + + + + StaticLibrary + true + v143 + Unicode + + + StaticLibrary + true + v143 + Unicode + + + StaticLibrary + false + v143 + true + Unicode + + + StaticLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(RootNamespace) + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(RootNamespace) + + + + + + Level3 + Disabled + WIN32;_CRT_SECURE_NO_WARNINGS;SHAPELIB_DLLEXPORT;_DEBUG;_LIB;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + OldStyle + false + MultiThreadedDLL + Default + + + Windows + true + + + $(OutDir)$(TargetName)$(TargetExt) + + + %(AdditionalLibraryDirectories) + + + + + + + Level3 + Disabled + WIN32;_CRT_SECURE_NO_WARNINGS;SHAPELIB_DLLEXPORT;_DEBUG;_LIB;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + OldStyle + false + MultiThreadedDLL + Default + stdcpp17 + + + Windows + true + + + $(OutDir)$(RootNamespace)$(TargetExt) + + + %(AdditionalLibraryDirectories) + + + + + Level3 + + + Full + + + false + WIN32;_CRT_SECURE_NO_WARNINGS;SHAPELIB_DLLEXPORT;NDEBUG;_LIB;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + None + false + true + + + Windows + true + true + true + + + $(OutDir)$(TargetName)$(TargetExt) + + + %(AdditionalLibraryDirectories) + + + + + Level3 + + + Full + + + true + WIN32;_CRT_SECURE_NO_WARNINGS;SHAPELIB_DLLEXPORT;NDEBUG;_LIB;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + None + false + true + stdcpp17 + + + Windows + true + true + true + + + $(OutDir)$(RootNamespace)$(TargetExt) + + + %(AdditionalLibraryDirectories) + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/support/SupportLibs-toolset142.sln b/support/SupportLibs-toolset142.sln new file mode 100644 index 00000000..aca31bc5 --- /dev/null +++ b/support/SupportLibs-toolset142.sln @@ -0,0 +1,52 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.33130.400 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spatialindex-mw", "spatialindex\spatialindex-vc\spatialindex-toolset142.vcxproj", "{38FBBD59-8344-4D8E-B728-3D51763B6A70}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cqlib-toolset142", "cqlib\cqlib-toolset142.vcxproj", "{E81699D6-81BA-41BF-A3A9-DD4CEF0B4E95}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ShapeLib-toolset142", "ShapeLib\ShapeLib-toolset142.vcxproj", "{A0B00502-605B-4382-B313-5983F6BC8E71}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|Win32.ActiveCfg = Debug|Win32 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|Win32.Build.0 = Debug|Win32 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|Win32.Deploy.0 = Debug|Win32 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|x64.ActiveCfg = Debug|x64 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|x64.Build.0 = Debug|x64 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Release|Win32.ActiveCfg = Release|Win32 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Release|Win32.Build.0 = Release|Win32 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Release|x64.ActiveCfg = Release|x64 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Release|x64.Build.0 = Release|x64 + {E81699D6-81BA-41BF-A3A9-DD4CEF0B4E95}.Debug|Win32.ActiveCfg = Debug|Win32 + {E81699D6-81BA-41BF-A3A9-DD4CEF0B4E95}.Debug|Win32.Build.0 = Debug|Win32 + {E81699D6-81BA-41BF-A3A9-DD4CEF0B4E95}.Debug|x64.ActiveCfg = Debug|x64 + {E81699D6-81BA-41BF-A3A9-DD4CEF0B4E95}.Debug|x64.Build.0 = Debug|x64 + {E81699D6-81BA-41BF-A3A9-DD4CEF0B4E95}.Release|Win32.ActiveCfg = Release|Win32 + {E81699D6-81BA-41BF-A3A9-DD4CEF0B4E95}.Release|Win32.Build.0 = Release|Win32 + {E81699D6-81BA-41BF-A3A9-DD4CEF0B4E95}.Release|x64.ActiveCfg = Release|x64 + {E81699D6-81BA-41BF-A3A9-DD4CEF0B4E95}.Release|x64.Build.0 = Release|x64 + {A0B00502-605B-4382-B313-5983F6BC8E71}.Debug|Win32.ActiveCfg = Debug|Win32 + {A0B00502-605B-4382-B313-5983F6BC8E71}.Debug|Win32.Build.0 = Debug|Win32 + {A0B00502-605B-4382-B313-5983F6BC8E71}.Debug|x64.ActiveCfg = Debug|x64 + {A0B00502-605B-4382-B313-5983F6BC8E71}.Debug|x64.Build.0 = Debug|x64 + {A0B00502-605B-4382-B313-5983F6BC8E71}.Release|Win32.ActiveCfg = Release|Win32 + {A0B00502-605B-4382-B313-5983F6BC8E71}.Release|Win32.Build.0 = Release|Win32 + {A0B00502-605B-4382-B313-5983F6BC8E71}.Release|x64.ActiveCfg = Release|x64 + {A0B00502-605B-4382-B313-5983F6BC8E71}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {78295CF0-1F26-4776-978E-2AAFFC25227B} + EndGlobalSection +EndGlobal diff --git a/support/SupportLibs-toolset143.sln b/support/SupportLibs-toolset143.sln new file mode 100644 index 00000000..a97bf9bf --- /dev/null +++ b/support/SupportLibs-toolset143.sln @@ -0,0 +1,52 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35931.197 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spatialindex-mw", "spatialindex\spatialindex-vc\spatialindex-toolset142.vcxproj", "{38FBBD59-8344-4D8E-B728-3D51763B6A70}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ShapeLib-toolset143", "ShapeLib\ShapeLib-toolset143.vcxproj", "{D6A9A8D7-5556-47C9-A002-FAA9B9BD1CEA}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cqlib-toolset143", "cqlib\cqlib-toolset143.vcxproj", "{19A1259D-0DCC-4FE5-9B0F-CF46B6F9DA81}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|Win32.ActiveCfg = Debug|Win32 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|Win32.Build.0 = Debug|Win32 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|Win32.Deploy.0 = Debug|Win32 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|x64.ActiveCfg = Debug|x64 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|x64.Build.0 = Debug|x64 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Release|Win32.ActiveCfg = Release|Win32 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Release|Win32.Build.0 = Release|Win32 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Release|x64.ActiveCfg = Release|x64 + {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Release|x64.Build.0 = Release|x64 + {D6A9A8D7-5556-47C9-A002-FAA9B9BD1CEA}.Debug|Win32.ActiveCfg = Debug|Win32 + {D6A9A8D7-5556-47C9-A002-FAA9B9BD1CEA}.Debug|Win32.Build.0 = Debug|Win32 + {D6A9A8D7-5556-47C9-A002-FAA9B9BD1CEA}.Debug|x64.ActiveCfg = Debug|x64 + {D6A9A8D7-5556-47C9-A002-FAA9B9BD1CEA}.Debug|x64.Build.0 = Debug|x64 + {D6A9A8D7-5556-47C9-A002-FAA9B9BD1CEA}.Release|Win32.ActiveCfg = Release|Win32 + {D6A9A8D7-5556-47C9-A002-FAA9B9BD1CEA}.Release|Win32.Build.0 = Release|Win32 + {D6A9A8D7-5556-47C9-A002-FAA9B9BD1CEA}.Release|x64.ActiveCfg = Release|x64 + {D6A9A8D7-5556-47C9-A002-FAA9B9BD1CEA}.Release|x64.Build.0 = Release|x64 + {19A1259D-0DCC-4FE5-9B0F-CF46B6F9DA81}.Debug|Win32.ActiveCfg = Debug|Win32 + {19A1259D-0DCC-4FE5-9B0F-CF46B6F9DA81}.Debug|Win32.Build.0 = Debug|Win32 + {19A1259D-0DCC-4FE5-9B0F-CF46B6F9DA81}.Debug|x64.ActiveCfg = Debug|x64 + {19A1259D-0DCC-4FE5-9B0F-CF46B6F9DA81}.Debug|x64.Build.0 = Debug|x64 + {19A1259D-0DCC-4FE5-9B0F-CF46B6F9DA81}.Release|Win32.ActiveCfg = Release|Win32 + {19A1259D-0DCC-4FE5-9B0F-CF46B6F9DA81}.Release|Win32.Build.0 = Release|Win32 + {19A1259D-0DCC-4FE5-9B0F-CF46B6F9DA81}.Release|x64.ActiveCfg = Release|x64 + {19A1259D-0DCC-4FE5-9B0F-CF46B6F9DA81}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {78295CF0-1F26-4776-978E-2AAFFC25227B} + EndGlobalSection +EndGlobal diff --git a/support/cqlib/cqlib-toolset142.vcxproj b/support/cqlib/cqlib-toolset142.vcxproj new file mode 100644 index 00000000..8c089ae9 --- /dev/null +++ b/support/cqlib/cqlib-toolset142.vcxproj @@ -0,0 +1,226 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E81699D6-81BA-41BF-A3A9-DD4CEF0B4E95} + cqlib + 10.0 + + + + StaticLibrary + v143 + false + MultiByte + + + StaticLibrary + v143 + false + MultiByte + + + StaticLibrary + v143 + false + MultiByte + + + StaticLibrary + v143 + false + MultiByte + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.21005.1 + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + Default + MultiThreadedDLL + + .\Debug/cqlib.pch + .\Debug/ + .\Debug/ + .\Debug/ + Level3 + true + EditAndContinue + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(OutDir)cqlib.lib + true + + + + + X64 + + + Disabled + WIN32;WIN64;_DEBUG;_LIB;%(PreprocessorDefinitions) + Default + MultiThreadedDLL + + .\Debug/cqlib.pch + .\Debug/ + .\Debug/ + .\Debug/ + Level3 + true + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(OutDir)$(TargetName)$(TargetExt) + true + + + + + Full + Default + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDLL + + + + $(IntDir)cqlib.pch + $(IntDir) + $(IntDir) + $(IntDir) + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(OutDir)cqlib.lib + true + + + $(OutDir)$(ProjectName).bsc + + + + + + + + X64 + + + Full + Default + WIN32;WIN64;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDLL + + + + $(IntDir)cqlib.pch + $(IntDir) + $(IntDir) + $(IntDir) + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(OutDir)cqlib.lib + true + true + + + $(OutDir)$(ProjectName).bsc + + + Copy lib to general lib folder + rem copy "$(TargetPath)" "$(ProjectDir)..\lib\v142\$(Platform)" + + + + + Disabled + EnableFastChecks + Disabled + EnableFastChecks + MaxSpeed + MaxSpeed + + + + + + + + + \ No newline at end of file diff --git a/support/cqlib/cqlib-toolset143.vcxproj b/support/cqlib/cqlib-toolset143.vcxproj new file mode 100644 index 00000000..e4d8f278 --- /dev/null +++ b/support/cqlib/cqlib-toolset143.vcxproj @@ -0,0 +1,228 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {19A1259D-0DCC-4FE5-9B0F-CF46B6F9DA81} + cqlib + 10.0 + + + + StaticLibrary + v143 + false + MultiByte + + + StaticLibrary + v143 + false + MultiByte + + + StaticLibrary + v143 + false + MultiByte + + + StaticLibrary + v143 + false + MultiByte + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.21005.1 + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(RootNamespace) + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(RootNamespace) + + + + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + Default + MultiThreadedDLL + + .\Debug/cqlib.pch + .\Debug/ + .\Debug/ + .\Debug/ + Level3 + true + EditAndContinue + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(OutDir)cqlib.lib + true + + + + + X64 + + + Disabled + WIN32;WIN64;_DEBUG;_LIB;%(PreprocessorDefinitions) + Default + MultiThreadedDLL + + .\Debug/cqlib.pch + .\Debug/ + .\Debug/ + .\Debug/ + Level3 + true + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(OutDir)$(TargetName)$(TargetExt) + true + + + + + Full + Default + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDLL + + + + $(IntDir)cqlib.pch + $(IntDir) + $(IntDir) + $(IntDir) + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(OutDir)cqlib.lib + true + + + $(OutDir)$(ProjectName).bsc + + + + + + + + X64 + + + Full + Default + WIN32;WIN64;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDLL + + + + $(IntDir)cqlib.pch + $(IntDir) + $(IntDir) + $(IntDir) + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(OutDir)cqlib.lib + true + true + + + $(OutDir)$(ProjectName).bsc + + + Copy lib to general lib folder + rem copy "$(TargetPath)" "$(ProjectDir)..\lib\v142\$(Platform)" + + + + + Disabled + EnableFastChecks + Disabled + EnableFastChecks + MaxSpeed + MaxSpeed + + + + + + + + + \ No newline at end of file diff --git a/support/spatialindex/spatialindex-vc/spatialindex-toolset141.vcxproj b/support/spatialindex/spatialindex-vc/spatialindex-toolset141.vcxproj index 37b60a5a..30eb2514 100644 --- a/support/spatialindex/spatialindex-vc/spatialindex-toolset141.vcxproj +++ b/support/spatialindex/spatialindex-vc/spatialindex-toolset141.vcxproj @@ -23,32 +23,32 @@ {38FBBD59-8344-4D8E-B728-3D51763B6A70} spatialindex ManagedCProj - 10.0.17763.0 + 10.0 StaticLibrary - v141 + v142 Unicode false true StaticLibrary - v141 + v142 Unicode false StaticLibrary - v141 + v142 Unicode false true StaticLibrary - v141 + v142 Unicode false @@ -93,7 +93,7 @@ Disabled - $(SolutionDir)include;%(AdditionalIncludeDirectories) + $(SolutionDir)include;C:\SWDEV\Projects\Lib\MapWinGIS\src\vcpkg\packages\libspatialindex_x64-windows\include;%(AdditionalIncludeDirectories) WIN32;_DEBUG;SPATIALINDEX_CREATE_DLL;%(PreprocessorDefinitions) MultiThreadedDLL @@ -108,12 +108,13 @@ Disabled - $(SolutionDir)include;%(AdditionalIncludeDirectories) + $(SolutionDir)include;C:\SWDEV\Projects\Lib\MapWinGIS\src\vcpkg\packages\libspatialindex_x64-windows\include;%(AdditionalIncludeDirectories) WIN64;_DEBUG;SPATIALINDEX_CREATE_DLL;%(PreprocessorDefinitions) MultiThreadedDLL Level3 ProgramDatabase + stdcpp17 diff --git a/support/spatialindex/spatialindex-vc/spatialindex-toolset142.vcxproj b/support/spatialindex/spatialindex-vc/spatialindex-toolset142.vcxproj new file mode 100644 index 00000000..51e521e7 --- /dev/null +++ b/support/spatialindex/spatialindex-vc/spatialindex-toolset142.vcxproj @@ -0,0 +1,315 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + spatialindex-mw + {38FBBD59-8344-4D8E-B728-3D51763B6A70} + spatialindex + ManagedCProj + 10.0 + + + + StaticLibrary + v143 + Unicode + false + true + + + StaticLibrary + v143 + Unicode + false + + + StaticLibrary + v143 + Unicode + false + true + + + StaticLibrary + v143 + Unicode + false + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.21005.1 + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)lib\$(PlatformToolset)\$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + + X64 + + + Disabled + $(SolutionDir)include;C:\SWDEV\Projects\Lib\MapWinGIS\src\vcpkg\packages\libspatialindex_x64-windows\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;SPATIALINDEX_CREATE_DLL;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level3 + OldStyle + Default + + + + + X64 + + + Disabled + $(SolutionDir)include;C:\SWDEV\Projects\Lib\MapWinGIS\src\vcpkg\packages\libspatialindex_x64-windows\include;%(AdditionalIncludeDirectories) + WIN64;_WIN64;_DEBUG;SPATIALINDEX_CREATE_DLL;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level3 + ProgramDatabase + stdcpp20 + + + + + X64 + + + Full + $(SolutionDir)include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level3 + + false + true + + + + + X64 + + + Full + $(SolutionDir)include;%(AdditionalIncludeDirectories) + WIN64;NDEBUG;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level3 + + false + true + + + + + true + true + + + true + true + + + true + true + + + + + + + + + + + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + + + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + + + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + + + + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + + + + + + + + + + + + + + + + + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + + + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + + + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + + + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.xdc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/TestApplication.sln b/test/TestApplication.sln index 0906b468..dcee9933 100644 --- a/test/TestApplication.sln +++ b/test/TestApplication.sln @@ -1,24 +1,30 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35931.197 d17.13 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication", "TestApplication\TestApplication.csproj", "{E813DA57-E5F5-48A6-A6B2-3545ECAAD7CB}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {E813DA57-E5F5-48A6-A6B2-3545ECAAD7CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E813DA57-E5F5-48A6-A6B2-3545ECAAD7CB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E813DA57-E5F5-48A6-A6B2-3545ECAAD7CB}.Debug|x64.ActiveCfg = Debug|x64 + {E813DA57-E5F5-48A6-A6B2-3545ECAAD7CB}.Debug|x64.Build.0 = Debug|x64 {E813DA57-E5F5-48A6-A6B2-3545ECAAD7CB}.Debug|x86.ActiveCfg = Debug|x86 {E813DA57-E5F5-48A6-A6B2-3545ECAAD7CB}.Debug|x86.Build.0 = Debug|x86 {E813DA57-E5F5-48A6-A6B2-3545ECAAD7CB}.Release|Any CPU.ActiveCfg = Release|Any CPU {E813DA57-E5F5-48A6-A6B2-3545ECAAD7CB}.Release|Any CPU.Build.0 = Release|Any CPU + {E813DA57-E5F5-48A6-A6B2-3545ECAAD7CB}.Release|x64.ActiveCfg = Release|x64 + {E813DA57-E5F5-48A6-A6B2-3545ECAAD7CB}.Release|x64.Build.0 = Release|x64 {E813DA57-E5F5-48A6-A6B2-3545ECAAD7CB}.Release|x86.ActiveCfg = Release|x86 {E813DA57-E5F5-48A6-A6B2-3545ECAAD7CB}.Release|x86.Build.0 = Release|x86 EndGlobalSection diff --git a/test/TestApplication/Properties/Resources.Designer.cs b/test/TestApplication/Properties/Resources.Designer.cs index 4394a5e5..655def32 100644 --- a/test/TestApplication/Properties/Resources.Designer.cs +++ b/test/TestApplication/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34014 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -19,7 +19,7 @@ namespace TestApplication.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/test/TestApplication/Properties/Settings.Designer.cs b/test/TestApplication/Properties/Settings.Designer.cs index 24009990..ddc38812 100644 --- a/test/TestApplication/Properties/Settings.Designer.cs +++ b/test/TestApplication/Properties/Settings.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34014 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -12,7 +12,7 @@ namespace TestApplication.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.13.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/test/TestApplication/TestApplication.csproj b/test/TestApplication/TestApplication.csproj index 8fa054cf..cf875459 100644 --- a/test/TestApplication/TestApplication.csproj +++ b/test/TestApplication/TestApplication.csproj @@ -10,7 +10,7 @@ Properties TestApplication TestApplication - v4.5.1 + v4.8 512 false @@ -43,6 +43,7 @@ prompt 4 false + x64 pdbonly @@ -73,6 +74,24 @@ prompt false + + true + C:\Projects\Lib\MapWinGIS_org\src\bin\Debug\x64\ + TRACE;DEBUG;CODE_ANALYSIS + full + x64 + 7.3 + prompt + false + + + C:\Projects\Lib\MapWinGIS_org\src\bin\Debug\x64\ + TRACE + true + x64 + 7.3 + prompt + diff --git a/test/TestApplication/app.config b/test/TestApplication/app.config index faedb805..95b45144 100644 --- a/test/TestApplication/app.config +++ b/test/TestApplication/app.config @@ -9,145 +9,145 @@ - + - + - + 0, 0 - + - + - + - + - + - + - + 0 - + 0 - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -156,4 +156,4 @@ - + From 7cd49d4ddc2c8a0c01e050b07ad8956672d64eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 13:34:38 +0200 Subject: [PATCH 14/55] Fixed selection (IK-384) allow selection of inner shape. Always draw selected objects, so the selection drawing can be drawn on top. --- src/ComHelpers/SelectionHelper.cpp | 45 +++++++++++++++++++++++++++--- src/ComHelpers/ShapefileHelper.cpp | 9 ++++-- src/Drawing/ShapefileDrawing.cpp | 3 +- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/ComHelpers/SelectionHelper.cpp b/src/ComHelpers/SelectionHelper.cpp index 9ed2372c..489d8b1b 100644 --- a/src/ComHelpers/SelectionHelper.cpp +++ b/src/ComHelpers/SelectionHelper.cpp @@ -209,23 +209,60 @@ bool SelectionHelper::SelectSingleShape(IShapefile* sf, Extent& box, long& shape { return SelectSingleShape(sf, box, SelectMode::INTERSECTION, shapeIndex); } + bool SelectionHelper::SelectSingleShape(IShapefile* sf, Extent& box, SelectMode mode, long& shapeIndex) { vector results; + bool foundMatch = false; + double minDistance = (std::numeric_limits::max)(); if (SelectShapes(sf, box, mode, results)) { - for (int i = results.size() - 1; i >= 0; i--) + auto center = box.GetCenter(); + IShape* ptShp = nullptr; + ComHelper::CreateShape(&ptShp); + ptShp->put_ShapeType(SHP_POINT); + IPoint* pnt; + ComHelper::CreatePoint(&pnt); + pnt->put_X(center.x); + pnt->put_Y(center.y); + VARIANT_BOOL retVal; + long pointIndex = 0; + ptShp->InsertPoint(pnt, &pointIndex, &retVal); + pnt->Release(); + for (int i = static_cast(results.size()) - 1; i >= 0; i--) { VARIANT_BOOL visible; sf->get_ShapeRendered(results[i], &visible); if (visible) { - shapeIndex = results[i]; - return true; + IShape* shp; + sf->get_Shape(results[i], &shp); + ShpfileType shpfileType; + shp->get_ShapeType(&shpfileType); + double distance; + if (shpfileType == SHP_POLYGON || shpfileType == SHP_POLYGONZ || shpfileType == SHP_POLYGONM) + { + // Measure distance to polygons boundary to allow selection of inner shape, (IK-384) + IShape* boundary; + shp->Boundary(&boundary); + boundary->Distance(ptShp, &distance); + boundary->Release(); + } + else + shp->Distance(ptShp, &distance); + + + if (minDistance > distance) + { + minDistance = distance; + shapeIndex = results[i]; + foundMatch = true; + } } } + ptShp->Release(); } - return false; + return foundMatch; } /***********************************************************************/ diff --git a/src/ComHelpers/ShapefileHelper.cpp b/src/ComHelpers/ShapefileHelper.cpp index 9b85fa09..f4c3da65 100644 --- a/src/ComHelpers/ShapefileHelper.cpp +++ b/src/ComHelpers/ShapefileHelper.cpp @@ -403,13 +403,13 @@ bool tryGetCloserPointForShape(IShape* shp, IShape* ptShp, double& minDist, doub // Get the distance double distance; resShp->get_Length(&distance); + resShp->Release(); - // Check if this is allowed and/or smaller than the previous found point: + // Check if this is allowed and/or smaller than the previous found point: if (distance < minDist && distance < maxDistance) { fx = xPnt; fy = yPnt; minDist = distance; - resShp->Release(); return true; } } @@ -488,6 +488,11 @@ bool ShapefileHelper::GetClosestSnapPosition(IShapefile* sf, double x, double y, else if (shptype == SHP_POLYGONZ) partShp->put_ShapeType(SHP_POLYLINEZ); + /*CString str; + str.Format("0x%016llx\r\n", shp); + const CComBSTR bstr(str); + partShp->put_Key(bstr); */ + // Insert part long part = 0; VARIANT_BOOL vbretval; diff --git a/src/Drawing/ShapefileDrawing.cpp b/src/Drawing/ShapefileDrawing.cpp index 3801854f..f1e47309 100644 --- a/src/Drawing/ShapefileDrawing.cpp +++ b/src/Drawing/ShapefileDrawing.cpp @@ -408,7 +408,8 @@ bool CShapefileDrawer::Draw(const CRect& rcBounds, IShapefile* sf) } } } - else + // Always draw selected objects, so the selection drawing can be drawn on top. + //else { long catIndex = (*_shapeData)[offset]->category; From 4f9c54de0a0517eb74d0121562299b9e5daa1c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 13:39:30 +0200 Subject: [PATCH 15/55] Fixed memory leak i selection. --- src/COM classes/Shapefile_Selection.cpp | 11 +++++++++++ src/Utilities/ColoringGraph.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/COM classes/Shapefile_Selection.cpp b/src/COM classes/Shapefile_Selection.cpp index 15fbf084..382438e2 100644 --- a/src/COM classes/Shapefile_Selection.cpp +++ b/src/COM classes/Shapefile_Selection.cpp @@ -80,7 +80,14 @@ bool CShapefile::SelectShapesCore(Extent& extents, const double tolerance, const // build GEOSGeom for comparison IShape* shpExt = nullptr; +#if DEBUG_ALLOCATED_OBJECTS + auto currentBrake = ComHelper::GetBreak(); + ComHelper::SetBreak(false); +#endif ComHelper::CreateShape(&shpExt); +#if DEBUG_ALLOCATED_OBJECTS + ComHelper::SetBreak(currentBrake); +#endif const bool bPtSelection = bMinX == bMaxX && bMinY == bMaxY; int localNumShapes = static_cast(_shapeData.size()); @@ -158,6 +165,8 @@ bool CShapefile::SelectShapesCore(Extent& extents, const double tolerance, const shpExt->AddPoint(bMinX, bMinY, &idx); // convert input point to GEOS GEOSGeom geosPoint = GeosConverter::ShapeToGeom(shpExt); // TODO: Fix compile warning + shpExt->Release(); + shpExt = nullptr; if (shpType2D == SHP_POLYGON) { @@ -216,6 +225,8 @@ bool CShapefile::SelectShapesCore(Extent& extents, const double tolerance, const shpExt->AddPoint(bMinX, bMinY, &idx); // convert extent to GEOS GEOSGeom geosExtent = GeosConverter::ShapeToGeom(shpExt); // TODO: Fix compile warning + shpExt->Release(); + shpExt = nullptr; for (i = 0; i < localNumShapes; i++) { diff --git a/src/Utilities/ColoringGraph.h b/src/Utilities/ColoringGraph.h index 6e96c7f0..8e47f00e 100644 --- a/src/Utilities/ColoringGraph.h +++ b/src/Utilities/ColoringGraph.h @@ -1,4 +1,5 @@ #pragma once +#include #include namespace Coloring From 5a5fe7277164cfe0e02fe93e58a77c8dc4bb10b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 13:44:09 +0200 Subject: [PATCH 16/55] Fixed preserving selection during update from OGR source. --- src/COM classes/OgrLayer.cpp | 49 +++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/COM classes/OgrLayer.cpp b/src/COM classes/OgrLayer.cpp index 9a5698db..5f2273a8 100644 --- a/src/COM classes/OgrLayer.cpp +++ b/src/COM classes/OgrLayer.cpp @@ -171,27 +171,40 @@ void COgrLayer::UpdateShapefileFromOGRLoader() { shp->Create(shpType, &vb); shp->ImportFromBinary(data[i]->Shape, &vb); - _shapefile->EditInsertShape(shp, &count, &vb); - tbl->UpdateTableRow(data[i]->Row, count); + ShpfileType shapeType; + shp->get_ShapeType(&shapeType); + auto compatible = shapeType == shpType + || ShapeUtility::Convert2D(shapeType) == ShapeUtility::Convert2D(shpType); + // Ignore incompatible shapes + if (compatible) + { + _shapefile->EditInsertShape(shp, &count, &vb); + + tbl->UpdateTableRow(data[i]->Row, count); + } data[i]->Row = NULL; // we no longer own it; it'll be cleared by Shapefile.EditClear - // Preserve selection accross reloads: - CComVariant pVal; - tbl->get_CellValue(0, count, &pVal); - bool wasSelected = false; - for (size_t i = 0; i < selectedOgrFIDs.size(); i++) - { - if (selectedOgrFIDs[i] == pVal) { - wasSelected = true; - break; - } - } - if (wasSelected) - _shapefile->put_ShapeSelected(count, VARIANT_TRUE); - - if (hasFid) - ((CShapefile*)_shapefile)->MapOgrFid2ShapeIndex(pVal.lVal, count); + if (compatible) + { + // Preserve selection accross reloads: + CComVariant pVal; + tbl->get_CellValue(0, count, &pVal); + bool wasSelected = false; + for (size_t i = 0; i < selectedOgrFIDs.size(); i++) + { + if (selectedOgrFIDs[i] == pVal) { + wasSelected = true; + break; + } + } + if (wasSelected) + _shapefile->put_ShapeSelected(count, VARIANT_TRUE); + + if (hasFid) + ((CShapefile*)_shapefile)->MapOgrFid2ShapeIndex(pVal.lVal, count); + } + count++; } From 711ec1f6a26480e4d5e4cb00c1c7ac4ef5c5bd26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 13:46:23 +0200 Subject: [PATCH 17/55] Added error handling in SaveToFile if DBFAddField() fails. --- src/COM classes/TableClass.cpp | 25 ++++++++++++++++++++++--- src/COM classes/TableClass.h | 2 ++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/COM classes/TableClass.cpp b/src/COM classes/TableClass.cpp index 2093976b..b8b45880 100644 --- a/src/COM classes/TableClass.cpp +++ b/src/COM classes/TableClass.cpp @@ -782,7 +782,9 @@ bool CTableClass::SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace } } - DBFAddField(newdbfHandle, OLE2CA(fname), (DBFFieldType)type, width, precision); + int ret = DBFAddField(newdbfHandle, OLE2CA(fname), (DBFFieldType)type, width, precision); + if (ret == -1) + ErrorMessage(tkDBF_CANT_ADD_DBF_FIELD); field->Release(); } @@ -822,6 +824,15 @@ bool CTableClass::SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace if (!updateFileInPlace) DBFClose(newdbfHandle); + // Set byte 29 to 0x00 in the .dbf file (Codepage mark) + FILE* dbfFile = _wfopen(dbfFilename, L"r+"); + if (dbfFile != NULL) { + fseek(dbfFile, 29, SEEK_SET); + fputc('\0', dbfFile); + fflush(dbfFile); + fclose(dbfFile); + } + return true; } @@ -863,6 +874,9 @@ STDMETHODIMP CTableClass::SaveAs(BSTR dbfFilename, ICallback *cBack, VARIANT_BOO // ************************************************************** void CTableClass::ClearFields() { + //if(_triggerDebug) + //DebugBreak(); + for (int i = 0; i < FieldCount(); i++) { if (_fields[i]->field != NULL) @@ -884,6 +898,9 @@ STDMETHODIMP CTableClass::Close(VARIANT_BOOL *retval) *retval = VARIANT_TRUE; + //if(_triggerDebug) + //DebugBreak(); + StopAllJoins(); ClearFields(); @@ -1474,7 +1491,9 @@ bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowI if (val.vt == VT_BSTR) { nonstackString = Utility::ConvertBSTRToLPSTR(val.bstrVal, (isUTF8 ? CP_UTF8 : CP_ACP)); // ((LPCSTR)Utility::ConvertToUtf8(val.bstrVal)); // Utility::SYS2A(val.bstrVal); + int fieldCount = DBFGetFieldCount(dbfHandle); DBFWriteStringAttribute(dbfHandle, toRowIndex, i, nonstackString); + //::OutputDebugString("DBFWriteStringAttribute() done!"); delete[] nonstackString; nonstackString = NULL; } @@ -1764,7 +1783,7 @@ STDMETHODIMP CTableClass::EditCellValue(long FieldIndex, long RowIndex, VARIANT // Darrel Brown, 10/16/2003 Added support for null cell values // jf, 2/17/2018, added support for Dates and Booleans - if (newVal.vt != VT_I4 && newVal.vt != VT_R8 && newVal.vt != VT_BSTR && newVal.vt != VT_DATE && newVal.vt != VT_BOOL && newVal.vt != VT_NULL) + if (newVal.vt != VT_I4 && newVal.vt != VT_R8 && newVal.vt != VT_BSTR && newVal.vt != VT_DATE && newVal.vt != VT_BOOL && newVal.vt != VT_NULL && newVal.vt != VT_EMPTY) { ErrorMessage(tkINCORRECT_VARIANT_TYPE); return S_OK; @@ -3296,7 +3315,7 @@ STDMETHODIMP CTableClass::StopJoin(int joinIndex, VARIANT_BOOL* retVal) STDMETHODIMP CTableClass::get_IsJoined(VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); - for (size_t i = _fields.size() - 1; i >= 0; i--) + for (size_t i = _fields.size() - 1; i >= 0 && _fields.size() > i; i--) { if (_fields[i]->Joined()) { *retVal = VARIANT_TRUE; diff --git a/src/COM classes/TableClass.h b/src/COM classes/TableClass.h index 4a1bd217..ed3009cc 100644 --- a/src/COM classes/TableClass.h +++ b/src/COM classes/TableClass.h @@ -46,6 +46,7 @@ class ATL_NO_VTABLE CTableClass : _pUnkMarshaler = NULL; _key = SysAllocString(L""); _lastRecordIndex = -1; + _triggerDebug = false; gReferenceCounter.AddRef(tkInterface::idTable); } @@ -194,6 +195,7 @@ class ATL_NO_VTABLE CTableClass : int _lastRecordIndex; // last index accessed with get_CellValue bool _appendMode; int _appendStartShapeCount; + bool _triggerDebug; public: bool m_needToSaveAsNewFile; From bdb0162116fd04836672d221aab97e35364234dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 13:54:02 +0200 Subject: [PATCH 18/55] Added functions PlaceLabels, PlaceAllMapLabels and GetLabelExtents. --- src/Drawing/LabelDrawing.cpp | 402 ++++++++++++++++++++++++++++++++++- src/Drawing/LabelDrawing.h | 9 +- src/Drawing/LabelOptions.h | 2 + 3 files changed, 408 insertions(+), 5 deletions(-) diff --git a/src/Drawing/LabelDrawing.cpp b/src/Drawing/LabelDrawing.cpp index 8ac833ce..6c9ca90c 100644 --- a/src/Drawing/LabelDrawing.cpp +++ b/src/Drawing/LabelDrawing.cpp @@ -54,7 +54,7 @@ void CLabelDrawer::InitSettings(LabelSettings& settings, ILabels* labels, IShape settings.scaleFactor = GetScaleFactor(labels); - settings.autoOffset = GetAutoOffset(labels, sf); + settings.autoOffset = sf != nullptr ? GetAutoOffset(labels, sf) : false; settings.numLabels = LabelsHelper::GetCount(labels); @@ -121,6 +121,8 @@ void CLabelDrawer::DrawLabels(ILabels* labels) gdi.InitDc(_graphics); } + lbs->AddDrawnLabel(-1); // Reset collection + // --------------------------------------------------------------- // drawing categories - we'll start from the categories // with the higher priority, therefore reverse order @@ -173,7 +175,7 @@ void CLabelDrawer::DrawLabels(ILabels* labels) if ((lbl->category == categoryIndex) || (categoryIndex == -1 && (lbl->category < 0 || lbl->category >= settings.numCategories))) {} else continue; /* Wrong category */ - + // blocking the labels with the text already displayed if (settings.removeDuplicates) { @@ -221,6 +223,7 @@ void CLabelDrawer::DrawLabels(ILabels* labels) continue; } + lbs->AddDrawnLabel(k); // actual drawing if (useGdiPlus) { gdiPlus.DrawLabel(options, rect, piX, piY, angle); @@ -248,6 +251,401 @@ void CLabelDrawer::DrawLabels(ILabels* labels) } } +int* CLabelDrawer::PlaceLabels(ILabels* labels) +{ + if (!CheckVisibility(labels)) + return NULL; + + CLabels* lbs = static_cast(labels); + vector*>* labelData = lbs->get_LabelData(); + + IShapefile* sf = lbs->get_ParentShapefile(); + std::vector* shapeData = NULL; + if (sf) { + shapeData = ((CShapefile*)sf)->get_ShapeVector(); + } + + // --------------------------------- + // settings, filter and sorting + // --------------------------------- + LabelSettings settings; + InitSettings(settings, labels, sf); + + vector visibilityMask(settings.numLabels, false); + GetVisibilityMask(labels, sf, shapeData, visibilityMask); + + // sort them if sort field is specified + vector* indices = NULL; + if (sf) { + ((CShapefile*)sf)->GetSorting(&indices); + } + + if (indices && indices->size() != settings.numLabels) { + indices = NULL; + } + + // --------------------------------- + // preparing to (not) draw + // --------------------------------- + GdiLabelDrawer gdi; + GdiPlusLabelDrawer gdiPlus; + CRect rect(0, 0, 0, 0); + std::set uniqueValues; + + bool useGdiPlus = GetUseGdiPlus(labels); + if (useGdiPlus) { + gdiPlus.InitGraphics(_graphics, labels); + } + else { + gdi.InitDc(_graphics); + } + + // --------------------------------------------------------------- + // drawing categories - we'll start from the categories + // with the higher priority, therefore reverse order + // --------------------------------------------------------------- + for (int categoryIndex = settings.numCategories - 1; categoryIndex >= -1; categoryIndex--) + { + CLabelOptions* options = GetCategoryOptions(labels, categoryIndex); + + if (!options || !options->visible) continue; + + + // --------------------------------------------------------------- + // place labels + // --------------------------------------------------------------- + for (long k = 0; k < settings.numLabels; k++) + { + long i = indices ? (*indices)[k] : k; + + if (!visibilityMask[i]) { + continue; + } + + vector* parts = (*labelData)[i]; + for (int j = 0; j < (int)parts->size(); j++) + { + CLabelInfo* lbl = (*parts)[j]; + + if (lbl->x < _extents->left) continue; + if (lbl->x > _extents->right) continue; + if (lbl->y < _extents->bottom) continue; + if (lbl->y > _extents->top) continue; + if (lbl->text.GetLength() <= 0) continue; + + if ((lbl->category == categoryIndex) || (categoryIndex == -1 && (lbl->category < 0 || lbl->category >= settings.numCategories))) {} + else continue; /* Wrong category */ + + // blocking the labels with the text already displayed + if (settings.removeDuplicates) + { + if (uniqueValues.find(lbl->text) != uniqueValues.end()) + continue; + else + uniqueValues.insert(lbl->text); + } + + // measuring label + if (useGdiPlus) { + gdiPlus.MeasureString(lbl, rect); + } + else { + gdi.MeasureString(lbl, rect); + } + + // rotation angle + double angle, angleRad; + LabelDrawingHelper::CalcRotation(lbl, _mapRotation, angle); + angleRad = AngleHelper::ToRad(angle); + + // calculating screen rectangle + double piX, piY; + + // Fix for MWGIS-79: + int shapeSize = 0; + if (sf) + shapeSize = (*shapeData)[i]->size; + CalcScreenRectangle(options, lbl, settings.autoOffset, shapeSize, rect, piX, piY); + + // do we have overlaps? + if (!TryAvoidCollisions(lbl, settings.avoidCollisions, rect, piX, piY, settings.buffer, angleRad)) { + continue; + } + + lbs->AddDrawnLabel(k); + // actual drawing + if (useGdiPlus) { + gdiPlus.DrawLabel(options, rect, piX, piY, angle); + } + else { + gdi.DrawLabel(options, lbl, rect, angleRad, piX, piY); + } + } + } // label + } +} + +CRect CLabelDrawer::GetLabelExtents(ILabels* labels, long index) +{ + auto lbs = static_cast(labels); + //CLabels* lbs = static_cast(labels); + vector*>* labelData = lbs->get_LabelData(); + + vector* parts = (*labelData)[index]; + CLabelInfo* lbl = (*parts)[0]; + + CLabelOptions* options = GetCategoryOptions(labels, index); + + //CRect rect(0, 0, 0, 0); + //double piX, piY; + //CalcScreenRectangle(options, lbl, false, 0, rect, piX, piY); + + + LabelSettings settings; + InitSettings(settings, labels, nullptr); + + // --------------------------------- + // preparing to draw + // --------------------------------- + GdiLabelDrawer gdi; + GdiPlusLabelDrawer gdiPlus; + CRect rect(0, 0, 0, 0); + std::set uniqueValues; + + bool useGdiPlus = GetUseGdiPlus(labels); + if(useGdiPlus) + gdiPlus.InitGraphics(_graphics, labels); + else + gdi.InitDc(_graphics); + + if(useGdiPlus) + { + // we create separate pens/brushes for each drawing method + gdiPlus.InitFromCategory(options, settings.hasRotation); + + // choosing appropriate font + gdiPlus.SelectFont(options, lbl, settings.scaleFactor); + + // measuring label + gdiPlus.MeasureString(lbl, rect); + + gdiPlus.ReleaseForCategory(settings.useVariableFontSize); + } + else + { + // we create separate pens/brushes for each drawing method + gdi.InitFromCategory(options); + + // choosing appropriate font + gdi.SelectFont(options, lbl, settings.scaleFactor); + + // measuring label + gdi.MeasureString(lbl, rect); + + gdi.ReleaseForCategory(settings.useVariableFontSize); + } + + double piX, piY; + if(_spatiallyReferenced) + ProjectionToPixel(lbl->x, lbl->y, piX, piY); + else + { + piX = lbl->x; + piY = lbl->y; + } + + rect.left += static_cast(piX); + rect.right += static_cast(piX); + rect.bottom += static_cast(piY); + rect.top += static_cast(piY); + + return rect; +} + +// ********************************************************************* +// PlaceAllMapLabels() +// ********************************************************************* +vector CLabelDrawer::PlaceAllMapLabels(ILabels* labels) +{ + std:vector indexes; + + if (!CheckVisibility(labels)) + return indexes; + + auto lbs = static_cast(labels); + vector*>* labelData = lbs->get_LabelData(); + + IShapefile* sf = lbs->get_ParentShapefile(); + std::vector* shapeData = nullptr; + if (sf) { + shapeData = ((CShapefile*)sf)->get_ShapeVector(); + } + + // --------------------------------- + // settings, filter and sorting + // --------------------------------- + LabelSettings settings; + InitSettings(settings, labels, sf); + + vector visibilityMask(settings.numLabels, false); + GetVisibilityMask(labels, sf, shapeData, visibilityMask); + + // sort them if sort field is specified + vector* indices = nullptr; + if (sf) { + ((CShapefile*)sf)->GetSorting(&indices); + } + + if (indices && indices->size() != settings.numLabels) { + indices = nullptr; + } + + // --------------------------------- + // preparing to draw + // --------------------------------- + GdiLabelDrawer gdi; + GdiPlusLabelDrawer gdiPlus; + CRect rect(0, 0, 0, 0); + std::set uniqueValues; + + bool useGdiPlus = GetUseGdiPlus(labels); + if (useGdiPlus) { + gdiPlus.InitGraphics(_graphics, labels); + } + else { + gdi.InitDc(_graphics); + } + + + // --------------------------------------------------------------- + // drawing categories - we'll start from the categories + // with the higher priority, therefore reverse order + // --------------------------------------------------------------- + for (int categoryIndex = settings.numCategories - 1; categoryIndex >= -1; categoryIndex--) + { + CLabelOptions* options = GetCategoryOptions(labels, categoryIndex); + if (!options || !options->visible) continue; + + // we create separate pens/brushes for each drawing method + if (useGdiPlus) + gdiPlus.InitFromCategory(options, settings.hasRotation); + else + gdi.InitFromCategory(options); + + if (!settings.useVariableFontSize) + { + if (useGdiPlus) + gdiPlus.SelectFont(options, options->fontSize, settings.scaleFactor); + else + gdi.SelectFont(options, options->fontSize, settings.scaleFactor); + } + + // --------------------------------------------------------------- + // drawing labels within category + // --------------------------------------------------------------- + for (long k = 0; k < settings.numLabels; k++) + { + long i = indices ? (*indices)[k] : k; + + if (!visibilityMask[i]) { + continue; + } + + vector* parts = (*labelData)[i]; + for (int j = 0; j < static_cast(parts->size()); j++) + { + CLabelInfo* lbl = (*parts)[j]; + + if (lbl->x < _extents->left) continue; + if (lbl->x > _extents->right) continue; + if (lbl->y < _extents->bottom) continue; + if (lbl->y > _extents->top) continue; + if (lbl->text.GetLength() <= 0) continue; + + if ((lbl->category == categoryIndex) || (categoryIndex == -1 && (lbl->category < 0 || lbl->category >= settings.numCategories))) {} + else continue; /* Wrong category */ + + // blocking the labels with the text already displayed + if (settings.removeDuplicates) + { + if (uniqueValues.find(lbl->text) != uniqueValues.end()) + continue; + + uniqueValues.insert(lbl->text); + } + + // choosing appropriate font + if (settings.useVariableFontSize) + { + if (useGdiPlus) { + gdiPlus.SelectFont(options, lbl, settings.scaleFactor); + } + else { + gdi.SelectFont(options, lbl, settings.scaleFactor); + } + } + + // measuring label + if (useGdiPlus) { + gdiPlus.MeasureString(lbl, rect); + } + else { + gdi.MeasureString(lbl, rect); + } + + // rotation angle + double angle, angleRad; + LabelDrawingHelper::CalcRotation(lbl, _mapRotation, angle); + angleRad = AngleHelper::ToRad(angle); + + // calculating screen rectangle + double piX, piY; + + // Fix for MWGIS-79: + int shapeSize = 0; + if (sf) + shapeSize = (*shapeData)[i]->size; + CalcScreenRectangle(options, lbl, settings.autoOffset, shapeSize, rect, piX, piY); + + // do we have overlaps? + if (!TryAvoidCollisions(lbl, settings.avoidCollisions, rect, piX, piY, settings.buffer, angleRad)) + continue; + + indexes.push_back(k); + /*lbs->AddDrawnLabel(k); + // actual drawing + if (useGdiPlus) { + gdiPlus.DrawLabel(options, rect, piX, piY, angle); + } + else { + gdi.DrawLabel(options, lbl, rect, angleRad, piX, piY); + } */ + } + } // label + + if (useGdiPlus) { + gdiPlus.ReleaseForCategory(settings.useVariableFontSize); + } + else { + gdi.ReleaseForCategory(settings.useVariableFontSize); + } + } // category + + // restoring rendering options + if (useGdiPlus) { + gdiPlus.RestoreGraphics(); + } + else { + gdi.ReleaseDc(); + } + + return indexes; + /*auto pArray = new int[indexes.size()]; + copy(indexes.begin(), indexes.end(), pArray); + return pArray;*/ +} + + // ********************************************************************* // GetCategoryOptions() // ********************************************************************* diff --git a/src/Drawing/LabelDrawing.h b/src/Drawing/LabelDrawing.h index 28be4999..4463d9fa 100644 --- a/src/Drawing/LabelDrawing.h +++ b/src/Drawing/LabelDrawing.h @@ -67,7 +67,7 @@ class CLabelDrawer: public CBaseDrawer _graphics = graphics; } - ~CLabelDrawer(void){}; + ~CLabelDrawer(void){} private: struct LabelSettings { @@ -82,7 +82,7 @@ class CLabelDrawer: public CBaseDrawer bool useVariableFontSize; }; -private: +private: HDC _hdc; double _currentScale; int _currentZoom; @@ -90,7 +90,7 @@ class CLabelDrawer: public CBaseDrawer CCollisionList* _collisionList; bool _spatiallyReferenced; bool _printing; - + private: void InitSettings(LabelSettings& settings, ILabels* labels, IShapefile* sf); bool HaveCollision(CRotatedRectangle& rect); @@ -108,5 +108,8 @@ class CLabelDrawer: public CBaseDrawer public: void DrawLabels(ILabels* LabelsClass); + int* PlaceLabels(ILabels* LabelsClass); + vector PlaceAllMapLabels(ILabels* labels); + CRect GetLabelExtents(ILabels* labels, long index); }; diff --git a/src/Drawing/LabelOptions.h b/src/Drawing/LabelOptions.h index 4d9bc995..39278b31 100644 --- a/src/Drawing/LabelOptions.h +++ b/src/Drawing/LabelOptions.h @@ -211,6 +211,7 @@ struct CLabelInfo rotatedFrame = NULL; horizontalFrame = NULL; isDrawn = VARIANT_FALSE; + key = SysAllocString(L""); } ~CLabelInfo() { @@ -232,5 +233,6 @@ struct CLabelInfo long category; VARIANT_BOOL isDrawn; short fontSize; + BSTR key; }; From c4eb7e4c862745f2c85b40f516c1fef459d0fe35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 1 Jun 2026 13:58:09 +0200 Subject: [PATCH 19/55] ZoomOut fix. --- src/MapControl/Map_Dynamic.cpp | 4 ++-- src/MapControl/Map_Scale.cpp | 42 +++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/MapControl/Map_Dynamic.cpp b/src/MapControl/Map_Dynamic.cpp index a5358118..06e4a6e7 100644 --- a/src/MapControl/Map_Dynamic.cpp +++ b/src/MapControl/Map_Dynamic.cpp @@ -145,7 +145,7 @@ void CMapView::DrawShapeEditor( Gdiplus::Graphics* g, bool dynamicBuffer ) // **************************************************************** void CMapView::DrawZoombox(Gdiplus::Graphics* g) { - bool zooming = m_cursorMode == cmZoomIn && _dragging.Operation == DragZoombox; + bool zooming = (m_cursorMode == cmZoomIn || m_cursorMode == cmZoomOut ) && _dragging.Operation == DragZoombox; bool selection = m_cursorMode == cmSelection && _dragging.Operation == DragSelectionBox; bool drawZoombox = _leftButtonDown && _dragging.Start != _dragging.Move && (zooming || selection); @@ -153,7 +153,7 @@ void CMapView::DrawZoombox(Gdiplus::Graphics* g) { CRect r = _dragging.GetRectangle(); Gdiplus::Rect rect(r.left, r.top, r.right - r.left, r.bottom - r.top); - + g->SetPixelOffsetMode(Gdiplus::PixelOffsetMode::PixelOffsetModeHighQuality); if (selection) { diff --git a/src/MapControl/Map_Scale.cpp b/src/MapControl/Map_Scale.cpp index 82cb59cc..68f03e4a 100644 --- a/src/MapControl/Map_Scale.cpp +++ b/src/MapControl/Map_Scale.cpp @@ -293,6 +293,32 @@ void CMapView::SetNewExtentsWithForcedZooming(Extent ext, bool zoomIn) SetExtentsCore(Extent(cLeft, cRight, cBottom, cTop)); } +// **************************************************** +// SetNewExtentsWithZoomOut() +// **************************************************** +// Sets new extents by zooming out using given extent (drawn rectangle) +void CMapView::SetNewExtentsWithZoomOut(Extent ext) +{ + auto extent = GetExtents(); + if (extent == NULL) return; + + double width, height; + extent->get_Width(&width); + extent->get_Height(&height); + + auto const pt = ext.GetCenter(); + auto const widthFactor = width / ext.Width(); + auto const heightFactor = height / ext.Height(); + width *= widthFactor; + height *= heightFactor; + + double zMin, zMax; + extent->get_zMin(&zMin); + extent->get_zMax(&zMax); + extent->SetBounds(pt.x - width / 2, pt.y - height / 2, zMin, pt.x + width / 2, pt.y + height / 2, zMax); + SetExtents(extent); +} + // **************************************************** // SetExtentsCore() // **************************************************** @@ -466,7 +492,9 @@ VARIANT_BOOL CMapView::SetGeographicExtents(IExtents* extents) if (_transformationMode == tmNotDefined) { +#if RELEASE_MODE this->ErrorMessage(tkTRANSFORMATIONMODE_NOT_DEFINED); +#endif return VARIANT_FALSE; } @@ -556,6 +584,11 @@ IExtents* CMapView::GetGeographicExtents() // *************************************************************** bool CMapView::GetGeographicExtentsInternal(bool clipForTiles, Extent* clipExtents, Extent& result) { + if (clipExtents != nullptr) + { + ::OutputDebugStringA(clipExtents->ToString()); + ::OutputDebugStringA("\r\n"); + } // we don't want to have coordinates outside world bounds, as it breaks tiles loading IExtents* ext = GetGeographicExtentsCore(clipForTiles, clipExtents); if (!ext) return false; @@ -564,6 +597,8 @@ bool CMapView::GetGeographicExtentsInternal(bool clipForTiles, Extent* clipExten ext->Release(); result = bounds; + ::OutputDebugStringA(result.ToString()); + ::OutputDebugStringA("\r\n"); return true; } @@ -855,7 +890,8 @@ void CMapView::ZoomToMaxVisibleExtents(void) { const double xrange = l->extents.right - l->extents.left; const double yrange = l->extents.top - l->extents.bottom; - if (xrange == 0 && yrange == 0 && l->extents.right == 0 && l->extents.top == 0) + if ((xrange == 0 && yrange == 0 && l->extents.right == 0 && l->extents.top == 0) || + std::isinf(xrange) || std::isinf(yrange) || std::isinf(l->extents.right) || std::isinf(l->extents.top)) continue; if (extentsSet == false) @@ -972,6 +1008,10 @@ void CMapView::CalculateVisibleExtents(Extent e, bool MapSizeChanged) double bottom = MIN(e.bottom, e.top); double top = MAX(e.bottom, e.top); + CString sOutput; + sOutput.AppendFormat("CalculateVisibleExtents() left: %.2f, right: %.2f, bottom: %.2f, top: : %.2f\r\n", left, right, bottom, top); + ::OutputDebugStringA(sOutput.GetBuffer()); + if (left == right) // lsu 26 jul 2009 for zooming to single point { left -= 0.5; From 4de01e84221a28369be102e7fb005f8ab469f8d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 13:29:14 +0200 Subject: [PATCH 20/55] Fixed using OpenStreetMapProvider (casting to WmsCustomProvider* was invalid). --- src/Tiles/TileManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tiles/TileManager.cpp b/src/Tiles/TileManager.cpp index 133572bc..31349e67 100644 --- a/src/Tiles/TileManager.cpp +++ b/src/Tiles/TileManager.cpp @@ -353,7 +353,7 @@ void TileManager::ClearBuffer() bool TileManager::IsNewRequest(Extent& mapExtents, CRect indices, int providerId, int zoom) { auto layersSelectionChanged = false; - auto customProvider = reinterpret_cast(_provider); + auto customProvider = dynamic_cast(_provider); if (customProvider != nullptr) { auto layers = customProvider->get_Layers(); layersSelectionChanged = _lastLayers != layers; From 69e0d1d46491913935e1bc99d696c9c43c47d4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 13:30:31 +0200 Subject: [PATCH 21/55] Made StopEditingShapes() also set IsEditingShapes to false for _sourceType == sstInMemory --- src/COM classes/Shapefile_Edit.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/COM classes/Shapefile_Edit.cpp b/src/COM classes/Shapefile_Edit.cpp index 6565524f..e0fe8bd6 100644 --- a/src/COM classes/Shapefile_Edit.cpp +++ b/src/COM classes/Shapefile_Edit.cpp @@ -180,6 +180,8 @@ STDMETHODIMP CShapefile::StopEditingShapes(VARIANT_BOOL applyChanges, VARIANT_BO } } } + else + _isEditingShapes = VARIANT_FALSE; *retval = VARIANT_TRUE; return S_OK; } From d48a6ecedbfd8c56cd5f30133723b087d2dba1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 13:32:51 +0200 Subject: [PATCH 22/55] Fixed dbf (DBFCreate_MW and DBFOpen_MW) to use correct utf-8 path. --- src/Shapefile/dbf.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Shapefile/dbf.cpp b/src/Shapefile/dbf.cpp index 6764eccb..4570f9e3 100644 --- a/src/Shapefile/dbf.cpp +++ b/src/Shapefile/dbf.cpp @@ -12,19 +12,41 @@ DBFHandle SHPAPI_CALL DBFOpen_MW( CStringW pszFilename, const char * pszAccess ) { - CStringA nameA = Utility::ConvertToAnsi1252(pszFilename); + CStringA nameA = Utility::ConvertToUtf8(pszFilename); + + // Save current locale, then switch CRT to UTF-8 so fopen() inside DBFOpen + // interprets the path bytes as UTF-8 instead of the system ANSI code page. + // Requires Windows 10 1803 or later. + CStringA prevLocale = setlocale(LC_ALL, nullptr); + setlocale(LC_ALL, ".UTF8"); + m_globalSettings.SetGdalUtf8(true); DBFHandle handle = DBFOpen(nameA, pszAccess); m_globalSettings.SetGdalUtf8(false); + + // Restore previous locale + setlocale(LC_ALL, prevLocale); + return handle; } DBFHandle SHPAPI_CALL DBFCreate_MW( CStringW nameW ) { - CStringA nameA = Utility::ConvertToAnsi1252(nameW); + CStringA nameA = Utility::ConvertToUtf8(nameW); + + // Save current locale, then switch CRT to UTF-8 so fopen() inside DBFCreate + // interprets the path bytes as UTF-8 instead of the system ANSI code page. + // Requires Windows 10 1803 or later. + CStringA prevLocale = setlocale(LC_ALL, nullptr); + setlocale(LC_ALL, ".UTF8"); + m_globalSettings.SetGdalUtf8(true); DBFHandle handle = DBFCreate(nameA); m_globalSettings.SetGdalUtf8(false); + + // Restore previous locale + setlocale(LC_ALL, prevLocale); + return handle; } From 240df4fc2ef93372cee2132cb70563da745ca2c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 13:40:04 +0200 Subject: [PATCH 23/55] Updated to match updating GDAL to 3.10 and proj7 to proj9. --- .../MapWinGisTests/UnitTests/GlobalSettingsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MapWinGisTests-net6/MapWinGisTests/UnitTests/GlobalSettingsTests.cs b/MapWinGisTests-net6/MapWinGisTests/UnitTests/GlobalSettingsTests.cs index 769528a8..4eac0a5d 100644 --- a/MapWinGisTests-net6/MapWinGisTests/UnitTests/GlobalSettingsTests.cs +++ b/MapWinGisTests-net6/MapWinGisTests/UnitTests/GlobalSettingsTests.cs @@ -60,7 +60,7 @@ public void GlobalSettingsProjPathTest() var projPath = _gs.ProjPath; _testOutputHelper.WriteLine("projPath: " + projPath); projPath.ShouldNotBeNullOrEmpty("ProjPath is not set"); - projPath.EndsWith("\\proj7\\share\\").ShouldBeTrue(); + projPath.EndsWith("\\proj9\\share\\").ShouldBeTrue(); // Change: var newpath = Path.Combine(Path.GetTempPath(), "new-proj-Воздух"); _testOutputHelper.WriteLine(newpath); @@ -79,7 +79,7 @@ public void GlobalSettingsGdalVersionTest() var gdalVersion = _gs.GdalVersion; _testOutputHelper.WriteLine(gdalVersion); gdalVersion.ShouldNotBeNullOrEmpty("GdalVersion is not set"); - gdalVersion.StartsWith("GDAL 3.5").ShouldBeTrue(); + gdalVersion.StartsWith("GDAL 3.10").ShouldBeTrue(); // Change: // GdalVersion is read-only } From 3060f99b8d68d1d3ec9670df59e8b6c5b5df99f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 13:41:08 +0200 Subject: [PATCH 24/55] Updated for version update to 5.5 and fixed showing MapControl before using it. --- MapWinGisTests-net6/MapWinGisTests/AxMapTests.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MapWinGisTests-net6/MapWinGisTests/AxMapTests.cs b/MapWinGisTests-net6/MapWinGisTests/AxMapTests.cs index 1115a860..be5c9f56 100644 --- a/MapWinGisTests-net6/MapWinGisTests/AxMapTests.cs +++ b/MapWinGisTests-net6/MapWinGisTests/AxMapTests.cs @@ -19,7 +19,7 @@ public void VersionTest() var version = form.GetMapWinGisVersion(); version.ShouldNotBeNull(); version.Major.ShouldBe(5); - version.Minor.ShouldBe(4); + version.Minor.ShouldBe(5); version.Build.ShouldBeGreaterThanOrEqualTo(0); _testOutputHelper.WriteLine("Version: {0}", version); } @@ -28,6 +28,7 @@ public void VersionTest() public void MapProjectionTest() { using var form = new WinFormsApp1.Form1(); + form.Show(); // We need to show the form to have a valid map control form.ShouldNotBeNull(); var sfLocation = Helpers.GetTestFilePath("UnitedStates-3857.shp"); @@ -69,7 +70,8 @@ public void ShapefileKeyTest() // AS mentioned at https://mapwindow.discourse.group/t/key-property-of-shape-object-not-work/1250 using var form = new WinFormsApp1.Form1(); - form.ShouldNotBeNull(); + form.Show(); // We need to show the form to have a valid map control + form.ShouldNotBeNull(); // Create shapefile: var sfPolygon = Helpers.CreateTestPolygonShapefile(); From 696b74909c1507bf56437e59c528a38b93bd0467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 13:43:46 +0200 Subject: [PATCH 25/55] Moved calling LoadOsm() until after Shown, because Mapcontrol is not valid/usable before that. --- MapWinGisTests-net6/WinFormsApp1/Form1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapWinGisTests-net6/WinFormsApp1/Form1.cs b/MapWinGisTests-net6/WinFormsApp1/Form1.cs index 1f966e25..2f08d222 100644 --- a/MapWinGisTests-net6/WinFormsApp1/Form1.cs +++ b/MapWinGisTests-net6/WinFormsApp1/Form1.cs @@ -14,7 +14,7 @@ public Form1() CallbackVerbosity = tkCallbackVerbosity.cvAll }; - LoadOsm(); + this.Shown += (s, e) => LoadOsm(); // This need to be done after the form is shown. GetMapWinGisVersion(); } From 88114438305e359ca0bd8a929d68893fe29ba974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 13:45:42 +0200 Subject: [PATCH 26/55] Added unpackGdal3 poweshell for toolset v143. now only x64 supported. --- .../unpackGdal3-Toolset143-GISInternals.ps1 | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 support/unpackGdal3-Toolset143-GISInternals.ps1 diff --git a/support/unpackGdal3-Toolset143-GISInternals.ps1 b/support/unpackGdal3-Toolset143-GISInternals.ps1 new file mode 100644 index 00000000..bdb27fe9 --- /dev/null +++ b/support/unpackGdal3-Toolset143-GISInternals.ps1 @@ -0,0 +1,113 @@ +Set-Location $PSScriptRoot + +################################################################### +# +# Powershell script to unpack the GDAL zips downloaded from +# https://www.gisinternals.com/release.php +# These files need to be manually downloaded first and saved in +# the support folder, the same folder this script is in. +# +# This script expects GDAL3+ binaries and copies the content to the v142 subfolder +# +# The script expects 4 zip files. 2 for Win32 and 2 for x64 +# If you only need 1 set of 2 zip files you can comment the call +# to UnpackGisInternalsZips at the bottom of this script +# +################################################################### + +Function UnpackGisInternalsZips{ + Param ([boolean]$Is64Bit, [string]$ToolsetVersion) + + # The names and filters for the Win32 zip files: + $regExZipfileNames = "release-1928-gdal-3*.zip" + $regExZipfileLibName = "release-1928-gdal-3*-libs.zip" + $subFolderName = "win32" + + if($Is64Bit) { + # The names and filters for the x64 zip files: + $regExZipfileNames = "release-1930-x64-gdal-3*.zip" + $regExZipfileLibName = "release-1930-x64-gdal-3*-libs.zip" + $subFolderName = "x64" + } + + Write-Host "Checking files (x64: $($Is64Bit))..." + $zipCount = (Get-ChildItem -Filter $regExZipfileNames).count + if ($zipCount -lt 2) { + Write-Host "Missing GIS internals zip files (x64: $($Is64Bit))." + Write-Host "Two zip files are required: compiled binaries and compiled libs and headers." + Pause + Exit + } + if ($zipCount -gt 2) { + Write-Host "Too many zip files (x64: $($Is64Bit))." + Write-Host "Two zip files are required: compiled binaries and compiled libs and headers." + Pause + Exit + } + + $zipLibsCount = (Get-ChildItem -Filter $regExZipfileLibName).count + if ($zipLibsCount -ne 1) { + Write-Host "Missing the GIS internals compiled libs and headers zip file (x64: $($Is64Bit))." + Write-Host "Two zip files are required: compiled binaries and compiled libs and headers." + Pause + Exit + } + + Write-Host "Clearing temp folder..." + CreateDirIfNeeded("temp") + Get-ChildItem temp\* -Force | Remove-Item -force -recurse + + Write-Host "Unzipping..." + Get-ChildItem -Filter $regExZipfileNames | Expand-Archive -DestinationPath temp\ + + # Move the files to the correct GDAL_SDK subfolders: + MoveFiles .\temp\bin\* .\GDAL_SDK\$($ToolsetVersion)\bin\$($subFolderName)\ + MoveFiles .\temp\include\* .\GDAL_SDK\$($ToolsetVersion)\include\$($subFolderName)\ + MoveFiles .\temp\lib\* .\GDAL_SDK\$($ToolsetVersion)\lib\$($subFolderName)\ + + Write-Host "Successfully copied the GisInternals files (x64: $($Is64Bit)) to subfolder $($ToolsetVersion)" +} + +Function CreateDirIfNeeded{ + Param ([string]$FolderName) + + if(![System.IO.Directory]::Exists($FolderName)) + { + Write-Host "Folder Doesn't Exists" + + #PowerShell Create directory: + New-Item $FolderName -ItemType Directory + } +} + +Function MoveFiles{ + Param ([string]$Path, [string]$Destination) + + # Extra check, folder should exist: + CreateDirIfNeeded($Destination) + + Write-Host "Removing previous files..." + Get-ChildItem $Destination -Force -Exclude !!!*.txt | Remove-Item -force -recurse + + Write-Host "Moving files..." + Move-Item -Path $Path -Destination $Destination +} + + + +################################################################### +################################################################### +# Entry point +################################################################### +################################################################### + +Write-Host "Current directory: $(Get-Location)" +Write-Host "Script directory: $PSScriptRoot" + +# Unzip the 2 Win32 zip files: +#UnpackGisInternalsZips -Is64Bit $False -ToolsetVersion "v143" + +# Unzip the 2 x64 zip files: +UnpackGisInternalsZips -Is64Bit $True -ToolsetVersion "v143" + +Write-Host "MapWinGIS.sln can now be built." \ No newline at end of file From 667892abb8294c976753737cc8381f48ae93e01c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 14:51:29 +0200 Subject: [PATCH 27/55] Cleanup, removed 32bit stuff. --- .../unpackGdal3-Toolset143-GISInternals.ps1 | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/support/unpackGdal3-Toolset143-GISInternals.ps1 b/support/unpackGdal3-Toolset143-GISInternals.ps1 index bdb27fe9..7436df17 100644 --- a/support/unpackGdal3-Toolset143-GISInternals.ps1 +++ b/support/unpackGdal3-Toolset143-GISInternals.ps1 @@ -9,8 +9,7 @@ Set-Location $PSScriptRoot # # This script expects GDAL3+ binaries and copies the content to the v142 subfolder # -# The script expects 4 zip files. 2 for Win32 and 2 for x64 -# If you only need 1 set of 2 zip files you can comment the call +# The script expects 2 zip files for x64 # to UnpackGisInternalsZips at the bottom of this script # ################################################################### @@ -18,18 +17,16 @@ Set-Location $PSScriptRoot Function UnpackGisInternalsZips{ Param ([boolean]$Is64Bit, [string]$ToolsetVersion) - # The names and filters for the Win32 zip files: - $regExZipfileNames = "release-1928-gdal-3*.zip" - $regExZipfileLibName = "release-1928-gdal-3*-libs.zip" - $subFolderName = "win32" - - if($Is64Bit) { - # The names and filters for the x64 zip files: - $regExZipfileNames = "release-1930-x64-gdal-3*.zip" - $regExZipfileLibName = "release-1930-x64-gdal-3*-libs.zip" - $subFolderName = "x64" + if(!$Is64Bit) { + Write-Host "Only 64-bit is supported." + Exit } + # The names and filters for the x64 zip files: + $regExZipfileNames = "release-1930-x64-gdal-3*.zip" + $regExZipfileLibName = "release-1930-x64-gdal-3*-libs.zip" + $subFolderName = "x64" + Write-Host "Checking files (x64: $($Is64Bit))..." $zipCount = (Get-ChildItem -Filter $regExZipfileNames).count if ($zipCount -lt 2) { @@ -65,7 +62,7 @@ Function UnpackGisInternalsZips{ MoveFiles .\temp\include\* .\GDAL_SDK\$($ToolsetVersion)\include\$($subFolderName)\ MoveFiles .\temp\lib\* .\GDAL_SDK\$($ToolsetVersion)\lib\$($subFolderName)\ - Write-Host "Successfully copied the GisInternals files (x64: $($Is64Bit)) to subfolder $($ToolsetVersion)" + Write-Host "Successfully copied the GisInternals files (x64: $($Is64Bit)) to subfolder $($ToolsetVersion)" } Function CreateDirIfNeeded{ @@ -104,9 +101,6 @@ Function MoveFiles{ Write-Host "Current directory: $(Get-Location)" Write-Host "Script directory: $PSScriptRoot" -# Unzip the 2 Win32 zip files: -#UnpackGisInternalsZips -Is64Bit $False -ToolsetVersion "v143" - # Unzip the 2 x64 zip files: UnpackGisInternalsZips -Is64Bit $True -ToolsetVersion "v143" From fa8ee4e10d108a573b917f50f7f8b46e9e6259d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 14:54:02 +0200 Subject: [PATCH 28/55] Configuration for debugging test from MapWinGisTests. --- src/MapWinGIS.sln | 2 +- src/MapWinGIS.vcxproj.user | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/MapWinGIS.sln b/src/MapWinGIS.sln index 998b80ca..9ce5b364 100644 --- a/src/MapWinGIS.sln +++ b/src/MapWinGIS.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 -VisualStudioVersion = 17.14.36203.30 d17.14 +VisualStudioVersion = 17.14.36203.30 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MapWinGIS", "MapWinGIS.vcxproj", "{1AB93398-2DE6-4043-BF6D-D438A794FB86}" EndProject diff --git a/src/MapWinGIS.vcxproj.user b/src/MapWinGIS.vcxproj.user index 5b64e465..fdce78cb 100644 --- a/src/MapWinGIS.vcxproj.user +++ b/src/MapWinGIS.vcxproj.user @@ -10,9 +10,11 @@ WindowsLocalDebugger - C:\Projects\Intrasis_WinGIS\Intrasis\Applications\IntrasisApp\bin\x64\Debug\net10.0-windows8.0\Intrasis.exe + "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\dotnet\net8.0\runtime\dotnet.exe" WindowsLocalDebugger - C:\Intrasis\Database\U20043\U20043.ipf sys hemlig - NativeOnly + test MapWinGisTests.csproj --no-build --configuration Release -p:Platform=x64 + NativeWithManagedCore + C:\Projects\Lib\Sweco_MapWinGIS\MapWinGisTests-net6\MapWinGisTests + false \ No newline at end of file From 4bbffcd5e4e6a89f1252a7da1a0221a1aa6d3709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 14:58:29 +0200 Subject: [PATCH 29/55] Updated to MapWinGIS version 5.5 and updated to .NET 8 --- .../MapWinGisTests-net6.sln.DotSettings | 1 + .../MapWinGisTests/MapWinGisTests.csproj | 27 ++++++++----------- .../WinFormsApp1/WinFormsApp1.csproj | 9 ++++--- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/MapWinGisTests-net6/MapWinGisTests-net6.sln.DotSettings b/MapWinGisTests-net6/MapWinGisTests-net6.sln.DotSettings index 2d72aa38..69675e4b 100644 --- a/MapWinGisTests-net6/MapWinGisTests-net6.sln.DotSettings +++ b/MapWinGisTests-net6/MapWinGisTests-net6.sln.DotSettings @@ -1,2 +1,3 @@  + True True \ No newline at end of file diff --git a/MapWinGisTests-net6/MapWinGisTests/MapWinGisTests.csproj b/MapWinGisTests-net6/MapWinGisTests/MapWinGisTests.csproj index 41d8d926..dd0c4d8d 100644 --- a/MapWinGisTests-net6/MapWinGisTests/MapWinGisTests.csproj +++ b/MapWinGisTests-net6/MapWinGisTests/MapWinGisTests.csproj @@ -1,4 +1,4 @@ - + net8.0-windows8.0 @@ -14,24 +14,19 @@ enable + true - - - - - - - - tlbimp - 4 - 5 - c368d713-cc5f-40ed-9f53-f84fe197b96a - 0 - false - False - + + tlbimp + 5 + 5 + c368d713-cc5f-40ed-9f53-f84fe197b96a + 0 + false + False + diff --git a/MapWinGisTests-net6/WinFormsApp1/WinFormsApp1.csproj b/MapWinGisTests-net6/WinFormsApp1/WinFormsApp1.csproj index 2a2b121b..327bc62c 100644 --- a/MapWinGisTests-net6/WinFormsApp1/WinFormsApp1.csproj +++ b/MapWinGisTests-net6/WinFormsApp1/WinFormsApp1.csproj @@ -2,25 +2,26 @@ WinExe - net6.0-windows + net8.0-windows8.0 enable true enable x86;x64 + 8.0 {C368D713-CC5F-40ED-9F53-F84FE197B96A} 5 - 4 + 5 0 aximp False tlbimp - 4 + 5 5 c368d713-cc5f-40ed-9f53-f84fe197b96a 0 @@ -45,7 +46,7 @@ - + \ No newline at end of file From 3bd9cdcb2b04badea221a19aaffb5edc1ab30ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 15:19:09 +0200 Subject: [PATCH 30/55] Updated build to reference registred MapWinGIS. --- .../MapWinGisTests/MapWinGisTests.csproj | 18 +++++++++--------- .../UnitTests/CodeCoverageTests.cs | 12 ++++++------ .../MapWinGisTests/UnitTests/ShapeTests.cs | 2 +- .../WinFormsApp1/WinFormsApp1.csproj | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/MapWinGisTests-net6/MapWinGisTests/MapWinGisTests.csproj b/MapWinGisTests-net6/MapWinGisTests/MapWinGisTests.csproj index dd0c4d8d..bcb41e3f 100644 --- a/MapWinGisTests-net6/MapWinGisTests/MapWinGisTests.csproj +++ b/MapWinGisTests-net6/MapWinGisTests/MapWinGisTests.csproj @@ -18,15 +18,15 @@ - - tlbimp - 5 - 5 - c368d713-cc5f-40ed-9f53-f84fe197b96a - 0 - false - False - + + tlbimp + 5 + 5 + c368d713-cc5f-40ed-9f53-f84fe197b96a + 0 + false + true + diff --git a/MapWinGisTests-net6/MapWinGisTests/UnitTests/CodeCoverageTests.cs b/MapWinGisTests-net6/MapWinGisTests/UnitTests/CodeCoverageTests.cs index 1d84996c..0deb0b9d 100644 --- a/MapWinGisTests-net6/MapWinGisTests/UnitTests/CodeCoverageTests.cs +++ b/MapWinGisTests-net6/MapWinGisTests/UnitTests/CodeCoverageTests.cs @@ -12,28 +12,28 @@ public CodeCoverageTests(ITestOutputHelper testOutputHelper) _testOutputHelper = testOutputHelper; } - //[Fact(Skip = "Unit test is not yet implemented")] - public void CheckShapefileClass() + [Fact] + public void CheckShapefileClass() { - CheckTests(typeof(ShapefileClass), "Shapefile"); + CheckTests(typeof(Shapefile), "Shapefile"); } [Fact] public void CheckShapeClass() { - CheckTests(typeof(ShapeClass), "Shape"); + CheckTests(typeof(Shape), "Shape"); } [Fact] public void CheckGlobalSettingsClass() { - CheckTests(typeof(GlobalSettingsClass), "GlobalSettings"); + CheckTests(typeof(GlobalSettings), "GlobalSettings"); } [Fact] public void CheckGdalUtilsClass() { - CheckTests(typeof(GdalUtilsClass), "GdalUtils"); + CheckTests(typeof(GdalUtils), "GdalUtils"); } private void CheckTests(Type myType, string className, bool scaffoldUnitTests = false) diff --git a/MapWinGisTests-net6/MapWinGisTests/UnitTests/ShapeTests.cs b/MapWinGisTests-net6/MapWinGisTests/UnitTests/ShapeTests.cs index 70712426..1bd42cc2 100644 --- a/MapWinGisTests-net6/MapWinGisTests/UnitTests/ShapeTests.cs +++ b/MapWinGisTests-net6/MapWinGisTests/UnitTests/ShapeTests.cs @@ -320,7 +320,7 @@ public void ShapeIsEmptyTest() [Fact] public void ShapePut_ZTest() { - Shape shape = new ShapeClass(); + Shape shape = new Shape(); shape.ShapeType = ShpfileType.SHP_POINTZ; shape.AddPoint(100, 100); diff --git a/MapWinGisTests-net6/WinFormsApp1/WinFormsApp1.csproj b/MapWinGisTests-net6/WinFormsApp1/WinFormsApp1.csproj index 327bc62c..45a60b67 100644 --- a/MapWinGisTests-net6/WinFormsApp1/WinFormsApp1.csproj +++ b/MapWinGisTests-net6/WinFormsApp1/WinFormsApp1.csproj @@ -26,7 +26,7 @@ c368d713-cc5f-40ed-9f53-f84fe197b96a 0 false - False + True From ff70380d8f000df8375582e1d841381ae8dc0541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 15:38:08 +0200 Subject: [PATCH 31/55] Updated build script --- .github/workflows/msbuild.yml | 51 +++++++++++++++-------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index ce7baeea..f75d479b 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -24,12 +24,11 @@ env: jobs: build: name: Build MapWinGIS - runs-on: windows-2019 + runs-on: windows-2022 strategy: matrix: - platform: ['Win32', 'x64'] - # platform: ['Win32'] + platform: ['x64'] steps: - uses: actions/checkout@v3 @@ -96,10 +95,8 @@ jobs: with: # Specify the Az PowerShell script here. inlineScript: | - Invoke-WebRequest -Uri "https://github.com/MapWindow/Dependencies/raw/main/GisInternals/release-1928-gdal-3-5-mapserver-8-0.zip" -MaximumRetryCount 3 -Resume -RetryIntervalSec 30 -OutFile ".\Support\release-1928-gdal-3-5-mapserver-8-0.zip" - Invoke-WebRequest -Uri "https://github.com/MapWindow/Dependencies/raw/main/GisInternals/release-1928-gdal-3-5-mapserver-8-0-libs.zip" -MaximumRetryCount 3 -Resume -RetryIntervalSec 30 -OutFile ".\Support\release-1928-gdal-3-5-mapserver-8-0-libs.zip" - Invoke-WebRequest -Uri "https://github.com/MapWindow/Dependencies/raw/main/GisInternals/release-1928-x64-gdal-3-5-mapserver-8-0.zip" -MaximumRetryCount 3 -Resume -RetryIntervalSec 30 -OutFile ".\Support\release-1928-x64-gdal-3-5-mapserver-8-0.zip" - Invoke-WebRequest -Uri "https://github.com/MapWindow/Dependencies/raw/main/GisInternals/release-1928-x64-gdal-3-5-mapserver-8-0-libs.zip" -MaximumRetryCount 3 -Resume -RetryIntervalSec 30 -OutFile ".\Support\release-1928-x64-gdal-3-5-mapserver-8-0-libs.zip" + Invoke-WebRequest -Uri "https://github.com/sweco-sedahd/Dependencies/blob/main/GisInternals/release-1930-x64-gdal-3-10-3-mapserver-8-2-2.zip" -MaximumRetryCount 3 -Resume -RetryIntervalSec 30 -OutFile ".\Support\release-1930-x64-gdal-3-10-3-mapserver-8-2-2.zip" + Invoke-WebRequest -Uri "https://github.com/sweco-sedahd/Dependencies/blob/main/GisInternals/release-1930-x64-gdal-3-10-3-mapserver-8-2-2-libs.zip" -MaximumRetryCount 3 -Resume -RetryIntervalSec 30 -OutFile ".\Support\release-1930-x64-gdal-3-10-3-mapserver-8-2-2-libs.zip" ls .\Support\ # Azure PS version to be used to execute the script, example: 1.8.0, 2.8.0, 3.4.0. To use the latest version, specify "latest". azPSVersion: "latest" @@ -107,13 +104,13 @@ jobs: errorActionPreference: Stop # If this is true, this task will fail if any errors are written to the error pipeline, or if any data is written to the Standard Error stream. failOnStandardError: true - + # Unzip zips by calling powershell script - name: Unzip working-directory: ./Support/ shell: pwsh - run: .\unpackGdal3-Toolset142-GISInternals.ps1 - + run: .\unpackGdal3-Toolset143-GISInternals.ps1 + # Build support libs - name: Build SupportLibs ${{matrix.platform}} working-directory: ${{env.GITHUB_WORKSPACE}} @@ -121,7 +118,7 @@ jobs: # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference # MSBuild SupportLibs.sln /t:Rebuild /p:Configuration=Release /p:Platform="Win32" run: msbuild /m /p:Configuration=Release /p:Platform=${{matrix.platform}} ${{env.SUPPORTLIBS_SOLUTION_FILE_PATH}} - + # Build MapWinGIS - name: Build MapWinGIS ${{matrix.platform}} working-directory: ${{env.GITHUB_WORKSPACE}} @@ -145,21 +142,15 @@ jobs: strategy: max-parallel: 1 matrix: - platform: ['x64', 'Win32'] - # platform: ['Win32'] - + platform: ['x64'] + steps: - uses: actions/checkout@v3 - - - name: Setup dotnet 6 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '6.x' - - name: Setup dotnet 7 + - name: Setup dotnet 8 uses: actions/setup-dotnet@v1 with: - dotnet-version: '6.x' + dotnet-version: '8.x' - name: Download MapWinGIS (${{matrix.platform}}) binaries uses: actions/download-artifact@v2 @@ -179,9 +170,9 @@ jobs: 3 = "FAIL_LOAD - LoadLibrary Failed"; 4 = "FAIL_ENTRY - GetProcAddress failed"; 5 = "FAIL_REG - DllRegisterServer or DllUnregisterServer failed."; - } - $regsvrp = Start-Process C:\Windows\SysWOW64\regsvr32.exe -ArgumentList "/s ${{ github.workspace }}\src\bin\${{env.BUILD_CONFIGURATION}}\${{matrix.platform}}\MapWinGIS.ocx" -PassThru - + } + $regsvrp = Start-Process C:\Windows\System32\regsvr32.exe -ArgumentList "/s ${{ github.workspace }}\src\bin\${{env.BUILD_CONFIGURATION}}\${{matrix.platform}}\MapWinGIS.ocx" -PassThru + $regsvrp.WaitForExit(5000) # Wait (up to) 5 seconds if($regsvrp.ExitCode -ne 0) { @@ -197,32 +188,32 @@ jobs: # Build test solution - name: setup-msbuild - uses: microsoft/setup-msbuild@v1.1 + uses: microsoft/setup-msbuild@v1.1 if: ${{matrix.platform == 'x64' }} with: msbuild-architecture: x64 - name: setup-msbuild - uses: microsoft/setup-msbuild@v1.1 + uses: microsoft/setup-msbuild@v1.1 if: ${{matrix.platform == 'Win32' }} with: msbuild-architecture: x86 - + - name: Build test solution ${{matrix.platform}} working-directory: ${{env.GITHUB_WORKSPACE}} # Add additional options to the MSBuild command line here (like platform or verbosity level). # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference # MSBuild SupportLibs.sln /t:Rebuild /p:Configuration=Release /p:Platform="Win32" - run: msbuild /m:2 /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:Platform=${{matrix.platform}} -restore /v:m ${{env.UNITTESTS_SOLUTION_FILE_PATH}} + run: msbuild /m:2 /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:Platform=${{matrix.platform}} -restore /v:m ${{env.UNITTESTS_SOLUTION_FILE_PATH}} # Run unit tests - name: Setup VSTest.console.exe uses: darenm/Setup-VSTest@v1 - name: Unit Testing x86 if: ${{matrix.platform == 'Win32' }} - run: vstest.console.exe /Blame /Diag:logs\log.txt /Platform:x86 -e:PROJ_LIB="${{ github.workspace }}\src\bin\${{env.BUILD_CONFIGURATION}}\Win32\proj7\share\" .\MapWinGisTests-net6\MapWinGisTests\bin\x86\${{env.BUILD_CONFIGURATION}}\net6.0-windows8.0\MapWinGisTests.dll + run: vstest.console.exe /Blame /Diag:logs\log.txt /Platform:x86 -e:PROJ_LIB="${{ github.workspace }}\src\bin\${{env.BUILD_CONFIGURATION}}\Win32\proj9\share\" .\MapWinGisTests-net6\MapWinGisTests\bin\x86\${{env.BUILD_CONFIGURATION}}\net8.0-windows8.0\MapWinGisTests.dll - name: Unit Testing x64 if: ${{matrix.platform == 'x64' }} - run: vstest.console.exe /Blame /Diag:logs\log.txt /Platform:x64 -e:PROJ_LIB="${{ github.workspace }}\src\bin\${{env.BUILD_CONFIGURATION}}\x64\proj7\share\" .\MapWinGisTests-net6\MapWinGisTests\bin\x64\${{env.BUILD_CONFIGURATION}}\net6.0-windows8.0\MapWinGisTests.dll + run: vstest.console.exe /Blame /Diag:logs\log.txt /Platform:x64 -e:PROJ_LIB="${{ github.workspace }}\src\bin\${{env.BUILD_CONFIGURATION}}\x64\proj9\share\" .\MapWinGisTests-net6\MapWinGisTests\bin\x64\${{env.BUILD_CONFIGURATION}}\net8.0-windows8.0\MapWinGisTests.dll # TODO: Create installer using innosetup # TODO: Publish installer to GitHub Releases From 3fc565620902cdd9e13f2c5444eb6fae10034f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 15:41:52 +0200 Subject: [PATCH 32/55] Updated actions/download-artifact --- .github/workflows/msbuild.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index f75d479b..0ade4a5b 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -129,11 +129,11 @@ jobs: # Save artifacts: - name: Archive production artifacts - uses: actions/upload-artifact@v3.1.1 + uses: actions/upload-artifact@v4 with: name: binaries-${{matrix.platform}} path: .\src\bin\${{env.BUILD_CONFIGURATION}}\${{matrix.platform}}\**\* - + unit-tests: name: Unit Testing needs: build @@ -153,7 +153,7 @@ jobs: dotnet-version: '8.x' - name: Download MapWinGIS (${{matrix.platform}}) binaries - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: name: binaries-${{matrix.platform}} path: .\src\bin\${{env.BUILD_CONFIGURATION}}\${{matrix.platform}}\ From 8774ebf624cf1f7a9c91499e37f13829fa22de4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 15:47:11 +0200 Subject: [PATCH 33/55] Updated versions in build script. --- .github/workflows/msbuild.yml | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index 0ade4a5b..87c61e1b 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -31,18 +31,18 @@ jobs: platform: ['x64'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true # Setup MSBuild - name: setup-msbuild - uses: microsoft/setup-msbuild@v1.1 + uses: microsoft/setup-msbuild@v2 if: ${{matrix.platform == 'x64' }} with: msbuild-architecture: x64 - name: setup-msbuild - uses: microsoft/setup-msbuild@v1.1 + uses: microsoft/setup-msbuild@v2 if: ${{matrix.platform == 'Win32' }} with: msbuild-architecture: x86 @@ -63,11 +63,9 @@ jobs: echo ("VCPKG_INSTALLED_DIR=${{ github.workspace }}/src/vcpkg_installed/x64-windows/") >> $env:GITHUB_ENV mkdir $[env.VCPKG_INSTALLED_DIR] - # Install VCPCK + # Install VCPKG - name: run-vcpkg - # You may pin to the exact commit or the version. - # uses: lukka/run-vcpkg@c5ce6a7de6e5ce834a25f7d55b6c250a275a6732 - uses: lukka/run-vcpkg@v10 + uses: lukka/run-vcpkg@v11 with: runVcpkgInstall: true vcpkgDirectory: ${{ github.workspace }}\src\vcpkg\ @@ -145,10 +143,10 @@ jobs: platform: ['x64'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup dotnet 8 - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: '8.x' @@ -188,12 +186,12 @@ jobs: # Build test solution - name: setup-msbuild - uses: microsoft/setup-msbuild@v1.1 + uses: microsoft/setup-msbuild@v2 if: ${{matrix.platform == 'x64' }} with: msbuild-architecture: x64 - name: setup-msbuild - uses: microsoft/setup-msbuild@v1.1 + uses: microsoft/setup-msbuild@v2 if: ${{matrix.platform == 'Win32' }} with: msbuild-architecture: x86 From a6615d13489928f5cafb3fcd8db3372ec0d6e7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 15:52:19 +0200 Subject: [PATCH 34/55] Buildfix: disable GHA binary caching by overriding the environment variable: --- .github/workflows/msbuild.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index 87c61e1b..30d32a1d 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -66,6 +66,8 @@ jobs: # Install VCPKG - name: run-vcpkg uses: lukka/run-vcpkg@v11 + env: + VCPKG_BINARY_SOURCES: clear with: runVcpkgInstall: true vcpkgDirectory: ${{ github.workspace }}\src\vcpkg\ From dd5e5b4889c60551b21726010d996a4df5c439c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 16:08:14 +0200 Subject: [PATCH 35/55] Update vcpkg submodule to 2024.12.16 --- src/vcpkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vcpkg b/src/vcpkg index 5cf60186..b322364f 160000 --- a/src/vcpkg +++ b/src/vcpkg @@ -1 +1 @@ -Subproject commit 5cf60186a241e84e8232641ee973395d4fde90e1 +Subproject commit b322364f06308bdd24823f9d8f03fe0cc86fd46f From 21bad82c8f2c9da46234e8c9b6a65f2789ac47fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 16:15:29 +0200 Subject: [PATCH 36/55] Fixed Dependencies urls. --- .github/workflows/msbuild.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index 30d32a1d..a24289d9 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -95,8 +95,8 @@ jobs: with: # Specify the Az PowerShell script here. inlineScript: | - Invoke-WebRequest -Uri "https://github.com/sweco-sedahd/Dependencies/blob/main/GisInternals/release-1930-x64-gdal-3-10-3-mapserver-8-2-2.zip" -MaximumRetryCount 3 -Resume -RetryIntervalSec 30 -OutFile ".\Support\release-1930-x64-gdal-3-10-3-mapserver-8-2-2.zip" - Invoke-WebRequest -Uri "https://github.com/sweco-sedahd/Dependencies/blob/main/GisInternals/release-1930-x64-gdal-3-10-3-mapserver-8-2-2-libs.zip" -MaximumRetryCount 3 -Resume -RetryIntervalSec 30 -OutFile ".\Support\release-1930-x64-gdal-3-10-3-mapserver-8-2-2-libs.zip" + Invoke-WebRequest -Uri "https://github.com/sweco-sedahd/Dependencies/raw/main/GisInternals/release-1930-x64-gdal-3-10-3-mapserver-8-2-2.zip" -MaximumRetryCount 3 -Resume -RetryIntervalSec 30 -OutFile ".\Support\release-1930-x64-gdal-3-10-3-mapserver-8-2-2.zip" + Invoke-WebRequest -Uri "https://github.com/sweco-sedahd/Dependencies/raw/main/GisInternals/release-1930-x64-gdal-3-10-3-mapserver-8-2-2-libs.zip" -MaximumRetryCount 3 -Resume -RetryIntervalSec 30 -OutFile ".\Support\release-1930-x64-gdal-3-10-3-mapserver-8-2-2-libs.zip" ls .\Support\ # Azure PS version to be used to execute the script, example: 1.8.0, 2.8.0, 3.4.0. To use the latest version, specify "latest". azPSVersion: "latest" From 0ee79466942d2dab636dcf0ff54951575aded171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 16:23:24 +0200 Subject: [PATCH 37/55] Added missing algorithm include for build on GitHub to work. --- src/Drawing/ShapefileDrawing.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Drawing/ShapefileDrawing.cpp b/src/Drawing/ShapefileDrawing.cpp index f1e47309..89b51e32 100644 --- a/src/Drawing/ShapefileDrawing.cpp +++ b/src/Drawing/ShapefileDrawing.cpp @@ -26,6 +26,7 @@ // Sergei Leschinski (lsu) 25 june 2010 - created the file #include "StdAfx.h" +#include #include "ShapefileDrawing.h" #include "LinePattern.h" #include "ShapefileReader.h" From 42faaf2c10bf43205c25c8f173a6fce522e6438b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 8 Jun 2026 16:33:19 +0200 Subject: [PATCH 38/55] Updated to SupportLibs-toolset143.sln --- .github/workflows/msbuild.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index a24289d9..e0ff7d7d 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -14,7 +14,7 @@ on: - 'docs/**' env: # Path to the solution files relative to the root of the project. - SUPPORTLIBS_SOLUTION_FILE_PATH: ./Support/SupportLibs.sln + SUPPORTLIBS_SOLUTION_FILE_PATH: ./Support/SupportLibs-toolset143.sln MAPWINGIS_SOLUTION_FILE_PATH: ./src/MapWinGIS.sln UNITTESTS_SOLUTION_FILE_PATH: ./MapWinGisTests-net6/MapWinGisTests-net6.sln From 7ffcada143212fcaba7f10b102b197b3a2e556f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Tue, 9 Jun 2026 08:09:32 +0200 Subject: [PATCH 39/55] Fixed depndent ShapeLib name. --- src/MapWinGIS.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MapWinGIS.vcxproj b/src/MapWinGIS.vcxproj index c8c0153a..4d10543d 100644 --- a/src/MapWinGIS.vcxproj +++ b/src/MapWinGIS.vcxproj @@ -249,7 +249,7 @@ if $(PlatformName) == x64 ( /MACHINE:x64 %(AdditionalOptions) MachineX64 - spatialindex-64.lib;ShapeLib-toolset142.lib;xtiff.lib;%(AdditionalDependencies) + spatialindex-64.lib;ShapeLib.lib;xtiff.lib;%(AdditionalDependencies) false From 2c520b2b05fe9b66fce80d485ad67e4babd130f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Tue, 9 Jun 2026 08:28:28 +0200 Subject: [PATCH 40/55] removed spatialindex. --- support/SupportLibs-toolset143.sln | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/support/SupportLibs-toolset143.sln b/support/SupportLibs-toolset143.sln index a97bf9bf..5376b652 100644 --- a/support/SupportLibs-toolset143.sln +++ b/support/SupportLibs-toolset143.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.13.35931.197 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spatialindex-mw", "spatialindex\spatialindex-vc\spatialindex-toolset142.vcxproj", "{38FBBD59-8344-4D8E-B728-3D51763B6A70}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ShapeLib-toolset143", "ShapeLib\ShapeLib-toolset143.vcxproj", "{D6A9A8D7-5556-47C9-A002-FAA9B9BD1CEA}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cqlib-toolset143", "cqlib\cqlib-toolset143.vcxproj", "{19A1259D-0DCC-4FE5-9B0F-CF46B6F9DA81}" @@ -17,15 +15,6 @@ Global Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|Win32.ActiveCfg = Debug|Win32 - {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|Win32.Build.0 = Debug|Win32 - {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|Win32.Deploy.0 = Debug|Win32 - {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|x64.ActiveCfg = Debug|x64 - {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Debug|x64.Build.0 = Debug|x64 - {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Release|Win32.ActiveCfg = Release|Win32 - {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Release|Win32.Build.0 = Release|Win32 - {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Release|x64.ActiveCfg = Release|x64 - {38FBBD59-8344-4D8E-B728-3D51763B6A70}.Release|x64.Build.0 = Release|x64 {D6A9A8D7-5556-47C9-A002-FAA9B9BD1CEA}.Debug|Win32.ActiveCfg = Debug|Win32 {D6A9A8D7-5556-47C9-A002-FAA9B9BD1CEA}.Debug|Win32.Build.0 = Debug|Win32 {D6A9A8D7-5556-47C9-A002-FAA9B9BD1CEA}.Debug|x64.ActiveCfg = Debug|x64 From 6fa683af371c4269783557db96446e054eae4404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Tue, 9 Jun 2026 08:42:34 +0200 Subject: [PATCH 41/55] changed to use geotiff.lib from GDAL SDK to replace xtiff.lib from vcpkg. --- src/MapWinGIS.vcxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MapWinGIS.vcxproj b/src/MapWinGIS.vcxproj index 4d10543d..5e6bef5a 100644 --- a/src/MapWinGIS.vcxproj +++ b/src/MapWinGIS.vcxproj @@ -174,7 +174,7 @@ echo in after $(CustomBuildAfterTargets) NotSet $(OutDir)MapWinGIS.ocx true - $(ProjectDir)..\Support\GDAL_SDK\$(PlatformToolset)\lib\$(Platform);$(ProjectDir)..\Support\lib\$(PlatformToolset)\$(Platform)\Release;$(ProjectDir)\vcpkg_installed\$(VcpkgTriplet)\$(VcpkgHostTriplet)\lib;$(ProjectDir)\vcpkg_installed\$(VCPKG_DEFAULT_TRIPLET)\lib;$(ProjectDir)vcpkg\vcpkg\buildtrees\libgeotiff\x64-windows-rel\lib;%(AdditionalLibraryDirectories) + $(ProjectDir)..\Support\GDAL_SDK\$(PlatformToolset)\lib\$(Platform);$(ProjectDir)..\Support\lib\$(PlatformToolset)\$(Platform)\Release;$(ProjectDir)\vcpkg_installed\$(VcpkgTriplet)\$(VcpkgHostTriplet)\lib;$(ProjectDir)\vcpkg_installed\$(VCPKG_DEFAULT_TRIPLET)\lib;%(AdditionalLibraryDirectories) false LIBC.lib;%(IgnoreSpecificDefaultLibraries) @@ -249,7 +249,7 @@ if $(PlatformName) == x64 ( /MACHINE:x64 %(AdditionalOptions) MachineX64 - spatialindex-64.lib;ShapeLib.lib;xtiff.lib;%(AdditionalDependencies) + spatialindex-64.lib;ShapeLib.lib;geotiff.lib;%(AdditionalDependencies) false From 3b09e7bba7ac297982ee8e5ad0b2ee3166885fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Fri, 26 Jun 2026 16:51:15 +0200 Subject: [PATCH 42/55] Added missing memory release in TryAutoDetectEpsg() and fixed bug in CorrectAxisOrder(). Handle _shpOffsets is empt in CShapefile::ReadComShape(). --- src/COM classes/GeoProjection.cpp | 9 +++++---- src/COM classes/Shapefile_ReadWrite.cpp | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/COM classes/GeoProjection.cpp b/src/COM classes/GeoProjection.cpp index c0036367..478de25f 100644 --- a/src/COM classes/GeoProjection.cpp +++ b/src/COM classes/GeoProjection.cpp @@ -1368,6 +1368,9 @@ STDMETHODIMP CGeoProjection::TryAutoDetectEpsg(int* epsgCode, VARIANT_BOOL* retV { _projection->Release(); _projection = static_cast(spahSrs[0]); + // free the remaining (unused) matches, then the array itself + for (int i = 1; i < nEntries; i++) + OSRDestroySpatialReference(spahSrs[i]); CPLFree(pahSrs); } else @@ -1562,10 +1565,8 @@ std::string CGeoProjection::CorrectAxisOrder(CString wkt) int position1 = -1; int position2 = -1; int pos = 0; - for (auto line : lines) + for (const auto& line : lines) { - auto f1 = line.find("AXIS[\"Northing\"") != std::string::npos; - auto f2 = line.find("AXIS[\"Easting\"") != std::string::npos; if (position1 == -1 && line.find("AXIS[\"Northing\"") != std::string::npos) position1 = pos; else if (position2 == -1 && line.find("AXIS[\"Easting\"") != std::string::npos) @@ -1573,7 +1574,7 @@ std::string CGeoProjection::CorrectAxisOrder(CString wkt) pos++; } - if (position1 < position2) + if (position1 != -1 && position2 != -1 && position1 < position2) std::swap(lines[position1], lines[position2]); for (auto line : lines) diff --git a/src/COM classes/Shapefile_ReadWrite.cpp b/src/COM classes/Shapefile_ReadWrite.cpp index 5e1a5471..ee9ebf1f 100644 --- a/src/COM classes/Shapefile_ReadWrite.cpp +++ b/src/COM classes/Shapefile_ReadWrite.cpp @@ -114,6 +114,9 @@ IShape* CShapefile::ReadFastModeShape(long shapeIndex) // ************************************************************ IShape* CShapefile::ReadComShape(long shapeIndex) { + if (_shpOffsets.empty()) + return nullptr; + // read the shp from disk fseek(_shpfile, _shpOffsets[shapeIndex], SEEK_SET); From 82995e68090a61b1b46dc507ac008bf535b87386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Fri, 26 Jun 2026 16:52:45 +0200 Subject: [PATCH 43/55] Fixed crach bug in CMapView::ChooseZoom(). Update version to 5.5.0.6 --- src/MapControl/Map_Tiles.cpp | 6 +++--- src/MapWinGIS.rc | 8 ++++---- src/MapWinGIS.vcxproj.user | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/MapControl/Map_Tiles.cpp b/src/MapControl/Map_Tiles.cpp index 8e835970..14adafd4 100644 --- a/src/MapControl/Map_Tiles.cpp +++ b/src/MapControl/Map_Tiles.cpp @@ -88,10 +88,10 @@ int CMapView::ChooseZoom(BaseProvider* provider, Extent ext, double scalingRatio #if BIG_TILE_SIZE auto tileImageSize = 512; - auto customProvider = reinterpret_cast(provider); + auto customProvider = dynamic_cast(provider); if (customProvider != nullptr) - tileImageSize = static_cast(customProvider->get_TileSize()); - int minSize = (int)(tileImageSize * scalingRatio * ratio); + tileImageSize = customProvider->get_TileSize(); + int minSize = static_cast(tileImageSize * scalingRatio * ratio); #else int minSize = (int)(256 * scalingRatio * ratio); #endif diff --git a/src/MapWinGIS.rc b/src/MapWinGIS.rc index e14daf13..63ba700a 100644 --- a/src/MapWinGIS.rc +++ b/src/MapWinGIS.rc @@ -113,8 +113,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 5,5,0,5 - PRODUCTVERSION 5,5,0,5 + FILEVERSION 5,5,0,6 + PRODUCTVERSION 5,5,0,6 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -132,13 +132,13 @@ BEGIN VALUE "Comments", "This control includes a mapping component and objects for reading and writing shapefiles and various triangulated irregular network and grid files. It also has extensive label and chart options and includes projection routines." VALUE "CompanyName", "MapWindow OSS Team - www.mapwindow.org" VALUE "FileDescription", "MapWinGIS ActiveX Control" - VALUE "FileVersion", "5.5.0.5" + VALUE "FileVersion", "5.5.0.6" VALUE "InternalName", "MapWinGIS ActiveX Control" VALUE "LegalCopyright", "Copyright (C) 2004-2022 MapWindow OSS Team" VALUE "LegalTrademarks", "MapWindow GIS is a trademark of Daniel P. Ames, 2005-2022" VALUE "OriginalFilename", "MapWinGIS.ocx" VALUE "ProductName", "MapWinGIS ActiveX Control" - VALUE "ProductVersion", "5.5.0.5" + VALUE "ProductVersion", "5.5.0.6" END END BLOCK "VarFileInfo" diff --git a/src/MapWinGIS.vcxproj.user b/src/MapWinGIS.vcxproj.user index fdce78cb..18f7c662 100644 --- a/src/MapWinGIS.vcxproj.user +++ b/src/MapWinGIS.vcxproj.user @@ -10,11 +10,11 @@ WindowsLocalDebugger - "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\dotnet\net8.0\runtime\dotnet.exe" + "C:\Projects\Arkeologerna_Intrasis4\Intrasis\Applications\IntrasisApp\bin\x64\Debug\net10.0-windows8.0\Intrasis.exe" WindowsLocalDebugger - test MapWinGisTests.csproj --no-build --configuration Release -p:Platform=x64 + C:\Intrasis\Database\KHM2018_Dilling216873_220314\KHM2018_Dilling216873_220314.idf admin admin NativeWithManagedCore - C:\Projects\Lib\Sweco_MapWinGIS\MapWinGisTests-net6\MapWinGisTests + C:\Intrasis\Database\KHM2018_Dilling216873_220314\ false \ No newline at end of file From 73259999085610a67b4e293d00cce2f1ac3a017d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Thu, 2 Jul 2026 12:57:00 +0200 Subject: [PATCH 44/55] Fixed possible heap corruption's, new version of function g123fstr() not tested. --- src/COM classes/Shape.cpp | 36 ++++++++++++++++++------------------ src/Grid/fip/gfstr.cpp | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/COM classes/Shape.cpp b/src/COM classes/Shape.cpp index 12019a0e..c0ea78aa 100644 --- a/src/COM classes/Shape.cpp +++ b/src/COM classes/Shape.cpp @@ -1739,21 +1739,21 @@ STDMETHODIMP CShape::SerializeToString(BSTR* serialized) AFX_MANAGE_STATE(AfxGetStaticModuleState()); // fast editing mode - const ShpfileType shptype = _shp->get_ShapeType(); + const ShpfileType shpType = _shp->get_ShapeType(); CString builder = ""; - char cbuf[20]; + CString chunk; double dbuf; double dbuf1; - _itoa(shptype, cbuf, 10); // TODO: Fix compile warning - builder.Append(cbuf); - builder.Append(";"); + + chunk.Format("%d;", shpType); + builder.Append(chunk); const int numParts = _shp->get_PartCount(); for (int i = 0; i < numParts; i++) { - sprintf(cbuf, "%d;", _shp->get_PartStartPoint(i)); // TODO: Fix compile warning - builder.Append(cbuf); + chunk.Format("%d;", _shp->get_PartStartPoint(i)); + builder.Append(chunk); } const int numPoints = _shp->get_PointCount(); @@ -1761,24 +1761,24 @@ STDMETHODIMP CShape::SerializeToString(BSTR* serialized) { _shp->get_PointXY(i, dbuf, dbuf1); - sprintf(cbuf, "%f|", dbuf); // TODO: Fix compile warning - builder.Append(cbuf); + chunk.Format("%f|", dbuf); + builder.Append(chunk); - sprintf(cbuf, "%f|", dbuf1); // TODO: Fix compile warning - builder.Append(cbuf); + chunk.Format("%f|", dbuf1); + builder.Append(chunk); - if (shptype == SHP_MULTIPOINTM || shptype == SHP_POLYGONM || shptype == SHP_POLYLINEM || - shptype == SHP_MULTIPOINTZ || shptype == SHP_POLYGONZ || shptype == SHP_POLYLINEZ) + if (shpType == SHP_MULTIPOINTM || shpType == SHP_POLYGONM || shpType == SHP_POLYLINEM || + shpType == SHP_MULTIPOINTZ || shpType == SHP_POLYGONZ || shpType == SHP_POLYLINEZ) { _shp->get_PointZ(i, dbuf); - sprintf(cbuf, "%f|", dbuf); // TODO: Fix compile warning - builder.Append(cbuf); + chunk.Format("%f|", dbuf); + builder.Append(chunk); } - if (shptype == SHP_MULTIPOINTM || shptype == SHP_POLYGONM || shptype == SHP_POLYLINEM) + if (shpType == SHP_MULTIPOINTM || shpType == SHP_POLYGONM || shpType == SHP_POLYLINEM) { _shp->get_PointM(i, dbuf); - sprintf(cbuf, "%f|", dbuf); // TODO: Fix compile warning - builder.Append(cbuf); + chunk.Format("%f|", dbuf); + builder.Append(chunk); } } *serialized = builder.AllocSysString(); diff --git a/src/Grid/fip/gfstr.cpp b/src/Grid/fip/gfstr.cpp index ab78eedb..3aac018e 100644 --- a/src/Grid/fip/gfstr.cpp +++ b/src/Grid/fip/gfstr.cpp @@ -82,7 +82,8 @@ *****************************************************************************/ #include "stc123.h" -int g123fstr(FILE *fp,char *buf_str,long str_len) +#if OLD_VERSION +int g123fstr_old(FILE *fp,char *buf_str,long str_len) { /* LOCAL VARIABLES */ char *tmpcptr; @@ -138,3 +139,36 @@ int g123fstr(FILE *fp,char *buf_str,long str_len) /*RETURN SUCCESS */ return(1); } +#endif + +int g123fstr(FILE* fp, char* buf_str, long str_len) +{ + /* LOCAL VARIABLES */ + char* tmpcptr; + long remaining; + + /* BASIC VALIDATION */ + if (fp == NULL || buf_str == NULL || str_len < 0) return(0); + + /* INITIALIZE POINTERS */ + tmpcptr = buf_str; + remaining = str_len; + + /* READ THE FULL STRING IN CHUNKS */ + while (remaining > 0) { + + size_t chunk = (remaining > MAXINT) ? (size_t)MAXINT : (size_t)remaining; + size_t read_len = fread(tmpcptr, sizeof(char), chunk, fp); + + if (read_len != chunk) return(0); + + tmpcptr += read_len; + remaining -= (long)read_len; + } + + /* APPEND NULL CHARACTER ONCE, AT THE END */ + *tmpcptr = NC; + + /* RETURN SUCCESS */ + return(1); +} \ No newline at end of file From c33fe42e831fef1fda11aca33553a11f0597dfda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Fri, 3 Jul 2026 12:44:30 +0200 Subject: [PATCH 45/55] Fixed Access violation bug, buffer whas allocated without size for null termination. --- src/COM classes/GeoProjection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/COM classes/GeoProjection.cpp b/src/COM classes/GeoProjection.cpp index 478de25f..045049e9 100644 --- a/src/COM classes/GeoProjection.cpp +++ b/src/COM classes/GeoProjection.cpp @@ -936,7 +936,7 @@ bool CGeoProjection::ReadFromFileCore(CStringW filename, bool esri) if (fileLen > 0) { fseek(prjFile, 0L, SEEK_SET); // allocate buffer for file - vector pszWKT = vector(fileLen, 0); + auto pszWKT = vector(fileLen + 1, 0); // read the file fread(pszWKT.data(), sizeof(char), fileLen, prjFile); fclose(prjFile); From 02e5b75db9872f819b6b490c037f72bc0951db09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 6 Jul 2026 12:35:29 +0200 Subject: [PATCH 46/55] Fixed arguemt check in CLinePattern::RemoveItem() --- src/COM classes/LinePattern.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/COM classes/LinePattern.cpp b/src/COM classes/LinePattern.cpp index e719fe07..ff3ce4b9 100644 --- a/src/COM classes/LinePattern.cpp +++ b/src/COM classes/LinePattern.cpp @@ -236,7 +236,7 @@ STDMETHODIMP CLinePattern::InsertMarker(int Index, tkDefaultPointSymbol marker, STDMETHODIMP CLinePattern::RemoveItem(int Index, VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if(Index < 0 && Index >= (int)_lines.size()) + if(Index < 0 || Index >= static_cast(_lines.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = VARIANT_FALSE; From 4e3ec794c450ed214b129350655f0e40101689f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 6 Jul 2026 12:41:29 +0200 Subject: [PATCH 47/55] Fixed copy in TExpandableBuffer::Expand, possible heap corruption. --- src/Grid/ExpandableBuffer.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Grid/ExpandableBuffer.hpp b/src/Grid/ExpandableBuffer.hpp index 35f34f88..f51a1b10 100644 --- a/src/Grid/ExpandableBuffer.hpp +++ b/src/Grid/ExpandableBuffer.hpp @@ -226,7 +226,7 @@ size_t TExpandableBuffer::Expand(size_t newSize) { T *pNewBuffer = new T[newSize]; - for (size_t i = 0; i < newSize; i++) + for (size_t i = 0; i < m_size; i++) { pNewBuffer[i] = m_pBuffer[i]; } From 1597a988475cd97f0243a6537b2a373ef577c885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Mon, 6 Jul 2026 13:04:56 +0200 Subject: [PATCH 48/55] Updated version to 5.5.0.7 --- src/MapWinGIS.rc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MapWinGIS.rc b/src/MapWinGIS.rc index 63ba700a..1fcfaac7 100644 --- a/src/MapWinGIS.rc +++ b/src/MapWinGIS.rc @@ -113,8 +113,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 5,5,0,6 - PRODUCTVERSION 5,5,0,6 + FILEVERSION 5,5,0,7 + PRODUCTVERSION 5,5,0,7 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -132,13 +132,13 @@ BEGIN VALUE "Comments", "This control includes a mapping component and objects for reading and writing shapefiles and various triangulated irregular network and grid files. It also has extensive label and chart options and includes projection routines." VALUE "CompanyName", "MapWindow OSS Team - www.mapwindow.org" VALUE "FileDescription", "MapWinGIS ActiveX Control" - VALUE "FileVersion", "5.5.0.6" + VALUE "FileVersion", "5.5.0.7" VALUE "InternalName", "MapWinGIS ActiveX Control" VALUE "LegalCopyright", "Copyright (C) 2004-2022 MapWindow OSS Team" VALUE "LegalTrademarks", "MapWindow GIS is a trademark of Daniel P. Ames, 2005-2022" VALUE "OriginalFilename", "MapWinGIS.ocx" VALUE "ProductName", "MapWinGIS ActiveX Control" - VALUE "ProductVersion", "5.5.0.6" + VALUE "ProductVersion", "5.5.0.7" END END BLOCK "VarFileInfo" From c27da560290be819ce1602a8126bc698fb263090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Fri, 17 Jul 2026 19:40:00 +0200 Subject: [PATCH 49/55] Cleanup and update to match upstream version. --- src/COM classes/GeoProjection.cpp | 31 ++++++++++++++++--------------- src/COM classes/ShapeEditor.cpp | 4 ++-- src/Ogr/OgrConverter.cpp | 18 +++++++++--------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/COM classes/GeoProjection.cpp b/src/COM classes/GeoProjection.cpp index 045049e9..b5001a46 100644 --- a/src/COM classes/GeoProjection.cpp +++ b/src/COM classes/GeoProjection.cpp @@ -532,33 +532,34 @@ STDMETHODIMP CGeoProjection::get_IsSame(IGeoProjection* proj, VARIANT_BOOL* pVal return S_OK; } + // Because layers loaed from diffrent sources (with the same GeoProjection) can fail test: _projection->IsSame(sr) CComBSTR name1; CComBSTR name2; this->get_Name(&name1); proj->get_Name(&name2); - if (name1 == name2) - { - *pVal = VARIANT_TRUE; - return S_OK; - } + auto nameIsEqual = name1 == name2; CComBSTR projName1; CComBSTR projName2; this->get_ProjectionName(&projName1); proj->get_ProjectionName(&projName2); - if (projName1 == projName2) + auto projNameIsEqual = projName1 == projName2; + + if (!projNameIsEqual) { - *pVal = VARIANT_TRUE; - return S_OK; + // Compare ProjectionName after filter out '.' and replacing all '-' with space. + // This is so that "WGS-84" and "WGS 84" is seen as the same + std::wstring pn1(projName1, SysStringLen(projName1)); + std::wstring pn2(projName2, SysStringLen(projName2)); + std::replace(pn1.begin(), pn1.end(), '-', ' '); + std::replace(pn2.begin(), pn2.end(), '-', ' '); + pn1.erase(std::remove(pn1.begin(), pn1.end(), '.'), pn1.end()); + pn2.erase(std::remove(pn2.begin(), pn2.end(), '.'), pn2.end()); + projNameIsEqual = pn1 == pn2; } - std::wstring pn1(projName1, SysStringLen(projName1)); - std::wstring pn2(projName2, SysStringLen(projName2)); - std::replace(pn1.begin(), pn1.end(), '-', ' '); - std::replace(pn2.begin(), pn2.end(), '-', ' '); - pn1.erase(std::remove(pn1.begin(), pn1.end(), '.'), pn1.end()); - pn2.erase(std::remove(pn2.begin(), pn2.end(), '.'), pn2.end()); - if (pn1 == pn2) + // We test if Name and ProjectionName are the same on both we call that the same. + if (nameIsEqual && projNameIsEqual) { *pVal = VARIANT_TRUE; return S_OK; diff --git a/src/COM classes/ShapeEditor.cpp b/src/COM classes/ShapeEditor.cpp index b8561279..10f080ac 100644 --- a/src/COM classes/ShapeEditor.cpp +++ b/src/COM classes/ShapeEditor.cpp @@ -405,7 +405,7 @@ STDMETHODIMP CShapeEditor::SetShape( IShape* shp ) VARIANT_BOOL vb; double x, y, z, m; shp->get_NumPoints(&numPoints); - + bool haveZ = ShapeUtility::IsZ(shpType); bool haveM = ShapeUtility::HaveM(shpType); @@ -744,7 +744,7 @@ STDMETHODIMP CShapeEditor::AddPoint(IPoint *newPoint, VARIANT_BOOL* retVal) newPoint->get_X(&x); newPoint->get_Y(&y); newPoint->get_Z(&z); - newPoint->get_Z(&m); + newPoint->get_M(&m); newPoint->Release(); _activeShape->AddPoint(x, y, z, m, -1, -1, PartBegin); *retVal = VARIANT_TRUE; diff --git a/src/Ogr/OgrConverter.cpp b/src/Ogr/OgrConverter.cpp index 478ec3dc..64af7a12 100644 --- a/src/Ogr/OgrConverter.cpp +++ b/src/Ogr/OgrConverter.cpp @@ -197,11 +197,11 @@ OGRGeometry* OgrConverter::ShapeToGeometry(IShape* shape, OGRwkbGeometryType for oGeom = oMPnt; } else if (shptype == SHP_POLYLINE || shptype == SHP_POLYLINEM || shptype == SHP_POLYLINEZ) - { + { bool multiLineString = (forceGeometryType == wkbMultiLineString || forceGeometryType == wkbMultiLineString25D); if (numParts <= 1 && !multiLineString) - { + { // create empty shape OGRLineString *oLine = (OGRLineString*)OGRGeometryFactory::createGeometry(wkbLineString); if (numPoints > 0) @@ -229,12 +229,12 @@ OGRGeometry* OgrConverter::ShapeToGeometry(IShape* shape, OGRwkbGeometryType for oGeom = oMLine; } } - + else if (shptype == SHP_POLYGON || shptype == SHP_POLYGONM || shptype == SHP_POLYGONZ) - { + { bool multiPolygon = (forceGeometryType == wkbMultiPolygon || forceGeometryType == wkbMultiPolygon25D); if (numParts <= 1 && !multiPolygon) - { + { // create empty shape OGRPolygon* oPoly; if (shptype == SHP_POLYGONZ) @@ -251,7 +251,7 @@ OGRGeometry* OgrConverter::ShapeToGeometry(IShape* shape, OGRwkbGeometryType for oGeom = oPoly; } else - { + { // if parts are present, add them if (numPoints > 0) { @@ -289,9 +289,9 @@ OGRGeometry* OgrConverter::ShapeToGeometry(IShape* shape, OGRwkbGeometryType for } else return NULL; // other types aren't supported - + if (oGeom != NULL) - { + { if (shptype == SHP_POINT || shptype == SHP_MULTIPOINT || shptype == SHP_POLYLINE || shptype == SHP_POLYGON) oGeom->setCoordinateDimension(2); else @@ -654,7 +654,7 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM, { oPoly = (OGRPolygon *) oMPoly->getGeometryRef(iGeom); - if (oPoly->getGeometryType() == wkbPolygon || oPoly->getGeometryType() == wkbPolygon25D || oPoly->getGeometryType() == wkbPolygonM || oPoly->getGeometryType() == wkbPolygonZM) + if (oPoly->getGeometryType() == wkbPolygon || oPoly->getGeometryType() == wkbPolygon25D || oPoly->getGeometryType() == wkbPolygonM || oPoly->getGeometryType() == wkbPolygonZM) { if( oPoly->getExteriorRing() == NULL) continue; if (oPoly->getExteriorRing()->IsEmpty()) continue; From 3bcd5233f67e10cc9cf34f28cc23f08b88e5a7fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Sat, 18 Jul 2026 16:30:30 +0200 Subject: [PATCH 50/55] Updates to match upstream. --- src/Image/GdalRaster.cpp | 9 ++++----- src/Shapefile/ShapeWrapperCOM.cpp | 21 ++++++--------------- src/Tiles/TileManager.cpp | 2 -- src/Utilities/UtilityFunctions.cpp | 19 ++++++++++--------- src/Utilities/UtilityFunctions.h | 3 ++- 5 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/Image/GdalRaster.cpp b/src/Image/GdalRaster.cpp index 4f298e11..dd15afc1 100644 --- a/src/Image/GdalRaster.cpp +++ b/src/Image/GdalRaster.cpp @@ -362,16 +362,15 @@ bool GdalRaster::ReadGeoTransform() double adfGeoTransform[6]; bool success = _dataset->GetGeoTransform(adfGeoTransform) == CE_None; - if (!success) { - // IK-82, try to convert from GCP to GeoTransform, with looser tolerances (ApproxOK = True) (if we have GCP) + if (!success) + { auto count = _dataset->GetGCPCount(); if (count > 0) { + // If normal GetGeoTransform failed, fallback generate GeoTransform from GCP using GDALGCPsToGeoTransform + // using bApproxOK: True to not requare exact fit (within 0.25 pixel) for all GCPs. auto gcps = _dataset->GetGCPs(); success = CPL_TO_BOOL(GDALGCPsToGeoTransform(count, gcps, adfGeoTransform, TRUE)); - CString sOutput; - sOutput.AppendFormat("GDALGCPsToGeoTransform(%d,..,TRUE): return: %s\r\n", count, success ? "true" : "false"); - ::OutputDebugStringA(sOutput.GetBuffer()); } } diff --git a/src/Shapefile/ShapeWrapperCOM.cpp b/src/Shapefile/ShapeWrapperCOM.cpp index 82613a3c..f999ee46 100644 --- a/src/Shapefile/ShapeWrapperCOM.cpp +++ b/src/Shapefile/ShapeWrapperCOM.cpp @@ -23,6 +23,7 @@ * (Open source contributors should list themselves and their modifications here). */ #include "stdafx.h" #include "ShapeWrapperCOM.h" +#include "UtilityFunctions.h" #include @@ -471,40 +472,30 @@ bool CShapeWrapperCOM::InsertPointXYZM(const int pointIndex, const double x, con return false; } -bool PointIsXYEqual(IPoint* p1, IPoint* p2) -{ - double x1, x2, y1, y2; - p1->get_X(&x1); - p2->get_X(&x2); - p1->get_Y(&y1); - p2->get_Y(&y2); - return abs(x1 - x2) < 0.00001 && abs(y1 - y2) < 0.00001; -} - // ******************************************************** // DeletePoint() // ******************************************************** bool CShapeWrapperCOM::DeletePoint(const int pointIndex) { - auto count = gsl::narrow_cast(_points.size()); - if (pointIndex < 0 || pointIndex >= count) + auto pointCount = gsl::narrow_cast(_points.size()); + if (pointIndex < 0 || pointIndex >= pointCount) { _lastErrorCode = tkINDEX_OUT_OF_BOUNDS; return false; } - const auto needToReClose = pointIndex == 0 && PointIsXYEqual(_points[count - 1], _points[0]); + const auto needToReClose = pointIndex == 0 && Utility::PointIsXYEqual(_points[pointCount - 1], _points[0]); _points[pointIndex]->Release(); _points.erase(_points.begin() + pointIndex); if (needToReClose) { // First point is the last point (to close) - count = gsl::narrow_cast(_points.size()); + pointCount = gsl::narrow_cast(_points.size()); IPoint* pt; auto hr = _points[0]->Clone(&pt); if (FAILED(hr)) { _lastErrorCode = tkINVALID_SHAPE; return false; } - auto replaceIndex = count - 1; + auto replaceIndex = pointCount - 1; _points[replaceIndex]->Release(); _points.erase(_points.begin() + replaceIndex); pt->AddRef(); diff --git a/src/Tiles/TileManager.cpp b/src/Tiles/TileManager.cpp index 31349e67..593c6e6e 100644 --- a/src/Tiles/TileManager.cpp +++ b/src/Tiles/TileManager.cpp @@ -151,8 +151,6 @@ bool TileManager::GetTileIndices(BaseProvider* provider, CRect& indices, int& zo return false; } - //VerifyLayers(); - if (!_map->_GetTilesForMap(provider, _scalingRatio, indices, zoom)) { Clear(); diff --git a/src/Utilities/UtilityFunctions.cpp b/src/Utilities/UtilityFunctions.cpp index 906345b3..4b53f9c1 100644 --- a/src/Utilities/UtilityFunctions.cpp +++ b/src/Utilities/UtilityFunctions.cpp @@ -39,15 +39,6 @@ namespace Utility return utf8; } - // ******************************************************** - // ConvertToAnsi1252() - // ******************************************************** - CStringA ConvertToAnsi1252(CStringW unicode) { - USES_CONVERSION; - CStringA acp = CW2A(unicode, CP_ACP); - return acp; - } - // ******************************************************** // ConvertFromUtf8() // ******************************************************** @@ -1419,6 +1410,16 @@ namespace Utility return strs.size(); } + + bool PointIsXYEqual(IPoint* p1, IPoint* p2, const double maxDiff) + { + double x1, x2, y1, y2; + p1->get_X(&x1); + p1->get_Y(&y1); + p2->get_X(&x2); + p2->get_Y(&y2); + return abs(x1 - x2) <= 0.00001 && abs(y1 - y2) <= maxDiff; + } } // ReSharper restore CppUseAuto diff --git a/src/Utilities/UtilityFunctions.h b/src/Utilities/UtilityFunctions.h index d0d6905f..d68769df 100644 --- a/src/Utilities/UtilityFunctions.h +++ b/src/Utilities/UtilityFunctions.h @@ -19,7 +19,6 @@ namespace Utility CString UrlEncode(CString s); CStringW XmlFilenameToUnicode(CStringA s, bool utf8); CStringA ConvertToUtf8(CStringW unicode); - CStringA ConvertToAnsi1252(CStringW unicode); CStringW ConvertFromUtf8(CStringA utf8); CString GetSocketErrorMessage(DWORD socketError); @@ -96,4 +95,6 @@ namespace Utility int GetCurrentYear(); size_t split(const std::string &txt, std::vector &strs, const char splittingChar); + + bool PointIsXYEqual(IPoint* p1, IPoint* p2, const double maxDiff = 0.00001); } \ No newline at end of file From c89f1d66c632cacc82fd2e0d671068bd0221b21e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Tue, 21 Jul 2026 13:32:41 +0200 Subject: [PATCH 51/55] Updates to match upstream MapWinGIS. --- src/COM classes/GdalRasterBand.cpp | 4 +--- src/MapWinGIS.vcxproj | 4 ++-- src/Structures/Extent.h | 4 +--- src/Tiles/Caching/SQLiteCache.cpp | 10 +++++----- src/Tiles/Providers/WmsCustomProvider.cpp | 7 ++----- 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/COM classes/GdalRasterBand.cpp b/src/COM classes/GdalRasterBand.cpp index 8c1ad946..dc856977 100644 --- a/src/COM classes/GdalRasterBand.cpp +++ b/src/COM classes/GdalRasterBand.cpp @@ -65,7 +65,6 @@ STDMETHODIMP CGdalRasterBand::get_Minimum(DOUBLE* pVal) if (!success) { - // Not an error, the band has no minimum value ErrorMessage("Failed to retrieve minimum."); } @@ -88,9 +87,8 @@ STDMETHODIMP CGdalRasterBand::get_Maximum(DOUBLE* pVal) if (!success) { - // Not an error, the band has no maximum value ErrorMessage("Failed to retrieve maximum."); - *pVal = 255; + *pVal = 255; // Default to 255 as get_Minimum defaults to 0.0 } return S_OK; diff --git a/src/MapWinGIS.vcxproj b/src/MapWinGIS.vcxproj index 5e6bef5a..15b51143 100644 --- a/src/MapWinGIS.vcxproj +++ b/src/MapWinGIS.vcxproj @@ -213,7 +213,7 @@ setx PROJ_LIB $(OutputPath)proj7\share Win32 - WIN32;%(PreprocessorDefinitions) + WIN32;DEBUG_LOG;%(PreprocessorDefinitions) false stdc11 stdcpp14 @@ -241,7 +241,7 @@ if $(PlatformName) == x64 ( x64 - WIN64;SQUARE_TILES;BIG_TILE_SIZE;DEBUG_ALLOCATED_OBJECTS_OFF;%(PreprocessorDefinitions) + WIN64;DEBUG_LOG;SQUARE_TILES;BIG_TILE_SIZE;DEBUG_ALLOCATED_OBJECTS_OFF;%(PreprocessorDefinitions) stdc11 stdcpp14 true diff --git a/src/Structures/Extent.h b/src/Structures/Extent.h index 33a74a61..6c2b58c8 100644 --- a/src/Structures/Extent.h +++ b/src/Structures/Extent.h @@ -143,9 +143,7 @@ class Extent CString ToString() { - auto width = Width(); - auto height = Height(); - return Debug::Format("x: %f; y: %f; w: %f; h: %f", left, top, width, height); + return Debug::Format("x: %f; y: %f; w: %f; h: %f", left, top, Width(), Height()); } }; diff --git a/src/Tiles/Caching/SQLiteCache.cpp b/src/Tiles/Caching/SQLiteCache.cpp index c3fe9193..5e8f70c0 100644 --- a/src/Tiles/Caching/SQLiteCache.cpp +++ b/src/Tiles/Caching/SQLiteCache.cpp @@ -209,16 +209,16 @@ void SQLiteCache::AddTile(TileCore* tile) { CString s = "REPLACE INTO Tiles VALUES (?, ?, ?, ?, ?, ?, ?)"; int val = sqlite3_prepare_v2(_conn, s, s.GetLength()+1, &stmt, &tail); - + if (val != SQLITE_OK) { +#ifdef DEBUG_LOG auto sqlite3_error = sqlite3_errmsg(_conn); auto errorCode = sqlite3_extended_errcode(_conn); - //std:string errorMessage("SQLiteCache::DoCaching: Failed to prepare statement: "); - //errorMessage += sqlite3_error ? sqlite3_error : "Unknown error"; - //CallbackHelper::ErrorMsg(errorMessage.c_str()); CallbackHelper::ErrorMsg(Debug::Format("SQLiteCache::DoCaching: Failed to prepare statement errorNo: %d Message: %s", errorCode, sqlite3_error)); - //CallbackHelper::ErrorMsg("SQLiteCache::DoCaching: Failed to prepare statement."); +#else + CallbackHelper::ErrorMsg("SQLiteCache::DoCaching: Failed to prepare statement."); +#endif } else { diff --git a/src/Tiles/Providers/WmsCustomProvider.cpp b/src/Tiles/Providers/WmsCustomProvider.cpp index 59d55191..80bae6f2 100644 --- a/src/Tiles/Providers/WmsCustomProvider.cpp +++ b/src/Tiles/Providers/WmsCustomProvider.cpp @@ -66,11 +66,7 @@ CString WmsCustomProvider::MakeTileImageUrl(CPoint &pos, int zoom) // ****************************************************** CString WmsCustomProvider::get_VersionString() { - auto version = _version; - if ( version == wvAuto ) - version = wv13; // Auto fall back to version 1.3 - - switch (version) + switch (_version) { case wvEmpty: return ""; @@ -81,6 +77,7 @@ CString WmsCustomProvider::get_VersionString() case wv111: return "&version=1.1.1"; case wv13: + case wvAuto: // Auto fall back to version: 1.3 return "&version=1.3.0"; default: return ""; From 3af7aaf853e5026c21b87bcdab4c54c2b7b583ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Wed, 22 Jul 2026 15:23:46 +0200 Subject: [PATCH 52/55] Updates to match upstream version. --- src/COM classes/OgrLayer.cpp | 3 +-- src/COM classes/Shape.cpp | 15 ++++----------- src/COM classes/Shapefile_ReadWrite.cpp | 2 +- src/COM classes/Shapefile_Selection.cpp | 7 ------- src/COM classes/TableClass.cpp | 14 +++----------- src/COM classes/TableClass.h | 2 -- src/MapControl/Map_Drawing.cpp | 2 -- src/Utilities/Debugging/ReferenceCounter.h | 1 - 8 files changed, 9 insertions(+), 37 deletions(-) diff --git a/src/COM classes/OgrLayer.cpp b/src/COM classes/OgrLayer.cpp index 5f2273a8..bd93bbb8 100644 --- a/src/COM classes/OgrLayer.cpp +++ b/src/COM classes/OgrLayer.cpp @@ -174,7 +174,7 @@ void COgrLayer::UpdateShapefileFromOGRLoader() ShpfileType shapeType; shp->get_ShapeType(&shapeType); - auto compatible = shapeType == shpType + auto compatible = shapeType == shpType || ShapeUtility::Convert2D(shapeType) == ShapeUtility::Convert2D(shpType); // Ignore incompatible shapes if (compatible) @@ -205,7 +205,6 @@ void COgrLayer::UpdateShapefileFromOGRLoader() ((CShapefile*)_shapefile)->MapOgrFid2ShapeIndex(pVal.lVal, count); } - count++; } } diff --git a/src/COM classes/Shape.cpp b/src/COM classes/Shape.cpp index c0ea78aa..d6f0aab8 100644 --- a/src/COM classes/Shape.cpp +++ b/src/COM classes/Shape.cpp @@ -269,13 +269,6 @@ STDMETHODIMP CShape::put_ShapeType(const ShpfileType newVal) const ShapeWrapperType type = _shp->get_WrapperType(); const ShapeWrapperType newType = ShapeUtility::GetShapeWrapperType(newVal, !_useFastMode); - /*if ((newVal == SHP_POINT || newVal == SHP_POINTM || newVal == SHP_POINTZ) && ComHelper::GetBreak()) { - CString str; - str.Format("0x%016llx SHP_POINT", this); - const CComBSTR bstr(str); - put_Key(bstr); - } */ - if (type == newType) { if (!_shp->put_ShapeType(newVal)) { @@ -1509,7 +1502,7 @@ STDMETHODIMP CShape::BufferWithParams(const DOUBLE distance, const LONG numSegme { if (!shapes.empty()) { *retVal = gsl::at(shapes, 0); - const int numShapes = shapes.size(); + const auto numShapes = shapes.size(); for (size_t i = 1; i < numShapes; i++) { gsl::at(shapes, i)->Release(); } @@ -1736,7 +1729,7 @@ STDMETHODIMP CShape::get_InteriorPoint(IPoint** retval) // ************************************************************* STDMETHODIMP CShape::SerializeToString(BSTR* serialized) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // fast editing mode const ShpfileType shpType = _shp->get_ShapeType(); @@ -2319,7 +2312,7 @@ bool Bytes2SafeArray(const unsigned char* data, const int size, VARIANT* arr) //*********************************************************************** STDMETHODIMP CShape::ExportToBinary(VARIANT* bytesArray, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) int* data = _shp->get_RawData(); const int contentLength = _shp->get_ContentLength(); @@ -2344,7 +2337,7 @@ STDMETHODIMP CShape::ExportToBinary(VARIANT* bytesArray, VARIANT_BOOL* retVal) //******************************************************************** STDMETHODIMP CShape::ImportFromBinary(const VARIANT bytesArray, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (bytesArray.vt != (VT_ARRAY | VT_UI1)) diff --git a/src/COM classes/Shapefile_ReadWrite.cpp b/src/COM classes/Shapefile_ReadWrite.cpp index ee9ebf1f..72443761 100644 --- a/src/COM classes/Shapefile_ReadWrite.cpp +++ b/src/COM classes/Shapefile_ReadWrite.cpp @@ -1110,7 +1110,7 @@ BOOL CShapefile::WriteShx(FILE * shx, ICallback * cBack) long percent = static_cast(static_cast(i + 1) / size * 100); - if (percent % 10 == 0) + if (i == 0 || percent % 10 == 0) CallbackHelper::Progress(callback, i, size, "Writing .shx file", _key, percent); } diff --git a/src/COM classes/Shapefile_Selection.cpp b/src/COM classes/Shapefile_Selection.cpp index 382438e2..0efe36f4 100644 --- a/src/COM classes/Shapefile_Selection.cpp +++ b/src/COM classes/Shapefile_Selection.cpp @@ -80,14 +80,7 @@ bool CShapefile::SelectShapesCore(Extent& extents, const double tolerance, const // build GEOSGeom for comparison IShape* shpExt = nullptr; -#if DEBUG_ALLOCATED_OBJECTS - auto currentBrake = ComHelper::GetBreak(); - ComHelper::SetBreak(false); -#endif ComHelper::CreateShape(&shpExt); -#if DEBUG_ALLOCATED_OBJECTS - ComHelper::SetBreak(currentBrake); -#endif const bool bPtSelection = bMinX == bMaxX && bMinY == bMaxY; int localNumShapes = static_cast(_shapeData.size()); diff --git a/src/COM classes/TableClass.cpp b/src/COM classes/TableClass.cpp index b8b45880..808f8e3e 100644 --- a/src/COM classes/TableClass.cpp +++ b/src/COM classes/TableClass.cpp @@ -824,7 +824,7 @@ bool CTableClass::SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace if (!updateFileInPlace) DBFClose(newdbfHandle); - // Set byte 29 to 0x00 in the .dbf file (Codepage mark) + // Set byte 29 to 0x00 in the .dbf file (Codepage mark) to make ReadRecord() treat text as UTF-8. FILE* dbfFile = _wfopen(dbfFilename, L"r+"); if (dbfFile != NULL) { fseek(dbfFile, 29, SEEK_SET); @@ -874,9 +874,6 @@ STDMETHODIMP CTableClass::SaveAs(BSTR dbfFilename, ICallback *cBack, VARIANT_BOO // ************************************************************** void CTableClass::ClearFields() { - //if(_triggerDebug) - //DebugBreak(); - for (int i = 0; i < FieldCount(); i++) { if (_fields[i]->field != NULL) @@ -898,9 +895,6 @@ STDMETHODIMP CTableClass::Close(VARIANT_BOOL *retval) *retval = VARIANT_TRUE; - //if(_triggerDebug) - //DebugBreak(); - StopAllJoins(); ClearFields(); @@ -1491,9 +1485,7 @@ bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowI if (val.vt == VT_BSTR) { nonstackString = Utility::ConvertBSTRToLPSTR(val.bstrVal, (isUTF8 ? CP_UTF8 : CP_ACP)); // ((LPCSTR)Utility::ConvertToUtf8(val.bstrVal)); // Utility::SYS2A(val.bstrVal); - int fieldCount = DBFGetFieldCount(dbfHandle); DBFWriteStringAttribute(dbfHandle, toRowIndex, i, nonstackString); - //::OutputDebugString("DBFWriteStringAttribute() done!"); delete[] nonstackString; nonstackString = NULL; } @@ -3314,8 +3306,8 @@ STDMETHODIMP CTableClass::StopJoin(int joinIndex, VARIANT_BOOL* retVal) // ***************************************************** STDMETHODIMP CTableClass::get_IsJoined(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - for (size_t i = _fields.size() - 1; i >= 0 && _fields.size() > i; i--) + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + for (size_t i = _fields.size(); i-- > 0;) { if (_fields[i]->Joined()) { *retVal = VARIANT_TRUE; diff --git a/src/COM classes/TableClass.h b/src/COM classes/TableClass.h index ed3009cc..4a1bd217 100644 --- a/src/COM classes/TableClass.h +++ b/src/COM classes/TableClass.h @@ -46,7 +46,6 @@ class ATL_NO_VTABLE CTableClass : _pUnkMarshaler = NULL; _key = SysAllocString(L""); _lastRecordIndex = -1; - _triggerDebug = false; gReferenceCounter.AddRef(tkInterface::idTable); } @@ -195,7 +194,6 @@ class ATL_NO_VTABLE CTableClass : int _lastRecordIndex; // last index accessed with get_CellValue bool _appendMode; int _appendStartShapeCount; - bool _triggerDebug; public: bool m_needToSaveAsNewFile; diff --git a/src/MapControl/Map_Drawing.cpp b/src/MapControl/Map_Drawing.cpp index f6977d94..9cef2ecc 100644 --- a/src/MapControl/Map_Drawing.cpp +++ b/src/MapControl/Map_Drawing.cpp @@ -341,8 +341,6 @@ void CMapView::RedrawWmsLayers(Gdiplus::Graphics* g) gWms->Clear(Gdiplus::Color::Transparent); } - //manager->VerifyLayers(); - TilesDrawer drawer(gWms, &_extents, _pixelPerProjectionX, _pixelPerProjectionY, PixelsPerMapUnit(), GetWgs84ToMapTransform()); drawer.DrawTiles(manager, GetMapProjection(), _isSnapshot, _projectionChangeCount); diff --git a/src/Utilities/Debugging/ReferenceCounter.h b/src/Utilities/Debugging/ReferenceCounter.h index 348707cb..de29b8ee 100644 --- a/src/Utilities/Debugging/ReferenceCounter.h +++ b/src/Utilities/Debugging/ReferenceCounter.h @@ -33,7 +33,6 @@ class ReferenceCounter int* val = &referenceCounts[(int)type]; (*val)--; } - void WriteReport(bool unreleasedOnly); CString GetReport(bool unreleasedOnly); From 79c46dfc8ea39211e4ec75720bc11e1072810a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Wed, 22 Jul 2026 21:24:39 +0200 Subject: [PATCH 53/55] SelectionHelper::SelectSingleShape() updated to match upstream. --- src/ComHelpers/SelectionHelper.cpp | 73 +++++++++++------------------- 1 file changed, 27 insertions(+), 46 deletions(-) diff --git a/src/ComHelpers/SelectionHelper.cpp b/src/ComHelpers/SelectionHelper.cpp index 489d8b1b..0bc777a7 100644 --- a/src/ComHelpers/SelectionHelper.cpp +++ b/src/ComHelpers/SelectionHelper.cpp @@ -1,4 +1,5 @@ #include "stdafx.h" +#include #include "SelectionHelper.h" #include "Shapefile.h" #include "ShapeHelper.h" @@ -213,56 +214,36 @@ bool SelectionHelper::SelectSingleShape(IShapefile* sf, Extent& box, long& shape bool SelectionHelper::SelectSingleShape(IShapefile* sf, Extent& box, SelectMode mode, long& shapeIndex) { vector results; - bool foundMatch = false; - double minDistance = (std::numeric_limits::max)(); - if (SelectShapes(sf, box, mode, results)) + if (!SelectShapes(sf, box, mode, results)) + return false; + + const auto center = box.GetCenter(); + const double tolerance = (std::max)(box.Width(), box.Height()); + + // top-most first + for (int i = static_cast(results.size()) - 1; i >= 0; i--) { - auto center = box.GetCenter(); - IShape* ptShp = nullptr; - ComHelper::CreateShape(&ptShp); - ptShp->put_ShapeType(SHP_POINT); - IPoint* pnt; - ComHelper::CreatePoint(&pnt); - pnt->put_X(center.x); - pnt->put_Y(center.y); - VARIANT_BOOL retVal; - long pointIndex = 0; - ptShp->InsertPoint(pnt, &pointIndex, &retVal); - pnt->Release(); - for (int i = static_cast(results.size()) - 1; i >= 0; i--) + VARIANT_BOOL visible = VARIANT_FALSE; + sf->get_ShapeRendered(results[i], &visible); + if (!visible) + continue; + + IShape* shp = nullptr; + sf->get_Shape(results[i], &shp); + if (!shp) + continue; + + // Real geometry match (handles polygon holes correctly). + const bool isMatch = ShapeHelper::PointWithinShape(shp, center.x, center.y, tolerance); + shp->Release(); + + if (isMatch) { - VARIANT_BOOL visible; - sf->get_ShapeRendered(results[i], &visible); - if (visible) - { - IShape* shp; - sf->get_Shape(results[i], &shp); - ShpfileType shpfileType; - shp->get_ShapeType(&shpfileType); - double distance; - if (shpfileType == SHP_POLYGON || shpfileType == SHP_POLYGONZ || shpfileType == SHP_POLYGONM) - { - // Measure distance to polygons boundary to allow selection of inner shape, (IK-384) - IShape* boundary; - shp->Boundary(&boundary); - boundary->Distance(ptShp, &distance); - boundary->Release(); - } - else - shp->Distance(ptShp, &distance); - - - if (minDistance > distance) - { - minDistance = distance; - shapeIndex = results[i]; - foundMatch = true; - } - } + shapeIndex = results[i]; + return true; } - ptShp->Release(); } - return foundMatch; + return false; } /***********************************************************************/ From adee16fc8a51dd8090de49024c566f223a789d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Fri, 24 Jul 2026 21:13:47 +0200 Subject: [PATCH 54/55] Updates to match upstream version. --- src/COM classes/Utils_OGR.cpp | 17 ++--- src/ComHelpers/ShapeHelper.cpp | 5 +- src/ComHelpers/ShapeHelper.h | 2 + src/ComHelpers/ShapefileHelper.cpp | 7 +- src/Drawing/ShapefileDrawing.cpp | 2 +- src/Grid/fip/gfstr.cpp | 101 ++++++----------------------- src/MapControl/Map_Events.cpp | 35 +--------- src/Processing/GeometryHelper.cpp | 2 - src/Utilities/GdalHelper.cpp | 4 +- 9 files changed, 37 insertions(+), 138 deletions(-) diff --git a/src/COM classes/Utils_OGR.cpp b/src/COM classes/Utils_OGR.cpp index d2efcd71..3035ef05 100644 --- a/src/COM classes/Utils_OGR.cpp +++ b/src/COM classes/Utils_OGR.cpp @@ -17,7 +17,6 @@ #include "vrtdataset.h" #pragma warning(disable:4996) -#define DISABLE_OGR2OGR 1 int CPL_STDCALL GDALProgressCallback(double dfComplete, const char* pszMessage, void* pData); @@ -49,7 +48,6 @@ typedef struct } AssociatedLayers; -#if GDAL_VERSION_MAJOR >= 3 static int TranslateLayer(TargetLayerInfo* psInfo, GDALDataset* poSrcDS, OGRLayer* poSrcLayer, @@ -59,7 +57,7 @@ static int TranslateLayer(TargetLayerInfo* psInfo, const char* pszDateLineOffset, const OGRSpatialReference* poOutputSRS, int bNullifyOutputSRS, - const OGRSpatialReference* poUserSourceSRS, + OGRSpatialReference* poUserSourceSRS, OGRCoordinateTransformation* poGCPCoordTrans, int eGType, int bPromoteToMulti, @@ -74,7 +72,7 @@ static int TranslateLayer(TargetLayerInfo* psInfo, GIntBig* pnReadFeatureCount, GDALProgressFunc pfnProgress, void* pProgressArg); -#endif + /* -------------------------------------------------------------------- */ /* CheckDestDataSourceNameConsistency() */ @@ -890,8 +888,8 @@ class GCPCoordTransformation : public OGRCoordinateTransformation poSRS->Dereference(); } - virtual const OGRSpatialReference* GetSourceCS() { return poSRS; } - virtual const OGRSpatialReference* GetTargetCS() { return poSRS; } + virtual OGRSpatialReference* GetSourceCS() { return poSRS; } + virtual OGRSpatialReference* GetTargetCS() { return poSRS; } virtual int Transform(int nCount, double* x, double* y, double* z) override @@ -1575,7 +1573,6 @@ __declspec(deprecated("This is a deprecated function, use CGdalUtils::GdalVector STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, BSTR bstrOptions, ICallback* cBack, VARIANT_BOOL* retval) { -#if !DISABLE_OGR2OGR USES_CONVERSION; struct CallbackParams params(GetCallback(), "Converting"); @@ -3066,10 +3063,6 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, * retval = nRetCode == 0 ? VARIANT_TRUE : VARIANT_FALSE; return ResetConfigOptions(tkNO_ERROR); -#else - *retval = VARIANT_FALSE; - return 0; -#endif } /************************************************************************/ @@ -3223,7 +3216,7 @@ class CompositeCT : public OGRCoordinateTransformation } - virtual const OGRSpatialReference* GetSourceCS() + virtual OGRSpatialReference* GetSourceCS() { return poCT1 ? poCT1->GetSourceCS() : poCT2 ? poCT2->GetSourceCS() : NULL; diff --git a/src/ComHelpers/ShapeHelper.cpp b/src/ComHelpers/ShapeHelper.cpp index 227bc385..7b449ac8 100644 --- a/src/ComHelpers/ShapeHelper.cpp +++ b/src/ComHelpers/ShapeHelper.cpp @@ -429,6 +429,7 @@ int ShapeHelper::GetContentLength(IShape* shp) } +#if DEBUG_LOG // ************************************************************* // DebugDump() // ************************************************************* @@ -442,7 +443,7 @@ void ShapeHelper::DebugDump(IShape* shp) shp->get_ShapeType(&shpType); if (numParts > 1) { - ::OutputDebugStringA("Not support NumParts > 1"); + ::OutputDebugStringA("Not supported, NumParts > 1"); return; } @@ -532,4 +533,4 @@ void ShapeHelper::DebugDump(IShape* shp) sOutput.Append("\r\n"); ::OutputDebugStringA(sOutput.GetBuffer()); } - +#endif diff --git a/src/ComHelpers/ShapeHelper.h b/src/ComHelpers/ShapeHelper.h index 5666ea81..315798d8 100644 --- a/src/ComHelpers/ShapeHelper.h +++ b/src/ComHelpers/ShapeHelper.h @@ -19,6 +19,8 @@ class ShapeHelper static void AddLabelToShape(IShape* shp, ILabels* labels, BSTR text, tkLabelPositioning method, tkLineLabelOrientation orientation, double offsetX, double offsetY); static IShape* CenterAsShape(IShape* shp); static int GetContentLength(IShape* shp); +#if DEBUG_LOG static void DebugDump(IShape* shp); +#endif }; diff --git a/src/ComHelpers/ShapefileHelper.cpp b/src/ComHelpers/ShapefileHelper.cpp index f4c3da65..ab29ee36 100644 --- a/src/ComHelpers/ShapefileHelper.cpp +++ b/src/ComHelpers/ShapefileHelper.cpp @@ -405,7 +405,7 @@ bool tryGetCloserPointForShape(IShape* shp, IShape* ptShp, double& minDist, doub resShp->get_Length(&distance); resShp->Release(); - // Check if this is allowed and/or smaller than the previous found point: + // Check if this is allowed and/or smaller than the previous found point: if (distance < minDist && distance < maxDistance) { fx = xPnt; fy = yPnt; @@ -488,11 +488,6 @@ bool ShapefileHelper::GetClosestSnapPosition(IShapefile* sf, double x, double y, else if (shptype == SHP_POLYGONZ) partShp->put_ShapeType(SHP_POLYLINEZ); - /*CString str; - str.Format("0x%016llx\r\n", shp); - const CComBSTR bstr(str); - partShp->put_Key(bstr); */ - // Insert part long part = 0; VARIANT_BOOL vbretval; diff --git a/src/Drawing/ShapefileDrawing.cpp b/src/Drawing/ShapefileDrawing.cpp index 89b51e32..6aab64a5 100644 --- a/src/Drawing/ShapefileDrawing.cpp +++ b/src/Drawing/ShapefileDrawing.cpp @@ -409,8 +409,8 @@ bool CShapefileDrawer::Draw(const CRect& rcBounds, IShapefile* sf) } } } + // Always draw selected objects, so the selection drawing can be drawn on top. - //else { long catIndex = (*_shapeData)[offset]->category; diff --git a/src/Grid/fip/gfstr.cpp b/src/Grid/fip/gfstr.cpp index 3aac018e..d36f07db 100644 --- a/src/Grid/fip/gfstr.cpp +++ b/src/Grid/fip/gfstr.cpp @@ -82,93 +82,34 @@ *****************************************************************************/ #include "stc123.h" -#if OLD_VERSION -int g123fstr_old(FILE *fp,char *buf_str,long str_len) -{ - /* LOCAL VARIABLES */ - char *tmpcptr; - long len; - long i = 1; - ldiv_t div_result; - - /* INITIALIZE LEN */ - len = 0; - - /* COMPUTE NUMBER OF TIMES TO READ STRING */ - div_result = ldiv(str_len,MAXINT); - - /* INITIALIZE STRING TO EMPTY */ - *buf_str = NC; - - /* SET TEMPORARY CHARACTER POINTER TO BUF_PTR */ - tmpcptr = buf_str; - - /* WHILE HAVE MORE READS DO */ - while (div_result.quot >= 0) { - - /* IF QUOTIENT IS GREATER THAN ZERO { STR_LEN > MAXINT } */ - if (div_result.quot > 0) { - - /* READ IN CHARACTER STRING */ - if ((len += fread(tmpcptr,sizeof(char),(size_t)(MAXINT),fp)) != MAXINT) return(0); - - /* TERMINATE TMPCPTR WITH NULL CHARACTER */ - tmpcptr[len] = NC; - - /* INCREMENT STRING POINTER */ - for (i=1; i<= MAXINT; i++) tmpcptr++; - - } - else { - - /* READ IN CHARACTER STRING */ - if ((len += fread(tmpcptr,sizeof(char),(size_t)(div_result.rem),fp)) != div_result.rem) return(0); - - /* TERMINATE TMPCPTR WITH NULL CHARACTER */ - tmpcptr[len] = NC; - }; - - /* DECREMENT QUOTIENT COUNTER */ - div_result.quot--; - - }; - - /* IF LEN NOT EQUAL TO STR_LEN, RETURN FAILURE */ - if (len != str_len) return(0); - - /*RETURN SUCCESS */ - return(1); -} -#endif - int g123fstr(FILE* fp, char* buf_str, long str_len) { - /* LOCAL VARIABLES */ - char* tmpcptr; - long remaining; - - /* BASIC VALIDATION */ - if (fp == NULL || buf_str == NULL || str_len < 0) return(0); + /* LOCAL VARIABLES */ + char* tmpCptr; + long remaining; - /* INITIALIZE POINTERS */ - tmpcptr = buf_str; - remaining = str_len; + /* BASIC VALIDATION */ + if (fp == nullptr || buf_str == nullptr || str_len < 0) + return(0); - /* READ THE FULL STRING IN CHUNKS */ - while (remaining > 0) { + /* INITIALIZE POINTERS */ + tmpCptr = buf_str; + remaining = str_len; - size_t chunk = (remaining > MAXINT) ? (size_t)MAXINT : (size_t)remaining; - size_t read_len = fread(tmpcptr, sizeof(char), chunk, fp); + /* READ THE FULL STRING IN CHUNKS */ + while(remaining > 0) { + size_t chunk = (remaining > MAXINT) ? static_cast(MAXINT) : static_cast(remaining); + size_t read_len = fread(tmpCptr, sizeof(char), chunk, fp); - if (read_len != chunk) return(0); + if (read_len != chunk) return(0); - tmpcptr += read_len; - remaining -= (long)read_len; - } + tmpCptr += read_len; + remaining -= static_cast(read_len); + } - /* APPEND NULL CHARACTER ONCE, AT THE END */ - *tmpcptr = NC; + /* APPEND NULL CHARACTER ONCE, AT THE END */ + *tmpCptr = NC; - /* RETURN SUCCESS */ - return(1); + /* RETURN SUCCESS */ + return(1); } \ No newline at end of file diff --git a/src/MapControl/Map_Events.cpp b/src/MapControl/Map_Events.cpp index a3db8a2b..7b072f3f 100644 --- a/src/MapControl/Map_Events.cpp +++ b/src/MapControl/Map_Events.cpp @@ -551,6 +551,7 @@ void CMapView::OnLButtonDown(UINT nFlags, CPoint point) if (m_cursorMode == cmAddShape) { if (StartNewBoundShape(projX, projY) != VARIANT_TRUE) return; } + if (alt) { // user wants to intercept coordinates and possibly modify them this->FireBeforeVertexDigitized(&projX, &projY, -1); } @@ -568,29 +569,15 @@ void CMapView::OnLButtonDown(UINT nFlags, CPoint point) { case cmEditShape: { - if( m_sendMouseDown == TRUE ) + if (m_sendMouseDown == TRUE) this->FireMouseDown(MK_LBUTTON, (short)vbflags, x, y); if (!VertexEditor::OnMouseDown(this, _shapeEditor, projX, projY, ctrl, shift)) { -#if DEBUG_ALLOCATED_OBJECTS - ComHelper::SetBreak(true); - auto preCount = gReferenceCounter.GetReferenceCount(); -#endif long layerHandle, shapeIndex; if (SelectShapeForEditing(x, y, layerHandle, shapeIndex)) { VertexEditor::StartEdit(_shapeEditor, layerHandle, shapeIndex); } -#if DEBUG_ALLOCATED_OBJECTS - auto postCount = gReferenceCounter.GetReferenceCount(); - if (preCount < postCount) - { - ::OutputDebugStringA("Increased!"); - auto report = gReferenceCounter.GetReferenceReport(); - ::OutputDebugStringA(report.GetBuffer()); - } - ComHelper::SetBreak(false); -#endif } UpdateShapeEditor(); } @@ -805,13 +792,7 @@ void CMapView::OnLButtonUp(UINT nFlags, CPoint point) case DragZoombox: case DragSelectionBox: { -#if DEBUG_ALLOCATED_OBJECTS - ComHelper::SetBreak(false); -#endif HandleLButtonUpZoomBox(vbflags, point.x, point.y); -#if DEBUG_ALLOCATED_OBJECTS - ComHelper::SetBreak(false); -#endif } break; } @@ -1448,9 +1429,6 @@ void CMapView::OnMouseMove(UINT nFlags, CPoint point) if (updateHotTracking && _dragging.Operation == DragNone) { LayerShape info; -#if DEBUG_ALLOCATED_OBJECTS - ComHelper::SetBreak(false); -#endif HotTrackingResult result = RecalcHotTracking(point, info); switch (result) { @@ -1467,9 +1445,6 @@ void CMapView::OnMouseMove(UINT nFlags, CPoint point) // do nothing break; } -#if DEBUG_ALLOCATED_OBJECTS - ComHelper::SetBreak(false); -#endif } if (_showCoordinates != cdmNone) { @@ -1552,14 +1527,8 @@ void CMapView::OnRButtonDown(UINT nFlags, CPoint point) long vbflags = ParseKeyboardEventFlags(nFlags); -#if DEBUG_ALLOCATED_OBJECTS - ComHelper::SetBreak(false); -#endif if( m_sendMouseDown == TRUE ) this->FireMouseDown( MK_RBUTTON, (short)vbflags, point.x, point.y ); -#if DEBUG_ALLOCATED_OBJECTS - ComHelper::SetBreak(false); -#endif if (_doTrapRMouseDown) { diff --git a/src/Processing/GeometryHelper.cpp b/src/Processing/GeometryHelper.cpp index cffec066..5ce35ffc 100644 --- a/src/Processing/GeometryHelper.cpp +++ b/src/Processing/GeometryHelper.cpp @@ -241,8 +241,6 @@ tkExtentsRelation GeometryHelper::RelateExtents(CRect& r1, CRect& r2) //************************************************************************** bool GeometryHelper::PointInExtent(double xMin, double yMin, double xMax, double yMax, double ptX, double ptY) { - //xMin, yMin, xMax, yMax - if ((ptX < xMin && ptX < xMax) || (ptX > xMin && ptX > xMax) || (ptY < yMin && ptY < yMax) || (ptY > yMin && ptY > yMax)) { diff --git a/src/Utilities/GdalHelper.cpp b/src/Utilities/GdalHelper.cpp index cec38a99..fa8f6b80 100644 --- a/src/Utilities/GdalHelper.cpp +++ b/src/Utilities/GdalHelper.cpp @@ -113,7 +113,7 @@ int GdalHelper::CloseSharedOgrDataset(GDALDataset* ds) const int count = ds->Dereference(); if (count == 0) { - Debug::WriteLine("Shared datasource(%s) is closed.", ds->GetDescription()); + //Debug::WriteLine("Shared datasource(%s) is closed.", ds->GetDescription()); RemoveCachedOgrDataset(ds); GDALClose(ds); } @@ -139,7 +139,7 @@ void GdalHelper::RemoveCachedOgrDataset(GDALDataset* ds) { if (it->second == ds) { - Debug::WriteLine("RemoveCachedOgrDataset(ds: %s)", it->first.GetString()); + //Debug::WriteLine("RemoveCachedOgrDataset(ds: %s)", it->first.GetString()); m_ogrDatasets.erase(it->first); break; } From a0b1388e6d5ba1a3932d82d2225ffb53c19aacba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hed=C3=A9n?= Date: Thu, 30 Jul 2026 19:09:17 +0200 Subject: [PATCH 55/55] Cleanup and fixed build warnings. --- InstallVcpkgPackages.ps1 | 2 +- src/COM classes/Chart.cpp | 10 +- src/COM classes/Charts.cpp | 80 +- src/COM classes/ColorScheme.cpp | 8 +- src/COM classes/Expression.cpp | 32 +- src/COM classes/FieldStatOperations.cpp | 28 +- src/COM classes/Function.cpp | 34 +- src/COM classes/GeoProjection.cpp | 70 +- src/COM classes/Grid.cpp | 452 ++++----- src/COM classes/GridColorScheme.cpp | 126 +-- src/COM classes/Image.cpp | 461 +++++----- src/COM classes/Labels.cpp | 158 ++-- src/COM classes/Labels.h | 10 +- src/COM classes/LinePattern.cpp | 78 +- src/COM classes/LineSegment.cpp | 46 +- src/COM classes/OgrLayer.cpp | 173 ++-- src/COM classes/SelectionList.cpp | 50 +- src/COM classes/ShapeDrawingOptions.cpp | 530 ++++++----- src/COM classes/ShapeNetwork.cpp | 955 ++++++++++---------- src/COM classes/ShapefileCategories.cpp | 212 ++--- src/COM classes/Shapefile_Edit.cpp | 245 +++-- src/COM classes/Shapefile_Geoprocessing.cpp | 107 ++- src/COM classes/Shapefile_ReadWrite.cpp | 131 ++- src/COM classes/Shapefile_Selection.cpp | 22 +- src/COM classes/TableClass.cpp | 423 +++++---- src/COM classes/TableClass.h | 6 +- src/COM classes/TileProviders.cpp | 38 +- src/COM classes/UndoList.cpp | 82 +- src/COM classes/Utils.cpp | 182 ++-- src/COM classes/Utils_GDAL.cpp | 594 ++++++------ src/COM classes/Utils_GridToImage.cpp | 151 ++-- src/COM classes/Utils_OGR.cpp | 494 +++++----- src/COM classes/Utils_Projections.cpp | 10 +- src/COM classes/WmsLayer.h | 2 +- src/ComHelpers/SelectionHelper.cpp | 16 +- src/ComHelpers/ShapeHelper.cpp | 16 +- src/ComHelpers/ShapeHelper.h | 2 +- src/CopyTamasFiles.bat | 9 +- src/Drawing/ChartDrawing.cpp | 71 +- src/Drawing/DrawingOptions.cpp | 55 +- src/Drawing/LabelDrawing.cpp | 24 +- src/Drawing/ShapefileDrawing.cpp | 62 +- src/Drawing/TilesDrawer.cpp | 10 +- src/Editor/ActiveShape.cpp | 2 +- src/Editor/EditorBase.cpp | 28 +- src/Editor/GeoShape.cpp | 28 +- src/Editor/MeasuringBase.cpp | 8 +- src/Editor/UndoListHelper.cpp | 2 +- src/Grid/GridManager.cpp | 30 +- src/Grid/dGrid.cpp | 764 ++++++++-------- src/Grid/fGrid.cpp | 660 +++++++------- src/Grid/fip/a_toe.cpp | 4 +- src/Grid/fip/c_dddir.cpp | 6 +- src/Grid/fip/c_ddlead.cpp | 10 +- src/Grid/fip/c_drlead.cpp | 16 +- src/Grid/fip/chk_sfld.cpp | 14 +- src/Grid/fip/gdstr.cpp | 8 +- src/Grid/fip/gsstr.cpp | 4 +- src/Grid/fip/ld_tagp.cpp | 12 +- src/Grid/fip/load_fld.cpp | 215 +++-- src/Grid/fip/rd_fld.cpp | 106 +-- src/Grid/fip/rd_sfld.cpp | 40 +- src/Grid/fip/str_tok.cpp | 6 +- src/Grid/fip/wint.cpp | 2 +- src/Grid/fip/wr_ddsfl.cpp | 107 ++- src/Grid/lGrid.cpp | 747 ++++++++------- src/Grid/sgrid.cpp | 667 +++++++------- src/Grid/tkGridRaster.cpp | 383 ++++---- src/MapControl/Map_Cursors.cpp | 66 +- src/MapControl/Map_Drawing.cpp | 179 ++-- src/MapControl/Map_DrawingLayer.cpp | 58 +- src/MapControl/Map_Events.cpp | 81 +- src/MapControl/Map_Identifier.cpp | 42 +- src/MapControl/Map_ImageGrouping.cpp | 68 +- src/MapControl/Map_Layer.cpp | 86 +- src/MapControl/Map_Properties.cpp | 108 +-- src/MapControl/Map_Scale.cpp | 71 +- src/MapControl/Map_Snapshot.cpp | 105 ++- src/MapControl/ToolTipEx.cpp | 32 +- src/Ogr/GeosConverter.cpp | 18 +- src/Ogr/Ogr2RawData.cpp | 6 +- src/Processing/Base64.cpp | Bin 7870 -> 7906 bytes src/Processing/ClipperConverter.cpp | 66 +- src/Processing/CustomExpression.cpp | 53 +- src/Processing/CustomExpression.h | 7 +- src/Processing/ExpressionParser.cpp | 20 +- src/Processing/ExpressionParts.cpp | 6 +- src/Processing/ExpressionParts.h | 16 +- src/Processing/JenksBreaks.cpp | 26 +- src/Processing/PointInPolygon.h | 28 +- src/Processing/QTree.cpp | 7 +- src/ShapeNetwork/graph.cpp | 22 +- src/ShapeNetwork/heap.cpp | 27 +- src/Shapefile/ShapeWrapperCOM.h | 4 +- src/Shapefile/ShapefileReader.cpp | 38 +- src/Structures/DrawList.h | 30 +- src/Tiles/Caching/DiskCache.cpp | 6 +- src/Tiles/Caching/PrefetchManager.cpp | 10 +- src/Tiles/Caching/SQLiteCache.cpp | 88 +- src/Tiles/Http/SecureHttpClient.cpp | 18 +- src/Tiles/Projections/BaseProjection.h | 1 - src/Tiles/Projections/CustomProjection.cpp | 13 +- src/Tiles/Providers/BaseProvider.cpp | 12 +- src/Tiles/Providers/CustomTileProvider.cpp | 2 +- src/Tiles/TileManager.cpp | 2 +- src/Tin/TinHeap.cpp | 19 +- src/Tin/point_table.cpp | 2 +- src/Tin/point_table.h | 4 +- src/Tin/triangle_table.cpp | 26 +- src/Tin/vertex_table.cpp | 4 +- src/Utilities/ColoringGraph.cpp | 8 +- src/Utilities/FieldClassification.cpp | 24 +- src/Utilities/HashTable.h | 10 +- src/Utilities/RegistryKey.cpp | 89 +- src/Utilities/Templates.h | 38 +- src/Utilities/UtilityFunctions.cpp | 38 +- 116 files changed, 5852 insertions(+), 5968 deletions(-) diff --git a/InstallVcpkgPackages.ps1 b/InstallVcpkgPackages.ps1 index d5ed599e..16af2582 100644 --- a/InstallVcpkgPackages.ps1 +++ b/InstallVcpkgPackages.ps1 @@ -6,7 +6,7 @@ try { # Rename Control folder "Rename Control folder" - Rename-Item "$CurrentDir\src\Control" -NewName Control_ + #Rename-Item "$CurrentDir\src\Control" -NewName Control_ # Check vcpkg install: $VcpkgFolder = "$CurrentDir\src\vcpkg" diff --git a/src/COM classes/Chart.cpp b/src/COM classes/Chart.cpp index afa3334d..6e9b8fb5 100644 --- a/src/COM classes/Chart.cpp +++ b/src/COM classes/Chart.cpp @@ -95,8 +95,8 @@ STDMETHODIMP CChart::put_IsDrawn(VARIANT_BOOL newVal) // *********************************************************** STDMETHODIMP CChart::get_ScreenExtents(IExtents** retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - IExtents* ext = NULL; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + IExtents* ext = nullptr; if (_chartData->frame) { @@ -107,7 +107,7 @@ STDMETHODIMP CChart::get_ScreenExtents(IExtents** retval) } else { - *retval = NULL; + *retval = nullptr; } return S_OK; } @@ -122,13 +122,13 @@ char* CChart::get_ChartData() } void CChart::put_ChartData(char* newVal) { - if (newVal == NULL) return; + if (newVal == nullptr) return; // if the memory was allocated in this class we should free it; if (_canDelete) { delete _chartData; - _chartData = NULL; + _chartData = nullptr; } _chartData = reinterpret_cast(newVal); diff --git a/src/COM classes/Charts.cpp b/src/COM classes/Charts.cpp index 91f6fd77..a2d0f9d8 100644 --- a/src/COM classes/Charts.cpp +++ b/src/COM classes/Charts.cpp @@ -208,7 +208,7 @@ STDMETHODIMP CCharts::put_PieRotation(double newVal) STDMETHODIMP CCharts::get_NumFields(long* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retVal = _bars.size(); + *retVal = static_cast(_bars.size()); return S_OK; } @@ -219,7 +219,7 @@ STDMETHODIMP CCharts::AddField2(long FieldIndex, OLE_COLOR Color) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) VARIANT_BOOL vbretval; - this->InsertField2(_bars.size(), FieldIndex, Color, &vbretval); + this->InsertField2(static_cast(_bars.size()), FieldIndex, Color, &vbretval); return S_OK; } @@ -246,15 +246,15 @@ STDMETHODIMP CCharts::AddField(IChartField* Field, VARIANT_BOOL* retVal) STDMETHODIMP CCharts::InsertField2(long Index, long FieldIndex, OLE_COLOR Color, VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >(long)_bars.size()) + if (Index < 0 || Index >static_cast(_bars.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = VARIANT_FALSE; } else { - IChartField* chartField = NULL; - CoCreateInstance(CLSID_ChartField, NULL, CLSCTX_INPROC_SERVER, IID_IChartField, (void**)&chartField); + IChartField* chartField = nullptr; + CoCreateInstance(CLSID_ChartField, nullptr, CLSCTX_INPROC_SERVER, IID_IChartField, (void**)&chartField); if (chartField) { chartField->put_Index(FieldIndex); @@ -274,7 +274,7 @@ STDMETHODIMP CCharts::InsertField2(long Index, long FieldIndex, OLE_COLOR Color, STDMETHODIMP CCharts::InsertField(long Index, IChartField* Field, VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >(long)_bars.size()) + if (Index < 0 || Index >static_cast(_bars.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = VARIANT_FALSE; @@ -302,7 +302,7 @@ STDMETHODIMP CCharts::InsertField(long Index, IChartField* Field, VARIANT_BOOL* STDMETHODIMP CCharts::RemoveField(long Index, VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >(long)_bars.size()) + if (Index < 0 || Index >static_cast(_bars.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = VARIANT_FALSE; @@ -470,7 +470,7 @@ STDMETHODIMP CCharts::put_UseVariableRadius(VARIANT_BOOL newVal) STDMETHODIMP CCharts::get_Transparency(SHORT* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retVal = (short)_options.transparency; + *retVal = static_cast(_options.transparency); return S_OK; } STDMETHODIMP CCharts::put_Transparency(SHORT newVal) @@ -541,7 +541,7 @@ STDMETHODIMP CCharts::get_Chart(long ShapeIndex, IChart** retVal) if (!_shapefile) { ErrorMessage(tkPARENT_SHAPEFILE_NOT_EXISTS); - *retVal = NULL; + *retVal = nullptr; return S_OK; } else @@ -550,13 +550,13 @@ STDMETHODIMP CCharts::get_Chart(long ShapeIndex, IChart** retVal) if (ShapeIndex < 0 || ShapeIndex >(long)positions->size()) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); - *retVal = NULL; + *retVal = nullptr; return S_OK; } else { - IChart* chart = NULL; - CoCreateInstance(CLSID_Chart, NULL, CLSCTX_INPROC_SERVER, IID_IChart, (void**)&chart); + IChart* chart = nullptr; + CoCreateInstance(CLSID_Chart, nullptr, CLSCTX_INPROC_SERVER, IID_IChart, (void**)&chart); if (chart) { ShapeRecord* data = (*positions)[ShapeIndex]; @@ -575,7 +575,7 @@ STDMETHODIMP CCharts::get_Field(long FieldIndex, IChartField** retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (FieldIndex < 0 || FieldIndex >(long)_bars.size() - 1) + if (FieldIndex < 0 || FieldIndex >static_cast(_bars.size()) - 1) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); } @@ -686,10 +686,10 @@ STDMETHODIMP CCharts::Clear() std::vector* data = ((CShapefile*)sf)->get_ShapeVector(); for (unsigned int i = 0; i < data->size(); i++) { - if ((*data)[i]->chart != NULL) + if ((*data)[i]->chart != nullptr) { delete (*data)[i]->chart; - (*data)[i]->chart = NULL; + (*data)[i]->chart = nullptr; } } } @@ -712,7 +712,7 @@ STDMETHODIMP CCharts::DrawChart(int hdc, float x, float y, VARIANT_BOOL hideLabe return S_OK; } - CDC* dc = CDC::FromHandle((HDC)hdc); + CDC* dc = CDC::FromHandle(reinterpret_cast(static_cast(hdc))); *retVal = DrawChartCore(dc, x, y, hideLabels, backColor); return S_OK; } @@ -759,7 +759,7 @@ VARIANT_BOOL CCharts::DrawChartCore(CDC* dc, float x, float y, VARIANT_BOOL hide Gdiplus::SolidBrush brushBackground(clr); Gdiplus::Pen penBackground(clr); - CFont* oldFont = NULL; + CFont* oldFont = nullptr; CFont fnt; CBrush brushFrame(_options.valuesFrameColor); @@ -837,7 +837,7 @@ VARIANT_BOOL CCharts::DrawChartCore(CDC* dc, float x, float y, VARIANT_BOOL hide } else { - CComPtr fld = NULL; + CComPtr fld = nullptr; this->get_Field(j, &fld); fld->get_Color(&color); } @@ -1003,11 +1003,11 @@ VARIANT_BOOL CCharts::DrawChartCore(CDC* dc, float x, float y, VARIANT_BOOL hide } else { - IChartField* fld = NULL; + IChartField* fld = nullptr; this->get_Field(j, &fld); fld->get_Color(&color); fld->Release(); - fld = NULL; + fld = nullptr; } // initializing brushes @@ -1126,7 +1126,7 @@ VARIANT_BOOL CCharts::DrawChartCore(CDC* dc, float x, float y, VARIANT_BOOL hide ValueRectangle value; value.string = s; - // drawing frame + // drawing frame if (!vertical) { CRect r(rect->left - 2, rect->top, rect->right + 2, rect->bottom); @@ -1185,7 +1185,7 @@ STDMETHODIMP CCharts::get_IconWidth(long *retVal) AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_options.chartType == chtBarChart) { - int barCount = _bars.size() == 0 ? 1 : _bars.size(); + int barCount = static_cast(_bars.size()) == 0 ? 1 : static_cast(_bars.size()); *retVal = _options.barWidth * barCount + 2; if (_options.use3Dmode) *retVal += int(sqrt(2.0f) / 2.0 * _options.thickness); // 45 degrees @@ -1228,7 +1228,7 @@ STDMETHODIMP CCharts::get_ValuesFontName(BSTR* retval) USES_CONVERSION; *retval = OLE2BSTR(_options.valuesFontName); return S_OK; -}; +} STDMETHODIMP CCharts::put_ValuesFontName(BSTR newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) @@ -1236,7 +1236,7 @@ STDMETHODIMP CCharts::put_ValuesFontName(BSTR newVal) ::SysFreeString(_options.valuesFontName); _options.valuesFontName = OLE2BSTR(newVal); return S_OK; -}; +} // ***************************************************************** // Select() @@ -1258,7 +1258,7 @@ STDMETHODIMP CCharts::Select(IExtents* BoundingBox, long Tolerance, SelectMode S vector results; - IUtils* utils = NULL; + IUtils* utils = nullptr; CoCreateInstance(CLSID_Utils, NULL, CLSCTX_INPROC_SERVER, IID_IUtils, (void**)&utils); long numShapes; @@ -1268,7 +1268,7 @@ STDMETHODIMP CCharts::Select(IExtents* BoundingBox, long Tolerance, SelectMode S for (long i = 0; i < numShapes; i++) { - if ((*data)[i]->chart->isDrawn && (*data)[i]->chart->frame != NULL) + if ((*data)[i]->chart->isDrawn && (*data)[i]->chart->frame != nullptr) { CRect* frame = (*data)[i]->chart->frame; tkExtentsRelation relation = GeometryHelper::RelateExtents(box, *frame); @@ -1288,7 +1288,7 @@ STDMETHODIMP CCharts::Select(IExtents* BoundingBox, long Tolerance, SelectMode S (*retval) = Templates::Vector2SafeArray(&results, VT_I4, Indices); return S_OK; -}; +} #pragma region "Serialiation" @@ -1310,7 +1310,7 @@ CPLXMLNode* CCharts::SerializeCore(CString ElementName) { USES_CONVERSION; - CPLXMLNode* psTree = CPLCreateXMLNode(NULL, CXT_Element, "ChartsClass"); + CPLXMLNode* psTree = CPLCreateXMLNode(nullptr, CXT_Element, "ChartsClass"); CString str; // fields @@ -1511,19 +1511,19 @@ bool CCharts::DeserializeCore(CPLXMLNode* node) { if (strcmp(node->pszValue, "ChartFieldClass") == 0) { - IChartField* field = NULL; - CoCreateInstance(CLSID_ChartField, NULL, CLSCTX_INPROC_SERVER, IID_IChartField, (void**)&field); + IChartField* field = nullptr; + CoCreateInstance(CLSID_ChartField, nullptr, CLSCTX_INPROC_SERVER, IID_IChartField, (void**)&field); // name - s = CPLGetXMLValue(node, "Name", NULL); + s = CPLGetXMLValue(node, "Name", nullptr); CComBSTR vbstr(s); field->put_Name(vbstr); - s = CPLGetXMLValue(node, "Color", NULL); + s = CPLGetXMLValue(node, "Color", nullptr); OLE_COLOR color = atoi(s); field->put_Color(color); - s = CPLGetXMLValue(node, "Index", NULL); + s = CPLGetXMLValue(node, "Index", nullptr); long index = atoi(s); field->put_Index(index); @@ -1707,7 +1707,7 @@ STDMETHODIMP CCharts::SaveToXML(BSTR Filename, VARIANT_BOOL* retVal) return S_OK; } - CPLXMLNode *psTree = CPLCreateXMLNode(NULL, CXT_Element, "MapWindow"); + CPLXMLNode *psTree = CPLCreateXMLNode(nullptr, CXT_Element, "MapWindow"); if (psTree) { Utility::WriteXmlHeaderAttributes(psTree, "Charts"); @@ -1731,17 +1731,17 @@ STDMETHODIMP CCharts::SaveToXML(BSTR Filename, VARIANT_BOOL* retVal) // ******************************************************** CPLXMLNode* CCharts::SerializeChartData(CString ElementName) { - CPLXMLNode* psCharts = CPLCreateXMLNode(NULL, CXT_Element, ElementName); + CPLXMLNode* psCharts = CPLCreateXMLNode(nullptr, CXT_Element, ElementName); if (psCharts) { if (!_shapefile) - return NULL; + return nullptr; std::vector* data = ((CShapefile*)_shapefile)->get_ShapeVector(); if (data) { - CPLXMLNode* nodeOld = NULL; - CPLXMLNode* nodeNew = NULL; + CPLXMLNode* nodeOld = nullptr; + CPLXMLNode* nodeNew = nullptr; for (unsigned int i = 0; i < data->size(); i++) { @@ -1751,7 +1751,7 @@ CPLXMLNode* CCharts::SerializeChartData(CString ElementName) } else { - nodeNew = CPLCreateXMLNode(NULL, CXT_Element, "Chart"); + nodeNew = CPLCreateXMLNode(nullptr, CXT_Element, "Chart"); CPLAddXMLSibling(nodeOld, nodeNew); nodeOld = nodeNew; } @@ -1841,7 +1841,7 @@ bool CCharts::DeserializeChartData(CPLXMLNode* node) node = CPLGetXMLNode(node, "Chart"); - int count = data->size(); + int count = static_cast(data->size()); while (node && i < count) { s = CPLGetXMLValue(node, "X", "0.0"); diff --git a/src/COM classes/ColorScheme.cpp b/src/COM classes/ColorScheme.cpp index ba421d58..bfcc8c85 100644 --- a/src/COM classes/ColorScheme.cpp +++ b/src/COM classes/ColorScheme.cpp @@ -157,7 +157,7 @@ STDMETHODIMP CColorScheme::SetColors4 (PredefinedColorScheme Scheme) _breaks.clear(); - int size = colors.size(); + int size = static_cast(colors.size()); for (int i = 0; i < size; i++) { ColorBreak br; @@ -234,7 +234,7 @@ STDMETHODIMP CColorScheme::Remove(long Index, VARIANT_BOOL* retVal) STDMETHODIMP CColorScheme::get_NumBreaks(long * retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retVal = _breaks.size(); + *retVal = static_cast(_breaks.size()); return S_OK; } @@ -285,7 +285,7 @@ STDMETHODIMP CColorScheme::get_RandomColor(double Value, OLE_COLOR* retVal) // the specified value is too big (there is no such big value in color scheme), we'll use the last interval in this case if (index == 0) { - index = _breaks.size() - 1; + index = static_cast(_breaks.size()) - 1; Value = _breaks[index].value; } @@ -343,7 +343,7 @@ STDMETHODIMP CColorScheme::get_GraduatedColor(double Value, OLE_COLOR* retVal) // the specified value is to big (there is no such big value in color scheme), we'll use the last interval in this case if (index == 0) { - index = _breaks.size() - 1; + index = static_cast(_breaks.size()) - 1; Value = _breaks[index].value; } diff --git a/src/COM classes/Expression.cpp b/src/COM classes/Expression.cpp index 49b3ade0..9da8c556 100644 --- a/src/COM classes/Expression.cpp +++ b/src/COM classes/Expression.cpp @@ -12,7 +12,7 @@ void CExpression::Clear() if (_table) { _table->Release(); - _table = NULL; + _table = nullptr; } } @@ -35,7 +35,7 @@ bool CExpression::ValidateExpression() // ********************************************************** STDMETHODIMP CExpression::get_LastErrorMessage(BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = W2BSTR(_lastErrorMessage); @@ -47,7 +47,7 @@ STDMETHODIMP CExpression::get_LastErrorMessage(BSTR* pVal) // ********************************************************** STDMETHODIMP CExpression::get_LastErrorPosition(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _lastErrorPosition; @@ -59,9 +59,9 @@ STDMETHODIMP CExpression::get_LastErrorPosition(LONG* pVal) // ********************************************************** STDMETHODIMP CExpression::get_NumSupportedFunctions(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *pVal = parser::functions.size(); + *pVal = static_cast(parser::functions.size()); return S_OK; } @@ -71,19 +71,19 @@ STDMETHODIMP CExpression::get_NumSupportedFunctions(LONG* pVal) // ********************************************************** STDMETHODIMP CExpression::get_SupportedFunction(LONG functionIndex, IFunction** pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *pVal = NULL; + *pVal = nullptr; vector list = parser::functions; - if (functionIndex < 0 || functionIndex >= (int)list.size()) + if (functionIndex < 0 || functionIndex >= static_cast(list.size())) { CallbackHelper::ErrorMsg("CExpression::get_SupportedFunction: index out of bounds"); return S_OK; } - IFunction* fn = NULL; + IFunction* fn = nullptr; ComHelper::CreateInstance(idFunction, (IDispatch**)&fn); ((CFunction*)fn)->Inject(list[functionIndex]); @@ -97,7 +97,7 @@ STDMETHODIMP CExpression::get_SupportedFunction(LONG functionIndex, IFunction** // ********************************************************** STDMETHODIMP CExpression::Parse(BSTR expr, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; @@ -114,7 +114,7 @@ STDMETHODIMP CExpression::Parse(BSTR expr, VARIANT_BOOL* retVal) // ********************************************************** STDMETHODIMP CExpression::ParseForTable(BSTR expr, ITable* table, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; @@ -141,7 +141,7 @@ STDMETHODIMP CExpression::ParseForTable(BSTR expr, ITable* table, VARIANT_BOOL* // ********************************************************** STDMETHODIMP CExpression::Calculate(VARIANT* result, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; @@ -160,7 +160,7 @@ STDMETHODIMP CExpression::Calculate(VARIANT* result, VARIANT_BOOL* retVal) // ********************************************************** STDMETHODIMP CExpression::CalculateForTableRow2(LONG rowIndex, VARIANT* result, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; @@ -187,7 +187,7 @@ STDMETHODIMP CExpression::CalculateForTableRow2(LONG rowIndex, VARIANT* result, // ********************************************************** STDMETHODIMP CExpression::CalculateForTableRow(LONG rowIndex, LONG targetFieldIndex, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; @@ -267,9 +267,9 @@ void CExpression::SetVariant(CExpressionValue* value, VARIANT* result) // ********************************************************** STDMETHODIMP CExpression::get_Table(ITable** pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (_table) { + if (_table) { _table->AddRef(); } diff --git a/src/COM classes/FieldStatOperations.cpp b/src/COM classes/FieldStatOperations.cpp index e66f8cdb..c8845b3a 100644 --- a/src/COM classes/FieldStatOperations.cpp +++ b/src/COM classes/FieldStatOperations.cpp @@ -53,7 +53,7 @@ STDMETHODIMP CFieldStatOperations::get_ErrorMsg(long ErrorCode, BSTR *pVal) STDMETHODIMP CFieldStatOperations::get_FieldIndex(int index, int* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if( index < 0 || index >= (long)_operations.size() ) + if( index < 0 || index >= static_cast(_operations.size()) ) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = -1; @@ -63,7 +63,7 @@ STDMETHODIMP CFieldStatOperations::get_FieldIndex(int index, int* retVal) *retVal = _operations[index]->fieldIndex; } return S_OK; -}; +} //**************************************************************** // get_FieldName() @@ -71,7 +71,7 @@ STDMETHODIMP CFieldStatOperations::get_FieldIndex(int index, int* retVal) STDMETHODIMP CFieldStatOperations::get_FieldName(int index, BSTR* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if( index < 0 || index >= (long)_operations.size() ) + if( index < 0 || index >= static_cast(_operations.size()) ) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = A2BSTR(""); @@ -81,7 +81,7 @@ STDMETHODIMP CFieldStatOperations::get_FieldName(int index, BSTR* retVal) *retVal = W2BSTR(_operations[index]->fieldName); } return S_OK; -}; +} //**************************************************************** // get_Operation() @@ -89,7 +89,7 @@ STDMETHODIMP CFieldStatOperations::get_FieldName(int index, BSTR* retVal) STDMETHODIMP CFieldStatOperations::get_Operation(int index, tkFieldStatOperation* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if( index < 0 || index >= (long)_operations.size() ) + if( index < 0 || index >= static_cast(_operations.size()) ) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = (tkFieldStatOperation)0; @@ -99,7 +99,7 @@ STDMETHODIMP CFieldStatOperations::get_Operation(int index, tkFieldStatOperation *retVal = _operations[index]->operation; } return S_OK; -}; +} //**************************************************************** // get_Count() @@ -107,9 +107,9 @@ STDMETHODIMP CFieldStatOperations::get_Operation(int index, tkFieldStatOperation STDMETHODIMP CFieldStatOperations::get_Count(int* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retVal = _operations.size(); + *retVal = static_cast(_operations.size()); return S_OK; -}; +} // *************************************************************** // AddFieldIndex() @@ -149,7 +149,7 @@ STDMETHODIMP CFieldStatOperations::Remove(int index, VARIANT_BOOL* retVal) AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; - if( index < 0 || index >= (long)_operations.size() ) + if( index < 0 || index >= static_cast(_operations.size()) ) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = VARIANT_FALSE; @@ -202,7 +202,7 @@ STDMETHODIMP CFieldStatOperations::Validate(IShapefile* sf, VARIANT_BOOL* retVal // searching index for name if (op->hasName) { - CComPtr table = NULL; + CComPtr table = nullptr; sf->get_Table(&table); if (table) { @@ -212,8 +212,8 @@ STDMETHODIMP CFieldStatOperations::Validate(IShapefile* sf, VARIANT_BOOL* retVal op->fieldIndex = fieldIndex; } } - - IField* field = NULL; + + IField* field = nullptr; if (op->fieldIndex >= 0 && op->fieldIndex < numFields) { sf->get_Field(op->fieldIndex, &field); @@ -254,7 +254,7 @@ STDMETHODIMP CFieldStatOperations::Validate(IShapefile* sf, VARIANT_BOOL* retVal STDMETHODIMP CFieldStatOperations::get_OperationIsValid(int index, VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if( index < 0 || index >= (long)_operations.size() ) + if( index < 0 || index >= static_cast(_operations.size()) ) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = VARIANT_FALSE; @@ -272,7 +272,7 @@ STDMETHODIMP CFieldStatOperations::get_OperationIsValid(int index, VARIANT_BOOL* STDMETHODIMP CFieldStatOperations::get_OperationIsValidReason(int index, tkFieldOperationValidity* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if( index < 0 || index >= (long)_operations.size() ) + if( index < 0 || index >= static_cast(_operations.size()) ) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = fovValid; diff --git a/src/COM classes/Function.cpp b/src/COM classes/Function.cpp index 8d3fd172..ed9fefc0 100644 --- a/src/COM classes/Function.cpp +++ b/src/COM classes/Function.cpp @@ -20,9 +20,9 @@ bool CFunction::Validate() // ********************************************************** STDMETHODIMP CFunction::get_Name(BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - - if (!Validate()) + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + + if (!Validate()) { *pVal = m_globalSettings.CreateEmptyBSTR(); return S_OK; @@ -39,7 +39,7 @@ STDMETHODIMP CFunction::get_Name(BSTR* pVal) // ********************************************************** STDMETHODIMP CFunction::get_Alias(long aliasIndex, BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (Validate()) { @@ -47,7 +47,7 @@ STDMETHODIMP CFunction::get_Alias(long aliasIndex, BSTR* pVal) vector* aliases = _function->getAliases(); - if (aliasIndex <= 0 || aliasIndex >= (long)aliases->size()) + if (aliasIndex <= 0 || aliasIndex >= static_cast(aliases->size())) { CallbackHelper::ErrorMsg("Function::get_Alias: index out of bounds."); } @@ -67,9 +67,9 @@ STDMETHODIMP CFunction::get_Alias(long aliasIndex, BSTR* pVal) // ********************************************************** STDMETHODIMP CFunction::get_NumAliases(long* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (!Validate()) + if (!Validate()) { *pVal = 0; return S_OK; @@ -77,7 +77,7 @@ STDMETHODIMP CFunction::get_NumAliases(long* pVal) vector* aliases = _function->getAliases(); - *pVal = aliases->size() - 1; + *pVal = static_cast(aliases->size()) - 1; if (*pVal == -1) { *pVal = 0; @@ -91,7 +91,7 @@ STDMETHODIMP CFunction::get_NumAliases(long* pVal) // ********************************************************** STDMETHODIMP CFunction::get_NumParameters(long* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!Validate()) { @@ -109,7 +109,7 @@ STDMETHODIMP CFunction::get_NumParameters(long* pVal) // ********************************************************** STDMETHODIMP CFunction::get_Group(tkFunctionGroup* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!Validate()) { @@ -127,7 +127,7 @@ STDMETHODIMP CFunction::get_Group(tkFunctionGroup* pVal) // ********************************************************** STDMETHODIMP CFunction::get_Description(BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (Validate()) { @@ -143,7 +143,7 @@ STDMETHODIMP CFunction::get_Description(BSTR* pVal) STDMETHODIMP CFunction::put_Description(BSTR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // may be useful for localization, currently not exposed to API @@ -155,7 +155,7 @@ STDMETHODIMP CFunction::put_Description(BSTR newVal) // ********************************************************** STDMETHODIMP CFunction::get_ParameterName(LONG parameterIndex, BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!Validate()) { @@ -183,7 +183,7 @@ STDMETHODIMP CFunction::get_ParameterName(LONG parameterIndex, BSTR* pVal) STDMETHODIMP CFunction::put_ParameterName(LONG parameterIndex, BSTR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // may be useful for localization, currently not exposed to API @@ -195,7 +195,7 @@ STDMETHODIMP CFunction::put_ParameterName(LONG parameterIndex, BSTR newVal) // ********************************************************** STDMETHODIMP CFunction::get_ParameterDescription(LONG parameterIndex, BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!Validate()) { @@ -223,7 +223,7 @@ STDMETHODIMP CFunction::get_ParameterDescription(LONG parameterIndex, BSTR* pVal STDMETHODIMP CFunction::put_ParameterDescription(LONG parameterIndex, BSTR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // may be useful for localization, currently not exposed to API @@ -235,7 +235,7 @@ STDMETHODIMP CFunction::put_ParameterDescription(LONG parameterIndex, BSTR newVa // ********************************************************** STDMETHODIMP CFunction::get_Signature(BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (Validate()) { diff --git a/src/COM classes/GeoProjection.cpp b/src/COM classes/GeoProjection.cpp index b5001a46..2f7f7e3a 100644 --- a/src/COM classes/GeoProjection.cpp +++ b/src/COM classes/GeoProjection.cpp @@ -177,7 +177,7 @@ STDMETHODIMP CGeoProjection::put_Key(BSTR newVal) // ******************************************************* STDMETHODIMP CGeoProjection::ExportToProj4(BSTR* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const OGR_SRSNode* node = _projection->GetRoot(); // no need to generate GDAL errors, if know that it's empty if (!node) { @@ -207,7 +207,7 @@ STDMETHODIMP CGeoProjection::ExportToProj4(BSTR* retVal) // ******************************************************* STDMETHODIMP CGeoProjection::ImportFromProj4(BSTR proj, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_isFrozen) { @@ -239,7 +239,7 @@ STDMETHODIMP CGeoProjection::ImportFromProj4(BSTR proj, VARIANT_BOOL* retVal) // ******************************************************* STDMETHODIMP CGeoProjection::Clear(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_isFrozen) { ErrorMessage(tkPROJECTION_IS_FROZEN); @@ -260,7 +260,7 @@ STDMETHODIMP CGeoProjection::Clear(VARIANT_BOOL* retVal) // ******************************************************* STDMETHODIMP CGeoProjection::Clone(IGeoProjection** retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) IGeoProjection* gp; ComHelper::CreateInstance(idGeoProjection, reinterpret_cast(&gp)); @@ -310,7 +310,7 @@ STDMETHODIMP CGeoProjection::ImportFromESRI(const BSTR proj, VARIANT_BOOL* retVa // ******************************************************* STDMETHODIMP CGeoProjection::ImportFromEPSG(const LONG projCode, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_isFrozen) { ErrorMessage(tkPROJECTION_IS_FROZEN); @@ -337,7 +337,7 @@ STDMETHODIMP CGeoProjection::ExportToWKT(BSTR* retVal) AFX_MANAGE_STATE(AfxGetStaticModuleState()) const OGR_SRSNode* node = _projection->GetRoot(); // no need to generate GDAL errors, if know that it's empty - if (!node) + if (!node) { *retVal = A2BSTR(""); return S_OK; @@ -368,7 +368,7 @@ STDMETHODIMP CGeoProjection::ExportToWKT(BSTR* retVal) // ******************************************************* STDMETHODIMP CGeoProjection::ExportToWktEx(BSTR* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const OGR_SRSNode* node = _projection->GetRoot(); // no need to generate GDAL errors, if know that it's empty if (!node) @@ -603,7 +603,7 @@ bool CGeoProjection::IsSameProjection(OGRCoordinateTransformation* transf, doubl // ******************************************************* STDMETHODIMP CGeoProjection::get_IsSameExt(IGeoProjection* proj, IExtents* bounds, int numSamplingPoints, VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = VARIANT_FALSE; if (!proj || !bounds) @@ -701,7 +701,7 @@ STDMETHODIMP CGeoProjection::get_IsSameExt(IGeoProjection* proj, IExtents* bound // ******************************************************* STDMETHODIMP CGeoProjection::get_IsSameGeogCS(IGeoProjection* proj, VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!proj) { ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); @@ -720,7 +720,7 @@ STDMETHODIMP CGeoProjection::get_IsSameGeogCS(IGeoProjection* proj, VARIANT_BOOL // ******************************************************* STDMETHODIMP CGeoProjection::get_InverseFlattening(DOUBLE* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) OGRErr err = OGRERR_NONE; *pVal = _projection->GetInvFlattening(&err); if (err != OGRERR_NONE) @@ -735,7 +735,7 @@ STDMETHODIMP CGeoProjection::get_InverseFlattening(DOUBLE* pVal) // ******************************************************* STDMETHODIMP CGeoProjection::get_SemiMajor(DOUBLE* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) OGRErr err = OGRERR_NONE; *pVal = _projection->GetSemiMajor(&err); if (err != OGRERR_NONE) @@ -750,7 +750,7 @@ STDMETHODIMP CGeoProjection::get_SemiMajor(DOUBLE* pVal) // ******************************************************* STDMETHODIMP CGeoProjection::get_SemiMinor(DOUBLE* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) OGRErr err = OGRERR_NONE; *pVal = _projection->GetSemiMinor(&err); if (err != OGRERR_NONE) @@ -765,7 +765,7 @@ STDMETHODIMP CGeoProjection::get_SemiMinor(DOUBLE* pVal) // ******************************************************* STDMETHODIMP CGeoProjection::get_ProjectionParam(tkProjectionParameter name, double* value, VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = VARIANT_FALSE; CString s; @@ -815,7 +815,7 @@ STDMETHODIMP CGeoProjection::get_ProjectionParam(tkProjectionParameter name, dou STDMETHODIMP CGeoProjection::get_IsEmpty(VARIANT_BOOL* retVal) { // https://gdal.org/api/ogrspatialref.html#_CPPv4NK19OGRSpatialReference7IsEmptyEv - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = _projection->IsEmpty() ? VARIANT_TRUE : VARIANT_FALSE; return S_OK; } @@ -825,7 +825,7 @@ STDMETHODIMP CGeoProjection::get_IsEmpty(VARIANT_BOOL* retVal) // ******************************************************* STDMETHODIMP CGeoProjection::CopyFrom(IGeoProjection* sourceProj, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; @@ -870,7 +870,7 @@ STDMETHODIMP CGeoProjection::CopyFrom(IGeoProjection* sourceProj, VARIANT_BOOL* // ******************************************************* STDMETHODIMP CGeoProjection::ReadFromFile(BSTR filename, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const CStringW filenameW(filename); @@ -884,7 +884,7 @@ STDMETHODIMP CGeoProjection::ReadFromFile(BSTR filename, VARIANT_BOOL* retVal) // ************************************************************ STDMETHODIMP CGeoProjection::ReadFromFileEx(BSTR filename, VARIANT_BOOL esri, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const CStringW filenameW = OLE2W(filename); @@ -964,7 +964,7 @@ bool CGeoProjection::ReadFromFileCore(CStringW filename, bool esri) // ******************************************************* STDMETHODIMP CGeoProjection::WriteToFile(BSTR filename, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const CStringW filenameW = OLE2W(filename); @@ -978,7 +978,7 @@ STDMETHODIMP CGeoProjection::WriteToFile(BSTR filename, VARIANT_BOOL* retVal) // ************************************************************ STDMETHODIMP CGeoProjection::WriteToFileEx(BSTR filename, VARIANT_BOOL esri, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const CStringW filenameW = OLE2W(filename); @@ -1030,7 +1030,7 @@ bool CGeoProjection::WriteToFileCore(CStringW filename, bool esri) // ******************************************************* STDMETHODIMP CGeoProjection::get_Name(BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_projection->IsGeographic()) { this->get_GeogCSName(pVal); @@ -1051,7 +1051,7 @@ STDMETHODIMP CGeoProjection::get_Name(BSTR* pVal) // ******************************************************* STDMETHODIMP CGeoProjection::get_ProjectionName(BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const char* name = _projection->GetAttrValue("PROJCS"); if (name) @@ -1067,7 +1067,7 @@ STDMETHODIMP CGeoProjection::get_ProjectionName(BSTR* pVal) // ******************************************************* STDMETHODIMP CGeoProjection::get_GeogCSName(BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const char* name = _projection->GetAttrValue("GEOGCS"); if (name) @@ -1083,7 +1083,7 @@ STDMETHODIMP CGeoProjection::get_GeogCSName(BSTR* pVal) // ******************************************************* STDMETHODIMP CGeoProjection::get_GeogCSParam(tkGeogCSParameter name, DOUBLE* pVal, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) OGRErr err = OGRERR_NONE; switch (name) @@ -1160,7 +1160,7 @@ STDMETHODIMP CGeoProjection::SetNad83Projection(tkNad83Projection projection) STDMETHODIMP CGeoProjection::get_HasTransformation(VARIANT_BOOL* retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = (_transformation != nullptr) ? VARIANT_TRUE : VARIANT_FALSE; return S_OK; } @@ -1170,7 +1170,7 @@ STDMETHODIMP CGeoProjection::get_HasTransformation(VARIANT_BOOL* retval) // *********************************************************** STDMETHODIMP CGeoProjection::StartTransform(IGeoProjection* target, VARIANT_BOOL* retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = VARIANT_FALSE; @@ -1217,7 +1217,7 @@ STDMETHODIMP CGeoProjection::StartTransform(IGeoProjection* target, VARIANT_BOOL // *********************************************************** STDMETHODIMP CGeoProjection::Transform(double* x, double* y, VARIANT_BOOL* retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!_transformation) { *retval = VARIANT_FALSE; @@ -1236,7 +1236,7 @@ STDMETHODIMP CGeoProjection::Transform(double* x, double* y, VARIANT_BOOL* retva // *********************************************************** STDMETHODIMP CGeoProjection::StopTransform() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_transformation) { OGRCoordinateTransformation::DestroyCT(_transformation); @@ -1250,7 +1250,7 @@ STDMETHODIMP CGeoProjection::StopTransform() // ************************************************************ STDMETHODIMP CGeoProjection::SetGoogleMercator(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: For GDAL3 Shouldn't this not be this->ImportFromEPSG(3857, retVal); @@ -1287,7 +1287,7 @@ STDMETHODIMP CGeoProjection::SetGoogleMercator(VARIANT_BOOL* retVal) // ************************************************************ STDMETHODIMP CGeoProjection::SetWgs84(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) #if GDAL_VERSION_MAJOR >= 3 @@ -1329,7 +1329,7 @@ STDMETHODIMP CGeoProjection::SetWgs84(VARIANT_BOOL* retVal) // ************************************************************ STDMETHODIMP CGeoProjection::get_IsFrozen(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = _isFrozen ? VARIANT_TRUE : VARIANT_FALSE; return S_OK; } @@ -1339,7 +1339,7 @@ STDMETHODIMP CGeoProjection::get_IsFrozen(VARIANT_BOOL* retVal) // ************************************************************ STDMETHODIMP CGeoProjection::TryAutoDetectEpsg(int* epsgCode, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *epsgCode = -1; if (!_isFrozen) { @@ -1453,7 +1453,7 @@ STDMETHODIMP CGeoProjection::ExportToEsri(BSTR* retVal) // ************************************************************ STDMETHODIMP CGeoProjection::get_LinearUnits(tkUnitsOfMeasure* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) char* s = nullptr; const double ratio = _projection->GetLinearUnits(&s); // don't free the memory, the string is internal to OGRSpatialReference @@ -1517,9 +1517,9 @@ std::string CGeoProjection::CorrectAxisOrder(CString wkt) std::string currentLine; int openCount = 0; // [ int commaCount = 0; - for (size_t i = 0; i < wkt.GetLength(); i++) + for (size_t i = 0; i < static_cast(wkt.GetLength()); i++) { - auto ch = wkt[i]; + auto ch = wkt[static_cast(i)]; if (ch == '\r' || ch == '\n') continue; else if (ch == '[') @@ -1587,4 +1587,4 @@ std::string CGeoProjection::CorrectAxisOrder(CString wkt) } return result; -} \ No newline at end of file +} diff --git a/src/COM classes/Grid.cpp b/src/COM classes/Grid.cpp index 422b01b4..4ef2b863 100644 --- a/src/COM classes/Grid.cpp +++ b/src/COM classes/Grid.cpp @@ -36,14 +36,14 @@ static char THIS_FILE[] = __FILE__; #endif // CGrid -CGrid * activeGridObject = NULL; +CGrid * activeGridObject = nullptr; // *************************************************** // gridCOMCALLBACK() // *************************************************** void gridCOMCALLBACK( int number, const char * message ) { - if( activeGridObject != NULL ) + if( activeGridObject != nullptr) activeGridObject->CallBack(number, message); } @@ -60,14 +60,14 @@ void CGrid::CallBack(long percent,const char * message) // *************************************************** CGrid::CGrid() { - _pUnkMarshaler = NULL; - _dgrid = NULL; - _fgrid = NULL; - _lgrid = NULL; - _sgrid = NULL; - _trgrid = NULL; - - _globalCallback = NULL; + _pUnkMarshaler = nullptr; + _dgrid = nullptr; + _fgrid = nullptr; + _lgrid = nullptr; + _sgrid = nullptr; + _trgrid = nullptr; + + _globalCallback = nullptr; _lastErrorCode = tkNO_ERROR; _key = SysAllocString(L""); _filename = L""; @@ -80,7 +80,7 @@ CGrid::CGrid() CGrid::~CGrid() { if( activeGridObject == this ) - activeGridObject = NULL; + activeGridObject = nullptr; VARIANT_BOOL retval; Close(&retval); @@ -98,7 +98,7 @@ CGrid::~CGrid() // Builds unique values color scheme for GDAL integer grids STDMETHODIMP CGrid::get_RasterColorTableColoringScheme(IGridColorScheme **pVal) { - *pVal = NULL; + *pVal = nullptr; if (!_trgrid) { return S_OK; } @@ -118,7 +118,7 @@ STDMETHODIMP CGrid::get_Header(IGridHeader **pVal) CoCreateInstance(CLSID_GridHeader, NULL, CLSCTX_INPROC_SERVER, IID_IGridHeader, (void**)pVal); CGridHeader* header = (CGridHeader*)(*pVal); - if (_trgrid != NULL) + if (_trgrid != nullptr) { // Make grid header double dX = _trgrid->getDX(); @@ -143,14 +143,14 @@ STDMETHODIMP CGrid::get_Header(IGridHeader **pVal) (*pVal)->put_ColorTable(cTbl); VariantClear(&ndv); - header->put_Owner((int*)(void*)_trgrid, (int*)NULL, (int*)NULL, (int*)NULL, (int*)NULL); + header->put_Owner((int*)(void*)_trgrid, (int*)nullptr, (int*)nullptr, (int*)nullptr, (int*)nullptr); } - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) { (*pVal)->put_dX(_dgrid->getHeader().getDx()); (*pVal)->put_dY(_dgrid->getHeader().getDy()); VARIANT ndv; - VariantInit(&ndv); + VariantInit(&ndv); ndv.vt = VT_R8; ndv.dblVal = _dgrid->getHeader().getNodataValue(); (*pVal)->put_NodataValue(ndv); @@ -163,14 +163,14 @@ STDMETHODIMP CGrid::get_Header(IGridHeader **pVal) (*pVal)->put_XllCenter(_dgrid->getHeader().getXllcenter()); (*pVal)->put_YllCenter(_dgrid->getHeader().getYllcenter()); VariantClear(&ndv); - header->put_Owner((int*)NULL, (int*)_dgrid, (int*)NULL, (int*)NULL, (int*)NULL); + header->put_Owner((int*)nullptr, (int*)_dgrid, (int*)nullptr, (int*)nullptr, (int*)nullptr); } - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) { (*pVal)->put_dX(_fgrid->getHeader().getDx()); (*pVal)->put_dY(_fgrid->getHeader().getDy()); VARIANT ndv; - VariantInit(&ndv); + VariantInit(&ndv); ndv.vt = VT_R4; ndv.fltVal = _fgrid->getHeader().getNodataValue(); (*pVal)->put_NodataValue(ndv); @@ -183,14 +183,14 @@ STDMETHODIMP CGrid::get_Header(IGridHeader **pVal) (*pVal)->put_XllCenter(_fgrid->getHeader().getXllcenter()); (*pVal)->put_YllCenter(_fgrid->getHeader().getYllcenter()); VariantClear(&ndv); - header->put_Owner((int*)NULL, (int*)NULL, (int*)NULL, (int*)NULL, (int*)_fgrid); + header->put_Owner((int*)nullptr, (int*)nullptr, (int*)nullptr, (int*)nullptr, (int*)_fgrid); } - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) { (*pVal)->put_dX(_lgrid->getHeader().getDx()); (*pVal)->put_dY(_lgrid->getHeader().getDy()); VARIANT ndv; - VariantInit(&ndv); + VariantInit(&ndv); ndv.vt = VT_I4; ndv.lVal = _lgrid->getHeader().getNodataValue(); (*pVal)->put_NodataValue(ndv); @@ -203,14 +203,14 @@ STDMETHODIMP CGrid::get_Header(IGridHeader **pVal) (*pVal)->put_XllCenter(_lgrid->getHeader().getXllcenter()); (*pVal)->put_YllCenter(_lgrid->getHeader().getYllcenter()); VariantClear(&ndv); - header->put_Owner((int*)NULL, (int*)NULL, (int*)NULL, (int*)_lgrid, (int*)NULL); + header->put_Owner((int*)nullptr, (int*)nullptr, (int*)nullptr, (int*)_lgrid, (int*)nullptr); } - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) { (*pVal)->put_dX(_sgrid->getHeader().getDx()); (*pVal)->put_dY(_sgrid->getHeader().getDy()); VARIANT ndv; - VariantInit(&ndv); + VariantInit(&ndv); ndv.vt = VT_I2; ndv.iVal = _sgrid->getHeader().getNodataValue(); (*pVal)->put_NodataValue(ndv); @@ -222,12 +222,12 @@ STDMETHODIMP CGrid::get_Header(IGridHeader **pVal) (*pVal)->put_NumberRows(_sgrid->getHeader().getNumberRows()); (*pVal)->put_XllCenter(_sgrid->getHeader().getXllcenter()); (*pVal)->put_YllCenter(_sgrid->getHeader().getYllcenter()); - VariantClear(&ndv); - header->put_Owner((int*)NULL, (int*)NULL, (int*)_sgrid, (int*)NULL, (int*)NULL); + VariantClear(&ndv); + header->put_Owner((int*)nullptr, (int*)nullptr, (int*)_sgrid, (int*)nullptr, (int*)nullptr); } else - { - *pVal = NULL; + { + *pVal = nullptr; ErrorMessage(tkGRID_NOT_INITIALIZED); } @@ -251,7 +251,7 @@ STDMETHODIMP CGrid::AssignNewProjection(BSTR projection, VARIANT_BOOL *retval) // SaveProjection() // *************************************************** // TODO: use geoprojection -void CGrid::SaveProjection(char* projection) +void CGrid::SaveProjection(char* projection) { try { @@ -259,7 +259,7 @@ void CGrid::SaveProjection(char* projection) if (projectionFilename != "") { - FILE * prjFile = NULL; + FILE * prjFile = nullptr; prjFile = _wfopen(projectionFilename, L"wb"); if (prjFile) { @@ -267,14 +267,14 @@ void CGrid::SaveProjection(char* projection) ProjectionTools * p = new ProjectionTools(); p->ToESRIWKTFromProj4(&wkt, projection); - if (wkt != NULL) + if (wkt != nullptr) { fprintf(prjFile, "%s", wkt); delete wkt; } fclose(prjFile); - prjFile = NULL; + prjFile = nullptr; delete p; //added by Lailin Chen 12/30/2005 } } @@ -291,29 +291,29 @@ void CGrid::set_ProjectionIntoHeader(char * projection) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if ( _trgrid != NULL) + if ( _trgrid != nullptr) { _trgrid->SetProjection(projection); } - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) { dHeader hdr = _dgrid->getHeader(); hdr.setProjection(projection); _dgrid->setHeader(hdr); } - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) { fHeader hdr = _fgrid->getHeader(); hdr.setProjection(projection); _fgrid->setHeader(hdr); } - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) { lHeader hdr = _lgrid->getHeader(); hdr.setProjection(projection); _lgrid->setHeader(hdr); } - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) { sHeader hdr = _sgrid->getHeader(); hdr.setProjection(projection); @@ -334,7 +334,7 @@ STDMETHODIMP CGrid::Resource(BSTR newSrcPath, VARIANT_BOOL *retval) USES_CONVERSION; Close(retval); - Open(newSrcPath, UnknownDataType, true, UseExtension, NULL, retval); + Open(newSrcPath, UnknownDataType, true, UseExtension, nullptr, retval); return S_OK; } @@ -347,12 +347,12 @@ void CGrid::GetRowCore(long Row, void *Vals, bool useDouble, VARIANT_BOOL * retv double* ValsDouble = reinterpret_cast(Vals); float* ValsFloat = reinterpret_cast(Vals); - if (_trgrid != NULL) + if (_trgrid != nullptr) { if (Row < 0 || Row >= _trgrid->getHeight() ) { _lastErrorCode = tkINDEX_OUT_OF_BOUNDS; - Vals = NULL; + Vals = nullptr; *retval = FALSE; } @@ -375,7 +375,7 @@ void CGrid::GetRowCore(long Row, void *Vals, bool useDouble, VARIANT_BOOL * retv } } } - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) { int ncols = _dgrid->getHeader().getNumberCols(); @@ -389,7 +389,7 @@ void CGrid::GetRowCore(long Row, void *Vals, bool useDouble, VARIANT_BOOL * retv } } } - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) { int ncols = _fgrid->getHeader().getNumberCols(); @@ -403,7 +403,7 @@ void CGrid::GetRowCore(long Row, void *Vals, bool useDouble, VARIANT_BOOL * retv } } } - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) { int ncols = _lgrid->getHeader().getNumberCols(); for (int i = 0; i < ncols; i++) @@ -416,7 +416,7 @@ void CGrid::GetRowCore(long Row, void *Vals, bool useDouble, VARIANT_BOOL * retv } } } - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) { int ncols = _sgrid->getHeader().getNumberCols(); for (int i = 0; i < ncols; i++) @@ -430,7 +430,7 @@ void CGrid::GetRowCore(long Row, void *Vals, bool useDouble, VARIANT_BOOL * retv } } else - { Vals = NULL; + { Vals = nullptr; ErrorMessage(tkGRID_NOT_INITIALIZED); *retval = S_OK; } @@ -462,15 +462,15 @@ STDMETHODIMP CGrid::GetRow2(long Row, double *Vals, VARIANT_BOOL * retval) // *************************************************** void CGrid::PutRowCore(long Row, void *Vals, bool useDouble, VARIANT_BOOL * retval) { - double* ValsDouble = reinterpret_cast(Vals); - float* ValsFloat = reinterpret_cast(Vals); + double* ValsDouble = static_cast(Vals); + float* ValsFloat = static_cast(Vals); if (_trgrid != NULL) { if (Row < 0 || Row >= _trgrid->getHeight() ) { _lastErrorCode = tkINDEX_OUT_OF_BOUNDS; - Vals = NULL; + Vals = nullptr; *retval = FALSE; } @@ -494,7 +494,7 @@ void CGrid::PutRowCore(long Row, void *Vals, bool useDouble, VARIANT_BOOL * retv } } } - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) { int ncols = _dgrid->getHeader().getNumberCols(); for (int i = 0; i < ncols; i++) @@ -507,7 +507,7 @@ void CGrid::PutRowCore(long Row, void *Vals, bool useDouble, VARIANT_BOOL * retv } } } - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) { int ncols = _fgrid->getHeader().getNumberCols(); for (int i = 0; i < ncols; i++) @@ -520,7 +520,7 @@ void CGrid::PutRowCore(long Row, void *Vals, bool useDouble, VARIANT_BOOL * retv } } } - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) { int ncols = _lgrid->getHeader().getNumberCols(); for (int i = 0; i < ncols; i++) @@ -535,7 +535,7 @@ void CGrid::PutRowCore(long Row, void *Vals, bool useDouble, VARIANT_BOOL * retv } } } - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) { int ncols = _sgrid->getHeader().getNumberCols(); for (int i = 0; i < ncols; i++) @@ -588,7 +588,7 @@ STDMETHODIMP CGrid::SetInvalidValuesToNodata(double MinThresholdValue, double Ma return S_OK; } - IGridHeader * hdr = NULL; + IGridHeader * hdr = nullptr; get_Header(&hdr); long maxi = 0; @@ -632,7 +632,7 @@ STDMETHODIMP CGrid::get_Value(long Column, long Row, VARIANT *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (_trgrid != NULL) + if (_trgrid != nullptr) { if (Column < 0 || Column >= _trgrid->getWidth() || Row< 0 || Row >= _trgrid->getHeight() ) { @@ -645,19 +645,19 @@ STDMETHODIMP CGrid::get_Value(long Column, long Row, VARIANT *pVal) pVal->vt = VT_R8; pVal->dblVal = _trgrid->getValue(Row, Column); } - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) { pVal->vt = VT_R8; pVal->dblVal = _dgrid->getValue( Column, Row ); } - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) { pVal->vt = VT_R4; pVal->fltVal = _fgrid->getValue( Column, Row ); } - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) { pVal->vt = VT_I4; pVal->lVal = _lgrid->getValue( Column, Row ); } - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) { pVal->vt = VT_I2; pVal->iVal = _sgrid->getValue( Column, Row ); } @@ -683,7 +683,7 @@ STDMETHODIMP CGrid::put_Value(long Column, long Row, VARIANT newVal) } else { - if ( _trgrid != NULL) + if ( _trgrid != nullptr) { if (Column < 0 || Column >= _trgrid->getWidth() || Row< 0 || Row >= _trgrid->getHeight() ) { @@ -701,14 +701,14 @@ STDMETHODIMP CGrid::put_Value(long Column, long Row, VARIANT newVal) return S_OK; } } - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) _dgrid->setValue( Column, Row, Value ); - else if( _fgrid != NULL ) - _fgrid->setValue( Column, Row, (float)Value ); - else if( _lgrid != NULL ) - _lgrid->setValue( Column, Row, (long)Value ); - else if( _sgrid != NULL ) - _sgrid->setValue( Column, Row, (short)Value ); + else if( _fgrid != nullptr) + _fgrid->setValue( Column, Row, static_cast(Value) ); + else if( _lgrid != nullptr) + _lgrid->setValue( Column, Row, static_cast(Value) ); + else if( _sgrid != nullptr) + _sgrid->setValue( Column, Row, static_cast(Value) ); } return S_OK; } @@ -720,15 +720,15 @@ STDMETHODIMP CGrid::get_InRam(VARIANT_BOOL *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if ( _trgrid != NULL) + if ( _trgrid != nullptr) *pVal = _trgrid->isInRam()?VARIANT_TRUE:VARIANT_FALSE; - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) *pVal = _dgrid->inRam()?VARIANT_TRUE:VARIANT_FALSE; - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) *pVal = _fgrid->inRam()?VARIANT_TRUE:VARIANT_FALSE; - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) *pVal = _lgrid->inRam()?VARIANT_TRUE:VARIANT_FALSE; - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) *pVal = _sgrid->inRam()?VARIANT_TRUE:VARIANT_FALSE; else { @@ -747,24 +747,24 @@ STDMETHODIMP CGrid::get_Maximum(VARIANT *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (_trgrid != NULL) + if (_trgrid != nullptr) { pVal->vt = VT_R8; pVal->dblVal = _trgrid->GetMaximum(); } - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) { pVal->vt = VT_R8; pVal->dblVal = _dgrid->maximum(); } - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) { pVal->vt = VT_R4; pVal->fltVal = _fgrid->maximum(); } - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) { pVal->vt = VT_I4; pVal->lVal = _lgrid->maximum(); } - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) { pVal->vt = VT_I2; pVal->iVal = _sgrid->maximum(); } @@ -783,7 +783,7 @@ STDMETHODIMP CGrid::get_Minimum(VARIANT *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (_trgrid != NULL) + if (_trgrid != nullptr) { // GDAL doesn't always exclude nodata values. // If nodata == minimum generate by brute force. @@ -831,19 +831,19 @@ STDMETHODIMP CGrid::get_Minimum(VARIANT *pVal) pVal->dblVal = _trgrid->GetMinimum(); } } - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) { pVal->vt = VT_R8; pVal->dblVal = _dgrid->minimum(); } - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) { pVal->vt = VT_R4; pVal->fltVal = _fgrid->minimum(); } - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) { pVal->vt = VT_I4; pVal->lVal = _lgrid->minimum(); } - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) { pVal->vt = VT_I2; pVal->iVal = _sgrid->minimum(); } @@ -864,15 +864,15 @@ STDMETHODIMP CGrid::get_DataType(GridDataType *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if ( _trgrid != NULL) + if ( _trgrid != nullptr) *pVal = _trgrid->GetDataType(); - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) *pVal = DoubleDataType; - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) *pVal = FloatDataType; - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) *pVal = LongDataType; - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) *pVal = ShortDataType; else { @@ -907,15 +907,15 @@ STDMETHODIMP CGrid::get_LastErrorCode(long *pVal) *pVal = _lastErrorCode; if( *pVal != tkNO_ERROR ) - { if ( _trgrid != NULL) + { if ( _trgrid != nullptr) *pVal = 0; // todo -- trgrid ought to keep track of an error code - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) *pVal = _dgrid->LastErrorCode(); - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) *pVal = _fgrid->LastErrorCode(); - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) *pVal = _lgrid->LastErrorCode(); - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) *pVal = _sgrid->LastErrorCode(); } @@ -941,7 +941,7 @@ STDMETHODIMP CGrid::get_GlobalCallback(ICallback **pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _globalCallback; - if( _globalCallback != NULL ) + if( _globalCallback != nullptr) _globalCallback->AddRef(); return S_OK; } @@ -978,7 +978,7 @@ void CGrid::SaveProjectionAsWkt() CStringW prjFilename = Utility::GetProjectionFilename(GetFilename()); if (prjFilename.GetLength() > 0) { - IGeoProjection* proj = NULL; + IGeoProjection* proj = nullptr; ComHelper::CreateInstance(idGeoProjection, (IDispatch**)&proj); if (proj) { @@ -1016,7 +1016,7 @@ bool CGrid::OpenCustomGrid(GridDataType DataType, bool inRam, GridFileType FileT { ErrorMessage(_dgrid->LastErrorCode()); delete _dgrid; - _dgrid = NULL; + _dgrid = nullptr; } } else if( DataType == FloatDataType ) @@ -1027,7 +1027,7 @@ bool CGrid::OpenCustomGrid(GridDataType DataType, bool inRam, GridFileType FileT { ErrorMessage(_fgrid->LastErrorCode()); delete _fgrid; - _fgrid = NULL; + _fgrid = nullptr; } } else if( DataType == LongDataType ) @@ -1038,7 +1038,7 @@ bool CGrid::OpenCustomGrid(GridDataType DataType, bool inRam, GridFileType FileT { ErrorMessage(_lgrid->LastErrorCode()); delete _lgrid; - _lgrid = NULL; + _lgrid = nullptr; } } else if( DataType == ShortDataType ) @@ -1049,7 +1049,7 @@ bool CGrid::OpenCustomGrid(GridDataType DataType, bool inRam, GridFileType FileT { ErrorMessage(_sgrid->LastErrorCode()); delete _sgrid; - _sgrid = NULL; + _sgrid = nullptr; } } return result; @@ -1069,7 +1069,7 @@ void CGrid::TryOpenAsAsciiGrid(GridDataType DataType, bool& inRam, bool& forcing long ncol, nrow; ncol = dhd.getNumberCols(); nrow = dhd.getNumberRows(); - if (MemoryAvailable(sizeof(double) * ncol * nrow)) {} + if (MemoryAvailable(static_cast(sizeof(double) * ncol * nrow))) {} else { inRam = false; @@ -1077,7 +1077,7 @@ void CGrid::TryOpenAsAsciiGrid(GridDataType DataType, bool& inRam, bool& forcing } fin.close(); delete _dgrid; - _dgrid = NULL; + _dgrid = nullptr; } else if (DataType == FloatDataType) { @@ -1088,7 +1088,7 @@ void CGrid::TryOpenAsAsciiGrid(GridDataType DataType, bool& inRam, bool& forcing long ncol, nrow; ncol = fhd.getNumberCols(); nrow = fhd.getNumberRows(); - if (MemoryAvailable(sizeof(double) * ncol * nrow)) {} + if (MemoryAvailable(static_cast(sizeof(double) * ncol * nrow))) {} else { inRam = false; @@ -1096,7 +1096,7 @@ void CGrid::TryOpenAsAsciiGrid(GridDataType DataType, bool& inRam, bool& forcing } fin.close(); delete _fgrid; - _fgrid = NULL; + _fgrid = nullptr; } else if (DataType == ShortDataType) { @@ -1107,7 +1107,7 @@ void CGrid::TryOpenAsAsciiGrid(GridDataType DataType, bool& inRam, bool& forcing long ncol, nrow; ncol = shd.getNumberCols(); nrow = shd.getNumberRows(); - if (MemoryAvailable(sizeof(double) * ncol * nrow)) {} + if (MemoryAvailable(static_cast(sizeof(double) * ncol * nrow))) {} else { inRam = false; @@ -1115,7 +1115,7 @@ void CGrid::TryOpenAsAsciiGrid(GridDataType DataType, bool& inRam, bool& forcing } fin.close(); delete _sgrid; - _sgrid = NULL; + _sgrid = nullptr; } else if (DataType == LongDataType) { @@ -1126,7 +1126,7 @@ void CGrid::TryOpenAsAsciiGrid(GridDataType DataType, bool& inRam, bool& forcing long ncol, nrow; ncol = lhd.getNumberCols(); nrow = lhd.getNumberRows(); - if (MemoryAvailable(sizeof(double) * ncol * nrow)) {} + if (MemoryAvailable(static_cast(sizeof(double) * ncol * nrow))) {} else { inRam = false; @@ -1134,7 +1134,7 @@ void CGrid::TryOpenAsAsciiGrid(GridDataType DataType, bool& inRam, bool& forcing } fin.close(); delete _lgrid; - _lgrid = NULL; + _lgrid = nullptr; } } @@ -1230,7 +1230,7 @@ STDMETHODIMP CGrid::Open(BSTR Filename, GridDataType DataType, VARIANT_BOOL InRa _filename = OLE2W(Filename); ICallback * tmpCallback = _globalCallback; - if( cBack != NULL ) _globalCallback = cBack; + if( cBack != nullptr) _globalCallback = cBack; bool inRam = InRam == VARIANT_TRUE ? true: false; // Are we handling ECWP imagery? @@ -1345,14 +1345,14 @@ STDMETHODIMP CGrid::CreateNew(BSTR Filename, IGridHeader *Header, GridDataType D { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retval = VARIANT_FALSE; + *retval = VARIANT_FALSE; USES_CONVERSION; ICallback * tmpCallback = _globalCallback; - if( cBack != NULL ) + if( cBack != nullptr) _globalCallback = cBack; - Close(retval); + Close(retval); VARIANT_BOOL bInRam = VARIANT_FALSE; bool boolInRam = false; @@ -1440,7 +1440,7 @@ STDMETHODIMP CGrid::CreateNew(BSTR Filename, IGridHeader *Header, GridDataType D else { delete _trgrid; - _trgrid = NULL; + _trgrid = nullptr; } } else @@ -1493,7 +1493,7 @@ STDMETHODIMP CGrid::CreateNew(BSTR Filename, IGridHeader *Header, GridDataType D { ErrorMessage(_dgrid->LastErrorCode()); delete _dgrid; - _dgrid = NULL; + _dgrid = nullptr; } VariantClear(&ndv); @@ -1535,7 +1535,7 @@ STDMETHODIMP CGrid::CreateNew(BSTR Filename, IGridHeader *Header, GridDataType D Header->get_YllCenter(&yllcenter); fhdr.setYllcenter(yllcenter); - if( _fgrid->initialize(OLE2CA(Filename),fhdr,(float)value,boolInRam) == true ) + if( _fgrid->initialize(OLE2CA(Filename),fhdr,static_cast(value),boolInRam) == true ) { _filename = OLE2W(Filename); *retval = VARIANT_TRUE; @@ -1544,7 +1544,7 @@ STDMETHODIMP CGrid::CreateNew(BSTR Filename, IGridHeader *Header, GridDataType D { ErrorMessage(_fgrid->LastErrorCode()); delete _fgrid; - _fgrid = NULL; + _fgrid = nullptr; } VariantClear(&ndv); } @@ -1583,7 +1583,7 @@ STDMETHODIMP CGrid::CreateNew(BSTR Filename, IGridHeader *Header, GridDataType D Header->get_YllCenter(&yllcenter); lhdr.setYllcenter(yllcenter); - if( _lgrid->initialize(OLE2CA(Filename),lhdr,(long)value,boolInRam) == true ) + if( _lgrid->initialize(OLE2CA(Filename),lhdr,static_cast(value),boolInRam) == true ) { _filename = OLE2W(Filename); *retval = VARIANT_TRUE; @@ -1592,7 +1592,7 @@ STDMETHODIMP CGrid::CreateNew(BSTR Filename, IGridHeader *Header, GridDataType D { ErrorMessage(_lgrid->LastErrorCode()); delete _lgrid; - _lgrid = NULL; + _lgrid = nullptr; } VariantClear(&ndv); } @@ -1607,7 +1607,7 @@ STDMETHODIMP CGrid::CreateNew(BSTR Filename, IGridHeader *Header, GridDataType D Header->get_dY(&dy); shdr.setDy(dy); VARIANT ndv; - VariantInit(&ndv); + VariantInit(&ndv); Header->get_NodataValue(&ndv); short sndv; sVal(ndv,sndv); @@ -1631,7 +1631,7 @@ STDMETHODIMP CGrid::CreateNew(BSTR Filename, IGridHeader *Header, GridDataType D Header->get_YllCenter(&yllcenter); shdr.setYllcenter(yllcenter); - if( _sgrid->initialize(OLE2CA(Filename),shdr,(short)value,boolInRam) == true ) + if( _sgrid->initialize(OLE2CA(Filename),shdr,static_cast(value),boolInRam) == true ) { _filename = OLE2W(Filename); *retval = VARIANT_TRUE; @@ -1640,7 +1640,7 @@ STDMETHODIMP CGrid::CreateNew(BSTR Filename, IGridHeader *Header, GridDataType D { ErrorMessage(_sgrid->LastErrorCode()); delete _sgrid; - _sgrid = NULL; + _sgrid = nullptr; } VariantClear(&ndv); } @@ -1663,21 +1663,21 @@ STDMETHODIMP CGrid::Close(VARIANT_BOOL *retval) AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = VARIANT_TRUE; - if ( _trgrid != NULL) + if ( _trgrid != nullptr) *retval = _trgrid->Close()?VARIANT_TRUE:VARIANT_FALSE; - _trgrid = NULL; - if( _dgrid != NULL ) + _trgrid = nullptr; + if( _dgrid != nullptr) *retval = _dgrid->close()?VARIANT_TRUE:VARIANT_FALSE; - _dgrid = NULL; - if( _fgrid != NULL ) + _dgrid = nullptr; + if( _fgrid != nullptr) *retval = _fgrid->close()?VARIANT_TRUE:VARIANT_FALSE; - _fgrid = NULL; - if( _lgrid != NULL ) + _fgrid = nullptr; + if( _lgrid != nullptr) *retval = _lgrid->close()?VARIANT_TRUE:VARIANT_FALSE; - _lgrid = NULL; - if( _sgrid != NULL ) + _lgrid = nullptr; + if( _sgrid != nullptr) *retval = _sgrid->close()?VARIANT_TRUE:VARIANT_FALSE; - _sgrid = NULL; + _sgrid = nullptr; return S_OK; } @@ -1691,11 +1691,11 @@ STDMETHODIMP CGrid::Save(BSTR Filename, GridFileType FileType, ICallback * cBac *retval = VARIANT_FALSE; - if (Filename == L"" || Filename == NULL) + if (Filename == L"" || Filename == nullptr) Filename = OLE2BSTR(_filename); ICallback * tmpCallback = _globalCallback; - if( cBack != NULL ) + if( cBack != nullptr) _globalCallback = cBack; activeGridObject = this; @@ -1717,14 +1717,14 @@ STDMETHODIMP CGrid::Save(BSTR Filename, GridFileType FileType, ICallback * cBac // (special conversion case) If they have a GDAL format and wish to save it to BGD, speed it up by writing // directly from the tkGridRaster class. (Generic conversion can do anything, but very slowly.) - if (_trgrid != NULL && FileType == Binary) + if (_trgrid != nullptr && FileType == Binary) { *retval = _trgrid->SaveToBGD(OLE2A(Filename), gridCOMCALLBACK) ? VARIANT_TRUE : VARIANT_FALSE; } // (special conversion case) If they have a BGD and wish to save it to a GDAL format, speed it up by writing // directly from the tkGridRaster class. (Generic conversion can do anything, but very slowly.) - else if (origFileType == Binary && _trgrid == NULL && - (_dgrid != NULL || _fgrid != NULL || _sgrid != NULL || _lgrid != NULL) && + else if (origFileType == Binary && _trgrid == nullptr && + (_dgrid != nullptr || _fgrid != nullptr || _sgrid != nullptr || _lgrid != nullptr) && (FileType == Ecw || FileType == Bil || FileType == Esri || FileType == Flt || FileType == MrSid || FileType == PAux || FileType == PCIDsk || FileType == DTed || FileType == GeoTiff)) @@ -1763,7 +1763,7 @@ STDMETHODIMP CGrid::Save(BSTR Filename, GridFileType FileType, ICallback * cBac if (!bRetval) return S_OK; tempGrid->Close(); - tempGrid = NULL; + tempGrid = nullptr; *retval = VARIANT_TRUE; //return S_OK; // Is it needed to @@ -1774,11 +1774,11 @@ STDMETHODIMP CGrid::Save(BSTR Filename, GridFileType FileType, ICallback * cBac // to save newly created ascii grids and use GDAL to save from GDAL formats // to ascii grids. This block also handles saving existing ascii grids that // were opened using the GDAL wrapper. - else if (_trgrid != NULL && (FileType != Ecw && FileType != Bil + else if (_trgrid != nullptr && (FileType != Ecw && FileType != Bil && FileType != MrSid && FileType != PAux && FileType != Esri && FileType != Flt && FileType != PCIDsk && FileType != DTed && FileType != GeoTiff) || - (_trgrid == NULL && (FileType == Ecw || FileType == Bil + (_trgrid == nullptr && (FileType == Ecw || FileType == Bil || FileType == Esri || FileType == MrSid || FileType == PAux || FileType == Flt || FileType == PCIDsk || FileType == DTed || FileType == GeoTiff))) @@ -1787,9 +1787,9 @@ STDMETHODIMP CGrid::Save(BSTR Filename, GridFileType FileType, ICallback * cBac // copy the data across and save it. // Make a temporary grid of the type requested - IGrid * tempGrid = NULL; + IGrid * tempGrid = nullptr; HRESULT reslt; - reslt = CoCreateInstance(CLSID_Grid, NULL, CLSCTX_INPROC_SERVER, IID_IGrid, (LPVOID*)(&tempGrid)); + reslt = CoCreateInstance(CLSID_Grid, nullptr, CLSCTX_INPROC_SERVER, IID_IGrid, (LPVOID*)(&tempGrid)); IGridHeader * hdr; this->get_Header(&hdr); @@ -1802,7 +1802,7 @@ STDMETHODIMP CGrid::Save(BSTR Filename, GridFileType FileType, ICallback * cBac hdr->get_NodataValue(&nodataval); VARIANT_BOOL rslt = VARIANT_FALSE; - tempGrid->CreateNew(Filename, hdr, dataType, nodataval, false, FileType, NULL, &rslt); + tempGrid->CreateNew(Filename, hdr, dataType, nodataval, false, FileType, nullptr, &rslt); if (!rslt) return S_OK; @@ -1831,15 +1831,15 @@ STDMETHODIMP CGrid::Save(BSTR Filename, GridFileType FileType, ICallback * cBac // Clean up VARIANT_BOOL discardResult; tempGrid->Close(&discardResult); - tempGrid = NULL; + tempGrid = nullptr; - hdr = NULL; // Set this to null so it doesn't + hdr = nullptr; // Set this to null so it doesn't // get destroyed when it goes out of scope; there // are still references to it. *retval = rslt; } - else if (_trgrid != NULL) + else if (_trgrid != nullptr) { if( _trgrid->Save(W2A(Filename), FileType) ) { @@ -1851,7 +1851,7 @@ STDMETHODIMP CGrid::Save(BSTR Filename, GridFileType FileType, ICallback * cBac ErrorMessage(tkFAILED_TO_SAVE_GRID); } } - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) { if( _dgrid->save(OLE2CA(Filename), (GRID_TYPE)FileType, gridCOMCALLBACK) == true ) { @@ -1863,7 +1863,7 @@ STDMETHODIMP CGrid::Save(BSTR Filename, GridFileType FileType, ICallback * cBac ErrorMessage(_dgrid->LastErrorCode()); } } - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) { if( _fgrid->save(OLE2CA(Filename), (GRID_TYPE)FileType, gridCOMCALLBACK) == true ) { @@ -1875,7 +1875,7 @@ STDMETHODIMP CGrid::Save(BSTR Filename, GridFileType FileType, ICallback * cBac ErrorMessage(_fgrid->LastErrorCode()); } } - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) { if( _lgrid->save(OLE2CA(Filename), (GRID_TYPE)FileType, gridCOMCALLBACK) == true ) { @@ -1887,7 +1887,7 @@ STDMETHODIMP CGrid::Save(BSTR Filename, GridFileType FileType, ICallback * cBac ErrorMessage(_lgrid->LastErrorCode()); } } - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) { if( _sgrid->save(OLE2CA(Filename), (GRID_TYPE)FileType, gridCOMCALLBACK) == true ) { @@ -1908,12 +1908,12 @@ STDMETHODIMP CGrid::Save(BSTR Filename, GridFileType FileType, ICallback * cBac try { // Write the projection to the .prj file - IGridHeader * header = NULL; + IGridHeader * header = nullptr; this->get_Header(&header); - CComBSTR bstrProj = NULL; + CComBSTR bstrProj = nullptr; header->get_Projection(&bstrProj); header->Release(); - header = NULL; + header = nullptr; if (strcmp(OLE2A(bstrProj), "") != 0) { @@ -1944,15 +1944,15 @@ STDMETHODIMP CGrid::Clear(VARIANT ClearValue, VARIANT_BOOL *retval) else { *retval = VARIANT_TRUE; - if ( _trgrid != NULL) + if ( _trgrid != nullptr) _trgrid->clear(value); - if( _dgrid != NULL ) + if( _dgrid != nullptr) _dgrid->clear(value); - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) _fgrid->clear((float)value); - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) _lgrid->clear((long)value); - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) _sgrid->clear((short)value); else { *retval = VARIANT_FALSE; @@ -1969,15 +1969,15 @@ STDMETHODIMP CGrid::ProjToCell(double x, double y, long *Column, long *Row) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if ( _trgrid != NULL ) + if ( _trgrid != nullptr) _trgrid->ProjToCell( x, y, *Column, *Row ); - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) _dgrid->ProjToCell( x, y, *Column, *Row ); - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) _fgrid->ProjToCell( x, y, *Column, *Row ); - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) _lgrid->ProjToCell( x, y, *Column, *Row ); - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) _sgrid->ProjToCell( x, y, *Column, *Row ); else { *Column = -1; @@ -1994,15 +1994,15 @@ STDMETHODIMP CGrid::CellToProj(long Column, long Row, double *x, double *y) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (_trgrid != NULL) + if (_trgrid != nullptr) _trgrid->CellToProj(Column, Row, *x, *y); - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) _dgrid->CellToProj(Column, Row, *x, *y); - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) _fgrid->CellToProj(Column, Row, *x, *y); - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) _lgrid->CellToProj(Column, Row, *x, *y); - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) _sgrid->CellToProj(Column, Row, *x, *y); else { *x = 0; @@ -2129,7 +2129,7 @@ void CGrid::GetFloatWindowCore(long StartRow, long EndRow, long StartCol, long E double* ValsDouble = reinterpret_cast(Vals); float* ValsFloat = reinterpret_cast(Vals); - if (_trgrid != NULL) + if (_trgrid != nullptr) { long height = _trgrid->getHeight(); long width = _trgrid->getWidth(); @@ -2137,7 +2137,7 @@ void CGrid::GetFloatWindowCore(long StartRow, long EndRow, long StartCol, long E StartCol < 0 || StartCol >= width || EndCol < 0 || EndCol >= width) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); - Vals = NULL; + Vals = nullptr; *retval = VARIANT_FALSE; return; } @@ -2147,7 +2147,7 @@ void CGrid::GetFloatWindowCore(long StartRow, long EndRow, long StartCol, long E *retval = VARIANT_FALSE; } } - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) { long position = 0; for (long j = StartRow; j <= EndRow; j++) @@ -2165,7 +2165,7 @@ void CGrid::GetFloatWindowCore(long StartRow, long EndRow, long StartCol, long E } } } - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) { long position = 0; for (long j = StartRow; j <= EndRow; j++) @@ -2183,7 +2183,7 @@ void CGrid::GetFloatWindowCore(long StartRow, long EndRow, long StartCol, long E } } } - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) { long position = 0; for (long j = StartRow; j <= EndRow; j++) @@ -2201,7 +2201,7 @@ void CGrid::GetFloatWindowCore(long StartRow, long EndRow, long StartCol, long E } } } - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) { long position = 0; for (long j = StartRow; j <= EndRow; j++) @@ -2220,7 +2220,7 @@ void CGrid::GetFloatWindowCore(long StartRow, long EndRow, long StartCol, long E } } else - { Vals = NULL; + { Vals = nullptr; ErrorMessage(tkGRID_NOT_INITIALIZED); *retval = VARIANT_FALSE; } @@ -2253,14 +2253,14 @@ STDMETHODIMP CGrid::PutFloatWindow2(long StartRow, long EndRow, long StartCol, l // ****************************************************************** void CGrid::PutFloatWindowCore(long StartRow, long EndRow, long StartCol, long EndCol, void *Vals, bool useDouble, VARIANT_BOOL * retval) { - double* ValsDouble = reinterpret_cast(Vals); - float* ValsFloat = reinterpret_cast(Vals); - if (_trgrid != NULL) + double* ValsDouble = static_cast(Vals); + float* ValsFloat = static_cast(Vals); + if (_trgrid != nullptr) { if (StartRow < 0 || StartRow >= _trgrid->getHeight() || EndRow < 0 || EndRow >= _trgrid->getHeight()) { _lastErrorCode = tkINDEX_OUT_OF_BOUNDS; - Vals = NULL; + Vals = nullptr; *retval = FALSE; } @@ -2269,7 +2269,7 @@ void CGrid::PutFloatWindowCore(long StartRow, long EndRow, long StartCol, long E *retval = FALSE; } } - else if( _dgrid != NULL ) + else if( _dgrid != nullptr) { int ncols = _dgrid->getHeader().getNumberCols(); long position = 0; @@ -2289,7 +2289,7 @@ void CGrid::PutFloatWindowCore(long StartRow, long EndRow, long StartCol, long E } } } - else if( _fgrid != NULL ) + else if( _fgrid != nullptr) { int ncols = _fgrid->getHeader().getNumberCols(); long position = 0; @@ -2309,7 +2309,7 @@ void CGrid::PutFloatWindowCore(long StartRow, long EndRow, long StartCol, long E } } } - else if( _lgrid != NULL ) + else if( _lgrid != nullptr) { int ncols = _lgrid->getHeader().getNumberCols(); long position = 0; @@ -2329,7 +2329,7 @@ void CGrid::PutFloatWindowCore(long StartRow, long EndRow, long StartCol, long E } } } - else if( _sgrid != NULL ) + else if( _sgrid != nullptr) { int ncols = _sgrid->getHeader().getNumberCols(); long position = 0; @@ -2364,9 +2364,9 @@ void CGrid::PutFloatWindowCore(long StartRow, long EndRow, long StartCol, long E STDMETHODIMP CGrid::get_Extents(IExtents** retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *retVal = NULL; + *retVal = nullptr; - IGridHeader* header = NULL; + IGridHeader* header = nullptr; this->get_Header(&header); if (header) { @@ -2385,7 +2385,7 @@ STDMETHODIMP CGrid::get_Extents(IExtents** retVal) double minY = yll - (cellHeight / 2); double maxY = yll + (cellHeight * (rows - 1)) + (cellHeight / 2); - IExtents* ext = NULL; + IExtents* ext = nullptr; ComHelper::CreateExtents(&ext); ext->SetBounds(minX, minY, 0.0, maxX, maxY, 0.0); @@ -2401,28 +2401,28 @@ IGrid* CGrid::Clone(BSTR newFilename) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); - IGridHeader* newHeader = NULL; - CoCreateInstance(CLSID_GridHeader,NULL,CLSCTX_INPROC_SERVER,IID_IGridHeader,(void**)&newHeader); + IGridHeader* newHeader = nullptr; + CoCreateInstance(CLSID_GridHeader, nullptr,CLSCTX_INPROC_SERVER,IID_IGridHeader,(void**)&newHeader); - IGridHeader* header = NULL; + IGridHeader* header = nullptr; this->get_Header(&header); newHeader->CopyFrom(header); CComVariant noDataValue; header->get_NodataValue(&noDataValue); - IGrid* newGrid = NULL; - CoCreateInstance(CLSID_Grid,NULL,CLSCTX_INPROC_SERVER,IID_IGrid,(void**)&newGrid); + IGrid* newGrid = nullptr; + CoCreateInstance(CLSID_Grid, nullptr,CLSCTX_INPROC_SERVER,IID_IGrid,(void**)&newGrid); GridDataType dataType; this->get_DataType(&dataType); VARIANT_BOOL vb; - newGrid->CreateNew(newFilename, newHeader, dataType, noDataValue, false, GridFileType::UseExtension, NULL, &vb); + newGrid->CreateNew(newFilename, newHeader, dataType, noDataValue, false, GridFileType::UseExtension, nullptr, &vb); if (!vb) { newGrid->Close(&vb); newGrid->Release(); - newGrid = NULL; + newGrid = nullptr; } header->Release(); @@ -2436,10 +2436,10 @@ IGrid* CGrid::Clone(BSTR newFilename) // ************************************************************** IGrid* CGrid::Clip(BSTR newFilename, long firstCol, long lastCol, long firstRow, long lastRow) { - IGridHeader* newHeader = NULL; - CoCreateInstance(CLSID_GridHeader,NULL,CLSCTX_INPROC_SERVER,IID_IGridHeader,(void**)&newHeader); + IGridHeader* newHeader = nullptr; + CoCreateInstance(CLSID_GridHeader, nullptr,CLSCTX_INPROC_SERVER,IID_IGridHeader,(void**)&newHeader); - IGridHeader* header = NULL; + IGridHeader* header = nullptr; this->get_Header(&header); newHeader->CopyFrom(header); @@ -2454,18 +2454,18 @@ IGrid* CGrid::Clip(BSTR newFilename, long firstCol, long lastCol, long firstRow, CComVariant noDataValue; header->get_NodataValue(&noDataValue); - IGrid* newGrid = NULL; - CoCreateInstance(CLSID_Grid,NULL,CLSCTX_INPROC_SERVER,IID_IGrid,(void**)&newGrid); + IGrid* newGrid = nullptr; + CoCreateInstance(CLSID_Grid, nullptr,CLSCTX_INPROC_SERVER,IID_IGrid,(void**)&newGrid); GridDataType dataType; this->get_DataType(&dataType); VARIANT_BOOL vb; - newGrid->CreateNew(newFilename, newHeader, dataType, noDataValue, false, GridFileType::UseExtension, NULL, &vb); + newGrid->CreateNew(newFilename, newHeader, dataType, noDataValue, false, GridFileType::UseExtension, nullptr, &vb); if (!vb) { newGrid->Close(&vb); newGrid->Release(); - newGrid = NULL; + newGrid = nullptr; } header->Release(); @@ -2480,7 +2480,7 @@ IGrid* CGrid::Clip(BSTR newFilename, long firstCol, long lastCol, long firstRow, STDMETHODIMP CGrid::get_NumBands(int *retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); - if (_trgrid != NULL) + if (_trgrid != nullptr) { *retVal = _trgrid->getNumBands(); } @@ -2501,7 +2501,7 @@ STDMETHODIMP CGrid::get_NumBands(int *retVal) STDMETHODIMP CGrid::get_ActiveBandIndex(int *retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *retVal = _trgrid != NULL ? _trgrid->GetActiveBandIndex() : 1; + *retVal = _trgrid != nullptr ? _trgrid->GetActiveBandIndex() : 1; return S_OK; } @@ -2512,7 +2512,7 @@ STDMETHODIMP CGrid::OpenBand(int bandIndex, VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); *retVal = VARIANT_FALSE; - if (_trgrid != NULL) // it works for GDAL-rooted grids + if (_trgrid != nullptr) // it works for GDAL-rooted grids { if (bandIndex < 1 || bandIndex > _trgrid->getNumBands()) { @@ -2581,7 +2581,7 @@ bool CGrid::IsRgb() STDMETHODIMP CGrid::OpenAsImage(IGridColorScheme* scheme, tkGridProxyMode proxyMode, ICallback* cBack, IImage** retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retVal = NULL; + *retVal = nullptr; if (!_globalCallback && cBack) ComHelper::SetRef(cBack, (IDispatch**)&_globalCallback, false); @@ -2639,10 +2639,10 @@ STDMETHODIMP CGrid::OpenAsImage(IGridColorScheme* scheme, tkGridProxyMode proxyM void CGrid::OpenAsDirectImage(IGridColorScheme* scheme, ICallback* cBack, IImage** retVal) { VARIANT_BOOL vb; - IImage* img = NULL; + IImage* img = nullptr; CStringW gridName = GetFilename().MakeLower(); - CoCreateInstance(CLSID_Image,NULL,CLSCTX_INPROC_SERVER,IID_IImage,(void**)&img); + CoCreateInstance(CLSID_Image, nullptr,CLSCTX_INPROC_SERVER,IID_IImage,(void**)&img); CComBSTR bstr(gridName); img->Open(bstr, ImageType::USE_FILE_EXTENSION, false, cBack, &vb); @@ -2695,7 +2695,7 @@ IImage* CGrid::OpenImageProxy() { VARIANT_BOOL hasProxy; this->get_HasValidImageProxy(&hasProxy); - IImage* iimg= NULL; + IImage* iimg = nullptr; if (hasProxy) { @@ -2708,7 +2708,7 @@ IImage* CGrid::OpenImageProxy() { iimg->Close(&vb); iimg->Release(); - iimg = NULL; + iimg = nullptr; } } return iimg; @@ -2780,7 +2780,7 @@ STDMETHODIMP CGrid::RetrieveOrGenerateColorScheme(tkGridSchemeRetrieval retrieva PredefinedColorScheme colors, IGridColorScheme** retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retVal = NULL; + *retVal = nullptr; RetrieveColorScheme(retrievalMethod, retVal); if (!(*retVal)) { @@ -2798,7 +2798,7 @@ bool schemeIsValid(IGridColorScheme** scheme) if (!valid) { (*scheme)->Release(); - (*scheme) = NULL; + (*scheme) = nullptr; } return true; } @@ -2809,8 +2809,8 @@ bool schemeIsValid(IGridColorScheme** scheme) STDMETHODIMP CGrid::RetrieveColorScheme(tkGridSchemeRetrieval method, IGridColorScheme** retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retVal = NULL; - IGridColorScheme* scheme = NULL; + *retVal = nullptr; + IGridColorScheme* scheme = nullptr; VARIANT_BOOL vb; // disk based for the grid itself @@ -2819,7 +2819,7 @@ STDMETHODIMP CGrid::RetrieveColorScheme(tkGridSchemeRetrieval method, IGridColor CStringW legendName = this->GetLegendName(); if (Utility::FileExistsW(legendName)) { - CoCreateInstance( CLSID_GridColorScheme, NULL, CLSCTX_INPROC_SERVER, IID_IGridColorScheme, (void**)&scheme); + CoCreateInstance( CLSID_GridColorScheme, nullptr, CLSCTX_INPROC_SERVER, IID_IGridColorScheme, (void**)&scheme); CComBSTR bstrLegendName(legendName); scheme->ReadFromFile(bstrLegendName, m_globalSettings.emptyBstr, &vb); } @@ -2835,7 +2835,7 @@ STDMETHODIMP CGrid::RetrieveColorScheme(tkGridSchemeRetrieval method, IGridColor if (hasProxy) { CStringW legendName = this->GetProxyLegendName(); - CoCreateInstance( CLSID_GridColorScheme, NULL, CLSCTX_INPROC_SERVER, IID_IGridColorScheme, (void**)&scheme); + CoCreateInstance( CLSID_GridColorScheme, nullptr, CLSCTX_INPROC_SERVER, IID_IGridColorScheme, (void**)&scheme); CComBSTR bstrLegendName(legendName); scheme->ReadFromFile(bstrLegendName, m_globalSettings.emptyBstr, &vb); } @@ -2861,8 +2861,8 @@ STDMETHODIMP CGrid::RetrieveColorScheme(tkGridSchemeRetrieval method, IGridColor STDMETHODIMP CGrid::GenerateColorScheme(tkGridSchemeGeneration method, PredefinedColorScheme colors, IGridColorScheme** retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retVal = NULL; - IGridColorScheme* scheme = NULL; + *retVal = nullptr; + IGridColorScheme* scheme = nullptr; switch(method) { case gsgGradient: @@ -2888,7 +2888,7 @@ STDMETHODIMP CGrid::GenerateColorScheme(tkGridSchemeGeneration method, Predefine // ************************************************************* bool CGrid::BuildUniqueColorScheme(int maxValuesCount, PredefinedColorScheme colors, ColoringType coloringType, IGridColorScheme** newScheme) { - *newScheme = NULL; + *newScheme = nullptr; set values; if (!this->GetUniqueValues(values, maxValuesCount)) @@ -2897,12 +2897,12 @@ bool CGrid::BuildUniqueColorScheme(int maxValuesCount, PredefinedColorScheme col if (values.size() == 0) // it's empty, hence no scheme return false; - IGridColorScheme* result = NULL; - CoCreateInstance(CLSID_GridColorScheme,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorScheme,(void**)&result); + IGridColorScheme* result = nullptr; + CoCreateInstance(CLSID_GridColorScheme, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorScheme,(void**)&result); if (result) { - IColorScheme* scheme = NULL; - CoCreateInstance(CLSID_ColorScheme,NULL,CLSCTX_INPROC_SERVER,IID_IColorScheme,(void**)&scheme); + IColorScheme* scheme = nullptr; + CoCreateInstance(CLSID_ColorScheme, nullptr,CLSCTX_INPROC_SERVER,IID_IColorScheme,(void**)&scheme); scheme->SetColors4(colors); double minValue, maxValue; @@ -2917,7 +2917,7 @@ bool CGrid::BuildUniqueColorScheme(int maxValuesCount, PredefinedColorScheme col // add break for value IGridColorBreak * brk; - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&brk); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&brk); brk->put_LowValue( val ); brk->put_HighValue( val ); @@ -2940,7 +2940,7 @@ bool CGrid::BuildUniqueColorScheme(int maxValuesCount, PredefinedColorScheme col } } - brk->put_LowColor(color); + brk->put_LowColor(color); brk->put_HighColor(color); brk->put_ColoringType(coloringType); @@ -2962,7 +2962,7 @@ bool CGrid::BuildUniqueColorScheme(int maxValuesCount, PredefinedColorScheme col // TODO: perhaps can be exposed to API bool CGrid::GetUniqueValues(set& values, int maxCount) { - IGridHeader* header = NULL; + IGridHeader* header = nullptr; this->get_Header(&header); if (!header) return false; @@ -3007,8 +3007,8 @@ IGridColorScheme* CGrid::BuildGradientColorSchemeCore(PredefinedColorScheme colo this->get_Maximum(&max); this->get_Minimum(&min); - IGridColorScheme* scheme = NULL; - CoCreateInstance(CLSID_GridColorScheme,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorScheme,(void**)&scheme); + IGridColorScheme* scheme = nullptr; + CoCreateInstance(CLSID_GridColorScheme, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorScheme,(void**)&scheme); if (scheme) { double low, high; @@ -3028,7 +3028,7 @@ STDMETHODIMP CGrid::get_Band(long bandIndex, IGdalRasterBand** retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *retVal = NULL; + *retVal = nullptr; if (!_trgrid) { @@ -3064,9 +3064,9 @@ STDMETHODIMP CGrid::get_ActiveBand(IGdalRasterBand** pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = NULL; + *pVal = nullptr; - if (_trgrid != NULL) + if (_trgrid != nullptr) { long bandIndex = _trgrid->GetActiveBandIndex(); get_Band(bandIndex, pVal); diff --git a/src/COM classes/GridColorScheme.cpp b/src/COM classes/GridColorScheme.cpp index 9da6a90d..ef597c0d 100644 --- a/src/COM classes/GridColorScheme.cpp +++ b/src/COM classes/GridColorScheme.cpp @@ -39,7 +39,7 @@ STDMETHODIMP CGridColorScheme::get_NumBreaks(long *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *pVal = _breaks.size(); + *pVal = static_cast(_breaks.size()); return S_OK; } @@ -58,13 +58,13 @@ STDMETHODIMP CGridColorScheme::put_AmbientIntensity(double newVal) AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; - //Intensity must be between 0 and 1 + //Intensity must be between 0 and 1 if ( newVal >=0 && newVal <= 1) { _ambientIntensity = newVal; } else - { + { ErrorMessage(tkOUT_OF_RANGE_0_TO_1); } @@ -90,7 +90,7 @@ STDMETHODIMP CGridColorScheme::put_LightSourceIntensity(double newVal) _lightSourceIntensity = newVal; } else - { + { ErrorMessage(tkOUT_OF_RANGE_0_TO_1); } @@ -137,10 +137,10 @@ STDMETHODIMP CGridColorScheme::SetLightSource(double Azimuth, double Elevation) _lightSourceElevation = Elevation; Matrix ry; - ry.rotateMY((int)Azimuth); + ry.rotateMY(static_cast(Azimuth)); Matrix rx; - rx.rotateX((int)Elevation); + rx.rotateX(static_cast(Elevation)); Matrix comp = rx*ry; @@ -158,7 +158,7 @@ STDMETHODIMP CGridColorScheme::InsertBreak(IGridColorBreak *BrkInfo) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if( BrkInfo == NULL ) + if( BrkInfo == nullptr) { ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); return S_OK; @@ -172,7 +172,7 @@ STDMETHODIMP CGridColorScheme::InsertBreak(IGridColorBreak *BrkInfo) STDMETHODIMP CGridColorScheme::InsertAt(int Position, IGridColorBreak *Break) { - if( Break == NULL ) + if( Break == nullptr) return S_OK; Break->AddRef(); @@ -184,12 +184,12 @@ STDMETHODIMP CGridColorScheme::get_Break(long Index, IGridColorBreak **pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if( Index >= 0 && Index < (long)_breaks.size() ) + if( Index >= 0 && Index < static_cast(_breaks.size()) ) { _breaks[Index]->AddRef(); *pVal = _breaks[Index]; } else - { *pVal = NULL; + { *pVal = nullptr; ErrorMessage(tkINDEX_OUT_OF_BOUNDS); } @@ -199,14 +199,14 @@ STDMETHODIMP CGridColorScheme::get_Break(long Index, IGridColorBreak **pVal) STDMETHODIMP CGridColorScheme::DeleteBreak(long Index) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - - if( Index >= 0 && Index < (long)_breaks.size() ) + + if( Index >= 0 && Index < static_cast(_breaks.size()) ) { _breaks[Index]->Release(); _breaks.erase( _breaks.begin() + Index ); } else - { + { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); } @@ -280,7 +280,7 @@ STDMETHODIMP CGridColorScheme::UsePredefined(double LowValue, double HighValue, } OLE_COLOR clr1, clr2; - IGridColorBreak* br = NULL; + IGridColorBreak* br = nullptr; double step = (HighValue - LowValue) / 6; for(int i = 0; i < 6; i++) @@ -299,8 +299,8 @@ STDMETHODIMP CGridColorScheme::UsePredefined(double LowValue, double HighValue, else if( Preset == SummerMountains ) { IGridColorBreak* lowbreak, * highbreak; - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); lowbreak->put_LowValue( LowValue ); lowbreak->put_HighValue( (HighValue + LowValue) / 2 ); @@ -321,8 +321,8 @@ STDMETHODIMP CGridColorScheme::UsePredefined(double LowValue, double HighValue, else if( Preset == FallLeaves ) { IGridColorBreak * lowbreak, * highbreak; - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); lowbreak->put_LowValue( LowValue ); lowbreak->put_HighValue( (HighValue + LowValue) / 2 ); @@ -343,8 +343,8 @@ STDMETHODIMP CGridColorScheme::UsePredefined(double LowValue, double HighValue, else if( Preset == Desert ) { IGridColorBreak * lowbreak, * highbreak; - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); lowbreak->put_LowValue(LowValue); lowbreak->put_HighValue( (HighValue + LowValue) / 2 ); @@ -365,8 +365,8 @@ STDMETHODIMP CGridColorScheme::UsePredefined(double LowValue, double HighValue, else if( Preset == Glaciers ) { IGridColorBreak * lowbreak, * highbreak; - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); lowbreak->put_LowValue(LowValue); lowbreak->put_HighValue( (HighValue + LowValue) / 2 ); @@ -387,8 +387,8 @@ STDMETHODIMP CGridColorScheme::UsePredefined(double LowValue, double HighValue, else if( Preset == Meadow ) { IGridColorBreak * lowbreak, * highbreak; - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); lowbreak->put_LowValue(LowValue); lowbreak->put_HighValue( (HighValue + LowValue) / 2 ); @@ -409,8 +409,8 @@ STDMETHODIMP CGridColorScheme::UsePredefined(double LowValue, double HighValue, else if( Preset == ValleyFires ) { IGridColorBreak * lowbreak, * highbreak; - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); lowbreak->put_LowValue(LowValue); lowbreak->put_HighValue( (HighValue + LowValue) / 2 ); @@ -431,8 +431,8 @@ STDMETHODIMP CGridColorScheme::UsePredefined(double LowValue, double HighValue, else if( Preset == DeadSea ) { IGridColorBreak * lowbreak, * highbreak; - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); lowbreak->put_LowValue(LowValue); lowbreak->put_HighValue( (HighValue + LowValue) / 2 ); @@ -453,8 +453,8 @@ STDMETHODIMP CGridColorScheme::UsePredefined(double LowValue, double HighValue, else if( Preset == Highway1 ) { IGridColorBreak * lowbreak, * highbreak; - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&lowbreak); + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&highbreak); lowbreak->put_LowValue(LowValue); lowbreak->put_HighValue( (HighValue + LowValue) / 2 ); @@ -480,7 +480,7 @@ STDMETHODIMP CGridColorScheme::GetLightSource(IVector **result) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - CoCreateInstance(CLSID_Vector,NULL,CLSCTX_INPROC_SERVER,IID_IVector,(void**)result); + CoCreateInstance(CLSID_Vector, nullptr,CLSCTX_INPROC_SERVER,IID_IVector,(void**)result); (*result)->put_i(_lightSource.geti()); (*result)->put_j(_lightSource.getj()); (*result)->put_k(_lightSource.getk()); @@ -512,7 +512,7 @@ STDMETHODIMP CGridColorScheme::get_GlobalCallback(ICallback **pVal) AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _globalCallback; - if( _globalCallback != NULL ) + if( _globalCallback != nullptr) { _globalCallback->AddRef(); } @@ -572,10 +572,10 @@ CPLXMLNode* CGridColorScheme::SerializeCore(CString ElementName) if (ElementName.GetLength() == 0) ElementName = "GridColorSchemeClass"; - CPLXMLNode* psTree = CPLCreateXMLNode( NULL, CXT_Element, ElementName); + CPLXMLNode* psTree = CPLCreateXMLNode(nullptr, CXT_Element, ElementName); Utility::CPLCreateXMLAttributeAndValue(psTree, "Key", OLE2CA(_key)); - Utility::CPLCreateXMLAttributeAndValue(psTree, "NoDataColor", (int)_noDataColor); + Utility::CPLCreateXMLAttributeAndValue(psTree, "NoDataColor", static_cast(_noDataColor)); Utility::CPLCreateXMLAttributeAndValue(psTree, "LightSourceIntensity", _lightSourceIntensity); Utility::CPLCreateXMLAttributeAndValue(psTree, "AmbientIntensity", _ambientIntensity); Utility::CPLCreateXMLAttributeAndValue(psTree, "LightSourceElevation", _lightSourceElevation); @@ -596,10 +596,10 @@ CPLXMLNode* CGridColorScheme::SerializeCore(CString ElementName) OLE_COLOR color; _breaks[i]->get_HighColor(&color); - Utility::CPLCreateXMLAttributeAndValue(psNode, "HighColor", (int)color); + Utility::CPLCreateXMLAttributeAndValue(psNode, "HighColor", static_cast(color)); _breaks[i]->get_LowColor(&color); - Utility::CPLCreateXMLAttributeAndValue(psNode, "LowColor", (int)color); + Utility::CPLCreateXMLAttributeAndValue(psNode, "LowColor", static_cast(color)); double val; _breaks[i]->get_LowValue(&val); @@ -660,28 +660,28 @@ bool CGridColorScheme::DeserializeCore(CPLXMLNode* node) CString s; - s = CPLGetXMLValue( node, "NoDataColor", NULL ); + s = CPLGetXMLValue( node, "NoDataColor", nullptr); if (s != "") _noDataColor = (OLE_COLOR)atoi(s); - s = CPLGetXMLValue( node, "LightSourceIntensity", NULL ); + s = CPLGetXMLValue( node, "LightSourceIntensity", nullptr); if (s != "") _lightSourceIntensity = Utility::atof_custom(s); - s = CPLGetXMLValue( node, "AmbientIntensity", NULL ); + s = CPLGetXMLValue( node, "AmbientIntensity", nullptr); if (s != "") _ambientIntensity = Utility::atof_custom(s); - s = CPLGetXMLValue( node, "LightSourceElevation", NULL ); + s = CPLGetXMLValue( node, "LightSourceElevation", nullptr); if (s != "") _lightSourceElevation = Utility::atof_custom(s); - s = CPLGetXMLValue( node, "LightSourceAzimuth", NULL ); + s = CPLGetXMLValue( node, "LightSourceAzimuth", nullptr); if (s != "") _lightSourceAzimuth = Utility::atof_custom(s); - s = CPLGetXMLValue( node, "LightSourceI", NULL ); + s = CPLGetXMLValue( node, "LightSourceI", nullptr); if (s != "") _lightSource.seti(Utility::atof_custom(s)); - s = CPLGetXMLValue( node, "LightSourceJ", NULL ); + s = CPLGetXMLValue( node, "LightSourceJ", nullptr); if (s != "") _lightSource.setj(Utility::atof_custom(s)); - s = CPLGetXMLValue( node, "LightSourceK", NULL ); + s = CPLGetXMLValue( node, "LightSourceK", nullptr); if (s != "") _lightSource.setk(Utility::atof_custom(s)); // restoring breaks @@ -695,54 +695,54 @@ bool CGridColorScheme::DeserializeCore(CPLXMLNode* node) { if (strcmp(node->pszValue, "GridColorBreakClass") == 0) { - IGridColorBreak* br = NULL; - CoCreateInstance(CLSID_GridColorBreak,NULL,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&br); - + IGridColorBreak* br = nullptr; + CoCreateInstance(CLSID_GridColorBreak, nullptr,CLSCTX_INPROC_SERVER,IID_IGridColorBreak,(void**)&br); + if (br) { // high color OLE_COLOR color = RGB(0,0,0); - s = CPLGetXMLValue( node, "HighColor", NULL ); + s = CPLGetXMLValue( node, "HighColor", nullptr); if (s != "") color = (OLE_COLOR)atoi( s ); br->put_HighColor(color); // low color color = RGB(0,0,0); - s = CPLGetXMLValue( node, "LowColor", NULL ); + s = CPLGetXMLValue( node, "LowColor", nullptr); if (s != "") color = (OLE_COLOR)atoi( s ); br->put_LowColor(color); // low value double val = 0.0; - s = CPLGetXMLValue( node, "LowValue", NULL ); + s = CPLGetXMLValue( node, "LowValue", nullptr); if (s != "") val = Utility::atof_custom( s ); br->put_LowValue(val); // high value val = 0.0; - s = CPLGetXMLValue( node, "HighValue", NULL ); + s = CPLGetXMLValue( node, "HighValue", nullptr); if (s != "") val = Utility::atof_custom( s ); br->put_HighValue(val); // caption - s = CPLGetXMLValue( node, "Caption", NULL ); + s = CPLGetXMLValue( node, "Caption", nullptr); CComBSTR bstrCaption(s); br->put_Caption(bstrCaption); // coloring type ColoringType type = Hillshade; - s = CPLGetXMLValue( node, "ColoringType", NULL ); + s = CPLGetXMLValue( node, "ColoringType", nullptr); if (s != "") type = (ColoringType)atoi( s ); br->put_ColoringType(type); // gradient model GradientModel model = Linear; - s = CPLGetXMLValue( node, "GradientModel", NULL ); + s = CPLGetXMLValue( node, "GradientModel", nullptr); if (s != "") model = (GradientModel)atoi( s ); br->put_GradientModel(model); VARIANT_BOOL visible = VARIANT_TRUE; - s = CPLGetXMLValue(node, "Visible", NULL); + s = CPLGetXMLValue(node, "Visible", nullptr); if (s != "") visible = (VARIANT_BOOL)atoi(s); br->put_Visible(visible); @@ -785,7 +785,7 @@ STDMETHODIMP CGridColorScheme::Deserialize(BSTR newVal) // ******************************************************** STDMETHODIMP CGridColorScheme::ReadFromFile(BSTR mwlegFilename, BSTR nodeName, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; USES_CONVERSION; @@ -813,10 +813,10 @@ STDMETHODIMP CGridColorScheme::ReadFromFile(BSTR mwlegFilename, BSTR nodeName, V // ******************************************************** STDMETHODIMP CGridColorScheme::WriteToFile(BSTR mwlegFilename, BSTR gridName, int bandIndex, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + USES_CONVERSION; - CPLXMLNode *psTree = CPLCreateXMLNode( NULL, CXT_Element, "ColoringScheme" ); + CPLXMLNode *psTree = CPLCreateXMLNode(nullptr, CXT_Element, "ColoringScheme" ); if (psTree) { Utility::WriteXmlHeaderAttributes(psTree, "GridColorScheme"); @@ -840,7 +840,7 @@ STDMETHODIMP CGridColorScheme::WriteToFile(BSTR mwlegFilename, BSTR gridName, in // ******************************************************** STDMETHODIMP CGridColorScheme::ApplyColoringType(ColoringType coloringType) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) for(size_t i = 0; i < _breaks.size(); i++) { _breaks[i]->put_ColoringType(coloringType); @@ -853,7 +853,7 @@ STDMETHODIMP CGridColorScheme::ApplyColoringType(ColoringType coloringType) // ******************************************************** STDMETHODIMP CGridColorScheme::ApplyGradientModel(GradientModel gradientModel) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) for(size_t i = 0; i < _breaks.size(); i++) { _breaks[i]->put_GradientModel(gradientModel); @@ -867,7 +867,7 @@ STDMETHODIMP CGridColorScheme::ApplyGradientModel(GradientModel gradientModel) STDMETHODIMP CGridColorScheme::ApplyColors(tkColorSchemeType type, IColorScheme* colorScheme, VARIANT_BOOL gradientWithinCategories, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (_breaks.size() < 2) @@ -913,4 +913,4 @@ STDMETHODIMP CGridColorScheme::ApplyColors(tkColorSchemeType type, IColorScheme* *retVal = VARIANT_TRUE; return S_OK; -} \ No newline at end of file +} diff --git a/src/COM classes/Image.cpp b/src/COM classes/Image.cpp index 6092a526..7ba1f545 100644 --- a/src/COM classes/Image.cpp +++ b/src/COM classes/Image.cpp @@ -60,7 +60,7 @@ VARIANT_BOOL CImageClass::WriteWorldFile(const CStringW worldFileName) } setlocale(LC_ALL,"C"); - fprintf(fout,"%.14f\n",_dX); + fprintf(fout,"%.14f\n",_dX); fprintf(fout,"%.14f\n",0.0); fprintf(fout,"%.14f\n",0.0); fprintf(fout,"%.14f\n",_dY*-1.0); @@ -118,7 +118,7 @@ STDMETHODIMP CImageClass::Resource(BSTR newImgPath, VARIANT_BOOL *retval) USES_CONVERSION; Close(retval); - Open(newImgPath, USE_FILE_EXTENSION, true, NULL, retval); + Open(newImgPath, USE_FILE_EXTENSION, true, nullptr, retval); return S_OK; } @@ -180,7 +180,7 @@ void CImageClass::LoadImageAttributesFromGridColorScheme(IGridColorScheme* schem // checkForProxy = false; image is being opened by grid code and we already know that it is a proxy, and all the logic will be executed in grid class void CImageClass::OpenImage(CStringW imageFileName, ImageType fileType, VARIANT_BOOL inRam, ICallback *cBack, GDALAccess accessMode, bool checkForProxy, VARIANT_BOOL *retval) { - _fileName = imageFileName; + _fileName = imageFileName; _inRam = inRam == VARIANT_TRUE; // child classes will be deleted here @@ -188,7 +188,7 @@ void CImageClass::OpenImage(CStringW imageFileName, ImageType fileType, VARIANT_ if (*retval == VARIANT_FALSE) return; - + // figuring out extension from the path if(fileType == USE_FILE_EXTENSION) { @@ -275,7 +275,7 @@ void CImageClass::SetImageTypeCore(ImageType fileType) // ******************************************************** // checks if this is a proxy for some grid bool CImageClass::CheckForProxy() -{ +{ if (!Utility::EndsWith(_fileName, L"_proxy.bmp") && !Utility::EndsWith(_fileName, L"_proxy.tif")) { return false; @@ -288,8 +288,8 @@ bool CImageClass::CheckForProxy() } CPLXMLNode* node = GdalHelper::ParseXMLFile(legendName); - - const char* value = CPLGetXMLValue( node, "GridName", NULL ); + + const char* value = CPLGetXMLValue( node, "GridName", nullptr); CStringW nameW = Utility::ConvertFromUtf8(value); if (nameW.GetLength() == 0 && _fileName.GetLength() > 16) @@ -308,7 +308,7 @@ bool CImageClass::CheckForProxy() this->isGridProxy = true; VARIANT_BOOL vb; - IGridColorScheme* scheme = NULL; + IGridColorScheme* scheme = nullptr; ComHelper::CreateInstance(idGridColorScheme, (IDispatch**)&scheme); CComBSTR bstrName(legendName); @@ -330,14 +330,14 @@ bool CImageClass::CheckForProxy() // OpenGdalRaster() // ******************************************************** bool CImageClass::OpenGdalRaster(const CStringW ImageFile, GDALAccess accessMode) -{ +{ if (!_raster) { return false; } - - // inRam is always true for GDAL-based images - _inRam = true; - + + // inRam is always true for GDAL-based images + _inRam = true; + if (!_raster->Open(ImageFile, accessMode)) { ErrorMessage(tkCANT_OPEN_FILE); @@ -346,10 +346,10 @@ bool CImageClass::OpenGdalRaster(const CStringW ImageFile, GDALAccess accessMode _fileName = ImageFile; _gdal = true; - _dataLoaded = false; //not yet loaded into ImageData + _dataLoaded = false; //not yet loaded into ImageData - // default is RGB(0,0,0) if no data value wasn't set - _transColor = (int)_raster->GetTransparentColor(); + // default is RGB(0,0,0) if no data value wasn't set + _transColor = static_cast(_raster->GetTransparentColor()); _transColor2 = _transColor; _useTransColor = _raster->HasTransparency() ? VARIANT_TRUE : VARIANT_FALSE; @@ -506,7 +506,7 @@ STDMETHODIMP CImageClass::Close(VARIANT_BOOL *retval) { _raster->Close(); delete _raster; - _raster = NULL; + _raster = nullptr; } else { @@ -516,14 +516,14 @@ STDMETHODIMP CImageClass::Close(VARIANT_BOOL *retval) } else { - if( _bitmapImage ) + if( _bitmapImage ) { _bitmapImage->Close(); delete _bitmapImage; - _bitmapImage = NULL; + _bitmapImage = nullptr; } } - + if (_labels) { _labels->Clear(); @@ -532,13 +532,13 @@ STDMETHODIMP CImageClass::Close(VARIANT_BOOL *retval) if (_imageData) { delete[] _imageData; - _imageData = NULL; + _imageData = nullptr; } if (_screenBitmap) { delete _screenBitmap; - _screenBitmap = NULL; + _screenBitmap = nullptr; } // set default properties @@ -552,18 +552,18 @@ STDMETHODIMP CImageClass::Close(VARIANT_BOOL *retval) if (m_pixels) { delete[] m_pixels; - m_pixels = NULL; + m_pixels = nullptr; } m_groupID = -1; - m_pixels = NULL; + m_pixels = nullptr; m_pixelsCount = 0; _pixelsSaved = false; if (_iconGdiPlus) { delete _iconGdiPlus; - _iconGdiPlus = NULL; + _iconGdiPlus = nullptr; } _sourceType = istUninitialized; @@ -591,7 +591,7 @@ STDMETHODIMP CImageClass::Clear(OLE_COLOR CanvasColor, ICallback *CBack, VARIANT colour NewColor(Red, Green, Blue); long size = _height * _width; - if (_imageData == NULL) + if (_imageData == nullptr) { *retval = VARIANT_FALSE; ErrorMessage(tkFILE_NOT_OPEN); @@ -691,7 +691,7 @@ STDMETHODIMP CImageClass::get_Value(long row, long col, int *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (!GetValueCore(row, col, true, (long*)pVal)) + if (!GetValueCore(row, col, true, reinterpret_cast(pVal))) { *pVal = -1; } @@ -706,7 +706,7 @@ STDMETHODIMP CImageClass::get_ValueWithAlpha(LONG row, LONG col, OLE_COLOR* pVal { AFX_MANAGE_STATE(AfxGetStaticModuleState()); - if (!GetValueCore(row, col, true, (long*)pVal)) + if (!GetValueCore(row, col, true, reinterpret_cast(pVal))) { *pVal = 0x00000000; } @@ -869,7 +869,7 @@ STDMETHODIMP CImageClass::get_TransparencyColor2(OLE_COLOR* retVal) STDMETHODIMP CImageClass::put_TransparencyColor2(OLE_COLOR newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (newVal != _transColor2) + if (newVal != _transColor2) { _pixelsSaved = false; // pixels saved for grouping will be invalid _canUseGrouping = true; @@ -889,7 +889,7 @@ STDMETHODIMP CImageClass::get_UseTransparencyColor(VARIANT_BOOL *pVal) STDMETHODIMP CImageClass::put_UseTransparencyColor(VARIANT_BOOL newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (newVal != _useTransColor) + if (newVal != _useTransColor) { _pixelsSaved = false; // pixels saved for grouping will be invalid _canUseGrouping = true; @@ -953,7 +953,7 @@ STDMETHODIMP CImageClass::get_GlobalCallback(ICallback **pVal) AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _globalCallback; - if( _globalCallback != NULL ) + if( _globalCallback != nullptr) _globalCallback->AddRef(); return S_OK; @@ -1004,7 +1004,7 @@ STDMETHODIMP CImageClass::get_FileHandle(long *pVal) if( _imgType == BITMAP_FILE ) { int handle = _bitmapImage->FileHandle(); if( handle >= 0 ) - *pVal = _dup(handle); + *pVal = _dup(handle); else *pVal = -1; } @@ -1105,13 +1105,13 @@ CStringW GetGdiPlusFormat(ImageType type, CStringW& ext) // ********************************************************** bool CImageClass::WriteGDIPlus(const CStringW imageFile, const bool worldFile, const ImageType type, ICallback *cBack) { - if (!_inRam) + if (!_inRam) { ErrorMessage(tkGDIPLUS_SAVING_AVAILABLE_INRAM); return false; } - if (_width == 0 || _height == 0) + if (_width == 0 || _height == 0) { ErrorMessage(tkIMAGE_BUFFER_IS_EMPTY); return false; @@ -1261,17 +1261,17 @@ bool CImageClass::getFileType(const CStringW ImageFile, ImageType &ft) // ReadBMP() // ********************************************************** bool CImageClass::ReadBMP(const CStringW ImageFile, bool InRam) -{ +{ bool result; - + _inRam = InRam; - + if (_imageData) { delete [] _imageData; - _imageData = NULL; + _imageData = nullptr; } - + result = _inRam ? _bitmapImage->Open(ImageFile,_imageData): _bitmapImage->Open(ImageFile); if(!result) { @@ -1291,7 +1291,7 @@ bool CImageClass::ReadBMP(const CStringW ImageFile, bool InRam) int NameLength = ImageFile.GetLength(); CStringW WorldFileName = ImageFile.Left(LocationOfPeriod); CStringW ext = ImageFile.Right(NameLength - LocationOfPeriod - 1); - + //Try all three worldfile naming conventions WorldFileName += "." + ext + "w"; if (! (ReadWorldFile(WorldFileName)) ) @@ -1304,10 +1304,10 @@ bool CImageClass::ReadBMP(const CStringW ImageFile, bool InRam) WorldFileName += ".wld"; ReadWorldFile(WorldFileName); } - } + } int val; - get_Value( 0, 0, &val ); + get_Value( 0, 0, &val ); _transColor = val; _transColor2 = val; return true; @@ -1368,7 +1368,7 @@ STDMETHODIMP CImageClass::get_Picture(IPictureDisp **pVal) if (_width <= 0 || _height <= 0) { - *pVal = NULL; + *pVal = nullptr; return S_OK; } @@ -1377,7 +1377,7 @@ STDMETHODIMP CImageClass::get_Picture(IPictureDisp **pVal) HBITMAP bmp = CreateCompatibleBitmap(desktop, _width, _height); HGDIOBJ oldobj = SelectObject(compatdc, bmp); VARIANT_BOOL vbretval; - GetImageBitsDC((long)compatdc, &vbretval); + GetImageBitsDC(static_cast(reinterpret_cast(compatdc)), &vbretval); DeleteDC(compatdc); ReleaseDC(GetDesktopWindow(), desktop); @@ -1385,7 +1385,7 @@ STDMETHODIMP CImageClass::get_Picture(IPictureDisp **pVal) pd.cbSizeofstruct = sizeof(PICTDESC); pd.picType = PICTYPE_BITMAP; pd.bmp.hbitmap = bmp; - pd.bmp.hpal = NULL; + pd.bmp.hpal = nullptr; OleCreatePictureIndirect(&pd, IID_IPictureDisp, TRUE, (void**)pVal); @@ -1397,7 +1397,7 @@ STDMETHODIMP CImageClass::putref_Picture(IPictureDisp *newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if( newVal == NULL ) + if( newVal == nullptr) { ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); return S_OK; @@ -1421,7 +1421,7 @@ STDMETHODIMP CImageClass::putref_Picture(IPictureDisp *newVal) //Variable Definitions HDC hdc, hdcold; SIZE size, bmpsize; - VARIANT_BOOL vbretval; + VARIANT_BOOL vbretval; //Dimensions - Conversion pic->get_Width(&size.cx); @@ -1432,19 +1432,19 @@ STDMETHODIMP CImageClass::putref_Picture(IPictureDisp *newVal) hdc = CreateCompatibleDC(GetDC(GetDesktopWindow())); //Change the dc of the IPicture - pic->SelectPicture(hdc,&hdcold,NULL); + pic->SelectPicture(hdc,&hdcold, nullptr); - SetImageBitsDC((long)hdc,&vbretval); + SetImageBitsDC(static_cast(reinterpret_cast(hdc)),&vbretval); //Reset the dc of the IPicture - pic->SelectPicture(hdcold,NULL,NULL); + pic->SelectPicture(hdcold, nullptr, nullptr); //Delete DC DeleteDC(hdc); break; } pic->Release(); - pic = NULL; + pic = nullptr; return S_OK; } @@ -1455,27 +1455,27 @@ STDMETHODIMP CImageClass::putref_Picture(IPictureDisp *newVal) STDMETHODIMP CImageClass::GetImageBitsDC(long hDC, VARIANT_BOOL * retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - + *retval = VARIANT_FALSE; - + if (_gdal && !_dataLoaded) { ErrorMessage(tkIMAGE_BUFFER_IS_EMPTY); return S_OK; } - + HBITMAP hBMP; - hBMP = (HBITMAP)GetCurrentObject((HDC)hDC,OBJ_BITMAP); + hBMP = (HBITMAP)GetCurrentObject(reinterpret_cast(static_cast(hDC)),OBJ_BITMAP); if (hBMP == NULL) { return S_OK; } BITMAP bm; - if(! GetObject(hBMP,sizeof(BITMAP),(void*)&bm) ) { + if(! GetObject(hBMP,sizeof(BITMAP),(void*)&bm) ) { return S_OK; } - if( bm.bmWidth != _width || bm.bmHeight != _height ) { + if( bm.bmWidth != _width || bm.bmHeight != _height ) { return S_OK; } @@ -1488,7 +1488,7 @@ STDMETHODIMP CImageClass::GetImageBitsDC(long hDC, VARIANT_BOOL * retval) ImageBufferToBits(bits, rowLength); - SetDIBitsToDevice((HDC)hDC,0,0,_width,_height,0,0,0,_height,bits,&bif,DIB_RGB_COLORS); + SetDIBitsToDevice(reinterpret_cast(static_cast(hDC)),0,0,_width,_height,0,0,0,_height,bits,&bif,DIB_RGB_COLORS); delete [] bits; @@ -1534,7 +1534,7 @@ void CImageClass::ImageBufferToBits(unsigned char * bits, int rowLength) bool CImageClass::DCBitsToImageBuffer(HDC hDC) { HBITMAP hBMP = (HBITMAP)GetCurrentObject(hDC,OBJ_BITMAP); - if( hBMP == NULL ) return false; + if( hBMP == nullptr) return false; BITMAP bm; if (!GetObject(hBMP, sizeof(BITMAP), (void*)&bm)) { @@ -1642,7 +1642,7 @@ STDMETHODIMP CImageClass::SetImageBitsDC(long hDC, VARIANT_BOOL * retval) AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = VARIANT_FALSE; - bool result = DCBitsToImageBuffer((HDC)hDC); + bool result = DCBitsToImageBuffer(reinterpret_cast(static_cast(hDC))); // GDI methods when drawing to bitmap with alpha component set alpha values to 0, // i.e. creating fully transparent pixels (this is true for fonts); @@ -1659,7 +1659,7 @@ STDMETHODIMP CImageClass::SetImageBitsDC(long hDC, VARIANT_BOOL * retval) // **************************************************************** STDMETHODIMP CImageClass::SetProjection(BSTR Proj4, VARIANT_BOOL * retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _projection->ImportFromProj4(Proj4, retval); if (retval) @@ -1677,21 +1677,21 @@ STDMETHODIMP CImageClass::SetProjection(BSTR Proj4, VARIANT_BOOL * retval) // **************************************************************** STDMETHODIMP CImageClass::GetProjection(BSTR * Proj4) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _projection->ExportToProj4(Proj4); return S_OK; } STDMETHODIMP CImageClass::get_OriginalWidth(LONG* OriginalWidth) -{ - AFX_MANAGE_STATE(AfxGetStaticModuleState()); +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *OriginalWidth = _gdal ? _raster->GetOrigWidth() : _width; return S_OK; } STDMETHODIMP CImageClass::get_OriginalHeight(LONG* OriginalHeight) -{ - AFX_MANAGE_STATE(AfxGetStaticModuleState()); +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *OriginalHeight = _gdal ? _raster->GetOrigHeight() : _height; return S_OK; } @@ -1830,16 +1830,16 @@ STDMETHODIMP CImageClass::get_NoBands(int *pVal) // **************************************************************** unsigned char* CImageClass::get_ImageData() { - return _imageData ? reinterpret_cast(_imageData) : NULL; + return _imageData ? reinterpret_cast(_imageData) : nullptr; } void CImageClass::put_ImageData(colour* data) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_imageData) { delete[] _imageData; - _imageData = NULL; + _imageData = nullptr; } _imageData = data; return; @@ -1853,7 +1853,7 @@ void CImageClass::ClearBuffer() if( _imageData ) { delete[] _imageData; - _imageData = NULL; + _imageData = nullptr; } _imageData = new colour[1]; @@ -1876,13 +1876,13 @@ void CImageClass::ClearBuffer() // ************************************************************** STDMETHODIMP CImageClass::get_ClearGDALCache(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = _gdal ? _raster->GetClearGdalCache() : VARIANT_FALSE; return S_OK; } STDMETHODIMP CImageClass::put_ClearGDALCache(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_gdal) { _raster->SetClearGdalCache(newVal ? true : false); @@ -1897,14 +1897,14 @@ STDMETHODIMP CImageClass::put_ClearGDALCache(VARIANT_BOOL newVal) // ************************************************************** STDMETHODIMP CImageClass::get_TransparencyPercent(double* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *retVal = _transparencyPercent; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *retVal = _transparencyPercent; return S_OK; } STDMETHODIMP CImageClass::put_TransparencyPercent(double newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < 0.0) newVal = 0.0; if (newVal > 1.0) newVal = 1.0; _transparencyPercent = newVal; @@ -1917,13 +1917,13 @@ STDMETHODIMP CImageClass::put_TransparencyPercent(double newVal) // ************************************************************** STDMETHODIMP CImageClass::get_DownsamplingMode(tkInterpolationMode* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = _downsamplingMode; return S_OK; } STDMETHODIMP CImageClass::put_DownsamplingMode(tkInterpolationMode newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _downsamplingMode = newVal; _bufferReloadIsNeeded = true; return S_OK; @@ -1934,13 +1934,13 @@ STDMETHODIMP CImageClass::put_DownsamplingMode(tkInterpolationMode newVal) // ************************************************************** STDMETHODIMP CImageClass::get_UpsamplingMode(tkInterpolationMode* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = _upsamplingMode; return S_OK; } STDMETHODIMP CImageClass::put_UpsamplingMode(tkInterpolationMode newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _upsamplingMode = newVal; _bufferReloadIsNeeded = true; return S_OK; @@ -1951,13 +1951,13 @@ STDMETHODIMP CImageClass::put_UpsamplingMode(tkInterpolationMode newVal) // ************************************************************** STDMETHODIMP CImageClass::get_DrawingMethod(int* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = 0; return S_OK; } STDMETHODIMP CImageClass::put_DrawingMethod(int newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return S_OK; } @@ -1972,10 +1972,10 @@ bool CImageClass::get_BufferIsDownsampled() __declspec(deprecated("This is a deprecated function, use CGdalUtils::GdalBuildOverviews instead")) STDMETHODIMP CImageClass::BuildOverviews (tkGDALResamplingMethod ResamplingMethod, int numOverviews, SAFEARRAY* OverviewList, VARIANT_BOOL* retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = VARIANT_FALSE; - int count = (int)OverviewList->rgsabound[0].cElements; + int count = static_cast(OverviewList->rgsabound[0].cElements); if (count < 0 || count != numOverviews) { ErrorMessage(tkINVALID_PARAMETER_VALUE); @@ -1988,7 +1988,7 @@ STDMETHODIMP CImageClass::BuildOverviews (tkGDALResamplingMethod ResamplingMetho return S_OK; } - int* overviewList = (int*)OverviewList->pvData; + int* overviewList = static_cast(OverviewList->pvData); GDALDataset* dataset = _raster->GetDataset(); if (dataset) { @@ -2012,17 +2012,17 @@ STDMETHODIMP CImageClass::BuildOverviews (tkGDALResamplingMethod ResamplingMetho // Returns reference to Labels class STDMETHODIMP CImageClass::get_Labels(ILabels** pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _labels; - if (_labels != NULL) + if (_labels != nullptr) _labels->AddRef(); return S_OK; -}; +} STDMETHODIMP CImageClass::put_Labels(ILabels* newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - if (newVal == NULL) + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + if (newVal == nullptr) { ErrorMessage(tkINVALID_PARAMETER_VALUE); return S_OK; @@ -2030,16 +2030,16 @@ STDMETHODIMP CImageClass::put_Labels(ILabels* newVal) ComHelper::SetRef(newVal, (IDispatch**)&_labels, false); return S_OK; -}; +} // ******************************************************************** // get_Extents() // ******************************************************************** STDMETHODIMP CImageClass::get_Extents(IExtents** pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - IExtents * bBox = NULL; + IExtents * bBox = nullptr; ComHelper::CreateExtents(&bBox); double minX, minY, maxX, maxY; @@ -2071,8 +2071,8 @@ void CImageClass::ClearNotNullPixels() { if ( m_pixels ) { - delete[] m_pixels; - m_pixels = NULL; + delete[] m_pixels; + m_pixels = nullptr; m_pixelsCount = 0; } } @@ -2098,7 +2098,7 @@ bool CImageClass::SaveNotNullPixels(bool forceSaving) if (_width <= 0 || _height <= 0 || (_width * _height > 1048576.0 * 100.0 / 3.0 )) // 100 MB return false; - + // the maximum part of non-transparent pixels double part = 0.1; if (forceSaving) @@ -2117,7 +2117,7 @@ bool CImageClass::SaveNotNullPixels(bool forceSaving) int count = 0; int maxPixels = (int)((double)_width * (double)_height * part); // this method will work only when pixles are scarce, therefore we set 10% as maximum - + // there is single transparent color if (_transColor == _transColor2) { @@ -2174,7 +2174,7 @@ bool CImageClass::SaveNotNullPixels(bool forceSaving) } // copying pixels to the permanent structure - if ( count < maxPixels) + if ( count < maxPixels) { if (count > 0) { @@ -2190,23 +2190,23 @@ bool CImageClass::SaveNotNullPixels(bool forceSaving) m_pixelsCount = 0; result = false; } - + // cleaning if( _imageData ) { delete[] _imageData; - _imageData = NULL; + _imageData = nullptr; } _width = 0; - _height = 0; + _height = 0; } - + delete[] tmpData; return result; } // ******************************************************************** -// ErrorMessage() +// ErrorMessage() // ******************************************************************** void CImageClass::ErrorMessage(long ErrorCode) { @@ -2220,7 +2220,7 @@ void CImageClass::ErrorMessage(long ErrorCode) // Returns image coordinates to the given map coordinates STDMETHODIMP CImageClass::ProjectionToImage(double ProjX, double ProjY, long* Column, long* Row) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_gdal) { *Column = Utility::Rint((ProjX - _raster->GetOrigXllCenter()) / _raster->GetOrigDx()); @@ -2241,8 +2241,8 @@ STDMETHODIMP CImageClass::ProjectionToImage(double ProjX, double ProjY, long* Co // !!! Don't check that input pixel is within width / height bounds !!! STDMETHODIMP CImageClass::ImageToProjection(long Column, long Row, double* ProjX, double* ProjY) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + if (_gdal) { *ProjX = _raster->GetOrigXllCenter() + (Column - 0.5) * _raster->GetOrigDx(); @@ -2262,7 +2262,7 @@ STDMETHODIMP CImageClass::ImageToProjection(long Column, long Row, double* ProjX // Returns image coordinates to the given map coordinates STDMETHODIMP CImageClass::ProjectionToBuffer(double ProjX, double ProjY, long* BufferX, long* BufferY) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *BufferX = Utility::Rint((ProjX - _xllCenter)/_dX); *BufferY = Utility::Rint((double)_height - 1 - ((ProjY - _yllCenter)/_dY)); return S_OK; @@ -2274,7 +2274,7 @@ STDMETHODIMP CImageClass::ProjectionToBuffer(double ProjX, double ProjY, long* B // Returns map coordinates to the given image coordinates STDMETHODIMP CImageClass::BufferToProjection(long BufferX, long BufferY, double* ProjX, double* ProjY) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *ProjX = _xllCenter + (BufferX - 0.5) * _dX; *ProjY = _yllCenter + (_height - 1 - BufferY + 0.5) * _dY; return S_OK; @@ -2285,13 +2285,13 @@ STDMETHODIMP CImageClass::BufferToProjection(long BufferX, long BufferY, double* // ************************************************************** STDMETHODIMP CImageClass::get_CanUseGrouping (VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = (VARIANT_BOOL)_canUseGrouping; return S_OK; } STDMETHODIMP CImageClass::put_CanUseGrouping(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _canUseGrouping = newVal?true:false; return S_OK; } @@ -2324,14 +2324,14 @@ STDMETHODIMP CImageClass::put_CanUseGrouping(VARIANT_BOOL newVal) // ************************************************************** STDMETHODIMP CImageClass::get_OriginalXllCenter( double *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _gdal && _raster ? _raster->GetOrigXllCenter() : _xllCenter; return S_OK; } STDMETHODIMP CImageClass::put_OriginalXllCenter( double newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_gdal && _raster) { _raster->SetOrigXllCenter(newVal); @@ -2347,14 +2347,14 @@ STDMETHODIMP CImageClass::put_OriginalXllCenter( double newVal) // ************************************************************** STDMETHODIMP CImageClass::get_OriginalYllCenter( double *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _gdal && _raster ? _raster->GetOrigYllCenter() : _yllCenter; return S_OK; } STDMETHODIMP CImageClass::put_OriginalYllCenter( double newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_gdal && _raster) { _raster->SetOrigYllCenter(newVal); @@ -2377,7 +2377,7 @@ STDMETHODIMP CImageClass::get_OriginalDX( double *pVal) STDMETHODIMP CImageClass::put_OriginalDX( double newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if ( newVal > 0.0) { if (_gdal && _raster) @@ -2398,14 +2398,14 @@ STDMETHODIMP CImageClass::put_OriginalDX( double newVal) // ************************************************************** STDMETHODIMP CImageClass::get_OriginalDY( double *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _gdal && _raster ? _raster->GetOrigDy() : _dY; return S_OK; } STDMETHODIMP CImageClass::put_OriginalDY( double newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if ( newVal > 0.0) { if (_gdal && _raster) @@ -2537,7 +2537,7 @@ STDMETHODIMP CImageClass::GetUniqueColors (double MaxBufferSizeMB, VARIANT* Colo { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - colour* data = NULL; + colour* data = nullptr; if ( _gdal ) { // TODO: opening for the second time isn't good enough; reconsider @@ -2553,14 +2553,14 @@ STDMETHODIMP CImageClass::GetUniqueColors (double MaxBufferSizeMB, VARIANT* Colo long size = raster->GetWidth() * raster->GetHeight(); BuildColorMap(data, size, Colors, Frequencies, Count); delete[] data; - data = NULL; + data = nullptr; } } // deleting temporary raster raster->Close(); delete raster; - raster = NULL; + raster = nullptr; } } else @@ -2604,11 +2604,11 @@ STDMETHODIMP CImageClass::GetUniqueColors (double MaxBufferSizeMB, VARIANT* Colo bool CImageClass::BuildColorMap(colour* data, int size, VARIANT* Colors, VARIANT* Frequencies, long* count) { *count = 0; - + if (size == 0) return false; - + std::map myMap; // color as key and frequency as value - + // building list of colors and frequencies for (int i = 0; i < size; i++) { @@ -2617,16 +2617,16 @@ bool CImageClass::BuildColorMap(colour* data, int size, VARIANT* Colors, VARIANT if (myMap.find(clr) != myMap.end()) myMap[clr] += 1; - else + else myMap[clr] = 1; } - + // sorting by frequency std::multimap sortedMap; std::map ::iterator p = myMap.begin(); while(p != myMap.end()) { - pair myPair(p->second, p->first); + pair myPair(p->second, p->first); sortedMap.insert(myPair); ++p; } @@ -2645,11 +2645,10 @@ bool CImageClass::BuildColorMap(colour* data, int size, VARIANT* Colors, VARIANT frequences[i] = pp->first; ++pp; ++i; } - *count = sortedMap.size(); + *count = static_cast(sortedMap.size()); // converting to safe arrays return (Templates::Vector2SafeArray( &colors, VT_UI4, Colors) && Templates::Vector2SafeArray(&frequences, VT_I4, Frequencies)); - } // ************************************************************** @@ -2657,7 +2656,7 @@ bool CImageClass::BuildColorMap(colour* data, int size, VARIANT* Colors, VARIANT // ************************************************************** STDMETHODIMP CImageClass::SetNoDataValue(double Value, VARIANT_BOOL* Result) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_gdal && _raster) { GDALDataset* dataset = _raster->GetDataset(); @@ -2665,7 +2664,7 @@ STDMETHODIMP CImageClass::SetNoDataValue(double Value, VARIANT_BOOL* Result) } else ErrorMessage(tkAPPLICABLE_GDAL_ONLY); - + return S_OK; } @@ -2674,7 +2673,7 @@ STDMETHODIMP CImageClass::SetNoDataValue(double Value, VARIANT_BOOL* Result) // ************************************************************** STDMETHODIMP CImageClass::get_NumOverviews(int* retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = 0; @@ -2696,8 +2695,8 @@ STDMETHODIMP CImageClass::get_NumOverviews(int* retval) // loads the whole buffer STDMETHODIMP CImageClass::LoadBuffer(double maxBufferSize, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) - + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *retVal = VARIANT_FALSE; if (_sourceType == istGDIPlus) @@ -2744,7 +2743,7 @@ STDMETHODIMP CImageClass::LoadBuffer(double maxBufferSize, VARIANT_BOOL* retVal) // ************************************************************** STDMETHODIMP CImageClass::get_SourceType (tkImageSourceType* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = _sourceType; return S_OK; } @@ -2755,41 +2754,41 @@ STDMETHODIMP CImageClass::get_SourceType (tkImageSourceType* retVal) // Deprecated methods. Use 'Original' properties instead // *************************************************** STDMETHODIMP CImageClass::GetOriginalXllCenter(double *pVal) -{ +{ AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _gdal && _raster ? _raster->GetOrigXllCenter() : *pVal = _xllCenter; return S_OK; } STDMETHODIMP CImageClass::GetOriginalYllCenter(double *pVal) -{ - AFX_MANAGE_STATE(AfxGetStaticModuleState()) +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _gdal && _raster ? _raster->GetOrigYllCenter() : _yllCenter; return S_OK; } STDMETHODIMP CImageClass::GetOriginal_dX(double *pVal) -{ +{ AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _gdal && _raster ? _raster->GetOrigDx() : *pVal = _dX; return S_OK; } STDMETHODIMP CImageClass::GetOriginal_dY(double *pVal) -{ +{ AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _gdal && _raster ? _raster->GetOrigDy() : *pVal = _dY; return S_OK; } STDMETHODIMP CImageClass::GetOriginalHeight(long *pVal) -{ +{ AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _gdal && _raster ? _raster->GetOrigHeight() : _height; return S_OK; } STDMETHODIMP CImageClass::GetOriginalWidth(long *pVal) -{ +{ AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _gdal ? _raster->GetOrigWidth() : _width; return S_OK; @@ -2834,10 +2833,10 @@ CPLXMLNode* CImageClass::SerializeCore(VARIANT_BOOL SerializePixels, CString Ele if (SerializePixels && (fullWidth * fullHeight > 200000) ) { ErrorMessage(tkICON_OR_TEXTURE_TOO_BIG); - return NULL; + return nullptr; } - CPLXMLNode* psTree = CPLCreateXMLNode( NULL, CXT_Element, ElementName); + CPLXMLNode* psTree = CPLCreateXMLNode(nullptr, CXT_Element, ElementName); // properties if (_setRGBToGrey != false) @@ -2893,7 +2892,7 @@ CPLXMLNode* CImageClass::SerializeCore(VARIANT_BOOL SerializePixels, CString Ele } else { - // if pixels are serialized, then it's icon or a texture; + // if pixels are serialized, then it's icon or a texture; // it's obvious that no labels can be there CPLXMLNode* psLabels = ((CLabels*)_labels)->SerializeCore("LabelsClass"); if (psLabels) @@ -2917,43 +2916,43 @@ bool CImageClass::DeserializeCore(CPLXMLNode* node) CString s = CPLGetXMLValue( node, "SetToGrey", "0" ); if (s != "") _setRGBToGrey = atoi(s) == 0 ? false : true; - s = CPLGetXMLValue( node, "TransparencyColor", NULL ); + s = CPLGetXMLValue( node, "TransparencyColor", nullptr); if (s != "") _transColor = (OLE_COLOR)atoi(s); - s = CPLGetXMLValue( node, "TransparencyColor2", NULL ); + s = CPLGetXMLValue( node, "TransparencyColor2", nullptr); _transColor2 = s != "" ? (OLE_COLOR)atoi(s) : _transColor ; - s = CPLGetXMLValue( node, "UseTransparencyColor", NULL ); + s = CPLGetXMLValue( node, "UseTransparencyColor", nullptr); if (s != "") _useTransColor = (VARIANT_BOOL)atoi(s); - s = CPLGetXMLValue( node, "TransparencyPercent", NULL ); + s = CPLGetXMLValue( node, "TransparencyPercent", nullptr); if (s != "") _transparencyPercent = Utility::atof_custom(s); - s = CPLGetXMLValue( node, "DownsamplingMode", NULL ); + s = CPLGetXMLValue( node, "DownsamplingMode", nullptr); if (s != "") _downsamplingMode = (tkInterpolationMode)atoi(s); - s = CPLGetXMLValue( node, "UpsamplingMode", NULL ); + s = CPLGetXMLValue( node, "UpsamplingMode", nullptr); if (s != "") _upsamplingMode = (tkInterpolationMode)atoi(s); - s = CPLGetXMLValue(node, "Brightness", NULL); + s = CPLGetXMLValue(node, "Brightness", nullptr); if (s != "") put_Brightness(static_cast(Utility::atof_custom(s))); - s = CPLGetXMLValue(node, "Contrast", NULL); + s = CPLGetXMLValue(node, "Contrast", nullptr); if (s != "") put_Contrast(static_cast(Utility::atof_custom(s))); - s = CPLGetXMLValue(node, "Saturation", NULL); + s = CPLGetXMLValue(node, "Saturation", nullptr); if (s != "") put_Saturation(static_cast(Utility::atof_custom(s))); - s = CPLGetXMLValue(node, "Hue", NULL); + s = CPLGetXMLValue(node, "Hue", nullptr); if (s != "") put_Hue(static_cast(Utility::atof_custom(s))); - s = CPLGetXMLValue(node, "Gamma", NULL); + s = CPLGetXMLValue(node, "Gamma", nullptr); if (s != "") put_Gamma(static_cast(Utility::atof_custom(s))); - s = CPLGetXMLValue(node, "ColorizeIntensity", NULL); + s = CPLGetXMLValue(node, "ColorizeIntensity", nullptr); if (s != "") put_ColorizeIntensity(static_cast(Utility::atof_custom(s))); - s = CPLGetXMLValue(node, "ColorizeColor", NULL); + s = CPLGetXMLValue(node, "ColorizeColor", nullptr); if (s != "") put_ColorizeColor((OLE_COLOR)atoi(s)); // labels @@ -3004,7 +3003,7 @@ void CImageClass::SerializePixelsCore(CPLXMLNode* psTree, long fullWidth, long f this->get_Filename(&filename); USES_CONVERSION; - unsigned char* buffer = NULL; + unsigned char* buffer = nullptr; int size = Utility::ReadFileToBuffer(OLE2W(filename), &buffer); if (size > 0) @@ -3058,12 +3057,12 @@ void CImageClass::DeserializePixels(CPLXMLNode* node) if (nodeBuffer) { bool gdiPlus = false; - s = CPLGetXMLValue(nodeBuffer, "GdiPlusBitmap", NULL); + s = CPLGetXMLValue(nodeBuffer, "GdiPlusBitmap", nullptr); if (s != "") gdiPlus = atoi(s) == 0 ? false : true; if (gdiPlus) { - std::string str = CPLGetXMLValue(nodeBuffer, "=ImageBuffer", NULL); + std::string str = CPLGetXMLValue(nodeBuffer, "=ImageBuffer", nullptr); if (str.size() != 0) { VARIANT_BOOL vbretval; @@ -3086,16 +3085,16 @@ void CImageClass::DeserializePixels(CPLXMLNode* node) else { long width = 0, height = 0; - s = CPLGetXMLValue(nodeBuffer, "Width", NULL); + s = CPLGetXMLValue(nodeBuffer, "Width", nullptr); if (s != "") width = atoi(s); - s = CPLGetXMLValue(nodeBuffer, "Height", NULL); + s = CPLGetXMLValue(nodeBuffer, "Height", nullptr); if (s != "") height = atoi(s); if (width > 0 && height > 0 && width * height < 200000) { - std::string str = CPLGetXMLValue(nodeBuffer, "=ImageBuffer", NULL); + std::string str = CPLGetXMLValue(nodeBuffer, "=ImageBuffer", nullptr); if (str.size() != 0) { // restoring buffer @@ -3142,7 +3141,7 @@ STDMETHODIMP CImageClass::Deserialize(BSTR newVal) // ******************************************************** STDMETHODIMP CImageClass::get_SourceGridName(BSTR* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; *retVal = OLE2BSTR(this->sourceGridName); return S_OK; @@ -3153,7 +3152,7 @@ STDMETHODIMP CImageClass::get_SourceGridName(BSTR* retVal) // ******************************************************** STDMETHODIMP CImageClass::get_SourceFilename(BSTR* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; *retVal = OLE2BSTR(isGridProxy ? this->sourceGridName: _fileName); return S_OK; @@ -3164,7 +3163,7 @@ STDMETHODIMP CImageClass::get_SourceFilename(BSTR* retVal) // ******************************************************** STDMETHODIMP CImageClass::get_IsGridProxy(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = isGridProxy ? VARIANT_TRUE: VARIANT_FALSE; return S_OK; } @@ -3174,15 +3173,15 @@ STDMETHODIMP CImageClass::get_IsGridProxy(VARIANT_BOOL* retVal) // ******************************************************** STDMETHODIMP CImageClass::get_GridProxyColorScheme(IGridColorScheme** retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retVal = NULL; + *retVal = nullptr; if (isGridProxy) { CStringW legendName = GridManager::GetProxyLegendName(sourceGridName); if (Utility::FileExistsW(legendName)) { - IGridColorScheme* scheme = NULL; + IGridColorScheme* scheme = nullptr; ComHelper::CreateInstance(idGridColorScheme, (IDispatch**)&scheme); VARIANT_BOOL vb; CComBSTR bstrName(legendName); @@ -3206,7 +3205,7 @@ STDMETHODIMP CImageClass::get_GridProxyColorScheme(IGridColorScheme** retVal) // ******************************************************** STDMETHODIMP CImageClass::get_GridRendering(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = _gdal ? _raster->WillBeRenderedAsGrid() : VARIANT_FALSE; @@ -3312,7 +3311,7 @@ STDMETHODIMP CImageClass::get_CustomColorScheme(IGridColorScheme** retVal) } else { - (*retVal) = NULL; + (*retVal) = nullptr; ErrorMessage(tkAPPLICABLE_GDAL_ONLY); } @@ -3364,7 +3363,7 @@ STDMETHODIMP CImageClass::get_IsRgb(VARIANT_BOOL* retVal) STDMETHODIMP CImageClass::OpenAsGrid(IGrid** retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retVal = NULL; + *retVal = nullptr; CStringW filename = isGridProxy ? this->sourceGridName : _fileName; if (Utility::FileExistsW(filename)) @@ -3378,7 +3377,7 @@ STDMETHODIMP CImageClass::OpenAsGrid(IGrid** retVal) if (!vb) { (*retVal)->Release(); - (*retVal) = NULL; + (*retVal) = nullptr; } } return S_OK; @@ -3415,7 +3414,7 @@ STDMETHODIMP CImageClass::put_SourceGridBandIndex(int newValue) // ******************************************************** STDMETHODIMP CImageClass::get_GeoProjection(IGeoProjection** pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_projection) _projection->AddRef(); @@ -3429,7 +3428,7 @@ STDMETHODIMP CImageClass::get_GeoProjection(IGeoProjection** pVal) // ******************************************************** STDMETHODIMP CImageClass::get_IsEmpty(VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _sourceType == istUninitialized ? VARIANT_TRUE : VARIANT_FALSE; return S_OK; } @@ -3439,7 +3438,7 @@ STDMETHODIMP CImageClass::get_IsEmpty(VARIANT_BOOL* pVal) // ******************************************************** int CImageClass::GetOriginalBufferWidth() { - if (_gdal && _raster) + if (_gdal && _raster) { return (_raster->GetVisibleRect().right - _raster->GetVisibleRect().left); } @@ -3452,7 +3451,7 @@ int CImageClass::GetOriginalBufferWidth() // ******************************************************** int CImageClass::GetOriginalBufferHeight() { - if (_gdal && _raster) + if (_gdal && _raster) { return (_raster->GetVisibleRect().right - _raster->GetVisibleRect().left); } @@ -3465,9 +3464,9 @@ int CImageClass::GetOriginalBufferHeight() // ******************************************************** STDMETHODIMP CImageClass::get_Band(long bandIndex, IGdalRasterBand** retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retVal = NULL; + *retVal = nullptr; if (!_gdal) { @@ -3501,7 +3500,7 @@ STDMETHODIMP CImageClass::get_Band(long bandIndex, IGdalRasterBand** retVal) // ******************************************************** STDMETHODIMP CImageClass::get_PaletteInterpretation2(tkPaletteInterpretation* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_gdal) { @@ -3520,11 +3519,11 @@ STDMETHODIMP CImageClass::get_PaletteInterpretation2(tkPaletteInterpretation* pV // ******************************************************** STDMETHODIMP CImageClass::get_ActiveBand(IGdalRasterBand** pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *pVal = NULL; + *pVal = nullptr; - if (_raster != NULL) + if (_raster != nullptr) { long bandIndex = _raster->GetActiveBandIndex(); get_Band(bandIndex, pVal); @@ -3542,7 +3541,7 @@ STDMETHODIMP CImageClass::get_ActiveBand(IGdalRasterBand** pVal) // ******************************************************** STDMETHODIMP CImageClass::get_Brightness(FLOAT* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _brightness; @@ -3551,7 +3550,7 @@ STDMETHODIMP CImageClass::get_Brightness(FLOAT* pVal) STDMETHODIMP CImageClass::put_Brightness(FLOAT newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < -1.0f) newVal = -1.0f; if (newVal > 1.0f) newVal = 1.0f; @@ -3566,7 +3565,7 @@ STDMETHODIMP CImageClass::put_Brightness(FLOAT newVal) // ******************************************************** STDMETHODIMP CImageClass::get_Contrast(FLOAT* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _contrast; @@ -3575,7 +3574,7 @@ STDMETHODIMP CImageClass::get_Contrast(FLOAT* pVal) STDMETHODIMP CImageClass::put_Contrast(FLOAT newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < 0.0f) newVal = 0.0f; if (newVal > 4.0f) newVal = 4.0f; @@ -3591,7 +3590,7 @@ STDMETHODIMP CImageClass::put_Contrast(FLOAT newVal) // ******************************************************** STDMETHODIMP CImageClass::get_Saturation(FLOAT* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _saturation; @@ -3600,7 +3599,7 @@ STDMETHODIMP CImageClass::get_Saturation(FLOAT* pVal) STDMETHODIMP CImageClass::put_Saturation(FLOAT newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < 0.0f) newVal = 0.0f; if (newVal > 3.0f) newVal = 3.0f; @@ -3615,7 +3614,7 @@ STDMETHODIMP CImageClass::put_Saturation(FLOAT newVal) // ******************************************************** STDMETHODIMP CImageClass::get_Hue(FLOAT* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _hue; @@ -3624,7 +3623,7 @@ STDMETHODIMP CImageClass::get_Hue(FLOAT* pVal) STDMETHODIMP CImageClass::put_Hue(FLOAT newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < -180.0f) newVal = -180.0f; if (newVal > 180.0f) newVal = 180.0f; @@ -3639,7 +3638,7 @@ STDMETHODIMP CImageClass::put_Hue(FLOAT newVal) // ******************************************************** STDMETHODIMP CImageClass::get_Gamma(FLOAT* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _gamma; @@ -3648,7 +3647,7 @@ STDMETHODIMP CImageClass::get_Gamma(FLOAT* pVal) STDMETHODIMP CImageClass::put_Gamma(FLOAT newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < 0.0f) newVal = 0.0f; if (newVal > 4.0f) newVal = 4.0f; @@ -3663,7 +3662,7 @@ STDMETHODIMP CImageClass::put_Gamma(FLOAT newVal) // ******************************************************** STDMETHODIMP CImageClass::get_ColorizeIntensity(FLOAT* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _colorizeIntensity; @@ -3672,7 +3671,7 @@ STDMETHODIMP CImageClass::get_ColorizeIntensity(FLOAT* pVal) STDMETHODIMP CImageClass::put_ColorizeIntensity(FLOAT newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < 0.0f) newVal = 0.0f; if (newVal > 1.0f) newVal = 1.0f; @@ -3687,7 +3686,7 @@ STDMETHODIMP CImageClass::put_ColorizeIntensity(FLOAT newVal) // ******************************************************** STDMETHODIMP CImageClass::get_ColorizeColor(OLE_COLOR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _colorizeColor; @@ -3696,7 +3695,7 @@ STDMETHODIMP CImageClass::get_ColorizeColor(OLE_COLOR* pVal) STDMETHODIMP CImageClass::put_ColorizeColor(OLE_COLOR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _colorizeColor = newVal; @@ -3718,7 +3717,7 @@ Gdiplus::ColorMatrix CImageClass::GetColorMatrix() // ******************************************************** STDMETHODIMP CImageClass::ClearOverviews(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!_gdal) { @@ -3738,9 +3737,9 @@ STDMETHODIMP CImageClass::ClearOverviews(VARIANT_BOOL* retVal) // ******************************************************** STDMETHODIMP CImageClass::get_GdalDriver(IGdalDriver** pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *pVal = NULL; + *pVal = nullptr; if (!_gdal) { @@ -3764,7 +3763,7 @@ STDMETHODIMP CImageClass::get_GdalDriver(IGdalDriver** pVal) // ******************************************************** STDMETHODIMP CImageClass::get_RedBandIndex(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = static_cast(GetRgbBandIndex(BandChannelRed)); @@ -3773,7 +3772,7 @@ STDMETHODIMP CImageClass::get_RedBandIndex(LONG* pVal) STDMETHODIMP CImageClass::put_RedBandIndex(LONG newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) SetRgbBandIndex(BandChannelRed, newVal); @@ -3785,7 +3784,7 @@ STDMETHODIMP CImageClass::put_RedBandIndex(LONG newVal) // ******************************************************** STDMETHODIMP CImageClass::get_GreenBandIndex(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = static_cast(GetRgbBandIndex(BandChannelGreen)); @@ -3794,7 +3793,7 @@ STDMETHODIMP CImageClass::get_GreenBandIndex(LONG* pVal) STDMETHODIMP CImageClass::put_GreenBandIndex(LONG newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) SetRgbBandIndex(BandChannelGreen, newVal); @@ -3806,7 +3805,7 @@ STDMETHODIMP CImageClass::put_GreenBandIndex(LONG newVal) // ******************************************************** STDMETHODIMP CImageClass::get_BlueBandIndex(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = static_cast(GetRgbBandIndex(BandChannelBlue)); @@ -3815,7 +3814,7 @@ STDMETHODIMP CImageClass::get_BlueBandIndex(LONG* pVal) STDMETHODIMP CImageClass::put_BlueBandIndex(LONG newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) SetRgbBandIndex(BandChannelBlue, newVal); @@ -3827,7 +3826,7 @@ STDMETHODIMP CImageClass::put_BlueBandIndex(LONG newVal) // ******************************************************** STDMETHODIMP CImageClass::get_UseRgbBandMapping(VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_raster) { @@ -3843,7 +3842,7 @@ STDMETHODIMP CImageClass::get_UseRgbBandMapping(VARIANT_BOOL* pVal) STDMETHODIMP CImageClass::put_UseRgbBandMapping(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_raster) { @@ -3897,7 +3896,7 @@ void CImageClass::SetRgbBandIndex(BandChannel channel, int bandIndex) // ******************************************************** STDMETHODIMP CImageClass::get_ForceSingleBandRendering(VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_raster) { @@ -3909,7 +3908,7 @@ STDMETHODIMP CImageClass::get_ForceSingleBandRendering(VARIANT_BOOL* pVal) STDMETHODIMP CImageClass::put_ForceSingleBandRendering(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_raster) { @@ -3924,7 +3923,7 @@ STDMETHODIMP CImageClass::put_ForceSingleBandRendering(VARIANT_BOOL newVal) // ******************************************************** bool CImageClass::GetBufferReloadIsNeeded() { - if (_bufferReloadIsNeeded) { + if (_bufferReloadIsNeeded) { return true; } @@ -3941,7 +3940,7 @@ bool CImageClass::GetBufferReloadIsNeeded() // ******************************************************** STDMETHODIMP CImageClass::get_AlphaBandIndex(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = static_cast(GetRgbBandIndex(BandChannelAlpha)); @@ -3950,7 +3949,7 @@ STDMETHODIMP CImageClass::get_AlphaBandIndex(LONG* pVal) STDMETHODIMP CImageClass::put_AlphaBandIndex(LONG newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) SetRgbBandIndex(BandChannelAlpha, newVal); @@ -3962,7 +3961,7 @@ STDMETHODIMP CImageClass::put_AlphaBandIndex(LONG newVal) // ******************************************************** STDMETHODIMP CImageClass::get_UseActiveBandAsAlpha(VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_raster) { @@ -3974,7 +3973,7 @@ STDMETHODIMP CImageClass::get_UseActiveBandAsAlpha(VARIANT_BOOL* pVal) STDMETHODIMP CImageClass::put_UseActiveBandAsAlpha(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_raster) { @@ -4009,7 +4008,7 @@ bool CImageClass::ValidateBandIndex(int bandIndex) // ******************************************************** STDMETHODIMP CImageClass::get_BandMinimum(LONG bandIndex, DOUBLE* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (ValidateBandIndex(bandIndex)) { @@ -4024,7 +4023,7 @@ STDMETHODIMP CImageClass::get_BandMinimum(LONG bandIndex, DOUBLE* pVal) // ******************************************************** STDMETHODIMP CImageClass::get_BandMaximum(LONG bandIndex, DOUBLE* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (ValidateBandIndex(bandIndex)) { @@ -4039,7 +4038,7 @@ STDMETHODIMP CImageClass::get_BandMaximum(LONG bandIndex, DOUBLE* pVal) // ******************************************************** STDMETHODIMP CImageClass::SetBandMinMax(LONG bandIndex, DOUBLE min, DOUBLE max, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!ValidateBandIndex(bandIndex)) { *retVal = VARIANT_FALSE; @@ -4047,7 +4046,7 @@ STDMETHODIMP CImageClass::SetBandMinMax(LONG bandIndex, DOUBLE min, DOUBLE max, } _raster->SetBandMinMax(bandIndex, min, max); - + *retVal = VARIANT_TRUE; return S_OK; } @@ -4057,7 +4056,7 @@ STDMETHODIMP CImageClass::SetBandMinMax(LONG bandIndex, DOUBLE min, DOUBLE max, // ******************************************************** STDMETHODIMP CImageClass::SetDefaultMinMax(LONG bandIndex, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!ValidateBandIndex(bandIndex)) { *retVal = VARIANT_FALSE; @@ -4065,7 +4064,7 @@ STDMETHODIMP CImageClass::SetDefaultMinMax(LONG bandIndex, VARIANT_BOOL* retVal) } _raster->SetDefaultMinMax(bandIndex); - + *retVal = VARIANT_TRUE; return S_OK; } @@ -4075,7 +4074,7 @@ STDMETHODIMP CImageClass::SetDefaultMinMax(LONG bandIndex, VARIANT_BOOL* retVal) // ******************************************************** STDMETHODIMP CImageClass::get_ReverseGreyscale(VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (IsGdalImageAvailable()) { @@ -4087,7 +4086,7 @@ STDMETHODIMP CImageClass::get_ReverseGreyscale(VARIANT_BOOL* pVal) STDMETHODIMP CImageClass::put_ReverseGreyscale(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (IsGdalImageAvailable()) { @@ -4102,7 +4101,7 @@ STDMETHODIMP CImageClass::put_ReverseGreyscale(VARIANT_BOOL newVal) // ******************************************************** STDMETHODIMP CImageClass::get_IgnoreColorTable(VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (IsGdalImageAvailable()) { @@ -4114,7 +4113,7 @@ STDMETHODIMP CImageClass::get_IgnoreColorTable(VARIANT_BOOL* pVal) STDMETHODIMP CImageClass::put_IgnoreColorTable(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (IsGdalImageAvailable()) { @@ -4129,7 +4128,7 @@ STDMETHODIMP CImageClass::put_IgnoreColorTable(VARIANT_BOOL newVal) // ******************************************************** STDMETHODIMP CImageClass::get_RenderingMode(tkRasterRendering* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _raster ? _raster->GuessRenderingMode() : rrRGB; @@ -4141,7 +4140,7 @@ STDMETHODIMP CImageClass::get_RenderingMode(tkRasterRendering* pVal) // ******************************************************** Gdiplus::Bitmap* CImageClass::GetIcon() { - return _iconGdiPlus ? _iconGdiPlus->m_bitmap : NULL; + return _iconGdiPlus ? _iconGdiPlus->m_bitmap : nullptr; } // ******************************************************** @@ -4149,7 +4148,7 @@ Gdiplus::Bitmap* CImageClass::GetIcon() // ******************************************************** STDMETHODIMP CImageClass::get_BufferOffsetX(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_raster) { @@ -4168,7 +4167,7 @@ STDMETHODIMP CImageClass::get_BufferOffsetX(LONG* pVal) // ******************************************************** STDMETHODIMP CImageClass::get_BufferOffsetY(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_raster) { @@ -4187,7 +4186,7 @@ STDMETHODIMP CImageClass::get_BufferOffsetY(LONG* pVal) // ******************************************************** STDMETHODIMP CImageClass::get_ActiveColorScheme(IGridColorScheme** pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_raster) { @@ -4197,7 +4196,7 @@ STDMETHODIMP CImageClass::get_ActiveColorScheme(IGridColorScheme** pVal) } else { - (*pVal) = NULL; + (*pVal) = nullptr; ErrorMessage(tkAPPLICABLE_GDAL_ONLY); } @@ -4209,7 +4208,7 @@ STDMETHODIMP CImageClass::get_ActiveColorScheme(IGridColorScheme** pVal) // ******************************************************** STDMETHODIMP CImageClass::put_GeoProjection(IGeoProjection* newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) ComHelper::SetRef((IDispatch*)newVal, (IDispatch**)&_projection, false); diff --git a/src/COM classes/Labels.cpp b/src/COM classes/Labels.cpp index 26cc7a15..386a3d2a 100644 --- a/src/COM classes/Labels.cpp +++ b/src/COM classes/Labels.cpp @@ -47,7 +47,7 @@ STDMETHODIMP CLabels::get_FontName(BSTR* retval) USES_CONVERSION; *retval = OLE2BSTR(_options->fontName); return S_OK; -}; +} STDMETHODIMP CLabels::put_FontName(BSTR newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) @@ -55,7 +55,7 @@ STDMETHODIMP CLabels::put_FontName(BSTR newVal) ::SysFreeString(_options->fontName); _options->fontName = OLE2BSTR(newVal); return S_OK; -}; +} // ***************************************************************** // Font/FrameTransparency() @@ -65,7 +65,7 @@ STDMETHODIMP CLabels::get_FontTransparency(long* retval) AFX_MANAGE_STATE(AfxGetStaticModuleState()) * retval = _options->fontTransparency; return S_OK; -}; +} STDMETHODIMP CLabels::put_FontTransparency(long newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) @@ -73,13 +73,13 @@ STDMETHODIMP CLabels::put_FontTransparency(long newVal) if (newVal > 255) newVal = 255; _options->fontTransparency = newVal; return S_OK; -}; +} STDMETHODIMP CLabels::get_FrameTransparency(long* retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) * retval = _options->frameTransparency; return S_OK; -}; +} STDMETHODIMP CLabels::put_FrameTransparency(long newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) @@ -87,7 +87,7 @@ STDMETHODIMP CLabels::put_FrameTransparency(long newVal) if (newVal > 255) newVal = 255; _options->frameTransparency = newVal; return S_OK; -}; +} // ***************************************************************** // Font style options @@ -96,46 +96,46 @@ STDMETHODIMP CLabels::get_FontItalic(VARIANT_BOOL* retval) { *retval = _options->fontStyle & fstItalic ? VARIANT_TRUE : VARIANT_FALSE; return S_OK; -}; +} STDMETHODIMP CLabels::put_FontItalic(const VARIANT_BOOL newVal) { if (newVal) _options->fontStyle |= fstItalic; else _options->fontStyle &= 0xFFFFFFFF ^ fstItalic; return S_OK; -}; +} STDMETHODIMP CLabels::get_FontBold(VARIANT_BOOL* retval) { *retval = _options->fontStyle & fstBold ? VARIANT_TRUE : VARIANT_FALSE; return S_OK; -}; +} STDMETHODIMP CLabels::put_FontBold(const VARIANT_BOOL newVal) { if (newVal) _options->fontStyle |= fstBold; else _options->fontStyle &= 0xFFFFFFFF ^ fstBold; return S_OK; -}; +} STDMETHODIMP CLabels::get_FontUnderline(VARIANT_BOOL* retval) { *retval = _options->fontStyle & fstUnderline ? VARIANT_TRUE : VARIANT_FALSE; return S_OK; -}; +} STDMETHODIMP CLabels::put_FontUnderline(const VARIANT_BOOL newVal) { if (newVal) _options->fontStyle |= fstUnderline; else _options->fontStyle &= 0xFFFFFFFF ^ fstUnderline; return S_OK; -}; +} STDMETHODIMP CLabels::get_FontStrikeOut(VARIANT_BOOL* retval) { *retval = _options->fontStyle & fstStrikeout ? VARIANT_TRUE : VARIANT_FALSE; return S_OK; -}; +} STDMETHODIMP CLabels::put_FontStrikeOut(const VARIANT_BOOL newVal) { if (newVal) _options->fontStyle |= fstStrikeout; else _options->fontStyle &= 0xFFFFFFFF ^ fstStrikeout; return S_OK; -}; +} //////////////////////////////////////////////////////////////// // END OF COMMON OPTIONS //////////////////////////////////////////////////////////////// @@ -207,7 +207,7 @@ STDMETHODIMP CLabels::get_Label(const long index, const long part, ILabel** pVal { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (index < 0 || index >= (long)_labels.size()) + if (index < 0 || index >= static_cast(_labels.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *pVal = nullptr; @@ -215,7 +215,7 @@ STDMETHODIMP CLabels::get_Label(const long index, const long part, ILabel** pVal else { const std::vector* parts = _labels[index]; - if (part < 0 || part >= (long)parts->size()) + if (part < 0 || part >= static_cast(parts->size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *pVal = nullptr; @@ -230,7 +230,7 @@ STDMETHODIMP CLabels::get_Label(const long index, const long part, ILabel** pVal } } return S_OK; -}; +} //***********************************************************************/ //* get_NumCategories() @@ -238,9 +238,9 @@ STDMETHODIMP CLabels::get_Label(const long index, const long part, ILabel** pVal STDMETHODIMP CLabels::get_NumCategories(long* pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - * pVal = _categories.size(); + * pVal = static_cast(_categories.size()); return S_OK; -}; +} //***********************************************************************/ //* get_numParts() @@ -248,7 +248,7 @@ STDMETHODIMP CLabels::get_NumCategories(long* pVal) STDMETHODIMP CLabels::get_NumParts(const long index, long* pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (index < 0 || index >= (long)_labels.size()) + if (index < 0 || index >= static_cast(_labels.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *pVal = -1; @@ -256,10 +256,10 @@ STDMETHODIMP CLabels::get_NumParts(const long index, long* pVal) else { const std::vector* parts = _labels[index]; - *pVal = parts->size(); + *pVal = static_cast(parts->size()); } return S_OK; -}; +} //***********************************************************************/ //* get_Category() @@ -282,7 +282,7 @@ STDMETHODIMP CLabels::get_Category(const long index, ILabelCategory** retval) //} //else { - if (index < 0 || index >= (long)_categories.size()) + if (index < 0 || index >= static_cast(_categories.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); } @@ -302,7 +302,7 @@ STDMETHODIMP CLabels::put_Category(const long index, ILabelCategory* newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (index < 0 || index >= (long)_categories.size()) + if (index < 0 || index >= static_cast(_categories.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); } @@ -328,7 +328,7 @@ STDMETHODIMP CLabels::AddLabel(const BSTR text, const double x, const double y, { AFX_MANAGE_STATE(AfxGetStaticModuleState()) VARIANT_BOOL vbretval; - this->InsertLabel(_labels.size(), text, x, y, rotation, category, offsetX, offsetY, &vbretval); + this->InsertLabel(static_cast(_labels.size()), text, x, y, rotation, category, offsetX, offsetY, &vbretval); return S_OK; } @@ -338,7 +338,7 @@ STDMETHODIMP CLabels::AddLabel(const BSTR text, const double x, const double y, STDMETHODIMP CLabels::InsertLabel(long Index, BSTR Text, double x, double y, double Rotation, long Category, double offsetX, double offsetY, VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >(long)_labels.size()) + if (Index < 0 || Index >static_cast(_labels.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = VARIANT_FALSE; @@ -385,7 +385,7 @@ CLabelInfo* CLabels::CreateNewLabel(const BSTR& Text, double x, double y, double STDMETHODIMP CLabels::RemoveLabel(long Index, VARIANT_BOOL* vbretval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >= (long)_labels.size()) + if (Index < 0 || Index >= static_cast(_labels.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *vbretval = VARIANT_FALSE; @@ -402,7 +402,7 @@ STDMETHODIMP CLabels::RemoveLabel(long Index, VARIANT_BOOL* vbretval) *vbretval = VARIANT_TRUE; } return S_OK; -}; +} ///***********************************************************************/ ///* AddPart() @@ -410,7 +410,7 @@ STDMETHODIMP CLabels::RemoveLabel(long Index, VARIANT_BOOL* vbretval) STDMETHODIMP CLabels::AddPart(long Index, BSTR Text, double x, double y, double Rotation, long Category, double offsetX, double offsetY) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >(int)_labels.size()) + if (Index < 0 || Index >static_cast(_labels.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); return S_OK; @@ -418,9 +418,9 @@ STDMETHODIMP CLabels::AddPart(long Index, BSTR Text, double x, double y, double std::vector* parts = _labels[Index]; VARIANT_BOOL vbretval; - InsertPart(Index, parts->size(), Text, x, y, Rotation, Category, offsetX, offsetY, &vbretval); + InsertPart(Index, static_cast(parts->size()), Text, x, y, Rotation, Category, offsetX, offsetY, &vbretval); return S_OK; -}; +} ///***********************************************************************/ ///* AddPart() @@ -428,7 +428,7 @@ STDMETHODIMP CLabels::AddPart(long Index, BSTR Text, double x, double y, double STDMETHODIMP CLabels::InsertPart(long Index, long Part, BSTR Text, double x, double y, double Rotation, long Category, double offsetX, double offsetY, VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >= (int)_labels.size()) + if (Index < 0 || Index >= static_cast(_labels.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); return S_OK; @@ -448,7 +448,7 @@ STDMETHODIMP CLabels::InsertPart(long Index, long Part, BSTR Text, double x, dou *retVal = VARIANT_TRUE; } return S_OK; -}; +} ///***********************************************************************/ ///* RemovePart() ///***********************************************************************/ @@ -456,7 +456,7 @@ STDMETHODIMP CLabels::RemovePart(long Index, long Part, VARIANT_BOOL* vbretval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >= (long)_labels.size()) + if (Index < 0 || Index >= static_cast(_labels.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *vbretval = VARIANT_FALSE; @@ -464,7 +464,7 @@ STDMETHODIMP CLabels::RemovePart(long Index, long Part, VARIANT_BOOL* vbretval) else { std::vector* parts = _labels[Index]; - if (Part < 0 || Part >= (long)parts->size()) + if (Part < 0 || Part >= static_cast(parts->size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *vbretval = VARIANT_FALSE; @@ -477,7 +477,7 @@ STDMETHODIMP CLabels::RemovePart(long Index, long Part, VARIANT_BOOL* vbretval) } } return S_OK; -}; +} // ***************************************************************** @@ -485,7 +485,7 @@ STDMETHODIMP CLabels::RemovePart(long Index, long Part, VARIANT_BOOL* vbretval) // ***************************************************************** STDMETHODIMP CLabels::AddCategory(BSTR Name, ILabelCategory** retVal) { - this->InsertCategory(_categories.size(), Name, retVal); + this->InsertCategory(static_cast(_categories.size()), Name, retVal); return S_OK; } @@ -496,7 +496,7 @@ STDMETHODIMP CLabels::InsertCategory(long Index, BSTR Name, ILabelCategory** ret { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >(long)_categories.size()) + if (Index < 0 || Index >static_cast(_categories.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = nullptr; @@ -534,7 +534,7 @@ STDMETHODIMP CLabels::RemoveCategory(long Index, VARIANT_BOOL* vbretval) AFX_MANAGE_STATE(AfxGetStaticModuleState()) * vbretval = VARIANT_FALSE; - if (Index < 0 || Index >= (long)_categories.size()) + if (Index < 0 || Index >= static_cast(_categories.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *vbretval = VARIANT_FALSE; @@ -566,7 +566,7 @@ STDMETHODIMP CLabels::Clear() } _labels.clear(); return S_OK; -}; +} // ***************************************************************** // ClearAllCategories() @@ -603,7 +603,7 @@ STDMETHODIMP CLabels::ApplyColorScheme(tkColorSchemeType Type, IColorScheme* Col STDMETHODIMP CLabels::ApplyColorScheme2(tkColorSchemeType Type, IColorScheme* ColorScheme, tkLabelElements Element) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - ApplyColorScheme3(Type, ColorScheme, Element, 0, _categories.size() - 1); + ApplyColorScheme3(Type, ColorScheme, Element, 0, static_cast(_categories.size()) - 1); return S_OK; } @@ -615,7 +615,7 @@ STDMETHODIMP CLabels::ApplyColorScheme3(tkColorSchemeType Type, IColorScheme* Co { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - long numBreaks; + long numBreaks; ColorScheme->get_NumBreaks(&numBreaks); if (Element == leDefault) @@ -633,8 +633,8 @@ STDMETHODIMP CLabels::ApplyColorScheme3(tkColorSchemeType Type, IColorScheme* Co } // we'll correct inproper indices - if (CategoryEndIndex >= (long)_categories.size()) - CategoryEndIndex = (long)(_categories.size() - 1); + if (CategoryEndIndex >= static_cast(_categories.size())) + CategoryEndIndex = static_cast(_categories.size() - 1); if (CategoryStartIndex < 0) CategoryStartIndex = 0; @@ -908,7 +908,7 @@ CLabelOptions* CLabels::get_LabelOptions() // ***************************************************************** STDMETHODIMP CLabels::GenerateCategories(long FieldIndex, tkClassificationType ClassificationType, long numClasses, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; *retVal = VARIANT_FALSE; @@ -931,7 +931,7 @@ STDMETHODIMP CLabels::GenerateCategories(long FieldIndex, tkClassificationType C ILabelCategory* cat = nullptr; - for (int i = 0; i < (int)values->size(); i++) + for (int i = 0; i < static_cast(values->size()); i++) { CString strValue; @@ -1129,7 +1129,7 @@ void CLabels::UpdateLabelOffsetsFromShapefile(long labelIndex, long categoryInde // Determines to which category belong individual labels STDMETHODIMP CLabels::ApplyCategories() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) this->ApplyExpression_(-1); return S_OK; } @@ -1164,7 +1164,7 @@ void CLabels::RefreshExpressions() CString numberFormat = LabelsHelper::GetFloatNumberFormat(this); - for (int i = 0; i < (int)_categories.size(); i++) + for (int i = 0; i < static_cast(_categories.size()); i++) { CComVariant vMin, vMax; _categories[i]->get_MinValue(&vMin); @@ -1194,13 +1194,13 @@ void CLabels::RefreshExpressions() // ***************************************************************** STDMETHODIMP CLabels::get_ClassificationField(long* FieldIndex) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *FieldIndex = _classificationField; return S_OK; } STDMETHODIMP CLabels::put_ClassificationField(long FieldIndex) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _classificationField = FieldIndex; return S_OK; } @@ -1210,7 +1210,7 @@ STDMETHODIMP CLabels::put_ClassificationField(long FieldIndex) // ***************************************************************** STDMETHODIMP CLabels::put_Synchronized(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal) { _synchronized = newVal; @@ -1228,7 +1228,7 @@ STDMETHODIMP CLabels::put_Synchronized(VARIANT_BOOL newVal) } STDMETHODIMP CLabels::get_Synchronized(VARIANT_BOOL* retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // the property must be set and the number of labels/parts must correspond if (LabelsSynchronized() && _synchronized) @@ -1248,7 +1248,7 @@ bool CLabels::LabelsSynchronized() long numShapes; _shapefile->get_NumShapes(&numShapes); - return numShapes == (long)_labels.size(); + return numShapes == static_cast(_labels.size()); } // ***************************************************************** @@ -1258,7 +1258,7 @@ STDMETHODIMP CLabels::get_Options(ILabelCategory** retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - * retVal = _category; + *retVal = _category; if (_category) _category->AddRef(); @@ -1269,9 +1269,9 @@ STDMETHODIMP CLabels::put_Options(ILabelCategory* newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - /*CLabelCategory* coCat = static_cast(newVal); - CLabelOptions* options = coCat->get_LabelOptions(); - _options = *options;*/ + /*CLabelCategory* coCat = static_cast(newVal); + CLabelOptions* options = coCat->get_LabelOptions(); + _options = *options;*/ ComHelper::SetRef(newVal, (IDispatch**)&_category, false); _options = ((CLabelCategory*)_category)->get_LabelOptions(); @@ -1286,10 +1286,10 @@ STDMETHODIMP CLabels::put_Options(ILabelCategory* newVal) // Must be called before the redraw (before the call of MapView::DrawLabelsAlt). void CLabels::ClearLabelFrames() { - for (int iLabel = 0; iLabel < (int)_labels.size(); iLabel++) + for (int iLabel = 0; iLabel < static_cast(_labels.size()); iLabel++) { vector* parts = _labels[iLabel]; - for (int j = 0; j < (int)parts->size(); j++) + for (int j = 0; j < static_cast(parts->size()); j++) { CLabelInfo* lbl = parts->at(j); if (lbl->horizontalFrame) @@ -1331,13 +1331,13 @@ STDMETHODIMP CLabels::put_VisibilityExpression(BSTR newVal) // ********************************************************** STDMETHODIMP CLabels::get_MinDrawingSize(LONG* retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = _minDrawingSize; return S_OK; } STDMETHODIMP CLabels::put_MinDrawingSize(LONG newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _minDrawingSize = newVal; return S_OK; } @@ -1348,7 +1348,7 @@ STDMETHODIMP CLabels::put_MinDrawingSize(LONG newVal) STDMETHODIMP CLabels::MoveCategoryUp(long Index, VARIANT_BOOL* retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < (long)_categories.size() && Index > 0) + if (Index < static_cast(_categories.size()) && Index > 0) { ILabelCategory* catBefore = _categories[Index - 1]; _categories[Index - 1] = _categories[Index]; @@ -1369,7 +1369,7 @@ STDMETHODIMP CLabels::MoveCategoryUp(long Index, VARIANT_BOOL* retval) STDMETHODIMP CLabels::MoveCategoryDown(long Index, VARIANT_BOOL* retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < (long)_categories.size() - 1 && Index >= 0) + if (Index < static_cast(_categories.size()) - 1 && Index >= 0) { ILabelCategory* catAfter = _categories[Index + 1]; _categories[Index + 1] = _categories[Index]; @@ -2644,7 +2644,7 @@ STDMETHODIMP CLabels::put_SavingMode(tkSavingMode newVal) // ************************************************************* STDMETHODIMP CLabels::get_Positioning(tkLabelPositioning* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _positioning; return S_OK; } @@ -2654,7 +2654,7 @@ STDMETHODIMP CLabels::get_Positioning(tkLabelPositioning* pVal) // ************************************************************* STDMETHODIMP CLabels::put_Positioning(tkLabelPositioning newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_shapefile) { ShpfileType type; @@ -2696,14 +2696,14 @@ STDMETHODIMP CLabels::put_Positioning(tkLabelPositioning newVal) // ************************************************************* STDMETHODIMP CLabels::get_TextRenderingHint(tkTextRenderingHint* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _textRenderingHint; return S_OK; } STDMETHODIMP CLabels::put_TextRenderingHint(tkTextRenderingHint newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal >= 0 && newVal <= ClearTypeGridFit) _textRenderingHint = newVal; return S_OK; @@ -2717,7 +2717,7 @@ bool CLabels::HasRotation() for (unsigned int i = 0; i < _labels.size(); i++) { vector* parts = _labels[i]; - for (int j = 0; j < (int)parts->size(); j++) + for (int j = 0; j < static_cast(parts->size()); j++) { CLabelInfo* lbl = (*parts)[j]; if (lbl->rotation != 0.0) @@ -2744,7 +2744,7 @@ void CLabels::AddEmptyLabel() // ************************************************************* STDMETHODIMP CLabels::get_FloatNumberFormat(BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = A2BSTR(_floatNumberFormat); return S_OK; } @@ -2754,7 +2754,7 @@ STDMETHODIMP CLabels::get_FloatNumberFormat(BSTR* pVal) // ************************************************************* STDMETHODIMP CLabels::put_FloatNumberFormat(BSTR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; CString format = OLE2A(newVal); CString s; @@ -2783,13 +2783,13 @@ STDMETHODIMP CLabels::ForceRecalculateExpression() // ************************************************************* STDMETHODIMP CLabels::get_FontSize(LONG* retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = _options->fontSize; return S_OK; } STDMETHODIMP CLabels::put_FontSize(LONG newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _options->fontSize = newVal; if (_options->fontSize > MAX_LABEL_SIZE) { @@ -2806,7 +2806,7 @@ STDMETHODIMP CLabels::put_FontSize(LONG newVal) // ************************************************************* STDMETHODIMP CLabels::get_FontSize2(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options->fontSize2; @@ -2814,7 +2814,7 @@ STDMETHODIMP CLabels::get_FontSize2(LONG* pVal) } STDMETHODIMP CLabels::put_FontSize2(LONG newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _options->fontSize2 = newVal; @@ -2834,7 +2834,7 @@ STDMETHODIMP CLabels::put_FontSize2(LONG newVal) // ************************************************************* STDMETHODIMP CLabels::get_UseVariableSize(VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _useVariableSize; @@ -2842,7 +2842,7 @@ STDMETHODIMP CLabels::get_UseVariableSize(VARIANT_BOOL* pVal) } STDMETHODIMP CLabels::put_UseVariableSize(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _useVariableSize = newVal; _fontSizeChanged = true; @@ -2855,7 +2855,7 @@ STDMETHODIMP CLabels::put_UseVariableSize(VARIANT_BOOL newVal) // ************************************************************* STDMETHODIMP CLabels::get_LogScaleForSize(VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _logScaleForSize; @@ -2863,7 +2863,7 @@ STDMETHODIMP CLabels::get_LogScaleForSize(VARIANT_BOOL* pVal) } STDMETHODIMP CLabels::put_LogScaleForSize(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _logScaleForSize = newVal; _fontSizeChanged = true; @@ -2940,7 +2940,7 @@ bool CLabels::RecalculateFontSize() // ************************************************************* STDMETHODIMP CLabels::UpdateSizeField() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _fontSizeChanged = true; diff --git a/src/COM classes/Labels.h b/src/COM classes/Labels.h index ec1c7857..403a827d 100644 --- a/src/COM classes/Labels.h +++ b/src/COM classes/Labels.h @@ -41,19 +41,19 @@ class ATL_NO_VTABLE CLabels : public: CLabels() { - _pUnkMarshaler = NULL; + _pUnkMarshaler = nullptr; _useVariableSize = VARIANT_TRUE; _logScaleForSize = VARIANT_FALSE; _fontSizeChanged = true; _floatNumberFormat = m_globalSettings.floatNumberFormat; - _shapefile = NULL; + _shapefile = nullptr; _synchronized = VARIANT_FALSE; USES_CONVERSION; _key = SysAllocString(L""); _expression = SysAllocString(L""); - _globalCallback = NULL; + _globalCallback = nullptr; _lastErrorCode = tkNO_ERROR; _scale = false; _verticalPosition = vpAboveAllLayers; @@ -98,7 +98,7 @@ class ATL_NO_VTABLE CLabels : _category->Release(); } - _shapefile = NULL; + _shapefile = nullptr; gReferenceCounter.Release(tkInterface::idLabels); } @@ -152,7 +152,7 @@ class ATL_NO_VTABLE CLabels : STDMETHOD(ClearCategories)(); // managing labels - STDMETHOD(get_Count)(/*[out, retval]*/long* pVal) {*pVal = _labels.size(); return S_OK;}; + STDMETHOD(get_Count)(/*[out, retval]*/long* pVal) {*pVal = static_cast(_labels.size()); return S_OK;}; STDMETHOD(get_NumParts)(/*[in]*/long index, /*[out, retval]*/long* pVal); STDMETHOD(get_NumCategories)(/*[out, retval]*/long* pVal); diff --git a/src/COM classes/LinePattern.cpp b/src/COM classes/LinePattern.cpp index ff3ce4b9..b8fcbb03 100644 --- a/src/COM classes/LinePattern.cpp +++ b/src/COM classes/LinePattern.cpp @@ -60,7 +60,7 @@ STDMETHODIMP CLinePattern::get_GlobalCallback(ICallback **pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _globalCallback; - if( _globalCallback != NULL ) + if( _globalCallback != nullptr) _globalCallback->AddRef(); return S_OK; } @@ -91,7 +91,7 @@ STDMETHODIMP CLinePattern::put_Key(BSTR newVal) } // ************************************************************** -// CLinePattern::ErrorMessage() +// CLinePattern::ErrorMessage() // ************************************************************** void CLinePattern::ErrorMessage(long ErrorCode) { @@ -107,7 +107,7 @@ void CLinePattern::ErrorMessage(long ErrorCode) STDMETHODIMP CLinePattern::get_Count(int* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retVal = _lines.size(); + *retVal = static_cast(_lines.size()); return S_OK; } @@ -117,10 +117,10 @@ STDMETHODIMP CLinePattern::get_Count(int* retVal) STDMETHODIMP CLinePattern::get_Line(int Index, ILineSegment** retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if(Index < 0 || Index >= (int)_lines.size()) + if(Index < 0 || Index >= static_cast(_lines.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); - *retVal = NULL; + *retVal = nullptr; } else { @@ -137,7 +137,7 @@ STDMETHODIMP CLinePattern::put_Line(int Index, ILineSegment* newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if(Index < 0 || Index >= (int)_lines.size()) + if(Index < 0 || Index >= static_cast(_lines.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); } @@ -163,7 +163,7 @@ STDMETHODIMP CLinePattern::AddLine(OLE_COLOR color, float width, tkDashStyle sty { AFX_MANAGE_STATE(AfxGetStaticModuleState()) VARIANT_BOOL vbretval; - InsertLine(_lines.size(), color, width, style, &vbretval); + InsertLine(static_cast(_lines.size()), color, width, style, &vbretval); return S_OK; } @@ -173,15 +173,15 @@ STDMETHODIMP CLinePattern::AddLine(OLE_COLOR color, float width, tkDashStyle sty STDMETHODIMP CLinePattern::InsertLine(int Index, OLE_COLOR color, float width, tkDashStyle style, VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index > (int)_lines.size()) + if (Index < 0 || Index > static_cast(_lines.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = VARIANT_FALSE; } else { - ILineSegment* segm = NULL; - CoCreateInstance( CLSID_LineSegment, NULL, CLSCTX_INPROC_SERVER, IID_ILineSegment, (void**)&segm ); + ILineSegment* segm = nullptr; + CoCreateInstance( CLSID_LineSegment, nullptr, CLSCTX_INPROC_SERVER, IID_ILineSegment, (void**)&segm ); segm->put_Color(color); segm->put_LineWidth(width); segm->put_LineStyle(style); @@ -200,7 +200,7 @@ STDMETHODIMP CLinePattern::InsertLine(int Index, OLE_COLOR color, float width, t STDMETHODIMP CLinePattern::AddMarker(tkDefaultPointSymbol marker, ILineSegment** retVal ) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - InsertMarker(_lines.size(), marker, retVal); + InsertMarker(static_cast(_lines.size()), marker, retVal); return S_OK; } @@ -210,15 +210,15 @@ STDMETHODIMP CLinePattern::AddMarker(tkDefaultPointSymbol marker, ILineSegment** STDMETHODIMP CLinePattern::InsertMarker(int Index, tkDefaultPointSymbol marker, ILineSegment** retVal ) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index > (int)_lines.size()) + if (Index < 0 || Index > static_cast(_lines.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); - *retVal = NULL; + *retVal = nullptr; } else { - ILineSegment* segm = NULL; - CoCreateInstance( CLSID_LineSegment, NULL, CLSCTX_INPROC_SERVER, IID_ILineSegment, (void**)&segm ); + ILineSegment* segm = nullptr; + CoCreateInstance( CLSID_LineSegment, nullptr, CLSCTX_INPROC_SERVER, IID_ILineSegment, (void**)&segm ); segm->put_Marker(marker); segm->put_LineType(lltMarker); segm->AddRef(); @@ -256,13 +256,13 @@ STDMETHODIMP CLinePattern::RemoveItem(int Index, VARIANT_BOOL* retVal) STDMETHODIMP CLinePattern::Clear() { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - + for (unsigned int i = 0; i < _lines.size(); i++) { if (_lines[i]) { _lines[i]->Release(); - _lines[i] = NULL; + _lines[i] = nullptr; } } @@ -285,7 +285,7 @@ STDMETHODIMP CLinePattern::Draw(int hdc, float x, float y, int clipWidth, int cl return S_OK; } - CDC* dc = CDC::FromHandle((HDC)hdc); + CDC* dc = CDC::FromHandle(reinterpret_cast(static_cast(hdc))); *retVal = this->DrawCore(dc, x, y, clipWidth, clipHeight, backColor, backAlpha); return S_OK; } @@ -356,13 +356,13 @@ VARIANT_BOOL CLinePattern::DrawCore(CDC* dc, float x, float y, int clipWidth, in // **************************************************************** STDMETHODIMP CLinePattern::get_Transparency (BYTE *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _transparency; return S_OK; } STDMETHODIMP CLinePattern::put_Transparency (BYTE newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < 0) newVal = 0; if (newVal > 255) newVal = 255; _transparency = newVal; @@ -387,12 +387,12 @@ STDMETHODIMP CLinePattern::Serialize(BSTR* retVal) CPLXMLNode* CLinePattern::SerializeCore(CString ElementName) { USES_CONVERSION; - CPLXMLNode* psTree = CPLCreateXMLNode( NULL, CXT_Element, ElementName); - + CPLXMLNode* psTree = CPLCreateXMLNode(nullptr, CXT_Element, ElementName); + CString str = OLE2CA(_key); Utility::CPLCreateXMLAttributeAndValue(psTree, "Key", CPLString().Printf(str)); Utility::CPLCreateXMLAttributeAndValue(psTree, "Transparency", CPLString().Printf("%d", (int)_transparency)); - + // segments if (_lines.size() > 0) { @@ -477,14 +477,14 @@ bool CLinePattern::DeserializeCore(CPLXMLNode* node) return false; CString s; - s = CPLGetXMLValue( node, "Key", NULL ); + s = CPLGetXMLValue( node, "Key", nullptr); if (s != "") { CComBSTR bstr(s); this->put_Key(bstr); } - s = CPLGetXMLValue( node, "Transparency", NULL ); + s = CPLGetXMLValue( node, "Transparency", nullptr); if (s != "") _transparency = (unsigned char)atoi(s.GetString()); // restoring segments @@ -498,85 +498,85 @@ bool CLinePattern::DeserializeCore(CPLXMLNode* node) { if (strcmp(node->pszValue, "LineSegmentClass") == 0) { - ILineSegment* segment = NULL; + ILineSegment* segment = nullptr; this->AddMarker(dpsDiamond, &segment); if (segment) { // line type tkLineType lineType; - s = CPLGetXMLValue( node, "LineType", NULL ); + s = CPLGetXMLValue( node, "LineType", nullptr); if (s != "") lineType = (tkLineType)atoi( s ); segment->put_LineType(lineType); // color OLE_COLOR color = RGB(0,0,0); - s = CPLGetXMLValue( node, "Color", NULL ); + s = CPLGetXMLValue( node, "Color", nullptr); if (s != "") color = (OLE_COLOR)atoi( s ); segment->put_Color(color); // outline color color = RGB(0,0,0); - s = CPLGetXMLValue( node, "MarkerOutlineColor", NULL ); + s = CPLGetXMLValue( node, "MarkerOutlineColor", nullptr); if (s != "") color = (OLE_COLOR)atoi( s ); segment->put_MarkerOutlineColor(color); // line width float val = 0.0f; - s = CPLGetXMLValue( node, "LineWidth", NULL ); + s = CPLGetXMLValue( node, "LineWidth", nullptr); if (s != "") val = (float)Utility::atof_custom( s ); segment->put_LineWidth(val); // marker size val = 0.0f; - s = CPLGetXMLValue( node, "MarkerSize", NULL ); + s = CPLGetXMLValue( node, "MarkerSize", nullptr); if (s != "") val = (float)Utility::atof_custom( s ); segment->put_MarkerSize(val); // marker interval val = 0.0f; - s = CPLGetXMLValue( node, "MarkerInterval", NULL ); + s = CPLGetXMLValue( node, "MarkerInterval", nullptr); if (s != "") val = (float)Utility::atof_custom( s ); segment->put_MarkerInterval(val); // marker interval is relative VARIANT_BOOL isRelative = VARIANT_FALSE; - s = CPLGetXMLValue(node, "MarkerIntervalIsRelative", NULL); + s = CPLGetXMLValue(node, "MarkerIntervalIsRelative", nullptr); if (s != "") isRelative = (VARIANT_BOOL)atoi(s); segment->put_MarkerIntervalIsRelative(isRelative); // marker offset val = 0.0f; - s = CPLGetXMLValue( node, "MarkerOffset", NULL ); + s = CPLGetXMLValue( node, "MarkerOffset", nullptr); if (s != "") val = (float)Utility::atof_custom( s ); segment->put_MarkerOffset(val); // marker interval is relative - s = CPLGetXMLValue(node, "MarkerOffsetIsRelative", NULL); + s = CPLGetXMLValue(node, "MarkerOffsetIsRelative", nullptr); if (s != "") isRelative = (VARIANT_BOOL)atoi(s); segment->put_MarkerOffsetIsRelative(isRelative); // line style tkDashStyle lineStyle = dsSolid; - s = CPLGetXMLValue( node, "LineStyle", NULL ); + s = CPLGetXMLValue( node, "LineStyle", nullptr); if (s != "") lineStyle = (tkDashStyle)atoi( s ); segment->put_LineStyle(lineStyle); // marker tkDefaultPointSymbol marker = dpsDiamond; - s = CPLGetXMLValue( node, "Marker", NULL ); + s = CPLGetXMLValue( node, "Marker", nullptr); if (s != "") marker = (tkDefaultPointSymbol)atoi( s ); segment->put_Marker(marker); // marker orientation tkLineLabelOrientation orientation = lorHorizontal; - s = CPLGetXMLValue( node, "MarkerOrientation", NULL ); + s = CPLGetXMLValue( node, "MarkerOrientation", nullptr); if (s != "") orientation = (tkLineLabelOrientation)atoi( s ); segment->put_MarkerOrientation(orientation); // marker flip first VARIANT_BOOL flipFirst = VARIANT_FALSE; - s = CPLGetXMLValue( node, "MarkerFlipFirst", NULL ); + s = CPLGetXMLValue( node, "MarkerFlipFirst", nullptr); if (s != "") flipFirst = (VARIANT_BOOL)atoi( s ); segment->put_MarkerFlipFirst(flipFirst); diff --git a/src/COM classes/LineSegment.cpp b/src/COM classes/LineSegment.cpp index 6bd9d656..8192f1bc 100644 --- a/src/COM classes/LineSegment.cpp +++ b/src/COM classes/LineSegment.cpp @@ -165,15 +165,15 @@ STDMETHODIMP CLineSegment::put_MarkerInterval(float newVal) // ************************************************************* STDMETHODIMP CLineSegment::get_MarkerIntervalIsRelative(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) - * retVal = _markerIntervalIsRelative; - return S_OK; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + * retVal = _markerIntervalIsRelative; + return S_OK; } STDMETHODIMP CLineSegment::put_MarkerIntervalIsRelative(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) - _markerIntervalIsRelative = newVal; - return S_OK; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _markerIntervalIsRelative = newVal; + return S_OK; } // ************************************************************* @@ -181,15 +181,15 @@ STDMETHODIMP CLineSegment::put_MarkerIntervalIsRelative(VARIANT_BOOL newVal) // ************************************************************* STDMETHODIMP CLineSegment::get_MarkerAllowOverflow(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) - * retVal = _markerAllowOverflow; - return S_OK; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + * retVal = _markerAllowOverflow; + return S_OK; } STDMETHODIMP CLineSegment::put_MarkerAllowOverflow(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) - _markerAllowOverflow = newVal; - return S_OK; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _markerAllowOverflow = newVal; + return S_OK; } // ************************************************************* @@ -223,7 +223,7 @@ STDMETHODIMP CLineSegment::put_MarkerFlipFirst(VARIANT_BOOL newVal) _markerFlipFirst = newVal; return S_OK; } - + // ************************************************************* // get_MarkerOffset() // ************************************************************* @@ -245,15 +245,15 @@ STDMETHODIMP CLineSegment::put_MarkerOffset(float newVal) // ************************************************************* STDMETHODIMP CLineSegment::get_MarkerOffsetIsRelative(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) - * retVal = _markerOffsetIsRelative; - return S_OK; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + * retVal = _markerOffsetIsRelative; + return S_OK; } STDMETHODIMP CLineSegment::put_MarkerOffsetIsRelative(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) - _markerOffsetIsRelative = newVal; - return S_OK; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _markerOffsetIsRelative = newVal; + return S_OK; } // ************************************************************* @@ -266,7 +266,7 @@ STDMETHODIMP CLineSegment::Draw (int hdc, float x, float y, int clipWidth, int c return S_OK; } - CDC* dc = CDC::FromHandle((HDC)hdc); + CDC* dc = CDC::FromHandle(reinterpret_cast(static_cast(hdc))); *retVal = this->DrawCore(dc, x, y, clipWidth, clipHeight, backColor, backAlpha); return S_OK; } @@ -304,8 +304,8 @@ VARIANT_BOOL CLineSegment::DrawCore(CDC* dc, float x, float y, int clipWidth, in Gdiplus::SolidBrush brushBackground(clr); g.Clear(clr); - VARIANT_BOOL vb; - Draw(g, (BYTE) 255, clipWidth, clipHeight, (int) x, (int) y, &vb); + VARIANT_BOOL vb; + Draw(g, (BYTE) 255, clipWidth, clipHeight, static_cast(x), static_cast(y), &vb); Gdiplus::Graphics gResult(dc->GetSafeHdc()); gResult.DrawImage(&bmp, x, y); @@ -330,7 +330,7 @@ STDMETHODIMP CLineSegment::Draw(Gdiplus::Graphics& g, BYTE transparency, int Ima void CLineSegment::DrawSimpleSegment(Gdiplus::Graphics& g, int ImageWidth, int ImageHeight, const BYTE& transparency) { if (_lineWidth <= 0) - return; + return; Gdiplus::PointF points[2]; points[0].X = 0.0f; diff --git a/src/COM classes/OgrLayer.cpp b/src/COM classes/OgrLayer.cpp index bd93bbb8..02b82eca 100644 --- a/src/COM classes/OgrLayer.cpp +++ b/src/COM classes/OgrLayer.cpp @@ -42,7 +42,7 @@ void COgrLayer::InitOpenedLayer() int featureCount; get_FeatureCount(VARIANT_FALSE, &featureCount); - CComPtr extents = NULL; + CComPtr extents = nullptr; get_Extents(&extents, VARIANT_TRUE, &vb); if (m_globalSettings.autoChooseOgrLoadingMode) { @@ -63,7 +63,7 @@ void COgrLayer::ClearCachedValues() if (_envelope) { delete _envelope; - _envelope = NULL; + _envelope = nullptr; } if (_featureCount != -1) { @@ -138,7 +138,7 @@ void COgrLayer::UpdateShapefileFromOGRLoader() selectedOgrFIDs.push_back(var); } - } + } VARIANT_BOOL vb; _shapefile->EditClear(&vb); @@ -148,24 +148,24 @@ void COgrLayer::UpdateShapefileFromOGRLoader() Debug::WriteWithThreadId(Debug::Format("Update shapefile: %d\n", data.size()), DebugOgrLoading); - CComPtr table = NULL; + CComPtr table = nullptr; _shapefile->get_Table(&table); - CComPtr labels = NULL; + CComPtr labels = nullptr; _shapefile->get_Labels(&labels); labels->Clear(); - CComPtr categories = NULL; + CComPtr categories = nullptr; _shapefile->get_Categories(&categories); long count = 0; if (table) { CTableClass* tbl = TableHelper::Cast(table); - _shapefile->StartEditingShapes(VARIANT_TRUE, NULL, &vb); + _shapefile->StartEditingShapes(VARIANT_TRUE, nullptr, &vb); for (size_t i = 0; i < data.size(); i++) { - CComPtr shp = NULL; + CComPtr shp = nullptr; ComHelper::CreateShape(&shp); if (shp) { @@ -183,11 +183,11 @@ void COgrLayer::UpdateShapefileFromOGRLoader() tbl->UpdateTableRow(data[i]->Row, count); } - data[i]->Row = NULL; // we no longer own it; it'll be cleared by Shapefile.EditClear + data[i]->Row = nullptr; // we no longer own it; it'll be cleared by Shapefile.EditClear if (compatible) { - // Preserve selection accross reloads: + // Preserve selection across reloads: CComVariant pVal; tbl->get_CellValue(0, count, &pVal); bool wasSelected = false; @@ -202,7 +202,7 @@ void COgrLayer::UpdateShapefileFromOGRLoader() _shapefile->put_ShapeSelected(count, VARIANT_TRUE); if (hasFid) - ((CShapefile*)_shapefile)->MapOgrFid2ShapeIndex(pVal.lVal, count); + ((CShapefile*)_shapefile)->MapOgrFid2ShapeIndex(pVal.lVal, count); } count++; @@ -213,7 +213,7 @@ void COgrLayer::UpdateShapefileFromOGRLoader() ShapefileHelper::ClearShapefileModifiedFlag(_shapefile); // Stop 'fake' editing session - _shapefile->StopEditingShapes(VARIANT_TRUE, VARIANT_TRUE, NULL, &vb); + _shapefile->StopEditingShapes(VARIANT_TRUE, VARIANT_TRUE, nullptr, &vb); } // clean the data @@ -241,7 +241,7 @@ STDMETHODIMP COgrLayer::put_Key(BSTR newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) ::SysFreeString(_key); - USES_CONVERSION; + USES_CONVERSION; _key = OLE2BSTR(newVal); return S_OK; } @@ -278,7 +278,7 @@ STDMETHODIMP COgrLayer::get_GlobalCallback(ICallback **pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _globalCallback; - if (_globalCallback != NULL) _globalCallback->AddRef(); + if (_globalCallback != nullptr) _globalCallback->AddRef(); return S_OK; } @@ -307,7 +307,7 @@ bool COgrLayer::CheckState() // ************************************************************* STDMETHODIMP COgrLayer::get_SourceType(tkOgrSourceType* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = _sourceType; return S_OK; } @@ -340,8 +340,8 @@ STDMETHODIMP COgrLayer::Close() } } - _dataset = NULL; - _layer = NULL; + _dataset = nullptr; + _layer = nullptr; } CloseShapefile(); @@ -366,7 +366,7 @@ void COgrLayer::CloseShapefile() VARIANT_BOOL vb; _shapefile->Close(&vb); ULONG count = _shapefile->Release(); - _shapefile = NULL; + _shapefile = nullptr; } } @@ -455,7 +455,7 @@ bool COgrLayer::InjectLayer(GDALDataset* ds, int layerIndex, CStringW connection // ************************************************************* STDMETHODIMP COgrLayer::ExtendFromQuery(BSTR sql, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; @@ -465,7 +465,7 @@ STDMETHODIMP COgrLayer::ExtendFromQuery(BSTR sql, VARIANT_BOOL* retVal) return S_OK; } - OGRLayer* layer = ds->ExecuteSQL(OgrHelper::Bstr2OgrString(sql), NULL, NULL); + OGRLayer* layer = ds->ExecuteSQL(OgrHelper::Bstr2OgrString(sql), nullptr, nullptr); if (!layer) { ErrorMessage(tkOGR_QUERY_FAILED); @@ -491,7 +491,7 @@ STDMETHODIMP COgrLayer::OpenFromQuery(BSTR connectionString, BSTR sql, VARIANT_B GDALDataset* ds = OpenDataset(connectionString, false); if (ds) { - OGRLayer* layer = ds->ExecuteSQL(OgrHelper::Bstr2OgrString(sql), NULL, NULL); + OGRLayer* layer = ds->ExecuteSQL(OgrHelper::Bstr2OgrString(sql), nullptr, nullptr); if (layer) { _connectionString = OLE2W(connectionString); @@ -552,7 +552,7 @@ STDMETHODIMP COgrLayer::OpenFromDatabase(BSTR connectionString, BSTR layerName, // ************************************************************* STDMETHODIMP COgrLayer::OpenFromFile(BSTR Filename, VARIANT_BOOL forUpdate, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; Close(); @@ -608,7 +608,7 @@ STDMETHODIMP COgrLayer::GetBuffer(IShapefile** retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retVal = NULL; + *retVal = nullptr; if (!CheckState()) return S_OK; // Lock shape file @@ -638,7 +638,7 @@ STDMETHODIMP COgrLayer::GetBuffer(IShapefile** retVal) // ************************************************************* STDMETHODIMP COgrLayer::ReloadFromSource(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (!CheckState()) return S_OK; @@ -688,7 +688,7 @@ STDMETHODIMP COgrLayer::ReloadFromSource(VARIANT_BOOL* retVal) // ************************************************************* STDMETHODIMP COgrLayer::RedefineQuery(BSTR newSql, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (!CheckState()) return S_OK; @@ -700,7 +700,7 @@ STDMETHODIMP COgrLayer::RedefineQuery(BSTR newSql, VARIANT_BOOL* retVal) if (_sourceType == ogrQuery) { - OGRLayer* layer = _dataset->ExecuteSQL(OgrHelper::Bstr2OgrString(newSql), NULL, NULL); + OGRLayer* layer = _dataset->ExecuteSQL(OgrHelper::Bstr2OgrString(newSql), nullptr, nullptr); if (layer) { _dataset->ReleaseResultSet(_layer); @@ -729,7 +729,7 @@ STDMETHODIMP COgrLayer::RedefineQuery(BSTR newSql, VARIANT_BOOL* retVal) // ************************************************************* STDMETHODIMP COgrLayer::GetConnectionString(BSTR* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; *retVal = W2BSTR(_connectionString); return S_OK; @@ -740,7 +740,7 @@ STDMETHODIMP COgrLayer::GetConnectionString(BSTR* retVal) // ************************************************************* STDMETHODIMP COgrLayer::GetSourceQuery(BSTR* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; *retVal = W2BSTR(_sourceQuery); return S_OK; @@ -751,8 +751,8 @@ STDMETHODIMP COgrLayer::GetSourceQuery(BSTR* retVal) // ************************************************************* STDMETHODIMP COgrLayer::get_GeoProjection(IGeoProjection** retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - IGeoProjection* gp = NULL; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + IGeoProjection* gp = nullptr; ComHelper::CreateInstance(idGeoProjection, (IDispatch**)&gp); *retVal = gp; @@ -771,7 +771,7 @@ STDMETHODIMP COgrLayer::get_GeoProjection(IGeoProjection** retVal) // ************************************************************* STDMETHODIMP COgrLayer::get_ShapeType(ShpfileType* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = SHP_NULLSHAPE; if (!CheckState()) return S_OK; *retVal = OgrConverter::GeometryType2ShapeType(_layer->GetGeomType()); @@ -783,7 +783,7 @@ STDMETHODIMP COgrLayer::get_ShapeType(ShpfileType* retVal) // ************************************************************* STDMETHODIMP COgrLayer::get_ShapeType2D(ShpfileType* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) get_ShapeType(pVal); *pVal = ShapeUtility::Convert2D(*pVal); return S_OK; @@ -794,20 +794,20 @@ STDMETHODIMP COgrLayer::get_ShapeType2D(ShpfileType* pVal) // ************************************************************* STDMETHODIMP COgrLayer::get_DataIsReprojected(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (!CheckState()) return S_OK; if (!_shapefile) return S_OK; // data wasn't loaded yet - CComPtr gp = NULL; + CComPtr gp = nullptr; get_GeoProjection(&gp); if (!gp) return S_OK; - CComPtr sf = NULL; + CComPtr sf = nullptr; GetBuffer(&sf); if (sf) { - CComPtr gp2 = NULL; + CComPtr gp2 = nullptr; sf->get_GeoProjection(&gp2); VARIANT_BOOL isSame; gp->get_IsSame(gp2, &isSame); @@ -821,7 +821,7 @@ STDMETHODIMP COgrLayer::get_DataIsReprojected(VARIANT_BOOL* retVal) // ************************************************************* STDMETHODIMP COgrLayer::get_FIDColumnName(BSTR* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (CheckState()) { CStringW s = OgrHelper::OgrString2Unicode(_layer->GetFIDColumn()); @@ -837,7 +837,7 @@ STDMETHODIMP COgrLayer::get_FIDColumnName(BSTR* retVal) // ************************************************************* STDMETHODIMP COgrLayer::SaveChanges(int* savedCount, tkOgrSaveType saveType, VARIANT_BOOL validateShapes, tkOgrSaveResult* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *savedCount = 0; *retVal = osrNoChanges; _updateErrors.clear(); @@ -907,7 +907,7 @@ STDMETHODIMP COgrLayer::SaveChanges(int* savedCount, tkOgrSaveType saveType, VAR // ************************************************************* STDMETHODIMP COgrLayer::HasLocalChanges(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; @@ -927,7 +927,7 @@ STDMETHODIMP COgrLayer::HasLocalChanges(VARIANT_BOOL* retVal) return S_OK; } - CComPtr table = NULL; + CComPtr table = nullptr; _shapefile->get_Table(&table); long numFields = ShapefileHelper::GetNumFields(_shapefile); @@ -947,7 +947,7 @@ STDMETHODIMP COgrLayer::HasLocalChanges(VARIANT_BOOL* retVal) for (long i = 1; i < numFields; i++) { - CComPtr field = NULL; + CComPtr field = nullptr; _shapefile->get_Field(i, &field); field->get_Modified(&modified); @@ -984,7 +984,7 @@ long COgrLayer::GetFidForShapefile() CSingleLock sfLock(&_loader.ShapefileLock, _dynamicLoading ? TRUE : FALSE); CComBSTR bstr; get_FIDColumnName(&bstr); - CComPtr table = NULL; + CComPtr table = nullptr; _shapefile->get_Table(&table); long shapeCmnId; table->get_FieldIndexByName(bstr, &shapeCmnId); @@ -1010,7 +1010,7 @@ STDMETHODIMP COgrLayer::TestCapability(tkOgrLayerCapability capability, VARIANT_ STDMETHODIMP COgrLayer::get_UpdateSourceErrorCount(int* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retVal = _updateErrors.size(); + *retVal = static_cast(_updateErrors.size()); return S_OK; } @@ -1020,7 +1020,7 @@ STDMETHODIMP COgrLayer::get_UpdateSourceErrorCount(int* retVal) STDMETHODIMP COgrLayer::get_UpdateSourceErrorMsg(int errorIndex, BSTR* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (errorIndex < 0 || errorIndex >= (int)_updateErrors.size()) + if (errorIndex < 0 || errorIndex >= static_cast(_updateErrors.size())) { *retVal = A2BSTR(""); ErrorMessage(tkINDEX_OUT_OF_BOUNDS); @@ -1036,7 +1036,7 @@ STDMETHODIMP COgrLayer::get_UpdateSourceErrorMsg(int errorIndex, BSTR* retVal) STDMETHODIMP COgrLayer::get_UpdateSourceErrorShapeIndex(int errorIndex, int* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (errorIndex < 0 || errorIndex >= (int)_updateErrors.size()) + if (errorIndex < 0 || errorIndex >= static_cast(_updateErrors.size())) { *retVal = -1; ErrorMessage(tkINDEX_OUT_OF_BOUNDS); @@ -1091,13 +1091,13 @@ void COgrLayer::ForceCreateShapefile() STDMETHODIMP COgrLayer::get_Extents(IExtents** extents, VARIANT_BOOL forceLoading, VARIANT_BOOL *retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *extents = NULL; + *extents = nullptr; *retVal = VARIANT_FALSE; if (!CheckState()) return S_OK; if (_envelope && forceLoading) { delete _envelope; - _envelope = NULL; + _envelope = nullptr; } if (!_envelope) @@ -1108,7 +1108,7 @@ STDMETHODIMP COgrLayer::get_Extents(IExtents** extents, VARIANT_BOOL forceLoadin } if (_envelope) { - IExtents* ext = NULL; + IExtents* ext = nullptr; ComHelper::CreateExtents(&ext); ext->SetBounds(_envelope->MinX, _envelope->MinY, 0.0, _envelope->MaxX, _envelope->MaxY, 0.0); *extents = ext; @@ -1202,7 +1202,7 @@ STDMETHODIMP COgrLayer::Serialize(BSTR* retVal) // ************************************************************* CPLXMLNode* COgrLayer::SerializeCore(CString ElementName) { - CPLXMLNode* psTree = CPLCreateXMLNode(NULL, CXT_Element, ElementName); + CPLXMLNode* psTree = CPLCreateXMLNode(nullptr, CXT_Element, ElementName); USES_CONVERSION; CStringW skey = OLE2W(_key); @@ -1258,13 +1258,13 @@ bool COgrLayer::DeserializeCore(CPLXMLNode* node) Close(); - CString s = CPLGetXMLValue(node, "SourceType", NULL); + CString s = CPLGetXMLValue(node, "SourceType", nullptr); tkOgrSourceType sourceType = (s != "") ? (tkOgrSourceType)atoi(s.GetString()) : ogrUninitialized; CStringW connectionString = Utility::ConvertFromUtf8(CPLGetXMLValue(node, "ConnectionString", "")); CStringW sourceQuery = Utility::ConvertFromUtf8(CPLGetXMLValue(node, "SourceQuery", "")); - s = CPLGetXMLValue(node, "ForUpdate", NULL); + s = CPLGetXMLValue(node, "ForUpdate", nullptr); bool forUpdate = (s != "") ? (atoi(s.GetString()) == 0 ? false : true) : false; CComBSTR bstrConnection(connectionString); @@ -1292,11 +1292,11 @@ bool COgrLayer::DeserializeOptions(CPLXMLNode* node) { bool success = true; - CString s = CPLGetXMLValue(node, "MaxFeatureCount", NULL); + CString s = CPLGetXMLValue(node, "MaxFeatureCount", nullptr); _loader.SetMaxCacheCount((s != "") ? atoi(s.GetString()) : m_globalSettings.ogrLayerMaxFeatureCount); // let's populate data (in case it was populated before serialization) - if (_sourceType != ogrUninitialized && _layer != NULL) + if (_sourceType != ogrUninitialized && _layer != nullptr) { CPLXMLNode* psChild = CPLGetXMLNode(node, "ShapefileData"); if (psChild) @@ -1325,7 +1325,7 @@ bool COgrLayer::DeserializeOptions(CPLXMLNode* node) // ************************************************************* STDMETHODIMP COgrLayer::get_GdalLastErrorMsg(BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) CStringW s = OgrHelper::OgrString2Unicode(CPLGetLastErrorMsg()); *pVal = W2BSTR(s); return S_OK; @@ -1336,13 +1336,13 @@ STDMETHODIMP COgrLayer::get_GdalLastErrorMsg(BSTR* pVal) // ************************************************************* STDMETHODIMP COgrLayer::get_DynamicLoading(VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _dynamicLoading; return S_OK; } STDMETHODIMP COgrLayer::put_DynamicLoading(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _dynamicLoading = newVal; if (newVal) { ForceCreateShapefile(); @@ -1355,13 +1355,13 @@ STDMETHODIMP COgrLayer::put_DynamicLoading(VARIANT_BOOL newVal) // ************************************************************* STDMETHODIMP COgrLayer::get_MaxFeatureCount(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _loader.GetMaxCacheCount(); return S_OK; } STDMETHODIMP COgrLayer::put_MaxFeatureCount(LONG newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _loader.SetMaxCacheCount(newVal <= 0 ? m_globalSettings.ogrLayerMaxFeatureCount : newVal); return S_OK; } @@ -1396,12 +1396,12 @@ CStringW COgrLayer::GetStyleTableName() // ************************************************************* STDMETHODIMP COgrLayer::get_SupportsStyles(VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = VARIANT_FALSE; if (!CheckState()) return S_OK; - if (_sourceType == ogrQuery) + if (_sourceType == ogrQuery) { ErrorMessage(tkOGR_NO_STYLE_FOR_QUERIES); return S_OK; @@ -1411,7 +1411,7 @@ STDMETHODIMP COgrLayer::get_SupportsStyles(VARIANT_BOOL* pVal) *pVal = VARIANT_TRUE; return S_OK; } - + OgrStyleHelper::CreateStyleTable(_dataset, GetLayerName()); return S_OK; } @@ -1421,7 +1421,7 @@ STDMETHODIMP COgrLayer::get_SupportsStyles(VARIANT_BOOL* pVal) // ************************************************************* STDMETHODIMP COgrLayer::SaveStyle(BSTR Name, CStringW xml, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (!CheckState()) return S_OK; @@ -1451,7 +1451,7 @@ STDMETHODIMP COgrLayer::SaveStyle(BSTR Name, CStringW xml, VARIANT_BOOL* retVal) // ************************************************************* STDMETHODIMP COgrLayer::GetNumStyles(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = -1; if (!CheckState()) return S_OK; @@ -1460,7 +1460,7 @@ STDMETHODIMP COgrLayer::GetNumStyles(LONG* pVal) sql.Format(L"SELECT COUNT(*) FROM %s WHERE layername = '%s'", GetStyleTableName(), GetLayerName()); CPLErrorReset(); - OGRLayer* layer = _dataset->ExecuteSQL(OgrHelper::String2OgrString(sql), NULL, NULL); + OGRLayer* layer = _dataset->ExecuteSQL(OgrHelper::String2OgrString(sql), nullptr, nullptr); if (layer) { layer->ResetReading(); OGRFeature* ft = layer->GetNextFeature(); @@ -1478,7 +1478,7 @@ STDMETHODIMP COgrLayer::GetNumStyles(LONG* pVal) // ************************************************************* STDMETHODIMP COgrLayer::get_StyleName(LONG styleIndex, BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!CheckState()) return S_OK; @@ -1487,12 +1487,12 @@ STDMETHODIMP COgrLayer::get_StyleName(LONG styleIndex, BSTR* pVal) bool found = false; CPLErrorReset(); - OGRLayer* layer = _dataset->ExecuteSQL(OgrHelper::String2OgrString(sql), NULL, NULL); + OGRLayer* layer = _dataset->ExecuteSQL(OgrHelper::String2OgrString(sql), nullptr, nullptr); if (layer) { layer->ResetReading(); - OGRFeature* ft = NULL; + OGRFeature* ft = nullptr; int count = 0; - while ((ft = layer->GetNextFeature()) != NULL) + while ((ft = layer->GetNextFeature()) != nullptr) { if (count == styleIndex) { CStringW name = OgrHelper::OgrString2Unicode(ft->GetFieldAsString(0)); @@ -1527,20 +1527,20 @@ CStringW COgrLayer::LoadStyleXML(CStringW name) // ************************************************************* STDMETHODIMP COgrLayer::ClearStyles(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!CheckState() || !HasStyleTable()) { *retVal = VARIANT_TRUE; return S_OK; } - + USES_CONVERSION; CStringW sql; sql.Format(L"DELETE FROM %s WHERE layername = '%s'", GetStyleTableName(), GetLayerName()); CPLErrorReset(); - _dataset->ExecuteSQL(OgrHelper::String2OgrString(sql), NULL, NULL); + _dataset->ExecuteSQL(OgrHelper::String2OgrString(sql), nullptr, nullptr); *retVal = CPLGetLastErrorNo() == OGRERR_NONE ? VARIANT_TRUE : VARIANT_FALSE; return S_OK; @@ -1551,7 +1551,7 @@ STDMETHODIMP COgrLayer::ClearStyles(VARIANT_BOOL* retVal) // ************************************************************* STDMETHODIMP COgrLayer::RemoveStyle(BSTR styleName, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (!CheckState()) return S_OK; @@ -1567,12 +1567,12 @@ STDMETHODIMP COgrLayer::RemoveStyle(BSTR styleName, VARIANT_BOOL* retVal) // ************************************************************* void COgrLayer::GetFieldValues(OGRFieldType fieldType, BSTR& fieldName, vector& values) { - if (_sourceType == ogrDbTable || _sourceType == ogrFile) + if (_sourceType == ogrDbTable || _sourceType == ogrFile) { // load only the necessary column CStringW sql; sql.Format(L"SELECT %s FROM %s;", fieldName, GetLayerName()); - OGRLayer* layer = _dataset->ExecuteSQL(OgrHelper::String2OgrString(sql), NULL, NULL); + OGRLayer* layer = _dataset->ExecuteSQL(OgrHelper::String2OgrString(sql), nullptr, nullptr); if (layer) { OgrHelper::GetFieldValues(layer, static_cast( _layer->GetFeatureCount()), fieldType, values, _globalCallback); @@ -1593,7 +1593,7 @@ STDMETHODIMP COgrLayer::GenerateCategories(BSTR FieldName, tkClassificationType long numClasses, tkMapColor colorStart, tkMapColor colorEnd, tkColorSchemeType schemeType, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (!CheckState()) return S_OK; @@ -1607,7 +1607,7 @@ STDMETHODIMP COgrLayer::GenerateCategories(BSTR FieldName, tkClassificationType CStringW fid = OgrHelper::OgrString2Unicode(_layer->GetFIDColumn()); bool hasFid = fid.GetLength() > 0; - CComPtr sf = NULL; + CComPtr sf = nullptr; GetBuffer(&sf); if (!sf) { ErrorMessage(tkOGR_NO_SHAPEFILE); @@ -1637,7 +1637,7 @@ STDMETHODIMP COgrLayer::GenerateCategories(BSTR FieldName, tkClassificationType return S_OK; } - IShapefileCategories* ct = NULL; + IShapefileCategories* ct = nullptr; sf->get_Categories(&ct); if (ct) { @@ -1650,7 +1650,7 @@ STDMETHODIMP COgrLayer::GenerateCategories(BSTR FieldName, tkClassificationType *retVal = VARIANT_TRUE; } - CComPtr scheme = NULL; + CComPtr scheme = nullptr; ComHelper::CreateInstance(idColorScheme, (IDispatch**)&scheme); if (scheme) { scheme->SetColors2(colorStart, colorEnd); @@ -1674,7 +1674,7 @@ STDMETHODIMP COgrLayer::GenerateCategories(BSTR FieldName, tkClassificationType // ************************************************************* STDMETHODIMP COgrLayer::get_DriverName(BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!CheckState()) { *pVal = A2BSTR(""); @@ -1685,7 +1685,6 @@ STDMETHODIMP COgrLayer::get_DriverName(BSTR* pVal) *pVal = A2BSTR(_dataset->GetDriverName()); // no need to convert from UTF-8: it's in ASCII return S_OK; } - return S_OK; } // ************************************************************* @@ -1693,7 +1692,7 @@ STDMETHODIMP COgrLayer::get_DriverName(BSTR* pVal) // ************************************************************* STDMETHODIMP COgrLayer::get_AvailableShapeTypes(VARIANT* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) vector result; if (!CheckState()) @@ -1757,13 +1756,13 @@ void COgrLayer::GetMsSqlShapeTypes(vector& result) set types; - OGRLayer* lyr = _dataset->ExecuteSQL(Utility::ConvertToUtf8(sql), NULL, NULL); + OGRLayer* lyr = _dataset->ExecuteSQL(Utility::ConvertToUtf8(sql), nullptr, nullptr); if (lyr) { lyr->ResetReading(); - OGRFeature* ft = NULL; - while ((ft = lyr->GetNextFeature()) != NULL) + OGRFeature* ft = nullptr; + while ((ft = lyr->GetNextFeature()) != nullptr) { CStringW s = Utility::ConvertFromUtf8(ft->GetFieldAsString(0)); ShpfileType shpType = OgrHelper::OgcType2ShapeType(s); @@ -1792,7 +1791,7 @@ void COgrLayer::GetMsSqlShapeTypes(vector& result) // ************************************************************* STDMETHODIMP COgrLayer::get_ActiveShapeType(ShpfileType* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) ShpfileType shpType; get_ShapeType(&shpType); @@ -1804,7 +1803,7 @@ STDMETHODIMP COgrLayer::get_ActiveShapeType(ShpfileType* pVal) STDMETHODIMP COgrLayer::put_ActiveShapeType(ShpfileType newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) ShpfileType shpType; get_ShapeType(&shpType); @@ -1834,7 +1833,7 @@ STDMETHODIMP COgrLayer::put_ActiveShapeType(ShpfileType newVal) // ************************************************************* STDMETHODIMP COgrLayer::get_IsExternalDatasource(VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _externalDatasource; diff --git a/src/COM classes/SelectionList.cpp b/src/COM classes/SelectionList.cpp index fad805fe..4a6db18f 100644 --- a/src/COM classes/SelectionList.cpp +++ b/src/COM classes/SelectionList.cpp @@ -8,7 +8,7 @@ // **************************************************************** STDMETHODIMP CSelectionList::AddShape(LONG layerHandle, LONG shapeIndex) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _items.push_back(new SelectedItem(layerHandle, shapeIndex)); return S_OK; } @@ -18,8 +18,8 @@ STDMETHODIMP CSelectionList::AddShape(LONG layerHandle, LONG shapeIndex) // **************************************************************** STDMETHODIMP CSelectionList::get_Count(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _items.size(); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = static_cast(_items.size()); return S_OK; } @@ -28,9 +28,9 @@ STDMETHODIMP CSelectionList::get_Count(LONG* pVal) // **************************************************************** STDMETHODIMP CSelectionList::get_LayerHandle(LONG index, LONG* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (index < 0 || index >= (long)_items.size()) + if (index < 0 || index >= static_cast(_items.size())) { *retVal = -1; return S_OK; @@ -46,8 +46,8 @@ STDMETHODIMP CSelectionList::get_LayerHandle(LONG index, LONG* retVal) // **************************************************************** STDMETHODIMP CSelectionList::get_ShapeIndex(LONG index, LONG* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - if (index < 0 || index >= (long)_items.size()) + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + if (index < 0 || index >= static_cast(_items.size())) { *retVal = -1; return S_OK; @@ -61,12 +61,12 @@ STDMETHODIMP CSelectionList::get_ShapeIndex(LONG index, LONG* retVal) // **************************************************************** STDMETHODIMP CSelectionList::Clear() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) for (size_t i = 0; i < _items.size(); i++) { delete _items[i]; - _items[i] = NULL; + _items[i] = nullptr; } _items.clear(); @@ -79,11 +79,11 @@ STDMETHODIMP CSelectionList::Clear() // **************************************************************** STDMETHODIMP CSelectionList::RemoveByLayerHandle(LONG layerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - for (long i = (long)_items.size() - 1; i >= 0; i--) + for (long i = static_cast(_items.size()) - 1; i >= 0; i--) { - if (_items[i]->LayerHandle == layerHandle) + if (_items[i]->LayerHandle == layerHandle) { delete _items[i]; _items.erase(_items.begin() + i); @@ -98,7 +98,7 @@ STDMETHODIMP CSelectionList::RemoveByLayerHandle(LONG layerHandle) // **************************************************************** STDMETHODIMP CSelectionList::AddPixel(LONG layerHandle, LONG column, LONG row) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _items.push_back(new SelectedItem(layerHandle, row, column)); @@ -110,7 +110,7 @@ STDMETHODIMP CSelectionList::AddPixel(LONG layerHandle, LONG column, LONG row) // **************************************************************** STDMETHODIMP CSelectionList::TogglePixel(LONG layerHandle, LONG column, LONG row) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) for (size_t i = 0; i < _items.size(); i++) { @@ -131,9 +131,9 @@ STDMETHODIMP CSelectionList::TogglePixel(LONG layerHandle, LONG column, LONG row // **************************************************************** STDMETHODIMP CSelectionList::get_LayerType(LONG index, tkLayerType* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (index < 0 || index >= (long)_items.size()) + if (index < 0 || index >= static_cast(_items.size())) { *pVal = tkLayerType::ltUndefined; return S_OK; @@ -149,9 +149,9 @@ STDMETHODIMP CSelectionList::get_LayerType(LONG index, tkLayerType* pVal) // **************************************************************** STDMETHODIMP CSelectionList::get_RasterX(LONG index, LONG* pVal) { - //AFX_MANAGE_STATE(AfxGetStaticModuleState()); + //AFX_MANAGE_STATE(AfxGetStaticModuleState()) - //if (index < 0 || index >= (long)_items.size()) + //if (index < 0 || index >= static_cast(_items.size())) //{ // *pVal = tkLayerType::ltUndefined; // return S_OK; @@ -169,7 +169,7 @@ STDMETHODIMP CSelectionList::get_RasterX(LONG index, LONG* pVal) // **************************************************************** STDMETHODIMP CSelectionList::get_RasterY(LONG index, LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) //if (index < 0 || index >= (long)_items.size()) //{ @@ -190,9 +190,9 @@ STDMETHODIMP CSelectionList::get_RasterY(LONG index, LONG* pVal) // **************************************************************** STDMETHODIMP CSelectionList::get_Row(LONG index, LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (index < 0 || index >= (long)_items.size()) + if (index < 0 || index >= static_cast(_items.size())) { *pVal = tkLayerType::ltUndefined; return S_OK; @@ -207,9 +207,9 @@ STDMETHODIMP CSelectionList::get_Row(LONG index, LONG* pVal) // **************************************************************** STDMETHODIMP CSelectionList::get_Column(LONG index, LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (index < 0 || index >= (long)_items.size()) + if (index < 0 || index >= static_cast(_items.size())) { *pVal = tkLayerType::ltUndefined; return S_OK; @@ -257,9 +257,9 @@ void CSelectionList::UpdatePixelBounds(long layerHandle, IImage* source, bool po // **************************************************************** SelectedItem* CSelectionList::GetItem(int index) { - if (index < 0 || index >= (long)_items.size()) + if (index < 0 || index >= static_cast(_items.size())) { - return NULL; + return nullptr; } return _items[index]; diff --git a/src/COM classes/ShapeDrawingOptions.cpp b/src/COM classes/ShapeDrawingOptions.cpp index 579c6338..2384d636 100644 --- a/src/COM classes/ShapeDrawingOptions.cpp +++ b/src/COM classes/ShapeDrawingOptions.cpp @@ -88,19 +88,19 @@ STDMETHODIMP CShapeDrawingOptions::get_ErrorMsg(long ErrorCode, BSTR *pVal) // ***************************************************************** STDMETHODIMP CShapeDrawingOptions::get_PointRotationExpression(BSTR* retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; - *retval = OLE2BSTR(_options.rotationExpression); - return S_OK; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + USES_CONVERSION; + *retval = OLE2BSTR(_options.rotationExpression); + return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_PointRotationExpression(BSTR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; - ::SysFreeString(_options.rotationExpression); - _options.rotationExpression = OLE2BSTR(newVal); - return S_OK; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + USES_CONVERSION; + ::SysFreeString(_options.rotationExpression); + _options.rotationExpression = OLE2BSTR(newVal); + return S_OK; } // ******************************************************* @@ -113,7 +113,7 @@ STDMETHODIMP CShapeDrawingOptions::get_Picture(IImage** pVal) if ( _options.picture ) _options.picture->AddRef(); return S_OK; -}; +} // ******************************************************* // put_Picture() @@ -156,7 +156,7 @@ STDMETHODIMP CShapeDrawingOptions::put_Picture(IImage* newVal) } } return S_OK; -}; +} // There are 2 overloads for each function: // hdc passed as int** - for new Graphics handle @@ -169,13 +169,13 @@ STDMETHODIMP CShapeDrawingOptions::put_Picture(IImage* newVal) STDMETHODIMP CShapeDrawingOptions::DrawPoint(int hdc, float x, float y, int clipWidth, int clipHeight, OLE_COLOR backColor, BYTE backAlpha, VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - CDC* dc = CDC::FromHandle((HDC)hdc); + CDC* dc = CDC::FromHandle(reinterpret_cast(static_cast(hdc))); if (clipWidth == 0) - clipWidth = (int)_options.pointSize + 1; + clipWidth = static_cast(_options.pointSize) + 1; if (clipHeight == 0) - clipHeight = (int)_options.pointSize + 1; + clipHeight = static_cast(_options.pointSize) + 1; *retVal = DrawPointCore(dc, x, y, clipWidth, clipHeight, backColor, backAlpha); return S_OK; @@ -210,7 +210,7 @@ VARIANT_BOOL CShapeDrawingOptions::DrawPointCore(CDC* dc, float x, float y, int return VARIANT_FALSE; } - IShape* shp = NULL; + IShape* shp = nullptr; ComHelper::CreateShape(&shp); if (!shp) return VARIANT_FALSE; @@ -223,7 +223,7 @@ VARIANT_BOOL CShapeDrawingOptions::DrawPointCore(CDC* dc, float x, float y, int return VARIANT_FALSE; } - IPoint* pnt = NULL; + IPoint* pnt = nullptr; ComHelper::CreatePoint(&pnt); pnt->put_X(clipWidth/2.0); pnt->put_Y(clipHeight/2.0); @@ -246,7 +246,7 @@ VARIANT_BOOL CShapeDrawingOptions::DrawPointCore(CDC* dc, float x, float y, int STDMETHODIMP CShapeDrawingOptions::DrawLine(int hdc, float x, float y, int width, int height, VARIANT_BOOL drawVertices, int clipWidth, int clipHeight, OLE_COLOR backColor, BYTE backAlpha, VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - CDC* dc = CDC::FromHandle((HDC)hdc); + CDC* dc = CDC::FromHandle(reinterpret_cast(static_cast(hdc))); if (clipWidth == 0) clipWidth = width + 1; @@ -286,19 +286,19 @@ VARIANT_BOOL CShapeDrawingOptions::DrawLineCore(CDC* dc, float x, float y, int w ErrorMessage(tkFAILED_TO_OBTAIN_DC); return VARIANT_FALSE; } - - IShape* shp = NULL; + + IShape* shp = nullptr; ComHelper::CreateShape(&shp); if (!shp) return VARIANT_FALSE; VARIANT_BOOL vbretval; shp->Create(SHP_POLYLINE, &vbretval); - - long position = 0; - shp->InsertPart(0, &position, &vbretval); - - IPoint* pnt = NULL; - + + long position = 0; + shp->InsertPart(0, &position, &vbretval); + + IPoint* pnt = nullptr; + for (int i = 0; i < 2; i++) { ComHelper::CreatePoint(&pnt); @@ -349,7 +349,7 @@ STDMETHODIMP CShapeDrawingOptions::DrawRectangle(int hdc, float x, float y, int int clipWidth, int clipHeight, OLE_COLOR backColor, BYTE backAlpha, VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - CDC* dc = CDC::FromHandle((HDC)hdc); + CDC* dc = CDC::FromHandle(reinterpret_cast(static_cast(hdc))); if (clipWidth == 0) clipWidth = width + 1; @@ -367,7 +367,7 @@ STDMETHODIMP CShapeDrawingOptions::DrawRectangle(int hdc, float x, float y, int //STDMETHODIMP CShapeDrawingOptions::DrawRectangleVB(int hdc, float x, float y, int width, int height, VARIANT_BOOL drawVertices, // int clipWidth, int clipHeight, OLE_COLOR backColor, BYTE backAlpha, VARIANT_BOOL* retVal) //{ -// AFX_MANAGE_STATE(AfxGetStaticModuleState()); +// AFX_MANAGE_STATE(AfxGetStaticModuleState()) // CDC* dc = CDC::FromHandle((HDC)hdc); // // if (clipWidth == 0) @@ -391,17 +391,17 @@ VARIANT_BOOL CShapeDrawingOptions::DrawRectangleCore(CDC* dc, float x, float y, return VARIANT_FALSE; } - IShape* shp = NULL; + IShape* shp = nullptr; ComHelper::CreateShape(&shp); if (!shp) return VARIANT_FALSE; VARIANT_BOOL vbretval; shp->Create(SHP_POLYGON, &vbretval); - long position = 0; - shp->InsertPart(0, &position, &vbretval); - - IPoint* pnt = NULL; + long position = 0; + shp->InsertPart(0, &position, &vbretval); + + IPoint* pnt = nullptr; for (int i = 0; i <= 4; i++) // <=4 { @@ -467,8 +467,6 @@ VARIANT_BOOL CShapeDrawingOptions::DrawRectangleCore(CDC* dc, float x, float y, VARIANT_BOOL retVal = this->DrawShapeCore(dc, x, y, shp, drawVertices, clipWidth, clipHeight, backColor, backAlpha); shp->Release(); return retVal; - - return VARIANT_TRUE; } #pragma endregion @@ -483,7 +481,7 @@ STDMETHODIMP CShapeDrawingOptions::DrawShape(int hdc, float x, float y, IShape* VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - CDC* dc = CDC::FromHandle((HDC)hdc); + CDC* dc = CDC::FromHandle(reinterpret_cast(static_cast(hdc))); *retVal = this->DrawShapeCore(dc, x, y, shape, drawVertices, clipWidth, clipHeight, backColor, backAlpha); return S_OK; @@ -496,7 +494,7 @@ STDMETHODIMP CShapeDrawingOptions::DrawShape(int hdc, float x, float y, IShape* // int clipWidth, int clipHeight, OLE_COLOR backColor, BYTE backAlpha, // VARIANT_BOOL* retVal) //{ -// AFX_MANAGE_STATE(AfxGetStaticModuleState()); +// AFX_MANAGE_STATE(AfxGetStaticModuleState()) // CDC* dc = CDC::FromHandle((HDC)hdc); // // *retVal = this->DrawShapeCore(dc, x, y, shape, drawVertices, clipWidth, clipHeight, backColor, backAlpha); @@ -534,8 +532,8 @@ VARIANT_BOOL CShapeDrawingOptions::DrawShapeCore(CDC* dc, float x, float y, ISha double xVal, yVal; VARIANT_BOOL vbretval; shape->get_XY(i, &xVal, &yVal, &vbretval); - points[i].X = (int)xVal; - points[i].Y = (int)yVal; + points[i].X = static_cast(xVal); + points[i].Y = static_cast(yVal); } Gdiplus::GraphicsPath path; @@ -557,7 +555,7 @@ VARIANT_BOOL CShapeDrawingOptions::DrawShapeCore(CDC* dc, float x, float y, ISha { VARIANT_BOOL vbretval; HDC hdcTemp = g.GetHDC(); - _options.linePattern->Draw((int)hdcTemp, 0.0f, 0.0f, clipWidth, clipHeight, backColor, backAlpha, &vbretval); + _options.linePattern->Draw(static_cast(reinterpret_cast(hdcTemp)), 0.0f, 0.0f, clipWidth, clipHeight, backColor, backAlpha, &vbretval); g.ReleaseHDC(hdcTemp); } else @@ -625,7 +623,7 @@ VARIANT_BOOL CShapeDrawingOptions::DrawShapeCore(CDC* dc, float x, float y, ISha { g.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality); - _options.DrawPointSymbol(g, dc, points, NULL, 1); + _options.DrawPointSymbol(g, dc, points, nullptr, 1); } // clearing @@ -702,72 +700,72 @@ VARIANT_BOOL CShapeDrawingOptions::DrawShapeCore(CDC* dc, float x, float y, ISha // ********************************************************* STDMETHODIMP CShapeDrawingOptions::get_PointCharacter (short* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *retVal = (short)_options.pointCharcter; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *retVal = static_cast(_options.pointCharcter); return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_PointCharacter (short newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - _options.pointCharcter = (unsigned char)newVal; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _options.pointCharcter = static_cast(newVal); return S_OK; } // ***************************************************************** // FontName() // ***************************************************************** -STDMETHODIMP CShapeDrawingOptions::get_FontName(BSTR* retval) +STDMETHODIMP CShapeDrawingOptions::get_FontName(BSTR* retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; *retval = A2BSTR(_options.fontName); return S_OK; -}; -STDMETHODIMP CShapeDrawingOptions::put_FontName(BSTR newVal) +} +STDMETHODIMP CShapeDrawingOptions::put_FontName(BSTR newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; _options.fontName = OLE2CA(newVal); return S_OK; -}; +} // ***************************************************************** // FontName() // ***************************************************************** -STDMETHODIMP CShapeDrawingOptions::get_Tag(BSTR* retVal) +STDMETHODIMP CShapeDrawingOptions::get_Tag(BSTR* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; *retVal = A2BSTR(_options.tag); return S_OK; -}; -STDMETHODIMP CShapeDrawingOptions::put_Tag(BSTR newVal) +} +STDMETHODIMP CShapeDrawingOptions::put_Tag(BSTR newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; _options.tag = OLE2CA(newVal); return S_OK; -}; +} // ***************************************************************** // RotationField() // ***************************************************************** STDMETHODIMP CShapeDrawingOptions::get_RotationField(BSTR* retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + USES_CONVERSION; - *retval = A2BSTR(_options.rotationField); - return S_OK; -}; + *retval = A2BSTR(_options.rotationField); + return S_OK; +} STDMETHODIMP CShapeDrawingOptions::put_RotationField(BSTR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + USES_CONVERSION; - _options.rotationField = OLE2CA(newVal); - return S_OK; -}; + _options.rotationField = OLE2CA(newVal); + return S_OK; +} // ***************************************************************** // Clone() @@ -776,8 +774,8 @@ STDMETHODIMP CShapeDrawingOptions::Clone(IShapeDrawingOptions** retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - IShapeDrawingOptions* sdo = NULL; - CoCreateInstance(CLSID_ShapeDrawingOptions,NULL,CLSCTX_INPROC_SERVER,IID_IShapeDrawingOptions,(void**)&sdo); + IShapeDrawingOptions* sdo = nullptr; + CoCreateInstance(CLSID_ShapeDrawingOptions, nullptr,CLSCTX_INPROC_SERVER,IID_IShapeDrawingOptions,(void**)&sdo); if (sdo) { ((CShapeDrawingOptions*)sdo)->put_underlyingOptions(&_options); @@ -971,14 +969,14 @@ STDMETHODIMP CShapeDrawingOptions::SetDefaultPointSymbol (tkDefaultPointSymbol s // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_Visible(VARIANT_BOOL *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = (VARIANT_BOOL)_options.visible; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = (VARIANT_BOOL)_options.visible; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_Visible(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - _options.visible = newVal?true:false; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _options.visible = newVal?true:false; return S_OK; } @@ -987,14 +985,14 @@ STDMETHODIMP CShapeDrawingOptions::put_Visible(VARIANT_BOOL newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_FillVisible (VARIANT_BOOL *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.fillVisible; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_FillVisible (VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - _options.fillVisible = newVal?true:false; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _options.fillVisible = newVal?true:false; return S_OK; } @@ -1003,14 +1001,14 @@ STDMETHODIMP CShapeDrawingOptions::put_FillVisible (VARIANT_BOOL newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_LineVisible (VARIANT_BOOL *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.linesVisible; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.linesVisible; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_LineVisible (VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - _options.linesVisible = newVal?true:false; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _options.linesVisible = newVal?true:false; return S_OK; } @@ -1019,13 +1017,13 @@ STDMETHODIMP CShapeDrawingOptions::put_LineVisible (VARIANT_BOOL newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_FillColor (OLE_COLOR *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.fillColor; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.fillColor; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_FillColor (OLE_COLOR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _options.fillColor = newVal; return S_OK; } @@ -1035,14 +1033,14 @@ STDMETHODIMP CShapeDrawingOptions::put_FillColor (OLE_COLOR newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_LineColor (OLE_COLOR *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.lineColor; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_LineColor (OLE_COLOR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - _options.lineColor = newVal; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _options.lineColor = newVal; return S_OK; } @@ -1051,13 +1049,13 @@ STDMETHODIMP CShapeDrawingOptions::put_LineColor (OLE_COLOR newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_DrawingMode (tkVectorDrawingMode *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.drawingMode; return S_OK; } -STDMETHODIMP CShapeDrawingOptions::put_DrawingMode (tkVectorDrawingMode newVal) +STDMETHODIMP CShapeDrawingOptions::put_DrawingMode (tkVectorDrawingMode newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // It's no longer allowed to change drawing mode //m_options.drawingMode = newVal; return S_OK; @@ -1066,18 +1064,18 @@ STDMETHODIMP CShapeDrawingOptions::put_DrawingMode (tkVectorDrawingMode newVal) // **************************************************************** // get_FillHatchStyle // **************************************************************** -STDMETHODIMP CShapeDrawingOptions::get_FillHatchStyle (tkGDIPlusHatchStyle *pVal) +STDMETHODIMP CShapeDrawingOptions::get_FillHatchStyle (tkGDIPlusHatchStyle *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.fillHatchStyle; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.fillHatchStyle; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_FillHatchStyle (tkGDIPlusHatchStyle newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal >= -1 && newVal <= 52) { - _options.fillHatchStyle = newVal; + _options.fillHatchStyle = newVal; } else { @@ -1091,16 +1089,16 @@ STDMETHODIMP CShapeDrawingOptions::put_FillHatchStyle (tkGDIPlusHatchStyle newVa // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_LineStipple (tkDashStyle *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.lineStipple; return S_OK; } -STDMETHODIMP CShapeDrawingOptions::put_LineStipple (tkDashStyle newVal) +STDMETHODIMP CShapeDrawingOptions::put_LineStipple (tkDashStyle newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal >= 0 && newVal <= 5) { - _options.lineStipple = newVal; + _options.lineStipple = newVal; } else { @@ -1114,16 +1112,16 @@ STDMETHODIMP CShapeDrawingOptions::put_LineStipple (tkDashStyle newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_PointShape (tkPointShapeType *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.pointShapeType; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_PointShape (tkPointShapeType newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal >= 0 && newVal <= 5) { - _options.pointShapeType = newVal; + _options.pointShapeType = newVal; } else { @@ -1137,16 +1135,16 @@ STDMETHODIMP CShapeDrawingOptions::put_PointShape (tkPointShapeType newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_FillTransparency (float *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.fillTransparency; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_FillTransparency (float newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < 0) newVal = 0; if (newVal > 255) newVal = 255; - _options.fillTransparency = newVal; + _options.fillTransparency = newVal; return S_OK; } @@ -1155,13 +1153,13 @@ STDMETHODIMP CShapeDrawingOptions::put_FillTransparency (float newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_LineWidth (float *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.lineWidth; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.lineWidth; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_LineWidth (float newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < 1) newVal = 1; if (newVal > 20) newVal = 20; _options.lineWidth = newVal; @@ -1173,16 +1171,16 @@ STDMETHODIMP CShapeDrawingOptions::put_LineWidth (float newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_PointSize (float *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.pointSize; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.pointSize; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_PointSize (float newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < 1) newVal = 1; if (newVal > 100) newVal = 100; - _options.pointSize = newVal; + _options.pointSize = newVal; return S_OK; } @@ -1192,14 +1190,14 @@ STDMETHODIMP CShapeDrawingOptions::put_PointSize (float newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_FillBgTransparent (VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.fillBgTransparent; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.fillBgTransparent; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_FillBgTransparent (VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - _options.fillBgTransparent = newVal?true:false; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _options.fillBgTransparent = newVal?true:false; return S_OK; } @@ -1208,14 +1206,14 @@ STDMETHODIMP CShapeDrawingOptions::put_FillBgTransparent (VARIANT_BOOL newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_FillBgColor (OLE_COLOR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.fillBgColor; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.fillBgColor; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_FillBgColor (OLE_COLOR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - _options.fillBgColor = newVal; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _options.fillBgColor = newVal; return S_OK; } @@ -1224,16 +1222,16 @@ STDMETHODIMP CShapeDrawingOptions::put_FillBgColor (OLE_COLOR newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_FillType (tkFillType* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.fillType; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.fillType; return S_OK; } -STDMETHODIMP CShapeDrawingOptions::put_FillType (tkFillType newVal) +STDMETHODIMP CShapeDrawingOptions::put_FillType (tkFillType newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal >= 0 && newVal <= 3) { - _options.fillType = newVal; + _options.fillType = newVal; } else { @@ -1247,16 +1245,16 @@ STDMETHODIMP CShapeDrawingOptions::put_FillType (tkFillType newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_FillGradientType (tkGradientType* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.fillGradientType; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_FillGradientType (tkGradientType newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal >= 0 && newVal <= 2) { - _options.fillGradientType = newVal; + _options.fillGradientType = newVal; } else { @@ -1270,13 +1268,13 @@ STDMETHODIMP CShapeDrawingOptions::put_FillGradientType (tkGradientType newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_PointType(tkPointSymbolType* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.pointSymbolType; return S_OK; } -STDMETHODIMP CShapeDrawingOptions::put_PointType (tkPointSymbolType newVal) +STDMETHODIMP CShapeDrawingOptions::put_PointType (tkPointSymbolType newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal >= 0 && newVal <= 2) { _options.pointSymbolType = newVal; @@ -1293,14 +1291,14 @@ STDMETHODIMP CShapeDrawingOptions::put_PointType (tkPointSymbolType newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_FillColor2 (OLE_COLOR *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.fillColor2; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.fillColor2; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_FillColor2 (OLE_COLOR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - _options.fillColor2 = newVal; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _options.fillColor2 = newVal; return S_OK; } @@ -1309,20 +1307,20 @@ STDMETHODIMP CShapeDrawingOptions::put_FillColor2 (OLE_COLOR newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_PointRotation (double *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.rotation; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.rotation; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_PointRotation (double newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal > 360.0 || newVal < -360.0) { ErrorMessage(tkINVALID_PARAMETER_VALUE); } else { - _options.rotation = newVal; + _options.rotation = newVal; } return S_OK; } @@ -1332,13 +1330,13 @@ STDMETHODIMP CShapeDrawingOptions::put_PointRotation (double newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_PointReflection(tkPointReflectionType* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.pointReflectionType; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_PointReflection(tkPointReflectionType newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal >= 0 && newVal <= 2) { _options.pointReflectionType = newVal; @@ -1355,16 +1353,16 @@ STDMETHODIMP CShapeDrawingOptions::put_PointReflection(tkPointReflectionType new // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_PointSidesCount (long *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.pointNumSides; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_PointSidesCount (long newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal > 20) newVal = 20; if (newVal < 2) newVal = 2; - _options.pointNumSides = newVal; + _options.pointNumSides = newVal; return S_OK; } @@ -1373,13 +1371,13 @@ STDMETHODIMP CShapeDrawingOptions::put_PointSidesCount (long newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_PointSidesRatio (float *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.pointShapeRatio; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_PointSidesRatio (float newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < 0.1f) newVal = 0.1f; if (newVal > 1.0f) newVal = 1.0f; _options.pointShapeRatio = newVal; @@ -1387,17 +1385,17 @@ STDMETHODIMP CShapeDrawingOptions::put_PointSidesRatio (float newVal) } // **************************************************************** -// get_PointSidesRatio +// get_FillRotation // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_FillRotation(double *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.fillGradientRotation; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.fillGradientRotation; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_FillRotation (double newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal > 360.0 || newVal < -360.0) { ErrorMessage(tkINVALID_PARAMETER_VALUE); @@ -1414,16 +1412,16 @@ STDMETHODIMP CShapeDrawingOptions::put_FillRotation (double newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_FillGradientBounds (tkGradientBounds *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.fillGradientBounds; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.fillGradientBounds; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_FillGradientBounds (tkGradientBounds newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal >= 0 && newVal <= 1) { - _options.fillGradientBounds = newVal; + _options.fillGradientBounds = newVal; } else { @@ -1437,16 +1435,16 @@ STDMETHODIMP CShapeDrawingOptions::put_FillGradientBounds (tkGradientBounds newV // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_LineTransparency(float *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.lineTransparency; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_LineTransparency(float newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < 0) newVal = 0; if (newVal > 255) newVal = 255; - _options.lineTransparency = newVal; + _options.lineTransparency = newVal; return S_OK; } @@ -1455,16 +1453,16 @@ STDMETHODIMP CShapeDrawingOptions::put_LineTransparency(float newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_PictureScaleX(double *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.scaleX; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.scaleX; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_PictureScaleX(double newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < 0.1) newVal = 0.1; if (newVal > 5.0) newVal = 5.0; - _options.scaleX = newVal; + _options.scaleX = newVal; return S_OK; } @@ -1473,16 +1471,16 @@ STDMETHODIMP CShapeDrawingOptions::put_PictureScaleX(double newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_PictureScaleY(double *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.scaleY; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.scaleY; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_PictureScaleY(double newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal < 0.1) newVal = 0.1; if (newVal > 5.0) newVal = 5.0; - _options.scaleY = newVal; + _options.scaleY = newVal; return S_OK; } #pragma endregion @@ -1492,14 +1490,14 @@ STDMETHODIMP CShapeDrawingOptions::put_PictureScaleY(double newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_AlignPictureByBottom(VARIANT_BOOL *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.alignIconByBottom; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.alignIconByBottom; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_AlignPictureByBottom(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - _options.alignIconByBottom = newVal ? true: false; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _options.alignIconByBottom = newVal ? true: false; return S_OK; } @@ -1520,10 +1518,10 @@ STDMETHODIMP CShapeDrawingOptions::Serialize(BSTR* retVal) CPLXMLNode* CShapeDrawingOptions::SerializeCore(CString ElementName) { USES_CONVERSION; - - CPLXMLNode* psTree = CPLCreateXMLNode( NULL, CXT_Element, ElementName); + + CPLXMLNode* psTree = CPLCreateXMLNode(nullptr, CXT_Element, ElementName); CString str; - + CDrawingOptionsEx* opt = new CDrawingOptionsEx(); if (opt->fillBgColor != _options.fillBgColor) @@ -1537,97 +1535,97 @@ CPLXMLNode* CShapeDrawingOptions::SerializeCore(CString ElementName) if (opt->fillColor2 != _options.fillColor2) Utility::CPLCreateXMLAttributeAndValue(psTree, "FillColor2", CPLString().Printf("%d", _options.fillColor2)); - + if (opt->fillGradientBounds != _options.fillGradientBounds) Utility::CPLCreateXMLAttributeAndValue(psTree, "FillGradientBounds", CPLString().Printf("%d", (int)_options.fillGradientBounds)); - + if (opt->fillGradientRotation != _options.fillGradientRotation) Utility::CPLCreateXMLAttributeAndValue(psTree, "FillGradientRotation", CPLString().Printf("%f", _options.fillGradientRotation)); - + if (opt->fillGradientType != _options.fillGradientType) Utility::CPLCreateXMLAttributeAndValue(psTree, "FillGradientType", CPLString().Printf("%d", (int)_options.fillGradientType)); - + if (opt->fillHatchStyle != _options.fillHatchStyle) Utility::CPLCreateXMLAttributeAndValue(psTree, "FillHatchStyle", CPLString().Printf("%d", (int)_options.fillHatchStyle)); - + if (opt->fillTransparency != _options.fillTransparency) Utility::CPLCreateXMLAttributeAndValue(psTree, "FillTransparency", CPLString().Printf("%f", _options.fillTransparency)); - + if (opt->fillType != _options.fillType) Utility::CPLCreateXMLAttributeAndValue(psTree, "FillType", CPLString().Printf("%d", (int)_options.fillType)); - + if (opt->fillVisible != _options.fillVisible) Utility::CPLCreateXMLAttributeAndValue(psTree, "FillVisible", CPLString().Printf("%d", (int)_options.fillVisible)); - + if (opt->fontName != _options.fontName) Utility::CPLCreateXMLAttributeAndValue(psTree, "FontName", _options.fontName); - - if (opt->rotationField != _options.rotationField) - Utility::CPLCreateXMLAttributeAndValue(psTree, "RotationField", _options.rotationField); + + if (opt->rotationField != _options.rotationField) + Utility::CPLCreateXMLAttributeAndValue(psTree, "RotationField", _options.rotationField); if (opt->lineColor != _options.lineColor) Utility::CPLCreateXMLAttributeAndValue(psTree, "LineColor", CPLString().Printf("%d", _options.lineColor)); if (opt->lineTransparency != _options.lineTransparency) Utility::CPLCreateXMLAttributeAndValue(psTree, "LineTransparency", CPLString().Printf("%f", _options.lineTransparency)); - + if (opt->lineStipple != _options.lineStipple) Utility::CPLCreateXMLAttributeAndValue(psTree, "LineStipple", CPLString().Printf("%d", (int)_options.lineStipple)); - + if (opt->linesVisible != _options.linesVisible) Utility::CPLCreateXMLAttributeAndValue(psTree, "LinesVisible", CPLString().Printf("%d", (int)_options.linesVisible)); - + if (opt->lineWidth != _options.lineWidth) Utility::CPLCreateXMLAttributeAndValue(psTree, "LineWidth", CPLString().Printf("%f", _options.lineWidth)); - + if (opt->pointCharcter != _options.pointCharcter) Utility::CPLCreateXMLAttributeAndValue(psTree, "PointCharcter", CPLString().Printf("%d", (int)_options.pointCharcter)); - + if (opt->pointColor != _options.pointColor) Utility::CPLCreateXMLAttributeAndValue(psTree, "PointColor", CPLString().Printf("%d", _options.pointColor)); - + if (opt->pointNumSides != _options.pointNumSides) Utility::CPLCreateXMLAttributeAndValue(psTree, "PointNumSides", CPLString().Printf("%d", _options.pointNumSides)); - + if (opt->pointShapeRatio != _options.pointShapeRatio) Utility::CPLCreateXMLAttributeAndValue(psTree, "PointShapeRatio", CPLString().Printf("%f", _options.pointShapeRatio)); - + if (opt->pointShapeType != _options.pointShapeType) Utility::CPLCreateXMLAttributeAndValue(psTree, "PointShapeType", CPLString().Printf("%d", (int)_options.pointShapeType)); - + if (opt->pointSize != _options.pointSize) Utility::CPLCreateXMLAttributeAndValue(psTree, "PointSize", CPLString().Printf("%f", _options.pointSize)); - + if (opt->pointSymbolType != _options.pointSymbolType) Utility::CPLCreateXMLAttributeAndValue(psTree, "PointSymbolType", CPLString().Printf("%d", (int)_options.pointSymbolType)); - + if (opt->rotation != _options.rotation) Utility::CPLCreateXMLAttributeAndValue(psTree, "Rotation", CPLString().Printf("%f", _options.rotation)); - + if (opt->pointReflectionType != _options.pointReflectionType) Utility::CPLCreateXMLAttributeAndValue(psTree, "PointReflectionType", CPLString().Printf("%d", (int)_options.pointReflectionType)); if (opt->scaleX != _options.scaleX) Utility::CPLCreateXMLAttributeAndValue(psTree, "ScaleX", CPLString().Printf("%f", _options.scaleX)); - + if (opt->scaleY != _options.scaleY) Utility::CPLCreateXMLAttributeAndValue(psTree, "ScaleY", CPLString().Printf("%f", _options.scaleY)); - + if (opt->verticesColor != _options.verticesColor) Utility::CPLCreateXMLAttributeAndValue(psTree, "VerticesColor", CPLString().Printf("%d", _options.verticesColor)); - + if (opt->verticesFillVisible != _options.verticesFillVisible) Utility::CPLCreateXMLAttributeAndValue(psTree, "VerticesFillVisible", CPLString().Printf("%d", (int)_options.verticesFillVisible)); - + if (opt->verticesSize != _options.verticesSize) Utility::CPLCreateXMLAttributeAndValue(psTree, "VerticesSize", CPLString().Printf("%d", _options.verticesSize)); - + if (opt->verticesType != _options.verticesType) Utility::CPLCreateXMLAttributeAndValue(psTree, "VerticesType", CPLString().Printf("%d", (int)_options.verticesType)); - + if (opt->verticesVisible != _options.verticesVisible) Utility::CPLCreateXMLAttributeAndValue(psTree, "VerticesVisible", CPLString().Printf("%d", (int)_options.verticesVisible)); - + if (opt->visible != _options.visible) Utility::CPLCreateXMLAttributeAndValue(psTree, "Visible", CPLString().Printf("%d", (int)_options.visible)); @@ -1645,21 +1643,21 @@ CPLXMLNode* CShapeDrawingOptions::SerializeCore(CString ElementName) if (opt->dynamicVisibility != _options.dynamicVisibility) Utility::CPLCreateXMLAttributeAndValue(psTree, "DynamicVisibility", CPLString().Printf("%d", (int)_options.dynamicVisibility)); - + if (opt->minVisibleScale != _options.minVisibleScale) Utility::CPLCreateXMLAttributeAndValue(psTree, "MinVisibleScale", CPLString().Printf("%f", _options.minVisibleScale)); - + if (opt->maxVisibleScale != _options.maxVisibleScale) Utility::CPLCreateXMLAttributeAndValue(psTree, "MaxVisibleScale", CPLString().Printf("%f", _options.maxVisibleScale)); - if (opt->minVisibleZoom != _options.minVisibleZoom) - Utility::CPLCreateXMLAttributeAndValue(psTree, "MinVisibleZoom", CPLString().Printf("%d", _options.minVisibleZoom)); + if (opt->minVisibleZoom != _options.minVisibleZoom) + Utility::CPLCreateXMLAttributeAndValue(psTree, "MinVisibleZoom", CPLString().Printf("%d", _options.minVisibleZoom)); - if (opt->maxVisibleZoom != _options.maxVisibleZoom) - Utility::CPLCreateXMLAttributeAndValue(psTree, "MaxVisibleZoom", CPLString().Printf("%d", _options.maxVisibleZoom)); + if (opt->maxVisibleZoom != _options.maxVisibleZoom) + Utility::CPLCreateXMLAttributeAndValue(psTree, "MaxVisibleZoom", CPLString().Printf("%d", _options.maxVisibleZoom)); - if (opt->rotationExpression != _options.rotationExpression) - Utility::CPLCreateXMLAttributeAndValue(psTree, "RotationExpression", OLE2CA(_options.rotationExpression)); + if (opt->rotationExpression != _options.rotationExpression) + Utility::CPLCreateXMLAttributeAndValue(psTree, "RotationExpression", OLE2CA(_options.rotationExpression)); delete opt; @@ -1671,7 +1669,7 @@ CPLXMLNode* CShapeDrawingOptions::SerializeCore(CString ElementName) CPLAddXMLChild(psTree, psNode); } } - + if (_options.picture) { CPLXMLNode* psNode = ((CImageClass*)_options.picture)->SerializeCore(VARIANT_TRUE, "Picture"); @@ -1680,7 +1678,7 @@ CPLXMLNode* CShapeDrawingOptions::SerializeCore(CString ElementName) CPLAddXMLChild(psTree, psNode); } } - + return psTree; } @@ -1735,7 +1733,7 @@ bool CShapeDrawingOptions::DeserializeCore(CPLXMLNode* node) s = CPLGetXMLValue( node, "LineColor", nullptr); _options.lineColor = (s == "") ? opt->lineColor : (OLE_COLOR)atoi(s.GetString()); - + s = CPLGetXMLValue( node, "LineStipple", nullptr); _options.lineStipple = (s == "") ? opt->lineStipple : (tkDashStyle)atoi(s.GetString()); @@ -1753,7 +1751,7 @@ bool CShapeDrawingOptions::DeserializeCore(CPLXMLNode* node) s = CPLGetXMLValue( node, "PointColor", nullptr); _options.pointColor = (s == "") ? opt->pointColor : (OLE_COLOR)atoi(s.GetString()); - + s = CPLGetXMLValue( node, "PointNumSides", nullptr); _options.pointNumSides = (s == "") ? opt->pointNumSides : atoi(s.GetString()); @@ -1762,25 +1760,25 @@ bool CShapeDrawingOptions::DeserializeCore(CPLXMLNode* node) s = CPLGetXMLValue( node, "PointShapeType", nullptr); _options.pointShapeType = (s == "") ? opt->pointShapeType : (tkPointShapeType)atoi(s.GetString()); - + s = CPLGetXMLValue( node, "PointSize", nullptr); _options.pointSize = (s == "") ? opt->pointSize : (float)Utility::atof_custom(s); s = CPLGetXMLValue( node, "PointSymbolType", nullptr); _options.pointSymbolType = (s == "") ? opt->pointSymbolType : (tkPointSymbolType)atoi(s.GetString()); - + s = CPLGetXMLValue( node, "Rotation", nullptr); _options.rotation = (s == "") ? opt->rotation : Utility::atof_custom(s); - + s = CPLGetXMLValue( node, "PointReflectionType", nullptr); _options.pointReflectionType = (s == "") ? opt->pointReflectionType : (tkPointReflectionType)atoi(s.GetString()); - + s = CPLGetXMLValue( node, "ScaleX", nullptr); _options.scaleX = (s == "") ? opt->scaleX : Utility::atof_custom(s); - + s = CPLGetXMLValue( node, "ScaleY", nullptr); _options.scaleY = (s == "") ? opt->scaleY : Utility::atof_custom(s); - + s = CPLGetXMLValue( node, "VerticesColor", nullptr); _options.verticesColor = (s == "") ? opt->verticesColor : atoi(s); @@ -1795,10 +1793,10 @@ bool CShapeDrawingOptions::DeserializeCore(CPLXMLNode* node) s = CPLGetXMLValue( node, "VerticesVisible", nullptr); _options.verticesVisible = (s == "") ? opt->verticesVisible : (VARIANT_BOOL)atoi(s.GetString()); - + s = CPLGetXMLValue( node, "Visible", nullptr); _options.visible = (s == "") ? opt->visible : atoi(s.GetString()) == 0 ? false : true; - + s = CPLGetXMLValue( node, "AlignPictureByBottom", nullptr); _options.alignIconByBottom = (s == "") ? opt->alignIconByBottom : atoi(s.GetString()) == 0 ? false : true; @@ -1810,29 +1808,29 @@ bool CShapeDrawingOptions::DeserializeCore(CPLXMLNode* node) s = CPLGetXMLValue(node, "DynamicVisibility", nullptr); _options.dynamicVisibility = (s == "") ? opt->dynamicVisibility : atoi(s.GetString()) == 0 ? false : true; - + s = CPLGetXMLValue(node, "MinVisibleScale", nullptr); _options.minVisibleScale = (s == "") ? opt->minVisibleScale : Utility::atof_custom(s); - + s = CPLGetXMLValue(node, "MaxVisibleScale", nullptr); _options.maxVisibleScale = (s == "") ? opt->maxVisibleScale : Utility::atof_custom(s); - s = CPLGetXMLValue(node, "MinVisibleZoom", NULL); - _options.minVisibleZoom = (s == "") ? opt->minVisibleZoom : atoi(s.GetString()); + s = CPLGetXMLValue(node, "MinVisibleZoom", nullptr); + _options.minVisibleZoom = (s == "") ? opt->minVisibleZoom : atoi(s.GetString()); - s = CPLGetXMLValue(node, "MaxVisibleZoom", NULL); - _options.maxVisibleZoom = (s == "") ? opt->maxVisibleZoom : atoi(s.GetString()); + s = CPLGetXMLValue(node, "MaxVisibleZoom", nullptr); + _options.maxVisibleZoom = (s == "") ? opt->maxVisibleZoom : atoi(s.GetString()); - s = CPLGetXMLValue(node, "RotationExpression", nullptr); - SysFreeString(_options.rotationExpression); - _options.rotationExpression = A2BSTR(s); + s = CPLGetXMLValue(node, "RotationExpression", nullptr); + SysFreeString(_options.rotationExpression); + _options.rotationExpression = A2BSTR(s); // restoring picture CPLXMLNode* psChild = CPLGetXMLNode(node, "Picture"); if (psChild) { - IImage* img = NULL; - CoCreateInstance(CLSID_Image,NULL,CLSCTX_INPROC_SERVER,IID_IImage,(void**)&img); + IImage* img = nullptr; + CoCreateInstance(CLSID_Image, nullptr,CLSCTX_INPROC_SERVER,IID_IImage,(void**)&img); if (img) { ((CImageClass*)img)->DeserializeCore(psChild); @@ -1845,8 +1843,8 @@ bool CShapeDrawingOptions::DeserializeCore(CPLXMLNode* node) psChild = CPLGetXMLNode(node, "LinePatternClass"); if (psChild) { - ILinePattern* pattern = NULL; - CoCreateInstance(CLSID_LinePattern,NULL,CLSCTX_INPROC_SERVER,IID_ILinePattern,(void**)&pattern); + ILinePattern* pattern = nullptr; + CoCreateInstance(CLSID_LinePattern, nullptr,CLSCTX_INPROC_SERVER,IID_ILinePattern,(void**)&pattern); if (pattern) { ((CLinePattern*)pattern)->DeserializeCore(psChild); @@ -1860,7 +1858,7 @@ bool CShapeDrawingOptions::DeserializeCore(CPLXMLNode* node) { _options.linePattern->Clear(); _options.linePattern->Release(); - _options.linePattern = NULL; + _options.linePattern = nullptr; } } @@ -1899,14 +1897,14 @@ STDMETHODIMP CShapeDrawingOptions::Deserialize(BSTR newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_MinScale (double *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.minScale; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.minScale; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_MinScale (double newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - _options.minScale = newVal; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _options.minScale = newVal; return S_OK; } @@ -1915,14 +1913,14 @@ STDMETHODIMP CShapeDrawingOptions::put_MinScale (double newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_MaxScale (double *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.maxScale; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.maxScale; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_MaxScale (double newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - _options.maxScale = newVal; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _options.maxScale = newVal; return S_OK; } @@ -1931,14 +1929,14 @@ STDMETHODIMP CShapeDrawingOptions::put_MaxScale (double newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_MinLineWidth (double *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.minLineWidth; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.minLineWidth; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_MinLineWidth (double newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - _options.minLineWidth = newVal; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _options.minLineWidth = newVal; return S_OK; } @@ -1947,14 +1945,14 @@ STDMETHODIMP CShapeDrawingOptions::put_MinLineWidth (double newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_MaxLineWidth (double *pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *pVal = _options.maxLineWidth; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *pVal = _options.maxLineWidth; return S_OK; } STDMETHODIMP CShapeDrawingOptions::put_MaxLineWidth (double newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - _options.maxLineWidth = newVal; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _options.maxLineWidth = newVal; return S_OK; } @@ -1963,77 +1961,77 @@ STDMETHODIMP CShapeDrawingOptions::put_MaxLineWidth (double newVal) // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_DynamicVisibility(VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.dynamicVisibility ? VARIANT_TRUE : VARIANT_FALSE; return S_OK; -}; +} STDMETHODIMP CShapeDrawingOptions::put_DynamicVisibility(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _options.dynamicVisibility = newVal == VARIANT_TRUE; return S_OK; -}; +} // **************************************************************** // get_MinVisibleScale // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_MinVisibleScale(DOUBLE* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.minVisibleScale; return S_OK; -}; +} STDMETHODIMP CShapeDrawingOptions::put_MinVisibleScale(DOUBLE newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _options.minVisibleScale = newVal; return S_OK; -}; +} // **************************************************************** // get_MaxVisibleScale // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_MaxVisibleScale(DOUBLE* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.maxVisibleScale; return S_OK; -}; +} STDMETHODIMP CShapeDrawingOptions::put_MaxVisibleScale(DOUBLE newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _options.maxVisibleScale = newVal; return S_OK; -}; +} // **************************************************************** // get_MinVisibleScale // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_MinVisibleZoom(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.minVisibleZoom; return S_OK; -}; +} STDMETHODIMP CShapeDrawingOptions::put_MinVisibleZoom(LONG newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _options.minVisibleZoom = newVal; return S_OK; -}; +} // **************************************************************** // get_MaxVisibleScale // **************************************************************** STDMETHODIMP CShapeDrawingOptions::get_MaxVisibleZoom(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _options.maxVisibleZoom; return S_OK; -}; +} STDMETHODIMP CShapeDrawingOptions::put_MaxVisibleZoom(LONG newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _options.maxVisibleZoom = newVal; return S_OK; -}; \ No newline at end of file +} diff --git a/src/COM classes/ShapeNetwork.cpp b/src/COM classes/ShapeNetwork.cpp index fc657a49..6d9fd792 100644 --- a/src/COM classes/ShapeNetwork.cpp +++ b/src/COM classes/ShapeNetwork.cpp @@ -53,7 +53,7 @@ void dPRINT_DATA( ofstream & out, void * data ) } long CShapeNetwork::UpEnd( edge * e, dPOINT * downpoint, double tolerance ) -{ +{ if( dPOINT_EQUAL( e->one->data, (void *)downpoint, (void*)&tolerance ) ) return e->twoIndex; else @@ -61,7 +61,7 @@ long CShapeNetwork::UpEnd( edge * e, dPOINT * downpoint, double tolerance ) } long CShapeNetwork::DownEnd( edge * e, dPOINT * downpoint, double tolerance ) -{ +{ if( dPOINT_EQUAL( e->one->data, (void *)downpoint, (void*)&tolerance ) ) return e->oneIndex; else @@ -69,7 +69,7 @@ long CShapeNetwork::DownEnd( edge * e, dPOINT * downpoint, double tolerance ) } void CShapeNetwork::CopyShape( bool reversePoints, IShape * oldshape, IShape * newshape ) -{ +{ ShpfileType shptype; VARIANT_BOOL vbretval; oldshape->get_ShapeType(&shptype); @@ -79,36 +79,36 @@ void CShapeNetwork::CopyShape( bool reversePoints, IShape * oldshape, IShape * n long numPoints = 0; oldshape->get_NumPoints(&numPoints); - - IPoint * oldpnt = NULL; - IPoint * newpnt = NULL; + + IPoint * oldpnt = nullptr; + IPoint * newpnt = nullptr; double x, y, z; long pos = 0; VARIANT_BOOL retval = FALSE; for( int i = 0; i < numPoints; i++ ) - { + { pos = i; oldshape->get_Point(pos,&oldpnt); oldpnt->get_X(&x); oldpnt->get_Y(&y); oldpnt->get_Z(&z); oldpnt->Release(); - oldpnt = NULL; + oldpnt = nullptr; - CoCreateInstance(CLSID_Point,NULL,CLSCTX_INPROC_SERVER,IID_IPoint,(void**)&newpnt); + CoCreateInstance(CLSID_Point, nullptr,CLSCTX_INPROC_SERVER,IID_IPoint,(void**)&newpnt); newpnt->put_X(x); newpnt->put_Y(y); newpnt->put_Z(z); if( reversePoints == true ) pos = 0; - newshape->InsertPoint(newpnt,&pos,&retval); - newpnt->Release(); - newpnt = NULL; + newshape->InsertPoint(newpnt,&pos,&retval); + newpnt->Release(); + newpnt = nullptr; } } void CShapeNetwork::CopyField( IField * oldfield, IField * newfield ) -{ +{ CComBSTR name; long precision = 0,width = 0; FieldType ftype; @@ -123,7 +123,8 @@ void CShapeNetwork::CopyField( IField * oldfield, IField * newfield ) } void CShapeNetwork::recPrintShpNetwork(shpNetNode * allnodes, long index, ofstream & out) -{ out<Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -161,9 +162,9 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F if( shpfiletype != SHP_POLYLINE && shpfiletype != SHP_POLYLINEZ && shpfiletype != SHP_POLYLINEM ) { *retval = 0; _lastErrorCode = tkINCOMPATIBLE_SHAPEFILE_TYPE; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -175,42 +176,42 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F if( ShapeIndex < 0 || ShapeIndex >= numShapes ) { *retval = 0; _lastErrorCode = tkINDEX_OUT_OF_BOUNDS; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } //Verify the PointIndex - IShape * outshp = NULL; + IShape * outshp = nullptr; long numPoints = 0; Shapefile->get_Shape(ShapeIndex,&outshp); outshp->get_ShapeType(&shpfiletype); outshp->get_NumPoints(&numPoints); outshp->Release(); - outshp = NULL; + outshp = nullptr; if( shpfiletype != SHP_POLYLINE && shpfiletype != SHP_POLYLINEZ && shpfiletype != SHP_POLYLINEM ) { *retval = 0; _lastErrorCode = tkINCOMPATIBLE_SHAPE_TYPE; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } if( FinalPointIndex != 0 && FinalPointIndex != numPoints - 1 ) { *retval = 0; _lastErrorCode = tkINVALID_FINAL_POINT_INDEX; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } - graph undir_graph; + graph undir_graph; long percent = 0, newpercent = 0; double total = numShapes; @@ -220,12 +221,13 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F double x1, y1, x2, y2; //Build the Undirected Graph for( int i = 0; i < numShapes; i++ ) - { IShape * shape = NULL; + { IShape * shape = nullptr; Shapefile->get_Shape(i,&shape); shape->get_ShapeType(&shpfiletype); if( shpfiletype == SHP_POLYLINE || shpfiletype == SHP_POLYLINEZ || shpfiletype == SHP_POLYLINEM ) - { IPoint * pnt1 = NULL, * pnt2 = NULL; + { + IPoint * pnt1 = nullptr, * pnt2 = nullptr; shape->get_NumPoints(&numPoints); shape->get_Point(0,&pnt1); @@ -252,9 +254,9 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F if( distance > Tolerance ) { graphnode * gnOne = new graphnode(); - graphnode * gnTwo = new graphnode(); - gnOne->data = (void*)p1; - gnTwo->data = (void*)p2; + graphnode * gnTwo = new graphnode(); + gnOne->data = static_cast(p1); + gnTwo->data = static_cast(p2); edge * newEdge = new edge(); newEdge->one = gnOne; @@ -263,22 +265,22 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F undir_graph.Insert(newEdge,(void*)&Tolerance,dPOINT_EQUAL); } else - { + { //Add the shape as a blank to the graph undir_graph.InsertBlank(); //Verify that this isn't the outlet shape if( i == ShapeIndex ) - { + { shape->Release(); - shape = NULL; - *retval = 0; + shape = nullptr; + *retval = 0; _lastErrorCode = tkTOLERANCE_TOO_LARGE; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - return S_OK; + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + return S_OK; } } } @@ -287,13 +289,13 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F //Verify that this isn't the outlet shape if( i == ShapeIndex ) { shape->Release(); - shape = NULL; - *retval = 0; + shape = nullptr; + *retval = 0; _lastErrorCode = tkINCOMPATIBLE_SHAPE_TYPE; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } else @@ -301,7 +303,7 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F } shape->Release(); - shape = NULL; + shape = nullptr; CallbackHelper::Progress(callback, i, total, "Building ShapeNetwork", _key, percent); } @@ -312,69 +314,69 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F double length = 0; double fx, fy; dPOINT dpnt; - IShape * shape = NULL; - IPoint * pnt = NULL; - IUtils * gen = NULL; + IShape * shape = nullptr; + IPoint * pnt = nullptr; + IUtils * gen = nullptr; - CoCreateInstance(CLSID_Utils,NULL,CLSCTX_INPROC_SERVER,IID_IUtils,(void**)&gen); + CoCreateInstance(CLSID_Utils,NULL,CLSCTX_INPROC_SERVER,IID_IUtils,(void**)&gen); for( int ls = 0; ls < numShapes; ls++ ) - { if( undir_graph.edges[ls] != NULL ) - { Shapefile->get_Shape(ls,&shape); + { if( undir_graph.edges[ls] != nullptr) + { Shapefile->get_Shape(ls,&shape); gen->get_Length(shape,&length); if( length <= Tolerance ) { gen->Release(); - gen = NULL; + gen = nullptr; shape->Release(); - shape = NULL; - - *retval = 0; + shape = nullptr; + + *retval = 0; _lastErrorCode = tkTOLERANCE_TOO_LARGE; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } undir_graph.edges[ls]->length = length; if( ShapeIndex == ls ) - { shape->get_Point(FinalPointIndex,&pnt); + { shape->get_Point(FinalPointIndex,&pnt); pnt->get_X(&fx); pnt->get_Y(&fy); dpnt.x = fx; - dpnt.y = fy; + dpnt.y = fy; pnt->Release(); - pnt = NULL; + pnt = nullptr; } shape->Release(); - shape = NULL; - } + shape = nullptr; + } } gen->Release(); - gen = NULL; + gen = nullptr; - //convert the undirected graph into a directed acyclic graph + //convert the undirected graph into a directed acyclic graph shpNetNode * edgeNetwork = new shpNetNode[numShapes]; //Find the up end of the outlet long up = UpEnd( undir_graph.edges[ShapeIndex], &dpnt, Tolerance ); - long down = DownEnd( undir_graph.edges[ShapeIndex], &dpnt, Tolerance ); + long down = DownEnd( undir_graph.edges[ShapeIndex], &dpnt, Tolerance ); edgeNetwork[ShapeIndex].downIndex = down; edgeNetwork[ShapeIndex].upIndex = up; edgeNetwork[ShapeIndex].distanceToOutlet = 0; std::deque tmp_ambigShapeIndex; - + heap minheap; heapnode hn; long parentIndex; double distance = 0; - + minheap.insert(ShapeIndex,0); - while( minheap.size() > 0 ) - { + while( minheap.size() > 0 ) + { hn = minheap.top(); minheap.pop(); parentIndex = hn.index; @@ -385,7 +387,7 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F _networkSize++; edgeNetwork[parentIndex].used = true; - edgeNetwork[parentIndex].length = e->length; + edgeNetwork[parentIndex].length = e->length; //Set up the parent if( edgeNetwork[parentIndex].pbIndex.size() > 0 ) @@ -395,20 +397,20 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F if( parentparent >= 0 ) edgeNetwork[parentparent].up.push_back(parentIndex); - + //Mark an ambiguous path if( edgeNetwork[parentIndex].pbIndex.size() > 1 ) - tmp_ambigShapeIndex.push_back(parentIndex); + tmp_ambigShapeIndex.push_back(parentIndex); } up = edgeNetwork[parentIndex].upIndex; - down = edgeNetwork[parentIndex].downIndex; - - distance = edgeNetwork[parentIndex].distanceToOutlet + e->length; + down = edgeNetwork[parentIndex].downIndex; + + distance = edgeNetwork[parentIndex].distanceToOutlet + e->length; graphnode * gn = undir_graph.graphnodes[up]; - for( int i = 0; i < (int)gn->edges.size(); i++ ) - { + for( int i = 0; i < static_cast(gn->edges.size()); i++ ) + { long childIndex = gn->edges[i]; if( edgeNetwork[childIndex].used == false ) @@ -428,62 +430,62 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F } //Ambiguous Path else if( distance == edgeNetwork[gn->edges[i]].distanceToOutlet ) - edgeNetwork[childIndex].pbIndex.push_back(parentIndex); + edgeNetwork[childIndex].pbIndex.push_back(parentIndex); } } } } - + //PrintShpNetwork(edgeNetwork,ShapeIndex,"Network.txt"); //copy the network into a new shapefile - if( _network != NULL ) + if( _network != nullptr) delete [] _network; _network = new shpNetNode[_networkSize]; long * shapeMap = new long[numShapes]; long shapepos = 0; VARIANT_BOOL vbretval = FALSE; - IShape * newshape = NULL; - IShape * oldshape = NULL; + IShape * newshape = nullptr; + IShape * oldshape = nullptr; //_unlink("d:\\data\\netfile.shp"); //_unlink("d:\\data\\netfile.shx"); //_unlink("d:\\data\\netfile.dbf"); - if( _netshpfile != NULL ) + if( _netshpfile != nullptr) _netshpfile->Release(); - _netshpfile = NULL; + _netshpfile = nullptr; //Create the shapefile - CoCreateInstance(CLSID_Shapefile,NULL,CLSCTX_INPROC_SERVER,IID_IShapefile,(void**)&_netshpfile); + CoCreateInstance(CLSID_Shapefile, nullptr,CLSCTX_INPROC_SERVER,IID_IShapefile,(void**)&_netshpfile); Shapefile->get_ShapefileType(&shpfiletype); _netshpfile->CreateNew(m_globalSettings.emptyBstr,shpfiletype,&vbretval); //Copy all of the Fields long numFields = 0; Shapefile->get_NumFields(&numFields); - IField * newfield = NULL; - IField * oldfield = NULL; + IField * newfield = nullptr; + IField * oldfield = nullptr; long fieldpos =0; int f = 0; for( f = 0; f < numFields; f++ ) - { CoCreateInstance(CLSID_Field,NULL,CLSCTX_INPROC_SERVER,IID_IField,(void**)&newfield); + { CoCreateInstance(CLSID_Field, nullptr,CLSCTX_INPROC_SERVER,IID_IField,(void**)&newfield); Shapefile->get_Field(f,&oldfield); CopyField(oldfield,newfield); fieldpos = f; _netshpfile->EditInsertField(newfield,&fieldpos,cBack,&vbretval); oldfield->Release(); - oldfield = NULL; + oldfield = nullptr; newfield->Release(); - newfield = NULL; + newfield = nullptr; } //Create two new fields - IField * id = NULL; - IField * did = NULL; - CoCreateInstance(CLSID_Field,NULL,CLSCTX_INPROC_SERVER,IID_IField,(void**)&id); - CoCreateInstance(CLSID_Field,NULL,CLSCTX_INPROC_SERVER,IID_IField,(void**)&did); - + IField * id = nullptr; + IField * did = nullptr; + CoCreateInstance(CLSID_Field, nullptr,CLSCTX_INPROC_SERVER,IID_IField,(void**)&id); + CoCreateInstance(CLSID_Field, nullptr,CLSCTX_INPROC_SERVER,IID_IField,(void**)&did); + CComBSTR bstrNetId("NET_ID"); id->put_Name(bstrNetId); id->put_Precision(0); @@ -500,22 +502,22 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F _netshpfile->EditInsertField(did,&fieldpos,cBack,&vbretval); _netshpfile->EditInsertField(id,&fieldpos,cBack,&vbretval); id->Release(); - id = NULL; + id = nullptr; did->Release(); - did = NULL; + did = nullptr; //Create the outlet shape ComHelper::CreateShape(&newshape); - Shapefile->get_Shape(ShapeIndex,&oldshape); + Shapefile->get_Shape(ShapeIndex,&oldshape); dPOINT zeroPnt; - IPoint * izpnt = NULL; + IPoint * izpnt = nullptr; oldshape->get_Point(0,&izpnt); double izx,izy; izpnt->get_X(&izx); izpnt->get_Y(&izy); izpnt->Release(); - izpnt = NULL; + izpnt = nullptr; zeroPnt.x = izx; zeroPnt.y = izy; @@ -528,9 +530,9 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F CopyShape(reversePoints,oldshape,newshape); _netshpfile->EditInsertShape(newshape,&shapepos,&vbretval); oldshape->Release(); - oldshape = NULL; + oldshape = nullptr; newshape->Release(); - newshape = NULL; + newshape = nullptr; VARIANT cID,cDID; VariantInit(&cID); @@ -543,7 +545,6 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F _netshpfile->EditCellValue(0,shapepos,cID,&vbretval); _netshpfile->EditCellValue(1,shapepos,cDID,&vbretval); - VARIANT cVal; VariantInit(&cVal); for( f = 0; f < numFields; f++ ) @@ -551,53 +552,53 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F //Adjust for the two new fields _netshpfile->EditCellValue(f + 2,shapepos,cVal,&vbretval); } - - shapeMap[ShapeIndex] = shapepos; + + shapeMap[ShapeIndex] = shapepos; _network[shapepos].distanceToOutlet = 0; _network[shapepos].parentIndex = -1; _network[shapepos].length = edgeNetwork[ShapeIndex].length; - + std::deque netPath; netPath.push_back(ShapeIndex); - + percent = 0, newpercent = 0; total = _networkSize; - + //add all other shapes by simulating a recursive search long shpcnt = 1; long insertedShapes = 1; while( netPath.size() > 0 ) - { + { long parent = netPath[0]; netPath.pop_front(); - + shpcnt++; - - for( int i = 0; i < (int)edgeNetwork[parent].up.size(); i++ ) + + for( int i = 0; i < static_cast(edgeNetwork[parent].up.size()); i++ ) { shapepos = insertedShapes; long childIndex = edgeNetwork[parent].up[i]; - netPath.push_back(childIndex); + netPath.push_back(childIndex); ComHelper::CreateShape(&newshape); - Shapefile->get_Shape(childIndex,&oldshape); - + Shapefile->get_Shape(childIndex,&oldshape); + oldshape->get_Point(0,&izpnt); izpnt->get_X(&izx); izpnt->get_Y(&izy); izpnt->Release(); - izpnt = NULL; + izpnt = nullptr; zeroPnt.x = izx; zeroPnt.y = izy; - IShape * parentShape = NULL; + IShape * parentShape = nullptr; Shapefile->get_Shape(parent,&parentShape); long pnumPts = 0; - parentShape->get_NumPoints(&pnumPts); - IPoint * parentPnt1 = NULL; - IPoint * parentPnt2 = NULL; + parentShape->get_NumPoints(&pnumPts); + IPoint * parentPnt1 = nullptr; + IPoint * parentPnt2 = nullptr; parentShape->get_Point(0,&parentPnt1); parentShape->get_Point(pnumPts-1,&parentPnt2); double pp1x, pp1y, pp2x, pp2y; @@ -606,11 +607,11 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F parentPnt2->get_X(&pp2x); parentPnt2->get_Y(&pp2y); parentPnt1->Release(); - parentPnt1 = NULL; + parentPnt1 = nullptr; parentPnt2->Release(); - parentPnt2 = NULL; + parentPnt2 = nullptr; parentShape->Release(); - parentShape = NULL; + parentShape = nullptr; dPOINT dpp1; dpp1.x = pp1x; @@ -625,12 +626,12 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F else reversePoints = true; - CopyShape(reversePoints,oldshape,newshape); + CopyShape(reversePoints,oldshape,newshape); _netshpfile->EditInsertShape(newshape,&shapepos,&vbretval); oldshape->Release(); - oldshape = NULL; + oldshape = nullptr; newshape->Release(); - newshape = NULL; + newshape = nullptr; cID.lVal = shapepos; cDID.lVal = shapeMap[parent]; @@ -643,7 +644,7 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F _netshpfile->EditCellValue(f + 2,shapepos,cVal,&vbretval); } - distance = edgeNetwork[parent].distanceToOutlet + undir_graph.edges[parent]->length; + distance = edgeNetwork[parent].distanceToOutlet + undir_graph.edges[parent]->length; shapeMap[childIndex] = shapepos; _network[shapeMap[parent]].up.push_back(shapepos); @@ -651,7 +652,7 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F _network[shapepos].parentIndex = shapeMap[parent]; _network[shapepos].length = edgeNetwork[childIndex].length; - insertedShapes++; + insertedShapes++; } CallbackHelper::Progress(callback, shpcnt, total, "ShpNetwork::Copying Shapefile", _key, percent); @@ -660,17 +661,17 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F //ShapeMap the Ambiguous Shapes _ambigShapeIndex.clear(); - for( int ti = 0; ti < (int)tmp_ambigShapeIndex.size(); ti++ ) + for( int ti = 0; ti < static_cast(tmp_ambigShapeIndex.size()); ti++ ) { long shpindex = tmp_ambigShapeIndex[ti]; _ambigShapeIndex.push_back(shapeMap[shpindex]); } - + delete [] shapeMap; delete [] edgeNetwork; _netshpfile->AddRef(); - *retval = _ambigShapeIndex.size() + 1; //ARA 02/03/06 Possible to have size() of 0 so needed to be incremented by 1 so it wasn't returning error code - + *retval = static_cast(_ambigShapeIndex.size()) + 1; //ARA 02/03/06 Possible to have size() of 0 so needed to be incremented by 1 so it wasn't returning error code + VariantClear(&cID); VariantClear(&cDID); VariantClear(&cVal); @@ -681,33 +682,33 @@ STDMETHODIMP CShapeNetwork::Build(IShapefile *Shapefile, long ShapeIndex, long F STDMETHODIMP CShapeNetwork::DeleteShape(long ShapeIndex, VARIANT_BOOL *retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - + if( IsAligned() == false ) { *retval = FALSE; _lastErrorCode = tkNOT_ALIGNED; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } if( ShapeIndex >= 0 && ShapeIndex < _networkSize ) - { + { VARIANT_BOOL vbretval = FALSE; //Verify that the shapefile and dbf are in editing mode _netshpfile->get_EditingShapes(&vbretval); if( vbretval == FALSE ) { *retval = FALSE; _lastErrorCode = tkSHPFILE_NOT_IN_EDIT_MODE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } _netshpfile->get_EditingTable(&vbretval); if( vbretval == FALSE ) { *retval = FALSE; _lastErrorCode = tkDBF_NOT_IN_EDIT_MODE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -720,14 +721,14 @@ STDMETHODIMP CShapeNetwork::DeleteShape(long ShapeIndex, VARIANT_BOOL *retval) netPath.push_back(ShapeIndex); long localNetSize = 0; while( netPath.size() > 0 ) - { + { long parent = netPath[0]; netPath.pop_front(); localNetSize++; _network[parent].used = true; - for( int i = 0; i < (int)_network[parent].up.size(); i++ ) + for( int i = 0; i < static_cast(_network[parent].up.size()); i++ ) { long index = _network[parent].up[i]; netPath.push_back(index); } @@ -747,41 +748,41 @@ STDMETHODIMP CShapeNetwork::DeleteShape(long ShapeIndex, VARIANT_BOOL *retval) int m = 0; for( m = 0; m < _networkSize; m++ ) { if( _network[m].used == true ) - { _netshpfile->EditDeleteShape(m - delcnt,&vbretval); - ++delcnt; + { _netshpfile->EditDeleteShape(m - delcnt,&vbretval); + ++delcnt; for( int k = m + 1; k < _networkSize; k++ ) - shifts[k]++; - } + shifts[k]++; + } } - //Change any indexes in the old network + //Change any indexes in the old network for( m = 0; m < _networkSize; m++ ) { long parentIndex = _network[m].parentIndex; if( parentIndex >= 0 ) _network[m].parentIndex -= shifts[parentIndex]; int kp = 0; - for( kp = 0; kp < (int)_network[m].up.size(); kp++ ) + for( kp = 0; kp < static_cast(_network[m].up.size()); kp++ ) { long childIndex = _network[m].up[kp]; if( _network[childIndex].used == true ) - _network[m].up.erase( _network[m].up.begin() + kp ); + _network[m].up.erase( _network[m].up.begin() + kp ); } - for( kp = 0; kp < (int)_network[m].up.size(); kp++ ) + for( kp = 0; kp < static_cast(_network[m].up.size()); kp++ ) _network[m].up[kp] -= shifts[_network[m].up[kp]]; } - + delete [] shifts; - shifts = NULL; + shifts = nullptr; - shpNetNode * newNetwork = new shpNetNode[_networkSize - localNetSize]; + shpNetNode * newNetwork = new shpNetNode[_networkSize - localNetSize]; long indcnt = 0; for( m = 0; m < _networkSize; m++ ) - { if( _network[m].used == false ) + { if( _network[m].used == false ) newNetwork[indcnt++] = _network[m]; } - + delete [] _network; _network = newNetwork; _networkSize = _networkSize - localNetSize; @@ -797,21 +798,20 @@ STDMETHODIMP CShapeNetwork::DeleteShape(long ShapeIndex, VARIANT_BOOL *retval) cDID.lVal = _network[fn].parentIndex; _netshpfile->EditCellValue(0,fn,cID,&vbretval); _netshpfile->EditCellValue(1,fn,cDID,&vbretval); - } - + } + VariantClear(&cID); VariantClear(&cDID); - + *retval = TRUE; } else { *retval = FALSE; _lastErrorCode = tkINDEX_OUT_OF_BOUNDS; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - return S_OK; + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + return S_OK; } - return S_OK; } @@ -823,13 +823,13 @@ STDMETHODIMP CShapeNetwork::MoveUp(long UpIndex, VARIANT_BOOL *retval) if( IsAligned() == false ) { *retval = FALSE; _lastErrorCode = tkNOT_ALIGNED; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } if( _currentNode >= 0 ) - { long numUps = _network[_currentNode].up.size(); + { long numUps = static_cast(_network[_currentNode].up.size()); if( UpIndex >= 0 && UpIndex < numUps ) { _currentNode = _network[_currentNode].up[UpIndex]; *retval = TRUE; @@ -837,18 +837,18 @@ STDMETHODIMP CShapeNetwork::MoveUp(long UpIndex, VARIANT_BOOL *retval) else { *retval = FALSE; _lastErrorCode = tkINDEX_OUT_OF_BOUNDS; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } } else { *retval = FALSE; _lastErrorCode = tkINVALID_NODE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; - } + } return S_OK; } @@ -856,17 +856,17 @@ STDMETHODIMP CShapeNetwork::MoveUp(long UpIndex, VARIANT_BOOL *retval) STDMETHODIMP CShapeNetwork::MoveDown(VARIANT_BOOL *retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - + if( IsAligned() == false ) { *retval = FALSE; _lastErrorCode = tkNOT_ALIGNED; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } if( _currentNode >= 0 ) - { + { if( _network[_currentNode].parentIndex >= 0 ) { _currentNode = _network[_currentNode].parentIndex; *retval = TRUE; @@ -874,18 +874,18 @@ STDMETHODIMP CShapeNetwork::MoveDown(VARIANT_BOOL *retval) else { *retval = FALSE; _lastErrorCode = tkNODE_AT_OUTLET; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } } else { *retval = FALSE; _lastErrorCode = tkINVALID_NODE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; - } + } return S_OK; } @@ -897,8 +897,8 @@ STDMETHODIMP CShapeNetwork::MoveTo(long ShapeIndex, VARIANT_BOOL *retval) if( IsAligned() == false ) { *retval = FALSE; _lastErrorCode = tkNOT_ALIGNED; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -909,8 +909,8 @@ STDMETHODIMP CShapeNetwork::MoveTo(long ShapeIndex, VARIANT_BOOL *retval) else { *retval = FALSE; _lastErrorCode = tkINDEX_OUT_OF_BOUNDS; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -920,12 +920,12 @@ STDMETHODIMP CShapeNetwork::MoveTo(long ShapeIndex, VARIANT_BOOL *retval) STDMETHODIMP CShapeNetwork::MoveToOutlet(VARIANT_BOOL *retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - + if( IsAligned() == false ) { *retval = FALSE; _lastErrorCode = tkNOT_ALIGNED; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -936,8 +936,8 @@ STDMETHODIMP CShapeNetwork::MoveToOutlet(VARIANT_BOOL *retval) else { *retval = FALSE; _lastErrorCode = tkINVALID_NODE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -949,48 +949,48 @@ STDMETHODIMP CShapeNetwork::get_Shapefile(IShapefile **pVal) AFX_MANAGE_STATE(AfxGetStaticModuleState()) if( IsAligned() == false ) - { *pVal = NULL; + { *pVal = nullptr; _lastErrorCode = tkNOT_ALIGNED; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } - if( _netshpfile != NULL ) + if( _netshpfile != nullptr) _netshpfile->AddRef(); - *pVal = _netshpfile; + *pVal = _netshpfile; return S_OK; } STDMETHODIMP CShapeNetwork::get_CurrentShape(IShape **pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - + if( IsAligned() == false ) - { *pVal = NULL; + { *pVal = nullptr; _lastErrorCode = tkNOT_ALIGNED; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } if( _currentNode >= 0 ) - { if( _netshpfile != NULL ) + { if( _netshpfile != nullptr) _netshpfile->get_Shape(_currentNode,pVal); else - { *pVal = NULL; + { *pVal = nullptr; _lastErrorCode = tkNO_NETWORK; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } } else - { *pVal = NULL; + { *pVal = nullptr; _lastErrorCode = tkINVALID_NODE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -1004,8 +1004,8 @@ STDMETHODIMP CShapeNetwork::get_CurrentShapeIndex(long *pVal) if( IsAligned() == false ) { *pVal = -1; _lastErrorCode = tkNOT_ALIGNED; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -1014,8 +1014,8 @@ STDMETHODIMP CShapeNetwork::get_CurrentShapeIndex(long *pVal) else { *pVal = -1; _lastErrorCode = tkINVALID_NODE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -1025,19 +1025,19 @@ STDMETHODIMP CShapeNetwork::get_CurrentShapeIndex(long *pVal) STDMETHODIMP CShapeNetwork::get_DistanceToOutlet(long PointIndex, double *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - + if( IsAligned() == false ) { *pVal = 0.0; _lastErrorCode = tkNOT_ALIGNED; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } if( _currentNode >= 0 ) { double distance = 0; - - IShape * shp = NULL; + + IShape * shp = nullptr; _netshpfile->get_Shape(_currentNode,&shp); long numPoints = 0; shp->get_NumPoints(&numPoints); @@ -1045,13 +1045,13 @@ STDMETHODIMP CShapeNetwork::get_DistanceToOutlet(long PointIndex, double *pVal) if( PointIndex < 0 || PointIndex >= numPoints ) { *pVal = 0; _lastErrorCode = tkINDEX_OUT_OF_BOUNDS; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } else - { distance = _network[_currentNode].distanceToOutlet; - IPoint * pnt = NULL; + { distance = _network[_currentNode].distanceToOutlet; + IPoint * pnt = nullptr; double x1, y1, z1; double x2, y2, z2; @@ -1060,7 +1060,7 @@ STDMETHODIMP CShapeNetwork::get_DistanceToOutlet(long PointIndex, double *pVal) pnt->get_Y(&y1); pnt->get_Z(&z1); pnt->Release(); - pnt = NULL; + pnt = nullptr; for( int i = 1; i < PointIndex; i++ ) { @@ -1069,7 +1069,7 @@ STDMETHODIMP CShapeNetwork::get_DistanceToOutlet(long PointIndex, double *pVal) pnt->get_Y(&y2); pnt->get_Z(&z2); pnt->Release(); - pnt = NULL; + pnt = nullptr; distance += sqrt( pow( x2 - x1, 2 ) + pow( y2 - y1, 2 ) + pow( z2 - z1, 2 ) ); @@ -1080,15 +1080,15 @@ STDMETHODIMP CShapeNetwork::get_DistanceToOutlet(long PointIndex, double *pVal) } shp->Release(); - shp = NULL; + shp = nullptr; *pVal = distance; } else { *pVal = 0.0; _lastErrorCode = tkINVALID_NODE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -1102,20 +1102,20 @@ STDMETHODIMP CShapeNetwork::get_NumDirectUps(long *pVal) if( IsAligned() == false ) { *pVal = 0; _lastErrorCode = tkNOT_ALIGNED; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } if( _currentNode >= 0 ) - *pVal = _network[_currentNode].up.size(); + *pVal = static_cast(_network[_currentNode].up.size()); else { *pVal = 0; _lastErrorCode = tkINVALID_NODE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; - } + } return S_OK; } @@ -1123,12 +1123,12 @@ STDMETHODIMP CShapeNetwork::get_NumDirectUps(long *pVal) STDMETHODIMP CShapeNetwork::get_NetworkSize(long *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - + if( IsAligned() == false ) { *pVal = 0; _lastErrorCode = tkNOT_ALIGNED; if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -1144,7 +1144,7 @@ STDMETHODIMP CShapeNetwork::get_NetworkSize(long *pVal) netPath.pop_front(); localNetSize++; - for( int i = 0; i < (int)_network[parent].up.size(); i++ ) + for( int i = 0; i < static_cast(_network[parent].up.size()); i++ ) { long index = _network[parent].up[i]; netPath.push_back(index); } @@ -1154,8 +1154,8 @@ STDMETHODIMP CShapeNetwork::get_NetworkSize(long *pVal) else { *pVal = 0; _lastErrorCode = tkINVALID_NODE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -1165,22 +1165,22 @@ STDMETHODIMP CShapeNetwork::get_NetworkSize(long *pVal) STDMETHODIMP CShapeNetwork::get_AmbigShapeIndex(long Index, long * pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - + if( IsAligned() == false ) { *pVal = -1; _lastErrorCode = tkNOT_ALIGNED; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } - if (Index >= 0 && Index < (long)_ambigShapeIndex.size()) + if (Index >= 0 && Index < static_cast(_ambigShapeIndex.size())) *pVal = _ambigShapeIndex[Index]; else { *pVal = -1; _lastErrorCode = tkINDEX_OUT_OF_BOUNDS; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -1190,17 +1190,17 @@ STDMETHODIMP CShapeNetwork::get_AmbigShapeIndex(long Index, long * pVal) STDMETHODIMP CShapeNetwork::get_LastErrorCode(long *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - + *pVal = _lastErrorCode; _lastErrorCode = tkNO_ERROR; - + return S_OK; } STDMETHODIMP CShapeNetwork::get_ErrorMsg(long ErrorCode, BSTR *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - + *pVal = A2BSTR(ErrorMsg(ErrorCode)); return S_OK; @@ -1209,10 +1209,10 @@ STDMETHODIMP CShapeNetwork::get_ErrorMsg(long ErrorCode, BSTR *pVal) STDMETHODIMP CShapeNetwork::get_GlobalCallback(ICallback **pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - + *pVal = _globalCallback; - if( _globalCallback != NULL ) - { + if( _globalCallback != nullptr) + { _globalCallback->AddRef(); } return S_OK; @@ -1255,8 +1255,8 @@ STDMETHODIMP CShapeNetwork::get_ParentIndex(long *pVal) if( IsAligned() == false ) { *pVal = -2; _lastErrorCode = tkNOT_ALIGNED; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -1265,8 +1265,8 @@ STDMETHODIMP CShapeNetwork::get_ParentIndex(long *pVal) else { *pVal = -2; _lastErrorCode = tkINVALID_NODE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -1275,19 +1275,19 @@ STDMETHODIMP CShapeNetwork::get_ParentIndex(long *pVal) STDMETHODIMP CShapeNetwork::put_ParentIndex(long newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if( IsAligned() == false ) { _lastErrorCode = tkNOT_ALIGNED; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } if( _currentNode == 0 ) { _lastErrorCode = tkCANT_CHANGE_OUTLET_PARENT; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } else if(_currentNode > 0 ) @@ -1298,46 +1298,46 @@ STDMETHODIMP CShapeNetwork::put_ParentIndex(long newVal) { if( snn.parentIndex == _currentNode ) { //There would create a loop _lastErrorCode = tkNET_LOOP; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } } //Possibly flip the shape so that Point0 is down - IShape * parentShape = NULL; + IShape * parentShape = nullptr; _netshpfile->get_Shape(newVal,&parentShape); long numPoints = 0; parentShape->get_NumPoints(&numPoints); if( numPoints < 2 ) { _lastErrorCode = tkINVALID_SHP_FILE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } - - IPoint * ppnt = NULL; + + IPoint * ppnt = nullptr; parentShape->get_Point(numPoints-1,&ppnt); double ppx, ppy; ppnt->get_X(&ppx); ppnt->get_Y(&ppy); ppnt->Release(); - ppnt = NULL; + ppnt = nullptr; parentShape->Release(); - parentShape = NULL; + parentShape = nullptr; - IShape * shp = NULL; + IShape * shp = nullptr; _netshpfile->get_Shape(_currentNode,&shp); shp->get_NumPoints(&numPoints); if( numPoints < 2 ) { _lastErrorCode = tkINVALID_SHP_FILE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } - IPoint * pnt1 = NULL, * pnt2 = NULL; + IPoint * pnt1 = nullptr, * pnt2 = nullptr; shp->get_Point(0,&pnt1); shp->get_Point(numPoints-1,&pnt2); double px1, px2, py1, py2; @@ -1346,11 +1346,11 @@ STDMETHODIMP CShapeNetwork::put_ParentIndex(long newVal) pnt2->get_X(&px2); pnt2->get_Y(&py2); shp->Release(); - shp = NULL; + shp = nullptr; pnt1->Release(); - pnt1 = NULL; + pnt1 = nullptr; pnt2->Release(); - pnt2 = NULL; + pnt2 = nullptr; double distance1 = sqrt( fabs( pow( px1 - ppx, 2 ) + pow( py1 - ppy, 2 ) ) ); double distance2 = sqrt( fabs( pow( px2 - ppx, 2 ) + pow( py2 - ppy, 2 ) ) ); @@ -1359,24 +1359,24 @@ STDMETHODIMP CShapeNetwork::put_ParentIndex(long newVal) _netshpfile->get_EditingShapes(&retval); if( retval == FALSE ) { _lastErrorCode = tkSHPFILE_NOT_IN_EDIT_MODE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } _netshpfile->get_EditingTable(&retval); if( retval == FALSE ) { _lastErrorCode = tkDBF_NOT_IN_EDIT_MODE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } //Reverse the points if( distance2 < distance1 ) { _netshpfile->get_Shape(_currentNode,&shp); - shp->get_NumPoints(&numPoints); - IPoint * pnt = NULL; + shp->get_NumPoints(&numPoints); + IPoint * pnt = nullptr; long pntcnt = numPoints; int i = 0; for( i = numPoints - 1; i >= 0; i-- ) @@ -1384,7 +1384,7 @@ STDMETHODIMP CShapeNetwork::put_ParentIndex(long newVal) long tmppntcnt = pntcnt; shp->InsertPoint(pnt,&tmppntcnt,&retval); pnt->Release(); - pnt = NULL; + pnt = nullptr; pntcnt++; } for( i = 0; i < numPoints; i++ ) @@ -1404,7 +1404,7 @@ STDMETHODIMP CShapeNetwork::put_ParentIndex(long newVal) _network[newVal].up.push_back(_currentNode); //Push all of the nodes up's onto the parent - for( int i = 0; i < (int)_network[_currentNode].up.size(); i++ ) + for( int i = 0; i < static_cast(_network[_currentNode].up.size()); i++ ) { long childIndex = _network[_currentNode].up[i]; _netshpfile->EditCellValue(1,childIndex,vnv,&retval); @@ -1417,23 +1417,23 @@ STDMETHODIMP CShapeNetwork::put_ParentIndex(long newVal) else { if( newVal == _currentNode ) { _lastErrorCode = tkNET_LOOP; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } else { _lastErrorCode = tkINDEX_OUT_OF_BOUNDS; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } } } else { _lastErrorCode = tkINVALID_NODE; - if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - return S_OK; + if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + return S_OK; } return S_OK; @@ -1445,13 +1445,13 @@ STDMETHODIMP CShapeNetwork::Open(IShapefile *sf, ICallback *cBack, VARIANT_BOOL ICallback* callback = cBack ? cBack : _globalCallback; - if( sf == NULL ) + if( sf == nullptr) { *retval = FALSE; _lastErrorCode = tkUNEXPECTED_NULL_PARAMETER; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -1461,10 +1461,10 @@ STDMETHODIMP CShapeNetwork::Open(IShapefile *sf, ICallback *cBack, VARIANT_BOOL if( numShapes <= 0 ) { *retval = FALSE; _lastErrorCode = tkINVALID_SHP_FILE; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } @@ -1474,39 +1474,39 @@ STDMETHODIMP CShapeNetwork::Open(IShapefile *sf, ICallback *cBack, VARIANT_BOOL if( numFields < 2 ) { *retval = FALSE; _lastErrorCode = tkMISSING_FIELD; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; - } + } FieldType foneType; FieldType ftwoType; - IField * fone = NULL; - IField * ftwo = NULL; + IField * fone = nullptr; + IField * ftwo = nullptr; sf->get_Field(0,&fone); sf->get_Field(1,&ftwo); fone->get_Type(&foneType); ftwo->get_Type(&ftwoType); fone->Release(); ftwo->Release(); - fone = NULL; - ftwo = NULL; + fone = nullptr; + ftwo = nullptr; if( foneType != INTEGER_FIELD || ftwoType != INTEGER_FIELD ) { *retval = FALSE; _lastErrorCode = tkINVALID_FIELD; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } Close(retval); - + _netshpfile = sf; - _netshpfile->AddRef(); - + _netshpfile->AddRef(); + _networkSize = numShapes; _currentNode = 0; _network = new shpNetNode[numShapes]; @@ -1516,29 +1516,29 @@ STDMETHODIMP CShapeNetwork::Open(IShapefile *sf, ICallback *cBack, VARIANT_BOOL VariantInit(&cDID); long lval1 = 0, lval2 = 0; - IUtils * gen = NULL; - CoCreateInstance(CLSID_Utils,NULL,CLSCTX_INPROC_SERVER,IID_IUtils,(void**)&gen); - + IUtils * gen = nullptr; + CoCreateInstance(CLSID_Utils, nullptr,CLSCTX_INPROC_SERVER,IID_IUtils,(void**)&gen); + long percent = 0, newpercent = 0; double total = numShapes; double length = 0; int i = 0; for( i = 0; i < numShapes; i++ ) - { - IShape * shp = NULL; + { + IShape * shp = nullptr; _netshpfile->get_Shape(i,&shp); - if( shp == NULL ) - { + if( shp == nullptr) + { _netshpfile->Release(); - _netshpfile = NULL; + _netshpfile = nullptr; *retval = FALSE; _lastErrorCode = tkINVALID_SHP_FILE; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + VariantClear(&cID); VariantClear(&cDID); @@ -1550,17 +1550,17 @@ STDMETHODIMP CShapeNetwork::Open(IShapefile *sf, ICallback *cBack, VARIANT_BOOL gen->get_Length(shp,&length); shp->Release(); - shp = NULL; + shp = nullptr; if( shptype != SHP_POLYLINE && shptype != SHP_POLYLINEZ && shptype != SHP_POLYLINEM ) { gen->Release(); Close(retval); *retval = FALSE; _lastErrorCode = tkINCOMPATIBLE_SHAPEFILE_TYPE; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); VariantClear(&cID); VariantClear(&cDID); @@ -1580,18 +1580,18 @@ STDMETHODIMP CShapeNetwork::Open(IShapefile *sf, ICallback *cBack, VARIANT_BOOL Close(retval); *retval = FALSE; _lastErrorCode = tkINVALID_FIELD_VALUE; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + VariantClear(&cID); VariantClear(&cDID); return S_OK; - } + } - lVal(cDID,lval2); + lVal(cDID,lval2); if( i == 0 ) { //assert( lval2 == -1 && "The DID != -1" ); @@ -1601,19 +1601,19 @@ STDMETHODIMP CShapeNetwork::Open(IShapefile *sf, ICallback *cBack, VARIANT_BOOL Close(retval); *retval = FALSE; _lastErrorCode = tkINVALID_FIELD_VALUE; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + VariantClear(&cID); VariantClear(&cDID); return S_OK; - } + } } else - { + { //assert( ( lval2 >= 0 && lval2 < numShapes ) && "The DID is out of range." ); if( lval2 < 0 || lval2 >= numShapes ) @@ -1621,30 +1621,30 @@ STDMETHODIMP CShapeNetwork::Open(IShapefile *sf, ICallback *cBack, VARIANT_BOOL Close(retval); *retval = FALSE; _lastErrorCode = tkINVALID_FIELD_VALUE; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + VariantClear(&cID); VariantClear(&cDID); return S_OK; - } + } } - + _network[i].length = length; _network[i].used = false; if( lval2 != -1 ) _network[lval2].up.push_back(i); _network[i].parentIndex = lval2; } - + CallbackHelper::Progress(callback, i, total, "ShpNetwork::Open", _key, percent); } gen->Release(); - gen = NULL; - + gen = nullptr; + //Verify that every end shape can get to the outlet std::deque netEnds; for( i = 0; i < _networkSize; i++ ) @@ -1652,8 +1652,8 @@ STDMETHODIMP CShapeNetwork::Open(IShapefile *sf, ICallback *cBack, VARIANT_BOOL netEnds.push_back(i); } percent = 0, newpercent = 0; - total = netEnds.size(); - for( i = 0; i < (int)netEnds.size(); i++ ) + total = static_cast(netEnds.size()); + for( i = 0; i < static_cast(netEnds.size()); i++ ) { bool * used = new bool[_networkSize]; memset(used,0,sizeof(bool)*_networkSize); @@ -1663,24 +1663,24 @@ STDMETHODIMP CShapeNetwork::Open(IShapefile *sf, ICallback *cBack, VARIANT_BOOL { delete [] used; - //This would create a loop + //This would create a loop Close(retval); *retval = FALSE; _lastErrorCode = tkNET_LOOP; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - - VariantClear(&cID); - VariantClear(&cDID); + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - return S_OK; + VariantClear(&cID); + VariantClear(&cDID); + + return S_OK; } used[snn.parentIndex] = true; } - + delete [] used; CallbackHelper::Progress(callback, i, total, "ShpNetwork::Verifying Integrity of Network", _key, percent); @@ -1694,16 +1694,16 @@ STDMETHODIMP CShapeNetwork::Open(IShapefile *sf, ICallback *cBack, VARIANT_BOOL { long parent = travNet[0]; travNet.pop_front(); - for( int i = 0; i < (int)_network[parent].up.size(); i++ ) + for( int i = 0; i < static_cast(_network[parent].up.size()); i++ ) { long index = _network[parent].up[i]; _network[index].distanceToOutlet = _network[parent].distanceToOutlet + _network[parent].length; travNet.push_back(index); - } + } } *retval = TRUE; - VariantClear(&cID); - VariantClear(&cDID); + VariantClear(&cID); + VariantClear(&cDID); return S_OK; } @@ -1711,12 +1711,12 @@ STDMETHODIMP CShapeNetwork::Close(VARIANT_BOOL *retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if( _netshpfile != NULL ) + if( _netshpfile != nullptr) _netshpfile->Release(); - _netshpfile = NULL; - if( _network != NULL ) + _netshpfile = nullptr; + if( _network != nullptr) delete [] _network; - _network = NULL; + _network = nullptr; _currentNode = -1; _networkSize = 0; @@ -1724,7 +1724,7 @@ STDMETHODIMP CShapeNetwork::Close(VARIANT_BOOL *retval) } bool CShapeNetwork::IsAligned() -{ if( _netshpfile == NULL ) +{ if( _netshpfile == nullptr) { if( _currentNode == -1 ) return true; else @@ -1743,9 +1743,9 @@ bool CShapeNetwork::IsAligned() long roundCustom( double d ) { if( ceil(d) - d <= .5 ) - return (int)ceil(d); + return static_cast(ceil(d)); else - return (int)floor(d); + return static_cast(floor(d)); } STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHeader * Header, double cellsize, ICallback *cBack, IGrid **retval) @@ -1756,23 +1756,23 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead ICallback * callback = _globalCallback ? _globalCallback : cBack; if( IsAligned() == false ) - { *retval = NULL; + { *retval = nullptr; _lastErrorCode = tkNOT_ALIGNED; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - return S_OK; + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + return S_OK; } - if( cBack == NULL ) + if( cBack == nullptr) cBack = _globalCallback; short nodata = -1; - + if( UseNetworkBounds != VARIANT_FALSE ) - { - IExtents * box = NULL; + { + IExtents * box = nullptr; _netshpfile->get_Extents(&box); double xllcenter = 0, yllcenter = 0; double xurcenter = 0, yurcenter = 0; @@ -1781,26 +1781,26 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead box->get_xMax(&xurcenter); box->get_yMax(&yurcenter); box->Release(); - + if( cellsize <= 0 ) - { *retval = NULL; + { *retval = nullptr; _lastErrorCode = tkINVALID_PARAMETER_VALUE; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } long ncols = roundCustom((xurcenter - xllcenter) / cellsize) + 1; long nrows = roundCustom((yurcenter - yllcenter) / cellsize) + 1; - IGridHeader * nbheader = NULL; - CoCreateInstance(CLSID_GridHeader,NULL,CLSCTX_INPROC_SERVER,IID_IGridHeader,(void**)&nbheader); + IGridHeader * nbheader = nullptr; + CoCreateInstance(CLSID_GridHeader, nullptr,CLSCTX_INPROC_SERVER,IID_IGridHeader,(void**)&nbheader); nbheader->put_dX(cellsize); nbheader->put_dY(cellsize); VARIANT vndv; - VariantInit(&vndv); + VariantInit(&vndv); vndv.vt = VT_I4; vndv.lVal = nodata; nbheader->put_NodataValue(vndv); @@ -1810,35 +1810,35 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead nbheader->put_YllCenter(yllcenter); VARIANT_BOOL vbretval = FALSE; - CoCreateInstance(CLSID_Grid,NULL,CLSCTX_INPROC_SERVER,IID_IGrid,(void**)retval); + CoCreateInstance(CLSID_Grid, nullptr,CLSCTX_INPROC_SERVER,IID_IGrid,(void**)retval); CallbackHelper::Progress(_globalCallback, 0, "ShpNetwork::RasterizeD8", _key); (*retval)->CreateNew(m_globalSettings.emptyBstr,nbheader,ShortDataType,vndv,VARIANT_TRUE,UseExtension,cBack,&vbretval); nbheader->Release(); - VariantClear(&vndv); + VariantClear(&vndv); if( vbretval == VARIANT_FALSE ) { (*retval)->Release(); - *retval = NULL; + *retval = nullptr; _lastErrorCode = tkGRID_NOT_INITIALIZED; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } } else - { if( Header == NULL ) - { *retval = NULL; + { if( Header == nullptr) + { *retval = nullptr; _lastErrorCode = tkUNEXPECTED_NULL_PARAMETER; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; - } - + } + double dx = 0.0, dy = 0.0; Header->get_dX(&dx); Header->get_dY(&dy); @@ -1847,19 +1847,19 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead cellsize = dy; if( cellsize <= 0 ) - { *retval = NULL; - + { *retval = nullptr; + if( cellsize == dx ) _lastErrorCode = tkINVALID_DX; else _lastErrorCode = tkINVALID_DY; - if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + if( cBack != nullptr) + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; - } + } //Reset the nodata value VARIANT vndv; @@ -1869,38 +1869,38 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead Header->put_NodataValue(vndv); VARIANT_BOOL vbretval = FALSE; - CoCreateInstance(CLSID_Grid,NULL,CLSCTX_INPROC_SERVER,IID_IGrid,(void**)retval); + CoCreateInstance(CLSID_Grid, nullptr,CLSCTX_INPROC_SERVER,IID_IGrid,(void**)retval); CallbackHelper::Progress(_globalCallback, 0, "ShpNetwork::RasterizeD8", _key); (*retval)->CreateNew(m_globalSettings.emptyBstr, Header, ShortDataType, vndv, VARIANT_TRUE, UseExtension, cBack, &vbretval); - VariantClear(&vndv); + VariantClear(&vndv); if( vbretval == FALSE ) { (*retval)->Release(); - *retval = NULL; + *retval = nullptr; _lastErrorCode = tkGRID_NOT_INITIALIZED; if( cBack != NULL ) - cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); - else if( _globalCallback != NULL ) - _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + cBack->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); + else if( _globalCallback != nullptr) + _globalCallback->Error(OLE2BSTR(_key),A2BSTR(ErrorMsg(_lastErrorCode))); return S_OK; } - } - + } + //Generate a stack that has the ups at elements 0 - std::deque upsfirst; std::deque netstack; netstack.push_back(0); while( netstack.size() > 0 )//&& upsfirst.size() < 30 ) - { + { long parent = netstack[0]; netstack.pop_front(); - upsfirst.push_front(parent); + upsfirst.push_front(parent); - for( int i = 0; i < (int)_network[parent].up.size(); i++ ) + for( int i = 0; i < static_cast(_network[parent].up.size()); i++ ) { long index = _network[parent].up[i]; - netstack.push_back(index); + netstack.push_back(index); } } @@ -1908,26 +1908,26 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead // Point0 is always the outlet long percent = 0, newpercent = 0; - double total = upsfirst.size(); + double total = static_cast(upsfirst.size()); - for( int s = 0; s < (int)upsfirst.size(); s++ ) + for( int s = 0; s < static_cast(upsfirst.size()); s++ ) { long shapeIndex = upsfirst[s]; - IShape * shp = NULL; + IShape * shp = nullptr; _netshpfile->get_Shape(shapeIndex,&shp); long numPoints = 0; shp->get_NumPoints(&numPoints); - + std::deque Rasterize; //Create a raster_cell that will be written - IPoint * downpnt = NULL; + IPoint * downpnt = nullptr; shp->get_Point(0,&downpnt); double dpx, dpy; downpnt->get_X(&dpx); downpnt->get_Y(&dpy); downpnt->Release(); - + snraspnt current_point; (*retval)->ProjToCell(dpx,dpy,&(current_point.column),&(current_point.row)); current_point.length = cellsize; @@ -1936,9 +1936,9 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead //Step through the line incrementing the length inside of the cell for( int i = 0; i < numPoints - 1; i++ ) - { - IPoint * one = NULL; - IPoint * two = NULL; + { + IPoint * one = nullptr; + IPoint * two = nullptr; shp->get_Point(i,&one); shp->get_Point(i+1,&two); @@ -1964,19 +1964,18 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead if( dx > 0 ) step_x = increment; if( dy > 0 ) - step_y = increment; - + step_y = increment; + if( dx != 0.0 ) - { + { double m = dy/dx; double b = y1 - m*x1; if( fabs(dx) > fabs(dy) ) - { + { for( double i = 0; i < fabs(dx); i=i+increment ) { y1 = ( m*x1 + b ); - - (*retval)->ProjToCell(x1,y1,&(temp_point.column),&(temp_point.row)); + (*retval)->ProjToCell(x1,y1,&(temp_point.column),&(temp_point.row)); current_point.column = temp_point.column; current_point.row = temp_point.row; @@ -1987,7 +1986,7 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead else { //Check to see if this raster has been used before bool prevUsed = false; - for( int pu = 0; pu < (int)Rasterize.size(); pu++ ) + for( int pu = 0; pu < static_cast(Rasterize.size()); pu++ ) { if( Rasterize[pu] == current_point ) { prevUsed = true; current_point = Rasterize[pu]; @@ -2002,18 +2001,16 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead current_point.length = increment; Rasterize.push_back( current_point ); } - } - + x1 = x1 + step_x; } } else { for( double j = 0; j < fabs(dy); j=j+increment ) - { x1 = ( ( y1 - b )/m ); - - (*retval)->ProjToCell(x1,y1,&(temp_point.column),&(temp_point.row)); + { x1 = ( ( y1 - b )/m ); + (*retval)->ProjToCell(x1,y1,&(temp_point.column),&(temp_point.row)); current_point.column = temp_point.column; current_point.row = temp_point.row; @@ -2024,7 +2021,7 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead else { //Check to see if this raster has been used before bool prevUsed = false; - for( int pu = 0; pu < (int)Rasterize.size(); pu++ ) + for( int pu = 0; pu < static_cast(Rasterize.size()); pu++ ) { if( Rasterize[pu] == current_point ) { prevUsed = true; current_point = Rasterize[pu]; @@ -2040,16 +2037,16 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead Rasterize.push_back( current_point ); } } - + y1 = y1 + step_y; } } } else - { + { for( double j = 0; j < fabs(dy); j=j+increment ) - { - (*retval)->ProjToCell(x1,y1,&(temp_point.column),&(temp_point.row)); + { + (*retval)->ProjToCell(x1,y1,&(temp_point.column),&(temp_point.row)); current_point.column = temp_point.column; current_point.row = temp_point.row; @@ -2060,7 +2057,7 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead else { //Check to see if this raster has been used before bool prevUsed = false; - for( int pu = 0; pu < (int)Rasterize.size(); pu++ ) + for( int pu = 0; pu < static_cast(Rasterize.size()); pu++ ) { if( Rasterize[pu] == current_point ) { prevUsed = true; current_point = Rasterize[pu]; @@ -2079,11 +2076,11 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead y1 = y1 + step_y; } - } + } } //Push the last point onto the deque - IPoint * uppnt = NULL; + IPoint * uppnt = nullptr; shp->get_Point(numPoints - 1,&uppnt); double uppx, uppy; uppnt->get_X(&uppx); @@ -2094,17 +2091,17 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead if( Rasterize[ Rasterize.size() - 1 ] == temp_point ) Rasterize[ Rasterize.size() - 1 ] = temp_point; else - Rasterize.push_back( temp_point ); + Rasterize.push_back( temp_point ); shp->Release(); - shp = NULL; + shp = nullptr; //Write the raster_cells to the grid // with directional information of network flow // // Flow Diagram // - // 4 3 2 + // 4 3 2 // 5 X 1 // 6 7 8 @@ -2115,10 +2112,10 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead VARIANT vval; VariantInit(&vval); short val; - + snraspnt last_raster = Rasterize[0]; - for( int k = 1; k < (int)Rasterize.size(); k++ ) + for( int k = 1; k < static_cast(Rasterize.size()); k++ ) { //Test if the Length is long enough to write in the final_grid double length = Rasterize[k].length; @@ -2131,7 +2128,7 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead sVal(vval,val); if( val != nodata ) { last_raster = Rasterize[k]; - continue; + continue; } } @@ -2143,10 +2140,10 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead (*retval)->put_Value( Rasterize[k].column, Rasterize[k].row, vval ); last_raster = Rasterize[k]; } - } + } + + Rasterize.clear(); - Rasterize.clear(); - CallbackHelper::Progress(callback, s, total, "ShpNetwork::RasterizeD8", _key, percent); VariantClear(&vval); @@ -2156,8 +2153,8 @@ STDMETHODIMP CShapeNetwork::RasterizeD8(VARIANT_BOOL UseNetworkBounds, IGridHead } short CShapeNetwork::RasterDirection( snraspnt & source, snraspnt & sink ) -{ - long src_i = source.column; +{ + long src_i = source.column; long src_j = source.row; long snk_i = sink.column; long snk_j = sink.row; diff --git a/src/COM classes/ShapefileCategories.cpp b/src/COM classes/ShapefileCategories.cpp index 127e1206..68335433 100644 --- a/src/COM classes/ShapefileCategories.cpp +++ b/src/COM classes/ShapefileCategories.cpp @@ -39,7 +39,7 @@ STDMETHODIMP CShapefileCategories::get_Count(long* pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *pVal = _categories.size(); + *pVal = static_cast(_categories.size()); return S_OK; } @@ -48,8 +48,8 @@ STDMETHODIMP CShapefileCategories::get_Count(long* pVal) // *************************************************************** STDMETHODIMP CShapefileCategories::Add(BSTR Name, IShapefileCategory** retVal) { - this->Insert(_categories.size(), Name, retVal); - + this->Insert(static_cast(_categories.size()), Name, retVal); + return S_OK; } @@ -59,9 +59,9 @@ STDMETHODIMP CShapefileCategories::Add(BSTR Name, IShapefileCategory** retVal) STDMETHODIMP CShapefileCategories::Insert(long Index, BSTR Name, IShapefileCategory** retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - - if(Index < 0 || Index > (long)_categories.size()) - { + + if(Index < 0 || Index > static_cast(_categories.size())) + { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = nullptr; return NULL; @@ -71,7 +71,7 @@ STDMETHODIMP CShapefileCategories::Insert(long Index, BSTR Name, IShapefileCateg IShapefileCategory* cat = nullptr; CoCreateInstance( CLSID_ShapefileCategory, nullptr, CLSCTX_INPROC_SERVER, IID_IShapefileCategory, (void**)&cat); if (cat == nullptr) return S_OK; - + // initialization with default options if shapefile is present if (_shapefile != nullptr) { @@ -79,7 +79,7 @@ STDMETHODIMP CShapefileCategories::Insert(long Index, BSTR Name, IShapefileCateg _shapefile->get_DefaultDrawingOptions(&defaultOpt); CDrawingOptionsEx* newOpt =((CShapeDrawingOptions*)defaultOpt)->get_UnderlyingOptions(); defaultOpt->Release(); - + IShapeDrawingOptions* opt = nullptr; cat->get_DrawingOptions(&opt); ((CShapeDrawingOptions*)opt)->put_underlyingOptions(newOpt); @@ -95,7 +95,7 @@ STDMETHODIMP CShapefileCategories::Insert(long Index, BSTR Name, IShapefileCateg { _categories.insert( _categories.begin() + Index, cat); } - + *retVal = cat; ((CShapefileCategory*) *retVal)->put_parentCollection(this); @@ -111,8 +111,8 @@ STDMETHODIMP CShapefileCategories::Remove(long Index, VARIANT_BOOL* vbRetval) AFX_MANAGE_STATE(AfxGetStaticModuleState()) *vbRetval = VARIANT_FALSE; - if( Index < 0 || Index >= (long)_categories.size() ) - { + if( Index < 0 || Index >= static_cast(_categories.size()) ) + { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *vbRetval = VARIANT_FALSE; } @@ -134,7 +134,7 @@ STDMETHODIMP CShapefileCategories::Clear() AFX_MANAGE_STATE(AfxGetStaticModuleState()) for (auto& _categorie : _categories) { - _categorie->Release(); + _categorie->Release(); } _categories.clear(); @@ -143,7 +143,7 @@ STDMETHODIMP CShapefileCategories::Clear() std::vector* data = ((CShapefile*)_shapefile)->get_ShapeVector(); for (auto& i : *data) { - i->category = -1; + i->category = -1; } } return S_OK; @@ -155,8 +155,8 @@ STDMETHODIMP CShapefileCategories::Clear() STDMETHODIMP CShapefileCategories::get_Item (long Index, IShapefileCategory** retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if( Index < 0 || Index >= (long)_categories.size() ) - { + if( Index < 0 || Index >= static_cast(_categories.size()) ) + { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retval = nullptr; } @@ -171,23 +171,23 @@ STDMETHODIMP CShapefileCategories::get_Item (long Index, IShapefileCategory** re STDMETHODIMP CShapefileCategories::put_Item(long Index, IShapefileCategory* newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if( Index < 0 || Index >= (long)_categories.size() ) - { + if( Index < 0 || Index >= static_cast(_categories.size()) ) + { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); return S_OK; } - if (!newVal) - { - ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); - return S_OK; - } - if (_categories[Index] != newVal) - { - _categories[Index]->Release(); - _categories[Index] = newVal; - _categories[Index]->AddRef(); - } - return S_OK; + if (!newVal) + { + ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); + return S_OK; + } + if (_categories[Index] != newVal) + { + _categories[Index]->Release(); + _categories[Index] = newVal; + _categories[Index]->AddRef(); + } + return S_OK; } // *************************************************************** @@ -196,27 +196,27 @@ STDMETHODIMP CShapefileCategories::put_Item(long Index, IShapefileCategory* newV // Add categories for a given range STDMETHODIMP CShapefileCategories::AddRange(long FieldIndex, tkClassificationType ClassificationType, long numClasses, VARIANT minValue, VARIANT maxValue, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; *retVal = VARIANT_FALSE; - + if(_shapefile == nullptr) return S_OK; - + CComPtr tbl = nullptr; _shapefile->get_Table(&tbl); if (!tbl) return S_OK; - + std::vector* values = TableHelper::Cast(tbl)->GenerateCategories(FieldIndex, ClassificationType, numClasses, minValue, maxValue); - + if (!values) return S_OK; - + _classificationField = -1; // fast processing is off IShapefileCategory* cat = nullptr; - + for (auto& value : *values) { CString strValue; @@ -228,16 +228,16 @@ STDMETHODIMP CShapefileCategories::AddRange(long FieldIndex, tkClassificationTyp cat->put_MinValue(value.minValue); cat->put_MaxValue(value.maxValue); cat->Release(); - } + } if (ClassificationType == ctUniqueValues) - { + { // no fast processing in this mode as user could generate categories by several fields // m_classificationField = FieldIndex; } - + delete values; - + //this->ApplyExpressions(); *retVal = VARIANT_TRUE; @@ -249,7 +249,7 @@ STDMETHODIMP CShapefileCategories::AddRange(long FieldIndex, tkClassificationTyp // ******************************************************** STDMETHODIMP CShapefileCategories::Generate2(BSTR fieldName, tkClassificationType ClassificationType, LONG numClasses, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (!_shapefile) return S_OK; @@ -271,18 +271,18 @@ STDMETHODIMP CShapefileCategories::Generate2(BSTR fieldName, tkClassificationTyp // *************************************************************** STDMETHODIMP CShapefileCategories::Generate(long FieldIndex, tkClassificationType ClassificationType, long numClasses, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; *retVal = VARIANT_FALSE; if(_shapefile == nullptr) return S_OK; - + CComPtr tbl = nullptr; _shapefile->get_Table(&tbl); if (!tbl) return S_OK; - + std::vector* values = TableHelper::Cast(tbl)->GenerateCategories(FieldIndex, ClassificationType, numClasses); if (!values) return S_OK; @@ -370,18 +370,18 @@ STDMETHODIMP CShapefileCategories::put_Caption(BSTR newVal) // ********************************************************** STDMETHODIMP CShapefileCategories::get_VisibilityExpression(BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; - *pVal = OLE2BSTR(_visExpression); - return S_OK; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + USES_CONVERSION; + *pVal = OLE2BSTR(_visExpression); + return S_OK; } STDMETHODIMP CShapefileCategories::put_VisibilityExpression(BSTR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()) - ::SysFreeString(_visExpression); - USES_CONVERSION; - _visExpression = OLE2BSTR(newVal); - return S_OK; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + ::SysFreeString(_visExpression); + USES_CONVERSION; + _visExpression = OLE2BSTR(newVal); + return S_OK; } //***********************************************************************/ @@ -459,7 +459,7 @@ CDrawingOptionsEx* CShapefileCategories::get_UnderlyingOptions(int Index) { if (Index >=0 && Index < (int)_categories.size()) return ((CShapefileCategory*)_categories[Index])->get_UnderlyingOptions(); - return nullptr; + return nullptr; } // ******************************************************************* @@ -485,7 +485,7 @@ STDMETHODIMP CShapefileCategories::ApplyExpression(long CategoryIndex, long star { if (i->category == CategoryIndex) { - i->category = -1; + i->category = -1; } } @@ -500,37 +500,37 @@ void CShapefileCategories::ApplyExpressionCore(long CategoryIndex, long startRow { if (!_shapefile) return; - + CComPtr tbl = nullptr; _shapefile->get_Table(&tbl); if ( !tbl ) return; - + // Process shape index range: long numShapes; _shapefile->get_NumShapes(&numShapes); endRowIndex = endRowIndex < 0 ? numShapes - 1 : endRowIndex; startRowIndex = startRowIndex < 0 ? 0 : startRowIndex; numShapes = endRowIndex - startRowIndex + 1; - + // vector of numShapes size with category index for each shape std::vector results; results.resize(numShapes, -1); - std::vector> rotations; - rotations.resize(_categories.size() + 1); + std::vector> rotations; + rotations.resize(_categories.size() + 1); bool uniqueValues = true; for (auto& _categorie : _categories) { tkCategoryValue value; - _categorie->get_ValueType(&value); + _categorie->get_ValueType(&value); if (value != cvSingleValue) { uniqueValues = false; break; } } - bool allCategories = CategoryIndex == -1; + bool allCategories = CategoryIndex == -1; // ---------------------------------------------------------------- // we got unique values classification and want to process it fast @@ -543,8 +543,8 @@ void CShapefileCategories::ApplyExpressionCore(long CategoryIndex, long startRow std::map myMap; // variant value as key and number of category as result for (unsigned int i = 0; i < _categories.size(); i++) { - if (!allCategories && i != CategoryIndex) - continue; + if (!allCategories && i != CategoryIndex) + continue; CComVariant val; _categories[i]->get_MinValue(&val); @@ -679,7 +679,7 @@ STDMETHODIMP CShapefileCategories::ApplyColorScheme (tkColorSchemeType Type, ICo STDMETHODIMP CShapefileCategories::ApplyColorScheme2 (tkColorSchemeType Type, IColorScheme* ColorScheme, tkShapeElements ShapeElement) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - ApplyColorScheme3(Type, ColorScheme, ShapeElement, 0, _categories.size() - 1); + ApplyColorScheme3(Type, ColorScheme, ShapeElement, 0, static_cast(_categories.size()) - 1); return S_OK; } @@ -707,9 +707,9 @@ STDMETHODIMP CShapefileCategories::ApplyColorScheme3 (tkColorSchemeType Type, IC } // we'll correct invalid indices - if (CategoryEndIndex >= (long)_categories.size()) + if (CategoryEndIndex >= static_cast(_categories.size())) { - CategoryEndIndex = (long)(_categories.size() - 1); + CategoryEndIndex = static_cast(_categories.size() - 1); } if (CategoryStartIndex < 0) @@ -726,7 +726,7 @@ STDMETHODIMP CShapefileCategories::ApplyColorScheme3 (tkColorSchemeType Type, IC double maxValue; ColorScheme->get_BreakValue(numBreaks - 1, &maxValue); - + // choosing the element to apply colors to if ( ShapeElement == shElementDefault) { @@ -750,19 +750,19 @@ STDMETHODIMP CShapefileCategories::ApplyColorScheme3 (tkColorSchemeType Type, IC { OLE_COLOR color; double value; - if ( Type == ctSchemeRandom ) + if ( Type == ctSchemeRandom ) { value = double(rand()/double(RAND_MAX)); ColorScheme->get_RandomColor(value, &color); } - else if ( Type == ctSchemeGraduated ) + else if ( Type == ctSchemeGraduated ) { value = double(i - CategoryStartIndex)/double(CategoryEndIndex - CategoryStartIndex) * maxValue; ColorScheme->get_GraduatedColor(value, &color); } - + _categories[i]->get_DrawingOptions(&options); - + if ( options ) { switch (ShapeElement) @@ -786,7 +786,7 @@ STDMETHODIMP CShapefileCategories::ApplyColorScheme3 (tkColorSchemeType Type, IC STDMETHODIMP CShapefileCategories::MoveUp (long Index, VARIANT_BOOL* retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < (long)_categories.size() && Index > 0) + if (Index < static_cast(_categories.size()) && Index > 0) { IShapefileCategory* catBefore = _categories[Index - 1]; _categories[Index - 1] = _categories[Index]; @@ -797,11 +797,11 @@ STDMETHODIMP CShapefileCategories::MoveUp (long Index, VARIANT_BOOL* retval) { if (i->category == Index) { - i->category = Index - 1; + i->category = Index - 1; } else if (i->category == Index - 1) { - i->category = Index; + i->category = Index; } } @@ -821,7 +821,7 @@ STDMETHODIMP CShapefileCategories::MoveUp (long Index, VARIANT_BOOL* retval) STDMETHODIMP CShapefileCategories::MoveDown (long Index, VARIANT_BOOL* retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < (long)_categories.size() - 1 && Index >= 0) + if (Index < static_cast(_categories.size()) - 1 && Index >= 0) { IShapefileCategory* catAfter = _categories[Index + 1]; _categories[Index + 1] = _categories[Index]; @@ -832,11 +832,11 @@ STDMETHODIMP CShapefileCategories::MoveDown (long Index, VARIANT_BOOL* retval) { if (i->category == Index) { - i->category = Index + 1; + i->category = Index + 1; } else if (i->category == Index + 1) { - i->category = Index; + i->category = Index; } } *retval = VARIANT_TRUE; @@ -870,7 +870,7 @@ CPLXMLNode* CShapefileCategories::SerializeCore(CString ElementName) CPLXMLNode* psTree = CPLCreateXMLNode( nullptr, CXT_Element, ElementName); - // classification field + // classification field Utility::CPLCreateXMLAttributeAndValue(psTree, "ClassificationField", CPLString().Printf("%d", _classificationField)); // field type @@ -952,7 +952,7 @@ bool CShapefileCategories::DeserializeCore(CPLXMLNode* node, bool applyExpressio s = CPLGetXMLValue( node, "ClassificationField", nullptr ); if (s != "") { - const int fieldIndex = atoi(s); + const int fieldIndex = atoi(s); CComPtr table = nullptr; _shapefile->get_Table(&table); @@ -1015,7 +1015,7 @@ bool CShapefileCategories::DeserializeCore(CPLXMLNode* node, bool applyExpressio cat->Release(); } node = node->psNext; - } + } if (applyExpressions) this->ApplyExpressions(); @@ -1059,7 +1059,7 @@ STDMETHODIMP CShapefileCategories::get_CategoryIndexByName(BSTR categoryName, in if (lstrcmpW(bstr, categoryName) == 0) { - *categoryIndex = i; + *categoryIndex = static_cast(i); break; } } @@ -1077,7 +1077,7 @@ STDMETHODIMP CShapefileCategories::get_CategoryIndex(IShapefileCategory* categor { if (_categories[i] == category) { - *categoryIndex = i; + *categoryIndex = static_cast(i); break; } } @@ -1091,7 +1091,7 @@ STDMETHODIMP CShapefileCategories::GeneratePolygonColors(IColorScheme* scheme, V { AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = VARIANT_FALSE; - + // ------------------------------------------------- // parameter validation // ------------------------------------------------- @@ -1125,19 +1125,19 @@ STDMETHODIMP CShapefileCategories::GeneratePolygonColors(IColorScheme* scheme, V //scheme->SetColors4(PredefinedColorScheme::SummerMountains); tempScheme= true; } - + // ------------------------------------------------- // do the processing // ------------------------------------------------- Coloring::ColorGraph* graph = ((CShapefile*)_shapefile)->GeneratePolygonColors(); if (graph) { - const int colorCount = graph->GetColorCount(); + const int colorCount = graph->GetColorCount(); // ------------------------------------------------- // create categories // ------------------------------------------------- - const int firstCategory = _categories.size(); + const int firstCategory = static_cast(_categories.size()); long numBreaks; scheme->get_NumBreaks(&numBreaks); for(int i = 0; i < colorCount; i++) @@ -1228,33 +1228,33 @@ STDMETHODIMP CShapefileCategories::Sort(LONG FieldIndex, VARIANT_BOOL Ascending, // string and boolean can be treated as string valDefault = ""; } - + multimap map; for (auto& _categorie : _categories) { - const VARIANT_BOOL vbretval = VARIANT_FALSE; + const VARIANT_BOOL vbretval = VARIANT_FALSE; CComVariant var = NULL; BSTR expr; - _categorie->get_Expression(&expr); + _categorie->get_Expression(&expr); // TODO: implement //table->CalculateStat(FieldIndex, Operation, expr, &var, &vbretval); if (vbretval) { - pair myPair(var, _categorie); + pair myPair(var, _categorie); map.insert(myPair); } else { - pair myPair(valDefault, _categorie); + pair myPair(valDefault, _categorie); map.insert(myPair); } } - multimap::iterator p = map.begin(); - + multimap::iterator p = map.begin(); + int i = 0; ASSERT(map.size() == _categories.size()); @@ -1262,8 +1262,8 @@ STDMETHODIMP CShapefileCategories::Sort(LONG FieldIndex, VARIANT_BOOL Ascending, { // IShapefileCategory* cat = p->second; _categories[i] = p->second; - i++; - ++p; + i++; + ++p; } *retVal = VARIANT_TRUE; @@ -1275,13 +1275,13 @@ STDMETHODIMP CShapefileCategories::Sort(LONG FieldIndex, VARIANT_BOOL Ascending, // ******************************************************** STDMETHODIMP CShapefileCategories::get_ClassificationField(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _classificationField; return S_OK; } STDMETHODIMP CShapefileCategories::put_ClassificationField(LONG newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _classificationField = newVal; return S_OK; } @@ -1295,12 +1295,12 @@ void CShapefileCategories::GetCategoryData(vector& data) data.clear(); for (auto& _categorie : _categories) { - auto* ct = new CategoriesData(); - _categorie->get_MinValue(&ct->minValue); - _categorie->get_MaxValue(&ct->maxValue); - _categorie->get_ValueType(&ct->valueType); + auto* ct = new CategoriesData(); + _categorie->get_MinValue(&ct->minValue); + _categorie->get_MaxValue(&ct->maxValue); + _categorie->get_ValueType(&ct->valueType); CComBSTR expr; - _categorie->get_Expression(&expr); + _categorie->get_Expression(&expr); ct->expression = OLE2A(expr); ct->classificationField = _classificationField; data.push_back(ct); @@ -1312,7 +1312,7 @@ void CShapefileCategories::GetCategoryData(vector& data) // ******************************************************** STDMETHODIMP CShapefileCategories::Add2(IShapefileCategory* category) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!category) { ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); @@ -1328,14 +1328,14 @@ STDMETHODIMP CShapefileCategories::Add2(IShapefileCategory* category) // ******************************************************** STDMETHODIMP CShapefileCategories::Insert2(LONG index, IShapefileCategory* category, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (!category) { ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); return S_OK; } - if (index < 0 || index >= (long)_categories.size()) + if (index < 0 || index >= static_cast(_categories.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); return S_OK; diff --git a/src/COM classes/Shapefile_Edit.cpp b/src/COM classes/Shapefile_Edit.cpp index e0fe8bd6..ebf0c6c0 100644 --- a/src/COM classes/Shapefile_Edit.cpp +++ b/src/COM classes/Shapefile_Edit.cpp @@ -41,14 +41,14 @@ STDMETHODIMP CShapefile::StartEditingShapes(VARIANT_BOOL startEditTable, ICallba StopAppendMode(); } - bool callbackIsNull = (_globalCallback == NULL); - if(cBack != NULL && _globalCallback == NULL) + bool callbackIsNull = (_globalCallback == nullptr); + if(cBack != nullptr && _globalCallback == nullptr) { - _globalCallback = cBack; + _globalCallback = cBack; _globalCallback->AddRef(); } - if( _table == NULL || _sourceType == sstUninitialized) + if( _table == nullptr || _sourceType == sstUninitialized) { ErrorMessage(tkSHAPEFILE_UNINITIALIZED); return S_OK; @@ -58,35 +58,35 @@ STDMETHODIMP CShapefile::StartEditingShapes(VARIANT_BOOL startEditTable, ICallba *retval = VARIANT_TRUE; return S_OK; } - else if (_writing) + else if (_writing) { ErrorMessage(tkSHP_READ_VIOLATION); return S_OK; } - double xMin, xMax, yMin, yMax, zMin, zMax; - this->ClearQTree(&xMin, &xMax, &yMin, &yMax, &zMin, &zMax); - + double xMin, xMax, yMin, yMax, zMin, zMax; + this->ClearQTree(&xMin, &xMax, &yMin, &yMax, &zMin, &zMax); + // reading shapes into memory - IShape * shp = NULL; - _lastErrorCode = tkNO_ERROR; - long percent = 0, newpercent = 0; - - int size = (int)_shapeData.size(); + IShape * shp = nullptr; + _lastErrorCode = tkNO_ERROR; + long percent = 0, newpercent = 0; + + int size = static_cast(_shapeData.size()); for( int i = 0; i < size; i++) - { + { get_Shape(i, &shp); if( _lastErrorCode != tkNO_ERROR ) - { + { ErrorMessage(_lastErrorCode); ReleaseMemoryShapes(); return S_OK; } - + _shapeData[i]->shape = shp; _shapeData[i]->originalIndex = i; - + if(_useQTree) { QuickExtentsCore(i, &xMin, &yMin, &xMax, &yMax); @@ -99,7 +99,7 @@ STDMETHODIMP CShapefile::StartEditingShapes(VARIANT_BOOL startEditTable, ICallba node.index = i; _qtree->AddNode(node); } - + CallbackHelper::Progress(_globalCallback, i, size, "Reading shapes into memory", _key, percent); } CallbackHelper::ProgressCompleted(_globalCallback); @@ -128,7 +128,7 @@ STDMETHODIMP CShapefile::StartEditingShapes(VARIANT_BOOL startEditTable, ICallba } if (callbackIsNull) { - _globalCallback = NULL; + _globalCallback = nullptr; } return S_OK; } @@ -148,15 +148,15 @@ STDMETHODIMP CShapefile::StopEditingShapes(VARIANT_BOOL applyChanges, VARIANT_BO if (!_globalCallback && cBack) put_GlobalCallback(cBack); - if( _table == NULL || _sourceType == sstUninitialized) + if( _table == nullptr || _sourceType == sstUninitialized) return S_OK; // don't report anything as StopEditingShapes will be called from Close for any InMemoryShapefile if( _isEditingShapes == FALSE ) - { + { *retval = VARIANT_TRUE; return S_OK; } - + if ( _writing ) { ErrorMessage(tkSHP_WRITE_VIOLATION, cBack); @@ -169,7 +169,7 @@ STDMETHODIMP CShapefile::StopEditingShapes(VARIANT_BOOL applyChanges, VARIANT_BO if(_shpfileName.GetLength() > 0) { Save(cBack, retval); - + if (*retval) { _isEditingShapes = VARIANT_FALSE; @@ -185,11 +185,11 @@ STDMETHODIMP CShapefile::StopEditingShapes(VARIANT_BOOL applyChanges, VARIANT_BO *retval = VARIANT_TRUE; return S_OK; } - + USES_CONVERSION; if( applyChanges ) - { + { _writing = true; // verify Shapefile Integrity @@ -202,18 +202,17 @@ STDMETHODIMP CShapefile::StopEditingShapes(VARIANT_BOOL applyChanges, VARIANT_BO _shpfile = _wfreopen(_shpfileName, L"wb+", _shpfile); _shxfile = _wfreopen(_shxfileName, L"wb+",_shxfile); - if( _shpfile == NULL || _shxfile == NULL ) - { - if( _shxfile != NULL ) - { + if( _shpfile == nullptr || _shxfile == nullptr) + { + if( _shxfile != nullptr) + { fclose( _shxfile ); - _shxfile = NULL; - + _shxfile = nullptr; } - if( _shpfile != NULL ) - { + if( _shpfile != nullptr) + { fclose( _shpfile ); - _shpfile = NULL; + _shpfile = nullptr; ErrorMessage(tkCANT_OPEN_SHP, cBack); } } @@ -228,24 +227,24 @@ STDMETHODIMP CShapefile::StopEditingShapes(VARIANT_BOOL applyChanges, VARIANT_BO _shpfile = _wfreopen(_shpfileName,L"rb+", _shpfile); _shxfile = _wfreopen(_shxfileName,L"rb+",_shxfile); - - if( _shpfile == NULL || _shxfile == NULL ) - { - if( _shxfile != NULL ) - { + + if( _shpfile == nullptr || _shxfile == nullptr) + { + if( _shxfile != nullptr) + { fclose( _shxfile ); - _shxfile = NULL; + _shxfile = nullptr; ErrorMessage(tkCANT_OPEN_SHX, cBack); } - if( _shpfile != NULL ) - { + if( _shpfile != nullptr) + { fclose( _shpfile ); - _shpfile = NULL; + _shpfile = nullptr; ErrorMessage(tkCANT_OPEN_SHP, cBack); } } else - { + { _isEditingShapes = FALSE; ReleaseMemoryShapes(); *retval = VARIANT_TRUE; @@ -270,7 +269,7 @@ STDMETHODIMP CShapefile::StopEditingShapes(VARIANT_BOOL applyChanges, VARIANT_BO _writing = false; } else - { + { // discard the changes _isEditingShapes = FALSE; ReleaseMemoryShapes(); @@ -287,7 +286,7 @@ STDMETHODIMP CShapefile::StopEditingShapes(VARIANT_BOOL applyChanges, VARIANT_BO *retval = VARIANT_TRUE; } - + return S_OK; } @@ -344,7 +343,7 @@ void CShapefile::RegisterNewShape(IShape* shape, long shapeIndex) } // updating labels and charts - if (_table) + if (_table) { double x = 0.0, y = 0.0, rotation = 0.0, offsetX = 0.0, offsetY = 0.0; VARIANT_BOOL vbretval; @@ -399,7 +398,7 @@ void CShapefile::RegisterNewShape(IShape* shape, long shapeIndex) // it's necessary to call RefreshExtents in this case, for zoom to layer working right if (!ShapeHelper::IsEmpty(shape)) { - CComPtr box = NULL; + CComPtr box = nullptr; shape->get_Extents(&box); double xm, ym, zm, xM, yM, zM; box->GetBounds(&xm, &ym, &zm, &xM, &yM, &zM); @@ -451,7 +450,7 @@ STDMETHODIMP CShapefile::EditUpdateShape(long shapeIndex, IShape* shpNew, VARIAN return S_OK; } - if (shapeIndex < 0 || shapeIndex >= (long)_shapeData.size()) + if (shapeIndex < 0 || shapeIndex >= static_cast(_shapeData.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); return S_OK; @@ -494,7 +493,7 @@ void CShapefile::ReregisterShape(int shapeIndex) { if (!_isEditingShapes) return; - if (shapeIndex < 0 || shapeIndex >= (int)_shapeData.size()) + if (shapeIndex < 0 || shapeIndex >= static_cast(_shapeData.size())) return; IShape* shp = _shapeData[shapeIndex]->shape; @@ -551,21 +550,21 @@ STDMETHODIMP CShapefile::EditInsertShape(IShape *shape, long *shapeIndex, VARIAN { AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = VARIANT_FALSE; - - if( _table == NULL || _sourceType == sstUninitialized ) - { + + if( _table == nullptr || _sourceType == sstUninitialized ) + { ErrorMessage(tkSHAPEFILE_UNINITIALIZED); return S_OK; } - bool canAppend = _appendMode && (*shapeIndex) >= (long)_shapeData.size(); + bool canAppend = _appendMode && (*shapeIndex) >= static_cast(_shapeData.size()); if (!_isEditingShapes && !canAppend) { ErrorMessage(tkSHPFILE_NOT_IN_EDIT_MODE); return S_OK; } - + VARIANT_BOOL isEditingTable; _table->get_EditingTable(&isEditingTable); @@ -574,13 +573,13 @@ STDMETHODIMP CShapefile::EditInsertShape(IShape *shape, long *shapeIndex, VARIAN ErrorMessage(tkDBF_NOT_IN_EDIT_MODE); return S_OK; } - - if (shape == NULL) + + if (shape == nullptr) { ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); return S_OK; } - + if (!IsShapeCompatible(shape)) { ErrorMessage(tkINCOMPATIBLE_SHAPEFILE_TYPE); @@ -588,7 +587,7 @@ STDMETHODIMP CShapefile::EditInsertShape(IShape *shape, long *shapeIndex, VARIAN } if (_appendMode) { - WriteAppendedShape(); + WriteAppendedShape(); } // wrong index will be corrected @@ -596,20 +595,20 @@ STDMETHODIMP CShapefile::EditInsertShape(IShape *shape, long *shapeIndex, VARIAN { *shapeIndex = 0; } - else if( *shapeIndex > (int)_shapeData.size() ) + else if( *shapeIndex > static_cast(_shapeData.size()) ) { - *shapeIndex = _shapeData.size(); + *shapeIndex = static_cast(_shapeData.size()); } _table->EditInsertRow( shapeIndex, retval ); - + if( *retval == VARIANT_FALSE ) - { + { _table->get_LastErrorCode(&_lastErrorCode); ErrorMessage(_lastErrorCode); - } + } else - { + { ShapeRecord* data = new ShapeRecord(); shape->AddRef(); data->shape = shape; @@ -620,10 +619,10 @@ STDMETHODIMP CShapefile::EditInsertShape(IShape *shape, long *shapeIndex, VARIAN GenerateQTree(); RegisterNewShape(shape, *shapeIndex); - + *retval = VARIANT_TRUE; } - + ((CTableClass*)_table)->set_IndexValue(*shapeIndex); return S_OK; @@ -670,8 +669,8 @@ STDMETHODIMP CShapefile::EditDeleteShape(long shapeIndex, VARIANT_BOOL *retval) AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = VARIANT_FALSE; - if( _table == NULL || _sourceType == sstUninitialized ) - { + if( _table == nullptr || _sourceType == sstUninitialized ) + { ErrorMessage(tkSHAPEFILE_UNINITIALIZED); } else if(!_isEditingShapes) @@ -682,32 +681,32 @@ STDMETHODIMP CShapefile::EditDeleteShape(long shapeIndex, VARIANT_BOOL *retval) { VARIANT_BOOL isEditingTable; _table->get_EditingTable(&isEditingTable); - + if(!isEditingTable) { ErrorMessage(tkDBF_NOT_IN_EDIT_MODE); } - else if( shapeIndex < 0 || shapeIndex >= (int)_shapeData.size() ) - { + else if( shapeIndex < 0 || shapeIndex >= static_cast(_shapeData.size()) ) + { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); } else { VARIANT_BOOL vbretval; _table->EditDeleteRow( shapeIndex, &vbretval); - + if(!vbretval) - { + { _table->get_LastErrorCode(&_lastErrorCode); ErrorMessage(_lastErrorCode); - } + } else - { + { VARIANT_BOOL bSynchronized; _labels->get_Synchronized(&bSynchronized); if (bSynchronized) _labels->RemoveLabel(shapeIndex, &vbretval); - + delete _shapeData[shapeIndex]; _shapeData.erase( _shapeData.begin() + shapeIndex ); @@ -754,7 +753,7 @@ STDMETHODIMP CShapefile::EditClear(VARIANT_BOOL *retval) AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = VARIANT_FALSE; - if (_table == NULL || _sourceType == sstUninitialized) + if (_table == nullptr || _sourceType == sstUninitialized) { return S_OK; } @@ -764,16 +763,16 @@ STDMETHODIMP CShapefile::EditClear(VARIANT_BOOL *retval) ErrorMessage(tkSHPFILE_NOT_IN_EDIT_MODE); return S_OK; } - + VARIANT_BOOL isEditingTable; _table->get_EditingTable(&isEditingTable); - + if( isEditingTable == FALSE ) { ErrorMessage(tkDBF_NOT_IN_EDIT_MODE); } else - { + { // deleting the labels VARIANT_BOOL bSynchronized; _labels->get_Synchronized(&bSynchronized); @@ -797,7 +796,7 @@ STDMETHODIMP CShapefile::EditClear(VARIANT_BOOL *retval) if (_useQTree) { - this->GenerateQTree(); // will clear it + this->GenerateQTree(); // will clear it } _sortingChanged = true; @@ -818,7 +817,7 @@ STDMETHODIMP CShapefile::EditClear(VARIANT_BOOL *retval) STDMETHODIMP CShapefile::get_CacheExtents(VARIANT_BOOL * pVal) { // The property no longer used - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = VARIANT_FALSE; return S_OK; } @@ -829,7 +828,7 @@ STDMETHODIMP CShapefile::get_CacheExtents(VARIANT_BOOL * pVal) STDMETHODIMP CShapefile::put_CacheExtents(VARIANT_BOOL newVal) { // The property no longer used - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return S_OK; } @@ -838,7 +837,7 @@ STDMETHODIMP CShapefile::put_CacheExtents(VARIANT_BOOL newVal) // ******************************************************************** STDMETHODIMP CShapefile::RefreshExtents(VARIANT_BOOL *retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = VARIANT_TRUE; if (!_isEditingShapes) return S_OK; @@ -852,12 +851,12 @@ STDMETHODIMP CShapefile::RefreshExtents(VARIANT_BOOL *retval) _minM = 0.0, _maxM = 0.0; bool first = true; - for( int i = 0; i < (int)_shapeData.size(); i++ ) + for( int i = 0; i < static_cast(_shapeData.size()); i++ ) { if (ShapeHelper::IsEmpty(_shapeData[i]->shape)) continue; - CShape* shp = ((CShape*)_shapeData[i]->shape); + CShape* shp = dynamic_cast(_shapeData[i]->shape); shp->get_ExtentsXYZM(Xmin, Ymin, Xmax, Ymax, Zmin, Zmax, Mmin, Mmax); // refresh shapefile extents @@ -888,7 +887,7 @@ STDMETHODIMP CShapefile::RefreshExtents(VARIANT_BOOL *retval) // ******************************************************************** STDMETHODIMP CShapefile::RefreshShapeExtents(LONG shapeId, VARIANT_BOOL *retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // The method is no longer used *retval = VARIANT_TRUE; return S_OK; @@ -901,14 +900,13 @@ STDMETHODIMP CShapefile::RefreshShapeExtents(LONG shapeId, VARIANT_BOOL *retval) // ******************************************************************** BOOL CShapefile::ReleaseMemoryShapes() { - - int size = (int)_shapeData.size(); + int size = static_cast(_shapeData.size()); for( int i = 0; i < size; i++ ) { if (_shapeData[i]->shape) { _shapeData[i]->shape->Release(); - _shapeData[i]->shape = NULL; + _shapeData[i]->shape = nullptr; } } return S_OK; @@ -923,22 +921,22 @@ BOOL CShapefile::VerifyMemShapes(ICallback * cBack) ShpfileType shapetype; long numPoints; long numParts; - IPoint * firstPnt = NULL; - IPoint * lastPnt = NULL; + IPoint * firstPnt = nullptr; + IPoint * lastPnt = nullptr; VARIANT_BOOL vbretval = VARIANT_FALSE; - + if (!_globalCallback && cBack) { _globalCallback = cBack; _globalCallback->AddRef(); } - for( int i = 0; i < (int)_shapeData.size(); i++ ) - { + for( int i = 0; i < static_cast(_shapeData.size()); i++ ) + { IShape* shp = _shapeData[i]->shape; if ( !shp ) continue; - + shp->get_ShapeType(&shapetype); // MWGIS-91 bool areEqualTypes = shapetype == _shpfiletype; @@ -949,48 +947,47 @@ BOOL CShapefile::VerifyMemShapes(ICallback * cBack) shp->get_NumParts(&numParts); if (shapetype != SHP_NULLSHAPE && !areEqualTypes) - { - + { ErrorMessage(tkINCOMPATIBLE_SHAPE_TYPE); return FALSE; } else if( shapetype == SHP_POINT || shapetype == SHP_POINTZ || shapetype == SHP_POINTM ) - { + { if( numPoints == 0 ) - { + { ShpfileType tmpshptype = SHP_NULLSHAPE; shp->put_ShapeType(tmpshptype); } } else if( shapetype == SHP_POLYLINE || shapetype == SHP_POLYLINEZ || shapetype == SHP_POLYLINEM ) - { + { if( numPoints < 2 ) - { + { ShpfileType tmpshptype = SHP_NULLSHAPE; shp->put_ShapeType(tmpshptype); } else if( numParts == 0 ) - { + { long partindex = 0; - shp->InsertPart(0,&partindex,&vbretval); + shp->InsertPart(0,&partindex,&vbretval); } } else if( shapetype == SHP_POLYGON || shapetype == SHP_POLYGONZ || shapetype == SHP_POLYGONM ) - { + { if( numPoints < 3 ) - { + { ShpfileType tmpshptype = SHP_NULLSHAPE; shp->put_ShapeType(tmpshptype); } - else - { + else + { if( numParts == 0 ) - { + { long partindex = 0; shp->InsertPart(0,&partindex,&vbretval); numParts = 1; } - + //force the first and last point of a ring to be the same long partOffset = 0; for( int p = 0; p < numParts; p++ ) @@ -1007,13 +1004,13 @@ BOOL CShapefile::VerifyMemShapes(ICallback * cBack) startRing = 0; if( endRing < startRing || endRing >= numPoints + partOffset ) endRing = numPoints + partOffset; - + shp->get_Point(startRing,&firstPnt); shp->get_Point(endRing - 1,&lastPnt); - + double x1, y1, z1; double x2, y2, z2; - + if ( firstPnt && lastPnt ) { firstPnt->get_X(&x1); @@ -1040,13 +1037,13 @@ BOOL CShapefile::VerifyMemShapes(ICallback * cBack) if ( firstPnt ) { firstPnt->Release(); - firstPnt = NULL; + firstPnt = nullptr; } if ( lastPnt ) { lastPnt->Release(); - lastPnt = NULL; + lastPnt = nullptr; } } } @@ -1069,7 +1066,7 @@ BOOL CShapefile::VerifyMemShapes(ICallback * cBack) // **************************************************************** STDMETHODIMP CShapefile::get_InteractiveEditing(VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _isEditingShapes && _interactiveEditing; return S_OK; } @@ -1079,7 +1076,7 @@ STDMETHODIMP CShapefile::get_InteractiveEditing(VARIANT_BOOL* pVal) // **************************************************************** STDMETHODIMP CShapefile::put_InteractiveEditing(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!_isEditingShapes && newVal) { // start edit mode; naturally no interactive editing without it @@ -1127,7 +1124,7 @@ bool CShapefile::ReopenFiles(bool writeMode) // **************************************************************** STDMETHODIMP CShapefile::StartAppendMode(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; @@ -1143,7 +1140,7 @@ STDMETHODIMP CShapefile::StartAppendMode(VARIANT_BOOL* retVal) return S_OK; } - _appendStartShapeCount = _shapeData.size(); + _appendStartShapeCount = static_cast(_shapeData.size()); ((CTableClass*)_table)->StartAppendMode(); @@ -1158,7 +1155,7 @@ STDMETHODIMP CShapefile::StartAppendMode(VARIANT_BOOL* retVal) // **************************************************************** STDMETHODIMP CShapefile::StopAppendMode() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_appendMode ) { @@ -1166,10 +1163,10 @@ STDMETHODIMP CShapefile::StopAppendMode() // updating shx file length fseek(_shxfile, 24, SEEK_SET); - int fileLength = HEADER_BYTES_16 + (int)_shapeData.size() * 4; // in 16 bit words + int fileLength = HEADER_BYTES_16 + static_cast(_shapeData.size()) * 4; // in 16 bit words ShapeUtility::WriteBigEndian(_shxfile, fileLength); - // bounds + // bounds fseek(_shxfile, 36, SEEK_SET); WriteBounds(_shxfile); fflush(_shxfile); @@ -1206,7 +1203,7 @@ STDMETHODIMP CShapefile::StopAppendMode() // **************************************************************** STDMETHODIMP CShapefile::get_AppendMode(VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _appendMode; diff --git a/src/COM classes/Shapefile_Geoprocessing.cpp b/src/COM classes/Shapefile_Geoprocessing.cpp index 954b626e..c8f49123 100644 --- a/src/COM classes/Shapefile_Geoprocessing.cpp +++ b/src/COM classes/Shapefile_Geoprocessing.cpp @@ -278,8 +278,7 @@ STDMETHODIMP CShapefile::SelectByShapefile(IShapefile* sf, tkSpatialRelation rel VARIANT_BOOL selectedOnly, VARIANT* arr, ICallback* cBack, VARIANT_BOOL* retval) { - - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; *retval = VARIANT_FALSE; @@ -296,7 +295,7 @@ STDMETHODIMP CShapefile::SelectByShapefile(IShapefile* sf, tkSpatialRelation rel } long _numShapes2; - const long _numShapes1 = _shapeData.size(); + const long _numShapes1 = static_cast(_shapeData.size()); sf->get_NumShapes(&_numShapes2); if (_numShapes1 == 0)return NULL; if (_numShapes2 == 0) return NULL; @@ -435,7 +434,7 @@ STDMETHODIMP CShapefile::SelectByShapefile(IShapefile* sf, tkSpatialRelation rel // no shapes fell into selection VARIANT_BOOL CShapefile::SelectShapesAlt(IExtents* boundBox, double tolerance, SelectMode selectMode, VARIANT* arr) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) double xMin, xMax, yMin, yMax, zMin, zMax; boundBox->GetBounds(&xMin, &yMin, &zMin, &xMax, &yMax, &zMax); @@ -506,7 +505,7 @@ VARIANT_BOOL CShapefile::SelectShapesAlt(IExtents* boundBox, double tolerance, S // field. Shapes with the same attribute are merged into one. STDMETHODIMP CShapefile::Dissolve(long fieldIndex, VARIANT_BOOL selectedOnly, IShapefile** sf) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) DissolveCore(fieldIndex, selectedOnly, nullptr, sf); return S_OK; } @@ -517,7 +516,7 @@ STDMETHODIMP CShapefile::Dissolve(long fieldIndex, VARIANT_BOOL selectedOnly, IS STDMETHODIMP CShapefile::DissolveWithStats(long fieldIndex, VARIANT_BOOL selectedOnly, IFieldStatOperations* statOperations, IShapefile** sf) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) DissolveCore(fieldIndex, selectedOnly, statOperations, sf); return S_OK; } @@ -679,7 +678,7 @@ void CShapefile::CalculateFieldStats(map*>& fieldMap, IFieldSta CString sSum; CComVariant var; int index = 0; - const int size = fieldMap.size(); + const int size = static_cast(fieldMap.size()); long percent = 0; map frequencies; @@ -861,7 +860,7 @@ void CShapefile::DissolveGEOS(long fieldIndex, VARIANT_BOOL selectedOnly, IField ReadGeosGeometries(selectedOnly); long percent = 0; - int size = (int)_shapeData.size(); + int size = static_cast(_shapeData.size()); for (long i = 0; i < size; i++) { CallbackHelper::Progress(_globalCallback, i, size, "Grouping shapes...", _key, percent); @@ -899,11 +898,11 @@ void CShapefile::DissolveGEOS(long fieldIndex, VARIANT_BOOL selectedOnly, IField const bool isM = ShapeUtility::IsM(_shpfiletype); - // saving results + // saving results long count = 0; // number of shapes inserted int shapeProcessed = 0; // for progress bar percent = 0; - size = shapeMap.size(); + size = static_cast(shapeMap.size()); VARIANT_BOOL vbretval; map*>::iterator p = shapeMap.begin(); @@ -981,7 +980,7 @@ void CShapefile::DissolveClipper(long fieldIndex, VARIANT_BOOL selectedOnly, IFi CComVariant val; // VARIANT hasn't got comparison operators and therefore // can't be used with associative containers long percent = 0; - const int size = (int)_shapeData.size(); + const int size = static_cast(_shapeData.size()); // std::vector polygons; std::vector polygons; polygons.resize(size, nullptr); @@ -1112,7 +1111,7 @@ void CShapefile::DissolveClipper(long fieldIndex, VARIANT_BOOL selectedOnly, IFi STDMETHODIMP CShapefile::AggregateShapesWithStats(VARIANT_BOOL selectedOnly, LONG fieldIndex, IFieldStatOperations* statOperations, IShapefile** retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) AggregateShapesCore(selectedOnly, fieldIndex, statOperations, retval); return S_OK; } @@ -1122,7 +1121,7 @@ STDMETHODIMP CShapefile::AggregateShapesWithStats(VARIANT_BOOL selectedOnly, LON // ******************************************************************** STDMETHODIMP CShapefile::AggregateShapes(VARIANT_BOOL selectedOnly, LONG fieldIndex, IShapefile** retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) AggregateShapesCore(selectedOnly, fieldIndex, nullptr, retval); return S_OK; } @@ -1191,7 +1190,7 @@ void CShapefile::AggregateShapesCore(VARIANT_BOOL selectedOnly, LONG fieldIndex, } long percent = 0; - int size = (int)_shapeData.size(); + int size = static_cast(_shapeData.size()); for (long i = 0; i < size; i++) { @@ -1236,7 +1235,7 @@ void CShapefile::AggregateShapesCore(VARIANT_BOOL selectedOnly, LONG fieldIndex, long count = 0; // number of shapes inserted int i = 0; // for progress bar percent = 0; - size = shapeMap.size(); + size = static_cast(shapeMap.size()); map*>::iterator p = shapeMap.begin(); while (p != shapeMap.end()) @@ -1381,7 +1380,7 @@ void CShapefile::AggregateShapesCore(VARIANT_BOOL selectedOnly, LONG fieldIndex, STDMETHODIMP CShapefile::BufferByDistance(double distance, LONG nSegments, VARIANT_BOOL selectedOnly, VARIANT_BOOL mergeResults, IShapefile** sf) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (mergeResults) { @@ -1430,7 +1429,7 @@ VARIANT_BOOL CShapefile::BufferByDistanceCore(double distance, LONG nSegments, V // processing // ------------------------------------------- VARIANT_BOOL vb; - const int size = _shapeData.size(); + const int size = static_cast(_shapeData.size()); long count = 0; long percent = 0; @@ -1451,7 +1450,7 @@ VARIANT_BOOL CShapefile::BufferByDistanceCore(double distance, LONG nSegments, V GEOSGeometry* oGeom1 = this->GetGeosGeometry(i); if (oGeom1) { - GEOSGeometry* oGeom2 = GeosHelper::Buffer(oGeom1, distance, (int)nSegments); + GEOSGeometry* oGeom2 = GeosHelper::Buffer(oGeom1, distance, static_cast(nSegments)); if (oGeom2 == nullptr) continue; @@ -1466,7 +1465,7 @@ VARIANT_BOOL CShapefile::BufferByDistanceCore(double distance, LONG nSegments, V if (GeosConverter::GeomToShapes(oGeom2, &vShapes, isM)) { this->InsertShapesVector(sf, vShapes, this, i, nullptr); - count += vShapes.size(); + count += static_cast(vShapes.size()); } GeosHelper::DestroyGeometry(oGeom2); } @@ -1545,7 +1544,7 @@ VARIANT_BOOL CShapefile::BufferByDistanceCore(double distance, LONG nSegments, V STDMETHODIMP CShapefile::Difference(VARIANT_BOOL selectedOnlySubject, IShapefile* sfOverlay, VARIANT_BOOL selectedOnlyOverlay, IShapefile** retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) DoClipOperation(selectedOnlySubject, sfOverlay, selectedOnlyOverlay, retval, clDifference); return S_OK; } @@ -1556,7 +1555,7 @@ STDMETHODIMP CShapefile::Difference(VARIANT_BOOL selectedOnlySubject, IShapefile STDMETHODIMP CShapefile::Clip(VARIANT_BOOL selectedOnlySubject, IShapefile* sfOverlay, VARIANT_BOOL selectedOnlyOverlay, IShapefile** retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) DoClipOperation(selectedOnlySubject, sfOverlay, selectedOnlyOverlay, retval, clClip); // enumeration should be repaired return S_OK; @@ -1569,7 +1568,7 @@ STDMETHODIMP CShapefile::GetIntersection(VARIANT_BOOL selectedOnlyOfThis, IShape VARIANT_BOOL selectedOnly, ShpfileType fileType, ICallback* cBack, IShapefile** retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) DoClipOperation(selectedOnlyOfThis, sf, selectedOnly, retval, clIntersection, fileType); return S_OK; } @@ -1580,7 +1579,7 @@ STDMETHODIMP CShapefile::GetIntersection(VARIANT_BOOL selectedOnlyOfThis, IShape STDMETHODIMP CShapefile::SymmDifference(VARIANT_BOOL selectedOnlySubject, IShapefile* sfOverlay, VARIANT_BOOL selectedOnlyOverlay, IShapefile** retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) DoClipOperation(selectedOnlySubject, sfOverlay, selectedOnlyOverlay, retval, clSymDifference); // enumeration should be repaired return S_OK; @@ -1592,7 +1591,7 @@ STDMETHODIMP CShapefile::SymmDifference(VARIANT_BOOL selectedOnlySubject, IShape STDMETHODIMP CShapefile::Union(VARIANT_BOOL selectedOnlySubject, IShapefile* sfOverlay, VARIANT_BOOL selectedOnlyOverlay, IShapefile** retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) DoClipOperation(selectedOnlySubject, sfOverlay, selectedOnlyOverlay, retval, clUnion); return S_OK; } @@ -1639,7 +1638,7 @@ ShpfileType GetClipOperationReturnType(ShpfileType type1, ShpfileType type2, tkC return type1; case clSymDifference: case clUnion: - // both types should be the same + // both types should be the same return type1; } @@ -1983,7 +1982,7 @@ void CShapefile::ClipGEOS(VARIANT_BOOL selectedOnlySubject, IShapefile* sfOverla } // extracting clip geometry - if (!((CShapefile*)sfOverlay)->ShapeAvailable(clipId, selectedOnlyOverlay)) + if (!static_cast(sfOverlay)->ShapeAvailable(clipId, selectedOnlyOverlay)) continue; GEOSGeometry* gsGeom2 = ((CShapefile*)sfOverlay)->GetGeosGeometry(clipId); @@ -1998,12 +1997,12 @@ void CShapefile::ClipGEOS(VARIANT_BOOL selectedOnlySubject, IShapefile* sfOverla GEOSGeometry* gsGeom2 = nullptr; bool deleteNeeded = false; - if ((int)vUnion.size() > 1) + if (static_cast(vUnion.size()) > 1) { gsGeom2 = GeosConverter::MergeGeometries(vUnion, nullptr, false, false); deleteNeeded = true; } - else if ((int)vUnion.size() == 1) + else if (static_cast(vUnion.size()) == 1) { gsGeom2 = vUnion[0]; } @@ -2809,14 +2808,14 @@ void CShapefile::DifferenceClipper(IShapefile* sfSubject, VARIANT_BOOL selectedO // ******************************************************************** STDMETHODIMP CShapefile::get_GeometryEngine(tkGeometryEngine* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _geometryEngine; return S_OK; } STDMETHODIMP CShapefile::put_GeometryEngine(tkGeometryEngine newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _geometryEngine = newVal; return S_OK; } @@ -2831,9 +2830,9 @@ STDMETHODIMP CShapefile::put_GeometryEngine(tkGeometryEngine newVal) // ******************************************************************** STDMETHODIMP CShapefile::PointInShape(LONG shapeIndex, DOUBLE x, DOUBLE y, VARIANT_BOOL* retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (shapeIndex < 0 || shapeIndex >= (long)_shapeData.size()) + if (shapeIndex < 0 || shapeIndex >= static_cast(_shapeData.size())) { *retval = VARIANT_FALSE; ErrorMessage(tkINDEX_OUT_OF_BOUNDS); @@ -2986,9 +2985,9 @@ STDMETHODIMP CShapefile::PointInShape(LONG shapeIndex, DOUBLE x, DOUBLE y, VARIA // ******************************************************************** STDMETHODIMP CShapefile::PointInShapefile(DOUBLE x, DOUBLE y, LONG* shapeIndex) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - const int nShapeCount = _polySf.size(); + const int nShapeCount = static_cast(_polySf.size()); for (int nShape = nShapeCount - 1; nShape >= 0; nShape--) // for(int nShape = 0; nShape < ShapeCount; nShape++) see http://www.mapwindow.org/phorum/read.php?3,9745,9950#msg-9950 { @@ -3078,7 +3077,7 @@ STDMETHODIMP CShapefile::PointInShapefile(DOUBLE x, DOUBLE y, LONG* shapeIndex) // ******************************************************************** STDMETHODIMP CShapefile::BeginPointInShapefile(VARIANT_BOOL* retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_writing) { //AfxMessageBox("Can't read"); @@ -3096,7 +3095,7 @@ STDMETHODIMP CShapefile::BeginPointInShapefile(VARIANT_BOOL* retval) CSingleLock lock(&_readLock, TRUE); - const int size = _shapeData.size(); + const int size = static_cast(_shapeData.size()); _polySf.resize(size); for (int nShape = 0; nShape < size; nShape++) @@ -3138,7 +3137,7 @@ STDMETHODIMP CShapefile::BeginPointInShapefile(VARIANT_BOOL* retval) // ******************************************************************** STDMETHODIMP CShapefile::EndPointInShapefile() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _polySf.clear(); @@ -3225,7 +3224,7 @@ VARIANT_BOOL CShapefile::ExplodeShapesCore(VARIANT_BOOL selectedOnly, IShapefile // ******************************************************************** STDMETHODIMP CShapefile::ExplodeShapes(VARIANT_BOOL selectedOnly, IShapefile** retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) Clone(retval); @@ -3259,7 +3258,7 @@ VARIANT_BOOL CShapefile::ExportSelectionCore(IShapefile* result) VARIANT_BOOL vbretval; - const long numShapes = _shapeData.size(); + const long numShapes = static_cast(_shapeData.size()); long count = 0; CComVariant var; @@ -3318,7 +3317,7 @@ VARIANT_BOOL CShapefile::ExportSelectionCore(IShapefile* result) // ******************************************************************** STDMETHODIMP CShapefile::ExportSelection(IShapefile** retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) Clone(retval); @@ -3336,7 +3335,7 @@ STDMETHODIMP CShapefile::ExportSelection(IShapefile** retval) // ******************************************************************** STDMETHODIMP CShapefile::Sort(LONG fieldIndex, VARIANT_BOOL ascending, IShapefile** retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; // ---------------------------------------------- @@ -3356,7 +3355,7 @@ STDMETHODIMP CShapefile::Sort(LONG fieldIndex, VARIANT_BOOL ascending, IShapefil LONG numFields; this->get_NumFields(&numFields); - const long numShapes = _shapeData.size(); + const long numShapes = static_cast(_shapeData.size()); multimap shapeMap; CComVariant val; @@ -3427,7 +3426,7 @@ STDMETHODIMP CShapefile::Sort(LONG fieldIndex, VARIANT_BOOL ascending, IShapefil STDMETHODIMP CShapefile::Merge(VARIANT_BOOL selectedOnlyThis, IShapefile* sf, VARIANT_BOOL selectedOnly, IShapefile** retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; if (sf == nullptr) @@ -3436,7 +3435,7 @@ STDMETHODIMP CShapefile::Merge(VARIANT_BOOL selectedOnlyThis, IShapefile* sf, VA return S_OK; } - const long numShapes1 = _shapeData.size(); + const long numShapes1 = static_cast(_shapeData.size()); long numShapes2; sf->get_NumShapes(&numShapes2); @@ -3590,7 +3589,7 @@ STDMETHODIMP CShapefile::Merge(VARIANT_BOOL selectedOnlyThis, IShapefile* sf, VA // ********************************************************************** STDMETHODIMP CShapefile::SimplifyLines(DOUBLE tolerance, VARIANT_BOOL selectedOnly, IShapefile** retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; // ---------------------------------------------- @@ -3622,7 +3621,7 @@ STDMETHODIMP CShapefile::SimplifyLines(DOUBLE tolerance, VARIANT_BOOL selectedOn // long index = 0; long percent = 0; - const int numShapes = (int)_shapeData.size(); + const int numShapes = static_cast(_shapeData.size()); for (int i = 0; i < numShapes; i++) { CallbackHelper::Progress(_globalCallback, i, numShapes, "Calculating...", _key, percent); @@ -3695,7 +3694,7 @@ STDMETHODIMP CShapefile::SimplifyLines(DOUBLE tolerance, VARIANT_BOOL selectedOn // ********************************************************************** STDMETHODIMP CShapefile::Segmentize(double metersTolerance, IShapefile** retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // ---------------------------------------------- // Validating @@ -3725,7 +3724,7 @@ STDMETHODIMP CShapefile::Segmentize(double metersTolerance, IShapefile** retVal) // turns on the quad tree this->GenerateTempQTree(false); - const long shapeCount = _shapeData.size(); + const long shapeCount = static_cast(_shapeData.size()); long percent = 0; // get 'meters' in units of the Shapefile @@ -3858,7 +3857,7 @@ Coloring::ColorGraph* CShapefile::GeneratePolygonColors() QTree* tree = GetTempQTree(); ReadGeosGeometries(VARIANT_FALSE); - const long numShapes = _shapeData.size(); + const long numShapes = static_cast(_shapeData.size()); long percent = 0; auto* graph = new Coloring::ColorGraph(); @@ -3868,17 +3867,17 @@ Coloring::ColorGraph* CShapefile::GeneratePolygonColors() // --------------------------------------- for (size_t i = 0; i < _shapeData.size(); i++) { - CallbackHelper::Progress(_globalCallback, i, numShapes, "Calculating spatial relations...", _key, percent); + CallbackHelper::Progress(_globalCallback, static_cast(i), numShapes, "Calculating spatial relations...", _key, percent); double xMin, xMax, yMin, yMax; - this->QuickExtentsCore(i, &xMin, &yMin, &xMax, &yMax); + this->QuickExtentsCore(static_cast(i), &xMin, &yMin, &xMax, &yMax); vector shapeIds = tree->GetNodes(QTreeExtent(xMin, xMax, yMax, yMin)); - graph->InsertNode(i); + graph->InsertNode(static_cast(i)); if (!shapeIds.empty()) { - GEOSGeometry* geom = GetGeosGeometry(i); + GEOSGeometry* geom = GetGeosGeometry(static_cast(i)); if (geom) { for (int shapeId : shapeIds) @@ -3917,7 +3916,7 @@ Coloring::ColorGraph* CShapefile::GeneratePolygonColors() } if (commonEdge) { - graph->InsertEdge(i, shapeId, angle); + graph->InsertEdge(static_cast(i), shapeId, angle); } } } diff --git a/src/COM classes/Shapefile_ReadWrite.cpp b/src/COM classes/Shapefile_ReadWrite.cpp index 72443761..d012954d 100644 --- a/src/COM classes/Shapefile_ReadWrite.cpp +++ b/src/COM classes/Shapefile_ReadWrite.cpp @@ -37,10 +37,10 @@ STDMETHODIMP CShapefile::get_Shape(long shapeIndex, IShape **pVal) VARIANT_BOOL vbretval = VARIANT_FALSE; // out of bounds? - if( shapeIndex < 0 || shapeIndex >= (long)_shapeData.size()) + if( shapeIndex < 0 || shapeIndex >= static_cast(_shapeData.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); - *pVal = NULL; + *pVal = nullptr; return S_OK; } @@ -78,7 +78,7 @@ IShape* CShapefile::ReadFastModeShape(long shapeIndex) if (index != shapeIndex + 1) { ErrorMessage(tkINVALID_SHP_FILE); - return NULL; + return nullptr; } int contentLength = ShapeUtility::ReadIntBigEndian(_shpfile) * 2; @@ -88,17 +88,17 @@ IShape* CShapefile::ReadFastModeShape(long shapeIndex) int length = contentLength; //- 2 * sizeof(int); char* data = new char[length]; - int count = (int)fread(data, sizeof(char), length, _shpfile); + int count = static_cast(fread(data, sizeof(char), length, _shpfile)); if (count != length) { delete[] data; - return NULL; + return nullptr; } - IShape* shape = NULL; + IShape* shape = nullptr; - if (data != NULL) + if (data != nullptr) { ComHelper::CreateShape(&shape); shape->put_GlobalCallback(_globalCallback); @@ -114,9 +114,6 @@ IShape* CShapefile::ReadFastModeShape(long shapeIndex) // ************************************************************ IShape* CShapefile::ReadComShape(long shapeIndex) { - if (_shpOffsets.empty()) - return nullptr; - // read the shp from disk fseek(_shpfile, _shpOffsets[shapeIndex], SEEK_SET); @@ -128,7 +125,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (intbuf != shapeIndex + 1 && intbuf != shapeIndex) { ErrorMessage(tkINVALID_SHP_FILE); - return NULL; + return nullptr; } fread(&intbuf, sizeof(int), 1, _shpfile); @@ -139,8 +136,8 @@ IShape* CShapefile::ReadComShape(long shapeIndex) ShpfileType shpType = (ShpfileType)intbuf; - IShape * shape = NULL; - IPoint * pnt = NULL; + IShape * shape = nullptr; + IPoint * pnt = nullptr; VARIANT_BOOL vbretval; #pragma region Nullshape Or Mismatch @@ -159,7 +156,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (shpType != SHP_NULLSHAPE) { ErrorMessage(tkINVALID_SHP_FILE); - return NULL; + return nullptr; } else { @@ -171,7 +168,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) else if (shpType != SHP_NULLSHAPE && !areEqualTypes) { ErrorMessage(tkINVALID_SHP_FILE); - return NULL; + return nullptr; } #pragma endregion @@ -202,7 +199,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (vbretval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } pnt->Release(); } @@ -238,7 +235,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (vbretval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } pnt->Release(); } @@ -272,7 +269,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (vbretval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } pnt->Release(); } @@ -315,7 +312,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } } @@ -333,7 +330,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } pnt->Release(); } @@ -375,7 +372,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } } @@ -394,7 +391,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } pnt->Release(); } @@ -406,12 +403,12 @@ IShape* CShapefile::ReadComShape(long shapeIndex) { fread(&z, sizeof(double), 1, _shpfile); pointIndex = k; - IPoint * pnt = NULL; + IPoint * pnt = nullptr; shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) + if (pnt == nullptr) { shape->Release(); - return NULL; + return nullptr; } pnt->put_Z(z); pnt->Release(); @@ -424,12 +421,12 @@ IShape* CShapefile::ReadComShape(long shapeIndex) { fread(&m, sizeof(double), 1, _shpfile); pointIndex = mc; - IPoint * pnt = NULL; + IPoint * pnt = nullptr; shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) + if (pnt == nullptr) { shape->Release(); - return NULL; + return nullptr; } pnt->put_M(m); //Rob Cairns 20-Dec-05 @@ -474,7 +471,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } } @@ -493,7 +490,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } pnt->Release(); } @@ -505,12 +502,12 @@ IShape* CShapefile::ReadComShape(long shapeIndex) { fread(&m, sizeof(double), 1, _shpfile); pointIndex = mc; - IPoint * pnt = NULL; + IPoint * pnt = nullptr; shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) + if (pnt == nullptr) { shape->Release(); - return NULL; + return nullptr; } pnt->put_M(m); pnt->Release(); @@ -556,7 +553,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } } @@ -574,7 +571,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } pnt->Release(); } @@ -616,7 +613,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } } @@ -635,7 +632,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } pnt->Release(); } @@ -647,12 +644,12 @@ IShape* CShapefile::ReadComShape(long shapeIndex) { fread(&z, sizeof(double), 1, _shpfile); pointIndex = k; - IPoint * pnt = NULL; + IPoint * pnt = nullptr; shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) + if (pnt == nullptr) { shape->Release(); - return NULL; + return nullptr; } pnt->put_Z(z); pnt->Release(); @@ -665,12 +662,12 @@ IShape* CShapefile::ReadComShape(long shapeIndex) { fread(&m, sizeof(double), 1, _shpfile); pointIndex = mc; - IPoint * pnt = NULL; + IPoint * pnt = nullptr; shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) + if (pnt == nullptr) { shape->Release(); - return NULL; + return nullptr; } pnt->put_M(m); pnt->Release(); @@ -713,7 +710,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } } @@ -732,7 +729,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } pnt->Release(); } @@ -745,12 +742,12 @@ IShape* CShapefile::ReadComShape(long shapeIndex) { fread(&m, sizeof(double), 1, _shpfile); pointIndex = mc; - IPoint * pnt = NULL; + IPoint * pnt = nullptr; shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) + if (pnt == nullptr) { shape->Release(); - return NULL; + return nullptr; } pnt->put_M(m); pnt->Release(); @@ -797,7 +794,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } pnt->Release(); } @@ -842,7 +839,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } pnt->Release(); } @@ -854,12 +851,12 @@ IShape* CShapefile::ReadComShape(long shapeIndex) { fread(&z, sizeof(double), 1, _shpfile); pointIndex = k; - IPoint * pnt = NULL; + IPoint * pnt = nullptr; shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) + if (pnt == nullptr) { shape->Release(); - return NULL; + return nullptr; } pnt->put_Z(z); pnt->Release(); @@ -872,12 +869,12 @@ IShape* CShapefile::ReadComShape(long shapeIndex) { fread(&m, sizeof(double), 1, _shpfile); pointIndex = mc; - IPoint * pnt = NULL; + IPoint * pnt = nullptr; shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) + if (pnt == nullptr) { shape->Release(); - return NULL; + return nullptr; } pnt->put_M(m); pnt->Release(); @@ -923,7 +920,7 @@ IShape* CShapefile::ReadComShape(long shapeIndex) if (retval == VARIANT_FALSE) { shape->Release(); - return NULL; + return nullptr; } pnt->Release(); } @@ -935,12 +932,12 @@ IShape* CShapefile::ReadComShape(long shapeIndex) { fread(&m, sizeof(double), 1, _shpfile); pointIndex = mc; - IPoint * pnt = NULL; + IPoint * pnt = nullptr; shape->get_Point(pointIndex, &pnt); - if (pnt == NULL) + if (pnt == nullptr) { shape->Release(); - return NULL; + return nullptr; } pnt->put_M(m); pnt->Release(); @@ -1064,7 +1061,7 @@ BOOL CShapefile::WriteShx(FILE * shx, ICallback * cBack) } // FILELENGTH (16 bit words) - int fileLength = HEADER_BYTES_16 + (int)_shapeData.size() * 4; + int fileLength = HEADER_BYTES_16 + static_cast(_shapeData.size()) * 4; ShapeUtility::WriteBigEndian(shx, fileLength); //VERSION @@ -1082,12 +1079,12 @@ BOOL CShapefile::WriteShx(FILE * shx, ICallback * cBack) long numPoints = 0; long numParts = 0; ShpfileType shptype; - IShape * shape = NULL; + IShape * shape = nullptr; long percent = 0, newpercent = 0; _shpOffsets.clear(); - int size = (int)_shapeData.size(); + int size = static_cast(_shapeData.size()); for( int i = 0; i < size; i++) { // convert to (32 bit words) @@ -1129,7 +1126,7 @@ BOOL CShapefile::WriteShx(FILE * shx, ICallback * cBack) // ************************************************************** int CShapefile::GetWriteFileLength() { - IShape * sh = NULL; + IShape * sh = nullptr; long numPoints = 0; long numParts = 0; long part = 0; @@ -1163,7 +1160,7 @@ bool CShapefile::AppendToShpFile(FILE* shp, IShapeWrapper* wrapper) int length = wrapper->get_ContentLength(); // write record header - ShapeUtility::WriteBigEndian(shp, _shapeData.size()); + ShapeUtility::WriteBigEndian(shp, static_cast(_shapeData.size())); ShapeUtility::WriteBigEndian(shp, length / 2); // write content @@ -1239,9 +1236,9 @@ BOOL CShapefile::WriteShp(FILE * shp, ICallback * cBack) long numPoints = 0; long numParts = 0; long part = 0; - IShape * sh = NULL; + IShape * sh = nullptr; - int size = _shapeData.size(); + int size = static_cast(_shapeData.size()); for( int k = 0; k < size; k++) { diff --git a/src/COM classes/Shapefile_Selection.cpp b/src/COM classes/Shapefile_Selection.cpp index 0efe36f4..223653da 100644 --- a/src/COM classes/Shapefile_Selection.cpp +++ b/src/COM classes/Shapefile_Selection.cpp @@ -37,7 +37,7 @@ CMutex selectShapesMutex(FALSE); STDMETHODIMP CShapefile::SelectShapes(IExtents* boundBox, const double tolerance, const SelectMode selectMode, VARIANT* result, VARIANT_BOOL* retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = VARIANT_FALSE; @@ -138,7 +138,7 @@ bool CShapefile::SelectShapesCore(Extent& extents, const double tolerance, const qtreeResult = _qtree->GetNodes(QTreeExtent(bMinX, bMaxX, bMaxY, bMinY)); } - localNumShapes = qtreeResult.size(); + localNumShapes = static_cast(qtreeResult.size()); useQTreeResults = true; } @@ -311,7 +311,7 @@ bool CShapefile::SelectShapesCore(Extent& extents, const double tolerance, const { if (this->DefineShapePoints(shapeVal, shapeType, parts, xPts, yPts) != FALSE) { - const long numpoints = xPts.size(); + const long numpoints = static_cast(xPts.size()); bool addShape = false; for (int j = 0; j < numpoints; j++) { @@ -360,7 +360,7 @@ bool CShapefile::SelectShapesCore(Extent& extents, const double tolerance, const // Returns and sets the selection state for a shape. STDMETHODIMP CShapefile::get_ShapeSelected(const long shapeIndex, VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (shapeIndex < 0 || shapeIndex >= gsl::narrow_cast(_shapeData.size())) { @@ -375,7 +375,7 @@ STDMETHODIMP CShapefile::get_ShapeSelected(const long shapeIndex, VARIANT_BOOL* } STDMETHODIMP CShapefile::put_ShapeSelected(const long shapeIndex, const VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (shapeIndex < 0 || shapeIndex >= gsl::narrow_cast(_shapeData.size())) { @@ -393,7 +393,7 @@ STDMETHODIMP CShapefile::put_ShapeSelected(const long shapeIndex, const VARIANT_ // ************************************************************* STDMETHODIMP CShapefile::get_NumSelected(long* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) long count = 0; for (const auto& i : _shapeData) @@ -410,7 +410,7 @@ STDMETHODIMP CShapefile::get_NumSelected(long* pVal) // ************************************************************* STDMETHODIMP CShapefile::SelectAll() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) for (const auto& i : _shapeData) { @@ -425,7 +425,7 @@ STDMETHODIMP CShapefile::SelectAll() // ************************************************************* STDMETHODIMP CShapefile::SelectNone() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) for (const auto& i : _shapeData) { @@ -440,7 +440,7 @@ STDMETHODIMP CShapefile::SelectNone() // ************************************************************* STDMETHODIMP CShapefile::InvertSelection() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) for (const auto& i : _shapeData) { @@ -521,7 +521,7 @@ BOOL CShapefile::DefineShapePoints(const long shapeIndex, ShpfileType& shapeType if (numPoints < 2) return FALSE; - // fill up parts: polyline must have at least 1 part + // fill up parts: polyline must have at least 1 part if (numParts > 0) { for (int p = 0; p < numParts; p++) @@ -549,7 +549,7 @@ BOOL CShapefile::DefineShapePoints(const long shapeIndex, ShpfileType& shapeType if (numPoints < 2) return FALSE; - // fill up parts: polygon must have at least 1 part + // fill up parts: polygon must have at least 1 part if (numParts > 0) { for (int p = 0; p < numParts; p++) diff --git a/src/COM classes/TableClass.cpp b/src/COM classes/TableClass.cpp index 808f8e3e..a025c6ad 100644 --- a/src/COM classes/TableClass.cpp +++ b/src/COM classes/TableClass.cpp @@ -58,7 +58,6 @@ void CTableClass::ParseExpressionCore(BSTR Expression, tkValueType returnType, C return; } - if (!expr.Parse(str, true, errorString)) { return; @@ -77,7 +76,7 @@ void CTableClass::ParseExpressionCore(BSTR Expression, tkValueType returnType, C { if (returnType == vtString) { - // there is no problem to convert any type to string + // there is no problem to convert any type to string *retVal = VARIANT_TRUE; } else @@ -96,7 +95,7 @@ void CTableClass::ParseExpressionCore(BSTR Expression, tkValueType returnType, C // Checks the correctness of the expression syntax, but doesn't check the validity of data types STDMETHODIMP CTableClass::ParseExpression(BSTR Expression, BSTR* ErrorString, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; @@ -131,7 +130,7 @@ STDMETHODIMP CTableClass::ParseExpression(BSTR Expression, BSTR* ErrorString, VA // Checks syntax of expression and data types based on the first record in the table STDMETHODIMP CTableClass::TestExpression(BSTR Expression, tkValueType ReturnType, BSTR* ErrorString, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) CStringW err; ParseExpressionCore(Expression, ReturnType, err, retVal); @@ -158,7 +157,7 @@ STDMETHODIMP CTableClass::Query(BSTR Expression, VARIANT* Result, BSTR* ErrorStr if (indices.size() == 0) { *ErrorString = SysAllocString(L"Selection is empty"); - Result = NULL; + Result = nullptr; } else { @@ -178,8 +177,8 @@ STDMETHODIMP CTableClass::Query(BSTR Expression, VARIANT* Result, BSTR* ErrorStr // ***************************************************************** STDMETHODIMP CTableClass::Calculate(BSTR Expression, LONG RowIndex, VARIANT* Result, BSTR* ErrorString, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - USES_CONVERSION; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + USES_CONVERSION; *retVal = VARIANT_FALSE; Result->vt = VT_NULL; @@ -271,7 +270,7 @@ bool CTableClass::CalculateCoreRaw(CStringW Expression, CStringW str; int start = (startRowIndex == -1) ? 0 : startRowIndex; - int end = (endRowIndex == -1) ? int(_rows.size()) : endRowIndex + 1; + int end = (endRowIndex == -1) ? static_cast(_rows.size()) : endRowIndex + 1; for (int i = start; i < end; i++) { @@ -398,11 +397,11 @@ STDMETHODIMP CTableClass::get_NumFields(long *pVal) STDMETHODIMP CTableClass::get_Field(long FieldIndex, IField **pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; - if (FieldIndex < 0 || FieldIndex >= (int)FieldCount()) + if (FieldIndex < 0 || FieldIndex >= static_cast(FieldCount())) { - *pVal = NULL; + *pVal = nullptr; ErrorMessage(tkINDEX_OUT_OF_BOUNDS); } else @@ -421,20 +420,20 @@ STDMETHODIMP CTableClass::get_CellValue(long FieldIndex, long RowIndex, VARIANT { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (FieldIndex < 0 || FieldIndex >= FieldCount() || RowIndex < 0 || RowIndex >= RowCount()) - { - VARIANT var; - VariantInit(&var); - var.vt = VT_EMPTY; - pVal = &var; - ErrorMessage(tkINDEX_OUT_OF_BOUNDS); - return S_OK; - } + if (FieldIndex < 0 || FieldIndex >= FieldCount() || RowIndex < 0 || RowIndex >= RowCount()) + { + VARIANT var; + VariantInit(&var); + var.vt = VT_EMPTY; + pVal = &var; + ErrorMessage(tkINDEX_OUT_OF_BOUNDS); + return S_OK; + } - if (ReadRecord(RowIndex) && _rows[RowIndex].row != NULL) + if (ReadRecord(RowIndex) && _rows[RowIndex].row != nullptr) { VARIANT* var = _rows[RowIndex].row->values[FieldIndex]; - if (var != NULL) + if (var != nullptr) { if (var->vt != VT_NULL) { @@ -450,7 +449,7 @@ STDMETHODIMP CTableClass::get_CellValue(long FieldIndex, long RowIndex, VARIANT return S_OK; } } - pVal = NULL; + pVal = nullptr; return S_OK; } @@ -460,7 +459,7 @@ STDMETHODIMP CTableClass::get_CellValue(long FieldIndex, long RowIndex, VARIANT STDMETHODIMP CTableClass::get_EditingTable(VARIANT_BOOL *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *pVal = _isEditingTable ? VARIANT_TRUE : VARIANT_FALSE; + *pVal = _isEditingTable ? VARIANT_TRUE : VARIANT_FALSE; return S_OK; } @@ -470,7 +469,7 @@ STDMETHODIMP CTableClass::get_EditingTable(VARIANT_BOOL *pVal) STDMETHODIMP CTableClass::get_LastErrorCode(long *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *pVal = _lastErrorCode; + *pVal = _lastErrorCode; _lastErrorCode = tkNO_ERROR; return S_OK; } @@ -481,7 +480,7 @@ STDMETHODIMP CTableClass::get_LastErrorCode(long *pVal) STDMETHODIMP CTableClass::get_ErrorMsg(long ErrorCode, BSTR *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; *pVal = A2BSTR(ErrorMsg(ErrorCode)); return S_OK; } @@ -492,7 +491,7 @@ STDMETHODIMP CTableClass::get_ErrorMsg(long ErrorCode, BSTR *pVal) STDMETHODIMP CTableClass::get_CdlgFilter(BSTR *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; *pVal = A2BSTR("dBase Files (*.dbf)|*.dbf"); return S_OK; } @@ -503,7 +502,7 @@ STDMETHODIMP CTableClass::get_CdlgFilter(BSTR *pVal) STDMETHODIMP CTableClass::get_GlobalCallback(ICallback **pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *pVal = _globalCallback; + *pVal = _globalCallback; if (_globalCallback) _globalCallback->AddRef(); return S_OK; @@ -511,7 +510,7 @@ STDMETHODIMP CTableClass::get_GlobalCallback(ICallback **pVal) STDMETHODIMP CTableClass::put_GlobalCallback(ICallback *newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - ComHelper::SetRef(newVal, (IDispatch**)&_globalCallback); + ComHelper::SetRef(newVal, (IDispatch**)&_globalCallback); return S_OK; } @@ -521,7 +520,7 @@ STDMETHODIMP CTableClass::put_GlobalCallback(ICallback *newVal) STDMETHODIMP CTableClass::get_Key(BSTR *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; *pVal = OLE2BSTR(_key); return S_OK; } @@ -529,7 +528,7 @@ STDMETHODIMP CTableClass::get_Key(BSTR *pVal) STDMETHODIMP CTableClass::put_Key(BSTR newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; ::SysFreeString(_key); _key = OLE2BSTR(newVal); return S_OK; @@ -541,10 +540,10 @@ STDMETHODIMP CTableClass::put_Key(BSTR newVal) STDMETHODIMP CTableClass::Open(BSTR dbfFilename, ICallback *cBack, VARIANT_BOOL *retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; *retval = VARIANT_FALSE; - if ((cBack != NULL) && (_globalCallback == NULL)) + if ((cBack != nullptr) && (_globalCallback == nullptr)) { _globalCallback = cBack; cBack->AddRef(); @@ -575,11 +574,11 @@ STDMETHODIMP CTableClass::Open(BSTR dbfFilename, ICallback *cBack, VARIANT_BOOL _dbfHandle = DBFOpen_MW(name, "rb+"); } - if (_dbfHandle == NULL) { + if (_dbfHandle == nullptr) { _dbfHandle = DBFOpen_MW(name, "rb"); } - if (_dbfHandle == NULL) + if (_dbfHandle == nullptr) { ErrorMessage(tkCANT_OPEN_DBF); return S_OK; @@ -602,7 +601,7 @@ STDMETHODIMP CTableClass::Open(BSTR dbfFilename, ICallback *cBack, VARIANT_BOOL STDMETHODIMP CTableClass::CreateNew(BSTR dbfFilename, VARIANT_BOOL *retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; // closing the existing table this->Close(retval); @@ -633,10 +632,10 @@ STDMETHODIMP CTableClass::CreateNew(BSTR dbfFilename, VARIANT_BOOL *retval) void CTableClass::CloseUnderlyingFile() { _filename = L""; - if (_dbfHandle != NULL) + if (_dbfHandle != nullptr) { DBFClose(_dbfHandle); - _dbfHandle = NULL; + _dbfHandle = nullptr; } } @@ -647,7 +646,7 @@ bool CTableClass::WriteAppendedRow() { if (_rows.size() == 0 || _rows.size() == _appendStartShapeCount) return false; - int rowIndex = _rows.size() - 1; + int rowIndex = static_cast(_rows.size()) - 1; if (!WriteRecord(_dbfHandle, rowIndex, rowIndex)) { @@ -681,7 +680,7 @@ void CTableClass::StopAppendMode() Close(&vb); // _appendMode will be set to false here CComBSTR bstr(filename); - Open(bstr, NULL, &vb); + Open(bstr, nullptr, &vb); } } @@ -693,13 +692,13 @@ bool CTableClass::SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; - if (_globalCallback == NULL && cBack != NULL) + if (_globalCallback == nullptr && cBack != nullptr) { _globalCallback = cBack; cBack->AddRef(); } - if (_dbfHandle == NULL && _isEditingTable == FALSE) + if (_dbfHandle == nullptr && _isEditingTable == FALSE) { ErrorMessage(_lastErrorCode); return false; @@ -712,7 +711,7 @@ bool CTableClass::SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace } DBFInfo * newdbfHandle = DBFCreate_MW(dbfFilename); - if (newdbfHandle == NULL) + if (newdbfHandle == nullptr) { ErrorMessage(tkCANT_CREATE_DBF); return false; @@ -727,7 +726,7 @@ bool CTableClass::SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace for (int i = 0; i < FieldCount(); i++) { - IField * field = NULL; + IField * field = nullptr; this->get_Field(i, &field); CComBSTR fname; FieldType type; @@ -798,7 +797,7 @@ bool CTableClass::SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace //if updating existing file, only write out modified records if (updateFileInPlace && - (_rows[rowIndex].row == NULL || _rows[rowIndex].row->status() != TableRow::DATA_MODIFIED)) + (_rows[rowIndex].row == nullptr || _rows[rowIndex].row->status() != TableRow::DATA_MODIFIED)) { currentRowIndex++; continue; @@ -826,7 +825,7 @@ bool CTableClass::SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace // Set byte 29 to 0x00 in the .dbf file (Codepage mark) to make ReadRecord() treat text as UTF-8. FILE* dbfFile = _wfopen(dbfFilename, L"r+"); - if (dbfFile != NULL) { + if (dbfFile != nullptr) { fseek(dbfFile, 29, SEEK_SET); fputc('\0', dbfFile); fflush(dbfFile); @@ -876,10 +875,10 @@ void CTableClass::ClearFields() { for (int i = 0; i < FieldCount(); i++) { - if (_fields[i]->field != NULL) + if (_fields[i]->field != nullptr) { // if the field is used somewhere else, we must not refer to this table - is it really needed ? - ((CField*)_fields[i]->field)->SetTable(NULL); + ((CField*)_fields[i]->field)->SetTable(nullptr); } delete _fields[i]; } @@ -893,7 +892,7 @@ STDMETHODIMP CTableClass::Close(VARIANT_BOOL *retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retval = VARIANT_TRUE; + *retval = VARIANT_TRUE; StopAllJoins(); @@ -910,10 +909,10 @@ STDMETHODIMP CTableClass::Close(VARIANT_BOOL *retval) _filename = L""; - if (_dbfHandle != NULL) + if (_dbfHandle != nullptr) { DBFClose(_dbfHandle); - _dbfHandle = NULL; + _dbfHandle = nullptr; } return S_OK; @@ -926,7 +925,7 @@ void CTableClass::LoadDefaultFields() { USES_CONVERSION; - if (_dbfHandle == NULL) return; + if (_dbfHandle == nullptr) return; for (size_t i = 0; i < _fields.size(); i++) // clear only for disk-based table; otherwise there is no way to restore them delete _fields[i]; @@ -936,13 +935,13 @@ void CTableClass::LoadDefaultFields() char * fname = new char[MAX_BUFFER]; int fwidth, fdecimals; DBFFieldType type; - IField * field = NULL; + IField * field = nullptr; for (long i = 0; i < num_fields; i++) { type = DBFGetFieldInfo(_dbfHandle, i, fname, &fwidth, &fdecimals); - CoCreateInstance(CLSID_Field, NULL, CLSCTX_INPROC_SERVER, IID_IField, (void**)&field); + CoCreateInstance(CLSID_Field, nullptr, CLSCTX_INPROC_SERVER, IID_IField, (void**)&field); field->put_GlobalCallback(_globalCallback); CComBSTR bstrName(fname); field->put_Name(bstrName); @@ -959,8 +958,8 @@ void CTableClass::LoadDefaultFields() ((CField*)field)->SetTable(this); } - if (fname != NULL) delete[] fname; - fname = NULL; + if (fname != nullptr) delete[] fname; + fname = nullptr; } // ************************************************************** @@ -970,7 +969,7 @@ void CTableClass::ClearRows() { for (int j = 0; j < RowCount(); j++) { - if (_rows[j].row != NULL) { + if (_rows[j].row != nullptr) { delete _rows[j].row; } } @@ -986,7 +985,7 @@ void CTableClass::LoadDefaultRows() { ClearRows(); - if (_dbfHandle == NULL) return; + if (_dbfHandle == nullptr) return; long num_rows = DBFGetRecordCount(_dbfHandle); @@ -994,7 +993,7 @@ void CTableClass::LoadDefaultRows() { RecordWrapper rw; rw.oldIndex = i; - rw.row = NULL; + rw.row = nullptr; _rows.push_back(rw); } } @@ -1007,7 +1006,7 @@ STDMETHODIMP CTableClass::EditClear(VARIANT_BOOL *retval) //Reset all editing bits and reload original _fields info and reinitialize the RowWrapper array AFX_MANAGE_STATE(AfxGetStaticModuleState()) - LoadDefaultFields(); + LoadDefaultFields(); LoadDefaultRows(); m_needToSaveAsNewFile = false; @@ -1022,9 +1021,9 @@ STDMETHODIMP CTableClass::EditClear(VARIANT_BOOL *retval) STDMETHODIMP CTableClass::EditInsertField(IField *Field, long *FieldIndex, ICallback *cBack, VARIANT_BOOL *retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retval = VARIANT_FALSE; + *retval = VARIANT_FALSE; - if (cBack != NULL && _globalCallback == NULL) + if (cBack != nullptr && _globalCallback == nullptr) { _globalCallback = cBack; cBack->AddRef(); @@ -1043,7 +1042,7 @@ STDMETHODIMP CTableClass::EditInsertField(IField *Field, long *FieldIndex, ICall } else if (*FieldIndex > FieldCount()) { - *FieldIndex = _fields.size(); + *FieldIndex = static_cast(_fields.size()); } FieldType type; @@ -1051,10 +1050,10 @@ STDMETHODIMP CTableClass::EditInsertField(IField *Field, long *FieldIndex, ICall for (long i = 0; i < RowCount(); i++) { - if (_rows[i].row == NULL) + if (_rows[i].row == nullptr) ReadRecord(i); - VARIANT * val = NULL; + VARIANT * val = nullptr; val = new VARIANT; VariantInit(val); @@ -1092,11 +1091,11 @@ STDMETHODIMP CTableClass::EditReplaceField(long FieldIndex, IField *newField, IC { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (FieldIndex < 0 || FieldIndex >= (int)_fields.size()) - { - ErrorMessage(tkINDEX_OUT_OF_BOUNDS); - return S_OK; - } + if (FieldIndex < 0 || FieldIndex >= static_cast(_fields.size())) + { + ErrorMessage(tkINDEX_OUT_OF_BOUNDS); + return S_OK; + } if (_fields[FieldIndex]->field == newField) { @@ -1122,9 +1121,9 @@ STDMETHODIMP CTableClass::EditReplaceField(long FieldIndex, IField *newField, IC STDMETHODIMP CTableClass::EditDeleteField(long FieldIndex, ICallback *cBack, VARIANT_BOOL *retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retval = VARIANT_FALSE; + *retval = VARIANT_FALSE; - if (_globalCallback == NULL && cBack != NULL) + if (_globalCallback == nullptr && cBack != nullptr) { _globalCallback = cBack; _globalCallback->AddRef(); @@ -1136,7 +1135,7 @@ STDMETHODIMP CTableClass::EditDeleteField(long FieldIndex, ICallback *cBack, VAR return S_OK; } - if (FieldIndex < 0 || FieldIndex >= (int)_fields.size()) + if (FieldIndex < 0 || FieldIndex >= static_cast(_fields.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); return S_OK; @@ -1144,10 +1143,10 @@ STDMETHODIMP CTableClass::EditDeleteField(long FieldIndex, ICallback *cBack, VAR for (long i = 0; i < RowCount(); i++) { - if (_rows[i].row != NULL && _rows[i].row->values[FieldIndex] != NULL) + if (_rows[i].row != nullptr && _rows[i].row->values[FieldIndex] != nullptr) { VariantClear(_rows[i].row->values[FieldIndex]); - _rows[i].row->values[FieldIndex] = NULL; + _rows[i].row->values[FieldIndex] = nullptr; _rows[i].row->values.erase(_rows[i].row->values.begin() + FieldIndex); } } @@ -1169,9 +1168,9 @@ STDMETHODIMP CTableClass::EditInsertRow(long * RowIndex, VARIANT_BOOL *retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retval = VARIANT_FALSE; + *retval = VARIANT_FALSE; - bool canAppend = _appendMode && *RowIndex >= (long)_rows.size(); + bool canAppend = _appendMode && *RowIndex >= static_cast(_rows.size()); if (!_isEditingTable && !canAppend) { @@ -1194,7 +1193,7 @@ STDMETHODIMP CTableClass::EditInsertRow(long * RowIndex, VARIANT_BOOL *retval) for (long i = 0; i < FieldCount(); i++) { - VARIANT * val = NULL; + VARIANT * val = nullptr; val = new VARIANT(); VariantInit(val); @@ -1232,7 +1231,7 @@ TableRow* CTableClass::CloneTableRow(int rowIndex) return row->Clone(); } } - return NULL; + return nullptr; } // ******************************************************** @@ -1241,7 +1240,7 @@ TableRow* CTableClass::CloneTableRow(int rowIndex) bool CTableClass::InsertTableRow(TableRow* row, long rowIndex) { if (!row) return false; - if (rowIndex < 0 || rowIndex >= (long)_rows.size()) + if (rowIndex < 0 || rowIndex >= static_cast(_rows.size())) return false; row->SetDirty(TableRow::DATA_INSERTED); @@ -1259,10 +1258,10 @@ bool CTableClass::InsertTableRow(TableRow* row, long rowIndex) // ******************************************************** TableRow* CTableClass::SwapTableRow(TableRow* newRow, long rowIndex) { - if (!newRow) return NULL; + if (!newRow) return nullptr; - if (rowIndex < 0 || rowIndex >= (long)_rows.size()) - return NULL; + if (rowIndex < 0 || rowIndex >= static_cast(_rows.size())) + return nullptr; if (ReadRecord(rowIndex)) { TableRow* oldRow = _rows[rowIndex].row; @@ -1271,7 +1270,7 @@ TableRow* CTableClass::SwapTableRow(TableRow* newRow, long rowIndex) return oldRow; } - return NULL; + return nullptr; } // ******************************************************** @@ -1280,7 +1279,7 @@ TableRow* CTableClass::SwapTableRow(TableRow* newRow, long rowIndex) bool CTableClass::UpdateTableRow(TableRow* newRow, long rowIndex) { if (!newRow) return false; - if (rowIndex < 0 || rowIndex >= (long)_rows.size()) + if (rowIndex < 0 || rowIndex >= static_cast(_rows.size())) return false; if (_rows[rowIndex].row) @@ -1296,11 +1295,11 @@ bool CTableClass::UpdateTableRow(TableRow* newRow, long rowIndex) // ******************************************************************* void CTableClass::TryClearLastRecord(long rowIndex) { - if (!m_globalSettings.cacheDbfRecords && _dbfHandle != NULL) + if (!m_globalSettings.cacheDbfRecords && _dbfHandle != nullptr) { if (_lastRecordIndex != rowIndex && _lastRecordIndex >= 0 && _lastRecordIndex < RowCount() && - _rows[_lastRecordIndex].row != NULL && !_rows[_lastRecordIndex].row->IsModified() && + _rows[_lastRecordIndex].row != nullptr && !_rows[_lastRecordIndex].row->IsModified() && _joins.size() == 0) { // make sure that only one row in a time can be read @@ -1325,10 +1324,10 @@ bool CTableClass::ReadRecord(long RowIndex) _lastRecordIndex = RowIndex; - if (_rows[RowIndex].row != NULL) + if (_rows[RowIndex].row != nullptr) return true; - if (_dbfHandle == NULL) + if (_dbfHandle == nullptr) { ErrorMessage(tkFILE_NOT_OPEN); return false; @@ -1340,7 +1339,7 @@ bool CTableClass::ReadRecord(long RowIndex) for (int i = 0; i < FieldCount(); i++) { FieldType type = GetFieldType(i); - VARIANT * val = NULL; + VARIANT * val = nullptr; if (_fields[i]->oldIndex != -1) { @@ -1449,7 +1448,7 @@ bool CTableClass::ReadRecord(long RowIndex) _rows[RowIndex].row->values.push_back(val); } - return (_rows[RowIndex].row != NULL); + return (_rows[RowIndex].row != nullptr); } // ******************************************************************* @@ -1459,9 +1458,9 @@ bool CTableClass::ReadRecord(long RowIndex) bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowIndex, bool isUTF8) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; - if (dbfHandle == NULL) + if (dbfHandle == nullptr) { ErrorMessage(tkFILE_NOT_OPEN); return false; @@ -1470,7 +1469,7 @@ bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowI if (fromRowIndex < 0 || fromRowIndex >= RowCount()) return false; - const char * nonstackString = NULL; + const char * nonstackString = nullptr; for (long i = 0; i < FieldCount(); i++) { @@ -1487,7 +1486,7 @@ bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowI nonstackString = Utility::ConvertBSTRToLPSTR(val.bstrVal, (isUTF8 ? CP_UTF8 : CP_ACP)); // ((LPCSTR)Utility::ConvertToUtf8(val.bstrVal)); // Utility::SYS2A(val.bstrVal); DBFWriteStringAttribute(dbfHandle, toRowIndex, i, nonstackString); delete[] nonstackString; - nonstackString = NULL; + nonstackString = nullptr; } else if (val.vt == VT_I4) { @@ -1527,7 +1526,7 @@ bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowI long lval = atoi(nonstackString); DBFWriteIntegerAttribute(dbfHandle, toRowIndex, i, lval); delete[] nonstackString; - nonstackString = NULL; + nonstackString = nullptr; } else if (val.vt == VT_I4) { @@ -1561,7 +1560,7 @@ bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowI double dblval = Utility::atof_custom(nonstackString); DBFWriteDoubleAttribute(dbfHandle, toRowIndex, i, dblval); delete[] nonstackString; - nonstackString = NULL; + nonstackString = nullptr; } else if (val.vt == VT_I4) { @@ -1659,7 +1658,7 @@ STDMETHODIMP CTableClass::EditCellValue(long FieldIndex, long RowIndex, VARIANT { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retval = VARIANT_FALSE; + *retval = VARIANT_FALSE; bool canAppend = _appendMode && _rows.size() > 0 && RowIndex == _rows.size() - 1; @@ -1693,7 +1692,7 @@ STDMETHODIMP CTableClass::EditCellValue(long FieldIndex, long RowIndex, VARIANT { LONGLONG val = *(newVal.pllVal); newVal.vt = VT_I4; - newVal.lVal = (long)val; + newVal.lVal = static_cast(val); } else if (newVal.vt == (VT_BYREF | VT_I2)) { @@ -1781,14 +1780,14 @@ STDMETHODIMP CTableClass::EditCellValue(long FieldIndex, long RowIndex, VARIANT return S_OK; } - if (_rows[RowIndex].row == NULL) + if (_rows[RowIndex].row == nullptr) { ReadRecord(RowIndex); } - if (_rows[RowIndex].row != NULL) + if (_rows[RowIndex].row != nullptr) { - if (_rows[RowIndex].row->values[FieldIndex] == NULL) + if (_rows[RowIndex].row->values[FieldIndex] == nullptr) { // tws 6/7/7 : VariantInit DOES NOT free any old value, but VariantClear and VariantCopy DO // so only use VariantInit when it is NEW, otherwise it will leak BSTRs @@ -1799,7 +1798,7 @@ STDMETHODIMP CTableClass::EditCellValue(long FieldIndex, long RowIndex, VARIANT VariantCopy(_rows[RowIndex].row->values[FieldIndex], &newVal); //Change the width of the field - IField * field = NULL; + IField * field = nullptr; this->get_Field(FieldIndex, &field); FieldType type; long precision, width; @@ -1854,7 +1853,7 @@ STDMETHODIMP CTableClass::StartEditingTable(ICallback *cBack, VARIANT_BOOL *retv { // StartEditingTable now just simply set the editing flag, not read all records into memory AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; if (_isEditingTable) { @@ -1862,7 +1861,7 @@ STDMETHODIMP CTableClass::StartEditingTable(ICallback *cBack, VARIANT_BOOL *retv return S_OK; } - if (_dbfHandle == NULL) + if (_dbfHandle == nullptr) { ErrorMessage(tkFILE_NOT_OPEN); *retval = VARIANT_FALSE; @@ -1891,7 +1890,7 @@ STDMETHODIMP CTableClass::StartEditingTable(ICallback *cBack, VARIANT_BOOL *retv // ***************************************************************** bool CTableClass::HasFieldChanges() { - for (int i = 0; i < (int)_fields.size(); i++) + for (int i = 0; i < static_cast(_fields.size()); i++) { CField* fld = (CField*)_fields[i]->field; if (fld->GetIsUpdated()) @@ -1907,7 +1906,7 @@ bool CTableClass::HasFieldChanges() // ***************************************************************** void CTableClass::MarkFieldsAsUnchanged() { - for (int i = 0; i < (int)_fields.size(); i++) + for (int i = 0; i < static_cast(_fields.size()); i++) { CField* fld = (CField*)_fields[i]->field; fld->SetIsUpdated(false); @@ -1921,7 +1920,7 @@ STDMETHODIMP CTableClass::StopEditingTable(VARIANT_BOOL ApplyChanges, ICallback { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retval = VARIANT_FALSE; + *retval = VARIANT_FALSE; if (!_globalCallback && cBack) { @@ -2006,7 +2005,7 @@ STDMETHODIMP CTableClass::StopEditingTable(VARIANT_BOOL ApplyChanges, ICallback STDMETHODIMP CTableClass::EditDeleteRow(long RowIndex, VARIANT_BOOL *retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retval = VARIANT_FALSE; + *retval = VARIANT_FALSE; ((CShapefile*) _shapefile)->MarkShapeDeleted(RowIndex); @@ -2022,7 +2021,7 @@ STDMETHODIMP CTableClass::EditDeleteRow(long RowIndex, VARIANT_BOOL *retval) return S_OK; } - if (_rows[RowIndex].row != NULL) + if (_rows[RowIndex].row != nullptr) delete _rows[RowIndex].row; _rows.erase(_rows.begin() + RowIndex); @@ -2047,7 +2046,7 @@ STDMETHODIMP CTableClass::Save(ICallback *cBack, VARIANT_BOOL *retval) // ********************************************************************* FieldType CTableClass::GetFieldType(long fieldIndex) { - IField * field = NULL; + IField * field = nullptr; this->get_Field(fieldIndex, &field); FieldType type; field->get_Type(&type); @@ -2060,7 +2059,7 @@ FieldType CTableClass::GetFieldType(long fieldIndex) // ********************************************************************* long CTableClass::GetFieldPrecision(long fieldIndex) { - IField * field = NULL; + IField * field = nullptr; get_Field(fieldIndex, &field); long precision; field->get_Precision(&precision); @@ -2078,7 +2077,7 @@ void CTableClass::ClearRow(long rowIndex) if (_rows[rowIndex].row) { delete _rows[rowIndex].row; - _rows[rowIndex].row = NULL; + _rows[rowIndex].row = nullptr; } } } @@ -2088,17 +2087,17 @@ void CTableClass::ClearRow(long rowIndex) // ********************************************************************* STDMETHODIMP CTableClass::get_MinValue(long FieldIndex, VARIANT* retval) { - if (FieldIndex < 0 || FieldIndex >= (long)_fields.size()) + if (FieldIndex < 0 || FieldIndex >= static_cast(_fields.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); - retval = NULL; + retval = nullptr; } else { CComVariant min, val; for (unsigned long i = 0; i < _rows.size(); i++) { - if (ReadRecord(i) && _rows[i].row != NULL) + if (ReadRecord(i) && _rows[i].row != nullptr) val.Copy(_rows[i].row->values[FieldIndex]); if (i == 0) min = val; else if (val < min) min = val; @@ -2114,17 +2113,17 @@ STDMETHODIMP CTableClass::get_MinValue(long FieldIndex, VARIANT* retval) // ********************************************************************* STDMETHODIMP CTableClass::get_MaxValue(long FieldIndex, VARIANT* retval) { - if (FieldIndex < 0 || FieldIndex >= (long)_fields.size()) + if (FieldIndex < 0 || FieldIndex >= static_cast(_fields.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); - retval = NULL; + retval = nullptr; } else { CComVariant max, val; - for (long i = 0; i < (long)_rows.size(); i++) + for (long i = 0; i < static_cast(_rows.size()); i++) { - if (ReadRecord(i) && _rows[i].row != NULL) + if (ReadRecord(i) && _rows[i].row != nullptr) val.Copy(_rows[i].row->values[FieldIndex]); if (i == 0) max = val; else if (val > max) max = val; @@ -2140,7 +2139,7 @@ STDMETHODIMP CTableClass::get_MaxValue(long FieldIndex, VARIANT* retval) // ********************************************************************* STDMETHODIMP CTableClass::get_MeanValue(long FieldIndex, double* retval) { - if (FieldIndex < 0 || FieldIndex >= (long)_fields.size()) + if (FieldIndex < 0 || FieldIndex >= static_cast(_fields.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retval = 0.0; @@ -2154,13 +2153,13 @@ STDMETHODIMP CTableClass::get_MeanValue(long FieldIndex, double* retval) double sum = 0; for (unsigned long i = 0; i < _rows.size(); i++) { - if (ReadRecord(i) && _rows[i].row != NULL) + if (ReadRecord(i) && _rows[i].row != nullptr) { if (type == DOUBLE_FIELD) sum += _rows[i].row->values[FieldIndex]->dblVal; else sum += _rows[i].row->values[FieldIndex]->lVal; } } - *retval = sum / (double)_rows.size(); + *retval = sum / static_cast(_rows.size()); } else { @@ -2176,10 +2175,10 @@ STDMETHODIMP CTableClass::get_MeanValue(long FieldIndex, double* retval) // ********************************************************************* STDMETHODIMP CTableClass::get_StandardDeviation(long FieldIndex, double* retval) { - if (FieldIndex < 0 || FieldIndex >= (long)_fields.size()) + if (FieldIndex < 0 || FieldIndex >= static_cast(_fields.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); - retval = NULL; + retval = nullptr; } else { @@ -2192,7 +2191,7 @@ STDMETHODIMP CTableClass::get_StandardDeviation(long FieldIndex, double* retval) double std = 0.0; for (unsigned long i = 0; i < _rows.size(); i++) { - if (ReadRecord(i) && _rows[i].row != NULL) + if (ReadRecord(i) && _rows[i].row != nullptr) { if (type == DOUBLE_FIELD) std += pow(_rows[i].row->values[FieldIndex]->dblVal - mean, 2); else std += pow((double)_rows[i].row->values[FieldIndex]->lVal - mean, 2); @@ -2245,7 +2244,7 @@ vector* CTableClass::GenerateCategories(long FieldIndex, tkClass long numShapes = this->RowCount(); // getting field type - IField* fld = NULL; + IField* fld = nullptr; this->get_Field(FieldIndex, &fld); FieldType fieldType; fld->get_Type(&fieldType); @@ -2253,7 +2252,7 @@ vector* CTableClass::GenerateCategories(long FieldIndex, tkClass fld->get_Name(&str); USES_CONVERSION; CStringW fieldName = OLE2CW(str); - fld->Release(); fld = NULL; + fld->Release(); fld = nullptr; /* we won't define intervals for string values */ if (ClassificationType != ctUniqueValues && fieldType == STRING_FIELD) @@ -2311,7 +2310,7 @@ vector* CTableClass::GenerateCategories(long FieldIndex, tkClass std::vector values; copy(dict.begin(), dict.end(), inserter(values, values.end())); - for (int i = 0; i < (int)values.size(); i++) + for (int i = 0; i < static_cast(values.size()); i++) { CategoriesData data; data.minValue = values[i]; @@ -2341,14 +2340,14 @@ vector* CTableClass::GenerateCategories(long FieldIndex, tkClass } sort(values.begin(), values.end()); - double step = totalSum / (double)numClasses; + double step = totalSum / static_cast(numClasses); int index = 1; double sum = 0; - for (int i = 0; i < (int)values.size(); i++) + for (int i = 0; i < static_cast(values.size()); i++) { sum += values[i]; - if (sum >= step * (double)index || i == numShapes - 1) + if (sum >= step * static_cast(index) || i == numShapes - 1) { CategoriesData data; @@ -2389,7 +2388,7 @@ vector* CTableClass::GenerateCategories(long FieldIndex, tkClass vMin.Clear(); vMax.Clear(); /* creating classes */ - double dStep = (dMax - dMin) / (double)numClasses; + double dStep = (dMax - dMin) / static_cast(numClasses); while (dMin < dMax) { CategoriesData data; @@ -2539,7 +2538,7 @@ vector* CTableClass::GenerateCategories(long FieldIndex, tkClass // in case % is present, we need to put to double it for proper formatting fieldName.Replace(L"%", L"%%"); - for (int i = 0; i < (int)result->size(); i++) + for (int i = 0; i < static_cast(result->size()); i++) { CategoriesData* data = &((*result)[i]); @@ -2579,7 +2578,7 @@ vector* CTableClass::GenerateCategories(long FieldIndex, tkClass else { delete result; - return NULL; + return nullptr; } } @@ -2607,7 +2606,7 @@ STDMETHODIMP CTableClass::get_FieldIndexByName(BSTR FieldName, long* retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *retval = -1; + *retval = -1; USES_CONVERSION; CString searchName = OLE2CA(FieldName); for (unsigned int i = 0; i < _fields.size(); i++) @@ -2760,7 +2759,7 @@ bool CTableClass::set_IndexValue(int rowIndex) if (!_isEditingTable) return false; - if (rowIndex < 0 || rowIndex >(int)_rows.size()) + if (rowIndex < 0 || rowIndex >static_cast(_rows.size())) return false; long fieldIndex = -1; @@ -2771,7 +2770,7 @@ bool CTableClass::set_IndexValue(int rowIndex) if (fieldIndex == -1) return false; - IField* field = NULL; + IField* field = nullptr; this->get_Field(fieldIndex, &field); FieldType type; field->get_Type(&type); @@ -2816,13 +2815,13 @@ bool CTableClass::set_IndexValue(int rowIndex) STDMETHODIMP CTableClass::EditAddField(BSTR name, FieldType type, int precision, int width, long* fieldIndex) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - // MWGIS-55: Check inputs: - if (width < 1) - { - *fieldIndex = -1; - ErrorMessage(tkDBF_WIDTH_TOO_SMALL); - return S_OK; - } + // MWGIS-55: Check inputs: + if (width < 1) + { + *fieldIndex = -1; + ErrorMessage(tkDBF_WIDTH_TOO_SMALL); + return S_OK; + } // width and precision of doubles if (type == DOUBLE_FIELD) @@ -2859,15 +2858,15 @@ STDMETHODIMP CTableClass::EditAddField(BSTR name, FieldType type, int precision, precision = 0; } - IField* field = NULL; - CoCreateInstance(CLSID_Field, NULL, CLSCTX_INPROC_SERVER, IID_IField, (void**)&field); + IField* field = nullptr; + CoCreateInstance(CLSID_Field, nullptr, CLSCTX_INPROC_SERVER, IID_IField, (void**)&field); field->put_Name(name); field->put_Width(width); field->put_Precision(precision); field->put_Type(type); - *fieldIndex = (long)_fields.size(); + *fieldIndex = static_cast(_fields.size()); VARIANT_BOOL vbretval; - this->EditInsertField(field, fieldIndex, NULL, &vbretval); + this->EditInsertField(field, fieldIndex, nullptr, &vbretval); field->Release(); // the reference was added in previous call if (vbretval == VARIANT_FALSE) *fieldIndex = -1; @@ -2945,7 +2944,7 @@ bool CTableClass::JoinFields(ITable* table2, std::vector& mapping table2->get_NumFields(&numFields); for (long i = 0; i < numFields; i++) { - IField* fld = NULL; + IField* fld = nullptr; table2->get_Field(i, &fld); CComBSTR name; fld->get_Name(&name); @@ -2959,7 +2958,7 @@ bool CTableClass::JoinFields(ITable* table2, std::vector& mapping long index; VARIANT_BOOL vbretval; this->get_NumFields(&index); - this->EditInsertField(fldNew, &index, NULL, &vbretval); + this->EditInsertField(fldNew, &index, nullptr, &vbretval); _fields[index]->SetJoinId(_lastJoinId); fldNew->Release(); @@ -2982,7 +2981,7 @@ bool CTableClass::JoinFields(ITable* table2, std::vector& mapping // ***************************************************** STDMETHODIMP CTableClass::Join(ITable* table2, BSTR fieldTo, BSTR fieldFrom, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; set fields; bool res = this->JoinInternal(table2, OLE2W(fieldTo), OLE2W(fieldFrom), "", "", fields); @@ -2995,7 +2994,7 @@ STDMETHODIMP CTableClass::Join(ITable* table2, BSTR fieldTo, BSTR fieldFrom, VAR // ***************************************************** STDMETHODIMP CTableClass::Join2(ITable* table2, BSTR fieldTo, BSTR fieldFrom, BSTR filenameToReopen, BSTR joinOptions, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; set fields; bool res = this->JoinInternal(table2, OLE2W(fieldTo), OLE2W(fieldFrom), OLE2W(filenameToReopen), OLE2A(joinOptions), fields); @@ -3008,7 +3007,7 @@ STDMETHODIMP CTableClass::Join2(ITable* table2, BSTR fieldTo, BSTR fieldFrom, BS // ***************************************************** STDMETHODIMP CTableClass::Join3(ITable* table2, BSTR fieldTo, BSTR fieldFrom, BSTR filenameToReopen, BSTR joinOptions, SAFEARRAY* filedList, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; // TODO: Looks very similar to CGdalUtils::ConvertSafeArray @@ -3048,7 +3047,7 @@ STDMETHODIMP CTableClass::Join3(ITable* table2, BSTR fieldTo, BSTR fieldFrom, BS // ***************************************************** STDMETHODIMP CTableClass::TryJoin(ITable* table2, BSTR fieldTo, BSTR fieldFrom, int* rowCount, int* joinRowCount, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; *rowCount = -1; *joinRowCount = -1; @@ -3074,7 +3073,7 @@ STDMETHODIMP CTableClass::TryJoin(ITable* table2, BSTR fieldTo, BSTR fieldFrom, for (size_t i = 0; i < _rows.size(); i++) { CComVariant v; - this->get_CellValue(index1, i, &v); + this->get_CellValue(index1, static_cast(i), &v); std::map::iterator it = vals.find(v); if (it != vals.end()) @@ -3116,8 +3115,8 @@ bool CTableClass::CheckJoinInput(ITable* table2, CStringW fieldTo, CStringW fiel return false; } - CComPtr fld1 = NULL; - CComPtr fld2 = NULL; + CComPtr fld1 = nullptr; + CComPtr fld2 = nullptr; this->get_Field(index1, &fld1); table2->get_Field(index2, &fld2); @@ -3192,7 +3191,7 @@ bool CTableClass::JoinInternal(ITable* table2, CStringW fieldTo, CStringW fieldF for (size_t i = 0; i < _rows.size(); i++) { CComVariant v; - this->get_CellValue(index1, i, &v); + this->get_CellValue(index1, static_cast(i), &v); std::map::iterator it = vals.find(v); if (it != vals.end()) @@ -3200,7 +3199,7 @@ bool CTableClass::JoinInternal(ITable* table2, CStringW fieldTo, CStringW fieldF for (size_t j = 0; j < mapping.size(); j++) { table2->get_CellValue(mapping[j]->srcIndex, it->second, &v); - this->EditCellValue(mapping[j]->destIndex, i, v, &vb); + this->EditCellValue(mapping[j]->destIndex, static_cast(i), v, &vb); if (vb) { count++; } @@ -3233,10 +3232,10 @@ void CTableClass::RemoveJoinedFields() } VARIANT_BOOL vb; - for (int i = _fields.size() - 1; i >= 0; i--) + for (int i = static_cast(_fields.size()) - 1; i >= 0; i--) { if (_fields[i]->Joined()) { - this->EditDeleteField(i, NULL, &vb); + this->EditDeleteField(i, nullptr, &vb); } } @@ -3250,7 +3249,7 @@ void CTableClass::RemoveJoinedFields() // ***************************************************** STDMETHODIMP CTableClass::StopAllJoins() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) this->RemoveJoinedFields(); @@ -3266,8 +3265,8 @@ STDMETHODIMP CTableClass::StopAllJoins() // ***************************************************** STDMETHODIMP CTableClass::StopJoin(int joinIndex, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - if (joinIndex < 0 || joinIndex >= (int)_joins.size()) + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + if (joinIndex < 0 || joinIndex >= static_cast(_joins.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = VARIANT_FALSE; @@ -3284,10 +3283,10 @@ STDMETHODIMP CTableClass::StopJoin(int joinIndex, VARIANT_BOOL* retVal) // remove all fields which belong to this join VARIANT_BOOL vb; - for (int i = _fields.size() - 1; i >= 0; i--) + for (int i = static_cast(_fields.size()) - 1; i >= 0; i--) { if (_fields[i]->GetJoinId() == id) - this->EditDeleteField(i, NULL, &vb); + this->EditDeleteField(i, nullptr, &vb); } if (!editing) @@ -3323,8 +3322,8 @@ STDMETHODIMP CTableClass::get_IsJoined(VARIANT_BOOL* retVal) // ***************************************************** STDMETHODIMP CTableClass::get_JoinCount(int* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - *retVal = _joins.size(); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + *retVal = static_cast(_joins.size()); return S_OK; } @@ -3334,8 +3333,8 @@ STDMETHODIMP CTableClass::get_JoinCount(int* retVal) // ***************************************************** STDMETHODIMP CTableClass::get_FieldIsJoined(int fieldIndex, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - if (fieldIndex < 0 || fieldIndex >= (int)_fields.size()) + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + if (fieldIndex < 0 || fieldIndex >= static_cast(_fields.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = VARIANT_FALSE; @@ -3351,9 +3350,9 @@ STDMETHODIMP CTableClass::get_FieldIsJoined(int fieldIndex, VARIANT_BOOL* retVal // ***************************************************** STDMETHODIMP CTableClass::get_FieldJoinIndex(int fieldIndex, int* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = -1; - if (fieldIndex < 0 || fieldIndex >= (int)_fields.size()) + if (fieldIndex < 0 || fieldIndex >= static_cast(_fields.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); } @@ -3364,7 +3363,7 @@ STDMETHODIMP CTableClass::get_FieldJoinIndex(int fieldIndex, int* retVal) { if (_joins[i]->joinId == id) { - *retVal = i; + *retVal = static_cast(i); break; } } @@ -3377,8 +3376,8 @@ STDMETHODIMP CTableClass::get_FieldJoinIndex(int fieldIndex, int* retVal) // ***************************************************** STDMETHODIMP CTableClass::get_JoinFilename(int joinIndex, BSTR* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - if (joinIndex < 0 || joinIndex >= (int)_joins.size()) + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + if (joinIndex < 0 || joinIndex >= static_cast(_joins.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = W2BSTR(L""); @@ -3395,8 +3394,8 @@ STDMETHODIMP CTableClass::get_JoinFilename(int joinIndex, BSTR* retVal) // ***************************************************** STDMETHODIMP CTableClass::get_JoinFromField(int joinIndex, BSTR* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - if (joinIndex < 0 || joinIndex >= (int)_joins.size()) + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + if (joinIndex < 0 || joinIndex >= static_cast(_joins.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = W2BSTR(L""); @@ -3414,8 +3413,8 @@ STDMETHODIMP CTableClass::get_JoinFromField(int joinIndex, BSTR* retVal) // ***************************************************** STDMETHODIMP CTableClass::get_JoinToField(int joinIndex, BSTR* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - if (joinIndex < 0 || joinIndex >= (int)_joins.size()) + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + if (joinIndex < 0 || joinIndex >= static_cast(_joins.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = W2BSTR(L""); @@ -3432,9 +3431,9 @@ STDMETHODIMP CTableClass::get_JoinToField(int joinIndex, BSTR* retVal) // ******************************************************** STDMETHODIMP CTableClass::get_JoinFields(LONG joinIndex, BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (joinIndex < 0 || joinIndex >= (int)_joins.size()) + if (joinIndex < 0 || joinIndex >= static_cast(_joins.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *pVal = W2BSTR(L""); @@ -3452,7 +3451,7 @@ STDMETHODIMP CTableClass::get_JoinFields(LONG joinIndex, BSTR* pVal) // ***************************************************** STDMETHODIMP CTableClass::Serialize(BSTR* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) CPLXMLNode* psTree = this->SerializeCore("TableClass"); Utility::SerializeAndDestroyXmlTree(psTree, retVal); return S_OK; @@ -3463,7 +3462,7 @@ STDMETHODIMP CTableClass::Serialize(BSTR* retVal) // ***************************************************** STDMETHODIMP CTableClass::Deserialize(BSTR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; CString s = OLE2CA(newVal); @@ -3486,9 +3485,9 @@ STDMETHODIMP CTableClass::Deserialize(BSTR newVal) CPLXMLNode* CTableClass::SerializeCore(CString ElementName) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; - CPLXMLNode* psTree = CPLCreateXMLNode(NULL, CXT_Element, ElementName); + CPLXMLNode* psTree = CPLCreateXMLNode(nullptr, CXT_Element, ElementName); CPLXMLNode* psFields = CPLCreateXMLNode(psTree, CXT_Element, "Fields"); if (psFields) @@ -3598,7 +3597,7 @@ void CTableClass::RestoreFields(CPLXMLNode* node) CString s = CPLGetXMLValue(node, "Index", ""); if (s != "") index = atoi(s); - if (index >= 0 && index < (long)_fields.size()) + if (index >= 0 && index < static_cast(_fields.size())) { s = CPLGetXMLValue(node, "Name", ""); if (s != "") @@ -3611,7 +3610,7 @@ void CTableClass::RestoreFields(CPLXMLNode* node) if (index == index2) { - CComPtr fld = NULL; + CComPtr fld = nullptr; get_Field(index, &fld); if (fld) @@ -3654,7 +3653,7 @@ void CTableClass::RestoreFields(CPLXMLNode* node) void CTableClass::RestoreJoins(CPLXMLNode* node) { CStringW folderName = L""; - wchar_t* cwd = NULL; + wchar_t* cwd = nullptr; if (this->_filename != L"") { cwd = new wchar_t[4096]; @@ -3669,23 +3668,23 @@ void CTableClass::RestoreJoins(CPLXMLNode* node) { if (strcmp(node->pszValue, "Join") == 0) { - CStringW filename = Utility::ConvertFromUtf8(CPLGetXMLValue(node, "Filename", NULL)).MakeLower(); - CString fieldTo = CPLGetXMLValue(node, "FieldTo", NULL); - CString fieldFrom = CPLGetXMLValue(node, "FieldFrom", NULL); - CString fields = CPLGetXMLValue(node, "Fields", NULL); - CString options = CPLGetXMLValue(node, "Options", NULL); + CStringW filename = Utility::ConvertFromUtf8(CPLGetXMLValue(node, "Filename", nullptr)).MakeLower(); + CString fieldTo = CPLGetXMLValue(node, "FieldTo", nullptr); + CString fieldFrom = CPLGetXMLValue(node, "FieldFrom", nullptr); + CString fields = CPLGetXMLValue(node, "Fields", nullptr); + CString options = CPLGetXMLValue(node, "Options", nullptr); if (filename.GetLength() > 0 && fieldTo.GetLength() > 0 && fieldFrom.GetLength() > 0) { // ask client to provide the data once more VARIANT_BOOL vb; - CComPtr tableToFill = NULL; + CComPtr tableToFill = nullptr; ComHelper::CreateInstance(idTable, (IDispatch**)&tableToFill); CComBSTR bstrFilename(filename); if (filename.GetLength() > 4 && filename.Right(4) == ".dbf") { - tableToFill->Open(bstrFilename, NULL, &vb); + tableToFill->Open(bstrFilename, nullptr, &vb); } else { @@ -3732,7 +3731,7 @@ void CTableClass::RestoreJoins(CPLXMLNode* node) // ******************************************************** bool CTableClass::GetUids(long fieldIndex, map& results) { - CComPtr fld = NULL; + CComPtr fld = nullptr; get_Field(fieldIndex, &fld); if (!fld) return false; @@ -3768,7 +3767,7 @@ bool CTableClass::GetUids(long fieldIndex, map& results) // ******************************************************** STDMETHODIMP CTableClass::get_Filename(BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; *pVal = OLE2BSTR(_filename); @@ -3781,9 +3780,9 @@ STDMETHODIMP CTableClass::get_Filename(BSTR* pVal) // ******************************************************** STDMETHODIMP CTableClass::get_JoinOptions(LONG joinIndex, BSTR* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (joinIndex < 0 || joinIndex >= (int)_joins.size()) + if (joinIndex < 0 || joinIndex >= static_cast(_joins.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *pVal = A2BSTR(""); @@ -3801,7 +3800,7 @@ STDMETHODIMP CTableClass::get_JoinOptions(LONG joinIndex, BSTR* pVal) // ******************************************************** void CTableClass::RemoveTempFiles() { - for (int i = 0; i < (int)_tempFiles.size(); i++) + for (int i = 0; i < static_cast(_tempFiles.size()); i++) { try { @@ -3822,7 +3821,7 @@ void CTableClass::RemoveTempFiles() // ******************************************************** bool CTableClass::GetSorting(long fieldIndex, vector& indices) { - if (fieldIndex < 0 || fieldIndex >= (long)_fields.size()) + if (fieldIndex < 0 || fieldIndex >= static_cast(_fields.size())) { CallbackHelper::ErrorMsg("Invalid field index for sorting"); return false; @@ -3834,8 +3833,8 @@ bool CTableClass::GetSorting(long fieldIndex, vector& indices) long percent = 0; for (size_t i = 0; i < _rows.size(); i++) { - this->get_CellValue(fieldIndex, i, &val); - pair myPair(val, (long)i); + this->get_CellValue(fieldIndex, static_cast(i), &val); + pair myPair(val, static_cast(i)); map.insert(myPair); } @@ -3861,7 +3860,7 @@ bool CTableClass::GetRelativeValues(long fieldIndex, bool logScale, vector= (long)_fields.size()) + if (fieldIndex < 0 || fieldIndex >= static_cast(_fields.size())) { CallbackHelper::ErrorMsg("Invalid field index for sorting."); return false; @@ -3907,7 +3906,7 @@ bool CTableClass::GetRelativeValues(long fieldIndex, bool logScale, vector(i), &value); dVal(value, dval); if (logScale) @@ -3928,14 +3927,14 @@ bool CTableClass::GetRelativeValues(long fieldIndex, bool logScale, vectorIsModified()) + if (_rows[j].row != nullptr && !_rows[j].row->IsModified()) { delete _rows[j].row; - _rows[j].row = NULL; + _rows[j].row = nullptr; } } @@ -3977,13 +3976,13 @@ bool CTableClass::ValidateFieldIndex(long fieldIndex) // ******************************************************** STDMETHODIMP CTableClass::get_RowIsModified(LONG RowIndex, VARIANT_BOOL* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!ValidateRowIndex(RowIndex)) { return S_OK; } - bool modified = _rows[RowIndex].row != NULL && _rows[RowIndex].row->IsModified(); + bool modified = _rows[RowIndex].row != nullptr && _rows[RowIndex].row->IsModified(); *pVal = modified ? VARIANT_TRUE : VARIANT_FALSE; return S_OK; @@ -4012,7 +4011,7 @@ void CTableClass::MarkFieldsAreClean() for (size_t i = 0; i < _fields.size(); i++) { if (_fields[i]) { - _fields[i]->oldIndex = i; + _fields[i]->oldIndex = static_cast(i); } } } diff --git a/src/COM classes/TableClass.h b/src/COM classes/TableClass.h index 4a1bd217..f4a65afb 100644 --- a/src/COM classes/TableClass.h +++ b/src/COM classes/TableClass.h @@ -203,8 +203,8 @@ class ATL_NO_VTABLE CTableClass : bool SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace, ICallback* cBack); void LoadDefaultFields(); void LoadDefaultRows(); - long RowCount() { return _rows.size(); } - long FieldCount() { return _fields.size(); } + long RowCount() { return static_cast(_rows.size()); } + long FieldCount() { return static_cast(_fields.size()); } bool ReadRecord(long RowIndex); bool WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowIndex, bool isUTF8 = false); void ClearRow(long rowIndex); @@ -262,7 +262,7 @@ class ATL_NO_VTABLE CTableClass : bool GetSorting(long fieldIndex, vector& indices); bool GetRelativeValues(long fieldIndex, bool logScale, vector& values); bool WriteAppendedRow(); - void StartAppendMode() { _appendMode = true; _appendStartShapeCount = _rows.size(); }; + void StartAppendMode() { _appendMode = true; _appendStartShapeCount = static_cast(_rows.size()); }; void StopAppendMode(); void MarkRowIsClean(long rowIndex); void MarkFieldsAreClean(); diff --git a/src/COM classes/TileProviders.cpp b/src/COM classes/TileProviders.cpp index 7271a5e0..a42dec51 100644 --- a/src/COM classes/TileProviders.cpp +++ b/src/COM classes/TileProviders.cpp @@ -307,7 +307,7 @@ STDMETHODIMP CTileProviders::Clear(VARIANT_BOOL clearCache) STDMETHODIMP CTileProviders::get_Count(LONG* pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - *pVal = _providers.size(); + *pVal = static_cast(_providers.size()); return S_OK; } @@ -366,14 +366,14 @@ STDMETHODIMP CTileProviders::Add(int Id, BSTR name, BSTR urlPattern, tkTileProje STDMETHODIMP CTileProviders::get_Id(int Index, LONG* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >= (int)_providers.size()) + if (Index < 0 || Index >= static_cast(_providers.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = -1; } else { - *retVal = (LONG)_providers[Index]->Id; + *retVal = static_cast(_providers[Index]->Id); } return S_OK; } @@ -385,7 +385,7 @@ STDMETHODIMP CTileProviders::get_Name(int Index, BSTR* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; - if (Index < 0 || Index >= (int)_providers.size()) + if (Index < 0 || Index >= static_cast(_providers.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = A2BSTR(""); @@ -400,7 +400,7 @@ STDMETHODIMP CTileProviders::get_Name(int Index, BSTR* retVal) STDMETHODIMP CTileProviders::put_Name(int Index, BSTR pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >= (int)_providers.size()) + if (Index < 0 || Index >= static_cast(_providers.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); return S_OK; @@ -418,7 +418,7 @@ STDMETHODIMP CTileProviders::get_Language(int Index, BSTR* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; - if (Index < 0 || Index >= (int)_providers.size()) + if (Index < 0 || Index >= static_cast(_providers.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = A2BSTR(""); @@ -433,7 +433,7 @@ STDMETHODIMP CTileProviders::get_Language(int Index, BSTR* retVal) STDMETHODIMP CTileProviders::put_Language(int Index, BSTR pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >= (int)_providers.size()) + if (Index < 0 || Index >= static_cast(_providers.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); } @@ -461,7 +461,7 @@ STDMETHODIMP CTileProviders::get_Version(int Index, BSTR* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; - if (Index < 0 || Index >= (int)_providers.size()) + if (Index < 0 || Index >= static_cast(_providers.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = A2BSTR(""); @@ -479,7 +479,7 @@ STDMETHODIMP CTileProviders::get_Version(int Index, BSTR* retVal) STDMETHODIMP CTileProviders::put_Version(int Index, BSTR pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >= (int)_providers.size()) + if (Index < 0 || Index >= static_cast(_providers.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); } @@ -497,7 +497,7 @@ STDMETHODIMP CTileProviders::put_Version(int Index, BSTR pVal) STDMETHODIMP CTileProviders::get_UrlPattern(int Index, BSTR* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >= (int)_providers.size()) + if (Index < 0 || Index >= static_cast(_providers.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = A2BSTR(""); @@ -515,7 +515,7 @@ STDMETHODIMP CTileProviders::get_UrlPattern(int Index, BSTR* retVal) STDMETHODIMP CTileProviders::get_Projection(int Index, tkTileProjection* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >= (int)_providers.size()) + if (Index < 0 || Index >= static_cast(_providers.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = (tkTileProjection)-1; @@ -534,7 +534,7 @@ STDMETHODIMP CTileProviders::get_Projection(int Index, tkTileProjection* retVal) STDMETHODIMP CTileProviders::get_MinZoom(int Index, int* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >= (int)_providers.size()) + if (Index < 0 || Index >= static_cast(_providers.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = -1; @@ -552,7 +552,7 @@ STDMETHODIMP CTileProviders::get_MinZoom(int Index, int* retVal) STDMETHODIMP CTileProviders::get_MaxZoom(int Index, int* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Index < 0 || Index >= (int)_providers.size()) + if (Index < 0 || Index >= static_cast(_providers.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); *retVal = -1; @@ -583,7 +583,7 @@ STDMETHODIMP CTileProviders::get_IndexByProviderId(int providerId, int* retVal) { if (providerId == _providers[i]->Id) { - *retVal = i; + *retVal = static_cast(i); break; } } @@ -597,7 +597,7 @@ CStringW CTileProviders::get_CopyrightNotice(tkTileProvider provider) { int index = -1; get_IndexByProviderId((int)provider, &index); - if (index >= 0 && index < (int)_providers.size()) + if (index >= 0 && index < static_cast(_providers.size())) { return _providers[index]->get_Copyright(); } @@ -613,7 +613,7 @@ CString CTileProviders::get_LicenseUrl(tkTileProvider provider) get_IndexByProviderId((int)provider, &index); - if (index >= 0 && index < (int)_providers.size()) + if (index >= 0 && index < static_cast(_providers.size())) { return _providers[index]->get_LicenseUrl(); } @@ -625,7 +625,7 @@ CString CTileProviders::get_LicenseUrl(tkTileProvider provider) // ******************************************************* STDMETHODIMP CTileProviders::get_GeographicBounds(int Index, IExtents** pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = nullptr; @@ -640,7 +640,7 @@ STDMETHODIMP CTileProviders::get_GeographicBounds(int Index, IExtents** pVal) STDMETHODIMP CTileProviders::put_GeographicBounds(int Index, IExtents* newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!ValidateProviderIndex(Index)) return S_OK; @@ -656,7 +656,7 @@ STDMETHODIMP CTileProviders::put_GeographicBounds(int Index, IExtents* newVal) // ******************************************************* bool CTileProviders::ValidateProviderIndex(int index) { - if (index < 0 || index >= (int)_providers.size()) + if (index < 0 || index >= static_cast(_providers.size())) { ErrorMessage(tkINDEX_OUT_OF_BOUNDS); return false; diff --git a/src/COM classes/UndoList.cpp b/src/COM classes/UndoList.cpp index 6af62cf6..075b3dae 100644 --- a/src/COM classes/UndoList.cpp +++ b/src/COM classes/UndoList.cpp @@ -13,7 +13,7 @@ const int CUndoList::EMPTY_BATCH_ID = -1; //***********************************************************************/ IShapefile* CUndoList::GetShapefile(long layerHandle) { - if (!CheckState()) return NULL; + if (!CheckState()) return nullptr; return _mapCallback->_GetShapefile(layerHandle); } @@ -43,7 +43,7 @@ bool CUndoList::CheckState() { if (!_mapCallback) { ErrorMessage(tkUNDO_LIST_NO_MAP); } - return _mapCallback != NULL; + return _mapCallback != nullptr; } //*********************************************************************** @@ -92,7 +92,7 @@ STDMETHODIMP CUndoList::get_ErrorMsg(long ErrorCode, BSTR *pVal) // ********************************************************** STDMETHODIMP CUndoList::Clear() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) for (size_t i = 0; i < _list.size(); i++) delete _list[i]; _list.clear(); @@ -107,7 +107,7 @@ STDMETHODIMP CUndoList::Clear() // ********************************************************** bool CUndoList::CheckShapeIndex(long layerHandle, LONG shapeIndex) { - CComPtr sf = NULL; + CComPtr sf = nullptr; sf.Attach(GetShapefile(layerHandle)); if (!sf) return false; long numShapes; @@ -124,7 +124,7 @@ bool CUndoList::CheckShapeIndex(long layerHandle, LONG shapeIndex) // ********************************************************** STDMETHODIMP CUndoList::Add(tkUndoOperation operation, LONG LayerHandle, LONG ShapeIndex, VARIANT_BOOL *retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (!CheckState()) return S_OK; @@ -154,7 +154,7 @@ STDMETHODIMP CUndoList::Add(tkUndoOperation operation, LONG LayerHandle, LONG Sh _list.push_back(item); *retVal = VARIANT_TRUE; - _position = _list.size() - 1; + _position = static_cast(_list.size()) - 1; if (!item->WithinBatch) { FireUndoListChanged(); @@ -199,7 +199,7 @@ bool CUndoList::AddGroupOperation(tkUndoOperation operation, int layerHandle, ve item->RotationAngle = angleDegrees; _list.push_back(item); - _position = _list.size() - 1; + _position = static_cast(_list.size()) - 1; FireUndoListChanged(); return true; @@ -211,7 +211,7 @@ bool CUndoList::AddGroupOperation(tkUndoOperation operation, int layerHandle, ve // if we are not in the end of list, trim the undone items void CUndoList::TrimList() { - for (int i = (int)(_list.size() - 1); i > _position; --i) { + for (int i = static_cast(_list.size() - 1); i > _position; --i) { delete _list[i]; _list.pop_back(); } @@ -226,13 +226,13 @@ bool CUndoList::CopyShapeState(long layerHandle, long shapeIndex, bool copyAttri item->SetShape(shp); if (copyAttributes) { - CComPtr sf = NULL; + CComPtr sf = nullptr; sf.Attach(GetShapefile(layerHandle)); if (sf) { - CComPtr tbl = NULL; + CComPtr tbl = nullptr; sf->get_Table(&tbl); if (tbl) { - TableRow* row = TableHelper::Cast(tbl)->CloneTableRow((int)shapeIndex); + TableRow* row = TableHelper::Cast(tbl)->CloneTableRow(static_cast(shapeIndex)); item->SetRow(row); } long category = -1; @@ -248,7 +248,7 @@ bool CUndoList::CopyShapeState(long layerHandle, long shapeIndex, bool copyAttri // ********************************************************** STDMETHODIMP CUndoList::Undo(VARIANT_BOOL zoomToShape, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (!CheckState()) return S_OK; @@ -282,11 +282,11 @@ STDMETHODIMP CUndoList::Undo(VARIANT_BOOL zoomToShape, VARIANT_BOOL* retVal) // ********************************************************** STDMETHODIMP CUndoList::Redo(VARIANT_BOOL zoomToShape, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (!CheckState()) return S_OK; - int maxIndex = (int)_list.size() - 1; + int maxIndex = static_cast(_list.size()) - 1; if (_position + 1 <= maxIndex) { int pos = _position + 1; @@ -315,7 +315,7 @@ STDMETHODIMP CUndoList::Redo(VARIANT_BOOL zoomToShape, VARIANT_BOOL* retVal) void CUndoList::ZoomToShape(VARIANT_BOOL zoomToShape, int itemIndex) { if (!zoomToShape) return; - if (itemIndex < 0 || itemIndex >= (int)_list.size())return; + if (itemIndex < 0 || itemIndex >= static_cast(_list.size()))return; UndoListItem* item = _list[itemIndex]; if (item->Operation == uoEditShape) { @@ -346,9 +346,9 @@ bool CUndoList::DiscardOne() // ********************************************************** bool CUndoList::UndoSingleItem(UndoListItem* item) { - CComPtr sf = NULL; + CComPtr sf = nullptr; sf.Attach(GetShapefile(item->LayerHandle)); - CComPtr table = NULL; + CComPtr table = nullptr; sf->get_Table(&table); VARIANT_BOOL vb; @@ -357,12 +357,12 @@ bool CUndoList::UndoSingleItem(UndoListItem* item) case uoRotateShapes: if (item->ShapeIndices) { - int size = item->ShapeIndices->size(); + int size = static_cast(item->ShapeIndices->size()); for (int i = 0; i < size; i++) { int index = (*item->ShapeIndices)[i]; - CComPtr shp = NULL; - sf->get_Shape((long)index, &shp); + CComPtr shp = nullptr; + sf->get_Shape(index, &shp); if (shp) { shp->Rotate(item->ProjOffset.x, item->ProjOffset.y, -item->RotationAngle); } @@ -373,12 +373,12 @@ bool CUndoList::UndoSingleItem(UndoListItem* item) case uoMoveShapes: if (item->ShapeIndices) { - int size = item->ShapeIndices->size(); + int size = static_cast(item->ShapeIndices->size()); for (int i = 0; i < size; i++) { int index = (*item->ShapeIndices)[i]; - CComPtr shp = NULL; - sf->get_Shape((long)index, &shp); + CComPtr shp = nullptr; + sf->get_Shape(index, &shp); if (shp) { shp->Move(item->ProjOffset.x, item->ProjOffset.y); } @@ -396,12 +396,12 @@ bool CUndoList::UndoSingleItem(UndoListItem* item) TableRow* oldRow = TableHelper::Cast(table)->SwapTableRow(item->Row, item->ShapeIndex); if (oldRow) delete oldRow; sf->put_ShapeCategory(item->ShapeIndex, item->StyleCategory); - item->SetShape(NULL); - item->Row = NULL; // the instance is used by table now + item->SetShape(nullptr); + item->Row = nullptr; // the instance is used by table now item->Operation = uoAddShape; IShapeEditor* editor = _mapCallback->_GetShapeEditor(); if (editor && !item->WithinBatch) { - CComPtr shp = NULL; + CComPtr shp = nullptr; shp.Attach(GetCurrentState(item->LayerHandle, item->ShapeIndex)); ((CShapeEditor*)editor)->RestoreState(shp, item->LayerHandle, item->ShapeIndex); } @@ -465,12 +465,12 @@ IShape* CUndoList::GetCurrentState(long layerHandle, long shapeIndex) { IShapeEditor* editor = _mapCallback->_GetShapeEditor(); - IShape* shp = NULL; + IShape* shp = nullptr; if (ShapeInEditor(layerHandle, shapeIndex)) { editor->get_RawData(&shp); } else { - CComPtr sf = NULL; + CComPtr sf = nullptr; sf.Attach(GetShapefile(layerHandle)); if (sf) { sf->get_Shape(shapeIndex, &shp); @@ -484,7 +484,7 @@ IShape* CUndoList::GetCurrentState(long layerHandle, long shapeIndex) // ********************************************************** STDMETHODIMP CUndoList::get_UndoCount(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = CheckState() ? FindPosition(_position) : -1; return S_OK; } @@ -494,7 +494,7 @@ STDMETHODIMP CUndoList::get_UndoCount(LONG* pVal) // ********************************************************** STDMETHODIMP CUndoList::get_RedoCount(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) long totalLength, undoCount; get_TotalLength(&totalLength); get_UndoCount(&undoCount); @@ -525,9 +525,9 @@ long CUndoList::FindPosition(int position) // ********************************************************** bool CUndoList::WithinBatch(int position) { - if (position < 0 || position >= (int)_list.size()) return false; + if (position < 0 || position >= static_cast(_list.size())) return false; int id = _list[position]->BatchId; - if (position + 1 < (int)_list.size() && _list[position + 1]->BatchId == id) + if (position + 1 < static_cast(_list.size()) && _list[position + 1]->BatchId == id) return true; if (position - 1 >= 0 && _list[position - 1]->BatchId == id) return true; @@ -539,7 +539,7 @@ bool CUndoList::WithinBatch(int position) // ********************************************************** STDMETHODIMP CUndoList::get_TotalLength(LONG* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) int lastId = EMPTY_BATCH_ID; long count = 0; for (size_t i = 0; i < _list.size(); i++) @@ -558,7 +558,7 @@ STDMETHODIMP CUndoList::get_TotalLength(LONG* pVal) // ********************************************************** STDMETHODIMP CUndoList::BeginBatch(VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_batchId == EMPTY_BATCH_ID) { _batchId = NextId(); *retVal = VARIANT_TRUE; @@ -575,14 +575,14 @@ STDMETHODIMP CUndoList::BeginBatch(VARIANT_BOOL* retVal) // ********************************************************** STDMETHODIMP CUndoList::EndBatch(LONG* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_batchId == EMPTY_BATCH_ID) { *retVal = -1; return S_OK; } else { long count = 0; - for (int i = _list.size() - 1; i >= 0; --i) + for (int i = static_cast(_list.size()) - 1; i >= 0; --i) { if (_list[i]->BatchId == _batchId) count++; @@ -602,7 +602,7 @@ STDMETHODIMP CUndoList::EndBatch(LONG* retVal) // ********************************************************** STDMETHODIMP CUndoList::GetLastId(LONG* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = _list.size() > 0 ? _list.at(_list.size() - 1)->BatchId : -1; return S_OK; } @@ -612,13 +612,13 @@ STDMETHODIMP CUndoList::GetLastId(LONG* retVal) // ********************************************************** STDMETHODIMP CUndoList::get_ShortcutKey(tkUndoShortcut* pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *pVal = _shortcutKey; return S_OK; } STDMETHODIMP CUndoList::put_ShortcutKey(tkUndoShortcut newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _shortcutKey = newVal; return S_OK; } @@ -638,9 +638,9 @@ void CUndoList::FireUndoListChanged() // ********************************************************** STDMETHODIMP CUndoList::ClearForLayer(LONG LayerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) bool changed = false; - for (int i = (int)_list.size() - 1; i >= 0; i--) + for (int i = static_cast(_list.size()) - 1; i >= 0; i--) { if (_list[i]->LayerHandle == LayerHandle) { diff --git a/src/COM classes/Utils.cpp b/src/COM classes/Utils.cpp index e9b28cd0..57cfb73e 100644 --- a/src/COM classes/Utils.cpp +++ b/src/COM classes/Utils.cpp @@ -145,7 +145,7 @@ STDMETHODIMP CUtils::PointInPolygon(IShape* Shape, IPoint* TestPoint, VARIANT_BO //if( TestPoint != NULL ) //{ - // double test_pointX, test_pointY; + // double test_pointX, test_pointY; // TestPoint->get_X(&test_pointX); // TestPoint->get_Y(&test_pointY); // @@ -264,7 +264,7 @@ inline void CUtils::set_sign(double val, int& SH) STDMETHODIMP CUtils::GridReplace(IGrid* Grid, VARIANT OldValue, VARIANT NewValue, ICallback* cBack, VARIANT_BOOL* retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; *retval = VARIANT_FALSE; ICallback* callback = cBack ? cBack : _globalCallback; @@ -318,7 +318,7 @@ STDMETHODIMP CUtils::GridInterpolateNoData(IGrid* Grid, ICallback* cBack, VARIAN { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - ICallback* callback = cBack ? cBack : _globalCallback; + ICallback* callback = cBack ? cBack : _globalCallback; if (Grid == nullptr) { @@ -378,12 +378,12 @@ STDMETHODIMP CUtils::RemoveColinearPoints(IShapefile* Shapes, double LinearToler { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Shapes == nullptr) - { - *retval = NULL; - ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); - return S_OK; - } + if (Shapes == nullptr) + { + *retval = NULL; + ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); + return S_OK; + } ICallback* callback = cBack ? cBack : _globalCallback; @@ -594,12 +594,12 @@ STDMETHODIMP CUtils::get_Length(IShape* Shape, double* pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Shape == nullptr) - { - *pVal = 0.0; - this->ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); - return S_OK; - } + if (Shape == nullptr) + { + *pVal = 0.0; + this->ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); + return S_OK; + } Shape->get_Length(pVal); return S_OK; } @@ -608,12 +608,12 @@ STDMETHODIMP CUtils::get_Perimeter(IShape* Shape, double* pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Shape == nullptr) - { - *pVal = 0.0; - this->ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); - return S_OK; - } + if (Shape == nullptr) + { + *pVal = 0.0; + this->ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); + return S_OK; + } Shape->get_Perimeter(pVal); return S_OK; @@ -622,12 +622,12 @@ STDMETHODIMP CUtils::get_Perimeter(IShape* Shape, double* pVal) STDMETHODIMP CUtils::get_Area(IShape* Shape, double* pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Shape == nullptr) - { - *pVal = 0.0; - this->ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); - return S_OK; - } + if (Shape == nullptr) + { + *pVal = 0.0; + this->ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); + return S_OK; + } Shape->get_Area(pVal); return S_OK; @@ -642,7 +642,7 @@ STDMETHODIMP CUtils::get_Area(IShape* Shape, double* pVal) //Returns true if clockwise, false if counter-clockwise. bool CUtils::is_clockwise(Poly* polygon) { - int numPoints = polygon->polyX.size(); + int numPoints = static_cast(polygon->polyX.size()); double area = 0; for (int i = 0; i <= numPoints - 2; i++) { @@ -716,7 +716,7 @@ STDMETHODIMP CUtils::get_LastErrorCode(long* pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - * pVal = _lastErrorCode; + * pVal = _lastErrorCode; _lastErrorCode = tkNO_ERROR; return S_OK; @@ -725,7 +725,7 @@ STDMETHODIMP CUtils::get_LastErrorCode(long* pVal) STDMETHODIMP CUtils::get_ErrorMsg(long ErrorCode, BSTR* pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; *pVal = A2BSTR(ErrorMsg(ErrorCode)); @@ -736,7 +736,7 @@ STDMETHODIMP CUtils::get_GlobalCallback(ICallback** pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - * pVal = _globalCallback; + * pVal = _globalCallback; if (_globalCallback != nullptr) { _globalCallback->AddRef(); @@ -747,14 +747,14 @@ STDMETHODIMP CUtils::get_GlobalCallback(ICallback** pVal) STDMETHODIMP CUtils::put_GlobalCallback(ICallback* newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - ComHelper::SetRef(newVal, (IDispatch**)&_globalCallback); + ComHelper::SetRef(newVal, (IDispatch**)&_globalCallback); return S_OK; } STDMETHODIMP CUtils::get_Key(BSTR* pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; *pVal = OLE2BSTR(_key); @@ -764,7 +764,7 @@ STDMETHODIMP CUtils::get_Key(BSTR* pVal) STDMETHODIMP CUtils::put_Key(BSTR newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; ::SysFreeString(_key); _key = OLE2BSTR(newVal); @@ -775,7 +775,7 @@ STDMETHODIMP CUtils::put_Key(BSTR newVal) STDMETHODIMP CUtils::GridMerge(VARIANT Grids, BSTR MergeFilename, VARIANT_BOOL InRam, GridFileType GrdFileType, ICallback* cBack, IGrid** retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; CComBSTR final_projection(""); @@ -801,7 +801,7 @@ STDMETHODIMP CUtils::GridMerge(VARIANT Grids, BSTR MergeFilename, VARIANT_BOOL I std::deque allGrids; int gridSize = 0; //size of allGrids -- ah 6/6/03 - int elements = (int)arraybound.cElements; //ah 6/6/03 + int elements = static_cast(arraybound.cElements); //ah 6/6/03 for (int index = 0; index < elements; index++) { @@ -819,7 +819,7 @@ STDMETHODIMP CUtils::GridMerge(VARIANT Grids, BSTR MergeFilename, VARIANT_BOOL I *retval = nullptr; ErrorMessage(callback, tkINTERFACE_NOT_SUPPORTED); - gridSize = (int)allGrids.size(); //ah 6/6/05 + gridSize = static_cast(allGrids.size()); //ah 6/6/05 for (int c = 0; c < gridSize; c++) { allGrids[c]->Release(); @@ -837,7 +837,7 @@ STDMETHODIMP CUtils::GridMerge(VARIANT Grids, BSTR MergeFilename, VARIANT_BOOL I return S_OK; } - gridSize = (int)allGrids.size(); + gridSize = static_cast(allGrids.size()); ProjectionTools* pt = new ProjectionTools(); for (int i = 0; i < gridSize; i++) { @@ -892,7 +892,7 @@ STDMETHODIMP CUtils::GridMerge(VARIANT Grids, BSTR MergeFilename, VARIANT_BOOL I double total = 0.0; //Get the bounds and DataType for the final grid - gridSize = (int)allGrids.size(); + gridSize = static_cast(allGrids.size()); for (int i = 0; i < gridSize; i++) { if (i == 0) @@ -940,7 +940,7 @@ STDMETHODIMP CUtils::GridMerge(VARIANT Grids, BSTR MergeFilename, VARIANT_BOOL I *retval = nullptr; ErrorMessage(callback, tkINCOMPATIBLE_DX); - gridSize = (int)allGrids.size(); + gridSize = static_cast(allGrids.size()); for (int c = 0; c < gridSize; c++) { allGrids[c]->Release(); @@ -954,7 +954,7 @@ STDMETHODIMP CUtils::GridMerge(VARIANT Grids, BSTR MergeFilename, VARIANT_BOOL I *retval = nullptr; ErrorMessage(callback, tkINCOMPATIBLE_DY); - gridSize = (int)allGrids.size(); + gridSize = static_cast(allGrids.size()); for (int c = 0; c < gridSize; c++) { allGrids[c]->Release(); @@ -982,7 +982,7 @@ STDMETHODIMP CUtils::GridMerge(VARIANT Grids, BSTR MergeFilename, VARIANT_BOOL I *retval = nullptr; ErrorMessage(callback, tkINVALID_DATA_TYPE); - gridSize = (int)allGrids.size(); + gridSize = static_cast(allGrids.size()); for (int c = 0; c < gridSize; c++) { @@ -996,7 +996,7 @@ STDMETHODIMP CUtils::GridMerge(VARIANT Grids, BSTR MergeFilename, VARIANT_BOOL I if (total <= 0) { *retval = nullptr; - gridSize = (int)allGrids.size(); + gridSize = static_cast(allGrids.size()); for (int c = 0; c < gridSize; c++) { @@ -1026,7 +1026,7 @@ STDMETHODIMP CUtils::GridMerge(VARIANT Grids, BSTR MergeFilename, VARIANT_BOOL I if (vbretval == FALSE) { *retval = nullptr; - gridSize = (int)allGrids.size(); + gridSize = static_cast(allGrids.size()); for (int c = 0; c < gridSize; c++) { allGrids[c]->Release(); @@ -1042,7 +1042,7 @@ STDMETHODIMP CUtils::GridMerge(VARIANT Grids, BSTR MergeFilename, VARIANT_BOOL I VARIANT vval; VariantInit(&vval); - gridSize = (int)allGrids.size(); + gridSize = static_cast(allGrids.size()); for (int n = gridSize - 1; n >= 0; n--) { IGridHeader* header = nullptr; @@ -1072,7 +1072,7 @@ STDMETHODIMP CUtils::GridMerge(VARIANT Grids, BSTR MergeFilename, VARIANT_BOOL I } } - gridSize = (int)allGrids.size(); + gridSize = static_cast(allGrids.size()); for (int c = 0; c < gridSize; c++) { allGrids[c]->Release(); @@ -1088,14 +1088,14 @@ STDMETHODIMP CUtils::GridMerge(VARIANT Grids, BSTR MergeFilename, VARIANT_BOOL I STDMETHODIMP CUtils::ShapeMerge(IShapefile* Shapes, long IndexOne, long IndexTwo, ICallback* cBack, IShape** retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - ErrorMessage(tkMETHOD_NOT_IMPLEMENTED); + ErrorMessage(tkMETHOD_NOT_IMPLEMENTED); return S_OK; } STDMETHODIMP CUtils::GridToGrid(IGrid* Grid, GridDataType OutDataType, ICallback* cBack, IGrid** retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; ICallback* callback = cBack ? cBack : _globalCallback; @@ -1154,12 +1154,12 @@ STDMETHODIMP CUtils::ShapeToShapeZ(IShapefile* Shapefile, IGrid* Grid, ICallback { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (Shapefile == nullptr || Grid == nullptr) - { - *retval = nullptr; - this->ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); - return S_OK; - } + if (Shapefile == nullptr || Grid == nullptr) + { + *retval = nullptr; + this->ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); + return S_OK; + } long ncols = 0, nrows = 0; IGridHeader* header = nullptr; @@ -1253,7 +1253,7 @@ STDMETHODIMP CUtils::ShapeToShapeZ(IShapefile* Shapefile, IGrid* Grid, ICallback STDMETHODIMP CUtils::TinToShapefile(ITin* Tin, ShpfileType Type, ICallback* cBack, IShapefile** retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - USES_CONVERSION; + USES_CONVERSION; if (Tin == nullptr) { @@ -1463,7 +1463,7 @@ STDMETHODIMP CUtils::GridToShapefile(IGrid* Grid, IGrid* ConnectionGrid, ICallba { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - ICallback* callback = cBack ? cBack : _globalCallback; + ICallback* callback = cBack ? cBack : _globalCallback; if (Grid == nullptr) { @@ -1854,7 +1854,7 @@ STDMETHODIMP CUtils::GridToShapefile(IGrid* Grid, IGrid* ConnectionGrid, ICallba if (polygon.size() > 3) { - long endIndex = polygon.size() - 1; + long endIndex = static_cast(polygon.size()) - 1; double x1 = polygon[0].column, x2 = polygon[1].column, @@ -2220,7 +2220,7 @@ void CUtils::mark_edge(double& polygon_id, long x, long y) } } - for (int d1 = 0; d1 < (int)decisions.size(); d1++) + for (int d1 = 0; d1 < static_cast(decisions.size()); d1++) setValue(_expand_grid, decisions[d1].column, decisions[d1].row, DECISION); } @@ -2291,7 +2291,7 @@ void CUtils::scan_fill_to_edge(double& nodata, long x, long y) } } - for (int d1 = 0; d1 < (int)decisions.size(); d1++) + for (int d1 = 0; d1 < static_cast(decisions.size()); d1++) setValue(_expand_grid, decisions[d1].column, decisions[d1].row, DECISION); } @@ -3005,7 +3005,7 @@ STDMETHODIMP CUtils::hBitmapToPicture(long hBitmap, IPictureDisp** retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - HBITMAP bitmap = (HBITMAP)hBitmap; + HBITMAP bitmap = reinterpret_cast(static_cast(hBitmap)); PICTDESC pictdesc; pictdesc.cbSizeofstruct = sizeof(PICTDESC); pictdesc.picType = PICTYPE_BITMAP; @@ -3278,7 +3278,7 @@ void CUtils::Parse(CString sOrig, int* opts) // *********************************************************** STDMETHODIMP CUtils::OGRLayerToShapefile(BSTR Filename, ShpfileType shpType, ICallback* cBack, IShapefile** sf) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) ICallback* callback = cBack ? cBack : _globalCallback; (*sf) = OgrConverter::ReadOgrLayer(Filename, callback); if (*sf) @@ -3295,7 +3295,7 @@ STDMETHODIMP CUtils::OGRLayerToShapefile(BSTR Filename, ShpfileType shpType, ICa STDMETHODIMP CUtils::ClipPolygon(PolygonOperation op, IShape* SubjectPolygon, IShape* ClipPolygon, IShape** retval) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - * retval = nullptr; + * retval = nullptr; if (SubjectPolygon == nullptr || ClipPolygon == nullptr) { @@ -3391,7 +3391,7 @@ STDMETHODIMP CUtils::MergeImages(/*[in]*/SAFEARRAY* inputNames, /*[in]*/ const BSTR outputName, /*out,retval*/VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - * retVal = VARIANT_FALSE; + * retVal = VARIANT_FALSE; USES_CONVERSION; // Check dimensions of the array. @@ -3571,7 +3571,7 @@ STDMETHODIMP CUtils::MergeImages(/*[in]*/SAFEARRAY* inputNames, /*[in]*/ // *********************************************************** STDMETHODIMP CUtils::ReprojectShapefile(IShapefile* sf, IGeoProjection* source, IGeoProjection* target, IShapefile** result) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // ------------------------------------------------ // Validation @@ -3714,7 +3714,7 @@ void CUtils::ErrorMessage(long errorCode, CString customMessage) STDMETHODIMP CUtils::ColorByName(tkMapColor name, OLE_COLOR* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = BGR_TO_RGB(name); return S_OK; } @@ -3724,7 +3724,7 @@ STDMETHODIMP CUtils::ColorByName(tkMapColor name, OLE_COLOR* retVal) // ************************************************************** STDMETHODIMP CUtils::ConvertDistance(tkUnitsOfMeasure sourceUnit, tkUnitsOfMeasure targetUnit, DOUBLE* value, VARIANT_BOOL* retval) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retval = Utility::ConvertDistance(sourceUnit, targetUnit, *value); return S_OK; } @@ -3734,7 +3734,7 @@ STDMETHODIMP CUtils::ConvertDistance(tkUnitsOfMeasure sourceUnit, tkUnitsOfMeasu // ************************************************************** STDMETHODIMP CUtils::ClipGridWithPolygon(BSTR inputGridfile, IShape* poly, BSTR resultGridfile, VARIANT_BOOL keepExtents, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; @@ -3766,7 +3766,7 @@ STDMETHODIMP CUtils::ClipGridWithPolygon(BSTR inputGridfile, IShape* poly, BSTR // ******************************************************** STDMETHODIMP CUtils::ClipGridWithPolygon2(IGrid* grid, IShape* poly, BSTR resultGridfile, VARIANT_BOOL keepExtents, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; @@ -4098,7 +4098,7 @@ bool GridStatsForPoly(IGrid* grid, IGridHeader* header, IShape* poly, Extent& bo STDMETHODIMP CUtils::GridStatisticsForPolygon(IGrid* grid, IGridHeader* header, IExtents* gridExtents, IShape* shape, double noDataValue, double* meanValue, double* minValue, double* maxValue, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (!grid || !header || !shape) { @@ -4134,7 +4134,7 @@ STDMETHODIMP CUtils::GridStatisticsForPolygon(IGrid* grid, IGridHeader* header, // ******************************************************** STDMETHODIMP CUtils::GridStatisticsToShapefile(IGrid* grid, IShapefile* sf, VARIANT_BOOL selectedOnly, VARIANT_BOOL overwriteFields, VARIANT_BOOL useCenterWithinMethod, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; if (!grid || !sf) { ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); @@ -4438,7 +4438,7 @@ STDMETHODIMP CUtils::GridStatisticsToShapefile(IGrid* grid, IShapefile* sf, VARI sf->EditCellValue(fieldIndices[10], n, vMinY, &vb); // 11 - "Variety" - int variety = values.size(); + int variety = static_cast(values.size()); CComVariant vVar(variety); sf->EditCellValue(fieldIndices[11], n, vVar, &vb); @@ -4476,7 +4476,7 @@ STDMETHODIMP CUtils::GridStatisticsToShapefile(IGrid* grid, IShapefile* sf, VARI STDMETHODIMP CUtils::CreateInstance(tkInterface interfaceId, IDispatch** retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - return ComHelper::CreateInstance(interfaceId, retVal); + return ComHelper::CreateInstance(interfaceId, retVal); } // ******************************************************** @@ -4485,7 +4485,7 @@ STDMETHODIMP CUtils::CreateInstance(tkInterface interfaceId, IDispatch** retVal) #include "..\Processing\GeograpicLib\Geodesic.hpp" STDMETHODIMP CUtils::GeodesicDistance(double lat1, double lng1, double lat2, double lng2, double* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const GeographicLib::Geodesic& geod = GeographicLib::Geodesic::WGS84; geod.Inverse(lat1, lng1, lat2, lng2, *retVal); @@ -4497,7 +4497,7 @@ STDMETHODIMP CUtils::GeodesicDistance(double lat1, double lng1, double lat2, dou // ******************************************************** STDMETHODIMP CUtils::GeodesicArea(IShape* shapeWgs84, DOUBLE* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!shapeWgs84) { @@ -4558,7 +4558,7 @@ double CalcPolyGeodesicArea(std::vector& points) STDMETHODIMP CUtils::MaskRaster(BSTR filename, BYTE newPerBandValue, VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - * retVal = VARIANT_FALSE; + * retVal = VARIANT_FALSE; GDALAllRegister(); @@ -4584,7 +4584,7 @@ STDMETHODIMP CUtils::MaskRaster(BSTR filename, BYTE newPerBandValue, VARIANT_BOO break; } - unsigned char noData = (unsigned char)poBand->GetNoDataValue(); + unsigned char noData = static_cast(poBand->GetNoDataValue()); int nXBlockSize, nYBlockSize; poBand->GetBlockSize(&nXBlockSize, &nYBlockSize); @@ -4708,7 +4708,7 @@ void SetGdalErrorHandler(ICallback* callback) STDMETHODIMP CUtils::CopyNodataValues(BSTR sourceFilename, BSTR destFilename, VARIANT_BOOL* retVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - * retVal = VARIANT_FALSE; + * retVal = VARIANT_FALSE; GDALAllRegister(); if (_globalCallback) { @@ -5204,7 +5204,7 @@ HRESULT CUtils::TileProjectionToGeoProjectionCore(tkTileProjection projection, V // ******************************************************** STDMETHODIMP CUtils::TileProjectionToGeoProjection(tkTileProjection projection, IGeoProjection** retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return TileProjectionToGeoProjectionCore(projection, VARIANT_FALSE, retVal); } @@ -5213,7 +5213,7 @@ STDMETHODIMP CUtils::TileProjectionToGeoProjection(tkTileProjection projection, // ******************************************************** STDMETHODIMP CUtils::get_ComUsageReport(VARIANT_BOOL unreleasedOnly, BSTR* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) CString s = gReferenceCounter.GetReport(unreleasedOnly ? true : false); USES_CONVERSION; *retVal = A2BSTR(s); @@ -5298,7 +5298,7 @@ GDALDataset* OpenOutputFile(GDALDriverH outputDriver, CStringW filename, int xSi GDALDataset* outputDataset = (GDALDataset*)GDALCreate(outputDriver, Utility::ConvertToUtf8(filename), xSize, ySize, 1, GDT_Float32, papszOptions); double transform[6]; - sourceTransform->GetGeoTransform((double*)&transform); + sourceTransform->GetGeoTransform(reinterpret_cast(&transform)); outputDataset->SetGeoTransform(transform); outputDataset->SetProjection(sourceTransform->GetProjectionRef()); @@ -5328,7 +5328,7 @@ int atoi_custom(const char* c) { STDMETHODIMP CUtils::CalculateRaster(SAFEARRAY* InputNames, BSTR expression, BSTR outputFilename, BSTR gdalOutputFormat, float outputNodataValue, ICallback* callback, BSTR* errorMsg, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; CustomExpression expr; @@ -5533,7 +5533,7 @@ STDMETHODIMP CUtils::CalculateRaster(SAFEARRAY* InputNames, BSTR expression, BST { for (int j = 0; j < numColumns; ++j) { - calcData[j] = (float)resultMatrix->number(); + calcData[j] = static_cast(resultMatrix->number()); } } else //result is real matrix @@ -5541,7 +5541,7 @@ STDMETHODIMP CUtils::CalculateRaster(SAFEARRAY* InputNames, BSTR expression, BST memcpy(calcData, resultMatrix->data(), resultMatrix->GetBufferSize()); } - float ndv = (float)resultMatrix->nodataValue(); + float ndv = static_cast(resultMatrix->nodataValue()); int count = 0; for (int j = 0; j < numColumns; ++j) { @@ -5636,7 +5636,7 @@ STDMETHODIMP CUtils::ReclassifyRaster(BSTR Filename, int bandIndex, BSTR outputN SAFEARRAY* HighBounds, SAFEARRAY* NewValues, BSTR gdalOutputFormat, ICallback* cBack, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; USES_CONVERSION; @@ -5759,7 +5759,7 @@ STDMETHODIMP CUtils::ReclassifyRaster(BSTR Filename, int bandIndex, BSTR outputN index = findBreak(breaks, (double)(*(data + j))); if (index != -1) { - *(data + j) = (float)breaks[index].newVal; + *(data + j) = static_cast(breaks[index].newVal); } else { @@ -5788,7 +5788,7 @@ STDMETHODIMP CUtils::ReclassifyRaster(BSTR Filename, int bandIndex, BSTR outputN // ************************************************* STDMETHODIMP CUtils::IsTiffGrid(BSTR Filename, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) *retVal = VARIANT_FALSE; try @@ -5835,7 +5835,7 @@ STDMETHODIMP CUtils::IsTiffGrid(BSTR Filename, VARIANT_BOOL* retVal) // ************************************************* STDMETHODIMP CUtils::EPSGUnitConversion(int EPSGUnitCode, tkUnitsOfMeasure* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // convert common EPSG codes to internal enumeration switch (EPSGUnitCode) @@ -5902,8 +5902,8 @@ STDMETHODIMP CUtils::LineInterpolatePoint(IShape* sourceLine, IPoint* startPoint { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - // initialize return point to null - * retVal = nullptr; + // initialize return point to null + * retVal = nullptr; // basic validation if (sourceLine == nullptr || startPoint == nullptr) @@ -6031,8 +6031,8 @@ STDMETHODIMP CUtils::LineProjectDistanceTo(IShape* sourceLine, IShape* reference { AFX_MANAGE_STATE(AfxGetStaticModuleState()) - // initialize return value - * distance = 0; + // initialize return value + * distance = 0; // basic validation if (sourceLine == nullptr || referenceShape == nullptr) diff --git a/src/COM classes/Utils_GDAL.cpp b/src/COM classes/Utils_GDAL.cpp index 9a14afc9..945e310c 100644 --- a/src/COM classes/Utils_GDAL.cpp +++ b/src/COM classes/Utils_GDAL.cpp @@ -46,7 +46,7 @@ void CheckExtensionConsistency(const char* pszDestFilename, { GDALDriverH hDriver = GDALGetDriver(i); const char* pszDriverExtension = - GDALGetMetadataItem( hDriver, GDAL_DMD_EXTENSION, NULL ); + GDALGetMetadataItem( hDriver, GDAL_DMD_EXTENSION, NULL ); if (pszDriverExtension && EQUAL(pszDestExtension, pszDriverExtension)) { if (GDALGetDriverByName(pszDriverName) != hDriver) @@ -152,7 +152,7 @@ BOOL CUtils::ProcessGeneralOptions(int * opts) fpOptFile = VSIFOpen( sFileName, "rb" ); - if( fpOptFile == NULL ) + if( fpOptFile == nullptr) { CPLError( CE_Failure, CPLE_AppDefined, "Unable to open optfile '%s'.\n%s", @@ -160,7 +160,7 @@ BOOL CUtils::ProcessGeneralOptions(int * opts) return FALSE; } - while( (pszLine = CPLReadLine( fpOptFile )) != NULL ) + while( (pszLine = CPLReadLine( fpOptFile )) != nullptr) { char **papszTokens; int i; @@ -169,7 +169,7 @@ BOOL CUtils::ProcessGeneralOptions(int * opts) continue; papszTokens = CSLTokenizeString( pszLine ); - for( i = 0; papszTokens != NULL && papszTokens[i] != NULL; i++) + for( i = 0; papszTokens != nullptr && papszTokens[i] != nullptr; i++) _sArr.Add( papszTokens[i] ); CSLDestroy( papszTokens ); } @@ -178,7 +178,7 @@ BOOL CUtils::ProcessGeneralOptions(int * opts) } } - *opts = _sArr.GetCount(); + *opts = static_cast(_sArr.GetCount()); return TRUE; } @@ -186,7 +186,7 @@ BOOL CUtils::ProcessGeneralOptions(int * opts) HRESULT CUtils::ResetConfigOptions(long ErrorCode) { for( int i = 0; i < _sConfig.GetCount(); i++ ) - CPLSetConfigOption( _sConfig[i].GetBuffer(0), NULL); + CPLSetConfigOption( _sConfig[i].GetBuffer(0), nullptr); _sConfig.RemoveAll(); @@ -230,10 +230,10 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, int bReportHistograms = FALSE; int bReportProj4 = FALSE; int nSubdataset = -1; - const char *pszFilename = NULL; - char **papszExtraMDDomains = NULL, **papszFileList; - const char *pszProjection = NULL; - OGRCoordinateTransformationH hTransform = NULL; + const char *pszFilename = nullptr; + char **papszExtraMDDomains = nullptr, **papszFileList; + const char *pszProjection = nullptr; + OGRCoordinateTransformationH hTransform = nullptr; int bShowFileList = TRUE; pszFilename = OLE2CA(bstrSrcFilename); @@ -302,10 +302,9 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, GDALDriverH hDriver = GDALGetDriver(iDr); const char *pszRWFlag; - if( GDALGetMetadataItem( hDriver, GDAL_DCAP_CREATE, NULL ) ) + if( GDALGetMetadataItem( hDriver, GDAL_DCAP_CREATE, nullptr) ) pszRWFlag = "rw+"; - else if( GDALGetMetadataItem( hDriver, GDAL_DCAP_CREATECOPY, - NULL ) ) + else if( GDALGetMetadataItem( hDriver, GDAL_DCAP_CREATECOPY, nullptr) ) pszRWFlag = "rw"; else pszRWFlag = "ro"; @@ -346,7 +345,7 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, sOutput.AppendFormat( " Short Name: %s\n", GDALGetDriverShortName( hDriver ) ); sOutput.AppendFormat( " Long Name: %s\n", GDALGetDriverLongName( hDriver ) ); - papszMD = GDALGetMetadata( hDriver, NULL ); + papszMD = GDALGetMetadata( hDriver, nullptr); if( CSLFetchNameValue( papszMD, GDAL_DMD_EXTENSION ) ) { @@ -397,7 +396,7 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, /* Open dataset. */ /* -------------------------------------------------------------------- */ hDataset = GdalHelper::OpenRasterDatasetW(OLE2W(bstrSrcFilename), GA_ReadOnly); - if( hDataset == NULL ) + if( hDataset == nullptr) { CPLError(CE_Failure,0, "gdalinfo failed - unable to open '%s'.\n", @@ -407,7 +406,7 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, GDALDumpOpenDatasets( stderr ); - CPLDumpSharedList( NULL ); + CPLDumpSharedList(nullptr); return ResetConfigOptions(tkGDAL_ERROR); } @@ -462,7 +461,7 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, sOutput.AppendFormat( "Files: %s\n", papszFileList[0] ); if( bShowFileList ) { - for( i = 1; papszFileList[i] != NULL; i++ ) + for( i = 1; papszFileList[i] != nullptr; i++ ) sOutput.AppendFormat( " %s\n", papszFileList[i] ); } } @@ -475,17 +474,17 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, /* -------------------------------------------------------------------- */ /* Report projection. */ /* -------------------------------------------------------------------- */ - if( GDALGetProjectionRef( hDataset ) != NULL ) + if( GDALGetProjectionRef( hDataset ) != nullptr) { OGRSpatialReferenceH hSRS; char *pszProjection; pszProjection = (char *) GDALGetProjectionRef( hDataset ); - hSRS = OSRNewSpatialReference(NULL); + hSRS = OSRNewSpatialReference(nullptr); if( OSRImportFromWkt( hSRS, &pszProjection ) == CE_None ) { - char *pszPrettyWkt = NULL; + char *pszPrettyWkt = nullptr; OSRExportToPrettyWkt( hSRS, &pszPrettyWkt, FALSE ); sOutput.AppendFormat( "Coordinate System is:\n%s\n", pszPrettyWkt ); @@ -497,7 +496,7 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, if ( bReportProj4 ) { - char *pszProj4 = NULL; + char *pszProj4 = nullptr; OSRExportToProj4( hSRS, &pszProj4 ); sOutput.AppendFormat("PROJ.4 string is:\n\'%s\'\n",pszProj4); CPLFree( pszProj4 ); @@ -536,17 +535,17 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, /* -------------------------------------------------------------------- */ if( bShowGCPs && GDALGetGCPCount( hDataset ) > 0 ) { - if (GDALGetGCPProjection(hDataset) != NULL) + if (GDALGetGCPProjection(hDataset) != nullptr) { OGRSpatialReferenceH hSRS; char *pszProjection; pszProjection = (char *) GDALGetGCPProjection( hDataset ); - hSRS = OSRNewSpatialReference(NULL); + hSRS = OSRNewSpatialReference(nullptr); if( OSRImportFromWkt( hSRS, &pszProjection ) == CE_None ) { - char *pszPrettyWkt = NULL; + char *pszPrettyWkt = nullptr; OSRExportToPrettyWkt( hSRS, &pszPrettyWkt, FALSE ); sOutput.AppendFormat( "GCP Projection = \n%s\n", pszPrettyWkt ); @@ -576,11 +575,11 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, /* -------------------------------------------------------------------- */ /* Report metadata. */ /* -------------------------------------------------------------------- */ - papszMetadata = (bShowMetadata) ? GDALGetMetadata( hDataset, NULL ) : NULL; + papszMetadata = (bShowMetadata) ? GDALGetMetadata( hDataset, nullptr) : nullptr; if( bShowMetadata && CSLCount(papszMetadata) > 0 ) { sOutput += "Metadata:\n"; - for( i = 0; papszMetadata[i] != NULL; i++ ) + for( i = 0; papszMetadata[i] != nullptr; i++ ) { sOutput.AppendFormat( " %s\n", papszMetadata[i] ); } @@ -592,7 +591,7 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, if( CSLCount(papszMetadata) > 0 ) { sOutput.AppendFormat( "Metadata (%s):\n", papszExtraMDDomains[iMDD]); - for( i = 0; papszMetadata[i] != NULL; i++ ) + for( i = 0; papszMetadata[i] != nullptr; i++ ) { if (EQUALN(papszExtraMDDomains[iMDD], "xml:", 4)) sOutput.AppendFormat( "%s\n", papszMetadata[i] ); @@ -605,11 +604,11 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, /* -------------------------------------------------------------------- */ /* Report "IMAGE_STRUCTURE" metadata. */ /* -------------------------------------------------------------------- */ - papszMetadata = (bShowMetadata) ? GDALGetMetadata( hDataset, "IMAGE_STRUCTURE" ) : NULL; + papszMetadata = (bShowMetadata) ? GDALGetMetadata( hDataset, "IMAGE_STRUCTURE" ) : nullptr; if( bShowMetadata && CSLCount(papszMetadata) > 0 ) { sOutput += "Image Structure Metadata:\n"; - for( i = 0; papszMetadata[i] != NULL; i++ ) + for( i = 0; papszMetadata[i] != nullptr; i++ ) { sOutput.AppendFormat( " %s\n", papszMetadata[i] ); } @@ -622,7 +621,7 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, if( CSLCount(papszMetadata) > 0 ) { sOutput += "Subdatasets:\n"; - for( i = 0; papszMetadata[i] != NULL; i++ ) + for( i = 0; papszMetadata[i] != nullptr; i++ ) { sOutput.AppendFormat( " %s\n", papszMetadata[i] ); } @@ -631,11 +630,11 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, /* -------------------------------------------------------------------- */ /* Report geolocation. */ /* -------------------------------------------------------------------- */ - papszMetadata = (bShowMetadata) ? GDALGetMetadata( hDataset, "GEOLOCATION" ) : NULL; + papszMetadata = (bShowMetadata) ? GDALGetMetadata( hDataset, "GEOLOCATION" ) : nullptr; if( bShowMetadata && CSLCount(papszMetadata) > 0 ) { sOutput += "Geolocation:\n"; - for( i = 0; papszMetadata[i] != NULL; i++ ) + for( i = 0; papszMetadata[i] != nullptr; i++ ) { sOutput.AppendFormat( " %s\n", papszMetadata[i] ); } @@ -644,11 +643,11 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, /* -------------------------------------------------------------------- */ /* Report RPCs */ /* -------------------------------------------------------------------- */ - papszMetadata = (bShowMetadata) ? GDALGetMetadata( hDataset, "RPC" ) : NULL; + papszMetadata = (bShowMetadata) ? GDALGetMetadata( hDataset, "RPC" ) : nullptr; if( bShowMetadata && CSLCount(papszMetadata) > 0 ) { sOutput += "RPC Metadata:\n"; - for( i = 0; papszMetadata[i] != NULL; i++ ) + for( i = 0; papszMetadata[i] != nullptr; i++ ) { sOutput.AppendFormat( " %s\n", papszMetadata[i] ); } @@ -660,15 +659,15 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, if( GDALGetGeoTransform( hDataset, adfGeoTransform ) == CE_None ) pszProjection = GDALGetProjectionRef(hDataset); - if( pszProjection != NULL && strlen(pszProjection) > 0 ) + if( pszProjection != nullptr && strlen(pszProjection) > 0 ) { - OGRSpatialReferenceH hProj, hLatLong = NULL; + OGRSpatialReferenceH hProj, hLatLong = nullptr; hProj = OSRNewSpatialReference( pszProjection ); - if( hProj != NULL ) + if( hProj != nullptr) hLatLong = OSRCloneGeogCS( hProj ); - if( hLatLong != NULL ) + if( hLatLong != nullptr) { CPLPushErrorHandler( CPLQuietErrorHandler ); hTransform = OCTNewCoordinateTransformation( hProj, hLatLong ); @@ -677,7 +676,7 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, OSRDestroySpatialReference( hLatLong ); } - if( hProj != NULL ) + if( hProj != nullptr) OSRDestroySpatialReference( hProj ); } @@ -698,10 +697,10 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, GDALGetRasterXSize(hDataset)/2.0, GDALGetRasterYSize(hDataset)/2.0 ); - if( hTransform != NULL ) + if( hTransform != nullptr) { OCTDestroyCoordinateTransformation( hTransform ); - hTransform = NULL; + hTransform = nullptr; } /* ==================================================================== */ @@ -735,7 +734,7 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, GDALGetColorInterpretationName( GDALGetRasterColorInterpretation(hBand)) ); - if( GDALGetDescription( hBand ) != NULL + if( GDALGetDescription( hBand ) != nullptr && strlen(GDALGetDescription( hBand )) > 0 ) sOutput.AppendFormat( " Description = %s\n", GDALGetDescription(hBand) ); @@ -773,7 +772,7 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, if( bReportHistograms ) { - int nBucketCount, *panHistogram = NULL; + int nBucketCount, *panHistogram = nullptr; struct CallbackParams params( GetCallback(), "Analyzing" ); eErr = GDALGetDefaultHistogram( hBand, &dfMin, &dfMax, @@ -819,13 +818,13 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, iOverview++ ) { GDALRasterBandH hOverview; - const char *pszResampling = NULL; + const char *pszResampling = nullptr; if( iOverview != 0 ) sOutput += ", " ; hOverview = GDALGetOverview( hBand, iOverview ); - if (hOverview != NULL) + if (hOverview != nullptr) { sOutput.AppendFormat( "%dx%d", GDALGetRasterBandXSize( hOverview ), @@ -872,7 +871,7 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, { sOutput += " Overviews: arbitrary\n"; } - + nMaskFlags = GDALGetMaskFlags( hBand ); if( (nMaskFlags & (GMF_NODATA|GMF_ALL_VALID)) == 0 ) { @@ -889,7 +888,7 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, sOutput += "ALL_VALID "; sOutput += "\n"; - if( hMaskBand != NULL && + if( hMaskBand != nullptr && GDALGetOverviewCount(hMaskBand) > 0 ) { int iOverview; @@ -918,13 +917,13 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, sOutput.AppendFormat( " Unit Type: %s\n", GDALGetRasterUnitType(hBand) ); } - if( GDALGetRasterCategoryNames(hBand) != NULL ) + if( GDALGetRasterCategoryNames(hBand) != nullptr) { char **papszCategories = GDALGetRasterCategoryNames(hBand); int i; sOutput += " Categories:\n"; - for( i = 0; papszCategories[i] != NULL; i++ ) + for( i = 0; papszCategories[i] != nullptr; i++ ) sOutput.AppendFormat( " %3d: %s\n", i, papszCategories[i] ); } @@ -934,28 +933,28 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, GDALGetRasterOffset( hBand, &bSuccess ), GDALGetRasterScale( hBand, &bSuccess ) ); - papszMetadata = (bShowMetadata) ? GDALGetMetadata( hBand, NULL ) : NULL; + papszMetadata = (bShowMetadata) ? GDALGetMetadata( hBand, nullptr) : nullptr; if( bShowMetadata && CSLCount(papszMetadata) > 0 ) { sOutput += " Metadata:\n"; - for( i = 0; papszMetadata[i] != NULL; i++ ) + for( i = 0; papszMetadata[i] != nullptr; i++ ) { sOutput.AppendFormat( " %s\n", papszMetadata[i] ); } } - papszMetadata = (bShowMetadata) ? GDALGetMetadata( hBand, "IMAGE_STRUCTURE" ) : NULL; + papszMetadata = (bShowMetadata) ? GDALGetMetadata( hBand, "IMAGE_STRUCTURE" ) : nullptr; if( bShowMetadata && CSLCount(papszMetadata) > 0 ) { sOutput += " Image Structure Metadata:\n"; - for( i = 0; papszMetadata[i] != NULL; i++ ) + for( i = 0; papszMetadata[i] != nullptr; i++ ) { sOutput.AppendFormat( " %s\n", papszMetadata[i] ); } } if( GDALGetRasterColorInterpretation(hBand) == GCI_PaletteIndex - && (hTable = GDALGetRasterColorTable( hBand )) != NULL ) + && (hTable = GDALGetRasterColorTable( hBand )) != nullptr) { int i; @@ -981,11 +980,11 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, } } - if( bShowRAT && GDALGetDefaultRAT( hBand ) != NULL ) + if( bShowRAT && GDALGetDefaultRAT( hBand ) != nullptr) { GDALRasterAttributeTableH hRAT = GDALGetDefaultRAT( hBand ); - GDALRATDumpReadable( hRAT, NULL ); + GDALRATDumpReadable( hRAT, nullptr); } } @@ -995,7 +994,7 @@ STDMETHODIMP CUtils::GDALInfo(BSTR bstrSrcFilename, BSTR bstrOptions, GDALDumpOpenDatasets( stderr ); - CPLDumpSharedList( NULL ); + CPLDumpSharedList(nullptr); CPLCleanupTLS(); *bstrInfo = sOutput.AllocSysString(); @@ -1053,8 +1052,8 @@ GDALInfoReportCorner(GDALDatasetH hDataset, /* -------------------------------------------------------------------- */ /* Transform to latlong and report. */ /* -------------------------------------------------------------------- */ - if( hTransform != NULL - && OCTTransform(hTransform,1,&dfGeoX,&dfGeoY,NULL) ) + if( hTransform != nullptr + && OCTTransform(hTransform,1,&dfGeoX,&dfGeoY, nullptr) ) { sTemp.Format( "(%s,", GDALDecToDMS( dfGeoX, "Long", 2 ) ); @@ -1126,7 +1125,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, GDALDatasetH hDataset, hOutDS; int i; int nRasterXSize, nRasterYSize; - const char *pszSource=NULL, *pszDest=NULL, *pszFormat = "GTiff"; + const char *pszSource = nullptr, *pszDest = nullptr, *pszFormat = "GTiff"; int bFormatExplicitelySet = FALSE; GDALDriverH hDriver; int *panBandList = NULL; /* negative value of panBandList[i] means mask band of ABS(panBandList[i]) */ @@ -1134,20 +1133,20 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, double adfGeoTransform[6]; GDALDataType eOutputType = GDT_Unknown; int nOXSize = 0, nOYSize = 0; - char *pszOXSize=NULL, *pszOYSize=NULL; - char **papszCreateOptions = NULL; + char *pszOXSize = nullptr, *pszOYSize = nullptr; + char **papszCreateOptions = nullptr; int anSrcWin[4], bStrict = FALSE; const char *pszProjection; int bScale = FALSE, bHaveScaleSrc = FALSE, bUnscale = FALSE; double dfScaleSrcMin=0.0, dfScaleSrcMax=255.0; double dfScaleDstMin=0.0, dfScaleDstMax=255.0; double dfULX, dfULY, dfLRX, dfLRY; - char **papszMetadataOptions = NULL; - char *pszOutputSRS = NULL; + char **papszMetadataOptions = nullptr; + char *pszOutputSRS = nullptr; int bGotBounds = FALSE; GDALProgressFunc pfnProgress = (GDALProgressFunc)GDALProgressCallback; int nGCPCount = 0; - GDAL_GCP *pasGCPs = NULL; + GDAL_GCP *pasGCPs = nullptr; int bCopySubDatasets = FALSE; double adfULLR[4] = { 0,0,0,0 }; int bSetNoData = FALSE; @@ -1188,7 +1187,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, } } else - argc = _sArr.GetCount(); + argc = static_cast(_sArr.GetCount()); /* -------------------------------------------------------------------- */ /* Handle command line arguments. */ @@ -1206,7 +1205,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, for( iType = 1; iType < GDT_TypeCount; iType++ ) { - if (GDALGetDataTypeName((GDALDataType)iType) != NULL + if (GDALGetDataTypeName((GDALDataType)iType) != nullptr && EQUAL(GDALGetDataTypeName((GDALDataType)iType), _sArr[i+1]) ) { @@ -1478,7 +1477,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, hDataset = GDALOpenShared(pszSource, GA_ReadOnly); - if (hDataset == NULL) + if (hDataset == nullptr) { return ResetConfigOptions(tkGDAL_ERROR); } @@ -1507,7 +1506,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, (*retval) = VARIANT_TRUE; _bSubCall = TRUE; - for ( i = 0; papszSubdatasets[i] != NULL; i += 2 ) + for ( i = 0; papszSubdatasets[i] != nullptr; i += 2 ) { sprintf (pszSubDest, "%s%d", pszDest, i/2 + 1); @@ -1515,7 +1514,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, BSTR bstrSubSrc = SysAllocString(CT2W(strstr(papszSubdatasets[i],"=")+1)); VARIANT_BOOL subret = VARIANT_FALSE; - this->TranslateRaster(bstrSubSrc,bstrSubDest,NULL,cBack,&subret); + this->TranslateRaster(bstrSubSrc,bstrSubDest, nullptr,cBack,&subret); SysFreeString(bstrSubDest); SysFreeString(bstrSubSrc); @@ -1621,7 +1620,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, { CPLError(CE_Failure, 0, "Computed -srcwin falls outside raster size of %dx%d.", - GDALGetRasterXSize(hDataset), + GDALGetRasterXSize(hDataset), GDALGetRasterYSize(hDataset) ); return ResetConfigOptions(tkGDAL_ERROR); } @@ -1651,7 +1650,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* Find the output driver. */ /* -------------------------------------------------------------------- */ hDriver = GDALGetDriverByName (pszFormat); - if (hDriver == NULL) + if (hDriver == nullptr) { CPLError(CE_Failure,0, "Output driver `%s' not recognized.", pszFormat ); @@ -1676,7 +1675,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, anSrcWin[0] == 0 && anSrcWin[1] == 0 && anSrcWin[2] == GDALGetRasterXSize(hDataset) && anSrcWin[3] == GDALGetRasterYSize(hDataset) - && pszOXSize == NULL && pszOYSize == NULL ); + && pszOXSize == nullptr && pszOYSize == nullptr); if( eOutputType == GDT_Unknown && !bScale && !bUnscale @@ -1684,7 +1683,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, && eMaskMode == MASK_AUTO && bSpatialArrangementPreserved && nGCPCount == 0 && !bGotBounds - && pszOutputSRS == NULL && !bSetNoData && !bUnsetNoData + && pszOutputSRS == nullptr && !bSetNoData && !bUnsetNoData && nRGBExpand == 0 && !bStats) { struct CallbackParams params(GetCallback(), "Translating"); @@ -1693,7 +1692,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, bStrict, papszCreateOptions, pfnProgress, ¶ms); - if (hOutDS != NULL) + if (hOutDS != nullptr) { (*retval) = VARIANT_TRUE; GDALClose (hOutDS); @@ -1720,7 +1719,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ /* Establish some parameters. */ /* -------------------------------------------------------------------- */ - if (pszOXSize == NULL) + if (pszOXSize == nullptr) { nOXSize = anSrcWin[2]; nOYSize = anSrcWin[3]; @@ -1745,14 +1744,14 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, if (nGCPCount == 0) { - if (pszOutputSRS != NULL) + if (pszOutputSRS != nullptr) { poVDS->SetProjection (pszOutputSRS); } else { pszProjection = GDALGetProjectionRef (hDataset); - if (pszProjection != NULL && strlen (pszProjection) > 0) + if (pszProjection != nullptr && strlen (pszProjection) > 0) poVDS->SetProjection (pszProjection); } } @@ -1789,9 +1788,9 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, { const char *pszGCPProjection = pszOutputSRS; - if( pszGCPProjection == NULL ) + if( pszGCPProjection == nullptr) pszGCPProjection = GDALGetGCPProjection( hDataset ); - if( pszGCPProjection == NULL ) + if( pszGCPProjection == nullptr) pszGCPProjection = ""; poVDS->SetGCPs( nGCPCount, pasGCPs, pszGCPProjection ); @@ -1860,11 +1859,11 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, char **papszMD; papszMD = ((GDALDataset*)hDataset)->GetMetadata("RPC"); - if( papszMD != NULL ) + if( papszMD != nullptr) poVDS->SetMetadata( papszMD, "RPC" ); papszMD = ((GDALDataset*)hDataset)->GetMetadata("GEOLOCATION"); - if( papszMD != NULL ) + if( papszMD != nullptr) poVDS->SetMetadata( papszMD, "GEOLOCATION" ); } @@ -1878,7 +1877,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, if (panBandList[0] < 0) poSrcBand = poSrcBand->GetMaskBand(); GDALColorTable* poColorTable = poSrcBand->GetColorTable(); - if (poColorTable == NULL) + if (poColorTable == nullptr) { CPLError(CE_Failure, 0, "Error : band %d has no color table", ABS(panBandList[0])); GDALClose( hDataset ); @@ -1955,7 +1954,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ /* Create this band. */ /* -------------------------------------------------------------------- */ - poVDS->AddBand( eBandType, NULL ); + poVDS->AddBand( eBandType, nullptr); poVRTBand = (VRTSourcedRasterBand *) poVDS->GetRasterBand( i+1 ); if (nSrcBand < 0) { @@ -2151,7 +2150,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, { double dfMin, dfMax, dfMean, dfStdDev; poVDS->GetRasterBand(i+1)->ComputeStatistics( bApproxStats, - &dfMin, &dfMax, &dfMean, &dfStdDev, GDALDummyProgress, NULL ); + &dfMin, &dfMax, &dfMean, &dfStdDev, GDALDummyProgress, nullptr); } } @@ -2163,7 +2162,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, hOutDS = GDALCreateCopy( hDriver, pszDest, (GDALDatasetH) poVDS, bStrict, papszCreateOptions, pfnProgress, ¶ms ); - if( hOutDS != NULL ) + if( hOutDS != nullptr) { int bHasGotErr = FALSE; CPLErrorReset(); @@ -2175,7 +2174,7 @@ STDMETHODIMP CUtils::TranslateRaster(BSTR bstrSrcFilename, BSTR bstrDstFilename, GDALClose( hOutDS ); if (bHasGotErr) - hOutDS = NULL; + hOutDS = nullptr; } GDALClose( (GDALDatasetH) poVDS ); @@ -2231,11 +2230,11 @@ static void AttachMetadata( GDALDatasetH hDS, char **papszMetadataOptions ) for( i = 0; i < nCount; i++ ) { - char *pszKey = NULL; + char *pszKey = nullptr; const char *pszValue; pszValue = CPLParseNameValue( papszMetadataOptions[i], &pszKey ); - GDALSetMetadataItem(hDS,pszKey,pszValue,NULL); + GDALSetMetadataItem(hDS,pszKey,pszValue, nullptr); CPLFree( pszKey ); } @@ -2263,8 +2262,8 @@ static void CopyBandInfo(GDALRasterBand * poSrcBand, GDALRasterBand * poDstBand, else { char** papszMetadata = poSrcBand->GetMetadata(); - char** papszMetadataNew = NULL; - for( int i = 0; papszMetadata != NULL && papszMetadata[i] != NULL; i++ ) + char** papszMetadataNew = nullptr; + for( int i = 0; papszMetadata != nullptr && papszMetadata[i] != nullptr; i++ ) { if (strncmp(papszMetadata[i], "STATISTICS_", 11) != 0) papszMetadataNew = CSLAddString(papszMetadataNew, papszMetadata[i]); @@ -2386,23 +2385,23 @@ static void ProcessLayer( /* -------------------------------------------------------------------- */ if (!bSRSIsSet) { - OGRSpatialReferenceH hDstSRS = NULL; - if( GDALGetProjectionRef( hDstDS ) != NULL ) + OGRSpatialReferenceH hDstSRS = nullptr; + if( GDALGetProjectionRef( hDstDS ) != nullptr) { char *pszProjection; pszProjection = (char *) GDALGetProjectionRef( hDstDS ); - hDstSRS = OSRNewSpatialReference(NULL); + hDstSRS = OSRNewSpatialReference(nullptr); if( OSRImportFromWkt( hDstSRS, &pszProjection ) != CE_None ) { OSRDestroySpatialReference(hDstSRS); - hDstSRS = NULL; + hDstSRS = nullptr; } } OGRSpatialReferenceH hSrcSRS = OGR_L_GetSpatialRef(hSrcLayer); - if( hDstSRS != NULL && hSrcSRS != NULL ) + if( hDstSRS != nullptr && hSrcSRS != nullptr) { if( OSRIsSame(hSrcSRS, hDstSRS) == FALSE ) { @@ -2411,20 +2410,20 @@ static void ProcessLayer( "Results might be incorrect (no on-the-fly reprojection of input data).\n"); } } - else if( hDstSRS != NULL && hSrcSRS == NULL ) + else if( hDstSRS != nullptr && hSrcSRS == nullptr) { CPLError( CE_Warning, CPLE_AppDefined, "Warning : the output raster dataset has a SRS, but the input vector layer SRS is unknown.\n" "Ensure input vector has the same SRS, otherwise results might be incorrect.\n"); } - else if( hDstSRS == NULL && hSrcSRS != NULL ) + else if( hDstSRS == nullptr && hSrcSRS != nullptr) { CPLError( CE_Warning, CPLE_AppDefined, "Warning : the input vector layer has a SRS, but the output raster dataset SRS is unknown.\n" "Ensure output raster dataset has the same SRS, otherwise results might be incorrect.\n"); } - if( hDstSRS != NULL ) + if( hDstSRS != nullptr) { OSRDestroySpatialReference(hDstSRS); } @@ -2459,11 +2458,11 @@ static void ProcessLayer( OGR_L_ResetReading( hSrcLayer ); - while( (hFeat = OGR_L_GetNextFeature( hSrcLayer )) != NULL ) + while( (hFeat = OGR_L_GetNextFeature( hSrcLayer )) != nullptr) { OGRGeometryH hGeom; - if( OGR_F_GetGeometryRef( hFeat ) == NULL ) + if( OGR_F_GetGeometryRef( hFeat ) == nullptr) { OGR_F_Destroy( hFeat ); continue; @@ -2511,9 +2510,9 @@ static void ProcessLayer( /* -------------------------------------------------------------------- */ /* Perform the burn. */ /* -------------------------------------------------------------------- */ - GDALRasterizeGeometries( hDstDS, anBandList.size(), &(anBandList[0]), - ahGeometries.size(), &(ahGeometries[0]), - NULL, NULL, &(adfFullBurnValues[0]), + GDALRasterizeGeometries( hDstDS, static_cast(anBandList.size()), &(anBandList[0]), + static_cast(ahGeometries.size()), &(ahGeometries[0]), + nullptr, nullptr, &(adfFullBurnValues[0]), papszRasterizeOptions, pfnProgress, pProgressData ); @@ -2522,7 +2521,7 @@ static void ProcessLayer( /* -------------------------------------------------------------------- */ int iGeom; - for( iGeom = ahGeometries.size()-1; iGeom >= 0; iGeom-- ) + for( iGeom = static_cast(ahGeometries.size())-1; iGeom >= 0; iGeom-- ) OGR_G_DestroyGeometry( ahGeometries[iGeom] ); } @@ -2542,8 +2541,8 @@ GDALDatasetH CreateOutputDataset(std::vector ahLayers, int bNoDataSet, double dfNoData) { int bFirstLayer = TRUE; - char* pszWKT = NULL; - GDALDatasetH hDstDS = NULL; + char* pszWKT = nullptr; + GDALDatasetH hDstDS = nullptr; unsigned int i; for( i = 0; i < ahLayers.size(); i++ ) @@ -2557,7 +2556,7 @@ GDALDatasetH CreateOutputDataset(std::vector ahLayers, if (OGR_L_GetExtent(hLayer, &sLayerEnvelop, TRUE) != OGRERR_NONE) { CPLError( CE_Failure, CPLE_AppDefined, "Cannot get layer extent\n"); - return NULL; + return nullptr; } /* When rasterizing point layers and that the bounds have */ @@ -2579,7 +2578,7 @@ GDALDatasetH CreateOutputDataset(std::vector ahLayers, sEnvelop.MaxX = sLayerEnvelop.MaxX; sEnvelop.MaxY = sLayerEnvelop.MaxY; - if (hSRS == NULL) + if (hSRS == nullptr) hSRS = OGR_L_GetSpatialRef(hLayer); bFirstLayer = FALSE; @@ -2596,7 +2595,7 @@ GDALDatasetH CreateOutputDataset(std::vector ahLayers, { if (bFirstLayer) { - if (hSRS == NULL) + if (hSRS == nullptr) hSRS = OGR_L_GetSpatialRef(hLayer); bFirstLayer = FALSE; @@ -2633,10 +2632,10 @@ GDALDatasetH CreateOutputDataset(std::vector ahLayers, hDstDS = GDALCreate(hDriver, pszDstFilename, nXSize, nYSize, nBandCount, eOutputType, papszCreateOptions); - if (hDstDS == NULL) + if (hDstDS == nullptr) { CPLError( CE_Failure, CPLE_AppDefined, "Cannot create %s\n", pszDstFilename); - return NULL; + return nullptr; } GDALSetGeoTransform(hDstDS, adfProjection); @@ -2691,21 +2690,21 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, int argc = 0; int i, b3D = FALSE; int bInverse = FALSE; - const char *pszSrcFilename = NULL; - const char *pszDstFilename = NULL; - char **papszLayers = NULL; - const char *pszSQL = NULL; - const char *pszBurnAttribute = NULL; - const char *pszWHERE = NULL; + const char *pszSrcFilename = nullptr; + const char *pszDstFilename = nullptr; + char **papszLayers = nullptr; + const char *pszSQL = nullptr; + const char *pszBurnAttribute = nullptr; + const char *pszWHERE = nullptr; std::vector anBandList; std::vector adfBurnValues; - char **papszRasterizeOptions = NULL; + char **papszRasterizeOptions = nullptr; double dfXRes = 0, dfYRes = 0; int bCreateOutput = FALSE; const char* pszFormat = "GTiff"; int bFormatExplicitelySet = FALSE; - char **papszCreateOptions = NULL; - GDALDriverH hDriver = NULL; + char **papszCreateOptions = nullptr; + GDALDriverH hDriver = nullptr; GDALDataType eOutputType = GDT_Float64; std::vector adfInitVals; int bNoDataSet = FALSE; @@ -2715,7 +2714,7 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, int nXSize = 0, nYSize = 0; int bQuiet = FALSE; GDALProgressFunc pfnProgress = GDALProgressCallback; - OGRSpatialReferenceH hSRS = NULL; + OGRSpatialReferenceH hSRS = nullptr; int bTargetAlignedPixels = FALSE; struct CallbackParams params(GetCallback(), "Rasterizing"); @@ -2852,7 +2851,7 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, } else if( EQUAL(_sArr[i],"-a_srs") && i < argc-1 ) { - hSRS = OSRNewSpatialReference( NULL ); + hSRS = OSRNewSpatialReference(nullptr); if( OSRSetFromUserInput(hSRS, _sArr[i+1]) != OGRERR_NONE ) { @@ -2894,7 +2893,7 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, for( iType = 1; iType < GDT_TypeCount; iType++ ) { - if( GDALGetDataTypeName((GDALDataType)iType) != NULL + if( GDALGetDataTypeName((GDALDataType)iType) != nullptr && EQUAL(GDALGetDataTypeName((GDALDataType)iType), _sArr[i+1]) ) { @@ -2942,13 +2941,13 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, pszSrcFilename = OLE2CA(bstrSrcFilename); pszDstFilename = OLE2CA(bstrDstFilename); - if( pszSrcFilename == NULL || pszDstFilename == NULL ) + if( pszSrcFilename == nullptr || pszDstFilename == nullptr) { CPLError( CE_Failure, CPLE_AppDefined, "Missing source or destination.\n\n" ); return ResetConfigOptions(tkGDAL_ERROR); } - if( adfBurnValues.size() == 0 && pszBurnAttribute == NULL && !b3D ) + if( adfBurnValues.size() == 0 && pszBurnAttribute == nullptr && !b3D ) { CPLError( CE_Failure, CPLE_AppDefined, "At least one of -3d, -burn or -a required.\n\n" ); return ResetConfigOptions(tkGDAL_ERROR); @@ -2977,10 +2976,10 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, int nBandCount = 1; if (adfBurnValues.size() != 0) - nBandCount = adfBurnValues.size(); + nBandCount = static_cast(adfBurnValues.size()); if ((int)adfInitVals.size() > nBandCount) - nBandCount = adfInitVals.size(); + nBandCount = static_cast(adfInitVals.size()); if (adfInitVals.size() == 1) { @@ -3003,19 +3002,19 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ OGRDataSourceH hSrcDS; - hSrcDS = OGROpen( pszSrcFilename, FALSE, NULL ); - if( hSrcDS == NULL ) + hSrcDS = OGROpen( pszSrcFilename, FALSE, nullptr); + if( hSrcDS == nullptr) { CPLError( CE_Failure, CPLE_AppDefined, "Failed to open feature source: %s\n", pszSrcFilename); return ResetConfigOptions(tkGDAL_ERROR); } - if( pszSQL == NULL && papszLayers == NULL ) + if( pszSQL == nullptr && papszLayers == nullptr) { if( OGR_DS_GetLayerCount(hSrcDS) == 1 ) { - papszLayers = CSLAddString(NULL, OGR_L_GetName(OGR_DS_GetLayer(hSrcDS, 0))); + papszLayers = CSLAddString(nullptr, OGR_L_GetName(OGR_DS_GetLayer(hSrcDS, 0))); } else { @@ -3028,7 +3027,7 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* Open target raster file. Eventually we will add optional */ /* creation. */ /* -------------------------------------------------------------------- */ - GDALDatasetH hDstDS = NULL; + GDALDatasetH hDstDS = nullptr; if (bCreateOutput) { @@ -3036,8 +3035,8 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* Find the output driver. */ /* -------------------------------------------------------------------- */ hDriver = GDALGetDriverByName( pszFormat ); - if( hDriver == NULL - || GDALGetMetadataItem( hDriver, GDAL_DCAP_CREATE, NULL ) == NULL ) + if( hDriver == nullptr + || GDALGetMetadataItem( hDriver, GDAL_DCAP_CREATE, nullptr) == nullptr) { CPLError(CE_Failure, CPLE_AppDefined, "Output driver `%s' not recognised or does not support direct output file creation", pszFormat); @@ -3050,19 +3049,19 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, else { hDstDS = GdalHelper::OpenRasterDatasetW(OLE2W(bstrDstFilename), GA_Update); - if( hDstDS == NULL ) + if( hDstDS == nullptr) return ResetConfigOptions(); } /* -------------------------------------------------------------------- */ /* Process SQL request. */ /* -------------------------------------------------------------------- */ - if( pszSQL != NULL ) + if( pszSQL != nullptr) { OGRLayerH hLayer; - hLayer = OGR_DS_ExecuteSQL( hSrcDS, pszSQL, NULL, NULL ); - if( hLayer != NULL ) + hLayer = OGR_DS_ExecuteSQL( hSrcDS, pszSQL, nullptr, nullptr); + if( hLayer != nullptr) { if (bCreateOutput) { @@ -3074,12 +3073,12 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, hDriver, pszDstFilename, nXSize, nYSize, dfXRes, dfYRes, bTargetAlignedPixels, - anBandList.size(), eOutputType, + static_cast(anBandList.size()), eOutputType, papszCreateOptions, adfInitVals, bNoDataSet, dfNoData); } - ProcessLayer( hLayer, hSRS != NULL, hDstDS, anBandList, + ProcessLayer( hLayer, hSRS != nullptr, hDstDS, anBandList, adfBurnValues, b3D, bInverse, pszBurnAttribute, papszRasterizeOptions, pfnProgress, ¶ms ); @@ -3092,14 +3091,14 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ int nLayerCount = CSLCount(papszLayers); - if (bCreateOutput && hDstDS == NULL) + if (bCreateOutput && hDstDS == nullptr) { std::vector ahLayers; for( i = 0; i < nLayerCount; i++ ) { OGRLayerH hLayer = OGR_DS_GetLayerByName( hSrcDS, papszLayers[i] ); - if( hLayer == NULL ) + if( hLayer == nullptr) { continue; } @@ -3111,7 +3110,7 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, hDriver, pszDstFilename, nXSize, nYSize, dfXRes, dfYRes, bTargetAlignedPixels, - anBandList.size(), eOutputType, + static_cast(anBandList.size()), eOutputType, papszCreateOptions, adfInitVals, bNoDataSet, dfNoData); } @@ -3123,7 +3122,7 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, for( i = 0; i < nLayerCount; i++ ) { OGRLayerH hLayer = OGR_DS_GetLayerByName( hSrcDS, papszLayers[i] ); - if( hLayer == NULL ) + if( hLayer == nullptr) { CPLError( CE_Warning, CPLE_AppDefined, "Unable to find layer %s, skipping.\n", papszLayers[i] ); @@ -3141,7 +3140,7 @@ STDMETHODIMP CUtils::GDALRasterize(BSTR bstrSrcFilename, BSTR bstrDstFilename, GDALCreateScaledProgress( 0.0, 1.0 * (i + 1) / nLayerCount, pfnProgress, ¶ms ); - ProcessLayer( hLayer, hSRS != NULL, hDstDS, anBandList, + ProcessLayer( hLayer, hSRS != nullptr, hDstDS, anBandList, adfBurnValues, b3D, bInverse, pszBurnAttribute, papszRasterizeOptions, GDALScaledProgress, pScaledProgress ); @@ -3199,11 +3198,11 @@ char *SanitizeSRS( const char *pszUserInput ) { OGRSpatialReferenceH hSRS; - char *pszResult = NULL; + char *pszResult = nullptr; CPLErrorReset(); - hSRS = OSRNewSpatialReference( NULL ); + hSRS = OSRNewSpatialReference(nullptr); if( OSRSetFromUserInput( hSRS, pszUserInput ) == OGRERR_NONE ) OSRExportToWkt( hSRS, &pszResult ); else @@ -3211,7 +3210,7 @@ char *SanitizeSRS( const char *pszUserInput ) CPLError( CE_Failure, CPLE_AppDefined, "Translating source or target SRS failed:\n%s", pszUserInput ); - return NULL; + return nullptr; } OSRDestroySpatialReference( hSRS ); @@ -3238,28 +3237,28 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, GDALDatasetH hDstDS; const char *pszFormat = "GTiff"; int bFormatExplicitelySet = FALSE; - char **papszSrcFiles = NULL; + char **papszSrcFiles = nullptr; char *pszDstFilename = NULL; int bCreateOutput = FALSE, i; - void *hTransformArg, *hGenImgProjArg=NULL, *hApproxArg=NULL; - char **papszWarpOptions = NULL; + void *hTransformArg, *hGenImgProjArg = nullptr, *hApproxArg = nullptr; + char **papszWarpOptions = nullptr; double dfErrorThreshold = 0.125; double dfWarpMemoryLimit = 0.0; - GDALTransformerFunc pfnTransformer = NULL; - char **papszCreateOptions = NULL; + GDALTransformerFunc pfnTransformer = nullptr; + char **papszCreateOptions = nullptr; GDALDataType eOutputType = GDT_Unknown, eWorkingType = GDT_Unknown; GDALResampleAlg eResampleAlg = GRA_NearestNeighbour; - const char *pszSrcNodata = NULL; - const char *pszDstNodata = NULL; + const char *pszSrcNodata = nullptr; + const char *pszDstNodata = nullptr; int bMulti = FALSE; - char **papszTO = NULL; - char *pszCutlineDSName = NULL; - char *pszCLayer = NULL, *pszCWHERE = NULL, *pszCSQL = NULL; - void *hCutline = NULL; + char **papszTO = nullptr; + char *pszCutlineDSName = nullptr; + char *pszCLayer = nullptr, *pszCWHERE = nullptr, *pszCSQL = nullptr; + void *hCutline = nullptr; int bHasGotErr = FALSE; int bCropToCutline = FALSE; int bOverwrite = FALSE; - struct CallbackParams params(GetCallback(), "Warping"); + struct CallbackParams params(GetCallback(), "Warping"); /* -------------------------------------------------------------------- */ /* Register standard GDAL drivers, and process generic GDAL */ @@ -3330,7 +3329,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, { char *pszSRS = SanitizeSRS(_sArr[++i]); - if (pszSRS == NULL) + if (pszSRS == nullptr) { CPLError(CE_Warning, CPLE_AppDefined, "GdalWarp: failed to read target projection argument (-t_srs)."); return ResetConfigOptions(); @@ -3343,7 +3342,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, { char *pszSRS = SanitizeSRS(_sArr[++i]); - if (pszSRS == NULL) + if (pszSRS == nullptr) { CPLError(CE_Warning, CPLE_AppDefined, "GdalWarp: failed to read source projection argument (-s_srs)."); return ResetConfigOptions(); @@ -3434,7 +3433,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, for( iType = 1; iType < GDT_TypeCount; iType++ ) { - if( GDALGetDataTypeName((GDALDataType)iType) != NULL + if( GDALGetDataTypeName((GDALDataType)iType) != nullptr && EQUAL(GDALGetDataTypeName((GDALDataType)iType), _sArr[i+1]) ) { @@ -3456,7 +3455,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, for( iType = 1; iType < GDT_TypeCount; iType++ ) { - if( GDALGetDataTypeName((GDALDataType)iType) != NULL + if( GDALGetDataTypeName((GDALDataType)iType) != nullptr && EQUAL(GDALGetDataTypeName((GDALDataType)iType), _sArr[i+1]) ) { @@ -3578,10 +3577,10 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, if( CSLCount(papszSrcFiles) > 1 ) { pszDstFilename = papszSrcFiles[CSLCount(papszSrcFiles)-1]; - papszSrcFiles[CSLCount(papszSrcFiles)-1] = NULL; + papszSrcFiles[CSLCount(papszSrcFiles)-1] = nullptr; } - if( pszDstFilename == NULL ) + if( pszDstFilename == nullptr) { CPLError(CE_Warning, CPLE_AppDefined, "GdalWarp: failed to find destination file name."); return ResetConfigOptions(); @@ -3614,13 +3613,13 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, hDstDS = GdalHelper::OpenRasterDatasetW(OLE2W(bstrDstFilename), GA_Update); CPLPopErrorHandler(); - if( hDstDS != NULL && bOverwrite ) + if( hDstDS != nullptr && bOverwrite ) { GDALClose(hDstDS); - hDstDS = NULL; + hDstDS = nullptr; } - if( hDstDS != NULL && bCreateOutput ) + if( hDstDS != nullptr && bCreateOutput ) { CPLError( CE_Failure, CPLE_AppDefined, "Output dataset %s exists,\n" @@ -3633,7 +3632,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* Avoid overwriting an existing destination file that cannot be opened in */ /* update mode with a new GTiff file */ - if ( hDstDS == NULL && !bOverwrite ) + if ( hDstDS == nullptr && !bOverwrite ) { CPLPushErrorHandler( CPLQuietErrorHandler ); hDstDS = GdalHelper::OpenRasterDatasetW(OLE2W(bstrDstFilename), GA_ReadOnly); @@ -3654,7 +3653,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* If we have a cutline datasource read it and attach it in the */ /* warp options. */ /* -------------------------------------------------------------------- */ - if( pszCutlineDSName != NULL ) + if( pszCutlineDSName != nullptr) { LoadCutline( pszCutlineDSName, pszCLayer, pszCWHERE, pszCSQL, &hCutline ); @@ -3754,10 +3753,10 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ int bInitDestSetForFirst = FALSE; - void* hUniqueTransformArg = NULL; - GDALDatasetH hUniqueSrcDS = NULL; + void* hUniqueTransformArg = nullptr; + GDALDatasetH hUniqueSrcDS = nullptr; - if( hDstDS == NULL ) + if( hDstDS == nullptr) { if (!bFormatExplicitelySet) CheckExtensionConsistency(pszDstFilename, pszFormat); @@ -3774,14 +3773,14 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, bEnableSrcAlpha, bEnableDstAlpha); bCreateOutput = TRUE; - if( CSLFetchNameValue( papszWarpOptions, "INIT_DEST" ) == NULL - && pszDstNodata == NULL ) + if( CSLFetchNameValue( papszWarpOptions, "INIT_DEST" ) == nullptr + && pszDstNodata == nullptr) { papszWarpOptions = CSLSetNameValue(papszWarpOptions, "INIT_DEST", "0"); bInitDestSetForFirst = TRUE; } - else if( CSLFetchNameValue( papszWarpOptions, "INIT_DEST" ) == NULL ) + else if( CSLFetchNameValue( papszWarpOptions, "INIT_DEST" ) == nullptr) { papszWarpOptions = CSLSetNameValue(papszWarpOptions, "INIT_DEST", "NO_DATA" ); @@ -3789,10 +3788,10 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, } CSLDestroy( papszCreateOptions ); - papszCreateOptions = NULL; + papszCreateOptions = nullptr; } - if( hDstDS == NULL ) + if( hDstDS == nullptr) // TODO: clean up memory...set error code? return ResetConfigOptions(); @@ -3801,7 +3800,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ int iSrc; - for( iSrc = 0; papszSrcFiles[iSrc] != NULL; iSrc++ ) + for( iSrc = 0; papszSrcFiles[iSrc] != nullptr; iSrc++ ) { GDALDatasetH hSrcDS; @@ -3813,7 +3812,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, else hSrcDS = GDALOpen( papszSrcFiles[iSrc], GA_ReadOnly ); // TODO: use Unicode - if( hSrcDS == NULL ) + if( hSrcDS == nullptr) // TODO: clean up memory? return ResetConfigOptions(); @@ -3833,7 +3832,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ if ( eResampleAlg != GRA_NearestNeighbour && - GDALGetRasterColorTable(GDALGetRasterBand(hSrcDS, 1)) != NULL) + GDALGetRasterColorTable(GDALGetRasterBand(hSrcDS, 1)) != nullptr) { CPLError( CE_Warning, CPLE_AppDefined, "Warning: Input file %s has a color table, which will likely lead to " "bad results when using a resampling method other than " @@ -3862,7 +3861,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, hTransformArg = hGenImgProjArg = GDALCreateGenImgProjTransformer2( hSrcDS, hDstDS, papszTO ); - if( hTransformArg == NULL ) + if( hTransformArg == nullptr) // TODO: clean up memory? return ResetConfigOptions(); @@ -3885,7 +3884,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ if( bInitDestSetForFirst && iSrc == 1 ) papszWarpOptions = CSLSetNameValue( papszWarpOptions, - "INIT_DEST", NULL ); + "INIT_DEST", nullptr); /* -------------------------------------------------------------------- */ /* Setup warp options. */ @@ -3945,7 +3944,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ /* Setup NODATA options. */ /* -------------------------------------------------------------------- */ - if( pszSrcNodata != NULL && !EQUALN(pszSrcNodata,"n",1) ) + if( pszSrcNodata != nullptr && !EQUALN(pszSrcNodata,"n",1) ) { char **papszTokens = CSLTokenizeString( pszSrcNodata ); int nTokenCount = CSLCount(papszTokens); @@ -3980,7 +3979,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* If -srcnodata was not specified, but the data has nodata */ /* values, use them. */ /* -------------------------------------------------------------------- */ - if( pszSrcNodata == NULL ) + if( pszSrcNodata == nullptr) { int bHaveNodata = FALSE; double dfReal = 0.0; @@ -4022,7 +4021,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* If the output dataset was created, and we have a destination */ /* nodata value, go through marking the bands with the information.*/ /* -------------------------------------------------------------------- */ - if( pszDstNodata != NULL ) + if( pszDstNodata != nullptr) { char **papszTokens = CSLTokenizeString( pszDstNodata ); int nTokenCount = CSLCount(papszTokens); @@ -4110,7 +4109,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* If we have a cutline, transform it into the source */ /* pixel/line coordinate system and insert into warp options. */ /* -------------------------------------------------------------------- */ - if( hCutline != NULL ) + if( hCutline != nullptr) { TransformCutlineToSource( hSrcDS, hCutline, &(psWO->papszWarpOptions), @@ -4136,7 +4135,7 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* have wrapped it inside the hApproxArg */ if (pfnTransformer == GDALApproxTransform) { - if( hGenImgProjArg != NULL ) + if( hGenImgProjArg != nullptr) GDALDestroyGenImgProjTransformer( hGenImgProjArg ); } @@ -4175,10 +4174,10 @@ STDMETHODIMP CUtils::GDALWarp(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ /* Cleanup */ /* -------------------------------------------------------------------- */ - if( hApproxArg != NULL ) + if( hApproxArg != nullptr) GDALDestroyApproxTransformer( hApproxArg ); - if( hGenImgProjArg != NULL ) + if( hGenImgProjArg != nullptr) GDALDestroyGenImgProjTransformer( hGenImgProjArg ); GDALDestroyWarpOptions( psWO ); @@ -4239,26 +4238,26 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename, GDALDriverH hDriver; GDALDatasetH hDstDS; void *hTransformArg; - GDALColorTableH hCT = NULL; + GDALColorTableH hCT = nullptr; double dfWrkMinX=0, dfWrkMaxX=0, dfWrkMinY=0, dfWrkMaxY=0; double dfWrkResX=0, dfWrkResY=0; int nDstBandCount = 0; std::vector apeColorInterpretations; - *phTransformArg = NULL; - *phSrcDS = NULL; + *phTransformArg = nullptr; + *phSrcDS = nullptr; /* -------------------------------------------------------------------- */ /* Find the output driver. */ /* -------------------------------------------------------------------- */ hDriver = GDALGetDriverByName( pszFormat ); - if( hDriver == NULL - || GDALGetMetadataItem( hDriver, GDAL_DCAP_CREATE, NULL ) == NULL ) + if( hDriver == nullptr + || GDALGetMetadataItem( hDriver, GDAL_DCAP_CREATE, nullptr) == nullptr) { CPLError(CE_Failure, CPLE_AppDefined, "Output driver `%s' not recognised or does not support direct output file creation.", pszFormat); // TODO: free up memory...set error code? - return NULL; + return nullptr; } /* -------------------------------------------------------------------- */ @@ -4275,18 +4274,18 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename, /* -------------------------------------------------------------------- */ int iSrc; char *pszThisTargetSRS = (char*)CSLFetchNameValue( papszTO, "DST_SRS" ); - if( pszThisTargetSRS != NULL ) + if( pszThisTargetSRS != nullptr) pszThisTargetSRS = CPLStrdup( pszThisTargetSRS ); - for( iSrc = 0; papszSrcFiles[iSrc] != NULL; iSrc++ ) + for( iSrc = 0; papszSrcFiles[iSrc] != nullptr; iSrc++ ) { GDALDatasetH hSrcDS; const char *pszThisSourceSRS = CSLFetchNameValue(papszTO,"SRC_SRS"); hSrcDS = GDALOpen( papszSrcFiles[iSrc], GA_ReadOnly ); // TODO: use Unicode - if( hSrcDS == NULL ) + if( hSrcDS == nullptr) // TODO: free up memory...set error code? - return NULL; + return nullptr; /* -------------------------------------------------------------------- */ /* Check that there's at least one raster band */ @@ -4295,7 +4294,7 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename, { CPLError(CE_Failure, CPLE_AppDefined, "Input file %s has no raster bands.\n", papszSrcFiles[iSrc]); // TODO: free up memory...set error code? - return NULL; + return nullptr; } if( eDT == GDT_Unknown ) @@ -4309,7 +4308,7 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename, { nDstBandCount = GDALGetRasterCount(hSrcDS); hCT = GDALGetRasterColorTable( GDALGetRasterBand(hSrcDS,1) ); - if( hCT != NULL ) + if( hCT != nullptr) { hCT = GDALCloneColorTable( hCT ); if( !bQuiet ) @@ -4327,21 +4326,21 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename, /* -------------------------------------------------------------------- */ /* Get the sourcesrs from the dataset, if not set already. */ /* -------------------------------------------------------------------- */ - if( pszThisSourceSRS == NULL ) + if( pszThisSourceSRS == nullptr) { const char *pszMethod = CSLFetchNameValue( papszTO, "METHOD" ); - if( GDALGetProjectionRef( hSrcDS ) != NULL + if( GDALGetProjectionRef( hSrcDS ) != nullptr && strlen(GDALGetProjectionRef( hSrcDS )) > 0 - && (pszMethod == NULL || EQUAL(pszMethod,"GEOTRANSFORM")) ) + && (pszMethod == nullptr || EQUAL(pszMethod,"GEOTRANSFORM")) ) pszThisSourceSRS = GDALGetProjectionRef( hSrcDS ); - else if( GDALGetGCPProjection( hSrcDS ) != NULL + else if( GDALGetGCPProjection( hSrcDS ) != nullptr && strlen(GDALGetGCPProjection(hSrcDS)) > 0 && GDALGetGCPCount( hSrcDS ) > 1 - && (pszMethod == NULL || EQUALN(pszMethod,"GCP_",4)) ) + && (pszMethod == nullptr || EQUALN(pszMethod,"GCP_",4)) ) pszThisSourceSRS = GDALGetGCPProjection( hSrcDS ); - else if( pszMethod != NULL && EQUAL(pszMethod,"RPC") ) + else if( pszMethod != nullptr && EQUAL(pszMethod,"RPC") ) #if GDAL_VERSION_MAJOR >= 3 pszThisSourceSRS = SRS_WKT_WGS84_LAT_LONG; // SRS_WKT_WGS84 macro is no longer declared by default since WKT without AXIS is too ambiguous. Preferred remediation: use SRS_WKT_WGS84_LAT_LONG #else @@ -4351,7 +4350,7 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename, pszThisSourceSRS = ""; } - if( pszThisTargetSRS == NULL ) + if( pszThisTargetSRS == nullptr) pszThisTargetSRS = CPLStrdup( pszThisSourceSRS ); /* -------------------------------------------------------------------- */ @@ -4359,13 +4358,13 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename, /* destination coordinate system. */ /* -------------------------------------------------------------------- */ hTransformArg = - GDALCreateGenImgProjTransformer2( hSrcDS, NULL, papszTO ); + GDALCreateGenImgProjTransformer2( hSrcDS, nullptr, papszTO ); - if( hTransformArg == NULL ) + if( hTransformArg == nullptr) { CPLFree( pszThisTargetSRS ); GDALClose( hSrcDS ); - return NULL; + return nullptr; } GDALTransformerInfo* psInfo = (GDALTransformerInfo*)hTransformArg; @@ -4385,10 +4384,10 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename, { CPLFree( pszThisTargetSRS ); GDALClose( hSrcDS ); - return NULL; + return nullptr; } - if (CPLGetConfigOption( "CHECK_WITH_INVERT_PROJ", NULL ) == NULL) + if (CPLGetConfigOption( "CHECK_WITH_INVERT_PROJ", nullptr) == nullptr) { double MinX = adfExtent[0]; double MaxX = adfExtent[2]; @@ -4439,7 +4438,7 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename, { CPLFree( pszThisTargetSRS ); GDALClose( hSrcDS ); - return NULL; + return nullptr; } } } @@ -4467,7 +4466,7 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename, dfWrkResY = MIN(dfWrkResY,ABS(adfThisGeoTransform[5])); } - if (iSrc == 0 && papszSrcFiles[1] == NULL) + if (iSrc == 0 && papszSrcFiles[1] == nullptr) { *phTransformArg = hTransformArg; *phSrcDS = hSrcDS; @@ -4487,7 +4486,7 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename, CPLError( CE_Failure, CPLE_AppDefined, "No usable source images." ); CPLFree( pszThisTargetSRS ); - return NULL; + return nullptr; } /* -------------------------------------------------------------------- */ @@ -4637,10 +4636,10 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename, hDstDS = GDALCreate( hDriver, pszFilename, nPixels, nLines, nDstBandCount, eDT, *ppapszCreateOptions ); - if( hDstDS == NULL ) + if( hDstDS == nullptr) { CPLFree( pszThisTargetSRS ); - return NULL; + return nullptr; } /* -------------------------------------------------------------------- */ @@ -4649,7 +4648,7 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename, GDALSetProjection( hDstDS, pszThisTargetSRS ); GDALSetGeoTransform( hDstDS, adfDstGeoTransform ); - if (*phTransformArg != NULL) + if (*phTransformArg != nullptr) GDALSetGenImgProjTransformerDstGeoTransform( *phTransformArg, adfDstGeoTransform); /* -------------------------------------------------------------------- */ @@ -4685,7 +4684,7 @@ GDALWarpCreateOutput( char **papszSrcFiles, const char *pszFilename, /* -------------------------------------------------------------------- */ /* Copy the color table, if required. */ /* -------------------------------------------------------------------- */ - if( hCT != NULL ) + if( hCT != nullptr) { GDALSetRasterColorTable( GDALGetRasterBand(hDstDS,1), hCT ); GDALDestroyColorTable( hCT ); @@ -4708,11 +4707,11 @@ class CutlineTransformer : public OGRCoordinateTransformation void *hSrcImageTransformer; - virtual OGRSpatialReference *GetSourceCS() { return NULL; } - virtual OGRSpatialReference *GetTargetCS() { return NULL; } + virtual OGRSpatialReference *GetSourceCS() { return nullptr; } + virtual OGRSpatialReference *GetTargetCS() { return nullptr; } virtual int Transform( int nCount, - double *x, double *y, double *z = NULL ) { + double *x, double *y, double *z = nullptr) { int nResult; int *pabSuccess = (int *) CPLCalloc(sizeof(int),nCount); @@ -4723,8 +4722,8 @@ class CutlineTransformer : public OGRCoordinateTransformation } virtual int TransformEx( int nCount, - double *x, double *y, double *z = NULL, - int *pabSuccess = NULL ) { + double *x, double *y, double *z = nullptr, + int *pabSuccess = nullptr) { return GDALGenImgProjTransform( hSrcImageTransformer, TRUE, nCount, x, y, z, pabSuccess ); } @@ -5163,23 +5162,23 @@ VRTBuilder::VRTBuilder(const char* pszOutputFilename, this->bAllowProjectionDifference = bAllowProjectionDifference; this->bAddAlpha = bAddAlpha; this->bHideNoData = bHideNoData; - this->pszSrcNoData = (pszSrcNoData) ? CPLStrdup(pszSrcNoData) : NULL; - this->pszVRTNoData = (pszVRTNoData) ? CPLStrdup(pszVRTNoData) : NULL; + this->pszSrcNoData = (pszSrcNoData) ? CPLStrdup(pszSrcNoData) : nullptr; + this->pszVRTNoData = (pszVRTNoData) ? CPLStrdup(pszVRTNoData) : nullptr; bUserExtent = FALSE; - pszProjectionRef = NULL; + pszProjectionRef = nullptr; nBands = 0; - pasBandProperties = NULL; + pasBandProperties = nullptr; bFirst = TRUE; bHasGeoTransform = FALSE; nRasterXSize = 0; nRasterYSize = 0; - pasDatasetProperties = NULL; + pasDatasetProperties = nullptr; bAllowSrcNoData = TRUE; - padfSrcNoData = NULL; + padfSrcNoData = nullptr; nSrcNoDataCount = 0; bAllowVRTNoData = TRUE; - padfVRTNoData = NULL; + padfVRTNoData = nullptr; nVRTNoDataCount = 0; bHasRunBuild = FALSE; bHasDatasetMask = FALSE; @@ -5202,7 +5201,7 @@ VRTBuilder::~VRTBuilder() } CPLFree(ppszInputFilenames); - if (pasDatasetProperties != NULL) + if (pasDatasetProperties != nullptr) { for(i=0;ifirstBandType, NULL); + GDALAddBand(hVRTDS, psDatasetProperties->firstBandType, nullptr); GDALProxyPoolDatasetH hProxyDS = GDALProxyPoolDatasetCreate(dsFileName, @@ -5638,7 +5637,7 @@ void VRTBuilder::CreateVRTSeparate(VRTDatasetH hVRTDS) (VRTSourcedRasterBandH)GDALGetRasterBand(hVRTDS, iBand); if (bHideNoData) - GDALSetMetadataItem(hVRTBand,"HideNoDataValue","1",NULL); + GDALSetMetadataItem(hVRTBand,"HideNoDataValue","1", nullptr); if (bAllowSrcNoData && psDatasetProperties->panHasNoData[0]) { @@ -5672,7 +5671,7 @@ void VRTBuilder::CreateVRTNonSeparate(VRTDatasetH hVRTDS) for(j=0;j_lastErrorCode = tkGDAL_ERROR; CPLError(CE_Failure, CPLE_AppDefined, "Invalid output file specified"); @@ -6205,7 +6204,7 @@ STDMETHODIMP CUtils::GDALBuildVrt(BSTR bstrDstFilename, BSTR bstrOptions, int bExists = (VSIStat(pszOutputFilename, &sBuf) == 0); if (bExists) { - GDALDriverH hDriver = GDALIdentifyDriver( pszOutputFilename, NULL ); + GDALDriverH hDriver = GDALIdentifyDriver( pszOutputFilename, nullptr); if (hDriver && !EQUAL(GDALGetDriverShortName(hDriver), "VRT")) { CPLError(CE_Failure, CPLE_AppDefined, @@ -6219,7 +6218,7 @@ STDMETHODIMP CUtils::GDALBuildVrt(BSTR bstrDstFilename, BSTR bstrOptions, } if (we_res != 0 && ns_res != 0 && - resolution != NULL && !EQUAL(resolution, "user")) + resolution != nullptr && !EQUAL(resolution, "user")) { CPLError(CE_Failure, CPLE_AppDefined, "-tr option is not compatible with -resolution %s\n", resolution); return ResetConfigOptions(tkGDAL_ERROR); @@ -6238,11 +6237,11 @@ STDMETHODIMP CUtils::GDALBuildVrt(BSTR bstrDstFilename, BSTR bstrOptions, } ResolutionStrategy eStrategy = AVERAGE_RESOLUTION; - if ( resolution == NULL || EQUAL(resolution, "user") ) + if ( resolution == nullptr || EQUAL(resolution, "user") ) { if ( we_res != 0 || ns_res != 0) eStrategy = USER_RESOLUTION; - else if ( resolution != NULL && EQUAL(resolution, "user") ) + else if ( resolution != nullptr && EQUAL(resolution, "user") ) { CPLError(CE_Failure, CPLE_AppDefined, "-tr option must be used with -resolution user\n"); return ResetConfigOptions(tkGDAL_ERROR); @@ -6262,7 +6261,7 @@ STDMETHODIMP CUtils::GDALBuildVrt(BSTR bstrDstFilename, BSTR bstrOptions, /* If -srcnodata is specified, use it as the -vrtnodata if the latter is not */ /* specified */ - if (pszSrcNoData != NULL && pszVRTNoData == NULL) + if (pszSrcNoData != nullptr && pszVRTNoData == nullptr) pszVRTNoData = pszSrcNoData; VRTBuilder oBuilder(pszOutputFilename, nInputFiles, ppszInputFilenames, @@ -6303,7 +6302,7 @@ STDMETHODIMP CUtils::GDALAddOverviews(BSTR bstrSrcFilename, BSTR bstrOptions, int nArgc = 0; GDALDatasetH hDataset; const char *pszResampling = "nearest"; - const char *pszFilename = NULL; + const char *pszFilename = nullptr; int anLevels[1024]; int nLevelCount = 0; int nResultStatus = 0; @@ -6352,7 +6351,7 @@ STDMETHODIMP CUtils::GDALAddOverviews(BSTR bstrSrcFilename, BSTR bstrOptions, sLevelToken = sLevels.Tokenize(" ", curPos); } - if( pszFilename == NULL || (nLevelCount == 0 && !bClean) ) + if( pszFilename == nullptr || (nLevelCount == 0 && !bClean) ) { return ResetConfigOptions(); } @@ -6361,7 +6360,7 @@ STDMETHODIMP CUtils::GDALAddOverviews(BSTR bstrSrcFilename, BSTR bstrOptions, /* Open data file. */ /* -------------------------------------------------------------------- */ if (bReadOnly) - hDataset = NULL; + hDataset = nullptr; else { CPLPushErrorHandler( CPLQuietErrorHandler ); @@ -6369,12 +6368,12 @@ STDMETHODIMP CUtils::GDALAddOverviews(BSTR bstrSrcFilename, BSTR bstrOptions, CPLPopErrorHandler(); } - if( hDataset == NULL ) + if( hDataset == nullptr) { hDataset = GdalHelper::OpenRasterDatasetW(OLE2W(bstrSrcFilename), GA_ReadOnly); } - if( hDataset == NULL ) + if( hDataset == nullptr) { return ResetConfigOptions(tkGDAL_ERROR); } @@ -6384,7 +6383,7 @@ STDMETHODIMP CUtils::GDALAddOverviews(BSTR bstrSrcFilename, BSTR bstrOptions, /* -------------------------------------------------------------------- */ if ( bClean && GDALBuildOverviews( hDataset,pszResampling, 0, 0, - 0, NULL, pfnProgress, ¶ms ) != CE_None ) + 0, nullptr, pfnProgress, ¶ms ) != CE_None ) { this->_lastErrorCode = tkGDAL_ERROR; CPLError(CE_Failure,0,"Cleaning overviews failed."); @@ -6396,7 +6395,7 @@ STDMETHODIMP CUtils::GDALAddOverviews(BSTR bstrSrcFilename, BSTR bstrOptions, /* -------------------------------------------------------------------- */ if (nLevelCount > 0 && nResultStatus == 0 && GDALBuildOverviews( hDataset,pszResampling, nLevelCount, anLevels, - 0, NULL, pfnProgress, ¶ms ) != CE_None ) + 0, nullptr, pfnProgress, ¶ms ) != CE_None ) { this->_lastErrorCode = tkGDAL_ERROR; CPLError(CE_Failure,0,"Overview building failed."); @@ -6461,14 +6460,14 @@ STDMETHODIMP CUtils::Polygonize(BSTR pszSrcFilename, BSTR pszDstFilename, /* Open source file. */ /* -------------------------------------------------------------------- */ GDALDatasetH hSrcDS = GdalHelper::OpenRasterDatasetW(OLE2W(pszSrcFilename), GA_ReadOnly); - if( hSrcDS == NULL ) + if( hSrcDS == nullptr) { (*retval) = VARIANT_FALSE; return S_OK; } GDALRasterBandH hSrcBand = GDALGetRasterBand( hSrcDS, iSrcBand ); - if( hSrcBand == NULL ) + if( hSrcBand == nullptr) { CPLError( CE_Failure, CPLE_AppDefined, "Band %d does not exist on dataset.", iSrcBand ); @@ -6477,12 +6476,12 @@ STDMETHODIMP CUtils::Polygonize(BSTR pszSrcFilename, BSTR pszDstFilename, } GDALRasterBandH hMaskBand; - GDALDatasetH hMaskDS = NULL; + GDALDatasetH hMaskDS = nullptr; if( NoMask ) { - hMaskBand = NULL; + hMaskBand = nullptr; } - else if( pszMaskFilename == NULL) // default mask + else if( pszMaskFilename == nullptr) // default mask { hMaskBand = GDALGetMaskBand( hSrcBand ); } @@ -6496,24 +6495,23 @@ STDMETHODIMP CUtils::Polygonize(BSTR pszSrcFilename, BSTR pszDstFilename, /* Try opening the destination file as an existing file. */ /* -------------------------------------------------------------------- */ CPLPushErrorHandler(CPLQuietErrorHandler); - OGRDataSourceH hDstDS = OGROpen( OLE2A(pszDstFilename), TRUE, NULL ); + OGRDataSourceH hDstDS = OGROpen( OLE2A(pszDstFilename), TRUE, nullptr); CPLPopErrorHandler(); /* -------------------------------------------------------------------- */ /* Create output file. */ /* -------------------------------------------------------------------- */ - if( hDstDS == NULL ) + if( hDstDS == nullptr) { OGRSFDriverH hDriver = OGRGetDriverByName( OLE2A(pszOGRFormat) ); - if( hDriver == NULL ) + if( hDriver == nullptr) { (*retval) = VARIANT_FALSE; return S_OK; } - hDstDS = OGR_Dr_CreateDataSource( hDriver, OLE2A(pszDstFilename), - NULL ); - if( hDstDS == NULL ) + hDstDS = OGR_Dr_CreateDataSource( hDriver, OLE2A(pszDstFilename),nullptr); + if( hDstDS == nullptr) { (*retval) = VARIANT_FALSE; return S_OK; @@ -6527,18 +6525,18 @@ STDMETHODIMP CUtils::Polygonize(BSTR pszSrcFilename, BSTR pszDstFilename, OGRLayerH hDstLayer = OGR_DS_GetLayerByName( hDstDS, OLE2A(pszDstLayerName) ); - if( hDstLayer == NULL ) + if( hDstLayer == nullptr) { - OGRSpatialReferenceH hSRS = NULL; + OGRSpatialReferenceH hSRS = nullptr; const char *pszWkt = GDALGetProjectionRef(hSrcDS); - if( pszWkt != NULL && _tcslen(pszWkt) != 0 ) + if( pszWkt != nullptr && _tcslen(pszWkt) != 0 ) { hSRS = OSRNewSpatialReference( pszWkt ); } hDstLayer = OGR_DS_CreateLayer( hDstDS, OLE2A(pszDstLayerName), hSRS, - wkbUnknown, NULL ); - if( hDstLayer == NULL ) + wkbUnknown, nullptr); + if( hDstLayer == nullptr) { (*retval) = VARIANT_FALSE; return S_OK; @@ -6557,7 +6555,7 @@ STDMETHODIMP CUtils::Polygonize(BSTR pszSrcFilename, BSTR pszDstFilename, /* -------------------------------------------------------------------- */ struct CallbackParams params(GetCallback(), "Polygonizing"); - GDALPolygonize( hSrcBand, hMaskBand, hDstLayer, dst_field, NULL, + GDALPolygonize( hSrcBand, hMaskBand, hDstLayer, dst_field, nullptr, (GDALProgressFunc) GDALProgressCallback, ¶ms ); OGR_DS_Destroy( hDstDS ); @@ -6657,14 +6655,14 @@ STDMETHODIMP CUtils::GenerateContour(BSTR pszSrcFilename, BSTR pszDstFilename, d GDALRasterBandH hBand; hSrcDS = GdalHelper::OpenRasterDatasetW(OLE2W(pszSrcFilename), GA_ReadOnly); - if( hSrcDS == NULL ) + if( hSrcDS == nullptr) { (*retval) = VARIANT_FALSE; return S_OK; } hBand = GDALGetRasterBand( hSrcDS, nBandIn ); - if( hBand == NULL ) + if( hBand == nullptr) { this->_lastErrorCode = tkGDAL_ERROR; CPLError( CE_Failure, CPLE_AppDefined, @@ -6683,11 +6681,11 @@ STDMETHODIMP CUtils::GenerateContour(BSTR pszSrcFilename, BSTR pszDstFilename, d /* -------------------------------------------------------------------- */ /* Try to get a coordinate system from the raster. */ /* -------------------------------------------------------------------- */ - OGRSpatialReferenceH hSRS = NULL; + OGRSpatialReferenceH hSRS = nullptr; const char *pszWKT = GDALGetProjectionRef( hBand ); - if( pszWKT != NULL && _tcslen(pszWKT) != 0 ) + if( pszWKT != nullptr && _tcslen(pszWKT) != 0 ) hSRS = OSRNewSpatialReference( pszWKT ); /* -------------------------------------------------------------------- */ @@ -6699,7 +6697,7 @@ STDMETHODIMP CUtils::GenerateContour(BSTR pszSrcFilename, BSTR pszDstFilename, d OGRLayerH hLayer; int nElevField = -1; - if( hDriver == NULL ) + if( hDriver == nullptr) { this->_lastErrorCode = tkGDAL_ERROR; CPLError( CE_Failure, CPLE_AppDefined, "Unable to find format driver named %s.\n", @@ -6708,8 +6706,8 @@ STDMETHODIMP CUtils::GenerateContour(BSTR pszSrcFilename, BSTR pszDstFilename, d return S_OK; } - hDS = OGR_Dr_CreateDataSource( hDriver, OLE2A(pszDstFilename), NULL ); - if( hDS == NULL ) + hDS = OGR_Dr_CreateDataSource( hDriver, OLE2A(pszDstFilename), nullptr); + if( hDS == nullptr) { this->_lastErrorCode = tkGDAL_ERROR; (*retval) = VARIANT_FALSE; @@ -6718,8 +6716,8 @@ STDMETHODIMP CUtils::GenerateContour(BSTR pszSrcFilename, BSTR pszDstFilename, d hLayer = OGR_DS_CreateLayer( hDS, "contour", hSRS, b3D ? wkbLineString25D : wkbLineString, - NULL ); - if( hLayer == NULL ) + nullptr); + if( hLayer == nullptr) { this->_lastErrorCode = tkGDAL_ERROR; (*retval) = VARIANT_FALSE; diff --git a/src/COM classes/Utils_GridToImage.cpp b/src/COM classes/Utils_GridToImage.cpp index 3e5d09ff..588ef1b7 100644 --- a/src/COM classes/Utils_GridToImage.cpp +++ b/src/COM classes/Utils_GridToImage.cpp @@ -17,7 +17,7 @@ void ReadBreaks(IGridColorScheme* ci, std::deque& result) double lowval, highval; for (int i = 0; i < numBreaks; i++) { - IGridColorBreak * bi = NULL; + IGridColorBreak * bi = nullptr; ci->get_Break(i, &bi); bi->get_LowValue(&lowval); bi->get_HighValue(&highval); @@ -37,7 +37,7 @@ void GetLightSource(IGridColorScheme* ci, cppVector& lightsource) { // TODO: can be moved to IGridColorScheme double lsi, lsj, lsk; - IVector * v = NULL; + IVector * v = nullptr; ci->GetLightSource(&v); v->get_i(&lsi); v->get_j(&lsj); @@ -83,7 +83,7 @@ inline void CUtils::WritePixel(IImage* img, int row, int col, OLE_COLOR color, STDMETHODIMP CUtils::GridToImage(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack, IImage ** retval) { // choosing inRam (logic preserved from older versions for backward compatibility) - IGridHeader * gridheader = NULL; + IGridHeader * gridheader = nullptr; Grid->get_Header(&gridheader); long ncols, nrows; gridheader->get_NumberCols(&ncols); @@ -108,13 +108,13 @@ STDMETHODIMP CUtils::GridToImage2(IGrid * Grid, IGridColorScheme * ci, tkGridPro HRESULT CUtils::RunGridToImage(IGrid * Grid, IGridColorScheme * ci, tkGridProxyFormat imageFormat, bool inRam, bool checkMemory, ICallback* callback, IImage ** retval) { - if( Grid == NULL || ci == NULL ) + if( Grid == nullptr || ci == nullptr) { ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); return S_OK; } - CComPtr gridheader = NULL; + CComPtr gridheader = nullptr; Grid->get_Header(&gridheader); long ncols, nrows; gridheader->get_NumberCols(&ncols); @@ -152,7 +152,7 @@ HRESULT CUtils::RunGridToImage(IGrid * Grid, IGridColorScheme * ci, tkGridProxyF // convert projection to WKT CComBSTR bstr, bstrWkt; gridheader->get_Projection(&bstr); - CComPtr gp = NULL; + CComPtr gp = nullptr; ComHelper::CreateInstance(idGeoProjection, (IDispatch**)&gp); gp->ImportFromAutoDetect(bstr, &vb); gp->ExportToWKT(&bstrWkt); @@ -201,14 +201,14 @@ HRESULT CUtils::RunGridToImage(IGrid * Grid, IGridColorScheme * ci, tkGridProxyF } // open the created file - CoCreateInstance(CLSID_Image, NULL, CLSCTX_INPROC_SERVER, IID_IImage, (void**)retval); + CoCreateInstance(CLSID_Image, nullptr, CLSCTX_INPROC_SERVER, IID_IImage, (void**)retval); if (*retval) { CImageClass* img = (CImageClass*)*retval; CComBSTR bstrName(imageFile); - (*retval)->Open(bstrName, ImageType::USE_FILE_EXTENSION, false, NULL, &vb); + (*retval)->Open(bstrName, ImageType::USE_FILE_EXTENSION, false, nullptr, &vb); if (!vb) { (*retval)->Release(); - (*retval) = NULL; + (*retval) = nullptr; return S_OK; } } @@ -244,15 +244,15 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack { AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; - *retval = NULL; + *retval = nullptr; - if (_globalCallback == NULL && cBack != NULL) + if (_globalCallback == nullptr && cBack != nullptr) { _globalCallback = cBack; _globalCallback->AddRef(); } - CComPtr gridheader = NULL; + CComPtr gridheader = nullptr; Grid->get_Header(&gridheader); long ncols, nrows; @@ -304,12 +304,12 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack VARIANT_BOOL vbretval; if (inRam) { - CoCreateInstance(CLSID_Image,NULL,CLSCTX_INPROC_SERVER,IID_IImage,(void**)retval); + CoCreateInstance(CLSID_Image, nullptr,CLSCTX_INPROC_SERVER,IID_IImage,(void**)retval); (*retval)->CreateNew( ncols, nrows, &vbretval ); } else { - _canScanlineBuffer = (MemoryAvailable(ncols * (sizeof(_int32)* 3))); + _canScanlineBuffer = MemoryAvailable(static_cast(ncols * (sizeof(_int32) * 3))); } std::deque bvals; @@ -319,7 +319,7 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack long newpercent = 0, percent = 0; for( int j = nrows-1; j >= 0; j-- ) - { + { // it could be more smooth in the nested cycle but better to spare performance CallbackHelper::Progress(_globalCallback, (nrows - j - 1)*ncols - 1, (int)total, "GridToImage", _key, percent); @@ -345,7 +345,7 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack continue; } - IGridColorBreak * bi = NULL; + IGridColorBreak * bi = nullptr; ci->get_Break( break_index, &bi ); OLE_COLOR hiColor, lowColor; @@ -390,9 +390,9 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack else if( j <= 0 ) { Grid->get_Value( i, j + 1, &vyone ); - Grid->get_Value( i + 1, j, &vytwo ); + Grid->get_Value( i + 1, j, &vytwo ); dVal(vyone,yone); - dVal(vytwo,ytwo); + dVal(vytwo,ytwo); ythree = val; } } @@ -402,7 +402,7 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack Grid->get_Value( i + 1, j - 1, &vytwo ); Grid->get_Value( i, j - 1, &vythree ); dVal(vytwo,ytwo); - dVal(vythree,ythree); + dVal(vythree,ythree); } double xone = xll + csize*j; @@ -434,7 +434,7 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack two.Normalize(); //Compute Normal - cppVector normal = two.crossProduct( one ); + cppVector normal = two.crossProduct( one ); //Compute I double I = ai*ka + li*kd*( lightsource.dot( normal ) ); @@ -443,11 +443,11 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack if( I > 1.0 ) I = 1.0; - //Two Color Gradient + //Two Color Gradient if( gradmodel == Linear ) { rightPercent = ( ( val - lowVal ) / biRange ); - leftPercent = 1.0 - rightPercent; + leftPercent = 1.0 - rightPercent; } else if( gradmodel == Logorithmic ) { @@ -457,13 +457,12 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack ht = 1.0; if( biRange > 1.0 && ht - lowVal > 1.0 ) { rightPercent = ( log( ht - lowVal)/log(biRange) ); - leftPercent = 1.0 - rightPercent; - } + leftPercent = 1.0 - rightPercent; + } else { rightPercent = 0.0; - leftPercent = 1.0; + leftPercent = 1.0; } - } else if( gradmodel == Exponential ) { @@ -473,11 +472,11 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack ht = 1.0; if( biRange > 1.0 ) { rightPercent = ( pow( ht - lowVal, 2)/pow(biRange, 2) ); - leftPercent = 1.0 - rightPercent; - } + leftPercent = 1.0 - rightPercent; + } else { rightPercent = 0.0; - leftPercent = 1.0; + leftPercent = 1.0; } } @@ -487,16 +486,16 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack WritePixel(*retval, j, i, RGB(finalColorR, finalColorG, finalColorB), finalColorR, finalColorG, finalColorB, ncols, inRam); } - } + } else if( colortype == Gradient ) { if( gradmodel == Linear ) - { + { rightPercent = ( ( val - lowVal ) / biRange ); - leftPercent = 1.0 - rightPercent; + leftPercent = 1.0 - rightPercent; } else if( gradmodel == Logorithmic ) - { + { double dLog = 0.0; double ht = val; if( ht < 1 ) @@ -504,16 +503,16 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack if( biRange > 1.0 && ht - lowVal > 1.0 ) { rightPercent = ( log( ht - lowVal)/log(biRange) ); - leftPercent = 1.0 - rightPercent; - } + leftPercent = 1.0 - rightPercent; + } else - { + { rightPercent = 0.0; - leftPercent = 1.0; - } + leftPercent = 1.0; + } } else if( gradmodel == Exponential ) - { + { double dLog = 0.0; double ht = val; if( ht < 1 ) @@ -522,12 +521,12 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack { rightPercent = ( pow( ht - lowVal, 2)/pow(biRange, 2) ); leftPercent = 1.0 - rightPercent; - } + } else { rightPercent = 0.0; - leftPercent = 1.0; - } + leftPercent = 1.0; + } } int finalColorR = (int)((double)GetRValue(lowColor)*leftPercent + (double)GetRValue(hiColor)*rightPercent ) %256; @@ -547,7 +546,7 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack PutBitmapValue(i, j, GetRValue(lowColor), GetGValue(lowColor), GetBValue(lowColor), ncols); } } - } + } } if (!inRam) @@ -556,11 +555,11 @@ void CUtils::GridToImageCore(IGrid *Grid, IGridColorScheme *ci, ICallback *cBack FinalizeAndCloseBitmap(ncols); - if (_rasterDataset != NULL) + if (_rasterDataset != nullptr) { _rasterDataset->FlushCache(); GDALClose(_rasterDataset); - _rasterDataset = NULL; + _rasterDataset = nullptr; } } @@ -579,11 +578,11 @@ void CUtils::CreateBitmap(CStringW filename, long cols, long rows, tkGridProxyFo GDALAllRegister(); GDALDriver *poDriver; - char **papszOptions = NULL; + char **papszOptions = nullptr; poDriver = GetGDALDriverManager()->GetDriverByName(format == gpfTiffProxy ? "GTiff" : "BMP"); - if( poDriver == NULL ) + if( poDriver == nullptr) return; bool hasOptions = false; @@ -605,7 +604,7 @@ void CUtils::CreateBitmap(CStringW filename, long cols, long rows, tkGridProxyFo _poBandR = _rasterDataset->GetRasterBand(1); _poBandG = _rasterDataset->GetRasterBand(2); _poBandB = _rasterDataset->GetRasterBand(3); - if (_poBandR != NULL && _poBandG != NULL && _poBandB != NULL) + if (_poBandR != nullptr && _poBandG != nullptr && _poBandB != nullptr) { *retval = VARIANT_TRUE; return; @@ -652,28 +651,28 @@ inline void CUtils::PutBitmapValue(long col, long row, _int32 Rvalue, _int32 Gva _bufferANum = row; // Fetch the buffer rather than creating anew; data may have been written to it out of order. - if (_bufferA_R != NULL) + if (_bufferA_R != nullptr) { CPLFree(_bufferA_R); - _bufferA_R = NULL; + _bufferA_R = nullptr; } _bufferA_R = (_int32*) CPLMalloc( sizeof(_int32)*totalWidth); _poBandR->RasterIO( GF_Read, 0, row, totalWidth, 1, _bufferA_R, totalWidth, 1, GDT_Int32, 0, 0 ); - if (_bufferA_G != NULL) + if (_bufferA_G != nullptr) { CPLFree(_bufferA_G); - _bufferA_G = NULL; + _bufferA_G = nullptr; } _bufferA_G = (_int32*) CPLMalloc( sizeof(_int32)*totalWidth); _poBandG->RasterIO( GF_Read, 0, row, totalWidth, 1, _bufferA_G, totalWidth, 1, GDT_Int32, 0, 0 ); - if (_bufferA_B != NULL) + if (_bufferA_B != nullptr) { CPLFree(_bufferA_B); - _bufferA_B = NULL; + _bufferA_B = nullptr; } _bufferA_B = (_int32*) CPLMalloc( sizeof(_int32)*totalWidth); @@ -702,28 +701,28 @@ inline void CUtils::PutBitmapValue(long col, long row, _int32 Rvalue, _int32 Gva _bufferBNum = row; // Fetch the buffer rather than creating anew; data may have been written to it out of order. - if (_bufferB_R != NULL) + if (_bufferB_R != nullptr) { CPLFree(_bufferB_R); - _bufferB_R = NULL; + _bufferB_R = nullptr; } _bufferB_R = (_int32*) CPLMalloc( sizeof(_int32)*totalWidth); _poBandR->RasterIO( GF_Read, 0, row, totalWidth, 1, _bufferB_R, totalWidth, 1, GDT_Int32, 0, 0 ); - if (_bufferB_G != NULL) + if (_bufferB_G != nullptr) { CPLFree(_bufferB_G); - _bufferB_G = NULL; + _bufferB_G = nullptr; } _bufferB_G = (_int32*) CPLMalloc( sizeof(_int32)*totalWidth); _poBandG->RasterIO( GF_Read, 0, row, totalWidth, 1, _bufferB_G, totalWidth, 1, GDT_Int32, 0, 0 ); - if (_bufferB_B != NULL) + if (_bufferB_B != nullptr) { CPLFree(_bufferB_B); - _bufferB_B = NULL; + _bufferB_B = nullptr; } _bufferB_B = (_int32*) CPLMalloc( sizeof(_int32)*totalWidth); @@ -748,54 +747,54 @@ inline void CUtils::PutBitmapValue(long col, long row, _int32 Rvalue, _int32 Gva // ************************************************************* void CUtils::FinalizeAndCloseBitmap(int totalWidth) { - if (_bufferA_R != NULL && _bufferA_G != NULL && _bufferA_B != NULL && _bufferANum != -1) + if (_bufferA_R != nullptr && _bufferA_G != nullptr && _bufferA_B != nullptr && _bufferANum != -1) { _poBandR->RasterIO( GF_Write, 0, _bufferANum, totalWidth, 1, _bufferA_R, totalWidth, 1, GDT_Int32, 0, 0 ); _poBandG->RasterIO( GF_Write, 0, _bufferANum, totalWidth, 1, _bufferA_G, totalWidth, 1, GDT_Int32, 0, 0 ); _poBandB->RasterIO( GF_Write, 0, _bufferANum, totalWidth, 1, _bufferA_B, totalWidth, 1, GDT_Int32, 0, 0 ); } - if (_bufferB_R != NULL && _bufferB_G != NULL && _bufferB_B != NULL && _bufferBNum != -1) + if (_bufferB_R != nullptr && _bufferB_G != nullptr && _bufferB_B != nullptr && _bufferBNum != -1) { _poBandR->RasterIO( GF_Write, 0, _bufferBNum, totalWidth, 1, _bufferB_R, totalWidth, 1, GDT_Int32, 0, 0 ); _poBandG->RasterIO( GF_Write, 0, _bufferBNum, totalWidth, 1, _bufferB_G, totalWidth, 1, GDT_Int32, 0, 0 ); _poBandB->RasterIO( GF_Write, 0, _bufferBNum, totalWidth, 1, _bufferB_B, totalWidth, 1, GDT_Int32, 0, 0 ); } - if (_bufferA_R != NULL) + if (_bufferA_R != nullptr) { CPLFree(_bufferA_R); - _bufferA_R = NULL; + _bufferA_R = nullptr; } - if (_bufferA_G != NULL) + if (_bufferA_G != nullptr) { CPLFree(_bufferA_G); - _bufferA_G = NULL; + _bufferA_G = nullptr; } - if (_bufferA_B != NULL) + if (_bufferA_B != nullptr) { CPLFree(_bufferA_B); - _bufferA_B = NULL; + _bufferA_B = nullptr; } - if (_bufferB_R != NULL) + if (_bufferB_R != nullptr) { CPLFree(_bufferB_R); - _bufferB_R = NULL; + _bufferB_R = nullptr; } - if (_bufferB_G != NULL) + if (_bufferB_G != nullptr) { CPLFree(_bufferB_G); - _bufferB_G = NULL; + _bufferB_G = nullptr; } - if (_bufferB_B != NULL) + if (_bufferB_B != nullptr) { CPLFree(_bufferB_B); - _bufferB_B = NULL; + _bufferB_B = nullptr; } - if (_rasterDataset != NULL) + if (_rasterDataset != nullptr) { delete _rasterDataset; - _rasterDataset = NULL; + _rasterDataset = nullptr; } } diff --git a/src/COM classes/Utils_OGR.cpp b/src/COM classes/Utils_OGR.cpp index 3035ef05..e0b1d6f5 100644 --- a/src/COM classes/Utils_OGR.cpp +++ b/src/COM classes/Utils_OGR.cpp @@ -106,7 +106,7 @@ void CheckDestDataSourceNameConsistency(const char* pszDestFilename, { "sql" , "PGDump" }, { "gtm" , "GPSTrackMaker" }, { "gmt" , "GMT" }, - { NULL, NULL } + { nullptr, nullptr } }; static const char* apszBeginName[][2] = { { "PG:" , "PG" }, { "MySQL:" , "MySQL" }, @@ -117,10 +117,10 @@ void CheckDestDataSourceNameConsistency(const char* pszDestFilename, { "OCI:" , "OCI" }, { "SDE:" , "SDE" }, { "WFS:" , "WFS" }, - { NULL, NULL } + { nullptr, nullptr } }; - for (i = 0; apszExtensions[i][0] != NULL; i++) + for (i = 0; apszExtensions[i][0] != nullptr; i++) { if (EQUAL(pszDestExtension, apszExtensions[i][0]) && !EQUAL(pszDriverName, apszExtensions[i][1])) { @@ -134,7 +134,7 @@ void CheckDestDataSourceNameConsistency(const char* pszDestFilename, } } - for (i = 0; apszBeginName[i][0] != NULL; i++) + for (i = 0; apszBeginName[i][0] != nullptr; i++) { if (EQUALN(pszDestFilename, apszBeginName[i][0], strlen(apszBeginName[i][0])) && !EQUAL(pszDriverName, apszBeginName[i][1])) @@ -176,37 +176,37 @@ static OGRGeometry* LoadGeometry(const char* pszDS, GDALDataset* poDS; OGRLayer* poLyr; OGRFeature* poFeat; - OGRGeometry* poGeom = NULL; + OGRGeometry* poGeom = nullptr; - poDS = (GDALDataset*)OGROpen(pszDS, FALSE, NULL); - if (poDS == NULL) - return NULL; + poDS = (GDALDataset*)OGROpen(pszDS, FALSE, nullptr); + if (poDS == nullptr) + return nullptr; - if (pszSQL != NULL) - poLyr = poDS->ExecuteSQL(pszSQL, NULL, NULL); - else if (pszLyr != NULL) + if (pszSQL != nullptr) + poLyr = poDS->ExecuteSQL(pszSQL, nullptr, nullptr); + else if (pszLyr != nullptr) poLyr = poDS->GetLayerByName(pszLyr); else poLyr = poDS->GetLayer(0); - if (poLyr == NULL) + if (poLyr == nullptr) { CPLError(CE_Failure, 0, "Failed to identify source layer from datasource.\n"); GDALClose((GDALDatasetH)poDS); - return NULL; + return nullptr; } if (pszWhere) poLyr->SetAttributeFilter(pszWhere); - while ((poFeat = poLyr->GetNextFeature()) != NULL) + while ((poFeat = poLyr->GetNextFeature()) != nullptr) { OGRGeometry* poSrcGeom = poFeat->GetGeometryRef(); if (poSrcGeom) { OGRwkbGeometryType eType = wkbFlatten(poSrcGeom->getGeometryType()); - if (poGeom == NULL) + if (poGeom == nullptr) poGeom = OGRGeometryFactory::createGeometry(wkbMultiPolygon); if (eType == wkbPolygon) @@ -227,17 +227,17 @@ static OGRGeometry* LoadGeometry(const char* pszDS, CPLError(CE_Failure, 0, "ERROR: Geometry not of polygon type.\n"); OGRGeometryFactory::destroyGeometry(poGeom); OGRFeature::DestroyFeature(poFeat); - if (pszSQL != NULL) + if (pszSQL != nullptr) poDS->ReleaseResultSet(poLyr); GDALClose((GDALDatasetH)poDS); - return NULL; + return nullptr; } } OGRFeature::DestroyFeature(poFeat); } - if (pszSQL != NULL) + if (pszSQL != nullptr) poDS->ReleaseResultSet(poLyr); GDALClose((GDALDatasetH)poDS); @@ -330,8 +330,8 @@ OGRSplitListFieldLayer::OGRSplitListFieldLayer(OGRLayer* poSrcLayer, if (nMaxSplitListSubFields < 0) nMaxSplitListSubFields = INT_MAX; this->nMaxSplitListSubFields = nMaxSplitListSubFields; - poFeatureDefn = NULL; - pasListFields = NULL; + poFeatureDefn = nullptr; + pasListFields = nullptr; nListFieldCount = 0; } @@ -354,13 +354,12 @@ OGRSplitListFieldLayer::~OGRSplitListFieldLayer() int OGRSplitListFieldLayer::BuildLayerDefn(GDALProgressFunc pfnProgress, void* pProgressArg) { - CPLAssert(poFeatureDefn == NULL); + CPLAssert(poFeatureDefn == nullptr); OGRFeatureDefn* poSrcFieldDefn = poSrcLayer->GetLayerDefn(); int nSrcFields = poSrcFieldDefn->GetFieldCount(); - pasListFields = - (ListFieldDesc*)CPLCalloc(sizeof(ListFieldDesc), nSrcFields); + pasListFields = (ListFieldDesc*)CPLCalloc(sizeof(ListFieldDesc), nSrcFields); nListFieldCount = 0; int i; @@ -398,7 +397,7 @@ int OGRSplitListFieldLayer::BuildLayerDefn(GDALProgressFunc pfnProgress, /* Scan the whole layer to compute the maximum number of */ /* items for each field of list type */ - while ((poSrcFeature = poSrcLayer->GetNextFeature()) != NULL) + while ((poSrcFeature = poSrcLayer->GetNextFeature()) != nullptr) { for (i = 0;i < nListFieldCount;i++) { @@ -420,7 +419,7 @@ int OGRSplitListFieldLayer::BuildLayerDefn(GDALProgressFunc pfnProgress, int j; for (j = 0;j < nCount;j++) { - int nWidth = strlen(paList[j]); + int nWidth = static_cast(strlen(paList[j])); if (nWidth > pasListFields[i].nWidth) pasListFields[i].nWidth = nWidth; } @@ -440,15 +439,14 @@ int OGRSplitListFieldLayer::BuildLayerDefn(GDALProgressFunc pfnProgress, OGRFeature::DestroyFeature(poSrcFeature); nFeatureIndex++; - if (pfnProgress != NULL && nFeatureCount != 0) + if (pfnProgress != nullptr && nFeatureCount != 0) pfnProgress(nFeatureIndex * 1.0 / nFeatureCount, "", pProgressArg); } } /* Now let's build the target feature definition */ - poFeatureDefn = - OGRFeatureDefn::CreateFeatureDefn(poSrcFieldDefn->GetName()); + poFeatureDefn = OGRFeatureDefn::CreateFeatureDefn(poSrcFieldDefn->GetName()); poFeatureDefn->Reference(); poFeatureDefn->SetGeomType(poSrcFieldDefn->GetGeomType()); @@ -504,9 +502,9 @@ int OGRSplitListFieldLayer::BuildLayerDefn(GDALProgressFunc pfnProgress, OGRFeature* OGRSplitListFieldLayer::TranslateFeature(OGRFeature* poSrcFeature) { - if (poSrcFeature == NULL) - return NULL; - if (poFeatureDefn == NULL) + if (poSrcFeature == nullptr) + return nullptr; + if (poFeatureDefn == nullptr) return poSrcFeature; OGRFeature* poFeature = OGRFeature::CreateFeature(poFeatureDefn); @@ -598,7 +596,7 @@ OGRFeature* OGRSplitListFieldLayer::GetFeature(long nFID) OGRFeatureDefn* OGRSplitListFieldLayer::GetLayerDefn() { - if (poFeatureDefn == NULL) + if (poFeatureDefn == nullptr) return poSrcLayer->GetLayerDefn(); return poFeatureDefn; } @@ -725,7 +723,7 @@ static void Usage(const char* pszAdditionalMsg, int bShort = true) static void Usage(int bShort = true) { - Usage(NULL, bShort); + Usage(nullptr, bShort); } static int bPreserveFID = FALSE; @@ -814,13 +812,11 @@ class GCPCoordTransformation final : public OGRCoordinateTransformation int bOverallSuccess; if (bUseTPS) - bOverallSuccess = GDALTPSTransform(hTransformArg, FALSE, - nCount, x, y, z, pabSuccess); + bOverallSuccess = GDALTPSTransform(hTransformArg, FALSE, static_cast(nCount), x, y, z, pabSuccess); else - bOverallSuccess = GDALGCPTransform(hTransformArg, FALSE, - nCount, x, y, z, pabSuccess); + bOverallSuccess = GDALGCPTransform(hTransformArg, FALSE, static_cast(nCount), x, y, z, pabSuccess); - for (int i = 0; i < nCount; i++) + for (int i = 0; i < static_cast(nCount); i++) { if (!pabSuccess[i]) { @@ -934,9 +930,9 @@ class GCPCoordTransformation : public OGRCoordinateTransformation void ApplySpatialFilter(OGRLayer* poLayer, OGRGeometry* poSpatialFilter, const char* pszGeomField) { - if (poSpatialFilter != NULL) + if (poSpatialFilter != nullptr) { - if (pszGeomField != NULL) + if (pszGeomField != nullptr) { int iGeomField = poLayer->GetLayerDefn()->GetGeomFieldIndex(pszGeomField); if (iGeomField >= 0) @@ -952,7 +948,7 @@ void ApplySpatialFilter(OGRLayer* poLayer, OGRGeometry* poSpatialFilter, static void FreeTargetLayerInfo(TargetLayerInfo* psInfo) { - if (psInfo == NULL) + if (psInfo == nullptr) return; for (int i = 0; i < psInfo->poDstLayer->GetLayerDefn()->GetGeomFieldCount(); i++) { @@ -1000,9 +996,9 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, { OGRLayer* poDstLayer; OGRFeatureDefn* poSrcFDefn; - OGRFeatureDefn* poDstFDefn = NULL; + OGRFeatureDefn* poDstFDefn = nullptr; - if (pszNewLayerName == NULL) + if (pszNewLayerName == nullptr) pszNewLayerName = poSrcLayer->GetName(); /* -------------------------------------------------------------------- */ @@ -1017,7 +1013,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, int nSrcGeomFieldCount = poSrcFDefn->GetGeomFieldCount(); if (papszSelFields && !bAppend) { - for (int iField = 0; papszSelFields[iField] != NULL; iField++) + for (int iField = 0; papszSelFields[iField] != nullptr; iField++) { int iSrcField = poSrcFDefn->GetFieldIndex(papszSelFields[iField]); if (iSrcField >= 0) @@ -1036,7 +1032,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, CPLError(CE_Failure, 0, "Field '%s' not found in source layer.\n", papszSelFields[iField]); if (!bSkipFailures) - return NULL; + return nullptr; } } } @@ -1048,7 +1044,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, "datasource does not support multiple geometry " "fields.\n"); if (!bSkipFailures) - return NULL; + return nullptr; else anRequestedGeomFields.resize(0); } @@ -1081,7 +1077,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, CPLErrorReset(); int iLayer = -1; - if (poDstLayer != NULL) + if (poDstLayer != nullptr) { int nLayerCount = poDstDS->GetLayerCount(); for (iLayer = 0; iLayer < nLayerCount; iLayer++) @@ -1093,7 +1089,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, if (iLayer == nLayerCount) /* shouldn't happen with an ideal driver */ - poDstLayer = NULL; + poDstLayer = nullptr; } /* -------------------------------------------------------------------- */ @@ -1101,28 +1097,28 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, /* question we need to delete it now so it will get recreated */ /* (overwritten). */ /* -------------------------------------------------------------------- */ - if (poDstLayer != NULL && bOverwrite) + if (poDstLayer != nullptr && bOverwrite) { if (poDstDS->DeleteLayer(iLayer) != OGRERR_NONE) { CPLError(CE_Failure, 0, "DeleteLayer() failed when overwrite requested.\n"); - return NULL; + return nullptr; } - poDstLayer = NULL; + poDstLayer = nullptr; } /* -------------------------------------------------------------------- */ /* If the layer does not exist, then create it. */ /* -------------------------------------------------------------------- */ - if (poDstLayer == NULL) + if (poDstLayer == nullptr) { if (!poDstDS->TestCapability(ODsCCreateLayer)) { CPLError(CE_Failure, 0, "Layer %s not found, and CreateLayer not supported by driver.\n", pszNewLayerName); - return NULL; + return nullptr; } int bForceGType = (eGType != -2); @@ -1194,8 +1190,8 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, (OGRwkbGeometryType)eGCreateLayerType, papszLCO); - if (poDstLayer == NULL) - return NULL; + if (poDstLayer == nullptr) + return nullptr; if (anRequestedGeomFields.size() == 0 && nSrcGeomFieldCount > 1 && @@ -1216,7 +1212,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, int iSrcGeomField = anRequestedGeomFields[i]; OGRGeomFieldDefn oGFldDefn (poSrcFDefn->GetGeomFieldDefn(iSrcGeomField)); - if (poOutputSRSIn != NULL) + if (poOutputSRSIn != nullptr) oGFldDefn.SetSpatialRef(poOutputSRSIn); if (bForceGType) oGFldDefn.SetType((OGRwkbGeometryType)eGType); @@ -1249,7 +1245,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, CPLError(CE_Failure, 0, "FAILED: Layer %s already exists, and -append not specified.\n" " Consider using -append, or -overwrite.\n", pszNewLayerName); - return NULL; + return nullptr; } else { @@ -1294,7 +1290,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, CPLError(CE_Failure, 0, "Field map should contain the value 'identity' or " "the same number of integer values as the source field count.\n"); VSIFree(panMap); - return NULL; + return nullptr; } for (iField = 0; iField < nSrcFieldCount; iField++) @@ -1304,7 +1300,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, { CPLError(CE_Failure, 0, "Invalid destination field index %d.\n", panMap[iField]); VSIFree(panMap); - return NULL; + return nullptr; } } } @@ -1313,7 +1309,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, int nDstFieldCount = 0; if (poDstFDefn) nDstFieldCount = poDstFDefn->GetFieldCount(); - for (iField = 0; papszSelFields[iField] != NULL; iField++) + for (iField = 0; papszSelFields[iField] != nullptr; iField++) { int iSrcField = poSrcFDefn->GetFieldIndex(papszSelFields[iField]); if (iSrcField >= 0) @@ -1321,7 +1317,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, OGRFieldDefn* poSrcFieldDefn = poSrcFDefn->GetFieldDefn(iSrcField); OGRFieldDefn oFieldDefn(poSrcFieldDefn); - if (papszFieldTypesToString != NULL && + if (papszFieldTypesToString != nullptr && (CSLFindString(papszFieldTypesToString, "All") != -1 || CSLFindString(papszFieldTypesToString, OGRFieldDefn::GetFieldTypeName(poSrcFieldDefn->GetType())) != -1)) @@ -1345,11 +1341,11 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, else if (poDstLayer->CreateField(&oFieldDefn) == OGRERR_NONE) { /* now that we've created a field, GetLayerDefn() won't return NULL */ - if (poDstFDefn == NULL) + if (poDstFDefn == nullptr) poDstFDefn = poDstLayer->GetLayerDefn(); /* Sanity check : if it fails, the driver is buggy */ - if (poDstFDefn != NULL && + if (poDstFDefn != nullptr && poDstFDefn->GetFieldCount() != nDstFieldCount + 1) { CPLError(CE_Warning, CPLE_AppDefined, @@ -1371,9 +1367,9 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, if (poSrcLayer->TestCapability(OLCIgnoreFields)) { int iSrcField; - char** papszIgnoredFields = NULL; + char** papszIgnoredFields = nullptr; int bUseIgnoredFields = TRUE; - char** papszWHEREUsedFields = NULL; + char** papszWHEREUsedFields = nullptr; if (pszWHERE) { @@ -1394,7 +1390,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, const char* pszFieldName = poSrcFDefn->GetFieldDefn(iSrcField)->GetNameRef(); int bFieldRequested = FALSE; - for (iField = 0; papszSelFields[iField] != NULL; iField++) + for (iField = 0; papszSelFields[iField] != nullptr; iField++) { if (EQUAL(pszFieldName, papszSelFields[iField])) { @@ -1403,7 +1399,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, } } bFieldRequested |= CSLFindString(papszWHEREUsedFields, pszFieldName) >= 0; - bFieldRequested |= (pszZField != NULL && EQUAL(pszFieldName, pszZField)); + bFieldRequested |= (pszZField != nullptr && EQUAL(pszFieldName, pszZField)); /* If source field not requested, add it to ignored files list */ if (!bFieldRequested) @@ -1442,7 +1438,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, OGRFieldDefn* poSrcFieldDefn = poSrcFDefn->GetFieldDefn(iField); OGRFieldDefn oFieldDefn(poSrcFieldDefn); - if (papszFieldTypesToString != NULL && + if (papszFieldTypesToString != nullptr && (CSLFindString(papszFieldTypesToString, "All") != -1 || CSLFindString(papszFieldTypesToString, OGRFieldDefn::GetFieldTypeName(poSrcFieldDefn->GetType())) != -1)) @@ -1467,7 +1463,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, int bHasRenamed = FALSE; /* In case the field name already exists in the target layer, */ /* build a unique field name */ - if (poDstFDefn != NULL && + if (poDstFDefn != nullptr && poDstFDefn->GetFieldIndex(oFieldDefn.GetNameRef()) >= 0) { int nTry = 1; @@ -1491,11 +1487,11 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, if (poDstLayer->CreateField(&oFieldDefn) == OGRERR_NONE) { /* now that we've created a field, GetLayerDefn() won't return NULL */ - if (poDstFDefn == NULL) + if (poDstFDefn == nullptr) poDstFDefn = poDstLayer->GetLayerDefn(); /* Sanity check : if it fails, the driver is buggy */ - if (poDstFDefn != NULL && + if (poDstFDefn != nullptr && poDstFDefn->GetFieldCount() != nDstFieldCount + 1) { CPLError(CE_Warning, CPLE_AppDefined, @@ -1523,11 +1519,11 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, { /* For an existing layer, build the map by fetching the index in the destination */ /* layer for each source field */ - if (poDstFDefn == NULL) + if (poDstFDefn == nullptr) { CPLError(CE_Failure, 0, "poDstFDefn == NULL.\n"); VSIFree(panMap); - return NULL; + return nullptr; } for (iField = 0; iField < nSrcFieldCount; iField++) @@ -1543,7 +1539,7 @@ static TargetLayerInfo* SetupTargetLayer(CPL_UNUSED GDALDataset* poSrcDS, } int iSrcZField = -1; - if (pszZField != NULL) + if (pszZField != nullptr) { iSrcZField = poSrcFDefn->GetFieldIndex(pszZField); } @@ -1580,61 +1576,61 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, int bQuiet = FALSE; int bFormatExplicitelySet = FALSE; const char* pszFormat = "ESRI Shapefile"; - const char* pszDataSource = NULL; - const char* pszDestDataSource = NULL; - char** papszLayers = NULL; - char** papszDSCO = NULL, ** papszLCO = NULL; + const char* pszDataSource = nullptr; + const char* pszDestDataSource = nullptr; + char** papszLayers = nullptr; + char** papszDSCO = nullptr, ** papszLCO = nullptr; int bTransform = FALSE; int bAppend = FALSE, bUpdate = FALSE, bOverwrite = FALSE; int bAddMissingFields = FALSE; - const char* pszOutputSRSDef = NULL; - const char* pszSourceSRSDef = NULL; - OGRSpatialReference* poOutputSRS = NULL; + const char* pszOutputSRSDef = nullptr; + const char* pszSourceSRSDef = nullptr; + OGRSpatialReference* poOutputSRS = nullptr; int bNullifyOutputSRS = FALSE; int bExactFieldNameMatch = TRUE; - OGRSpatialReference* poSourceSRS = NULL; - char* pszNewLayerName = NULL; - const char* pszWHERE = NULL; - OGRGeometry* poSpatialFilter = NULL; - const char* pszGeomField = NULL; + OGRSpatialReference* poSourceSRS = nullptr; + char* pszNewLayerName = nullptr; + const char* pszWHERE = nullptr; + OGRGeometry* poSpatialFilter = nullptr; + const char* pszGeomField = nullptr; const char* pszSelect; - char** papszSelFields = NULL; - const char* pszSQLStatement = NULL; - const char* pszDialect = NULL; + char** papszSelFields = nullptr; + const char* pszSQLStatement = nullptr; + const char* pszDialect = nullptr; int eGType = -2; int bPromoteToMulti = FALSE; GeomOperation eGeomOp = NONE; double dfGeomOpParam = 0; - char** papszFieldTypesToString = NULL; + char** papszFieldTypesToString = nullptr; int bUnsetFieldWidth = FALSE; int bDisplayProgress = FALSE; - GDALProgressFunc pfnProgress = NULL; - void* pProgressArg = NULL; + GDALProgressFunc pfnProgress = nullptr; + void* pProgressArg = nullptr; int bWrapDateline = FALSE; const char* pszDateLineOffset = "10"; int bClipSrc = FALSE; - OGRGeometry* poClipSrc = NULL; - const char* pszClipSrcDS = NULL; - const char* pszClipSrcSQL = NULL; - const char* pszClipSrcLayer = NULL; - const char* pszClipSrcWhere = NULL; - OGRGeometry* poClipDst = NULL; - const char* pszClipDstDS = NULL; - const char* pszClipDstSQL = NULL; - const char* pszClipDstLayer = NULL; - const char* pszClipDstWhere = NULL; + OGRGeometry* poClipSrc = nullptr; + const char* pszClipSrcDS = nullptr; + const char* pszClipSrcSQL = nullptr; + const char* pszClipSrcLayer = nullptr; + const char* pszClipSrcWhere = nullptr; + OGRGeometry* poClipDst = nullptr; + const char* pszClipDstDS = nullptr; + const char* pszClipDstSQL = nullptr; + const char* pszClipDstLayer = nullptr; + const char* pszClipDstWhere = nullptr; int bSplitListFields = FALSE; int nMaxSplitListSubFields = -1; int bExplodeCollections = FALSE; - const char* pszZField = NULL; - const char* pszFieldMap = NULL; - char** papszFieldMap = NULL; + const char* pszZField = nullptr; + const char* pszFieldMap = nullptr; + char** papszFieldMap = nullptr; int nCoordDim = -1; - char** papszOpenOptions = NULL; - char** papszDestOpenOptions = NULL; + char** papszOpenOptions = nullptr; + char** papszDestOpenOptions = nullptr; int nGCPCount = 0; - GDAL_GCP* pasGCPs = NULL; + GDAL_GCP* pasGCPs = nullptr; int nTransformOrder = 0; /* Default to 0 for now... let the lib decide */ *retval = VARIANT_FALSE; @@ -1650,7 +1646,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, return ResetConfigOptions(tkGDAL_ERROR); } - char** papszArgv = NULL; + char** papszArgv = nullptr; for (int i = 0; i < _sArr.GetCount(); i++) { papszArgv = CSLAddString(papszArgv, _sArr[i]); @@ -1908,7 +1904,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, else if (EQUAL(*iter, "All")) { CSLDestroy(papszFieldTypesToString); - papszFieldTypesToString = NULL; + papszFieldTypesToString = nullptr; papszFieldTypesToString = CSLAddString(papszFieldTypesToString, "All"); break; } @@ -1944,9 +1940,9 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, VSIStatBufL sStat; bClipSrc = TRUE; if (IsNumber(papszArgv[iArg + 1]) - && papszArgv[iArg + 2] != NULL - && papszArgv[iArg + 3] != NULL - && papszArgv[iArg + 4] != NULL) + && papszArgv[iArg + 2] != nullptr + && papszArgv[iArg + 3] != nullptr + && papszArgv[iArg + 4] != nullptr) { OGRLinearRing oRing; @@ -1965,8 +1961,8 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, VSIStatL(papszArgv[iArg + 1], &sStat) != 0) { char* pszTmp = (char*)papszArgv[iArg + 1]; - OGRGeometryFactory::createFromWkt(&pszTmp, NULL, &poClipSrc); - if (poClipSrc == NULL) + OGRGeometryFactory::createFromWkt(&pszTmp, nullptr, &poClipSrc); + if (poClipSrc == nullptr) { Usage("Invalid geometry. Must be a valid POLYGON or MULTIPOLYGON WKT"); } @@ -2007,9 +2003,9 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, VSIStatBufL sStat; if (IsNumber(papszArgv[iArg + 1]) - && papszArgv[iArg + 2] != NULL - && papszArgv[iArg + 3] != NULL - && papszArgv[iArg + 4] != NULL) + && papszArgv[iArg + 2] != nullptr + && papszArgv[iArg + 3] != nullptr + && papszArgv[iArg + 4] != nullptr) { OGRLinearRing oRing; @@ -2028,8 +2024,8 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, VSIStatL(papszArgv[iArg + 1], &sStat) != 0) { char* pszTmp = (char*)papszArgv[iArg + 1]; - OGRGeometryFactory::createFromWkt(&pszTmp, NULL, &poClipDst); - if (poClipDst == NULL) + OGRGeometryFactory::createFromWkt(&pszTmp, nullptr, &poClipDst); + if (poClipDst == nullptr) { Usage("Invalid geometry. Must be a valid POLYGON or MULTIPOLYGON WKT"); } @@ -2089,7 +2085,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, else if (EQUAL(papszArgv[iArg], "-gcp")) { CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(4); - char* endptr = NULL; + char* endptr = nullptr; /* -gcp pixel line easting northing [elev] */ nGCPCount++; @@ -2101,7 +2097,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, pasGCPs[nGCPCount - 1].dfGCPLine = atof(papszArgv[++iArg]); pasGCPs[nGCPCount - 1].dfGCPX = atof(papszArgv[++iArg]); pasGCPs[nGCPCount - 1].dfGCPY = atof(papszArgv[++iArg]); - if (papszArgv[iArg + 1] != NULL + if (papszArgv[iArg + 1] != nullptr && (CPLStrtod(papszArgv[iArg + 1], &endptr) != 0.0 || papszArgv[iArg + 1][0] == '0')) { /* Check that last argument is really a number and not a filename */ @@ -2121,7 +2117,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1); nTransformOrder = atoi(papszArgv[++iArg]); } - else if (EQUAL(papszArgv[iArg], "-fieldmap") && papszArgv[iArg + 1] != NULL) + else if (EQUAL(papszArgv[iArg], "-fieldmap") && papszArgv[iArg + 1] != nullptr) { CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1); pszFieldMap = papszArgv[++iArg]; @@ -2132,17 +2128,17 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, { Usage(CPLSPrintf("Unknown option name '%s'", papszArgv[iArg])); } - else if (pszDestDataSource == NULL) + else if (pszDestDataSource == nullptr) pszDestDataSource = papszArgv[iArg]; - else if (pszDataSource == NULL) + else if (pszDataSource == nullptr) pszDataSource = papszArgv[iArg]; else papszLayers = CSLAddString(papszLayers, papszArgv[iArg]); } - if (pszDataSource == NULL) + if (pszDataSource == nullptr) { - if (pszDestDataSource == NULL) + if (pszDestDataSource == nullptr) Usage("no target datasource provided"); else Usage("no source datasource provided"); @@ -2163,34 +2159,34 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, Usage("if -addfields is specified, -fieldmap cannot be used."); } - if (pszSourceSRSDef != NULL && pszOutputSRSDef == NULL) + if (pszSourceSRSDef != nullptr && pszOutputSRSDef == nullptr) { Usage("if -s_srs is specified, -t_srs must also be specified"); } - if (bClipSrc && pszClipSrcDS != NULL) + if (bClipSrc && pszClipSrcDS != nullptr) { poClipSrc = LoadGeometry(pszClipSrcDS, pszClipSrcSQL, pszClipSrcLayer, pszClipSrcWhere); - if (poClipSrc == NULL) + if (poClipSrc == nullptr) { Usage("cannot load source clip geometry"); } } - else if (bClipSrc && poClipSrc == NULL) + else if (bClipSrc && poClipSrc == nullptr) { if (poSpatialFilter) poClipSrc = poSpatialFilter->clone(); - if (poClipSrc == NULL) + if (poClipSrc == nullptr) { Usage("-clipsrc must be used with -spat option or a\n" "bounding box, WKT string or datasource must be specified"); } } - if (pszClipDstDS != NULL) + if (pszClipDstDS != nullptr) { poClipDst = LoadGeometry(pszClipDstDS, pszClipDstSQL, pszClipDstLayer, pszClipDstWhere); - if (poClipDst == NULL) + if (poClipDst == nullptr) { Usage("cannot load dest clip geometry"); } @@ -2200,8 +2196,8 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* Open data source. */ /* -------------------------------------------------------------------- */ GDALDataset* poDS; - GDALDataset* poODS = NULL; - GDALDriver* poDriver = NULL; + GDALDataset* poODS = nullptr; + GDALDriver* poDriver = nullptr; int bCloseODS = TRUE; /* Avoid opening twice the same datasource if it is both the input and output */ @@ -2209,8 +2205,8 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, if (bUpdate && strcmp(pszDestDataSource, pszDataSource) == 0) { poODS = poDS = (GDALDataset*)GDALOpenEx(pszDataSource, - GDAL_OF_UPDATE | GDAL_OF_VECTOR, NULL, papszOpenOptions, NULL); - if (poDS != NULL) + GDAL_OF_UPDATE | GDAL_OF_VECTOR, nullptr, papszOpenOptions, nullptr); + if (poDS != nullptr) poDriver = poDS->GetDriver(); /* Restrict to those 2 drivers. For example it is known to break with */ @@ -2219,7 +2215,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, EQUAL(poDriver->GetDescription(), "SQLite"))) { poDS = (GDALDataset*)GDALOpenEx(pszDataSource, - GDAL_OF_VECTOR, NULL, papszOpenOptions, NULL); + GDAL_OF_VECTOR, nullptr, papszOpenOptions, nullptr); } else bCloseODS = FALSE; @@ -2230,11 +2226,11 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* Various tests to avoid overwriting the source layer(s) */ /* or to avoid appending a layer to itself */ int bError = FALSE; - if (pszNewLayerName == NULL) + if (pszNewLayerName == nullptr) bError = TRUE; else if (CSLCount(papszLayers) == 1) bError = strcmp(pszNewLayerName, papszLayers[0]) == 0; - else if (pszSQLStatement == NULL) + else if (pszSQLStatement == nullptr) bError = TRUE; if (bError) { @@ -2249,12 +2245,12 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, } else poDS = (GDALDataset*)GDALOpenEx(pszDataSource, - GDAL_OF_VECTOR, NULL, papszOpenOptions, NULL); + GDAL_OF_VECTOR, nullptr, papszOpenOptions, nullptr); /* -------------------------------------------------------------------- */ /* Report failure */ /* -------------------------------------------------------------------- */ - if (poDS == NULL) + if (poDS == nullptr) { OGRSFDriverRegistrar* poR = OGRSFDriverRegistrar::GetRegistrar(); @@ -2275,30 +2271,30 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* Try opening the output datasource as an existing, writable */ /* -------------------------------------------------------------------- */ - if (bUpdate && poODS == NULL) + if (bUpdate && poODS == nullptr) { poODS = (GDALDataset*)GDALOpenEx(pszDestDataSource, - GDAL_OF_UPDATE | GDAL_OF_VECTOR, NULL, papszDestOpenOptions, NULL); - if (poODS != NULL) + GDAL_OF_UPDATE | GDAL_OF_VECTOR, nullptr, papszDestOpenOptions, nullptr); + if (poODS != nullptr) poDriver = poODS->GetDriver(); - if (poODS == NULL) + if (poODS == nullptr) { if (bOverwrite || bAppend) { poODS = (GDALDataset*)GDALOpenEx(pszDestDataSource, - GDAL_OF_VECTOR, NULL, papszDestOpenOptions, NULL); - if (poODS == NULL) + GDAL_OF_VECTOR, nullptr, papszDestOpenOptions, nullptr); + if (poODS == nullptr) { /* ok the datasource doesn't exist at all */ bUpdate = FALSE; } else { - if (poODS != NULL) + if (poODS != nullptr) poDriver = poODS->GetDriver(); GDALClose((GDALDatasetH)poODS); - poODS = NULL; + poODS = nullptr; } } @@ -2329,7 +2325,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, int iDriver; poDriver = poR->GetDriverByName(pszFormat); - if (poDriver == NULL) + if (poDriver == nullptr) { CPLError(CE_Failure, 0, "Unable to find driver `%s'.\n", pszFormat); CPLError(CE_Failure, 0, "The following drivers are available:\n"); @@ -2359,10 +2355,10 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ VSIStatBufL sStat; if (EQUAL(poDriver->GetDescription(), "ESRI Shapefile") && - pszSQLStatement == NULL && + pszSQLStatement == nullptr && (CSLCount(papszLayers) > 1 || (CSLCount(papszLayers) == 0 && poDS->GetLayerCount() > 1)) && - pszNewLayerName == NULL && + pszNewLayerName == nullptr && EQUAL(CPLGetExtension(pszDestDataSource), "SHP") && VSIStatL(pszDestDataSource, &sStat) != 0) { @@ -2380,7 +2376,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* Create the output data source. */ /* -------------------------------------------------------------------- */ poODS = poDriver->Create(pszDestDataSource, 0, 0, 0, GDT_Unknown, papszDSCO); - if (poODS == NULL) + if (poODS == nullptr) { CPLError(CE_Failure, 0, "%s driver failed to create %s\n", pszFormat, pszDestDataSource); @@ -2391,9 +2387,9 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ /* Parse the output SRS definition if possible. */ /* -------------------------------------------------------------------- */ - if (pszOutputSRSDef != NULL) + if (pszOutputSRSDef != nullptr) { - poOutputSRS = (OGRSpatialReference*)OSRNewSpatialReference(NULL); + poOutputSRS = (OGRSpatialReference*)OSRNewSpatialReference(nullptr); if (poOutputSRS->SetFromUserInput(pszOutputSRSDef) != OGRERR_NONE) { CPLError(CE_Failure, 0, "Failed to process SRS definition: %s\n", @@ -2405,9 +2401,9 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ /* Parse the source SRS definition if possible. */ /* -------------------------------------------------------------------- */ - if (pszSourceSRSDef != NULL) + if (pszSourceSRSDef != nullptr) { - poSourceSRS = (OGRSpatialReference*)OSRNewSpatialReference(NULL); + poSourceSRS = (OGRSpatialReference*)OSRNewSpatialReference(nullptr); if (poSourceSRS->SetFromUserInput(pszSourceSRSDef) != OGRERR_NONE) { CPLError(CE_Failure, 0, "Failed to process SRS definition: %s\n", @@ -2420,7 +2416,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* Create a transformation object from the source to */ /* destination coordinate system. */ /* -------------------------------------------------------------------- */ - GCPCoordTransformation* poGCPCoordTrans = NULL; + GCPCoordTransformation* poGCPCoordTrans = nullptr; if (nGCPCount > 0) { poGCPCoordTrans = new GCPCoordTransformation(nGCPCount, pasGCPs, @@ -2429,7 +2425,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, if (!(poGCPCoordTrans->IsValid())) { delete poGCPCoordTrans; - poGCPCoordTrans = NULL; + poGCPCoordTrans = nullptr; } } @@ -2448,22 +2444,22 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ /* Special case for -sql clause. No source layers required. */ /* -------------------------------------------------------------------- */ - if (pszSQLStatement != NULL) + if (pszSQLStatement != nullptr) { OGRLayer* poResultSet; - if (pszWHERE != NULL) + if (pszWHERE != nullptr) CPLError(CE_Failure, 0, "-where clause ignored in combination with -sql.\n"); if (CSLCount(papszLayers) > 0) CPLError(CE_Failure, 0, "layer names ignored in combination with -sql.\n"); poResultSet = poDS->ExecuteSQL(pszSQLStatement, - (pszGeomField == NULL) ? poSpatialFilter : NULL, + (pszGeomField == nullptr) ? poSpatialFilter : nullptr, pszDialect); - if (poResultSet != NULL) + if (poResultSet != nullptr) { - if (poSpatialFilter != NULL && pszGeomField != NULL) + if (poSpatialFilter != nullptr && pszGeomField != nullptr) { int iGeomField = poResultSet->GetLayerDefn()->GetGeomFieldIndex(pszGeomField); if (iGeomField >= 0) @@ -2511,7 +2507,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ VSIStatBufL sStat; if (EQUAL(poDriver->GetDescription(), "ESRI Shapefile") && - pszNewLayerName == NULL && + pszNewLayerName == nullptr && VSIStatL(pszDestDataSource, &sStat) == 0 && VSI_ISREG(sStat.st_mode)) { pszNewLayerName = CPLStrdup(CPLGetBasename(pszDestDataSource)); @@ -2538,7 +2534,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, poPassedLayer->ResetReading(); - if (psInfo == NULL || + if (psInfo == nullptr || !TranslateLayer(psInfo, poDS, poPassedLayer, poODS, bTransform, bWrapDateline, pszDateLineOffset, poOutputSRS, bNullifyOutputSRS, @@ -2549,7 +2545,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, nCountLayerFeatures, poClipSrc, poClipDst, bExplodeCollections, - nSrcFileSize, NULL, + nSrcFileSize, nullptr, pfnProgress, ¶ms)) { CPLError(CE_Failure, CPLE_AppDefined, @@ -2598,7 +2594,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ VSIStatBufL sStat; if (EQUAL(poDriver->GetDescription(), "ESRI Shapefile") && - (CSLCount(papszLayers) == 1 || nSrcLayerCount == 1) && pszNewLayerName == NULL && + (CSLCount(papszLayers) == 1 || nSrcLayerCount == 1) && pszNewLayerName == nullptr && VSIStatL(pszDestDataSource, &sStat) == 0 && VSI_ISREG(sStat.st_mode)) { pszNewLayerName = CPLStrdup(CPLGetBasename(pszDestDataSource)); @@ -2618,7 +2614,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, { OGRLayer* poLayer = poDS->GetLayer(iLayer); - if (poLayer == NULL) + if (poLayer == nullptr) { CPLError(CE_Failure, 0, "FAILURE: Couldn't fetch advertised layer %d!\n", iLayer); @@ -2633,13 +2629,13 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, if (bSrcIsOSM) { CPLString osInterestLayers = "SET interest_layers ="; - for (iLayer = 0; papszLayers[iLayer] != NULL; iLayer++) + for (iLayer = 0; papszLayers[iLayer] != nullptr; iLayer++) { if (iLayer != 0) osInterestLayers += ","; osInterestLayers += papszLayers[iLayer]; } - poDS->ExecuteSQL(osInterestLayers.c_str(), NULL, NULL); + poDS->ExecuteSQL(osInterestLayers.c_str(), nullptr, nullptr); } } @@ -2649,7 +2645,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, for (iLayer = 0; iLayer < nSrcLayerCount; iLayer++) { OGRLayer* poLayer = poDS->GetLayer(iLayer); - if (poLayer == NULL) + if (poLayer == nullptr) { CPLError(CE_Failure, 0, "FAILURE: Couldn't fetch advertised layer %d!\n", iLayer); @@ -2660,7 +2656,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, if (CSLFindString(papszLayers, poLayer->GetName()) >= 0) { - if (pszWHERE != NULL) + if (pszWHERE != nullptr) { if (poLayer->SetAttributeFilter(pszWHERE) != OGRERR_NONE) { @@ -2692,14 +2688,14 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, pszWHERE, bExactFieldNameMatch); - if (psInfo == NULL && !bSkipFailures) + if (psInfo == nullptr && !bSkipFailures) return ResetConfigOptions(tkGDAL_ERROR); pasAssocLayers[iLayer].psInfo = psInfo; } else { - pasAssocLayers[iLayer].psInfo = NULL; + pasAssocLayers[iLayer].psInfo = nullptr; } } @@ -2748,7 +2744,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* No matching target layer : just consumes the features */ OGRFeature* poFeature; - while ((poFeature = poLayer->GetNextFeature()) != NULL) + while ((poFeature = poLayer->GetNextFeature()) != nullptr) { nReadFeatureCount++; OGRFeature::DestroyFeature(poFeature); @@ -2779,7 +2775,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, else { int nLayerCount = 0; - OGRLayer** papoLayers = NULL; + OGRLayer** papoLayers = nullptr; /* -------------------------------------------------------------------- */ /* Process each data source layer. */ @@ -2795,7 +2791,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, { OGRLayer* poLayer = poDS->GetLayer(iLayer); - if (poLayer == NULL) + if (poLayer == nullptr) { CPLError(CE_Failure, 0, "FAILURE: Couldn't fetch advertised layer %d!\n", iLayer); @@ -2814,12 +2810,12 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, papoLayers = (OGRLayer**)CPLMalloc(sizeof(OGRLayer*) * nLayerCount); for (int iLayer = 0; - papszLayers[iLayer] != NULL; + papszLayers[iLayer] != nullptr; iLayer++) { OGRLayer* poLayer = poDS->GetLayerByName(papszLayers[iLayer]); - if (poLayer == NULL) + if (poLayer == nullptr) { CPLError(CE_Failure, 0, "FAILURE: Couldn't fetch requested layer '%s'!\n", papszLayers[iLayer]); @@ -2838,13 +2834,13 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, /* -------------------------------------------------------------------- */ VSIStatBufL sStat; if (EQUAL(poDriver->GetDescription(), "ESRI Shapefile") && - nLayerCount == 1 && pszNewLayerName == NULL && + nLayerCount == 1 && pszNewLayerName == nullptr && VSIStatL(pszDestDataSource, &sStat) == 0 && VSI_ISREG(sStat.st_mode)) { pszNewLayerName = CPLStrdup(CPLGetBasename(pszDestDataSource)); } - long* panLayerCountFeatures = (long*)CPLCalloc(sizeof(long), nLayerCount); + long* panLayerCountFeatures = static_cast(CPLCalloc(sizeof(long), nLayerCount)); long nCountLayersFeatures = 0; long nAccCountFeatures = 0; int iLayer; @@ -2855,10 +2851,10 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, iLayer++) { OGRLayer* poLayer = papoLayers[iLayer]; - if (poLayer == NULL) + if (poLayer == nullptr) continue; - if (pszWHERE != NULL) + if (pszWHERE != nullptr) { if (poLayer->SetAttributeFilter(pszWHERE) != OGRERR_NONE) { @@ -2892,7 +2888,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, iLayer++) { OGRLayer* poLayer = papoLayers[iLayer]; - if (poLayer == NULL) + if (poLayer == nullptr) continue; @@ -2912,8 +2908,8 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, } else { - pfnProgress = NULL; - pProgressArg = NULL; + pfnProgress = nullptr; + pProgressArg = nullptr; } int nRet = ((OGRSplitListFieldLayer*)poPassedLayer)->BuildLayerDefn(pfnProgress, pProgressArg); @@ -2969,7 +2965,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, poPassedLayer->ResetReading(); - if ((psInfo == NULL || + if ((psInfo == nullptr || !TranslateLayer(psInfo, poDS, poPassedLayer, poODS, bTransform, bWrapDateline, pszDateLineOffset, poOutputSRS, bNullifyOutputSRS, @@ -2980,7 +2976,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, panLayerCountFeatures[iLayer], poClipSrc, poClipDst, bExplodeCollections, - nSrcFileSize, NULL, + nSrcFileSize, nullptr, pfnProgress, pProgressArg)) && !bSkipFailures) { @@ -3030,7 +3026,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, if (poGCPCoordTrans) delete poGCPCoordTrans; - if (pasGCPs != NULL) + if (pasGCPs != nullptr) { GDALDeinitGCPs(nGCPCount, pasGCPs); CPLFree(pasGCPs); @@ -3070,7 +3066,7 @@ STDMETHODIMP CUtils::OGR2OGR(BSTR bstrSrcFilename, BSTR bstrDstFilename, /************************************************************************/ static void SetZ(OGRGeometry* poGeom, double dfZ) { - if (poGeom == NULL) + if (poGeom == nullptr) return; switch (wkbFlatten(poGeom->getGeometryType())) { @@ -3323,7 +3319,7 @@ static int SetupCT(TargetLayerInfo* psInfo, if (bTransform) { - if (poSourceSRS == NULL) + if (poSourceSRS == nullptr) { CPLError(CE_Failure, 0, "Can't transform coordinates, source layer has no\n" "coordinate system. Use -s_srs to set one.\n"); @@ -3331,10 +3327,10 @@ static int SetupCT(TargetLayerInfo* psInfo, return FALSE; } - CPLAssert(NULL != poSourceSRS); - CPLAssert(NULL != poOutputSRS); + CPLAssert(nullptr != poSourceSRS); + CPLAssert(nullptr != poOutputSRS); - if (psInfo->papoCT[iGeom] != NULL && + if (psInfo->papoCT[iGeom] != nullptr && psInfo->papoCT[iGeom]->GetSourceCS() == poSourceSRS) { poCT = psInfo->papoCT[iGeom]; @@ -3342,9 +3338,9 @@ static int SetupCT(TargetLayerInfo* psInfo, else { poCT = OGRCreateCoordinateTransformation(poSourceSRS, poOutputSRS); - if (poCT == NULL) + if (poCT == nullptr) { - char* pszWKT = NULL; + char* pszWKT = nullptr; CPLError(CE_Failure, 0, "Failed to create coordinate transformation between the\n" "following coordinate systems. This may be because they\n" @@ -3361,7 +3357,7 @@ static int SetupCT(TargetLayerInfo* psInfo, return FALSE; } - if (poGCPCoordTrans != NULL) + if (poGCPCoordTrans != nullptr) poCT = new CompositeCT(poGCPCoordTrans, poCT); } @@ -3378,7 +3374,7 @@ static int SetupCT(TargetLayerInfo* psInfo, if (bWrapDateline) { - if (bTransform && poCT != NULL && poOutputSRS != NULL && poOutputSRS->IsGeographic()) + if (bTransform && poCT != nullptr && poOutputSRS != nullptr && poOutputSRS->IsGeographic()) { papszTransformOptions = CSLAddString(papszTransformOptions, "WRAPDATELINE=YES"); @@ -3387,7 +3383,7 @@ static int SetupCT(TargetLayerInfo* psInfo, papszTransformOptions = CSLAddString(papszTransformOptions, soOffset); } - else if (poSourceSRS != NULL && poSourceSRS->IsGeographic()) + else if (poSourceSRS != nullptr && poSourceSRS->IsGeographic()) { papszTransformOptions = CSLAddString(papszTransformOptions, "WRAPDATELINE=YES"); @@ -3445,7 +3441,7 @@ static int TranslateLayer(TargetLayerInfo* psInfo, int bForceToPolygon = FALSE; int bForceToMultiPolygon = FALSE; int bForceToMultiLineString = FALSE; - int* panMap = NULL; + int* panMap = nullptr; int iSrcZField; poDstLayer = psInfo->poDstLayer; @@ -3454,7 +3450,7 @@ static int TranslateLayer(TargetLayerInfo* psInfo, int nSrcGeomFieldCount = poSrcLayer->GetLayerDefn()->GetGeomFieldCount(); int nDstGeomFieldCount = poDstLayer->GetLayerDefn()->GetGeomFieldCount(); - if (poOutputSRS == NULL && !bNullifyOutputSRS) + if (poOutputSRS == nullptr && !bNullifyOutputSRS) { if (nSrcGeomFieldCount == 1) { @@ -3493,7 +3489,7 @@ static int TranslateLayer(TargetLayerInfo* psInfo, while (TRUE) { - OGRFeature* poDstFeature = NULL; + OGRFeature* poDstFeature = nullptr; if (nFIDToFetch != OGRNullFID) { @@ -3501,12 +3497,12 @@ static int TranslateLayer(TargetLayerInfo* psInfo, if (nFeaturesInTransaction == 0) poFeature = poSrcLayer->GetFeature(nFIDToFetch); else - poFeature = NULL; + poFeature = nullptr; } else poFeature = poSrcLayer->GetNextFeature(); - if (poFeature == NULL) + if (poFeature == nullptr) break; if (psInfo->nFeaturesRead == 0 || psInfo->bPerFeatureCT) @@ -3564,7 +3560,7 @@ static int TranslateLayer(TargetLayerInfo* psInfo, /* Optimization to avoid duplicating the source geometry in the */ /* target feature : we steal it from the source feature for now... */ - OGRGeometry* poStolenGeometry = NULL; + OGRGeometry* poStolenGeometry = nullptr; if (!bExplodeCollections && nSrcGeomFieldCount == 1 && nDstGeomFieldCount == 1) { @@ -3604,7 +3600,7 @@ static int TranslateLayer(TargetLayerInfo* psInfo, for (int iGeom = 0; iGeom < nDstGeomFieldCount; iGeom++) { OGRGeometry* poDstGeometry = poDstFeature->GetGeomFieldRef(iGeom); - if (poDstGeometry == NULL) + if (poDstGeometry == nullptr) continue; if (nParts > 0) @@ -3652,7 +3648,7 @@ static int TranslateLayer(TargetLayerInfo* psInfo, if (poClipSrc) { OGRGeometry* poClipped = poDstGeometry->Intersection(poClipSrc); - if (poClipped == NULL || poClipped->IsEmpty()) + if (poClipped == nullptr || poClipped->IsEmpty()) { OGRGeometryFactory::destroyGeometry(poClipped); goto end_loop; @@ -3666,11 +3662,11 @@ static int TranslateLayer(TargetLayerInfo* psInfo, poCT = poGCPCoordTrans; char** papszTransformOptions = psInfo->papapszTransformOptions[iGeom]; - if (poCT != NULL || papszTransformOptions != NULL) + if (poCT != nullptr || papszTransformOptions != nullptr) { OGRGeometry* poReprojectedGeom = OGRGeometryFactory::transformWithOptions(poDstGeometry, poCT, papszTransformOptions); - if (poReprojectedGeom == NULL) + if (poReprojectedGeom == nullptr) { if (nGroupTransactions) poDstLayer->CommitTransaction(); @@ -3688,7 +3684,7 @@ static int TranslateLayer(TargetLayerInfo* psInfo, poDstFeature->SetGeomFieldDirectly(iGeom, poReprojectedGeom); poDstGeometry = poReprojectedGeom; } - else if (poOutputSRS != NULL) + else if (poOutputSRS != nullptr) { poDstGeometry->assignSpatialReference(poOutputSRS); } @@ -3696,7 +3692,7 @@ static int TranslateLayer(TargetLayerInfo* psInfo, if (poClipDst) { OGRGeometry* poClipped = poDstGeometry->Intersection(poClipDst); - if (poClipped == NULL || poClipped->IsEmpty()) + if (poClipped == nullptr || poClipped->IsEmpty()) { OGRGeometryFactory::destroyGeometry(poClipped); goto end_loop; @@ -3766,8 +3762,8 @@ static int TranslateLayer(TargetLayerInfo* psInfo, { if ((nCount % 1000) == 0) { - OGRLayer* poFCLayer = poSrcDS->ExecuteSQL("GetBytesRead()", NULL, NULL); - if (poFCLayer != NULL) + OGRLayer* poFCLayer = poSrcDS->ExecuteSQL("GetBytesRead()", nullptr, nullptr); + if (poFCLayer != nullptr) { OGRFeature* poFeat = poFCLayer->GetNextFeature(); if (poFeat) @@ -3818,18 +3814,18 @@ STDMETHODIMP CUtils::OGRInfo(BSTR bstrSrcFilename, BSTR bstrOptions, BSTR bstrLa CString sOutput = ""; int nArgc = 0; - const char* pszWHERE = NULL; - const char* pszDataSource = NULL; - char** papszLayers = NULL; - OGRGeometry* poSpatialFilter = NULL; + const char* pszWHERE = nullptr; + const char* pszDataSource = nullptr; + char** papszLayers = nullptr; + OGRGeometry* poSpatialFilter = nullptr; int nRepeatCount = 1, bAllLayers = FALSE; - const char* pszSQLStatement = NULL; - const char* pszDialect = NULL; + const char* pszSQLStatement = nullptr; + const char* pszDialect = nullptr; int bReadOnly = FALSE; int bVerbose = TRUE; int bSummaryOnly = FALSE; int nFetchFID = OGRNullFID; - char** papszOptions = NULL; + char** papszOptions = nullptr; pszDataSource = OLE2CA(bstrSrcFilename); /* -------------------------------------------------------------------- */ @@ -3911,7 +3907,7 @@ STDMETHODIMP CUtils::OGRInfo(BSTR bstrSrcFilename, BSTR bstrOptions, BSTR bstrLa } } - if (bstrLayers != NULL && SysStringLen(bstrLayers) > 0) + if (bstrLayers != nullptr && SysStringLen(bstrLayers) > 0) { int curPos = 0; CString sLayers = OLE2CA(bstrLayers); @@ -3928,30 +3924,30 @@ STDMETHODIMP CUtils::OGRInfo(BSTR bstrSrcFilename, BSTR bstrOptions, BSTR bstrLa /* -------------------------------------------------------------------- */ /* Open data source. */ /* -------------------------------------------------------------------- */ - GDALDataset* poDS = NULL; - GDALDriver* poDriver = NULL; + GDALDataset* poDS = nullptr; + GDALDriver* poDriver = nullptr; poDS = (GDALDataset*)GDALOpenEx(pszDataSource, (!bReadOnly ? GDAL_OF_UPDATE : GDAL_OF_READONLY) | GDAL_OF_VECTOR, - NULL, NULL, NULL); // TODO: revisit; used to be = papszOpenOptions + nullptr, nullptr, nullptr); // TODO: revisit; used to be = papszOpenOptions - if (poDS == NULL && !bReadOnly) + if (poDS == nullptr && !bReadOnly) { poDS = (GDALDataset*)GDALOpenEx(pszDataSource, - GDAL_OF_READONLY | GDAL_OF_VECTOR, NULL, NULL, NULL); // TODO: revisit; used to be = papszOpenOptions - if (poDS != NULL && bVerbose) + GDAL_OF_READONLY | GDAL_OF_VECTOR, nullptr, nullptr, nullptr); // TODO: revisit; used to be = papszOpenOptions + if (poDS != nullptr && bVerbose) { printf("Had to open data source read-only.\n"); bReadOnly = TRUE; } } - if (poDS != NULL) + if (poDS != nullptr) poDriver = poDS->GetDriver(); /* -------------------------------------------------------------------- */ /* Report failure */ /* -------------------------------------------------------------------- */ - if (poDS == NULL) + if (poDS == nullptr) { OGRSFDriverRegistrar* poR = OGRSFDriverRegistrar::GetRegistrar(); @@ -3989,9 +3985,9 @@ STDMETHODIMP CUtils::OGRInfo(BSTR bstrSrcFilename, BSTR bstrOptions, BSTR bstrLa /* -------------------------------------------------------------------- */ /* Special case for -sql clause. No source layers required. */ /* -------------------------------------------------------------------- */ - if (pszSQLStatement != NULL) + if (pszSQLStatement != nullptr) { - OGRLayer* poResultSet = NULL; + OGRLayer* poResultSet = nullptr; nRepeatCount = 0; // skip layer reporting. @@ -4001,9 +3997,9 @@ STDMETHODIMP CUtils::OGRInfo(BSTR bstrSrcFilename, BSTR bstrOptions, BSTR bstrLa poResultSet = poDS->ExecuteSQL(pszSQLStatement, poSpatialFilter, pszDialect); - if (poResultSet != NULL) + if (poResultSet != nullptr) { - if (pszWHERE != NULL) + if (pszWHERE != nullptr) { if (poResultSet->SetAttributeFilter(pszWHERE) != OGRERR_NONE) { @@ -4014,7 +4010,7 @@ STDMETHODIMP CUtils::OGRInfo(BSTR bstrSrcFilename, BSTR bstrOptions, BSTR bstrLa } } - sOutput += ReportOnLayer(poResultSet, NULL, NULL, bVerbose, + sOutput += ReportOnLayer(poResultSet, nullptr, nullptr, bVerbose, bSummaryOnly, nFetchFID, papszOptions); poDS->ReleaseResultSet(poResultSet); } @@ -4033,7 +4029,7 @@ STDMETHODIMP CUtils::OGRInfo(BSTR bstrSrcFilename, BSTR bstrOptions, BSTR bstrLa { OGRLayer* poLayer = poDS->GetLayer(iLayer); - if (poLayer == NULL) + if (poLayer == nullptr) { sOutput.AppendFormat("FAILURE: Couldn't fetch advertised layer %d!\n", iLayer); @@ -4071,11 +4067,11 @@ STDMETHODIMP CUtils::OGRInfo(BSTR bstrSrcFilename, BSTR bstrOptions, BSTR bstrLa /* Process specified data source layers. */ /* -------------------------------------------------------------------- */ char** papszIter = papszLayers; - for (; *papszIter != NULL; papszIter++) + for (; *papszIter != nullptr; papszIter++) { OGRLayer* poLayer = poDS->GetLayerByName(*papszIter); - if (poLayer == NULL) + if (poLayer == nullptr) { sOutput.AppendFormat("FAILURE: Couldn't fetch requested layer %s!\n", *papszIter); @@ -4097,7 +4093,7 @@ STDMETHODIMP CUtils::OGRInfo(BSTR bstrSrcFilename, BSTR bstrOptions, BSTR bstrLa end: CSLDestroy(papszLayers); CSLDestroy(papszOptions); - if (poDS != NULL) + if (poDS != nullptr) GDALClose((GDALDatasetH)poDS); if (poSpatialFilter) OGRGeometryFactory::destroyGeometry(poSpatialFilter); @@ -4125,7 +4121,7 @@ static CString ReportOnLayer(OGRLayer* poLayer, const char* pszWHERE, /* -------------------------------------------------------------------- */ /* Set filters if provided. */ /* -------------------------------------------------------------------- */ - if (pszWHERE != NULL) + if (pszWHERE != nullptr) { if (poLayer->SetAttributeFilter(pszWHERE) != OGRERR_NONE) { @@ -4134,7 +4130,7 @@ static CString ReportOnLayer(OGRLayer* poLayer, const char* pszWHERE, } } - if (poSpatialFilter != NULL) + if (poSpatialFilter != nullptr) poLayer->SetSpatialFilter(poSpatialFilter); /* -------------------------------------------------------------------- */ @@ -4158,7 +4154,7 @@ static CString ReportOnLayer(OGRLayer* poLayer, const char* pszWHERE, char* pszWKT; - if (poLayer->GetSpatialRef() == NULL) + if (poLayer->GetSpatialRef() == nullptr) pszWKT = CPLStrdup("(unknown)"); else { @@ -4195,27 +4191,27 @@ static CString ReportOnLayer(OGRLayer* poLayer, const char* pszWHERE, /* -------------------------------------------------------------------- */ /* Read, and dump features. */ /* -------------------------------------------------------------------- */ - OGRFeature* poFeature = NULL; + OGRFeature* poFeature = nullptr; if (nFetchFID == OGRNullFID && !bSummaryOnly) { - while ((poFeature = poLayer->GetNextFeature()) != NULL) + while ((poFeature = poLayer->GetNextFeature()) != nullptr) { - poFeature->DumpReadable(NULL, papszOptions); + poFeature->DumpReadable(nullptr, papszOptions); OGRFeature::DestroyFeature(poFeature); } } else if (nFetchFID != OGRNullFID) { poFeature = poLayer->GetFeature(nFetchFID); - if (poFeature == NULL) + if (poFeature == nullptr) { sOutput.AppendFormat("Unable to locate feature id %d on this layer.\n", nFetchFID); } else { - poFeature->DumpReadable(NULL, papszOptions); + poFeature->DumpReadable(nullptr, papszOptions); OGRFeature::DestroyFeature(poFeature); } } diff --git a/src/COM classes/Utils_Projections.cpp b/src/COM classes/Utils_Projections.cpp index a1afeb73..28edd864 100644 --- a/src/COM classes/Utils_Projections.cpp +++ b/src/COM classes/Utils_Projections.cpp @@ -154,7 +154,7 @@ STDMETHODIMP CUtils::GetWGS84ProjectionName(tkWgs84Projection projectionID, BSTR // but also includes those not specified by the enumerations, such as NAD27, NAD83 Harn, Beijing, Pulkova, etc. STDMETHODIMP CUtils::GetProjectionNameByID(int SRID, BSTR* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) try { @@ -184,7 +184,7 @@ STDMETHODIMP CUtils::GetProjectionNameByID(int SRID, BSTR* retVal) STDMETHODIMP CUtils::GetProjectionList(tkProjectionSet projectionSets, VARIANT* list, VARIANT_BOOL* retVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // guilty until proven innocent *retVal = VARIANT_FALSE; @@ -197,14 +197,14 @@ STDMETHODIMP CUtils::GetProjectionList(tkProjectionSet projectionSets, VARIANT* } else { - SAFEARRAY FAR* psa = NULL; + SAFEARRAY FAR* psa = nullptr; SAFEARRAYBOUND sabound[1]; sabound[0].lLbound = 0; int theSize = 0; if ((projectionSets & psAll_Projections) == psAll_Projections) { - theSize = pcsStrings.size(); + theSize = static_cast(pcsStrings.size()); } else { @@ -242,7 +242,7 @@ STDMETHODIMP CUtils::GetProjectionList(tkProjectionSet projectionSets, VARIANT* if (psa) { - BSTR* pBSTR = NULL; + BSTR* pBSTR = nullptr; SafeArrayAccessData(psa, (void **)&pBSTR); CComBSTR comBSTR; diff --git a/src/COM classes/WmsLayer.h b/src/COM classes/WmsLayer.h index a18384ef..2c1e5bc3 100644 --- a/src/COM classes/WmsLayer.h +++ b/src/COM classes/WmsLayer.h @@ -104,7 +104,7 @@ class ATL_NO_VTABLE CWmsLayer : STDMETHOD(get_TileSize)(LONG* pVal); STDMETHOD(put_TileSize)(LONG newVal); -private: +private: BSTR _key; long _lastErrorCode; WmsCustomProvider* _provider; diff --git a/src/ComHelpers/SelectionHelper.cpp b/src/ComHelpers/SelectionHelper.cpp index 0bc777a7..4a73f9e9 100644 --- a/src/ComHelpers/SelectionHelper.cpp +++ b/src/ComHelpers/SelectionHelper.cpp @@ -20,13 +20,13 @@ bool SelectionHelper::PolylineIntersection(std::vector& xPts, std::vecto int end_part = 0; size_t numpoints = xPts.size(); - long numparts = parts.size(); + long numparts = static_cast(parts.size()); for (long i = 0; i < numparts; i++) { beg_part = parts[i]; if (beg_part < 0) beg_part = 0; - end_part = (int)(parts.size() - 1) > i ? parts[i + 1] : numpoints; + end_part = static_cast(parts.size()) - 1 > i ? parts[i + 1] : static_cast(numpoints); //for(size_t j = 0; j < numpoints - 1; j++) for (long j = beg_part; j < end_part - 1; j++) @@ -68,7 +68,7 @@ bool SelectionHelper::PolylineIntersection(std::vector& xPts, std::vecto return true; } - // generate the equation of the line + // generate the equation of the line double m = dy / dx; double b = p1y - m*p1x; @@ -103,7 +103,7 @@ bool SelectionHelper::PolygonIntersection(std::vector& xPts, std::vector int end_part = 0; bool selected = false; - long numparts = parts.size(); + long numparts = static_cast(parts.size()); size_t numpoints = xPts.size(); for (long j = 0; j < numparts && !selected; j++) @@ -115,7 +115,7 @@ bool SelectionHelper::PolygonIntersection(std::vector& xPts, std::vector if ((int)(parts.size() - 1) > j) end_part = parts[j + 1]; else - end_part = numpoints; + end_part = static_cast(numpoints); for (long k = beg_part; k < end_part - 1; k++) { @@ -162,7 +162,7 @@ bool SelectionHelper::PolygonIntersection(std::vector& xPts, std::vector return true; } - // generate the equation of the line + // generate the equation of the line double m = dy / dx; double b = p1y - m*p1x; @@ -190,7 +190,7 @@ bool SelectionHelper::PolygonIntersection(std::vector& xPts, std::vector bool SelectionHelper::SelectWithShapeBounds(IShapefile* sf, IShape* shp, vector& indices) { if (!sf || !shp) return false; - CComPtr box = NULL; + CComPtr box = nullptr; shp->get_Extents(&box); return SelectShapes(sf, Extent(box), SelectMode::INTERSECTION, indices); } @@ -347,7 +347,7 @@ int SelectionHelper::SelectByPolygon(IShapefile* sf, IShape* poly, int& errorCod for (size_t i = 0; i < indices.size(); i++) { - CComPtr shp = NULL; + CComPtr shp = nullptr; sf->get_Shape(indices[i], &shp); if (shp) { diff --git a/src/ComHelpers/ShapeHelper.cpp b/src/ComHelpers/ShapeHelper.cpp index 7b449ac8..232f6c98 100644 --- a/src/ComHelpers/ShapeHelper.cpp +++ b/src/ComHelpers/ShapeHelper.cpp @@ -31,7 +31,7 @@ ShpfileType ShapeHelper::GetShapeType2D(IShape* shp) bool ShapeHelper::PointInThisPoly(IShape* shp, double x, double y) { if (!shp) return false; - CComPtr pnt = NULL; + CComPtr pnt = nullptr; ComHelper::CreatePoint(&pnt); VARIANT_BOOL vb; shp->PointInThisPoly(pnt, &vb); @@ -102,7 +102,7 @@ bool ShapeHelper::PointWithinShape(IShape* shape, double projX, double projY, do return true; VARIANT_BOOL vb; - IPoint* pnt = NULL; + IPoint* pnt = nullptr; ComHelper::CreatePoint(&pnt); pnt->put_X(b_minX); @@ -282,7 +282,7 @@ bool ShapeHelper::ForceProperShapeType(IShape* shp, ShpfileType sfType) if (ShapeUtility::Convert2D(sfType) == SHP_MULTIPOINT && ShapeUtility::Convert2D(shapeType) == SHP_POINT) { VARIANT_BOOL vb; - CComPtr pnt = NULL; + CComPtr pnt = nullptr; shp->get_Point(0, &pnt); shp->Create(sfType, &vb); if (vb) @@ -349,7 +349,7 @@ int ShapeHelper::GetLargestPart(IShape* shp) for (int j = 0; j < numParts; j++) { - CComPtr shpPart = NULL; + CComPtr shpPart = nullptr; shp->get_PartAsShape(j, &shpPart); if (!shpPart) continue; @@ -395,13 +395,13 @@ void ShapeHelper::AddLabelToShape(IShape* shp, ILabels* labels, BSTR text, tkLab // ************************************************************* IShape* ShapeHelper::CenterAsShape(IShape* shp) { - if (!shp) return NULL; + if (!shp) return nullptr; - CComPtr pnt = NULL; + CComPtr pnt = nullptr; shp->get_Center(&pnt); VARIANT_BOOL vb; - IShape* shpNew = NULL; + IShape* shpNew = nullptr; ComHelper::CreateShape(&shp); shp->Create(SHP_POINT, &vb); @@ -429,7 +429,7 @@ int ShapeHelper::GetContentLength(IShape* shp) } -#if DEBUG_LOG +#ifndef RELEASE_MODE // ************************************************************* // DebugDump() // ************************************************************* diff --git a/src/ComHelpers/ShapeHelper.h b/src/ComHelpers/ShapeHelper.h index 315798d8..4023d91c 100644 --- a/src/ComHelpers/ShapeHelper.h +++ b/src/ComHelpers/ShapeHelper.h @@ -19,7 +19,7 @@ class ShapeHelper static void AddLabelToShape(IShape* shp, ILabels* labels, BSTR text, tkLabelPositioning method, tkLineLabelOrientation orientation, double offsetX, double offsetY); static IShape* CenterAsShape(IShape* shp); static int GetContentLength(IShape* shp); -#if DEBUG_LOG +#ifndef RELEASE_MODE static void DebugDump(IShape* shp); #endif }; diff --git a/src/CopyTamasFiles.bat b/src/CopyTamasFiles.bat index 726ef8b3..ca143898 100644 --- a/src/CopyTamasFiles.bat +++ b/src/CopyTamasFiles.bat @@ -10,7 +10,7 @@ REM * Paul Meems, update for ecw dll, June 2015 * REM * Paul Meems, update for ecw dll to v5.3, Aug 2017 * REM * Paul Meems, update for xerces and lti_dsdk dll, Aug 2018 * REM * Paul Meems, update for GDAL v3+, Jan 2022 * -REM * Daniel Hedén, update for GDAL v3.10.3, proj9 * +REM * Daniel Hedén, update for GDAL v3.10.3 and proj9 * REM * Usage to test: * REM * CopyTamasFiles.bat D:\dev\MapwinGIS\GitHub\support\GDAL_SDK\v140\bin\win32 D:\dev\MapwinGIS\GitHub\src\bin\Win32\ REM ************************************************************* @@ -37,9 +37,6 @@ REM Copy PROJ4 data: xcopy /v /c /r /y %_from_dir%\gdal-data\*.* %_to_dir%gdal-data\ REM xcopy /v /c /r /y %_from_dir%\proj\SHARE\*.* %_to_dir%..\PROJ_NAD\ -REM Copy Proj7 data. TODO: Check if copied to correct location: -rem xcopy /v /c /r /y %_from_dir%\proj7\share\*.* %_to_dir%proj7\share\ - REM Copy Proj9 data. TODO: Check if copied to correct location: xcopy /v /c /r /y %_from_dir%\proj9\share\*.* %_to_dir%proj9\share\ @@ -53,9 +50,9 @@ REM Copy gdal plugins-external xcopy /v /c /r /y %_from_dir%\gdal\plugins-optional\*.* %_to_dir%gdal\plugins-optional\ REM Copy needed Tamas binaries: -FOR %%G IN (cfitsio.dll freexl.dll geos.dll geos_c.dll hdf.dll hdf5.dll hdf5_hl.dll hdf5_cpp.dll hdf5_hl_cpp.dll libcrypto-1_1.dll libcrypto-1_1-x64.dll libcrypto-3-x64.dll +FOR %%G IN (cfitsio.dll freexl.dll geos.dll geos_c.dll hdf.dll hdf5.dll hdf5_hl.dll hdf5_cpp.dll hdf5_hl_cpp.dll libcrypto-3.dll libcrypto-1_1.dll libcrypto-1_1-x64.dll libcrypto-3-x64.dll libcurl.dll libexpat.dll tiff.dll tiffxx.dll ogdi.dll mfhdf.dll pcre.dll - iconv-2.dll libmysql.dll libpng16.dll libpq.dll libssl-1_1.dll libssl-1_1-x64.dll libssl-3-x64.dll libxml2.dll lti_lidar_dsdk_1.1.dll netcdf.dll + iconv-2.dll libmysql.dll libpng16.dll libpq.dll libssl-1_1.dll libssl-1_1-x64.dll libssl-3.dll libssl-3-x64.dll libxml2.dll lti_lidar_dsdk_1.1.dll netcdf.dll openjp2.dll proj_9.dll spatialite.dll sqlite3.dll szip.dll tbb.dll xdr.dll zlib.dll zstd.dll NCSEcw.dll) DO ( IF EXIST %_from_dir%\%%G ( diff --git a/src/Drawing/ChartDrawing.cpp b/src/Drawing/ChartDrawing.cpp index 218ae9d3..f46f1217 100644 --- a/src/Drawing/ChartDrawing.cpp +++ b/src/Drawing/ChartDrawing.cpp @@ -79,7 +79,7 @@ bool CChartDrawer::PrepareValues(IShapefile* sf, ICharts* charts, ChartOptions* CComBSTR expr; charts->get_VisibilityExpression(&expr); - CComPtr tbl = NULL; + CComPtr tbl = nullptr; sf->get_Table(&tbl); std::vector arrInit; @@ -172,7 +172,7 @@ void CChartDrawer::DrawCharts(IShapefile* sf) REAL dx = _graphics->GetDpiX(); // reading chart properties - CComPtr charts = NULL; + CComPtr charts = nullptr; sf->get_Charts(&charts); if (!charts) return; @@ -217,9 +217,9 @@ void CChartDrawer::DrawCharts(IShapefile* sf) bool vertical = (options->valuesStyle == vsVertical); CString sFormat = normalized ? "%.2f" : "%g"; // format for numbers - CFont* oldFont = NULL; + CFont* oldFont = nullptr; CFont fnt; - Font* gdiPlusFont = NULL; + Font* gdiPlusFont = nullptr; if (options->valuesVisible ) { @@ -243,7 +243,7 @@ void CChartDrawer::DrawCharts(IShapefile* sf) if (gdiPlusFont) { delete gdiPlusFont; - gdiPlusFont = NULL; + gdiPlusFont = nullptr; } for (size_t i = 0; i < values.size(); i++) { @@ -374,7 +374,7 @@ void CChartDrawer::DrawPieCharts(IShapefile* sf, ICharts* charts, ChartOptions* chartRect = new CRect((int)(xStart - pieWidth / 2), (int)(yStart - pieHeight / 2), int(xStart + pieWidth / 2), int(yStart + pieHeight / 2)); // collision avoidance - if (options->avoidCollisions && _collisionList != NULL) + if (options->avoidCollisions && _collisionList != nullptr) { if (_collisionList->HaveCollision(*chartRect)) { @@ -422,8 +422,8 @@ void CChartDrawer::DrawPieCharts(IShapefile* sf, ICharts* charts, ChartOptions* labelAngle = labelAngle - 360.0f; } - int x = (int)(xStart + sin(labelAngle / 180.0 * pi_) * options->radius); - int y = (int)(yStart - cos(labelAngle / 180.0 * pi_) * options->radius); + int x = static_cast(xStart + sin(labelAngle / 180.0 * pi_) * options->radius); + int y = static_cast(yStart - cos(labelAngle / 180.0 * pi_) * options->radius); if (labelAngle >= 0.0 && labelAngle <= 180.0) { @@ -448,7 +448,7 @@ void CChartDrawer::DrawPieCharts(IShapefile* sf, ICharts* charts, ChartOptions* rect->MoveToX(x - rect->Width() / 2); rect->MoveToY(y - rect->Height() / 2); - if (options->avoidCollisions && _collisionList != NULL) + if (options->avoidCollisions && _collisionList != nullptr) { if (_collisionList->HaveCollision(*rect)) { @@ -467,7 +467,7 @@ void CChartDrawer::DrawPieCharts(IShapefile* sf, ICharts* charts, ChartOptions* if (chartRect) { delete chartRect; - chartRect = NULL; + chartRect = nullptr; } continue; } @@ -487,7 +487,7 @@ void CChartDrawer::DrawPieCharts(IShapefile* sf, ICharts* charts, ChartOptions* yStart -= pieHeight / 2.0f; for (int j = 0; j < numBars; j++) { - sweepAngle = (REAL)(values[i][j] / sum * 360.0); + sweepAngle = static_cast(values[i][j] / sum * 360.0); if (sweepAngle > 0.0) { _graphics->FillPie(brushes[j], xStart, yStart, pieWidth, pieHeight, startAngle, sweepAngle); @@ -532,7 +532,7 @@ void CChartDrawer::DrawPieCharts(IShapefile* sf, ICharts* charts, ChartOptions* // drawing the values if (options->valuesVisible) { - for (unsigned int i = initLabelIndex; i < allLabels.size(); i++) + for (int i = static_cast(initLabelIndex); i < static_cast(allLabels.size()); i++) { CRect* rect = &allLabels[i].rect; _collisionList->AddRectangle(rect, collisionBuffer, collisionBuffer); @@ -542,12 +542,12 @@ void CChartDrawer::DrawPieCharts(IShapefile* sf, ICharts* charts, ChartOptions* ShapeRecord* info = (*positions)[i]; if (info) { - // storing rectangle for dragging operations + // storing rectangle for dragging operations info->chart->frame = chartRect; info->chart->isDrawn = true; } - if (options->avoidCollisions && _collisionList != NULL) + if (options->avoidCollisions && _collisionList != nullptr) { _collisionList->AddRectangle(chartRect, collisionBuffer, collisionBuffer); } @@ -597,8 +597,8 @@ void CChartDrawer::DrawBarCharts(IShapefile* sf, ICharts* charts, ChartOptions* ProjectionToPixel(pnt->chart->x, pnt->chart->y, x, y); - x += (double)offsetX; - y += (double)offsetY; + x += static_cast(offsetX); + y += static_cast(offsetY); // calculating max height double max = 0.0; @@ -609,8 +609,8 @@ void CChartDrawer::DrawBarCharts(IShapefile* sf, ICharts* charts, ChartOptions* } double maxHeight = options->barHeight / maxValue * max; - int xStart = int(x - numBars * options->barWidth / 2.0); - int yStart = int(y + maxHeight / 2.0); + int xStart = static_cast(x - numBars * options->barWidth / 2.0); + int yStart = static_cast(y + maxHeight / 2.0); double angle = 45.0; @@ -618,7 +618,7 @@ void CChartDrawer::DrawBarCharts(IShapefile* sf, ICharts* charts, ChartOptions* bool canDraw = false; for (int j = 0; j < numBars; j++) { - int height = int((double)options->barHeight / maxValue * values[i][j]); + int height = static_cast(static_cast(options->barHeight) / maxValue * values[i][j]); if (height > 0) canDraw = true; } @@ -629,14 +629,14 @@ void CChartDrawer::DrawBarCharts(IShapefile* sf, ICharts* charts, ChartOptions* } // collision avoidance - CRect* rectChart = NULL; - if (options->avoidCollisions && _collisionList != NULL) + CRect* rectChart = nullptr; + if (options->avoidCollisions && _collisionList != nullptr) { rectChart = new CRect((int)xStart, int(yStart - options->barHeight), int(xStart + options->barWidth * numBars), (int)yStart); if (options->use3Dmode) { - rectChart->right += (long)(sin(pi_ / 4.0) * options->thickness); - rectChart->top -= (long)(cos(pi_ / 4.0) * options->thickness); + rectChart->right += static_cast(sin(pi_ / 4.0) * options->thickness); + rectChart->top -= static_cast(cos(pi_ / 4.0) * options->thickness); } if (_collisionList->HaveCollision(*rectChart)) @@ -649,15 +649,15 @@ void CChartDrawer::DrawBarCharts(IShapefile* sf, ICharts* charts, ChartOptions* std::vector labels; if (options->valuesVisible) { - int xAdd = (int)(sin(45.0 / 180 * pi_) * options->thickness); + int xAdd = static_cast(sin(45.0 / 180 * pi_) * options->thickness); // drawing values - xStart = int(x - numBars * options->barWidth / 2.0); - yStart = int(y + maxHeight / 2.0); + xStart = static_cast(x - numBars * options->barWidth / 2.0); + yStart = static_cast(y + maxHeight / 2.0); for (int j = 0; j < numBars; j++) { - int height = int((double)options->barHeight / maxValue * values[i][j]); + int height = static_cast(static_cast(options->barHeight) / maxValue * values[i][j]); if (height != 0) { CString s = Utility::FormatNumber(values[i][j], sFormat); @@ -700,7 +700,7 @@ void CChartDrawer::DrawBarCharts(IShapefile* sf, ICharts* charts, ChartOptions* rect->MoveToXY(xShift, yShift); } - if (options->avoidCollisions && _collisionList != NULL) + if (options->avoidCollisions && _collisionList != nullptr) { if (_collisionList->HaveCollision(*rect)) { @@ -713,7 +713,7 @@ void CChartDrawer::DrawBarCharts(IShapefile* sf, ICharts* charts, ChartOptions* ValueRectangle value; value.string = s; - // drawing frame + // drawing frame if (!vertical) { CRect r(rect->left - 2, rect->top, rect->right + 2, rect->bottom); @@ -738,17 +738,17 @@ void CChartDrawer::DrawBarCharts(IShapefile* sf, ICharts* charts, ChartOptions* if (rectChart) { delete rectChart; - rectChart = NULL; + rectChart = nullptr; } continue; } } // drawing the bars - xStart = int(x - numBars * options->barWidth / 2.0); + xStart = static_cast(x - numBars * options->barWidth / 2.0); for (int j = 0; j < numBars; j++) { - int height = int((double)options->barHeight / maxValue * values[i][j]); + int height = static_cast(static_cast(options->barHeight) / maxValue * values[i][j]); if (height != 0) { // drawing bars @@ -796,7 +796,7 @@ void CChartDrawer::DrawBarCharts(IShapefile* sf, ICharts* charts, ChartOptions* DrawLabels(gdiPlusFont, options, labels, true, vertical); // adding chart rect to collision list - if (options->avoidCollisions && _collisionList != NULL) + if (options->avoidCollisions && _collisionList != nullptr) { _collisionList->AddRectangle(rectChart, collisionBuffer, collisionBuffer); ShapeRecord* info = (*positions)[i]; @@ -882,10 +882,9 @@ void CChartDrawer::DrawLabels(Gdiplus::Font* font, ChartOptions* options, std::v else { _graphics->DrawString(s, s.GetLength(), font, r, &format, &textBrush); _graphics->SetTransform(&transform); - } - if (addToCollisionList && options->avoidCollisions && _collisionList != NULL) + if (addToCollisionList && options->avoidCollisions && _collisionList != nullptr) { _collisionList->AddRectangle(rect, 0, 0); } @@ -900,7 +899,7 @@ void CChartDrawer::PrepareBrushes(long numBars, ICharts* charts, ChartOptions* o { for (long i = 0; i < numBars; i++) { - CComPtr chartField = NULL; + CComPtr chartField = nullptr; charts->get_Field(i, &chartField); OLE_COLOR color; diff --git a/src/Drawing/DrawingOptions.cpp b/src/Drawing/DrawingOptions.cpp index dfd6cc69..ea7ceb15 100644 --- a/src/Drawing/DrawingOptions.cpp +++ b/src/Drawing/DrawingOptions.cpp @@ -86,9 +86,9 @@ CDrawingOptionsEx& CDrawingOptionsEx::operator=(const CDrawingOptionsEx& opt) this->minLineWidth = opt.minLineWidth; this->maxLineWidth = opt.maxLineWidth; - this->picture = NULL; - this->bitmapPlus = NULL; - this->imgAttributes = NULL; + this->picture = nullptr; + this->bitmapPlus = nullptr; + this->imgAttributes = nullptr; this->verticesColor = opt.verticesColor; this->verticesFillVisible = opt.verticesFillVisible; @@ -106,13 +106,13 @@ CDrawingOptionsEx& CDrawingOptionsEx::operator=(const CDrawingOptionsEx& opt) this->minVisibleZoom = opt.minVisibleZoom; this->maxVisibleZoom = opt.maxVisibleZoom; - brushPlus = NULL; + brushPlus = nullptr; if(pen) delete pen; pen = new CPen(); if (brush) delete brush; brush = new CBrush(); - penOld = NULL; - brushOld = NULL; + penOld = nullptr; + brushOld = nullptr; return *this; } @@ -277,14 +277,14 @@ void CDrawingOptionsEx::ReleaseGdiBrushAndPen(CDC* dc) { dc->SelectObject(this->penOld); this->pen->DeleteObject(); - this->penOld = NULL; + this->penOld = nullptr; } if (this->brushOld) { dc->SelectObject(this->brushOld); this->brush->DeleteObject(); - this->brushOld = NULL; + this->brushOld = nullptr; } } #pragma endregion @@ -323,7 +323,7 @@ void CDrawingOptionsEx::InitGdiPlusBrush( Gdiplus::RectF* bounds ) this->ReleaseGdiPlusBrush(); - long alpha = ((long)this->fillTransparency)<<24; + long alpha = static_cast(this->fillTransparency)<<24; if (this->fillType == ftStandard ) { @@ -337,7 +337,7 @@ void CDrawingOptionsEx::InitGdiPlusBrush( Gdiplus::RectF* bounds ) { brushPlus = new SolidBrush(Color(alpha | BGR_TO_RGB(this->fillColor))); } - else + else { Gdiplus::Color clr; if ( this->fillBgTransparent ) @@ -356,8 +356,8 @@ void CDrawingOptionsEx::InitGdiPlusBrush( Gdiplus::RectF* bounds ) { // texture fill bool canDraw = true; - - if (this->picture == NULL) canDraw = false; + + if (this->picture == nullptr) canDraw = false; if (this->scaleX == 0 || this->scaleY == 0) canDraw = false; long width, height; @@ -379,7 +379,7 @@ void CDrawingOptionsEx::InitGdiPlusBrush( Gdiplus::RectF* bounds ) // swap with scaled bitmap if (this->scaleX != 1.0 || this->scaleY != 1.0) { - Bitmap* newBmp = new Bitmap((int)(bmp->GetWidth() * this->scaleX), + Bitmap* newBmp = new Bitmap((int)(bmp->GetWidth() * this->scaleX), (int)(bmp->GetHeight() * this->scaleY)); Graphics* g = new Gdiplus::Graphics(newBmp); g->DrawImage(bmp, Rect(0, 0, newBmp->GetWidth(), newBmp->GetHeight()), 0, 0, bmp->GetWidth(), bmp->GetHeight(), Gdiplus::UnitPixel); @@ -595,7 +595,7 @@ void CDrawingOptionsEx::InitGdiPlusPicture() { this->ReleaseGdiPlusBitmap(); - if (this->picture == NULL) + if (this->picture == nullptr) { return; } @@ -613,7 +613,7 @@ void CDrawingOptionsEx::InitGdiPlusPicture() if (imgAttributes) { delete imgAttributes; - imgAttributes = NULL; + imgAttributes = nullptr; } double alpha = fillTransparency/255.0; @@ -634,7 +634,6 @@ void CDrawingOptionsEx::LoadIcon() // first let's check whether it is in-memory GDI+ icon after deserialization if (type == istGDIPlus) { - bitmapPlus = ImageHelper::GetGdiPlusIcon(this->picture); _needDeleteBitmapPlus = false; return; @@ -685,20 +684,20 @@ Gdiplus::GraphicsPath* CDrawingOptionsEx::get_FontCharacterPath(CDC* dc, bool pr CFont* oldFont = dc->SelectObject(&fnt); Gdiplus::Font fontPlus(dc->m_hDC); dc->SelectObject(&oldFont); - + CString str((char)this->pointCharcter); - int fontSize = MultiByteToWideChar(CP_ACP, 0, str.GetString(), -1, NULL, 0); + int fontSize = MultiByteToWideChar(CP_ACP, 0, str.GetString(), -1, nullptr, 0); WCHAR* wText = new WCHAR[fontSize]; MultiByteToWideChar(CP_ACP, 0, str.GetString(), -1, wText, fontSize); - + Gdiplus::GraphicsPath* path = new Gdiplus::GraphicsPath(); Gdiplus::StringFormat fmt; fmt.SetAlignment(Gdiplus::StringAlignmentCenter); fmt.SetLineAlignment(Gdiplus::StringAlignmentCenter); Gdiplus::FontFamily family; fontPlus.GetFamily(&family); - + path->StartFigure(); - path->AddString(wText, wcslen(wText), &family , fontPlus.GetStyle(), fontPlus.GetSize(), Gdiplus::PointF(0.0f, 0.0f), &fmt); + path->AddString(wText, static_cast(wcslen(wText)), &family , fontPlus.GetStyle(), fontPlus.GetSize(), Gdiplus::PointF(0.0f, 0.0f), &fmt); delete[] wText; return path; @@ -712,7 +711,7 @@ void CDrawingOptionsEx::ReleaseGdiPlusBrush() if (brushPlus) { delete brushPlus; - brushPlus = NULL; + brushPlus = nullptr; } } @@ -726,7 +725,7 @@ void CDrawingOptionsEx::ReleaseGdiPlusBitmap() // deleting only in case it's not in-memory bitmap delete bitmapPlus; } - bitmapPlus = NULL; + bitmapPlus = nullptr; } // *************************************************************** @@ -737,7 +736,7 @@ void CDrawingOptionsEx::ReleaseGdiPlusPen() if (penPlus) { delete penPlus; - penPlus = NULL; + penPlus = nullptr; } } @@ -751,7 +750,7 @@ void CDrawingOptionsEx::InitGdiVerticesPen(CDC* dc) { if (this->penOld || this->brushOld) { - this->ReleaseGdiBrushAndPen(dc); + this->ReleaseGdiBrushAndPen(dc); } if (this->verticesFillVisible) @@ -885,7 +884,7 @@ void CDrawingOptionsEx::DrawPointSymbol(Gdiplus::Graphics& g, CDC* dc, Gdiplus:: g.SetTransform(&mtx); delete[] pointsTemp; - pointsTemp = NULL; + pointsTemp = nullptr; } } } @@ -981,7 +980,7 @@ void CDrawingOptionsEx::DrawPointSymbol(Gdiplus::Graphics& g, CDC* dc, Gdiplus:: if (this->penPlus) this->penPlus->SetAlignment(Gdiplus::PenAlignmentCenter); - Gdiplus::GraphicsPath* path2 = NULL; + Gdiplus::GraphicsPath* path2 = nullptr; if (path && this->drawFrame) { path2 = this->GetFrameForPath(*path); @@ -1106,7 +1105,7 @@ bool CDrawingOptionsEx::CanUseLinePattern() Gdiplus::GraphicsPath* CDrawingOptionsEx::GetFrameForPath(Gdiplus::GraphicsPath& path) { - Gdiplus::GraphicsPath* path2 = NULL; + Gdiplus::GraphicsPath* path2 = nullptr; Gdiplus::RectF bounds; Gdiplus::Status status = path.GetBounds(&bounds); if (status == Gdiplus::Status::Ok) diff --git a/src/Drawing/LabelDrawing.cpp b/src/Drawing/LabelDrawing.cpp index 6c9ca90c..d3c40b1d 100644 --- a/src/Drawing/LabelDrawing.cpp +++ b/src/Drawing/LabelDrawing.cpp @@ -54,7 +54,7 @@ void CLabelDrawer::InitSettings(LabelSettings& settings, ILabels* labels, IShape settings.scaleFactor = GetScaleFactor(labels); - settings.autoOffset = sf != nullptr ? GetAutoOffset(labels, sf) : false; + settings.autoOffset = GetAutoOffset(labels, sf); settings.numLabels = LabelsHelper::GetCount(labels); @@ -254,15 +254,15 @@ void CLabelDrawer::DrawLabels(ILabels* labels) int* CLabelDrawer::PlaceLabels(ILabels* labels) { if (!CheckVisibility(labels)) - return NULL; + return nullptr; CLabels* lbs = static_cast(labels); vector*>* labelData = lbs->get_LabelData(); IShapefile* sf = lbs->get_ParentShapefile(); - std::vector* shapeData = NULL; + std::vector* shapeData = nullptr; if (sf) { - shapeData = ((CShapefile*)sf)->get_ShapeVector(); + shapeData = static_cast(sf)->get_ShapeVector(); } // --------------------------------- @@ -275,13 +275,13 @@ int* CLabelDrawer::PlaceLabels(ILabels* labels) GetVisibilityMask(labels, sf, shapeData, visibilityMask); // sort them if sort field is specified - vector* indices = NULL; + vector* indices = nullptr; if (sf) { ((CShapefile*)sf)->GetSorting(&indices); } if (indices && indices->size() != settings.numLabels) { - indices = NULL; + indices = nullptr; } // --------------------------------- @@ -323,7 +323,7 @@ int* CLabelDrawer::PlaceLabels(ILabels* labels) } vector* parts = (*labelData)[i]; - for (int j = 0; j < (int)parts->size(); j++) + for (int j = 0; j < static_cast(parts->size()); j++) { CLabelInfo* lbl = (*parts)[j]; @@ -341,8 +341,8 @@ int* CLabelDrawer::PlaceLabels(ILabels* labels) { if (uniqueValues.find(lbl->text) != uniqueValues.end()) continue; - else - uniqueValues.insert(lbl->text); + + uniqueValues.insert(lbl->text); } // measuring label @@ -383,11 +383,13 @@ int* CLabelDrawer::PlaceLabels(ILabels* labels) } } // label } + + return nullptr; } CRect CLabelDrawer::GetLabelExtents(ILabels* labels, long index) { - auto lbs = static_cast(labels); + auto lbs = dynamic_cast(labels); //CLabels* lbs = static_cast(labels); vector*>* labelData = lbs->get_LabelData(); @@ -467,7 +469,7 @@ CRect CLabelDrawer::GetLabelExtents(ILabels* labels, long index) // ********************************************************************* vector CLabelDrawer::PlaceAllMapLabels(ILabels* labels) { - std:vector indexes; + vector indexes; if (!CheckVisibility(labels)) return indexes; diff --git a/src/Drawing/ShapefileDrawing.cpp b/src/Drawing/ShapefileDrawing.cpp index 6aab64a5..a818e345 100644 --- a/src/Drawing/ShapefileDrawing.cpp +++ b/src/Drawing/ShapefileDrawing.cpp @@ -213,7 +213,7 @@ bool CShapefileDrawer::Draw(const CRect& rcBounds, IShapefile* sf) } else { - numShapes = selectResult->size(); + numShapes = static_cast(selectResult->size()); sort(selectResult->begin(), selectResult->end()); } } @@ -277,7 +277,7 @@ bool CShapefileDrawer::Draw(const CRect& rcBounds, IShapefile* sf) _shapeData = _shapefile->get_ShapeVector(); if (_shptype == SHP_POLYGON || _shptype == SHP_POLYLINE) { - int size = _shapeData->size(); + int size = static_cast(_shapeData->size()); for (int i = 0; i < size; i++) { (*_shapeData)[i]->size = 0; @@ -315,7 +315,7 @@ bool CShapefileDrawer::Draw(const CRect& rcBounds, IShapefile* sf) // Building lists of shape indices for each category // -------------------------------------------------------------- unsigned int k = 0; // position in arr of visible shapes - for (int i = 0; i < (int)numShapes; i++) + for (int i = 0; i < static_cast(numShapes); i++) { if (useQTree && _isEditing) { @@ -369,7 +369,7 @@ bool CShapefileDrawer::Draw(const CRect& rcBounds, IShapefile* sf) } } - if (offset >= (int)_shapeData->size()) + if (offset >= static_cast(_shapeData->size())) { // TODO: is is possible to check that the index has the same number of shapes as shapefile? if (!_isEditing && useSpatialIndex) { @@ -452,7 +452,7 @@ bool CShapefileDrawer::Draw(const CRect& rcBounds, IShapefile* sf) { if (selectionAppearance == saSelectionColor) { - for (int i = categorySelIndices.size() - 1; i >= 0; i--) + for (int i = static_cast(categorySelIndices.size()) - 1; i >= 0; i--) { if (i == numCategories) { @@ -476,7 +476,7 @@ bool CShapefileDrawer::Draw(const CRect& rcBounds, IShapefile* sf) } // drawing unselected shapes - for (int i = categoryIndices.size() - 2; i >= 0; i--) + for (int i = static_cast(categoryIndices.size()) - 2; i >= 0; i--) { if (i == numCategories) { @@ -500,7 +500,7 @@ bool CShapefileDrawer::Draw(const CRect& rcBounds, IShapefile* sf) { if (selectionAppearance == saSelectionColor) { - for (int i = categorySelIndices.size() - 1; i >= 0; i--) + for (int i = static_cast(categorySelIndices.size()) - 1; i >= 0; i--) { if (i == numCategories) { @@ -759,7 +759,7 @@ void CShapefileDrawer::DrawPointCategory(CDrawingOptionsEx* options, std::vector else if (pntShape == pshPixel && options->drawingMode == vdmGDIPlus) { bmPixel = new Bitmap(1, 1, _graphics); - long alpha = ((long)options->fillTransparency) << 24; + long alpha = static_cast(options->fillTransparency) << 24; bmPixel->SetPixel(0, 0, Color(alpha | BGR_TO_RGB(pixelColor))); } } @@ -823,7 +823,7 @@ void CShapefileDrawer::DrawPointCategory(CDrawingOptionsEx* options, std::vector size_t numShapes = hasSorting ? visibilityMask.size() : indices->size(); - for (int j = 0; j < (int)numShapes; j++) + for (int j = 0; j < static_cast(numShapes); j++) { if (hasSorting) { @@ -987,7 +987,7 @@ void CShapefileDrawer::DrawPointCategory(CDrawingOptionsEx* options, std::vector // if not set explicitly, try to grab it from category if (angle == 0) - angle = (float)options->rotation; + angle = static_cast(options->rotation); // if any angle is specified, apply it if (angle != 0) _graphics->RotateTransform(angle); @@ -1023,7 +1023,7 @@ void CShapefileDrawer::DrawPointCategory(CDrawingOptionsEx* options, std::vector if (drawSelection) { - SolidBrush brush(Utility::OleColor2GdiPlus(m_selectionColor, (BYTE)m_selectionTransparency)); + SolidBrush brush(Utility::OleColor2GdiPlus(m_selectionColor, static_cast(m_selectionTransparency))); _graphics->FillRectangle(&brush, rect); } @@ -1043,10 +1043,10 @@ void CShapefileDrawer::DrawPointCategory(CDrawingOptionsEx* options, std::vector _graphics->TranslateTransform(Gdiplus::REAL(xInt), Gdiplus::REAL(yInt)); // does point have an individual rotation? - float angle = (float)((*_shapeData)[points[i].id])->rotation; + float angle = (*_shapeData)[points[i].id]->rotation; // if nothing specified, revert to options-level angle if (angle == 0) - angle = (float)options->rotation; + angle = static_cast(options->rotation); // if angle is non-zero, apply it if (angle != 0) _graphics->RotateTransform(angle); @@ -1120,7 +1120,7 @@ void CShapefileDrawer::DrawPointCategory(CDrawingOptionsEx* options, std::vector _graphics->SetTransform(&mtxInit); } - (*_shapeData)[shapeIndex]->size = (int)options->pointSize; + (*_shapeData)[shapeIndex]->size = static_cast(options->pointSize); } } } @@ -1202,7 +1202,7 @@ void CShapefileDrawer::DrawPolyCategory(CDrawingOptionsEx* options, std::vector< // ----------------------------------------------------- if (perShapeDrawing) { - for (int j = 0; j < (int)indices->size(); j++) + for (int j = 0; j < static_cast(indices->size()); j++) { GraphicsPath pathFill(Gdiplus::FillModeWinding); @@ -1260,7 +1260,7 @@ void CShapefileDrawer::DrawPolyCategory(CDrawingOptionsEx* options, std::vector< } // constructing a path - for (int j = 0; j < (int)indices->size(); j++) + for (int j = 0; j < static_cast(indices->size()); j++) { this->DrawPolygonGDIPlus((*indices)[j], *path, delta, pointColor, drawingMode, xMin, xMax, yMin, yMax); } @@ -1273,10 +1273,10 @@ void CShapefileDrawer::DrawPolyCategory(CDrawingOptionsEx* options, std::vector< // drawing fill (calculating measures of gradient: whole layer) if (options->fillVisible && _shptype == SHP_POLYGON) { - int xmin = int((_xMin - _extents->left) * _dx); - int ymin = int((_extents->top - _yMin) * _dy); - int xmax = int((_xMax - _extents->left) * _dx); - int ymax = int((_extents->top - _yMax) * _dy); + int xmin = static_cast((_xMin - _extents->left) * _dx); + int ymin = static_cast((_extents->top - _yMin) * _dy); + int xmax = static_cast((_xMax - _extents->left) * _dx); + int ymax = static_cast((_extents->top - _yMax) * _dy); RectF rect((Gdiplus::REAL)xmin, (Gdiplus::REAL)ymin, (Gdiplus::REAL)xmax - xmin, (Gdiplus::REAL)ymax - ymin); options->FillGraphicsPath(_graphics, path, rect); @@ -1312,12 +1312,12 @@ void CShapefileDrawer::DrawPolyCategory(CDrawingOptionsEx* options, std::vector< { if (_shptype == SHP_POLYGON) { - SolidBrush brush(Utility::OleColor2GdiPlus(m_selectionColor, (BYTE)m_selectionTransparency)); + SolidBrush brush(Utility::OleColor2GdiPlus(m_selectionColor, static_cast(m_selectionTransparency))); _graphics->FillPath(&brush, path); } else { - Pen pen(Utility::OleColor2GdiPlus(m_selectionColor, (BYTE)m_selectionTransparency)); + Pen pen(Utility::OleColor2GdiPlus(m_selectionColor, static_cast(m_selectionTransparency))); pen.SetLineJoin(Gdiplus::LineJoinRound); _graphics->DrawPath(&pen, path); } @@ -1488,7 +1488,7 @@ void CShapefileDrawer::DrawLineCategoryGDI(CDrawingOptionsEx* options, std::vect OLE_COLOR pointColor = options->linesVisible ? options->lineColor : options->fillColor; _bmpPixel->SetPixel(0, 0, Utility::OleColor2GdiPlus(pointColor)); - for (int j = 0; j < (int)indices->size(); j++) + for (int j = 0; j < static_cast(indices->size()); j++) { int shapeIndex = (*indices)[j]; if (!_isEditing) @@ -1614,8 +1614,8 @@ void CShapefileDrawer::DrawVertices(Gdiplus::GraphicsPath* path, CDrawingOptions for (int i = 0; i < count; i++) { - int x = (int)-points[i].X; - int y = (int)-points[i].Y; + int x = static_cast(-points[i].X); + int y = static_cast(-points[i].Y); _dc->SetWindowOrg(x, y); @@ -1663,7 +1663,7 @@ void CShapefileDrawer::DrawLinePatternCategory(CDrawingOptionsEx* options, std:: _bmpPixel->SetPixel(0, 0, Utility::OleColor2GdiPlus(pointColor)); // constructing a path - for (int j = 0; j < (int)indices->size(); j++) + for (int j = 0; j < static_cast(indices->size()); j++) { this->DrawPolygonGDIPlus((*indices)[j], *path, delta, pointColor, vdmGDIPlus, xMin, xMax, yMin, yMax); } @@ -1696,7 +1696,7 @@ void CShapefileDrawer::DrawLinePatternCategory(CDrawingOptionsEx* options, std:: if (maxWidth > 0.0f) { - Gdiplus::Pen penSelection(Utility::OleColor2GdiPlus(m_selectionColor, (BYTE)m_selectionTransparency), maxWidth); + Gdiplus::Pen penSelection(Utility::OleColor2GdiPlus(m_selectionColor, static_cast(m_selectionTransparency)), maxWidth); penSelection.SetLineJoin(Gdiplus::LineJoinRound); _graphics->DrawPath(&penSelection, path); } @@ -1875,8 +1875,8 @@ void CShapefileDrawer::DrawPolylinePath(Gdiplus::GraphicsPath* path, CDrawingOpt totalLength = totalLengths[n] - (overflow ? 0 : markerSize); // Apply scale factor for offset & interval values if requested: - markerOffset = markerOffsetBase * ((offsetIsRelative) ? (float)totalLength : 1.0f); - interval = intervalBase * ((intervalIsRelative) ? (float)totalLength : 1.0f); + markerOffset = markerOffsetBase * ((offsetIsRelative) ? static_cast(totalLength) : 1.0f); + interval = intervalBase * ((intervalIsRelative) ? static_cast(totalLength) : 1.0f); firstMarkerDrawn = false; // Set starting offset: offset = markerOffset + (overflow ? 0 : markerSize * 0.5); @@ -2326,8 +2326,8 @@ void CShapefileDrawer::DrawPolyGDI(IShapeData* shp, CDrawingOptionsEx* options, // Draws point in place of small polygons inline void CShapefileDrawer::DrawPolygonPoint(double& xMin, double& xMax, double& yMin, double& yMax, OLE_COLOR& pointColor) { - int x = (int)(((xMax + xMin) / 2 - _extents->left) * _dx); - int y = (int)((_extents->top - (yMax + yMin) / 2) * _dy); + int x = static_cast(((xMax + xMin) / 2 - _extents->left) * _dx); + int y = static_cast((_extents->top - (yMax + yMin) / 2) * _dy); if (!_dc) { diff --git a/src/Drawing/TilesDrawer.cpp b/src/Drawing/TilesDrawer.cpp index 1d9c072c..f3ba31ca 100644 --- a/src/Drawing/TilesDrawer.cpp +++ b/src/Drawing/TilesDrawer.cpp @@ -71,7 +71,7 @@ void TilesDrawer::DrawTiles( TileManager* manager, IGeoProjection* mapProjection InitImageAttributes(manager, attr); bool isSame = IsSameProjection(mapProjection, provider); - + // copy to temporary vector, for not lock the original one for the whole length of drawing std::vector tiles; manager->CopyBuffer(tiles); @@ -120,7 +120,7 @@ void TilesDrawer::DrawTiles( TileManager* manager, IGeoProjection* mapProjection DrawGrid(tile, screenBounds); } - tile->isDrawn(true); + tile->isDrawn(true); } } @@ -179,7 +179,7 @@ void TilesDrawer::DrawOverlays(TileCore* tile, RectF screenBounds, ImageAttribut #endif for (size_t i = 0; i < tile->Overlays.size(); i++) { - Bitmap* bmp = tile->get_Bitmap(i)->m_bitmap; + Bitmap* bmp = tile->get_Bitmap(static_cast(i))->m_bitmap; if (bmp) { // to debug the issue with occasional seams @@ -330,7 +330,7 @@ bool TilesDrawer::IsSameProjection(IGeoProjection* mapProjection, BaseProvider* // check perhaps map projection is the same as the one for tiles // then we don't have to use conversion to WGS84 decimal degrees VARIANT_BOOL isSame = VARIANT_FALSE; - CustomProjection* customProj = NULL; + CustomProjection* customProj = nullptr; if (mapProjection) { @@ -442,7 +442,7 @@ void TilesDrawer::DrawGridText(TileCore* tile, RectF& screenRect) format.SetAlignment(StringAlignmentCenter); format.SetLineAlignment(StringAlignmentCenter); - _graphics->DrawString(wStr, wcslen(wStr), font, screenRect, &format, &brush); + _graphics->DrawString(wStr, static_cast(wcslen(wStr)), font, screenRect, &format, &brush); delete font; delete wStr; diff --git a/src/Editor/ActiveShape.cpp b/src/Editor/ActiveShape.cpp index 06edd382..a8b56315 100644 --- a/src/Editor/ActiveShape.cpp +++ b/src/Editor/ActiveShape.cpp @@ -308,7 +308,7 @@ void ActiveShape::DrawLines(Gdiplus::Graphics* g, const int size, const Gdiplus: bounds.Y = static_cast(data[i].Y + dy - bounds.Height / 2); } - CRect r((bounds.GetLeft()), (bounds.GetTop()), (bounds.GetRight()), (bounds.GetBottom())); + CRect r(static_cast(bounds.GetLeft()), static_cast(bounds.GetTop()), static_cast(bounds.GetRight()), static_cast(bounds.GetBottom())); if (!collisionList.HaveCollision(r)) { g->FillRectangle(&_whiteBrush, bounds); g->DrawString(s, s.GetLength(), _font, bounds, &_format, &_textBrush); diff --git a/src/Editor/EditorBase.cpp b/src/Editor/EditorBase.cpp index 3ca81b45..8e9953cd 100644 --- a/src/Editor/EditorBase.cpp +++ b/src/Editor/EditorBase.cpp @@ -14,11 +14,11 @@ int EditorBase::GetClosestVertex(double projX, double projY, double tolerance) if (dist < min) { min = dist; - pointIndex = i; + pointIndex = static_cast(i); } } if (pointIndex == 0 && HasClosedPolygon()) { - pointIndex = _points.size() - 1; + pointIndex = static_cast(_points.size()) - 1; } return min < tolerance ? pointIndex : -1; @@ -114,7 +114,7 @@ bool EditorBase::ClearHighlightedPart() // ************************************************ bool EditorBase::SetSelectedVertex(int index) { - if (index < 0 || index >= (int)_points.size()) + if (index < 0 || index >= static_cast(_points.size())) return false; _selectedPart = -1; @@ -136,7 +136,7 @@ bool EditorBase::SetSelectedVertex(int index) // ************************************************ bool EditorBase::SetHighlightedVertex(int index) { - if (index < 0 || index >= (int)_points.size()) + if (index < 0 || index >= static_cast(_points.size())) return false; if (index != _highlightedVertex) @@ -192,9 +192,9 @@ bool EditorBase::PartIsWithin(int outerRing, int innerRing) { if (GetShapeType2D() == SHP_POLYGON) { - CComPtr shp = NULL; + CComPtr shp = nullptr; shp.Attach(GetPartAsShape(outerRing)); - if (shp != NULL) + if (shp != nullptr) { int startIndex, endIndex; if (GetPart(innerRing, startIndex, endIndex)) @@ -202,7 +202,7 @@ bool EditorBase::PartIsWithin(int outerRing, int innerRing) VARIANT_BOOL vb; for (int i = startIndex; i <= endIndex; i++) { - CComPtr pnt = NULL; + CComPtr pnt = nullptr; ComHelper::CreatePoint(&pnt); pnt->put_X(_points[i]->Proj.x); pnt->put_Y(_points[i]->Proj.y); @@ -224,7 +224,7 @@ IShape* EditorBase::GetPartAsShape(int partIndex) int startIndex, endIndex; if (GetPart(partIndex, startIndex, endIndex)) { - IShape* shp = NULL; + IShape* shp = nullptr; ComHelper::CreateShape(&shp); VARIANT_BOOL vb; shp->Create(GetShapeType2D(), &vb); @@ -237,7 +237,7 @@ IShape* EditorBase::GetPartAsShape(int partIndex) } return shp; } - return NULL; + return nullptr; } // ************************************************ @@ -247,7 +247,7 @@ bool EditorBase::GetPart(int partIndex, int& startIndex, int& endIndex) { startIndex = GetPartStart(partIndex); endIndex = SeekPartEnd(startIndex); - if (startIndex >= (int)_points.size() && endIndex >= (int)_points.size()) return false; + if (startIndex >= static_cast(_points.size()) && endIndex >= static_cast(_points.size())) return false; return startIndex != -1 && endIndex != -1; } @@ -269,7 +269,7 @@ bool EditorBase::SetHighlightedPart(int part) // ******************************************************* bool EditorBase::RemoveVertex(int vertexIndex) { - if (vertexIndex < 0 && vertexIndex >= (int)_points.size()) + if (vertexIndex < 0 && vertexIndex >= static_cast(_points.size())) return false; PointPart part = _points[vertexIndex]->Part; @@ -343,7 +343,7 @@ void EditorBase::Move(double offsetXProj, double offsetYProj) { _points[i]->Proj.x += offsetXProj; _points[i]->Proj.y += offsetYProj; - UpdateLatLng(i); + UpdateLatLng(static_cast(i)); } SetModified(); } @@ -383,14 +383,14 @@ void EditorBase::MoveVertex(double xProj, double yProj) int index = _selectedVertex; int closeIndex = GetCloseIndex(index); - if (index >= 0 && index < (int)_points.size()) + if (index >= 0 && index < static_cast(_points.size())) { _points[index]->Proj.x = xProj; _points[index]->Proj.y = yProj; UpdateLatLng(index); // coordinates of the first and last point of polygon must be the same - if (closeIndex >= 0 && closeIndex < (int)_points.size()) { + if (closeIndex >= 0 && closeIndex < static_cast(_points.size())) { _points[closeIndex]->Proj.x = _points[index]->Proj.x; _points[closeIndex]->Proj.y = _points[index]->Proj.y; UpdateLatLng(closeIndex); diff --git a/src/Editor/GeoShape.cpp b/src/Editor/GeoShape.cpp index 3ae2e737..ccdd6be0 100644 --- a/src/Editor/GeoShape.cpp +++ b/src/Editor/GeoShape.cpp @@ -34,7 +34,7 @@ double GeoShape::GetGeodesicArea(bool closingPoint, double x, double y) poly.Clear(); - for (int i = GetFirstPolyPointIndex(); i < (int)_points.size(); i++) + for (int i = GetFirstPolyPointIndex(); i < static_cast(_points.size()); i++) { poly.AddPoint(_points[i]->y, _points[i]->x); } @@ -68,14 +68,14 @@ double GeoShape::GetGeodesicArea(bool closingPoint, double x, double y) // **************************************************************** IPoint* GeoShape::GetPolygonCenter(Gdiplus::PointF* data, int length) { - IPoint* pnt = NULL; + IPoint* pnt = nullptr; if (HasPolygon() && length > 2) { // let's draw fill and area Gdiplus::PointF* polyData = &data[0]; // find position for label - CComPtr shp = NULL; + CComPtr shp = nullptr; ComHelper::CreateShape(&shp); if (shp) { @@ -92,7 +92,7 @@ IPoint* GeoShape::GetPolygonCenter(Gdiplus::PointF* data, int length) shp->get_Centroid(&pnt); // make sure that centroid lies within extents of shapes; otherwise place it at the center - CComPtr ext = NULL; + CComPtr ext = nullptr; shp->get_Extents(&ext); double x, y; @@ -115,7 +115,7 @@ IPoint* GeoShape::GetPolygonCenter(Gdiplus::PointF* data, int length) // *************************************************************** IGeoProjection* GeoShape::GetWgs84Projection() { - return _mapCallback ? _mapCallback->_GetWgs84Projection() : NULL; + return _mapCallback ? _mapCallback->_GetWgs84Projection() : nullptr; } // *************************************************************** @@ -123,7 +123,7 @@ IGeoProjection* GeoShape::GetWgs84Projection() // *************************************************************** IGeoProjection* GeoShape::GetMapProjection() { - return _mapCallback ? _mapCallback->_GetMapProjection() : NULL; + return _mapCallback ? _mapCallback->_GetMapProjection() : nullptr; } // *************************************************************** // GetTransformationMode() @@ -164,7 +164,7 @@ void GeoShape::PixelToProj(double pixelX, double pixelY, double& projX, double& // ******************************************************* void GeoShape::UpdateLatLng(int pointIndex) { - if (pointIndex < 0 || pointIndex >= (int)_points.size()) return; + if (pointIndex < 0 || pointIndex >= static_cast(_points.size())) return; MeasurePoint* pnt = _points[pointIndex]; double x = pnt->Proj.x, y = pnt->Proj.y; @@ -286,7 +286,7 @@ int GeoShape::GetPartStart(int partIndex) { if (_points[i]->Part == PartBegin) count++; if (count == partIndex) - return i; + return static_cast(i); } return 0; } @@ -295,11 +295,11 @@ int GeoShape::GetPartStart(int partIndex) { // GetPartStart() // ******************************************************* int GeoShape::SeekPartEnd(int startSearchFrom) { - for (int i = startSearchFrom; i < (int)_points.size(); i++) { + for (int i = startSearchFrom; i < static_cast(_points.size()); i++) { if (_points[i]->Part == PartEnd) return i; } - return _points.size() - 1; + return static_cast(_points.size()) - 1; } // ******************************************************* @@ -403,7 +403,7 @@ double GeoShape::GetGeodesicDistance() // *************************************************************** double GeoShape::GetSegmentAngle(int segmentIndex, long& errorCode) { - if (segmentIndex < 0 || segmentIndex >= (long)_points.size() - 1) + if (segmentIndex < 0 || segmentIndex >= static_cast(_points.size()) - 1) { errorCode = tkINDEX_OUT_OF_BOUNDS; return 0.0; @@ -427,7 +427,7 @@ double GeoShape::GetSegmentAngle(int segmentIndex, long& errorCode) // ************************************************************** double GeoShape::GetSegmentLength(int segmentIndex, long& errorCode) { - if (segmentIndex < 0 || segmentIndex >= (long)_points.size() - 1) + if (segmentIndex < 0 || segmentIndex >= static_cast(_points.size()) - 1) { errorCode = tkINDEX_OUT_OF_BOUNDS; return 0.0; @@ -530,7 +530,7 @@ int GeoShape::FindSegmentWithPoint(double xProj, double yProj) { if (GeometryHelper::PointOnSegment(_points[i]->Proj.x, _points[i]->Proj.y, _points[i + 1]->Proj.x, _points[i + 1]->Proj.y, xProj, yProj)) - return i; + return static_cast(i); } return -1; } @@ -540,7 +540,7 @@ int GeoShape::FindSegmentWithPoint(double xProj, double yProj) // ******************************************************* int GeoShape::GetPolyPointCount(bool dynamicPoly) { - int size = _points.size() - GetFirstPolyPointIndex(); + int size = static_cast(_points.size()) - GetFirstPolyPointIndex(); if (dynamicPoly) size++; return size; } \ No newline at end of file diff --git a/src/Editor/MeasuringBase.cpp b/src/Editor/MeasuringBase.cpp index ea57229c..8dfcd683 100644 --- a/src/Editor/MeasuringBase.cpp +++ b/src/Editor/MeasuringBase.cpp @@ -7,7 +7,7 @@ bool MeasuringBase::GetPartStartAndEnd(int partIndex, MixedShapePart whichPoints, int& startIndex, int& endIndex) { startIndex = 0; - endIndex = _points.size(); // actually the next after end one + endIndex = static_cast(_points.size()); // actually the next after end one switch (whichPoints) { @@ -15,12 +15,12 @@ bool MeasuringBase::GetPartStartAndEnd(int partIndex, MixedShapePart whichPoints { if (_firstPolyPointIndex == -1) return false; - if (_firstPolyPointIndex >(int)_points.size() - 1) + if (_firstPolyPointIndex >static_cast(_points.size()) - 1) { return false; } startIndex = _firstPolyPointIndex; - endIndex = (int)_points.size(); + endIndex = static_cast(_points.size()); return true; } } @@ -109,7 +109,7 @@ bool MeasuringBase::SnapToPreviousVertex(int& vertexIndex, double screenX, doubl double xTemp, yTemp; vertexIndex = -1; - int size = _points.size() - 2; + int size = static_cast(_points.size()) - 2; for (int i = 0; i < size; i++) { ProjToPixel(_points[i]->Proj.x, _points[i]->Proj.y, xTemp, yTemp); diff --git a/src/Editor/UndoListHelper.cpp b/src/Editor/UndoListHelper.cpp index efb249b0..ced7dd81 100644 --- a/src/Editor/UndoListHelper.cpp +++ b/src/Editor/UndoListHelper.cpp @@ -24,7 +24,7 @@ void UndoListHelper::AddShapes(IShapefile* sf, vector shapes, long laye void UndoListHelper::DeleteShapes(IShapefile* sf, vector& deleteList, long layerHandle, IUndoList* undoList) { VARIANT_BOOL vb; - for (int i = deleteList.size() - 1; i >= 0; i--) + for (int i = static_cast(deleteList.size()) - 1; i >= 0; i--) { undoList->Add(uoRemoveShape, layerHandle, deleteList[i], &vb); if (vb) { diff --git a/src/Grid/GridManager.cpp b/src/Grid/GridManager.cpp index dbd30fcd..dae541ed 100644 --- a/src/Grid/GridManager.cpp +++ b/src/Grid/GridManager.cpp @@ -15,7 +15,7 @@ GridManager::~GridManager() } DATA_TYPE GridManager::getGridDataType( const char * cfilename, GRID_TYPE GridType ) -{ +{ CString filename = cfilename; GRID_TYPE grid_type = GridType; @@ -58,7 +58,7 @@ DATA_TYPE GridManager::getGridDataType( const char * cfilename, GRID_TYPE GridTy else { type = UNKNOWN_TYPE; - } + } } XTIFFClose(tiff); @@ -67,7 +67,7 @@ DATA_TYPE GridManager::getGridDataType( const char * cfilename, GRID_TYPE GridTy else if( grid_type == ASCII_GRID ) return DOUBLE_TYPE; else if( grid_type == BINARY_GRID ) - { + { FILE * in = fopen( filename, "rb" ); if( !in ) return INVALID_DATA_TYPE; @@ -94,7 +94,7 @@ DATA_TYPE GridManager::getGridDataType( const char * cfilename, GRID_TYPE GridTy return DOUBLE_TYPE; else if( grid_type == ESRI_GRID ) { if( filename.GetLength() <= 0 ) - return INVALID_DATA_TYPE; + return INVALID_DATA_TYPE; else { DATA_TYPE data_type = esri_data_type(filename); return data_type; @@ -105,7 +105,7 @@ DATA_TYPE GridManager::getGridDataType( const char * cfilename, GRID_TYPE GridTy } GRID_TYPE GridManager::getGridType( const char * cfilename ) -{ +{ CString filename = cfilename; GRID_TYPE grid_type = INVALID_GRID_TYPE; @@ -114,7 +114,7 @@ GRID_TYPE GridManager::getGridType( const char * cfilename ) { char * clean_filename = new char[ filename.GetLength() + 1]; strcpy( clean_filename, filename ); - for( int i = _tcslen( clean_filename ) - 1; i >= 0; i-- ) + for( size_t i = _tcslen( clean_filename ) - 1; i >= 0; i-- ) { if( clean_filename[i] == '\\' || clean_filename[i] == '/' ) clean_filename[i] = '\0'; else @@ -146,7 +146,7 @@ GRID_TYPE GridManager::getGridType( const char * cfilename ) cff.Close(); //File does not exist so parse it out - int length = _tcslen(filename ); + int length = static_cast(_tcslen(filename )); bool foundPeriod = false; for( int e = length-1; e >= 0; e-- ) { if( filename[e] == '\\' || filename[e] == '/' ) @@ -158,9 +158,9 @@ GRID_TYPE GridManager::getGridType( const char * cfilename ) } } - if ( foundPeriod == false ) + if ( foundPeriod == false ) return ESRI_GRID; - + if( length > 4 ) { char ext[4]; @@ -168,7 +168,7 @@ GRID_TYPE GridManager::getGridType( const char * cfilename ) ext[1] = filename[length - 2]; ext[2] = filename[length - 1]; ext[3] = '\0'; - + if( islower( ext[0] ) ) ext[0] = toupper( ext[0] ); if( islower( ext[1] ) ) @@ -205,11 +205,11 @@ bool GridManager::deleteGrid( const char * cfilename, GRID_TYPE GridType ) if( type == GEOTIFF_GRID)//added 8/15/05 -- ah, might need to change to delete _unlink(filename); else if( type == ASCII_GRID ) - _unlink( filename ); + _unlink( filename ); else if( type == BINARY_GRID ) - _unlink( filename ); + _unlink( filename ); else if( type == ESRI_GRID ) - delete_esri_grid( filename ); + delete_esri_grid( filename ); else if( type == SDTS_GRID ) { CString prefix = filename.Left( 4 ); @@ -254,7 +254,7 @@ bool GridManager::NeedProxyForGrid(CStringW filename, tkGridProxyMode proxyMode, if(GdalHelper::HasOverviews(filename)) return false; - bool tempGridNeeded = grid == NULL; + bool tempGridNeeded = grid == nullptr; // then if there is a proxy bool hasProxy = GridManager::HasValidProxy(filename); @@ -269,7 +269,7 @@ bool GridManager::NeedProxyForGrid(CStringW filename, tkGridProxyMode proxyMode, } bool canBuildOverviews = m_globalSettings.rasterOverviewCreation != rocNo; - if (!GdalHelper::SupportsOverviews(filename, NULL)) + if (!GdalHelper::SupportsOverviews(filename, nullptr)) canBuildOverviews = false; return !canBuildOverviews; } diff --git a/src/Grid/dGrid.cpp b/src/Grid/dGrid.cpp index 9f1f7f55..0a52799c 100644 --- a/src/Grid/dGrid.cpp +++ b/src/Grid/dGrid.cpp @@ -20,7 +20,8 @@ extern ESRI_GRIDDELETE_PROC griddelete; extern ESRI_CELLLAYERCREATE_PROC celllayercreate; dGrid::dGrid() -{ data = NULL; +{ + data = nullptr; isInRam = true; findNewMax = false; findNewMin = false; @@ -33,16 +34,16 @@ dGrid::dGrid() current_row = -1; //BINARY - row_one = NULL; - row_two = NULL; - row_three = NULL; - file_in_out = NULL; + row_one = nullptr; + row_two = nullptr; + row_three = nullptr; + file_in_out = nullptr; //ESRI - grid_layer = -1; - row_buf1 = NULL; - row_buf2 = NULL; - row_buf3 = NULL; + grid_layer = -1; + row_buf1 = nullptr; + row_buf2 = nullptr; + row_buf3 = nullptr; leadid = 0; initialize_esri(); @@ -66,13 +67,13 @@ long dGrid::LastErrorCode() //OPERATORS double dGrid::operator()( int Column, int Row ) -{ +{ if( inGrid( Column, Row ) ) { if( isInRam ) - return data[Row][Column]; + return data[Row][Column]; else - return getValueDisk( Column, Row ); + return getValueDisk( Column, Row ); } else return gridHeader.getNodataValue(); @@ -83,7 +84,7 @@ bool dGrid::open( const char * cfilename, bool InRam, GRID_TYPE GridType, void ( { CString filename = cfilename; - if( data != NULL || file_in_out != NULL ) + if( data != nullptr || file_in_out != nullptr) close(); isInRam = InRam; @@ -98,9 +99,8 @@ bool dGrid::open( const char * cfilename, bool InRam, GRID_TYPE GridType, void ( gridType = GridType; if( gridType == USE_EXTENSION ) gridType = getGridType( filename ); - if( isInRam == true ) - return readDiskToMemory( callback ); + return readDiskToMemory( callback ); else { //1. Read the header information //2. Find the min and max @@ -110,7 +110,7 @@ bool dGrid::open( const char * cfilename, bool InRam, GRID_TYPE GridType, void ( } bool dGrid::readDiskToMemory( void (*callback)(int number, const char * message ) ) -{ +{ if( gridType == ASCII_GRID ) return asciiReadDiskToMemory( callback ); else if( gridType == BINARY_GRID ) @@ -137,14 +137,14 @@ bool dGrid::readDiskToDisk( void (*callback)(int number, const char * message ) */ lastErrorCode = tkINVALID_GRID_FILE_TYPE; return false; -} +} bool dGrid::writeMemoryToDisk( void(*callback)(int number, const char * message ) ) { if( gridType == ASCII_GRID ) return asciiWriteMemoryToDisk( callback ); else if( gridType == BINARY_GRID ) - return binaryWriteMemoryToDisk( callback ); + return binaryWriteMemoryToDisk( callback ); else if( gridType == ESRI_GRID ) return esriWriteMemoryToDisk( callback ); /* @@ -152,15 +152,15 @@ bool dGrid::writeMemoryToDisk( void(*callback)(int number, const char * message return sdtsWriteMemoryToDisk( callback ); */ lastErrorCode = tkINVALID_GRID_FILE_TYPE; - return false; + return false; } bool dGrid::writeDiskToDisk() -{ +{ if( gridType == ASCII_GRID ) return asciiWriteDiskToDisk(); else if( gridType == BINARY_GRID ) - return binaryWriteDiskToDisk(); + return binaryWriteDiskToDisk(); else if( gridType == ESRI_GRID ) return esriWriteDiskToDisk(); /* @@ -176,7 +176,7 @@ bool dGrid::initialize( const char * cfilename, dHeader header, double initialVa CString filename = cfilename; close(); - isInRam = InRam; + isInRam = InRam; gridFilename = filename; gridHeader = header; @@ -193,11 +193,11 @@ bool dGrid::initialize( const char * cfilename, dHeader header, double initialVa isInRam = true; // Force inram true for ascii grids; no support for disk-based ascii grids. if( isInRam == true ) - { - if (data != NULL) + { + if (data != nullptr) { delete [] data; - data = NULL; + data = nullptr; } data = new double*[ gridHeader.getNumberRows() ]; for( int y = 0; y < gridHeader.getNumberRows(); y++ ) @@ -213,7 +213,7 @@ bool dGrid::initialize( const char * cfilename, dHeader header, double initialVa return true; } else - { + { if( gridType == BINARY_GRID ) return binaryInitializeDisk( initialValue ); else if( gridType == ESRI_GRID ) @@ -234,13 +234,13 @@ bool dGrid::initialize( const char * cfilename, dHeader header, double initialVa #pragma optimize("", off) bool dGrid::close() -{ +{ if( isInRam == true ) { dealloc(); return true; } else - { + { // bool result = writeDiskToDisk(); // Chris Michaelis July 02 2003 - every time this is called, @@ -253,37 +253,37 @@ bool dGrid::close() // This change is made in sGrid, dGrid, fGrid, and lGrid. bool result = true; - if( file_in_out != NULL ) + if( file_in_out != nullptr) { fclose( file_in_out ); - file_in_out = NULL; + file_in_out = nullptr; } - if( row_one != NULL ) + if( row_one != nullptr) { delete [] row_one; - row_one = NULL; + row_one = nullptr; } - if( row_two != NULL ) + if( row_two != nullptr) { delete [] row_two; - row_two = NULL; + row_two = nullptr; } - if( row_three != NULL ) + if( row_three != nullptr) { delete [] row_three; - row_three = NULL; + row_three = nullptr; } - if( row_buf1 != NULL ) - { CFree1((char *)row_buf1); - row_buf1 = NULL; + if( row_buf1 != nullptr) + { CFree1(static_cast(row_buf1)); + row_buf1 = nullptr; } - if( row_buf2 != NULL ) - { CFree1((char *)row_buf2); - row_buf2 = NULL; + if( row_buf2 != nullptr) + { CFree1(static_cast(row_buf2)); + row_buf2 = nullptr; } - if( row_buf3 != NULL ) - { CFree1((char *)row_buf3); - row_buf3 = NULL; + if( row_buf3 != nullptr) + { CFree1(static_cast(row_buf3)); + row_buf3 = nullptr; } if( grid_layer >= 0 ) { - if( celllyrclose != NULL ) + if( celllyrclose != nullptr) celllyrclose(grid_layer); grid_layer = -1; } @@ -293,7 +293,7 @@ bool dGrid::close() #pragma optimize("", on) bool dGrid::save( const char * cfilename, GRID_TYPE GridType, void (*callback)(int number, const char * message ) ) -{ +{ CString filename = cfilename; if( isInRam == true ) @@ -303,7 +303,7 @@ bool dGrid::save( const char * cfilename, GRID_TYPE GridType, void (*callback)(i if( GridType == USE_EXTENSION ) GridType = getGridType( gridFilename ); - + // Save was successful. Update my grid type to be the new grid type. gridType = GridType; @@ -321,9 +321,9 @@ bool dGrid::save( const char * cfilename, GRID_TYPE GridType, void (*callback)(i } } else - { + { if( filename.GetLength() <= 0 ) - return writeDiskToDisk(); + return writeDiskToDisk(); //Convert the Grid else { if( GridType == USE_EXTENSION ) @@ -336,11 +336,11 @@ bool dGrid::save( const char * cfilename, GRID_TYPE GridType, void (*callback)(i gridFilename += "\\"; } - + if( GridType == ASCII_GRID ) { if ( asciiSaveAs( filename, callback ) ) - { + { // Save was successful. Update my grid type to be the new grid type. gridType = GridType; return true; @@ -349,7 +349,7 @@ bool dGrid::save( const char * cfilename, GRID_TYPE GridType, void (*callback)(i else if( GridType == BINARY_GRID ) { if ( binarySaveAs( filename, callback ) ) - { + { // Save was successful. Update my grid type to be the new grid type. gridType = GridType; return true; @@ -358,7 +358,7 @@ bool dGrid::save( const char * cfilename, GRID_TYPE GridType, void (*callback)(i else if( GridType == ESRI_GRID ) { if ( esriSaveAs( filename, callback ) ) - { + { // Save was successful. Update my grid type to be the new grid type. gridType = GridType; return true; @@ -375,9 +375,9 @@ inline double dGrid::getValue( int Column, int Row ) if( inGrid( Column ,Row ) ) { if( isInRam ) - return data[Row][Column]; + return data[Row][Column]; else - return getValueDisk( Column, Row ); + return getValueDisk( Column, Row ); } else { lastErrorCode = tkINDEX_OUT_OF_BOUNDS; @@ -399,7 +399,7 @@ inline double dGrid::getValueDisk( int Column, int Row ) } void dGrid::setValue( int Column, int Row, double Value ) -{ +{ if( inGrid( Column, Row ) ) { if( max == gridHeader.getNodataValue() ) @@ -419,7 +419,7 @@ void dGrid::setValue( int Column, int Row, double Value ) if( isInRam ) data[Row][Column] = Value; else - setValueDisk( Column, Row, Value ); + setValueDisk( Column, Row, Value ); } else lastErrorCode = tkINDEX_OUT_OF_BOUNDS; @@ -433,15 +433,16 @@ inline void dGrid::setValueDisk( int Column, int Row, double Value ) else if( gridType == ESRI_GRID ) esriSetValueDisk( Column, Row, Value ); else if( gridType == SDTS_GRID ) - return; + return; } void dGrid::dealloc() -{ if( isInRam && data != NULL ) +{ + if( isInRam && data != nullptr) { for( int y = 0; y < gridHeader.getNumberRows(); y++ ) - delete [] data[y]; - delete [] data; - data = NULL; + delete [] data[y]; + delete [] data; + data = nullptr; } gridHeader.setNumberRows( 0 ); gridHeader.setNumberCols( 0 ); @@ -450,29 +451,31 @@ void dGrid::dealloc() } void dGrid::alloc() -{ if( isInRam ) +{ + if( isInRam ) { if( gridHeader.getNumberCols() > 0 && gridHeader.getNumberRows() > 0 ) { - if (data != NULL) + if (data != nullptr) { delete [] data; - data = NULL; + data = nullptr; } data = new double *[gridHeader.getNumberRows()]; for( int y = 0; y < gridHeader.getNumberRows(); y++ ) - data[y] = new double[gridHeader.getNumberCols()]; - } + data[y] = new double[gridHeader.getNumberCols()]; + } } } //DATA MEMBER ACCESS dHeader dGrid::getHeader() -{ return gridHeader; +{ + return gridHeader; } void dGrid::setHeader( dHeader h ) -{ +{ //Don't allow the Rows and Columns to Change gridHeader.setDx( h.getDx() ); gridHeader.setDy( h.getDy() ); @@ -499,9 +502,9 @@ void dGrid::CellToProj( long column, long row, double & x, double & y ) inline int dGrid::round( double d ) { if( ceil(d) - d <= .5 ) - return (int)ceil(d); + return static_cast(ceil(d)); else - return (int)floor(d); + return static_cast(floor(d)); } void dGrid::clear(double clearValue) @@ -512,16 +515,18 @@ void dGrid::clear(double clearValue) int nrows= gridHeader.getNumberRows(); for( int j = 0; j < nrows; j++ ) { for( int i = 0; i < ncols; i++ ) - data[j][i] = clearValue; + data[j][i] = clearValue; } } else - { clearDisk(clearValue); + { + clearDisk(clearValue); } } void dGrid::clearDisk(double clearValue) -{ if( gridType == ASCII_GRID ) +{ + if( gridType == ASCII_GRID ) return; else if( gridType == BINARY_GRID ) binaryClearDisk(clearValue); @@ -632,11 +637,11 @@ GRID_TYPE dGrid::getGridType( const char * filename ) { GRID_TYPE grid_type = INVALID_GRID_TYPE; - if( filename != NULL && _tcslen( filename ) > 0 ) + if( filename != nullptr && _tcslen( filename ) > 0 ) { char * clean_filename = new char[_tcslen( filename ) + 1]; strcpy( clean_filename, filename ); - for( int i = _tcslen( clean_filename ) - 1; i >= 0; i-- ) + for( int i = static_cast(_tcslen( clean_filename )) - 1; i >= 0; i-- ) { if( clean_filename[i] == '\\' || clean_filename[i] == '/' ) clean_filename[i] = '\0'; else @@ -667,7 +672,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) cff.Close(); //File does not exist so parse it out - int length = _tcslen(filename ); + int length = static_cast(_tcslen(filename )); bool foundPeriod = false; for( int e = length-1; e >= 0; e-- ) { if( filename[e] == '\\' || filename[e] == '/' ) @@ -737,16 +742,18 @@ GRID_TYPE dGrid::getGridType( const char * filename ) ///\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ bool dGrid::asciiReadDiskToMemory( void (*callback)(int number, const char * message ) ) - { + { ifstream in(gridFilename); if( !in ) - { lastErrorCode = tkCANT_OPEN_FILE; + { + lastErrorCode = tkCANT_OPEN_FILE; return false; } else - { asciiReadHeader( in ); - + { + asciiReadHeader( in ); + int percent = 0; long num_read = 0; double total = gridHeader.getNumberRows()*gridHeader.getNumberCols(); @@ -761,21 +768,21 @@ GRID_TYPE dGrid::getGridType( const char * filename ) return false; } else - { if( callback != NULL ) + { if( callback != nullptr) callback( 0, "Allocating and Initializing Memory" ); alloc(); } - + for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { num_read++; if( !in ) { dealloc(); - return false; + return false; } - in>>data[j][i]; + in>>data[j][i]; if( min == nodata ) { min = data[j][i]; max = data[j][i]; @@ -790,24 +797,25 @@ GRID_TYPE dGrid::getGridType( const char * filename ) } } - if( callback != NULL ) - { int newpercent = (int)(((num_read)/total)*100); + if( callback != nullptr) + { int newpercent = static_cast(((num_read) / total) * 100); if( newpercent > percent ) { percent = newpercent; - callback( percent, "Reading Ascii Grid" ); + callback( percent, "Reading Ascii Grid" ); } - } + } } } asciiReadFooter( in ); in.close(); return true; - } + } } bool dGrid::asciiReadDiskToDisk( void(*callback)(int number, const char * message ) ) - { isInRam = true; - return asciiReadDiskToMemory( callback ); + { + isInRam = true; + return asciiReadDiskToMemory( callback ); } bool dGrid::asciiWriteMemoryToDisk( void(*callback)(int number, const char * message ) ) @@ -819,7 +827,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) return false; } else - { + { asciiWriteHeader(out); double total = gridHeader.getNumberRows()*gridHeader.getNumberCols(); int percent = 0; @@ -828,24 +836,24 @@ GRID_TYPE dGrid::getGridType( const char * filename ) for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { num_written++; - + out<((num_written / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Writing Ascii Grid" ); - } + } } } out<>header_value; } - + //Read past a header value, so put it back in.seekg( filePosition, ios::beg ); @@ -879,18 +887,20 @@ GRID_TYPE dGrid::getGridType( const char * filename ) } void dGrid::asciiReadFooter( istream & in ) - { char * header_value = new char[MAX_STRING_LENGTH]; + { + char * header_value = new char[MAX_STRING_LENGTH]; in>>header_value; while( in ) { asciiIsHeaderValue( (TCHAR*)header_value, in ); - in>>header_value; + in>>header_value; } delete [] header_value; } void dGrid::asciiWriteHeader( ostream & out ) - { out<<"NCOLS "<((num_written / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Writing Ascii Grid" ); - } + } } } out< percent ) @@ -1145,26 +1157,24 @@ GRID_TYPE dGrid::getGridType( const char * filename ) callback( percent, "Reading Binary Grid" ); } } - } - } - + } + fclose(in); - return true; + return true; } - } bool dGrid::binaryReadDiskToDisk() - { + { file_in_out = fopen( gridFilename, "r+b" ); - + if( !file_in_out ) { lastErrorCode = tkCANT_CREATE_FILE; return false; } else - { + { binaryReadHeader(file_in_out); if( gridHeader.getNumberCols() < 0 || gridHeader.getNumberRows() < 0 || @@ -1172,7 +1182,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) data_type != DOUBLE_TYPE ) { dealloc(); fclose( file_in_out ); - file_in_out = NULL; + file_in_out = nullptr; lastErrorCode = tkINCOMPATIBLE_DATA_TYPE; return false; } @@ -1199,7 +1209,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) // lastErrorCode = tkINVALID_FILE; // return false; // } - // + // // fread( &value,sizeof(double),1,file_in_out ); @@ -1218,34 +1228,34 @@ GRID_TYPE dGrid::getGridType( const char * filename ) // } // } //} - + //Darrel Brown, 10/10/2003 //set flags in the grid to make sure the min/max get calculated when asked for // This is done because the above code was commented findNewMax = findNewMin = true; if( gridHeader.getNumberCols() > 0 ) - { + { row_one = new double[gridHeader.getNumberCols()]; row_two = new double[gridHeader.getNumberCols()]; row_three = new double[gridHeader.getNumberCols()]; - - binaryBufferRows( 1 ); - } - return true; - } + + binaryBufferRows( 1 ); + } + return true; + } } bool dGrid::binaryWriteMemoryToDisk( void(*callback)(int number, const char * message ) ) - { + { FILE * out = fopen( gridFilename, "wb" ); - + if( !out ) { lastErrorCode = tkCANT_CREATE_FILE; return false; } else - { + { binaryWriteHeader(out); double total = gridHeader.getNumberRows() * gridHeader.getNumberCols(); int percent = 0; @@ -1254,22 +1264,22 @@ GRID_TYPE dGrid::getGridType( const char * filename ) for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { num_written++; - + fwrite( &data[j][i],sizeof(double),1,out); - if( callback != NULL ) + if( callback != nullptr) { - int newpercent = (int)((num_written/total)*100); + int newpercent = static_cast((num_written / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Binary Grid Write"); - } + } } - } + } } fclose( out ); - return true; - } + return true; + } } bool dGrid::binaryWriteDiskToDisk() @@ -1280,12 +1290,12 @@ GRID_TYPE dGrid::getGridType( const char * filename ) { rewind( file_in_out ); binaryWriteHeader(file_in_out); return true; - } + } } bool dGrid::binaryInitializeDisk( double initialValue ) - { + { file_in_out = fopen( gridFilename, "w+b" ); if( !file_in_out ) @@ -1293,20 +1303,20 @@ GRID_TYPE dGrid::getGridType( const char * filename ) return false; } else - { + { binaryWriteHeader(file_in_out); file_position_beg_of_data = ftell( file_in_out); for( int j = gridHeader.getNumberRows() - 1; j >= 0; j-- ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) - { - fwrite( &initialValue,sizeof(double),1,file_in_out); - } + { + fwrite(&initialValue, sizeof(double), 1, file_in_out); + } } - + min = initialValue; max = initialValue; - + current_row = 0; row_one = new double[gridHeader.getNumberCols()]; row_two = new double[gridHeader.getNumberCols()]; @@ -1318,11 +1328,11 @@ GRID_TYPE dGrid::getGridType( const char * filename ) row_three[i] = initialValue; } } - return true; + return true; } void dGrid::binaryReadHeader( FILE * in ) - { + { rewind(in); long ncols; fread( &ncols, sizeof(int),1,in); @@ -1349,9 +1359,9 @@ GRID_TYPE dGrid::getGridType( const char * filename ) gridHeader.setYllcenter( yllcenter ); fread( &data_type, sizeof(DATA_TYPE),1,in); - + double nodata_value; - fread( &nodata_value, sizeof(double),1,in); + fread( &nodata_value, sizeof(double),1,in); gridHeader.setNodataValue( nodata_value ); char * projection = new char[MAX_STRING_LENGTH + 1]; @@ -1384,13 +1394,13 @@ GRID_TYPE dGrid::getGridType( const char * filename ) fwrite( &type, sizeof(DATA_TYPE),1,out); double nodata = gridHeader.getNodataValue(); fwrite( &nodata, sizeof(double),1,out); - + char * projection = new char[MAX_STRING_LENGTH + 1]; strcpy( projection, gridHeader.getProjection() ); if( _tcslen( projection ) > 0 ) fwrite( projection, sizeof(char), _tcslen(projection),out); if( _tcslen( projection ) < MAX_STRING_LENGTH ) - { int size_of_pad = MAX_STRING_LENGTH - _tcslen(projection); + { int size_of_pad = MAX_STRING_LENGTH - static_cast(_tcslen(projection)); char * pad = new char[size_of_pad]; for( int p = 0; p < size_of_pad; p++ ) pad[p] = 0; @@ -1404,13 +1414,13 @@ GRID_TYPE dGrid::getGridType( const char * filename ) if( _tcslen( notes ) > 0 ) fwrite( notes, sizeof(char), _tcslen(notes), out); if( _tcslen( notes ) < MAX_STRING_LENGTH ) - { int size_of_pad = MAX_STRING_LENGTH - _tcslen(notes); + { int size_of_pad = MAX_STRING_LENGTH - static_cast(_tcslen(notes)); char * pad = new char[size_of_pad]; for( int p = 0; p < size_of_pad; p++ ) pad[p] = 0; fwrite(pad, sizeof(char), size_of_pad, out ); delete [] pad; - } + } delete [] notes; } @@ -1425,28 +1435,28 @@ GRID_TYPE dGrid::getGridType( const char * filename ) else { binaryBufferRows( Row ); return row_two[ Column ]; - } + } } void dGrid::binarySetValueDisk( int Column, int Row, double Value ) { long file_position = file_position_beg_of_data + sizeof(double)*Row*gridHeader.getNumberCols() + sizeof(double)*Column; - + if( fseek( file_in_out, file_position, SEEK_SET ) == -1L ) {} else - { + { if( fwrite( &Value, sizeof(double), 1, file_in_out ) < 1 ) - {} + {} else { if( Row == current_row - 1 ) row_one[ Column ] = Value; else if( Row == current_row ) row_two[ Column ] = Value; else if( Row == current_row + 1 ) - row_three[ Column ] = Value; + row_three[ Column ] = Value; } - } + } } void dGrid::binaryClearDisk(double clearValue) @@ -1454,14 +1464,14 @@ GRID_TYPE dGrid::getGridType( const char * filename ) if( fseek( file_in_out, file_position_beg_of_data, SEEK_SET ) == -1L ) return; else - { + { for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { if( fwrite( &clearValue, sizeof(double), 1, file_in_out ) < 1 ) return; } - } - } + } + } } void dGrid::binaryBufferRows( int center_row ) @@ -1480,7 +1490,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) } else nd_fill_one = true; - + if( gridHeader.getNumberRows() >= center_row && center_row >= 0 ) { long file_position = file_position_beg_of_data + sizeof(double)*(center_row)*gridHeader.getNumberCols(); @@ -1502,7 +1512,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) } else nd_fill_three = true; - + current_row = center_row; if( nd_fill_one || nd_fill_two || nd_fill_three ) @@ -1521,12 +1531,12 @@ GRID_TYPE dGrid::getGridType( const char * filename ) bool dGrid::binarySaveAs( CString filename, void(*callback)(int number, const char * message) ) - { + { // Write to a temporary file first. char tempName[ FILENAME_MAX ] = {0}; tmpnam(tempName); FILE * out = fopen( tempName, "wb" ); - + if( !out ) return false; @@ -1543,15 +1553,15 @@ GRID_TYPE dGrid::getGridType( const char * filename ) value = getValue( i, j ); fwrite( &value,sizeof(double),1,out); - if( callback != NULL ) + if( callback != nullptr) { - int newpercent = (int)((num_written/total)*100); + int newpercent = static_cast((num_written / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Binary Grid Write"); - } + } } - } + } } fclose( out ); @@ -1592,32 +1602,32 @@ GRID_TYPE dGrid::getGridType( const char * filename ) #pragma optimize("", off) bool dGrid::esriReadDiskToMemory( void (*callback)(int number, const char * message ) ) { - if( celllayeropen == NULL || - celllyrclose == NULL || - bndcellread == NULL || - privateaccesswindowset == NULL || - privatewindowcols == NULL || - privatewindowrows == NULL || - getwindowrow == NULL || - getmissingfloat == NULL ) + if( celllayeropen == nullptr || + celllyrclose == nullptr || + bndcellread == nullptr || + privateaccesswindowset == nullptr || + privatewindowcols == nullptr || + privatewindowrows == nullptr || + getwindowrow == nullptr || + getmissingfloat == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; } - double csize; + double csize; double bndbox[4]; double adjbndbox[4]; double nodata = -1; int cell_type; - - char * fname = new char[_MAX_PATH+1]; + + char * fname = new char[_MAX_PATH+1]; if( GetShortPathName(gridFilename,fname,_MAX_PATH) == 0 ) - strcpy( fname, gridFilename ); + strcpy( fname, gridFilename ); grid_layer = celllayeropen(fname,READONLY,ROWIO,&cell_type,&csize); if( grid_layer >= 0 ) - { + { //Get the bounding box of the input cell layer //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner if( bndcellread(fname,bndbox) < 0 ) @@ -1627,11 +1637,11 @@ GRID_TYPE dGrid::getGridType( const char * filename ) grid_layer = -1; lastErrorCode = tkESRI_INVALID_BOUNDS; return false; - } - + } + //Need to find cell_type if( cell_type == CELLFLOAT ) - { getmissingfloat(&float_null); + { getmissingfloat(&float_null); nodata = float_null; } if( cell_type == CELLINT ) @@ -1640,15 +1650,15 @@ GRID_TYPE dGrid::getGridType( const char * filename ) celllyrclose(grid_layer); grid_layer = -1; lastErrorCode = tkINVALID_GRID_FILE_TYPE; - return false; + return false; } gridHeader.setXllcenter( bndbox[0] + .5*csize ); gridHeader.setYllcenter( bndbox[1] + .5*csize ); gridHeader.setDx( csize ); gridHeader.setDy( csize ); gridHeader.setNodataValue( nodata ); - - //Set the Window to the output bounding box and cellsize + + //Set the Window to the output bounding box and cellsize if( privateaccesswindowset(grid_layer,bndbox,csize,adjbndbox) < 0) { dealloc(); //Close handle @@ -1657,7 +1667,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) lastErrorCode = tkESRI_ACCESS_WINDOW_SET; return false; } - + //Get the number of rows and columns in the window gridHeader.setNumberCols( privatewindowcols(grid_layer) ); gridHeader.setNumberRows( privatewindowrows(grid_layer) ); @@ -1675,9 +1685,9 @@ GRID_TYPE dGrid::getGridType( const char * filename ) alloc(); //Now copy row major into array - //Allocate row buffer - row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( row_buf1 == NULL ) + //Allocate row buffer + row_buf1 = reinterpret_cast(CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE))); + if ( row_buf1 == nullptr) { dealloc(); //Close handle celllyrclose(grid_layer); @@ -1695,9 +1705,9 @@ GRID_TYPE dGrid::getGridType( const char * filename ) max = nodata; for ( int j = 0; j < gridHeader.getNumberRows(); j++) { - getwindowrow(grid_layer, j, (CELLTYPE*)row_buf1); + getwindowrow(grid_layer, j, static_cast(row_buf1)); - register float *buf = (float *)row_buf1; + register float *buf = static_cast(row_buf1); for( int i = 0; i < gridHeader.getNumberCols(); i++) { if( buf[i] == float_null ) @@ -1713,15 +1723,14 @@ GRID_TYPE dGrid::getGridType( const char * filename ) if( max == nodata ) max = buf[i]; else if( buf[i] > max ) - max = buf[i]; + max = buf[i]; } - } - + } int newpercent = (int)((j/total)*100); if( newpercent > percent ) { percent = newpercent; - if( callback != NULL ) + if( callback != nullptr) callback( percent, "Reading Esri Grid" ); } @@ -1729,55 +1738,55 @@ GRID_TYPE dGrid::getGridType( const char * filename ) //Free row buffer CFree1((char *)row_buf1); - row_buf1 = NULL; + row_buf1 = nullptr; //Close handle celllyrclose(grid_layer); grid_layer = -1; return true; - } + } else { dealloc(); grid_layer = -1; lastErrorCode = tkESRI_LAYER_OPEN; return false; - } + } } #pragma optimize("", on) #pragma optimize("", off) bool dGrid::esriReadDiskToDisk() - { + { //Check for the needed functions - if( bndcellread == NULL || - celllyrclose == NULL || - celllayeropen == NULL || - privateaccesswindowset == NULL || - privatewindowcols == NULL || - privatewindowrows == NULL || - getwindowrow == NULL || - getmissingfloat == NULL ) + if( bndcellread == nullptr || + celllyrclose == nullptr || + celllayeropen == nullptr || + privateaccesswindowset == nullptr || + privatewindowcols == nullptr || + privatewindowrows == nullptr || + getwindowrow == nullptr || + getmissingfloat == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; } - double csize; + double csize; double bndbox[4]; double adjbndbox[4]; double nodata = -1; int cell_type; - char * fname = new char[_MAX_PATH+1]; + char * fname = new char[_MAX_PATH+1]; if( GetShortPathName(gridFilename,fname,_MAX_PATH) == 0 ) strcpy( fname, gridFilename ); grid_layer = celllayeropen(fname,READWRITE,ROWIO,&cell_type,&csize); if( grid_layer >= 0 ) - { + { //Get the bounding box of the input cell layer //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner - + if( bndcellread(fname,bndbox) < 0 ) { dealloc(); //Close handle @@ -1800,7 +1809,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) grid_layer = -1; lastErrorCode = tkINVALID_GRID_FILE_TYPE; delete [] fname; - return false; + return false; } gridHeader.setXllcenter( bndbox[0] + .5*csize ); @@ -1809,7 +1818,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) gridHeader.setDy( csize ); gridHeader.setNodataValue( nodata ); - //Set the Window to the output bounding box and cellsize + //Set the Window to the output bounding box and cellsize if( privateaccesswindowset(grid_layer,bndbox,csize,adjbndbox) < 0) { dealloc(); //Close handle @@ -1834,11 +1843,11 @@ GRID_TYPE dGrid::getGridType( const char * filename ) return false; } - //Allocate row buffer + //Allocate row buffer row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - row_buf2 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - row_buf3 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( row_buf1 == NULL || row_buf2 == NULL || row_buf3 == NULL ) + row_buf2 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); + row_buf3 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); + if ( row_buf1 == nullptr || row_buf2 == nullptr || row_buf3 == nullptr) { dealloc(); //Close handle celllyrclose(grid_layer); @@ -1847,7 +1856,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) delete [] fname; return false; } - + //Find the min and max double nodata = gridHeader.getNodataValue(); min = nodata; @@ -1855,7 +1864,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) findNewMin = true; findNewMax = true; /*for ( int j = 0; j < gridHeader.getNumberRows(); j++) - { + { getwindowrow(grid_layer, j, (CELLTYPE*)row_buf1); register float *buf = (float *)row_buf1; @@ -1872,12 +1881,12 @@ GRID_TYPE dGrid::getGridType( const char * filename ) else if( buf[i] > max ) max = buf[i]; } - } + } - } */ + } */ esriBufferRows( 0 ); delete [] fname; - return true; + return true; } else { dealloc(); @@ -1893,13 +1902,13 @@ GRID_TYPE dGrid::getGridType( const char * filename ) bool dGrid::esriWriteMemoryToDisk( void(*callback)(int number, const char * message ) ) { //Check the needed functions - if( celllyrclose == NULL || - celllyrexists == NULL || - celllayercreate == NULL || - griddelete == NULL || - privateaccesswindowset == NULL || - getmissingfloat == NULL || - putwindowrow == NULL ) + if( celllyrclose == nullptr || + celllyrexists == nullptr || + celllayercreate == nullptr || + griddelete == nullptr || + privateaccesswindowset == nullptr || + getmissingfloat == nullptr || + putwindowrow == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; @@ -1915,12 +1924,12 @@ GRID_TYPE dGrid::getGridType( const char * filename ) bndbox[2] = gridHeader.getXllcenter() + gridHeader.getNumberCols()*gridHeader.getDx() - gridHeader.getDx()*.5; bndbox[3] = gridHeader.getYllcenter() + gridHeader.getNumberRows()*gridHeader.getDy() - gridHeader.getDy()*.5; double adjbndbox[4]; - + char * fname = new char[gridFilename.GetLength()+1]; - strcpy( fname, gridFilename ); + strcpy( fname, gridFilename ); if( celllyrexists( fname ) != 0 ) griddelete( fname ); - + grid_layer = celllayercreate( fname, WRITEONLY, ROWIO, cell_type, csize, bndbox); if( grid_layer < 0 ) { grid_layer = -1; @@ -1931,20 +1940,20 @@ GRID_TYPE dGrid::getGridType( const char * filename ) if( privateaccesswindowset( grid_layer, bndbox, csize, adjbndbox) < 0 ) { celllyrclose(grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); grid_layer = -1; lastErrorCode = tkESRI_ACCESS_WINDOW_SET; return false; } - getmissingfloat(&float_null); + getmissingfloat(&float_null); - //Allocate row buffer - row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( row_buf1 == NULL ) + //Allocate row buffer + row_buf1 = reinterpret_cast(CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE))); + if ( row_buf1 == nullptr) { celllyrclose(grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); grid_layer = -1; lastErrorCode = tkCANT_ALLOC_MEMORY; return false; @@ -1954,32 +1963,32 @@ GRID_TYPE dGrid::getGridType( const char * filename ) int percent = 0; double nodata = gridHeader.getNodataValue(); - register float *buf = (float *)row_buf1; + register float *buf = static_cast(row_buf1); for( int j = 0; j < gridHeader.getNumberRows(); j++) { for( int i = 0; i < gridHeader.getNumberCols(); i++) { - buf[i] = (float)data[j][i]; + buf[i] = static_cast(data[j][i]); if(buf[i] == nodata) buf[i] = float_null; } - putwindowrow( grid_layer, j, (CELLTYPE*)row_buf1); + putwindowrow( grid_layer, j, static_cast(row_buf1)); int newpercent = (int)((j/total)*100); if( newpercent > percent ) { percent = newpercent; - if( callback != NULL ) + if( callback != nullptr) callback( percent, "Writing Esri Grid" ); } } - - CFree1 ((char *)row_buf1); - row_buf1 = NULL; - //Close handle + CFree1 (static_cast(row_buf1)); + row_buf1 = nullptr; + + //Close handle celllyrclose(grid_layer); grid_layer = -1; - return true; + return true; } #pragma optimize("", on) @@ -1990,21 +1999,21 @@ GRID_TYPE dGrid::getGridType( const char * filename ) #pragma optimize("", off) bool dGrid::esriInitializeDisk( double InitialValue ) - { - if( celllyrexists == NULL || - celllyrclose == NULL || - griddelete == NULL || - celllayercreate == NULL || - privateaccesswindowset == NULL || - putwindowrow == NULL || - getmissingfloat == NULL ) + { + if( celllyrexists == nullptr || + celllyrclose == nullptr || + griddelete == nullptr || + celllayercreate == nullptr || + privateaccesswindowset == nullptr || + putwindowrow == nullptr || + getmissingfloat == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; } int cell_type = CELLFLOAT; - + double csize = gridHeader.getDx(); //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner double bndbox[4]; @@ -2012,10 +2021,10 @@ GRID_TYPE dGrid::getGridType( const char * filename ) bndbox[1] = gridHeader.getYllcenter() - gridHeader.getDy()*.5; bndbox[2] = gridHeader.getXllcenter() + gridHeader.getNumberCols()*gridHeader.getDx() - gridHeader.getDx()*.5; bndbox[3] = gridHeader.getYllcenter() + gridHeader.getNumberRows()*gridHeader.getDy() - gridHeader.getDy()*.5; - + char * fname = new char[gridFilename.GetLength()+1]; strcpy( fname, gridFilename ); - + if( celllyrexists( fname ) != 0 ) { if( griddelete( fname ) == 0 ) @@ -2025,7 +2034,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) return false; } } - + grid_layer = celllayercreate( fname, WRITEONLY, ROWIO, cell_type, csize, bndbox); if( grid_layer < 0 ) @@ -2034,38 +2043,38 @@ GRID_TYPE dGrid::getGridType( const char * filename ) delete [] fname; return false; } - + getmissingfloat(&float_null); double adjbndbox[4]; if( privateaccesswindowset( grid_layer, bndbox, csize, adjbndbox) < 0 ) { celllyrclose(grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); grid_layer = -1; lastErrorCode = tkESRI_ACCESS_WINDOW_SET; delete [] fname; return false; } - //Allocate row buffer + //Allocate row buffer row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if( row_buf1 == NULL ) - { - celllyrclose(grid_layer); + if( row_buf1 == nullptr) + { + celllyrclose(grid_layer); if( celllyrexists( fname ) ) griddelete( fname ); grid_layer = -1; lastErrorCode = tkCANT_ALLOC_MEMORY; delete [] fname; return false; - } + } - double nodata = gridHeader.getNodataValue(); + double nodata = gridHeader.getNodataValue(); max = nodata; min = nodata; - float *buf = (float *)row_buf1; + float *buf = static_cast(row_buf1); if( InitialValue == nodata ) { @@ -2075,20 +2084,20 @@ GRID_TYPE dGrid::getGridType( const char * filename ) else { for( int i = 0; i < gridHeader.getNumberCols(); i++) //casting added by dpa 6/7/05 - buf[i] = (float) InitialValue; + buf[i] = static_cast(InitialValue); } - + for( int j = 0; j < gridHeader.getNumberRows(); j++) - putwindowrow( grid_layer, j, (CELLTYPE*)row_buf1); - - //Close and Reopen so VAT Table is Written + putwindowrow( grid_layer, j, static_cast(row_buf1)); + + //Close and Reopen so VAT Table is Written celllyrclose(grid_layer); grid_layer = -1; - CFree1 ((char *)row_buf1); - row_buf1 = NULL; + CFree1 (static_cast(row_buf1)); + row_buf1 = nullptr; delete [] fname; - return esriReadDiskToDisk(); + return esriReadDiskToDisk(); } #pragma optimize("", on) @@ -2102,28 +2111,28 @@ GRID_TYPE dGrid::getGridType( const char * filename ) if( Row == current_row - 1 ) { - if( ((float *)row_buf1)[Column] == float_null ) + if( static_cast(row_buf1)[Column] == float_null ) return gridHeader.getNodataValue(); - return double((((float *)row_buf1)[Column])); + return static_cast(static_cast(row_buf1)[Column]); } else if( Row == current_row ) { - if( ((float *)row_buf2)[Column] == float_null ) + if( static_cast(row_buf2)[Column] == float_null ) return gridHeader.getNodataValue(); - return double((((float *)row_buf2)[Column])); + return static_cast(static_cast(row_buf2)[Column]); } else if( Row == current_row + 1 ) { - if( ((float *)row_buf3)[Column] == float_null ) + if( static_cast(row_buf3)[Column] == float_null ) return gridHeader.getNodataValue(); - return double((((float *)row_buf3)[Column])); + return static_cast(static_cast(row_buf3)[Column]); } else { esriBufferRows( Row ); - if( ((float *)row_buf2)[Column] == float_null ) + if( static_cast(row_buf2)[Column] == float_null ) return gridHeader.getNodataValue(); - return double((((float *)row_buf2)[Column])); + return static_cast(static_cast(row_buf2)[Column]); } return gridHeader.getNodataValue(); @@ -2133,7 +2142,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) #pragma optimize("", off) void dGrid::esriSetValueDisk( int Column, int Row, double Value ) { - if( putwindowrow == NULL ) + if( putwindowrow == nullptr) return; double value = Value; @@ -2144,41 +2153,41 @@ GRID_TYPE dGrid::getGridType( const char * filename ) if( value == gridHeader.getNodataValue() ) value = float_null; - register float *buf = (float *)row_buf1; + register float *buf = static_cast(row_buf1); //casting added by dpa 6/7/05 - buf[Column] = (float) value; - putwindowrow( grid_layer, Row, (CELLTYPE*)row_buf1); + buf[Column] = static_cast(value); + putwindowrow( grid_layer, Row, static_cast(row_buf1)); } else if( Row == current_row ) { if( value == gridHeader.getNodataValue() ) value = float_null; - - register float *buf = (float *)row_buf2; - //casting added by dpa 6/7/05 - buf[Column] = (float) value; - putwindowrow( grid_layer, Row, (CELLTYPE*)row_buf2); + + register float *buf = static_cast(row_buf2); + //casting added by dpa 6/7/05 + buf[Column] = static_cast(value); + putwindowrow( grid_layer, Row, static_cast(row_buf2)); } else if( Row == current_row + 1 ) { if( value == gridHeader.getNodataValue() ) value = float_null; - register float *buf = (float *)row_buf3; + register float *buf = static_cast(row_buf3); //casting added by dpa 6/7/05 - buf[Column] = (float) value; - putwindowrow( grid_layer, Row, (CELLTYPE*)row_buf3); - } + buf[Column] = static_cast(value); + putwindowrow( grid_layer, Row, static_cast(row_buf3)); + } } #pragma optimize("", on) #pragma optimize("", off) void dGrid::esriClearDisk(double clearValue) { - if( putwindowrow == NULL ) + if( putwindowrow == nullptr) return; - register float *buf = (float *)row_buf1; + register float *buf = static_cast(row_buf1); for( int j = 0; j < gridHeader.getNumberRows(); j++) { double val = clearValue; @@ -2187,35 +2196,35 @@ GRID_TYPE dGrid::getGridType( const char * filename ) for( int i = 0; i < gridHeader.getNumberCols(); i++) { //casting added by dpa 6/7/05 - buf[i]=(float) val; + buf[i] = static_cast(val); } - putwindowrow( grid_layer, j, (CELLTYPE*)row_buf1); + putwindowrow( grid_layer, j, static_cast(row_buf1)); } for( int i = 0; i < gridHeader.getNumberCols(); i++) { //casting added by dpa 6/7/05 - buf[i]=(float) clearValue; - } + buf[i] = static_cast(clearValue); + } - esriBufferRows( 0 ); + esriBufferRows( 0 ); } #pragma optimize("", on) #pragma optimize("", off) void dGrid::esriBufferRows( int center_row ) { - if( getwindowrow == NULL ) + if( getwindowrow == nullptr) { register float *ibuf; for( int i = 0; i < gridHeader.getNumberCols(); i++ ) - { - ibuf = (float *)row_buf1; + { + ibuf = static_cast(row_buf1); ibuf[i] = float_null; - ibuf = (float *)row_buf2; + ibuf = static_cast(row_buf2); ibuf[i] = float_null; - ibuf = (float *)row_buf3; - ibuf[i] = float_null; - } + ibuf = static_cast(row_buf3); + ibuf[i] = float_null; + } return; } @@ -2225,7 +2234,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) if( gridHeader.getNumberRows() >= center_row -1 && center_row - 1 >= 0 ) { - getwindowrow(grid_layer, center_row - 1, (CELLTYPE*)row_buf1); + getwindowrow(grid_layer, center_row - 1, static_cast(row_buf1)); nd_fill_one = false; } else @@ -2233,7 +2242,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) if( gridHeader.getNumberRows() >= center_row && center_row >= 0 ) { - getwindowrow(grid_layer, center_row, (CELLTYPE*)row_buf2); + getwindowrow(grid_layer, center_row, static_cast(row_buf2)); nd_fill_two = false; } else @@ -2241,7 +2250,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) if( gridHeader.getNumberRows() >= center_row + 1 && center_row + 1 >= 0 ) { - getwindowrow(grid_layer, center_row + 1, (CELLTYPE*)row_buf3); + getwindowrow(grid_layer, center_row + 1, static_cast(row_buf3)); nd_fill_three = false; } else @@ -2253,22 +2262,22 @@ GRID_TYPE dGrid::getGridType( const char * filename ) if( nd_fill_one || nd_fill_two || nd_fill_three ) { register float *ibuf; - + for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { if( nd_fill_one ) - { ibuf = (float *)row_buf1; + { ibuf = static_cast(row_buf1); ibuf[i] = float_null; } if( nd_fill_two ) - { ibuf = (float *)row_buf2; + { ibuf = static_cast(row_buf2); ibuf[i] = float_null; } if( nd_fill_three ) - { ibuf = (float *)row_buf3; + { ibuf = static_cast(row_buf3); ibuf[i] = float_null; - } - } + } + } } } #pragma optimize("", on) @@ -2278,20 +2287,20 @@ GRID_TYPE dGrid::getGridType( const char * filename ) { long temp_grid_layer = -1; //Check the needed functions - if( celllyrclose == NULL || - celllyrexists == NULL || - celllayercreate == NULL || - griddelete == NULL || - privateaccesswindowset == NULL || - getmissingfloat == NULL || - putwindowrow == NULL ) + if( celllyrclose == nullptr || + celllyrexists == nullptr || + celllayercreate == nullptr || + griddelete == nullptr || + privateaccesswindowset == nullptr || + getmissingfloat == nullptr || + putwindowrow == nullptr) { temp_grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; } int cell_type = CELLFLOAT; - + double csize = gridHeader.getDx(); //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner double bndbox[4]; @@ -2300,12 +2309,12 @@ GRID_TYPE dGrid::getGridType( const char * filename ) bndbox[2] = gridHeader.getXllcenter() + gridHeader.getNumberCols()*gridHeader.getDx() - gridHeader.getDx()*.5; bndbox[3] = gridHeader.getYllcenter() + gridHeader.getNumberRows()*gridHeader.getDy() - gridHeader.getDy()*.5; double adjbndbox[4]; - + char * fname = new char[filename.GetLength()+1]; - strcpy( fname, filename ); + strcpy( fname, filename ); if( celllyrexists( fname ) != 0 ) griddelete( fname ); - + temp_grid_layer = celllayercreate( fname, WRITEONLY, ROWIO, cell_type, csize, bndbox); if( temp_grid_layer < 0 ) { temp_grid_layer = -1; @@ -2317,7 +2326,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) if( privateaccesswindowset( temp_grid_layer, bndbox, csize, adjbndbox) < 0 ) { celllyrclose(temp_grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); temp_grid_layer = -1; lastErrorCode = tkESRI_ACCESS_WINDOW_SET; delete [] fname; @@ -2325,13 +2334,13 @@ GRID_TYPE dGrid::getGridType( const char * filename ) } getmissingfloat(&float_null); - - //Allocate row buffer + + //Allocate row buffer void * temp_row_buf = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( temp_row_buf == NULL ) + if ( temp_row_buf == nullptr) { celllyrclose(temp_grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); temp_grid_layer = -1; lastErrorCode = tkCANT_ALLOC_MEMORY; delete [] fname; @@ -2342,35 +2351,35 @@ GRID_TYPE dGrid::getGridType( const char * filename ) int percent = 0; double nodata = gridHeader.getNodataValue(); - register float *buf = (float *)temp_row_buf; + register float *buf = static_cast(temp_row_buf); for( int j = 0; j < gridHeader.getNumberRows(); j++) { for( int i = 0; i < gridHeader.getNumberCols(); i++) { - buf[i] = (float)getValue( i, j ); + buf[i] = static_cast(getValue(i, j)); if(buf[i] == nodata) buf[i] = float_null; } - putwindowrow( temp_grid_layer, j, (CELLTYPE*)temp_row_buf); + putwindowrow( temp_grid_layer, j, (CELLTYPE*)temp_row_buf); int newpercent = (int)((j/total)*100); if( newpercent > percent ) { percent = newpercent; - if( callback != NULL ) + if( callback != nullptr) callback( percent, "Writing Esri Grid" ); } } - CFree1 ((char *)temp_row_buf); - temp_row_buf = NULL; + CFree1 (static_cast(temp_row_buf)); + temp_row_buf = nullptr; if( isInRam == true ) { gridFilename = filename; - //Close handle + //Close handle celllyrclose(temp_grid_layer); temp_grid_layer = -1; delete [] fname; - return true; + return true; } else { celllyrclose(temp_grid_layer); @@ -2396,14 +2405,13 @@ GRID_TYPE dGrid::getGridType( const char * filename ) # define null 0 bool dGrid::sdtsReadDiskToMemory( void(*callback)(int number, const char * message ) ) - { - + { //Initialize the grid strcpy( file_name, gridFilename ); - //Find the byte order of the machine + //Find the byte order of the machine g123order(&order); - + char * fname = new char[ gridFilename.GetLength() + 1]; strcpy( fname, gridFilename ); long fillvalue; @@ -2411,9 +2419,9 @@ GRID_TYPE dGrid::getGridType( const char * filename ) { lastErrorCode = tkSDTS_BAD_FILE_HEADER; return false; } - + alloc(); - + cells_out( gridFilename, status, fillvalue, callback ); //Check for -255 Value that can be produced on extraction @@ -2421,11 +2429,11 @@ GRID_TYPE dGrid::getGridType( const char * filename ) double value = gridHeader.getNodataValue(); double average = 0; int cnt = 0; - + for( int row = 0; row < gridHeader.getNumberRows(); row++ ) - { + { for( int column = 0; column < gridHeader.getNumberCols(); column++ ) - { + { value = getValue( column, row ); average = 0; cnt = 0; @@ -2477,16 +2485,16 @@ GRID_TYPE dGrid::getGridType( const char * filename ) else average = nodata_value; - setValue( column, row, (double)average ); + setValue( column, row, average ); } } } - - return true; + + return true; } bool dGrid::read_sdts_header(char * filename, dHeader & h, long & fillvalue) - { + { strcpy( file_name, filename ); baseAndId(); if (!beg123file (filename,'R',&int_level,&ice,ccs,&fpin)) @@ -2541,7 +2549,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) { int len,j; //parse out base_name - len = _tcslen(file_name); + len = static_cast(_tcslen(file_name)); for(j=0;j(atof(string)); } } else if (!strcmp (tag, "SADR") && !strcmp (descr, "Y")) @@ -3443,7 +3451,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) } else if (strstr(frmts, "R")) { - sadr_y = (long) atof(string); + sadr_y = static_cast(atof(string)); } } } while (status != 4); /* Break out of loop at end of file */ @@ -3467,7 +3475,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) char data[1000]; FILE* fp; int len; - char* index = NULL; + char* index = nullptr; baseAndId(); strcpy (file_name,base_name); @@ -3477,7 +3485,7 @@ GRID_TYPE dGrid::getGridType( const char * filename ) if(!fp) return 0; - len = fread(data,sizeof(char),MAX-1,fp); + len = static_cast(fread(data,sizeof(char),MAX-1,fp)); fclose(fp); data[MAX-1] = '\0'; diff --git a/src/Grid/fGrid.cpp b/src/Grid/fGrid.cpp index c9966d6a..bd754077 100644 --- a/src/Grid/fGrid.cpp +++ b/src/Grid/fGrid.cpp @@ -22,7 +22,7 @@ extern ESRI_GRIDDELETE_PROC griddelete; extern ESRI_CELLLAYERCREATE_PROC celllayercreate; fGrid::fGrid() -{ data = NULL; +{ data = nullptr; isInRam = true; findNewMax = false; findNewMin = false; @@ -35,16 +35,16 @@ fGrid::fGrid() current_row = -2; //BINARY - row_one = NULL; - row_two = NULL; - row_three = NULL; - file_in_out = NULL; + row_one = nullptr; + row_two = nullptr; + row_three = nullptr; + file_in_out = nullptr; //ESRI - grid_layer = -1; - row_buf1 = NULL; - row_buf2 = NULL; - row_buf3 = NULL; + grid_layer = -1; + row_buf1 = nullptr; + row_buf2 = nullptr; + row_buf3 = nullptr; leadid = 0; initialize_esri(); @@ -66,13 +66,13 @@ long fGrid::LastErrorCode() //OPERATORS float fGrid::operator()( int Column, int Row ) -{ +{ if( inGrid( Column, Row ) ) { if( isInRam ) - return data[Row][Column]; + return data[Row][Column]; else - return getValueDisk( Column, Row ); + return getValueDisk( Column, Row ); } else return gridHeader.getNodataValue(); @@ -80,15 +80,14 @@ float fGrid::operator()( int Column, int Row ) //FUNCTIONS bool fGrid::open( const char * cfilename, bool InRam, GRID_TYPE GridType, void (*callback)( int number, const char * message ) ) -{ +{ CString filename = cfilename; - if( data != NULL || file_in_out != NULL ) + if( data != nullptr || file_in_out != nullptr) close(); - isInRam = InRam; - + if( filename.GetLength() <= 0 ) { lastErrorCode = tkINVALID_FILENAME; return false; @@ -101,7 +100,7 @@ bool fGrid::open( const char * cfilename, bool InRam, GRID_TYPE GridType, void ( gridType = getGridType( filename ); if( isInRam == true ) - return readDiskToMemory( callback ); + return readDiskToMemory( callback ); else { //1. Read the header information //2. Find the min and max @@ -111,7 +110,7 @@ bool fGrid::open( const char * cfilename, bool InRam, GRID_TYPE GridType, void ( } bool fGrid::readDiskToMemory( void (*callback)(int number, const char * message ) ) -{ +{ if( gridType == ASCII_GRID ) return asciiReadDiskToMemory( callback ); else if( gridType == BINARY_GRID ) @@ -138,14 +137,14 @@ bool fGrid::readDiskToDisk( void (*callback)(int number, const char * message ) */ lastErrorCode = tkINVALID_GRID_FILE_TYPE; return false; -} +} bool fGrid::writeMemoryToDisk( void(*callback)(int number, const char * message ) ) { if( gridType == ASCII_GRID ) return asciiWriteMemoryToDisk( callback ); else if( gridType == BINARY_GRID ) - return binaryWriteMemoryToDisk( callback ); + return binaryWriteMemoryToDisk( callback ); else if( gridType == ESRI_GRID ) return esriWriteMemoryToDisk( callback ); /* @@ -157,7 +156,7 @@ bool fGrid::writeMemoryToDisk( void(*callback)(int number, const char * message } bool fGrid::writeDiskToDisk() -{ +{ if( gridType == ASCII_GRID ) return asciiWriteDiskToDisk(); else if( gridType == BINARY_GRID ) @@ -169,15 +168,15 @@ bool fGrid::writeDiskToDisk() return sdtsWriteDiskToDisk( callback ); */ lastErrorCode = tkINVALID_GRID_FILE_TYPE; - return false; + return false; } bool fGrid::initialize( const char * cfilename, fHeader header, float initialValue, bool InRam, GRID_TYPE GridType ) -{ +{ CString filename = cfilename; close(); - isInRam = InRam; + isInRam = InRam; gridFilename = filename; gridHeader = header; @@ -195,10 +194,10 @@ bool fGrid::initialize( const char * cfilename, fHeader header, float initialVal if( isInRam == true ) { - if (data != NULL) + if (data != nullptr) { delete [] data; - data = NULL; + data = nullptr; } data = new float*[ gridHeader.getNumberRows() ]; for( int y = 0; y < gridHeader.getNumberRows(); y++ ) @@ -214,7 +213,7 @@ bool fGrid::initialize( const char * cfilename, fHeader header, float initialVal return true; } else - { + { if( gridType == BINARY_GRID ) return binaryInitializeDisk( initialValue ); else if( gridType == ESRI_GRID ) @@ -235,10 +234,10 @@ bool fGrid::initialize( const char * cfilename, fHeader header, float initialVal #pragma optimize("", off) bool fGrid::close() -{ +{ if( isInRam == true ) - { + { dealloc(); return true; } @@ -256,37 +255,37 @@ bool fGrid::close() // This change is made in sGrid, dGrid, fGrid, and lGrid. bool result = true; - if( file_in_out != NULL ) + if( file_in_out != nullptr) { fclose( file_in_out ); - file_in_out = NULL; + file_in_out = nullptr; } - if( row_one != NULL ) + if( row_one != nullptr) { delete [] row_one; - row_one = NULL; + row_one = nullptr; } - if( row_two != NULL ) + if( row_two != nullptr) { delete [] row_two; - row_two = NULL; + row_two = nullptr; } - if( row_three != NULL ) + if( row_three != nullptr) { delete [] row_three; - row_three = NULL; + row_three = nullptr; } - if( row_buf1 != NULL ) - { CFree1((char *)row_buf1); - row_buf1 = NULL; + if( row_buf1 != nullptr) + { CFree1(static_cast(row_buf1)); + row_buf1 = nullptr; } - if( row_buf2 != NULL ) - { CFree1((char *)row_buf2); - row_buf2 = NULL; + if( row_buf2 != nullptr) + { CFree1(static_cast(row_buf2)); + row_buf2 = nullptr; } - if( row_buf3 != NULL ) - { CFree1((char *)row_buf3); - row_buf3 = NULL; + if( row_buf3 != nullptr) + { CFree1(static_cast(row_buf3)); + row_buf3 = nullptr; } if( grid_layer >= 0 ) { - if( celllyrclose != NULL ) + if( celllyrclose != nullptr) celllyrclose(grid_layer); grid_layer = -1; } @@ -324,9 +323,9 @@ bool fGrid::save( const char * cfilename, GRID_TYPE GridType, void (*callback)(i } } else - { + { if( filename.GetLength() <= 0 ) - return writeDiskToDisk(); + return writeDiskToDisk(); //Convert the Grid else { if( GridType == USE_EXTENSION ) @@ -339,7 +338,7 @@ bool fGrid::save( const char * cfilename, GRID_TYPE GridType, void (*callback)(i gridFilename += "\\"; } - + if( GridType == ASCII_GRID ) { if ( asciiSaveAs( filename, callback ) ) @@ -378,9 +377,9 @@ inline float fGrid::getValue( int Column, int Row ) if( inGrid( Column, Row ) ) { if( isInRam ) - return data[Row][Column]; + return data[Row][Column]; else - return getValueDisk( Column, Row ); + return getValueDisk( Column, Row ); } else { lastErrorCode = tkINDEX_OUT_OF_BOUNDS; @@ -397,14 +396,14 @@ inline float fGrid::getValueDisk( int Column, int Row ) return esriGetValueDisk( Column, Row ); else if( gridType == SDTS_GRID ) return gridHeader.getNodataValue(); - + return gridHeader.getNodataValue(); } inline void fGrid::setValue( int Column, int Row, float Value ) -{ +{ if( inGrid( Column, Row ) ) - { + { if( max == gridHeader.getNodataValue() ) max = Value; else if( Value > max && Value != gridHeader.getNodataValue() ) @@ -422,7 +421,7 @@ inline void fGrid::setValue( int Column, int Row, float Value ) if( isInRam ) data[Row][Column] = Value; else - setValueDisk( Column, Row, Value ); + setValueDisk( Column, Row, Value ); } else lastErrorCode = tkINDEX_OUT_OF_BOUNDS; @@ -436,15 +435,15 @@ inline void fGrid::setValueDisk( int Column, int Row, float Value ) else if( gridType == ESRI_GRID ) esriSetValueDisk( Column, Row, Value ); else if( gridType == SDTS_GRID ) - return; + return; } void fGrid::dealloc() -{ if( isInRam && data != NULL ) +{ if( isInRam && data != nullptr) { for( int y = 0; y < gridHeader.getNumberRows(); y++ ) - delete [] data[y]; - delete [] data; - data = NULL; + delete [] data[y]; + delete [] data; + data = nullptr; } gridHeader.setNumberRows( 0 ); gridHeader.setNumberCols( 0 ); @@ -457,15 +456,15 @@ void fGrid::alloc() { if( gridHeader.getNumberCols() > 0 && gridHeader.getNumberRows() > 0 ) { - if (data != NULL) + if (data != nullptr) { delete [] data; - data = NULL; + data = nullptr; } data = new float *[gridHeader.getNumberRows()]; for( int y = 0; y < gridHeader.getNumberRows(); y++ ) - data[y] = new float[gridHeader.getNumberCols()]; - } + data[y] = new float[gridHeader.getNumberCols()]; + } } } @@ -475,7 +474,7 @@ inline fHeader fGrid::getHeader() } void fGrid::setHeader( fHeader h ) -{ +{ //Don't allow the Rows and Columns to Change gridHeader.setDx( h.getDx() ); gridHeader.setDy( h.getDy() ); @@ -502,9 +501,9 @@ void fGrid::CellToProj( long column, long row, double & x, double & y ) inline int fGrid::round( double d ) { if( ceil(d) - d <= .5 ) - return (int)ceil(d); + return static_cast(ceil(d)); else - return (int)floor(d); + return static_cast(floor(d)); } void fGrid::clear(float clearValue) @@ -515,7 +514,7 @@ void fGrid::clear(float clearValue) int nrows= gridHeader.getNumberRows(); for( int j = 0; j < nrows; j++ ) { for( int i = 0; i < ncols; i++ ) - data[j][i] = clearValue; + data[j][i] = clearValue; } } else @@ -656,11 +655,11 @@ GRID_TYPE fGrid::getGridType( const char * filename ) { GRID_TYPE grid_type = INVALID_GRID_TYPE; - if( filename != NULL && _tcslen( filename ) > 0 ) + if( filename != nullptr && _tcslen( filename ) > 0 ) { char * clean_filename = new char[_tcslen( filename ) + 1]; strcpy( clean_filename, filename ); - for( int i = _tcslen( clean_filename ) - 1; i >= 0; i-- ) + for( int i = static_cast(_tcslen( clean_filename )) - 1; i >= 0; i-- ) { if( clean_filename[i] == '\\' || clean_filename[i] == '/' ) clean_filename[i] = '\0'; else @@ -691,7 +690,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) cff.Close(); //File does not exist so parse it out - int length = _tcslen(filename ); + int length = static_cast(_tcslen(filename )); bool foundPeriod = false; for( int e = length-1; e >= 0; e-- ) { if( filename[e] == '\\' || filename[e] == '/' ) @@ -761,7 +760,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) ///\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ bool fGrid::asciiReadDiskToMemory( void (*callback)(int number, const char * message ) ) - { + { ifstream in(gridFilename); if( !in ) @@ -770,7 +769,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) } else { asciiReadHeader( in ); - + int percent = 0; long num_read = 0; double total = gridHeader.getNumberRows()*gridHeader.getNumberCols(); @@ -785,21 +784,21 @@ GRID_TYPE fGrid::getGridType( const char * filename ) return false; } else - { if( callback != NULL ) + { if( callback != nullptr) callback( 0, "Allocating and Initializing Memory" ); alloc(); } - + for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { num_read++; if( !in ) { dealloc(); - return false; + return false; } - in>>data[j][i]; + in>>data[j][i]; if( min == nodata ) { min = data[j][i]; max = data[j][i]; @@ -813,14 +812,14 @@ GRID_TYPE fGrid::getGridType( const char * filename ) max = data[j][i]; } } - - if( callback != NULL ) + + if( callback != nullptr) { int newpercent = (int)(((num_read)/total)*100); if( newpercent > percent ) { percent = newpercent; - callback( percent, "Reading Ascii Grid" ); + callback( percent, "Reading Ascii Grid" ); } - } + } } } asciiReadFooter( in ); @@ -831,7 +830,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) bool fGrid::asciiReadDiskToDisk( void(*callback)(int number, const char * message ) ) { isInRam = true; - return asciiReadDiskToMemory( callback ); + return asciiReadDiskToMemory( callback ); } bool fGrid::asciiWriteMemoryToDisk( void(*callback)(int number, const char * message ) ) @@ -855,21 +854,21 @@ GRID_TYPE fGrid::getGridType( const char * filename ) out<((num_written / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Writing Ascii Grid" ); - } + } } } out<>dy; gridHeader.setDy( dy ); return true; @@ -1064,7 +1063,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) return false; } else - { + { asciiWriteHeader(out); double total = gridHeader.getNumberRows()*gridHeader.getNumberCols(); int percent = 0; @@ -1073,16 +1072,16 @@ GRID_TYPE fGrid::getGridType( const char * filename ) for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { num_written++; - + out< percent ) { percent = newpercent; callback( percent, "Writing Ascii Grid" ); - } + } } } out<(((num_read) / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Reading Binary Grid" ); } } - + } - } - + } + fclose(in); - return true; + return true; } - } bool fGrid::binaryReadDiskToDisk() - { + { file_in_out = fopen( gridFilename, "r+b" ); if( !file_in_out ) @@ -1191,15 +1189,15 @@ GRID_TYPE fGrid::getGridType( const char * filename ) return false; } else - { - binaryReadHeader(file_in_out); + { + binaryReadHeader(file_in_out); if( gridHeader.getNumberCols() < 0 || gridHeader.getNumberRows() < 0 || gridHeader.getDx() < 0 || gridHeader.getDy() < 0 || data_type != FLOAT_TYPE ) { dealloc(); fclose( file_in_out ); - file_in_out = NULL; + file_in_out = nullptr; lastErrorCode = tkINCOMPATIBLE_DATA_TYPE; return false; } @@ -1252,27 +1250,27 @@ GRID_TYPE fGrid::getGridType( const char * filename ) findNewMax = findNewMin = true; if( gridHeader.getNumberCols() > 0 ) - { + { row_one = new float[gridHeader.getNumberCols()]; row_two = new float[gridHeader.getNumberCols()]; row_three = new float[gridHeader.getNumberCols()]; - binaryBufferRows( 1 ); - } - return true; - } + binaryBufferRows( 1 ); + } + return true; + } } bool fGrid::binaryWriteMemoryToDisk( void(*callback)(int number, const char * message ) ) - { + { FILE * out = fopen( gridFilename, "wb" ); - + if( !out ) { lastErrorCode = tkCANT_CREATE_FILE; return false; } else - { + { binaryWriteHeader(out); double total = gridHeader.getNumberRows() * gridHeader.getNumberCols(); int percent = 0; @@ -1281,22 +1279,22 @@ GRID_TYPE fGrid::getGridType( const char * filename ) for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { num_written++; - + fwrite( &data[j][i],sizeof(float),1,out); - if( callback != NULL ) + if( callback != nullptr) { - int newpercent = (int)((num_written/total)*100); + int newpercent = static_cast((num_written / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Binary Grid Write"); - } + } } - } + } } fclose( out ); - return true; - } + return true; + } } bool fGrid::binaryWriteDiskToDisk() @@ -1307,12 +1305,11 @@ GRID_TYPE fGrid::getGridType( const char * filename ) { rewind( file_in_out ); binaryWriteHeader(file_in_out); return true; - } - + } } bool fGrid::binaryInitializeDisk( float initialValue ) - { + { file_in_out = fopen( gridFilename, "w+b" ); if( !file_in_out ) @@ -1320,20 +1317,20 @@ GRID_TYPE fGrid::getGridType( const char * filename ) return false; } else - { + { binaryWriteHeader(file_in_out); file_position_beg_of_data = ftell( file_in_out); - + for( int j = gridHeader.getNumberRows() - 1; j >= 0; j-- ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) - { - fwrite( &initialValue,sizeof(float),1,file_in_out); - } + { + fwrite( &initialValue,sizeof(float),1,file_in_out); + } } - + min = initialValue; max = initialValue; - + current_row = 0; row_one = new float[gridHeader.getNumberCols()]; row_two = new float[gridHeader.getNumberCols()]; @@ -1345,11 +1342,11 @@ GRID_TYPE fGrid::getGridType( const char * filename ) row_three[i] = initialValue; } } - return true; + return true; } void fGrid::binaryReadHeader( FILE * in ) - { + { rewind(in); long ncols; fread( &ncols, sizeof(int),1,in); @@ -1378,7 +1375,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) fread( &data_type, sizeof(DATA_TYPE),1,in); float nodata_value; - fread( &nodata_value, sizeof(float),1,in); + fread( &nodata_value, sizeof(float),1,in); gridHeader.setNodataValue( nodata_value ); char * projection = new char[MAX_STRING_LENGTH + 1]; @@ -1417,7 +1414,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) if( strlen( projection ) > 0 ) fwrite( projection, sizeof(char), strlen(projection),out); if( strlen( projection ) < MAX_STRING_LENGTH ) - { int size_of_pad = MAX_STRING_LENGTH - strlen(projection); + { int size_of_pad = MAX_STRING_LENGTH - static_cast(strlen(projection)); char * pad = new char[size_of_pad]; for( int p = 0; p < size_of_pad; p++ ) pad[p] = 0; @@ -1431,7 +1428,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) if( strlen( notes ) > 0 ) fwrite( notes, sizeof(char), strlen(notes), out); if( strlen( notes ) < MAX_STRING_LENGTH ) - { int size_of_pad = MAX_STRING_LENGTH - strlen(notes); + { int size_of_pad = MAX_STRING_LENGTH - static_cast(strlen(notes)); char * pad = new char[size_of_pad]; for( int p = 0; p < size_of_pad; p++ ) pad[p] = 0; @@ -1452,7 +1449,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) else { binaryBufferRows( Row ); return row_two[ Column ]; - } + } } void fGrid::binarySetValueDisk( int Column, int Row, float Value ) @@ -1464,16 +1461,16 @@ GRID_TYPE fGrid::getGridType( const char * filename ) else { if( fwrite( &Value, sizeof(float), 1, file_in_out ) < 1 ) - {} + {} else { if( Row == current_row - 1 ) row_one[ Column ] = Value; else if( Row == current_row ) row_two[ Column ] = Value; else if( Row == current_row + 1 ) - row_three[ Column ] = Value; + row_three[ Column ] = Value; } - } + } } void fGrid::binaryClearDisk(float clearValue) @@ -1481,14 +1478,14 @@ GRID_TYPE fGrid::getGridType( const char * filename ) if( fseek( file_in_out, file_position_beg_of_data, SEEK_SET ) == -1L ) return; else - { + { for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { if( fwrite( &clearValue, sizeof(float), 1, file_in_out ) < 1 ) return; } - } - } + } + } } void fGrid::binaryBufferRows( int center_row ) @@ -1570,15 +1567,15 @@ GRID_TYPE fGrid::getGridType( const char * filename ) value = getValue( i, j ); fwrite( &value,sizeof(float),1,out); - if( callback != NULL ) + if( callback != nullptr) { int newpercent = (int)((num_written/total)*100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Binary Grid Write"); - } + } } - } + } } fclose( out ); @@ -1619,32 +1616,32 @@ GRID_TYPE fGrid::getGridType( const char * filename ) #pragma optimize("", off) bool fGrid::esriReadDiskToMemory( void (*callback)(int number, const char * message ) ) { - if( celllayeropen == NULL || - celllyrclose == NULL || - bndcellread == NULL || - privateaccesswindowset == NULL || - privatewindowcols == NULL || - privatewindowrows == NULL || - getwindowrow == NULL || - getmissingfloat == NULL ) + if( celllayeropen == nullptr || + celllyrclose == nullptr || + bndcellread == nullptr || + privateaccesswindowset == nullptr || + privatewindowcols == nullptr || + privatewindowrows == nullptr || + getwindowrow == nullptr || + getmissingfloat == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; } - double csize; + double csize; double bndbox[4]; double adjbndbox[4]; float nodata = -1; int cell_type; - char * fname = new char[_MAX_PATH+1]; + char * fname = new char[_MAX_PATH+1]; if( GetShortPathName(gridFilename,fname,_MAX_PATH) == 0 ) strcpy( fname, gridFilename ); grid_layer = celllayeropen(fname,READONLY,ROWIO,&cell_type,&csize); if( grid_layer >= 0 ) - { + { //Get the bounding box of the input cell layer //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner if( bndcellread(fname,bndbox) < 0 ) @@ -1654,11 +1651,11 @@ GRID_TYPE fGrid::getGridType( const char * filename ) grid_layer = -1; lastErrorCode = tkESRI_INVALID_BOUNDS; return false; - } - + } + //Need to find cell_type if( cell_type == CELLFLOAT ) - { getmissingfloat(&float_null); + { getmissingfloat(&float_null); nodata = float_null; } if( cell_type == CELLINT ) @@ -1667,7 +1664,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) celllyrclose(grid_layer); grid_layer = -1; lastErrorCode = tkINVALID_GRID_FILE_TYPE; - return false; + return false; } gridHeader.setXllcenter( bndbox[0] + .5*csize ); @@ -1676,7 +1673,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) gridHeader.setDy( csize ); gridHeader.setNodataValue( nodata ); - //Set the Window to the output bounding box and cellsize + //Set the Window to the output bounding box and cellsize if( privateaccesswindowset(grid_layer,bndbox,csize,adjbndbox) < 0) { dealloc(); //Close handle @@ -1685,7 +1682,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) lastErrorCode = tkESRI_ACCESS_WINDOW_SET; return false; } - + //Get the number of rows and columns in the window gridHeader.setNumberCols( privatewindowcols(grid_layer) ); gridHeader.setNumberRows( privatewindowrows(grid_layer) ); @@ -1703,9 +1700,9 @@ GRID_TYPE fGrid::getGridType( const char * filename ) alloc(); //Now copy row major into array - //Allocate row buffer + //Allocate row buffer row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( row_buf1 == NULL ) + if ( row_buf1 == nullptr) { dealloc(); //Close handle celllyrclose(grid_layer); @@ -1723,9 +1720,9 @@ GRID_TYPE fGrid::getGridType( const char * filename ) max = nodata; for ( int j = 0; j < gridHeader.getNumberRows(); j++) { - getwindowrow(grid_layer, j, (CELLTYPE*)row_buf1); + getwindowrow(grid_layer, j, static_cast(row_buf1)); - register float *buf = (float *)row_buf1; + register float *buf = static_cast(row_buf1); for( int i = 0; i < gridHeader.getNumberCols(); i++) { if( buf[i] == float_null ) @@ -1741,15 +1738,14 @@ GRID_TYPE fGrid::getGridType( const char * filename ) if( max == nodata ) max = buf[i]; else if( buf[i] > max ) - max = buf[i]; + max = buf[i]; } - } - + } - int newpercent = (int)((j/total)*100); + int newpercent = static_cast((j / total) * 100); if( newpercent > percent ) { percent = newpercent; - if( callback != NULL ) + if( callback != nullptr ) callback( percent, "Reading Esri Grid" ); } @@ -1757,52 +1753,52 @@ GRID_TYPE fGrid::getGridType( const char * filename ) //Free row buffer CFree1((char *)row_buf1); - row_buf1 = NULL; + row_buf1 = nullptr; //Close handle celllyrclose(grid_layer); grid_layer = -1; return true; - } + } else { dealloc(); grid_layer = -1; lastErrorCode = tkESRI_LAYER_OPEN; return false; - } + } } #pragma optimize("", on) #pragma optimize("", off) bool fGrid::esriReadDiskToDisk() - { + { //Check for the needed functions - if( bndcellread == NULL || - celllyrclose == NULL || - celllayeropen == NULL || - privateaccesswindowset == NULL || - privatewindowcols == NULL || - privatewindowrows == NULL || - getwindowrow == NULL || - getmissingfloat == NULL ) + if( bndcellread == nullptr || + celllyrclose == nullptr || + celllayeropen == nullptr || + privateaccesswindowset == nullptr || + privatewindowcols == nullptr || + privatewindowrows == nullptr || + getwindowrow == nullptr || + getmissingfloat == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; } - double csize; + double csize; double bndbox[4]; double adjbndbox[4]; float nodata = -1; int cell_type; - char * fname = new char[_MAX_PATH+1]; + char * fname = new char[_MAX_PATH+1]; if( GetShortPathName(gridFilename,fname,_MAX_PATH) == 0 ) strcpy( fname, gridFilename ); grid_layer = celllayeropen(fname,READWRITE,ROWIO,&cell_type,&csize); if( grid_layer >= 0 ) - { + { //Get the bounding box of the input cell layer //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner @@ -1828,7 +1824,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) grid_layer = -1; lastErrorCode = tkINVALID_GRID_FILE_TYPE; delete [] fname; - return false; + return false; } gridHeader.setXllcenter( bndbox[0] + .5*csize ); @@ -1837,7 +1833,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) gridHeader.setDy( csize ); gridHeader.setNodataValue( nodata ); - //Set the Window to the output bounding box and cellsize + //Set the Window to the output bounding box and cellsize if( privateaccesswindowset(grid_layer,bndbox,csize,adjbndbox) < 0) { dealloc(); //Close handle @@ -1862,11 +1858,11 @@ GRID_TYPE fGrid::getGridType( const char * filename ) return false; } - //Allocate row buffer + //Allocate row buffer row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - row_buf2 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - row_buf3 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( row_buf1 == NULL || row_buf2 == NULL || row_buf3 == NULL ) + row_buf2 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); + row_buf3 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); + if ( row_buf1 == nullptr || row_buf2 == nullptr || row_buf3 == nullptr) { dealloc(); //Close handle celllyrclose(grid_layer); @@ -1875,7 +1871,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) delete [] fname; return false; } - + //Find the min and max float nodata = gridHeader.getNodataValue(); min = nodata; @@ -1901,12 +1897,12 @@ GRID_TYPE fGrid::getGridType( const char * filename ) else if( buf[i] > max ) max = buf[i]; } - } - + } + } */ esriBufferRows( 0 ); delete [] fname; - return true; + return true; } else { dealloc(); @@ -1922,13 +1918,13 @@ GRID_TYPE fGrid::getGridType( const char * filename ) bool fGrid::esriWriteMemoryToDisk( void(*callback)(int number, const char * message ) ) { //Check the needed functions - if( celllyrclose == NULL || - celllyrexists == NULL || - celllayercreate == NULL || - griddelete == NULL || - privateaccesswindowset == NULL || - getmissingfloat == NULL || - putwindowrow == NULL ) + if( celllyrclose == nullptr || + celllyrexists == nullptr || + celllayercreate == nullptr || + griddelete == nullptr || + privateaccesswindowset == nullptr || + getmissingfloat == nullptr || + putwindowrow == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; @@ -1946,7 +1942,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) double adjbndbox[4]; char * fname = new char[gridFilename.GetLength()+1]; - strcpy( fname, gridFilename ); + strcpy( fname, gridFilename ); if( celllyrexists( fname ) != 0 ) griddelete( fname ); @@ -1960,20 +1956,20 @@ GRID_TYPE fGrid::getGridType( const char * filename ) if( privateaccesswindowset( grid_layer, bndbox, csize, adjbndbox) < 0 ) { celllyrclose(grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); grid_layer = -1; lastErrorCode = tkESRI_ACCESS_WINDOW_SET; return false; } - getmissingfloat(&float_null); + getmissingfloat(&float_null); - //Allocate row buffer - row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); + //Allocate row buffer + row_buf1 = reinterpret_cast(CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE))); if ( row_buf1 == NULL ) { celllyrclose(grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); grid_layer = -1; lastErrorCode = tkCANT_ALLOC_MEMORY; return false; @@ -1983,32 +1979,32 @@ GRID_TYPE fGrid::getGridType( const char * filename ) int percent = 0; float nodata = gridHeader.getNodataValue(); - register float *buf = (float *)row_buf1; + register float *buf = static_cast(row_buf1); for( int j = 0; j < gridHeader.getNumberRows(); j++) { for( int i = 0; i < gridHeader.getNumberCols(); i++) { - buf[i] = (float)data[j][i]; + buf[i] = data[j][i]; if(buf[i] == nodata) buf[i] = float_null; } - putwindowrowfloat( grid_layer, j, (float*)row_buf1); + putwindowrowfloat( grid_layer, j, static_cast(row_buf1)); int newpercent = (int)((j/total)*100); if( newpercent > percent ) { percent = newpercent; - if( callback != NULL ) + if( callback != nullptr) callback( percent, "Writing Esri Grid" ); } } - CFree1 ((char *)row_buf1); - row_buf1 = NULL; + CFree1 ((char *)row_buf1); + row_buf1 = nullptr; - //Close handle + //Close handle celllyrclose(grid_layer); grid_layer = -1; - return true; + return true; } #pragma optimize("", on) @@ -2020,13 +2016,13 @@ GRID_TYPE fGrid::getGridType( const char * filename ) #pragma optimize("", off) bool fGrid::esriInitializeDisk( float InitialValue ) { - if( celllyrexists == NULL || - celllyrclose == NULL || - griddelete == NULL || - celllayercreate == NULL || - privateaccesswindowset == NULL || - putwindowrow == NULL || - getmissingfloat == NULL ) + if( celllyrexists == nullptr || + celllyrclose == nullptr || + griddelete == nullptr || + celllayercreate == nullptr || + privateaccesswindowset == nullptr || + putwindowrow == nullptr || + getmissingfloat == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; @@ -2070,31 +2066,31 @@ GRID_TYPE fGrid::getGridType( const char * filename ) if( privateaccesswindowset( grid_layer, bndbox, csize, adjbndbox) < 0 ) { celllyrclose(grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); grid_layer = -1; lastErrorCode = tkESRI_ACCESS_WINDOW_SET; delete [] fname; return false; } - //Allocate row buffer + //Allocate row buffer row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if( row_buf1 == NULL ) + if( row_buf1 == nullptr) { - celllyrclose(grid_layer); + celllyrclose(grid_layer); if( celllyrexists( fname ) ) griddelete( fname ); grid_layer = -1; lastErrorCode = tkCANT_ALLOC_MEMORY; delete [] fname; return false; - } + } - float nodata = gridHeader.getNodataValue(); + float nodata = gridHeader.getNodataValue(); max = nodata; min = nodata; - register float *buf = (float *)row_buf1; + register float *buf = (float *)row_buf1; if( InitialValue == nodata ) { @@ -2107,22 +2103,22 @@ GRID_TYPE fGrid::getGridType( const char * filename ) } for( int j = 0; j < gridHeader.getNumberRows(); j++) - putwindowrow( grid_layer, j, (CELLTYPE*)row_buf1); - - //Close and Reopen so VAT Table is Written + putwindowrow( grid_layer, j, static_cast(row_buf1)); + + //Close and Reopen so VAT Table is Written celllyrclose(grid_layer); grid_layer = -1; CFree1 ((char *)row_buf1); - row_buf1 = NULL; + row_buf1 = nullptr; delete [] fname; - return esriReadDiskToDisk(); + return esriReadDiskToDisk(); } #pragma optimize("", on) #pragma optimize("", off) float fGrid::esriGetValueDisk( int Column, int Row ) - { + { if( Column < 0 || Column >= gridHeader.getNumberCols() ) return gridHeader.getNodataValue(); if( Row < 0 || Row >= gridHeader.getNumberRows() ) @@ -2130,28 +2126,27 @@ GRID_TYPE fGrid::getGridType( const char * filename ) if( Row == current_row - 1 ) { - if( ((float *)row_buf1)[Column] == float_null ) + if( static_cast(row_buf1)[Column] == float_null ) return gridHeader.getNodataValue(); - return float((((float *)row_buf1)[Column])); + return static_cast(static_cast(row_buf1)[Column]); } else if( Row == current_row ) - { - if( ((float *)row_buf2)[Column] == float_null ) + { + if( static_cast(row_buf2)[Column] == float_null ) return gridHeader.getNodataValue(); - return float((((float *)row_buf2)[Column])); + return float((static_cast(row_buf2)[Column])); } else if( Row == current_row + 1 ) - { - if( ((float *)row_buf3)[Column] == float_null ) + { + if( static_cast(row_buf3)[Column] == float_null ) return gridHeader.getNodataValue(); - return float((((float *)row_buf3)[Column])); + return static_cast(static_cast(row_buf3)[Column]); } else { esriBufferRows( Row ); - - if( ((float *)row_buf2)[Column] == float_null ) + if( static_cast(row_buf2)[Column] == float_null ) return gridHeader.getNodataValue(); - return float((((float *)row_buf2)[Column])); + return static_cast(static_cast(row_buf2)[Column]); } return gridHeader.getNodataValue(); @@ -2161,7 +2156,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) #pragma optimize("", off) void fGrid::esriSetValueDisk( int Column, int Row, float Value ) { - if( putwindowrow == NULL ) + if( putwindowrow == nullptr) return; float value = Value; @@ -2172,38 +2167,38 @@ GRID_TYPE fGrid::getGridType( const char * filename ) if( value == gridHeader.getNodataValue() ) value = float_null; - register float *buf = (float *)row_buf1; + register float *buf = static_cast(row_buf1); buf[Column] = value; - putwindowrow( grid_layer, Row, (CELLTYPE*)row_buf1); + putwindowrow( grid_layer, Row, static_cast(row_buf1)); } else if( Row == current_row ) { if( value == gridHeader.getNodataValue() ) value = float_null; - register float *buf = (float *)row_buf2; + register float *buf = static_cast(row_buf2); buf[Column] = value; - putwindowrow( grid_layer, Row, (CELLTYPE*)row_buf2); + putwindowrow( grid_layer, Row, static_cast(row_buf2)); } else if( Row == current_row + 1 ) { if( value == gridHeader.getNodataValue() ) value = float_null; - register float *buf = (float *)row_buf3; + register float *buf = static_cast(row_buf3); buf[Column] = value; - putwindowrow( grid_layer, Row, (CELLTYPE*)row_buf3); - } + putwindowrow( grid_layer, Row, static_cast(row_buf3)); + } } #pragma optimize("", on) #pragma optimize("", off) void fGrid::esriClearDisk(float clearValue) { - if( putwindowrow == NULL ) + if( putwindowrow == nullptr) return; - register float *buf = (float *)row_buf1; + register float *buf = static_cast(row_buf1); for( int j = 0; j < gridHeader.getNumberRows(); j++) { float val = clearValue; @@ -2214,32 +2209,32 @@ GRID_TYPE fGrid::getGridType( const char * filename ) { buf[i]=val; } - putwindowrow( grid_layer, j, (CELLTYPE*)row_buf1); + putwindowrow( grid_layer, j, static_cast(row_buf1)); } for( int i = 0; i < gridHeader.getNumberCols(); i++) { buf[i]=clearValue; - } + } - esriBufferRows( 0 ); + esriBufferRows( 0 ); } #pragma optimize("", on) #pragma optimize("", off) void fGrid::esriBufferRows( int center_row ) { - if( getwindowrow == NULL ) + if( getwindowrow == nullptr) { register float *ibuf; for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { - ibuf = (float *)row_buf1; + ibuf = static_cast(row_buf1); ibuf[i] = float_null; - ibuf = (float *)row_buf2; + ibuf = static_cast(row_buf2); ibuf[i] = float_null; - ibuf = (float *)row_buf3; - ibuf[i] = float_null; - } + ibuf = static_cast(row_buf3); + ibuf[i] = float_null; + } return; } @@ -2249,7 +2244,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) if( gridHeader.getNumberRows() >= center_row -1 && center_row - 1 >= 0 ) { - getwindowrow(grid_layer, center_row - 1, (CELLTYPE*)row_buf1); + getwindowrow(grid_layer, center_row - 1, static_cast(row_buf1)); nd_fill_one = false; } else @@ -2257,7 +2252,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) if( gridHeader.getNumberRows() >= center_row && center_row >= 0 ) { - getwindowrow(grid_layer, center_row, (CELLTYPE*)row_buf2); + getwindowrow(grid_layer, center_row, static_cast(row_buf2)); nd_fill_two = false; } else @@ -2265,7 +2260,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) if( gridHeader.getNumberRows() >= center_row + 1 && center_row + 1 >= 0 ) { - getwindowrow(grid_layer, center_row + 1, (CELLTYPE*)row_buf3); + getwindowrow(grid_layer, center_row + 1, static_cast(row_buf3)); nd_fill_three = false; } else @@ -2281,18 +2276,18 @@ GRID_TYPE fGrid::getGridType( const char * filename ) for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { if( nd_fill_one ) - { ibuf = (float *)row_buf1; + { ibuf = static_cast(row_buf1); ibuf[i] = float_null; } if( nd_fill_two ) - { ibuf = (float *)row_buf2; + { ibuf = static_cast(row_buf2); ibuf[i] = float_null; } if( nd_fill_three ) - { ibuf = (float *)row_buf3; + { ibuf = static_cast(row_buf3); ibuf[i] = float_null; - } - } + } + } } } #pragma optimize("", on) @@ -2302,20 +2297,20 @@ GRID_TYPE fGrid::getGridType( const char * filename ) { long temp_grid_layer = -1; //Check the needed functions - if( celllyrclose == NULL || - celllyrexists == NULL || - celllayercreate == NULL || - griddelete == NULL || - privateaccesswindowset == NULL || - getmissingfloat == NULL || - putwindowrow == NULL ) + if( celllyrclose == nullptr || + celllyrexists == nullptr || + celllayercreate == nullptr || + griddelete == nullptr || + privateaccesswindowset == nullptr || + getmissingfloat == nullptr || + putwindowrow == nullptr) { temp_grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; } int cell_type = CELLFLOAT; - + double csize = gridHeader.getDx(); //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner double bndbox[4]; @@ -2324,12 +2319,12 @@ GRID_TYPE fGrid::getGridType( const char * filename ) bndbox[2] = gridHeader.getXllcenter() + gridHeader.getNumberCols()*gridHeader.getDx() - gridHeader.getDx()*.5; bndbox[3] = gridHeader.getYllcenter() + gridHeader.getNumberRows()*gridHeader.getDy() - gridHeader.getDy()*.5; double adjbndbox[4]; - + char * fname = new char[filename.GetLength()+1]; - strcpy( fname, filename ); + strcpy( fname, filename ); if( celllyrexists( fname ) != 0 ) griddelete( fname ); - + temp_grid_layer = celllayercreate( fname, WRITEONLY, ROWIO, cell_type, csize, bndbox); if( temp_grid_layer < 0 ) { temp_grid_layer = -1; @@ -2341,7 +2336,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) if( privateaccesswindowset( temp_grid_layer, bndbox, csize, adjbndbox) < 0 ) { celllyrclose(temp_grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); temp_grid_layer = -1; lastErrorCode = tkESRI_ACCESS_WINDOW_SET; delete [] fname; @@ -2349,13 +2344,13 @@ GRID_TYPE fGrid::getGridType( const char * filename ) } getmissingfloat(&float_null); - - //Allocate row buffer + + //Allocate row buffer void * temp_row_buf = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( temp_row_buf == NULL ) + if ( temp_row_buf == nullptr) { celllyrclose(temp_grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); temp_grid_layer = -1; lastErrorCode = tkCANT_ALLOC_MEMORY; delete [] fname; @@ -2366,35 +2361,35 @@ GRID_TYPE fGrid::getGridType( const char * filename ) int percent = 0; float nodata = gridHeader.getNodataValue(); - register float *buf = (float *)temp_row_buf; + register float *buf = static_cast(temp_row_buf); for( int j = 0; j < gridHeader.getNumberRows(); j++) { for( int i = 0; i < gridHeader.getNumberCols(); i++) { - buf[i] = (float)getValue( i, j ); + buf[i] = getValue( i, j ); if(buf[i] == nodata) buf[i] = float_null; } - putwindowrow( temp_grid_layer, j, (CELLTYPE*)temp_row_buf); + putwindowrow( temp_grid_layer, j, static_cast(temp_row_buf)); - int newpercent = (int)((j/total)*100); + int newpercent = static_cast((j / total) * 100); if( newpercent > percent ) { percent = newpercent; - if( callback != NULL ) + if( callback != nullptr) callback( percent, "Writing Esri Grid" ); } } - CFree1 ((char *)temp_row_buf); - temp_row_buf = NULL; + CFree1 (static_cast(temp_row_buf)); + temp_row_buf = nullptr; if( isInRam == true ) { gridFilename = filename; - //Close handle + //Close handle celllyrclose(temp_grid_layer); temp_grid_layer = -1; delete [] fname; - return true; + return true; } else { celllyrclose(temp_grid_layer); @@ -2425,9 +2420,9 @@ GRID_TYPE fGrid::getGridType( const char * filename ) //Initialize the grid strcpy( file_name, gridFilename ); - //Find the byte order of the machine + //Find the byte order of the machine g123order(&order); - + char * fname = new char[ gridFilename.GetLength() + 1]; strcpy( fname, gridFilename ); long fillvalue; @@ -2436,9 +2431,9 @@ GRID_TYPE fGrid::getGridType( const char * filename ) delete [] fname; return false; } - + alloc(); - + cells_out( gridFilename, status, fillvalue, callback ); //Check for -255 Value that can be produced on extraction @@ -2446,16 +2441,16 @@ GRID_TYPE fGrid::getGridType( const char * filename ) float value = gridHeader.getNodataValue(); double average = 0; int cnt = 0; - + for( int row = 0; row < gridHeader.getNumberRows(); row++ ) - { + { for( int column = 0; column < gridHeader.getNumberCols(); column++ ) - { + { value = getValue( column, row ); average = 0; cnt = 0; if( value == -255 ) - { + { float up = getValue( column, row + 1 ); if( up != nodata_value && up != -255 ) { average += up; @@ -2502,11 +2497,11 @@ GRID_TYPE fGrid::getGridType( const char * filename ) else average = nodata_value; - setValue( column, row, (float)average ); + setValue( column, row, static_cast(average) ); } } } - + delete [] fname; return true; } @@ -2523,12 +2518,12 @@ GRID_TYPE fGrid::getGridType( const char * filename ) dem_head(status); long voidvalue; cell_range(status, voidvalue, fillvalue); - h.setNodataValue( (float)voidvalue ); + h.setNodataValue( static_cast(voidvalue) ); double xhrs, yhrs; get_iref(xhrs, yhrs); - h.setDx( (int)xhrs ); - h.setDy( (int)xhrs ); + h.setDx( static_cast(xhrs) ); + h.setDy( static_cast(xhrs) ); get_xref(); @@ -2567,7 +2562,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) { int len,j; //parse out base_name - len = strlen(file_name); + len = static_cast(strlen(file_name)); for(j=0;j(vscale * u.f); } else { - li = (long)nodata_value; + li = static_cast(nodata_value); } //BIAS FOR ELEVATION if( li < -1000 ) - li = (long)nodata_value; + li = static_cast(nodata_value); //Set the cell value if(li != nodata_value && li != fillvalue) { if(fom == 'f') { - li = (long)(li/3.2808); + li = static_cast(li / 3.2808); } if( li == 32767 || li == -32767 ) setValue( i, j, -255 ); else - setValue( i, j, (float)li ); + setValue( i, j, static_cast(li) ); - int newpercent = (int)((cnt/total)*100); + int newpercent = static_cast((cnt / total) * 100); if( newpercent > percent ) { percent = newpercent; if( callback ) @@ -3463,7 +3457,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) } else if (strstr(frmts, "R")) { - sadr_x = (long) atof(string); + sadr_x = static_cast(atof(string)); } } else if (!strcmp (tag, "SADR") && !strcmp (descr, "Y")) @@ -3480,9 +3474,9 @@ GRID_TYPE fGrid::getGridType( const char * filename ) } else if (strstr(frmts, "R")) { - sadr_y = (long) atof(string); + sadr_y = static_cast(atof(string)); } - } + } } while (status != 4); /* Break out of loop at end of file */ done: stat2 = end123file (&fpin); @@ -3504,7 +3498,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) char data[1000]; FILE* fp; int len; - char* index = NULL; + char* index = nullptr; baseAndId(); strcpy (file_name,base_name); @@ -3514,7 +3508,7 @@ GRID_TYPE fGrid::getGridType( const char * filename ) if(!fp) return 0; - len = fread(data,sizeof(char),MAX-1,fp); + len = static_cast(fread(data,sizeof(char),MAX-1,fp)); fclose(fp); data[MAX-1] = '\0'; diff --git a/src/Grid/fip/a_toe.cpp b/src/Grid/fip/a_toe.cpp index 8af81a3c..c04aa4c9 100644 --- a/src/Grid/fip/a_toe.cpp +++ b/src/Grid/fip/a_toe.cpp @@ -311,11 +311,11 @@ int a123toe(char *string) /* DO FOR EACH CHARACTER IN STRING */ - len = _tcslen(string); + len = static_cast(_tcslen(string)); for (i=0;i(string[i])]; } diff --git a/src/Grid/fip/c_dddir.cpp b/src/Grid/fip/c_dddir.cpp index f537da23..7149dcf2 100644 --- a/src/Grid/fip/c_dddir.cpp +++ b/src/Grid/fip/c_dddir.cpp @@ -178,7 +178,7 @@ int cmp123dddir() int status; /* IF DD_HD NEXT IS NULL, RETURN FAILURE */ - if (cur_fm->dd_hd->next == NULL) return(0); + if (cur_fm->dd_hd->next == nullptr) return(0); /* CALL VER123DDTAG() TO VERIFY TAG ORDER IN DATA DESCRIPTIVE RECORD */ if (!ver123ddtag()) return(0); @@ -187,7 +187,7 @@ int cmp123dddir() cur_fm->cur_dd = cur_fm->dd_hd->next; /* WHILE CUR_DD NOT NULL DO */ - while(cur_fm->cur_dd != NULL) { + while(cur_fm->cur_dd != nullptr) { /* SET SUBFIELD STATE TO FIELD CONTROL SUBFIELD */ cur_fm->sf_state_dd = 1; @@ -196,7 +196,7 @@ int cmp123dddir() if (!rd123ddfld(cur_fm->fp,tag,glb_str2,&status)) return(0); /* SET FD_LEN TO LENGTH OF THE STRING RETURNED FROM RD123DDFLD() */ - cur_fm->cur_dd->fd_len = _tcslen(glb_str2); + cur_fm->cur_dd->fd_len = static_cast(_tcslen(glb_str2)); /* SET FD_POS TO POS */ cur_fm->cur_dd->fd_pos = pos; diff --git a/src/Grid/fip/c_ddlead.cpp b/src/Grid/fip/c_ddlead.cpp index 1227b058..13152a64 100644 --- a/src/Grid/fip/c_ddlead.cpp +++ b/src/Grid/fip/c_ddlead.cpp @@ -236,7 +236,7 @@ int cmp123ddlead() cur_fm->cur_dd = cur_fm->dd_hd; /* WHILE CUR_DD NEXT NOT NULL DO */ - while(cur_fm->cur_dd->next != NULL) { + while(cur_fm->cur_dd->next != nullptr) { /* SET CUR_DD TO CUR_DD NEXT */ cur_fm->cur_dd = cur_fm->cur_dd->next; @@ -245,21 +245,21 @@ int cmp123ddlead() i123toa(cur_fm->cur_dd->fd_len,tmp_str); /* IF NUMBER OF CHARACTERS MAKING UP FD_LEN IS LARGER THAN S_FDLEN */ - if ((tmp_len = _tcslen(tmp_str)) > cur_fm->dl_hd->s_fdlen) { + if ((tmp_len = static_cast(_tcslen(tmp_str))) > cur_fm->dl_hd->s_fdlen) { /* SET S_FDLEN TO NUMBER OF CHARACTERS IN FD_LEN */ cur_fm->dl_hd->s_fdlen = tmp_len; } /* IF NUMBER OF CHARACTERS MAKING UP FD_CNTRL LARGER THAN FD_CNTRL_L */ - if ((tmp_len = _tcslen(cur_fm->cur_dd->fd_cntrl)) > cur_fm->dl_hd->fd_cntrl_l) { + if ((tmp_len = static_cast(_tcslen(cur_fm->cur_dd->fd_cntrl))) > cur_fm->dl_hd->fd_cntrl_l) { /* SET FD_CNTRL_L TO NUMBER OF CHARACTERS IN FD_CNTRL */ cur_fm->dl_hd->fd_cntrl_l = tmp_len; } /* IF NUMBER OF CHARACTERS IN TAG EXCEED S_TAG */ - if ((tmp_len = _tcslen(cur_fm->cur_dd->tag)) > cur_fm->dl_hd->s_tag) { + if ((tmp_len = static_cast(_tcslen(cur_fm->cur_dd->tag))) > cur_fm->dl_hd->s_tag) { /* SET S_TAG TO NUMBER OF CHARACTERS */ cur_fm->dl_hd->s_tag = tmp_len; @@ -281,7 +281,7 @@ int cmp123ddlead() { LAST FIELD IN DD } */ i123toa(cur_fm->cur_dd->fd_pos,tmp_str); - cur_fm->dl_hd->s_fdpos = _tcslen(tmp_str); + cur_fm->dl_hd->s_fdpos = static_cast(_tcslen(tmp_str)); /* IF SIZE OF FIELD POSITION IS NOT A VALID SIZE, RETURN FAILURE */ if (cur_fm->dl_hd->s_fdpos < 1 || cur_fm->dl_hd->s_fdpos > 9) return(0); diff --git a/src/Grid/fip/c_drlead.cpp b/src/Grid/fip/c_drlead.cpp index 9f29cfe9..03ae4238 100644 --- a/src/Grid/fip/c_drlead.cpp +++ b/src/Grid/fip/c_drlead.cpp @@ -236,7 +236,7 @@ int cmp123drlead() cur_fm->cur_dr = cur_fm->dr_hd; /* WHILE CUR_DR NEXT NOT NULL DO */ - while (cur_fm->cur_dr->next != NULL) { + while (cur_fm->cur_dr->next != nullptr) { /* SET CUR_DR TO CUR_DR NEXT */ cur_fm->cur_dr = cur_fm->cur_dr->next; @@ -245,32 +245,32 @@ int cmp123drlead() i123toa(cur_fm->cur_dr->fd_len,anum); /* SET LEN TO NUMBER OF CHARACTERS IN ANUM */ - len = _tcslen(anum); + len = static_cast(_tcslen(anum)); /* IF NUMBER OF CHARACTERS IN FD_LEN EXCEEDS S_FDLEN */ if (len > cur_fm->rl_hd->s_fdlen) { /* SET S_FDLEN TO NUMBER OF CHARACTERS IN FD_LEN */ cur_fm->rl_hd->s_fdlen = len; - } - + } + /* IF NUMBER OF CHARACTERS IN TAG EXCEED S_TAG */ - len = _tcslen (cur_fm->cur_dr->tag); + len = static_cast(_tcslen (cur_fm->cur_dr->tag)); if (len > cur_fm->rl_hd->s_tag) { /* SET S_TAG TO NUMBER OF CHARACTERS IN TAG */ cur_fm->rl_hd->s_tag = len; - } + } /* INCREMENT NUM_ENT */ num_ent++; - } + } /* SET S_FDPOS TO NUMBER OF CHARACTERS IN FD_POS { LAST DR FIELD ENTRY } */ i123toa(cur_fm->cur_dr->fd_pos,anum); - len = _tcslen(anum); + len = static_cast(_tcslen(anum)); cur_fm->rl_hd->s_fdpos = len; /* IF SIZE OF FIELD POSITION IS NOT VALID SIZE, RETURN FAILURE */ diff --git a/src/Grid/fip/chk_sfld.cpp b/src/Grid/fip/chk_sfld.cpp index 99b6e0cc..51b677ec 100644 --- a/src/Grid/fip/chk_sfld.cpp +++ b/src/Grid/fip/chk_sfld.cpp @@ -321,7 +321,7 @@ int chk123sfld(FILE *fp,char *tag,char *descr,char *frmt) else if (cur_fm->sf_state_dr == 3) { /* IF CUR_DR DIMENSION LENGTH POINTER NULL */ - if (cur_fm->cur_dr->dim_lptr == NULL) { + if (cur_fm->cur_dr->dim_lptr == nullptr) { /* SET PREVIOUS STATE TO STATE */ p_state = cur_fm->sf_state_dr; @@ -329,7 +329,7 @@ int chk123sfld(FILE *fp,char *tag,char *descr,char *frmt) else { /* IF CUR_DV IS CUR_DR VALUES OR CUR_DV IS NULL */ - if (cur_fm->cur_dv == cur_fm->cur_dr->values || cur_fm->cur_dv == NULL) { + if (cur_fm->cur_dv == cur_fm->cur_dr->values || cur_fm->cur_dv == nullptr) { /* SET PREVIOUS STATE TO DIMENSION LENGTH POINTER SUBFIELD */ p_state = 2; @@ -378,7 +378,7 @@ int chk123sfld(FILE *fp,char *tag,char *descr,char *frmt) index = 0; /* IF ROOT POINTER TO FORMAT CONTROL IS NOT NULL */ - if (cur_fm->cur_dd->fmt_rt != NULL) { + if (cur_fm->cur_dd->fmt_rt != nullptr) { /* SET FORMAT STRING TO DATA TYPE AND INCREMENT INDEX */ frmt[index++] = cur_fm->cur_fc->d_type; @@ -409,7 +409,7 @@ int chk123sfld(FILE *fp,char *tag,char *descr,char *frmt) strcat(frmt,w_str); /* SET INDEX TO LENGTH OF FORMAT STRING */ - index = _tcslen(frmt); + index = static_cast(_tcslen(frmt)); } /* APPEND RIGHT PARENTHESIS TO FORMAT STRING AND INCREMENT INDEX */ @@ -424,13 +424,13 @@ int chk123sfld(FILE *fp,char *tag,char *descr,char *frmt) *descr = NC; /* IF LABELS NOT NULL */ - if (cur_fm->cur_dd->labels != NULL) { + if (cur_fm->cur_dd->labels != nullptr) { /* SET CUR_LP TO LP_HD */ cur_fm->cur_lp = cur_fm->lp_hd; /* WHILE CUR_LP NEXT IS NOT NULL DO */ - while (cur_fm->cur_lp->next != NULL) { + while (cur_fm->cur_lp->next != nullptr) { /* SET CUR_LP TO CUR_LP NEXT */ cur_fm->cur_lp = cur_fm->cur_lp->next; @@ -448,7 +448,7 @@ int chk123sfld(FILE *fp,char *tag,char *descr,char *frmt) } /* IF CURRENT LABEL NOT NULL */ - if (cur_fm->cur_lp->cur->label != NULL) { + if (cur_fm->cur_lp->cur->label != nullptr) { /* CONCATENATE CURRENT LABEL TO DESCRIPTION */ strcat(descr,cur_fm->cur_lp->cur->label); diff --git a/src/Grid/fip/gdstr.cpp b/src/Grid/fip/gdstr.cpp index f29d9850..12dc010b 100644 --- a/src/Grid/fip/gdstr.cpp +++ b/src/Grid/fip/gdstr.cpp @@ -100,7 +100,7 @@ int g123dstr(char **in_str,char *buf_str,int delim) if (strchr(*in_str,FT)) /* SET FTPOS TO POSITION OF FIELD TERMINATOR */ - ftpos = strcspn(*in_str,FT_STR) + 1L; + ftpos = static_cast(strcspn(*in_str,FT_STR)) + 1L; /* ELSE SET FTPOS TO ZERO */ else ftpos = 0; @@ -115,7 +115,7 @@ int g123dstr(char **in_str,char *buf_str,int delim) dlstr[1] = NC; /* SET DLPOS TO POSITION OF DELIMITOR */ - dlpos = strcspn(*in_str,dlstr) + 1L; + dlpos = static_cast(strcspn(*in_str,dlstr)) + 1L; } /* ELSE SET DLPOS TO ZERO */ else dlpos = 0; @@ -137,7 +137,7 @@ int g123dstr(char **in_str,char *buf_str,int delim) /* ELSE IF FIELD TERMINATOR OCCURS BEFORE DELIMITOR OR FIELD TERMINATOR OCCURS BUT DELIMITOR DOES NOT */ - else if (((ftpos) && (ftpos < dlpos)) + else if (((ftpos) && (ftpos < dlpos)) || ((ftpos) && (!dlpos))) { /* COPY TERMINATED STRING FROM INPUT STRING TO BUF_STR */ @@ -159,4 +159,4 @@ int g123dstr(char **in_str,char *buf_str,int delim) /* RETURN SUCCESS */ return(1); -} +} diff --git a/src/Grid/fip/gsstr.cpp b/src/Grid/fip/gsstr.cpp index 23b37138..22322acb 100644 --- a/src/Grid/fip/gsstr.cpp +++ b/src/Grid/fip/gsstr.cpp @@ -93,13 +93,13 @@ int g123sstr(char **in_str,char *buf_str,long str_len) if (strchr(*in_str,FT)) /* SET FTPOS TO POSITION OF FIELD TERMINATOR */ - ftpos = strcspn(*in_str,FT_STR) + 1L; + ftpos = static_cast(strcspn(*in_str,FT_STR)) + 1L; /* ELSE SET FTPOS TO ZERO */ else ftpos = 0; /* SET IN_STR_LEN TO INPUT STRING LENGTH */ - in_str_len = _tcslen(*in_str); + in_str_len = static_cast(_tcslen(*in_str)); /* IF STRING TERMINATED BY A FIELD TERMINATOR IS SHORTER THAN STRING TO BE RETRIEVED */ diff --git a/src/Grid/fip/ld_tagp.cpp b/src/Grid/fip/ld_tagp.cpp index 3c32c92a..238dc184 100644 --- a/src/Grid/fip/ld_tagp.cpp +++ b/src/Grid/fip/ld_tagp.cpp @@ -185,25 +185,25 @@ int load123tagp(char *string) char second_tag[10]; /* ALLOCATE NEW_TL { DUMMY } */ - if ((new_tl = (struct tl *) malloc(sizeof(struct tl))) == NULL) return(0); + if ((new_tl = (struct tl *) malloc(sizeof(struct tl))) == nullptr) return(0); /* SET TAG_L TO NEW_TL */ cur_fm->cr_hd->tag_l = new_tl; /* SET NEW_TL NEXT TO NULL */ - new_tl->next = NULL; + new_tl->next = nullptr; /* SET CUR_TL TO NEW_TL */ cur_tl = new_tl; /* GET INPUT STRING LENGTH */ - length = _tcslen(string); + length = static_cast(_tcslen(string)); /* WHILE INDEX LESS THAN LENGTH DO */ while(index < length) { /* PARSE FIRST TAG FROM STRING */ - strncpy(first_tag,&string[index],(int) cur_fm->dl_hd->s_tag); + strncpy(first_tag,&string[index],static_cast(cur_fm->dl_hd->s_tag)); first_tag[cur_fm->dl_hd->s_tag] = NC; /* UPDATE INDEX OF INPUT STRING */ @@ -217,13 +217,13 @@ int load123tagp(char *string) index += cur_fm->dl_hd->s_tag; /* ALLOCATE NEW_TL */ - if ((new_tl = (struct tl *) malloc(sizeof(struct tl))) == NULL) return(0); + if ((new_tl = (struct tl *) malloc(sizeof(struct tl))) == nullptr) return(0); /* SET CUR_TL NEXT TO NEW_TL */ cur_tl->next = new_tl; /* SET NEW_TL NEXT TO NULL */ - new_tl->next = NULL; + new_tl->next = nullptr; /* SET TAG1 TO FIRST TAG */ strcpy(new_tl->tag_1,first_tag); diff --git a/src/Grid/fip/load_fld.cpp b/src/Grid/fip/load_fld.cpp index 367d577d..23303bbc 100644 --- a/src/Grid/fip/load_fld.cpp +++ b/src/Grid/fip/load_fld.cpp @@ -453,50 +453,49 @@ int load123fld(char **in_str,char *in_str_end,int comprssd) struct dd *cur_dd ; struct dv *new_dv ; char *save_in_str; - /* SAVE POINTER TO INPUT STRING */ save_in_str = *in_str; - + /* SET LOCAL CUR_DD TO CUR_DD IN FM STRUCTURE */ cur_dd = cur_fm->cur_dd; - + /* IF LABELS POINTER AND FMT_RT POINTER OF CUR_DD ARE NULL */ - if ((cur_dd->labels == NULL) && (cur_dd->fmt_rt == NULL)) { - + if ((cur_dd->labels == nullptr) && (cur_dd->fmt_rt == nullptr)) { + /* IF NO FIELD CONTROLS { ELEMENTARY DATA FIELD } */ if (!_tcslen(cur_dd->fd_cntrl)) { /* ALLOCATE NEW_DV { SET UP DUMMY HEADER } */ - if ((new_dv = (struct dv *) malloc(sizeof(struct dv))) == NULL) return(0); + if ((new_dv = (struct dv *) malloc(sizeof(struct dv))) == nullptr) return(0); /* INITIALIZE POINTERS */ - new_dv->value = NULL; - new_dv->nxt_val = NULL; - new_dv->nxt_vset = NULL; + new_dv->value = nullptr; + new_dv->nxt_val = nullptr; + new_dv->nxt_vset = nullptr; /* SET VALUES OF CUR_DR TO NEW_DV */ cur_fm->cur_dr->values = new_dv; - + /* SET CUR_DV TO NEW_DV */ cur_fm->cur_dv = new_dv; /* ALLOCATE NEW_DV */ - if((new_dv = (struct dv *) malloc(sizeof(struct dv))) == NULL) + if((new_dv = (struct dv *) malloc(sizeof(struct dv))) == nullptr) return(0); /* INITIALIZE POINTERS */ - new_dv->value = NULL; - new_dv->nxt_val = NULL; - new_dv->nxt_vset = NULL; + new_dv->value = nullptr; + new_dv->nxt_val = nullptr; + new_dv->nxt_vset = nullptr; /* SET NXT_VSET CUR_DV TO NEW_DV */ cur_fm->cur_dv->nxt_vset = new_dv; /* CALCULATE SIZE OF AND ALLOCATE BUFFER SPACE FOR VALUE */ len = (size_t) (cur_fm->cur_dr->fd_len + 1); - if ((new_dv->value = (char *) malloc(len * sizeof(char))) == NULL) + if ((new_dv->value = (char *) malloc(len * sizeof(char))) == nullptr) return(0); - + /* INITIALIZE STRING */ *new_dv->value = NC; @@ -511,13 +510,13 @@ int load123fld(char **in_str,char *in_str_end,int comprssd) } else { - + /* IF FIELD CONTROLS INDICATE VECTOR OR ELEMENTARY FIELD */ if ((cur_dd->fd_cntrl[FCDSTYPE] == '1') || (cur_dd->fd_cntrl[FCDSTYPE] == '0')) { /* ALLOCATE BUFFER OF SIZE FIELD LENGTH */ len = (size_t) (cur_fm->cur_dr->fd_len + 1); - if ((buffer = (char *) malloc(len * sizeof(char))) == NULL) + if ((buffer = (char *) malloc(len * sizeof(char))) == nullptr) return(0); /* SET START BUFFER POINTER TO BEGINNING OF BUFFER */ @@ -534,70 +533,69 @@ int load123fld(char **in_str,char *in_str_end,int comprssd) /* CALL STR123TOK() TO SEPARATE DELIMITED DATA VALUES */ i = str123tok(&buffer,DEL_STR,&tok_len); - + /* ALLOCATE NEW_DV { SET UP DUMMY HEADER } */ - if ((new_dv = (struct dv *) malloc(sizeof(struct dv))) == NULL) return(0); + if ((new_dv = (struct dv *) malloc(sizeof(struct dv))) == nullptr) return(0); /* INITIALIZE POINTERS */ - new_dv->value = NULL; - new_dv->nxt_val = NULL; - new_dv->nxt_vset = NULL; - + new_dv->value = nullptr; + new_dv->nxt_val = nullptr; + new_dv->nxt_vset = nullptr; + /* SET CURRENT DATA RECORD VALUES TO NEW_DV */ cur_fm->cur_dr->values = new_dv; - + /* SET CUR_DV TO NEW_DV */ cur_fm->cur_dv = new_dv; - + /* WHILE POINTER RETURNED FROM STR123TOK() NOT NULL */ - while ( i != NULL) { - + while ( i != nullptr) { + /* ALLOCATE NEW_DV */ - if ((new_dv = (struct dv *) malloc(sizeof(struct dv))) == NULL) return(0); + if ((new_dv = (struct dv *) malloc(sizeof(struct dv))) == nullptr) return(0); /* INITIALIZE POINTERS */ - new_dv->value = NULL; - new_dv->nxt_val = NULL; - new_dv->nxt_vset = NULL; - + new_dv->value = nullptr; + new_dv->nxt_val = nullptr; + new_dv->nxt_vset = nullptr; + /* SET LEN TO LENGTH OF DATA VALUE RETURNED */ len = (size_t) _tcslen(i) + 1; - + /* ALLOCATE SPACE FOR STRING */ - if ((val_str = (char *) malloc(len * sizeof(char))) == NULL) + if ((val_str = static_cast(malloc(len * sizeof(char)))) == nullptr) return(0); /* SET STRING TO EMPTY */ *val_str = NC; - + /* COPY STRING RETURNED FROM STR123TOK() TO NEW SPACE */ strcpy(val_str,i); - - /* SET VALUE TO VAL_STR */ + + /* SET VALUE TO VAL_STR */ new_dv->value = val_str; /* IF NOT AT HEADER RECORD */ if (cur_fm->cur_dr->values != cur_fm->cur_dv) { - /* SET NEXT FIELD OF CUR_DV TO NEW_DV */ cur_fm->cur_dv->nxt_val = new_dv; } else { /* SET NEXT VALUE SET FIELD TO NEW_DV */ cur_fm->cur_dv->nxt_vset = new_dv; - }; - + } + /* SET CUR_DV TO NEW_DV */ cur_fm->cur_dv = new_dv; - + /* CALL STR123TOK() TO RETURN NEXT DATA VALUE */ i = str123tok(&buffer,DEL_STR,&tok_len); - - }; + + } /* FREE SPACE OF START OF BUFFER POINTER */ free(st_buff); - - } + + } /* ELSE { ARRAY DATA } */ else { @@ -609,78 +607,77 @@ int load123fld(char **in_str,char *in_str_end,int comprssd) cur_fm->cur_dm = cur_dd->dim_lptr->nxt; } else { - /* CALL GET123DIM() TO INPUT AND STORE DIMENSION INFORMATION FROM DR */ if (!get123dim(in_str,&cur_fm->cur_dr->num_dim,&prim_dms)) return(0); } - + /* IF FIELD LENGTH EXCEEDS MAXIMUM AMOUNT OF CONTIGUOUS SPACE, RETURN FAILURE */ if (cur_fm->cur_dr->fd_len > MAXSIZ) return(0); - + /* CALL G123DSTR() TO LOAD BUFFER WITH ALL DATA VALUES */ if (!g123dstr(in_str,glb_str,FT)) return(0); /* CALL RET123DV() TO EXTRACT DATA VALUES */ if (!ret123dv(glb_str,prim_dms)) return(0); - - }; - }; - } + + } + } + } /* ELSEIF FMT_RT IS NOT NULL AND LABELS IS NULL OF CUR_DD */ - else if ((cur_dd->fmt_rt != NULL) && (cur_dd->labels == NULL)) { + else if ((cur_dd->fmt_rt != nullptr) && (cur_dd->labels == nullptr)) { /* IF FIELD CONTROLS INDICATE VECTOR OR ELEMENTARY DATA */ if ((cur_dd->fd_cntrl[FCDSTYPE] == '1') || (cur_dd->fd_cntrl[FCDSTYPE] == '0')) { - + /* ALLOCATE NEW_DV { SET UP DUMMY HEADER } */ - if ((new_dv = (struct dv *) malloc(sizeof(struct dv))) == NULL) - return(0); + if ((new_dv = (struct dv *) malloc(sizeof(struct dv))) == nullptr) + return(0); /* INITIALIZE POINTERS */ - new_dv->value = NULL; - new_dv->nxt_val = NULL; - new_dv->nxt_vset = NULL; - + new_dv->value = nullptr; + new_dv->nxt_val = nullptr; + new_dv->nxt_vset = nullptr; + /* SET CURRENT DATA RECORD VALUES TO NEW_DV */ cur_fm->cur_dr->values = new_dv; - + /* SET CUR_DV TO NEW_DV */ cur_fm->cur_dv = new_dv; - + /* SET CUR_FCR TO FMT_RT OF CUR_DD { INITIALIZE FOR GET123FMT } */ cur_fm->cur_fcr = cur_dd->fmt_rt; /* SET CUR_FC TO FMT_RT FIELD OF CUR_DD */ cur_fm->cur_fc = cur_dd->fmt_rt; - + /* INITIALIZE END OF FIELD FLAG */ end_of_fld = 0; - + /* WHILE HAVE NOT READ LAST VALUE OF FIELD DO */ while ( !end_of_fld) { - + /* CALL GET123FMT() TO RETRIEVE FORMAT OF DATA VALUE STRING */ if (!get123fmt(&d_type,&width,&delim)) return(0); - + /* CLEAR STRING */ glb_str[0] = NC; /* CALL GET123DVAL() TO READ IN DATA VALUE INTO VAL_STR */ if (!get123dval(in_str,in_str_end,d_type,&width,delim,comprssd,glb_str)) return(0); - + /* ALLOCATE NEW_DV */ - if ((new_dv = (struct dv *) malloc(sizeof(struct dv))) == NULL) return(0); + if ((new_dv = (struct dv *) malloc(sizeof(struct dv))) == nullptr) return(0); /* INITIALIZE POINTERS */ - new_dv->value = NULL; - new_dv->nxt_val = NULL; - new_dv->nxt_vset = NULL; + new_dv->value = nullptr; + new_dv->nxt_val = nullptr; + new_dv->nxt_vset = nullptr; /* IF DATA TYPE NOT 'B' */ if (d_type != 'B') { @@ -691,27 +688,26 @@ int load123fld(char **in_str,char *in_str_end,int comprssd) tmp_cptr = strchr(glb_str,FT); /* SET END OF FIELD FLAG IF FT IS IN STRING */ - end_of_fld = (tmp_cptr != NULL); + end_of_fld = (tmp_cptr != nullptr); /* IF TMP_CPTR NOT NULL REPLACE FT WITH NULL CHARACTER */ - if (tmp_cptr != NULL) *tmp_cptr = NC; - + if (tmp_cptr != nullptr) *tmp_cptr = NC; + /* SET LEN TO LENGTH OF DATA VALUE */ - len = (size_t) _tcslen(glb_str) + 1; - + len = _tcslen(glb_str) + 1; + /* RESERVE SPACE FOR STRING */ - if ((val_str = (char *) malloc(len * sizeof(char))) == NULL) return(0); + if ((val_str = static_cast(malloc(len * sizeof(char)))) == nullptr) return(0); /* SET VAL_STR TO EMPTY STRING */ *val_str = NC; - + /* COPY STRING FROM BUFFER TO NEW SPACE */ strcpy(val_str,glb_str); - - /* SET VALUE TO VAL_STR */ + + /* SET VALUE TO VAL_STR */ new_dv->value = val_str; - - } + } /* ELSE DATA TYPE IS BINARY */ else { @@ -720,8 +716,8 @@ int load123fld(char **in_str,char *in_str_end,int comprssd) len = (size_t) width + 1; /* RESERVE SPACE FOR STRING */ - if ((val_str = (char *) malloc(len * sizeof(char))) == NULL) - return(0); + if ((val_str = (char *) malloc(len * sizeof(char))) == nullptr) + return(0); /* COPY BUFFER TO VALUE STRING */ memcpy(val_str,glb_str,--len); @@ -741,25 +737,21 @@ int load123fld(char **in_str,char *in_str_end,int comprssd) } else { - /* SET NXT_VSET FIELD OF CUR_DV TO NEW_DV */ cur_fm->cur_dv->nxt_vset = new_dv; - }; - + } + /* SET CUR_DV TO NEW_DV */ cur_fm->cur_dv = new_dv; /* IF NOT END OF FIELD */ if (!end_of_fld) { - /* IF END OF INPUT STRING */ if (*in_str >= in_str_end) { - /* SET END OF FIELD FLAG TO TRUE */ end_of_fld = 1; } else { - /* IF DATA TYPE IS BINARY AND ENTIRE FIELD LENGTH HAS BEEN RETRIEVED */ @@ -770,19 +762,16 @@ int load123fld(char **in_str,char *in_str_end,int comprssd) /* MOVE BEGINNING OF INPUT STRING PAST FIELD TERMINATOR */ *in_str = *in_str + 1; - } /* ELSE IF DATA TYPE IS NOT BINARY AND CHARACTER IS FIELD TERMINATOR AND DATA VALUE IS NOT DELIMITED */ else if (d_type != 'B' && *in_str[0] == FT && width != 0) { - /* SET END OF FIELD FLAG TO TRUE */ end_of_fld = 1; /* MOVE BEGINNING OF INPUT STRING PAST FIELD TERMINATOR */ *in_str = *in_str + 1; - } } } @@ -790,7 +779,6 @@ int load123fld(char **in_str,char *in_str_end,int comprssd) } /* ELSE { ARRAY DATA } */ else { - /* IF NUMBER OF DIMENSIONS IN DDR (CUR_DD) EXISTS */ if (cur_dd->num_dim) { @@ -799,65 +787,64 @@ int load123fld(char **in_str,char *in_str_end,int comprssd) cur_fm->cur_dm = cur_dd->dim_lptr->nxt; } else { - /* CALL GET123DIM() TO INPUT AND STORE DIMENSION INFORMATION FROM DR */ if (!get123dim(in_str,&cur_fm->cur_dr->num_dim,&prim_dms)) return(0); } - + /* SET CUR_FCR TO FMT_RT FIELD OF CUR_DD */ cur_fm->cur_fcr = cur_dd->fmt_rt; /* SET CUR_FC TO FMT_RT FIELD OF CUR_DD */ cur_fm->cur_fc = cur_dd->fmt_rt; - + /* COMPUTE PROPER FIELD LENGTH */ - if (comprssd) field_length = cur_fm->cur_dr->fd_len-(*in_str-save_in_str); - else field_length = in_str_end - *in_str; - + if (comprssd) field_length = static_cast(cur_fm->cur_dr->fd_len-(*in_str-save_in_str)); + else field_length = static_cast(in_str_end - *in_str); + /* CALL RET123FV() TO RETRIEVE FORMATTED DATA VALUES RETURN A - POINTER TO A STRUCTURE STORING THE VALUES + POINTER TO A STRUCTURE STORING THE VALUES */ if (!ret123fv(in_str,in_str_end,prim_dms,field_length,comprssd)) return(0); } - } + } /* ELSEIF LABELS IS NOT NULL AND FMT_RT IS NULL OF CUR_DD */ - else if ((cur_dd->labels != NULL) && (cur_dd->fmt_rt == NULL)) { - + else if ((cur_dd->labels != nullptr) && (cur_dd->fmt_rt == nullptr)) { + /* CALL RET123PDM() TO RETURN PRIM_DMS */ if (!ret123pdm(&prim_dms)) return(0); - + /* CALL G123DSTR() TO LOAD BUFFER WITH ALL DATA VALUES */ if (!g123dstr(in_str,glb_str,FT)) return(0); /* CALL RET123DV() TO EXTRACT DATA VALUES */ if (!ret123dv(glb_str,prim_dms)) return(0); - } + } /* ELSE { LABELS AND FMT_RT POINTER FIELD OF CUR_DD NOT NULL } */ else { - + /* CALL RET123PDM() TO RETURN PRIM_DMS */ if (!ret123pdm(&prim_dms)) return(0); - + /* SET CUR_FCR TO FMT_RT FIELD OF CUR_DD */ cur_fm->cur_fcr = cur_dd->fmt_rt; - + /* SET CUR_FC TO FMT_RT FIELD OF CUR_DD */ cur_fm->cur_fc = cur_dd->fmt_rt; - + /* COMPUTE PROPER FIELD LENGTH */ if (comprssd) field_length = cur_fm->cur_dr->fd_len; - else field_length = in_str_end - *in_str; - + else field_length = static_cast(in_str_end - *in_str); + /* CALL RET123FV() TO RETRIEVE FORMATTED DATA VALUES AND RETURN A POINTER TO A STRUCTURE STORING THE VALUES */ if (!ret123fv(in_str,in_str_end,prim_dms,field_length,comprssd)) return(0); } - /* RETURN SUCCESS */ + /* RETURN SUCCESS */ return(1); } diff --git a/src/Grid/fip/rd_fld.cpp b/src/Grid/fip/rd_fld.cpp index db5c9f3b..c157db91 100644 --- a/src/Grid/fip/rd_fld.cpp +++ b/src/Grid/fip/rd_fld.cpp @@ -452,17 +452,17 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta /* INIT STATUS TO FAILURE */ *status = 0; - + /* CALL GET123LEVEL() TO GET APPROPRIATE FM ENTRY FOR THIS FILE POINTER */ if (!get123level(fp)) return(0); /* SET CUR_DR TO NEXT FIELD */ - if (cur_fm->cur_dr != NULL) { + if (cur_fm->cur_dr != nullptr) { cur_fm->cur_dr = cur_fm->cur_dr->next; - }; + } /* IF CUR_DR IS NULL */ - if (cur_fm->cur_dr == NULL) { + if (cur_fm->cur_dr == nullptr) { /* CALL LD123REC() TO LOAD DATA RECORD INFORMATION INTO DATA STRUCTURES FOR REFERENCE @@ -474,16 +474,16 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta /* SET STATUS TO END OF FILE */ *status = 4; - }; + } return(0); - }; - + } + /* SET STATUS TO START OF RECORD */ *status = 2; - + /* SET CUR_DR TO NEXT POINTER OF DR_HD */ cur_fm->cur_dr = cur_fm->dr_hd->next; - }; + } /* CALL RET123MATCH() TO RETURN DATA DESCRIPTION FOR CURRENT ENTRY */ if (!ret123match(cur_fm->cur_dr->tag)) return(0); @@ -506,24 +506,24 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta #else strcat(rd_str,anum); #endif - + /* UPDATE INDEX POINTER */ - byte_pos += _tcslen(anum); + byte_pos += static_cast(_tcslen(anum)); /* CONCATENATE UT TO RD_STR */ strcat(rd_str,UT_STR); /* UPDATE INDEX POINTER */ - byte_pos += _tcslen(UT_STR); + byte_pos += static_cast(_tcslen(UT_STR)); /* SET CUR_DM TO DIM_LPTR */ cur_fm->cur_dm = cur_fm->cur_dr->dim_lptr; - + /* SKIP DUMMY DM */ cur_fm->cur_dm = cur_fm->cur_dm->nxt; /* WHILE CUR_DM NOT NULL DO */ - while(cur_fm->cur_dm != NULL) { + while(cur_fm->cur_dm != nullptr) { /* CONCATENATE LEN TO RD_STR */ i123toa(cur_fm->cur_dm->len,anum); @@ -534,13 +534,13 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta #endif /* UPDATE INDEX POINTER */ - byte_pos += _tcslen(anum); + byte_pos += static_cast(_tcslen(anum)); /* CONCATENATE UT TO RD_STR */ strcat(rd_str,UT_STR); /* UPDATE INDEX POINTER */ - byte_pos += _tcslen(UT_STR); + byte_pos += static_cast(_tcslen(UT_STR)); /* SET CUR_DM TO NXT */ cur_fm->cur_dm = cur_fm->cur_dm->nxt; @@ -548,23 +548,20 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta } /* IF FMT_RT OF CUR_DD IS NULL { NO FORMATS FOR VALUES } */ - if (cur_fm->cur_dd->fmt_rt == NULL) { + if (cur_fm->cur_dd->fmt_rt == nullptr) { /* SET ROW_DVH TO NXT_VSET FIELD OF VALUES FIELD OF CUR_DR */ cur_fm->row_dvh = cur_fm->cur_dr->values->nxt_vset; /* WHILE ROW_DVH NOT NULL DO */ - while(cur_fm->row_dvh != NULL) { - + while(cur_fm->row_dvh != nullptr) { /* SET CUR_DV TO ROW_DVH */ cur_fm->cur_dv = cur_fm->row_dvh; /* WHILE CUR_DV NOT NULL DO */ - while(cur_fm->cur_dv != NULL) { - + while(cur_fm->cur_dv != nullptr) { /* IF STRING VALUE NOT NULL */ - if (cur_fm->cur_dv->value != NULL) { - + if (cur_fm->cur_dv->value != nullptr) { /* DETERMINE LENGTH OF VALUE IN BYTES */ b_siz = _tcslen(cur_fm->cur_dv->value); @@ -576,22 +573,21 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta #endif /* UPDATE INDEX POINTER */ - byte_pos += b_siz; + byte_pos += static_cast(b_siz); - }; + } /* SET CUR_DV TO NXT_VAL */ cur_fm->cur_dv = cur_fm->cur_dv->nxt_val; /* IF CUR_DV NOT NULL */ - if (cur_fm->cur_dv != NULL) { + if (cur_fm->cur_dv != nullptr) { /* CONCATENATE UT TO RD_STR */ strcat(&rd_str[byte_pos],UT_STR); /* UPDATE INDEX POINTER */ byte_pos++; - } } @@ -599,14 +595,13 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta cur_fm->row_dvh = cur_fm->row_dvh->nxt_vset; /* IF ROW_DVH NOT NULL */ - if (cur_fm->row_dvh != NULL) { + if (cur_fm->row_dvh != nullptr) { /* CONCATENATE UT TO RD_STR */ strcat(&rd_str[byte_pos],UT_STR); /* UPDATE INDEX POINTER */ byte_pos++; - } } } @@ -620,20 +615,19 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta cur_fm->cur_fcr = cur_fm->cur_fc; /* IF VALUES OF CUR_DR NOT NULL */ - if (cur_fm->cur_dr->values != NULL) { + if (cur_fm->cur_dr->values != nullptr) { /* SET ROW_DVH TO NXT_VSET FIELD OF VALUES FIELD OF CUR_DR */ cur_fm->row_dvh = cur_fm->cur_dr->values->nxt_vset; /* WHILE ROW_DVH NOT NULL DO */ - while(cur_fm->row_dvh != NULL) { + while(cur_fm->row_dvh != nullptr) { /* SET CUR_DV TO ROW_DVH */ cur_fm->cur_dv = cur_fm->row_dvh; /* WHILE CUR_DV NOT NULL DO */ - while(cur_fm->cur_dv != NULL) { - + while(cur_fm->cur_dv != nullptr) { /* INITIALIZE VARIABLES */ memset(delim,NC,2); memset(dtyp,NC,2); @@ -654,7 +648,7 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta } /* IF VALUE STRING IS NOT NULL */ - if (cur_fm->cur_dv->value != NULL) { + if (cur_fm->cur_dv->value != nullptr) { /* DETERMINE LENGTH OF VALUE IN BYTES */ b_siz = _tcslen(cur_fm->cur_dv->value); @@ -667,9 +661,9 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta #endif /* UPDATE INDEX POINTER */ - byte_pos += b_siz; + byte_pos += static_cast(b_siz); } - } + } /* ELSE BINARY DATA */ else { @@ -757,13 +751,12 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta } /* COMPUTE NEW BYTE AND BITS POSITIONS */ - byte_pos = byte_pos + (int) bytes.quot; - bit_pos = (int) bytes.rem; + byte_pos = byte_pos + static_cast(bytes.quot); + bit_pos = static_cast(bytes.rem); /* ADD TRUNCATING NULL CHARACTER TO READ STRING */ if (bytes.rem != 0) rd_str[byte_pos+1] = NC; else rd_str[byte_pos] = NC; - } /* ELSE ON BYTE BOUNDARY */ @@ -776,8 +769,8 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta rd_str[byte_pos+b_siz] = NC; /* COMPUTE NEW BYTE AND BIT POSITIONS */ - byte_pos = byte_pos + (int) bytes.quot; - bit_pos = (int) bytes.rem; + byte_pos = byte_pos + static_cast(bytes.quot); + bit_pos = static_cast(bytes.rem); } } @@ -797,10 +790,10 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta rd_str[byte_pos+b_siz] = NC; /* UPDATE INDEX POINTER */ - byte_pos += b_siz; + byte_pos += static_cast(b_siz); } } - }; + } /* IF DATA TYPE IS NOT BINARY */ if (*dtyp != 'B') { @@ -809,7 +802,7 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta if (!width && delim[0] == NC) { /* IF NEXT OF CUR_DV NOT NULL */ - if (cur_fm->cur_dv->nxt_val != NULL) { + if (cur_fm->cur_dv->nxt_val != nullptr) { /* CONCATENATE UT TO RD_STR */ strcat(&rd_str[byte_pos],UT_STR); @@ -822,7 +815,7 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta else if (delim[0] != NC) { /* IF NEXT OF CUR_DV NOT NULL */ - if (cur_fm->cur_dv->nxt_val != NULL) { + if (cur_fm->cur_dv->nxt_val != nullptr) { /* CONCATENATE DELIM RETRIEVED BY GET123FMT() TO RD_STR */ #if CONV @@ -833,7 +826,7 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta /* UPDATE INDEX POINTER */ byte_pos++; - }; + } } } @@ -848,7 +841,7 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta if (*dtyp != 'B') { /* IF ROW_DVH IS NOT NULL */ - if (cur_fm->row_dvh != NULL) { + if (cur_fm->row_dvh != nullptr) { /* IF WIDTH IS ZERO AND DELIM IS NC */ if (!width && delim[0] == NC) { @@ -899,31 +892,28 @@ int rd123fld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int* sta cur_fm->sf_state_dr = 4; /* IF NOT END OF DR FIELDS */ - if ( cur_fm->cur_dr->next != NULL) { - + if ( cur_fm->cur_dr->next != nullptr) { /* IF STATUS NOT EQUAL TO START OF RECORD */ if (*status != 2) { - /* SET STATUS TO OK */ *status = 1; - }; + } } else { - /* CALL SET123STAT TO CHECK FOR END OF FILE */ if (!set123stat(fp,status)) return(0); - + /* IF STATUS IS NOT END OF FILE */ if (*status != 4) { /* SET STATUS TO END OF RECORD */ *status = 3; - }; - }; - + } + } + /* SET STR_LEN */ - *str_len = (long) byte_pos; - + *str_len = static_cast(byte_pos); + /* RETURN SUCCESS */ return(1); } diff --git a/src/Grid/fip/rd_sfld.cpp b/src/Grid/fip/rd_sfld.cpp index 9442dd35..8f998e00 100644 --- a/src/Grid/fip/rd_sfld.cpp +++ b/src/Grid/fip/rd_sfld.cpp @@ -486,7 +486,7 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st if (!free123lab()) return (0); /* IF CUR_DR IS NULL */ - if (cur_fm->cur_dr == NULL) { + if (cur_fm->cur_dr == nullptr) { /* CALL LD123REC() TO INPUT DATA RECORD */ if (!ld123rec()) { @@ -511,7 +511,7 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st }; /* IF NEXT CUR_DR NOT NULL */ - if (cur_fm->cur_dr->next != NULL) { + if (cur_fm->cur_dr->next != nullptr) { /* MOVE CUR_DR TO CUR_DR NEXT */ cur_fm->cur_dr = cur_fm->cur_dr->next; @@ -603,13 +603,13 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st cur_fm->cur_dm = cur_fm->cur_dm->nxt; /* IF CUR_DM IS NULL */ - if (cur_fm->cur_dm == NULL) { + if (cur_fm->cur_dm == nullptr) { /* SET STATE TO DATA VALUE STRING SUBFIELD */ cur_fm->sf_state_dr = 3; /* IF LABELS ARE PRESENT */ - if (cur_fm->cur_dd->labels != NULL) { + if (cur_fm->cur_dd->labels != nullptr) { /* CALL SETUP123LAB() TO SET UP LABELS POINTER STRUCTURE */ if (!setup123lb()) return (0); @@ -643,7 +643,7 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st cur_fm->sf_state_dr = 3; /* IF LABELS ARE PRESENT */ - if (cur_fm->cur_dd->labels != NULL) { + if (cur_fm->cur_dd->labels != nullptr) { /* CALL SETUP123LB() TO SET UP LABELS POINTER STRUCTURE */ if (!setup123lb()) return (0); @@ -714,7 +714,7 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st if (!first) { /* IF LABELS FIELD OF CURRENT DD NOT NULL */ - if (cur_fm->cur_dd->labels != NULL) { + if (cur_fm->cur_dd->labels != nullptr) { /* CALL INCRE123LAB() TO INCREMENT LABEL TO CORRESPOND TO THIS DATA VALUE @@ -730,7 +730,7 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st }; /* IF FORMATS FIELD OF CURRENT DD NOT EQUAL TO NULL */ - if (cur_fm->cur_dd->fmt_rt != NULL ) { + if (cur_fm->cur_dd->fmt_rt != nullptr) { /* CALL GET123FMT() TO RETRIEVE FORMAT CORRESPONDING TO THIS DATA VALUE */ if(!get123fmt(&dtyp,&width,&delim)) return (0); @@ -738,10 +738,10 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st }; /* IF CUR_DV NOT NULL */ - if (cur_fm->cur_dv != NULL) { + if (cur_fm->cur_dv != nullptr) { /* IF VALUE IS NOT NULL */ - if (cur_fm->cur_dv->value != NULL) { + if (cur_fm->cur_dv->value != nullptr) { /* IF DATA TYPE IS NOT BINARY */ if (dtyp != 'B') { @@ -750,7 +750,7 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st strcpy(rd_str,cur_fm->cur_dv->value); /* SET STRING LENGTH */ - *str_len = _tcslen(cur_fm->cur_dv->value); + *str_len = static_cast(_tcslen(cur_fm->cur_dv->value)); } /* ELSE BINARY DATA */ else { @@ -781,7 +781,7 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st rd_str[b_siz] = NC; /* SET STRING LENGTH */ - *str_len = b_siz; + *str_len = static_cast(b_siz); } /* ELSE FIELD IS FIXED LENGTH BIT FIELD */ @@ -798,7 +798,7 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st rd_str[b_siz] = NC; /* SET STRING LENGTH */ - *str_len = b_siz; + *str_len = static_cast(b_siz); } }; } @@ -817,10 +817,10 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st cur_fm->cur_dv = cur_fm->row_dvh; /* IF CUR_DV NOT NULL */ - if (cur_fm->cur_dv != NULL) { + if (cur_fm->cur_dv != nullptr) { /* IF VALUE IS NOT NULL */ - if (cur_fm->cur_dv->value != NULL) { + if (cur_fm->cur_dv->value != nullptr) { /* IF DATA TYPE IS NOT BINARY */ if (dtyp != 'B') { @@ -829,7 +829,7 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st strcpy(rd_str,cur_fm->cur_dv->value); /* SET STRING LENGTH */ - *str_len = _tcslen(cur_fm->cur_dv->value); + *str_len = static_cast(_tcslen(cur_fm->cur_dv->value)); } /* ELSE BINARY DATA */ @@ -861,7 +861,7 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st rd_str[b_siz] = NC; /* SET STRING LENGTH */ - *str_len = b_siz; + *str_len = static_cast(b_siz); } /* ELSE FIELD IS FIXED LENGTH BIT FIELD */ @@ -878,7 +878,7 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st rd_str[b_siz] = NC; /* SET STRING LENGTH */ - *str_len = b_siz; + *str_len = static_cast(b_siz); } }; } @@ -900,11 +900,11 @@ int rd123sfld(FILE *fp,char *tag,char *leadid,char *rd_str,long *str_len,int *st } /* IF NXT_VAL IS NULL AND ROW_DVH NXT_VSET IS NULL */ - if ((cur_fm->cur_dv->nxt_val == NULL) && - (cur_fm->row_dvh->nxt_vset == NULL)) { + if ((cur_fm->cur_dv->nxt_val == nullptr) && + (cur_fm->row_dvh->nxt_vset == nullptr)) { /* IF CUR_DR NEXT IS NULL */ - if (cur_fm->cur_dr->next == NULL) { + if (cur_fm->cur_dr->next == nullptr) { /* CHECK FOR END OF FILE */ if (!set123stat(fp,status)) return (0); diff --git a/src/Grid/fip/str_tok.cpp b/src/Grid/fip/str_tok.cpp index 1c2734d6..b77dd4a6 100644 --- a/src/Grid/fip/str_tok.cpp +++ b/src/Grid/fip/str_tok.cpp @@ -88,7 +88,7 @@ char *str123tok(char **string,char *delims,long *str_len) *string += strspn(*string,delims); /* IF INPUT STRING POINTER IS NULL CHARACTER, RETURN NULL */ - if (**string == NC) return(NULL); + if (**string == NC) return(nullptr); /* SET START STRING POINTER TO INPUT STRING POINTER */ st_str = *string; @@ -99,10 +99,10 @@ char *str123tok(char **string,char *delims,long *str_len) tmp_str = strpbrk(*string,delims); /* IF TEMPORARY STRING POINTER IS NULL */ - if (tmp_str == NULL) { + if (tmp_str == nullptr) { /* SET INPUT STRING POINTER TO END OF STRING */ - for(i = 0, *str_len = _tcslen(st_str); i < *str_len; (*string)++, i++); + for(i = 0, *str_len = static_cast(_tcslen(st_str)); i < *str_len; (*string)++, i++); } else { diff --git a/src/Grid/fip/wint.cpp b/src/Grid/fip/wint.cpp index 31cf1c63..83d9a873 100644 --- a/src/Grid/fip/wint.cpp +++ b/src/Grid/fip/wint.cpp @@ -78,7 +78,7 @@ int w123int(FILE *fp,long i_val,long o_len) i123toa(i_val,int_str); /* GET STRING LENGTH OF INT_STR */ - s_len = _tcslen(int_str); + s_len = static_cast(_tcslen(int_str)); /* IF LEN OF INT_STR LESS THAN O_LEN AND O_LEN NOT ZERO */ if (s_len < o_len && o_len) { diff --git a/src/Grid/fip/wr_ddsfl.cpp b/src/Grid/fip/wr_ddsfl.cpp index 6f50a27f..75458b03 100644 --- a/src/Grid/fip/wr_ddsfl.cpp +++ b/src/Grid/fip/wr_ddsfl.cpp @@ -572,14 +572,14 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) } /* ALLOCATE NEW_DD */ - if ((new_dd = (struct dd *) malloc(sizeof(struct dd))) == NULL) return(0); + if ((new_dd = static_cast(malloc(sizeof(struct dd)))) == nullptr) return(0); /* SET POINTERS TO NULL */ - new_dd->name = NULL; - new_dd->dim_lptr = NULL; - new_dd->labels = NULL; - new_dd->fmt_rt = NULL; - new_dd->next = NULL; + new_dd->name = nullptr; + new_dd->dim_lptr = nullptr; + new_dd->labels = nullptr; + new_dd->fmt_rt = nullptr; + new_dd->next = nullptr; /* SET FD_CNTRL TO NULL CHARACTER */ new_dd->fd_cntrl[FCDSTYPE] = NC; @@ -604,19 +604,19 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) if (cur_fm->dl_hd->s_tag == 0) { /* SET TAG SIZE TO LENGTH OF INPUT TAG */ - cur_fm->dl_hd->s_tag = _tcslen(tag); + cur_fm->dl_hd->s_tag = static_cast(_tcslen(tag)); } /* IF CR_HD NOT ALLOCATED */ - if (cur_fm->cr_hd == NULL) { + if (cur_fm->cr_hd == nullptr) { /* ALLOCATE CR_HD */ - if ((new_cr = (struct cr *) malloc (sizeof (struct cr))) == NULL) return(0); + if ((new_cr = (struct cr *) malloc (sizeof (struct cr))) == nullptr) return(0); /* SET POINTERS TO NULL */ - new_cr->f_title = NULL; - new_cr->tag_l = NULL; - new_cr->u_afd = NULL; + new_cr->f_title = nullptr; + new_cr->tag_l = nullptr; + new_cr->u_afd = nullptr; /* SET CR_HD TO NEW_CR */ cur_fm->cr_hd = new_cr; @@ -636,8 +636,8 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) /* ALLOCATE SPACE TO HOLD INPUT STRING WR_STR--INCLUDE VALID SUBFIELD FLAG IN LENGTH CALCULATION */ - len = (size_t) _tcslen(wr_str) + validsfld; - if ((i_str = (char *) malloc (len * sizeof(char))) == NULL) return(0); + len = _tcslen(wr_str) + validsfld; + if ((i_str = static_cast(malloc(len * sizeof(char)))) == nullptr) return(0); *i_str = NC; /* IF VALID SUBFIELD, COPY WR_STR TO I_STR */ @@ -655,23 +655,23 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) else if (int_tag == 2) { /* IF CR_HD NOT ALLOCATED */ - if (cur_fm->cr_hd == NULL) { + if (cur_fm->cr_hd == nullptr) { /* ALLOCATE CR_HD */ - if ((new_cr = (struct cr *) malloc (sizeof (struct cr))) == NULL) return(0); + if ((new_cr = (struct cr *) malloc (sizeof (struct cr))) == nullptr) return(0); /* SET POINTERS TO NULL */ - new_cr->f_title = NULL; - new_cr->tag_l = NULL; - new_cr->u_afd = NULL; + new_cr->f_title = nullptr; + new_cr->tag_l = nullptr; + new_cr->u_afd = nullptr; /* SET CR_HD TO NEW_CR */ cur_fm->cr_hd = new_cr; } /* ALLOCATE SPACE TO HOLD INPUT STRING WR_STR */ - len = (size_t) _tcslen(wr_str) + 1; - if ((i_str = (char *) malloc (len*sizeof(char))) == NULL) return(0); + len = _tcslen(wr_str) + 1; + if ((i_str = static_cast(malloc(len * sizeof(char)))) == nullptr) return(0); *i_str = NC; /* COPY WR_STR TO I_STR */ @@ -707,8 +707,8 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) /* ALLOCATE SPACE TO HOLD INPUT STRING WR_STR --INCLUDE VALID SUBFIELD FLAG IN LENGTH CALCULATION */ - len = (size_t) _tcslen(wr_str) + validsfld; - if ((i_str = (char *) malloc (len*sizeof(char))) == NULL) return(0); + len = _tcslen(wr_str) + validsfld; + if ((i_str = static_cast(malloc(len * sizeof(char)))) == NULL) return(0); *i_str = NC; /* IF VALID SUBFIELD, COPY WR_STR TO I_STR */ @@ -777,7 +777,7 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) case 5: /* IF DD_HD NEXT IS NULL, RETURN FAILURE */ - if (cur_fm->dd_hd->next == NULL) return(0); + if (cur_fm->dd_hd->next == nullptr) return(0); /* CASE STATE */ switch (cur_fm->sf_state_dd) { @@ -799,8 +799,8 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) /* ALLOCATE SPACE TO HOLD INPUT STRING I_STR --INCLUDE VALID SUBFIELD FLAG IN LENGTH CALCULATION */ - len = (size_t) _tcslen(wr_str) + validsfld; - if ((i_str = (char *) malloc (len * sizeof(char))) == NULL) return(0); + len = _tcslen(wr_str) + validsfld; + if ((i_str = static_cast(malloc(len * sizeof(char)))) == nullptr) return(0); *i_str = NC; /* IF VALID SUBFIELD, COPY WR_STR TO I_STR */ @@ -826,8 +826,8 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) /* ALLOCATE SPACE TO HOLD WR_STR --INCLUDE VALID SUBFIELD FLAG IN LENGTH CALCULATION */ - len = (size_t) _tcslen(wr_str) + validsfld; - if ((i_str = (char *) malloc (len*sizeof(char))) == NULL) return(0); + len = _tcslen(wr_str) + validsfld; + if ((i_str = static_cast(malloc(len * sizeof(char)))) == nullptr) return(0); *i_str = NC; /* IF VALID SUBFIELD, COPY WR_STR TO I_STR */ @@ -950,23 +950,23 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) if (int_tag == 2) { /* IF CR_HD NOT ALLOCATED */ - if (cur_fm->cr_hd == NULL) { + if (cur_fm->cr_hd == nullptr) { /* ALLOCATE CR_HD */ - if ((new_cr = (struct cr *) malloc (sizeof (struct cr))) == NULL) return(0); + if ((new_cr = static_cast(malloc(sizeof(struct cr)))) == nullptr) return(0); /* SET POINTERS TO NULL */ - new_cr->f_title = NULL; - new_cr->tag_l = NULL; - new_cr->u_afd = NULL; + new_cr->f_title = nullptr; + new_cr->tag_l = nullptr; + new_cr->u_afd = nullptr; /* SET CR_HD TO NEW_CR */ cur_fm->cr_hd = new_cr; } /* ALLOCATE SPACE TO HOLD INPUT STRING WR_STR */ - len = (size_t) _tcslen(wr_str) + 1; - if ((i_str = (char *) malloc (len * sizeof(char))) == NULL) return(0); + len = _tcslen(wr_str) + 1; + if ((i_str = static_cast(malloc(len * sizeof(char)))) == nullptr) return(0); *i_str = NC; /* COPY WR_STR TO I_STR */ @@ -984,14 +984,14 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) case 1: /* ALLOCATE NEW_DD */ - if ((new_dd = (struct dd *) malloc(sizeof(struct dd))) == NULL) return(0); + if ((new_dd = static_cast(malloc(sizeof(struct dd)))) == nullptr) return(0); /* SET POINTERS TO NULL */ - new_dd->name = NULL; - new_dd->dim_lptr = NULL; - new_dd->labels = NULL; - new_dd->fmt_rt = NULL; - new_dd->next = NULL; + new_dd->name = nullptr; + new_dd->dim_lptr = nullptr; + new_dd->labels = nullptr; + new_dd->fmt_rt = nullptr; + new_dd->next = nullptr; /* SET FD_CNTRL TO NULL CHARACTER */ new_dd->fd_cntrl[FCDSTYPE] = NC; @@ -1021,14 +1021,14 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) if (cur_fm->dl_hd->ilevel == 1) { /* ALLOCATE NEW_DD */ - if ((new_dd = (struct dd *) malloc(sizeof(struct dd))) == NULL) return(0); + if ((new_dd = static_cast(malloc(sizeof(struct dd)))) == nullptr) return(0); /* SET POINTERS TO NULL */ - new_dd->name = NULL; - new_dd->dim_lptr = NULL; - new_dd->labels = NULL; - new_dd->fmt_rt = NULL; - new_dd->next = NULL; + new_dd->name = nullptr; + new_dd->dim_lptr = nullptr; + new_dd->labels = nullptr; + new_dd->fmt_rt = nullptr; + new_dd->next = nullptr; /* SET FD_CNTRL TO NULL CHARACTER */ new_dd->fd_cntrl[FCDSTYPE] = NC; @@ -1055,8 +1055,8 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) /* ALLOCATE SPACE TO HOLD INPUT STRING WR_STR --INCLUDE VALID SUBFIELD FLAG IN LENGTH CALCULATION */ - len = (size_t) _tcslen(wr_str) + validsfld; - if ((i_str = (char *) malloc (len * sizeof(char))) == NULL) return(0); + len = _tcslen(wr_str) + validsfld; + if ((i_str = static_cast(malloc(len * sizeof(char)))) == nullptr) return(0); *i_str = NC; /* IF VALID SUBFIELD, COPY WR_STR TO I_STR */ @@ -1071,8 +1071,8 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) /* ALLOCATE SPACE TO HOLD WR_STR --INCLUDE VALID SUBFIELD FLAG IN LENGTH CALCULATION */ - len = (size_t) _tcslen(wr_str) + validsfld; - if ((i_str = (char *) malloc (len * sizeof(char))) == NULL) return(0); + len = _tcslen(wr_str) + validsfld; + if ((i_str = static_cast(malloc(len * sizeof(char)))) == nullptr) return(0); *i_str = NC; /* IF VALID SUBFIELD, COPY WR_STR TO I_STR */ @@ -1080,7 +1080,6 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) /* SET NAME TO I_STR */ cur_fm->cur_dd->name = i_str; - } break; @@ -1162,5 +1161,5 @@ int wr123ddsfld(FILE *fp,char *tag,char *wr_str,int option) /* RETURN SUCCESS */ return (1); -} - +} + diff --git a/src/Grid/lGrid.cpp b/src/Grid/lGrid.cpp index dc099174..4b20f658 100644 --- a/src/Grid/lGrid.cpp +++ b/src/Grid/lGrid.cpp @@ -20,7 +20,7 @@ extern ESRI_GRIDDELETE_PROC griddelete; extern ESRI_CELLLAYERCREATE_PROC celllayercreate; lGrid::lGrid() -{ data = NULL; +{ data = nullptr; isInRam = true; findNewMax = false; findNewMin = false; @@ -33,16 +33,16 @@ lGrid::lGrid() current_row = -1; //BINARY - row_one = NULL; - row_two = NULL; - row_three = NULL; - file_in_out = NULL; + row_one = nullptr; + row_two = nullptr; + row_three = nullptr; + file_in_out = nullptr; //ESRI - grid_layer = -1; - row_buf1 = NULL; - row_buf2 = NULL; - row_buf3 = NULL; + grid_layer = -1; + row_buf1 = nullptr; + row_buf2 = nullptr; + row_buf3 = nullptr; leadid = 0; initialize_esri(); @@ -50,27 +50,27 @@ lGrid::lGrid() } lGrid::~lGrid() -{ +{ close(); shutdown_esri(); } - + long lGrid::LastErrorCode() { long tmpec = lastErrorCode; lastErrorCode = tkNO_ERROR; return tmpec; } - + //OPERATORS long lGrid::operator()( int Column, int Row ) -{ +{ if( inGrid( Column, Row ) ) { if( isInRam ) - return data[Row][Column]; + return data[Row][Column]; else - return getValueDisk( Column, Row ); + return getValueDisk( Column, Row ); } else return gridHeader.getNodataValue(); @@ -78,14 +78,14 @@ long lGrid::operator()( int Column, int Row ) //FUNCTIONS bool lGrid::open( const char * cfilename, bool InRam, GRID_TYPE GridType, void (*callback)( int number, const char * message ) ) -{ +{ CString filename = cfilename; - if( data != NULL || file_in_out != NULL ) + if( data != nullptr || file_in_out != nullptr) close(); isInRam = InRam; - + if( filename.GetLength() <= 0 ) { lastErrorCode = tkINVALID_FILENAME; return false; @@ -96,9 +96,9 @@ bool lGrid::open( const char * cfilename, bool InRam, GRID_TYPE GridType, void ( gridType = GridType; if( gridType == USE_EXTENSION ) gridType = getGridType( filename ); - + if( isInRam == true ) - return readDiskToMemory( callback ); + return readDiskToMemory( callback ); else { //1. Read the header information //2. Find the min and max @@ -108,7 +108,7 @@ bool lGrid::open( const char * cfilename, bool InRam, GRID_TYPE GridType, void ( } bool lGrid::readDiskToMemory( void (*callback)(int number, const char * message ) ) -{ +{ if( gridType == ASCII_GRID ) return asciiReadDiskToMemory( callback ); else if( gridType == BINARY_GRID ) @@ -135,30 +135,30 @@ bool lGrid::readDiskToDisk( void (*callback)(int number, const char * message ) */ lastErrorCode = tkINVALID_GRID_FILE_TYPE; return false; -} +} bool lGrid::writeMemoryToDisk( void(*callback)(int number, const char * message ) ) { if( gridType == ASCII_GRID ) return asciiWriteMemoryToDisk( callback ); else if( gridType == BINARY_GRID ) - return binaryWriteMemoryToDisk( callback ); + return binaryWriteMemoryToDisk( callback ); else if( gridType == ESRI_GRID ) - return esriWriteMemoryToDisk( callback ); + return esriWriteMemoryToDisk( callback ); /* else if( gridType == SDTS_GRID ) return sdtsWriteMemoryToDisk( callback ); */ lastErrorCode = tkINVALID_GRID_FILE_TYPE; - return false; + return false; } bool lGrid::writeDiskToDisk() -{ +{ if( gridType == ASCII_GRID ) return asciiWriteDiskToDisk(); else if( gridType == BINARY_GRID ) - return binaryWriteDiskToDisk(); + return binaryWriteDiskToDisk(); else if( gridType == ESRI_GRID ) return esriWriteDiskToDisk(); /* @@ -166,19 +166,19 @@ bool lGrid::writeDiskToDisk() return sdtsWriteDiskToDisk( callback ); */ lastErrorCode = tkINVALID_GRID_FILE_TYPE; - return false; + return false; } bool lGrid::initialize( const char * cfilename, lHeader header, long initialValue, bool InRam, GRID_TYPE GridType ) -{ +{ CString filename = cfilename; close(); - isInRam = InRam; + isInRam = InRam; gridFilename = filename; gridHeader = header; - + gridType = GridType; if( gridType == USE_EXTENSION ) gridType = getGridType( filename ); @@ -192,11 +192,11 @@ bool lGrid::initialize( const char * cfilename, lHeader header, long initialValu isInRam = true; // Force inram true for ascii grids; no support for disk-based ascii grids. if( isInRam == true ) - { - if (data != NULL) + { + if (data != nullptr) { delete [] data; - data = NULL; + data = nullptr; } data = new long*[ gridHeader.getNumberRows() ]; for( int y = 0; y < gridHeader.getNumberRows(); y++ ) @@ -212,7 +212,7 @@ bool lGrid::initialize( const char * cfilename, lHeader header, long initialValu return true; } else - { + { if( gridType == BINARY_GRID ) return binaryInitializeDisk( initialValue ); else if( gridType == ESRI_GRID ) @@ -252,37 +252,37 @@ bool lGrid::close() // This change is made in sGrid, dGrid, fGrid, and lGrid. bool result = true; - if( file_in_out != NULL ) + if( file_in_out != nullptr) { fclose( file_in_out ); - file_in_out = NULL; + file_in_out = nullptr; } - if( row_one != NULL ) + if( row_one != nullptr) { delete [] row_one; - row_one = NULL; + row_one = nullptr; } - if( row_two != NULL ) + if( row_two != nullptr) { delete [] row_two; - row_two = NULL; + row_two = nullptr; } - if( row_three != NULL ) + if( row_three != nullptr) { delete [] row_three; - row_three = NULL; + row_three = nullptr; } - if( row_buf1 != NULL ) - { CFree1((char *)row_buf1); - row_buf1 = NULL; + if( row_buf1 != nullptr) + { CFree1(static_cast(row_buf1)); + row_buf1 = nullptr; } - if( row_buf2 != NULL ) - { CFree1((char *)row_buf2); - row_buf2 = NULL; + if( row_buf2 != nullptr) + { CFree1(static_cast(row_buf2)); + row_buf2 = nullptr; } - if( row_buf3 != NULL ) - { CFree1((char *)row_buf3); - row_buf3 = NULL; + if( row_buf3 != nullptr) + { CFree1(static_cast(row_buf3)); + row_buf3 = nullptr; } if( grid_layer >= 0 ) { - if( celllyrclose != NULL ) + if( celllyrclose != nullptr) celllyrclose(grid_layer); grid_layer = -1; } @@ -292,17 +292,17 @@ bool lGrid::close() #pragma optimize("", on) bool lGrid::save( const char * cfilename, GRID_TYPE GridType, void (*callback)(int number, const char * message ) ) -{ +{ CString filename = cfilename; if( isInRam == true ) { if( filename.GetLength() > 0 ) gridFilename = filename; - + if( GridType == USE_EXTENSION ) GridType = getGridType( gridFilename ); - + // Save was successful. Update my grid type to be the new grid type. gridType = GridType; @@ -320,9 +320,9 @@ bool lGrid::save( const char * cfilename, GRID_TYPE GridType, void (*callback)(i } } else - { + { if( filename.GetLength() <= 0 ) - return writeDiskToDisk(); + return writeDiskToDisk(); //Convert the Grid else { if( GridType == USE_EXTENSION ) @@ -335,7 +335,7 @@ bool lGrid::save( const char * cfilename, GRID_TYPE GridType, void (*callback)(i gridFilename += "\\"; } - + if( GridType == ASCII_GRID ) { if ( asciiSaveAs( filename, callback ) ) @@ -374,9 +374,9 @@ inline long lGrid::getValue( int Column, int Row ) if( inGrid( Column, Row ) ) { if( isInRam ) - return data[Row][Column]; + return data[Row][Column]; else - return getValueDisk( Column, Row ); + return getValueDisk( Column, Row ); } else { lastErrorCode = tkINDEX_OUT_OF_BOUNDS; @@ -398,7 +398,7 @@ inline long lGrid::getValueDisk( int Column, int Row ) } void lGrid::setValue( int Column, int Row, long Value ) -{ +{ if( inGrid( Column, Row ) ) { if( max == gridHeader.getNodataValue() ) @@ -418,7 +418,7 @@ void lGrid::setValue( int Column, int Row, long Value ) if( isInRam ) data[Row][Column] = Value; else - setValueDisk( Column, Row, Value ); + setValueDisk( Column, Row, Value ); } else lastErrorCode = tkINDEX_OUT_OF_BOUNDS; @@ -432,15 +432,15 @@ inline void lGrid::setValueDisk( int Column, int Row, long Value ) else if( gridType == ESRI_GRID ) esriSetValueDisk( Column, Row, Value ); else if( gridType == SDTS_GRID ) - return; + return; } void lGrid::dealloc() -{ if( isInRam && data != NULL ) +{ if( isInRam && data != nullptr) { for( int y = 0; y < gridHeader.getNumberRows(); y++ ) - delete [] data[y]; - delete [] data; - data = NULL; + delete [] data[y]; + delete [] data; + data = nullptr; } gridHeader.setNumberRows( 0 ); gridHeader.setNumberCols( 0 ); @@ -452,16 +452,16 @@ void lGrid::alloc() { if( isInRam ) { if( gridHeader.getNumberCols() > 0 && gridHeader.getNumberRows() > 0 ) - { - if (data != NULL) + { + if (data != nullptr) { delete [] data; - data = NULL; + data = nullptr; } data = new long *[gridHeader.getNumberRows()]; for( int y = 0; y < gridHeader.getNumberRows(); y++ ) - data[y] = new long[gridHeader.getNumberCols()]; - } + data[y] = new long[gridHeader.getNumberCols()]; + } } } @@ -499,9 +499,9 @@ void lGrid::CellToProj( long column, long row, double & x, double & y ) inline int lGrid::round( double d ) { if( ceil(d) - d <= .5 ) - return (int)ceil(d); + return static_cast(ceil(d)); else - return (int)floor(d); + return static_cast(floor(d)); } void lGrid::clear(long clearValue) @@ -512,7 +512,7 @@ void lGrid::clear(long clearValue) int nrows= gridHeader.getNumberRows(); for( int j = 0; j < nrows; j++ ) { for( int i = 0; i < ncols; i++ ) - data[j][i] = clearValue; + data[j][i] = clearValue; } } else @@ -623,7 +623,7 @@ long lGrid::minimum() { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { long val = getValue( i, j ); - // find both min and max at the same time + // find both min and max at the same time if( min == nodata_value ) min = val; else if( val < min && val != nodata_value ) @@ -653,11 +653,11 @@ GRID_TYPE lGrid::getGridType( const char * filename ) { GRID_TYPE grid_type = INVALID_GRID_TYPE; - if( filename != NULL && _tcslen( filename ) > 0 ) + if( filename != nullptr && _tcslen( filename ) > 0 ) { char * clean_filename = new char[_tcslen( filename ) + 1]; strcpy( clean_filename, filename ); - for( int i = _tcslen( clean_filename ) - 1; i >= 0; i-- ) + for( int i = static_cast(_tcslen( clean_filename )) - 1; i >= 0; i-- ) { if( clean_filename[i] == '\\' || clean_filename[i] == '/' ) clean_filename[i] = '\0'; else @@ -688,7 +688,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) cff.Close(); //File does not exist so parse it out - int length = _tcslen(filename ); + int length = static_cast(_tcslen(filename )); bool foundPeriod = false; for( int e = length-1; e >= 0; e-- ) { if( filename[e] == '\\' || filename[e] == '/' ) @@ -708,7 +708,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) delete [] clean_filename; return ESRI_GRID; } - + if( length > 4 ) { char ext[4]; @@ -757,7 +757,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) ///\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ bool lGrid::asciiReadDiskToMemory( void (*callback)(int number, const char * message ) ) - { + { ifstream in(gridFilename); if( !in ) @@ -780,21 +780,21 @@ GRID_TYPE lGrid::getGridType( const char * filename ) { lastErrorCode = tkZERO_ROWS_OR_COLS; return false; } - { if( callback != NULL ) + { if( callback != nullptr) callback( 0, "Allocating and Initializing Memory" ); alloc(); } - + for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { num_read++; if( !in ) { dealloc(); - return false; + return false; } - in>>data[j][i]; + in>>data[j][i]; if( min == nodata ) { min = data[j][i]; max = data[j][i]; @@ -809,13 +809,13 @@ GRID_TYPE lGrid::getGridType( const char * filename ) } } - if( callback != NULL ) - { int newpercent = (int)(((num_read)/total)*100); + if( callback != nullptr) + { int newpercent = static_cast(((num_read) / total) * 100); if( newpercent > percent ) { percent = newpercent; - callback( percent, "Reading Ascii Grid" ); + callback( percent, "Reading Ascii Grid" ); } - } + } } } asciiReadFooter( in ); @@ -838,7 +838,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) return false; } else - { + { asciiWriteHeader(out); double total = gridHeader.getNumberRows()*gridHeader.getNumberCols(); int percent = 0; @@ -850,21 +850,21 @@ GRID_TYPE lGrid::getGridType( const char * filename ) out<((num_written / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Writing Ascii Grid" ); - } + } } } out<>dy; gridHeader.setDy( dy ); return true; @@ -1056,7 +1056,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) return false; } else - { + { asciiWriteHeader(out); double total = gridHeader.getNumberRows()*gridHeader.getNumberCols(); int percent = 0; @@ -1065,16 +1065,16 @@ GRID_TYPE lGrid::getGridType( const char * filename ) for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { num_written++; - + out< percent ) { percent = newpercent; callback( percent, "Writing Ascii Grid" ); - } + } } } out< percent ) @@ -1164,34 +1164,32 @@ GRID_TYPE lGrid::getGridType( const char * filename ) callback( percent, "Reading Binary Grid" ); } } - } - } - + } + fclose(in); - return true; + return true; } - } bool lGrid::binaryReadDiskToDisk() - { + { file_in_out = fopen( gridFilename, "r+b" ); - + if( !file_in_out ) { lastErrorCode = tkCANT_CREATE_FILE; return false; } else - { - binaryReadHeader(file_in_out); - + { + binaryReadHeader(file_in_out); + if( gridHeader.getNumberCols() < 0 || gridHeader.getNumberRows() < 0 || gridHeader.getDx() < 0 || gridHeader.getDy() < 0 || data_type != LONG_TYPE ) { dealloc(); fclose( file_in_out ); - file_in_out = NULL; + file_in_out = nullptr; lastErrorCode = tkINCOMPATIBLE_DATA_TYPE; return false; } @@ -1243,27 +1241,27 @@ GRID_TYPE lGrid::getGridType( const char * filename ) findNewMax = findNewMin = true; if( gridHeader.getNumberCols() > 0 ) - { + { row_one = new long[gridHeader.getNumberCols()]; row_two = new long[gridHeader.getNumberCols()]; row_three = new long[gridHeader.getNumberCols()]; - binaryBufferRows( 1 ); - } - return true; - } + binaryBufferRows( 1 ); + } + return true; + } } bool lGrid::binaryWriteMemoryToDisk( void(*callback)(int number, const char * message ) ) - { + { FILE * out = fopen( gridFilename, "wb" ); - + if( !out ) { lastErrorCode = tkCANT_CREATE_FILE; return false; } else - { + { binaryWriteHeader(out); double total = gridHeader.getNumberRows() * gridHeader.getNumberCols(); int percent = 0; @@ -1272,22 +1270,22 @@ GRID_TYPE lGrid::getGridType( const char * filename ) for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { num_written++; - + fwrite( &data[j][i],sizeof(long),1,out); - if( callback != NULL ) + if( callback != nullptr) { int newpercent = (int)((num_written/total)*100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Binary Grid Write"); - } + } } - } + } } fclose( out ); - return true; - } + return true; + } } bool lGrid::binaryWriteDiskToDisk() @@ -1298,12 +1296,11 @@ GRID_TYPE lGrid::getGridType( const char * filename ) { rewind( file_in_out ); binaryWriteHeader(file_in_out); return true; - } - + } } bool lGrid::binaryInitializeDisk( long initialValue ) - { + { file_in_out = fopen( gridFilename, "w+b" ); if( !file_in_out ) @@ -1311,20 +1308,20 @@ GRID_TYPE lGrid::getGridType( const char * filename ) return false; } else - { + { binaryWriteHeader(file_in_out); file_position_beg_of_data = ftell( file_in_out); for( int j = gridHeader.getNumberRows() - 1; j >= 0; j-- ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { - fwrite( &initialValue,sizeof(long),1,file_in_out); - } + fwrite( &initialValue,sizeof(long),1,file_in_out); + } } - + min = initialValue; max = initialValue; - + current_row = 0; row_one = new long[gridHeader.getNumberCols()]; row_two = new long[gridHeader.getNumberCols()]; @@ -1336,7 +1333,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) row_three[i] = initialValue; } } - return true; + return true; } void lGrid::binaryReadHeader( FILE * in ) @@ -1369,7 +1366,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) fread( &data_type, sizeof(DATA_TYPE),1,in); long nodata_value; - fread( &nodata_value, sizeof(long),1,in); + fread( &nodata_value, sizeof(long),1,in); gridHeader.setNodataValue( nodata_value ); char * projection = new char[MAX_STRING_LENGTH + 1]; @@ -1402,13 +1399,13 @@ GRID_TYPE lGrid::getGridType( const char * filename ) fwrite( &type, sizeof(DATA_TYPE),1,out); long nodata = gridHeader.getNodataValue(); fwrite( &nodata, sizeof(long),1,out); - + char * projection = new char[MAX_STRING_LENGTH + 1]; strcpy( projection, gridHeader.getProjection() ); if( _tcslen( projection ) > 0 ) fwrite( projection, sizeof(char), _tcslen(projection),out); if( _tcslen( projection ) < MAX_STRING_LENGTH ) - { int size_of_pad = MAX_STRING_LENGTH - _tcslen(projection); + { int size_of_pad = MAX_STRING_LENGTH - static_cast(_tcslen(projection)); char * pad = new char[size_of_pad]; for( int p = 0; p < size_of_pad; p++ ) pad[p] = 0; @@ -1422,13 +1419,13 @@ GRID_TYPE lGrid::getGridType( const char * filename ) if( _tcslen( notes ) > 0 ) fwrite( notes, sizeof(char), _tcslen(notes), out); if( _tcslen( notes ) < MAX_STRING_LENGTH ) - { int size_of_pad = MAX_STRING_LENGTH - _tcslen(notes); + { int size_of_pad = MAX_STRING_LENGTH - static_cast(_tcslen(notes)); char * pad = new char[size_of_pad]; for( int p = 0; p < size_of_pad; p++ ) pad[p] = 0; fwrite(pad, sizeof(char), size_of_pad, out ); delete [] pad; - } + } delete [] notes; } @@ -1443,28 +1440,28 @@ GRID_TYPE lGrid::getGridType( const char * filename ) else { binaryBufferRows( Row ); return row_two[ Column ]; - } + } } void lGrid::binarySetValueDisk( int Column, int Row, long Value ) { long file_position = file_position_beg_of_data + sizeof(long)*Row*gridHeader.getNumberCols() + sizeof(long)*Column; - + if( fseek( file_in_out, file_position, SEEK_SET ) == -1L ) {} else - { + { if( fwrite( &Value, sizeof(long), 1, file_in_out ) < 1 ) - {} + {} else { if( Row == current_row - 1 ) row_one[ Column ] = Value; else if( Row == current_row ) row_two[ Column ] = Value; else if( Row == current_row + 1 ) - row_three[ Column ] = Value; + row_three[ Column ] = Value; } - } + } } void lGrid::binaryClearDisk(long clearValue) @@ -1472,14 +1469,14 @@ GRID_TYPE lGrid::getGridType( const char * filename ) if( fseek( file_in_out, file_position_beg_of_data, SEEK_SET ) == -1L ) return; else - { + { for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { if( fwrite( &clearValue, sizeof(long), 1, file_in_out ) < 1 ) return; } - } - } + } + } } void lGrid::binaryBufferRows( int center_row ) @@ -1498,7 +1495,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) } else nd_fill_one = true; - + if( gridHeader.getNumberRows() >= center_row && center_row >= 0 ) { long file_position = file_position_beg_of_data + sizeof(long)*(center_row)*gridHeader.getNumberCols(); @@ -1533,18 +1530,18 @@ GRID_TYPE lGrid::getGridType( const char * filename ) row_two[i] = gridHeader.getNodataValue(); if( nd_fill_three ) row_three[i] = gridHeader.getNodataValue(); - } + } } } bool lGrid::binarySaveAs( CString filename, void(*callback)(int number, const char * message) ) - { + { // Write to a temporary file first. char tempName[ FILENAME_MAX ] = {0}; tmpnam(tempName); FILE * out = fopen( tempName, "wb" ); - + if( !out ) return false; @@ -1561,20 +1558,20 @@ GRID_TYPE lGrid::getGridType( const char * filename ) value = getValue( i, j ); fwrite( &value,sizeof(long),1,out); - if( callback != NULL ) + if( callback != nullptr) { int newpercent = (int)((num_written/total)*100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Binary Grid Write"); - } + } } - } + } } fclose( out ); if( isInRam == true ) - { + { if( !MoveFileEx(tempName, filename, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED) ) @@ -1584,7 +1581,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) } else { close(); - + if( !MoveFileEx(tempName, filename, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED) ) @@ -1610,31 +1607,31 @@ GRID_TYPE lGrid::getGridType( const char * filename ) #pragma optimize("", off) bool lGrid::esriReadDiskToMemory( void (*callback)(int number, const char * message ) ) { - if( celllayeropen == NULL || - celllyrclose == NULL || - bndcellread == NULL || - privateaccesswindowset == NULL || - privatewindowcols == NULL || - privatewindowrows == NULL || - getwindowrow == NULL ) + if( celllayeropen == nullptr || + celllyrclose == nullptr || + bndcellread == nullptr || + privateaccesswindowset == nullptr || + privatewindowcols == nullptr || + privatewindowrows == nullptr || + getwindowrow == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; } - double csize; + double csize; double bndbox[4]; double adjbndbox[4]; long nodata = -1; int cell_type; - - char * fname = new char[_MAX_PATH+1]; + + char * fname = new char[_MAX_PATH+1]; if( GetShortPathName(gridFilename,fname,_MAX_PATH) == 0 ) - strcpy( fname, gridFilename ); + strcpy( fname, gridFilename ); grid_layer = celllayeropen(fname,READONLY,ROWIO,&cell_type,&csize); if( grid_layer >= 0 ) - { + { //Get the bounding box of the input cell layer //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner if( bndcellread(fname,bndbox) < 0 ) @@ -1651,7 +1648,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) gridHeader.setDx( csize ); gridHeader.setDy( csize ); gridHeader.setNodataValue( nodata ); - + //Need to find cell_type if( cell_type == CELLINT ) { nodata = MISSINGINT; @@ -1662,10 +1659,10 @@ GRID_TYPE lGrid::getGridType( const char * filename ) celllyrclose(grid_layer); grid_layer = -1; lastErrorCode = tkINVALID_GRID_FILE_TYPE; - return false; + return false; } - - //Set the Window to the output bounding box and cellsize + + //Set the Window to the output bounding box and cellsize if( privateaccesswindowset(grid_layer,bndbox,csize,adjbndbox) < 0) { dealloc(); //Close handle @@ -1674,7 +1671,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) lastErrorCode = tkESRI_ACCESS_WINDOW_SET; return false; } - + //Get the number of rows and columns in the window gridHeader.setNumberCols( privatewindowcols(grid_layer) ); gridHeader.setNumberRows( privatewindowrows(grid_layer) ); @@ -1695,9 +1692,9 @@ GRID_TYPE lGrid::getGridType( const char * filename ) alloc(); //Now copy row major into array - //Allocate row buffer + //Allocate row buffer row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( row_buf1 == NULL ) + if ( row_buf1 == nullptr) { dealloc(); //Close handle celllyrclose(grid_layer); @@ -1708,7 +1705,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) int percent = 0; double total = gridHeader.getNumberRows(); - + //Find the min and max long nodata = gridHeader.getNodataValue(); min = nodata; @@ -1716,11 +1713,11 @@ GRID_TYPE lGrid::getGridType( const char * filename ) for ( int j = 0; j < gridHeader.getNumberRows(); j++) { if( cell_type == CELLINT) - { getwindowrow(grid_layer, j, (CELLTYPE*)row_buf1); + { getwindowrow(grid_layer, j, static_cast(row_buf1)); - register int *buf = (int *)row_buf1; + register int *buf = static_cast(row_buf1); for( int i = 0; i < gridHeader.getNumberCols(); i++) - { + { if( buf[i] == MISSINGINT ) data[j][i] = nodata; else @@ -1734,15 +1731,15 @@ GRID_TYPE lGrid::getGridType( const char * filename ) if( max == nodata ) max = buf[i]; else if( buf[i] > max ) - max = buf[i]; + max = buf[i]; } - } - } + } + } - int newpercent = (int)((j/total)*100); + int newpercent = static_cast((j / total) * 100); if( newpercent > percent ) { percent = newpercent; - if( callback != NULL ) + if( callback != nullptr) callback( percent, "Reading Esri Grid" ); } @@ -1750,19 +1747,19 @@ GRID_TYPE lGrid::getGridType( const char * filename ) //Free row buffer CFree1((char *)row_buf1); - row_buf1 = NULL; - + row_buf1 = nullptr; + //Close handle celllyrclose(grid_layer); grid_layer = -1; return true; - } + } else { dealloc(); grid_layer = -1; lastErrorCode = tkESRI_LAYER_OPEN; return false; - } + } } #pragma optimize("", on) @@ -1770,31 +1767,31 @@ GRID_TYPE lGrid::getGridType( const char * filename ) bool lGrid::esriReadDiskToDisk() { //Check for the needed functions - if( bndcellread == NULL || - celllyrclose == NULL || - celllayeropen == NULL || - privateaccesswindowset == NULL || - privatewindowcols == NULL || - privatewindowrows == NULL || - getwindowrow == NULL ) + if( bndcellread == nullptr || + celllyrclose == nullptr || + celllayeropen == nullptr || + privateaccesswindowset == nullptr || + privatewindowcols == nullptr || + privatewindowrows == nullptr || + getwindowrow == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; } - double csize; + double csize; double bndbox[4]; double adjbndbox[4]; long nodata = -1; int cell_type; - char * fname = new char[_MAX_PATH+1]; + char * fname = new char[_MAX_PATH+1]; if( GetShortPathName(gridFilename,fname,_MAX_PATH) == 0 ) - strcpy( fname, gridFilename ); + strcpy( fname, gridFilename ); grid_layer = celllayeropen(fname,READWRITE,ROWIO,&cell_type,&csize); if( grid_layer >= 0 ) - { + { //Get the bounding box of the input cell layer //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner @@ -1813,7 +1810,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) gridHeader.setDx( csize ); gridHeader.setDy( csize ); gridHeader.setNodataValue( nodata ); - + //Needed to find type if( cell_type == CELLINT ) { nodata = MISSINGINT; @@ -1825,10 +1822,10 @@ GRID_TYPE lGrid::getGridType( const char * filename ) grid_layer = -1; lastErrorCode = tkINVALID_GRID_FILE_TYPE; delete [] fname; - return false; + return false; } - - //Set the Window to the output bounding box and cellsize + + //Set the Window to the output bounding box and cellsize if( privateaccesswindowset(grid_layer,bndbox,csize,adjbndbox) < 0) { dealloc(); //Close handle @@ -1856,11 +1853,11 @@ GRID_TYPE lGrid::getGridType( const char * filename ) return false; } - //Allocate row buffer + //Allocate row buffer row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - row_buf2 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - row_buf3 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( row_buf1 == NULL || row_buf2 == NULL || row_buf3 == NULL ) + row_buf2 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); + row_buf3 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); + if ( row_buf1 == nullptr || row_buf2 == nullptr || row_buf3 == nullptr) { dealloc(); //Close handle celllyrclose(grid_layer); @@ -1895,12 +1892,11 @@ GRID_TYPE lGrid::getGridType( const char * filename ) else if( buf[i] > max ) max = buf[i]; } - } - - } */ + } + } */ esriBufferRows( 0 ); delete [] fname; - return true; + return true; } else { dealloc(); @@ -1908,7 +1904,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) lastErrorCode = tkESRI_LAYER_OPEN; delete [] fname; return false; - } + } } #pragma optimize("", on) @@ -1916,20 +1912,20 @@ GRID_TYPE lGrid::getGridType( const char * filename ) bool lGrid::esriWriteMemoryToDisk( void(*callback)(int number, const char * message ) ) { //Check the needed functions - if( celllyrclose == NULL || - celllyrexists == NULL || - celllayercreate == NULL || - griddelete == NULL || - privateaccesswindowset == NULL || - getmissingfloat == NULL || - putwindowrow == NULL ) + if( celllyrclose == nullptr || + celllyrexists == nullptr || + celllayercreate == nullptr || + griddelete == nullptr || + privateaccesswindowset == nullptr || + getmissingfloat == nullptr || + putwindowrow == nullptr ) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; } int cell_type = CELLINT; - + double csize = gridHeader.getDx(); //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner double bndbox[4]; @@ -1938,10 +1934,10 @@ GRID_TYPE lGrid::getGridType( const char * filename ) bndbox[2] = gridHeader.getXllcenter() + gridHeader.getNumberCols()*gridHeader.getDx() - gridHeader.getDx()*.5; bndbox[3] = gridHeader.getYllcenter() + gridHeader.getNumberRows()*gridHeader.getDy() - gridHeader.getDy()*.5; double adjbndbox[4]; - + char * fname = new char[gridFilename.GetLength()+1]; - strcpy( fname, gridFilename ); - + strcpy( fname, gridFilename ); + if( celllyrexists( fname ) != 0 ) griddelete( fname ); @@ -1951,23 +1947,23 @@ GRID_TYPE lGrid::getGridType( const char * filename ) lastErrorCode = tkESRI_LAYER_CREATE; return false; } - + if( privateaccesswindowset( grid_layer, bndbox, csize, adjbndbox) < 0 ) - { + { celllyrclose(grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); grid_layer = -1; lastErrorCode = tkESRI_ACCESS_WINDOW_SET; return false; } - - //Allocate row buffer - row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( row_buf1 == NULL ) + + //Allocate row buffer + row_buf1 = reinterpret_cast(CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE))); + if ( row_buf1 == nullptr) { celllyrclose(grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); grid_layer = -1; lastErrorCode = tkCANT_ALLOC_MEMORY; return false; @@ -1977,32 +1973,32 @@ GRID_TYPE lGrid::getGridType( const char * filename ) int percent = 0; long nodata = gridHeader.getNodataValue(); - register int *buf = (int *)row_buf1; + register int *buf = static_cast(row_buf1); for( int j = 0; j < gridHeader.getNumberRows(); j++) { for( int i = 0; i < gridHeader.getNumberCols(); i++) - { - buf[i] = (int)data[j][i]; + { + buf[i] = (int)data[j][i]; if(buf[i] == nodata) - buf[i] = MISSINGINT; + buf[i] = MISSINGINT; } - putwindowrow( grid_layer, j, (CELLTYPE*)row_buf1); + putwindowrow( grid_layer, j, static_cast(row_buf1)); - int newpercent = (int)((j/total)*100); + int newpercent = static_cast((j / total) * 100); if( newpercent > percent ) { percent = newpercent; - if( callback != NULL ) + if( callback != nullptr) callback( percent, "Writing Esri Grid" ); } } - CFree1 ((char *)row_buf1); - row_buf1 = NULL; + CFree1 ((char *)row_buf1); + row_buf1 = nullptr; - //Close handle + //Close handle celllyrclose(grid_layer); grid_layer = -1; - return true; + return true; } #pragma optimize("", on) @@ -2016,12 +2012,12 @@ GRID_TYPE lGrid::getGridType( const char * filename ) { ////AfxMessageBox("Initializing Esri Grid");// - if( celllyrexists == NULL || - celllyrclose == NULL || - griddelete == NULL || - celllayercreate == NULL || - privateaccesswindowset == NULL || - putwindowrow == NULL ) + if( celllyrexists == nullptr || + celllyrclose == nullptr || + griddelete == nullptr || + celllayercreate == nullptr || + privateaccesswindowset == nullptr || + putwindowrow == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; @@ -2067,33 +2063,33 @@ GRID_TYPE lGrid::getGridType( const char * filename ) if( privateaccesswindowset( grid_layer, bndbox, csize, adjbndbox) < 0 ) { celllyrclose(grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); grid_layer = -1; lastErrorCode = tkESRI_ACCESS_WINDOW_SET; delete [] fname; return false; } - //Allocate row buffer + //Allocate row buffer row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if( row_buf1 == NULL ) - { - celllyrclose(grid_layer); + if( row_buf1 == nullptr) + { + celllyrclose(grid_layer); if( celllyrexists( fname ) ) griddelete( fname ); grid_layer = -1; lastErrorCode = tkCANT_ALLOC_MEMORY; delete [] fname; return false; - } + } ////AfxMessageBox("Pass-Allocation of RowBuf");// - long nodata = gridHeader.getNodataValue(); + long nodata = gridHeader.getNodataValue(); max = nodata; min = nodata; - register int *buf = (int *)row_buf1; + register int *buf = static_cast(row_buf1); if( InitialValue == nodata ) { @@ -2106,18 +2102,18 @@ GRID_TYPE lGrid::getGridType( const char * filename ) } ////AfxMessageBox("Pass-Initialize Buffer");// - + for( int j = 0; j < gridHeader.getNumberRows(); j++) - putwindowrow( grid_layer, j, (CELLTYPE*)row_buf1); + putwindowrow( grid_layer, j, static_cast(row_buf1)); ////AfxMessageBox("Pass-PutWindowRow");// - //Close and Reopen so VAT Table is Written + //Close and Reopen so VAT Table is Written celllyrclose(grid_layer); grid_layer = -1; - CFree1 ((char *)row_buf1); - row_buf1 = NULL; - + CFree1 (static_cast(row_buf1)); + row_buf1 = nullptr; + ////AfxMessageBox("Passed-Calling ReadDiskToDisk"); delete [] fname; return esriReadDiskToDisk(); @@ -2133,41 +2129,42 @@ GRID_TYPE lGrid::getGridType( const char * filename ) return gridHeader.getNodataValue(); if( Row == current_row - 1 ) - { - if( ((int *)row_buf1)[Column] == MISSINGINT ) + { + if( static_cast(row_buf1)[Column] == MISSINGINT ) return gridHeader.getNodataValue(); - return long((((int *)row_buf1)[Column])); + return static_cast(static_cast(row_buf1)[Column]); } else if( Row == current_row ) - { - if( ((int *)row_buf2)[Column] == MISSINGINT ) + { + if( static_cast(row_buf2)[Column] == MISSINGINT ) return gridHeader.getNodataValue(); - return long((((int *)row_buf2)[Column])); + return static_cast(static_cast(row_buf2)[Column]); } else if( Row == current_row + 1 ) - { - if( ((int *)row_buf3)[Column] == MISSINGINT ) + { + if( static_cast(row_buf3)[Column] == MISSINGINT ) return gridHeader.getNodataValue(); - return long((((int *)row_buf3)[Column])); + return static_cast(static_cast(row_buf3)[Column]); } else - { esriBufferRows( Row ); - - if( ((int *)row_buf2)[Column] == MISSINGINT ) + { + esriBufferRows( Row ); + + if( static_cast(row_buf2)[Column] == MISSINGINT ) return gridHeader.getNodataValue(); - return long((((int *)row_buf2)[Column])); + return static_cast(static_cast(row_buf2)[Column]); } - - return gridHeader.getNodataValue(); + + return gridHeader.getNodataValue(); } #pragma optimize("", on) #pragma optimize("", off) void lGrid::esriSetValueDisk( int Column, int Row, long Value ) { - if( putwindowrow == NULL ) + if( putwindowrow == nullptr) return; - + int value = Value; //Load the buffers with the current row getValueDisk( Column, Row ); @@ -2176,38 +2173,38 @@ GRID_TYPE lGrid::getGridType( const char * filename ) if( value == gridHeader.getNodataValue() ) value = MISSINGINT; - register int *buf = (int *)row_buf1; + register int *buf = static_cast(row_buf1); buf[Column] = value; - putwindowrow( grid_layer, Row, (CELLTYPE*)row_buf1); + putwindowrow( grid_layer, Row, static_cast(row_buf1)); } else if( Row == current_row ) { if( value == gridHeader.getNodataValue() ) value = MISSINGINT; - - register int *buf = (int *)row_buf2; + + register int *buf = static_cast(row_buf2); buf[Column] = value; - putwindowrow( grid_layer, Row, (CELLTYPE*)row_buf2); + putwindowrow( grid_layer, Row, static_cast(row_buf2)); } else if( Row == current_row + 1 ) { if( value == gridHeader.getNodataValue() ) value = MISSINGINT; - register int *buf = (int *)row_buf3; + register int *buf = static_cast(row_buf3); buf[Column] = value; - putwindowrow( grid_layer, Row, (CELLTYPE*)row_buf3); - } + putwindowrow( grid_layer, Row, static_cast(row_buf3)); + } } #pragma optimize("", on) #pragma optimize("", off) void lGrid::esriClearDisk(long clearValue) { - if( putwindowrow == NULL ) + if( putwindowrow == nullptr) return; - register int *buf = (int *)row_buf1; + register int *buf = static_cast(row_buf1); for( int j = 0; j < gridHeader.getNumberRows(); j++) { long val = clearValue; @@ -2217,32 +2214,32 @@ GRID_TYPE lGrid::getGridType( const char * filename ) { buf[i]=val; } - putwindowrow( grid_layer, j, (CELLTYPE*)row_buf1); + putwindowrow( grid_layer, j, static_cast(row_buf1)); } for( int i = 0; i < gridHeader.getNumberCols(); i++) { buf[i]=clearValue; - } + } - esriBufferRows( 0 ); + esriBufferRows( 0 ); } #pragma optimize("", on) #pragma optimize("", off) void lGrid::esriBufferRows( int center_row ) { - if( getwindowrow == NULL ) + if( getwindowrow == nullptr) { register int *ibuf; - + for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { - ibuf = (int *)row_buf1; + ibuf = static_cast(row_buf1); + ibuf[i] = MISSINGINT; + ibuf = static_cast(row_buf2); ibuf[i] = MISSINGINT; - ibuf = (int *)row_buf2; + ibuf = static_cast(row_buf3); ibuf[i] = MISSINGINT; - ibuf = (int *)row_buf3; - ibuf[i] = MISSINGINT; - } + } return; } @@ -2251,16 +2248,16 @@ GRID_TYPE lGrid::getGridType( const char * filename ) bool nd_fill_three = false; if( gridHeader.getNumberRows() >= center_row -1 && center_row - 1 >= 0 ) - { - getwindowrow(grid_layer, center_row - 1, (CELLTYPE*)row_buf1); + { + getwindowrow(grid_layer, center_row - 1, static_cast(row_buf1)); nd_fill_one = false; } else nd_fill_one = true; if( gridHeader.getNumberRows() >= center_row && center_row >= 0 ) - { - getwindowrow(grid_layer, center_row, (CELLTYPE*)row_buf2); + { + getwindowrow(grid_layer, center_row, static_cast(row_buf2)); nd_fill_two = false; } else @@ -2268,7 +2265,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) if( gridHeader.getNumberRows() >= center_row + 1 && center_row + 1 >= 0 ) { - getwindowrow(grid_layer, center_row + 1, (CELLTYPE*)row_buf3); + getwindowrow(grid_layer, center_row + 1, static_cast(row_buf3)); nd_fill_three = false; } else @@ -2278,25 +2275,25 @@ GRID_TYPE lGrid::getGridType( const char * filename ) //Initialize row to nodata if( nd_fill_one || nd_fill_two || nd_fill_three ) - { + { register int *ibuf; for( int i = 0; i < gridHeader.getNumberCols(); i++ ) - { + { if( nd_fill_one ) - { ibuf = (int *)row_buf1; + { ibuf = static_cast(row_buf1); ibuf[i] = MISSINGINT; } if( nd_fill_two ) - { ibuf = (int *)row_buf2; + { ibuf = static_cast(row_buf2); ibuf[i] = MISSINGINT; } if( nd_fill_three ) - { ibuf = (int *)row_buf3; + { ibuf = static_cast(row_buf3); ibuf[i] = MISSINGINT; - } - } - } + } + } + } } #pragma optimize("", on) @@ -2307,13 +2304,13 @@ GRID_TYPE lGrid::getGridType( const char * filename ) long temp_grid_layer = -1; //Check the needed functions - if( celllyrclose == NULL || - celllyrexists == NULL || - celllayercreate == NULL || - griddelete == NULL || - privateaccesswindowset == NULL || - getmissingfloat == NULL || - putwindowrow == NULL ) + if( celllyrclose == nullptr || + celllyrexists == nullptr || + celllayercreate == nullptr || + griddelete == nullptr || + privateaccesswindowset == nullptr || + getmissingfloat == nullptr || + putwindowrow == nullptr) { temp_grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; @@ -2322,7 +2319,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) ////AfxMessageBox("Pass-Necessary Function");// int cell_type = CELLINT; - + double csize = gridHeader.getDx(); //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner double bndbox[4]; @@ -2332,12 +2329,12 @@ GRID_TYPE lGrid::getGridType( const char * filename ) bndbox[3] = gridHeader.getYllcenter() + gridHeader.getNumberRows()*gridHeader.getDy() - gridHeader.getDy()*.5; double adjbndbox[4]; - + char * fname = new char[filename.GetLength()+1]; - strcpy( fname, filename ); + strcpy( fname, filename ); if( celllyrexists( fname ) != 0 ) griddelete( fname ); - + temp_grid_layer = celllayercreate( fname, WRITEONLY, ROWIO, cell_type, csize, bndbox); if( temp_grid_layer < 0 ) { temp_grid_layer = -1; @@ -2351,21 +2348,21 @@ GRID_TYPE lGrid::getGridType( const char * filename ) if( privateaccesswindowset( temp_grid_layer, bndbox, csize, adjbndbox) < 0 ) { celllyrclose(temp_grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); temp_grid_layer = -1; lastErrorCode = tkESRI_ACCESS_WINDOW_SET; delete [] fname; return false; } - + ////AfxMessageBox("Pass-PrivateAccessWindowSet");// //Allocate row buffer - void * temp_row_buf = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( temp_row_buf == NULL ) + void * temp_row_buf = reinterpret_cast(CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE))); + if ( temp_row_buf == nullptr) { celllyrclose(temp_grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); temp_grid_layer = -1; lastErrorCode = tkCANT_ALLOC_MEMORY; delete [] fname; @@ -2378,37 +2375,37 @@ GRID_TYPE lGrid::getGridType( const char * filename ) int percent = 0; long nodata = gridHeader.getNodataValue(); - register int *buf = (int *)temp_row_buf; + register int *buf = static_cast(temp_row_buf); for( int j = 0; j < gridHeader.getNumberRows(); j++) { for( int i = 0; i < gridHeader.getNumberCols(); i++) { - buf[i] = (int)getValue( i, j ); + buf[i] = static_cast(getValue(i, j)); if(buf[i] == nodata) buf[i] = MISSINGINT; } - putwindowrow( temp_grid_layer, j, (CELLTYPE*)temp_row_buf); + putwindowrow( temp_grid_layer, j, static_cast(temp_row_buf)); - int newpercent = (int)((j/total)*100); + int newpercent = static_cast((j / total) * 100); if( newpercent > percent ) { percent = newpercent; - if( callback != NULL ) + if( callback != nullptr) callback( percent, "Writing Esri Grid" ); } } ////AfxMessageBox("Pass-PutWindowRow"); - CFree1 ((char *)temp_row_buf); - temp_row_buf = NULL; + CFree1 (static_cast(temp_row_buf)); + temp_row_buf = nullptr; if( isInRam == true ) { gridFilename = filename; - //Close handle + //Close handle celllyrclose(temp_grid_layer); temp_grid_layer = -1; delete [] fname; - return true; + return true; } else { celllyrclose(temp_grid_layer); @@ -2416,7 +2413,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) close(); delete [] fname; return open( filename, false, ESRI_GRID, callback ); - } + } } #pragma optimize("", on) @@ -2434,14 +2431,14 @@ GRID_TYPE lGrid::getGridType( const char * filename ) # define null 0 bool lGrid::sdtsReadDiskToMemory( void(*callback)(int number, const char * message ) ) - { - + { + //Initialize the grid strcpy( file_name, gridFilename ); - //Find the byte order of the machine + //Find the byte order of the machine g123order(&order); - + char * fname = new char[ gridFilename.GetLength() + 1]; strcpy( fname, gridFilename ); long fillvalue; @@ -2459,16 +2456,16 @@ GRID_TYPE lGrid::getGridType( const char * filename ) long value = gridHeader.getNodataValue(); double average = 0; int cnt = 0; - + for( int row = 0; row < gridHeader.getNumberRows(); row++ ) - { + { for( int column = 0; column < gridHeader.getNumberCols(); column++ ) { value = getValue( column, row ); average = 0; cnt = 0; if( value == -255 ) - { + { long up = getValue( column, row + 1 ); if( up != nodata_value && up != -255 ) { average += up; @@ -2515,12 +2512,12 @@ GRID_TYPE lGrid::getGridType( const char * filename ) else average = nodata_value; - setValue( column, row, (long)average ); + setValue( column, row, static_cast(average) ); } } } - - return true; + + return true; } bool lGrid::read_sdts_header(char * filename, lHeader & h, long & fillvalue) @@ -2539,8 +2536,8 @@ GRID_TYPE lGrid::getGridType( const char * filename ) double xhrs, yhrs; get_iref(xhrs, yhrs); - h.setDx( (int)xhrs ); - h.setDy( (int)xhrs ); + h.setDx( static_cast(xhrs) ); + h.setDy( static_cast(xhrs) ); get_xref(); @@ -2579,7 +2576,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) { int len,j; //parse out base_name - len = _tcslen(file_name); + len = static_cast(_tcslen(file_name)); for(j=0;j(vscale * u.f); } else { - li = (long)nodata_value; + li = static_cast(nodata_value); } //BIAS FOR ELEVATION if( li < -1000 ) - li = (long)nodata_value; + li = static_cast(nodata_value); //Set the cell value if(li != nodata_value && li != fillvalue) { if(fom == 'f') { - li = (long)(li/3.2808); + li = static_cast(li / 3.2808); } if( li == 32767 || li == -32767 ) @@ -3378,7 +3375,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) else setValue( i, j, (long)li ); - int newpercent = (int)((cnt/total)*100); + int newpercent = static_cast((cnt / total) * 100); if( newpercent > percent ) { percent = newpercent; if( callback ) @@ -3386,7 +3383,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) } } else - setValue( i, j, (long)nodata_value ); + setValue( i, j, static_cast(nodata_value) ); cnt++; i++; } @@ -3475,7 +3472,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) } else if (strstr(frmts, "R")) { - sadr_x = (long) atof(string); + sadr_x = static_cast(atof(string)); } } else if (!strcmp (tag, "SADR") && !strcmp (descr, "Y")) @@ -3492,7 +3489,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) } else if (strstr(frmts, "R")) { - sadr_y = (long) atof(string); + sadr_y = static_cast(atof(string)); } } } while (status != 4); /* Break out of loop at end of file */ @@ -3516,7 +3513,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) char data[1000]; FILE* fp; int len; - char* index = NULL; + char* index = nullptr; baseAndId(); strcpy (file_name,base_name); @@ -3526,7 +3523,7 @@ GRID_TYPE lGrid::getGridType( const char * filename ) if(!fp) return 0; - len = fread(data,sizeof(char),MAX-1,fp); + len = static_cast(fread(data,sizeof(char),MAX-1,fp)); fclose(fp); data[MAX-1] = '\0'; diff --git a/src/Grid/sgrid.cpp b/src/Grid/sgrid.cpp index 6bcf3095..a600be92 100644 --- a/src/Grid/sgrid.cpp +++ b/src/Grid/sgrid.cpp @@ -21,7 +21,7 @@ extern ESRI_GRIDDELETE_PROC griddelete; extern ESRI_CELLLAYERCREATE_PROC celllayercreate; sGrid::sGrid() -{ data = NULL; +{ data = nullptr; isInRam = true; findNewMax = false; findNewMin = false; @@ -34,16 +34,16 @@ sGrid::sGrid() current_row = -1; //BINARY - row_one = NULL; - row_two = NULL; - row_three = NULL; - file_in_out = NULL; + row_one = nullptr; + row_two = nullptr; + row_three = nullptr; + file_in_out = nullptr; //ESRI - grid_layer = -1; - row_buf1 = NULL; - row_buf2 = NULL; - row_buf3 = NULL; + grid_layer = -1; + row_buf1 = nullptr; + row_buf2 = nullptr; + row_buf3 = nullptr; leadid = 0; initialize_esri(); @@ -51,7 +51,7 @@ sGrid::sGrid() } sGrid::~sGrid() -{ +{ close(); shutdown_esri(); @@ -62,16 +62,16 @@ long sGrid::LastErrorCode() lastErrorCode = tkNO_ERROR; return tmpec; } - + //OPERATORS short sGrid::operator()( int Column, int Row ) -{ +{ if( inGrid( Column, Row ) ) { if( isInRam ) - return data[Row][Column]; + return data[Row][Column]; else - return getValueDisk( Column, Row ); + return getValueDisk( Column, Row ); } else return gridHeader.getNodataValue(); @@ -79,13 +79,13 @@ short sGrid::operator()( int Column, int Row ) //FUNCTIONS bool sGrid::open( const char * cfilename, bool InRam, GRID_TYPE GridType, void (*callback)( int number, const char * message ) ) -{ +{ CString filename = cfilename; - if( data != NULL || file_in_out != NULL ) + if( data != nullptr || file_in_out != nullptr) close(); isInRam = InRam; - + if( filename.GetLength() <= 0 ) { lastErrorCode = tkINVALID_FILENAME; return false; @@ -96,9 +96,9 @@ bool sGrid::open( const char * cfilename, bool InRam, GRID_TYPE GridType, void ( gridType = GridType; if( gridType == USE_EXTENSION ) gridType = getGridType( filename ); - + if( isInRam == true ) - return readDiskToMemory( callback ); + return readDiskToMemory( callback ); else { //1. Read the header information //2. Find the min and max @@ -108,7 +108,7 @@ bool sGrid::open( const char * cfilename, bool InRam, GRID_TYPE GridType, void ( } bool sGrid::readDiskToMemory( void (*callback)(int number, const char * message ) ) -{ +{ if( gridType == ASCII_GRID ) return asciiReadDiskToMemory( callback ); else if( gridType == BINARY_GRID ) @@ -118,7 +118,7 @@ bool sGrid::readDiskToMemory( void (*callback)(int number, const char * message else if( gridType == SDTS_GRID ) return sdtsReadDiskToMemory( callback ); lastErrorCode = tkINVALID_GRID_FILE_TYPE; - return false; + return false; } bool sGrid::readDiskToDisk( void (*callback)(int number, const char * message ) ) @@ -142,7 +142,7 @@ bool sGrid::writeMemoryToDisk( void(*callback)(int number, const char * message if( gridType == ASCII_GRID ) return asciiWriteMemoryToDisk( callback ); else if( gridType == BINARY_GRID ) - return binaryWriteMemoryToDisk( callback ); + return binaryWriteMemoryToDisk( callback ); else if( gridType == ESRI_GRID ) return esriWriteMemoryToDisk( callback ); /* @@ -154,11 +154,11 @@ bool sGrid::writeMemoryToDisk( void(*callback)(int number, const char * message } bool sGrid::writeDiskToDisk() -{ +{ if( gridType == ASCII_GRID ) return asciiWriteDiskToDisk(); else if( gridType == BINARY_GRID ) - return binaryWriteDiskToDisk(); + return binaryWriteDiskToDisk(); else if( gridType == ESRI_GRID ) return esriWriteDiskToDisk(); /* @@ -170,7 +170,7 @@ bool sGrid::writeDiskToDisk() } bool sGrid::initialize( const char * cfilename, sHeader header, short initialValue, bool InRam, GRID_TYPE GridType ) -{ +{ CString filename = cfilename; close(); @@ -193,10 +193,10 @@ bool sGrid::initialize( const char * cfilename, sHeader header, short initialVal if( isInRam == true ) { - if (data != NULL) + if (data != nullptr) { delete [] data; - data = NULL; + data = nullptr; } data = new short*[ gridHeader.getNumberRows() ]; for( int y = 0; y < gridHeader.getNumberRows(); y++ ) @@ -212,7 +212,7 @@ bool sGrid::initialize( const char * cfilename, sHeader header, short initialVal return true; } else - { + { if( gridType == BINARY_GRID ) return binaryInitializeDisk( initialValue ); else if( gridType == ESRI_GRID ) @@ -252,37 +252,37 @@ bool sGrid::close() // This change is made in sGrid, dGrid, fGrid, and lGrid. bool result = true; - if( file_in_out != NULL ) + if( file_in_out != nullptr) { fclose( file_in_out ); - file_in_out = NULL; + file_in_out = nullptr; } - if( row_one != NULL ) + if( row_one != nullptr) { delete [] row_one; - row_one = NULL; + row_one = nullptr; } - if( row_two != NULL ) + if( row_two != nullptr) { delete [] row_two; - row_two = NULL; + row_two = nullptr; } - if( row_three != NULL ) + if( row_three != nullptr) { delete [] row_three; - row_three = NULL; + row_three = nullptr; } - if( row_buf1 != NULL ) - { CFree1((char *)row_buf1); - row_buf1 = NULL; + if( row_buf1 != nullptr) + { CFree1(static_cast(row_buf1)); + row_buf1 = nullptr; } - if( row_buf2 != NULL ) - { CFree1((char *)row_buf2); - row_buf2 = NULL; + if( row_buf2 != nullptr) + { CFree1(static_cast(row_buf2)); + row_buf2 = nullptr; } - if( row_buf3 != NULL ) - { CFree1((char *)row_buf3); - row_buf3 = NULL; + if( row_buf3 != nullptr) + { CFree1(static_cast(row_buf3)); + row_buf3 = nullptr; } if( grid_layer >= 0 ) { - if( celllyrclose != NULL ) + if( celllyrclose != nullptr) celllyrclose(grid_layer); grid_layer = -1; } @@ -375,9 +375,9 @@ inline short sGrid::getValue( int Column, int Row ) if( inGrid( Column, Row ) ) { if( isInRam ) - return data[Row][Column]; + return data[Row][Column]; else - return getValueDisk( Column, Row ); + return getValueDisk( Column, Row ); } else { lastErrorCode = tkINDEX_OUT_OF_BOUNDS; @@ -399,7 +399,7 @@ inline short sGrid::getValueDisk( int Column, int Row ) } void sGrid::setValue( int Column, int Row, short Value ) -{ +{ if( inGrid( Column, Row ) ) { if( max == gridHeader.getNodataValue() ) @@ -419,7 +419,7 @@ void sGrid::setValue( int Column, int Row, short Value ) if( isInRam ) data[Row][Column] = Value; else - setValueDisk( Column, Row, Value ); + setValueDisk( Column, Row, Value ); } else lastErrorCode = tkINDEX_OUT_OF_BOUNDS; @@ -437,11 +437,11 @@ inline void sGrid::setValueDisk( int Column, int Row, short Value ) } void sGrid::dealloc() -{ if( isInRam && data != NULL ) +{ if( isInRam && data != nullptr) { for( int y = 0; y < gridHeader.getNumberRows(); y++ ) - delete [] data[y]; - delete [] data; - data = NULL; + delete [] data[y]; + delete [] data; + data = nullptr; } gridHeader.setNumberRows( 0 ); gridHeader.setNumberCols( 0 ); @@ -454,15 +454,15 @@ void sGrid::alloc() { if( gridHeader.getNumberCols() > 0 && gridHeader.getNumberRows() > 0 ) { - if (data != NULL) + if (data != nullptr) { delete [] data; - data = NULL; + data = nullptr; } data = new short *[gridHeader.getNumberRows()]; for( int y = 0; y < gridHeader.getNumberRows(); y++ ) - data[y] = new short[gridHeader.getNumberCols()]; - } + data[y] = new short[gridHeader.getNumberCols()]; + } } } @@ -472,7 +472,7 @@ sHeader sGrid::getHeader() } void sGrid::setHeader( sHeader h ) -{ +{ //Don't allow the Rows and Columns to Change gridHeader.setDx( h.getDx() ); gridHeader.setDy( h.getDy() ); @@ -500,9 +500,9 @@ void sGrid::CellToProj( long column, long row, double & x, double & y ) inline int sGrid::round( double d ) { if( ceil(d) - d <= .5 ) - return (int)ceil(d); + return static_cast(ceil(d)); else - return (int)floor(d); + return static_cast(floor(d)); } void sGrid::clear( short clearValue ) @@ -513,7 +513,7 @@ void sGrid::clear( short clearValue ) int nrows= gridHeader.getNumberRows(); for( int j = 0; j < nrows; j++ ) { for( int i = 0; i < ncols; i++ ) - data[j][i] = clearValue; + data[j][i] = clearValue; } } else @@ -651,14 +651,14 @@ short ** sGrid::getArrayPtr() } GRID_TYPE sGrid::getGridType( const char * filename ) -{ +{ GRID_TYPE grid_type = INVALID_GRID_TYPE; - if( filename != NULL && _tcslen( filename ) > 0 ) + if( filename != nullptr && _tcslen( filename ) > 0 ) { char * clean_filename = new char[_tcslen( filename ) + 1]; strcpy( clean_filename, filename ); - for( int i = _tcslen( clean_filename ) - 1; i >= 0; i-- ) + for( int i = static_cast(_tcslen( clean_filename )) - 1; i >= 0; i-- ) { if( clean_filename[i] == '\\' || clean_filename[i] == '/' ) clean_filename[i] = '\0'; else @@ -689,7 +689,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) cff.Close(); //File does not exist so parse it out - int length = _tcslen(filename ); + int length = static_cast(_tcslen(filename )); bool foundPeriod = false; for( int e = length-1; e >= 0; e-- ) { if( filename[e] == '\\' || filename[e] == '/' ) @@ -759,7 +759,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) ///\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ bool sGrid::asciiReadDiskToMemory( void (*callback)(int number, const char * message ) ) - { + { ifstream in(gridFilename); if( !in ) @@ -794,10 +794,10 @@ GRID_TYPE sGrid::getGridType( const char * filename ) { num_read++; if( !in ) { dealloc(); - return false; + return false; } - in>>data[j][i]; + in>>data[j][i]; if( min == nodata ) { min = data[j][i]; max = data[j][i]; @@ -812,13 +812,13 @@ GRID_TYPE sGrid::getGridType( const char * filename ) } } - if( callback != NULL ) + if( callback != nullptr) { int newpercent = (int)(((num_read)/total)*100); if( newpercent > percent ) { percent = newpercent; - callback( percent, "Reading Ascii Grid" ); + callback( percent, "Reading Ascii Grid" ); } - } + } } } asciiReadFooter( in ); @@ -829,7 +829,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) bool sGrid::asciiReadDiskToDisk( void(*callback)(int number, const char * message ) ) { isInRam = true; - return asciiReadDiskToMemory( callback ); + return asciiReadDiskToMemory( callback ); } bool sGrid::asciiWriteMemoryToDisk( void(*callback)(int number, const char * message ) ) @@ -850,24 +850,24 @@ GRID_TYPE sGrid::getGridType( const char * filename ) for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { num_written++; - + out<((num_written / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Writing Ascii Grid" ); - } + } } } out<>dy; gridHeader.setDy( dy ); return true; @@ -1059,7 +1059,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) return false; } else - { + { asciiWriteHeader(out); double total = gridHeader.getNumberRows()*gridHeader.getNumberCols(); int percent = 0; @@ -1068,16 +1068,16 @@ GRID_TYPE sGrid::getGridType( const char * filename ) for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { num_written++; - + out<((num_written / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Writing Ascii Grid" ); - } + } } } out<(((num_read) / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Reading Binary Grid" ); } } - } - } - + } + fclose(in); - return true; + return true; } - } bool sGrid::binaryReadDiskToDisk() { file_in_out = fopen( gridFilename, "r+b" ); - + if( !file_in_out ) { lastErrorCode = tkCANT_CREATE_FILE; return false; } else - { - binaryReadHeader(file_in_out); + { + binaryReadHeader(file_in_out); - if( gridHeader.getNumberCols() < 0 || gridHeader.getNumberRows() < 0 || + if( gridHeader.getNumberCols() < 0 || gridHeader.getNumberRows() < 0 || gridHeader.getDx() < 0 || gridHeader.getDy() < 0 || data_type != SHORT_TYPE ) { dealloc(); fclose( file_in_out ); - file_in_out = NULL; + file_in_out = nullptr; lastErrorCode = tkINCOMPATIBLE_DATA_TYPE; return false; } @@ -1252,22 +1250,22 @@ GRID_TYPE sGrid::getGridType( const char * filename ) row_two = new short[gridHeader.getNumberCols()]; row_three = new short[gridHeader.getNumberCols()]; - binaryBufferRows( 1 ); - } - return true; - } + binaryBufferRows( 1 ); + } + return true; + } } bool sGrid::binaryWriteMemoryToDisk( void(*callback)(int number, const char * message ) ) - { + { FILE * out = fopen( gridFilename, "wb" ); - + if( !out ) { lastErrorCode = tkCANT_CREATE_FILE; return false; } else - { + { binaryWriteHeader(out); double total = gridHeader.getNumberRows() * gridHeader.getNumberCols(); int percent = 0; @@ -1279,19 +1277,19 @@ GRID_TYPE sGrid::getGridType( const char * filename ) fwrite( &data[j][i],sizeof(short),1,out); - if( callback != NULL ) + if( callback != nullptr) { - int newpercent = (int)((num_written/total)*100); + int newpercent = static_cast((num_written / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Binary Grid Write"); - } + } } - } + } } fclose( out ); - return true; - } + return true; + } } bool sGrid::binaryWriteDiskToDisk() @@ -1321,14 +1319,14 @@ GRID_TYPE sGrid::getGridType( const char * filename ) for( int j = gridHeader.getNumberRows() - 1; j >= 0; j-- ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) - { - fwrite( &initialValue,sizeof(short),1,file_in_out); - } + { + fwrite( &initialValue,sizeof(short),1,file_in_out); + } } - + min = initialValue; max = initialValue; - + current_row = 0; row_one = new short[gridHeader.getNumberCols()]; row_two = new short[gridHeader.getNumberCols()]; @@ -1340,7 +1338,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) row_three[i] = initialValue; } } - return true; + return true; } void sGrid::binaryReadHeader( FILE * in ) @@ -1373,7 +1371,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) fread( &data_type, sizeof(DATA_TYPE),1,in); short nodata_value; - fread( &nodata_value, sizeof(short),1,in); + fread( &nodata_value, sizeof(short),1,in); gridHeader.setNodataValue( nodata_value ); char * projection = new char[MAX_STRING_LENGTH + 1]; @@ -1412,7 +1410,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) if( _tcslen( projection ) > 0 ) fwrite( projection, sizeof(char), _tcslen(projection),out); if( _tcslen( projection ) < MAX_STRING_LENGTH ) - { int size_of_pad = MAX_STRING_LENGTH - _tcslen(projection); + { int size_of_pad = MAX_STRING_LENGTH - static_cast(_tcslen(projection)); char * pad = new char[size_of_pad]; for( int p = 0; p < size_of_pad; p++ ) pad[p] = 0; @@ -1426,7 +1424,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) if( _tcslen( notes ) > 0 ) fwrite( notes, sizeof(char), _tcslen(notes), out); if( _tcslen( notes ) < MAX_STRING_LENGTH ) - { int size_of_pad = MAX_STRING_LENGTH - _tcslen(notes); + { int size_of_pad = MAX_STRING_LENGTH - static_cast(_tcslen(notes)); char * pad = new char[size_of_pad]; for( int p = 0; p < size_of_pad; p++ ) pad[p] = 0; @@ -1453,22 +1451,22 @@ GRID_TYPE sGrid::getGridType( const char * filename ) void sGrid::binarySetValueDisk( int Column, int Row, short Value ) { long file_position = file_position_beg_of_data + sizeof(short)*Row*gridHeader.getNumberCols() + sizeof(short)*Column; - + if( fseek( file_in_out, file_position, SEEK_SET ) == -1L ) {} else { if( fwrite( &Value, sizeof(short), 1, file_in_out ) < 1 ) - {} + {} else { if( Row == current_row - 1 ) row_one[ Column ] = Value; else if( Row == current_row ) row_two[ Column ] = Value; else if( Row == current_row + 1 ) - row_three[ Column ] = Value; + row_three[ Column ] = Value; } - } + } } void sGrid::binaryClearDisk(short clearValue) @@ -1476,14 +1474,14 @@ GRID_TYPE sGrid::getGridType( const char * filename ) if( fseek( file_in_out, file_position_beg_of_data, SEEK_SET ) == -1L ) return; else - { + { for( int j = 0; j < gridHeader.getNumberRows(); j++ ) { for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { if( fwrite( &clearValue, sizeof(short), 1, file_in_out ) < 1 ) return; } - } - } + } + } } void sGrid::binaryBufferRows( int center_row ) @@ -1502,7 +1500,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) } else nd_fill_one = true; - + if( gridHeader.getNumberRows() >= center_row && center_row >= 0 ) { long file_position = file_position_beg_of_data + sizeof(short)*(center_row)*gridHeader.getNumberCols(); @@ -1565,9 +1563,9 @@ GRID_TYPE sGrid::getGridType( const char * filename ) value = getValue( i, j ); fwrite( &value,sizeof(short),1,out); - if( callback != NULL ) + if( callback != nullptr) { - int newpercent = (int)((num_written/total)*100); + int newpercent = static_cast((num_written / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Binary Grid Write"); @@ -1614,31 +1612,31 @@ GRID_TYPE sGrid::getGridType( const char * filename ) #pragma optimize("", off) bool sGrid::esriReadDiskToMemory( void (*callback)(int number, const char * message ) ) { - if( celllayeropen == NULL || - celllyrclose == NULL || - bndcellread == NULL || - privateaccesswindowset == NULL || - privatewindowcols == NULL || - privatewindowrows == NULL || - getwindowrow == NULL ) + if( celllayeropen == nullptr || + celllyrclose == nullptr || + bndcellread == nullptr || + privateaccesswindowset == nullptr || + privatewindowcols == nullptr || + privatewindowrows == nullptr || + getwindowrow == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; } - double csize; + double csize; double bndbox[4]; double adjbndbox[4]; short nodata = -1; int cell_type; - - char * fname = new char[_MAX_PATH+1]; + + char * fname = new char[_MAX_PATH+1]; if( GetShortPathName(gridFilename,fname,_MAX_PATH) == 0 ) strcpy( fname, gridFilename ); grid_layer = celllayeropen(fname,READONLY,ROWIO,&cell_type,&csize); if( grid_layer >= 0 ) - { + { //Get the bounding box of the input cell layer //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner if( bndcellread(fname,bndbox) < 0 ) @@ -1669,7 +1667,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) return false; } - //Set the Window to the output bounding box and cellsize + //Set the Window to the output bounding box and cellsize if( privateaccesswindowset(grid_layer,bndbox,csize,adjbndbox) < 0) { dealloc(); //Close handle @@ -1678,7 +1676,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) lastErrorCode = tkESRI_ACCESS_WINDOW_SET; return false; } - + //Get the number of rows and columns in the window gridHeader.setNumberCols( privatewindowcols(grid_layer) ); gridHeader.setNumberRows( privatewindowrows(grid_layer) ); @@ -1699,9 +1697,9 @@ GRID_TYPE sGrid::getGridType( const char * filename ) alloc(); //Now copy row major into array - //Allocate row buffer - row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( row_buf1 == NULL ) + //Allocate row buffer + row_buf1 = reinterpret_cast(CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE))); + if ( row_buf1 == nullptr) { dealloc(); //Close handle celllyrclose(grid_layer); @@ -1718,11 +1716,11 @@ GRID_TYPE sGrid::getGridType( const char * filename ) min = nodata; max = nodata; for ( int j = 0; j < gridHeader.getNumberRows(); j++) - { - if( cell_type == CELLINT) - { getwindowrow(grid_layer, j, (CELLTYPE*)row_buf1); + { + if( cell_type == CELLINT) + { getwindowrow(grid_layer, j, static_cast(row_buf1)); - register int *buf = (int *)row_buf1; + register int *buf = static_cast(row_buf1); for( int i = 0; i < gridHeader.getNumberCols(); i++) { if( buf[i] == MISSINGINT ) @@ -1738,35 +1736,36 @@ GRID_TYPE sGrid::getGridType( const char * filename ) if( max == nodata ) max = buf[i]; else if( buf[i] > max ) - max = buf[i]; + max = buf[i]; } - } - } + } + } - int newpercent = (int)((j/total)*100); - if( newpercent > percent ) - { percent = newpercent; - if( callback != NULL ) + int newpercent = static_cast((j / total) * 100); + if( newpercent > percent ) + { + percent = newpercent; + if( callback != nullptr) callback( percent, "Reading Esri Grid" ); - } + } } //Free row buffer - CFree1((char *)row_buf1); - row_buf1 = NULL; + CFree1(static_cast(row_buf1)); + row_buf1 = nullptr; //Close handle celllyrclose(grid_layer); grid_layer = -1; return true; - } + } else { dealloc(); grid_layer = -1; lastErrorCode = tkESRI_LAYER_OPEN; return false; - } + } } #pragma optimize("", on) @@ -1774,34 +1773,34 @@ GRID_TYPE sGrid::getGridType( const char * filename ) bool sGrid::esriReadDiskToDisk() { //Check for the needed functions - if( bndcellread == NULL || - celllyrclose == NULL || - celllayeropen == NULL || - privateaccesswindowset == NULL || - privatewindowcols == NULL || - privatewindowrows == NULL || - getwindowrow == NULL ) + if( bndcellread == nullptr || + celllyrclose == nullptr || + celllayeropen == nullptr || + privateaccesswindowset == nullptr || + privatewindowcols == nullptr || + privatewindowrows == nullptr || + getwindowrow == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; } - double csize; + double csize; double bndbox[4]; double adjbndbox[4]; short nodata = -1; int cell_type; - char * fname = new char[_MAX_PATH+1]; + char * fname = new char[_MAX_PATH+1]; if( GetShortPathName(gridFilename,fname,_MAX_PATH) == 0 ) strcpy( fname, gridFilename ); grid_layer = celllayeropen(fname,READWRITE,ROWIO,&cell_type,&csize); if( grid_layer >= 0 ) - { + { //Get the bounding box of the input cell layer //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner - + if( bndcellread(fname,bndbox) < 0 ) { dealloc(); //Close handle @@ -1829,10 +1828,10 @@ GRID_TYPE sGrid::getGridType( const char * filename ) grid_layer = -1; lastErrorCode = tkINVALID_GRID_FILE_TYPE; delete [] fname; - return false; + return false; } - - //Set the Window to the output bounding box and cellsize + + //Set the Window to the output bounding box and cellsize if( privateaccesswindowset(grid_layer,bndbox,csize,adjbndbox) < 0) { dealloc(); //Close handle @@ -1861,10 +1860,10 @@ GRID_TYPE sGrid::getGridType( const char * filename ) } //Allocate row buffer - row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - row_buf2 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - row_buf3 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( row_buf1 == NULL || row_buf2 == NULL || row_buf3 == NULL ) + row_buf1 = reinterpret_cast(CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE))); + row_buf2 = reinterpret_cast(CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE))); + row_buf3 = reinterpret_cast(CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE))); + if ( row_buf1 == nullptr || row_buf2 == nullptr || row_buf3 == nullptr) { dealloc(); //Close handle celllyrclose(grid_layer); @@ -1898,12 +1897,12 @@ GRID_TYPE sGrid::getGridType( const char * filename ) else if( buf[i] > max ) max = buf[i]; } - } - - } */ + } + + } */ esriBufferRows( 0 ); delete [] fname; - return true; + return true; } else { dealloc(); @@ -1919,20 +1918,20 @@ GRID_TYPE sGrid::getGridType( const char * filename ) bool sGrid::esriWriteMemoryToDisk( void(*callback)(int number, const char * message ) ) { //Check the needed functions - if( celllyrclose == NULL || - celllyrexists == NULL || - celllayercreate == NULL || - griddelete == NULL || - privateaccesswindowset == NULL || - getmissingfloat == NULL || - putwindowrow == NULL ) + if( celllyrclose == nullptr || + celllyrexists == nullptr || + celllayercreate == nullptr || + griddelete == nullptr || + privateaccesswindowset == nullptr || + getmissingfloat == nullptr || + putwindowrow == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; } int cell_type = CELLINT; - + double csize = gridHeader.getDx(); //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner double bndbox[4]; @@ -1943,10 +1942,10 @@ GRID_TYPE sGrid::getGridType( const char * filename ) double adjbndbox[4]; char * fname = new char[gridFilename.GetLength()+1]; - strcpy( fname, gridFilename ); + strcpy( fname, gridFilename ); if( celllyrexists( fname ) != 0 ) griddelete( fname ); - + grid_layer = celllayercreate( fname, WRITEONLY, ROWIO, cell_type, csize, bndbox); if( grid_layer < 0 ) { grid_layer = -1; @@ -1957,19 +1956,18 @@ GRID_TYPE sGrid::getGridType( const char * filename ) if( privateaccesswindowset( grid_layer, bndbox, csize, adjbndbox) < 0 ) { celllyrclose(grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); grid_layer = -1; lastErrorCode = tkESRI_ACCESS_WINDOW_SET; return false; } - - - //Allocate row buffer + + //Allocate row buffer row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( row_buf1 == NULL ) + if ( row_buf1 == nullptr) { celllyrclose(grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); grid_layer = -1; lastErrorCode = tkCANT_ALLOC_MEMORY; return false; @@ -1979,32 +1977,32 @@ GRID_TYPE sGrid::getGridType( const char * filename ) int percent = 0; short nodata = gridHeader.getNodataValue(); - register int *buf = (int *)row_buf1; + register int *buf = static_cast(row_buf1); for( int j = 0; j < gridHeader.getNumberRows(); j++) { for( int i = 0; i < gridHeader.getNumberCols(); i++) { - buf[i] = (int)data[j][i]; + buf[i] = static_cast(data[j][i]); if(buf[i] == nodata) buf[i] = MISSINGINT; } - putwindowrow( grid_layer, j, (CELLTYPE*)row_buf1); + putwindowrow( grid_layer, j, static_cast(row_buf1)); - int newpercent = (int)((j/total)*100); + int newpercent = static_cast((j / total) * 100); if( newpercent > percent ) { percent = newpercent; - if( callback != NULL ) + if( callback != nullptr) callback( percent, "Writing Esri Grid" ); } } - - CFree1 ((char *)row_buf1); - row_buf1 = NULL; - //Close handle + CFree1 (static_cast(row_buf1)); + row_buf1 = nullptr; + + //Close handle celllyrclose(grid_layer); grid_layer = -1; - return true; + return true; } #pragma optimize("", on) @@ -2016,19 +2014,19 @@ GRID_TYPE sGrid::getGridType( const char * filename ) #pragma optimize("", off) bool sGrid::esriInitializeDisk( short InitialValue ) { - if( celllyrexists == NULL || - celllyrclose == NULL || - griddelete == NULL || - celllayercreate == NULL || - privateaccesswindowset == NULL || - putwindowrow == NULL ) + if( celllyrexists == nullptr || + celllyrclose == nullptr || + griddelete == nullptr || + celllayercreate == nullptr || + privateaccesswindowset == nullptr || + putwindowrow == nullptr) { grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; } int cell_type = CELLINT; - + double csize = gridHeader.getDx(); //Bounding box is xllcorner, yllcorner, xurcorner, yurcorner double bndbox[4]; @@ -2036,10 +2034,10 @@ GRID_TYPE sGrid::getGridType( const char * filename ) bndbox[1] = gridHeader.getYllcenter() - gridHeader.getDy()*.5; bndbox[2] = gridHeader.getXllcenter() + gridHeader.getNumberCols()*gridHeader.getDx() - gridHeader.getDx()*.5; bndbox[3] = gridHeader.getYllcenter() + gridHeader.getNumberRows()*gridHeader.getDy() - gridHeader.getDy()*.5; - + char * fname = new char[gridFilename.GetLength()+1]; strcpy( fname, gridFilename ); - + if( celllyrexists( fname ) != 0 ) { if( griddelete( fname ) == 0 ) @@ -2058,36 +2056,36 @@ GRID_TYPE sGrid::getGridType( const char * filename ) delete [] fname; return false; } - + double adjbndbox[4]; if( privateaccesswindowset( grid_layer, bndbox, csize, adjbndbox) < 0 ) { celllyrclose(grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); grid_layer = -1; lastErrorCode = tkESRI_ACCESS_WINDOW_SET; delete [] fname; return false; } - //Allocate row buffer + //Allocate row buffer row_buf1 = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if( row_buf1 == NULL ) - { - celllyrclose(grid_layer); + if( row_buf1 == nullptr) + { + celllyrclose(grid_layer); if( celllyrexists( fname ) ) griddelete( fname ); grid_layer = -1; lastErrorCode = tkCANT_ALLOC_MEMORY; delete [] fname; return false; - } + } short nodata = gridHeader.getNodataValue(); max = nodata; min = nodata; - register int *buf = (int *)row_buf1; + register int *buf = static_cast(row_buf1); if( InitialValue == nodata ) { @@ -2098,18 +2096,18 @@ GRID_TYPE sGrid::getGridType( const char * filename ) { for( int i = 0; i < gridHeader.getNumberCols(); i++) buf[i] = InitialValue; } - + for( int j = 0; j < gridHeader.getNumberRows(); j++) - putwindowrow( grid_layer, j, (CELLTYPE*)row_buf1); - + putwindowrow( grid_layer, j, static_cast(row_buf1)); + //Close and Reopen so VAT Table is Written celllyrclose(grid_layer); grid_layer = -1; - CFree1 ((char *)row_buf1); - row_buf1 = NULL; + CFree1 (static_cast(row_buf1)); + row_buf1 = nullptr; delete [] fname; - return esriReadDiskToDisk(); + return esriReadDiskToDisk(); } #pragma optimize("", on) @@ -2123,28 +2121,28 @@ GRID_TYPE sGrid::getGridType( const char * filename ) if( Row == current_row - 1 ) { - if( ((int *)row_buf1)[Column] == MISSINGINT ) + if( static_cast(row_buf1)[Column] == MISSINGINT ) return gridHeader.getNodataValue(); - return short((((int *)row_buf1)[Column])); + return static_cast(static_cast(row_buf1)[Column]); } else if( Row == current_row ) { - if( ((int *)row_buf2)[Column] == MISSINGINT ) + if( static_cast(row_buf2)[Column] == MISSINGINT ) return gridHeader.getNodataValue(); - return short((((int *)row_buf2)[Column])); + return static_cast(static_cast(row_buf2)[Column]); } else if( Row == current_row + 1 ) { - if( ((int *)row_buf3)[Column] == MISSINGINT ) + if( static_cast(row_buf3)[Column] == MISSINGINT ) return gridHeader.getNodataValue(); - return short((((int *)row_buf3)[Column])); + return static_cast(static_cast(row_buf3)[Column]); } else { esriBufferRows( Row ); - if( ((int *)row_buf2)[Column] == MISSINGINT ) + if( static_cast(row_buf2)[Column] == MISSINGINT ) return gridHeader.getNodataValue(); - return short((((int *)row_buf2)[Column])); + return static_cast(static_cast(row_buf2)[Column]); } return gridHeader.getNodataValue(); @@ -2154,7 +2152,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) #pragma optimize("", off) void sGrid::esriSetValueDisk( int Column, int Row, short Value ) { - if( putwindowrow == NULL ) + if( putwindowrow == nullptr) return; int value = Value; @@ -2165,27 +2163,27 @@ GRID_TYPE sGrid::getGridType( const char * filename ) if( value == gridHeader.getNodataValue() ) value = MISSINGINT; - register int *buf = (int *)row_buf1; - buf[Column] = value; + register int *buf = (int *)row_buf1; + buf[Column] = value; putwindowrow( grid_layer, Row, (CELLTYPE*)row_buf1); } else if( Row == current_row ) { if( value == gridHeader.getNodataValue() ) value = MISSINGINT; - - register int *buf = (int *)row_buf2; + + register int *buf = (int *)row_buf2; buf[Column] = value; - putwindowrow( grid_layer, Row, (CELLTYPE*)row_buf2); + putwindowrow( grid_layer, Row, (CELLTYPE*)row_buf2); } else if( Row == current_row + 1 ) { if( value == gridHeader.getNodataValue() ) value = MISSINGINT; - register int *buf = (int *)row_buf3; + register int *buf = (int *)row_buf3; buf[Column] = value; - putwindowrow( grid_layer, Row, (CELLTYPE*)row_buf3); + putwindowrow( grid_layer, Row, (CELLTYPE*)row_buf3); } } #pragma optimize("", on) @@ -2193,10 +2191,10 @@ GRID_TYPE sGrid::getGridType( const char * filename ) #pragma optimize("", off) void sGrid::esriClearDisk(short clearValue) { - if( putwindowrow == NULL ) + if( putwindowrow == nullptr) return; - register int *buf = (int *)row_buf1; + register int *buf = static_cast(row_buf1); for( int j = 0; j < gridHeader.getNumberRows(); j++) { int val = clearValue; @@ -2206,32 +2204,32 @@ GRID_TYPE sGrid::getGridType( const char * filename ) { buf[i]=val; } - putwindowrow( grid_layer, j, (CELLTYPE*)row_buf1); + putwindowrow( grid_layer, j, static_cast(row_buf1)); } for( int i = 0; i < gridHeader.getNumberCols(); i++) { buf[i]=clearValue; - } + } - esriBufferRows( 0 ); + esriBufferRows( 0 ); } #pragma optimize("", on) #pragma optimize("", off) void sGrid::esriBufferRows( int center_row ) { - if( getwindowrow == NULL ) + if( getwindowrow == nullptr) { register int *ibuf; - + for( int i = 0; i < gridHeader.getNumberCols(); i++ ) - { - ibuf = (int *)row_buf1; + { + ibuf = static_cast(row_buf1); ibuf[i] = MISSINGINT; - ibuf = (int *)row_buf2; + ibuf = static_cast(row_buf2); ibuf[i] = MISSINGINT; - ibuf = (int *)row_buf3; - ibuf[i] = MISSINGINT; - } + ibuf = static_cast(row_buf3); + ibuf[i] = MISSINGINT; + } return; } @@ -2240,16 +2238,16 @@ GRID_TYPE sGrid::getGridType( const char * filename ) bool nd_fill_three = false; if( gridHeader.getNumberRows() >= center_row -1 && center_row - 1 >= 0 ) - { - getwindowrow(grid_layer, center_row - 1, (CELLTYPE*)row_buf1); + { + getwindowrow(grid_layer, center_row - 1, static_cast(row_buf1)); nd_fill_one = false; } else nd_fill_one = true; if( gridHeader.getNumberRows() >= center_row && center_row >= 0 ) - { - getwindowrow(grid_layer, center_row, (CELLTYPE*)row_buf2); + { + getwindowrow(grid_layer, center_row, static_cast(row_buf2)); nd_fill_two = false; } else @@ -2257,7 +2255,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) if( gridHeader.getNumberRows() >= center_row + 1 && center_row + 1 >= 0 ) { - getwindowrow(grid_layer, center_row + 1, (CELLTYPE*)row_buf3); + getwindowrow(grid_layer, center_row + 1, static_cast(row_buf3)); nd_fill_three = false; } else @@ -2273,18 +2271,18 @@ GRID_TYPE sGrid::getGridType( const char * filename ) for( int i = 0; i < gridHeader.getNumberCols(); i++ ) { if( nd_fill_one ) - { ibuf = (int *)row_buf1; + { ibuf = static_cast(row_buf1); ibuf[i] = MISSINGINT; } if( nd_fill_two ) - { ibuf = (int *)row_buf2; + { ibuf = static_cast(row_buf2); ibuf[i] = MISSINGINT; } if( nd_fill_three ) - { ibuf = (int *)row_buf3; + { ibuf = static_cast(row_buf3); ibuf[i] = MISSINGINT; - } - } + } + } } } #pragma optimize("", on) @@ -2294,13 +2292,13 @@ GRID_TYPE sGrid::getGridType( const char * filename ) { long temp_grid_layer = -1; //Check the needed functions - if( celllyrclose == NULL || - celllyrexists == NULL || - celllayercreate == NULL || - griddelete == NULL || - privateaccesswindowset == NULL || - getmissingfloat == NULL || - putwindowrow == NULL ) + if( celllyrclose == nullptr || + celllyrexists == nullptr || + celllayercreate == nullptr || + griddelete == nullptr || + privateaccesswindowset == nullptr || + getmissingfloat == nullptr || + putwindowrow == nullptr) { temp_grid_layer = -1; lastErrorCode = tkESRI_DLL_NOT_INITIALIZED; return false; @@ -2316,12 +2314,12 @@ GRID_TYPE sGrid::getGridType( const char * filename ) bndbox[2] = gridHeader.getXllcenter() + gridHeader.getNumberCols()*gridHeader.getDx() - gridHeader.getDx()*.5; bndbox[3] = gridHeader.getYllcenter() + gridHeader.getNumberRows()*gridHeader.getDy() - gridHeader.getDy()*.5; double adjbndbox[4]; - + char * fname = new char[filename.GetLength()+1]; - strcpy( fname, filename ); + strcpy( fname, filename ); if( celllyrexists( fname ) != 0 ) griddelete( fname ); - + temp_grid_layer = celllayercreate( fname, WRITEONLY, ROWIO, cell_type, csize, bndbox); if( temp_grid_layer < 0 ) { temp_grid_layer = -1; @@ -2333,19 +2331,19 @@ GRID_TYPE sGrid::getGridType( const char * filename ) if( privateaccesswindowset( temp_grid_layer, bndbox, csize, adjbndbox) < 0 ) { celllyrclose(temp_grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); temp_grid_layer = -1; lastErrorCode = tkESRI_ACCESS_WINDOW_SET; delete [] fname; return false; } - - //Allocate row buffer + + //Allocate row buffer void * temp_row_buf = (CELLTYPE*)CAllocate1(gridHeader.getNumberCols() + 1, sizeof(CELLTYPE)); - if ( temp_row_buf == NULL ) + if ( temp_row_buf == nullptr) { celllyrclose(temp_grid_layer); if( celllyrexists( fname ) ) - griddelete( fname ); + griddelete( fname ); temp_grid_layer = -1; lastErrorCode = tkCANT_ALLOC_MEMORY; delete [] fname; @@ -2356,35 +2354,35 @@ GRID_TYPE sGrid::getGridType( const char * filename ) int percent = 0; short nodata = gridHeader.getNodataValue(); - register int *buf = (int *)temp_row_buf; + register int *buf = static_cast(temp_row_buf); for( int j = 0; j < gridHeader.getNumberRows(); j++) { for( int i = 0; i < gridHeader.getNumberCols(); i++) { - buf[i] = (int)getValue( i, j ); + buf[i] = static_cast(getValue(i, j)); if(buf[i] == nodata) buf[i] = MISSINGINT; } - putwindowrow( temp_grid_layer, j, (CELLTYPE*)temp_row_buf); + putwindowrow( temp_grid_layer, j, static_cast(temp_row_buf)); - int newpercent = (int)((j/total)*100); + int newpercent = static_cast((j / total) * 100); if( newpercent > percent ) { percent = newpercent; - if( callback != NULL ) + if( callback != nullptr) callback( percent, "Writing Esri Grid" ); } } - - CFree1 ((char *)temp_row_buf); - temp_row_buf = NULL; + + CFree1 (static_cast(temp_row_buf)); + temp_row_buf = nullptr; if( isInRam == true ) { gridFilename = filename; - //Close handle + //Close handle celllyrclose(temp_grid_layer); temp_grid_layer = -1; delete [] fname; - return true; + return true; } else { celllyrclose(temp_grid_layer); @@ -2415,7 +2413,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) //Initialize the grid strcpy( file_name, gridFilename ); - //Find the byte order of the machine + //Find the byte order of the machine g123order(&order); char * fname = new char[ gridFilename.GetLength() + 1]; @@ -2491,7 +2489,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) else average = nodata_value; - setValue( column, row, (short)average ); + setValue( column, row, static_cast(average) ); } } } @@ -2511,12 +2509,12 @@ GRID_TYPE sGrid::getGridType( const char * filename ) dem_head(status); long voidvalue; cell_range(status, voidvalue, fillvalue); - h.setNodataValue( (short)voidvalue ); + h.setNodataValue( static_cast(voidvalue) ); double xhrs, yhrs; get_iref(xhrs, yhrs); - h.setDx( (int)xhrs ); - h.setDy( (int)xhrs ); + h.setDx( static_cast(xhrs) ); + h.setDy( static_cast(xhrs) ); get_xref(); @@ -2531,7 +2529,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) double upperlx, upperly; get_nw_corner(upperlx, upperly); - double miny = upperly - ( nrow * yhrs) ; + double miny = upperly - ( nrow * yhrs) ; double minx = upperlx ; if( SWX < NWX ) @@ -2543,10 +2541,10 @@ GRID_TYPE sGrid::getGridType( const char * filename ) else miny = SEY; - double mydouble = (int)minx; - h.setXllcenter( ((int)(mydouble/xhrs + 0.99999)*xhrs) ); - mydouble = (int)miny; - h.setYllcenter( ((int)(mydouble/yhrs + 0.99999)*yhrs) ); + double mydouble = static_cast(minx); + h.setXllcenter( (static_cast(mydouble / xhrs + 0.99999)*xhrs) ); + mydouble = static_cast(miny); + h.setYllcenter( (static_cast(mydouble / yhrs + 0.99999)*yhrs) ); return true; } @@ -2555,7 +2553,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) { int len,j; //parse out base_name - len = _tcslen(file_name); + len = static_cast(_tcslen(file_name)); for(j=0;j(MSB * I256) ; i4 = i4 + LSB; *num = i4; /* RETURN SUCCESS */ @@ -3238,7 +3235,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) double total = gridHeader.getNumberCols()*gridHeader.getNumberRows(); double nodata_value = gridHeader.getNodataValue(); float vscale; - + char fom = FeetOrMeters(); if( fom == 'm' && gridHeader.getDx() == 10 && gridHeader.getDy() == 10 ) @@ -3254,7 +3251,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) return ; } - if (! rd123ddrec(fpin,string,&status)) + if (! rd123ddrec(fpin,string,&status)) { printf ("\n*** ERROR READING DDR ***"); // fprintf (fpdem,"\n*** ERROR READING DDR ***"); @@ -3265,20 +3262,20 @@ GRID_TYPE sGrid::getGridType( const char * filename ) /* Loop to process each subfield */ do { /* Read data record subfield */ - if (! rd123sfld (fpin,tag,&leadid,string,&str_len,&status)) + if (! rd123sfld (fpin,tag,&leadid,string,&str_len,&status)) { printf ("\nERROR READING DATA RECORD SUBFIELD"); goto done; } /* Retrieve description of current subfield */ - if (! chk123sfld(fpin,tag,descr,frmts)) + if (! chk123sfld(fpin,tag,descr,frmts)) { printf ("\nERROR CHECKING DATA RECORD SUBFIELD"); // fprintf (fpdem,"\nERROR CHECKING DATA RECORD SUBFIELD"); goto done; } - if (strstr (frmts, "B") != NULL) + if (strstr (frmts, "B") != nullptr) { /* strncpy (temp, string, (int)str_len); @@ -3330,31 +3327,31 @@ GRID_TYPE sGrid::getGridType( const char * filename ) float f; } u; s123tol(string, &u.i, !order); - li = (int) (vscale * u.f); + li = static_cast(vscale * u.f); } else { - li = (long)nodata_value; + li = static_cast(nodata_value); } //BIAS FOR ELEVATION if( li < -1000 ) - li = (long)nodata_value; + li = static_cast(nodata_value); //Set the cell value if(li != nodata_value && li != fillvalue) { if(fom == 'f') { - li = (long)(li/3.2808); + li = static_cast(li / 3.2808); } if( li == 32767 || li == -32767 ) setValue( i, j, -255 ); else - setValue( i, j, (short)li ); + setValue( i, j, static_cast(li) ); - int newpercent = (int)((cnt/total)*100); + int newpercent = static_cast((cnt / total) * 100); if( newpercent > percent ) { percent = newpercent; if( callback ) @@ -3362,7 +3359,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) } } else - setValue( i, j, (short)nodata_value ); + setValue( i, j, static_cast(nodata_value) ); cnt++; i++; } @@ -3451,7 +3448,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) } else if (strstr(frmts, "R")) { - sadr_x = (long) atof(string); + sadr_x = static_cast(atof(string)); } } else if (!strcmp (tag, "SADR") && !strcmp (descr, "Y")) @@ -3468,7 +3465,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) } else if (strstr(frmts, "R")) { - sadr_y = (long) atof(string); + sadr_y = static_cast(atof(string)); } } } while (status != 4); /* Break out of loop at end of file */ @@ -3492,7 +3489,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) char data[1000]; FILE* fp; int len; - char* index = NULL; + char* index = nullptr; baseAndId(); strcpy (file_name,base_name); @@ -3502,7 +3499,7 @@ GRID_TYPE sGrid::getGridType( const char * filename ) if(!fp) return 0; - len = fread(data,sizeof(char),MAX-1,fp); + len = static_cast(fread(data,sizeof(char),MAX-1,fp)); fclose(fp); data[MAX-1] = '\0'; diff --git a/src/Grid/tkGridRaster.cpp b/src/Grid/tkGridRaster.cpp index 79e22113..18115aef 100644 --- a/src/Grid/tkGridRaster.cpp +++ b/src/Grid/tkGridRaster.cpp @@ -64,17 +64,17 @@ void tkGridRaster::CellToProj( long column, long row, double & x, double & y ) inline int tkGridRaster::round( double d ) { if( ceil(d) - d <= .5 ) - return (int)ceil(d); + return static_cast(ceil(d)); else - return (int)floor(d); + return static_cast(floor(d)); } void tkGridRaster::SaveHeaderInfo() { - if (_rasterDataset == NULL) + if (_rasterDataset == nullptr) return; - if (_poBand == NULL) + if (_poBand == nullptr) return; _poBand->SetNoDataValue(_noDataValue); @@ -87,19 +87,19 @@ void tkGridRaster::SaveHeaderInfo() adfGeoTransform[4] = 0; adfGeoTransform[5] = _dY * -1; - _rasterDataset->SetGeoTransform( adfGeoTransform ); + _rasterDataset->SetGeoTransform( adfGeoTransform ); if (_projection.GetLength() != 0) { // SetProjection expects WKT if (startsWith(_projection.GetBuffer(), "+proj")) { - char * wkt = NULL; + char * wkt = nullptr; ProjectionTools * p = new ProjectionTools(); p->ToESRIWKTFromProj4(&wkt, _projection.GetBuffer()); - if (wkt != NULL && strcmp(wkt, "") != 0) + if (wkt != nullptr && strcmp(wkt, "") != 0) { _rasterDataset->SetProjection(wkt); } @@ -121,11 +121,11 @@ void tkGridRaster::SaveHeaderInfo() _rasterDataset->FlushCache(); delete _rasterDataset; - _poBand = NULL; + _poBand = nullptr; _rasterDataset = GdalHelper::OpenRasterDatasetW(_filename); - if( _rasterDataset != NULL ) + if( _rasterDataset != nullptr) { _poBand = _rasterDataset->GetRasterBand(1); } @@ -170,7 +170,7 @@ bool tkGridRaster::LoadRasterCore(char* filenameA, bool InRam, GridFileType file // it PixelIsPoint for MapWinGIS compatibility. Saving out won't hurt // anything, since the tiepoints won't change. CreateNew will default // to PixelIsArea by applying the reverse of this adjustment. - const char * pszCellRegistration = _rasterDataset->GetMetadataItem("AREA_OR_POINT", NULL); + const char * pszCellRegistration = _rasterDataset->GetMetadataItem("AREA_OR_POINT", nullptr); // PixelIsArea. Use half-cell offset fix. (Shift Inward) _dX = adfGeoTransform[1]; @@ -196,7 +196,7 @@ bool tkGridRaster::LoadRasterCore(char* filenameA, bool InRam, GridFileType file this->ReadProjection(); - _inRam = InRam; + _inRam = InRam; if (_inRam) { LoadFullBuffer(); @@ -207,12 +207,12 @@ bool tkGridRaster::LoadRasterCore(char* filenameA, bool InRam, GridFileType file if (_genericType == GDT_Int32 || _genericType == GDT_Byte) { // Chris M 1/28/2007 -- multiply this by two, since we use two buffers - if (MemoryAvailable(2 * _width * sizeof(_int32))) + if (MemoryAvailable(static_cast(2 * _width * sizeof(_int32)))) _canScanlineBuffer = true; } else { - if (MemoryAvailable(2 * _width * sizeof(float))) + if (MemoryAvailable(static_cast(2 * _width * sizeof(float)))) _canScanlineBuffer = true; } } @@ -221,7 +221,7 @@ bool tkGridRaster::LoadRasterCore(char* filenameA, bool InRam, GridFileType file // Meh - doesn't particularly matter if the dataset loaded. } - return (_rasterDataset != NULL); + return (_rasterDataset != nullptr); } int tkGridRaster::getNumBands() @@ -262,7 +262,7 @@ bool tkGridRaster::OpenBand(int bandIndex) _dataType = _poBand->GetRasterDataType(); _cIntp = _poBand->GetColorInterpretation(); _poColorT = _poBand->GetColorTable(); - if (_poColorT != NULL) + if (_poColorT != nullptr) { _hasColorTable = true; } @@ -279,7 +279,7 @@ bool tkGridRaster::OpenBand(int bandIndex) case GDT_Byte: _genericType = GDT_Byte; break; - case GDT_Int16: + case GDT_Int16: case GDT_UInt16: _genericType = GDT_Int32; break; @@ -325,7 +325,7 @@ void tkGridRaster::ReadProjection() const char * wkt = _rasterDataset->GetProjectionRef(); if (wkt) { - IGeoProjection* proj = NULL; + IGeoProjection* proj = nullptr; ComHelper::CreateInstance(idGeoProjection, (IDispatch**)&proj); if (proj) { @@ -368,7 +368,7 @@ bool tkGridRaster::CreateNew(CStringW filename, GridFileType newFileType, double if (DataType == ByteDataType) _genericType = GDT_Byte; - char **papszOptions = NULL; + char **papszOptions = nullptr; char *pszFormat; if (newFileType == Ecw) @@ -388,12 +388,12 @@ bool tkGridRaster::CreateNew(CStringW filename, GridFileType newFileType, double if (newFileType == GeoTiff) pszFormat = T2A("GTiff"); - GDALDriver *poDriver; + GDALDriver *poDriver; - poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat); + poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat); - if( poDriver == NULL ) - return false; + if( poDriver == nullptr) + return false; if (filename.GetLength() == 0) return false; @@ -434,12 +434,12 @@ bool tkGridRaster::CreateNew(CStringW filename, GridFileType newFileType, double adfGeoTransform[4] = 0; adfGeoTransform[5] = _dY * -1; - _rasterDataset->SetGeoTransform( adfGeoTransform ); + _rasterDataset->SetGeoTransform( adfGeoTransform ); - if (_rasterDataset == NULL) + if (_rasterDataset == nullptr) return false; - _poBand = _rasterDataset->GetRasterBand(1); // to open the first band is ok here; + _poBand = _rasterDataset->GetRasterBand(1); // to open the first band is ok here; if (_hasColorTable) { @@ -457,7 +457,7 @@ bool tkGridRaster::CreateNew(CStringW filename, GridFileType newFileType, double // Make a buffer if (_genericType == GDT_Int32 || _genericType == GDT_Byte) { - _int32buffer = (_int32 *) CPLMalloc( sizeof(_int32)*_width*_height ); + _int32buffer = static_cast<_int32*>(CPLMalloc(sizeof(_int32) * _width * _height)); if (!_int32buffer) { _inRam = false; // Force the user to use disk-based; @@ -466,7 +466,7 @@ bool tkGridRaster::CreateNew(CStringW filename, GridFileType newFileType, double } else { - _floatbuffer = (float *) CPLMalloc( sizeof(float)*_width*_height ); + _floatbuffer = static_cast(CPLMalloc(sizeof(float) * _width * _height)); if (!_floatbuffer) { _inRam = false; // Force the user to use disk-based; @@ -484,12 +484,12 @@ bool tkGridRaster::CreateNew(CStringW filename, GridFileType newFileType, double // SetProjection expects WKT if (startsWith(projection, "+proj")) { - char * wkt = NULL; + char * wkt = nullptr; ProjectionTools * p = new ProjectionTools(); p->ToESRIWKTFromProj4(&wkt, projection); - if (wkt != NULL && strcmp(wkt, "") != 0) + if (wkt != nullptr && strcmp(wkt, "") != 0) { _rasterDataset->SetProjection(wkt); } @@ -559,7 +559,7 @@ bool tkGridRaster::CanCreate(GridFileType newFileType) // Don't delete poDriver - metadata will be reference counted -- don't free it. // reference counted. - if( poDriver == NULL ) + if( poDriver == nullptr) return false; papszMetadata = poDriver->GetMetadata(); @@ -584,7 +584,7 @@ bool tkGridRaster::CanCreate() poDriver = _rasterDataset->GetDriver(); // Don't delete poDriver - metadata will be reference counted -- don't free it. - if( poDriver == NULL ) + if( poDriver == nullptr) return false; // No driver == no dataset == no write. papszMetadata = poDriver->GetMetadata(); @@ -606,46 +606,46 @@ bool tkGridRaster::Close() { try { - if (_rasterDataset != NULL) + if (_rasterDataset != nullptr) { delete _rasterDataset; - _rasterDataset=NULL; + _rasterDataset = nullptr; } - if( _int32buffer != NULL ) + if( _int32buffer != nullptr) { CPLFree( _int32buffer ); - _int32buffer = NULL; + _int32buffer = nullptr; } - if( _floatbuffer != NULL ) + if( _floatbuffer != nullptr) { CPLFree( _floatbuffer ); - _floatbuffer = NULL; + _floatbuffer = nullptr; } - if( _int32ScanlineBufferA != NULL ) + if( _int32ScanlineBufferA != nullptr) { CPLFree( _int32ScanlineBufferA ); - _int32ScanlineBufferA = NULL; + _int32ScanlineBufferA = nullptr; } - if( _floatScanlineBufferA != NULL ) + if( _floatScanlineBufferA != nullptr) { CPLFree( _floatScanlineBufferA ); - _floatScanlineBufferA = NULL; + _floatScanlineBufferA = nullptr; } - if( _int32ScanlineBufferB != NULL ) + if( _int32ScanlineBufferB != nullptr) { CPLFree( _int32ScanlineBufferB ); - _int32ScanlineBufferB = NULL; + _int32ScanlineBufferB = nullptr; } - if( _floatScanlineBufferB != NULL ) + if( _floatScanlineBufferB != nullptr) { CPLFree( _floatScanlineBufferB ); - _floatScanlineBufferB = NULL; + _floatScanlineBufferB = nullptr; } _cachedMax = -9999; @@ -704,77 +704,76 @@ void tkGridRaster::LoadFullBuffer() { try { - if (_genericType == GDT_Int32 || _genericType == GDT_Byte) - { - // Is there enough memory available? - // CDM 1/6/2007: On one really extreme case, the amount - // of memory required would have caused the size of the largest - // datatype to overflow repeatedly. So check in a stepwise - // fashion "up to" the size we really want - if (!MemoryAvailable(_width*_height)) - { - _inRam = false; - return; - } - if (!MemoryAvailable(_width*_height*2)) - { - _inRam = false; - return; - } - if (!MemoryAvailable(_width*_height*sizeof(_int32)*2)) - { - _inRam = false; - return; - } - - _int32buffer = (_int32 *) CPLMalloc( sizeof(_int32)*_width*_height ); - if (!_int32buffer) + if (_genericType == GDT_Int32 || _genericType == GDT_Byte) { - _inRam = false; // Force the user to use disk-based; - // not enough memory likely to load into memory. - return; - } + // Is there enough memory available? + // CDM 1/6/2007: On one really extreme case, the amount + // of memory required would have caused the size of the largest + // datatype to overflow repeatedly. So check in a stepwise + // fashion "up to" the size we really want + if (!MemoryAvailable(_width*_height)) + { + _inRam = false; + return; + } + if (!MemoryAvailable(_width*_height*2)) + { + _inRam = false; + return; + } + if (!MemoryAvailable(static_cast(_width*_height*sizeof(_int32)*2))) + { + _inRam = false; + return; + } - _poBand->AdviseRead ( 0, 0, _width, _height, _width, _height, GDT_Int32, NULL); - _poBand->RasterIO( GF_Read, 0, 0, _width, _height, - _int32buffer, _width, _height, GDT_Int32,0, 0 ); + _int32buffer = (_int32 *) CPLMalloc( sizeof(_int32)*_width*_height ); + if (!_int32buffer) + { + _inRam = false; // Force the user to use disk-based; + // not enough memory likely to load into memory. + return; + } - } - else - { - // Is there enough memory available? - // CDM 1/6/2007: On one really extreme case, the amount - // of memory required would have caused the size of the largest - // datatype to overflow repeatedly. So check in a stepwise - // fashion "up to" the size we really want - if (!MemoryAvailable(_width*_height)) - { - _inRam = false; - return; - } - if (!MemoryAvailable(_width*_height*2)) - { - _inRam = false; - return; + _poBand->AdviseRead ( 0, 0, _width, _height, _width, _height, GDT_Int32, nullptr); + _poBand->RasterIO( GF_Read, 0, 0, _width, _height, + _int32buffer, _width, _height, GDT_Int32,0, 0 ); } - if (!MemoryAvailable(_width*_height*sizeof(float)*2)) + else { - _inRam = false; - return; - } + // Is there enough memory available? + // CDM 1/6/2007: On one really extreme case, the amount + // of memory required would have caused the size of the largest + // datatype to overflow repeatedly. So check in a stepwise + // fashion "up to" the size we really want + if (!MemoryAvailable(_width*_height)) + { + _inRam = false; + return; + } + if (!MemoryAvailable(_width*_height*2)) + { + _inRam = false; + return; + } + if (!MemoryAvailable(static_cast(_width*_height*sizeof(float)*2))) + { + _inRam = false; + return; + } - _floatbuffer = (float *) CPLMalloc( sizeof(float)*_width*_height ); - if (!_floatbuffer) - { - _inRam = false; // Force the user to use disk-based; - // not enough memory likely to load into memory. - return; - } + _floatbuffer = static_cast(CPLMalloc(sizeof(float) * _width * _height)); + if (!_floatbuffer) + { + _inRam = false; // Force the user to use disk-based; + // not enough memory likely to load into memory. + return; + } - _poBand->AdviseRead ( 0, 0, _width, _height, _width, _height, GDT_Float32, NULL); - _poBand->RasterIO( GF_Read, 0, 0, _width, _height, - _floatbuffer, _width, _height, GDT_Float32,0, 0 ); - } + _poBand->AdviseRead ( 0, 0, _width, _height, _width, _height, GDT_Float32, nullptr); + _poBand->RasterIO( GF_Read, 0, 0, _width, _height, + _floatbuffer, _width, _height, GDT_Float32,0, 0 ); + } } catch(...) { @@ -784,16 +783,16 @@ void tkGridRaster::LoadFullBuffer() bool tkGridRaster::GetFloatWindow(void *Vals, long StartRow, long EndRow, long StartCol, long EndCol, bool useDouble) { - if (_poBand == NULL) return false; + if (_poBand == nullptr) return false; // Load from buffer if it exists, otherwise use RasterIO. // Since there are lots of potential buffers, just call getValue - if (_int32buffer != NULL || _floatbuffer != NULL || _int32ScanlineBufferB != NULL || _floatScanlineBufferB != NULL || _int32ScanlineBufferA != NULL || _floatScanlineBufferA != NULL) + if (_int32buffer != nullptr || _floatbuffer != nullptr || _int32ScanlineBufferB != nullptr || _floatScanlineBufferB != nullptr || _int32ScanlineBufferA != nullptr || _floatScanlineBufferA != nullptr) { long position = 0; - double* ValsDouble = reinterpret_cast(Vals); - float* ValsFloat = reinterpret_cast(Vals); + double* ValsDouble = static_cast(Vals); + float* ValsFloat = static_cast(Vals); for (long j = StartRow; j <= EndRow; j++) { @@ -834,19 +833,19 @@ bool tkGridRaster::GetFloatWindow(void *Vals, long StartRow, long EndRow, long S bool tkGridRaster::PutFloatWindow(void *Vals, long StartRow, long EndRow, long StartCol, long EndCol, bool useDouble) { - if (_poBand == NULL) return false; + if (_poBand == nullptr) return false; // Reset our cached max/min values to our "unset" flags _cachedMin = 9999; _cachedMax = -9999; // Save to buffer if it exists, otherwise use RasterIO. - if (_int32buffer != NULL || _floatbuffer != NULL || _int32ScanlineBufferB != NULL || - _floatScanlineBufferB != NULL || _int32ScanlineBufferA != NULL || _floatScanlineBufferA != NULL) + if (_int32buffer != nullptr || _floatbuffer != nullptr || _int32ScanlineBufferB != nullptr || + _floatScanlineBufferB != nullptr || _int32ScanlineBufferA != nullptr || _floatScanlineBufferA != nullptr) { - double* ValsDouble = reinterpret_cast(Vals); - float* ValsFloat = reinterpret_cast(Vals); + double* ValsDouble = static_cast(Vals); + float* ValsFloat = static_cast(Vals); long position = 0; @@ -889,19 +888,19 @@ bool tkGridRaster::PutFloatWindow(void *Vals, long StartRow, long EndRow, long S void tkGridRaster::clear(double value) { - if (_inRam && _int32buffer != NULL) + if (_inRam && _int32buffer != nullptr) { for (int i = 0; i < _width * _height; i++) _int32buffer[i] = static_cast<_int32>(value); } - else if (_inRam && _floatbuffer != NULL) + else if (_inRam && _floatbuffer != nullptr) { for (int i = 0; i < _width * _height; i++) _floatbuffer[i] = static_cast(value); } else if (!_inRam) { - if (_poBand != NULL) + if (_poBand != nullptr) _poBand->Fill(value); } } @@ -915,7 +914,7 @@ bool tkGridRaster::SaveFullBuffer() // Chris Michaelis 1/28/2007 // Do not use ELSE's here -- otherwise only every other line will be saved - if (_genericType != GDT_Int32 && _scanlineADataChanged && _floatScanlineBufferA != NULL) + if (_genericType != GDT_Int32 && _scanlineADataChanged && _floatScanlineBufferA != nullptr) { _poBand->RasterIO( GF_Write, 0, _scanlineBufferNumberA, _width, 1, _floatScanlineBufferA, _width, 1, GDT_Float32,0, 0 ); @@ -931,7 +930,7 @@ bool tkGridRaster::SaveFullBuffer() _scanlineADataChanged = false; } - if (_genericType != GDT_Int32 && _scanlineBDataChanged && _floatScanlineBufferB != NULL) + if (_genericType != GDT_Int32 && _scanlineBDataChanged && _floatScanlineBufferB != nullptr) { _poBand->RasterIO( GF_Write, 0, _scanlineBufferNumberB, _width, 1, _floatScanlineBufferB, _width, 1, GDT_Float32,0, 0 ); @@ -948,14 +947,14 @@ bool tkGridRaster::SaveFullBuffer() } // Buffer save -- if not scanlining. - if ((_genericType == GDT_Int32 || _genericType == GDT_Byte) && _int32buffer != NULL) + if ((_genericType == GDT_Int32 || _genericType == GDT_Byte) && _int32buffer != nullptr) { _poBand->RasterIO( GF_Write, 0, 0, _width, _height, _int32buffer, _width, _height, GDT_Int32,0, 0 ); retVal = true; } - if (_genericType == GDT_Float32 && _floatbuffer != NULL) + if (_genericType == GDT_Float32 && _floatbuffer != nullptr) { _poBand->RasterIO( GF_Write, 0, 0, _width, _height, _floatbuffer, _width, _height, GDT_Float32,0, 0 ); @@ -994,7 +993,7 @@ bool tkGridRaster::Save(CStringW saveToFilename, GridFileType newFileFormat) { CStringW prjFilename = saveToFilename; prjFilename = prjFilename.Left(prjFilename.GetLength() - 3) + L"prj"; - FILE * prjFile = NULL; + FILE * prjFile = nullptr; prjFile = _wfopen(prjFilename, L"wb"); if (prjFile) { @@ -1004,7 +1003,7 @@ bool tkGridRaster::Save(CStringW saveToFilename, GridFileType newFileFormat) fprintf(prjFile, "%s", wkt); fclose(prjFile); - prjFile = NULL; + prjFile = nullptr; delete p; //added by Lailin Chen 12/30/2005 } } @@ -1026,21 +1025,21 @@ bool tkGridRaster::Save(CStringW saveToFilename, GridFileType newFileFormat) CStringA saveFilenameA = Utility::ConvertToUtf8(saveToFilename); m_globalSettings.SetGdalUtf8(true); - poDstDS = _rasterDataset->GetDriver()->CreateCopy( saveFilenameA, _rasterDataset, FALSE, NULL, NULL, NULL ); + poDstDS = _rasterDataset->GetDriver()->CreateCopy( saveFilenameA, _rasterDataset, FALSE, nullptr, nullptr, nullptr); m_globalSettings.SetGdalUtf8(false); - if (poDstDS == NULL) + if (poDstDS == nullptr) return false; // If in ram, save any changes also. if (_inRam) { - if ((_genericType == GDT_Int32 || _genericType == GDT_Byte) && _int32buffer != NULL) + if ((_genericType == GDT_Int32 || _genericType == GDT_Byte) && _int32buffer != nullptr) { _rasterDataset->GetRasterBand(1)->RasterIO( GF_Write, 0, 0, _width, _height, _int32buffer, _width, _height, GDT_Int32, 0, 0 ); } - else if (_genericType == GDT_Float32 && _floatbuffer != NULL) + else if (_genericType == GDT_Float32 && _floatbuffer != nullptr) { _rasterDataset->GetRasterBand(1)->RasterIO( GF_Write, 0, 0, _width, _height, _floatbuffer, _width, _height, GDT_Float32,0, 0 ); @@ -1050,14 +1049,14 @@ bool tkGridRaster::Save(CStringW saveToFilename, GridFileType newFileFormat) poDstDS->FlushCache(); // Clean up the destination dataset - if( poDstDS != NULL ) + if( poDstDS != nullptr) delete poDstDS; return true; } else // Different file type and/or different filename { - char **papszOptions = NULL; + char **papszOptions = nullptr; char *pszFormat; if (newFileFormat == Ecw) @@ -1081,7 +1080,7 @@ bool tkGridRaster::Save(CStringW saveToFilename, GridFileType newFileFormat) poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat); - if( poDriver == NULL ) + if( poDriver == nullptr) return false; // Create a new file and dump to it @@ -1092,7 +1091,7 @@ bool tkGridRaster::Save(CStringW saveToFilename, GridFileType newFileFormat) outFile->putValue(j, i, getValue(j, i)); outFile->Save(saveToFilename, newFileFormat); outFile->Close(); - outFile = NULL; + outFile = nullptr; return true; } @@ -1100,9 +1099,9 @@ bool tkGridRaster::Save(CStringW saveToFilename, GridFileType newFileFormat) double tkGridRaster::getValue( long Row, long Column ) { - if (_inRam == true && _int32buffer != NULL) + if (_inRam == true && _int32buffer != nullptr) return static_cast(_int32buffer[Column + Row * _width]); - else if (_inRam == true && _floatbuffer != NULL) + else if (_inRam == true && _floatbuffer != nullptr) return static_cast(_floatbuffer[Column + Row * _width]); else { @@ -1111,18 +1110,18 @@ double tkGridRaster::getValue( long Row, long Column ) { // Return from one-row buffer _scanlineLastAccessed = 'A'; - if ((_genericType == GDT_Int32 || _genericType == GDT_Byte) && _int32ScanlineBufferA != NULL) + if ((_genericType == GDT_Int32 || _genericType == GDT_Byte) && _int32ScanlineBufferA != nullptr) return static_cast(_int32ScanlineBufferA[Column]); - else if (_floatScanlineBufferA != NULL) + else if (_floatScanlineBufferA != nullptr) return static_cast(_floatScanlineBufferA[Column]); } else if (Row == _scanlineBufferNumberB) { // Return from one-row buffer _scanlineLastAccessed = 'B'; - if ((_genericType == GDT_Int32 || _genericType == GDT_Byte) && _int32ScanlineBufferB != NULL) + if ((_genericType == GDT_Int32 || _genericType == GDT_Byte) && _int32ScanlineBufferB != nullptr) return static_cast(_int32ScanlineBufferB[Column]); - else if (_floatScanlineBufferB != NULL) + else if (_floatScanlineBufferB != nullptr) return static_cast(_floatScanlineBufferB[Column]); } @@ -1140,12 +1139,12 @@ double tkGridRaster::getValue( long Row, long Column ) if (_scanlineBDataChanged) SaveFullBuffer(); - if (_int32ScanlineBufferB == NULL) - _int32ScanlineBufferB = (_int32*) CPLMalloc( sizeof(_int32)*_width); + if (_int32ScanlineBufferB == nullptr) + _int32ScanlineBufferB = static_cast<_int32*>(CPLMalloc(sizeof(_int32) * _width)); // If we get here and the buffer is still null, apparently // there's not really enough memory to do this...! - if (_int32ScanlineBufferB == NULL) + if (_int32ScanlineBufferB == nullptr) { // Clear and prevent buffering _scanlineBufferNumberA = -1; @@ -1170,12 +1169,12 @@ double tkGridRaster::getValue( long Row, long Column ) if (_scanlineBDataChanged) SaveFullBuffer(); - if (_floatScanlineBufferB == NULL) - _floatScanlineBufferB = (float *) CPLMalloc( sizeof(float)*_width); + if (_floatScanlineBufferB == nullptr) + _floatScanlineBufferB = static_cast(CPLMalloc(sizeof(float) * _width)); // If we get here and the buffer is still null, apparently // there's not really enough memory to do this...! - if (_floatScanlineBufferB == NULL) + if (_floatScanlineBufferB == nullptr) { // Clear and prevent buffering _scanlineBufferNumberA = -1; @@ -1204,12 +1203,12 @@ double tkGridRaster::getValue( long Row, long Column ) if (_scanlineADataChanged) SaveFullBuffer(); - if (_int32ScanlineBufferA == NULL) - _int32ScanlineBufferA = (_int32*) CPLMalloc( sizeof(_int32)*_width); + if (_int32ScanlineBufferA == nullptr) + _int32ScanlineBufferA = static_cast<_int32*>(CPLMalloc(sizeof(_int32) * _width)); // If we get here and the buffer is still null, apparently // there's not really enough memory to do this...! - if (_int32ScanlineBufferA == NULL) + if (_int32ScanlineBufferA == nullptr) { // Clear and prevent buffering _scanlineBufferNumberA = -1; @@ -1234,12 +1233,12 @@ double tkGridRaster::getValue( long Row, long Column ) if (_scanlineADataChanged) SaveFullBuffer(); - if (_floatScanlineBufferA == NULL) - _floatScanlineBufferA = (float *) CPLMalloc( sizeof(float)*_width); + if (_floatScanlineBufferA == nullptr) + _floatScanlineBufferA = static_cast(CPLMalloc(sizeof(float) * _width)); // If we get here and the buffer is still null, apparently // there's not really enough memory to do this...! - if (_floatScanlineBufferA == NULL) + if (_floatScanlineBufferA == nullptr) { // Clear and prevent buffering _scanlineBufferNumberA = -1; @@ -1293,28 +1292,28 @@ void tkGridRaster::putValue( long Row, long Column, double Value ) _cachedMin = 9999; _cachedMax = -9999; - if (_inRam == true && _int32buffer != NULL) + if (_inRam == true && _int32buffer != nullptr) _int32buffer[Column + Row * _width] = static_cast<_int32>(Value); - else if (_inRam == true && _floatbuffer != NULL) + else if (_inRam == true && _floatbuffer != nullptr) _floatbuffer[Column + Row * _width] = static_cast(Value); // If there is a loaded scanline buffer for this row, use it and set the modified flag. - else if ((_genericType == GDT_Int32 || _genericType == GDT_Byte) && _scanlineBufferNumberB == Row && _int32ScanlineBufferB != NULL) + else if ((_genericType == GDT_Int32 || _genericType == GDT_Byte) && _scanlineBufferNumberB == Row && _int32ScanlineBufferB != nullptr) { _int32ScanlineBufferB[Column] = static_cast<_int32>(Value); _scanlineBDataChanged = true; } - else if (_genericType != GDT_Int32 && _scanlineBufferNumberB == Row && _floatScanlineBufferB != NULL) + else if (_genericType != GDT_Int32 && _scanlineBufferNumberB == Row && _floatScanlineBufferB != nullptr) { _floatScanlineBufferB[Column] = static_cast(Value); _scanlineBDataChanged = true; } - else if ((_genericType == GDT_Int32 || _genericType == GDT_Byte) && _scanlineBufferNumberA == Row && _int32ScanlineBufferA != NULL) + else if ((_genericType == GDT_Int32 || _genericType == GDT_Byte) && _scanlineBufferNumberA == Row && _int32ScanlineBufferA != nullptr) { _int32ScanlineBufferA[Column] = static_cast<_int32>(Value); _scanlineADataChanged = true; } - else if (_genericType != GDT_Int32 && _scanlineBufferNumberA == Row && _floatScanlineBufferA != NULL) + else if (_genericType != GDT_Int32 && _scanlineBufferNumberA == Row && _floatScanlineBufferA != nullptr) { _floatScanlineBufferA[Column] = static_cast(Value); _scanlineADataChanged = true; @@ -1394,7 +1393,7 @@ bool tkGridRaster::SaveToBGD(CString filename, void(*callback)(int number, const if( _tcslen( projection ) < MAX_STRING_LENGTH ) { - int size_of_pad = MAX_STRING_LENGTH - _tcslen(projection); + int size_of_pad = MAX_STRING_LENGTH - static_cast(_tcslen(projection)); char * pad = new char[size_of_pad]; for( int p = 0; p < size_of_pad; p++ ) pad[p] = 0; @@ -1403,7 +1402,7 @@ bool tkGridRaster::SaveToBGD(CString filename, void(*callback)(int number, const } CString prjFilename = filename.Left(filename.GetLength() - 3) + "prj"; - FILE * prjFile = NULL; + FILE * prjFile = nullptr; prjFile = fopen(prjFilename, "wb"); if (prjFile) { @@ -1416,7 +1415,7 @@ bool tkGridRaster::SaveToBGD(CString filename, void(*callback)(int number, const fprintf(prjFile, "%s", wkt); fclose(prjFile); - prjFile = NULL; + prjFile = nullptr; delete p; //added by Lailin Chen 12/30/2005 } catch(...) @@ -1451,9 +1450,9 @@ bool tkGridRaster::SaveToBGD(CString filename, void(*callback)(int number, const lValue = static_cast(getValue( j, i )); fwrite( &lValue,sizeof(long),1,out); - if( callback != NULL ) + if( callback != nullptr) { - int newpercent = (int)((num_written/total)*100); + int newpercent = static_cast((num_written / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Binary Grid Write"); @@ -1471,9 +1470,9 @@ bool tkGridRaster::SaveToBGD(CString filename, void(*callback)(int number, const fValue = static_cast(getValue( j, i )); fwrite( &fValue,sizeof(float),1,out); - if( callback != NULL ) + if( callback != nullptr) { - int newpercent = (int)((num_written/total)*100); + int newpercent = static_cast((num_written / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Binary Grid Write"); @@ -1484,7 +1483,7 @@ bool tkGridRaster::SaveToBGD(CString filename, void(*callback)(int number, const } fflush(out); fclose( out ); - out = NULL; + out = nullptr; return true; } return true; @@ -1554,9 +1553,9 @@ bool tkGridRaster::ReadFromBGD(CString filename, void (*callback)(int number, co putValue(j, i, dData); } - if( callback != NULL ) + if( callback != nullptr) { - int newpercent = (int)(((num_read)/total)*100); + int newpercent = static_cast(((num_read) / total) * 100); if( newpercent > percent ) { percent = newpercent; callback( percent, "Reading Binary Grid" ); @@ -1632,14 +1631,14 @@ void tkGridRaster::ReadBGDHeader( CString filename, FILE * in, DATA_TYPE &bgdDat // a .prj file will override what's in the header try { - char * newProj = NULL; + char * newProj = nullptr; // TODO: Should we use GeoPorjection instead? ProjectionTools * p = new ProjectionTools(); CString prjFilename = filename.Left(filename.GetLength() - 3) + "prj"; p->GetProj4FromPRJFile(prjFilename.GetBuffer(), &newProj); delete p; - if (newProj != NULL && _tcslen(newProj) > 0) + if (newProj != nullptr && _tcslen(newProj) > 0) { strncpy(projection, newProj, MAX_STRING_LENGTH); CPLFree(newProj); @@ -1654,12 +1653,12 @@ void tkGridRaster::ReadBGDHeader( CString filename, FILE * in, DATA_TYPE &bgdDat // SetProjection expects WKT if (startsWith(projection, "+proj")) { - char * wkt = NULL; + char * wkt = nullptr; ProjectionTools * p = new ProjectionTools(); p->ToESRIWKTFromProj4(&wkt, projection); - if (wkt != NULL && strcmp(wkt, "") != 0) + if (wkt != nullptr && strcmp(wkt, "") != 0) { if (_rasterDataset) _rasterDataset->SetProjection(wkt); } @@ -1703,16 +1702,16 @@ bool tkGridRaster::contains(char * haystack, char needle) const bool tkGridRaster::MemoryAvailable(double bytes) { - if (bytes > MAX_INRAM_SIZE) return false; + if (bytes > MAX_INRAM_SIZE) return false; - MEMORYSTATUS stat; + MEMORYSTATUS stat; - GlobalMemoryStatus (&stat); + GlobalMemoryStatus (&stat); - if (stat.dwAvailPhys >= bytes) - return true; + if (stat.dwAvailPhys >= bytes) + return true; - return false; + return false; } bool tkGridRaster::ColorTable2BSTR(BSTR *pVal) @@ -1766,7 +1765,7 @@ bool tkGridRaster::BSTR2ColorTable(BSTR cTbl) { USES_CONVERSION; int numColors = 0; - CString str (cTbl == NULL ? L"" : cTbl); + CString str (cTbl == nullptr ? L"" : cTbl); if (str.IsEmpty()) { _hasColorTable=false; @@ -1778,24 +1777,24 @@ bool tkGridRaster::BSTR2ColorTable(BSTR cTbl) resToken= str.Tokenize(_T(":"),curPos); while (resToken != _T("")) { - vCT.push_back(resToken); - resToken = str.Tokenize(_T(":"), curPos); + vCT.push_back(resToken); + resToken = str.Tokenize(_T(":"), curPos); } - numColors=vCT.size()/4; + numColors = static_cast(vCT.size()) / 4; GDALPaletteInterp cInt; int iInt = atoi(vCT[0]); switch (iInt) { case 0: - cInt=GPI_Gray;break; + cInt = GPI_Gray;break; case 1: - cInt=GPI_RGB;break; + cInt = GPI_RGB;break; case 2: - cInt=GPI_CMYK;break; + cInt = GPI_CMYK;break; case 3: - cInt=GPI_HLS;break; + cInt = GPI_HLS;break; default: - cInt=GPI_RGB; + cInt = GPI_RGB; } _poColorT = new GDALColorTable(cInt); @@ -1803,10 +1802,10 @@ bool tkGridRaster::BSTR2ColorTable(BSTR cTbl) for (int i = 0; i < numColors-1; i++) { - poCE.c1=atoi(vCT[(i+1)*4+0]); - poCE.c2=atoi(vCT[(i+1)*4+1]); - poCE.c3=atoi(vCT[(i+1)*4+2]); - poCE.c4=atoi(vCT[(i+1)*4+3]); + poCE.c1 = atoi(vCT[(i+1)*4+0]); + poCE.c2 = atoi(vCT[(i+1)*4+1]); + poCE.c3 = atoi(vCT[(i+1)*4+2]); + poCE.c4 = atoi(vCT[(i+1)*4+3]); _poColorT->SetColorEntry(i,&poCE); } _hasColorTable = true; diff --git a/src/MapControl/Map_Cursors.cpp b/src/MapControl/Map_Cursors.cpp index 86dfa1f5..06338feb 100644 --- a/src/MapControl/Map_Cursors.cpp +++ b/src/MapControl/Map_Cursors.cpp @@ -9,7 +9,7 @@ // ******************************************************* BOOL CMapView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { - HCURSOR NewCursor = NULL; + HCURSOR NewCursor = nullptr; if( nHitTest != HTCLIENT ) { @@ -19,19 +19,19 @@ BOOL CMapView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) bool hasGuiCursor = true; if (_copyrightLinkActive) { - NewCursor = LoadCursor(NULL, IDC_HAND); + NewCursor = LoadCursor(nullptr, IDC_HAND); } else { switch (_lastZooombarPart) { case ZoombarHandle: - NewCursor = LoadCursor(NULL, IDC_SIZENS); + NewCursor = LoadCursor(nullptr, IDC_SIZENS); break; case ZoombarMinus: case ZoombarPlus: case ZoombarBar: - NewCursor = LoadCursor(NULL, IDC_HAND); + NewCursor = LoadCursor(nullptr, IDC_HAND); break; default: hasGuiCursor = false; @@ -48,7 +48,7 @@ BOOL CMapView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) } } - if (NewCursor != NULL) + if (NewCursor != nullptr) ::SetCursor( NewCursor ); else COleControl::OnSetCursor( pWnd, nHitTest, message ); @@ -61,7 +61,7 @@ BOOL CMapView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) // ******************************************************* HCURSOR CMapView::GetCursorIcon() { - HCURSOR newCursor = NULL; + HCURSOR newCursor = nullptr; switch (m_mapCursor) { case crsrMapDefault: @@ -80,8 +80,8 @@ HCURSOR CMapView::GetCursorIcon() newCursor = (_useAlternatePanCursor == TRUE) ? _cursorAlternatePan : _cursorPan; break; - case cmSelection: - case cmSelectByPolygon: + case cmSelection: + case cmSelectByPolygon: newCursor = _cursorSelect; break; @@ -115,71 +115,71 @@ HCURSOR CMapView::GetCursorIcon() break;*/ case cmNone: - newCursor = (HCURSOR)m_uDCursorHandle; + newCursor = reinterpret_cast(static_cast(m_uDCursorHandle)); break; } break; case crsrAppStarting: - newCursor = LoadCursor(NULL, IDC_APPSTARTING); + newCursor = LoadCursor(nullptr, IDC_APPSTARTING); break; case crsrArrow: - newCursor = LoadCursor(NULL, IDC_ARROW); + newCursor = LoadCursor(nullptr, IDC_ARROW); break; case crsrCross: - newCursor = LoadCursor(NULL, IDC_CROSS); + newCursor = LoadCursor(nullptr, IDC_CROSS); break; case crsrHelp: - newCursor = LoadCursor(NULL, IDC_HELP); + newCursor = LoadCursor(nullptr, IDC_HELP); break; case crsrIBeam: - newCursor = LoadCursor(NULL, IDC_IBEAM); + newCursor = LoadCursor(nullptr, IDC_IBEAM); break; case crsrNo: - newCursor = LoadCursor(NULL, IDC_NO); + newCursor = LoadCursor(nullptr, IDC_NO); break; case crsrSizeAll: - newCursor = LoadCursor(NULL, IDC_SIZEALL); + newCursor = LoadCursor(nullptr, IDC_SIZEALL); break; case crsrSizeNESW: - newCursor = LoadCursor(NULL, IDC_SIZENESW); + newCursor = LoadCursor(nullptr, IDC_SIZENESW); break; case crsrSizeNS: - newCursor = LoadCursor(NULL, IDC_SIZENS); + newCursor = LoadCursor(nullptr, IDC_SIZENS); break; case crsrSizeNWSE: - newCursor = LoadCursor(NULL, IDC_SIZENWSE); + newCursor = LoadCursor(nullptr, IDC_SIZENWSE); break; case crsrSizeWE: - newCursor = LoadCursor(NULL, IDC_SIZEWE); + newCursor = LoadCursor(nullptr, IDC_SIZEWE); break; case crsrUpArrow: - newCursor = LoadCursor(NULL, IDC_UPARROW); + newCursor = LoadCursor(nullptr, IDC_UPARROW); break; case crsrHand: - newCursor = LoadCursor(NULL, IDC_HAND); + newCursor = LoadCursor(nullptr, IDC_HAND); break; case crsrWait: if (!_disableWaitCursor) - newCursor = LoadCursor(NULL, IDC_WAIT); + newCursor = LoadCursor(nullptr, IDC_WAIT); break; case crsrUserDefined: - newCursor = (HCURSOR)m_uDCursorHandle; + newCursor = reinterpret_cast(static_cast(m_uDCursorHandle)); break; } return newCursor; @@ -221,19 +221,19 @@ void CMapView::UpdateCursor(tkCursorMode newCursor, bool clearEditor) if (!InitRotationTool()) return; } - + bool refreshNeeded = newCursor == cmRotateShapes || m_cursorMode == cmRotateShapes; if (MeasuringHelper::OnCursorChanged(_measuring, newCursor)) refreshNeeded = true; - + if (!EditorHelper::OnCursorChanged(_shapeEditor, clearEditor, newCursor, refreshNeeded)) return; m_cursorMode = newCursor; OnSetCursor(this, HTCLIENT, 0); - + if (refreshNeeded) RedrawCore(RedrawSkipDataLayers, true); } @@ -243,26 +243,26 @@ void CMapView::UpdateCursor(tkCursorMode newCursor, bool clearEditor) // ********************************************************* HCURSOR CMapView::SetWaitCursor() { - if (_disableWaitCursor) - return NULL; + if (_disableWaitCursor) + return nullptr; HCURSOR oldCursor = ::GetCursor(); - + CPoint cpos; GetCursorPos(&cpos); CRect wrect; GetWindowRect(&wrect); - + HWND wndActive = ::GetActiveWindow(); if ((wndActive == this->GetSafeHwnd()) || (wndActive == this->GetParentOwner()->GetSafeHwnd())) { if( wrect.PtInRect(cpos) && (m_mapCursor != crsrUserDefined) && !_disableWaitCursor) { - ::SetCursor(LoadCursor(NULL, IDC_WAIT) ); + ::SetCursor(LoadCursor(nullptr, IDC_WAIT) ); } } - return oldCursor; + return oldCursor; } diff --git a/src/MapControl/Map_Drawing.cpp b/src/MapControl/Map_Drawing.cpp index 9cef2ecc..1e4fac2a 100644 --- a/src/MapControl/Map_Drawing.cpp +++ b/src/MapControl/Map_Drawing.cpp @@ -34,7 +34,7 @@ void CMapView::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) //This line is intended to ensure proper function in MSAccess by verifying that the hWnd handle exists //before trying to draw. Lailin Chen - 2005/10/17 - if (this->m_hWnd == NULL) + if (this->m_hWnd == nullptr) return; // no redraw is allowed when the rubber band is being dragged @@ -47,7 +47,7 @@ void CMapView::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) m_drawMutex.Lock(); // TODO: perhaps use lighter CCriticalSection - if (!_canUseMainBuffer || !_canUseVolatileBuffer || !_canUseLayerBuffer) + if (!_canUseMainBuffer || !_canUseVolatileBuffer || !_canUseLayerBuffer) { bool hasMouseMoveData = HasDrawingData(tkDrawingDataAvailable::MeasuringData) || HasDrawingData(tkDrawingDataAvailable::Coordinates) || @@ -80,9 +80,9 @@ void CMapView::HandleNewDrawing(CDC* pdc, const CRect& rcBounds, const CRect& rc { Gdiplus::Color backColor = Utility::OleColor2GdiPlus(m_backColor); - Gdiplus::Graphics* gBuffer = NULL; // for control rendering - Gdiplus::Graphics* gPrinting = NULL; // for snapshot drawing - Gdiplus::Graphics* g = NULL; // the right one to draw + Gdiplus::Graphics* gBuffer = nullptr; // for control rendering + Gdiplus::Graphics* gPrinting = nullptr; // for snapshot drawing + Gdiplus::Graphics* g = nullptr; // the right one to draw // preparing graphics (for snapshot drawing to output canvas directly; // for control rendering main buffer is used) @@ -121,8 +121,8 @@ void CMapView::HandleNewDrawing(CDC* pdc, const CRect& rcBounds, const CRect& rc if (m_sendOnDrawBackBuffer) { - // passing main buffer to client for custom drawing - FireOnDrawbackBufferCore(g, _isSnapshot ? NULL : _bufferBitmap); + // passing main buffer to client for custom drawing + FireOnDrawbackBufferCore(g, _isSnapshot ? nullptr : _bufferBitmap); } #if DEBUG_ALLOCATED_OBJECTS ComHelper::SetBreak(false); @@ -136,7 +136,7 @@ void CMapView::HandleNewDrawing(CDC* pdc, const CRect& rcBounds, const CRect& rc DWORD endTick = GetTickCount(); if (layersRedraw) { - _lastRedrawTime = (float)(endTick - startTick) / 1000.0f; + _lastRedrawTime = static_cast(endTick - startTick) / 1000.0f; } ShowRedrawTime(g, _lastRedrawTime, layersRedraw); @@ -175,11 +175,11 @@ void CMapView::DumpBuffers() #ifndef RELEASE_MODE CLSID clsid; Utility::GetEncoderClsid(L"image/png", &clsid); - _bufferBitmap->Save(L"D:\\buffer.png", &clsid, NULL); - _drawingBitmap->Save(L"D:\\drawing.png", &clsid, NULL); - _tilesBitmap->Save(L"D:\\tiles.png", &clsid, NULL); - _layerBitmap->Save(L"D:\\layers.png", &clsid, NULL); - _volatileBitmap->Save(L"D:\\volatile.png", &clsid, NULL); + _bufferBitmap->Save(L"D:\\buffer.png", &clsid, nullptr); + _drawingBitmap->Save(L"D:\\drawing.png", &clsid, nullptr); + _tilesBitmap->Save(L"D:\\tiles.png", &clsid, nullptr); + _layerBitmap->Save(L"D:\\layers.png", &clsid, nullptr); + _volatileBitmap->Save(L"D:\\volatile.png", &clsid, nullptr); #endif } @@ -192,7 +192,7 @@ void CMapView::FireOnDrawbackBufferCore(Gdiplus::Graphics* g, Gdiplus::Bitmap* b if (g && (_customDrawingFlags & OnDrawBackBufferHdc)) { HDC hdc = g->GetHDC(); - FireOnDrawBackBuffer((long)hdc); + FireOnDrawBackBuffer(static_cast(reinterpret_cast(hdc))); g->ReleaseHDC(hdc); } @@ -202,7 +202,7 @@ void CMapView::FireOnDrawbackBufferCore(Gdiplus::Graphics* g, Gdiplus::Bitmap* b Gdiplus::Rect r(0, 0, _bufferBitmap->GetWidth(), _bufferBitmap->GetHeight()); Gdiplus::BitmapData bmd; _bufferBitmap->LockBits(&r, Gdiplus::ImageLockModeRead | Gdiplus::ImageLockModeWrite, _bufferBitmap->GetPixelFormat(), &bmd); - FireOnDrawBackBuffer2((long)bmd.Height, (long)bmd.Width, (long)bmd.Stride, (long)bmd.PixelFormat, (long)bmd.Scan0); + FireOnDrawBackBuffer2(static_cast(bmd.Height), static_cast(bmd.Width), bmd.Stride, bmd.PixelFormat, static_cast(reinterpret_cast(bmd.Scan0))); _bufferBitmap->UnlockBits(&bmd); } } @@ -232,7 +232,7 @@ bool CMapView::RedrawLayers(Gdiplus::Graphics* g, CDC* dc, const CRect& rcBounds int y = dragging ? _dragging.Move.y - _dragging.Start.y : 0; // update from the layer buffer - g->DrawImage(_layerBitmap, (float)x, (float)y); + g->DrawImage(_layerBitmap, static_cast(x), static_cast(y)); } else { @@ -248,7 +248,7 @@ bool CMapView::RedrawLayers(Gdiplus::Graphics* g, CDC* dc, const CRect& rcBounds { HDC hdc = g->GetHDC(); tkMwBoolean retVal = blnFalse; - this->FireBeforeLayers((long)hdc, rcBounds.left, rcBounds.right, rcBounds.top, rcBounds.bottom, &retVal); + this->FireBeforeLayers(static_cast(reinterpret_cast(hdc)), rcBounds.left, rcBounds.right, rcBounds.top, rcBounds.bottom, &retVal); g->ReleaseHDC(hdc); } @@ -275,7 +275,7 @@ bool CMapView::RedrawLayers(Gdiplus::Graphics* g, CDC* dc, const CRect& rcBounds { HDC hdc = g->GetHDC(); tkMwBoolean retVal = blnFalse; - this->FireAfterLayers((long)hdc, rcBounds.left, rcBounds.right, rcBounds.top, rcBounds.bottom, &retVal); + this->FireAfterLayers(static_cast(reinterpret_cast(hdc)), rcBounds.left, rcBounds.right, rcBounds.top, rcBounds.bottom, &retVal); g->ReleaseHDC(hdc); } } @@ -304,7 +304,7 @@ void CMapView::RedrawWmsLayers(Gdiplus::Graphics* g) continue; } - CComPtr wms = NULL; + CComPtr wms = nullptr; layer->QueryWmsLayer(&wms); TileManager* manager = WmsHelper::Cast(wms)->get_Manager(); @@ -361,7 +361,7 @@ void CMapView::RedrawTiles(Gdiplus::Graphics* g, CDC* dc) { if (HasDrawingData(tkDrawingDataAvailable::TilesData)) { - CTiles* tiles = (CTiles*)_tiles; + CTiles* tiles = static_cast(_tiles); if (_isSnapshot) { get_TileManager()->MarkUndrawn(); @@ -420,7 +420,7 @@ void CMapView::RedrawVolatileData(Gdiplus::Graphics* g, CDC* dc, const CRect& rc { HDC hdc = g->GetHDC(); tkMwBoolean retVal = blnFalse; - this->FireBeforeDrawing((long)hdc, rcBounds.left, rcBounds.right, rcBounds.top, rcBounds.bottom, &retVal); + this->FireBeforeDrawing(static_cast(reinterpret_cast(hdc)), rcBounds.left, rcBounds.right, rcBounds.top, rcBounds.bottom, &retVal); g->ReleaseHDC(hdc); } @@ -438,7 +438,7 @@ void CMapView::RedrawVolatileData(Gdiplus::Graphics* g, CDC* dc, const CRect& rc { HDC hdc = g->GetHDC(); tkMwBoolean retVal = blnFalse; - this->FireAfterDrawing((long)hdc, rcBounds.left, rcBounds.right, rcBounds.top, rcBounds.bottom, &retVal); + this->FireAfterDrawing(static_cast(reinterpret_cast(hdc)), rcBounds.left, rcBounds.right, rcBounds.top, rcBounds.bottom, &retVal); g->ReleaseHDC(hdc); } } @@ -515,7 +515,7 @@ void CMapView::DrawIdentified(Gdiplus::Graphics* g, const CRect& rcBounds) // *************************************************************** void CMapView::RenderIdentifiedShapes(vector& handles, CShapefileDrawer& drawer, const CRect& rcBounds) { - VARIANT_BOOL vb; + VARIANT_BOOL vb; for (size_t i = 0; i < handles.size(); i++) { @@ -554,7 +554,7 @@ void CMapView::UpdateSelectedPixels(vector& handles, bool& hasPolygons, bo if (layer->IsImage()) { - CComPtr img = NULL; + CComPtr img = nullptr; img.Attach(GetImage(handles[i])); if (!img) continue; @@ -618,7 +618,7 @@ void CMapView::RenderSelectedPixels(vector& handles, CShapefileDrawer& dra // *************************************************************** void CMapView::UpdateTileBuffer( CDC* dc, bool zoomingAnimation ) { - CTiles* tiles = (CTiles*)_tiles; + CTiles* tiles = static_cast(_tiles); Gdiplus::Graphics* gTiles = Gdiplus::Graphics::FromImage(_tilesBitmap); int tileProvider = GetTileProvider(); @@ -629,7 +629,7 @@ void CMapView::UpdateTileBuffer( CDC* dc, bool zoomingAnimation ) // it's the first tile for current extents, we need to initialize the buffer bool canReuseBuffer = /*ForceDiscreteZoom() &&*/ - GetTileProvider() == _tileBuffer.Provider && + GetTileProvider() == _tileBuffer.Provider && _currentZoom != _tileBuffer.Zoom && abs(_currentZoom - _tileBuffer.Zoom) <= 4; // for larger difference it's not practical bool wasReused = false; @@ -695,10 +695,10 @@ void CMapView::DrawZoomingAnimation( Extent match, Gdiplus::Graphics* gTemp, CDC double ty = (_extents.top - match.top)/_extents.Height(); double ty2 = 1.0f - (match.bottom - _extents.bottom)/_extents.Height(); - target.X = (float)(tx * _viewWidth); - target.Y = (float)(ty * _viewHeight); - target.Width = (float)((tx2 - tx) * _viewWidth); - target.Height = (float)((ty2 - ty) * _viewHeight); + target.X = static_cast(tx * _viewWidth); + target.Y = static_cast(ty * _viewHeight); + target.Width = static_cast((tx2 - tx) * _viewWidth); + target.Height = static_cast((ty2 - ty) * _viewHeight); // source rectangle (cached tile buffer) Extent buffer = _tileBuffer.Extents; @@ -707,10 +707,10 @@ void CMapView::DrawZoomingAnimation( Extent match, Gdiplus::Graphics* gTemp, CDC double sy = (buffer.top - match.top)/buffer.Height(); double sy2 = 1.0f - (match.bottom - buffer.bottom)/buffer.Height(); - source.X = (float)(sx * _tilesBitmap->GetWidth()); - source.Y = (float)(sy * _tilesBitmap->GetHeight()); - source.Width = (float)((sx2 - sx) * _tilesBitmap->GetWidth()); - source.Height = (float)((sy2 - sy) * _tilesBitmap->GetHeight()); + source.X = static_cast(sx * _tilesBitmap->GetWidth()); + source.Y = static_cast(sy * _tilesBitmap->GetHeight()); + source.Width = static_cast((sx2 - sx) * _tilesBitmap->GetWidth()); + source.Height = static_cast((sy2 - sy) * _tilesBitmap->GetHeight()); double x, x2, y, y2; @@ -772,10 +772,10 @@ void CMapView::DrawZoomingAnimation( Extent match, Gdiplus::Graphics* gTemp, CDC y = i / steps * ty; y2 = ty2 + (1 - ty2) * (1 - i/steps); - tRect.X = (float)(x * _viewWidth); - tRect.Width = (float)(x2 * _viewWidth - tRect.X); - tRect.Y = (float)(y * _viewHeight); - tRect.Height =(float)(y2 * _viewHeight - tRect.Y); + tRect.X = static_cast(x * _viewWidth); + tRect.Width = static_cast(x2 * _viewWidth - tRect.X); + tRect.Y = static_cast(y * _viewHeight); + tRect.Height = static_cast(y2 * _viewHeight - tRect.Y); lastTime = GetTickCount(); @@ -830,7 +830,7 @@ void CMapView::DrawLayers(const CRect & rcBounds, Gdiplus::Graphics* graphics, b register int i; long startcondition = 0; - long endcondition = _activeLayers.size(); + long endcondition = static_cast(_activeLayers.size()); // nothing to draw if (endcondition == 0) @@ -884,8 +884,8 @@ void CMapView::DrawLayers(const CRect & rcBounds, Gdiplus::Graphics* graphics, b Layer * l = _allLayers[_activeLayers[i]]; if (l->IsShapefile() && l->wasRendered) // if it's hidden don't clear every time { - CComPtr sf = NULL; - // don't mark as 'undrawn' if we're not going to redraw it + CComPtr sf = nullptr; + // don't mark as 'undrawn' if we're not going to redraw it if (l->QueryShapefile(&sf) && ShapefileHelper::IsVolatile(sf) != layerBuffer) { ShapefileHelper::Cast(sf)->MarkUndrawn(); @@ -914,17 +914,17 @@ void CMapView::DrawLayers(const CRect & rcBounds, Gdiplus::Graphics* graphics, b LayerDrawer::DrawLabels(l, lblDrawer, vpAboveParentLayer); } - else if (l->IsShapefile() || l->IsDynamicOgrLayer()) + else if (l->IsShapefile() || l->IsDynamicOgrLayer()) { - CComPtr sf = NULL; + CComPtr sf = nullptr; if (l->IsDynamicOgrLayer()) { // Try to get the data loaded so far & update labels & categories l->UpdateShapefile(); // Get the shapefile - l->QueryShapefile(&sf); + l->QueryShapefile(&sf); } else { @@ -934,18 +934,18 @@ void CMapView::DrawLayers(const CRect & rcBounds, Gdiplus::Graphics* graphics, b if (!l->extents.Intersects(_extents)) continue; - // Update labels & categories - l->UpdateShapefile(); + // Update labels & categories + l->UpdateShapefile(); } // layerBuffer == true indicates we're drawing the non-Volatile layers if (l->QueryShapefile(&sf) && ShapefileHelper::IsVolatile(sf) == layerBuffer) continue; - // Perform the draw: - sfDrawer.Draw(rcBounds, sf); - LayerDrawer::DrawLabels(l, lblDrawer, vpAboveParentLayer); - LayerDrawer::DrawCharts(l, chartDrawer, vpAboveParentLayer); + // Perform the draw: + sfDrawer.Draw(rcBounds, sf); + LayerDrawer::DrawLabels(l, lblDrawer, vpAboveParentLayer); + LayerDrawer::DrawCharts(l, chartDrawer, vpAboveParentLayer); } } } @@ -959,7 +959,7 @@ void CMapView::DrawLayers(const CRect & rcBounds, Gdiplus::Graphics* graphics, b _shapeCountInView = shapeCount; // drawing labels and charts above the layers - for (i = 0; i < (int)_activeLayers.size(); i++) + for (i = 0; i < static_cast(_activeLayers.size()); i++) { Layer * l = _allLayers[_activeLayers[i]]; @@ -967,7 +967,7 @@ void CMapView::DrawLayers(const CRect & rcBounds, Gdiplus::Graphics* graphics, b if (!l->IsVisible(scale, zoom)) continue; - CComPtr sf = NULL; + CComPtr sf = nullptr; if (l->QueryShapefile(&sf) && ShapefileHelper::IsVolatile(sf) == layerBuffer) continue; @@ -976,11 +976,11 @@ void CMapView::DrawLayers(const CRect & rcBounds, Gdiplus::Graphics* graphics, b LayerDrawer::DrawCharts(l, chartDrawer, vpAboveAllLayers); } - if (layerBuffer && oldCursor != NULL) { + if (layerBuffer && oldCursor != nullptr) { ::SetCursor(oldCursor); } - if (isConcealed) + if (isConcealed) delete[] isConcealed; } @@ -991,10 +991,10 @@ void CMapView::DrawImageLayer(const CRect& rcBounds, Layer* l, Gdiplus::Graphics { if (!l->IsImage()) return; - IImage * iimg = NULL; + IImage * iimg = nullptr; if (!l->QueryImage(&iimg)) return; - CImageClass* img = (CImageClass*)iimg; + CImageClass* img = static_cast(iimg); if (_canUseImageGrouping && img->m_groupID != -1) { @@ -1097,7 +1097,7 @@ bool CMapView::HaveDataLayersWithinView() for(size_t i = 0; i < _activeLayers.size(); i++) { Layer * l = _allLayers[_activeLayers[i]]; - if( l != NULL ) + if( l != nullptr) { if (l->IsVisible(scale, zoom)) { @@ -1121,9 +1121,9 @@ void CMapView::DrawImageGroups() // building groups this->BuildImageGroups(*newGroups); - + // comparing them with the old list - if (_imageGroups != NULL) + if (_imageGroups != nullptr) { if (this->ImageGroupsAreEqual(*_imageGroups, *newGroups)) { @@ -1134,21 +1134,21 @@ void CMapView::DrawImageGroups() } newGroups->clear(); delete newGroups; - newGroups = NULL; + newGroups = nullptr; } else { // groups has changed, swapping pointers - if (_imageGroups != NULL) + if (_imageGroups != nullptr) { for (size_t i = 0; i < _imageGroups->size(); i++) { delete (*_imageGroups)[i]; } - + _imageGroups->clear(); delete _imageGroups; - _imageGroups = NULL; + _imageGroups = nullptr; } _imageGroups = newGroups; } @@ -1157,7 +1157,7 @@ void CMapView::DrawImageGroups() { _imageGroups = newGroups; } - + // mark all images as undrawn for (size_t i = 0; i < _imageGroups->size(); i++) { @@ -1171,7 +1171,7 @@ void ResizeBuffer(Gdiplus::Bitmap** bitmap, int cx, int cy) if (*bitmap) { delete *bitmap; - *bitmap = NULL; + *bitmap = nullptr; } *bitmap = new Gdiplus::Bitmap(cx, cy); } @@ -1194,7 +1194,7 @@ void CMapView::ResizeBuffers(int cx, int cy) if (_tilesBitmap) { delete _tilesBitmap; - _tilesBitmap = NULL; + _tilesBitmap = nullptr; } _tilesBitmap = new Gdiplus::Bitmap(cx, cy); _tileBuffer.Provider = tkTileProvider::ProviderNone; // buffer can't be reused @@ -1209,7 +1209,7 @@ void CMapView::ResizeBuffers(int cx, int cy) // *************************************************************** bool CMapView::HasDrawingData(tkDrawingDataAvailable type) { - switch(type) + switch(type) { case FocusRect: { @@ -1225,7 +1225,7 @@ bool CMapView::HasDrawingData(tkDrawingDataAvailable type) { return _dragging.Operation == DragMoveShapes || _dragging.Operation == DragRotateShapes; } - case ActShape: + case ActShape: { /*VARIANT_BOOL isEmpty; _shapeEditor->get_IsEmpty(&isEmpty);*/ @@ -1241,7 +1241,7 @@ bool CMapView::HasDrawingData(tkDrawingDataAvailable type) return false; return true; // GetEditorBase()->GetPointCount() > 0; always draw this to show snap points } - case tkDrawingDataAvailable::LayersData: + case tkDrawingDataAvailable::LayersData: { return _activeLayers.size() > 0; } @@ -1299,7 +1299,7 @@ bool CMapView::HasDrawingData(tkDrawingDataAvailable type) // **************************************************************** bool CMapView::HasImages() { - for(long i = _activeLayers.size() - 1; i >= 0; i-- ) + for(long i = static_cast(_activeLayers.size()) - 1; i >= 0; i-- ) { Layer * l = _allLayers[_activeLayers[i]]; if( IS_VALID_PTR(l) ) @@ -1316,7 +1316,7 @@ bool CMapView::HasImages() // **************************************************************** bool CMapView::HasHotTracking() { - for (long i = _activeLayers.size() - 1; i >= 0; i--) + for (long i = static_cast(_activeLayers.size())- 1; i >= 0; i--) { if (CheckLayer(slctHotTracking, _activeLayers[i])) { @@ -1331,14 +1331,14 @@ bool CMapView::HasHotTracking() // **************************************************************** bool CMapView::HasVolatileShapefiles() { - for(long i = _activeLayers.size() - 1; i >= 0; i-- ) + for(long i = static_cast(_activeLayers.size()) - 1; i >= 0; i-- ) { Layer * l = _allLayers[_activeLayers[i]]; if( IS_VALID_PTR(l) ) { if( l->IsShapefile()) { - IShapefile* sf = NULL; + IShapefile* sf = nullptr; l->QueryShapefile(&sf); if (sf) { VARIANT_BOOL vb; @@ -1368,7 +1368,7 @@ void CMapView::CheckForConcealedImages(bool* isConcealed, long& startcondition, { if( l->IsImage() && l->IsVisible(scale, zoom)) { - IImage * iimg = NULL; + IImage * iimg = nullptr; if (!l->QueryImage(&iimg)) continue; this->AdjustLayerExtents(i); @@ -1376,7 +1376,7 @@ void CMapView::CheckForConcealedImages(bool* isConcealed, long& startcondition, VARIANT_BOOL useTransparencyColor; iimg->get_UseTransparencyColor(&useTransparencyColor); iimg->Release(); - iimg = NULL; + iimg = nullptr; if( useTransparencyColor == FALSE ) { @@ -1430,7 +1430,7 @@ void CMapView::DrawLayersRotated(CDC* pdc, Gdiplus::Graphics* gLayers, const CRe { CDC *tmpBackbuffer = new CDC(); CRect tmpRcBounds = new CRect(); - Extent tmpExtent, saveExtent; + Extent tmpExtent, saveExtent; long save_viewWidth, save_viewHeight; if (_rotate == NULL) @@ -1497,9 +1497,9 @@ int* CMapView::PlaceLabels(const CRect& rcBounds, Gdiplus::Graphics* graphics, b // clear extents of drawn labels and charts this->ClearLabelFrames(); - long endcondition = _activeLayers.size(); + long endCondition = static_cast(_activeLayers.size()); // nothing to draw - if (endcondition == 0) + if (endCondition == 0) return nullptr; register int i; @@ -1511,15 +1511,15 @@ int* CMapView::PlaceLabels(const CRect& rcBounds, Gdiplus::Graphics* graphics, b // Check whether some layers are completely concealed by images // no need to draw them then // ------------------------------------------------------------------ - bool* isConcealed = new bool[endcondition]; - memset(isConcealed, 0, endcondition * sizeof(bool)); + bool* isConcealed = new bool[endCondition]; + memset(isConcealed, 0, endCondition * sizeof(bool)); double scale = GetCurrentScale(); int zoom; _tiles->get_CurrentZoom(&zoom); if (layerBuffer) - CheckForConcealedImages(isConcealed, startcondition, endcondition, scale, zoom); + CheckForConcealedImages(isConcealed, startcondition, endCondition, scale, zoom); double currentScale = this->GetCurrentScale(); @@ -1538,12 +1538,12 @@ int* CMapView::PlaceLabels(const CRect& rcBounds, Gdiplus::Graphics* graphics, b CLabelDrawer lblDrawer(graphics, &_extents, _pixelPerProjectionX, _pixelPerProjectionY, currentScale, _currentZoom, chosenListLabels, _rotateAngle, _isSnapshot); // mark all shapes as not drawn - for (int i = startcondition; i < endcondition; i++) + for (int i = startcondition; i < endCondition; i++) { Layer* l = _allLayers[_activeLayers[i]]; if (l->IsShapefile() && l->wasRendered) // if it's hidden don't clear every time { - CComPtr sf = NULL; + CComPtr sf = nullptr; // don't mark as 'undrawn' if we're not going to redraw it if (l->QueryShapefile(&sf) && ShapefileHelper::IsVolatile(sf) != layerBuffer) { @@ -1554,7 +1554,7 @@ int* CMapView::PlaceLabels(const CRect& rcBounds, Gdiplus::Graphics* graphics, b // run drawing int shapeCount = 0; - for (int i = startcondition; i < endcondition; i++) + for (int i = startcondition; i < endCondition; i++) { long layerHandle = _activeLayers[i]; Layer* l = _allLayers[layerHandle]; @@ -1574,7 +1574,7 @@ int* CMapView::PlaceLabels(const CRect& rcBounds, Gdiplus::Graphics* graphics, b else if (l->IsShapefile() || l->IsDynamicOgrLayer()) { - CComPtr sf = NULL; + CComPtr sf = nullptr; if (l->IsDynamicOgrLayer()) { // Try to get the data loaded so far & update labels & categories @@ -1613,8 +1613,9 @@ int* CMapView::PlaceLabels(const CRect& rcBounds, Gdiplus::Graphics* graphics, b if (!layerBuffer && shapeCount > _shapeCountInView) _shapeCountInView = shapeCount; + int* ret = nullptr; // drawing labels and charts above the layers - for (i = 0; i < (int)_activeLayers.size(); i++) + for (i = 0; i < static_cast(_activeLayers.size()); i++) { Layer* l = _allLayers[_activeLayers[i]]; @@ -1622,18 +1623,20 @@ int* CMapView::PlaceLabels(const CRect& rcBounds, Gdiplus::Graphics* graphics, b if (!l->IsVisible(scale, zoom)) continue; - CComPtr sf = NULL; + CComPtr sf = nullptr; if (l->QueryShapefile(&sf) && ShapefileHelper::IsVolatile(sf) == layerBuffer) continue; //LayerDrawer::DrawLabels(l, lblDrawer, vpAboveAllLayers); - auto ret = LayerDrawer::PlaceLabels(l, lblDrawer, vpAboveAllLayers); + ret = LayerDrawer::PlaceLabels(l, lblDrawer, vpAboveAllLayers); //LayerDrawer::DrawCharts(l, chartDrawer, vpAboveAllLayers); } if (isConcealed) delete[] isConcealed; + + return ret; } diff --git a/src/MapControl/Map_DrawingLayer.cpp b/src/MapControl/Map_DrawingLayer.cpp index 23215868..8b1b13b3 100644 --- a/src/MapControl/Map_DrawingLayer.cpp +++ b/src/MapControl/Map_DrawingLayer.cpp @@ -12,7 +12,7 @@ // *************************************************************** bool CMapView::IsValidDrawList(long listHandle) { - if (listHandle >= 0 && listHandle < (long)_allDrawLists.size()) + if (listHandle >= 0 && listHandle < static_cast(_allDrawLists.size())) { return _allDrawLists[listHandle] != nullptr; } @@ -357,13 +357,13 @@ void CMapView::DrawCircleOnGraphics(Gdiplus::Graphics* graphics, _DrawCircle* ci { auto color = Utility::OleColor2GdiPlus(circle->color, circle->alpha); - auto radius = (float)circle->radius; + auto radius = static_cast(circle->radius); if (project) radius *= static_cast(_pixelPerProjectionX); - auto width = (float)circle->width; + auto width = static_cast(circle->width); - Gdiplus::REAL pixX = (float)circle->x; - Gdiplus::REAL pixY = (float)circle->y; + Gdiplus::REAL pixX = static_cast(circle->x); + Gdiplus::REAL pixY = static_cast(circle->y); if (project) PROJECTION_TO_PIXEL(pixX, pixY, pixX, pixY); pixX -= radius; @@ -389,7 +389,7 @@ void CMapView::DrawPolygonOnGraphics(Gdiplus::Graphics* graphics, _DrawPolygon* Gdiplus::Point* pnts = new Gdiplus::Point[polygon->numPoints]; long pointCount = polygon->numPoints; - auto width = (float)polygon->width; + auto width = static_cast(polygon->width); auto color = Utility::OleColor2GdiPlus(polygon->color, polygon->alpha); for (int j = 0; j < pointCount; j++) @@ -407,12 +407,12 @@ void CMapView::DrawPolygonOnGraphics(Gdiplus::Graphics* graphics, _DrawPolygon* if (polygon->fill) { Gdiplus::SolidBrush brush(color); - graphics->FillPolygon(&brush, pnts, (INT)pointCount); + graphics->FillPolygon(&brush, pnts, static_cast(pointCount)); } else { Gdiplus::Pen pen(color, width); - graphics->DrawPolygon(&pen, pnts, (INT)pointCount); + graphics->DrawPolygon(&pen, pnts, static_cast(pointCount)); } delete[] pnts; @@ -420,7 +420,7 @@ void CMapView::DrawPolygonOnGraphics(Gdiplus::Graphics* graphics, _DrawPolygon* void CMapView::DrawLineOnGraphics(Gdiplus::Graphics* graphics, _DrawLine* line, bool project) { - auto width = (float)line->width; + auto width = static_cast(line->width); auto color = Utility::OleColor2GdiPlus(line->color, line->alpha); Gdiplus::Point* pnts = new Gdiplus::Point[2]; @@ -482,7 +482,7 @@ void CMapView::ClearDrawing(long Drawing) if (IsValidDrawList(Drawing)) { - long endcondition = _activeDrawLists.size(); + long endcondition = static_cast(_activeDrawLists.size()); for (int i = 0; i < endcondition; i++) { if (_activeDrawLists[i] == Drawing) @@ -522,7 +522,7 @@ LONG CMapView::DrawLabel(LPCTSTR text, DOUBLE x, DOUBLE y, DOUBLE rotation) // *************************************************************** LONG CMapView::DrawLabelEx(LONG drawHandle, LPCTSTR text, DOUBLE x, DOUBLE y, DOUBLE rotation) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (IsValidDrawList(drawHandle)) { if (_allDrawLists[drawHandle]->m_labels) @@ -611,7 +611,7 @@ void CMapView::ClearDrawings() { _currentDrawing = -1; - long endcondition = _allDrawLists.size(); + long endcondition = static_cast(_allDrawLists.size()); for (int i = 0; i < endcondition; i++) { if (IsValidDrawList(i)) @@ -628,12 +628,12 @@ void CMapView::ClearDrawings() long CMapView::NewDrawing(short projection) { DrawList* dlist = new DrawList(); - dlist->listType = (tkDrawReferenceList)projection; + dlist->listType = static_cast(projection); bool inserted = false; long drawHandle = -1; register int i; - long endcondition = _allDrawLists.size(); + long endcondition = static_cast(_allDrawLists.size()); for (i = 0; i < endcondition && !inserted; i++) { if (_allDrawLists[i] == nullptr) @@ -645,7 +645,7 @@ long CMapView::NewDrawing(short projection) } if (inserted == false) { - drawHandle = _allDrawLists.size(); + drawHandle = static_cast(_allDrawLists.size()); _allDrawLists.push_back(dlist); } @@ -754,8 +754,8 @@ void CMapView::DrawPolygon(VARIANT* xPoints, VARIANT* yPoints, long numPoints, O USES_CONVERSION; SAFEARRAY* sax = *xPoints->pparray; SAFEARRAY* say = *yPoints->pparray; - double* xPts = (double*)sax->pvData; - double* yPts = (double*)say->pvData; + double* xPts = static_cast(sax->pvData); + double* yPts = static_cast(say->pvData); if (IsValidDrawList(_currentDrawing)) { @@ -793,8 +793,8 @@ void CMapView::DrawWidePolygon(VARIANT* xPoints, VARIANT* yPoints, long numPoint USES_CONVERSION; SAFEARRAY* sax = *xPoints->pparray; SAFEARRAY* say = *yPoints->pparray; - double* xPts = (double*)sax->pvData; - double* yPts = (double*)say->pvData; + double* xPts = static_cast(sax->pvData); + double* yPts = static_cast(say->pvData); if (IsValidDrawList(_currentDrawing)) { @@ -828,7 +828,7 @@ void CMapView::DrawWidePolygon(VARIANT* xPoints, VARIANT* yPoints, long numPoint // ***************************************************************** void CMapView::DrawWideCircleEx(LONG layerHandle, double x, double y, double radius, OLE_COLOR color, VARIANT_BOOL fill, short outlineWidth, BYTE alpha) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) long oldCurrentLayer = this->_currentDrawing; //Save the current layer for restore this->_currentDrawing = layerHandle; this->DrawWideCircle(x, y, radius, color, fill, outlineWidth, alpha); @@ -840,7 +840,7 @@ void CMapView::DrawWideCircleEx(LONG layerHandle, double x, double y, double rad // *********************************************************** void CMapView::DrawWidePolygonEx(LONG layerHandle, VARIANT* xPoints, VARIANT* yPoints, long numPoints, OLE_COLOR color, VARIANT_BOOL fill, short outlineWidth, BYTE alpha) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) long oldCurrentLayer = this->_currentDrawing; //Save the current layer for restore this->_currentDrawing = layerHandle; this->DrawWidePolygon(xPoints, yPoints, numPoints, color, fill, outlineWidth, alpha); @@ -852,7 +852,7 @@ void CMapView::DrawWidePolygonEx(LONG layerHandle, VARIANT* xPoints, VARIANT* yP // ***************************************************************** void CMapView::DrawLineEx(LONG LayerHandle, DOUBLE x1, DOUBLE y1, DOUBLE x2, DOUBLE y2, LONG pixelWidth, OLE_COLOR color, BYTE alpha) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) long oldCurrentLayer = this->_currentDrawing;//Save the current layer for restore this->_currentDrawing = LayerHandle; @@ -866,7 +866,7 @@ void CMapView::DrawLineEx(LONG LayerHandle, DOUBLE x1, DOUBLE y1, DOUBLE x2, DOU // ***************************************************************** void CMapView::DrawPointEx(LONG layerHandle, DOUBLE x, DOUBLE y, LONG pixelSize, OLE_COLOR color, BYTE alpha) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) long oldCurrentLayer = this->_currentDrawing;//Save the current layer for restore this->_currentDrawing = layerHandle; @@ -880,7 +880,7 @@ void CMapView::DrawPointEx(LONG layerHandle, DOUBLE x, DOUBLE y, LONG pixelSize, // ***************************************************************** void CMapView::DrawCircleEx(LONG layerHandle, DOUBLE x, DOUBLE y, DOUBLE pixelRadius, OLE_COLOR color, VARIANT_BOOL fill, BYTE alpha) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) long oldCurrentLayer = this->_currentDrawing;//Save the current layer for restore this->_currentDrawing = layerHandle; @@ -893,7 +893,7 @@ void CMapView::DrawCircleEx(LONG layerHandle, DOUBLE x, DOUBLE y, DOUBLE pixelRa // ***************************************************************** void CMapView::DrawPolygonEx(LONG layerHandle, VARIANT* xPoints, VARIANT* yPoints, LONG numPoints, OLE_COLOR color, VARIANT_BOOL fill, BYTE alpha) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) long oldCurrentLayer = this->_currentDrawing;//Save the current layer for restore this->_currentDrawing = layerHandle; @@ -906,7 +906,7 @@ void CMapView::DrawPolygonEx(LONG layerHandle, VARIANT* xPoints, VARIANT* yPoint // ***************************************************************** void CMapView::SetDrawingLayerVisible(LONG layerHandle, VARIANT_BOOL visible) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!visible) { @@ -972,7 +972,7 @@ void CMapView::SetDrawingKey(long DrawHandle, LPCTSTR lpszNewValue) // Access for CLabels class ILabels* CMapView::GetDrawingLabels(long DrawingLayerIndex) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (IsValidDrawList(DrawingLayerIndex)) { _allDrawLists[DrawingLayerIndex]->m_labels->AddRef(); @@ -992,7 +992,7 @@ ILabels* CMapView::GetDrawingLabels(long DrawingLayerIndex) // Setting new CLabels class void CMapView::SetDrawingLabels(long DrawingLayerIndex, ILabels* newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal == nullptr) { ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); @@ -1033,7 +1033,7 @@ IPlacedLabels* CMapView::PlaceAllMapLabels(long layerHandle) ComHelper::CreateInstance(idPlacedLabels, (IDispatch**)&placedLabels); auto indexes = array.data(); - placedLabels->SetVector(indexes, array.size()); + placedLabels->SetVector(indexes, static_cast(array.size())); return placedLabels; } diff --git a/src/MapControl/Map_Events.cpp b/src/MapControl/Map_Events.cpp index 7b072f3f..5d7d6531 100644 --- a/src/MapControl/Map_Events.cpp +++ b/src/MapControl/Map_Events.cpp @@ -93,7 +93,7 @@ void CMapView::TurnOffPanning() // *************************************************************** bool CMapView::UndoCore(bool shift) { - if (EditorHelper::IsDigitizingCursor((tkCursorMode)m_cursorMode)) + if (EditorHelper::IsDigitizingCursor(static_cast(m_cursorMode))) { VARIANT_BOOL result = VARIANT_FALSE; _shapeEditor->UndoPoint(&result); @@ -135,7 +135,7 @@ void CMapView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) double dx = (this->_extents.right - this->_extents.left)/4.0; double dy = (this->_extents.top - this->_extents.bottom)/4.0; - CComPtr box = NULL; + CComPtr box = nullptr; bool arrows = nChar == VK_LEFT || nChar == VK_RIGHT || nChar == VK_UP || nChar == VK_DOWN; if (arrows) ComHelper::CreateExtents(&box); @@ -179,7 +179,7 @@ void CMapView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) _measuringPersistent = vb ? true: false; _measuring->put_Persistent(VARIANT_TRUE); } - _lastCursorMode = (tkCursorMode)m_cursorMode; + _lastCursorMode = static_cast(m_cursorMode); UpdateCursor(cmPan, false); } else @@ -244,7 +244,7 @@ void CMapView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) if (_activeLayers.size() > 0) { if (_activeLayerPosition < 0) { - _activeLayerPosition = _activeLayers.size() - 1; + _activeLayerPosition = static_cast(_activeLayers.size()) - 1; } int handle = GetLayerHandle(_activeLayerPosition); ZoomToLayer(handle); @@ -262,7 +262,7 @@ void CMapView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) _activeLayerPosition++; if (_activeLayers.size() > 0) { - if (_activeLayerPosition >= (int)_activeLayers.size()) { + if (_activeLayerPosition >= static_cast(_activeLayers.size())) { _activeLayerPosition = 0; } int handle = GetLayerHandle(_activeLayerPosition); @@ -323,14 +323,14 @@ BOOL CMapView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) _rotate->getOriginalPixelPoint(curMousePt.x, curMousePt.y, &(origMousePt.x), &(origMousePt.y)); PixelToProj((double)(origMousePt.x), (double)(origMousePt.y), &xCent, &yCent); - dx = (double)(origMousePt.x) / (double)(rect.right - rect.left); - dy = (double)(origMousePt.y) / (double)(rect.bottom - rect.top); + dx = static_cast(origMousePt.x) / static_cast(rect.right - rect.left); + dy = static_cast(origMousePt.y) / static_cast(rect.bottom - rect.top); } else { PixelToProj((double)(pt.x - rect.left), (double)(pt.y - rect.top), &xCent, &yCent); - dx = (double)(pt.x - rect.left) / (rect.right - rect.left); - dy = (double)(pt.y - rect.top) / (rect.bottom - rect.top); + dx = static_cast(pt.x - rect.left) / (rect.right - rect.left); + dy = static_cast(pt.y - rect.top) / (rect.bottom - rect.top); } // make sure that we have enough momentum to reach the next tile level @@ -406,7 +406,7 @@ bool CMapView::HandleOnZoombarMouseDown( CPoint point ) case ZoombarPart::ZoombarBar: { double ratio = _zoombarParts.GetRelativeZoomFromClick(point.y); - int zoom = (int)(minZoom + (maxZoom - minZoom) * ratio + 0.5); + int zoom = static_cast(minZoom + (maxZoom - minZoom) * ratio + 0.5); ZoomToTileLevel(zoom); return true; } @@ -446,12 +446,12 @@ bool CMapView::HandleOnCopyrighMouseDown(CPoint point) tkTileProvider provider = GetTileProvider(); if (provider != tkTileProvider::ProviderNone && _transformationMode != tmNotDefined) { - CComPtr providers = NULL; + CComPtr providers = nullptr; _tiles->get_Providers(&providers); - CString s = ((CTileProviders*)&(*providers))->get_LicenseUrl(provider); + CString s = static_cast(&(*providers))->get_LicenseUrl(provider); _copyrightLinkActive = false; RedrawCore(tkRedrawType::RedrawSkipDataLayers, true); - ShellExecute(0, NULL, s, NULL, NULL, SW_SHOWDEFAULT); + ShellExecute(0, nullptr, s, nullptr, nullptr, SW_SHOWDEFAULT); return true; } } @@ -570,7 +570,7 @@ void CMapView::OnLButtonDown(UINT nFlags, CPoint point) case cmEditShape: { if (m_sendMouseDown == TRUE) - this->FireMouseDown(MK_LBUTTON, (short)vbflags, x, y); + this->FireMouseDown(MK_LBUTTON, static_cast(vbflags), x, y); if (!VertexEditor::OnMouseDown(this, _shapeEditor, projX, projY, ctrl, shift)) { long layerHandle, shapeIndex; @@ -619,7 +619,7 @@ void CMapView::OnLButtonDown(UINT nFlags, CPoint point) HandleOnLButtonMoveOrRotate(x, y); break; } - + case cmZoomIn: { this->SetCapture(); @@ -634,9 +634,7 @@ void CMapView::OnLButtonDown(UINT nFlags, CPoint point) break; case cmZoomOut: { - //ZoomToCursorPosition(false); - this->SetCapture(); - _dragging.Operation = DragZoombox; + ZoomToCursorPosition(false); break; } case cmPan: @@ -658,7 +656,7 @@ void CMapView::OnLButtonDown(UINT nFlags, CPoint point) if (added) { FireMeasuringChanged(tkMeasuringAction::PointAdded); - if( m_sendMouseDown ) this->FireMouseDown( MK_LBUTTON, (short)vbflags, x, y ); + if( m_sendMouseDown ) this->FireMouseDown( MK_LBUTTON, static_cast(vbflags), x, y ); RedrawCore(RedrawSkipDataLayers, true); } } @@ -668,7 +666,7 @@ void CMapView::OnLButtonDown(UINT nFlags, CPoint point) { SetCapture(); if( m_sendMouseDown == TRUE ) - this->FireMouseDown(MK_LBUTTON, (short)vbflags, x, y); + this->FireMouseDown(MK_LBUTTON, static_cast(vbflags), x, y); } break; } @@ -802,7 +800,7 @@ void CMapView::OnLButtonUp(UINT nFlags, CPoint point) // in case of selection mouse down event will be triggered in this function (to preserve backward compatibility); // so mouse up should be further on to preserve at least some logic if (m_sendMouseUp && _leftButtonDown) - FireMouseUp(MK_LBUTTON, (short)vbflags, point.x, point.y); + FireMouseUp(MK_LBUTTON, static_cast(vbflags), point.x, point.y); _leftButtonDown = FALSE; } @@ -878,7 +876,7 @@ void CMapView::ZoomToCursorPosition(bool zoomIn) double xCent, yCent, dx, dy; // pt is screen position, and we need the position within the map rectangle - PixelToProj((double)(pt.x - rect.left), (double)(pt.y - rect.top), &xCent, &yCent); + PixelToProj(pt.x - rect.left, pt.y - rect.top, &xCent, &yCent); // if we are recentering the map... if (GetRecenterMapOnZoom()) @@ -892,8 +890,8 @@ void CMapView::ZoomToCursorPosition(bool zoomIn) { // dx and dy represent the mouse position as a percent of the screen; // maintain the current screen position as a percent - dx = (double)(pt.x - rect.left) / (rect.right - rect.left); - dy = (double)(pt.y - rect.top) / (rect.bottom - rect.top); + dx = static_cast(pt.x - rect.left) / (rect.right - rect.left); + dy = static_cast(pt.y - rect.top) / (rect.bottom - rect.top); } double ratio; @@ -933,7 +931,7 @@ void CMapView::HandleLButtonUpZoomBox(long vbflags, long x, long y) bool ctrl = vbflags & 2 ? true : false; long layerHandle = -1; bool selectingSelectable = false; - CComPtr sf = NULL; + CComPtr sf = nullptr; if (m_cursorMode == cmSelection) { @@ -1044,7 +1042,7 @@ void CMapView::HandleLButtonUpZoomBox(long vbflags, long x, long y) { if (m_sendMouseDown) { - this->FireMouseDown(MK_LBUTTON, (short)vbflags, x, y); + this->FireMouseDown(MK_LBUTTON, static_cast(vbflags), x, y); } } // if at least one layer had a selection, fire event when all layers are done @@ -1059,7 +1057,7 @@ void CMapView::HandleLButtonUpZoomBox(long vbflags, long x, long y) else if (m_sendMouseDown) { // we get here if layer handle was specified in ChooseLayer, but handle was invalid - this->FireMouseDown(MK_LBUTTON, (short)vbflags, x, y); + this->FireMouseDown(MK_LBUTTON, static_cast(vbflags), x, y); } break; } @@ -1087,9 +1085,6 @@ void CMapView::HandleLButtonUpZoomBox(long vbflags, long x, long y) case cmZoomIn: SetNewExtentsWithForcedZooming(box, true); break; - case cmZoomOut: - SetNewExtentsWithZoomOut(box); - break; case cmSelection: if (sf) { @@ -1195,9 +1190,9 @@ void CMapView::DisplayPanningInertia( CPoint point ) if (size > 1 ) { DWORD minTime = timeNow - normalInterval; - int firstIndex = size - 2; + int firstIndex = static_cast(size) - 2; - for(int i = size - 1; i >= 0; i--) + for(int i = static_cast(size) - 1; i >= 0; i--) { if (_panningList[i]->time < minTime) { @@ -1222,8 +1217,8 @@ void CMapView::DisplayPanningInertia( CPoint point ) if (inertia) { // for small map the same inertia is perceived as being faster - double coeff = 1.5 + (_viewWidth * _viewHeight) / 1e6 * 0.7; - double ratio = normalInterval / (double)interval * coeff; + double coeff = 1.5 + (_viewWidth * _viewHeight) / 1e6 * 0.7; + double ratio = normalInterval / static_cast(interval) * coeff; dx *= ratio; dy *= ratio; @@ -1254,11 +1249,11 @@ void CMapView::DisplayPanningInertia( CPoint point ) MSG msg; // remove all key down, so that pressed TAB won't be processed after the end of animation - if (::PeekMessage(&msg, NULL, WM_KEYDOWN, WM_KEYDOWN, PM_NOREMOVE )) + if (::PeekMessage(&msg, nullptr, WM_KEYDOWN, WM_KEYDOWN, PM_NOREMOVE )) break; // let user stop animation with left button click - if (::PeekMessage(&msg, NULL, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_NOREMOVE )) + if (::PeekMessage(&msg, nullptr, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_NOREMOVE )) break; } _panningAnimation = false; @@ -1348,7 +1343,7 @@ void CMapView::OnMouseMove(UINT nFlags, CPoint point) } else { - this->FireMouseMove( (short)mbutton, (short)vbflags, point.x, point.y ); + this->FireMouseMove( static_cast(mbutton), static_cast(vbflags), point.x, point.y ); } } @@ -1361,7 +1356,7 @@ void CMapView::OnMouseMove(UINT nFlags, CPoint point) bool updateHotTracking = true; bool refreshNeeded = _dragging.Operation != DragNone; - if ((EditorHelper::IsDigitizingCursor((tkCursorMode)m_cursorMode) || m_cursorMode == cmMeasure)) + if ((EditorHelper::IsDigitizingCursor(static_cast(m_cursorMode)) || m_cursorMode == cmMeasure)) { ActiveShape* shp = GetActiveShape(); @@ -1528,7 +1523,7 @@ void CMapView::OnRButtonDown(UINT nFlags, CPoint point) long vbflags = ParseKeyboardEventFlags(nFlags); if( m_sendMouseDown == TRUE ) - this->FireMouseDown( MK_RBUTTON, (short)vbflags, point.x, point.y ); + this->FireMouseDown( MK_RBUTTON, static_cast(vbflags), point.x, point.y ); if (_doTrapRMouseDown) { @@ -1573,7 +1568,7 @@ void CMapView::OnRButtonUp(UINT nFlags, CPoint point) long vbflags = ParseKeyboardEventFlags(nFlags); if( m_sendMouseUp == TRUE ) - this->FireMouseUp( MK_RBUTTON, (short)vbflags, point.x, point.y ); + this->FireMouseUp( MK_RBUTTON, static_cast(vbflags), point.x, point.y ); } // ********************************************************* @@ -1628,7 +1623,7 @@ void CMapView::OnSize(UINT nType, int cx, int cy) { _viewWidth = cx; _viewHeight = cy; - _aspectRatio = (double)_viewWidth/(double)_viewHeight; + _aspectRatio = static_cast(_viewWidth)/static_cast(_viewHeight); _isSizing = false; SetExtentsCore(_extents, false, true); @@ -1648,12 +1643,12 @@ void CMapView::OnSize(UINT nType, int cx, int cy) // ******************************************************* void CMapView::OnDropFiles(HDROP hDropInfo) { - long numFiles = DragQueryFile( hDropInfo, 0xFFFFFFFF, NULL, 0 ); + long numFiles = DragQueryFile( hDropInfo, 0xFFFFFFFF, nullptr, 0 ); register int i; for( i = 0; i < numFiles; i++ ) { - long fsize = DragQueryFile( hDropInfo, i, NULL, 0 ); + long fsize = DragQueryFile( hDropInfo, i, nullptr, 0 ); if( fsize > 0 ) { char * fname = new char[fsize + 2]; DragQueryFile( hDropInfo, i, fname, fsize + 1 ); diff --git a/src/MapControl/Map_Identifier.cpp b/src/MapControl/Map_Identifier.cpp index 09c5db7a..bbe30005 100644 --- a/src/MapControl/Map_Identifier.cpp +++ b/src/MapControl/Map_Identifier.cpp @@ -85,7 +85,7 @@ VARIANT_BOOL CMapView::DefaultSnappingAlgorithm(double maxDist, double minDist, VARIANT_BOOL result = VARIANT_FALSE; // Determine which layer(s) to snap to: - bool digitizing = EditorHelper::IsDigitizingCursor((tkCursorMode)m_cursorMode); + bool digitizing = EditorHelper::IsDigitizingCursor(static_cast(m_cursorMode)); tkLayerSelection behavior; _shapeEditor->get_SnapBehavior(&behavior); tkSnapMode mode; @@ -109,7 +109,7 @@ VARIANT_BOOL CMapView::DefaultSnappingAlgorithm(double maxDist, double minDist, continue; // Get shapefile - CComPtr sf = NULL; + CComPtr sf = nullptr; sf.Attach(this->GetShapefile(layerHandle)); if (!sf) continue; @@ -133,7 +133,7 @@ VARIANT_BOOL CMapView::DefaultSnappingAlgorithm(double maxDist, double minDist, sf->GetClosestVertex(x, y, maxDist, &shapeIndex, &pointIndex, &distance, &vb); if (vb && distance < minDist) { - IShape* shape = NULL; + IShape* shape = nullptr; sf->get_Shape(shapeIndex, &shape); if (shape) { @@ -193,8 +193,8 @@ bool CMapView::SelectLayerHandles(LayerSelector selector, std::vector& laye } } - IShapefile * sf = NULL; - for (int i = 0; i < (int)_activeLayers.size(); i++) + IShapefile * sf = nullptr; + for (int i = 0; i < static_cast(_activeLayers.size()); i++) { int handle = GetLayerHandle(i); bool result = CheckLayer(selector, handle); @@ -259,7 +259,7 @@ bool CMapView::CheckShapefileLayer(LayerSelector selector, int layerHandle, ISha result = VARIANT_TRUE; } else if ((!editorEmpty && m_cursorMode == cmEditShape) || - EditorHelper::IsDigitizingCursor((tkCursorMode)m_cursorMode)) + EditorHelper::IsDigitizingCursor(static_cast(m_cursorMode))) { // highlight vertices for easier snapping switch (highlighting) { @@ -290,7 +290,7 @@ bool CMapView::CheckShapefileLayer(LayerSelector selector, int layerHandle, ISha // ************************************************************ bool CMapView::CheckLayer(LayerSelector selector, int layerHandle) { - CComPtr sf = NULL; + CComPtr sf = nullptr; Layer* layer = GetLayer(layerHandle); if (!layer || !layer->wasRendered) return false; @@ -304,7 +304,7 @@ bool CMapView::CheckLayer(LayerSelector selector, int layerHandle) } else if (layer->IsImage()) { - // it's raster + // it's raster switch (selector) { case slctIdentify: @@ -352,9 +352,9 @@ bool CMapView::DrillDownSelect(double projX, double projY, long& layerHandle, lo { vector handles; SelectLayerHandles(slctIdentify, handles); - for (int i = handles.size() - 1; i >= 0; i--) + for (long i = static_cast(handles.size()) - 1; i >= 0; i--) { - CComPtr sf = NULL; + CComPtr sf = nullptr; sf.Attach(GetShapefile(handles[i])); if (sf) { Extent box = GetPointSelectionBox(sf, projX, projY); @@ -379,7 +379,7 @@ bool CMapView::DrillDownSelect(double projX, double projY, ISelectionList* list, vector results; - for (int i = handles.size() - 1; i >= 0; i--) + for (int i = static_cast(handles.size()) - 1; i >= 0; i--) { Layer* layer = GetLayer(handles[i]); @@ -400,7 +400,7 @@ bool CMapView::DrillDownSelect(double projX, double projY, ISelectionList* list, if (layer->IsShapefile()) { - CComPtr sf = NULL; + CComPtr sf = nullptr; sf.Attach(GetShapefile(handles[i])); if (sf) @@ -430,7 +430,7 @@ bool CMapView::DrillDownSelect(double projX, double projY, ISelectionList* list, } else if (layer->IsImage()) { - CComPtr img = NULL; + CComPtr img = nullptr; img.Attach(GetImage(handles[i])); if (img) { @@ -475,10 +475,10 @@ LayerShape CMapView::FindShapeAtScreenPoint(CPoint point, LayerSelector selector // ************************************************************ LayerShape CMapView::FindShapeAtProjPoint(double prjX, double prjY, std::vector& layers) { - IShapefile * sf = NULL; - for (int i = (int)layers.size() - 1; i >= 0; i--) + IShapefile * sf = nullptr; + for (int i = static_cast(layers.size()) - 1; i >= 0; i--) { - CComPtr sf = NULL; + CComPtr sf = nullptr; sf.Attach(GetShapefile(layers[i])); if (sf) { double tol = 0.0; @@ -519,7 +519,7 @@ bool CMapView::SelectShapeForEditing(int x, int y, long& layerHandle, long& shap // ************************************************************ HotTrackingResult CMapView::RecalcHotTracking(CPoint point, LayerShape& result) { - bool cursorCheck = EditorHelper::IsSnappableCursor((tkCursorMode)m_cursorMode) || m_cursorMode == cmEditShape || m_cursorMode == cmIdentify; + bool cursorCheck = EditorHelper::IsSnappableCursor(static_cast(m_cursorMode)) || m_cursorMode == cmEditShape || m_cursorMode == cmIdentify; if (!cursorCheck) return NoShape; if (_shapeCountInView < m_globalSettings.hotTrackingMaxShapeCount && HasHotTracking()) @@ -550,21 +550,21 @@ void CMapView::ClearHotTracking() // ************************************************************ void CMapView::UpdateHotTracking(LayerShape info, bool fireEvent) { - CComPtr sf = NULL; + CComPtr sf = nullptr; sf.Attach(GetShapefile(info.LayerHandle)); if (sf) { - CComPtr shape = NULL; + CComPtr shape = nullptr; sf->get_Shape(info.ShapeIndex, &shape); if (shape) { - CComPtr shpClone = NULL; + CComPtr shpClone = nullptr; shape->Clone(&shpClone); _hotTracking.Update(sf, shpClone, info.LayerHandle, info.ShapeIndex); OLE_COLOR color; _identifier->get_OutlineColor(&color); - CComPtr options = NULL; + CComPtr options = nullptr; options.Attach(ShapeStyleHelper::GetHotTrackingStyle(sf, color, m_cursorMode == cmIdentify)); if (options) { _hotTracking.UpdateStyle(options); diff --git a/src/MapControl/Map_ImageGrouping.cpp b/src/MapControl/Map_ImageGrouping.cpp index 369665b7..74206b33 100644 --- a/src/MapControl/Map_ImageGrouping.cpp +++ b/src/MapControl/Map_ImageGrouping.cpp @@ -16,14 +16,14 @@ void CMapView::BuildImageGroups(std::vector& imageGroups) for(size_t i = 0; i < _activeLayers.size(); i++) { Layer * l = _allLayers[_activeLayers[i]]; - if( l != NULL ) + if( l != nullptr) { if(l->IsImage()) { - IImage* iimg = NULL; + IImage* iimg = nullptr; if (l->QueryImage(&iimg)) { - CImageClass* img = (CImageClass*)iimg; + CImageClass* img = static_cast(iimg); img->m_groupID = -1; if (l->get_Visible()) @@ -59,7 +59,7 @@ void CMapView::BuildImageGroups(std::vector& imageGroups) (group->yllCenter == yllCenter)) { groupFound = true; - group->imageIndices.push_back(i); + group->imageIndices.push_back(static_cast(i)); break; } } @@ -69,7 +69,7 @@ void CMapView::BuildImageGroups(std::vector& imageGroups) // adding new group ImageGroup* group = new ImageGroup(dx, dy, xllCenter, yllCenter, width, height); imageGroups.push_back(group); - imageGroups[imageGroups.size() - 1]->imageIndices.push_back(i); + imageGroups[imageGroups.size() - 1]->imageIndices.push_back(static_cast(i)); } } } @@ -81,11 +81,11 @@ void CMapView::BuildImageGroups(std::vector& imageGroups) // now we'll check whether the pixels of image are scarce enough for us // the group wil work only in case there is more then 1 suitable image int groupId = 0; - IImage* iimg = NULL; + IImage* iimg = nullptr; for (size_t i = 0; i < imageGroups.size(); i++) { std::vector* indices = &imageGroups[i]->imageIndices; - int groupSize = indices->size(); + int groupSize = static_cast(indices->size()); if (groupSize > 1) { @@ -94,7 +94,7 @@ void CMapView::BuildImageGroups(std::vector& imageGroups) Layer * l = _allLayers[_activeLayers[(*indices)[j]]]; if (l->QueryImage(&iimg)) { - CImageClass* img = (CImageClass*)iimg; + CImageClass* img = static_cast(iimg); if (!img->_pixelsSaved) // it's the first time we try to draw image or transparency color chnaged { @@ -122,7 +122,7 @@ void CMapView::BuildImageGroups(std::vector& imageGroups) Layer * l = _allLayers[_activeLayers[imageIndex]]; if (l->QueryImage(&iimg)) { - CImageClass* img = (CImageClass*)iimg; + CImageClass* img = static_cast(iimg); img->m_groupID = groupId; iimg->Release(); } @@ -172,16 +172,16 @@ tkInterpolationMode CMapView::ChooseInterpolationMode(tkInterpolationMode mode1, void CMapView::DrawImageGroups(const CRect& rcBounds, Gdiplus::Graphics* graphics, int groupIndex) { CImageDrawer imgDrawer(graphics, &_extents, _pixelPerProjectionX, _pixelPerProjectionY, _viewWidth, _viewHeight); - IImage* iimg = NULL; + IImage* iimg = nullptr; ImageGroup* group = (*_imageGroups)[groupIndex]; if (! group->isValid ) return; - + // in case the image was drawn at least once at current resolution, we can use screenBitmap - ScreenBitmap* bmp = NULL; + ScreenBitmap* bmp = nullptr; bmp = group->screenBitmap; - if (bmp != NULL) + if (bmp != nullptr) { if (bmp->extents == _extents && bmp->pixelPerProjectionX == _pixelPerProjectionX && @@ -199,17 +199,17 @@ void CMapView::DrawImageGroups(const CRect& rcBounds, Gdiplus::Graphics* graphic return; } } - + double scale = GetCurrentScale(); int zoom; this->_tiles->get_CurrentZoom(&zoom); - if(group->image == NULL) + if(group->image == nullptr) { - // creating a new temporary image - IImage* imgGroup = NULL; + // creating a new temporary image + IImage* imgGroup = nullptr; VARIANT_BOOL vbretval; - CoCreateInstance(CLSID_Image,NULL,CLSCTX_INPROC_SERVER,IID_IImage,(void**)&imgGroup); + CoCreateInstance(CLSID_Image, nullptr,CLSCTX_INPROC_SERVER,IID_IImage,(void**)&imgGroup); imgGroup->CreateNew(group->width, group->height, &vbretval); if ( !vbretval ) @@ -228,23 +228,23 @@ void CMapView::DrawImageGroups(const CRect& rcBounds, Gdiplus::Graphics* graphic tkInterpolationMode upsamplingMode = imNone; // acquiring reference to the destination color array - unsigned char* data = ((CImageClass*)imgGroup)->get_ImageData(); + unsigned char* data = static_cast(imgGroup)->get_ImageData(); colour* dstData = reinterpret_cast(data); - + // passing the data from all images bool visibleLayerExists = false; - bool useTransparencyColor = true; + bool useTransparencyColor = true; for(size_t j = 0; j < _activeLayers.size(); j++) { Layer * l = _allLayers[_activeLayers[j]]; - if( l != NULL ) - { + if( l != nullptr) + { //if(l->type == ImageLayer && (l->flags & Visible)) if(l->IsImage() && l->IsVisible(scale, zoom)) { if (l->QueryImage(&iimg)) { - CImageClass* img = (CImageClass*)iimg; + CImageClass* img = static_cast(iimg); if ( img ) { @@ -254,7 +254,7 @@ void CMapView::DrawImageGroups(const CRect& rcBounds, Gdiplus::Graphics* graphic tkInterpolationMode upMode; img->get_DownsamplingMode(&downMode); img->get_UpsamplingMode(&upMode); - + // in case at least one image don't use transparency the grouped bitmap will have white background VARIANT_BOOL transp; img->get_UseTransparencyColor(&transp); @@ -284,7 +284,7 @@ void CMapView::DrawImageGroups(const CRect& rcBounds, Gdiplus::Graphics* graphic } } } - + if (useTransparencyColor) { imgGroup->put_TransparencyColor(RGB(255, 255, 255)); @@ -315,12 +315,12 @@ void CMapView::DrawImageGroups(const CRect& rcBounds, Gdiplus::Graphics* graphic bmp = imgDrawer.DrawImage(rcBounds, group->image, true); if (bmp) { - if (group->screenBitmap != NULL) + if (group->screenBitmap != nullptr) { delete group->screenBitmap; - group->screenBitmap = NULL; + group->screenBitmap = nullptr; } - + int width = bmp->bitmap->GetWidth(); int height = bmp->bitmap->GetHeight(); @@ -355,16 +355,16 @@ bool CMapView::ImageGroupsAreEqual(std::vector& groups1, std::vecto // ********************************************************* void CMapView::SetGridFileName(LONG LayerHandle, LPCTSTR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if(IS_VALID_LAYER(LayerHandle,_allLayers)) { // redirected to image class for backward compatibility IImage* img = this->GetImage(LayerHandle); - if (img != NULL) + if (img != nullptr) { USES_CONVERSION; - ((CImageClass*)img)->SetSourceGridName(A2W(newVal)); // TODO: use Unicode + static_cast(img)->SetSourceGridName(A2W(newVal)); // TODO: use Unicode img->Release(); } else @@ -393,10 +393,10 @@ void CMapView::ReloadBuffers() if (l->IsImage()) { - IImage * iimg = NULL; + IImage * iimg = nullptr; if (l->QueryImage(&iimg)) { - ((CImageClass*)iimg)->SetBufferReloadIsNeeded(); + static_cast(iimg)->SetBufferReloadIsNeeded(); iimg->Release(); } } diff --git a/src/MapControl/Map_Layer.cpp b/src/MapControl/Map_Layer.cpp index 8a8df2fd..b5fbad88 100644 --- a/src/MapControl/Map_Layer.cpp +++ b/src/MapControl/Map_Layer.cpp @@ -22,7 +22,7 @@ // ************************************************************ long CMapView::GetNumLayers() { - return _activeLayers.size(); + return static_cast(_activeLayers.size()); } // ************************************************************ @@ -30,7 +30,7 @@ long CMapView::GetNumLayers() // ************************************************************ BSTR CMapView::GetLayerName(LONG layerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (IsValidLayer(layerHandle)) { @@ -44,7 +44,7 @@ BSTR CMapView::GetLayerName(LONG layerHandle) void CMapView::SetLayerName(LONG layerHandle, LPCTSTR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (IsValidLayer(layerHandle)) { @@ -62,7 +62,7 @@ void CMapView::SetLayerName(LONG layerHandle, LPCTSTR newVal) // **************************************************** BSTR CMapView::GetLayerDescription(LONG layerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) Layer* layer = GetLayer(layerHandle); if (!layer) { @@ -78,7 +78,7 @@ BSTR CMapView::GetLayerDescription(LONG layerHandle) // **************************************************** void CMapView::SetLayerDescription(LONG layerHandle, LPCTSTR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (Layer* layer = GetLayer(layerHandle)) { layer->description = newVal; @@ -121,7 +121,7 @@ long CMapView::GetLayerPosition(long layerHandle) { if (IsValidLayer(layerHandle)) { - const long endcondition = _activeLayers.size(); + const long endcondition = static_cast(_activeLayers.size()); for (int i = 0; i < endcondition; i++) { if (_activeLayers[i] == layerHandle) @@ -141,7 +141,7 @@ long CMapView::GetLayerPosition(long layerHandle) long CMapView::GetLayerHandle(long layerPosition) { // TODO: How to cast _activeLayers.size() to long? - if (layerPosition >= 0 && layerPosition < (long)_activeLayers.size()) + if (layerPosition >= 0 && layerPosition < static_cast(_activeLayers.size())) { return _activeLayers[layerPosition]; } @@ -266,7 +266,7 @@ int CMapView::AddLayerCore(Layer* layer) { if (!_allLayers[i]) // that means we can reuse it { - layerHandle = i; + layerHandle = static_cast(i); _allLayers[i] = layer; break; } @@ -274,7 +274,7 @@ int CMapView::AddLayerCore(Layer* layer) if (layerHandle == -1) { - layerHandle = _allLayers.size(); + layerHandle = static_cast(_allLayers.size()); _allLayers.push_back(layer); } @@ -926,7 +926,7 @@ void CMapView::RemoveLayerCore(long layerHandle, bool closeDatasources, bool fro } const bool hadLayers = _activeLayers.size() > 0; - if (layerHandle >= (long)_allLayers.size()) return; // TODO: How to cast _activeLayers.size() to long? + if (layerHandle >= static_cast(_allLayers.size())) return; // TODO: How to cast _activeLayers.size() to long? Layer* l = _allLayers[layerHandle]; if (l == nullptr) return; @@ -1025,15 +1025,15 @@ void CMapView::RemoveAllLayers() // *************************************************************** BOOL CMapView::MoveLayerUp(long initialPosition) { - if (initialPosition >= 0 && initialPosition < (long)_activeLayers.size()) // TODO: How to cast _activeLayers.size() to long? + if (initialPosition >= 0 && initialPosition < static_cast(_activeLayers.size())) { const long layerHandle = _activeLayers[initialPosition]; _activeLayers.erase(_activeLayers.begin() + initialPosition); long newPos = initialPosition + 1; - if (newPos > (long)_activeLayers.size()) // TODO: How to cast _activeLayers.size() to long? - newPos = _activeLayers.size(); + if (newPos > static_cast(_activeLayers.size())) + newPos = static_cast(_activeLayers.size()); _activeLayers.insert(_activeLayers.begin() + newPos, layerHandle); @@ -1051,7 +1051,7 @@ BOOL CMapView::MoveLayerUp(long initialPosition) BOOL CMapView::MoveLayerDown(long initialPosition) { // TODO: How to cast _activeLayers.size() to long? - if (initialPosition >= 0 && initialPosition < (long)_activeLayers.size()) + if (initialPosition >= 0 && initialPosition < static_cast(_activeLayers.size())) { const long layerHandle = _activeLayers[initialPosition]; _activeLayers.erase(_activeLayers.begin() + initialPosition); @@ -1080,8 +1080,8 @@ BOOL CMapView::MoveLayer(long initialPosition, long targetPosition) return TRUE; // TODO: How to cast _activeLayers.size() to long? - if (initialPosition >= 0 && initialPosition < (long)_activeLayers.size() && - targetPosition >= 0 && targetPosition < (long)_activeLayers.size()) + if (initialPosition >= 0 && initialPosition < static_cast(_activeLayers.size()) && + targetPosition >= 0 && targetPosition < static_cast(_activeLayers.size())) { const long layerHandle = _activeLayers[initialPosition]; @@ -1103,7 +1103,7 @@ BOOL CMapView::MoveLayer(long initialPosition, long targetPosition) BOOL CMapView::MoveLayerTop(long initialPosition) { // TODO: How to cast _activeLayers.size() to long? - if (initialPosition >= 0 && initialPosition < (long)_activeLayers.size()) + if (initialPosition >= 0 && initialPosition < static_cast(_activeLayers.size())) { const long layerHandle = _activeLayers[initialPosition]; _activeLayers.erase(_activeLayers.begin() + initialPosition); @@ -1124,7 +1124,7 @@ BOOL CMapView::MoveLayerTop(long initialPosition) BOOL CMapView::MoveLayerBottom(long initialPosition) { // TODO: How to cast _activeLayers.size() to long? - if (initialPosition >= 0 && initialPosition < (long)_activeLayers.size()) + if (initialPosition >= 0 && initialPosition < static_cast(_activeLayers.size())) { const long layerHandle = _activeLayers[initialPosition]; _activeLayers.erase(_activeLayers.begin() + initialPosition); @@ -1193,7 +1193,7 @@ void CMapView::ReSourceLayer(long layerHandle, LPCTSTR newSrcPath) // *************************************************************** BOOL CMapView::ReloadOgrLayerFromSource(long ogrLayerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // get the layer from the specified handle Layer* layer = GetLayer(ogrLayerHandle); @@ -1245,7 +1245,7 @@ BOOL CMapView::ReloadOgrLayerFromSource(long ogrLayerHandle) // *************************************************************** void CMapView::RestartBackgroundLoading(long ogrLayerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // get the layer from the specified handle Layer* layer = GetLayer(ogrLayerHandle); @@ -1262,14 +1262,14 @@ void CMapView::RestartBackgroundLoading(long ogrLayerHandle) // ****************************************************************** DOUBLE CMapView::GetLayerMaxVisibleScale(LONG layerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const Layer* const layer = GetLayer(layerHandle); return layer ? layer->maxVisibleScale : 0.0; } void CMapView::SetLayerMaxVisibleScale(LONG layerHandle, DOUBLE newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (Layer* layer = GetLayer(layerHandle)) { layer->maxVisibleScale = newVal; } @@ -1280,14 +1280,14 @@ void CMapView::SetLayerMaxVisibleScale(LONG layerHandle, DOUBLE newVal) // ****************************************************************** DOUBLE CMapView::GetLayerMinVisibleScale(LONG layerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const Layer* const layer = GetLayer(layerHandle); return layer ? layer->minVisibleScale : 0.0; } void CMapView::SetLayerMinVisibleScale(LONG layerHandle, DOUBLE newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (Layer* layer = GetLayer(layerHandle)) { layer->minVisibleScale = newVal; } @@ -1298,14 +1298,14 @@ void CMapView::SetLayerMinVisibleScale(LONG layerHandle, DOUBLE newVal) // ****************************************************************** int CMapView::GetLayerMinVisibleZoom(LONG layerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const Layer* const layer = GetLayer(layerHandle); return layer ? layer->minVisibleZoom : -1; } void CMapView::SetLayerMinVisibleZoom(LONG layerHandle, int newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (Layer* layer = GetLayer(layerHandle)) { if (newVal < 0) newVal = 0; if (newVal > 18) newVal = 18; @@ -1318,14 +1318,14 @@ void CMapView::SetLayerMinVisibleZoom(LONG layerHandle, int newVal) // ****************************************************************** int CMapView::GetLayerMaxVisibleZoom(LONG layerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const Layer* const layer = GetLayer(layerHandle); return layer ? layer->maxVisibleZoom : -1; } void CMapView::SetLayerMaxVisibleZoom(LONG layerHandle, int newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (Layer* layer = GetLayer(layerHandle)) { if (newVal < 0) newVal = 0; @@ -1339,14 +1339,14 @@ void CMapView::SetLayerMaxVisibleZoom(LONG layerHandle, int newVal) // ****************************************************************** VARIANT_BOOL CMapView::GetLayerDynamicVisibility(LONG layerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const Layer* const layer = GetLayer(layerHandle); return layer ? static_cast(layer->dynamicVisibility) : VARIANT_FALSE; } void CMapView::SetLayerDynamicVisibility(LONG layerHandle, VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (Layer* layer = GetLayer(layerHandle)) { layer->dynamicVisibility = newVal ? true : false; @@ -1516,7 +1516,7 @@ int CMapView::DeserializeLayerCore(CPLXMLNode* node, CStringW projectName, bool // Filename isn't saved BSTR CMapView::SerializeLayer(LONG layerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; CString str = ""; @@ -1541,7 +1541,7 @@ CPLXMLNode* CMapView::SerializeLayerCore(LONG layerHandle, CStringW filename) USES_CONVERSION; // TODO: How to cast _activeLayers.size() to long? - if (layerHandle < 0 || layerHandle >= (long)_allLayers.size()) + if (layerHandle < 0 || layerHandle >= static_cast(_allLayers.size())) { this->ErrorMessage(tkINVALID_LAYER_HANDLE); return nullptr; @@ -1666,7 +1666,7 @@ CPLXMLNode* CMapView::SerializeLayerCore(LONG layerHandle, CStringW filename) // Restores options, but doesn't add layer VARIANT_BOOL CMapView::DeserializeLayer(LONG layerHandle, LPCTSTR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) USES_CONVERSION; const CString s = newVal; @@ -1832,12 +1832,12 @@ VARIANT_BOOL CMapView::DeserializeLayerOptionsCore(LONG layerHandle, CPLXMLNode* // ********************************************************* BSTR CMapView::GetLayerFilename(LONG layerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) BSTR filename; // TODO: How to cast _activeLayers.size() to long? - if (layerHandle < 0 || layerHandle >= (long)_allLayers.size()) + if (layerHandle < 0 || layerHandle >= static_cast(_allLayers.size())) { this->ErrorMessage(tkINVALID_LAYER_HANDLE); filename = SysAllocString(L""); @@ -1858,7 +1858,7 @@ BSTR CMapView::GetLayerFilename(LONG layerHandle) // ********************************************************* VARIANT_BOOL CMapView::RemoveLayerOptions(LONG layerHandle, LPCTSTR optionsName) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const CString name = get_OptionsFilename(layerHandle, optionsName); if (Utility::FileExists(name)) { @@ -1897,7 +1897,7 @@ CString CMapView::get_OptionsFilename(LONG layerHandle, LPCTSTR optionsName) // ********************************************************* VARIANT_BOOL CMapView::SaveLayerOptions(LONG layerHandle, LPCTSTR optionsName, VARIANT_BOOL overwrite, LPCTSTR description) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) bool result = false; if (Layer* layer = GetLayer(layerHandle)) @@ -2029,7 +2029,7 @@ VARIANT_BOOL CMapView::LoadLayerOptionsCore(CString baseName, LONG layerHandle, // ********************************************************* VARIANT_BOOL CMapView::LoadLayerOptions(LONG layerHandle, LPCTSTR optionsName, BSTR* description) { - AFX_MANAGE_STATE(AfxGetStaticModuleState());; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (Layer* l = GetLayer(layerHandle)) { @@ -2056,10 +2056,10 @@ VARIANT_BOOL CMapView::LoadLayerOptions(LONG layerHandle, LPCTSTR optionsName, B // ******************************************************* VARIANT_BOOL CMapView::GetLayerSkipOnSaving(LONG layerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: How to cast _activeLayers.size() to long? - if (layerHandle < 0 || layerHandle >= (long)_allLayers.size()) + if (layerHandle < 0 || layerHandle >= static_cast(_allLayers.size())) { this->ErrorMessage(tkINVALID_LAYER_HANDLE); return VARIANT_FALSE; @@ -2078,10 +2078,10 @@ VARIANT_BOOL CMapView::GetLayerSkipOnSaving(LONG layerHandle) // ******************************************************* void CMapView::SetLayerSkipOnSaving(LONG layerHandle, VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: How to cast _activeLayers.size() to long? - if (layerHandle < 0 || layerHandle >= (long)_allLayers.size()) + if (layerHandle < 0 || layerHandle >= static_cast(_allLayers.size())) { this->ErrorMessage(tkINVALID_LAYER_HANDLE); return; @@ -2098,7 +2098,7 @@ void CMapView::SetLayerSkipOnSaving(LONG layerHandle, VARIANT_BOOL newVal) // ******************************************************* IExtents* CMapView::GetLayerExtents(LONG layerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!IsValidLayer(layerHandle)) { diff --git a/src/MapControl/Map_Properties.cpp b/src/MapControl/Map_Properties.cpp index 539124c9..175bf3a2 100644 --- a/src/MapControl/Map_Properties.cpp +++ b/src/MapControl/Map_Properties.cpp @@ -6,7 +6,7 @@ // ******************************************************* long CMapView::HWnd() { - return (long)this->m_hWnd; + return static_cast(reinterpret_cast(this->m_hWnd)); } // ******************************************************* @@ -22,7 +22,7 @@ short CMapView::GetIsLocked() // ******************************************************* VARIANT_BOOL CMapView::GetShowVersionNumber(void) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _showVersionNumber ? VARIANT_TRUE : VARIANT_FALSE; } @@ -31,7 +31,7 @@ VARIANT_BOOL CMapView::GetShowVersionNumber(void) // ******************************************************* void CMapView::SetShowVersionNumber(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_showVersionNumber != newVal) { _showVersionNumber = newVal; @@ -44,7 +44,7 @@ void CMapView::SetShowVersionNumber(VARIANT_BOOL newVal) // ******************************************************* VARIANT_BOOL CMapView::GetShowRedrawTime(void) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _showRedrawTime ? VARIANT_TRUE : VARIANT_FALSE; } @@ -53,7 +53,7 @@ VARIANT_BOOL CMapView::GetShowRedrawTime(void) // ******************************************************* void CMapView::SetShowRedrawTime(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_showRedrawTime != newVal) { _showRedrawTime = newVal; @@ -63,48 +63,48 @@ void CMapView::SetShowRedrawTime(VARIANT_BOOL newVal) VARIANT_BOOL CMapView::GetCanUseImageGrouping() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _canUseImageGrouping ? VARIANT_TRUE : VARIANT_FALSE; } void CMapView::SetCanUseImageGrouping(VARIANT_BOOL newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _canUseImageGrouping = (newVal != VARIANT_FALSE); } short CMapView::GetMapResizeBehavior() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _mapResizeBehavior; } void CMapView::SetMapResizeBehavior(short nNewValue) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _mapResizeBehavior = (tkResizeBehavior)nNewValue; } void CMapView::SetTrapRMouseDown(BOOL nNewValue) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _doTrapRMouseDown = nNewValue; } BOOL CMapView::GetTrapRMouseDown() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _doTrapRMouseDown; } void CMapView::SetDisableWaitCursor(BOOL nNewValue) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _disableWaitCursor = nNewValue; } BOOL CMapView::GetDisableWaitCursor() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _disableWaitCursor; } @@ -117,7 +117,7 @@ ICallback* CMapView::GetGlobalCallback() void CMapView::SetGlobalCallback(ICallback* newValue) { - ICallback * cback = NULL; + ICallback * cback = nullptr; newValue->QueryInterface(IID_ICallback, (void**)&cback); if( _globalCallback ) @@ -139,14 +139,14 @@ void CMapView::SetUseSeamlessPan(BOOL newVal) BSTR CMapView::GetSerialNumber(void) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _serial.AllocSysString(); } void CMapView::SetSerialNumber(LPCTSTR newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (VerifySerial(newVal)) { @@ -159,39 +159,39 @@ void CMapView::SetSerialNumber(LPCTSTR newVal) void CMapView::SetUseAlternatePanCursor(VARIANT_BOOL nNewValue) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _useAlternatePanCursor = (nNewValue != VARIANT_FALSE); //_cursorPan = (_useAlternatePanCursor == TRUE ? AfxGetApp()->LoadCursor(IDC_PAN_ALTERNATE) : AfxGetApp()->LoadCursor(IDC_PAN)); } VARIANT_BOOL CMapView::GetUseAlternatePanCursor() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _useAlternatePanCursor ? VARIANT_TRUE : VARIANT_FALSE; } void CMapView::SetRecenterMapOnZoom(VARIANT_BOOL nNewValue) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _recenterMapOnZoom = (nNewValue != VARIANT_FALSE); } VARIANT_BOOL CMapView::GetRecenterMapOnZoom() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _recenterMapOnZoom ? VARIANT_TRUE : VARIANT_FALSE; } void CMapView::SetShowCoordinatesBackground(VARIANT_BOOL nNewValue) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - _showCoordinatesBackground = (nNewValue != VARIANT_FALSE); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + _showCoordinatesBackground = (nNewValue != VARIANT_FALSE); } VARIANT_BOOL CMapView::GetShowCoordinatesBackground() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); - return _showCoordinatesBackground ? VARIANT_TRUE : VARIANT_FALSE; + AFX_MANAGE_STATE(AfxGetStaticModuleState()) + return _showCoordinatesBackground ? VARIANT_TRUE : VARIANT_FALSE; } // *************************************************************** // @@ -216,13 +216,13 @@ void CMapView::SetMouseWheelSpeed(DOUBLE newVal) //********************************************************************* void CMapView::SetShapeDrawingMethod(short newVal) { - _shapeDrawingMethod = (tkShapeDrawingMethod)newVal; + _shapeDrawingMethod = static_cast(newVal); // generating or clearing per-shape options for(size_t i = 0; i < _activeLayers.size(); i++) { Layer * l = _allLayers[_activeLayers[i]]; - if( l != NULL ) + if( l != nullptr) { if(l->IsShapefile()) { @@ -260,7 +260,7 @@ void CMapView::SetMapRotationAngle(float nNewValue) return; _rotateAngle = nNewValue; - if (_rotate == NULL) + if (_rotate == nullptr) _rotate = new Rotate(); _rotate->setRotateAngle(_rotateAngle); } @@ -276,7 +276,7 @@ float CMapView::GetMapRotationAngle() // ****************************************************************** BSTR CMapView::GetVersionNumber(void) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_versionNumber.GetLength() == 0) _versionNumber = Utility::GetFileVersionString(); USES_CONVERSION; @@ -288,12 +288,12 @@ BSTR CMapView::GetVersionNumber(void) // ***************************************************** tkScalebarUnits CMapView::GetScalebarUnits(void) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _scalebarUnits; } void CMapView::SetScalebarUnits(tkScalebarUnits pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _scalebarUnits = pVal; if( !_lockCount ) InvalidateControl(); @@ -304,14 +304,14 @@ void CMapView::SetScalebarUnits(tkScalebarUnits pVal) // ***************************************************** void CMapView::SetScalebarVisible(VARIANT_BOOL pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _scalebarVisible = (pVal != VARIANT_FALSE); if( !_lockCount ) InvalidateControl(); } VARIANT_BOOL CMapView::GetScalebarVisible(void) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _scalebarVisible ? VARIANT_TRUE : VARIANT_FALSE; } @@ -320,7 +320,7 @@ VARIANT_BOOL CMapView::GetScalebarVisible(void) // ***************************************************** void CMapView::SetShowZoomBar(VARIANT_BOOL pVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _zoombarVisible = (pVal != VARIANT_FALSE); if( !_lockCount ) { @@ -330,7 +330,7 @@ void CMapView::SetShowZoomBar(VARIANT_BOOL pVal) } VARIANT_BOOL CMapView::GetShowZoomBar(void) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _zoombarVisible ? VARIANT_TRUE : VARIANT_FALSE; } @@ -349,7 +349,7 @@ bool CMapView::SendSelectBoxDrag() // ***************************************************** ITiles* CMapView::GetTiles(void) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _tiles->AddRef(); return _tiles; } @@ -359,7 +359,7 @@ ITiles* CMapView::GetTiles(void) // ***************************************************** IFileManager* CMapView::GetFileManager(void) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_fileManager) _fileManager->AddRef(); return _fileManager; @@ -370,7 +370,7 @@ IFileManager* CMapView::GetFileManager(void) // ***************************************************** IIdentifier* CMapView::GetIdentifier(void) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_identifier) _identifier->AddRef(); return _identifier; @@ -382,12 +382,12 @@ IIdentifier* CMapView::GetIdentifier(void) // ***************************************************** short CMapView::GetZoomBehavior() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _zoomBehavior; } void CMapView::SetZoomBehavior(short nNewValue) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _zoomBehavior = (tkZoomBehavior)nNewValue; } @@ -405,7 +405,7 @@ bool CMapView::ForceDiscreteZoom() // *************************************************************** bool CMapView::HasRotation() { - return _rotate != NULL && _rotateAngle != 0 && false; // TODO: restore, reimplement and test + return _rotate != nullptr && _rotateAngle != 0 && false; // TODO: restore, reimplement and test } // ***************************************************** @@ -413,12 +413,12 @@ bool CMapView::HasRotation() // ***************************************************** tkCustomState CMapView::GetAnimationOnZooming() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _zoomAnimation; } void CMapView::SetAnimationOnZooming(tkCustomState nNewValue) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _zoomAnimation = nNewValue; } @@ -427,12 +427,12 @@ void CMapView::SetAnimationOnZooming(tkCustomState nNewValue) // ***************************************************** tkCustomState CMapView::GetInertiaOnPanning() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _panningInertia; } void CMapView::SetInertiaOnPanning(tkCustomState nNewValue) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _panningInertia = nNewValue; } @@ -441,12 +441,12 @@ void CMapView::SetInertiaOnPanning(tkCustomState nNewValue) // ***************************************************** VARIANT_BOOL CMapView::GetReuseTileBuffer() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _reuseTileBuffer; } void CMapView::SetReuseTileBuffer(VARIANT_BOOL nNewValue) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _reuseTileBuffer = nNewValue; } @@ -455,12 +455,12 @@ void CMapView::SetReuseTileBuffer(VARIANT_BOOL nNewValue) // ***************************************************** tkZoomBarVerbosity CMapView::GetZoomBarVerbosity() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _zoomBarVerbosity; } void CMapView::SetZoomBarVerbosity(tkZoomBarVerbosity nNewValue) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _zoomBarVerbosity = nNewValue; } @@ -469,12 +469,12 @@ void CMapView::SetZoomBarVerbosity(tkZoomBarVerbosity nNewValue) // ***************************************************** tkZoomBoxStyle CMapView::GetZoomBoxStyle() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _zoomBoxStyle; } void CMapView::SetZoomBoxStyle(tkZoomBoxStyle nNewValue) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) _zoomBoxStyle = nNewValue; } @@ -483,12 +483,12 @@ void CMapView::SetZoomBoxStyle(tkZoomBoxStyle nNewValue) // ***************************************************** long CMapView::GetZoomBarMinZoom() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _zoomBarMinZoom; } void CMapView::SetZoomBarMinZoom(long nNewValue) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (nNewValue < 1) nNewValue = -1; if (nNewValue > 25) nNewValue = 25; @@ -502,12 +502,12 @@ void CMapView::SetZoomBarMinZoom(long nNewValue) // ***************************************************** long CMapView::GetZoomBarMaxZoom() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return _zoomBarMaxZoom; } void CMapView::SetZoomBarMaxZoom(long nNewValue) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (nNewValue < 1) nNewValue = -1; if (nNewValue > 25) nNewValue = 25; diff --git a/src/MapControl/Map_Scale.cpp b/src/MapControl/Map_Scale.cpp index 68f03e4a..2ca3faf3 100644 --- a/src/MapControl/Map_Scale.cpp +++ b/src/MapControl/Map_Scale.cpp @@ -293,32 +293,6 @@ void CMapView::SetNewExtentsWithForcedZooming(Extent ext, bool zoomIn) SetExtentsCore(Extent(cLeft, cRight, cBottom, cTop)); } -// **************************************************** -// SetNewExtentsWithZoomOut() -// **************************************************** -// Sets new extents by zooming out using given extent (drawn rectangle) -void CMapView::SetNewExtentsWithZoomOut(Extent ext) -{ - auto extent = GetExtents(); - if (extent == NULL) return; - - double width, height; - extent->get_Width(&width); - extent->get_Height(&height); - - auto const pt = ext.GetCenter(); - auto const widthFactor = width / ext.Width(); - auto const heightFactor = height / ext.Height(); - width *= widthFactor; - height *= heightFactor; - - double zMin, zMax; - extent->get_zMin(&zMin); - extent->get_zMax(&zMax); - extent->SetBounds(pt.x - width / 2, pt.y - height / 2, zMin, pt.x + width / 2, pt.y + height / 2, zMax); - SetExtents(extent); -} - // **************************************************** // SetExtentsCore() // **************************************************** @@ -395,7 +369,7 @@ void CMapView::GetMapSizeInches(double& mw, double& mh) // ********************************************************** DOUBLE CMapView::GetCurrentScale(void) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_extents.Width() == 0.0 || _extents.Height() == 0.0 || _viewWidth == 0 || _viewHeight == 0) { @@ -417,7 +391,7 @@ DOUBLE CMapView::GetCurrentScale(void) // ********************************************************** void CMapView::SetCurrentScale(DOUBLE newVal) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (newVal <= 0.0) return; @@ -483,7 +457,7 @@ void CMapView::SetExtents(IExtents* newValue) // ***************************************************** VARIANT_BOOL CMapView::SetGeographicExtents(IExtents* extents) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (!extents) { this->ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); @@ -492,9 +466,7 @@ VARIANT_BOOL CMapView::SetGeographicExtents(IExtents* extents) if (_transformationMode == tmNotDefined) { -#if RELEASE_MODE this->ErrorMessage(tkTRANSFORMATIONMODE_NOT_DEFINED); -#endif return VARIANT_FALSE; } @@ -551,7 +523,7 @@ VARIANT_BOOL CMapView::SetGeographicExtents(IExtents* extents) // ***************************************************** IMeasuring* CMapView::GetMeasuring() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_measuring) { _measuring->AddRef(); } @@ -563,7 +535,7 @@ IMeasuring* CMapView::GetMeasuring() // ***************************************************** IShapeEditor* CMapView::GetShapeEditor() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) if (_shapeEditor) { _shapeEditor->AddRef(); } @@ -575,7 +547,7 @@ IShapeEditor* CMapView::GetShapeEditor() // ***************************************************** IExtents* CMapView::GetGeographicExtents() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) return GetGeographicExtentsCore(false); } @@ -584,11 +556,6 @@ IExtents* CMapView::GetGeographicExtents() // *************************************************************** bool CMapView::GetGeographicExtentsInternal(bool clipForTiles, Extent* clipExtents, Extent& result) { - if (clipExtents != nullptr) - { - ::OutputDebugStringA(clipExtents->ToString()); - ::OutputDebugStringA("\r\n"); - } // we don't want to have coordinates outside world bounds, as it breaks tiles loading IExtents* ext = GetGeographicExtentsCore(clipForTiles, clipExtents); if (!ext) return false; @@ -597,8 +564,6 @@ bool CMapView::GetGeographicExtentsInternal(bool clipForTiles, Extent* clipExten ext->Release(); result = bounds; - ::OutputDebugStringA(result.ToString()); - ::OutputDebugStringA("\r\n"); return true; } @@ -699,7 +664,7 @@ IExtents* CMapView::GetGeographicExtentsCore(bool clipForTiles, Extent* clipExte // ***************************************************** DOUBLE CMapView::GetPixelsPerDegree(void) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) double val = 1.0; if (this->_unitsOfMeasure != umDecimalDegrees) @@ -738,7 +703,7 @@ DOUBLE CMapView::GetPixelsPerDegree(void) // Without conversion to decimal degrees DOUBLE CMapView::PixelsPerMapUnit(void) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) const double val = 1.0; double x = 0.0, y = 0.0; double screenX = 0.0, screenY = 0.0; @@ -804,7 +769,7 @@ double CMapView::UnitsPerPixel() // ***************************************************** VARIANT_BOOL CMapView::ZoomToSelected(LONG layerHandle) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) long numSelected = 0; IShapefile* sf = this->GetShapefile(layerHandle); @@ -833,7 +798,7 @@ void CMapView::ZoomToMaxExtents() { bool extentsSet = false; - const long endcondition = _activeLayers.size(); + const long endcondition = static_cast(_activeLayers.size()); for (int i = 0; i < endcondition; i++) { if (this->LayerIsEmpty(_activeLayers[i])) continue; @@ -881,7 +846,7 @@ void CMapView::ZoomToMaxVisibleExtents(void) { bool extentsSet = false; - const long endcondition = _activeLayers.size(); + const long endcondition = static_cast(_activeLayers.size()); for (int i = 0; i < endcondition; i++) { Layer* l = _allLayers[_activeLayers[i]]; @@ -983,7 +948,7 @@ VARIANT_BOOL CMapView::ZoomToShape2(long layerHandle, long shapeIndex, VARIANT_B IShapefile* sf = GetShapefile(layerHandle); double left, right, top, bottom; - static_cast(sf)->QuickExtentsCore(shapeIndex, &left, &bottom, &right, &top); + dynamic_cast(sf)->QuickExtentsCore(shapeIndex, &left, &bottom, &right, &top); sf->Release(); Extent extNew(left, right, bottom, top); @@ -1008,10 +973,6 @@ void CMapView::CalculateVisibleExtents(Extent e, bool MapSizeChanged) double bottom = MIN(e.bottom, e.top); double top = MAX(e.bottom, e.top); - CString sOutput; - sOutput.AppendFormat("CalculateVisibleExtents() left: %.2f, right: %.2f, bottom: %.2f, top: : %.2f\r\n", left, right, bottom, top); - ::OutputDebugStringA(sOutput.GetBuffer()); - if (left == right) // lsu 26 jul 2009 for zooming to single point { left -= 0.5; @@ -1171,7 +1132,7 @@ void CMapView::CalculateVisibleExtents(Extent e, bool MapSizeChanged) // **************************************************************** IExtents* CMapView::GetMaxExtents() { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) bool extentsSet = false; Extent maxExtents; @@ -1320,7 +1281,7 @@ void CMapView::LogPrevExtent() } // let's discard part of the history that was reverted with ZoomToPrev - const int removeCount = _prevExtents.size() - 1 - _prevExtentsIndex; + const int removeCount = static_cast(_prevExtents.size() - 1 - _prevExtentsIndex); if (removeCount > 0) { int count = 0; @@ -1340,7 +1301,7 @@ void CMapView::LogPrevExtent() _prevExtents.erase(_prevExtents.begin()); } - _prevExtentsIndex = _prevExtents.size() - 1; + _prevExtentsIndex = static_cast(_prevExtents.size() - 1); } // *************************************************** @@ -1411,7 +1372,7 @@ long CMapView::GetExtentHistoryRedoCount() return 0; } - return (_prevExtents.size() - 1) - _prevExtentsIndex; + return static_cast((_prevExtents.size() - 1) - _prevExtentsIndex); } // *************************************************** diff --git a/src/MapControl/Map_Snapshot.cpp b/src/MapControl/Map_Snapshot.cpp index 860dedcf..cf8acc6f 100644 --- a/src/MapControl/Map_Snapshot.cpp +++ b/src/MapControl/Map_Snapshot.cpp @@ -34,25 +34,25 @@ // ********************************************************* LPDISPATCH CMapView::SnapShot(IExtents* BoundBox) { - if( BoundBox == NULL ) - { + if( BoundBox == nullptr) + { ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); - return NULL; + return nullptr; } - IExtents * box = NULL; + IExtents * box = nullptr; BoundBox->QueryInterface(IID_IExtents, (void**)&box); - if( box == NULL ) + if( box == nullptr) { ErrorMessage(tkINTERFACE_NOT_SUPPORTED); - return NULL; + return nullptr; } double left, right, bottom, top, nv; box->GetBounds(&left,&bottom,&nv,&right,&top,&nv); box->Release(); - + return SnapShotCore(left, right, bottom, top, _viewWidth, _viewHeight); } @@ -61,8 +61,8 @@ LPDISPATCH CMapView::SnapShot(IExtents* BoundBox) // ********************************************************* // use the indicated layer and zoom/width to determine the output size and clipping IDispatch* CMapView::SnapShot2(LONG clippingLayerNbr, DOUBLE zoom, long pWidth) -{ - AFX_MANAGE_STATE(AfxGetStaticModuleState()); +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()) long Width, Height; double left, right, bottom, top; @@ -71,10 +71,10 @@ IDispatch* CMapView::SnapShot2(LONG clippingLayerNbr, DOUBLE zoom, long pWidth) if( !IS_VALID_PTR(l) ) { ErrorMessage(tkINVALID_LAYER_HANDLE); - return NULL; + return nullptr; } else - { + { this->AdjustLayerExtents(clippingLayerNbr); left = l->extents.left; right = l->extents.right; @@ -84,30 +84,30 @@ IDispatch* CMapView::SnapShot2(LONG clippingLayerNbr, DOUBLE zoom, long pWidth) if( l->IsShapefile() ) { double ar = (right-left)/(top-bottom); - Width = (long) (pWidth == 0 ? ((right - left) * zoom) : pWidth); - Height = (long)((double)pWidth / ar); + Width = static_cast(pWidth == 0 ? ((right - left) * zoom) : pWidth); + Height = static_cast(static_cast(pWidth) / ar); } else if(l->IsImage()) { - Width = (long)(right - left); - Height = (long)(top - bottom); + Width = static_cast(right - left); + Height = static_cast(top - bottom); if (zoom > 0) { - Width *= (long)zoom; - Height *= (long)zoom; + Width *= static_cast(zoom); + Height *= static_cast(zoom); } } else { ErrorMessage(tkUNEXPECTED_LAYER_TYPE); - return NULL; + return nullptr; } } if (Width <= 0 || Height <= 0) { ErrorMessage(tkINVALID_WIDTH_OR_HEIGHT); - return NULL; + return nullptr; } return this->SnapShotCore(left, right, top, bottom, Width, Height); @@ -119,14 +119,14 @@ IDispatch* CMapView::SnapShot2(LONG clippingLayerNbr, DOUBLE zoom, long pWidth) //A new snapshot method which works a bit better specifically for the printing engine //1. Draw to a back buffer, 2. Populate an Image object LPDISPATCH CMapView::SnapShot3(double left, double right, double top, double bottom, long width) -{ - AFX_MANAGE_STATE(AfxGetStaticModuleState()); +{ + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - long Height = (long)((double)width / ((right-left)/(top-bottom))); + long Height = static_cast(static_cast(width) / ((right - left) / (top - bottom))); if (width <= 0 || Height <= 0) { ErrorMessage(tkINVALID_WIDTH_OR_HEIGHT); - return NULL; + return nullptr; } return this->SnapShotCore(left, right, top, bottom, width, Height); @@ -138,33 +138,32 @@ LPDISPATCH CMapView::SnapShot3(double left, double right, double top, double bot // Loads tiles for specified extents BOOL CMapView::LoadTilesForSnapshot(IExtents* extents, LONG widthPixels, LPCTSTR key) { - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()) - if (!extents) + if (!extents) { ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); return FALSE; } - + // Get the image height based on the box aspect ratio double xMin, xMax, yMin, yMax, zMin, zMax; extents->GetBounds(&xMin, &yMin, &zMin, &xMax, &yMax, &zMax); // Make sure that the width and height are valid - long Height = static_cast((double)widthPixels *(yMax - yMin) / (xMax - xMin)); + long Height = static_cast(static_cast(widthPixels) *(yMax - yMin) / (xMax - xMin)); if (widthPixels <= 0 || Height <= 0) { ErrorMessage(tkINVALID_WIDTH_OR_HEIGHT); return FALSE; } - + //CString key = (char*)key; SetTempExtents(xMin, xMax, yMin, yMax, widthPixels, Height); bool tilesInCache = TilesAreInCache(); if (!tilesInCache) { ReloadTiles(true, true, key); - } RestoreExtents(); @@ -178,27 +177,27 @@ BOOL CMapView::LoadTilesForSnapshot(IExtents* extents, LONG widthPixels, LPCTSTR BOOL CMapView::SnapShotToDC2(PVOID hdc, IExtents* extents, LONG width, float offsetX, float offsetY, float clipX, float clipY, float clipWidth, float clipHeight) { - if(!extents || !hdc) + if(!extents || !hdc) { ErrorMessage(tkUNEXPECTED_NULL_PARAMETER); return FALSE; } // getting DC to draw - HDC dc = reinterpret_cast(hdc); + HDC dc = static_cast(hdc); CDC * tempDC = CDC::FromHandle(dc); // Get the image height based on the box aspect ration double xMin, xMax, yMin, yMax, zMin, zMax; extents->GetBounds(&xMin, &yMin, &zMin, &xMax, &yMax, &zMax); - + // Make sure that the width and height are valid - long Height = static_cast((double)width *(yMax - yMin) / (xMax - xMin)); + long Height = static_cast(static_cast(width) *(yMax - yMin) / (xMax - xMin)); if (width <= 0 || Height <= 0) { ErrorMessage(tkINVALID_WIDTH_OR_HEIGHT); return FALSE; } - + SnapShotCore(xMin, xMax, yMin, yMax, width, Height, tempDC, offsetX, offsetY, clipX, clipY, clipWidth, clipHeight); return TRUE; } @@ -238,7 +237,7 @@ void CMapView::SetTempExtents(double left, double right, double top, double bott _viewWidth=Width; _viewHeight=Height; //ResizeBuffers(m_viewWidth, m_viewHeight); - _aspectRatio = (double)Width / (double)Height; + _aspectRatio = static_cast(Width) / static_cast(Height); double xrange = right - left; double yrange = top - bottom; @@ -287,15 +286,15 @@ IDispatch* CMapView::SnapShotCore(double left, double right, double top, double { if (left == right || top == bottom) { - return NULL; + return nullptr; } // PM dec 2017 if (Width == 0) Width = 100; if (Height == 0) Height = 100; - bool createDC = (snapDC == NULL); - CBitmap * bmp = NULL; + bool createDC = (snapDC == nullptr); + CBitmap * bmp = nullptr; if (createDC) { @@ -304,7 +303,7 @@ IDispatch* CMapView::SnapShotCore(double left, double right, double top, double { delete bmp; ErrorMessage(tkFAILED_TO_ALLOCATE_MEMORY); - return NULL; + return nullptr; } } @@ -313,7 +312,7 @@ IDispatch* CMapView::SnapShotCore(double left, double right, double top, double SetTempExtents(left, right, top, bottom, Width, Height); // create canvas - CBitmap * oldBMP = NULL; + CBitmap * oldBMP = nullptr; if (createDC) { snapDC = new CDC(); @@ -332,7 +331,7 @@ IDispatch* CMapView::SnapShotCore(double left, double right, double top, double ReloadTiles(true,true); // simply move them to the screen buffer (is performed synchronously) CRect rcBounds(0,0,_viewWidth,_viewHeight); - CRect rcClip((int)clipX, (int)clipY, (int)clipWidth, (int)clipHeight); + CRect rcClip(static_cast(clipX), static_cast(clipY), static_cast(clipWidth), static_cast(clipHeight)); CRect* r = clipWidth != 0.0 && clipHeight != 0.0 ? &rcClip : &rcBounds; // draws to output canvas directly because of m_isSnapshot parameter @@ -344,21 +343,21 @@ IDispatch* CMapView::SnapShotCore(double left, double right, double top, double ScheduleLayerRedraw(); _isSnapshot = false; - IImage * iimg = NULL; + IImage * iImg = nullptr; if (createDC) { // create output VARIANT_BOOL retval; - ComHelper::CreateInstance(idImage, (IDispatch**)&iimg); - iimg->SetImageBitsDC((long)snapDC->m_hDC,&retval); - - double dx = (right-left)/(double)(_viewWidth); - double dy = (top-bottom)/(double)(_viewHeight); - iimg->put_dX(dx); - iimg->put_dY(dy); - iimg->put_XllCenter(left + dx*.5); - iimg->put_YllCenter(bottom + dy*.5); + ComHelper::CreateInstance(idImage, reinterpret_cast(&iImg)); + iImg->SetImageBitsDC(static_cast(reinterpret_cast(snapDC->m_hDC)), &retval); + + double dx = (right-left)/static_cast(_viewWidth); + double dy = (top-bottom)/static_cast(_viewHeight); + iImg->put_dX(dx); + iImg->put_dY(dy); + iImg->put_XllCenter(left + dx*.5); + iImg->put_YllCenter(bottom + dy*.5); // dispose the canvas snapDC->SelectObject(oldBMP); @@ -380,7 +379,7 @@ IDispatch* CMapView::SnapShotCore(double left, double right, double top, double ReloadTiles(true,true); LockWindow( lmUnlock ); - return iimg; + return iImg; } // ******************************************************************** @@ -396,7 +395,7 @@ void CMapView::DrawBackBuffer(int hdc, int imageWidth, int imageHeight) return; } - CDC* dc = CDC::FromHandle((HDC)hdc); + CDC* dc = CDC::FromHandle(reinterpret_cast(static_cast(hdc))); CRect rect(0,0, imageWidth, imageHeight); OnDraw(dc, rect, rect); } \ No newline at end of file diff --git a/src/MapControl/ToolTipEx.cpp b/src/MapControl/ToolTipEx.cpp index 6eadafef..c144055e 100644 --- a/src/MapControl/ToolTipEx.cpp +++ b/src/MapControl/ToolTipEx.cpp @@ -71,7 +71,7 @@ COLORREF CToolTipEx::SetBkColor(COLORREF crColor) { COLORREF oldColor; - oldColor = SendMessage(TTM_GETTIPBKCOLOR, 0, 0); + oldColor = static_cast(SendMessage(TTM_GETTIPBKCOLOR, 0, 0)); SendMessage(TTM_SETTIPBKCOLOR, (WPARAM)(COLORREF)crColor, 0); return oldColor; @@ -81,7 +81,7 @@ COLORREF CToolTipEx::SetTextColor(COLORREF crColor) { COLORREF oldColor; - oldColor = SendMessage(TTM_GETTIPTEXTCOLOR, 0, 0); + oldColor = static_cast(SendMessage(TTM_GETTIPTEXTCOLOR, 0, 0)); SendMessage(TTM_SETTIPTEXTCOLOR, (WPARAM)(COLORREF)crColor, 0); return oldColor; @@ -89,12 +89,12 @@ COLORREF CToolTipEx::SetTextColor(COLORREF crColor) COLORREF CToolTipEx::GetBkColor() { - return SendMessage(TTM_GETTIPBKCOLOR, 0, 0); + return static_cast(SendMessage(TTM_GETTIPBKCOLOR, 0, 0)); } COLORREF CToolTipEx::GetTextColor() { - return SendMessage(TTM_GETTIPTEXTCOLOR, 0, 0); + return static_cast(SendMessage(TTM_GETTIPTEXTCOLOR, 0, 0)); } int CToolTipEx::SetDelayTime(DWORD dwType, int nTime) @@ -118,8 +118,8 @@ int CToolTipEx::SetDelayTime(DWORD dwType, int nTime) case TTDT_AUTOPOP: case TTDT_INITIAL: case TTDT_RESHOW: - nDuration = SendMessage(TTM_GETDELAYTIME, (DWORD)dwType, 0); - SendMessage(TTM_SETDELAYTIME, (WPARAM)(DWORD)dwType, (LPARAM)(INT)MAKELONG(nTime, 0)); + nDuration = static_cast(SendMessage(TTM_GETDELAYTIME, dwType, 0)); + SendMessage(TTM_SETDELAYTIME, dwType, static_cast(MAKELONG(nTime, 0))); return nDuration; } return -1; @@ -138,13 +138,13 @@ int CToolTipEx::GetDelayTime(DWORD dwType) // // TTDT_RESHOW Retrieve the length of time it takes for // subsequent tooltip windows to appear as the pointer moves - // from one tool to another. + // from one tool to another. switch(dwType) { case TTDT_AUTOPOP: case TTDT_INITIAL: case TTDT_RESHOW: - return SendMessage(TTM_GETDELAYTIME, (DWORD)dwType, 0); + return static_cast(SendMessage(TTM_GETDELAYTIME, dwType, 0)); } return -1; } @@ -159,7 +159,7 @@ void CToolTipEx::GetMargin(LPRECT lpRect) // tooltip text, in pixels. // lpRect.right Distance between right border and right end of // tooltip text, in pixels - SendMessage(TTM_GETMARGIN, 0, (LPARAM)(LPRECT)lpRect); + SendMessage(TTM_GETMARGIN, 0, reinterpret_cast(lpRect)); } int CToolTipEx::GetMaxTipWidth() @@ -172,7 +172,7 @@ int CToolTipEx::GetMaxTipWidth() // played on a single line. The length of this line may exceed // the maximum tooltip width. // Defaults to -1 when tooltip control is first created. - return SendMessage(TTM_GETMAXTIPWIDTH, 0, 0); + return static_cast(SendMessage(TTM_GETMAXTIPWIDTH, 0, 0)); } RECT CToolTipEx::SetMargin(LPRECT lpRect) @@ -187,7 +187,7 @@ RECT CToolTipEx::SetMargin(LPRECT lpRect) // tooltip text, in pixels. RECT TempRect; GetMargin(&TempRect); - SendMessage(TTM_SETMARGIN, 0, (LPARAM)(LPRECT)lpRect); + SendMessage(TTM_SETMARGIN, 0, reinterpret_cast(lpRect)); return TempRect; } @@ -201,13 +201,13 @@ int CToolTipEx::SetMaxTipWidth(int nWidth) // cannot be segmented into multiple lines, it will be dis- // played on a single line. The length of this line may exceed // the maximum tooltip width. - return SendMessage(TTM_SETMAXTIPWIDTH, 0, (LPARAM)(INT)nWidth); + return static_cast(SendMessage(TTM_SETMAXTIPWIDTH, 0, nWidth)); } void CToolTipEx::TrackActivate(BOOL bActivate, LPTOOLINFO lpti) { - SendMessage(TTM_TRACKACTIVATE, (WPARAM)(BOOL)bActivate, - (LPARAM)(LPTOOLINFO)lpti); + SendMessage(TTM_TRACKACTIVATE, static_cast(bActivate), + reinterpret_cast(lpti)); } void CToolTipEx::TrackPosition(LPPOINT lppt) @@ -219,7 +219,7 @@ void CToolTipEx::TrackPosition(LPPOINT lppt) // displayed at specific coordinates, include the TTF_ABSOLUTE // flag in the uFlags member of the TOOLINFO structure when // adding the tool. - SendMessage(TTM_TRACKPOSITION, 0, (LPARAM)(DWORD)MAKELONG(lppt->x, lppt->y)); + SendMessage(TTM_TRACKPOSITION, 0, static_cast(MAKELONG(lppt->x, lppt->y))); } void CToolTipEx::TrackPosition(int xPos, int yPos) @@ -231,5 +231,5 @@ void CToolTipEx::TrackPosition(int xPos, int yPos) // displayed at specific coordinates, include the TTF_ABSOLUTE // flag in the uFlags member of the TOOLINFO structure when // adding the tool. - SendMessage(TTM_TRACKPOSITION, 0, (LPARAM)(DWORD)MAKELONG(xPos, yPos)); + SendMessage(TTM_TRACKPOSITION, 0, static_cast(MAKELONG(xPos, yPos))); } diff --git a/src/Ogr/GeosConverter.cpp b/src/Ogr/GeosConverter.cpp index 289153cd..5204a83a 100644 --- a/src/Ogr/GeosConverter.cpp +++ b/src/Ogr/GeosConverter.cpp @@ -46,7 +46,7 @@ GEOSGeometry* DoBuffer(DOUBLE distance, long nQuadSegments, GEOSGeometry* gsGeom bool GeosConverter::GeomToShapes(GEOSGeom gsGeom, vector* vShapes, bool isM) { bool substitute = false; - bool has25D = false; + bool has25D = false; if (!GeosHelper::IsValid(gsGeom)) { @@ -101,7 +101,7 @@ GEOSGeom GeosConverter::ShapeToGeom(IShape* shp) OGRGeometryFactory::destroyGeometry(oGeom); return result; } - return nullptr; + return nullptr; } // ***************************************************** @@ -111,8 +111,8 @@ GEOSGeom GeosConverter::ShapeToGeom(IShape* shp) GEOSGeometry* GeosConverter::SimplifyPolygon(const GEOSGeometry *gsGeom, double tolerance) { const GEOSGeometry* gsRing = GeosHelper::GetExteriorRing(gsGeom); // no memory is allocated there - // ReSharper disable once CppLocalVariableMayBeConst - GEOSGeom gsPoly = GeosHelper::TopologyPreserveSimplify(gsRing, tolerance); // memory allocation + // ReSharper disable once CppLocalVariableMayBeConst + GEOSGeom gsPoly = GeosHelper::TopologyPreserveSimplify(gsRing, tolerance); // memory allocation if (!gsPoly) return nullptr; @@ -127,7 +127,7 @@ GEOSGeometry* GeosConverter::SimplifyPolygon(const GEOSGeometry *gsGeom, double if (gsOut) { char* type = GeosHelper::GetGeometryType(gsOut); - const CString s = type; + const CString s = type; GeosHelper::Free(type); if (s == "LinearRing") holes.push_back(gsOut); @@ -138,7 +138,7 @@ GEOSGeometry* GeosConverter::SimplifyPolygon(const GEOSGeometry *gsGeom, double GEOSGeometry *gsNew; if (!holes.empty()) { - gsNew = GeosHelper::CreatePolygon(gsPoly, &holes[0], holes.size()); // memory allocation (should be released by caller) + gsNew = GeosHelper::CreatePolygon(gsPoly, &holes[0], static_cast(holes.size())); // memory allocation (should be released by caller) } else { @@ -154,7 +154,7 @@ void GeosConverter::NormalizeSplitResults(GEOSGeometry* result, GEOSGeometry* su { if (!result) return; - const int numGeoms = GeosHelper::GetNumGeometries(result); + const int numGeoms = GeosHelper::GetNumGeometries(result); if (numGeoms > 1) { if (shpType == SHP_POLYGON) @@ -174,7 +174,7 @@ void GeosConverter::NormalizeSplitResults(GEOSGeometry* result, GEOSGeometry* su double polyArea; GeosHelper::Area(polygon, &polyArea); - const double areaRatio = intersectArea / polyArea; + const double areaRatio = intersectArea / polyArea; if (areaRatio > 0.99 && areaRatio < 1.01) { GEOSGeometry* clone = GeosHelper::CloneGeometry(polygon); if (clone) { @@ -213,7 +213,7 @@ GEOSGeometry* GeosConverter::MergeGeometries(vector& data, ICallb int count = 0; // number of union operation performed long percent = 0; - const int size = data.size(); + const int size = static_cast(data.size()); int depth = 0; if (size == 1) diff --git a/src/Ogr/Ogr2RawData.cpp b/src/Ogr/Ogr2RawData.cpp index 1de5924a..5a6517a9 100644 --- a/src/Ogr/Ogr2RawData.cpp +++ b/src/Ogr/Ogr2RawData.cpp @@ -45,10 +45,10 @@ bool Ogr2RawData::Layer2RawData(OGRLayer* layer, Extent* extents, OgrDynamicLoad OGRFeatureDefn *poFields = layer->GetLayerDefn(); layer->ResetReading(); - while ((poFeature = layer->GetNextFeature()) != NULL) + while ((poFeature = layer->GetNextFeature()) != nullptr) { // Get shape or create empty one: - IShape* shp = NULL; + IShape* shp = nullptr; OGRGeometry *oGeom = poFeature->GetGeometryRef(); if (oGeom) shp = OgrConverter::GeometryToShape(oGeom, loader->IsMShapefile); @@ -82,7 +82,7 @@ bool Ogr2RawData::Layer2RawData(OGRLayer* layer, Extent* extents, OgrDynamicLoad } loader->PutData(shapeData); - callback->LoadedCount = shapeData.size(); + callback->LoadedCount = static_cast(shapeData.size()); loader->LastSuccessExtents = *extents; if (callback->LoadedCount == 0) diff --git a/src/Processing/Base64.cpp b/src/Processing/Base64.cpp index b17dbce973a69dca124f01da1239b15e86a390c3..5c2fff3f70d6734b26e6bb2026f01cdf1d4e27bf 100644 GIT binary patch delta 42 ycmdmI`^a{~7Lmzy;u4&h40#MC40a3}lk-JnCtncZW7cG_o;*=Rc=IQbGn@b~Bn^cC delta 28 kcmaE4yU%vR7LmzU#ALYj7>XG(8LAjk88kNk7kSJH0Gw0_`Tzg` diff --git a/src/Processing/ClipperConverter.cpp b/src/Processing/ClipperConverter.cpp index 614b6af1..cf28003a 100644 --- a/src/Processing/ClipperConverter.cpp +++ b/src/Processing/ClipperConverter.cpp @@ -9,21 +9,21 @@ // ClipperLib::Polygons* ClipperConverter::Shape2ClipperPolygon(IShape* shp) ClipperLib::Paths* ClipperConverter::Shape2ClipperPolygon(IShape* shp) { - if (!shp) - return NULL; + if (!shp) + return nullptr; ShpfileType shpType; shp->get_ShapeType(&shpType); if (shpType != SHP_POLYGON && shpType != SHP_POLYGONM && shpType != SHP_POLYGONZ) - return NULL; - + return nullptr; + long numParts, numPoints; shp->get_NumParts(&numParts); shp->get_NumPoints(&numPoints); if (numPoints == 0 || numParts == 0) - return NULL; - + return nullptr; + double x, y; // ClipperLib::Polygons* retval = new ClipperLib::Polygons(); @@ -52,8 +52,8 @@ ClipperLib::Paths* ClipperConverter::Shape2ClipperPolygon(IShape* shp) y *= conversionFactor; } - pnt.X = (ClipperLib::long64)x; - pnt.Y = (ClipperLib::long64)y; + pnt.X = static_cast(x); + pnt.Y = static_cast(y); polygon.push_back(pnt); } retval->push_back(polygon); @@ -66,7 +66,7 @@ ClipperLib::Paths* ClipperConverter::Shape2ClipperPolygon(IShape* shp) else { delete retval; - return NULL; + return nullptr; } } @@ -79,7 +79,7 @@ ClipperLib::Paths* ClipperConverter::Shape2ClipperPolygon(IShape* shp) IShape* ClipperConverter::ClipperPolygon2Shape(ClipperLib::Paths* polygon) { bool pointsExist = false; - for (long i = 0; i < (long)polygon->size(); i++) + for (long i = 0; i < static_cast(polygon->size()); i++) { // ClipperLib::Polygon* poly = &((*polygon)[i]); ClipperLib::Path* poly = &((*polygon)[i]); @@ -91,26 +91,26 @@ IShape* ClipperConverter::ClipperPolygon2Shape(ClipperLib::Paths* polygon) } if (!pointsExist) - return NULL; + return nullptr; - IShape* shp = NULL; + IShape* shp = nullptr; ComHelper::CreateShape(&shp); if (!shp) - return NULL; + return nullptr; VARIANT_BOOL vbretval; shp->Create(SHP_POLYGON, &vbretval); if (!vbretval) { shp->Release(); - return NULL; + return nullptr; } double x, y; long cnt = 0; long part = 0; - for (long i = 0; i < (long)polygon->size(); i++) + for (long i = 0; i < static_cast(polygon->size()); i++) { // ClipperLib::Polygon* poly = &((*polygon)[i]); ClipperLib::Path* poly = &((*polygon)[i]); @@ -118,15 +118,15 @@ IShape* ClipperConverter::ClipperPolygon2Shape(ClipperLib::Paths* polygon) { shp->InsertPart(cnt, &part, &vbretval); part++; - - int j = poly->size() - 1; + + int j = static_cast(poly->size() - 1); for (; j >= 0; j--) { - IPoint* pnt = NULL; + IPoint* pnt = nullptr; ComHelper::CreatePoint(&pnt); - x = (double)(*poly)[j].X; - y = (double)(*poly)[j].Y; + x = static_cast((*poly)[j].X); + y = static_cast((*poly)[j].Y); if (this->conversionFactor != 1.0) { @@ -143,24 +143,24 @@ IShape* ClipperConverter::ClipperPolygon2Shape(ClipperLib::Paths* polygon) } // the first and the last point of the part must be the same - int size = poly->size() - 1; + int size = static_cast(poly->size() - 1); if (size > 0) { if (((*poly)[0]).X != ((*poly)[size]).X || ((*poly)[0]).Y != ((*poly)[size]).Y) { - IPoint* pnt = NULL; + IPoint* pnt = nullptr; ComHelper::CreatePoint(&pnt); - x = (double)(*poly)[size].X; // slightly inoptimal, this point was calculated already - y = (double)(*poly)[size].Y; + x = static_cast((*poly)[size].X); // slightly inoptimal, this point was calculated already + y = static_cast((*poly)[size].Y); if (this->conversionFactor != 1.0) { x /= conversionFactor; y /= conversionFactor; } - + pnt->put_X(x); pnt->put_Y(y); @@ -209,12 +209,12 @@ ClipperLib::Paths* ClipperConverter::ClipPolygon(ClipperLib::Paths* polyClip, Cl } else { - return NULL; + return nullptr; } } else { - return NULL; + return nullptr; } } @@ -238,10 +238,10 @@ IShape* ClipperConverter::ClipPolygon(IShape* shapeClip, IShape* shapeSubject, P case UNION_OPERATION: operNew = ClipperLib::ctUnion; break; - default: - return NULL; + default: + return nullptr; } - + //shapeSubject ClipperConverter ogr; // ClipperLib::Polygons* poly1 = ogr.Shape2ClipperPolygon(shapeClip); @@ -259,7 +259,7 @@ IShape* ClipperConverter::ClipPolygon(IShape* shapeClip, IShape* shapeSubject, P return shp; } } - return NULL; + return nullptr; } // *************************************************** @@ -267,14 +267,14 @@ IShape* ClipperConverter::ClipPolygon(IShape* shapeClip, IShape* shapeSubject, P // *************************************************** void ClipperConverter::AddPolygons(IShapefile* sf, ClipperLib::Clipper& clp, ClipperLib::PolyType clipType, bool selectedOnly) { - if (!sf) return; + if (!sf) return; long numShapes; sf->get_NumShapes(&numShapes); ClipperConverter converter(sf); - IShape* shp = NULL; + IShape* shp = nullptr; for (long i = 0; i < numShapes; i++) { if (selectedOnly && !ShapefileHelper::ShapeSelected(sf, i)) diff --git a/src/Processing/CustomExpression.cpp b/src/Processing/CustomExpression.cpp index bfdbd6cd..68e8373f 100644 --- a/src/Processing/CustomExpression.cpp +++ b/src/Processing/CustomExpression.cpp @@ -34,7 +34,7 @@ CExpressionValue* CustomExpression::Calculate(CStringW& errorMessage) { Reset(); - + bool success = false; // if the operations should be cached we'll ensure that there is no obsolete data in vector @@ -67,7 +67,7 @@ CExpressionValue* CustomExpression::Calculate(CStringW& errorMessage) } } while (true); - + // operation was saved - no need to cache any more if (_saveOperations) { @@ -75,7 +75,7 @@ CExpressionValue* CustomExpression::Calculate(CStringW& errorMessage) _saveOperations = false; } - return success ? _parts[_parts.size() - 1]->val : NULL; + return success ? _parts[_parts.size() - 1]->val : nullptr; } // ******************************************************************* @@ -135,7 +135,7 @@ bool CustomExpression::EvaluateFunction(CExpressionPart* part) // we did the same check during parsing, // but still let's leave it as additional safeguard - if (!part->function->CheckArguments((int)args.size(), _errorMessage)) + if (!part->function->CheckArguments(static_cast(args.size()), _errorMessage)) { return false; } @@ -205,7 +205,7 @@ bool CustomExpression::FinishPart(CExpressionPart* part) if (part->activeCount == 1) { - int size = part->elements.size(); + int size = static_cast(part->elements.size()); for (int i = 0; i < size; i++) { if (!part->elements[i]->turnedOff) @@ -227,7 +227,7 @@ void CustomExpression::ResetActiveCountForParts() { for (unsigned int i = 0; i < _parts.size(); i++) { - _parts[i]->activeCount = _parts[i]->elements.size(); + _parts[i]->activeCount = static_cast(_parts[i]->elements.size()); } } @@ -256,7 +256,7 @@ bool CustomExpression::FindOperation(CExpressionPart* part, COperation& operatio int priority = 255; std::vector* elements = &part->elements; - int size = elements->size(); + int size = static_cast(elements->size()); for (int i = 0; i < size; i++) { CElement* element = (*elements)[i]; @@ -392,10 +392,10 @@ bool CustomExpression::CalculateOperation( CExpressionPart* part, COperation& op { USES_CONVERSION; - CExpressionValue* valLeft = NULL; - CExpressionValue* valRight = NULL; - CElement* elLeft = NULL; - CElement* elRight = NULL; + CExpressionValue* valLeft = nullptr; + CExpressionValue* valRight = nullptr; + CElement* elLeft = nullptr; + CElement* elRight = nullptr; tkOperation oper = part->elements[operation.id]->operation; if (oper == operNOT || oper == operChangeSign ) @@ -546,7 +546,7 @@ bool CustomExpression::CalculateOperation( CExpressionPart* part, COperation& op RasterMatrix* matrix = elLeft->calcVal->matrix(); float* data = new float[1]; - data[0] = (float)valRight->dbl(); + data[0] = static_cast(valRight->dbl()); RasterMatrix* right = new RasterMatrix(1, 1, data, matrix->nodataValue() ); matrix->twoArgumentOperation(GetMatrixOperation(oper), *right); @@ -558,7 +558,7 @@ bool CustomExpression::CalculateOperation( CExpressionPart* part, COperation& op elLeft->calcVal->matrix(matrix); float* data = new float[1]; - data[0] = (float)valLeft->dbl(); + data[0] = static_cast(valLeft->dbl()); RasterMatrix* left = new RasterMatrix(1, 1, data, matrix->nodataValue() ); matrix->twoArgumentOperation(GetMatrixOperation(oper), *left); @@ -658,9 +658,9 @@ bool CustomExpression::CalculateOperation( CExpressionPart* part, COperation& op } else { - elLeft->calcVal->dbl(double((int)valLeft->dbl() / (int)valRight->dbl())); + elLeft->calcVal->dbl(static_cast(static_cast(valLeft->dbl()) / static_cast(valRight->dbl()))); } - else if ( oper == operMOD ) elLeft->calcVal->dbl(double((int)valLeft->dbl() % (int)valRight->dbl())); + else if ( oper == operMOD ) elLeft->calcVal->dbl(static_cast(static_cast(valLeft->dbl()) % static_cast(valRight->dbl()))); } else if (valLeft->IsFloatArray() && valRight->IsFloatArray() ) { @@ -678,7 +678,7 @@ bool CustomExpression::CalculateOperation( CExpressionPart* part, COperation& op RasterMatrix* matrix = elLeft->calcVal->matrix(); float* data = new float[1]; - data[0] = (float)valRight->dbl(); + data[0] = static_cast(valRight->dbl()); RasterMatrix* right = new RasterMatrix(1, 1, data, matrix->nodataValue() ); matrix->twoArgumentOperation(GetMatrixOperation(oper), *right); delete right; @@ -689,7 +689,7 @@ bool CustomExpression::CalculateOperation( CExpressionPart* part, COperation& op elLeft->calcVal->matrix(matrix); float* data = new float[1]; - data[0] = (float)valLeft->dbl(); + data[0] = static_cast(valLeft->dbl()); RasterMatrix* left = new RasterMatrix(1, 1, data, matrix->nodataValue() ); matrix->twoArgumentOperation(GetMatrixOperation(oper), *left); delete left; @@ -707,7 +707,7 @@ bool CustomExpression::CalculateOperation( CExpressionPart* part, COperation& op return false; } } - + if (oper == operNOT || oper == operChangeSign) { // unary operator @@ -731,7 +731,7 @@ bool CustomExpression::CalculateOperation( CExpressionPart* part, COperation& op inline CExpressionValue* CustomExpression::GetValue(CExpressionPart* part, int elementId ) { CElement* element = part->elements[elementId]; - CExpressionValue* val = NULL; + CExpressionValue* val = nullptr; if ( element->wasCalculated ) val = element->calcVal; else if (element->partIndex != -1) val = _parts[element->partIndex]->val; @@ -746,16 +746,16 @@ inline CExpressionValue* CustomExpression::GetValue(CExpressionPart* part, int e bool CustomExpression::ReadFieldNames(ITable* tbl) { _fields.clear(); - + if (!tbl) return false; - + long numFields; tbl->get_NumFields(&numFields); for (int i = 0; i < numFields; i++) { // TODO: wrap - IField* fld = NULL; + IField* fld = nullptr; tbl->get_Field(i, &fld); if (fld) { @@ -811,7 +811,7 @@ void CustomExpression::Clear() { // arguments are references to parts present in the list // therefore there is no need to delete them - _parts[i]->arguments.clear(); + _parts[i]->arguments.clear(); delete _parts[i]; } @@ -825,7 +825,7 @@ void CustomExpression::Clear() if (_shape) { _shape->Release(); - _shape = NULL; + _shape = nullptr; } } @@ -908,13 +908,14 @@ void CustomExpression::put_Shape(IShape* shape) ComHelper::SetRef(shape, (IDispatch**)&_shape, true); } -void CustomExpression::put_FieldValue(int FieldId, BSTR newVal) +void CustomExpression::put_FieldValue(int FieldId, BSTR newVal) { USES_CONVERSION; _variables[FieldId]->val->str(OLE2W(newVal)); } -void CustomExpression::put_FieldValue(int FieldId, CStringW newVal) { +void CustomExpression::put_FieldValue(int FieldId, CStringW newVal) +{ USES_CONVERSION; _variables[FieldId]->val->str(newVal); } diff --git a/src/Processing/CustomExpression.h b/src/Processing/CustomExpression.h index d803f360..0cee556d 100644 --- a/src/Processing/CustomExpression.h +++ b/src/Processing/CustomExpression.h @@ -32,9 +32,8 @@ class CustomExpression public: CustomExpression() : _useFields(true), _saveOperations(true), _floatFormat(m_globalSettings.floatNumberFormat), - _shape(NULL), _errorPosition(-1) + _shape(nullptr), _errorPosition(-1) { - } ~CustomExpression() @@ -95,7 +94,7 @@ class CustomExpression vector* GetFields() { return &_fields; } // variable fields - int get_NumFields() { return _variables.size(); } + int get_NumFields() { return static_cast(_variables.size()); } int get_FieldIndex(int FieldId) { return _variables[FieldId]->fieldIndex; } CStringW get_FieldName(int FieldId) { return _variables[FieldId]->fieldName; } CExpressionValue* get_FieldValue(int FieldId) { return _variables[FieldId]->val;} @@ -103,7 +102,7 @@ class CustomExpression void put_FieldValue(int FieldId, BSTR newVal); void put_FieldValue(int FieldId, CStringW newVal); void put_FieldValue(int FieldId, bool newVal) { _variables[FieldId]->val->bln(newVal);} - int get_PartCount() { return _parts.size(); } + int get_PartCount() { return static_cast(_parts.size()); } IShape* get_Shape(); void put_Shape(IShape* shape); diff --git a/src/Processing/ExpressionParser.cpp b/src/Processing/ExpressionParser.cpp index e7d0e94a..5d1b97ea 100644 --- a/src/Processing/ExpressionParser.cpp +++ b/src/Processing/ExpressionParser.cpp @@ -304,7 +304,7 @@ CustomFunction* ExpressionParser::ParseFunction(CStringW& s, int begin, int& fnB return fn; } - return NULL; + return nullptr; } // ************************************************************ @@ -329,16 +329,16 @@ bool ExpressionParser::ParseArgumentList(CStringW s, CustomFunction* fn) if (arg) { - arg->isArgument = true; + arg->isArgument = true; _expression->AddPart(arg); - // argument list holds references to parts which are calculated before function + // argument list holds references to parts which are calculated before function // there is no need to delete arguments, as they will be deleted when parts list is cleared part->arguments.push_back(arg); } else { - // error message is set above + // error message is set above delete part; return false; } @@ -347,7 +347,7 @@ bool ExpressionParser::ParseArgumentList(CStringW s, CustomFunction* fn) }; CStringW errorMessage; - if (!fn->CheckArguments(part->arguments.size(), errorMessage)) + if (!fn->CheckArguments(static_cast(part->arguments.size()), errorMessage)) { SetErrorMessage(errorMessage); delete part; @@ -383,7 +383,7 @@ CExpressionPart* ExpressionParser::ParseExpressionPart(CStringW s) { delete element; delete part; - return NULL; + return nullptr; } // saving element @@ -400,14 +400,14 @@ CExpressionPart* ExpressionParser::ParseExpressionPart(CStringW s) { SetErrorMessage(L"Expression part is empty"); delete part; - return NULL; + return nullptr; } if (part->elements[part->elements.size() - 1]->type == etOperation) { SetErrorMessage(L"Operator doesn't have right operand."); delete part; - return NULL; + return nullptr; } return part; @@ -618,7 +618,7 @@ bool ExpressionParser::ReadValue(CStringW s, int& position, CElement* element) if (IsInteger(sub)) { element->type = etValue; - unsigned int index = _wtoi(LPCWSTR(sub)); + unsigned int index = _wtoi(static_cast(sub)); vector* strings = _expression->GetStrings(); element->val->str(index < strings->size() ? (*strings)[index] : L""); @@ -648,7 +648,7 @@ bool ExpressionParser::ReadValue(CStringW s, int& position, CElement* element) // writing the number of bracket if (IsInteger(sub)) { - element->partIndex = _wtoi(LPCWSTR(sub)); + element->partIndex = _wtoi(static_cast(sub)); element->type = etPart; } else diff --git a/src/Processing/ExpressionParts.cpp b/src/Processing/ExpressionParts.cpp index 4fa8ff4a..a0dc2d17 100644 --- a/src/Processing/ExpressionParts.cpp +++ b/src/Processing/ExpressionParts.cpp @@ -351,7 +351,7 @@ void CExpressionPart::ReleaseValue() // functions don't have nested elements, only parts, // so we own the element, and must release it delete val; - val = NULL; + val = nullptr; } } @@ -360,8 +360,8 @@ void CExpressionPart::ReleaseValue() //************************************************************ void CExpressionPart::Reset() { - int size = elements.size(); - for (int j = 0; j < size; j++) + size_t size = elements.size(); + for (size_t j = 0; j < size; j++) { CElement* el = elements[j]; el->wasCalculated = false; diff --git a/src/Processing/ExpressionParts.h b/src/Processing/ExpressionParts.h index fd4a8db2..b3dfd675 100644 --- a/src/Processing/ExpressionParts.h +++ b/src/Processing/ExpressionParts.h @@ -87,8 +87,8 @@ class CExpressionValue _dbl = 0.0; _bln = false; _type = vtDouble; - _matrix = NULL; - _band = NULL; + _matrix = nullptr; + _band = nullptr; } ~CExpressionValue() @@ -155,7 +155,7 @@ class CExpressionValue { if (_matrix) { delete _matrix; - _matrix = NULL; + _matrix = nullptr; } } @@ -288,7 +288,7 @@ class CustomFunction CStringW GetName() { return _aliases[0]; } - int numParams() { return _params.size(); } + int numParams() { return static_cast(_params.size()); } bool useGeometry() { return _useGeometry; } @@ -315,7 +315,7 @@ class CustomFunction { if (parameterIndex < 0 || parameterIndex >= static_cast(_params.size())) { - return NULL; + return nullptr; } return _params[parameterIndex]; @@ -346,8 +346,8 @@ class CExpressionPart { isArgument = false; activeCount = 0; - function = NULL; - val = NULL; + function = nullptr; + val = nullptr; } ~CExpressionPart() @@ -360,6 +360,6 @@ class CExpressionPart void ReleaseValue(); public: - bool isFunction() { return function != NULL; } + bool isFunction() { return function != nullptr; } void Reset(); }; \ No newline at end of file diff --git a/src/Processing/JenksBreaks.cpp b/src/Processing/JenksBreaks.cpp index 283ced23..0054399d 100644 --- a/src/Processing/JenksBreaks.cpp +++ b/src/Processing/JenksBreaks.cpp @@ -33,7 +33,7 @@ CJenksBreaks::CJenksBreaks(std::vector* values, int numClasses) { _init = false; - if ((int)values->size() < numClasses) + if (static_cast(values->size()) < numClasses) { // it doesn't make any sense to create Jenks breaks // more simple classification shall be used @@ -43,10 +43,10 @@ CJenksBreaks::CJenksBreaks(std::vector* values, int numClasses) if (numClasses > 0) { _numClasses = numClasses; - _numValues = values->size(); - - double classCount = (double)_numValues/(double)numClasses; - sort(values->begin(), values->end()); //values sould be sorted + _numValues = static_cast(values->size()); + + double classCount = static_cast(_numValues)/static_cast(numClasses); + sort(values->begin(), values->end()); //values should be sorted // fill values for (int i = 0; i < _numValues; i++) @@ -54,7 +54,7 @@ CJenksBreaks::CJenksBreaks(std::vector* values, int numClasses) JenksData data; data.value = (*values)[i]; data.square = pow((*values)[i], 2.0); - data.classId = int(floor(i/classCount)); + data.classId = static_cast(floor(i / classCount)); _values.push_back(data); } @@ -118,7 +118,7 @@ std::vector* CJenksBreaks::get_Results() } else { - return NULL; + return nullptr; } } @@ -133,7 +133,7 @@ void CJenksBreaks::Optimize() // initialization double minValue = get_SumStandardDeviations(); // current best minimum _leftBound = 0; // we'll consider all classes in the beginning - _rightBound = _classes.size() - 1; + _rightBound = static_cast(_classes.size() - 1); _previousMaxId = -1; _previousTargetId = - 1; int numAttemmpts = 0; @@ -379,7 +379,7 @@ std::vector* CJenksBreaks::SolveAsDP(std::vector& data, int numClas for(size_t m = 1; m <= l; m++) { - int i = l - m; + int i = static_cast(l - m); double val = data[i]; s2 += val * val; s1 += val; @@ -391,7 +391,7 @@ std::vector* CJenksBreaks::SolveAsDP(std::vector& data, int numClas double newVal = values[i][j - 1] + SSD; if(newVal <= values[l][j]) // if new class is better than previous than let's write it { - values[l][j] = (float)newVal; + values[l][j] = static_cast(newVal); chosen[l][j] = i; } } @@ -399,10 +399,10 @@ std::vector* CJenksBreaks::SolveAsDP(std::vector& data, int numClas } // building result - int k = numValues; + auto k = numValues; std::vector* result = new std::vector(); result->resize(numClasses); - for(int j = result->size() - 1; j >= 1; j--) + for(size_t j = result->size() - 1; j >= 1; j--) { int id = chosen[k][j] - 1; (*result)[j - 1] = id; @@ -419,7 +419,7 @@ std::vector* CJenksBreaks::SolveAsDP(std::vector& data, int numClas // For testing only std::vector* CJenksBreaks::BuildEqualBreaks(std::vector& data, int numClasses) { - int numValues = data.size(); + int numValues = static_cast(data.size()); std::vector* result = new std::vector; result->resize(numClasses + 1); diff --git a/src/Processing/PointInPolygon.h b/src/Processing/PointInPolygon.h index 945fcf77..51dd4bee 100644 --- a/src/Processing/PointInPolygon.h +++ b/src/Processing/PointInPolygon.h @@ -8,7 +8,7 @@ class CPointInPolygon { deque _polyY; deque _scanX; // line data for a single scan (y = const) deque _scanParts; -public: +public: // ************************************************** // setPolygon // ************************************************** @@ -17,14 +17,14 @@ class CPointInPolygon { if (!poly) return false; - ShpfileType shptype; - poly->get_ShapeType(&shptype); + ShpfileType shpType; + poly->get_ShapeType(&shpType); - if(shptype != SHP_POLYGON && shptype != SHP_POLYGONZ && shptype != SHP_POLYGONM ) + if(shpType != SHP_POLYGON && shpType != SHP_POLYGONZ && shpType != SHP_POLYGONM ) { return false; } - + _polyParts.clear(); _polyX.clear(); _polyY.clear(); @@ -36,23 +36,23 @@ class CPointInPolygon { if(numParts == 0) { - _polyParts.push_back(0); + _polyParts.push_back(0); } else { long part =0; for( int j = 0; j < numParts; j++ ) - { + { poly->get_Part(j,&part); _polyParts.push_back(part); } } - + VARIANT_BOOL ret; double x = 0.0; double y = 0.0; for( int i = 0; i < numPoints; i++ ) - { + { poly->get_XY(i, &x, &y, &ret); _polyX.push_back(x); _polyY.push_back(y); @@ -69,12 +69,12 @@ class CPointInPolygon { _scanX.clear(); _scanParts.clear(); - long numParts = _polyParts.size(); + long numParts = static_cast(_polyParts.size()); for (long j = 0; j < numParts; j++) { long start = _polyParts[j]; - long end = (j == numParts - 1) ? _polyX.size(): _polyParts[j + 1]; + long end = (j == numParts - 1) ? static_cast(_polyX.size()): _polyParts[j + 1]; bool partEmpty = true; @@ -95,7 +95,7 @@ class CPointInPolygon { _scanX.push_back(x); if (partEmpty) { - _scanParts.push_back(_scanX.size() - 1); // save the index of the first intersection for a part + _scanParts.push_back(static_cast(_scanX.size()) - 1); // save the index of the first intersection for a part partEmpty = false; } } @@ -105,7 +105,7 @@ class CPointInPolygon { sort(_scanX.begin() + _scanParts[_scanParts.size() - 1], _scanX.end()); } } - + #ifdef _DEBUG CString temp; CString s; @@ -142,7 +142,7 @@ class CPointInPolygon { { int count = 0; long start = _scanParts[j]; - long end = (j == numParts - 1) ? _scanX.size(): _scanParts[j + 1]; + long end = (j == numParts - 1) ? static_cast(_scanX.size()): _scanParts[j + 1]; for (long i = start; i < end; i++) { if (_scanX[i] < x) diff --git a/src/Processing/QTree.cpp b/src/Processing/QTree.cpp index 069f8712..98158944 100644 --- a/src/Processing/QTree.cpp +++ b/src/Processing/QTree.cpp @@ -43,7 +43,7 @@ QTree::~QTree(void) void QTree::Regenerate() { - const unsigned int nodeNumber = nodes.size(); + const int nodeNumber = static_cast(nodes.size()); const double middleX = (this->extent.left + this->extent.right) / 2; const double middleY = (this->extent.top + this->extent.bottom) / 2; @@ -221,7 +221,7 @@ void QTree::AddNode(const QTreeNode& node) bool QTree::RemoveNode(int index) { - for (int i = nodes.size() - 1; i >= 0; i--) + for (int i = static_cast(nodes.size()) - 1; i >= 0; i--) { if (nodes[i]->index == index) { @@ -230,7 +230,6 @@ bool QTree::RemoveNode(int index) nodes.erase(nodes.begin() + i); return true; } - } if (LT != nullptr && LT->RemoveNode(index)) { @@ -306,7 +305,7 @@ vector QTree::GetNodes(QTreeExtent queryExtent) } } } - for (int i = nodes.size() - 1; i >= 0; i--) + for (int i = static_cast(nodes.size()) - 1; i >= 0; i--) { if (nodes[i]->Extent.IntersectIn(queryExtent)) result.push_back(nodes[i]->index); diff --git a/src/ShapeNetwork/graph.cpp b/src/ShapeNetwork/graph.cpp index ed7a1d50..bf6eab27 100644 --- a/src/ShapeNetwork/graph.cpp +++ b/src/ShapeNetwork/graph.cpp @@ -7,13 +7,13 @@ graph::graph() graph::~graph() { for( int i = 0; i < (int)edges.size(); i++ ) - { if( edges[i] != NULL ) + { if( edges[i] != nullptr) delete edges[i]; - edges[i] = NULL; + edges[i] = nullptr; } - for( int j = 0; j < (int)graphnodes.size(); j++ ) + for( int j = 0; j < static_cast(graphnodes.size()); j++ ) { delete graphnodes[j]; - graphnodes[j] = NULL; + graphnodes[j] = nullptr; } } @@ -27,7 +27,7 @@ long graph::Insert( edge * e, void * exParam, bool (* CALLBACK_EQUALS)( void * d long oneIndex = 0, twoIndex = 0; - for( int i = 0; i < (int)graphnodes.size(); i++ ) + for( int i = 0; i < static_cast(graphnodes.size()); i++ ) { if( !one_equal ) { if( CALLBACK_EQUALS(e->one->data, graphnodes[i]->data, exParam ) == true ) @@ -53,17 +53,17 @@ long graph::Insert( edge * e, void * exParam, bool (* CALLBACK_EQUALS)( void * d } if( one_equal == false ) - { oneIndex = graphnodes.size(); + { oneIndex = static_cast(graphnodes.size()); graphnodes.push_back(e->one); } if( two_equal == false ) - { twoIndex = graphnodes.size(); + { twoIndex = static_cast(graphnodes.size()); graphnodes.push_back(e->two); } e->oneIndex = oneIndex; e->twoIndex = twoIndex; - long position = edges.size(); + long position = static_cast(edges.size()); e->one->edges.push_back(position); e->two->edges.push_back(position); edges.push_back( e ); @@ -72,17 +72,17 @@ long graph::Insert( edge * e, void * exParam, bool (* CALLBACK_EQUALS)( void * d } void graph::InsertBlank() -{ edges.push_back( NULL ); +{ edges.push_back( nullptr ); } void graph::Save(const char * filename, void (*PRINT_DATA)( ofstream & out, void * data ) ) { ofstream outf("graph.txt"); - for( int j = 0; j < (int)graphnodes.size(); j++ ) + for( int j = 0; j < static_cast(graphnodes.size()); j++ ) { PRINT_DATA( outf, graphnodes[j]->data ); outf<<"\t:"; - for( int i = 0; i < (int)graphnodes[j]->edges.size(); i++ ) + for( int i = 0; i < static_cast(graphnodes[j]->edges.size()); i++ ) outf<edges[i]<<" "; outf<(all_nodes.size()); } inline void heap::trickleUp() -{ - long index = all_nodes.size() - 1 ; +{ + long index = static_cast(all_nodes.size()) - 1 ; long parent; bool trickle = true; - heapnode tempNode; + heapnode tempNode; while( trickle ) - { + { //Even Kid if( index % 2 == 0 ) parent = ( index - 2 ) / 2;//*.5; @@ -58,7 +59,8 @@ inline void heap::trickleUp() } void heap::pop() -{ all_nodes.pop_front(); +{ + all_nodes.pop_front(); if( all_nodes.size() > 1 ) { all_nodes.push_front( all_nodes[ all_nodes.size() - 1 ] ); all_nodes.pop_back(); @@ -67,14 +69,15 @@ void heap::pop() } heapnode heap::top() -{ if( all_nodes.size() > 0 ) +{ + if( all_nodes.size() > 0 ) return all_nodes[0]; else return heapnode(); } inline void heap::trickleDown() -{ +{ long index = 0; bool trickle = true; long swap_index; @@ -85,7 +88,7 @@ inline void heap::trickleDown() long kid2 = kid1 + 1; swap_index = minValIndex( kid1, kid2 ); - if( swap_index > 0 && swap_index < (int)all_nodes.size() ) + if( swap_index > 0 && swap_index < static_cast(all_nodes.size()) ) { if( all_nodes[index] > all_nodes[swap_index] ) { tempNode = all_nodes[index]; @@ -103,7 +106,7 @@ inline void heap::trickleDown() inline long heap::minValIndex( long kid1, long kid2 ) { - long heap_size = all_nodes.size(); + long heap_size = static_cast(all_nodes.size()); if( kid2 >= heap_size || kid1 >= heap_size ) return kid1; else diff --git a/src/Shapefile/ShapeWrapperCOM.h b/src/Shapefile/ShapeWrapperCOM.h index a3420f0b..9dea2b61 100644 --- a/src/Shapefile/ShapeWrapperCOM.h +++ b/src/Shapefile/ShapeWrapperCOM.h @@ -75,8 +75,8 @@ class CShapeWrapperCOM : public IShapeWrapper public: ShapeWrapperType get_WrapperType() { return ShapeWrapperType::swtCom; } - int get_PointCount(){ return _points.size(); } - int get_PartCount(){ return _parts.size(); } + int get_PointCount(){ return static_cast(_points.size()); } + int get_PartCount(){ return static_cast(_parts.size()); } // type ShpfileType get_ShapeType(){ return _shapeType; } diff --git a/src/Shapefile/ShapefileReader.cpp b/src/Shapefile/ShapefileReader.cpp index f2c062f4..2310538c 100644 --- a/src/Shapefile/ShapefileReader.cpp +++ b/src/Shapefile/ShapefileReader.cpp @@ -13,7 +13,7 @@ bool CShapefileReader::ReadShapefileIndex(CStringW filename, FILE* shpFile, CCri { return false; } - + // reading shape index (SHX) CStringW sFilename = filename; sFilename.SetAt(sFilename.GetLength() - 1, L'x'); @@ -22,23 +22,23 @@ bool CShapefileReader::ReadShapefileIndex(CStringW filename, FILE* shpFile, CCri if (!shxfile ) { - _shpfile = NULL; - _indexData = NULL; + _shpfile = nullptr; + _indexData = nullptr; USES_CONVERSION; CallbackHelper::ErrorMsg(Debug::Format("Failed to open SHX file: %s", OLE2A(sFilename))); return false; } - + fseek (shxfile, 0, SEEK_END); int indexFileSize = ftell(shxfile); rewind(shxfile); - + // 100 is for header fseek(shxfile, 100, SEEK_SET); _indexData = new char[indexFileSize - 100]; - long result = fread(_indexData, sizeof(char), indexFileSize - 100, shxfile); + auto result = fread(_indexData, sizeof(char), indexFileSize - 100, shxfile); fclose(shxfile); //_shpHeader.numShapes = (indexFileSize - 100)/8; // 2 int on record @@ -67,31 +67,31 @@ char* CShapefileReader::ReadShapeData(int& offset, int& recordLength) // index records are 8 bytes; char* data = _indexData + offset*8; SwapEndian(data); - int readOffset = (*(int*)data) * 2; + int readOffset = (*reinterpret_cast(data)) * 2; data = _indexData + offset * 8 + 4; SwapEndian(data); - int contentLength = (*(int*)data); + int contentLength = (*reinterpret_cast(data)); if (contentLength > 0) { CSingleLock lock(_readLock); lock.Lock(); - int ret = fseek(_shpfile, (long)readOffset + 2 * sizeof(int), SEEK_SET); - if (ret != 0) return NULL; + int ret = fseek(_shpfile, static_cast(readOffset) + 2 * sizeof(int), SEEK_SET); + if (ret != 0) return nullptr; // *2: for conversion from 16-bit words to 8-bit words int length = contentLength * 2; char* shapeData = new char[length]; - int count = (int)fread(shapeData, sizeof(char), length, _shpfile); + int count = static_cast(fread(shapeData, sizeof(char), length, _shpfile)); recordLength = length; return shapeData; } - return NULL; + return nullptr; } // **************************************************************** @@ -100,10 +100,10 @@ char* CShapefileReader::ReadShapeData(int& offset, int& recordLength) PolygonData* CShapefileReader::ReadPolygonData(char* data) { PolygonData* shapeData = new PolygonData(); - shapeData->partCount = *(int*)(data + 36); - shapeData->pointCount = *(int*)(data + 40); - shapeData->parts = (int*)(data + 44); - shapeData->points = (double*)(data + 44 + sizeof(int) * shapeData->partCount); + shapeData->partCount = *reinterpret_cast(data + 36); + shapeData->pointCount = *reinterpret_cast(data + 40); + shapeData->parts = reinterpret_cast(data + 44); + shapeData->points = reinterpret_cast(data + 44 + sizeof(int) * shapeData->partCount); return shapeData; } @@ -111,9 +111,9 @@ PolygonData* CShapefileReader::ReadMultiPointData(char* data) { PolygonData* shapeData = new PolygonData(); shapeData->partCount = 0; - shapeData->pointCount = *(int*)(data + 36); - shapeData->parts = NULL; - shapeData->points = (double*)(data + 40); + shapeData->pointCount = *reinterpret_cast(data + 36); + shapeData->parts = nullptr; + shapeData->points = reinterpret_cast(data + 40); return shapeData; } diff --git a/src/Structures/DrawList.h b/src/Structures/DrawList.h index ec96dfa2..c36cd806 100644 --- a/src/Structures/DrawList.h +++ b/src/Structures/DrawList.h @@ -33,20 +33,20 @@ struct _DrawCircle }; struct _DrawPolygon -{ +{ _DrawPolygon() - { xpnts=NULL; - ypnts=NULL; + { xpnts = nullptr; + ypnts = nullptr; } ~_DrawPolygon() { if( xpnts ) delete [] xpnts; - xpnts = NULL; + xpnts = nullptr; if( ypnts ) delete [] ypnts; - ypnts = NULL; + ypnts = nullptr; } - + double * xpnts; double * ypnts; long numPoints; @@ -57,30 +57,30 @@ struct _DrawPolygon }; class DrawList //: public LabelLayer -{ +{ public: DrawList() { key = SysAllocString(L""); - m_labels = NULL; - CoCreateInstance(CLSID_Labels,NULL,CLSCTX_INPROC_SERVER,IID_ILabels,(void**)&m_labels); + m_labels = nullptr; + CoCreateInstance(CLSID_Labels, nullptr,CLSCTX_INPROC_SERVER,IID_ILabels,(void**)&m_labels); } ~DrawList() { ::SysFreeString(key); register int i; - int endcondition = m_dpoints.size(); + auto endcondition = static_cast(m_dpoints.size()); for(i=0;i(m_dlines.size()); for(i=0;i(m_dcircles.size()); for(i=0;i(m_dpolygons.size()); for(i=0;iRelease(); } - + tkDrawReferenceList listType; BSTR key; diff --git a/src/Tiles/Caching/DiskCache.cpp b/src/Tiles/Caching/DiskCache.cpp index fa51cb83..1959b5b3 100644 --- a/src/Tiles/Caching/DiskCache.cpp +++ b/src/Tiles/Caching/DiskCache.cpp @@ -30,7 +30,7 @@ void DiskCache::InitEncoder() { if (_ext.GetLength() >= 4) { - const CStringW s = _ext.Mid(0, 4).MakeLower(); // try to guess it from input + const CStringW s = _ext.Mid(0, 4).MakeLower(); // try to guess it from input if (s == L".png") { @@ -110,7 +110,7 @@ void DiskCache::AddTile(TileCore* tile) for (size_t i = 0; i < tile->Overlays.size(); i++) { - bmp = tile->get_Bitmap(i)->m_bitmap; + bmp = tile->get_Bitmap(static_cast(i))->m_bitmap; if (bmp) { g->DrawImage(bmp, 0.0f, 0.0f); @@ -118,7 +118,7 @@ void DiskCache::AddTile(TileCore* tile) } USES_CONVERSION; - const CStringW path = tile->GetPath(_rootPath, _ext); + const CStringW path = tile->GetPath(_rootPath, _ext); bmp->Save(path, &_pngClsid, nullptr); delete g; diff --git a/src/Tiles/Caching/PrefetchManager.cpp b/src/Tiles/Caching/PrefetchManager.cpp index 383258a3..3f8e2ef2 100644 --- a/src/Tiles/Caching/PrefetchManager.cpp +++ b/src/Tiles/Caching/PrefetchManager.cpp @@ -68,10 +68,10 @@ void PrefetchManager::BuildDownloadList(BaseProvider* provider, int zoom, CRect provider->get_Projection()->GetTileMatrixMinXY(zoom, size1); provider->get_Projection()->GetTileMatrixMaxXY(zoom, size2); - const int minX = (int)BaseProjection::Clip(indices.left, size1.cx, size2.cx); - const int maxX = (int)BaseProjection::Clip(indices.right, size1.cy, size2.cy); - const int minY = (int)BaseProjection::Clip(MIN(indices.top, indices.bottom), size1.cx, size2.cx); - const int maxY = (int)BaseProjection::Clip(MAX(indices.top, indices.bottom), size1.cy, size2.cy); + const int minX = static_cast(BaseProjection::Clip(indices.left, size1.cx, size2.cx)); + const int maxX = static_cast(BaseProjection::Clip(indices.right, size1.cy, size2.cy)); + const int minY = static_cast(BaseProjection::Clip(MIN(indices.top, indices.bottom), size1.cx, size2.cx)); + const int maxY = static_cast(BaseProjection::Clip(MAX(indices.top, indices.bottom), size1.cy, size2.cy)); const int centX = (maxX + minX) / 2; const int centY = (maxY + minY) / 2; @@ -138,7 +138,7 @@ long PrefetchManager::Prefetch(BaseProvider* provider, CRect indices, int zoom, // actual call to do the job _loader.Load(points, provider, zoom, info); - const long size = points.size(); + const long size = static_cast(points.size()); TilePoint::ReleaseMemory(points); diff --git a/src/Tiles/Caching/SQLiteCache.cpp b/src/Tiles/Caching/SQLiteCache.cpp index 5e8f70c0..5e6045ef 100644 --- a/src/Tiles/Caching/SQLiteCache.cpp +++ b/src/Tiles/Caching/SQLiteCache.cpp @@ -32,7 +32,7 @@ void SQLiteCache::Close() if (_conn) { sqlite3_close(_conn); - _conn = NULL; + _conn = nullptr; } } @@ -66,7 +66,7 @@ bool SQLiteCache::Initialize(SqliteOpenMode openMode) } } _section.Unlock(); - return _conn != NULL; + return _conn != nullptr; } // *********************************************************** @@ -116,7 +116,7 @@ bool SQLiteCache::set_DbName(CStringW name) CStringW SQLiteCache::get_DefaultDbName() { wchar_t* path = new wchar_t[MAX_PATH + 1]; - GetModuleFileNameW(NULL, path, MAX_PATH); + GetModuleFileNameW(nullptr, path, MAX_PATH); CStringW name = Utility::GetFolderFromPath(path); name += L"\\"; name += DB_NAME; @@ -139,16 +139,16 @@ bool SQLiteCache::CreateDatabase() if (_conn) { int val = sqlite3_close(_conn); - _conn = NULL; + _conn = nullptr; } bool ret = false; - int val = sqlite3_open_v2(name, &_conn, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE| SQLITE_OPEN_FULLMUTEX, NULL); + int val = sqlite3_open_v2(name, &_conn, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE| SQLITE_OPEN_FULLMUTEX, nullptr); if (!val) { char* sql = "CREATE TABLE IF NOT EXISTS Tiles (id INTEGER NOT NULL PRIMARY KEY, X INTEGER NOT NULL, " "Y INTEGER NOT NULL, Zoom INTEGER NOT NULL, Type INTEGER NOT NULL, Size INTEGER NOT NULL, CacheTime DATETIME );"; - val = sqlite3_exec(_conn, sql, NULL, NULL, NULL); + val = sqlite3_exec(_conn, sql, nullptr, nullptr, nullptr); if (!val) { @@ -158,12 +158,12 @@ bool SQLiteCache::CreateDatabase() "UPDATE Tiles SET cacheTime = DATETIME('NOW') WHERE rowid = new.rowid; " "END;"; - val = sqlite3_exec(_conn, s, NULL, NULL, NULL); + val = sqlite3_exec(_conn, s, nullptr, nullptr, nullptr); if (!val) { sql = "CREATE TABLE IF NOT EXISTS TilesData (id INTEGER NOT NULL PRIMARY KEY CONSTRAINT fk_Tiles_id " "REFERENCES Tiles(id) ON DELETE CASCADE, Tile BLOB NULL);"; - val = sqlite3_exec(_conn, sql, NULL, NULL, NULL); + val = sqlite3_exec(_conn, sql, nullptr, nullptr, nullptr); if (!val) { @@ -173,7 +173,7 @@ bool SQLiteCache::CreateDatabase() "DELETE from TilesData WHERE TilesData.Id = OLD.id; " "END;"; - return !sqlite3_exec(_conn, sql, NULL, NULL, NULL); + return !sqlite3_exec(_conn, sql, nullptr, nullptr, nullptr); } } } @@ -201,7 +201,7 @@ void SQLiteCache::AddTile(TileCore* tile) sqlite3_stmt *stmt; for (size_t i = 0; i < tile->Overlays.size(); i++) { - CMemoryBitmap* bmp = tile->get_Bitmap(i); + CMemoryBitmap* bmp = tile->get_Bitmap(static_cast(i)); if (bmp) { int size = bmp->get_Size(); @@ -212,7 +212,7 @@ void SQLiteCache::AddTile(TileCore* tile) if (val != SQLITE_OK) { -#ifdef DEBUG_LOG +#ifndef RELEASE_MODE auto sqlite3_error = sqlite3_errmsg(_conn); auto errorCode = sqlite3_extended_errcode(_conn); CallbackHelper::ErrorMsg(Debug::Format("SQLiteCache::DoCaching: Failed to prepare statement errorNo: %d Message: %s", errorCode, sqlite3_error)); @@ -241,7 +241,7 @@ void SQLiteCache::AddTile(TileCore* tile) memcpy(data, hMem, size); ::GlobalUnlock(hMem); - val = sqlite3_bind_blob(stmt, 2, data, size, NULL); + val = sqlite3_bind_blob(stmt, 2, data, size, nullptr); val = sqlite3_step(stmt); if (val == SQLITE_OK || val == SQLITE_DONE) @@ -282,8 +282,7 @@ void SQLiteCache::AutoClear() try { _section.Lock(); - CString sql; - sql = "SELECT Size, CacheTime FROM Tiles ORDER BY CacheTime ASC"; + CString sql = "SELECT Size, CacheTime FROM Tiles ORDER BY CacheTime ASC"; const char *tail; sqlite3_stmt *stmt; @@ -313,7 +312,7 @@ void SQLiteCache::AutoClear() sql = "DELETE FROM Tiles"; } - val = sqlite3_exec(_conn, sql, NULL, NULL, NULL); + val = sqlite3_exec(_conn, sql, nullptr, nullptr, nullptr); _section.Unlock(); } catch(...) @@ -344,7 +343,7 @@ bool SQLiteCache::get_TileExists(BaseProvider* provider, int scale, int x, int y CString sql; sql.Format("SELECT id FROM Tiles WHERE X = %d AND Y = %d AND Zoom = %d AND Type = %d", x, y, scale, provider->Id); int val = sqlite3_prepare_v2(_conn, sql, sql.GetLength() + 1, &stmt, &tail); - + _section.Lock(); if( sqlite3_step(stmt) != SQLITE_ROW) { @@ -356,7 +355,6 @@ bool SQLiteCache::get_TileExists(BaseProvider* provider, int scale, int x, int y if (!exists) break; } - } catch (...) { @@ -373,10 +371,10 @@ bool SQLiteCache::get_TileExists(BaseProvider* provider, int scale, int x, int y // Extracts a tile from the database TileCore* SQLiteCache::get_Tile(BaseProvider* provider, int scale, int x, int y) { - TileCore* tile = NULL; + TileCore* tile = nullptr; if(!Initialize(SqliteOpenMode::OpenIfExists)) - return NULL; + return nullptr; _section.Lock(); @@ -399,18 +397,18 @@ TileCore* SQLiteCache::get_Tile(BaseProvider* provider, int scale, int x, int y) sqlite3_stmt *stmt2; sqlite3_int64 id = sqlite3_column_int64(stmt, 0); sql.Format("SELECT tile FROM TilesData WHERE Id = %d", id); - + if (sqlite3_prepare_v2(_conn, sql, sql.GetLength() + 1, &stmt2, &tail2) == SQLITE_OK) { if (sqlite3_step(stmt2) == SQLITE_ROW) { const void* data = sqlite3_column_blob(stmt2, 0); int size = sqlite3_column_bytes(stmt2, 0); - + if (size > 0) { CMemoryBitmap* bmp = new CMemoryBitmap(); - if (bmp->LoadFromRawData((const char*)data, size)) + if (bmp->LoadFromRawData(static_cast(data), size)) { if (i == 0) tile = new TileCore(providerId, scale, CPoint(x, y), provider->get_Projection()); @@ -437,7 +435,7 @@ TileCore* SQLiteCache::get_Tile(BaseProvider* provider, int scale, int x, int y) if (tile && tile->Overlays.size() != provider->get_SubProviders()->size()) { delete tile; - tile = NULL; + tile = nullptr; } // for composite providers @@ -461,21 +459,21 @@ void SQLiteCache::Clear(int providerId, int fromScale, int toScale) { if(!Initialize(SqliteOpenMode::OpenIfExists)) return; - + // there is no need to delete from tilesdata table as there is ON CASCADE DELETE rule specified in foreign key constraint // updated: in fact there is a trigger which does the job CString temp; CString sql = "DELETE FROM TILES"; - - if (providerId != (int)tkTileProvider::ProviderNone || fromScale != 0 || toScale != 100) + + if (providerId != static_cast(tkTileProvider::ProviderNone) || fromScale != 0 || toScale != 100) sql += " WHERE "; - - if (providerId != (int)tkTileProvider::ProviderNone) + + if (providerId != static_cast(tkTileProvider::ProviderNone)) { temp.Format(" Type = %d", providerId); sql += temp; } - + if (fromScale != 0 || toScale != 100) { if (temp.GetLength() > 0) @@ -484,9 +482,9 @@ void SQLiteCache::Clear(int providerId, int fromScale, int toScale) temp.Format(" Zoom >= %d AND Zoom <= %d ", fromScale, toScale); sql += temp; } - + _section.Lock(); - int val = sqlite3_exec(_conn, sql, NULL, NULL, NULL); + int val = sqlite3_exec(_conn, sql, nullptr, nullptr, nullptr); _section.Unlock(); } @@ -494,10 +492,10 @@ void SQLiteCache::Clear(int providerId, int fromScale, int toScale) // get_FileSize() // **************************************************************** double SQLiteCache::get_SizeMB() -{ +{ if(!Initialize(SqliteOpenMode::OpenIfExists)) return 0.0; - + const char *tail; sqlite3_stmt *stmt; @@ -505,7 +503,7 @@ double SQLiteCache::get_SizeMB() CString sql = "SELECT SUM(size) FROM Tiles"; int val = sqlite3_prepare_v2(_conn, sql, sql.GetLength() + 1, &stmt, &tail); - + if (val != SQLITE_OK) { CallbackHelper::ErrorMsg(Debug::Format("SQLiteCache::get_FileSize: Failed to prepare statement; %d.", val)); @@ -519,7 +517,7 @@ double SQLiteCache::get_SizeMB() _section.Unlock(); val = sqlite3_finalize(stmt); } - return (double)size/(double)(0x1 << 20); + return static_cast(size)/static_cast(0x1 << 20); } // **************************************************************** @@ -529,7 +527,7 @@ double SQLiteCache::get_SizeMB(int providerId, int scale) { if(!Initialize(SqliteOpenMode::OpenIfExists)) return 0.0; - + int size = 0; double result = 0.0; const char *tail; @@ -538,11 +536,11 @@ double SQLiteCache::get_SizeMB(int providerId, int scale) try { CString sql = "SELECT size FROM Tiles"; - if (providerId != (int)tkTileProvider::ProviderNone || scale != -1) + if (providerId != static_cast(tkTileProvider::ProviderNone) || scale != -1) sql += " WHERE "; - + CString temp; - if (providerId != (int)tkTileProvider::ProviderNone) + if (providerId != static_cast(tkTileProvider::ProviderNone)) { temp.Format("Type = %d", providerId); sql += temp; @@ -569,7 +567,7 @@ double SQLiteCache::get_SizeMB(int providerId, int scale) CallbackHelper::ErrorMsg("SQLiteCache: exception on getting file size."); } - return (double)size/(double)(0x1 << 20); + return static_cast(size)/static_cast(0x1 << 20); } // **************************************************************** @@ -588,7 +586,7 @@ long SQLiteCache::get_TileCount(int provider, int zoom, CRect indices) { CString format = "SELECT count(*) FROM Tiles Where Type = %d and Zoom = %d and X >= %d and " "X <= %d and Y >= %d and Y <= %d"; - + CString sql; sql.Format(format, provider, zoom, indices.left, indices.right, indices.bottom, indices.top); @@ -597,8 +595,8 @@ long SQLiteCache::get_TileCount(int provider, int zoom, CRect indices) if (!val) { int size = 0; - - _section.Lock(); + + _section.Lock(); if( sqlite3_step(stmt) == SQLITE_ROW) size = sqlite3_column_int(stmt, 0); val = sqlite3_finalize(stmt); @@ -629,13 +627,13 @@ bool SQLiteCache::get_TilesXY(int provider, int zoom, int xMin, int xMax, int yM { CString format = "SELECT X, Y FROM Tiles Where Type = %d and Zoom = %d and X >= %d and " "X <= %d and Y >= %d and Y <= %d"; - + CString sql; sql.Format(format, provider, zoom, xMin, xMax, yMin, yMax); _section.Lock(); int val = sqlite3_prepare_v2(_conn, sql, sql.GetLength() + 1, &stmt, &tail); - + while( sqlite3_step(stmt) == SQLITE_ROW) { int x = sqlite3_column_int(stmt, 0); diff --git a/src/Tiles/Http/SecureHttpClient.cpp b/src/Tiles/Http/SecureHttpClient.cpp index 5ec4e91e..259e2262 100644 --- a/src/Tiles/Http/SecureHttpClient.cpp +++ b/src/Tiles/Http/SecureHttpClient.cpp @@ -30,7 +30,7 @@ SecureHttpClient::SecureHttpClient(): file(nullptr) curl = curl_easy_init(); // set up write buffer - chunk.memory = (char *)malloc(1); /* will be grown as needed */ + chunk.memory = static_cast(malloc(1)); /* will be grown as needed */ chunk.size = 0; /* no data yet */ /* PM: Add user agent */ @@ -40,15 +40,15 @@ SecureHttpClient::SecureHttpClient(): file(nullptr) curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); /* we pass our 'chunk' struct to the callback function */ - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, static_cast(&chunk)); } size_t SecureHttpClient::WriteMemoryCallback(void* contents, size_t size, size_t nmemb, void* userp) { const size_t realsize = size * nmemb; - auto* mem = (struct MemoryStruct *)userp; + auto* mem = static_cast(userp); - mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1); + mem->memory = static_cast(realloc(mem->memory, mem->size + realsize + 1)); if (mem->memory == nullptr) { /* out of memory! */ @@ -95,8 +95,8 @@ bool SecureHttpClient::SetProxyAndAuthentication(const CString& userName, const } //curlCode = curl_easy_setopt(curl, CURLOPT_PROXY, (LPCTSTR)domain); - curlCode = curl_easy_setopt(curl, CURLOPT_USERNAME, (LPCTSTR)userName); - curlCode = curl_easy_setopt(curl, CURLOPT_PASSWORD, (LPCTSTR)password); + curlCode = curl_easy_setopt(curl, CURLOPT_USERNAME, static_cast(userName)); + curlCode = curl_easy_setopt(curl, CURLOPT_PASSWORD, static_cast(password)); // TODO: this needs to be expanded to have more options, e.g. hidden auth is now impossible if (m_globalSettings.proxyAuthentication == tkProxyAuthentication::asNtlm) @@ -112,7 +112,7 @@ bool SecureHttpClient::SetProxyAndAuthentication(const CString& userName, const // ************************************************************* int SecureHttpClient::GetBodyLength() const { - return chunk.size; + return static_cast(chunk.size); } // ************************************************************* @@ -120,7 +120,7 @@ int SecureHttpClient::GetBodyLength() const // ************************************************************* BYTE* SecureHttpClient::GetBody() const { - return (BYTE*)chunk.memory; + return reinterpret_cast(chunk.memory); } // ************************************************************* @@ -161,7 +161,7 @@ TileHttpContentType SecureHttpClient::get_ContentType(int providerId) const return TileHttpContentType::httpXml; } - if (providerId == (int)tkTileProvider::Rosreestr) + if (providerId == static_cast(tkTileProvider::Rosreestr)) { // ad-hoc fix return TileHttpContentType::httpImage; diff --git a/src/Tiles/Projections/BaseProjection.h b/src/Tiles/Projections/BaseProjection.h index cdbbc596..1b924b85 100644 --- a/src/Tiles/Projections/BaseProjection.h +++ b/src/Tiles/Projections/BaseProjection.h @@ -72,7 +72,6 @@ class BaseProjection public: virtual void FromLatLngToXY(PointLatLng pnt, int zoom, CPoint& ret) = 0; - virtual void FromXYToLatLng(CPoint pnt, int zoom, PointLatLng& ret) = 0; virtual void FromXYToProj(CPoint pnt, int zoom, PointLatLng& ret) = 0; virtual double GetWidth() = 0; diff --git a/src/Tiles/Projections/CustomProjection.cpp b/src/Tiles/Projections/CustomProjection.cpp index a73c8763..a1e3eb28 100644 --- a/src/Tiles/Projections/CustomProjection.cpp +++ b/src/Tiles/Projections/CustomProjection.cpp @@ -31,16 +31,9 @@ void CustomProjection::FromLatLngToXY(PointLatLng pnt, int zoom, CPoint &ret) double lat = pnt.Lat; double lng = pnt.Lng; -#if DEBUG - CComBSTR bstr; - CString proj; - _projWGS84->ExportToWktEx(&bstr); - proj = bstr; -#endif - VARIANT_BOOL vb; _projWGS84->Transform(&lng, &lat, &vb); - + FromProjToXY(lat, lng, zoom, ret); } @@ -69,8 +62,8 @@ void CustomProjection::FromProjToXY(double lat, double lng, int zoom, CPoint &re int mapSizeX = s.cx; int mapSizeY = s.cy; - ret.x = (int) Clip(x * mapSizeX, 0, mapSizeX); - ret.y = (int) Clip(y * mapSizeY, 0, mapSizeY); + ret.x = static_cast(Clip(x * mapSizeX, 0, mapSizeX)); + ret.y = static_cast(Clip(y * mapSizeY, 0, mapSizeY)); Clip(ret, zoom); } diff --git a/src/Tiles/Providers/BaseProvider.cpp b/src/Tiles/Providers/BaseProvider.cpp index 9b723a02..1fa3191f 100644 --- a/src/Tiles/Providers/BaseProvider.cpp +++ b/src/Tiles/Providers/BaseProvider.cpp @@ -41,10 +41,6 @@ TileCore* BaseProvider::GetTileImage(CPoint& pos, const int zoom) { auto* tile = new TileCore(this->Id, zoom, pos, this->_projection); // TODO: Fix compile warning auto* customProvider = dynamic_cast(this); - - if (tile->tileX() == 234 && tile->tileY() == 28) - ::OutputDebugStringA("\r\n"); - if (customProvider != nullptr) { auto bbOrder = customProvider->get_BoundingBoxOrder(); @@ -122,18 +118,18 @@ CMemoryBitmap* BaseProvider::GetTileFileData(CString url) return nullptr; fl.seekg(0, std::ios::end); - const int sz = fl.tellg(); + const std::streamoff sz = fl.tellg(); if (sz == 0) return nullptr; - std::vector buf(sz); + std::vector buf(static_cast(sz)); fl.seekg(0, std::ios::beg); fl.read(buf.data(), buf.size()); if (!fl) return nullptr; - return ReadBitmap(buf.data(), buf.size()); + return ReadBitmap(buf.data(), static_cast(buf.size())); } // ************************************************************ @@ -185,10 +181,12 @@ CMemoryBitmap* BaseProvider::ProcessHttpRequest(void* secureHttpClient, const CS case TileHttpContentType::httpXml: if (IsWms()) { +#ifndef RELEASE_MODE auto status = client->GetStatus(); CString sOutput; sOutput.AppendFormat("WMS server response status: %d", status); ::OutputDebugStringA(sOutput.GetBuffer()); +#endif const CString s(body); ParseServerException(s); } diff --git a/src/Tiles/Providers/CustomTileProvider.cpp b/src/Tiles/Providers/CustomTileProvider.cpp index 1f792560..33dd8259 100644 --- a/src/Tiles/Providers/CustomTileProvider.cpp +++ b/src/Tiles/Providers/CustomTileProvider.cpp @@ -95,7 +95,7 @@ CString CustomTileProvider::MakeTileImageUrl(CPoint &pos, int zoom) if (_pattern.GetLength() != 0 && _tokens.size() > 0) { - int val = GetServerNum(pos, _tokens.size()); + int val = GetServerNum(pos, static_cast(_tokens.size())); url.Replace(_pattern, _tokens[val]); } return url; diff --git a/src/Tiles/TileManager.cpp b/src/Tiles/TileManager.cpp index 593c6e6e..908e80e5 100644 --- a/src/Tiles/TileManager.cpp +++ b/src/Tiles/TileManager.cpp @@ -106,7 +106,7 @@ void TileManager::LoadTiles(BaseProvider* provider, bool isSnapshot, const CStri // it will be considered completed when this amount of tiles is loaded if (!cacheOnly) { - requestInfo->totalCount = activeTasks.size() + points.size(); + requestInfo->totalCount = static_cast(activeTasks.size() + points.size()); } // delete unused tiles from the screen buffer diff --git a/src/Tin/TinHeap.cpp b/src/Tin/TinHeap.cpp index 895145d9..e4e1f6c4 100644 --- a/src/Tin/TinHeap.cpp +++ b/src/Tin/TinHeap.cpp @@ -11,7 +11,7 @@ TinHeap::~TinHeap() { } void TinHeap::clear() -{ +{ all_nodes.clear(); } @@ -27,15 +27,15 @@ void TinHeap::insert( long triangleIndex, double dev, vertex v ) } inline void TinHeap::trickleUp() -{ - long index = all_nodes.size() - 1 ; +{ + long index = static_cast(all_nodes.size()) - 1 ; long parent; bool trickle = true; heapNode tempNode; while( trickle ) - { + { //Even Kid if( index % 2 == 0 ) parent = ( index - 2 ) / 2; //*.5; @@ -65,7 +65,7 @@ void TinHeap::pop() { all_nodes.push_front( all_nodes[ all_nodes.size() - 1 ] ); all_nodes.pop_back(); trickleDown(); - } + } } heapNode TinHeap::top() @@ -87,12 +87,12 @@ inline void TinHeap::trickleDown() long kid2 = kid1 + 1; swap_index = maxValIndex( kid1, kid2 ); - if( swap_index > 0 && swap_index < (int)all_nodes.size() ) + if( swap_index > 0 && swap_index < static_cast(all_nodes.size()) ) { if( all_nodes[index] < all_nodes[swap_index] ) { tempNode = all_nodes[index]; all_nodes[index] = all_nodes[swap_index]; - all_nodes[swap_index] = tempNode; + all_nodes[swap_index] = tempNode; index = swap_index; } else @@ -105,11 +105,12 @@ inline void TinHeap::trickleDown() inline long TinHeap::maxValIndex( long kid1, long kid2 ) { - long heap_size = all_nodes.size(); + long heap_size = static_cast(all_nodes.size()); if( kid2 >= heap_size || kid1 >= heap_size ) return kid1; else - { if( all_nodes[kid1] > all_nodes[kid2] ) + { + if( all_nodes[kid1] > all_nodes[kid2] ) return kid1; else return kid2; diff --git a/src/Tin/point_table.cpp b/src/Tin/point_table.cpp index a2bf09c7..4ebba8f3 100644 --- a/src/Tin/point_table.cpp +++ b/src/Tin/point_table.cpp @@ -7,7 +7,7 @@ point_table::point_table() long point_table::add( Point p ) { point_list.push_back( p ); - return point_list.size() - 1; + return static_cast(point_list.size()) - 1; } void point_table::clear() diff --git a/src/Tin/point_table.h b/src/Tin/point_table.h index 6a271f6f..83704bfd 100644 --- a/src/Tin/point_table.h +++ b/src/Tin/point_table.h @@ -11,8 +11,8 @@ class point_table Point getPoint( long index ); void clear(); int size() - { return point_list.size(); } - private: + { return static_cast(point_list.size()); } + private: std::deque point_list; }; diff --git a/src/Tin/triangle_table.cpp b/src/Tin/triangle_table.cpp index 74028b2a..69b3e966 100644 --- a/src/Tin/triangle_table.cpp +++ b/src/Tin/triangle_table.cpp @@ -2,7 +2,7 @@ # include "triangle_table.h" triangleTable::triangleTable() -{ +{ } triangleTable::~triangleTable() @@ -10,9 +10,9 @@ triangleTable::~triangleTable() } void triangleTable::clear() -{ for( int i = 0; i < (int)rows.size(); i++ ) +{ for( int i = 0; i < static_cast(rows.size()); i++ ) { delete rows[i]; - rows[i] = NULL; + rows[i] = nullptr; } rows.clear(); } @@ -46,28 +46,28 @@ void * triangleTable::getValue( COLUMN column, long row ) void triangleTable::setValue( COLUMN column, long row, void * value ) { if( column == VTX_ONE ) - rows[row]->row.vertexOne = *((long*)value); + rows[row]->row.vertexOne = *static_cast(value); else if( column == VTX_TWO ) - rows[row]->row.vertexTwo = *((long*)value); + rows[row]->row.vertexTwo = *static_cast(value); else if( column == VTX_THREE ) - rows[row]->row.vertexThree = *((long*)value); + rows[row]->row.vertexThree = *static_cast(value); else if( column == BDR_ONE ) - rows[row]->row.borderOne = *((long*)value); + rows[row]->row.borderOne = *static_cast(value); else if( column == BDR_TWO ) - rows[row]->row.borderTwo = *((long*)value); + rows[row]->row.borderTwo = *static_cast(value); else if( column == BDR_THREE ) - rows[row]->row.borderThree = *((long*)value); + rows[row]->row.borderThree = *static_cast(value); else if( column == DEV_VERTEX ) - rows[row]->row.devVertex = *((vertex*)value); + rows[row]->row.devVertex = *static_cast(value); else if( column == MAX_DEV ) - rows[row]->row.maxDev = *((double*)value); + rows[row]->row.maxDev = *static_cast(value); } long triangleTable::addRow( tinTableRow & r ) { tableRowNode * new_row = new tableRowNode(); new_row->row = r; rows.push_back( new_row ); - return rows.size() - 1; + return static_cast(rows.size()) - 1; } void triangleTable::setRow( tinTableRow & r, long row ) @@ -75,5 +75,5 @@ void triangleTable::setRow( tinTableRow & r, long row ) } long triangleTable::size() -{ return rows.size(); +{ return static_cast(rows.size()); } \ No newline at end of file diff --git a/src/Tin/vertex_table.cpp b/src/Tin/vertex_table.cpp index ef3756f2..406f8946 100644 --- a/src/Tin/vertex_table.cpp +++ b/src/Tin/vertex_table.cpp @@ -11,7 +11,7 @@ vertexTable::~vertexTable() long vertexTable::add( vertex p ) { vertex_list.push_back( p ); - return vertex_list.size() - 1; + return static_cast(vertex_list.size()) - 1; } void vertexTable::clear() @@ -27,5 +27,5 @@ void vertexTable::setVertex( vertex v, long index ) } long vertexTable::size() -{ return vertex_list.size(); +{ return static_cast(vertex_list.size()); } \ No newline at end of file diff --git a/src/Utilities/ColoringGraph.cpp b/src/Utilities/ColoringGraph.cpp index 64cc4319..01290f4f 100644 --- a/src/Utilities/ColoringGraph.cpp +++ b/src/Utilities/ColoringGraph.cpp @@ -41,7 +41,7 @@ namespace Coloring { for(size_t i = 0; i < this->edges.size(); i++) { - this->GetNeighbor(i)->IncrementSpentCount(); + this->GetNeighbor(static_cast(i))->IncrementSpentCount(); } } @@ -132,7 +132,7 @@ namespace Coloring colors.insert(nodes[i]->color); } } - return colors.size(); + return static_cast(colors.size()); } // ******************************************************** @@ -155,7 +155,7 @@ namespace Coloring { for(size_t i = 0; i < n->edges.size(); i++) { - ColorNode* nb = n->GetNeighbor(i); + ColorNode* nb = n->GetNeighbor(static_cast(i)); if (nb->spent == 0) candidates.push_back(nb); } @@ -185,7 +185,7 @@ namespace Coloring for(size_t i = 0; i < nodes.size(); i++) { if (nodes[i]->color == -1) - nonColored.push_back(i); + nonColored.push_back(static_cast(i)); } seedId = nonColored.size() > 10 ? nonColored[rand() % (nonColored.size() - 1)] : nonColored[0]; } diff --git a/src/Utilities/FieldClassification.cpp b/src/Utilities/FieldClassification.cpp index 2d8e33d3..5b17e968 100644 --- a/src/Utilities/FieldClassification.cpp +++ b/src/Utilities/FieldClassification.cpp @@ -39,25 +39,25 @@ vector* FieldClassification::GenerateCategories(CStringW fieldNa minValue.vt = VT_EMPTY; maxValue.vt = VT_EMPTY; - long numShapes = srcValues.size(); + long numShapes = static_cast(srcValues.size()); /* we won't define intervals for string values */ if (ClassificationType != ctUniqueValues && fieldType == STRING_FIELD) { errorCode = tkNOT_UNIQUE_CLASSIFICATION_FOR_STRINGS; - return NULL; + return nullptr; } if ((numClasses <= 0 || numClasses > 1000) && (ClassificationType != ctUniqueValues)) { errorCode = tkTOO_MANY_CATEGORIES; - return NULL; + return nullptr; } if (ClassificationType == ctStandardDeviation) { errorCode = tkINVALID_PARAMETER_VALUE; - return NULL; + return nullptr; } // natural breaks aren't designed to work otherwise @@ -101,7 +101,7 @@ vector* FieldClassification::GenerateCategories(CStringW fieldNa std::vector values; copy(dict.begin(), dict.end(), inserter(values, values.end())); - for (int i = 0; i < (int)values.size(); i++) + for (int i = 0; i < static_cast(values.size()); i++) { CategoriesData data; data.minValue = values[i]; @@ -130,14 +130,14 @@ vector* FieldClassification::GenerateCategories(CStringW fieldNa } sort(values.begin(), values.end()); - double step = totalSum / (double)numClasses; + double step = totalSum / static_cast(numClasses); int index = 1; double sum = 0; - for (int i = 0; i < (int)values.size(); i++) + for (int i = 0; i < static_cast(values.size()); i++) { sum += values[i]; - if (sum >= step * (double)index || i == numShapes - 1) + if (sum >= step * static_cast(index) || i == numShapes - 1) { CategoriesData data; @@ -178,7 +178,7 @@ vector* FieldClassification::GenerateCategories(CStringW fieldNa vMin.Clear(); vMax.Clear(); /* creating classes */ - double dStep = (dMax - dMin) / (double)numClasses; + double dStep = (dMax - dMin) / static_cast(numClasses); while (dMin < dMax) { CategoriesData data; @@ -287,7 +287,7 @@ vector* FieldClassification::GenerateCategories(CStringW fieldNa if (ClassificationType == ctUniqueValues) { USES_CONVERSION; - for (int i = 0; i < (int)result->size(); i++) + for (int i = 0; i < static_cast(result->size()); i++) { //CString strExpression; CStringW strValue; @@ -317,7 +317,7 @@ vector* FieldClassification::GenerateCategories(CStringW fieldNa // in case % is present, we need to put to double it for proper formatting fieldName.Replace(L"%", L"%%"); - for (int i = 0; i < (int)result->size(); i++) + for (int i = 0; i < static_cast(result->size()); i++) { CategoriesData* data = &((*result)[i]); @@ -357,6 +357,6 @@ vector* FieldClassification::GenerateCategories(CStringW fieldNa else { delete result; - return NULL; + return nullptr; } } \ No newline at end of file diff --git a/src/Utilities/HashTable.h b/src/Utilities/HashTable.h index 08cfad5a..889465d7 100644 --- a/src/Utilities/HashTable.h +++ b/src/Utilities/HashTable.h @@ -15,13 +15,13 @@ class HashEntry { public: - HashEntry(){Occupied = false; ent = NULL; index = -1;} + HashEntry(){Occupied = false; ent = nullptr; index = -1;} ColorEntry * ent; int index; bool Occupied; }; -class HashTable +class HashTable { private: int Hash(colort c, ColorEntry * ent) @@ -29,7 +29,7 @@ class HashTable int hash; hash = c; - hash = (hash << 1) ^ (int)ent ^ hash; + hash = (hash << 1) ^ static_cast(reinterpret_cast(ent)) ^ hash; hash &= 8191; return hash; @@ -65,9 +65,7 @@ class HashTable void InsertEntry(ColorEntry * ce, int i) { - int hash; - - hash = Hash(ce->c, ce->next); + int hash = Hash(ce->c, ce->next); while(table[hash].Occupied) { diff --git a/src/Utilities/RegistryKey.cpp b/src/Utilities/RegistryKey.cpp index bcca7a3c..ebd30dd6 100644 --- a/src/Utilities/RegistryKey.cpp +++ b/src/Utilities/RegistryKey.cpp @@ -14,8 +14,8 @@ const long BUFFER_SIZE = 500; RegistryKey::RegistryKey() { - m_hKey = NULL; - m_KeyName = NULL; + m_hKey = nullptr; + m_KeyName = nullptr; m_ErrorCode = REG_KEY_NOT_OPEN; m_NumSubKeys = -1; m_NumValues = -1; @@ -28,10 +28,9 @@ RegistryKey::~RegistryKey() bool RegistryKey::OpenKey(HKEY BaseSection, char *KeyName) { - Close(); - if (KeyName == NULL) + if (KeyName == nullptr) { m_ErrorCode = REG_INVALID_NULL_PARAM; return false; @@ -42,8 +41,7 @@ bool RegistryKey::OpenKey(HKEY BaseSection, char *KeyName) if (m_ErrorCode != REG_NO_ERROR) return false; - - m_ErrorCode = RegQueryInfoKey(m_hKey,NULL,NULL,NULL,&m_NumSubKeys,NULL,NULL,&m_NumValues,NULL,NULL,NULL,NULL); + m_ErrorCode = RegQueryInfoKey(m_hKey, nullptr, nullptr, nullptr,&m_NumSubKeys, nullptr, nullptr,&m_NumValues, nullptr, nullptr, nullptr, nullptr); if (m_ErrorCode != REG_NO_ERROR) return false; @@ -57,7 +55,7 @@ bool RegistryKey::OpenKey(HKEY BaseSection, char *KeyName) char * RegistryKey::getValueName(unsigned long KeyIndex) { - char * buffer = NULL; + char * buffer = nullptr; if(isOpen() == false) { @@ -75,7 +73,7 @@ char * RegistryKey::getValueName(unsigned long KeyIndex) if (LoadValue(KeyIndex,false) == true) return m_KeyValues[KeyIndex]->name; else - return NULL; + return nullptr; } //char * RegistryKey::getErrorMsg() @@ -116,7 +114,7 @@ char * RegistryKey::getValueName(unsigned long KeyIndex) bool RegistryKey::isOpen() { - if (m_hKey == NULL) + if (m_hKey == nullptr) return false; else return true; @@ -139,26 +137,24 @@ void RegistryKey::Close() RegCloseKey(m_hKey); } - - while (m_KeyValues.empty() == false) { - KeyValue * kv = NULL; + KeyValue * kv = nullptr; kv = m_KeyValues[0]; m_KeyValues.erase(m_KeyValues.begin()); - if (kv != NULL) + if (kv != nullptr) delete kv;//->~KeyValue(); } m_KeyValues.clear(); - if (m_KeyName != NULL) + if (m_KeyName != nullptr) delete [] m_KeyName; - m_KeyName = NULL; + m_KeyName = nullptr; m_ErrorCode = REG_KEY_NOT_OPEN; - m_hKey = NULL; + m_hKey = nullptr; m_NumSubKeys = -1; m_NumValues = -1; } @@ -168,12 +164,12 @@ RegistryKey * RegistryKey::getSubKey(unsigned long Index) RegistryKey * retval = new RegistryKey; if (!isOpen()) - return NULL; + return nullptr; if (Index >= m_NumSubKeys) { m_ErrorCode = REG_INDEX_OUT_OF_BOUNDS; - return NULL; + return nullptr; } //get the name of the Requested key specified @@ -183,15 +179,14 @@ RegistryKey * RegistryKey::getSubKey(unsigned long Index) RegEnumKey(m_hKey,Index,KeyName,BUFFER_SIZE); if (retval->OpenKey(m_hKey,KeyName) == false) - return NULL; + return nullptr; return retval; - } void RegistryKey::setKeyName(char *name) { - if(m_KeyName != NULL) + if(m_KeyName != nullptr) delete [] m_KeyName; m_KeyName = new char [strlen(name) + 1]; @@ -204,35 +199,35 @@ BYTE * RegistryKey::getValueData(unsigned long ValueIndex) if(isOpen() == false) { m_ErrorCode = REG_KEY_NOT_OPEN; - return NULL; + return nullptr; } if (ValueIndex >= m_NumValues) { m_ErrorCode = REG_INDEX_OUT_OF_BOUNDS; - return NULL; + return nullptr; } if (LoadValue(ValueIndex,false) == true) - { - KeyValue * kv = NULL; + { + KeyValue * kv = nullptr; kv = m_KeyValues[ValueIndex]; unsigned long bufferSize = kv->dataSize; LPBYTE buffer = new BYTE[bufferSize]; - unsigned long NameLength = strlen(kv->name) +1; + unsigned long NameLength = static_cast(strlen(kv->name) +1); + + m_ErrorCode = RegEnumValue(m_hKey,ValueIndex,kv->name,&NameLength, nullptr,&(kv->type),buffer,&bufferSize); - m_ErrorCode = RegEnumValue(m_hKey,ValueIndex,kv->name,&NameLength,NULL,&(kv->type),buffer,&bufferSize); - if (m_ErrorCode != REG_NO_ERROR) { cout << "DataType: " << REG_SZ << endl; cout.flush(); delete [] buffer; - buffer = NULL; - return NULL; + buffer = nullptr; + return nullptr; } kv->dataSize = bufferSize; @@ -240,13 +235,13 @@ BYTE * RegistryKey::getValueData(unsigned long ValueIndex) return buffer; } else - return NULL; + return nullptr; } char * RegistryKey::getKeyName() { - char * retval = NULL; - if (m_KeyName != NULL) + char * retval = nullptr; + if (m_KeyName != nullptr) { retval = new char[strlen(m_KeyName)+1]; strcpy(retval,m_KeyName); @@ -262,56 +257,52 @@ DWORD RegistryKey::getValueType(unsigned long Index) return REG_NONE; } - if (LoadValue(Index,false) == true) return m_KeyValues[Index]->type; else - return NULL; - + return 0; } void RegistryKey::InitKeyValueList() { - for (int i = 0; i < (int)m_NumValues; i++) - m_KeyValues.push_back(NULL); + for (int i = 0; i < static_cast(m_NumValues); i++) + m_KeyValues.push_back(nullptr); } bool RegistryKey::LoadValue(unsigned long Index, bool ForceReload) { - char * NameBuffer; unsigned long NameLength = BUFFER_SIZE; - if (m_KeyValues[Index] == NULL || ForceReload == true) + if (m_KeyValues[Index] == nullptr || ForceReload == true) { - if (m_KeyValues[Index] != NULL) + if (m_KeyValues[Index] != nullptr) delete m_KeyValues[Index]; - m_KeyValues[Index] = NULL; + m_KeyValues[Index] = nullptr; NameBuffer = new char [NameLength]; KeyValue * kv = new KeyValue(); //get the information, but don't get the data until requested - m_ErrorCode = RegEnumValue(m_hKey,Index,NameBuffer,&NameLength, NULL,&(kv->type),NULL,&(kv->dataSize)); - - + m_ErrorCode = RegEnumValue(m_hKey,Index,NameBuffer,&NameLength, nullptr,&(kv->type), nullptr,&(kv->dataSize)); + if (m_ErrorCode != REG_NO_ERROR) { delete [] NameBuffer; delete kv; return false; } - + kv->name = new char[NameLength+1]; - + strcpy(kv->name,NameBuffer); delete [] NameBuffer; - + m_KeyValues[Index] = kv; - kv = NULL; + kv = nullptr; kv = m_KeyValues[Index]; } return true; diff --git a/src/Utilities/Templates.h b/src/Utilities/Templates.h index 818bae2c..67109c86 100644 --- a/src/Utilities/Templates.h +++ b/src/Utilities/Templates.h @@ -14,25 +14,25 @@ namespace Templates template bool Vector2SafeArray(std::vector* v, VARIANT* arr) { - SAFEARRAY FAR* psa = NULL; + SAFEARRAY FAR* psa = nullptr; SAFEARRAYBOUND rgsabound[1]; - rgsabound[0].lLbound = 0; + rgsabound[0].lLbound = 0; - if( v != NULL && v->size() > 0 ) + if( v != nullptr && v->size() > 0 ) { - rgsabound[0].cElements = v->size(); - psa = SafeArrayCreate( VT_DISPATCH, 1, rgsabound); - + rgsabound[0].cElements = static_cast(v->size()); + psa = SafeArrayCreate( VT_DISPATCH, 1, rgsabound); + if( psa ) { - LPDISPATCH *pDispatch = NULL; - SafeArrayAccessData(psa,(void HUGEP* FAR*)(&pDispatch)); + LPDISPATCH *pDispatch = nullptr; + SafeArrayAccessData(psa,reinterpret_cast(&pDispatch)); - for( int i = 0; i < (int)v->size(); i++) + for( int i = 0; i < static_cast(v->size()); i++) pDispatch[i] = (*v)[i]; - + SafeArrayUnaccessData(psa); - + arr->vt = VT_ARRAY|VT_DISPATCH; arr->parray = psa; return true; @@ -54,29 +54,29 @@ namespace Templates template bool Vector2SafeArray(std::vector* v, VARTYPE variantType, VARIANT* arr) { - SAFEARRAY FAR* psa = NULL; + SAFEARRAY FAR* psa = nullptr; SAFEARRAYBOUND rgsabound[1]; - rgsabound[0].lLbound = 0; + rgsabound[0].lLbound = 0; if (v->size() > 0) { - rgsabound[0].cElements = v->size(); + rgsabound[0].cElements = static_cast(v->size()); psa = SafeArrayCreate( variantType, 1, rgsabound); - + if( psa ) { T/*long HUGEP*/ *plng; - SafeArrayAccessData(psa,(void HUGEP* FAR*)&plng); - + SafeArrayAccessData(psa, (void HUGEP * FAR*) & plng); + // can we copy bytes from set object directly? memcpy(plng,&(v->at(0)),sizeof(T)*v->size()); SafeArrayUnaccessData(psa); - + arr->vt = VT_ARRAY|variantType; arr->parray = psa; return true; } - + arr->vt = VT_ARRAY|variantType; arr->parray = psa; return false; diff --git a/src/Utilities/UtilityFunctions.cpp b/src/Utilities/UtilityFunctions.cpp index 4b53f9c1..98a64dab 100644 --- a/src/Utilities/UtilityFunctions.cpp +++ b/src/Utilities/UtilityFunctions.cpp @@ -413,7 +413,7 @@ namespace Utility { FILE* file = _wfopen(filename, L"rb"); - long size = 0; + size_t size = 0; if (file) { fseek(file, 0, SEEK_END); @@ -426,14 +426,14 @@ namespace Utility } fclose(file); } - return size; + return static_cast(size); } int ReadFileToBuffer(CStringW filename, char** buffer) { FILE* file = _wfopen(filename, L"rb"); - long size = 0; + size_t size = 0; if (file) { fseek(file, 0, SEEK_END); @@ -446,7 +446,7 @@ namespace Utility } fclose(file); } - return size; + return static_cast(size); } #define _SECOND ((__int64) 10000000) @@ -845,7 +845,7 @@ namespace Utility static const double doBase = 10.0; double doComplete5, doComplete5i; - doComplete5 = doValue * pow(doBase, (double)(nPrecision + 1)); + doComplete5 = doValue * pow(doBase, static_cast(nPrecision + 1)); if (doValue < 0.0) doComplete5 -= 5.0; @@ -855,7 +855,7 @@ namespace Utility doComplete5 /= doBase; modf(doComplete5, &doComplete5i); - return doComplete5i / pow(doBase, (double)nPrecision); + return doComplete5i / pow(doBase, static_cast(nPrecision)); } bool FloatsEqual(const float& a, const float& b) @@ -883,7 +883,7 @@ namespace Utility if (size == 0) return -1; // Failure - pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size)); + pImageCodecInfo = static_cast(malloc(size)); if (pImageCodecInfo == nullptr) return -1; // Failure @@ -966,7 +966,7 @@ namespace Utility memcpy(&bitsNew[i * nBytesInRow], &pixels[i * width * 3], width * 3); // saing the image - Gdiplus::Bitmap* bmp = new Gdiplus::Bitmap(&bif, (void*)bitsNew); + Gdiplus::Bitmap* bmp = new Gdiplus::Bitmap(&bif, static_cast(bitsNew)); CLSID pngClsid; GetEncoderClsid(L"png", &pngClsid); // perhaps some other formats ? @@ -1001,19 +1001,19 @@ namespace Utility temp.push_back(inpStr[iter]); } - int size = temp.size(); + auto size = static_cast(temp.size()); DWORD* output = new DWORD[size]; //get the multiplier - multiplier = atoi((char*)&temp[0]); + multiplier = atoi(reinterpret_cast(&temp[0])); for (int i = 1; i < size; i++) { - output[i - 1] = multiplier * atoi((char*)&temp[i]); // multiply to enhance value since range = 0 - 9 + output[i - 1] = multiplier * atoi(reinterpret_cast(&temp[i])); // multiply to enhance value since range = 0 - 9 } /* get the number of elements*/ - num = temp.size() - 1; // take off one for the multiplier and one for the null value + num = static_cast(temp.size() - 1); // take off one for the multiplier and one for the null value temp.clear(); // be frugal with memory.. return output; @@ -1032,7 +1032,7 @@ namespace Utility byte Utility::GetBrightness(OLE_COLOR color) { - return ((short)GetRValue(color) + (short)GetGValue(color) + (short)GetBValue(color)) / 3; + return (static_cast(GetRValue(color)) + static_cast(GetGValue(color)) + static_cast(GetBValue(color))) / 3; } // *********************************************************** @@ -1181,11 +1181,11 @@ namespace Utility if (GetFileVersionInfoW(path, verHandle, verSize, verData)) { - if (VerQueryValue(verData, "\\", (VOID FAR * FAR*) & lpBuffer, &size)) + if (VerQueryValue(verData, "\\", reinterpret_cast(&lpBuffer), &size)) { if (size) { - VS_FIXEDFILEINFO* verInfo = (VS_FIXEDFILEINFO*)lpBuffer; + VS_FIXEDFILEINFO* verInfo = reinterpret_cast(lpBuffer); if (verInfo->dwSignature == 0xfeef04bd) { int major = HIWORD(verInfo->dwFileVersionMS); @@ -1330,11 +1330,11 @@ namespace Utility register LPBYTE pOutTmp = nullptr; LPBYTE pOutBuf = nullptr; register LPBYTE pInTmp = nullptr; - LPBYTE pInBuf = (LPBYTE)sIn.GetBuffer(nLen); + LPBYTE pInBuf = reinterpret_cast(sIn.GetBuffer(nLen)); BYTE b = 0; //alloc out buffer - pOutBuf = (LPBYTE)sOut.GetBuffer(nLen * 3 - 2);//new BYTE [nLen * 3]; + pOutBuf = reinterpret_cast(sOut.GetBuffer(nLen * 3 - 2));//new BYTE [nLen * 3]; if (pOutBuf) { @@ -1381,10 +1381,10 @@ namespace Utility nullptr, socketError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&lpMsgBuf, + reinterpret_cast(&lpMsgBuf), 0, nullptr); - CString s = (char*)lpMsgBuf; + CString s = static_cast(lpMsgBuf); LocalFree(lpMsgBuf); return s;