Hello Alex,
I'm working on the point polygon Annotation.
I need to move the polygon around my AnnotationViewer and store it's coordinates each time it moves.
I have undo/redo buttons, it's working well on the rectangle annotation but not on the polygon annotation.
I have the following code for the rectangle annotation which is working fine.
Code: Select all
IPolygonData selectedPolygonData = null;
if (historyDirection.Equals(PolygonHistoryDirection.Back))
{
selectedPolygonData = (RectangleData)selectedPolygon.GoToPreviousStateAndGet();
}
else
{
selectedPolygonData = (RectangleData)selectedPolygon.GoToNextStateAndGet();
}
// Apply the new state on the focused(selected) annotationViewData
AnnotationDataState annotationDataState = new AnnotationDataState(annotationView.Data)
{
Location = ((RectangleData)selectedPolygonData).Rectangle.Location,
Size = ((RectangleData)selectedPolygonData).Rectangle.Size
};
annotationDataState.Apply(GetSelectedAnnotationView().Data);
Here is my code to create the Polygon Annotation View (I use the same method to create my Rectangle Annotation).
Code: Select all
annotationView = AnnotationViewFactory.CreateView(new PolygonAnnotationData());
annotationView.Name = annotationView.Data.Guid.ToString();
View.GetAnnotationViewer().AddAndBuildAnnotation(annotationView);
Here is my code to handle the changes on my polygon annotation.
selectedPolygonData is my class and is containing a property called Points which is a List<PointF>.
For rectangle I store the the Size and Location, for polygon I store all the points.
But I do not have the possibility to get the annotation state as for the rectangle, it doesn't hold the value of the points, only the Location and size.
I need to have and be able to build point polygon from a list of PointF.
I tried the following code without success.
Code: Select all
IPolygonData selectedPolygonData = null;
if (historyDirection.Equals(PolygonHistoryDirection.Back))
{
selectedPolygonData = (PolygonPointsData)selectedPolygon.GoToPreviousStateAndGet();
}
else
{
selectedPolygonData = (PolygonPointsData)selectedPolygon.GoToNextStateAndGet();
}
// Apply the new state on the focused(selected) annotationViewData
var data = ((PolygonAnnotationData) GetSelectedAnnotationView().Data);
AnnotationPointCollection annoPointCollection = data.Points;
annoPointCollection.Clear();
foreach (var point in ((PolygonPointsData)selectedPolygonData).Points)
{
annoPointCollection.Add(point);
}
My function to create the polygon annotation view from my point list:
This doesn't work either.
Code: Select all
private AnnotationView CreatePolygonPointsAnnotationView(List<PointF> pointsList, string toolTip, string name)
{
PolygonAnnotationData polyPointsAnnotationData = new PolygonAnnotationData
{
CanResize = true,
ToolTip = toolTip,
CanRotate = false,
FillBrush = new AnnotationSolidBrush(Color.Transparent),
Border = true,
Outline = { Brush = new AnnotationSolidBrush(Color.Blue), Width = 1 }
};
foreach (var point in pointsList)
{
polyPointsAnnotationData.Points.Add(point);
}
return new PolygonAnnotationView(polyPointsAnnotationData) { Name = name };
}
Is there a special class to build the polygon point based annotation that I missed? Or just doing it wrong?
Best wishes,
Jerome.