Beispiel #1
0
        public static void RemoveDrawObjects(this ICanvasDataContext canvasDataContext, ICollection <DrawObject> drawObjects)
        {
            if (drawObjects == null)
            {
                throw new ArgumentNullException(nameof(drawObjects));
            }

            if (drawObjects.Count == 0)
            {
                return;
            }

            //激发即将移除事件;
            var removingArgs = new CanvasDrawObjectsRemovingEventArgs(drawObjects, canvasDataContext);

            CommonEventHelper.Publish <CanvasDrawObjectsRemovingEvent, CanvasDrawObjectsRemovingEventArgs>(removingArgs);
            CommonEventHelper.PublishEventToHandlers <ICanvasDrawObjectsRemovingEventHandler, CanvasDrawObjectsRemovingEventArgs>(removingArgs);
            //若指示取消或集合为空,则不继续执行;
            if (removingArgs.Cancel || removingArgs.RemovingDrawObjects.Count == 0)
            {
                return;
            }

            var removingGroups = removingArgs.RemovingDrawObjects.
                                 GroupBy(p => p.Parent as CanvasLayer).Where(p => p.Key != null).ToArray();

            void RemoveDrawObjects()
            {
                try {
                    foreach (var tuple in removingGroups)
                    {
                        tuple.Key.RemoveDrawObjects(tuple);
                    }
                }
                catch (Exception ex) {
                    LoggerService.WriteException(ex);
                    MsgBoxService.ShowError(ex.Message);
                }
            }

            void AddDrawObjects()
            {
                try {
                    foreach (var tuple in removingGroups)
                    {
                        tuple.Key.AddDrawObjects(tuple);
                    }
                }
                catch (Exception ex) {
                    LoggerService.WriteException(ex);
                    MsgBoxService.ShowError(ex.Message);
                }
            }

            RemoveDrawObjects();

            var action = new StandardEditTransaction(AddDrawObjects, RemoveDrawObjects);

            canvasDataContext.CommitTransaction(action);
        }
Beispiel #2
0
        public static void AddDrawObjects(this ICanvasDataContext canvasDataContext, ICollection <DrawObject> drawObjects)
        {
            if (drawObjects == null)
            {
                throw new ArgumentNullException(nameof(drawObjects));
            }

            if (drawObjects.Count == 0)
            {
                return;
            }

            var activeLayer = canvasDataContext.ActiveLayer;

            if (activeLayer == null)
            {
                return;
                //throw new InvalidOperationException(LanguageService.FindResourceString(Exception_ActiveLayerCannotBeNull));
            }

            void AddDrawObjects()
            {
                activeLayer.AddDrawObjects(drawObjects);
            };

            void RemoveDrawObjects()
            {
                activeLayer.RemoveDrawObjects(drawObjects);
            }

            AddDrawObjects();

            var transaction = new StandardEditTransaction(RemoveDrawObjects, AddDrawObjects);

            canvasDataContext.CommitTransaction(transaction);
        }