Ejemplo n.º 1
0
        public void Flush()
        {
            var lineString = newArrowLineGeometry;

            if (null == lineString)
            {
                return;
            }

            FeatureProvider.Add(lineString);

            StopDrawing();

            IFeature feature = FeatureProvider.GetFeature(FeatureProvider.GetFeatureCount() - 1);

            // hack? sourceLayer doesn't have to be part of a network; thus we are
            // required to force repaint. DataSource has no knowledge of layer.
            Layer.RenderRequired = true;

            if (null != feature)
            {
                MapControl.SelectTool.Select(Layer, feature, 0);
            }

            newArrowLineGeometry = null;
        }
Ejemplo n.º 2
0
        public void Flush()
        {
            ILineString lineString = (ILineString)newLineGeometry[0];

            if (null == lineString)
            {
                return;
            }
            // MouseDoubleClick has added 2 points at the end of the line; remove the last point.
            lineString = RemoveDuplicatePoints(lineString);
            if (null != lineString)
            {
                FeatureProvider.Add(lineString);
            }
            StopDrawing();
            IFeature feature = FeatureProvider.GetFeature(FeatureProvider.GetFeatureCount() - 1);

            // hack? sourceLayer doesn't have to be part of a network; thus we are
            // required to force repaint. DataSource has no knowledge of layer.
            Layer.RenderRequired = true;

            if (null != feature)
            {
                MapControl.SelectTool.Select(Layer, feature, 0);
            }
            newLineGeometry.Clear();
        }
Ejemplo n.º 3
0
        public override void OnMouseUp(ICoordinate worldPosition, MouseEventArgs e)
        {
            if (!isBusy)
            {
                return;
            }
            if (null == snapResult)
            {
                MapControl.SelectTool.Clear();
            }
            else
            {
                GeometryHelper.SetCoordinate(newNode, 0, snapResult.Location);
                FeatureProvider.Add(newNode);

                IFeature feature = FeatureProvider.GetFeature(FeatureProvider.GetFeatureCount() - 1);


                IFeatureEditor featureEditor = MapControl.SelectTool.GetFeatureEditor(Layer, feature);
//if (null != featureEditor)
//{only when move
//    featureEditor.Start();
//    featureEditor.Stop(snapResult);
//}

                Layer.RenderRequired = true;
                MapControl.SelectTool.Select(Layer, feature, 0);
            }
            isBusy = false;
            StopDrawing();
            MapControl.Refresh();
        }
Ejemplo n.º 4
0
        private void StartNewPolygon(ICoordinate worldPos)
        {
            List <ICoordinate> vertices = new List <ICoordinate>();

            vertices.Add(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y));
            vertices.Add(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y));
            vertices.Add(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y));
            vertices.Add(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y)); // ILinearRing must have > 3 points
            ILinearRing linearRing = GeometryFactory.CreateLinearRing(vertices.ToArray());
            IPolygon    polygon    = GeometryFactory.CreatePolygon(linearRing, null);

            FeatureProvider.Add(polygon);
            newObjectIndex = FeatureProvider.GetFeatureCount() - 1;

            // do not remove see newline MapControl.SelectTool.Select((VectorLayer)Layer, polygon, 1);
        }
Ejemplo n.º 5
0
        // 0 0 0 0
        // 0 1 0 0
        // 0 1 2 0
        // 0 1 2 3 0 ...
        private void AppendCurvePoint(IPolygon polygon, ICoordinate worldPos)
        {
            List <ICoordinate> vertices = new List <ICoordinate>();

            ILineString linearRing = polygon.ExteriorRing;

            for (int i = 0; i < linearRing.Coordinates.Length; i++)
            {
                if (linearRing.Coordinates.Length <= 4)
                {
                    if (1 == i)
                    {
                        if (linearRing.Coordinates[0].Equals2D(linearRing.Coordinates[1]))
                        {
                            // 0 0 ? 0 -> 0 1 ? 0
                            vertices.Add(worldPos);
                        }
                        else
                        {
                            // 0 1 ? 0 -> 0 1 ? 0
                            vertices.Add(linearRing.Coordinates[i]);
                        }
                    }
                    else if (2 == i)
                    {
                        if (linearRing.Coordinates[1].Equals2D(linearRing.Coordinates[2]))
                        {
                            // 0 0 0 0 -> 0 1 1 0
                            vertices.Add(worldPos);
                        }
                        else
                        {
                            // 0 1 2 0 -> 0 1 2 3 0
                            vertices.Add(linearRing.Coordinates[i]);
                            vertices.Add(worldPos);
                        }
                    }
                    else
                    {
                        vertices.Add(linearRing.Coordinates[i]);
                    }
                }
                else
                {
                    if (i == (linearRing.Coordinates.Length - 1))
                    {
                        // insert before last point to keep ring closed
                        vertices.Add(worldPos);
                    }
                    vertices.Add(linearRing.Coordinates[i]);
                }
            }
            int         index         = FeatureProvider.GetFeatureCount() - 1;
            ILinearRing newLinearRing = GeometryFactory.CreateLinearRing(vertices.ToArray());
            IPolygon    newPolygon    = GeometryFactory.CreatePolygon(newLinearRing, null);

            //##layerEditor.UpdateCurvePointInserted(index, newPolygon, vertices.Count - 1);
            //((FeatureProvider)layerEditor.VectorLayer.DataSource).UpdateGeometry(index, newPolygon);
            ((Feature)FeatureProvider.Features[index]).Geometry = newPolygon;
            Layer.RenderRequired = true;
            // do not remove see newline MapControl.SelectTool.Select((VectorLayer)Layer, newPolygon, -1);
        }
Ejemplo n.º 6
0
        public override void OnMouseUp(ICoordinate worldPosition, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            if (newLineGeometry.Count == 0)
            {
                return;
            }

            ISnapResult snapResult = MapControl.SnapTool.ExecuteLayerSnapRules(Layer, null, adding ? newLineGeometry[0] : null,
                                                                               worldPosition,
                                                                               adding ? newLineGeometry[0].Coordinates.Length - 1 : -1);
            IGeometry      defaultGeometry = null;
            IFeatureEditor featureEditor   = MapControl.SelectTool.GetFeatureEditor(Layer, null);

            if (null != featureEditor)
            {
                defaultGeometry = featureEditor.CreateDefaultGeometry(Layer, newLineGeometry[0],
                                                                      (null != snapResult) ? snapResult.NearestTarget : null,
                                                                      (null != snapResult) ? snapResult.Location : null);
                if (null != defaultGeometry)
                {
                    newLineGeometry.Clear();
                    newLineGeometry.Add(defaultGeometry);
                }
            }
            ILineString lineString = (ILineString)newLineGeometry[0];

            if (null == lineString)
            {
                isBusy = false;
                return;
            }
            if (ActualAutoCurve)
            {
                if (null == defaultGeometry)
                {
                    snapResult = Snap(worldPosition);
                    if (null == snapResult)
                    {
                        // hack if obligatory snapping failed mimic result. This is not valid for NewNodeTool
                        // Think of solution within snaprule
                        snapResult = new SnapResult(worldPosition, null, null, -1, -1);
                    }
                    if (TemporalEnd)
                    {
                        GeometryHelper.SetCoordinate(lineString, lineString.Coordinates.Length - 1, snapResult.Location);
                    }
                    else
                    {
                        lineString = AppendCurvePoint(lineString, snapResult.Location);
                    }
                    lineString = RemoveDuplicatePoints(lineString);
                }
                adding             = false;
                newLineGeometry[0] = lineString;
                //Flush();
                SelectTool selectTool = MapControl.SelectTool;

                if (null != lineString && snapResult != null)
                {
                    // TODO: call editor here instead of feature provider
                    int count = FeatureProvider.GetFeatureCount();

                    try
                    {
                        FeatureProvider.Add(lineString); // will add Cross Section and call ConnectCrossSectionToBranch
                    }
                    catch (Exception exception)
                    {
                        // an exception during add operation can fail; for example when adding a branch feature
                        log.Warn(exception.Message);
                        adding = false;
                        StopDrawing();
                        newLineGeometry.Clear();
                        return;
                    }

                    // was adding succesfull?
                    if ((1 + count) == FeatureProvider.GetFeatureCount())
                    {
                        IFeature feature = FeatureProvider.GetFeature(count);
                        //Layer.RenderRequired = true;
                        MapControl.SelectTool.Select(Layer, feature, 0);
                    }
                }
                else
                {
                    // do not add a linestring with zero length
                    selectTool.Clear();
                }
                adding = false;
                StopDrawing();
                newLineGeometry.Clear();
            }
            Layer.RenderRequired = true;
            MapControl.Refresh();
            isBusy = false;
        }