示例#1
0
        public override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                SelectTool selectTool = MapControl.SelectTool;

                if (selectTool.FeatureEditors.Count == 0)
                {
                    return; //nothing selected, nothing to delete
                }
                List <int> indices = new List <int>(selectTool.SelectedTrackerIndices);
                indices.Sort();
                IFeatureEditor featureEditor = selectTool.FeatureEditors[0];
                if ((featureEditor.SourceFeature.Geometry is ILineString) && (indices.Count > 0))
                {
                    featureEditor.EditableObject.BeginEdit(string.Format("Remove curvepoint(s) from feature {0}",
                                                                         featureEditor.SourceFeature is INameable
                            ? ((INameable)featureEditor.SourceFeature).Name
                            : ""));
                    for (int i = indices.Count - 1; i >= 0; i--)
                    {
                        // todo ?move to FeatureMutator and add support for polygon
                        if (RemoveCurvePoint(selectTool.FeatureEditors[0].SourceFeature, indices[i]))
                        {
                            e.Handled = true;
                        }
                    }
                    featureEditor.EditableObject.EndEdit();
                }
                MapControl.Refresh();
            }
        }
示例#2
0
        public override void OnMouseMove(ICoordinate worldPosition, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.None && !isMoving)
            {
                return;
            }

            SelectTool selectTool = MapControl.SelectTool;

            if (isMoving)
            {
                MapControl.MoveTool.OnMouseMove(worldPosition, e);
            }
            else if ((selectTool.FeatureEditors.Count == 1) && (selectTool.FeatureEditors[0].SourceFeature.Geometry is ILineString))
            {
                MapControl.SelectTool.OnMouseMove(worldPosition, e);
                IEnvelope envelope = MapHelper.GetEnvelope(worldPosition, (float)MapHelper.ImageToWorld(Map, 40));
                Snap(selectTool.FeatureEditors[0].Layer, selectTool.FeatureEditors[0].SourceFeature.Geometry,
                     worldPosition, envelope);

                StartDrawing();
                DoDrawing(true);
                StopDrawing();
            }
        }
示例#3
0
        private void InsertCurvePoint(IFeature feature)
        {
            if (feature.Geometry is ILineString)
            {
                if (null == SnapResult)
                {
                    return;
                }
                List <ICoordinate> vertices = new List <ICoordinate>();

                int curvePointIndex = 0;
                for (int i = 0; i < feature.Geometry.Coordinates.Length; i++)
                {
                    vertices.Add(feature.Geometry.Coordinates[i]);
                    if (i == SnapResult.SnapIndexPrevious)
                    {
                        if ((!double.IsNaN(feature.Geometry.Coordinates[i].Z)) && (!double.IsNaN(feature.Geometry.Coordinates[i + 1].Z)))
                        {
                            double previous = Math.Sqrt(Math.Pow(SnapResult.Location.X - feature.Geometry.Coordinates[i].X, 2) +
                                                        Math.Pow(SnapResult.Location.Y - feature.Geometry.Coordinates[i].Y, 2));
                            double next = Math.Sqrt(Math.Pow(feature.Geometry.Coordinates[i + 1].X - SnapResult.Location.X, 2) +
                                                    Math.Pow(feature.Geometry.Coordinates[i + 1].Y - SnapResult.Location.Y, 2));
                            double fraction = previous / (previous + next);
                            double z        = feature.Geometry.Coordinates[i].Z +
                                              (feature.Geometry.Coordinates[i + 1].Z - feature.Geometry.Coordinates[i].Z) *
                                              fraction;
                            ICoordinate coordinate = GeometryFactory.CreateCoordinate(SnapResult.Location.X,
                                                                                      SnapResult.Location.Y);
                            coordinate.Z = z;
                            vertices.Add(coordinate);
                        }
                        else
                        {
                            vertices.Add(SnapResult.Location);
                        }
                        curvePointIndex = i + 1;
                    }

                    //NS: 2013-09-02, Jika convert curve masih gagal, maka gunakan curve tool dengan pembatasan,
                    // bahwa dalam 1 LineString maksimum 4 titik :)
                    //if (vertices.Count == 4)
                    //    MapControl.ActivateTool(MapControl.MoveTool);
                }
                ILineString newLineString = GeometryFactory.CreateLineString(vertices.ToArray());
                SelectTool  selectTool    = MapControl.SelectTool;
                //VectorLayer targetLayer = selectTool.MultiSelection[0].Layer;
                ILayer targetLayer = selectTool.FeatureEditors[0].Layer;
                feature.Geometry = newLineString;
                MapControl.SelectTool.Select(targetLayer, feature, curvePointIndex);
            }
        }
示例#4
0
        public override void OnMouseUp(Coordinate worldPosition, MouseEventArgs e)
        {
            if (isMoving)
            {
                MoveTool.OnMouseUp(worldPosition, e);
            }
            else
            {
                SelectTool.OnMouseUp(worldPosition, e);
            }

            isBusy   = false;
            isMoving = false;
        }
示例#5
0
        public override void OnMouseDown(ICoordinate worldPosition, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            isBusy = true;

            SelectTool selectTool = MapControl.SelectTool;

            if (selectTool.FeatureEditors.Count == 1)
            {
                if ((selectTool.FeatureEditors[0].SourceFeature.Geometry is ILineString) ||
                    (selectTool.FeatureEditors[0].SourceFeature.Geometry is IPolygon))
                {
                    ITrackerFeature trackerFeature = MapControl.SelectTool.GetTrackerAtCoordinate(worldPosition);
                    // hack knowledge of -1 for trackerfeature should not be here
                    // if user click visible tracker it will be handled as move, otherwize a trackers will be added.
                    if ((null != trackerFeature) && (-1 != trackerFeature.Index))
                    {
                        MapControl.MoveTool.OnMouseDown(worldPosition, e);
                        isMoving = true;
                        return;
                    }
                    if (null != SnapResult)
                    {
                        // todo ?move to FeatureEditor and add support for polygon
                        IFeatureEditor featureEditor = selectTool.FeatureEditors[0];

                        if (featureEditor.SourceFeature.Geometry is ILineString)
                        {
                            featureEditor.EditableObject.BeginEdit(string.Format("Insert curvepoint into feature {0}",
                                                                                 featureEditor.SourceFeature is INameable
                                         ? ((INameable)featureEditor.SourceFeature).Name
                                         : ""));
                            //featureEditor.Stop(SnapResult);
                            InsertCurvePoint(featureEditor.SourceFeature);
                            featureEditor.EditableObject.EndEdit();
                        }
                        featureEditor.Layer.RenderRequired = true;
                        MapControl.Refresh();
                        return;
                    }
                }
            }
            // if no curvepoint added handle as normal selection
            selectTool.OnMouseDown(worldPosition, e);
        }
示例#6
0
        private void InsertCurvePoint(IFeature feature)
        {
            if (feature.Geometry is ILineString)
            {
                if (null == SnapResult)
                {
                    return;
                }
                List <ICoordinate> vertices = new List <ICoordinate>();

                int curvePointIndex = 0;
                for (int i = 0; i < feature.Geometry.Coordinates.Length; i++)
                {
                    vertices.Add(feature.Geometry.Coordinates[i]);
                    if (i == SnapResult.SnapIndexPrevious)
                    {
                        if ((!double.IsNaN(feature.Geometry.Coordinates[i].Z)) && (!double.IsNaN(feature.Geometry.Coordinates[i + 1].Z)))
                        {
                            double previous = Math.Sqrt(Math.Pow(SnapResult.Location.X - feature.Geometry.Coordinates[i].X, 2) +
                                                        Math.Pow(SnapResult.Location.Y - feature.Geometry.Coordinates[i].Y, 2));
                            double next = Math.Sqrt(Math.Pow(feature.Geometry.Coordinates[i + 1].X - SnapResult.Location.X, 2) +
                                                    Math.Pow(feature.Geometry.Coordinates[i + 1].Y - SnapResult.Location.Y, 2));
                            double fraction = previous / (previous + next);
                            double z        = feature.Geometry.Coordinates[i].Z +
                                              (feature.Geometry.Coordinates[i + 1].Z - feature.Geometry.Coordinates[i].Z) *
                                              fraction;
                            ICoordinate coordinate = GeometryFactory.CreateCoordinate(SnapResult.Location.X,
                                                                                      SnapResult.Location.Y);
                            coordinate.Z = z;
                            vertices.Add(coordinate);
                        }
                        else
                        {
                            vertices.Add(SnapResult.Location);
                        }
                        curvePointIndex = i + 1;
                    }
                }
                ILineString newLineString = GeometryFactory.CreateLineString(vertices.ToArray());
                SelectTool  selectTool    = MapControl.SelectTool;
                //VectorLayer targetLayer = selectTool.MultiSelection[0].Layer;
                ILayer targetLayer = selectTool.FeatureEditors[0].Layer;
                feature.Geometry = newLineString;
                MapControl.SelectTool.Select(targetLayer, feature, curvePointIndex);
            }
        }
示例#7
0
        public override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                SelectTool selectTool = MapControl.SelectTool;

                List <int> indices = new List <int>(selectTool.SelectedTrackerIndices);
                indices.Sort();
                for (int i = indices.Count - 1; i >= 0; i--)
                {
                    // todo ?move to FeatureMutator and add support for polygon
                    if (selectTool.FeatureEditors[0].SourceFeature.Geometry is ILineString)
                    {
                        if (RemoveCurvePoint(selectTool.FeatureEditors[0].SourceFeature, indices[i]))
                        {
                            e.Handled = true;
                        }
                    }
                }
                MapControl.Refresh();
            }
        }
示例#8
0
        public override void OnMouseMove(Coordinate worldPosition, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.None && !isMoving)
            {
                return;
            }

            if (isMoving)
            {
                MoveTool.OnMouseMove(worldPosition, e);
            }
            else if ((SelectTool.SelectedFeatureInteractors.Count == 1) &&
                     SupportedGeometry(SelectTool.SelectedFeatureInteractors[0].SourceFeature.Geometry))
            {
                SelectTool.OnMouseMove(worldPosition, e);
                Snap(SelectTool.SelectedFeatureInteractors[0].SourceFeature.Geometry, worldPosition);
                SetMouseCursor(worldPosition);
                StartDrawing();
                DoDrawing(true);
                StopDrawing();
            }
        }
示例#9
0
        public override void OnMouseDown(ICoordinate worldPosition, MouseEventArgs e)
        {
            isBusy = true;

            SelectTool selectTool = MapControl.SelectTool;

            if (selectTool.FeatureEditors.Count == 1)
            {
                if ((selectTool.FeatureEditors[0].SourceFeature.Geometry is ILineString) ||
                    (selectTool.FeatureEditors[0].SourceFeature.Geometry is IPolygon))
                {
                    ITrackerFeature trackerFeature = MapControl.SelectTool.GetTrackerAtCoordinate(worldPosition);
                    // hack knowledge of -1 for trackerfeature should not be here
                    // if user click visible tracker it will be handled as move, otherwize a trackers will be added.
                    if ((null != trackerFeature) && (-1 != trackerFeature.Index))
                    {
                        MapControl.MoveTool.OnMouseDown(worldPosition, e);
                        isMoving = true;
                        return;
                    }
                    if (null != SnapResult)
                    {
                        // todo ?move to FeatureMutator and add support for polygon
                        if (selectTool.FeatureEditors[0].SourceFeature.Geometry is ILineString)
                        {
                            InsertCurvePoint(selectTool.FeatureEditors[0].SourceFeature);
                        }
                        selectTool.FeatureEditors[0].Layer.RenderRequired = true;
                        MapControl.Refresh();
                        return;
                    }
                }
            }
            // if no curvepoint added handle as normal selection
            selectTool.OnMouseDown(worldPosition, e);
        }
示例#10
0
        public void GetFeatureInteractorForLayerWithoutFeatureEditorShouldNotGiveErrorMessage_Tools8065()
        {
            var tool = new SelectTool();
            var layer = new RegularGridCoverageLayer();
            Assert.IsNotNull(layer.FeatureEditor);

            // No message should be generated and null should be returned
            TestHelper.AssertLogMessagesCount(() => Assert.IsNull(tool.GetFeatureInteractor(layer, null)), 0);
        }
示例#11
0
        public override void OnMouseDown(ICoordinate worldPosition, MouseEventArgs e)
        {
            MapControl.SnapTool.Reset();
            SelectTool selectTool                   = MapControl.SelectTool;
            IFeature   oldSelectedFeature           = null;
            IList <ITrackerFeature> focusedTrackers = new List <ITrackerFeature>();
            ITrackerFeature         trackerFeature  = selectTool.GetTrackerAtCoordinate(worldPosition);

            if (null != trackerFeature)
            {
                oldSelectedFeature = trackerFeature.FeatureEditor.SourceFeature;
                focusedTrackers    = trackerFeature.FeatureEditor.GetFocusedTrackers();
            }

            // Let the selecttool handle the mouse event unless multiple trackers have focus and
            // there is no key pressed. In this case the user expects to move the focused trackers
            // and SelectTool will reset them
            if (!((focusedTrackers.Count > 1) && (!selectTool.KeyToggleSelection) &&
                  (!selectTool.KeyExtendSelection) /* && (trackerFeature.Selected)*/))
            {
                selectTool.OnMouseDown(worldPosition, e);
                // did we just deselect out only selected tracker?
                if (null != trackerFeature)
                {
                    int focusedTrackersCount = trackerFeature.FeatureEditor.GetFocusedTrackers().Count;
                    if ((focusedTrackers.Count != focusedTrackersCount) && (0 == focusedTrackersCount))
                    {
                        return;
                    }
                }
            }

            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            if (1 != selectTool.FeatureEditors.Count)
            {
                return;
            }
            dragSource = null;
            if (selectTool.FeatureEditors.Count == 1)
            {
                isBusy = true;
                IFeature feature = selectTool.FeatureEditors[0].SourceFeature;
                if (oldSelectedFeature != feature)
                {
                    if (!selectTool.FeatureEditors[0].AllowSingleClickAndMove())
                    {
                        isBusy = false;
                        return;
                    }
                }

                if (!selectTool.FeatureEditors[0].AllowMove())
                {
                    isBusy = false;
                    return;
                }

                // TODO: this code looks too complicated
                //IFeatureProvider featureProvider = selectTool.MultiSelection[0].Layer.DataSource;
                IFeatureProvider featureProvider = selectTool.FeatureEditors[0].Layer.DataSource;
                // IndexOf doesn;'t work on shapefiles; featurerows are recreated during each read
                int dragIndex = featureProvider.Features.IndexOf(feature);
                if (-1 == dragIndex)
                {
                    isBusy = false;
                    return;
                }
                dragSource = StartDragging(worldPosition, featureProvider.GetFeature(dragIndex));
                if (null == dragSource)
                {
                    isBusy = false;
                    return;
                }
            }
            else
            {
                return;
            }
            MouseDownLocation = worldPosition;
            snappingSource    = null;
            IList <ITrackerFeature> list = selectTool.FeatureEditors[0].GetFocusedTrackers();

            if (null == list)
            {
                return;
            }
            if (list.Count <= 0)
            {
                return;
            }
            if (list.Count == 1)
            {
                snappingSource = list[0];
            }
            return;
        }
示例#12
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 = GetDefaultGeometry(snapResult);

            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);
                    }

                    if (!KeepDuplicates)
                    {
                        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
                    IFeature newFeature;
                    try
                    {
                        if (CloseLine)
                        {
                            lineString = CloseLineString(lineString);
                        }

                        newFeature = 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 (null != newFeature)
                    {
                        //Layer.RenderRequired = true;
                        MapControl.SelectTool.Select(Layer, newFeature, 0);
                    }
                }
                else
                {
                    // do not add a linestring with zero length
                    selectTool.Clear();
                }
                adding = false;
                StopDrawing();
                newLineGeometry.Clear();
            }
            Layer.RenderRequired = true;
            MapControl.Refresh();
            isBusy = false;
        }
示例#13
0
        public override void OnMouseDown(Coordinate worldPosition, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            isBusy = true;

            if (SelectTool.SelectedFeatureInteractors.Count != 1)
            {
                SelectTool.OnMouseDown(worldPosition, e);
                return;
            }
            var featureInteractor = SelectTool.SelectedFeatureInteractors[0];

            if (SupportedGeometry(featureInteractor.SourceFeature.Geometry))
            {
                if (SnapResult == null)
                {
                    SelectTool.OnMouseDown(worldPosition, e);
                    return;
                }

                var trackerFeature = featureInteractor.GetTrackerAtCoordinate(SnapResult.Location);

                // if user click visible tracker it will be handled as move, otherwise a Trackers will be added.
                if (Mode == EditMode.Add && trackerFeature != null && trackerFeature.Index != -1)
                {
                    MoveTool.OnMouseDown(worldPosition, e);
                    isMoving = true;
                    return;
                }

                featureInteractor.Start();

                if (featureInteractor.EditableObject != null)
                {
                    var featureName = featureInteractor.SourceFeature is INameable
                                          ? ((INameable)featureInteractor.SourceFeature).Name
                                          : "";

                    featureInteractor.EditableObject.BeginEdit(string.Format(ActionName + " {0}", featureName));
                }

                var result = Mode == EditMode.Add
                                  ? featureInteractor.InsertTracker(SnapResult.Location, SnapResult.SnapIndexPrevious + 1)
                                  : featureInteractor.RemoveTracker(trackerFeature);

                featureInteractor.Stop();

                if (featureInteractor.EditableObject != null)
                {
                    featureInteractor.EditableObject.EndEdit();
                }

                SelectTool.Select(featureInteractor.Layer, featureInteractor.SourceFeature);

                if (result)
                {
                    featureInteractor.Layer.RenderRequired = true;

                    MapControl.Refresh();

                    return;
                }
            }

            // if no curve point modification, handle as normal selection
            SelectTool.OnMouseDown(worldPosition, e);
        }