Exemplo n.º 1
0
        public void SynchronizeConnectors()
        {
            string node_source      = NodeSource;
            string connector_source = ConnectorSource;
            var    k    = ModelSource;
            var    type = k.GetType();
            var    connectorsproperty = type.GetProperty(connector_source);
            var    connectors         = connectorsproperty.GetValue(k) as IList;

            if (connectors.Count == Connections.Count)
            {
                for (int i = 0; i < this.Connections.Count; i++)
                {
                    ErdLineConnector lc = this.Connections[i] as ErdLineConnector;
                    lc.DataContext = connectors[i];
                    lc.Style       = ConnectorStyle as Style;
                    lc.ApplyTemplate();
                }
                foreach (Node n in this.Nodes)
                {
                    // find a ContentPresenter of that list item.. [Call FindVisualChild Method]
                    ContentPresenter ContentPresenterObj = WpfUIUtilities.FindVisualChild <ContentPresenter>(n);

                    // call FindName on the DataTemplate of that ContentPresenter
                    DataTemplate DataTemplateObj = ContentPresenterObj.ContentTemplate;

                    // Label Chk = (Label)DataTemplateObj.FindName("lbl", ContentPresenterObj);
                    Header header = (Header)WpfUIUtilities.FindVisualChild <Header>(ContentPresenterObj);
                    if (header == null)
                    {
                        continue;
                    }
                    string content = header.ItemName;


                    foreach (var ee in this.Connections)
                    {
                        if (!(ee is ErdLineConnector))
                        {
                            continue;
                        }
                        ErdLineConnector er = ee as ErdLineConnector;
                        if (er.HeadNodeName == content)
                        {
                            er.HeadNode = n;
                        }
                        if (er.TailNodeName == content)
                        {
                            er.TailNode = n;
                        }
                        er.ApplyTemplate();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void OnModelSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ErdDiagramModel erd = d as ErdDiagramModel;

            string node_source       = erd.NodeSource;
            string connector_source  = erd.ConnectorSource;
            var    newElement        = e.NewValue;
            var    type              = newElement.GetType();
            var    nodesproperty     = type.GetProperty(node_source);
            var    connectorproperty = type.GetProperty(connector_source);

            if (nodesproperty == null || connectorproperty == null)
            {
                return;
            }

            var nodes      = nodesproperty.GetValue(newElement) as IList;
            var connectors = connectorproperty.GetValue(newElement) as IList;

            if (!(nodes is IList) || !(connectors is IList))
            {
                return;
            }
            int i = 1;

            foreach (var node in nodes)
            {
                Node newnode = new Node();
                newnode.OffsetX = 300 * i;
                i++;
                newnode.OffsetY         = 10 * i;
                newnode.ContentTemplate = erd.ItemTemplate;
                newnode.Content         = node;
                erd.Nodes.Add(newnode);
            }

            foreach (var connector in connectors)
            {
                ErdLineConnector lc = new ErdLineConnector();
                lc.Content     = connector;
                lc.DataContext = connector;
                lc.Style       = erd.ConnectorStyle;
                lc.ApplyTemplate();



                erd.Connections.Add(lc);
            }
        }
Exemplo n.º 3
0
        private void ErdDiagramControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            ErdDiagramModel model = this.Model as ErdDiagramModel;

            foreach (Node n in model.Nodes)
            {
                ContentPresenter ContentPresenterObj = WpfUIUtilities.FindVisualChild <ContentPresenter>(n);

                // call FindName on the DataTemplate of that ContentPresenter
                DataTemplate DataTemplateObj = ContentPresenterObj.ContentTemplate;

                // Label Chk = (Label)DataTemplateObj.FindName("lbl", ContentPresenterObj);
                Header header = (Header)WpfUIUtilities.FindVisualChild <Header>(ContentPresenterObj);

                /* Panel pnl = n.ContentTemplate.LoadContent() as Panel;
                 * if (pnl == null) throw new Exception("The first element of template must be panel");
                 * Header header = pnl.Children[0] as Header;*/
                if (header == null)
                {
                    throw new Exception("The first element of template must be header");
                }
                string content = header.ItemName;


                foreach (var ee in model.Connections)
                {
                    if (!(ee is ErdLineConnector))
                    {
                        continue;
                    }
                    ErdLineConnector er = ee as ErdLineConnector;
                    if (er.HeadNodeName == content)
                    {
                        er.HeadNode = n;
                    }
                    if (er.TailNodeName == content)
                    {
                        er.TailNode = n;
                    }
                    er.ApplyTemplate();
                }
            }
        }
Exemplo n.º 4
0
        private static void OnTailNodeRelationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ErdLineConnector lineconnector = d as ErdLineConnector;
            Decorator        decorator     = GetShape(lineconnector, e.NewValue.ToString());

            lineconnector.TailDecoratorShape = decorator.shape;
            lineconnector.TailDecoratorStyle = decorator.style;
            if (lineconnector.HeadNode != null && lineconnector.TailNode != null)
            {
                RegularConnectorPositionStrategy r = new RegularConnectorPositionStrategy();
                r.headNodeHeigth   = lineconnector.HeadNode.ActualHeight;
                r.headNodeWidth    = lineconnector.HeadNode.ActualWidth;
                r.headNodePosition = new Point(lineconnector.HeadNode.OffsetX, lineconnector.HeadNode.OffsetY);
                r.tailNodeHeight   = lineconnector.TailNode.ActualHeight;
                r.tailNodeWidth    = lineconnector.TailNode.ActualWidth;
                r.tailNodePosition = new Point(lineconnector.TailNode.OffsetX, lineconnector.TailNode.OffsetY);
                KeyValuePair <Point, Point> kvp = r.GetPosition();
                lineconnector.StartPointPosition = kvp.Key;
                lineconnector.EndPointPosition   = kvp.Value;
            }
            //lineconnector.TailDecoratorPosition = new Point(lineconnector.TailNode.Position.X, lineconnector.TailNode.Position.Y);
        }
Exemplo n.º 5
0
        private static Decorator GetShape(ErdLineConnector lineconnector, string relationval)
        {
            Decorator d = new Decorator();

            d.shape = DecoratorShape.Circle;
            d.style = new DecoratorStyle();
            switch (relationval.ToUpper())
            {
            case "ONE":  d.style.Fill = new SolidColorBrush(Colors.White);
                break;

            case "MANY":
                d.style.Fill = new SolidColorBrush(Colors.Aqua);
                break;

            case "INHERITANCE":
                d.shape = DecoratorShape.Arrow;
                break;

            default: break;
            }
            return(d);
        }