Example #1
0
        /// <summary>
        /// Insert above anchor component
        /// </summary>
        /// <param name="component">New component</param>
        /// <param name="anchor">Anchor component</param>
        public RungUI InsertAbove(ComponentUIBase component, ComponentUIBase anchor)
        {
            ComponentGridPosition _anchor = _Components.Where(x => x.Component == anchor).First();
            IEnumerable <ComponentGridPosition> column_components = _Components.Where(x => (x.Column == _anchor.Column));

            Core.Components.Node NodeA;
            Core.Components.Node NodeB;

            if (column_components.Count() > 1)
            {
                var nodes = FindInterception(column_components.First().Component, column_components.Last().Component);
                NodeA = nodes.Item1;
                NodeB = nodes.Item2;
            }
            else
            {
                //No other components um column
                NodeA = anchor.LogicComponent.LeftLide;
                NodeB = anchor.LogicComponent.RightLide;
            }

            List <ComponentGridPosition> move_list = GetAllBetween(NodeA, NodeB).Where(x => x.Row > _anchor.Row).ToList();

            _LogicalRung.InsertAbove(component.LogicComponent, anchor.LogicComponent);

            if (!IsSlotEmpty(RowDefinitions.Count - 1, _anchor.Column) ||
                (component.LogicComponent.Class != Core.Components.ComponentBase.ComponentClass.Output && _anchor.Column >= ColumnDefinitions.Count - _OutputBlockLegth))
            {
                AddRow(_anchor.Row);
            }

            if (_anchor.Column >= ColumnDefinitions.Count - _OutputBlockLegth)
            {
                move_list.AddRange(_Components.Where(x => x.Component.LogicComponent.Class == Core.Components.ComponentBase.ComponentClass.Output && x.Row > _anchor.Row && !move_list.Contains(x)));
            }

            var WU = GetAllWiredUnder(_anchor);

            if (WU.Count() > 0)
            {
                int max_row = WU.Max(x => x.Row + 1);
                move_list.AddRange(WU);
                if (max_row > RowDefinitions.Count - 1)
                {
                    AddRow(_anchor.Row);
                }
            }

            foreach (ComponentGridPosition item in move_list.Distinct())
            {
                item.SetPossition(item.Row + 1, item.Column);
            }

            _Components.Add(new ComponentGridPosition(component, _anchor.Row, _anchor.Column));

            _anchor.SetPossition(_anchor.Row + 1, _anchor.Column);

            Children.Add(component);
            return(this);
        }
Example #2
0
        /// <summary>
        /// Insert component with auto select position
        /// </summary>
        /// <param name="component">Component to be added</param>
        public RungUI Add(ComponentUIBase component)
        {
            _LogicalRung.Add(component.LogicComponent);

            if (component.LogicComponent.Class == Core.Components.ComponentBase.ComponentClass.Output)
            {
                var temp = _Components.Where(x => x.Component.LogicComponent.Class == Core.Components.ComponentBase.ComponentClass.Output);
                if (_OutputBlockLegth == 0)
                {
                    _OutputBlockLegth = 1;
                }

                if (temp.Count() == 0)
                {
                    _Components.Add(new ComponentGridPosition(component, 0, ColumnDefinitions.Count - 1));
                }
                else
                {
                    int max_row = temp.Max(x => x.Row);
                    if (max_row == RowDefinitions.Count - 1)
                    {
                        AddRow();
                    }

                    _Components.Add(new ComponentGridPosition(component, max_row + 1, ColumnDefinitions.Count - 1));
                }
            }
            else
            {
                AddColumn();
                foreach (var item in _Components)
                {
                    item.SetPossition(item.Row, item.Column + 1);
                }
                _Components.Add(new ComponentGridPosition(component, 0, 0));
            }

            Children.Add(component);
            return(this);
        }
Example #3
0
 public ComponentGridPosition(ComponentUIBase component, int row, int column)
 {
     Component = component;
     Row       = row;
     Column    = column;
 }
Example #4
0
        /// <summary>
        /// Delete compoenent from the rung
        /// </summary>
        /// <param name="component">Component to be deleted</param>
        public RungUI Remove(ComponentUIBase component)
        {
            ComponentGridPosition _component = _Components.Where(x => x.Component == component).First();


            if (_LogicalRung.Components.Where(x => x.LeftLide == component.LogicComponent.LeftLide && x.RightLide == component.LogicComponent.RightLide).Count() > 1)
            {
                foreach (ComponentGridPosition item in GetAllBetween(component.LogicComponent.LeftLide, component.LogicComponent.RightLide).Where(x => x.Row > _component.Row))
                {
                    item.SetPossition(item.Row - 1, item.Column);
                }
            }
            else
            {
                IEnumerable <ComponentGridPosition> RR = _Components.Where(x => x.Component.LogicComponent.RightLide == component.LogicComponent.RightLide && x != _component);

                if (RR.Count() > 0)
                {
                    IEnumerable <ComponentGridPosition> column_components = _Components.Where(x => x.Column == _component.Column);

                    if (column_components.Count() == 1)
                    {
                        foreach (ComponentGridPosition item in _Components.Where(x => x.Column > _component.Column))
                        {
                            item.SetPossition(item.Row, item.Column - 1);
                        }
                    }
                    else
                    {
                        foreach (ComponentGridPosition item in GetAllBetween(component.LogicComponent.LeftLide, component.LogicComponent.RightLide).Where(x => x.Row > _component.Row))
                        {
                            item.SetPossition(item.Row - 1, item.Column);
                        }
                    }
                }
                else
                {
                    foreach (ComponentGridPosition item in _Components.Where(x => x.Component.LogicComponent.LeftLide == component.LogicComponent.RightLide))
                    {
                        item.SetPossition(item.Row, item.Column - 1);
                    }
                }
            }

            _Components.Remove(_component);
            _LogicalRung.Remove(component.LogicComponent);
            Children.Remove(component);

            var row = RowDefinitions.Where(x => _Components.Where(y => (y.Row == RowDefinitions.IndexOf(x))).Count() == 0);

            if (row.Count() != 0)
            {
                int row_index = RowDefinitions.IndexOf(row.First());
                foreach (ComponentGridPosition item in _Components.Where(x => x.Row > row_index))
                {
                    item.SetPossition(item.Row - 1, item.Column);
                }
                RowDefinitions.RemoveAt(row_index);
            }

            var column = ColumnDefinitions.Where(x => _Components.Where(y => (y.Column == ColumnDefinitions.IndexOf(x))).Count() == 0);

            if (column.Count() != 0)
            {
                int column_index = ColumnDefinitions.IndexOf(column.First());
                if (_component.Column >= ColumnDefinitions.Count - _OutputBlockLegth)
                {
                    _OutputBlockLegth--;
                }
                foreach (ComponentGridPosition item in _Components.Where(x => x.Column > column_index))
                {
                    item.SetPossition(item.Row, item.Column - 1);
                }
                ColumnDefinitions.RemoveAt(column_index);
            }

            return(this);
        }
Example #5
0
 /// <summary>
 /// Insert before anchor node
 /// </summary>
 /// <param name="component">New component</param>
 /// <param name="anchor">Anchor node</param>
 public RungUI InsertAfter(ComponentUIBase component, Node anchor)
 {
     return(this);
 }
Example #6
0
        /// <summary>
        /// Insert after anchor component
        /// </summary>
        /// <param name="component">New component</param>
        /// <param name="anchor">Anchor component</param>
        public RungUI InsertAfter(ComponentUIBase component, ComponentUIBase anchor)
        {
            ComponentGridPosition _anchor = _Components.Where(x => x.Component == anchor).First();
            IEnumerable <ComponentGridPosition> column_components = _Components.Where(x => (x.Column == _anchor.Column));
            List <ComponentGridPosition>        move_list         = new List <ComponentGridPosition>();
            bool addColumn = false;

            if (column_components.Count() > 1)
            {
                IEnumerable <ComponentGridPosition>         test_componets = column_components.Where(x => x != _anchor);
                IEnumerable <Core.Components.ComponentBase> parallel       = null;
                int parallel_max_col;

                foreach (var item in test_componets)
                {
                    var nodes = FindInterception(item.Component, _anchor.Component);
                    var temp  = _LogicalRung.GetAllBetween(nodes.Item1, nodes.Item2);
                    parallel = (parallel == null || parallel.Count() > temp.Count()) ? temp : parallel;
                }

                parallel_max_col = _Components.Where(x => parallel.Contains(x.Component.LogicComponent)).Max(x => x.Column);

                addColumn = !IsSlotEmpty(_anchor.Row, parallel_max_col);
                if (addColumn)
                {
                    move_list.AddRange(_Components.Where(x => (x.Column > _anchor.Column) && (!(parallel.Contains(x.Component.LogicComponent)) || x.Row == _anchor.Row)));
                }
            }
            else
            {
                move_list.AddRange(_Components.Where(x => (x.Column > _anchor.Column)));
                addColumn = true;
            }

            _LogicalRung.InsertAfter(component.LogicComponent, anchor.LogicComponent);

            _Components.Add(new ComponentGridPosition(component, _anchor.Row, _anchor.Column + 1));

            if (addColumn)
            {
                if (_OutputBlockLegth == 0 && component.LogicComponent.Class == Core.Components.ComponentBase.ComponentClass.Output)
                {
                    _OutputBlockLegth = 1;
                }
                else if (_anchor.Column >= ColumnDefinitions.Count - _OutputBlockLegth)
                {
                    _OutputBlockLegth++;
                }
                AddColumn(_anchor.Column);
                move_list.AddRange(_Components.Where(x => x.Component.LogicComponent.Class == Core.Components.ComponentBase.ComponentClass.Output && !move_list.Contains(x)));
            }

            foreach (ComponentGridPosition item in move_list)
            {
                item.SetPossition(item.Row, item.Column + 1);
            }

            Children.Add(component);

            return(this);
        }
Example #7
0
        /// <summary>
        /// Insert before anchor component
        /// </summary>
        /// <param name="component">New component</param>
        /// <param name="anchor">Anchor component</param>
        public RungUI InsertBefore(ComponentUIBase component, ComponentUIBase anchor)
        {
            ComponentGridPosition _anchor = _Components.Where(x => x.Component == anchor).First();
            IEnumerable <ComponentGridPosition>         column_components = _Components.Where(x => (x.Column == _anchor.Column));
            List <ComponentGridPosition>                move_list         = new List <ComponentGridPosition>();
            IEnumerable <Core.Components.ComponentBase> parallel          = null;
            bool addColumn = false;

            if (_anchor.Component.LogicComponent.Class == Core.Components.ComponentBase.ComponentClass.Output)
            {
                Core.Components.Node NodeA;
                Core.Components.Node NodeB;

                if (column_components.Count() > 1)
                {
                    var nodes = FindInterception(column_components.First().Component, column_components.Last().Component);
                    NodeA = nodes.Item1;
                    NodeB = nodes.Item2;
                }
                else
                {
                    //No other components um column
                    NodeA = anchor.LogicComponent.LeftLide;
                    NodeB = anchor.LogicComponent.RightLide;
                }

                parallel = _LogicalRung.GetAllBetween(NodeA, NodeB);

                int parallel_min_col = _Components.Where(x => parallel.Contains(x.Component.LogicComponent)).Min(x => x.Column);
                addColumn = !(parallel_min_col < _anchor.Column && IsSlotEmpty(_anchor.Row, _anchor.Column - 1));

                int insert_pos = parallel_min_col;
                while (insert_pos < _anchor.Column && !IsSlotEmpty(_anchor.Row, insert_pos))
                {
                    insert_pos++;
                }

                _LogicalRung.InsertBefore(component.LogicComponent, anchor.LogicComponent);

                _Components.Add(new ComponentGridPosition(component, _anchor.Row, insert_pos));
            }
            else
            {
                if (column_components.Count() > 1)
                {
                    IEnumerable <ComponentGridPosition> test_componets = column_components.Where(x => x != _anchor);
                    int parallel_max_col;

                    foreach (var item in test_componets)
                    {
                        var nodes = FindInterception(item.Component, _anchor.Component);
                        var temp  = _LogicalRung.GetAllBetween(nodes.Item1, nodes.Item2);
                        parallel = (parallel == null || parallel.Count() > temp.Count()) ? temp : parallel;
                    }

                    parallel_max_col = _Components.Where(x => parallel.Contains(x.Component.LogicComponent)).Max(x => x.Column);

                    addColumn = !IsSlotEmpty(_anchor.Row, parallel_max_col);
                    if (addColumn)
                    {
                        move_list.AddRange(_Components.Where(x => (x.Column > _anchor.Column) && (!(parallel.Contains(x.Component.LogicComponent)) || x.Row == _anchor.Row)));
                    }
                }
                else
                {
                    move_list.AddRange(_Components.Where(x => (x.Column > _anchor.Column)));
                    addColumn = true;
                }

                move_list.Add(_anchor);

                _LogicalRung.InsertBefore(component.LogicComponent, anchor.LogicComponent);

                _Components.Add(new ComponentGridPosition(component, _anchor.Row, _anchor.Column));
            }

            if (addColumn)
            {
                if (_anchor.Column >= ColumnDefinitions.Count - _OutputBlockLegth)
                {
                    _OutputBlockLegth++;
                }
                AddColumn(_anchor.Column);
                move_list.AddRange(_Components.Where(x => x.Component.LogicComponent.Class == Core.Components.ComponentBase.ComponentClass.Output && !move_list.Contains(x)));
            }

            foreach (ComponentGridPosition item in move_list)
            {
                item.SetPossition(item.Row, item.Column + 1);
            }

            Children.Add(component);
            return(this);
        }
Example #8
0
 private Tuple <Core.Components.Node, Core.Components.Node> FindInterception(ComponentUIBase componentA, ComponentUIBase componentB)
 {
     return(_LogicalRung.FindInterception(componentA.LogicComponent, componentB.LogicComponent));
 }