Esempio n. 1
0
        void ProcessEntity(object data, Point point)
        {
            var control = DesignManager.CreateDesignControl(data);

            Canvas.SetLeft(control, point.X);
            Canvas.SetTop(control, point.Y);
            Draw(control);
            if (DesignManager.IsAutoConnectNode != null && DesignManager.IsAutoConnectNode())
            {
                AutoAddConnection(control);
            }
        }
Esempio n. 2
0
        void ProcessLink(object data, Point point)
        {
            if (data == null)
            {
                return;
            }

            var l = DesignManager.GetDesignLink(data);

            if (l == null)
            {
                return;
            }

            var s = GetItemByID(l.Item1);
            var t = GetItemByID(l.Item2);

            if (s == null && t == null)
            {
                CommonProc.ShowMessage("Error", "Link source item and target item does not exist in diagram");
                return;
            }
            if (s == null)
            {
                var control = DesignManager.CreateDesignControl(s);
                Canvas.SetLeft(control, point.X);
                Canvas.SetTop(control, point.Y);
                Draw(control);
                if (DesignManager.IsAutoConnectNode != null && DesignManager.IsAutoConnectNode())
                {
                    AutoAddConnection(control);
                }
            }
            if (t == null)
            {
                var control = DesignManager.CreateDesignControl(t);
                Canvas.SetLeft(control, point.X);
                Canvas.SetTop(control, point.Y);
                Draw(control);
                if (DesignManager.IsAutoConnectNode != null && DesignManager.IsAutoConnectNode())
                {
                    AutoAddConnection(control);
                }
            }
            Connect(l);
        }
Esempio n. 3
0
        public void InitContextMemu(Dictionary <string, Func <FrameworkElement> > createCommandList)
        {
            contextFlyout = new MenuFlyout();

            MenuFlyoutItem pasteItem = new MenuFlyoutItem {
                Text = "Paste"
            };

            pasteItem.Click += (s, e) =>
            {
                object data;
                if (Clipboard.GetContent().Properties.TryGetValue("entity", out data))
                {
                    ProcessEntity(data, contextMenuPoint);
                }
                if (Clipboard.GetContent().Properties.TryGetValue("link", out data))
                {
                    ProcessLink(data, contextMenuPoint);
                }
            };
            contextFlyout.Items.Add(pasteItem);
            contextFlyout.Items.Add(new MenuFlyoutSeparator());

            MenuFlyoutItem saveItem = new MenuFlyoutItem {
                Text = "Save"
            };

            saveItem.Click += SaveMenu_OnClick;
            contextFlyout.Items.Add(saveItem);
            MenuFlyoutItem loadItem = new MenuFlyoutItem {
                Text = "Load"
            };

            loadItem.Click += LoadMenu_OnClick;
            contextFlyout.Items.Add(loadItem);

            contextFlyout.Items.Add(new MenuFlyoutSeparator());

            if (createCommandList != null)
            {
                foreach (var ccommand in createCommandList)
                {
                    MenuFlyoutItem addItem = new MenuFlyoutItem
                    {
                        Text = "Add " + ccommand.Key,
                    };
                    addItem.Click += (s, e) =>
                    {
                        var control  = ccommand.Value();
                        var dcontrol = DesignManager.CreateDesignControl(control);
                        Canvas.SetLeft(dcontrol, contextMenuPoint.X);
                        Canvas.SetTop(dcontrol, contextMenuPoint.Y);
                        Draw(dcontrol);
                    };
                    contextFlyout.Items.Add(addItem);
                }
            }

            contextFlyout.Items.Add(new MenuFlyoutSeparator());
            MenuFlyoutItem fitItem = new MenuFlyoutItem {
                Text = "Auto fit"
            };

            loadItem.Click += (s, e) =>
            {
                ActoSize();
            };
            contextFlyout.Items.Add(fitItem);
        }