I have been trying to use the ShapeEditor.AddPoint() function and I have been getting unexpected results. After looking at this it seems the function is always adding a new part when it is called. Looking at the source I don’t see any way to set the active part or specify a part to add the point to. If I am reading the function correctly the PartBegin is always being passed. Please let me know if this is by design or if there is a way to change this behavior. This is the AddPoint function from ShapeEditor.cpp.
// *******************************************************
// AddPoint()
// *******************************************************
STDMETHODIMP CShapeEditor::AddPoint(IPoint newPoint, VARIANT_BOOL retVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
*retVal = VARIANT_FALSE;
if (newPoint == NULL) {
ErrorMessage(tkUNEXPECTED_NULL_PARAMETER);
} else {
VARIANT_BOOL digitizing;
get_IsDigitizing(&digitizing);
tkCursorMode cursor = _mapCallback->_GetCursorMode();
if (digitizing) {
double x, y;
newPoint->get_X(&x);
newPoint->get_Y(&y);
newPoint->Release();
_activeShape->AddPoint(x, y, -1, -1, PartBegin);
*retVal = VARIANT_TRUE;
return S_OK;
}
}
return S_OK;
Hello @HollidayHT
The ShapeEditor::AddPoint
method was added relatively recently as part of a fairly large update that I don’t yet understand. My best guess from a check-in comment is that it is intended to be used to start an operation when in Digitizing mode, which I’m not familiar with. I don’t think it is used by any of the standard tools.
My little understanding from prior use of the ShapeEditor is that all points are added automatically by the standard built-in tools, and you shouldn’t have to call AddPoint directly. And the default behavior of the lower-level ActiveShape::AddPoint
does not initiate a Part with each point.
Once you have added a shape by standard means, it should be a single part, after which you can programmatically break it into parts if necessary.
Perhaps you could provide more context in terms of your intent. For example, are you wanting to create custom behavior outside of the standard set of tools?
Regards,
Jerry.
1 Like
Thanks for the quick response.
I am adding a trace option that adds vertices as the users moves the mouse.
Private Sub AxMap1_MouseMoveEvent(sender As Object, e As _DMapEvents_MouseMoveEvent) Handles AxMap1.MouseMoveEvent
If bDoTrace And iEditingLayer >= 0 Then
Dim sf As Shapefile = GetORGShapefile(AxMap1, iEditingLayer)
Dim dProj As New Point
Dim iShape As Integer
Dim iPoint As Integer
Dim dDistance As Double
Dim dMaxDistance As Double = 4
AxMap1.PixelToProj(e.x, e.y, dProj.x, dProj.y)
If sf.GetClosestVertex(dProj.x, dProj.y, dMaxDistance, iShape, iPoint, dDistance) Then
Dim iPntCnt As Integer = AxMap1.ShapeEditor.numPoints
Dim pntNew As Point = sf.Shape(iShape).Point(iPoint)
Dim pLast As New Point
AxMap1.ShapeEditor.get_PointXY(iPntCnt - 1, pLast.x, pLast.y)
If CalcPointDistance(pntNew, pLast) > 1 Then
AxMap1.ShapeEditor.AddPoint(pntNew)
End If
End If
End If
End Sub
The AddPoint() function would be very useful as previously the only way I could find to add points to the ShapeEditor was to simulate a mouse click at a pixel location. As you point out, we can only add a single part polygon when the editor is digitizing so I don’t understand why the function would add a new part each time it’s called.
Thanks for your help on this.
ToddH