Ejemplo n.º 1
0
        public PasteResult Paste(int layerHandle, IFeatureSet fs)
        {
            if (fs == null || IsEmpty || !fs.InteractiveEditing)
            {
                return(PasteResult.NoInput);
            }

            if (_buffer.GeometryType != fs.GeometryType)
            {
                return(PasteResult.ShapeTypeMismatch);
            }

            var fieldMap = _buffer.Table.BuildFieldMap(fs.Table);

            var history = _map.History;

            history.BeginBatch();

            fs.ClearSelection();

            for (int i = 0; i < _buffer.Features.Count; i++)
            {
                // don't create a copy, buffer won't be used any more
                int shapeIndex = fs.Features.EditAdd(_buffer.Features[i].Geometry.Clone());

                _buffer.Table.CopyAttributes(i, fs.Table, shapeIndex, fieldMap);   // TODO: don't use field map for the same FeatureSet
                history.Add(UndoOperation.AddShape, layerHandle, shapeIndex);
                fs.Features[shapeIndex].Selected = true;
            }

            history.EndBatch();

            Clear();
            return(PasteResult.Ok);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Changes selection of the feature set adding new shapes using the specified mode
        /// </summary>
        public static void UpdateSelection(this IFeatureSet fs, IEnumerable <int> indices, SelectionOperation mode)
        {
            if (fs == null || indices == null)
            {
                return;
            }

            if (mode == SelectionOperation.New)
            {
                fs.ClearSelection();
            }

            var sf = fs.GetInternal();

            switch (mode)
            {
            case SelectionOperation.New:
                foreach (var item in indices)
                {
                    sf.ShapeSelected[item] = true;
                }
                break;

            case SelectionOperation.Add:
                foreach (var item in indices)
                {
                    sf.ShapeSelected[item] = true;
                }

                break;

            case SelectionOperation.Exclude:
                foreach (var item in indices)
                {
                    sf.ShapeSelected[item] = false;
                }

                break;

            case SelectionOperation.Invert:
                foreach (var item in indices)
                {
                    sf.ShapeSelected[item] = !sf.ShapeSelected[item];
                }
                break;
            }
        }