private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { switch (DrawingMode) { case Mode.Polygon: Point p = e.GetPosition(mainContainer); PolygonPoints.Add(p); if (PolygonPoints.Count > 1) { this.PolygonRadioBtn.IsEnabled = true; } if (!CGPolygon.PolygonIsConvex(PolygonPoints)) { MessageBox.Show("Polygon is not convex"); PolygonPoints.Remove(p); break; } var circle = new Ellipse { Stroke = Brushes.Black, StrokeThickness = 2, }; Canvas.SetLeft(circle, p.X - 2); Canvas.SetTop(circle, p.Y - 2); mainContainer.Children.Add(circle); break; case Mode.DrawLine: Point lP = e.GetPosition(mainContainer); break; } }
public PolygonPointsError([NotNull] PolygonPoints polygonPoints, [NotNull] string errorDescription, IssueCode issueCode) { _polygonPoints = polygonPoints; _errorDescription = errorDescription; _issueCode = issueCode; }
private PolygonPoints GetPolygonPoints([NotNull] IFeature feature, int tableIndex) { Dictionary <int, PolygonPoints> polygonPointsByOid; if (!_polygonPointsByTableIndex.TryGetValue(tableIndex, out polygonPointsByOid)) { polygonPointsByOid = new Dictionary <int, PolygonPoints>(); _polygonPointsByTableIndex.Add(tableIndex, polygonPointsByOid); } int oid = feature.OID; PolygonPoints polygonPoints; if (!polygonPointsByOid.TryGetValue(oid, out polygonPoints)) { polygonPoints = new PolygonPoints(feature, tableIndex); polygonPointsByOid.Add(oid, polygonPoints); } return(polygonPoints); }
public override void Draw(Graphics myGp) { if (PolygonPoints.Count != 0) { myPen = new Pen(myOutLineColor, width); myPen.DashStyle = DStyle; myBrush = new SolidBrush(myFillColor); if (BrushTypes == 0) { myBrush = new SolidBrush(myFillColor); } if (BrushTypes == 1) { myBrush = new HatchBrush(HatchStyle.LargeCheckerBoard, myFillColor); } if (BrushTypes == 2) { myBrush = new HatchBrush(HatchStyle.LargeConfetti, myFillColor); } if (BrushTypes == 3) { myBrush = new HatchBrush(HatchStyle.LightUpwardDiagonal, myFillColor); } if (Filled == false) { myGp.DrawPolygon(myPen, PolygonPoints.ToArray()); } else { myGp.FillPolygon(myBrush, PolygonPoints.ToArray()); myGp.DrawPolygon(myPen, PolygonPoints.ToArray()); } } }
private void clearBtn_Click(object sender, RoutedEventArgs e) { mainContainer.Children.RemoveRange(0, mainContainer.Children.Count); PolygonPoints.Clear(); }
private bool IsError([NotNull] PolygonPoints polygonPoints, [NotNull] out string errorDescription, [CanBeNull] out IssueCode issueCode) { errorDescription = string.Empty; issueCode = null; int pointCount = polygonPoints.PointCount; bool singleExpectedCount = _minimumPointCount == _maximumPointCount; if (pointCount < _minimumPointCount) { string expectedDescription = singleExpectedCount ? "expected" : "minimum"; if (polygonPoints.PointCountComplete) { errorDescription = string.Format("Incorrect point count: {0} ({1}: {2})", pointCount, expectedDescription, _minimumPointCount); issueCode = singleExpectedCount ? Codes[Code.PointCount_SmallerThanExpected] : Codes[Code.PointCount_SmallerThanMinimum]; return(true); } // there may be additional points outside the test perimeter, can't report as error return(false); } if (pointCount > _maximumPointCount) { string expectedDescription = singleExpectedCount ? "expected" : "maximum"; if (polygonPoints.PointCountComplete) { errorDescription = string.Format("Incorrect point count: {0} ({1}: {2})", pointCount, expectedDescription, _maximumPointCount); issueCode = singleExpectedCount ? Codes[Code.PointCount_LargerThanExpected] : Codes[Code.PointCount_LargerThanMaximum]; } else { // TODO replace 'polygon' with 'polyline' if geometry is polyline errorDescription = string.Format( "Incorrect point count: {0} ({1}: {2}); " + "Note: the polygon exceeds the test perimeter, " + "there may be additional points outside the perimeter", pointCount, expectedDescription, _maximumPointCount); } return(true); } return(false); }
protected override int ExecuteCore(IRow row, int tableIndex) { if (tableIndex >= _polygonClassesCount) { return(NoError); } if (_queryFilter == null) { InitFilter(); Assert.NotNull(_queryFilter, "_queryFilter"); } var feature = (IFeature)row; IGeometry containingShape = feature.Shape; if (containingShape == null || containingShape.IsEmpty) { return(NoError); } IPolyline line = containingShape as IPolyline; if (line != null && PolylineUsage != PolylineUsage.AsIs) { if (!line.IsClosed) { if (PolylineUsage == PolylineUsage.AsPolygonIfClosedElseReportIssue) { return(ReportError("Unclosed line", line, Codes[Code.NotClosed_Line], null, InvolvedRowUtils.GetInvolvedRows(feature))); } if (PolylineUsage == PolylineUsage.AsPolygonIfClosedElseIgnore) { return(NoError); } } else { containingShape = GeometryFactory.CreatePolygon(line); } } if (IsPolygonFullyChecked(row.OID, tableIndex)) { return(NoError); } PolygonPoints polygonPoints = GetPolygonPoints(feature, tableIndex); if (_relevantPointCondition == null) { _relevantPointCondition = new RelevantPointCondition( _relevantPointConditionSql, GetSqlCaseSensitivity()); } for (int pointClassIndex = _polygonClassesCount; pointClassIndex < _totalClassesCount; pointClassIndex++) { _queryFilter[pointClassIndex].Geometry = containingShape; foreach (IRow pointRow in Search(InvolvedTables[pointClassIndex], _queryFilter[pointClassIndex], _helper[pointClassIndex])) { var pointFeature = (IFeature)pointRow; // point feature is POINT, polygon feature is POLYGON if (!_relevantPointCondition.IsFulfilled( pointFeature, pointClassIndex, row, tableIndex)) { continue; } polygonPoints.AddPointFeature(pointFeature, pointClassIndex); } } return(NoError); }