Esempio n. 1
0
        public static IPathFinder GetPathFinder(PathFinderTypes pathFinder)
        {
            switch (pathFinder)
            {
            case PathFinderTypes.OrthogonalPathFinder:
                return(orthogonalPathFinder);

            default:
                return(straightPathFinder);
            }
        }
Esempio n. 2
0
        public Connection(Connector source, Connector sink, PathFinderTypes pathFinder)
        {
            this.ID         = Guid.NewGuid();
            this.Source     = source;
            this.pathFinder = pathFinder;
            this.Sink       = sink;

            this.MouseDown += Connection_MouseDown;

            //base.Unloaded += new RoutedEventHandler(Connection_Unloaded);
        }
 public static IPathFinder GetPathFinder(PathFinderTypes pathFinder)
 {
     switch (pathFinder)
     {
         case PathFinderTypes.OrthogonalPathFinder:
             return orthogonalPathFinder;
         case PathFinderTypes.OrthogonalPathFinderWithoutMargin:
             return orthogonalPathFinderWithoutMargin;
         default:
             return straightPathFinder;
     }
 }
        public void RestoreDiagram(XElement root)
        {
            if (root == null)
            {
                return;
            }

            this.Children.Clear();
            this.SelectionService.ClearSelection();

            IEnumerable <XElement> itemsXML = root.Elements("DesignerItems").Elements("DesignerItem");

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

                raiseDesignerItemAdded(item.Content, item);
            }

            this.InvalidateVisual();

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

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

                String          sourceConnectorName = connectionXML.Element("SourceConnectorName").Value;
                String          sinkConnectorName   = connectionXML.Element("SinkConnectorName").Value;
                PathFinderTypes pathFinder          = (PathFinderTypes)Enum.Parse(typeof(PathFinderTypes), connectionXML.Element("PathFinder").Value);
                SolidColorBrush color           = (SolidColorBrush) new BrushConverter().ConvertFromString(connectionXML.Element("Color").Value);
                double          strokeThickness = Double.Parse(connectionXML.Element("StrokeThickness")?.Value);

                Connector sourceConnector = GetConnector(sourceID, sourceConnectorName);
                Connector sinkConnector   = GetConnector(sinkID, sinkConnectorName);

                Connection connection = ConnectionGenerator(sourceConnector, sinkConnector, pathFinder);
                //Canvas.SetZIndex(connection, Int32.Parse(connectionXML.Element("zIndex").Value));
                connection.ShowShadow      = bool.Parse(connectionXML.Element("ShowShadow").Value);
                connection.ZIndex          = Int32.Parse(connectionXML.Element("zIndex").Value);
                connection.Color           = color;
                connection.StrokeThickness = strokeThickness;
                this.Children.Add(connection);
            }
        }
Esempio n. 5
0
        private void Open_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            XElement root = LoadSerializedDataFromFile();

            if (root == null)
            {
                return;
            }

            this.Children.Clear();
            this.SelectionService.ClearSelection();

            IEnumerable <XElement> itemsXML = root.Elements("DesignerItems").Elements("DesignerItem");

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

                raiseDesignerItemAdded(item.Content, item);
            }

            this.InvalidateVisual();

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

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

                String          sourceConnectorName = connectionXML.Element("SourceConnectorName").Value;
                String          sinkConnectorName   = connectionXML.Element("SinkConnectorName").Value;
                PathFinderTypes pathFinder          = (PathFinderTypes)Enum.Parse(typeof(PathFinderTypes), connectionXML.Element("PathFinder").Value);


                Connector sourceConnector = GetConnector(sourceID, sourceConnectorName);
                Connector sinkConnector   = GetConnector(sinkID, sinkConnectorName);

                Connection connection = ConnectionGenerator(sourceConnector, sinkConnector, pathFinder);
                //Canvas.SetZIndex(connection, Int32.Parse(connectionXML.Element("zIndex").Value));
                connection.ZIndex = Int32.Parse(connectionXML.Element("zIndex").Value);
                this.Children.Add(connection);
            }
        }
Esempio n. 6
0
        public Connection(Connector source, Connector sink, PathFinderTypes pathFinder)
        {
            this.ID = Guid.NewGuid();
            this.Source = source;
            this.pathFinder = pathFinder;
            this.Sink = sink;

            this.MouseDown += Connection_MouseDown;

            //base.Unloaded += new RoutedEventHandler(Connection_Unloaded);
        }
Esempio n. 7
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);

            foreach (XElement itemXML in itemsXML)
            {
                Guid oldID = new Guid(itemXML.Element("ID").Value);
                Guid newID = Guid.NewGuid();
                //mappingOldToNewIDs.Add(oldID, newID);
                DesignerItem item = DeserializeDesignerItem(itemXML, newID, offsetX, offsetY);
                this.Children.Add(item);
                SetConnectorDecoratorTemplate(item);
                newItems.Add(item);

                raiseDesignerItemAdded(item.Content, item);

                mappingOldToNewIDs.Add(oldID, item.ID);
                //mappingOldToNewIDs[oldID] = item.ID;
            }

            // 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);
                }
            }

            SelectionService.RaiseSelectionChanged();

            // 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;
                    PathFinderTypes pathFinder          = (PathFinderTypes)Enum.Parse(typeof(PathFinderTypes), connectionXML.Element("PathFinder").Value);

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

                    Connection connection = ConnectionGenerator(sourceConnector, sinkConnector, pathFinder);
                    //Canvas.SetZIndex(connection, Int32.Parse(connectionXML.Element("zIndex").Value));
                    connection.ZIndex = 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);
        }