コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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;
        }
コード例 #4
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);
        }