Ejemplo n.º 1
0
 private void SetConnectorDecoratorTemplate(DesignerItem item, ControlTemplate template)
 {
     if (item.ApplyTemplate())
     {
         Control decorator = item.Template.FindName("PART_ConnectorDecorator", item) as Control;
         if (decorator != null && template != null)
         {
             decorator.Template = template;
             decorator.ApplyTemplate();
         }
     }
 }
Ejemplo n.º 2
0
        private Connector GetConnector(Guid itemID, String connectorName)
        {
            DesignerItem designerItem = (from item in this.Children.OfType <DesignerItem>()
                                         where item.ID == itemID
                                         select item).FirstOrDefault();

            Control connectorDecorator = designerItem.Template.FindName("PART_ConnectorDecorator", designerItem) as Control;

            connectorDecorator.ApplyTemplate();

            return(connectorDecorator.Template.FindName(connectorName, connectorDecorator) as Connector);
        }
        public static List <DesignerItem> LoadDiagramDesignerItems(XElement root, List <ModuleDescription> moduleDescriptions)
        {
            List <DesignerItem>    designerItems = new List <DesignerItem>();
            IEnumerable <XElement> itemsXML      = root.Elements("DesignerItems").Elements("DesignerItem");

            foreach (XElement itemXML in itemsXML)
            {
                Guid         id   = new Guid(itemXML.Element("ID").Value);
                DesignerItem item = DeserializeDesignerItem(moduleDescriptions, itemXML, id, 0, 0);

                designerItems.Add(item);
            }
            return(designerItems);
        }
Ejemplo n.º 4
0
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);
            DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;

            if (dragObject != null)
            {
                DesignerItem newItem = null;
                Object       content = GetContent("Process", "Process_DragThumb", dragObject.ModuleDescription);
                if (content != null)
                {
                    newItem                   = new DesignerItem();
                    newItem.Content           = content;
                    newItem.ModuleDescription = dragObject.ModuleDescription;

                    // Next to do - save and load moduledescription on designerItems!
                    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);
                    SetDesignerItemConnectorDecoratorTemplate(newItem);

                    //update selection
                    this.SelectionService.SelectItem(newItem);
                    newItem.Focus();
                }

                e.Handled = true;
            }
        }
        private static DesignerItem DeserializeDesignerItem(List <ModuleDescription> moduleDescriptions, XElement itemXML, Guid id, double OffsetX, double OffsetY)
        {
            DesignerItem item = new DesignerItem(id);

            item.Width    = Double.Parse(itemXML.Element("Width").Value, CultureInfo.InvariantCulture);
            item.Height   = Double.Parse(itemXML.Element("Height").Value, CultureInfo.InvariantCulture);
            item.ParentID = new Guid(itemXML.Element("ParentID").Value);
            item.IsGroup  = Boolean.Parse(itemXML.Element("IsGroup").Value);
            var itemLabel = itemXML.Element("ItemLabel");

            item.ItemLabel = itemLabel == null ? "" : itemLabel.Value;
            Canvas.SetLeft(item, Double.Parse(itemXML.Element("Left").Value, CultureInfo.InvariantCulture) + OffsetX);
            Canvas.SetTop(item, Double.Parse(itemXML.Element("Top").Value, CultureInfo.InvariantCulture) + OffsetY);
            Canvas.SetZIndex(item, Int32.Parse(itemXML.Element("zIndex").Value));

            item.ModuleDescription = moduleDescriptions.Where(t => t.ModuleType.Name == itemXML.Element("ModuleDescription").Value).FirstOrDefault();

            return(item);
        }
Ejemplo n.º 6
0
        private void CopyCurrentSelection()
        {
            IEnumerable <DesignerItem> selectedDesignerItems =
                this.SelectionService.CurrentSelection.OfType <DesignerItem>();

            List <Connection> selectedConnections =
                this.SelectionService.CurrentSelection.OfType <Connection>().ToList();

            foreach (Connection connection in this.Children.OfType <Connection>())
            {
                if (!selectedConnections.Contains(connection))
                {
                    DesignerItem sourceItem = (from item in selectedDesignerItems
                                               where item.ID == connection.Source.ParentDesignerItem.ID
                                               select item).FirstOrDefault();

                    DesignerItem sinkItem = (from item in selectedDesignerItems
                                             where item.ID == connection.Sink.ParentDesignerItem.ID
                                             select item).FirstOrDefault();

                    if (sourceItem != null &&
                        sinkItem != null &&
                        BelongToSameGroup(sourceItem, sinkItem))
                    {
                        selectedConnections.Add(connection);
                    }
                }
            }

            XElement designerItemsXML = SerializeDesignerItems(selectedDesignerItems);
            XElement connectionsXML   = SerializeConnections(selectedConnections);

            XElement root = new XElement("Root");

            root.Add(designerItemsXML);
            root.Add(connectionsXML);

            root.Add(new XAttribute("OffsetX", 10));
            root.Add(new XAttribute("OffsetY", 10));

            Clipboard.Clear();
            Clipboard.SetData(DataFormats.Xaml, root);
        }
        private void SetDesignerItemConnectorDecoratorTemplate(DesignerItem designerItem)
        {
            switch (designerItem.ModuleDescription.Attributes.ModuleType)
            {
            case ModuleType.Step:
                SetConnectorDecoratorTemplate(designerItem, DesignerItemControlTemplates["DefaultDecoratorWithErrorTemplate"]);
                break;

            case ModuleType.Transformation:
                if (designerItem.ModuleDescription.ModuleType.Name == "JoinRecords")
                {
                    SetConnectorDecoratorTemplate(designerItem, DesignerItemControlTemplates["MergeDecoratorTemplate"]);
                }
                else
                {
                    SetConnectorDecoratorTemplate(designerItem, DesignerItemControlTemplates["DefaultDecoratorTemplate"]);
                }
                break;

            default:
                SetConnectorDecoratorTemplate(designerItem, DesignerItemControlTemplates["DefaultDecoratorTemplate"]);
                break;
            }
        }
Ejemplo n.º 8
0
 public void RaiseMagnifyDoubleClick(DesignerItem designerItem)
 {
     RaiseEvent(new RoutedEventArgs(DesignerCanvas.MagnifyDoubleClickEvent, designerItem));
 }
Ejemplo n.º 9
0
        private void Paste_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            XElement root = LoadSerializedDataFromClipBoard();

            if (root == null)
            {
                return;
            }

            // create DesignerItems
            Dictionary <Guid, Guid> mappingOldToNewIDs = new Dictionary <Guid, Guid>();
            List <ISelectable>      newItems           = new List <ISelectable>();
            IEnumerable <XElement>  itemsXML           = root.Elements("DesignerItems").Elements("DesignerItem");

            double offsetX = Double.Parse(root.Attribute("OffsetX").Value, CultureInfo.InvariantCulture);
            double offsetY = Double.Parse(root.Attribute("OffsetY").Value, CultureInfo.InvariantCulture);

            Style itemStyle = (Style)FindResource("Process");
            Style itemControlTemplateStyle = (Style)FindResource("Process_DragThumb");

            foreach (XElement itemXML in itemsXML)
            {
                Guid oldID = new Guid(itemXML.Element("ID").Value);
                Guid newID = Guid.NewGuid();
                mappingOldToNewIDs.Add(oldID, newID);
                DesignerItem item = DeserializeDesignerItem(this.ModuleDescriptions, itemXML, newID, offsetX, offsetY);
                item.Content = GetContentItem(itemStyle, itemControlTemplateStyle, item.ModuleDescription);
                this.Children.Add(item);
                SetDesignerItemConnectorDecoratorTemplate(item);
                newItems.Add(item);
            }

            // update group hierarchy
            SelectionService.ClearSelection();
            foreach (DesignerItem el in newItems)
            {
                if (el.ParentID != Guid.Empty)
                {
                    el.ParentID = mappingOldToNewIDs[el.ParentID];
                }
            }


            foreach (DesignerItem item in newItems)
            {
                if (item.ParentID == Guid.Empty)
                {
                    SelectionService.AddToSelection(item);
                }
            }

            // create Connections
            IEnumerable <XElement> connectionsXML = root.Elements("Connections").Elements("Connection");

            foreach (XElement connectionXML in connectionsXML)
            {
                Guid oldSourceID = new Guid(connectionXML.Element("SourceID").Value);
                Guid oldSinkID   = new Guid(connectionXML.Element("SinkID").Value);

                if (mappingOldToNewIDs.ContainsKey(oldSourceID) && mappingOldToNewIDs.ContainsKey(oldSinkID))
                {
                    Guid newSourceID = mappingOldToNewIDs[oldSourceID];
                    Guid newSinkID   = mappingOldToNewIDs[oldSinkID];

                    String sourceConnectorName = connectionXML.Element("SourceConnectorName").Value;
                    String sinkConnectorName   = connectionXML.Element("SinkConnectorName").Value;

                    Connector sourceConnector = GetConnector(newSourceID, sourceConnectorName);
                    Connector sinkConnector   = GetConnector(newSinkID, sinkConnectorName);

                    Connection connection = new Connection(sourceConnector, sinkConnector);
                    Canvas.SetZIndex(connection, Int32.Parse(connectionXML.Element("zIndex").Value));
                    this.Children.Add(connection);

                    SelectionService.AddToSelection(connection);
                }
            }

            DesignerCanvas.BringToFront.Execute(null, this);

            // update paste offset
            root.Attribute("OffsetX").Value = (offsetX + 10).ToString();
            root.Attribute("OffsetY").Value = (offsetY + 10).ToString();
            Clipboard.Clear();
            Clipboard.SetData(DataFormats.Xaml, root);

            if (OnPastedCurrentSelection != null)
            {
                OnPastedCurrentSelection(sender, new ItemsPastedEventArgs()
                {
                    MappingOldToNewIDs = mappingOldToNewIDs
                });
            }
        }