示例#1
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.LeftButton != MouseButtonState.Pressed)
                this.dragStartPoint = null;

            if (this.dragStartPoint.HasValue)
            {
                // XamlWriter.Save() has limitations in exactly what is serialized,
                // see SDK documentation; short term solution only;
                string xamlString = XamlWriter.Save(this.Content);
                DragObject dataObject = new DragObject();
                dataObject.Xaml = xamlString;

                WrapPanel panel = VisualTreeHelper.GetParent(this) as WrapPanel;
                if (panel != null)
                {
                    // desired size for DesignerCanvas is the stretched Toolbox item size
                    double scale = 1.3;
                    dataObject.DesiredSize = new Size(panel.ItemWidth * scale, panel.ItemHeight * scale);
                }

                DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);

                e.Handled = true;
            }
        }
        static void Fe_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Point? dragStartPoint = GetDragStartPoint((DependencyObject)sender);

            if (e.LeftButton != MouseButtonState.Pressed)
                dragStartPoint = null;

            if (dragStartPoint.HasValue)
            {
                DragObject dataObject = new DragObject();
                dataObject.ContentType = (((FrameworkElement)sender).DataContext as ToolBoxData).Type;
                dataObject.DesiredSize = new Size(65, 65);
                DragDrop.DoDragDrop((DependencyObject)sender, dataObject, DragDropEffects.Copy);
                e.Handled = true;
            }
        }
        private void Parent_MouseMove(object sender, MouseEventArgs e)
        {
            if(e.LeftButton != MouseButtonState.Pressed) {
                isDragging = false;
            }

            if(isDragging == false) {
                return;
            }

            var dataObject = new DragObject { formatStr = Palleter.palleterFormatName, data = Interface_Element.ElementName };
            dataObject.DesiredSize = new Size(100, 100);
            //получаем панель, на которой расположен элемент
            //начанаем операцию DragDrop
            DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);
            //сообщение обработали
            e.Handled = true;
            //что бы не начинать операцию Drag&Drop повторно при любом сдвиге мыши, сбрасываем флаг переноса
            isDragging = false;
        }
示例#4
0
        protected override void OnDrop(DragEventArgs e)
        {
            DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;

            if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml))
            {
                DesignerItem newItem = null;
                if (dragObject.DesignerItem == null)
                {
                    Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml)));

                    if (content != null)
                    {
                        itemCounter = this.Children.OfType <DesignerItem>().Where(x => x.Tag.ToString() == dragObject.Class).Count();

                        newItem         = new DesignerItem(Guid.NewGuid(), dragObject.Class, ++itemCounter);
                        newItem.Content = content;

                        Point position = e.GetPosition(this);

                        if (dragObject.DesiredSize.HasValue)
                        {
                            Size desiredSize = dragObject.DesiredSize.Value;
                            newItem.Width  = desiredSize.Width;
                            newItem.Height = desiredSize.Height;

                            DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2));
                            DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2));
                        }
                        else
                        {
                            DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X));
                            DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y));
                        }

                        Canvas.SetZIndex(newItem, this.Children.Count);
                        this.Children.Add(newItem);

                        SetConnectorDecoratorTemplate(newItem);

                        DrawConnection(newItem.ID, OperationGuid);
                        ResourceWindow.UpdateResource(newItem);

                        //update selection
                        this.SelectionService.SelectItem(newItem);
                        newItem.Focus();
                    }
                    e.Handled = true;
                }
                else
                {
                    newItem = dragObject.DesignerItem;
                    if (!(newItem.Parent is DesignerCanvas))
                    {
                        newItem.Width  = 60;
                        newItem.Height = 60;

                        //Toolbox.Items.Remove(Toolbox.Items.OfType<ToolboxItem>().Where(x => x.DesignerItem == newItem).FirstOrDefault());
                        ((ToolboxItem)Toolbox.Items[0]).Content = null;
                        Toolbox.Items.RemoveAt(0);
                        //var parent = newItem.Parent;


                        Point position = e.GetPosition(this);
                        DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2));
                        DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2));

                        Canvas.SetZIndex(newItem, this.Children.Count);
                        this.Children.Add(newItem);

                        SetConnectorDecoratorTemplate(newItem);

                        DrawConnection(newItem.ID, OperationGuid);
                        ResourceWindow.UpdateResource(newItem);

                        this.SelectionService.SelectItem(newItem);
                        newItem.Focus();
                    }

                    e.Handled = true;
                }
                newItem.MouseDoubleClick += DesignerItem_MouseDoubleClick;

                //MessageBox.Show("resourcecanvas: " + newItem.BoundLogicItem.ID.ToString());
            }
        }
 public virtual object CreateInstanceFromDragObject(DragObject dragObject)
 {
     return Activator.CreateInstance(dragObject.ObjectType);
 }
示例#6
0
 public virtual object CreateInstanceFromDragObject(DragObject dragObject)
 {
     return(Activator.CreateInstance(dragObject.ObjectType));
 }
示例#7
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                this.dragStartPoint = null;
            }

            if (this.dragStartPoint.HasValue)
            {
                // XamlWriter.Save() has limitations in exactly what is serialized,
                // see SDK documentation; short term solution only;
                string     xamlString = XamlWriter.Save(this.Content);
                DragObject dataObject = new DragObject();
                dataObject.Xaml  = xamlString;
                dataObject.Class = dataObject.GetClassByTag();
                this.Tag         = dataObject.Class;


                WrapPanel panel = VisualTreeHelper.GetParent(this) as WrapPanel;
                if (panel != null)
                {
                    // desired size for DesignerCanvas is the stretched Toolbox item size
                    double scale = 1.3;
                    dataObject.DesiredSize = new Size(panel.ItemWidth * scale, panel.ItemHeight * scale);
                }

                if (DesignerItem != null)
                {
                    dataObject.DesignerItem = DesignerItem;
                }

                #region  аннее
                //var _dataObject = new object();
                //object designerItem = this;
                //if (designerItem is DesignerItem)
                //{
                //    _dataObject = designerItem;
                //}
                //else
                //{
                //    // XamlWriter.Save() has limitations in exactly what is serialized,
                //    // see SDK documentation; short term solution only;
                //    string xamlString = XamlWriter.Save(this.Content);
                //    DragObject dataObject = new DragObject();
                //    dataObject.Xaml = xamlString;
                //    dataObject.Class = dataObject.GetClassByTag();
                //    this.Tag = dataObject.Class; WrapPanel panel = VisualTreeHelper.GetParent(this) as WrapPanel;

                //    if (panel != null)
                //    {
                //        // desired size for DesignerCanvas is the stretched Toolbox item size
                //        double scale = 1.3;
                //        dataObject.DesiredSize = new Size(panel.ItemWidth * scale, panel.ItemHeight * scale);
                //    }
                //    _dataObject = dataObject;
                //}
                #endregion

                DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);

                e.Handled = true;
            }
        }
示例#8
0
        protected override void OnDrop(DragEventArgs e)
        {
            //base.OnDrop(e);

            #region FileImport

            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                // Can have more than one file.
                string[]      files         = (string[])e.Data.GetData(DataFormats.FileDrop);
                List <string> validSNPFiles = new List <string>();
                foreach (string file in files)
                {
                    if (TouchstoneFile.ExtensionIsValid(file))
                    {
                        validSNPFiles.Add(file);
                    }
                }

                if (validSNPFiles.Count > 0)
                {
                    Point  position       = e.GetPosition(this);
                    Vector positionOffset = new Vector(0, 0);
                    foreach (string validFile in validSNPFiles)
                    {
                        TouchstoneFile   touchstoneFile = new TouchstoneFile();
                        TouchstoneResult touchstoneResult;
                        try
                        {
                            touchstoneResult = touchstoneFile.Read(validFile);
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine(exception);
                            throw;
                        }

                        if (touchstoneResult != null)
                        {
                            ImportedComponentModel importedComponentModel = new ImportedComponentModel();
                            importedComponentModel.Size     = new Size(60, 50);
                            importedComponentModel.Position = Point.Add(position, positionOffset);
                            positionOffset = Vector.Add(positionOffset, new Vector(10, 10));
                            importedComponentModel.LoadFromTouchstoneResult(touchstoneResult);
                            importedComponentModel.FileName = validFile;
                            importedComponentModel.Name     = Path.GetFileNameWithoutExtension(validFile);

                            if (DataContext is MainVM mainVM)
                            {
                                if (mainVM.AddElement is RelayCommand relayCommand)
                                {
                                    relayCommand.Run(importedComponentModel);
                                }
                                else
                                {
                                    throw new Exception("MainVM AddElement Command should be type of RelayCommand");
                                }
                            }
                            else
                            {
                                throw new Exception("DataContext of DesignerCanvas should be MainVM type");
                            }
                        }
                    }
                }
            }

            #endregion

            #region Drag from toolbox / Copy by drag

            DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;
            DragString dragString = e.Data.GetData(typeof(DragString)) as DragString;
            if (dragObject != null)
            {
                Point position = e.GetPosition(this);

                double width  = dragObject.DesiredSize.Width;
                double height = dragObject.DesiredSize.Height;

                double left = Math.Max(0, position.X - width / 2);
                double top  = Math.Max(0, position.Y - height / 2);

                Element NewElement = Creator.CreateElementByType(dragObject.Type, width, height, top, left);

                if (DataContext is MainVM mainVM)
                {
                    if (mainVM.AddElement is RelayCommand relayCommand)
                    {
                        relayCommand.Run(NewElement);
                    }
                    else
                    {
                        throw new Exception("MainVM AddElement Command should be type of RelayCommand");
                    }
                }
                else
                {
                    throw new Exception("DataContext of DesignerCanvas should be MainVM type");
                }

                e.Handled = true;
            }
            else if (dragString != null)
            {
                if (DataContext is MainVM mainVM)
                {
                    Vector elementsShift = Point.Subtract(e.GetPosition(this), dragString.DragPointStart);
                    mainVM.ReadAndShiftElementsAndConnectionsFromString(dragString.DraggedString, elementsShift);
                }
            }

            #endregion
        }
示例#9
0
        public DesignerItem getElement(DragObject data)
        {
            if(data.data == null) {
                Debugger.Break(); // отсутствие данных
                return new DesignerItem {
                };
            }
            if(data.data.ToString() == Class_Element.ElementName) {
                var refRes = new DesignerItem {
                    Content = new Class_Element()
                };
                refRes.Connectors = new Connector[]{
                    new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"),
                    new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"),
                    new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"),
                    new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right")
                };
                return refRes;
            }
            if(data.data.ToString() == Interface_Element.ElementName) {
                var refRes = new DesignerItem {
                    Content = new Interface_Element()
                };
                refRes.Connectors = new Connector[]{
                    new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"),
                    new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"),
                    new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"),
                    new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right")
                };
                return refRes;
            }
            if(data.data.ToString() == Objects_Element.ElementName) {
                var refRes = new DesignerItem {
                    Content = new Objects_Element()
                };
                refRes.Connectors = new Connector[]{
                    new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"),
                    new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"),
                    new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"),
                    new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right")
                };
                return refRes;
            }
            if(data.data.ToString() == Node_Element.ElementName) {
                var refRes = new DesignerItem {
                    Content = new Node_Element()
                };
                refRes.Connectors = new Connector[]{
                    new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"),
                    new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"),
                    new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"),
                    new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right")
                };
                return refRes;
            }
            if(data.data.ToString() == Package_Element.ElementName) {
                var refRes = new DesignerItem {
                    Content = new Package_Element()
                };
                refRes.Connectors = new Connector[]{
                    new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"),
                    new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"),
                    new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"),
                    new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right")
                };
                return refRes;
            }
            if(data.data.ToString() == Component_Element.ElementName) {
                var refRes = new DesignerItem {
                    Content = new Component_Element()
                };
                refRes.Connectors = new Connector[]{
                    new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"),
                    new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"),
                    new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"),
                    new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right")
                };
                return refRes;
            }
            if(data.data.ToString() == Remark_Element.ElementName) {
                var refRes = new DesignerItem {
                    Content = new Remark_Element()
                };
                refRes.Connectors = new Connector[]{
                    new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"),
                    new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"),
                    new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"),
                    new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right")
                };
                return refRes;
            }
            if(data.data.ToString() == Scenario_Element.ElementName) {
                var refRes = new DesignerItem {
                    Content = new Scenario_Element()
                };
                refRes.Connectors = new Connector[]{
                    new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"),
                    new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"),
                    new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"),
                    new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right")
                };
                return refRes;
            }
            if(data.data.ToString() == Actor_Element.ElementName) {
                var refRes = new DesignerItem {
                    Content = new Actor_Element()
                };
                refRes.Connectors = new Connector[]{
                    new Connector(ConnectorOrientation.Top, refRes, 0.5, 0, "Top"),
                    new Connector(ConnectorOrientation.Bottom, refRes, 0.5, 1, "Bottom"),
                    new Connector(ConnectorOrientation.Left, refRes, 0, 0.5, "Left"),
                    new Connector(ConnectorOrientation.Right, refRes, 1, 0.5, "Right")
                };
                return refRes;
            }

            Debugger.Break(); // непредусмотренное название фигуры
            var res = new DesignerItem {
            };
            res.Connectors = new Connector[]{
                new Connector(ConnectorOrientation.Top, res, 0.5, 0, "Top"),
                new Connector(ConnectorOrientation.Bottom, res, 0.33, 1, "Bottom_Left"),
                new Connector(ConnectorOrientation.Bottom, res, 0.67, 1, "Bottom_Right"),
                new Connector(ConnectorOrientation.None, res, 0.5, 1, "Bottom_Center")
            };
            return res;
        }
示例#10
0
        public virtual DragObject GetDragObject()
        {
            DragObject dataObject = new DragObject();
            dataObject.ObjectType = this.Content.GetType();

            var panel = VisualTreeHelper.GetParent(this) as Panel;
            if (panel != null)
            {
                dataObject.DesiredSize = GetDesiredSize((DependencyObject)this.Content);

                dataObject.InsertInBackground = GetInsertInBackground((DependencyObject)this.Content);
                // desired size for DesignerCanvas is the stretched Toolbox item size
                if (dataObject.DesiredSize == Size.Empty)
                {
                    double scale = 1.3;
                    if (panel is WrapPanel)
                        dataObject.DesiredSize = new Size(((WrapPanel)panel).ItemWidth * scale, ((WrapPanel)panel).ItemHeight * scale);
                }
            }

            return dataObject;
        }