Skip to content

Commit 1f6ca14

Browse files
committed
Added edit support for geometry with X and M.
1 parent 965aa69 commit 1f6ca14

10 files changed

Lines changed: 195 additions & 23 deletions

File tree

src/COM classes/ShapeEditor.cpp

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,23 @@ STDMETHODIMP CShapeEditor::get_ValidatedShape(IShape** retVal)
173173
// *******************************************************
174174
void CShapeEditor::CopyData(int firstIndex, int lastIndex, IShape* target )
175175
{
176+
ShpfileType shpType;
177+
target->get_ShapeType(&shpType);
178+
bool haveZ = ShapeUtility::IsZ(shpType);
179+
bool haveM = ShapeUtility::HaveM(shpType);
176180
long index, partCount = 0;
177181
VARIANT_BOOL vb;
178182
for(int i = firstIndex; i < lastIndex; i++)
179183
{
180184
MeasurePoint* pnt = _activeShape->GetPoint(i);
181185
if (pnt) {
182186
target->AddPoint(pnt->Proj.x, pnt->Proj.y, &index);
187+
IPoint* pt;
188+
target->get_Point(index, &pt);
189+
if (haveZ)
190+
pt->put_Z(pnt->z);
191+
if (haveM)
192+
pt->put_M(pnt->m);
183193
if (pnt->Part == PartBegin) {
184194
target->InsertPart(i, &partCount, &vb);
185195
partCount++;
@@ -345,11 +355,13 @@ STDMETHODIMP CShapeEditor::StartEdit(LONG LayerHandle, LONG ShapeIndex, VARIANT_
345355
if (list) {
346356
list->get_UndoCount(&_startingUndoCount);
347357
}
348-
358+
359+
_startedEditOnInvalidShape = false;
349360
CComPtr<IShape> shp = NULL;
350361
sf->get_Shape(ShapeIndex, &shp);
351362
if (shp)
352363
{
364+
_startedEditOnInvalidShape = !Validate(&shp);
353365
put_EditorState(esEdit);
354366
SetShape(shp);
355367
_layerHandle = LayerHandle;
@@ -391,17 +403,28 @@ STDMETHODIMP CShapeEditor::SetShape( IShape* shp )
391403
}
392404

393405
VARIANT_BOOL vb;
394-
double x, y;
406+
double x, y, z, m;
395407
shp->get_NumPoints(&numPoints);
396408

409+
bool haveZ = ShapeUtility::IsZ(shpType);
410+
bool haveM = ShapeUtility::HaveM(shpType);
411+
397412
for(long i = 0; i < numPoints; i++)
398413
{
399414
PointPart part = PartNone;
400415
if (parts.find(i) != parts.end()) part = PartBegin;
401416
if (endParts.find(i) != endParts.end()) part = PartEnd;
402417

403418
shp->get_XY(i, &x, &y, &vb);
404-
_activeShape->AddPoint(x, y, -1, -1, part);
419+
if(haveZ)
420+
shp->get_Z(i, &z, &vb);
421+
else
422+
z = 0.0;
423+
if(haveM)
424+
shp->get_M(i, &m, &vb);
425+
else
426+
m = 0.0;
427+
_activeShape->AddPoint(x, y, z, m, -1, -1, part);
405428
}
406429
return S_OK;
407430
}
@@ -717,11 +740,13 @@ STDMETHODIMP CShapeEditor::AddPoint(IPoint *newPoint, VARIANT_BOOL* retVal)
717740
get_IsDigitizing(&digitizing);
718741
tkCursorMode cursor = _mapCallback->_GetCursorMode();
719742
if (digitizing) {
720-
double x, y;
743+
double x, y, z, m;
721744
newPoint->get_X(&x);
722745
newPoint->get_Y(&y);
746+
newPoint->get_Z(&z);
747+
newPoint->get_Z(&m);
723748
newPoint->Release();
724-
_activeShape->AddPoint(x, y, -1, -1, PartBegin);
749+
_activeShape->AddPoint(x, y, z, m, -1, -1, PartBegin);
725750
*retVal = VARIANT_TRUE;
726751
return S_OK;
727752
}
@@ -1167,6 +1192,8 @@ bool CShapeEditor::TryStop()
11671192

11681193
CComPtr<IShape> shp = NULL;
11691194
get_ValidatedShape(&shp);
1195+
if (!shp && _startedEditOnInvalidShape ) // Invalid so get the invalid raw shape if we started with invalid shape (IK-379)
1196+
get_RawData(&shp);
11701197

11711198
switch (_state)
11721199
{
@@ -1183,8 +1210,9 @@ bool CShapeEditor::TryStop()
11831210
VARIANT_BOOL isEmpty;
11841211
get_IsEmpty(&isEmpty);
11851212
if (isEmpty) return true;
1186-
if (!shp) return false;
1187-
bool result = TrySaveShape(shp);
1213+
if (!shp && !_activeShape->AllowSaveInvalidGeometry) return false;
1214+
if( shp ) // Only try to save if we have a shape (IK-379)
1215+
bool result = TrySaveShape(shp);
11881216
SetRedrawNeeded(rtVolatileLayer);
11891217
break;
11901218
}
@@ -1277,8 +1305,9 @@ void CShapeEditor::HandleProjPointAdd(double projX, double projY)
12771305
{
12781306
double pixelX, pixelY;
12791307
_mapCallback->_ProjectionToPixel(projX, projY, &pixelX, &pixelY);
1280-
_activeShape->AddPoint(projX, projY, pixelX, pixelY);
1308+
_activeShape->AddPoint(projX, projY, 0.0, 0.0, pixelX, pixelY);
12811309
_activeShape->ClearSnapPoint();
1310+
_mapCallback->_FireVertexAdded(&projX, &projY);
12821311
}
12831312

12841313
// ***************************************************************
@@ -1783,3 +1812,37 @@ STDMETHODIMP CShapeEditor::Deserialize(BSTR state, VARIANT_BOOL* retVal)
17831812

17841813
return S_OK;
17851814
}
1815+
1816+
// ***************************************************************
1817+
// EnableInsertVertex()
1818+
// ***************************************************************
1819+
STDMETHODIMP CShapeEditor::get_EnableInsertVertex(VARIANT_BOOL* pVal)
1820+
{
1821+
AFX_MANAGE_STATE(AfxGetStaticModuleState());
1822+
*pVal = _activeShape->EnableInsertVertex;
1823+
return S_OK;
1824+
}
1825+
1826+
STDMETHODIMP CShapeEditor::put_EnableInsertVertex(VARIANT_BOOL newVal)
1827+
{
1828+
AFX_MANAGE_STATE(AfxGetStaticModuleState());
1829+
_activeShape->EnableInsertVertex = newVal ? true : false;
1830+
return S_OK;
1831+
}
1832+
1833+
// ***************************************************************
1834+
// AllowSaveInvalidGeometry()
1835+
// ***************************************************************
1836+
STDMETHODIMP CShapeEditor::get_AllowSaveInvalidGeometry(VARIANT_BOOL* pVal)
1837+
{
1838+
AFX_MANAGE_STATE(AfxGetStaticModuleState());
1839+
*pVal = _activeShape->AllowSaveInvalidGeometry;
1840+
return S_OK;
1841+
}
1842+
1843+
STDMETHODIMP CShapeEditor::put_AllowSaveInvalidGeometry(VARIANT_BOOL newVal)
1844+
{
1845+
AFX_MANAGE_STATE(AfxGetStaticModuleState());
1846+
_activeShape->AllowSaveInvalidGeometry = newVal ? true : false;
1847+
return S_OK;
1848+
}

src/COM classes/ShapeEditor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class ATL_NO_VTABLE CShapeEditor :
162162
double _snapTolerance;
163163
tkLayerSelection _snapBehavior;
164164
EditorBase* _activeShape;
165+
bool _startedEditOnInvalidShape;
165166
long _layerHandle;
166167
long _shapeIndex;
167168
long _lastErrorCode;
@@ -256,5 +257,10 @@ class ATL_NO_VTABLE CShapeEditor :
256257
STDMETHOD(put_ShowLength)(VARIANT_BOOL newVal);
257258
STDMETHOD(Serialize)(BSTR* retVal);
258259
STDMETHOD(Deserialize)(BSTR state, VARIANT_BOOL* retVal);
260+
STDMETHOD(get_EnableInsertVertex)(VARIANT_BOOL* pVal);
261+
STDMETHOD(put_EnableInsertVertex)(VARIANT_BOOL newVal);
262+
STDMETHOD(get_AllowSaveInvalidGeometry)(VARIANT_BOOL* pVal);
263+
STDMETHOD(put_AllowSaveInvalidGeometry)(VARIANT_BOOL newVal);
264+
259265
};
260266
OBJECT_ENTRY_AUTO(__uuidof(ShapeEditor), CShapeEditor)

src/Editor/ActiveShape.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ bool ActiveShape::HandlePointAdd(const double screenX, const double screenY, con
677677
PixelToProj(screenX, screenY, projX, projY);
678678
}
679679

680-
AddPoint(projX, projY, screenX, screenY);
680+
AddPoint(projX, projY, 0.0, 0.0, screenX, screenY);
681681

682682
UpdatePolyCloseState(true, closePointIndex);
683683

@@ -687,7 +687,7 @@ bool ActiveShape::HandlePointAdd(const double screenX, const double screenY, con
687687
// *******************************************************
688688
// AddPoint()
689689
// *******************************************************
690-
void ActiveShape::AddPoint(const double xProj, const double yProj, const double xScreen, const double yScreen, const PointPart part)
690+
void ActiveShape::AddPoint(const double xProj, const double yProj, const double z, const double m, const double xScreen, const double yScreen, const PointPart part)
691691
{
692692
ClearIfStopped();
693693

@@ -697,6 +697,8 @@ void ActiveShape::AddPoint(const double xProj, const double yProj, const double
697697
MeasurePoint* pnt = new MeasurePoint(); // TODO: Fix compile warning
698698
pnt->Proj.x = xProj;
699699
pnt->Proj.y = yProj;
700+
pnt->z = z;
701+
pnt->m = m;
700702
pnt->Part = part;
701703
_points.push_back(pnt);
702704

@@ -712,7 +714,7 @@ void ActiveShape::AddPoint(const double xProj, const double yProj)
712714
{
713715
double xScreen, yScreen;
714716
ProjToPixel(xProj, yProj, xScreen, yScreen);
715-
AddPoint(xProj, yProj, xScreen, yScreen);
717+
AddPoint(xProj, yProj, 0.0, 0.0, xScreen, yScreen);
716718
}
717719

718720
// **************************************************************

src/Editor/ActiveShape.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ActiveShape : public GeoShape
5353
ShowLength = true;
5454
ShowTotalLength = true;
5555
ShowArea = true;
56+
EnableInsertVertex = true;
5657
};
5758

5859
virtual ~ActiveShape() {
@@ -117,6 +118,8 @@ class ActiveShape : public GeoShape
117118
tkAreaDisplayMode AreaDisplayMode;
118119
tkBearingType BearingType;
119120
tkAngleFormat AngleFormat;
121+
bool EnableInsertVertex;
122+
bool AllowSaveInvalidGeometry;
120123

121124
OLE_COLOR FillColor;
122125
OLE_COLOR LineColor;
@@ -155,7 +158,7 @@ class ActiveShape : public GeoShape
155158
virtual bool UndoPoint();
156159
virtual bool GetPartStartAndEnd(int partIndex, MixedShapePart whichPoints, int& startIndex, int& endIndex);
157160
ShapeInputMode GetInputMode() const { return _inputMode; }
158-
void AddPoint(double xProj, double yProj, double xScreen, double yScreen, PointPart part = PartNone);
161+
void AddPoint(double xProj, double yProj, const double z, const double m, double xScreen, double yScreen, PointPart part = PartNone);
159162
void AddPoint(double xProj, double yProj);
160163
bool HandlePointAdd(double screenX, double screenY, bool ctrl);
161164
int GetPointCount() const { return gsl::narrow_cast<int>(_points.size()); }

src/Editor/MeasuringBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void MeasuringBase::HandleProjPointAdd(double projX, double projY)
7777
{
7878
double pixelX, pixelY;
7979
_mapCallback->_ProjectionToPixel(projX, projY, &pixelX, &pixelY);
80-
AddPoint(projX, projY, pixelX, pixelY);
80+
AddPoint(projX, projY, 0.0, 0.0, pixelX, pixelY);
8181
}
8282

8383
// *******************************************************

src/MapControl/Map_Edit.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,21 @@ bool CMapView::HandleLButtonUpDragVertexOrShape(UINT nFlags)
3232
bool shift = (nFlags & MK_SHIFT) != 0;
3333
bool alt = GetKeyState(VK_MENU) < 0 ? true : false;
3434

35+
// dhe
36+
alt = true;
37+
3538
if (SnappingIsOn(shift))
3639
{
3740
VARIANT_BOOL result = this->FindSnapPointCore(_dragging.Move.x, _dragging.Move.y, &x2, &y2);
3841
if ((result == VARIANT_FALSE) && shift)
3942
return true; // can't proceed without snapping in this mode
4043
}
4144

45+
int selectedVertex;
46+
auto ret = _shapeEditor->get_SelectedVertex(&selectedVertex);
47+
4248
if (alt) { // user wants to intercept coordinates and possibly modify them
43-
this->FireBeforeVertexDigitized(&x2, &y2);
49+
this->FireBeforeVertexDigitized(&x2, &y2, selectedVertex);
4450
}
4551

4652
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)
8894
// get Snap setting
8995
_shapeEditor->get_SnapBehavior(&snapBehavior);
9096

97+
#if DEBUG_ALLOCATED_OBJECTS
98+
ComHelper::SetBreak(false);
99+
auto preCount = gReferenceCounter.GetReferenceCount();
100+
#endif
91101
double projX, projY;
92102
VARIANT_BOOL snapped = FindSnapPointCore(x, y, &projX, &projY);
103+
#if DEBUG_ALLOCATED_OBJECTS
104+
auto postCount = gReferenceCounter.GetReferenceCount();
105+
if (preCount < postCount)
106+
::OutputDebugStringA("Increased!");
107+
ComHelper::SetBreak(false);
108+
#endif
93109
if (!snapped) {
94110
PixelToProjection(x, y, projX, projY);
95111
GetEditorBase()->ClearSnapPoint();

0 commit comments

Comments
 (0)