Skip to content

Commit f7e0ad4

Browse files
committed
Added IPlacedLabels
1 parent 1f6ca14 commit f7e0ad4

23 files changed

Lines changed: 656 additions & 27 deletions

src/COM classes/LabelClass.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,62 @@ STDMETHODIMP CLabelClass::get_ScreenExtents(IExtents** retval)
9393
}
9494
return S_OK;
9595
}
96+
97+
98+
// ***********************************************************
99+
// MapExtents
100+
// ***********************************************************
101+
STDMETHODIMP CLabelClass::get_MapExtents(double inversePixelPerProjection, IExtents** retVal)
102+
{
103+
AFX_MANAGE_STATE(AfxGetStaticModuleState())
104+
IExtents* ext = nullptr;
105+
if(_label->horizontalFrame)
106+
{
107+
ComHelper::CreateExtents(&ext);
108+
109+
auto width2 = (_label->horizontalFrame->right - _label->horizontalFrame->left) * inversePixelPerProjection / 2.0;
110+
auto height2 = (_label->horizontalFrame->bottom - _label->horizontalFrame->top) * inversePixelPerProjection / 2.0;
111+
ext->SetBounds(_label->x - width2,
112+
_label->y - height2,
113+
0.0,
114+
_label->x + width2,
115+
_label->y + height2,
116+
0.0);
117+
*retVal = ext;
118+
}
119+
else if(_label->rotatedFrame)
120+
{
121+
ComHelper::CreateExtents(&ext);
122+
CRect* rect = _label->rotatedFrame->BoundingBox();
123+
auto width2 = (rect->right - rect->left) * inversePixelPerProjection / 2.0;
124+
auto height2 = (rect->bottom - rect->top) * inversePixelPerProjection / 2.0;
125+
ext->SetBounds(_label->x - width2,
126+
_label->y - height2,
127+
0.0,
128+
_label->x + width2,
129+
_label->y + height2,
130+
0.0);
131+
*retVal = ext;
132+
}
133+
else
134+
*retVal = nullptr;
135+
return S_OK;
136+
}
137+
138+
// ************************************************************
139+
// get/put_Key()
140+
// ************************************************************
141+
STDMETHODIMP CLabelClass::get_Key(BSTR* pVal)
142+
{
143+
AFX_MANAGE_STATE(AfxGetStaticModuleState())
144+
*pVal = OLE2BSTR(_label->key);
145+
return S_OK;
146+
}
147+
148+
STDMETHODIMP CLabelClass::put_Key(BSTR newVal)
149+
{
150+
AFX_MANAGE_STATE(AfxGetStaticModuleState())
151+
SysFreeString(_label->key);
152+
_label->key = OLE2BSTR(newVal);
153+
return S_OK;
154+
}

src/COM classes/LabelClass.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ class ATL_NO_VTABLE CLabelClass :
105105

106106
STDMETHOD(get_ScreenExtents)(IExtents** retval);
107107

108+
STDMETHOD(get_MapExtents)(double inversePixelPerProjection, IExtents** retVal);
109+
110+
STDMETHOD(get_Key)(/*[out, retval]*/ BSTR* pVal);
111+
STDMETHOD(put_Key)(/*[in]*/ BSTR newVal);
108112
private:
109113
CLabelInfo* _label;
110114
bool _canDelete; // CLabelInfo can be allocated locally, then we need to delete it

src/COM classes/Labels.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,44 @@ STDMETHODIMP CLabels::Select(IExtents* BoundingBox, long Tolerance, SelectMode S
838838

839839
return S_OK;
840840
};
841+
// *****************************************************************
842+
// SelectNotDrawn()
843+
// *****************************************************************
844+
// Selection of not drawn labels which fall in the given bounding box
845+
STDMETHODIMP CLabels::SelectNotDrawn(IExtents* BoundingBox, VARIANT* LabelIndices, VARIANT* PartIndices, VARIANT_BOOL* retval)
846+
{
847+
*retval = VARIANT_FALSE;
848+
if (!BoundingBox) return S_OK;
849+
double xMin, yMin, zMin, xMax, yMax, zMax;
850+
BoundingBox->GetBounds(&xMin, &yMin, &zMin, &xMax, &yMax, &zMax);
851+
852+
vector<long> indices;
853+
vector<long> parts;
854+
855+
for (unsigned long i = 0; i < _labels.size(); i++)
856+
{
857+
vector<CLabelInfo*>* labelParts = _labels[i];
858+
for (unsigned long j = 0; j < labelParts->size(); j++)
859+
{
860+
CLabelInfo* lbl = labelParts->at(j);
861+
if (lbl->horizontalFrame == nullptr && lbl->rotatedFrame == nullptr)
862+
{
863+
auto isInside = GeometryHelper::PointInExtent(xMin, yMin, xMax, yMax, lbl->x, lbl->y);
864+
if (isInside)
865+
{
866+
indices.push_back(i);
867+
parts.push_back(j);
868+
}
869+
}
870+
}
871+
}
872+
873+
bool result = Templates::Vector2SafeArray(&indices, VT_I4, LabelIndices);
874+
*retval = Templates::Vector2SafeArray(&parts, VT_I4, PartIndices);
875+
*retval = *retval && result;
876+
877+
return S_OK;
878+
}
841879

842880
// *******************************************************************
843881
// put_ParentShapefile()
@@ -2909,3 +2947,29 @@ STDMETHODIMP CLabels::UpdateSizeField()
29092947
return S_OK;
29102948
}
29112949

2950+
2951+
2952+
// *************************************************************
2953+
// get_LabelDrawnInMap()
2954+
// *************************************************************
2955+
STDMETHODIMP CLabels::get_LabelDrawnInMap(long index, VARIANT_BOOL* pVal)
2956+
{
2957+
AFX_MANAGE_STATE(AfxGetStaticModuleState());
2958+
2959+
auto match = _drawnInMap.find(index);
2960+
*pVal = match != _drawnInMap.end();
2961+
2962+
return S_OK;
2963+
}
2964+
2965+
// *************************************************************
2966+
// AddDrawnLabel()
2967+
// *************************************************************
2968+
void CLabels::AddDrawnLabel(long index)
2969+
{
2970+
if (index == -1) // Reset
2971+
_drawnInMap.clear();
2972+
else
2973+
_drawnInMap.insert(index);
2974+
}
2975+

src/COM classes/Labels.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#pragma once
2727
#include "LabelOptions.h"
2828
#include "LabelCategory.h"
29+
#include <set>
2930

3031
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
3132
#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 :
164165
// selection
165166
STDMETHOD(Select)(IExtents* BoundingBox, long Tolerance, SelectMode SelectMode, VARIANT* LabelIndices, VARIANT* PartIndices, VARIANT_BOOL* retval);
166167

168+
STDMETHOD(SelectNotDrawn)(IExtents* BoundingBox, VARIANT* LabelIndices, VARIANT* PartIndices, VARIANT_BOOL* retval);
169+
167170
// ------------------------------------------------------
168171
// Class-specific properties
169172
// ------------------------------------------------------
@@ -388,7 +391,8 @@ class ATL_NO_VTABLE CLabels :
388391
STDMETHOD(get_LogScaleForSize)(VARIANT_BOOL* pVal);
389392
STDMETHOD(put_LogScaleForSize)(VARIANT_BOOL newVal);
390393
STDMETHOD(UpdateSizeField)();
391-
394+
STDMETHOD(get_LabelDrawnInMap)(long index, VARIANT_BOOL* pVal);
395+
392396
private:
393397
int _sourceField;
394398

@@ -454,6 +458,7 @@ class ATL_NO_VTABLE CLabels :
454458

455459
tkTextRenderingHint _textRenderingHint;
456460
VARIANT_BOOL _synchronized;
461+
std::set<long> _drawnInMap;
457462

458463
private:
459464
inline void ErrorMessage(long errorCode);
@@ -489,7 +494,8 @@ class ATL_NO_VTABLE CLabels :
489494
void LoadLblOptions(CPLXMLNode* node);
490495

491496
bool RecalculateFontSize();
492-
497+
498+
void AddDrawnLabel(long index);
493499

494500
};
495501

src/COM classes/PlacedLabels.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// PlacedLabels.cpp : Implementation of CPlacedLabels
2+
3+
#include "stdafx.h"
4+
#include "PlacedLabels.h"
5+
6+
// *****************************************************************
7+
// get_NumShapes()
8+
// *****************************************************************
9+
STDMETHODIMP CPlacedLabels::get_NumIndex(long* pVal)
10+
{
11+
AFX_MANAGE_STATE(AfxGetStaticModuleState())
12+
*pVal = static_cast<long>(_indexes.size());
13+
return S_OK;
14+
}
15+
16+
17+
// *****************************************************************
18+
// GetIndexes()
19+
// *****************************************************************
20+
STDMETHODIMP CPlacedLabels::GetIndexes(SAFEARRAY** retval)
21+
{
22+
AFX_MANAGE_STATE(AfxGetStaticModuleState())
23+
*retval = SafeArrayCreateVector(VT_I4, 0, static_cast<ULONG>(_indexes.size()));
24+
SafeArrayLock((*retval));
25+
auto pData = static_cast<long*>((*retval)->pvData);
26+
for(size_t i = 0; i < _indexes.size(); i++)
27+
{
28+
pData[i] = _indexes[i];
29+
}
30+
SafeArrayUnlock((*retval));
31+
32+
return S_OK;
33+
}
34+
35+
36+
// *****************************************************************
37+
// GetIndexes()
38+
// *****************************************************************
39+
STDMETHODIMP CPlacedLabels::SetVector(int* indexes, const int length)
40+
{
41+
AFX_MANAGE_STATE(AfxGetStaticModuleState())
42+
43+
for(int i = 0; i < length; i++)
44+
{
45+
_indexes.push_back(indexes[i]);
46+
}
47+
48+
return S_OK;
49+
}

src/COM classes/PlacedLabels.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// PlacedLabels.h : Declaration of the CPlacedLabels
2+
#pragma once
3+
4+
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
5+
#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."
6+
#endif
7+
8+
using namespace ATL;
9+
10+
// CPlacedLabels
11+
class ATL_NO_VTABLE CPlacedLabels :
12+
public CComObjectRootEx<CComObjectThreadModel>,
13+
public CComCoClass<CPlacedLabels, &CLSID_PlacedLabels>,
14+
public IDispatchImpl<IPlacedLabels, &IID_IPlacedLabels, &LIBID_MapWinGIS, /*wMajor =*/ VERSION_MAJOR, /*wMinor =*/ VERSION_MINOR>
15+
{
16+
public:
17+
CPlacedLabels()
18+
{
19+
_pUnkMarshaler = nullptr;
20+
//_hotTracking = VARIANT_TRUE;
21+
//_mode = imAllLayers;
22+
//_color = RGB(255, 0, 0); //RGB(30, 144, 255);
23+
//_activeLayer = -1;
24+
}
25+
26+
DECLARE_REGISTRY_RESOURCEID(IDR_PLACEDLABELS)
27+
28+
BEGIN_COM_MAP(CPlacedLabels)
29+
COM_INTERFACE_ENTRY(IPlacedLabels)
30+
COM_INTERFACE_ENTRY(IDispatch)
31+
COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, _pUnkMarshaler.p)
32+
END_COM_MAP()
33+
34+
DECLARE_PROTECT_FINAL_CONSTRUCT()
35+
36+
DECLARE_GET_CONTROLLING_UNKNOWN()
37+
38+
HRESULT FinalConstruct()
39+
{
40+
return CoCreateFreeThreadedMarshaler(GetControllingUnknown(), &_pUnkMarshaler.p);
41+
}
42+
43+
void FinalRelease()
44+
{
45+
_pUnkMarshaler.Release();
46+
}
47+
48+
CComPtr<IUnknown> _pUnkMarshaler;
49+
50+
public:
51+
STDMETHOD(get_NumIndex)(/*[out, retval]*/ long* pVal);
52+
STDMETHOD(GetIndexes)( /*[out, retval]*/ SAFEARRAY** retval);
53+
STDMETHOD(SetVector)(int* indexes, int length);
54+
55+
private:
56+
std::vector<int> _indexes;
57+
};
58+
OBJECT_ENTRY_AUTO(__uuidof(PlacedLabels), CPlacedLabels)

src/COM classes/PlacedLabels.rgs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
HKCR
2+
{
3+
MapWinGIS.PlacedLabels.1 = s 'PlacedLabels Class'
4+
{
5+
CLSID = s '{92A8E8D4-617E-47A4-8180-82E24AD3C984}'
6+
}
7+
MapWinGIS.PlacedLabels = s 'PlacedLabels Class'
8+
{
9+
CLSID = s '{92A8E8D4-617E-47A4-8180-82E24AD3C984}'
10+
CurVer = s 'MapWinGIS.PlacedLabels.1'
11+
}
12+
NoRemove CLSID
13+
{
14+
ForceRemove {92A8E8D4-617E-47A4-8180-82E24AD3C984} = s 'PlacedLabels Class'
15+
{
16+
ProgID = s 'MapWinGIS.PlacedLabels.1'
17+
VersionIndependentProgID = s 'MapWinGIS.PlacedLabels'
18+
ForceRemove 'Programmable'
19+
InprocServer32 = s '%MODULE%'
20+
{
21+
val ThreadingModel = s 'Both'
22+
}
23+
'TypeLib' = s '{C368D713-CC5F-40ED-9F53-F84FE197B96A}'
24+
}
25+
}
26+
}

src/MapControl/DispIds.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ enum { //{{AFX_DISP_ID(CMapView)
33
// NOTE: ClassWizard will add and remove enumeration elements here
44
// DO NOT EDIT what you see in these blocks of generated code !
55
// **ClassWizard is a thing of the past... feel free to edit this code.
6+
dispidGetDrawingLabelExtents = 270L,
7+
dispidPlaceAllMapLabels = 269L,
68
dispidShowCoordinatesBackground = 268L,
79
dispidSetLatitudeLongitude = 267L,
810
dispidStartNewBoundShapeEx = 266L,
@@ -19,7 +21,7 @@ enum { //{{AFX_DISP_ID(CMapView)
1921
dispidZoomToNext = 255L,
2022
dispidShowCoordinatesFormat = 254L,
2123
dispidLayerExtents = 253L,
22-
dispidCustomDrawingFlags = 252L,
24+
dispidCustomDrawingFlags = 252L,
2325
dispidFocusRectangle = 251L,
2426
dispidIdentifiedShapes = 250L,
2527

@@ -303,6 +305,7 @@ enum { //{{AFX_DISP_ID(CMapView)
303305
eventidLayerReprojectedIncomplete = 39L,
304306
eventidBeforeVertexDigitized = 40L,
305307
eventidSnapPointRequested = 41L,
306-
eventidSnapPointFound = 42L
308+
eventidSnapPointFound = 42L,
309+
eventidFireVertexAdded = 43L
307310
//}}AFX_DISP_ID
308311
};

src/MapControl/GlobalSettingsInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct GlobalSettingsInfo
108108
cacheDbfRecords = true;
109109
overrideLocalCallback = true;
110110
proxyAuthentication = asBasic;
111-
httpUserAgent = "MapWinGIS/5.4"; // TODO Use VERSION Macros
111+
httpUserAgent = "MapWinGIS/5.5"; // TODO Use VERSION Macros
112112
hereAppId = "";
113113
hereAppCode = "";
114114
bingApiKey = "";
@@ -180,7 +180,7 @@ struct GlobalSettingsInfo
180180
shortUnitStrings[lsMeters] = L"m";
181181
shortUnitStrings[lsKilometers] = L"km";
182182
shortUnitStrings[lsSquareKilometers] = L"sq.km";
183-
shortUnitStrings[lsSquareMeters] = L"sq.m";
183+
shortUnitStrings[lsSquareMeters] = L"";
184184
shortUnitStrings[lsMapUnits] = L"mu";
185185
shortUnitStrings[lsSquareMapUnits] = L"sq.mu";
186186
shortUnitStrings[lsMiles] = L"mi";

src/MapControl/Map.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ BEGIN_EVENT_MAP(CMapView, COleControl)
146146
EVENT_CUSTOM_ID("BeforeLayers", eventidBeforeLayers, FireBeforeLayers, VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4)
147147
EVENT_CUSTOM_ID("AfterLayers", eventidAfterLayers, FireAfterLayers, VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4)
148148
EVENT_CUSTOM_ID("LayerReprojectedIncomplete", eventidLayerReprojectedIncomplete, FireLayerReprojectedIncomplete, VTS_I4 VTS_I4 VTS_I4)
149-
EVENT_CUSTOM_ID("BeforeVertexDigitized", eventidBeforeVertexDigitized, FireBeforeVertexDigitized, VTS_PR8 VTS_PR8)
149+
EVENT_CUSTOM_ID("BeforeVertexDigitized", eventidBeforeVertexDigitized, FireBeforeVertexDigitized, VTS_PR8 VTS_PR8 VTS_I4)
150150
EVENT_CUSTOM_ID("SnapPointRequested", eventidSnapPointRequested, FireSnapPointRequested, VTS_R8 VTS_R8 VTS_PR8 VTS_PR8 VTS_PI4 VTS_PI4)
151151
EVENT_CUSTOM_ID("SnapPointFound", eventidSnapPointFound, FireSnapPointFound, VTS_R8 VTS_R8 VTS_PR8 VTS_PR8)
152+
EVENT_CUSTOM_ID("VertexAdded", eventidFireVertexAdded, FireVertexAdded, VTS_R8 VTS_R8)
153+
152154
EVENT_STOCK_DBLCLICK()
153155
//}}AFX_EVENT_MAP
154156

0 commit comments

Comments
 (0)