Esempio n. 1
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();
        }
Esempio n. 2
0
 public TrackerFeature(IFeatureEditor featureMutator, IGeometry geometry, int index, Bitmap bitmap)
 {
     FeatureEditor = featureMutator;
     Geometry      = geometry;
     Bitmap        = bitmap;
     Index         = index;
 }
Esempio n. 3
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();
            }
        }
Esempio n. 4
0
 public TrackerFeature(IFeatureEditor featureMutator, IGeometry geometry, int index, Bitmap bitmap)
 {
     FeatureEditor = featureMutator;
     Geometry = geometry;
     Bitmap = bitmap;
     Index = index;
 }
Esempio n. 5
0
        // TODO, HACK: what SelectTool has to do with FeatureEditor? Refactor it.
        public IFeatureEditor GetFeatureEditor(ILayer layer, IFeature feature)
        {
            try
            {
                IFeatureEditor featureEditor = null;

                if (null != FeatureEditorCreation)
                {
                    // allow custom feature editor creation
                    featureEditor = FeatureEditorCreation(layer, feature,
                                                          (layer is VectorLayer) ? ((VectorLayer)layer).Style : null);
                }
                if (null == featureEditor)
                {
                    // no custom feature editor; fall back to default editors.
                    featureEditor = FeatureEditorFactory.Create(CoordinateConverter, layer, feature,
                                                                (layer is VectorLayer)
                                                                    ? ((VectorLayer)layer).Style
                                                                    : null);
                }
                return(featureEditor);
            }
            catch (Exception exception)
            {
                log.Error("Error creating feature editor: " + exception.Message);
                return(null);
            }
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        private IGeometry GetDefaultGeometry(ISnapResult snapResult)
        {
            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);
                }
            }
            return(defaultGeometry);
        }
Esempio n. 8
0
        private bool StartSelection(ILayer layer, IFeature feature, int trackerIndex)
        {
            IFeatureEditor featureEditor = GetFeatureEditor(layer, feature);

            if (null == featureEditor)
            {
                return(false);
            }
            if (featureEditor.AllowSingleClickAndMove())
            {
                // do not yet select, but allow MltiSelect
                FeatureEditors.Add(featureEditor);
                SynchronizeTrackers();
                UpdateMapControlSelection();
                return(true);
            }
            return(false);
        }
Esempio n. 9
0
        public void AddSelection(ILayer layer, IFeature feature, int trackerIndex, bool synchronizeUI)
        {
            if (!layer.Enabled)
            {
                return;
            }
            IFeatureEditor featureEditor = GetFeatureEditor(layer, feature);

            if (null == featureEditor)
            {
                return;
            }
            FeatureEditors.Add(featureEditor);
            SynchronizeTrackers();
            if (synchronizeUI)
            {
                UpdateMapControlSelection();
            }
        }
Esempio n. 10
0
        public void DeleteSelection()
        {
            int featuresDeleted = 0;

            for (int i = 0; i < MapControl.SelectTool.FeatureEditors.Count; i++)
            {
                IFeatureEditor featureMutator = MapControl.SelectTool.FeatureEditors[i];
                if (!featureMutator.AllowDeletion())
                {
                    continue;
                }
                featureMutator.Delete();
                featuresDeleted++;
            }
            if (featuresDeleted > 0)
            {
                // Better not to reset the selection if you haven't done anything.
                MapControl.SelectTool.Clear();
            }
        }
Esempio n. 11
0
        public void DeleteSelection()
        {
            if (MapControl.SelectTool.FeatureEditors.Count == 0)
            {
                return;
            }
            int featuresDeleted = 0;

            IEditableObject editableObject = MapControl.SelectTool.FeatureEditors[0].EditableObject;

            for (int i = 0; i < MapControl.SelectTool.FeatureEditors.Count; i++)
            {
                IFeatureEditor featureMutator = MapControl.SelectTool.FeatureEditors[i];
                if (!featureMutator.AllowDeletion())
                {
                    continue;
                }

                if (featuresDeleted == 0 && editableObject != null)
                {
                    editableObject.BeginEdit("Delete feature(s)");
                }

                featureMutator.Delete();
                featuresDeleted++;
            }
            if (featuresDeleted > 0)
            {
                // Better not to reset the selection if you haven't done anything.
                MapControl.SelectTool.Clear();

                if (editableObject != null)
                {
                    editableObject.EndEdit();
                }
            }
        }
Esempio n. 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 = 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;
        }
Esempio n. 13
0
        public override void OnMouseDown(ICoordinate worldPosition, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            var oldSelectedTrackerIndicesCount = SelectedTrackerIndices.Count;
            var oldTrackerFeatureCount         = trackers.Count;

            IsBusy = true;
            ILayer selectedLayer;

            mouseDownLocation = worldPosition;

            // Check first if an object is already selected and if the mousedown has occured at this object.
            ITrackerFeature trackerFeature = GetTrackerAtCoordinate(worldPosition);

            if (FeatureEditors.Count > 1)
            {
                // hack: if multiple selection toggle/select complete feature
                trackerFeature = null;
            }

            SetClickOnExistingSelection(false, null);

            if (null != trackerFeature)
            {
                if (1 == FeatureEditors.Count)
                {
                    SetClickOnExistingSelection(true, worldPosition);
                    FocusTracker(trackerFeature);
                    MapControl.Refresh();
                }
                return;
            }
            // single selection. Find the nearest geometry and give
            float    limit   = (float)MapControlHelper.ImageToWorld(Map, 4);
            IFeature nearest = FindNearestFeature(worldPosition, limit, out selectedLayer, ol => ol.IsVisible);

            if (null != nearest)
            {
                // Create or add a new FeatureEditor
                if (FeatureEditors.Count > 0)
                {
                    IFeatureEditor currentMutator = GetActiveMutator(nearest);
                    if (KeyExtendSelection)
                    {
                        if (null == currentMutator)
                        {
                            // not in selection; add
                            AddSelection(selectedLayer, nearest, -1, true);
                        } // else possibly set default focus tracker
                    }
                    else if (KeyToggleSelection)
                    {
                        if (null == currentMutator)
                        {
                            // not in selection; add
                            AddSelection(selectedLayer, nearest, -1, true);
                        }
                        else
                        {
                            // in selection; remove
                            RemoveSelection(nearest);
                        }
                    }
                    else
                    {
                        // no special key processing; handle as a single select.
                        Clear();
                        if (!StartSelection(selectedLayer, nearest, -1))
                        {
                            StartMultiSelect();
                        }
                        //AddSelection(selectedLayer, nearest, -1);
                    }
                }
                else
                {
                    if (!StartSelection(selectedLayer, nearest, -1))
                    {
                        StartMultiSelect();
                    }
                    //AddSelection(selectedLayer, nearest, -1);
                }
            }
            else
            {
                // We didn't find an object at the position of the mouse button -> start a multiple select
                if (!KeyExtendSelection)
                {
                    // we are not extending the current selection
                    Clear();
                }
                if (e.Button == MouseButtons.Left)
                //if (IsActive)
                {
                    StartMultiSelect();
                }
            }

            if ((oldSelectedTrackerIndicesCount != SelectedTrackerIndices.Count ||
                 oldTrackerFeatureCount != trackers.Count) && trackingLayer.DataSource.Features.Count != 0)
            {
                MapControl.Refresh();
            }
        }
Esempio n. 14
0
        public override void OnMouseDown(ICoordinate worldPosition, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            var oldSelectedTrackerIndicesCount = SelectedTrackerIndices.Count;
            var oldTrackerFeatureCount         = trackers.Count;

            IsBusy = true;
            ILayer selectedLayer;

            mouseDownLocation = worldPosition;

            // Check first if an object is already selected and if the mousedown has occured at this object.
            ITrackerFeature trackerFeature = GetTrackerAtCoordinate(worldPosition);

            if (FeatureEditors.Count > 1)
            {
                // hack: if multiple selection toggle/select complete feature
                trackerFeature = null;
            }

            SetClickOnExistingSelection(false, null);

            if (null != trackerFeature)
            {
                if (1 == FeatureEditors.Count)
                {
                    SetClickOnExistingSelection(true, worldPosition);
                    FocusTracker(trackerFeature);
                    MapControl.Refresh();
                }
                return;
            }
            // single selection. Find the nearest geometry and give
            float    limit   = (float)MapHelper.ImageToWorld(Map, 4);
            IFeature nearest = FindNearestFeature(worldPosition, limit, out selectedLayer, ol => ol.Visible);

            if (null != nearest)
            {
                // Create or add a new FeatureEditor
                if (FeatureEditors.Count > 0)
                {
                    IFeatureEditor currentMutator = GetActiveMutator(nearest);
                    if (KeyExtendSelection)
                    {
                        if (null == currentMutator)
                        {
                            // not in selection; add
                            AddSelection(selectedLayer, nearest, -1, true);
                        } // else possibly set default focus tracker
                    }
                    else if (KeyToggleSelection)
                    {
                        if (null == currentMutator)
                        {
                            // not in selection; add
                            AddSelection(selectedLayer, nearest, -1, true);
                        }
                        else
                        {
                            // in selection; remove
                            RemoveSelection(nearest);
                        }
                    }
                    else
                    {
                        // no special key processing; handle as a single select.
                        Clear(false);
                        if (!StartSelection(selectedLayer, nearest, -1))
                        {
                            StartMultiSelect();
                        }
                        //AddSelection(selectedLayer, nearest, -1);
                    }
                }
                else
                {
                    if (!StartSelection(selectedLayer, nearest, -1))
                    {
                        StartMultiSelect();
                    }
                    //AddSelection(selectedLayer, nearest, -1);
                }
            }
            else
            {
                // We didn't find an object at the position of the mouse button -> start a multiple select
                if (!KeyExtendSelection)
                {
                    // we are not extending the current selection
                    Clear(false);
                }
                if (e.Button == MouseButtons.Left)
                //if (IsActive)
                {
                    StartMultiSelect();
                }
            }

            if ((oldSelectedTrackerIndicesCount != SelectedTrackerIndices.Count ||
                 oldTrackerFeatureCount != trackers.Count) && trackingLayer.DataSource.Features.Count != 0)
            {
                MapControl.Refresh();
            }

            //NS, 2013-09-04
            //Convert LineString to Curve: if numPoint = 2 then convert it...
            //if ((null != nearest)&&(nearest.Geometry.NumPoints == 2))
            //{
            //    // todo ?move to FeatureEditor and add support for polygon
            //    IFeatureEditor featureEditor = GetActiveMutator(nearest);

            //    if (featureEditor.SourceFeature.Geometry is ILineString)
            //    {
            //        featureEditor.EditableObject.BeginEdit(string.Format("Insert curvepoint into feature {0}",
            //                     featureEditor.SourceFeature is DelftTools.Utils.INameable
            //                     ? ((DelftTools.Utils.INameable)featureEditor.SourceFeature).Name
            //                     : ""));
            //        //featureEditor.Stop(SnapResult);
            //        ConvertToCurve(featureEditor.SourceFeature, featureEditor.Layer);
            //        featureEditor.EditableObject.EndEdit();
            //    }
            //    featureEditor.Layer.RenderRequired = true;
            //    MapControl.Refresh();
            //    //return;
            //}
        }